diff options
Diffstat (limited to 'Runtime/GfxDevice')
251 files changed, 120223 insertions, 0 deletions
diff --git a/Runtime/GfxDevice/BatchRendering.cpp b/Runtime/GfxDevice/BatchRendering.cpp new file mode 100644 index 0000000..3707b2c --- /dev/null +++ b/Runtime/GfxDevice/BatchRendering.cpp @@ -0,0 +1,279 @@ +#include "UnityPrefix.h" +#include "BatchRendering.h" + +#include "GfxDevice.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/Filters/Mesh/TransformVertex.h" +#include "Runtime/Filters/Mesh/LodMesh.h" +#include "Runtime/Filters/Mesh/MeshRenderer.h" +#include "Runtime/Filters/Mesh/SpriteRenderer.h" +#include "Runtime/Camera/Renderqueue.h" +#include "Runtime/Utilities/Prefetch.h" +#include "Runtime/Utilities/LogAssert.h" +#include "Runtime/Graphics/ParticleSystem/ParticleSystemRenderer.h" + + +BatchRenderer::BatchRenderer() +:m_BatchInstances(kMemTempAlloc) +,m_ActiveChannels(0) +,m_ActiveType(kRendererUnknown) +{ + m_BatchInstances.reserve(128); +} + +void BatchRenderer::Add(BaseRenderer* renderer, int subsetIndex, ChannelAssigns const* channels, const Matrix4x4f& xform, int xformType) +{ + const RendererType rendererType = renderer->GetRendererType(); + if (m_ActiveChannels != channels || m_ActiveType != rendererType) + Flush(); + + m_ActiveChannels = channels; + m_ActiveType = rendererType; + +#if GFX_ENABLE_DRAW_CALL_BATCHING + + // batching requires position + bool channelSetupAllowsBatching = (channels->GetTargetMap() & (1<<kVertexCompVertex)); +#if GFX_OPENGLESxx_ONLY + // we do not renormalize normals in gles11 so let's play safe here + channelSetupAllowsBatching &= !(GetGfxDevice().IsPositionRequiredForTexGen() || GetGfxDevice().IsNormalRequiredForTexGen()); +#endif + + + bool rendererTypeAllowsBatching = (rendererType == kRendererMesh) || (rendererType == kRendererSprite); + if(rendererType == kRendererParticleSystem) + { + ParticleSystemRenderer* psRenderer = (ParticleSystemRenderer*)renderer; + if(kSRMMesh != psRenderer->GetRenderMode()) // We currently don't do batching for mesh particle emitters + rendererTypeAllowsBatching = true; + } + if (channelSetupAllowsBatching && rendererTypeAllowsBatching) + { + BatchInstanceData& rb = m_BatchInstances.push_back(); + rb.renderer = (Renderer*)renderer; + rb.subsetIndex = subsetIndex; + rb.xform = xform; + rb.xformType = xformType; + } + else +#endif + { + Assert(channels); + SetupObjectMatrix (xform, xformType); + renderer->Render (subsetIndex, *channels); + } +} + +void BatchRenderer::Flush() +{ + size_t instanceCount = m_BatchInstances.size(); +#if GFX_ENABLE_DRAW_CALL_BATCHING + if (instanceCount > 0) + { + Assert(m_ActiveChannels); + if (instanceCount == 1) + { + const BatchInstanceData* data = m_BatchInstances.begin(); + SetupObjectMatrix (data->xform, data->xformType); + data->renderer->Render (data->subsetIndex, *m_ActiveChannels); + } + else if(m_ActiveType == kRendererMesh) + MeshRenderer::RenderMultiple (m_BatchInstances.begin(), instanceCount, *m_ActiveChannels); + else if(m_ActiveType == kRendererParticleSystem) + ParticleSystemRenderer::RenderMultiple (m_BatchInstances.begin(), instanceCount, *m_ActiveChannels); +#if ENABLE_SPRITES + else if (m_ActiveType == kRendererSprite) + SpriteRenderer::RenderMultiple (m_BatchInstances.begin(), instanceCount, *m_ActiveChannels); +#endif + else + Assert (!"Renderer type does not support batching"); + } +#else + Assert(instanceCount == 0); +#endif + m_BatchInstances.resize_uninitialized(0); + m_ActiveChannels = 0; + m_ActiveType = kRendererUnknown; +} + +void AppendMeshIndices(UInt16* dstIndices, size_t& dstIndexCount, const UInt16* srcIndices, size_t srcIndexCount, bool isTriStrip) +{ + Prefetch(srcIndices, srcIndexCount * kVBOIndexSize); + + if (isTriStrip && dstIndexCount > 0) + { + dstIndices[dstIndexCount] = dstIndices[dstIndexCount - 1]; + dstIndexCount++; + dstIndices[dstIndexCount] = srcIndices[0]; + dstIndexCount++; + } + + memcpy(&dstIndices[dstIndexCount], srcIndices, srcIndexCount * kVBOIndexSize); + dstIndexCount += srcIndexCount; + + if (isTriStrip && (srcIndexCount % 2 == 1)) + { + Assert(dstIndexCount != 0); + dstIndices[dstIndexCount] = dstIndices[dstIndexCount - 1]; + dstIndexCount++; + Assert(dstIndexCount % 2 == 0); + } +} + + +static inline void +TransformIndicesInternalImplPositive( int* __restrict dst, const int* __restrict src, unsigned count, int offset ) +{ + Assert( offset>=0 ); + Assert( offset<(int)0xFFFF ); + const int maskOffset = ((unsigned)offset << 16) | (unsigned)offset; + + for( unsigned i = 0 ; i < count ; ++i ) + *dst++ = *src++ + maskOffset; +} + +static inline void +TransformIndicesInternalImplNegative( int* __restrict dst, const int* __restrict src, unsigned count, int offset ) +{ + Assert( offset>=0 ); + Assert( offset<(int)0xFFFF ); + const int maskOffset = ((unsigned)offset << 16) | (unsigned)offset; + + for( unsigned i = 0 ; i < count ; ++i ) + *dst++ = *src++ - maskOffset; +} + +size_t TransformIndices(UInt16* dst, const void* srcIB, size_t firstByte, size_t indexCount, size_t firstVertex, size_t batchVertexOffset, bool isTriStrip) +{ + UInt16* srcIndices = (UInt16*)((UInt8*)srcIB + firstByte); + Prefetch(srcIndices, indexCount * kVBOIndexSize); + + UInt16* const baseDataPtr = dst; + if (isTriStrip && batchVertexOffset > 0) + { + Assert(srcIndices[0] >= firstVertex); + dst[0] = dst[-1]; + dst[1] = srcIndices[0] - firstVertex + batchVertexOffset; + dst += 2; + } + + int offset = (int)batchVertexOffset - (int)firstVertex; + int copyCount = indexCount/2; + if( offset >= 0 ) TransformIndicesInternalImplPositive((int*)dst, (int*)srcIndices, copyCount, offset); + else TransformIndicesInternalImplNegative((int*)dst, (int*)srcIndices, copyCount, -offset); + + // leftover, as we copy ints + if(2*copyCount != indexCount) + dst[indexCount-1] = srcIndices[indexCount-1] - firstVertex + batchVertexOffset; + +#ifdef CHECK_INDEX_TRANSFORM_RESULTS + const UInt16* dstCheck = dst; + for( unsigned i = 0 ; i < indexCount ; ++i ) + Assert( dstCheck[i] == srcIndices[i] - submesh.firstVertex + batchVertexOffset ); +#endif + + dst += indexCount; + if (isTriStrip && indexCount % 2 == 1) + { + dst[0] = dst[-1]; + ++dst; + } + Assert ((dst - baseDataPtr) <= indexCount + 3); + return (dst - baseDataPtr); +} + +size_t TransformVertices(UInt8* dst, Matrix4x4f const& m, const VertexBufferData& src, size_t firstVertex, size_t vertexCount, UInt32 channelsInVBO) +{ + UInt8* inChannels[kShaderChannelCount]; + UInt32 inStrides[kShaderChannelCount]; + bool multiStream = false; + for (int i = 0; i < kShaderChannelCount; i++) + { + if (channelsInVBO & (1 << i)) + { + const ChannelInfo& info = src.channels[i]; + DebugAssert(info.IsValid()); + UInt32 stride = info.CalcStride(src.streams); + UInt32 offset = info.CalcOffset(src.streams) + stride * firstVertex; + inChannels[i] = &src.buffer[offset]; + inStrides[i] = stride; + if (info.stream > 0) + multiStream = true; + } + else + { + inChannels[i] = NULL; + inStrides[i] = 0; + } + } + + TransformVerticesStrided( + StrideIterator<Vector3f>(inChannels[kShaderChannelVertex], inStrides[kShaderChannelVertex]), + StrideIterator<Vector3f>(inChannels[kShaderChannelNormal], inStrides[kShaderChannelNormal]), + StrideIterator<ColorRGBA32>(inChannels[kShaderChannelColor], inStrides[kShaderChannelColor]), + StrideIterator<Vector2f>(inChannels[kShaderChannelTexCoord0], inStrides[kShaderChannelTexCoord0]), + StrideIterator<Vector2f>(inChannels[kShaderChannelTexCoord1], inStrides[kShaderChannelTexCoord1]), + StrideIterator<Vector4f>(inChannels[kShaderChannelTangent], inStrides[kShaderChannelTangent]), + dst, m, vertexCount, multiStream); + + return vertexCount; +} +#if ENABLE_SPRITES +void TransformSprite (UInt8* vb, UInt16* ib, const Matrix4x4f* m, const SpriteRenderData* rd, ColorRGBA32 color, size_t firstVertex) +{ + UInt32 vertexCount = rd->vertices.size(); + UInt32 indexCount = rd->indices.size(); + UInt8* srcVertices = vertexCount > 0 ? (UInt8 *)&rd->vertices[0] : NULL; + UInt16* srcIndices = indexCount > 0 ? (UInt16 *)&rd->indices[0] : NULL; + +#if (UNITY_SUPPORTS_NEON || UNITY_SUPPORTS_VFP) && !UNITY_DISABLE_NEON_SKINNING + int stride = sizeof(SpriteVertex); + UInt8* end = srcVertices + vertexCount * stride; + UInt8* uv = srcVertices + sizeof(Vector3f); + Matrix4x4f xform = (m) ? *m : Matrix4x4f::identity; +# if UNITY_SUPPORTS_NEON + if (CPUInfo::HasNEONSupport()) + s_TransformVertices_Sprite_NEON(srcVertices, end, uv, xform.m_Data, (UInt8 *)vb, stride, color.GetUInt32()); + else +# endif +# if UNITY_SUPPORTS_VFP + s_TransformVertices_Sprite_VFP (srcVertices, end, uv, xform.m_Data, (UInt8 *)vb, stride, color.GetUInt32()); +# else + { + ErrorString("non-NEON path not enabled!"); + } +# endif +#else + struct SpriteVBOLayout { + Vector3f pos; + ColorRGBA32 col; + Vector2f uv; + }; + SpriteVertex *src = (SpriteVertex *)srcVertices; + SpriteVBOLayout *dst = (SpriteVBOLayout *)vb; + while (vertexCount-- > 0) + { + dst->pos = (m) ? m->MultiplyPoint3(src->pos) : src->pos; + dst->col = color; + dst->uv = src->uv; + dst++; + src++; + } +#endif + Prefetch(srcIndices, indexCount * kVBOIndexSize); + if (firstVertex) + { + int maskOffset = ((unsigned)firstVertex << 16) | (unsigned)firstVertex; + int copyCount = indexCount>>1; + + if(2*copyCount != indexCount) + ib[indexCount-1] = srcIndices[indexCount-1] + firstVertex; + int *dst = (int *)ib; + int *src = (int *)srcIndices; + while (copyCount-- > 0) + *(dst++) = *(src++) + maskOffset; + } + else + memcpy(ib, srcIndices, sizeof(UInt16) * indexCount); +} +#endif diff --git a/Runtime/GfxDevice/BatchRendering.h b/Runtime/GfxDevice/BatchRendering.h new file mode 100644 index 0000000..a12bdbb --- /dev/null +++ b/Runtime/GfxDevice/BatchRendering.h @@ -0,0 +1,34 @@ +#pragma once + +#include "GfxDeviceConfigure.h" +#include "Runtime/Camera/BaseRenderer.h" +#include "Runtime/Utilities/dynamic_array.h" +#include "Runtime/Math/Color.h" + +struct BatchInstanceData; +class Matrix4x4f; +struct SubMesh; +struct VertexBufferData; +class BaseRenderer; +class ChannelAssigns; +#if ENABLE_SPRITES +struct SpriteRenderData; +#endif +struct BatchRenderer +{ + dynamic_array<BatchInstanceData> m_BatchInstances; + ChannelAssigns const* m_ActiveChannels; + RendererType m_ActiveType; + + BatchRenderer(); + + void Add(BaseRenderer* renderer, int subsetIndex, ChannelAssigns const* channels, const Matrix4x4f& xform, int xformType); + void Flush(); +}; + +void AppendMeshIndices(UInt16* dstIndices, size_t& dstIndexCount, const UInt16* srcIndices, size_t srcIndexCount, bool isTriStrip); +size_t TransformIndices(UInt16* dst, const void* srcIB, size_t firstByte, size_t indexCount, size_t firstVertex, size_t batchVertexOffset, bool isTriStrip); +size_t TransformVertices(UInt8* dst, Matrix4x4f const& m, const VertexBufferData& src, size_t firstVertex, size_t vertexCount, UInt32 channelsInVBO); +#if ENABLE_SPRITES +void TransformSprite (UInt8* vb, UInt16* ib, const Matrix4x4f* m, const SpriteRenderData* rd, ColorRGBA32 color, size_t firstVertex); +#endif diff --git a/Runtime/GfxDevice/BuiltinShaderParams.cpp b/Runtime/GfxDevice/BuiltinShaderParams.cpp new file mode 100644 index 0000000..a8edcb5 --- /dev/null +++ b/Runtime/GfxDevice/BuiltinShaderParams.cpp @@ -0,0 +1,100 @@ +#include "UnityPrefix.h" +#include "BuiltinShaderParams.h" +#include "BuiltinShaderParamsNames.h" + +BuiltinShaderParamValues::BuiltinShaderParamValues () +{ + memset (vectorParamValues, 0, sizeof(vectorParamValues)); + memset (matrixParamValues, 0, sizeof(matrixParamValues)); + memset (instanceVectorValues, 0, sizeof(instanceVectorValues)); + + // Initialize default light directions to (1,0,0,0), to avoid the case + // when a shader with uninitialized value gets "tolight" vector of zero, + // which returns NaN when doing normalize() on it, on GeForce FX/6/7. + for (int i = 0; i < kMaxSupportedVertexLights; ++i) + vectorParamValues[kShaderVecLight0Position+i].x = 1.0f; +} + + + +bool BuiltinShaderParamIndices::CheckMatrixParam(const char* name, int index, int rowCount, int colCount, int cbID) +{ + int paramIndex; + if (IsShaderInstanceMatrixParam(name, ¶mIndex)) + { + mat[paramIndex].gpuIndex = index; + mat[paramIndex].rows = rowCount; + mat[paramIndex].cols = colCount; + #if GFX_SUPPORTS_CONSTANT_BUFFERS + mat[paramIndex].cbID = cbID; + #endif + return true; + } + return false; +} + +bool BuiltinShaderParamIndices::CheckVectorParam(const char* name, int index, int dim, int cbID) +{ + int paramIndex; + if (IsShaderInstanceVectorParam(name, ¶mIndex)) + { + vec[paramIndex].gpuIndex = index; + vec[paramIndex].dim = dim; + #if GFX_SUPPORTS_CONSTANT_BUFFERS + vec[paramIndex].cbID = cbID; + #endif + return true; + } + return false; +} + +// -------------------------------------------------------------------------- + +#if ENABLE_UNIT_TESTS + +#include "External/UnitTest++/src/UnitTest++.h" + +SUITE (BuiltinShaderParamsTests) +{ + // Having anything named _Reflection as built-in property is dangerous. + // We do have a built-in matrix like that, but there are often shaders using that name + // as texture. Ensure we never have anything _Reflection in built-ins. + TEST(MakeSureNoBuiltinNamedReflection) + { + int index; + CHECK (!IsVectorBuiltinParam ("_Reflection", &index)); + CHECK (!IsMatrixBuiltinParam ("_Reflection", &index)); + CHECK (!IsTexEnvBuiltinParam ("_Reflection", &index)); + } + + // Ensure initial vector & matrix values are zero (except light directions, which should default to 1,0,0,0). + // For some built-ins, we only setup their values when needed (e.g. when actual light is set up), + // but a shader might reference them and get NaNs or other totally invalid values. + TEST (BuiltinParamValuesAreInitialized) + { + BuiltinShaderParamValues vals; + for (int i = 0; i < kShaderVecCount; ++i) + { + const Vector4f& v = vals.GetVectorParam(BuiltinShaderVectorParam(i)); + float expected = (i>=kShaderVecLight0Position && i<=kShaderVecLight7Position) ? 1.0f : 0.0f; + CHECK_EQUAL (expected,v.x); CHECK_EQUAL (0.0f,v.y); CHECK_EQUAL (0.0f,v.z); CHECK_EQUAL (0.0f,v.w); + } + for (int i = 0; i < kShaderMatCount; ++i) + { + const Matrix4x4f& v = vals.GetMatrixParam(BuiltinShaderMatrixParam(i)); + for (int j = 0; j < 16; ++j) + { + CHECK_EQUAL (0.0f, v.GetPtr()[j]); + } + } + } + + // basic checks for builtin arrays recognition + TEST(BuiltinArrays) + { + CHECK_EQUAL(IsBuiltinArrayName("unity_LightPosition"), true); + CHECK_EQUAL(IsBuiltinArrayName("unity_LightPosition0"), false); + } +} // SUITE + +#endif // ENABLE_UNIT_TESTS diff --git a/Runtime/GfxDevice/BuiltinShaderParams.h b/Runtime/GfxDevice/BuiltinShaderParams.h new file mode 100644 index 0000000..a39f7f2 --- /dev/null +++ b/Runtime/GfxDevice/BuiltinShaderParams.h @@ -0,0 +1,73 @@ +#pragma once + +#include "GfxDeviceObjects.h" +#include "BuiltinShaderParamsNames.h" +#include "Runtime/Utilities/fixed_bitset.h" +#include "Runtime/Utilities/NonCopyable.h" + +#include "Runtime/Math/Vector4.h" +#include "Runtime/Math/Matrix4x4.h" +#include "External/shaderlab/Library/texenv.h" + + +struct BuiltinShaderParamIndices +{ + struct MatrixParamData { + MatrixParamData() : gpuIndex(-1), rows(0), cols(0) + #if GFX_SUPPORTS_CONSTANT_BUFFERS + , cbID(-1) + #endif + { } + int gpuIndex; + UInt16 rows; + UInt16 cols; + #if GFX_SUPPORTS_CONSTANT_BUFFERS + int cbID; + #endif + }; + struct VectorParamData { + VectorParamData() : gpuIndex(-1), dim(0) + #if GFX_SUPPORTS_CONSTANT_BUFFERS + , cbID(-1) + #endif + { } + int gpuIndex; + SInt16 dim; + #if GFX_SUPPORTS_CONSTANT_BUFFERS + int cbID; + #endif + }; + + MatrixParamData mat[kShaderInstanceMatCount]; + VectorParamData vec[kShaderInstanceVecCount]; + + bool CheckMatrixParam (const char* name, int index, int rowCount, int colCount, int cbID); + bool CheckVectorParam (const char* name, int index, int dim, int cbID); +}; + + +class BuiltinShaderParamValues : public NonCopyable +{ +public: + BuiltinShaderParamValues (); + + FORCE_INLINE const Vector4f& GetVectorParam(BuiltinShaderVectorParam param) const { DebugAssert(param >= 0 && param < kShaderVecCount); return vectorParamValues[param]; } + FORCE_INLINE const Matrix4x4f& GetMatrixParam(BuiltinShaderMatrixParam param) const { DebugAssert(param >= 0 && param < kShaderMatCount); return matrixParamValues[param]; } + FORCE_INLINE const ShaderLab::TexEnv& GetTexEnvParam(BuiltinShaderTexEnvParam param) const { DebugAssert(param >= 0 && param < kShaderTexEnvCount); return texEnvParamValues[param]; } + FORCE_INLINE const Vector4f& GetInstanceVectorParam(ShaderBuiltinInstanceVectorParam param) const { DebugAssert(param >= 0 && param < kShaderInstanceVecCount); return instanceVectorValues[param]; } + + FORCE_INLINE Vector4f& GetWritableVectorParam(BuiltinShaderVectorParam param) { DebugAssert(param >= 0 && param < kShaderVecCount); return vectorParamValues[param]; } + FORCE_INLINE Matrix4x4f& GetWritableMatrixParam(BuiltinShaderMatrixParam param) { DebugAssert(param >= 0 && param < kShaderMatCount); return matrixParamValues[param]; } + FORCE_INLINE ShaderLab::TexEnv& GetWritableTexEnvParam(BuiltinShaderTexEnvParam param) { DebugAssert(param >= 0 && param < kShaderTexEnvCount); return texEnvParamValues[param]; } + + FORCE_INLINE void SetVectorParam(BuiltinShaderVectorParam param, const Vector4f& val) { GetWritableVectorParam(param) = val; } + FORCE_INLINE void SetMatrixParam(BuiltinShaderMatrixParam param, const Matrix4x4f& val) { GetWritableMatrixParam(param) = val; } + FORCE_INLINE void SetTexEnvParam(BuiltinShaderTexEnvParam param, const ShaderLab::TexEnv& val) { GetWritableTexEnvParam(param) = val; } + FORCE_INLINE void SetInstanceVectorParam(ShaderBuiltinInstanceVectorParam param, const Vector4f& val) { DebugAssert(param >= 0 && param < kShaderInstanceVecCount); instanceVectorValues[param] = val; } + +private: + Vector4f vectorParamValues[kShaderVecCount]; + Matrix4x4f matrixParamValues[kShaderMatCount]; + ShaderLab::TexEnv texEnvParamValues[kShaderTexEnvCount]; + Vector4f instanceVectorValues[kShaderInstanceVecCount]; +}; diff --git a/Runtime/GfxDevice/BuiltinShaderParamsNames.cpp b/Runtime/GfxDevice/BuiltinShaderParamsNames.cpp new file mode 100644 index 0000000..d0c9eb2 --- /dev/null +++ b/Runtime/GfxDevice/BuiltinShaderParamsNames.cpp @@ -0,0 +1,259 @@ +#include "UnityPrefix.h" +#include "BuiltinShaderParamsNames.h" +#include "Runtime/Utilities/ArrayUtility.h" + +namespace +{ + struct ParamNameIndex + { + bool operator < (const ParamNameIndex& rhs) const { return strcmp(name, rhs.name) < 0; } + bool operator == (const ParamNameIndex& rhs) const { return strcmp(name, rhs.name) == 0; } + const char* name; + int index; + }; + + class ParamNameLookup + { + public: + ParamNameLookup() {} + + void AddBuiltinNames(const char** names, int count) + { + m_Params.resize(count); + for (int i = 0; i < count; ++i) + { + m_Params[i].name = names[i]; + m_Params[i].index = i; + } + } + void AddSynonyms(ParamNameIndex* params, int count) + { + m_Params.reserve(m_Params.size() + count); + for (int i = 0; i < count; ++i) + m_Params.push_back(params[i]); + } + void Sort() + { + std::sort(m_Params.begin(), m_Params.end()); + } + bool Find(const char* name, int* outIndex) const + { + ParamNameIndex key = { name, 0 }; + ParamNameArray::const_iterator found = std::find(m_Params.begin(), m_Params.end(), key); + if (found != m_Params.end()) + { + if (outIndex) + *outIndex = found->index; + return true; + } + return false; + } + + private: + typedef std::vector<ParamNameIndex> ParamNameArray; + ParamNameArray m_Params; + }; + + struct ParamNameLookups + { + ParamNameLookup instanceMatrices; + ParamNameLookup instanceVectors; + ParamNameLookup vectors; + ParamNameLookup matrices; + ParamNameLookup texEnvs; + }; + + ParamNameLookups* s_NameLookups; +} + + +//============================================================================== + + +inline static const char** GetInstanceMatrixParams() +{ + static const char* lookup[kShaderInstanceMatCount] = { + BUILTIN_SHADER_PARAMS_INSTANCE_MATRICES + +#if GFX_HIGH_LEVEL_FF + , + BUILTIN_SHADER_PARAMS_INSTANCE_MATRICES_FF +#endif + }; + return lookup; +} + +inline static const char** GetInstanceVectorParams() +{ + static const char* lookup[kShaderInstanceVecCount] = { + BUILTIN_SHADER_PARAMS_INSTANCE_VECTORS + }; + return lookup; +} + +inline static const char** GetBuiltinVectorParams() +{ + static const char* lookup[kShaderVecCount] = { + BUILTIN_SHADER_PARAMS_VECTORS +#if GFX_HIGH_LEVEL_FF + , + BUILTIN_SHADER_PARAMS_VECTORS_FF +#endif + }; + return lookup; +} + +static ParamNameIndex s_VectorSynonymMapping[] = { + { "glstate_light0_diffuse", kShaderVecLight0Diffuse }, + { "glstate_light1_diffuse", kShaderVecLight1Diffuse }, + { "glstate_light2_diffuse", kShaderVecLight2Diffuse }, + { "glstate_light3_diffuse", kShaderVecLight3Diffuse }, + { "glstate_light0_position", kShaderVecLight0Position }, + { "glstate_light1_position", kShaderVecLight1Position }, + { "glstate_light2_position", kShaderVecLight2Position }, + { "glstate_light3_position", kShaderVecLight3Position }, + { "glstate_light0_attenuation", kShaderVecLight0Atten }, + { "glstate_light1_attenuation", kShaderVecLight1Atten }, + { "glstate_light2_attenuation", kShaderVecLight2Atten }, + { "glstate_light3_attenuation", kShaderVecLight3Atten }, + { "glstate_light0_spotDirection", kShaderVecLight0SpotDirection }, + { "glstate_light1_spotDirection", kShaderVecLight1SpotDirection }, + { "glstate_light2_spotDirection", kShaderVecLight2SpotDirection }, + { "glstate_light3_spotDirection", kShaderVecLight3SpotDirection } +}; + +inline static const char** GetBuiltinMatrixParams() +{ + static const char* lookup[kShaderMatCount] = { + BUILTIN_SHADER_PARAMS_MATRICES + }; + return lookup; +} + +static ParamNameIndex s_MatrixSynonymMapping[] = { + { "unity_World2Shadow", kShaderMatWorldToShadow }, + { "unity_World2Shadow0", kShaderMatWorldToShadow }, + { "unity_World2Shadow1", kShaderMatWorldToShadow1 }, + { "unity_World2Shadow2", kShaderMatWorldToShadow2 }, + { "unity_World2Shadow3", kShaderMatWorldToShadow3 } +}; + +inline static const char** GetBuiltinTexEnvParams() +{ + static const char* lookup[kShaderTexEnvCount] = { + BUILTIN_SHADER_PARAMS_TEXENVS + }; + return lookup; +} + + +//------------------------------------------------------------------------------ + +const char* GetShaderInstanceMatrixParamName(int paramIndex) +{ + Assert(paramIndex >= 0 && paramIndex < kShaderInstanceMatCount); + return GetInstanceMatrixParams()[paramIndex]; +} +const char* GetShaderInstanceVectorParamName(int paramIndex) +{ + Assert(paramIndex >= 0 && paramIndex < kShaderInstanceVecCount); + return GetInstanceVectorParams()[paramIndex]; +} +const char* GetBuiltinMatrixParamName(int paramIndex) +{ + Assert(paramIndex >= 0 && paramIndex < kShaderMatCount); + return GetBuiltinMatrixParams()[paramIndex]; +} +const char* GetBuiltinVectorParamName(int paramIndex) +{ + Assert(paramIndex >= 0 && paramIndex < kShaderVecCount); + return GetBuiltinVectorParams()[paramIndex]; +} +const char* GetBuiltinTexEnvParamName(int paramIndex) +{ + Assert(paramIndex >= 0 && paramIndex < kShaderTexEnvCount); + return GetBuiltinTexEnvParams()[paramIndex]; +} + +//------------------------------------------------------------------------------ + +void InitializeBuiltinShaderParamNames () +{ + Assert (!s_NameLookups); + // needs to dynamically allocate this due to static initialization order (FastPropertyNames + // might be initialized before this is etc.) + s_NameLookups = new ParamNameLookups (); + + s_NameLookups->instanceMatrices.AddBuiltinNames(GetInstanceMatrixParams(), kShaderInstanceMatCount); + s_NameLookups->instanceMatrices.Sort(); + + s_NameLookups->instanceVectors.AddBuiltinNames(GetInstanceVectorParams(), kShaderInstanceVecCount); + s_NameLookups->instanceVectors.Sort(); + + s_NameLookups->vectors.AddBuiltinNames(GetBuiltinVectorParams(), kShaderVecCount); + s_NameLookups->vectors.AddSynonyms(s_VectorSynonymMapping, ARRAY_SIZE(s_VectorSynonymMapping)); + s_NameLookups->vectors.Sort(); + + s_NameLookups->matrices.AddBuiltinNames(GetBuiltinMatrixParams(), kShaderMatCount); + s_NameLookups->matrices.AddSynonyms(s_MatrixSynonymMapping, ARRAY_SIZE(s_MatrixSynonymMapping)); + s_NameLookups->matrices.Sort(); + + s_NameLookups->texEnvs.AddBuiltinNames(GetBuiltinTexEnvParams(), kShaderTexEnvCount); + s_NameLookups->texEnvs.Sort(); +} + +void CleanupBuiltinShaderParamNames () +{ + delete s_NameLookups; + s_NameLookups = NULL; +} + +bool IsShaderInstanceMatrixParam(const char* name, int* paramIndex) +{ + return s_NameLookups->instanceMatrices.Find(name, paramIndex); +} + +bool IsShaderInstanceVectorParam(const char* name, int* paramIndex) +{ + return s_NameLookups->instanceVectors.Find(name, paramIndex); +} + +bool IsVectorBuiltinParam(const char* name, int* paramIndex) +{ + return s_NameLookups->vectors.Find(name, paramIndex); +} + +bool IsMatrixBuiltinParam(const char* name, int* paramIndex) +{ + return s_NameLookups->matrices.Find(name, paramIndex); +} + +bool IsTexEnvBuiltinParam(const char* name, int* paramIndex) +{ + return s_NameLookups->texEnvs.Find(name, paramIndex); +} + +bool IsBuiltinArrayName(const char* name) +{ + static const char* _BuiltinArrayName[] = + { + "glstate_matrix_texture", + "unity_LightColor", + "unity_LightPosition", + "unity_LightAtten", + "unity_World2Shadow", + "unity_ShadowSplitSpheres", + "_ShadowOffsets", + "unity_CameraWorldClipPlanes" + }; + + static const unsigned _BuiltinArrayCount = sizeof(_BuiltinArrayName) / sizeof(const char*); + + for( unsigned i = 0 ; i < _BuiltinArrayCount ; ++i ) + { + if( ::strcmp(name, _BuiltinArrayName[i]) == 0 ) + return true; + } + + return false; +} diff --git a/Runtime/GfxDevice/BuiltinShaderParamsNames.h b/Runtime/GfxDevice/BuiltinShaderParamsNames.h new file mode 100644 index 0000000..7e68b6e --- /dev/null +++ b/Runtime/GfxDevice/BuiltinShaderParamsNames.h @@ -0,0 +1,444 @@ +#pragma once + + +// Fixed function emulation is done in a high-level language where we need variable names etc. +#define GFX_HIGH_LEVEL_FF (GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30 || GFX_SUPPORTS_D3D11) + + +// We need the set of "known" glstate parameters for both non-OpenGL rendering runtimes and +// the CgBatch compiler (so that it can report errors for unsupported ones). +// Hence they are in a separate file here. + +const char* GetShaderInstanceMatrixParamName(int paramIndex); +const char* GetShaderInstanceVectorParamName(int paramIndex); + +const char* GetBuiltinVectorParamName(int paramIndex); +const char* GetBuiltinMatrixParamName(int paramIndex); +const char* GetBuiltinTexEnvParamName(int paramIndex); + +bool IsShaderInstanceMatrixParam(const char* name, int* paramIndex=0); +bool IsShaderInstanceVectorParam(const char* name, int* paramIndex); + +bool IsVectorBuiltinParam(const char* name, int* paramIndex=0); +bool IsMatrixBuiltinParam(const char* name, int* paramIndex=0); +bool IsTexEnvBuiltinParam(const char* name, int* paramIndex=0); + +void InitializeBuiltinShaderParamNames (); +void CleanupBuiltinShaderParamNames (); + +bool IsBuiltinArrayName(const char* name); + + +// Matrices set by unity as "per-instance" data for each object. +enum ShaderBuiltinInstanceMatrixParam { + kShaderInstanceMatMVP = 0, + kShaderInstanceMatMV, + kShaderInstanceMatM, + kShaderInstanceMatInvM, + kShaderInstanceMatTransMV, + kShaderInstanceMatInvTransMV, + kShaderInstanceMatTexture0, + kShaderInstanceMatTexture1, + kShaderInstanceMatTexture2, + kShaderInstanceMatTexture3, + kShaderInstanceMatTexture4, + kShaderInstanceMatTexture5, + kShaderInstanceMatTexture6, + kShaderInstanceMatTexture7, + +#if GFX_HIGH_LEVEL_FF + kShaderInstanceMatNormalMatrix, +#endif + + kShaderInstanceMatCount +}; + +enum ShaderBuiltinInstanceVectorParam { + kShaderInstanceVecScale, + + kShaderInstanceVecCount +}; + + +enum BuiltinShaderMatrixParam { + kShaderMatView, + kShaderMatProj, + kShaderMatViewProj, + kShaderMatWorldToCamera, + kShaderMatCameraToWorld, + kShaderMatWorldToShadow, + kShaderMatWorldToShadow1, + kShaderMatWorldToShadow2, + kShaderMatWorldToShadow3, + kShaderMatLightmapMatrix, + kShaderMatProjector, + kShaderMatProjectorDistance, + kShaderMatProjectorClip, + kShaderMatGUIClip, + kShaderMatLightMatrix, + + kShaderMatCount +}; + +enum BuiltinShaderVectorParam { + kShaderVecLight0Diffuse = 0, + kShaderVecLight1Diffuse, + kShaderVecLight2Diffuse, + kShaderVecLight3Diffuse, + kShaderVecLight4Diffuse, + kShaderVecLight5Diffuse, + kShaderVecLight6Diffuse, + kShaderVecLight7Diffuse, + kShaderVecLight0Position, + kShaderVecLight1Position, + kShaderVecLight2Position, + kShaderVecLight3Position, + kShaderVecLight4Position, + kShaderVecLight5Position, + kShaderVecLight6Position, + kShaderVecLight7Position, + kShaderVecLight0SpotDirection, + kShaderVecLight1SpotDirection, + kShaderVecLight2SpotDirection, + kShaderVecLight3SpotDirection, + kShaderVecLight4SpotDirection, + kShaderVecLight5SpotDirection, + kShaderVecLight6SpotDirection, + kShaderVecLight7SpotDirection, + kShaderVecLight0Atten, + kShaderVecLight1Atten, + kShaderVecLight2Atten, + kShaderVecLight3Atten, + kShaderVecLight4Atten, + kShaderVecLight5Atten, + kShaderVecLight6Atten, + kShaderVecLight7Atten, + kShaderVecLightModelAmbient, + kShaderVecWorldSpaceLightPos0, + kShaderVecLightColor0, + kShaderVecWorldSpaceCameraPos, + kShaderVecProjectionParams, + kShaderVecScreenParams, + kShaderVecZBufferParams, + kShaderVecLightPositionRange, + kShaderVecUnityAmbient, //@TODO: kill it; replace all uses with LightModelAmbient + kShaderVecLightmapFade, + kShaderVecShadowOffset0, + kShaderVecShadowOffset1, + kShaderVecShadowOffset2, + kShaderVecShadowOffset3, + kShaderVecLightShadowData, + kShaderVecLightShadowBias, + kShaderVecLightSplitsNear, + kShaderVecLightSplitsFar, + kShaderVecShadowSplitSpheres0, + kShaderVecShadowSplitSpheres1, + kShaderVecShadowSplitSpheres2, + kShaderVecShadowSplitSpheres3, + kShaderVecShadowSplitSqRadii, + kShaderVecShadowFadeCenterAndType, + kShaderVecSHAr, + kShaderVecSHAg, + kShaderVecSHAb, + kShaderVecSHBr, + kShaderVecSHBg, + kShaderVecSHBb, + kShaderVecSHC, + kShaderVecTime, + kShaderVecSinTime, + kShaderVecCosTime, + kShaderVecPiTime, + kShaderVecDeltaTime, + kShaderVecVertexLightPosX0, + kShaderVecVertexLightPosY0, + kShaderVecVertexLightPosZ0, + kShaderVecVertexLightAtten0, + kShaderVecUnityLightmapST, + kShaderVecUnityFogStart, + kShaderVecUnityFogEnd, + kShaderVecUnityFogDensity, + kShaderVecUnityFogColor, + kShaderVecColorSpaceGrey, + kShaderVecNPOTScale, + kShaderVecCameraWorldClipPlanes0, + kShaderVecCameraWorldClipPlanes1, + kShaderVecCameraWorldClipPlanes2, + kShaderVecCameraWorldClipPlanes3, + kShaderVecCameraWorldClipPlanes4, + kShaderVecCameraWorldClipPlanes5, + + // common textures texel size + kShaderVecWhiteTexelSize, + kShaderVecBlackTexelSize, + kShaderVecRedTexelSize, + kShaderVecGrayTexelSize, + kShaderVecGreyTexelSize, + kShaderVecGrayscaleRampTexelSize, + kShaderVecGreyscaleRampTexelSize, + kShaderVecBumpTexelSize, + kShaderVecLightmapTexelSize, + kShaderVecUnityLightmapTexelSize, + kShaderVecUnityLightmapIndTexelSize, + kShaderVecUnityLightmapThirdTexelSize, + kShaderVecLightTextureB0TexelSize, + kShaderVecGUIClipTexelSize, + kShaderVecDitherMaskLODSize, + kShaderVecRandomRotationTexelSize, + + +#if GFX_HIGH_LEVEL_FF + kShaderVecFFColor, + kShaderVecFFTextureEnvColor0, + kShaderVecFFTextureEnvColor1, + kShaderVecFFTextureEnvColor2, + kShaderVecFFTextureEnvColor3, + kShaderVecFFTextureEnvColor4, + kShaderVecFFTextureEnvColor5, + kShaderVecFFTextureEnvColor6, + kShaderVecFFTextureEnvColor7, + kShaderVecFFMatEmission, + kShaderVecFFMatAmbient, + kShaderVecFFMatDiffuse, + kShaderVecFFMatSpecular, + kShaderVecFFMatShininess, + kShaderVecFFAlphaTestRef, + kShaderVecFFFogColor, + kShaderVecFFFogParams, +#endif + + kShaderVecCount +}; + +enum BuiltinShaderTexEnvParam { + kShaderTexEnvWhite = 0, + kShaderTexEnvBlack, + kShaderTexEnvRed, + kShaderTexEnvGray, + kShaderTexEnvGrey, // TODO: synonims + kShaderTexEnvGrayscaleRamp, + kShaderTexEnvGreyscaleRamp, // TODO: synonims + kShaderTexEnvBump, + kShaderTexEnvLightmap, + kShaderTexEnvUnityLightmap, + kShaderTexEnvUnityLightmapInd, + kShaderTexEnvUnityLightmapThird, + kShaderTexEnvDitherMaskLOD, + kShaderTexEnvRandomRotation, + + kShaderTexEnvCount +}; + + + +#define BUILTIN_SHADER_PARAMS_INSTANCE_MATRICES \ + "glstate_matrix_mvp", \ + "glstate_matrix_modelview0", \ + "_Object2World", \ + "_World2Object", \ + "glstate_matrix_transpose_modelview0", \ + "glstate_matrix_invtrans_modelview0", \ + "glstate_matrix_texture0", \ + "glstate_matrix_texture1", \ + "glstate_matrix_texture2", \ + "glstate_matrix_texture3", \ + "glstate_matrix_texture4", \ + "glstate_matrix_texture5", \ + "glstate_matrix_texture6", \ + "glstate_matrix_texture7" \ + +#define BUILTIN_SHADER_PARAMS_INSTANCE_VECTORS \ + "unity_Scale" \ + + +#define BUILTIN_SHADER_PARAMS_MATRICES \ + "unity_MatrixV", \ + "glstate_matrix_projection", \ + "unity_MatrixVP", \ + "_WorldToCamera", \ + "_CameraToWorld", \ + "_World2Shadow", \ + "_World2Shadow1", \ + "_World2Shadow2", \ + "_World2Shadow3", \ + "unity_LightmapMatrix", \ + "_Projector", \ + "_ProjectorDistance", \ + "_ProjectorClip", \ + "_GUIClipTextureMatrix", \ + "_LightMatrix0" \ + + +#define BUILTIN_SHADER_PARAMS_VECTORS \ + "unity_LightColor0", \ + "unity_LightColor1", \ + "unity_LightColor2", \ + "unity_LightColor3", \ + "unity_LightColor4", \ + "unity_LightColor5", \ + "unity_LightColor6", \ + "unity_LightColor7", \ + "unity_LightPosition0", \ + "unity_LightPosition1", \ + "unity_LightPosition2", \ + "unity_LightPosition3", \ + "unity_LightPosition4", \ + "unity_LightPosition5", \ + "unity_LightPosition6", \ + "unity_LightPosition7", \ + "unity_SpotDirection0", \ + "unity_SpotDirection1", \ + "unity_SpotDirection2", \ + "unity_SpotDirection3", \ + "unity_SpotDirection4", \ + "unity_SpotDirection5", \ + "unity_SpotDirection6", \ + "unity_SpotDirection7", \ + "unity_LightAtten0", \ + "unity_LightAtten1", \ + "unity_LightAtten2", \ + "unity_LightAtten3", \ + "unity_LightAtten4", \ + "unity_LightAtten5", \ + "unity_LightAtten6", \ + "unity_LightAtten7", \ + "glstate_lightmodel_ambient", \ + "_WorldSpaceLightPos0", \ + "_LightColor0", \ + "_WorldSpaceCameraPos", \ + "_ProjectionParams", \ + "_ScreenParams", \ + "_ZBufferParams", \ + "_LightPositionRange", \ + "unity_Ambient", \ + "unity_LightmapFade", \ + "_ShadowOffsets0", \ + "_ShadowOffsets1", \ + "_ShadowOffsets2", \ + "_ShadowOffsets3", \ + "_LightShadowData", \ + "unity_LightShadowBias", \ + "_LightSplitsNear", \ + "_LightSplitsFar", \ + "unity_ShadowSplitSpheres0", \ + "unity_ShadowSplitSpheres1", \ + "unity_ShadowSplitSpheres2", \ + "unity_ShadowSplitSpheres3", \ + "unity_ShadowSplitSqRadii", \ + "unity_ShadowFadeCenterAndType", \ + "unity_SHAr", \ + "unity_SHAg", \ + "unity_SHAb", \ + "unity_SHBr", \ + "unity_SHBg", \ + "unity_SHBb", \ + "unity_SHC", \ + "_Time", \ + "_SinTime", \ + "_CosTime", \ + "_PiTime", \ + "unity_DeltaTime", \ + "unity_4LightPosX0", \ + "unity_4LightPosY0", \ + "unity_4LightPosZ0", \ + "unity_4LightAtten0", \ + "unity_LightmapST", \ + "unity_FogStart", \ + "unity_FogEnd", \ + "unity_FogDensity", \ + "unity_FogColor", \ + "unity_ColorSpaceGrey", \ + "unity_NPOTScale", \ + "unity_CameraWorldClipPlanes0", \ + "unity_CameraWorldClipPlanes1", \ + "unity_CameraWorldClipPlanes2", \ + "unity_CameraWorldClipPlanes3", \ + "unity_CameraWorldClipPlanes4", \ + "unity_CameraWorldClipPlanes5", \ + \ + "white_TexelSize", \ + "black_TexelSize", \ + "red_TexelSize", \ + "gray_TexelSize", \ + "grey_TexelSize", \ + "grayscaleRamp_TexelSize", \ + "greyscaleRamp_TexelSize", \ + "bump_TexelSize", \ + "lightmap_TexelSize", \ + "unity_Lightmap_TexelSize", \ + "unity_LightmapInd_TexelSize", \ + "unity_LightmapThird_TexelSize", \ + "_LightTextureB0_TexelSize", \ + "_GUIClipTexture_TexelSize", \ + "_DitherMaskLOD_TexelSize", \ + "unity_RandomRotation16_TexelSize" + +#define BUILTIN_SHADER_PARAMS_VECTORS_SYNONYMS \ + /* aliases for unity_LightColorN */ \ + "glstate_light0_diffuse", \ + "glstate_light1_diffuse", \ + "glstate_light2_diffuse", \ + "glstate_light3_diffuse", \ + /* aliases for unity_LightPositionN */ \ + "glstate_light0_position", \ + "glstate_light1_position", \ + "glstate_light2_position", \ + "glstate_light3_position", \ + /* aliases for unity_LightAttenN */ \ + "glstate_light0_attenuation", \ + "glstate_light1_attenuation", \ + "glstate_light2_attenuation", \ + "glstate_light3_attenuation", \ + /* aliases for unity_SpotDirectionN */ \ + "glstate_light0_spotDirection", \ + "glstate_light1_spotDirection", \ + "glstate_light2_spotDirection", \ + "glstate_light3_spotDirection" + + + + +#define BUILTIN_SHADER_PARAMS_TEXENVS \ + "white", \ + "black", \ + "red", \ + "gray", \ + "grey", \ + "grayscaleRamp", \ + "greyscaleRamp", \ + "bump", \ + "lightmap", \ + "unity_Lightmap", \ + "unity_LightmapInd", \ + "unity_LightmapThird", \ + "_DitherMaskLOD", \ + "unity_RandomRotation16" + + + +#if GFX_HIGH_LEVEL_FF + +#define BUILTIN_SHADER_PARAMS_INSTANCE_MATRICES_FF \ + "_glesNormalMatrix" \ + + +#define BUILTIN_SHADER_PARAMS_VECTORS_FF \ + "_glesFFColor", \ + "_glesTextureEnvColor0", \ + "_glesTextureEnvColor1", \ + "_glesTextureEnvColor2", \ + "_glesTextureEnvColor3", \ + "_glesTextureEnvColor4", \ + "_glesTextureEnvColor5", \ + "_glesTextureEnvColor6", \ + "_glesTextureEnvColor7", \ + "_glesFrontMaterial.emission", \ + "_glesFrontMaterial.ambient", \ + "_glesFrontMaterial.diffuse", \ + "_glesFrontMaterial.specular", \ + "_glesFrontMaterial.shininess", \ + "_glesAlphaTestReference", \ + "_glesFogColor", \ + "_glesFogParams" \ + +#endif + diff --git a/Runtime/GfxDevice/ChannelAssigns.cpp b/Runtime/GfxDevice/ChannelAssigns.cpp new file mode 100644 index 0000000..59ec758 --- /dev/null +++ b/Runtime/GfxDevice/ChannelAssigns.cpp @@ -0,0 +1,225 @@ +#include "UnityPrefix.h" +#include "ChannelAssigns.h" +//#include "ShaderLabErrors.h" + +// Channel names (strings for reading from ShaderLab) +static const char * const kShaderChannelName[kShaderChannelCount] = { + "VERTEX", + "NORMAL", + "COLOR", + "TEXCOORD", + "TEXCOORD1", + "TANGENT", +}; + + +ShaderChannel GetShaderChannelFromName( const std::string& name ) +{ + std::string nameUpper = ToUpper(name); + for( int i = 0; i < kShaderChannelCount; ++i ) + if( kShaderChannelName[i] == nameUpper ) + return (ShaderChannel)i; + + return kShaderChannelNone; +} + + + +ChannelAssigns::ChannelAssigns() +: m_TargetMap(0) +, m_SourceMap(0) +, m_DirectlyWired(true) +{ + for( int i = 0; i < kVertexCompCount; ++i ) + m_Channels[i] = kShaderChannelNone; +} + +void ChannelAssigns::MergeWith( const ChannelAssigns& additional ) +{ + for( int i = 0; i < kVertexCompCount; ++i ) + { + ShaderChannel source = additional.GetSourceForTarget(VertexComponent(i)); + if( source != kShaderChannelNone ) + Bind( source, (VertexComponent)i ); + } +} + +static bool IsChannelDirectlyWired (ShaderChannel source, VertexComponent target) +{ + switch (source) + { + case kShaderChannelVertex: + return (target == kVertexCompVertex); + case kShaderChannelNormal: + return (target == kVertexCompNormal); + case kShaderChannelColor: + return (target == kVertexCompColor); + case kShaderChannelTexCoord0: + return (target == kVertexCompTexCoord0); + case kShaderChannelTexCoord1: + return (target == kVertexCompTexCoord1); + case kShaderChannelTangent: + return (target == kVertexCompTexCoord2); + default: + break; + } + return false; +} + +void ChannelAssigns::Bind (ShaderChannel source, VertexComponent target) +{ + AssertIf( source == kShaderChannelNone ); + // TODO: skip kShaderChannelTexCoord ones here? + // TODO: filter duplicates somehow? + m_Channels[target] = source; + m_TargetMap |= (1<<target); + m_SourceMap |= (1<<source); + + if (m_DirectlyWired) + m_DirectlyWired = IsChannelDirectlyWired (source, target); +} + +void ChannelAssigns::Unbind( VertexComponent target ) +{ + m_TargetMap &= ~(1<<target); + m_Channels[target] = kShaderChannelNone; + + RecalculateIsDirectlyWired (); +} + +void ChannelAssigns::RecalculateIsDirectlyWired () +{ + m_DirectlyWired = true; + for (int i = 0; i < kVertexCompCount && m_DirectlyWired; ++i) + { + ShaderChannel source = GetSourceForTarget(VertexComponent(i)); + if( source != kShaderChannelNone ) + m_DirectlyWired &= IsChannelDirectlyWired (source, (VertexComponent)i); + } +} + +bool ChannelAssigns::operator== (const ChannelAssigns& other) const +{ + return m_SourceMap == other.m_SourceMap && + m_TargetMap == other.m_TargetMap && + memcmp(&m_Channels[0], &other.m_Channels[0], sizeof(m_Channels)) == 0; +} + + +#if ENABLE_UNIT_TESTS +#include "External/UnitTest++/src/UnitTest++.h" +#include "External/shaderlab/Library/SLParserData.h" +SUITE (ChanelAssignsTest) +{ +TEST(IsDirectlyWired) +{ + ChannelAssigns ch; + // usual binding + ch.Bind(kShaderChannelVertex, kVertexCompVertex); + CHECK(ch.IsDirectlyWired()); + ch.Bind(kShaderChannelNormal, kVertexCompNormal); + CHECK(ch.IsDirectlyWired()); + ch.Bind(kShaderChannelColor, kVertexCompColor); + CHECK(ch.IsDirectlyWired()); + ch.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord0); + CHECK(ch.IsDirectlyWired()); + ch.Bind(kShaderChannelTexCoord1, kVertexCompTexCoord1); + CHECK(ch.IsDirectlyWired()); + ch.Bind(kShaderChannelTangent, kVertexCompTexCoord2); + CHECK(ch.IsDirectlyWired()); + + // bind twice + ch.Bind(kShaderChannelVertex, kVertexCompVertex); + ch.Bind(kShaderChannelNormal, kVertexCompNormal); + ch.Bind(kShaderChannelColor, kVertexCompColor); + ch.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord0); + ch.Bind(kShaderChannelTexCoord1, kVertexCompTexCoord1); + ch.Bind(kShaderChannelTangent, kVertexCompTexCoord2); + CHECK(ch.IsDirectlyWired()); + + // cross-bar + ch.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord2); + CHECK(!ch.IsDirectlyWired()); + + // unbinding cross-bar + ch.Unbind(kVertexCompTexCoord2); + CHECK(ch.IsDirectlyWired()); + + // rebinding + ch.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord0); + ch.Bind(kShaderChannelTexCoord1, kVertexCompTexCoord1); + ch.Bind(kShaderChannelTangent, kVertexCompTexCoord2); + CHECK(ch.IsDirectlyWired()); + + // cross-bar 2 + ChannelAssigns ch2 = ch; + ch2.Bind(kShaderChannelVertex, kVertexCompNormal); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelNormal, kVertexCompColor); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelColor, kVertexCompTexCoord0); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord2); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelTexCoord1, kVertexCompVertex); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelTangent, kVertexCompAttrib0); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord1); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord2); + CHECK(!ch2.IsDirectlyWired()); + ch2 = ch; + ch2.Bind(kShaderChannelTexCoord0, kVertexCompColor); + CHECK(!ch2.IsDirectlyWired()); + + // unbinding all + ch.Unbind(kVertexCompVertex); + ch.Unbind(kVertexCompNormal); + ch.Unbind(kVertexCompColor); + ch.Unbind(kVertexCompTexCoord0); + ch.Unbind(kVertexCompTexCoord1); + ch.Unbind(kVertexCompTexCoord2); + CHECK(ch.IsDirectlyWired()); + + // check empty/1channel + ch.Bind(kShaderChannelVertex, kVertexCompTexCoord0); + CHECK(!ch.IsDirectlyWired()); + + ch.Unbind(kVertexCompTexCoord0); + CHECK(ch.IsDirectlyWired()); + CHECK(ch.IsEmpty()); + + ch.Bind(kShaderChannelVertex, kVertexCompVertex); + CHECK(ch.IsDirectlyWired()); +} +TEST(IsDirectlyWiredXBar) +{ + ChannelAssigns ch; + // usual binding + ch.Bind(kShaderChannelVertex, kVertexCompVertex); + ch.Bind(kShaderChannelNormal, kVertexCompNormal); + CHECK(ch.IsDirectlyWired()); + ch.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord1); + ch.Bind(kShaderChannelTexCoord1, kVertexCompTexCoord0); + CHECK(!ch.IsDirectlyWired()); +} +TEST(IsDirectlyWiredUpdatedWhenCreatingFromParserChannels) +{ + ShaderLab::ParserBindChannels pchn; + pchn.Bind(kShaderChannelTexCoord0, kVertexCompTexCoord1, false, NULL); + pchn.Bind(kShaderChannelTexCoord1, kVertexCompTexCoord0, false, NULL); + ChannelAssigns ch; + ch.FromParsedChannels (pchn); + CHECK(!ch.IsDirectlyWired()); +} +} + +#endif diff --git a/Runtime/GfxDevice/ChannelAssigns.h b/Runtime/GfxDevice/ChannelAssigns.h new file mode 100644 index 0000000..fafb4d5 --- /dev/null +++ b/Runtime/GfxDevice/ChannelAssigns.h @@ -0,0 +1,52 @@ +#ifndef __CHANNELASSIGNS_H__ +#define __CHANNELASSIGNS_H__ + +#include <string> +#include "GfxDeviceTypes.h" + +namespace ShaderLab { +struct ParserBindChannels; +} + +// Tracks which vertex components should be sourced from which shader channels +// TODO: It gets serialized a lot for multithreading, can we make it more compact? +class ChannelAssigns { +public: + ChannelAssigns(); + void FromParsedChannels (const ShaderLab::ParserBindChannels& parsed); // ShaderParser.cpp + + void Bind( ShaderChannel source, VertexComponent target ); + void Unbind( VertexComponent target ); + void MergeWith( const ChannelAssigns& additional ); + + UInt32 GetTargetMap() const { return m_TargetMap; } + UInt32 GetSourceMap() const { return m_SourceMap; } + bool IsEmpty() const { return m_TargetMap == 0; } + + // if and only if all source channels directly map to target components + // src.Vertex -> dst.Vertex, src.Normal -> dst.Normal, etc + // there is NO cross-bar connections like: src.TexCoord0 -> dst.TexCoord1 + bool IsDirectlyWired() const { return m_DirectlyWired; } + + ShaderChannel GetSourceForTarget( VertexComponent target ) const { return ShaderChannel(m_Channels[target]); } + + bool operator== (const ChannelAssigns& other) const; + +private: + void RecalculateIsDirectlyWired (); + +private: + UInt32 m_TargetMap; // bitfield of which vertex components are sourced + UInt32 m_SourceMap; // bitfield of which source channels are used + SInt8 m_Channels[kVertexCompCount]; // for each vertex component: from which channel it is sourced + bool m_DirectlyWired; + + // Friends for serialization + friend struct GfxRet_ChannelAssigns; +}; + + +ShaderChannel GetShaderChannelFromName( const std::string& name ); + + +#endif diff --git a/Runtime/GfxDevice/GLDataBufferCommon.h b/Runtime/GfxDevice/GLDataBufferCommon.h new file mode 100644 index 0000000..7e7a9b9 --- /dev/null +++ b/Runtime/GfxDevice/GLDataBufferCommon.h @@ -0,0 +1,24 @@ +#ifndef GL_DATABUFFER_COMMON_H +#define GL_DATABUFFER_COMMON_H + +#if GFX_SUPPORTS_OPENGL || GFX_SUPPORTS_OPENGLES || GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30 + +#define DATA_BUFFER_ID_MASK 0xC0000000 +#define MAKE_DATA_BUFFER_ID(id) (id|DATA_BUFFER_ID_MASK) + +inline void glRegisterBufferData(UInt32 bufferID, GLsizeiptr size, void* related) +{ + REGISTER_EXTERNAL_GFX_DEALLOCATION(MAKE_DATA_BUFFER_ID(bufferID) ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(MAKE_DATA_BUFFER_ID(bufferID),size,related); +} + +inline void glDeregisterBufferData(int count, GLuint* buffferIds) +{ + for (size_t q = 0; q < count; ++q) + REGISTER_EXTERNAL_GFX_DEALLOCATION(MAKE_DATA_BUFFER_ID(buffferIds[q]) ); +} + +#endif + +#endif // GL_DATABUFFER_COMMON_H + diff --git a/Runtime/GfxDevice/GLESChannels.h b/Runtime/GfxDevice/GLESChannels.h new file mode 100644 index 0000000..9a683e7 --- /dev/null +++ b/Runtime/GfxDevice/GLESChannels.h @@ -0,0 +1,84 @@ +#ifndef GLES_CHANNELS_H +#define GLES_CHANNELS_H + +#if GFX_SUPPORTS_OPENGLES20 + #include "Runtime/GfxDevice/opengles20/UnityGLES20Ext.h" +#endif + +// dimensionality of the different channels (element count) +static const int kDefaultChannelSizes[kShaderChannelCount] = { + 3, // pos + 3, // normal + 4, // color + 2, // uv + 2, // uv2 + 4, // tangent +}; + +static const GLenum kDefaultChannelTypes[kShaderChannelCount] = { + GL_FLOAT, // pos + GL_FLOAT, // normal + GL_UNSIGNED_BYTE, // color + GL_FLOAT, // UV0 + GL_FLOAT, // UV1 + GL_FLOAT, // tangent +}; + +enum VertexChannel { + kVtxChnVertex = 1 << kVertexCompVertex, + kVtxChnColor = 1 << kVertexCompColor, + kVtxChnNormal = 1 << kVertexCompNormal, + kVtxChnTexCoord0 = 1 << kVertexCompTexCoord0, + kVtxChnTexCoord1 = 1 << kVertexCompTexCoord1, + kVtxChnTexCoord2 = 1 << kVertexCompTexCoord2, + kVtxChnTexCoord3 = 1 << kVertexCompTexCoord3, + kVtxChnTexCoord4 = 1 << kVertexCompTexCoord4, + kVtxChnTexCoord5 = 1 << kVertexCompTexCoord5, + kVtxChnTexCoord6 = 1 << kVertexCompTexCoord6, + kVtxChnTexCoord7 = 1 << kVertexCompTexCoord7 +}; + +static const VertexChannel sTexCoordChannels[] = { + kVtxChnTexCoord0, kVtxChnTexCoord1, kVtxChnTexCoord2, kVtxChnTexCoord3, + kVtxChnTexCoord4, kVtxChnTexCoord5, kVtxChnTexCoord6, kVtxChnTexCoord7 +}; + +static void SetupGLESChannelSizes(const ChannelInfoArray channels, int outSizes[kShaderChannelCount]) +{ + for (int i = 0; i < kShaderChannelCount; i++) + { + if (channels[i].format == kChannelFormatColor) + outSizes[i] = 4; + else + outSizes[i] = channels[i].dimension; + } +} + +static void SetupGLESChannelTypes(const ChannelInfoArray channels, GLenum outTypes[kShaderChannelCount]) +{ + for (int i = 0; i < kShaderChannelCount; i++) + { + switch (channels[i].format) + { + case kChannelFormatFloat: + outTypes[i] = GL_FLOAT; + break; +#if GFX_SUPPORTS_OPENGLES20 + case kChannelFormatFloat16: + outTypes[i] = GL_HALF_FLOAT_OES; + break; +#endif + case kChannelFormatColor: + outTypes[i] = GL_UNSIGNED_BYTE; + break; + case kChannelFormatByte: + outTypes[i] = GL_BYTE; + break; + default: + if (channels[i].IsValid()) + ErrorString("Vertex channel has invalid type for GLES"); + } + } +} + +#endif diff --git a/Runtime/GfxDevice/GLESCommon.h b/Runtime/GfxDevice/GLESCommon.h new file mode 100644 index 0000000..9d1ffee --- /dev/null +++ b/Runtime/GfxDevice/GLESCommon.h @@ -0,0 +1,105 @@ +#ifndef GLES_COMMON_H +#define GLES_COMMON_H + +// internal header +// common gles 1.x/2.x stuff +// also some common android/ios stuff + +#include <ctype.h> + +inline int GLES_EstimateVRAM_MB(int total_mem_mb) +{ +#if UNITY_IPHONE + // For iOS we estimate 1/4 of POT(total_mem) + const int physical_mem_mb = 1 << (32 - __builtin_clz(total_mem_mb - 1)); + return physical_mem_mb >> 2; +#elif UNITY_ANDROID || UNITY_BB10 || UNITY_TIZEN + // There is (afawk) no way to determine the size of the VRAM + // So we try to create ('fake') a value that is somewhere along the lines of possibly correct. + // We make two assumption here: + // 1) The VRAM is cut-out from the physical memory range and 2) VRAM size is never bigger than + // a 1/4 of the physical memory size, but still bigger than a 1/16 of the total memory size. + // Even if not correct it should give an indication of how much memory is available for GPU resources. + const int physical_mem_mb = 1 << (32 - __builtin_clz(total_mem_mb - 1)); + return std::max( std::min(physical_mem_mb - total_mem_mb, (physical_mem_mb >> 2)), (total_mem_mb >> 4) ); +#else + return 256; +#endif +} + +namespace systeminfo { int GetPhysicalMemoryMB(); } +struct GraphicsCaps; + +inline void GLES_InitCommonCaps(GraphicsCaps* caps) +{ + { + caps->vendorID = 0; + caps->rendererID = 0; + + #define GRAB_STRING(target, name) \ + do { \ + const char* _tmp_str = (const char*)glGetString(name); \ + GLESAssert(); \ + caps->target = _tmp_str ? _tmp_str : "<unknown>"; \ + } while(0) \ + + GRAB_STRING(rendererString, GL_RENDERER); + GRAB_STRING(vendorString, GL_VENDOR); + GRAB_STRING(driverVersionString, GL_VERSION); + + #undef GRAB_STRING + + // Distill + // driverVersionString = "OpenGL ES 2.0 build 1.8@905891" + // into + // driverLibraryString = "build 1.8@905891" + // + // See http://www.khronos.org/opengles/sdk/1.1/docs/man/glGetString.xml + // + const char OpenGL[] = "OpenGL"; + const char ES[] = "ES"; + const char* gl_version = caps->driverVersionString.c_str(); + for (int i = 0 ; i < 3; ++i, ++gl_version) + { + if( (i == 0 && strncmp(gl_version, OpenGL, sizeof(OpenGL)-1)) + || (i == 1 && strncmp(gl_version, ES, sizeof(ES)-1)) + || (i == 2 && !isdigit(*gl_version)) + ) + { + gl_version = NULL; + break; + } + if ( !(gl_version = strstr(gl_version, " ")) ) + break; + } + + if (gl_version) + caps->driverLibraryString = gl_version; + else + caps->driverLibraryString = "n/a"; + + caps->fixedVersionString = caps->driverVersionString; + + const char* ext = (const char*)glGetString(GL_EXTENSIONS); + GLESAssert(); + + ::printf_console ("Renderer: %s\n", caps->rendererString.c_str()); + ::printf_console ("Vendor: %s\n", caps->vendorString.c_str()); + ::printf_console ("Version: %s\n", caps->driverVersionString.c_str()); + + if(ext) DebugTextLineByLine(ext); + else ::printf_console("glGetString(GL_EXTENSIONS) - failure"); + } + + { + #if UNITY_ANDROID || UNITY_IPHONE || UNITY_BB10 || UNITY_TIZEN + caps->videoMemoryMB = GLES_EstimateVRAM_MB(systeminfo::GetPhysicalMemoryMB()); + #else + caps->videoMemoryMB = 256; // awesome estimation + #endif + } +} + + +#endif // GLES_COMMON_H + diff --git a/Runtime/GfxDevice/GLRTCommon.h b/Runtime/GfxDevice/GLRTCommon.h new file mode 100644 index 0000000..89d0659 --- /dev/null +++ b/Runtime/GfxDevice/GLRTCommon.h @@ -0,0 +1,370 @@ +#ifndef GL_RT_COMMON_H +#define GL_RT_COMMON_H + +// internal header +// common RT-related stuff +// as we might need both gles and gles20 linked we a forced to use external defines here + +#ifndef GL_RT_COMMON_GLES +#define GL_RT_COMMON_GLES 0 +#endif + +#ifndef GL_RT_COMMON_GLES2 +#define GL_RT_COMMON_GLES2 0 +#endif + +#ifndef GL_RT_COMMON_GL +#define GL_RT_COMMON_GL 0 +#endif + +#if GL_RT_COMMON_GLES==0 && GL_RT_COMMON_GLES2==0 && GL_RT_COMMON_GL==0 +#error dont include this header without specifying api used +#endif + + +#if GL_RT_COMMON_GLES +#define CHECK GL_CHK +#define EXT_CALL(f) f##OES +#define EXT_ENUM(x) x##_OES +#define MANGLE_NAME(f) f##GLES +#elif GL_RT_COMMON_GLES2 +#define CHECK GLES_CHK +#define EXT_CALL(f) f +#define EXT_ENUM(x) x +#define MANGLE_NAME(f) f##GLES2 +#elif GL_RT_COMMON_GL +#define CHECK GL_CHK +#define EXT_CALL(f) f##EXT +#define EXT_ENUM(x) x##_EXT +#define MANGLE_NAME(f) f##GL +#endif + + +//============================================================================== +// rt format handling +//============================================================================== + + +inline GLenum MANGLE_NAME(RTColorTextureFormat)(RenderTextureFormat fmt) +{ + switch( fmt ) + { + case kRTFormatARGB32: + case kRTFormatARGB4444: + case kRTFormatARGB1555: + case kRTFormatARGBHalf: + case kRTFormatARGBFloat: +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + return GL_RGBA; +#else + return GL_BGRA; +#endif + + case kRTFormatRGB565: + return GL_RGB; + + case kRTFormatR8: + case kRTFormatRHalf: + case kRTFormatRFloat: +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + return 0x1903; // GL_RED_EXT +#else + return GL_RED; +#endif + + case kRTFormatRGHalf: + case kRTFormatRGFloat: +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + return 0x8227; // GL_RG_EXT +#else + return 0x8227; // GL_RG +#endif + + // int formats are not supported + case kRTFormatARGBInt: + case kRTFormatRInt: + case kRTFormatRGInt: + break; + + default: + break; + } + + Assert( false && "wrong color rt format" ); + return 0; +} + + +inline GLenum MANGLE_NAME(RTColorInternalFormat)(RenderTextureFormat fmt) +{ + switch( fmt ) + { +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + case kRTFormatARGB32: return GL_RGBA; + case kRTFormatARGB4444: return GL_RGBA; + case kRTFormatARGB1555: return GL_RGBA; + case kRTFormatRGB565: return GL_RGB; + case kRTFormatARGBHalf: return GL_RGBA; + case kRTFormatARGBFloat: return GL_RGBA; + case kRTFormatR8: return 0x1903; // GL_RED_EXT + case kRTFormatRHalf: return 0x1903; // GL_RED_EXT + case kRTFormatRFloat: return 0x1903; // GL_RED_EXT + case kRTFormatRGHalf: return 0x8227; // GL_RG_EXT + case kRTFormatRGFloat: return 0x8227; // GL_RG_EXT +#else + case kRTFormatARGB32: return GL_RGBA; + case kRTFormatARGB4444: return GL_RGBA4; + case kRTFormatARGB1555: return GL_RGB5_A1; + case kRTFormatRGB565: return GL_RGB5; + case kRTFormatARGBHalf: return GL_RGBA16F_ARB; + case kRTFormatARGBFloat: return GL_RGBA32F_ARB; + case kRTFormatR8: return 0x8229; // GL_R8 + case kRTFormatRHalf: return 0x822D; // GL_R16F + case kRTFormatRFloat: return 0x822E; // GL_R32F + case kRTFormatRGHalf: return 0x822F; // GL_RG16F + case kRTFormatRGFloat: return 0x8230; // GL_RG32F +#endif + + case kRTFormatARGBInt: break; + case kRTFormatRInt: break; + case kRTFormatRGInt: break; + + default: + break; + } + + Assert( false && "wrong color rt format" ); + return 0; +} + +inline GLenum MANGLE_NAME(RBColorInternalFormat)(RenderTextureFormat fmt) +{ +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + switch( fmt ) + { + case kRTFormatARGB32: return GL_RGBA8_OES; + case kRTFormatRGB565: return EXT_ENUM(GL_RGB565); + default: break; + } + + Assert(false && "wrong color rb format"); + return 0; +#else + return RTColorTextureFormatGL(fmt); +#endif +} + + +inline GLenum MANGLE_NAME(RTColorTextureFormatSRGB)(RenderTextureFormat fmt) +{ +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + switch( fmt ) + { + case kRTFormatARGB32: return 0x8C42; // GL_SRGB_ALPHA_EXT + default: break; + } + return MANGLE_NAME(RTColorTextureFormat)(fmt); +#else + return RTColorTextureFormatGL(fmt); +#endif +} + + +inline GLenum MANGLE_NAME(RTColorInternalFormatSRGB)(RenderTextureFormat fmt) +{ +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + switch( fmt ) + { + case kRTFormatARGB32: return 0x8C42; // GL_SRGB_ALPHA_EXT + default: break; + } + return MANGLE_NAME(RTColorInternalFormat)(fmt); +#else + switch( fmt ) + { + case kRTFormatARGB32: return GL_SRGB8_ALPHA8_EXT; + default: break; + } + return RTColorInternalFormatGL(fmt); +#endif + + Assert( false && "wrong color rt format" ); + return 0; +} + +inline GLenum MANGLE_NAME(RTColorTextureType)(RenderTextureFormat fmt) +{ + switch( fmt ) + { + case kRTFormatARGB32: return GL_UNSIGNED_BYTE; + case kRTFormatARGB4444: return GL_UNSIGNED_SHORT_4_4_4_4; + case kRTFormatARGB1555: return GL_UNSIGNED_SHORT_5_5_5_1; + case kRTFormatRGB565: return GL_UNSIGNED_SHORT_5_6_5; + + case kRTFormatR8: return GL_UNSIGNED_BYTE; + + case kRTFormatARGBHalf: + case kRTFormatRHalf: + case kRTFormatRGHalf: +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + return 0x8D61; // GL_HALF_FLOAT_OES; +#else + return GL_HALF_FLOAT_ARB; +#endif + + case kRTFormatARGBFloat: + case kRTFormatRFloat: + case kRTFormatRGFloat: + return GL_FLOAT; + + case kRTFormatARGBInt: + case kRTFormatRInt: + case kRTFormatRGInt: + break; + + default: + break; + } + + Assert( false && "wrong color rt format" ); + return 0; +} + + +//============================================================================== +// rt format support +//============================================================================== + + +#if GL_RT_COMMON_GLES +#define DEPTH_ENUM GL_DEPTH_COMPONENT16_OES +#elif GL_RT_COMMON_GLES2 +#define DEPTH_ENUM GL_DEPTH_COMPONENT16 +#elif GL_RT_COMMON_GL +#define DEPTH_ENUM GL_DEPTH_COMPONENT +#endif + +struct MANGLE_NAME(FBColorFormatChecker) +{ + GLint oldFB; + GLint oldRB; + + GLuint fb; + GLuint depth; + GLuint color; + + static const int FBExt = 8; + + MANGLE_NAME(FBColorFormatChecker)() + { + #if UNITY_IPHONE + CHECK(glGetIntegerv(EXT_ENUM(GL_FRAMEBUFFER_BINDING), &oldFB)); + CHECK(glGetIntegerv(EXT_ENUM(GL_RENDERBUFFER_BINDING), &oldRB)); + #else + oldFB = oldRB = 0; + #endif + + CHECK(EXT_CALL(glGenFramebuffers)(1, &fb)); + CHECK(EXT_CALL(glBindFramebuffer)(EXT_ENUM(GL_FRAMEBUFFER), fb)); + + CHECK(EXT_CALL(glGenRenderbuffers)(1, &depth)); + CHECK(EXT_CALL(glBindRenderbuffer)(EXT_ENUM(GL_RENDERBUFFER), depth)); + CHECK(EXT_CALL(glRenderbufferStorage)(EXT_ENUM(GL_RENDERBUFFER), DEPTH_ENUM, FBExt, FBExt)); + + CHECK(glGenTextures(1, &color)); + } + + ~MANGLE_NAME(FBColorFormatChecker)() + { + // gives out warning under emu + #if !UNITY_GLES_EMU + CHECK(EXT_CALL(glFramebufferTexture2D)(EXT_ENUM(GL_FRAMEBUFFER), EXT_ENUM(GL_COLOR_ATTACHMENT0), GL_TEXTURE_2D, 0, 0)); + CHECK(EXT_CALL(glFramebufferRenderbuffer)(EXT_ENUM(GL_FRAMEBUFFER), EXT_ENUM(GL_DEPTH_ATTACHMENT), EXT_ENUM(GL_RENDERBUFFER), 0)); + #endif + + CHECK(EXT_CALL(glBindFramebuffer)(EXT_ENUM(GL_FRAMEBUFFER), oldFB)); + CHECK(EXT_CALL(glDeleteFramebuffers)(1, &fb)); + + CHECK(EXT_CALL(glBindRenderbuffer)(EXT_ENUM(GL_RENDERBUFFER), oldRB)); + CHECK(EXT_CALL(glDeleteRenderbuffers)(1, &depth)); + + CHECK(glDeleteTextures(1, &color)); + } + + bool CheckFormatSupported(GLint internalFormat, GLenum format, GLenum type) + { + #if !GL_RT_COMMON_GLES2 + CHECK(glEnable(GL_TEXTURE_2D)); + #endif + CHECK(glBindTexture(GL_TEXTURE_2D, color)); + CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); + CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); + CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); + + #if GL_RT_COMMON_GL + CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); + #endif + + CHECK(glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, FBExt, FBExt, 0, format, type, 0)); + + CHECK(EXT_CALL(glFramebufferTexture2D)(EXT_ENUM(GL_FRAMEBUFFER), EXT_ENUM(GL_COLOR_ATTACHMENT0), GL_TEXTURE_2D, color, 0)); + CHECK(EXT_CALL(glFramebufferRenderbuffer)(EXT_ENUM(GL_FRAMEBUFFER), EXT_ENUM(GL_DEPTH_ATTACHMENT), EXT_ENUM(GL_RENDERBUFFER), depth)); + + GLenum status = EXT_CALL(glCheckFramebufferStatus)(EXT_ENUM(GL_FRAMEBUFFER)); + + CHECK(glBindTexture(GL_TEXTURE_2D, 0)); + + return (status == EXT_ENUM(GL_FRAMEBUFFER_COMPLETE)); + } +}; + + +//============================================================================== +// fb/rt format query +//============================================================================== + +// for now +#if GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + +inline RenderTextureFormat MANGLE_NAME(QueryFBColorFormat)() +{ + GLint rbits=0, gbits=0, bbits=0, abits=0; + CHECK(glGetIntegerv(GL_RED_BITS, &rbits)); + CHECK(glGetIntegerv(GL_GREEN_BITS, &gbits)); + CHECK(glGetIntegerv(GL_BLUE_BITS, &bbits)); + CHECK(glGetIntegerv(GL_ALPHA_BITS, &abits)); + + if(rbits==8 && gbits==8 && bbits==8 && abits==8) + return kRTFormatARGB32; + else if(rbits==4 && gbits==4 && bbits==4 && abits==4) + return kRTFormatARGB4444; + else if(rbits==5 && gbits==5 && bbits==5 && abits==1) + return kRTFormatARGB1555; + else if(rbits==5 && gbits==6 && bbits==5 && abits==0) + return kRTFormatRGB565; + +#if UNITY_ANDROID + //we can end up with 32bits without alpha + if(rbits==8 && gbits==8 && bbits==8) + return kRTFormatARGB32; +#endif + + return kRTFormatARGB32; +} + +inline DepthBufferFormat MANGLE_NAME(QueryFBDepthFormat)() +{ + GLint dbits=0; + CHECK(glGetIntegerv(GL_DEPTH_BITS, &dbits)); + + if(dbits == 0) + return kDepthFormatNone; + + return dbits == 16 ? kDepthFormat16 : kDepthFormat24; +} + +#endif // GL_RT_COMMON_GLES || GL_RT_COMMON_GLES2 + +#endif // GL_RT_COMMON_H + diff --git a/Runtime/GfxDevice/GPUSkinningInfo.h b/Runtime/GfxDevice/GPUSkinningInfo.h new file mode 100644 index 0000000..7f32a0c --- /dev/null +++ b/Runtime/GfxDevice/GPUSkinningInfo.h @@ -0,0 +1,61 @@ +#ifndef __GPUSKINNINGINFO_H__ +#define __GPUSKINNINGINFO_H__ + +class VBO; +class ThreadedStreamBuffer; +class Matrix4x4f; +struct BoneInfluence; + +/** +* Abstract class for GPU skinning, implemented in each GfxDevice +*/ +class GPUSkinningInfo +{ +protected: + //! Number of vertices in the skin + UInt32 m_VertexCount; + //! Channel map for the VBO + UInt32 m_ChannelMap; + //! Destination VBO stride + int m_Stride; + + //! Destination VBO + VBO *m_DestVBO; + + //! Bones per vertex, must be 1, 2 or 4 + UInt32 m_BonesPerVertex; + + // Protected constructor and destructor, can only be created and deleted from GfxDevice impl. + // For threading purposes, constructor should not perform any GL operations (called directly from main thread). + GPUSkinningInfo() : m_VertexCount(0), m_ChannelMap(0), m_Stride(0), m_DestVBO(NULL), m_BonesPerVertex(4) {} + virtual ~GPUSkinningInfo() {}; + +public: + virtual UInt32 GetVertexCount() const { return m_VertexCount; } + virtual UInt32 GetChannelMap() const { return m_ChannelMap; } + virtual int GetStride() const { return m_Stride; } + virtual VBO * GetDestVBO() const { return m_DestVBO; } + virtual UInt32 GetBonesPerVertex() const { return m_BonesPerVertex; } + + /** Update vertex count */ + virtual void SetVertexCount(UInt32 count) { m_VertexCount = count; } + + /** Update channel map */ + virtual void SetChannelMap(UInt32 channelmap) { m_ChannelMap = channelmap; } + + /** Update stride of the vertices in bytes (not including skin data). */ + virtual void SetStride(int stride) { m_Stride = stride; } + + /** Update destination VBO */ + virtual void SetDestVBO(VBO *vbo) { m_DestVBO = vbo; } + + /** Update bones-per-vertex */ + virtual void SetBonesPerVertex(UInt32 bones) { m_BonesPerVertex = bones; } + +}; + + + + + +#endif diff --git a/Runtime/GfxDevice/GfxDevice.cpp b/Runtime/GfxDevice/GfxDevice.cpp new file mode 100644 index 0000000..a1837df --- /dev/null +++ b/Runtime/GfxDevice/GfxDevice.cpp @@ -0,0 +1,926 @@ +#include "UnityPrefix.h" +#include "GfxDevice.h" +#include "Runtime/Utilities/HashFunctions.h" +#include "Runtime/Filters/Mesh/MeshSkinning.h" +#include "Runtime/Camera/CameraUtil.h" +#include "Runtime/Dynamics/PhysicsManager.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Graphics/RenderSurface.h" +#include "Runtime/Shaders/Shader.h" +#include "Runtime/Shaders/VBO.h" +#include "Runtime/Threads/AtomicOps.h" +#include "Runtime/Threads/Thread.h" +#include "Runtime/Misc/Plugins.h" +#include "Runtime/Profiler/Profiler.h" +#include "ChannelAssigns.h" +#include "BatchRendering.h" +#include "GpuProgram.h" +#include "Runtime/Geometry/BoundingUtils.h" + +#if ENABLE_TEXTUREID_MAP + #include "TextureIdMap.h" +#endif + +#if ENABLE_SPRITES + #include "Runtime/Graphics/SpriteFrame.h" +#endif + +class VBOList +{ +public: + List<VBO> m_List; +}; + +static GfxDevice* gfxDevice = NULL; + +#if ENABLE_MULTITHREADED_CODE +static GfxDevice* realGfxDevice = NULL; +static Thread::ThreadID realGfxDeviceThreadId; +static GfxThreadingMode gfxThreadingMode = kGfxThreadingModeDirect; +#endif + +void ApplyTexEnvData (unsigned int texUnit, unsigned int samplerUnit, const TexEnvData& data) +{ + GfxDevice& device = GetRealGfxDevice(); + + device.SetTexture (kShaderFragment, texUnit, samplerUnit, data.textureID, static_cast<TextureDimension>(data.texDim), data.mipBias); + // Only setup texture matrix & transform for texture units that fit into supported + // coordinate count. Shaders can use more textures, + // but then they can't have T&L matrices nor fixed function texgen. + if (texUnit < kMaxSupportedTextureCoords) + { + device.SetTextureTransform (texUnit, static_cast<TextureDimension>(data.texDim), static_cast<TexGenMode>(data.texGen), data.identityMatrix, data.matrix.GetPtr()); + } +} + +void ClearStaticBatchIndices(); + +bool IsGfxDevice() +{ + return gfxDevice != NULL; +} + +GfxDevice& GetGfxDevice() +{ + Assert( gfxDevice ); +#if ENABLE_MULTITHREADED_CODE + DebugAssert(realGfxDevice == NULL || Thread::CurrentThreadIsMainThread()); +#endif + return *gfxDevice; +} + +GfxDevice& GetUncheckedGfxDevice() +{ + return *gfxDevice; +} + +void SetGfxDevice(GfxDevice* device) +{ + gfxDevice = device; +} + +void DestroyGfxDevice() +{ + if (gfxDevice) + { + UNITY_DELETE(gfxDevice, kMemGfxDevice); + gfxDevice = NULL; + } +} + +GfxDevice& GetRealGfxDevice() +{ +#if ENABLE_MULTITHREADED_CODE + if (realGfxDevice) + { + DebugAssert(Thread::EqualsCurrentThreadIDForAssert(realGfxDeviceThreadId)); + return *realGfxDevice; + } +#endif + return *gfxDevice; +} + +bool IsRealGfxDeviceThreadOwner() +{ +#if ENABLE_MULTITHREADED_CODE + if (realGfxDevice) + return Thread::EqualsCurrentThreadIDForAssert(realGfxDeviceThreadId); +#endif + return true; +} + +#if ENABLE_MULTITHREADED_CODE +void SetRealGfxDevice(GfxDevice* device) +{ + Assert( !realGfxDevice ); + realGfxDevice = device; + SetRealGfxDeviceThreadOwnership(); +} + +void SetRealGfxDeviceThreadOwnership() +{ + realGfxDeviceThreadId = Thread::GetCurrentThreadID(); +} + +void DestroyRealGfxDevice() +{ + if (realGfxDevice) + { + UNITY_DELETE(realGfxDevice, kMemGfxThread); + realGfxDevice = NULL; + } +} + +void SetGfxThreadingMode(GfxThreadingMode mode) +{ + gfxThreadingMode = mode; +} + +GfxThreadingMode GetGfxThreadingMode() +{ + return gfxThreadingMode; +} +#endif + +#if GFX_DEVICE_VIRTUAL +GfxDevice::GfxDevice() +{ + OnCreate(); +} + +GfxDevice::~GfxDevice() +{ + OnDelete(); +} +#endif + +void GfxDevice::OnCreate() +{ + m_Stats.ResetFrame(); + m_SavedStats.ResetFrame(); + m_ActiveRenderTexture = NULL; + m_InsideFrame = false; + m_IsRecording = false; + m_IsThreadable = false; + m_FramebufferDepthFormat = kDepthFormatNone; + for (int i = 0; i < kShaderTypeCount; ++i) + m_BuiltinParamIndices[i] = &m_NullParamIndices; + m_VBOList = new VBOList; + +#if ENABLE_TEXTUREID_MAP + TextureIdMap::Initialize(); +#endif +} + +void GfxDevice::OnDelete() +{ + delete m_VBOList; + +#if ENABLE_TEXTUREID_MAP + TextureIdMap::Uninitialize(); +#endif + + ClearStaticBatchIndices(); +} + +void GfxDevice::OnCreateVBO(VBO* vbo) +{ + SET_ALLOC_OWNER(this); + m_VBOList->m_List.push_back(*vbo); +} + +void GfxDevice::OnDeleteVBO(VBO* vbo) +{ + m_VBOList->m_List.erase(vbo); +} + +int GfxDevice::GetTotalVBOCount() const +{ + int count = 0; + List<VBO>::iterator itr, end = m_VBOList->m_List.end(); + for (itr = m_VBOList->m_List.begin(); itr != end; ++itr) + { + if (!itr->GetHideFromRuntimeStats()) + ++count; + } + return count; +} + +int GfxDevice::GetTotalVBOBytes() const +{ + int size = 0; + List<VBO>::iterator itr, end = m_VBOList->m_List.end(); + for (itr = m_VBOList->m_List.begin(); itr != end; ++itr) + { + if (!itr->GetHideFromRuntimeStats()) + size += itr->GetRuntimeMemorySize(); + } + return size; +} + +void GfxDevice::RecreateAllVBOs() +{ + List<VBO>::iterator itr, end = m_VBOList->m_List.end(); + for (itr = m_VBOList->m_List.begin() ; itr != end; ++itr) + { + itr->Recreate(); + } + GetDynamicVBO().Recreate(); +} + +#if GFX_SUPPORTS_D3D9 +void GfxDevice::ResetDynamicVBs() +{ + List<VBO>::iterator itr, end = m_VBOList->m_List.end(); + for (itr = m_VBOList->m_List.begin() ; itr != end; ++itr) + { + itr->ResetDynamicVB(); + } +} +#endif + +#if GFX_SUPPORTS_OPENGLES20 +void GfxDevice::MarkAllVBOsLost() +{ + for(List<VBO>::iterator itr = m_VBOList->m_List.begin(), end = m_VBOList->m_List.end() ; itr != end; ++itr) + itr->MarkBuffersLost(); +} +#endif + +void GfxDevice::SetWorldMatrixAndType( const float matrix[16], TransformType type ) +{ + SetWorldMatrix(matrix); + bool backface = (type & kOddNegativeScaleTransform) != 0; + int normalization = (type & kUniformScaleTransform) ? kNormalizationScale : 0; + normalization |= (type & kNonUniformScaleTransform) ? kNormalizationFull : 0; + DebugAssert(normalization != (kNormalizationScale|kNormalizationFull)); + SetNormalizationBackface(NormalizationMode(normalization), backface); +} + +void GfxDevice::SetInverseScale (float invScale) +{ + m_BuiltinParamValues.SetInstanceVectorParam(kShaderInstanceVecScale, Vector4f(0,0,0, invScale)); +} + +GpuProgram* GfxDevice::CreateGpuProgram( const std::string& source, CreateGpuProgramOutput& output ) +{ + return ::CreateGpuProgram( source, output ); +} + +void GfxDevice::RecordSetBlendState(const DeviceBlendState* state, const ShaderLab::FloatVal& alphaRef, const ShaderLab::PropertySheet* props ) +{ + ErrorString("GfxDevice does not support recording"); +} + +void GfxDevice::RecordSetMaterial( const ShaderLab::VectorVal& ambient, const ShaderLab::VectorVal& diffuse, const ShaderLab::VectorVal& specular, const ShaderLab::VectorVal& emissive, const ShaderLab::FloatVal& shininess, const ShaderLab::PropertySheet* props ) +{ + ErrorString("GfxDevice does not support recording"); +} + +void GfxDevice::RecordSetColor( const ShaderLab::VectorVal& color, const ShaderLab::PropertySheet* props ) +{ + ErrorString("GfxDevice does not support recording"); +} + +void GfxDevice::RecordEnableFog( FogMode fogMode, const ShaderLab::FloatVal& fogStart, const ShaderLab::FloatVal& fogEnd, const ShaderLab::FloatVal& fogDensity, const ShaderLab::VectorVal& fogColor, const ShaderLab::PropertySheet* props ) +{ + ErrorString("GfxDevice does not support recording"); +} + +void GfxDevice::SetMaterialProperties(const MaterialPropertyBlock& block) +{ + m_MaterialProperties = block; +} + + + +struct SkinMeshTask +{ + SkinMeshInfo info; + VBO* vbo; + void* vboMemory; +}; + +#if ENABLE_MULTITHREADED_SKINNING +static JobScheduler::JobGroupID s_SkinJobGroup; +#endif +static dynamic_array<SkinMeshTask> s_ActiveSkins; +static bool s_InsideSkinning = false; + +void EndSkinTask(SkinMeshTask& task) +{ + if (task.vbo) + task.vbo->UnmapVertexStream(0); + task.info.Release(); +} + +void GfxDevice::BeginSkinning( int maxSkinCount ) +{ + Assert(!s_InsideSkinning); +#if ENABLE_MULTITHREADED_SKINNING + s_SkinJobGroup = GetJobScheduler().BeginGroup(maxSkinCount); +#endif + s_ActiveSkins.reserve(maxSkinCount); + s_InsideSkinning = true; +} + +bool GfxDevice::SkinMesh( const SkinMeshInfo& skin, VBO* vbo ) +{ + Assert(s_InsideSkinning); + Assert((vbo == NULL) != (skin.outVertices == NULL)); + VertexStreamData mappedVSD; + if (vbo && !vbo->MapVertexStream(mappedVSD, 0)) + { + // Bail out before we push to active skins + skin.Release(); + return false; + } + + // Array must be preallocated to at least the right size + Assert(s_ActiveSkins.size() < s_ActiveSkins.capacity()); + int skinIndex = s_ActiveSkins.size(); + s_ActiveSkins.resize_uninitialized(skinIndex + 1); + SkinMeshTask& task = s_ActiveSkins[skinIndex]; + task.info = skin; + task.vbo = vbo; + + // Caller passes in a buffer if it wants to read it back + // Otherwise skin directly to VBO memory + if (vbo) + task.info.outVertices = mappedVSD.buffer; + +#if ENABLE_MULTITHREADED_SKINNING + GetJobScheduler().SubmitJob(s_SkinJobGroup, DeformSkinnedMeshJob, &task.info, NULL); +#else + DeformSkinnedMesh(task.info); + EndSkinTask(task); +#endif + return true; +} + +void GfxDevice::EndSkinning() +{ + Assert(s_InsideSkinning); +#if ENABLE_MULTITHREADED_SKINNING + GetJobScheduler().WaitForGroup(s_SkinJobGroup); + for (int i = 0; i < s_ActiveSkins.size(); i++) + EndSkinTask(s_ActiveSkins[i]); +#endif + s_ActiveSkins.resize_uninitialized(0); + s_InsideSkinning = false; +} + +#if GFX_ENABLE_DRAW_CALL_BATCHING +struct StaticBatch +{ +#if GFX_SUPPORTS_OPENGLES20 && GFX_OPENGLESxx_ONLY + enum { kMaxIndexCount = 16384 * 3 }; +#else // everything else + // Anything over 32k causes a slowdown on MBPs with AMD cards (Case 394520) + enum { kMaxIndexCount = 32000 }; +#endif + ~StaticBatch() { UNITY_FREE( kMemBatchedGeometry, indices); } + bool isActive; + ABSOLUTE_TIME startTime; + ChannelAssigns channels; + size_t indexCount; + size_t vertexCount; + size_t meshCount; + GfxPrimitiveType topology; + size_t vertexRangeBegin; + size_t vertexRangeEnd; + UInt16* indices; +} s_StaticBatch; + +void ClearStaticBatchIndices() +{ + UNITY_FREE(kMemBatchedGeometry,s_StaticBatch.indices); + s_StaticBatch.indices = NULL; +} + +int GfxDevice::GetMaxStaticBatchIndices() +{ + return StaticBatch::kMaxIndexCount; +} + +void GfxDevice::BeginStaticBatching (const ChannelAssigns& channels, GfxPrimitiveType topology) +{ + Assert(!s_StaticBatch.isActive); + Assert(topology==kPrimitiveTriangles || topology==kPrimitiveTriangleStripDeprecated); + + StaticBatch& batch = s_StaticBatch; + if (!batch.indices) + { + const size_t ibSize = StaticBatch::kMaxIndexCount * kVBOIndexSize; + batch.indices = reinterpret_cast<UInt16*>(UNITY_MALLOC_ALIGNED( kMemBatchedGeometry, ibSize, 32)); + } + batch.startTime = START_TIME; + batch.channels = channels; + batch.indexCount = 0; + batch.vertexCount = 0; + batch.meshCount = 0; + batch.topology = topology; + batch.vertexRangeBegin = std::numeric_limits<size_t>::max(); + batch.vertexRangeEnd = 0; + batch.isActive = true; +} + +void GfxDevice::StaticBatchMesh( UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ) +{ + Assert(s_StaticBatch.isActive); + + StaticBatch& batch = s_StaticBatch; + batch.vertexCount += vertexCount; + batch.vertexRangeBegin = std::min<size_t>(batch.vertexRangeBegin, firstVertex); + batch.vertexRangeEnd = std::max<size_t>(batch.vertexRangeEnd, firstVertex + vertexCount); + const UInt16* srcIndices = reinterpret_cast<const UInt16*>(static_cast<const UInt8*>(indices.indices) + firstIndexByte); + AppendMeshIndices(batch.indices, batch.indexCount, srcIndices, indexCount, batch.topology==kPrimitiveTriangleStripDeprecated); + batch.meshCount++; +} + +void GfxDevice::EndStaticBatching( VBO& vbo, const Matrix4x4f& matrix, TransformType transformType, int sourceChannels ) +{ + Assert(s_StaticBatch.isActive); + + SetWorldMatrixAndType(matrix.GetPtr(), transformType); + const StaticBatch& batch = s_StaticBatch; + vbo.DrawCustomIndexed(batch.channels, batch.indices, batch.indexCount, batch.topology, + batch.vertexRangeBegin, batch.vertexRangeEnd, batch.vertexCount); + + ABSOLUTE_TIME elapsedTime = ELAPSED_TIME(batch.startTime); + int primCount = GetPrimitiveCount(batch.indexCount, batch.topology, false); + GetFrameStats().AddBatch(primCount, batch.vertexCount, batch.meshCount, elapsedTime); + s_StaticBatch.isActive = false; +} + +struct DynamicBatch +{ + bool isActive; + ABSOLUTE_TIME startTime; + ChannelAssigns shaderChannels; + UInt32 availableChannels; + size_t maxVertices; + size_t maxIndices; + size_t vertexCount; + size_t indexCount; + size_t meshCount; + GfxPrimitiveType topology; + size_t destStride; + UInt8* outVertices; + UInt16* outIndices; +} s_DynamicBatch; + +void GfxDevice::BeginDynamicBatching( const ChannelAssigns& shaderChannels, UInt32 availableChannels, size_t maxVertices, size_t maxIndices, GfxPrimitiveType topology) +{ + Assert(!s_DynamicBatch.isActive); + Assert(topology != kPrimitiveLineStrip); + + DynamicBatch& batch = s_DynamicBatch; + batch.startTime = START_TIME; + batch.shaderChannels = shaderChannels; + batch.availableChannels = availableChannels; + batch.maxVertices = maxVertices; + batch.maxIndices = (topology == kPrimitiveQuads) ? maxIndices/4*6 : maxIndices; + batch.vertexCount = 0; + batch.indexCount = 0; + batch.meshCount = 0; + batch.topology = topology; + + batch.destStride = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) + if( availableChannels & (1<<i) ) + batch.destStride += VBO::GetDefaultChannelByteSize(i); + + DynamicVBO::RenderMode renderMode; + switch (topology) + { + case kPrimitiveTriangleStripDeprecated: + renderMode = DynamicVBO::kDrawIndexedTriangleStrip; + break; + case kPrimitiveLines: + renderMode = DynamicVBO::kDrawIndexedLines; + break; + case kPrimitiveQuads: + renderMode = DynamicVBO::kDrawIndexedQuads; + break; + case kPrimitivePoints: + renderMode = DynamicVBO::kDrawIndexedPoints; + break; + default: + renderMode = DynamicVBO::kDrawIndexedTriangles; + break; + } + + // Get VBO chunk + batch.isActive = GetDynamicVBO().GetChunk( + availableChannels, maxVertices, batch.maxIndices, renderMode, + (void**)&batch.outVertices, (void**)&batch.outIndices); +} + +void GfxDevice::DynamicBatchMesh( const Matrix4x4f& matrix, const VertexBufferData& vertices, UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ) +{ + Assert(s_DynamicBatch.isActive); + DynamicBatch& batch = s_DynamicBatch; + size_t outIndexCount; + + // convert quad indices to triangle indices + if (batch.topology == kPrimitiveQuads) + { + int quadIndexCount = indexCount/4*6; + UInt16* quadIB = ALLOC_TEMP_MANUAL (UInt16, quadIndexCount); + UInt16* src = (UInt16*)((UInt8*)indices.indices + firstIndexByte); + Prefetch(src, indexCount * kVBOIndexSize); + for (int i = 0; i < indexCount/4; ++i) + { + quadIB[6*i+0] = src[0]; + quadIB[6*i+1] = src[1]; + quadIB[6*i+2] = src[2]; + quadIB[6*i+3] = src[0]; + quadIB[6*i+4] = src[2]; + quadIB[6*i+5] = src[3]; + src += 4; + } + outIndexCount = TransformIndices(batch.outIndices, quadIB, 0, quadIndexCount, firstVertex, batch.vertexCount, false); + FREE_TEMP_MANUAL(quadIB); + } + else + outIndexCount = TransformIndices(batch.outIndices, indices.indices, firstIndexByte, indexCount, firstVertex, batch.vertexCount, batch.topology==kPrimitiveTriangleStripDeprecated); + + size_t outVertexCount = TransformVertices(batch.outVertices, matrix, vertices, firstVertex, vertexCount, batch.availableChannels); + + batch.outIndices += outIndexCount; + batch.outVertices += outVertexCount * batch.destStride; + batch.indexCount += outIndexCount; + batch.vertexCount += outVertexCount; + batch.meshCount++; +} + +void GfxDevice::EndDynamicBatching( TransformType transformType ) +{ + Assert(s_DynamicBatch.isActive); + + const DynamicBatch& batch = s_DynamicBatch; + Assert(batch.vertexCount <= batch.maxVertices); + Assert(batch.indexCount <= batch.maxIndices); + + // Release VBO chunk + GetDynamicVBO().ReleaseChunk(batch.vertexCount, batch.indexCount); + + SetWorldMatrixAndType(Matrix4x4f::identity.GetPtr(), transformType); + + GetDynamicVBO().DrawChunk(batch.shaderChannels); + ABSOLUTE_TIME elapsedTime = ELAPSED_TIME(batch.startTime); + int primCount = GetPrimitiveCount(batch.indexCount, batch.topology, false); + GetFrameStats().AddBatch(primCount, batch.vertexCount, batch.meshCount, elapsedTime); + s_DynamicBatch.isActive = false; +} +#if ENABLE_SPRITES +void GfxDevice::DynamicBatchSprite(const Matrix4x4f* matrix, const SpriteRenderData* rd, ColorRGBA32 color) +{ + Assert(s_DynamicBatch.isActive); + DynamicBatch& batch = s_DynamicBatch; + + TransformSprite (batch.outVertices, batch.outIndices, matrix, rd, color, batch.vertexCount); + int outIndexCount = (int)rd->indices.size(); + int outVertexCount = (int)rd->vertices.size(); + batch.outIndices += outIndexCount; + batch.outVertices += outVertexCount * batch.destStride; + batch.indexCount += outIndexCount; + batch.vertexCount += outVertexCount; + batch.meshCount++; +} +#endif +#else +void ClearStaticBatchIndices(){} +#endif //GFX_ENABLE_DRAW_CALL_BATCHING + +void GfxDevice::AddBatchingStats( int batchedTris, int batchedVerts, int batchedCalls ) +{ + ABSOLUTE_TIME unusedTime; + ABSOLUTE_TIME_INIT(unusedTime); + GetFrameStats().AddBatch(batchedTris, batchedVerts, batchedCalls, unusedTime); +} + +// on gl/gles we create textures at the very beginning with glGenTextures +// so start generate ids from smth not 0 +volatile int GfxDevice::ms_TextureIDGenerator = 10; +volatile int GfxDevice::ms_ComputeBufferIDGenerator = 0; + +#if !UNITY_WII // Wii also needs to register the ID, so separate impl +TextureID GfxDevice::CreateTextureID () +{ + return TextureID(AtomicIncrement(&ms_TextureIDGenerator)); +} +#endif + +void GfxDevice::FreeTextureID( TextureID texture ) +{ +} + +ComputeBufferID GfxDevice::CreateComputeBufferID() +{ + return ComputeBufferID(AtomicIncrement (&ms_ComputeBufferIDGenerator)); +} + +void GfxDevice::FreeComputeBufferID(ComputeBufferID id) +{ + // Do nothing yet +} + + +void GfxDevice::ResetFrameStats() +{ + m_Stats.ResetFrame(); +} + +void GfxDevice::BeginFrameStats() +{ + m_Stats.BeginFrameStats(); +} + +void GfxDevice::EndFrameStats() +{ + m_Stats.EndClientFrameStats(); +} + +void GfxDevice::SaveDrawStats() +{ + m_SavedStats.CopyAllDrawStats(m_Stats); + m_SavedStats.CopyClientStats(m_Stats); +} + +void GfxDevice::RestoreDrawStats() +{ + m_Stats.CopyAllDrawStats(m_SavedStats); + m_Stats.CopyClientStats(m_SavedStats); +} + +void GfxDevice::SynchronizeStats() +{ +} + +#if UNITY_EDITOR +void GfxDevice::SetColorBytes (const UInt8 color[4]) +{ + float colorFloat[4]; + colorFloat[0] = ByteToNormalized(color[0]); + colorFloat[1] = ByteToNormalized(color[1]); + colorFloat[2] = ByteToNormalized(color[2]); + colorFloat[3] = ByteToNormalized(color[3]); + SetColor (colorFloat); +} +#endif + + +void GfxThreadableDevice::SetShadersMainThread (ShaderLab::SubProgram* programs[kShaderTypeCount], const ShaderLab::PropertySheet* props) +{ + ErrorString("Don't call SetShadersMainThread on threadable device! Use GraphicsHelper instead"); +} + + + +void GfxDevice::CommonReloadResources(UInt32 flags) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_WORKER + if (flags & kReloadTextures) + Texture::ReloadAll(); + + if (flags & kReloadShaders) + Shader::ReloadAllShaders(); + + if (flags & kReleaseRenderTextures) + RenderTexture::ReleaseAll(); +#else + //todo. +#endif +} + + +void CalculateDeviceProjectionMatrix (Matrix4x4f& m, bool usesOpenGLTextureCoords, bool invertY) +{ + if (usesOpenGLTextureCoords) + return; // nothing to do on OpenGL-like devices + + // Otherwise, the matrix is OpenGL style, and we have to convert it to + // D3D-like projection matrix + + if (invertY) + { + m.Get(1,0) = -m.Get(1,0); + m.Get(1,1) = -m.Get(1,1); + m.Get(1,2) = -m.Get(1,2); + m.Get(1,3) = -m.Get(1,3); + } + + + // Now scale&bias to get Z range from -1..1 to 0..1: + // matrix = scaleBias * matrix + // 1 0 0 0 + // 0 1 0 0 + // 0 0 0.5 0.5 + // 0 0 0 1 + m.Get(2,0) = m.Get(2,0) * 0.5f + m.Get(3,0) * 0.5f; + m.Get(2,1) = m.Get(2,1) * 0.5f + m.Get(3,1) * 0.5f; + m.Get(2,2) = m.Get(2,2) * 0.5f + m.Get(3,2) * 0.5f; + m.Get(2,3) = m.Get(2,3) * 0.5f + m.Get(3,3) * 0.5f; +} + + + +void GfxDevice::SetupVertexLightParams(int light, const GfxVertexLight& data) +{ + DebugAssert(light >= 0 && light < kMaxSupportedVertexLights); + + const Matrix4x4f& viewMat = m_BuiltinParamValues.GetMatrixParam(kShaderMatView); + + Vector4f& position = m_BuiltinParamValues.GetWritableVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Position + light)); + Vector4f& spotDirection = m_BuiltinParamValues.GetWritableVectorParam(BuiltinShaderVectorParam(kShaderVecLight0SpotDirection + light)); + Vector4f& atten = m_BuiltinParamValues.GetWritableVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Atten + light)); + + // color + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + light), data.color); + + // position + if (data.type == kLightDirectional) + { + Vector3f p = viewMat.MultiplyVector3 ((const Vector3f&)data.position); + position.Set(-p.x, -p.y, -p.z, 0.0f); + } + else + { + Vector3f p = viewMat.MultiplyPoint3 ((const Vector3f&)data.position); + position.Set(p.x, p.y, p.z, 1.0f); + } + + // attenuation set in a way where distance attenuation can be computed: + // float lengthSq = dot(toLight, toLight); + // float atten = 1.0 / (1.0 + lengthSq * unity_LightAtten[i].z); + // and spot cone attenuation: + // float rho = max (0, dot(normalize(toLight), unity_SpotDirection[i].xyz)); + // float spotAtt = (rho - unity_LightAtten[i].x) * unity_LightAtten[i].y; + // spotAtt = saturate(spotAtt); + // and the above works for all light types, i.e. spot light code works out + // to correct math for point & directional lights as well. + + const float rangeSq = data.range * data.range; + + // spot direction & attenuation + if (data.spotAngle > 0.0f) + { + // spot light + Vector3f d = viewMat.MultiplyVector3((const Vector3f&)data.spotDirection); + spotDirection.Set(-d.x, -d.y, -d.z, 0.0f); + + const float radAngle = Deg2Rad(data.spotAngle); + const float cosTheta = cosf(radAngle*0.25f); + const float cosPhi = cosf(radAngle*0.5f); + const float cosDiff = cosTheta - cosPhi; + atten.Set(cosPhi, (cosDiff != 0.0f) ? 1.0f / cosDiff : 1.0f, data.quadAtten, rangeSq); + } + else + { + // non-spot light + spotDirection.Set(0.0f, 0.0f, 1.0f, 0.0f); + atten.Set(-1.0f, 1.0f, data.quadAtten, rangeSq); + } +} + + + +#if UNITY_EDITOR +VertexComponent kSuitableVertexComponentForChannel[kShaderChannelCount] = { + kVertexCompVertex, + kVertexCompNormal, + kVertexCompColor, + kVertexCompTexCoord0, + kVertexCompTexCoord1, + kVertexCompTexCoord2, +}; +#endif + +static const float kDodecahedron[20][3] = { + { 0.607f, 0.000f, 0.795f }, + { 0.188f, 0.577f, 0.795f }, + { -0.491f, 0.357f, 0.795f }, + { -0.491f, -0.357f, 0.795f }, + { 0.188f, -0.577f, 0.795f }, + { 0.982f, 0.000f, 0.188f }, + { 0.304f, 0.934f, 0.188f }, + { -0.795f, 0.577f, 0.188f }, + { -0.795f, -0.577f, 0.188f }, + { 0.304f, -0.934f, 0.188f }, + { 0.795f, 0.577f, -0.188f }, + { -0.304f, 0.934f, -0.188f }, + { -0.982f, 0.000f, -0.188f }, + { -0.304f, -0.934f, -0.188f }, + { 0.795f, -0.577f, -0.188f }, + { 0.491f, 0.357f, -0.795f }, + { -0.188f, 0.577f, -0.795f }, + { -0.607f, 0.000f, -0.795f }, + { -0.188f, -0.577f, -0.795f }, + { 0.491f, -0.357f, -0.795f }, +}; + +#define DODECAHEDRON_TRIANGLE(x,y,z,a,b,c,s) \ + ImmediateVertex(x + kDodecahedron[a][0] * s, y + kDodecahedron[a][1] * s, z + kDodecahedron[a][2] * s); \ + ImmediateVertex(x + kDodecahedron[b][0] * s, y + kDodecahedron[b][1] * s, z + kDodecahedron[b][2] * s); \ + ImmediateVertex(x + kDodecahedron[c][0] * s, y + kDodecahedron[c][1] * s, z + kDodecahedron[c][2] * s); + +#define DODECAHEDRON_FACE(x,y,z,a,b,c,d,e,s) \ + DODECAHEDRON_TRIANGLE(x,y,z,a,b,c,s) \ + DODECAHEDRON_TRIANGLE(x,y,z,a,c,d,s) \ + DODECAHEDRON_TRIANGLE(x,y,z,a,d,e,s) + +void GfxDevice::ImmediateShape( float x, float y, float z, float scale, ImmediateShapeType shape ) +{ + switch (shape) + { + case kShapeCube: + ImmediateBegin(kPrimitiveQuads); + ImmediateNormal(0, 0, 0); + // -z + ImmediateVertex (x+scale, y-scale, z-scale); + ImmediateVertex (x-scale, y-scale, z-scale); + ImmediateVertex (x-scale, y+scale, z-scale); + ImmediateVertex (x+scale, y+scale, z-scale); + // +z + ImmediateVertex (x-scale, y-scale, z+scale); + ImmediateVertex (x+scale, y-scale, z+scale); + ImmediateVertex (x+scale, y+scale, z+scale); + ImmediateVertex (x-scale, y+scale, z+scale); + // -x + ImmediateVertex (x-scale, y+scale, z-scale); + ImmediateVertex (x-scale, y-scale, z-scale); + ImmediateVertex (x-scale, y-scale, z+scale); + ImmediateVertex (x-scale, y+scale, z+scale); + // +x + ImmediateVertex (x+scale, y-scale, z-scale); + ImmediateVertex (x+scale, y+scale, z-scale); + ImmediateVertex (x+scale, y+scale, z+scale); + ImmediateVertex (x+scale, y-scale, z+scale); + // -y + ImmediateVertex (x-scale, y-scale, z-scale); + ImmediateVertex (x+scale, y-scale, z-scale); + ImmediateVertex (x+scale, y-scale, z+scale); + ImmediateVertex (x-scale, y-scale, z+scale); + // +y + ImmediateVertex (x+scale, y+scale, z-scale); + ImmediateVertex (x-scale, y+scale, z-scale); + ImmediateVertex (x-scale, y+scale, z+scale); + ImmediateVertex (x+scale, y+scale, z+scale); + + ImmediateEnd(); + break; + + case kShapeDodecahedron: + // template edge length + // a = 0.713644 + // radius of sphere containing the dodecahedron + // r = a / 20 * sqrtf(250 + 110*sqrtf(5)) + // scale our radius to fit the template + // TODO: is this correct? :) + scale = scale * 1.258408f; + + ImmediateBegin(kPrimitiveTriangles); + ImmediateNormal(0, 0, 0); + + DODECAHEDRON_FACE(x,y,z, 0,1,2,3,4, scale); + DODECAHEDRON_FACE(x,y,z, 0,5,10,6,1, scale); + DODECAHEDRON_FACE(x,y,z, 1,6,11,7,2, scale); + DODECAHEDRON_FACE(x,y,z, 2,7,12,8,3, scale); + DODECAHEDRON_FACE(x,y,z, 3,8,13,9,4, scale); + DODECAHEDRON_FACE(x,y,z, 4,9,14,5,0, scale); + DODECAHEDRON_FACE(x,y,z, 15,16,11,6,10, scale); + DODECAHEDRON_FACE(x,y,z, 16,17,12,7,11, scale); + DODECAHEDRON_FACE(x,y,z, 17,18,13,8,12, scale); + DODECAHEDRON_FACE(x,y,z, 18,19,14,9,13, scale); + DODECAHEDRON_FACE(x,y,z, 19,15,10,5,14, scale); + DODECAHEDRON_FACE(x,y,z, 15,19,18,17,16, scale); + + ImmediateEnd(); + break; + + default: + FatalErrorString("Unknown ImmediateShape"); + break; + }; +} + +#undef DODECAHEDRON_FACE +#undef DODECAHEDRON_TRIANGLE + +UInt32 GfxDevice::GetNativeTextureID(TextureID id) +{ +#if ENABLE_TEXTUREID_MAP + return TextureIdMap::QueryNativeTexture(id); +#else + return id.m_ID; +#endif +} + +void GfxDevice::InsertCustomMarker (int marker) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_WORKER + PluginsRenderMarker (marker); +#endif +} diff --git a/Runtime/GfxDevice/GfxDevice.h b/Runtime/GfxDevice/GfxDevice.h new file mode 100644 index 0000000..07d3906 --- /dev/null +++ b/Runtime/GfxDevice/GfxDevice.h @@ -0,0 +1,813 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" +#include "GfxDeviceConfigure.h" +#include "GfxDeviceTypes.h" +#include "GfxDeviceObjects.h" +#include "GfxDeviceStats.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/Math/Color.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Shaders/MaterialProperties.h" +#include "Runtime/Threads/Thread.h" +#include "BuiltinShaderParams.h" +#include "Runtime/Modules/ExportModules.h" + +#if UNITY_EDITOR && UNITY_WIN +#include "GfxDeviceWindow.h" +#endif + +#if ENABLE_TEXTUREID_MAP + #include "TextureIdMap.h" +#endif + + +// On some platforms we choose renderer at runtime; on others there's always a single +// renderer. On those that have only one, GFX_DEVICE_VIRTUAL is defined to zero, and +// the actual implementation is named GfxDevice, and uses no virtual functions. + +#if UNITY_PS3 +//# define CELL_GCM_DEBUG +# include <cell/gcm.h> +#endif + +#if UNITY_WIN || UNITY_OSX || UNITY_LINUX || UNITY_PS3 || UNITY_IPHONE || UNITY_ANDROID || UNITY_PEPPER || UNITY_XENON || UNITY_BB10 || UNITY_WEBGL || UNITY_TIZEN +#define GFX_DEVICE_VIRTUAL 1 +#else +#define GFX_DEVICE_VIRTUAL 0 +#endif + +#if (UNITY_OSX && WEBPLUG) || UNITY_LINUX && !UNITY_PEPPER +#define GFX_USES_VIEWPORT_OFFSET 1 +#else +#define GFX_USES_VIEWPORT_OFFSET 0 +#endif + + + +#if GFX_DEVICE_VIRTUAL + +#define GFX_API virtual +#define GFX_PURE = 0 +#define GFX_GL_IMPL GfxDeviceGL + +#else + +#define GFX_API +#define GFX_PURE +#define GFX_GL_IMPL GfxDevice +struct GfxDeviceImpl; + +#endif + +#define GFX_DEVICE_VERIFY_ENABLE (!UNITY_RELEASE) + +class VBO; +class RawVBO; +class VBOList; +class DynamicVBO; +class RenderTexture; +class ImageReference; +class Matrix4x4f; +class GpuProgram; +class GpuProgramParameters; +class GfxTimerQuery; +class GfxDisplayList; +class MaterialPropertyBlock; +class ShaderErrors; +class ChannelAssigns; +class CreateGpuProgramOutput; +struct SkinMeshInfo; +struct MemExportInfo; +struct VertexBufferData; +struct IndexBufferData; +struct PropertyNamesSet; +#if ENABLE_SPRITES +struct SpriteRenderData; +#endif +struct BoneInfluence; +namespace ShaderLab { + class IntShader; + struct ParserShader; + struct TextureBinding; + class PropertySheet; + class SubProgram; +} +namespace xenon { + class IVideoPlayer; +} + +class GPUSkinningInfo; + +class GfxDevice { +public: + + enum PresentMode + { + kPresentBeforeUpdate, + kPresentAfterDraw + }; + + enum SurfaceFlags + { + kSurfaceDefault = 0, + + // Bits 0 and 1 are used to control render target restores. There flags are mutually exclusive. + kSurfaceNeverRestore = (1<<0), // Xbox 360: SetRenderTarget will never restore contents to EDRAM. + kSurfaceAlwaysRestore = (1<<1), // Xbox 360: SetRenderTarget will always restore contents to EDRAM. + kSurfaceRestoreMask = kSurfaceNeverRestore | kSurfaceAlwaysRestore, + // Xbox 360: SetRenderTarget by default will only restore contents to EDRAM if render target was previously used that frame. + + // next flag (1<<2) + }; + + enum ReloadResourcesFlags { + kReleaseRenderTextures = (1<<0), + kReloadShaders = (1<<1), + kReloadTextures = (1<<2), + }; + + enum RenderTargetFlags { + kFlagDontRestoreColor = (1<<0), // Xbox 360 specific: do not restore old contents to EDRAM + kFlagDontRestoreDepth = (1<<1), // Xbox 360 specific: do not restore old contents to EDRAM + kFlagDontRestore = kFlagDontRestoreColor | kFlagDontRestoreDepth, + kFlagForceResolve = (1<<3), // Xbox 360 specific: force a resolve to system RAM + }; + + enum ImmediateShapeType { + kShapeCube = 0, // Quads + kShapeDodecahedron // Triangles + }; + + enum GfxProfileControl { + kGfxProfBeginFrame = 0, + kGfxProfEndFrame, + kGfxProfDisableSampling, + kGfxProfSetActive, + }; + + GfxDevice(); + GFX_API ~GfxDevice(); + + GFX_API void InvalidateState() GFX_PURE; + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState() GFX_PURE; + #endif + + GfxDeviceRenderer GetRenderer() const { return m_Renderer; } + // OpenGL: texture V coordinate is 0 at the bottom; 1 at the top + // otherwise: texture V coordinate is 0 at the top; 1 at the bottom + bool UsesOpenGLTextureCoords() const { return m_UsesOpenGLTextureCoords; } + // Should half-texel offset be applied for pixel-correct rendering (true on D3D9)? + bool UsesHalfTexelOffset() const { return m_UsesHalfTexelOffset; } + + GFX_API void SetMaxBufferedFrames (int bufferSize) { m_MaxBufferedFrames = bufferSize; } + int GetMaxBufferedFrames () const { return m_MaxBufferedFrames; } + + const GfxDeviceStats& GetFrameStats() const { return m_Stats; } + GfxDeviceStats& GetFrameStats() { return m_Stats; } + + RenderTexture* GetActiveRenderTexture() const + { +#if !UNITY_EDITOR // TODO: this needs fixing in the editor + ASSERT_RUNNING_ON_MAIN_THREAD; +#endif + return m_ActiveRenderTexture; + } + void SetActiveRenderTexture(RenderTexture* rt) + { +#if !UNITY_EDITOR // TODO: this needs fixing in the editor + ASSERT_RUNNING_ON_MAIN_THREAD; +#endif + m_ActiveRenderTexture = rt; + } + + const BuiltinShaderParamValues& GetBuiltinParamValues() const { return m_BuiltinParamValues; } + BuiltinShaderParamValues& GetBuiltinParamValues() { return m_BuiltinParamValues; } + const GfxFogParams& GetFogParams() const { return m_FogParams; } + + static inline ColorRGBA32 ConvertToDeviceVertexColor(const ColorRGBA32& color) + { + #if GFX_OPENGLESxx_ONLY || UNITY_PS3 || UNITY_WII + // Optimization: we know that we never have to swizzle vertex color here + DebugAssert(gGraphicsCaps.needsToSwizzleVertexColors == false); + return color; + #elif UNITY_XENON + // Optimization: we know that we always have to swizzle vertex color on Xbox360 platform + DebugAssert(gGraphicsCaps.needsToSwizzleVertexColors == true); + return color.SwizzleToARGB(); + #else + return gGraphicsCaps.needsToSwizzleVertexColors ? color.SwizzleToBGRA() : color; + #endif + }; + + int GetTotalVBOCount() const; + int GetTotalVBOBytes() const; + + void RecreateAllVBOs(); + + #if GFX_SUPPORTS_D3D9 + void ResetDynamicVBs(); + #endif + #if GFX_SUPPORTS_OPENGLES20 + void MarkAllVBOsLost(); + #endif + + + GFX_API void Clear (UInt32 clearFlags, const float color[4], float depth, int stencil) GFX_PURE; + GFX_API void SetInvertProjectionMatrix( bool enable ) GFX_PURE; + GFX_API bool GetInvertProjectionMatrix() const GFX_PURE; + #if GFX_USES_VIEWPORT_OFFSET + GFX_API void SetViewportOffset( float x, float y ) GFX_PURE; + GFX_API void GetViewportOffset( float &x, float &y ) const GFX_PURE; + #endif + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state) GFX_PURE; + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state) GFX_PURE; + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state) GFX_PURE; + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state) GFX_PURE; + + GFX_API void RecordSetBlendState(const DeviceBlendState* state, const ShaderLab::FloatVal& alphaRef, const ShaderLab::PropertySheet* props ); + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef) GFX_PURE; + GFX_API void SetRasterState(const DeviceRasterState* state) GFX_PURE; + GFX_API void SetDepthState(const DeviceDepthState* state) GFX_PURE; + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef) GFX_PURE; + GFX_API void SetSRGBWrite (const bool) GFX_PURE; + GFX_API bool GetSRGBWrite () GFX_PURE; + + GFX_API void SetUserBackfaceMode(bool enable) GFX_PURE; + GFX_API void SetWireframe(bool wire) GFX_PURE; + GFX_API bool GetWireframe() const GFX_PURE; + + GFX_API void SetWorldMatrixAndType( const float matrix[16], TransformType type ); + GFX_API void SetWorldMatrix( const float matrix[16] ) GFX_PURE; + GFX_API void SetViewMatrix( const float matrix[16] ) GFX_PURE; + GFX_API void SetProjectionMatrix (const Matrix4x4f& matrix) GFX_PURE; + + GFX_API void GetMatrix( float outMatrix[16] ) const GFX_PURE; + + + GFX_API const float* GetWorldMatrix() const GFX_PURE; + GFX_API const float* GetViewMatrix() const GFX_PURE; + GFX_API const float* GetProjectionMatrix() const GFX_PURE; // get projection matrix as passed from Unity (OpenGL projection conventions) + GFX_API const float* GetDeviceProjectionMatrix() const GFX_PURE; // get projection matrix that will be actually used + + GFX_API void SetInverseScale (float invScale); + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ) GFX_PURE; + + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) GFX_PURE; + GFX_API void RecordSetMaterial( const ShaderLab::VectorVal& ambient, const ShaderLab::VectorVal& diffuse, const ShaderLab::VectorVal& specular, const ShaderLab::VectorVal& emissive, const ShaderLab::FloatVal& shininess, const ShaderLab::PropertySheet* props ); + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) GFX_PURE; + GFX_API void RecordSetColor( const ShaderLab::VectorVal& color, const ShaderLab::PropertySheet* props ); + GFX_API void SetColor( const float color[4] ) GFX_PURE; + GFX_API void SetViewport( int x, int y, int width, int height ) GFX_PURE; + GFX_API void GetViewport( int* values ) const GFX_PURE; + + GFX_API void SetScissorRect( int x, int y, int width, int height ) GFX_PURE; + GFX_API void DisableScissor() GFX_PURE; + GFX_API bool IsScissorEnabled() const GFX_PURE; + GFX_API void GetScissorRect( int values[4] ) const GFX_PURE; + + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) GFX_PURE; + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ) GFX_PURE; + GFX_API void SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ) GFX_PURE; + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) GFX_PURE; + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) GFX_PURE; + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]) GFX_PURE; + GFX_API void SetTextureName( TextureID texture, char const* name ) GFX_PURE; + + GFX_API void SetMaterialProperties(const MaterialPropertyBlock& block); + + GFX_API GpuProgram* CreateGpuProgram( const std::string& source, CreateGpuProgramOutput& output ); + GFX_API void SetShadersMainThread( ShaderLab::SubProgram* programs[kShaderTypeCount], const ShaderLab::PropertySheet* props ) GFX_PURE; + + GFX_API bool IsShaderActive( ShaderType type ) const GFX_PURE; + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ) GFX_PURE; + GFX_API void SetConstantBufferInfo (int /*id*/, int /*size*/) { } + + GFX_API void DisableLights( int startLight ) GFX_PURE; + GFX_API void SetLight( int light, const GfxVertexLight& data) GFX_PURE; + GFX_API void SetAmbient( const float ambient[4] ) GFX_PURE; + + GFX_API void RecordEnableFog( FogMode fogMode, const ShaderLab::FloatVal& fogStart, const ShaderLab::FloatVal& fogEnd, const ShaderLab::FloatVal& fogDensity, const ShaderLab::VectorVal& fogColor, const ShaderLab::PropertySheet* props ); + GFX_API void EnableFog( const GfxFogParams& fog ) GFX_PURE; + GFX_API void DisableFog() GFX_PURE; + + GFX_API VBO* CreateVBO() GFX_PURE; + GFX_API void DeleteVBO( VBO* vbo ) GFX_PURE; + GFX_API DynamicVBO& GetDynamicVBO() GFX_PURE; + + GFX_API void BeginSkinning( int maxSkinCount ); + GFX_API bool SkinMesh( const SkinMeshInfo& skin, VBO* vbo ); + GFX_API void EndSkinning(); + +#if GFX_ENABLE_DRAW_CALL_BATCHING + static int GetMaxStaticBatchIndices(); + GFX_API void BeginStaticBatching(const ChannelAssigns& channels, GfxPrimitiveType topology); + GFX_API void StaticBatchMesh( UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ); + GFX_API void EndStaticBatching( VBO& vbo, const Matrix4x4f& matrix, TransformType transformType, int sourceChannels ); + + GFX_API void BeginDynamicBatching( const ChannelAssigns& shaderChannels, UInt32 availableChannels, size_t maxVertices, size_t maxIndices, GfxPrimitiveType topology); + GFX_API void DynamicBatchMesh( const Matrix4x4f& matrix, const VertexBufferData& vertices, UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ); + GFX_API void EndDynamicBatching( TransformType transformType ); +#if ENABLE_SPRITES + GFX_API void DynamicBatchSprite(const Matrix4x4f* matrix, const SpriteRenderData* rd, ColorRGBA32 color); +#endif +#endif + + GFX_API void AddBatchingStats( int batchedTris, int batchedVerts, int batchedCalls ); + + /** + * CreateGPUSkinningInfo - Create a GPU-assisted skinning object. + * + * GPU-assisted skinning is limited to platforms that support GPU + * writing the skinned output mesh into a VBO (StreamOut, MemExport, Transform Feedback). + * + * The returned object should be used against a single Skinned Mesh instance, and deleted once no longer needed. + * + * @return GFX_API GPUSkinningInfo* New GPU skinning object, or NULL if GPU skinning is not supported on this GfxDevice. + */ + GFX_API GPUSkinningInfo* CreateGPUSkinningInfo() GFX_PURE; + + /** + * DeleteGPUSkinningInfo - Release a GPUSkinningInfo object. + * + * @param info GPUSkinningInfo object to delete + */ + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info) GFX_PURE; + + /** + * SkinOnGPU - Perform GPU-assisted skinning into the destination VBO. + * + * @param info GPUSkinningInfo object filled with valid data and set up using UpdateSkinData and UpdateSkinBones + * @param lastThisFrame True if this is the last GPU-skinned mesh in this frame, false otherwise. + */ + GFX_API void SkinOnGPU( GPUSkinningInfo* info, bool lastThisFrame ) GFX_PURE; + + /** + * UpdateSkinSourceData - Pass the Vertex and skin data to the GPU. + * + * Assumes channel map, vertex count and stride has been previously set. + * If dirty is true, the vertex or skin data has changed since the last call, and the implementation should refresh the content. + * Otherwise, the implementation should just check that it has set up its internal buffers correctly and return. + * + * @param info GPUSkinningInfo object, expected to be properly set up with calls to setVertexCount, setChannelMap and setStride + * @param vertData Vertex data, array size defined by previous calls to setVertexCount(), setChannelMap() and setStride + * @param skinData Bone influence data, array size defined by setVertexCount + * @param dirty Dirty flag, see above + */ + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) GFX_PURE; + + /** + * UpdateSkinBonePoses - Update bone pose matrices for a GPU-assisted skin. + * + * Note that the array is not guaranteed to stay alive after the call, so unless + * the data can be uploaded immediately, a local copy is required. + * + * @param boneCount Number of bones + * @param poses Array of bone matrices + */ + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) GFX_PURE; + + +#if UNITY_XENON + GFX_API RawVBO* CreateRawVBO( UInt32 size, UInt32 flags ) GFX_PURE; + GFX_API void DeleteRawVBO( RawVBO* vbo ) GFX_PURE; + GFX_API void EnablePersistDisplayOnQuit( bool enabled ) GFX_PURE; + + GFX_API void RegisterTexture2D( TextureID tid, IDirect3DBaseTexture9* texture ) GFX_PURE; + GFX_API void PatchTexture2D( TextureID tid, IDirect3DBaseTexture9* texture ) GFX_PURE; + GFX_API void DeleteTextureEntryOnly( TextureID textureID ) GFX_PURE; + GFX_API void UnbindAndDelayReleaseTexture( IDirect3DBaseTexture9* texture ) GFX_PURE; + GFX_API void SetTextureWrapModes( TextureID textureID, TextureWrapMode wrapU, TextureWrapMode wrapV, TextureWrapMode wrapW ) GFX_PURE; + + GFX_API void OnLastFrameCallback() GFX_PURE; + + GFX_API xenon::IVideoPlayer* CreateVideoPlayer( bool fullscreen ) GFX_PURE; + GFX_API void DeleteVideoPlayer( xenon::IVideoPlayer* player ) GFX_PURE; + GFX_API void SetNullPixelShader() GFX_PURE; + GFX_API void SetHiZEnable( const HiZstate hiz_enable ) GFX_PURE; + GFX_API void SetHiStencilState( const bool hiStencilEnable, const bool hiStencilWriteEnable, const int hiStencilRef, const CompareFunction cmpFunc ) GFX_PURE; + GFX_API void HiStencilFlush( const HiSflush flushtype ) GFX_PURE; +#endif + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) GFX_PURE; + GFX_API RenderSurfaceHandle CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) GFX_PURE; + GFX_API void DestroyRenderSurface (RenderSurfaceHandle& rs) GFX_PURE; + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel = 0, CubemapFace face = kCubeFaceUnknown) GFX_PURE; + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, UInt32 flags) +#if !UNITY_XENON + { SetRenderTargets(count, colorHandles, depthHandle, mipLevel, face); } +#else + GFX_PURE +#endif + ; + + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) GFX_PURE; + + GFX_API void DiscardContents (RenderSurfaceHandle& rs) GFX_PURE; + // Do not produce a warning for next unresolve of current RT; it is expected and there's nothing we can do about it + GFX_API void IgnoreNextUnresolveOnCurrentRenderTarget() { } + GFX_API void IgnoreNextUnresolveOnRS(RenderSurfaceHandle rs) { } + + GFX_API void ResolveDepthIntoTexture (RenderSurfaceHandle /*colorHandle*/, RenderSurfaceHandle /*depthHandle*/) { } + + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface (int index) GFX_PURE; + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface () GFX_PURE; + + // TODO: we might need to extend it in the future, e.g. for multi-display + GFX_API RenderSurfaceHandle GetBackBufferColorSurface () { return m_BackBufferColor; } + GFX_API RenderSurfaceHandle GetBackBufferDepthSurface () { return m_BackBufferDepth; } + + GFX_API void SetBackBufferColorSurface(RenderSurfaceBase* color) { m_BackBufferColor=RenderSurfaceHandle(color); } + GFX_API void SetBackBufferDepthSurface(RenderSurfaceBase* depth) { m_BackBufferDepth=RenderSurfaceHandle(depth); } + + GFX_API bool IsRenderTargetConfigValid(UInt32 width, UInt32 height, RenderTextureFormat /*colorFormat*/, DepthBufferFormat /*depthFormat*/) +#if !UNITY_XENON + { return width <= gGraphicsCaps.maxRenderTextureSize && height <= gGraphicsCaps.maxRenderTextureSize; } +#else + GFX_PURE +#endif + ; + + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags = 0) GFX_PURE; + + GFX_API TextureID CreateTextureID(); + GFX_API void FreeTextureID( TextureID texture ); + +#if ENABLE_TEXTUREID_MAP + GFX_API intptr_t CreateExternalTextureFromNative(intptr_t nativeTex) { return nativeTex; } + GFX_API void UpdateExternalTextureFromNative(TextureID tex, intptr_t nativeTex) { TextureIdMap::UpdateTexture(tex, nativeTex); } +#endif + + enum kUploadTextureFlags + { + kUploadTextureDefault = 0, + kUploadTextureDontUseSubImage = 1<<0, // texture might not be created yet, or is being resized + kUploadTextureOSDrawingCompatible = 1<<1, // create an OS-drawing compatible one (e.g. for GDI on Windows) + // NOTE: Richard S added these on another Xbox360 branch, uncomment/merge when that branch comes back + //kUploadTextureTiled = 1<<2, + //kUploadTextureMemoryReady = 1<<3, + }; + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) GFX_PURE; + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) GFX_PURE; + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) GFX_PURE; + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) GFX_PURE; + GFX_API void DeleteTexture( TextureID texture ) GFX_PURE; + + GFX_API PresentMode GetPresentMode() GFX_PURE; + + GFX_API void BeginFrame() GFX_PURE; + GFX_API void EndFrame() GFX_PURE; + inline bool IsInsideFrame() const { return m_InsideFrame; } + inline void SetInsideFrame(bool v) { m_InsideFrame = v; } + GFX_API void PresentFrame() GFX_PURE; + // Check if device is in valid state. E.g. lost device on D3D9; in this case all rendering + // should be skipped. + GFX_API bool IsValidState() GFX_PURE; + GFX_API bool HandleInvalidState() { return true; } + GFX_API void ResetDynamicResources() {} + GFX_API bool IsReadyToBeginFrame() { return true; } + + // Fully finish any queued-up rendering (including on the GPU) + GFX_API void FinishRendering() GFX_PURE; + // Insert CPU fence into command queue (if threaded) + GFX_API UInt32 InsertCPUFence() { return 0; } + // Get next CPU fence that will be inserted + GFX_API UInt32 GetNextCPUFence() { return 0; } + // Finish any threaded commands before CPU fence + GFX_API void WaitOnCPUFence(UInt32 /*fence*/) {} + + // Are we recording graphics commands? + inline bool IsRecording() const { return m_IsRecording; } + + // Does this device derive from GfxThreadableDevice? + inline bool IsThreadable() const { return m_IsThreadable; } + + // Acquire thread ownership on the calling thread. Worker releases ownership. + GFX_API void AcquireThreadOwnership() {} + // Release thread ownership on the calling thread. Worker acquires ownership. + GFX_API void ReleaseThreadOwnership() {} + + // Immediate mode rendering + GFX_API void ImmediateShape( float x, float y, float z, float scale, ImmediateShapeType shape ); + GFX_API void ImmediateVertex( float x, float y, float z ) GFX_PURE; + GFX_API void ImmediateNormal( float x, float y, float z ) GFX_PURE; + GFX_API void ImmediateColor( float r, float g, float b, float a ) GFX_PURE; + GFX_API void ImmediateTexCoordAll( float x, float y, float z ) GFX_PURE; + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ) GFX_PURE; + GFX_API void ImmediateBegin( GfxPrimitiveType type ) GFX_PURE; + GFX_API void ImmediateEnd() GFX_PURE; + + // Recording display lists +#if GFX_SUPPORTS_DISPLAY_LISTS + GFX_API bool BeginRecording() { return false; } + GFX_API bool EndRecording( GfxDisplayList** outDisplayList ) { return false; } +#endif + + // Capturing screen shots / blits + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ) GFX_PURE; + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) GFX_PURE; + GFX_API void GrabIntoRenderTexture (RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height) GFX_PURE; + + // Any housekeeping around draw calls + GFX_API void BeforeDrawCall( bool immediateMode ) GFX_PURE; + GFX_API void AfterDrawCall() {}; + + GFX_API bool IsPositionRequiredForTexGen (int texStageIndex) const GFX_PURE; + GFX_API bool IsNormalRequiredForTexGen (int texStageIndex) const GFX_PURE; + GFX_API bool IsPositionRequiredForTexGen() const GFX_PURE; + GFX_API bool IsNormalRequiredForTexGen() const GFX_PURE; + + GFX_API void SetActiveContext (void* /*ctx*/) {}; + + GFX_API void ResetFrameStats(); + GFX_API void BeginFrameStats(); + GFX_API void EndFrameStats(); + GFX_API void SaveDrawStats(); + GFX_API void RestoreDrawStats(); + GFX_API void SynchronizeStats(); + + #if ENABLE_PROFILER + GFX_API void BeginProfileEvent (const char* /*name*/) {} + GFX_API void EndProfileEvent () {} + GFX_API void ProfileControl (GfxProfileControl /*ctrl*/, unsigned /*param*/) {} + + GFX_API GfxTimerQuery* CreateTimerQuery() GFX_PURE; + GFX_API void DeleteTimerQuery(GfxTimerQuery* query) GFX_PURE; + GFX_API void BeginTimerQueries() GFX_PURE; + GFX_API void EndTimerQueries() GFX_PURE; + GFX_API bool TimerQueriesIsActive() { return false; } + #endif + + // Editor-only stuff + #if UNITY_EDITOR + GFX_API void SetColorBytes (const UInt8 color[4]); + GFX_API void SetAntiAliasFlag( bool aa ) GFX_PURE; + GFX_API void DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ) GFX_PURE; + GFX_API int GetCurrentTargetAA() const GFX_PURE; + + #if UNITY_WIN + //ToDo: This is windows specific code, we should replace HWND window with something more abstract + GFX_API GfxDeviceWindow* CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) GFX_PURE; + + #endif + #endif + + #if UNITY_WIN + GFX_API int GetCurrentTargetWidth() const { return 0; } + GFX_API int GetCurrentTargetHeight() const { return 0; } + GFX_API void SetCurrentTargetSize(int /*width*/, int /*height*/) { } + GFX_API void SetCurrentWindowSize(int /*width*/, int /*height*/) { } + #endif + + static void CommonReloadResources( UInt32 flags ); + + #if GFX_SUPPORTS_OPENGL + GFX_API void UnbindObjects () {} + #endif + + #if GFX_OPENGLESxx_ONLY || GFX_SUPPORTS_MOLEHILL + GFX_API void ReloadResources() GFX_PURE; + #endif + + #if !GFX_DEVICE_VIRTUAL + GfxDeviceImpl* GetImpl() { return impl; } + #endif + +#if GFX_DEVICE_VIRTUAL + GFX_API RenderTextureFormat GetDefaultRTFormat() const { return kRTFormatARGB32; } +#else + GFX_API RenderTextureFormat GetDefaultRTFormat() const; +#endif + +#if GFX_DEVICE_VIRTUAL + GFX_API RenderTextureFormat GetDefaultHDRRTFormat() const { return kRTFormatARGBHalf; } +#else + GFX_API RenderTextureFormat GetDefaultHDRRTFormat() const; +#endif + + GFX_API void* GetNativeGfxDevice() { return NULL; } + GFX_API void* GetNativeTexturePointer(TextureID /*id*/) { return NULL; } + GFX_API UInt32 GetNativeTextureID(TextureID id); + GFX_API void InsertCustomMarker (int marker); + + GFX_API ComputeBufferID CreateComputeBufferID(); + GFX_API void FreeComputeBufferID(ComputeBufferID id); + + GFX_API void SetComputeBufferData (ComputeBufferID /*bufferHandle*/, const void* /*data*/, size_t /*size*/) { } + GFX_API void GetComputeBufferData (ComputeBufferID /*bufferHandle*/, void* /*dest*/, size_t /*destSize*/) { } + GFX_API void CopyComputeBufferCount (ComputeBufferID /*srcBuffer*/, ComputeBufferID /*dstBuffer*/, UInt32 /*dstOffset*/) { } + + GFX_API void SetRandomWriteTargetTexture (int /*index*/, TextureID /*tid*/) { } + GFX_API void SetRandomWriteTargetBuffer (int /*index*/, ComputeBufferID /*bufferHandle*/) { } + GFX_API void ClearRandomWriteTargets () { } + + GFX_API ComputeProgramHandle CreateComputeProgram (const UInt8* /*code*/, size_t /*codeSize*/) { ComputeProgramHandle cp; return cp; } + GFX_API void DestroyComputeProgram (ComputeProgramHandle& /*cpHandle*/) { } + GFX_API void CreateComputeConstantBuffers (unsigned /*count*/, const UInt32* /*sizes*/, ConstantBufferHandle* /*outCBs*/) { } + GFX_API void DestroyComputeConstantBuffers (unsigned /*count*/, ConstantBufferHandle* /*cbs*/) { } + GFX_API void CreateComputeBuffer (ComputeBufferID /*id*/, size_t /*count*/, size_t /*stride*/, UInt32 /*flags*/) { } + GFX_API void DestroyComputeBuffer (ComputeBufferID /*handle*/) { } + GFX_API void UpdateComputeConstantBuffers (unsigned /*count*/, ConstantBufferHandle* /*cbs*/, UInt32 /*cbDirty*/, size_t /*dataSize*/, const UInt8* /*data*/, const UInt32* /*cbSizes*/, const UInt32* /*cbOffsets*/, const int* /*bindPoints*/) { } + GFX_API void UpdateComputeResources ( + unsigned /*texCount*/, const TextureID* /*textures*/, const int* /*texBindPoints*/, + unsigned /*samplerCount*/, const unsigned* /*samplers*/, + unsigned /*inBufferCount*/, const ComputeBufferID* /*inBuffers*/, const int* /*inBufferBindPoints*/, + unsigned /*outBufferCount*/, const ComputeBufferID* /*outBuffers*/, const TextureID* /*outTextures*/, const UInt32* /*outBufferBindPoints*/) { } + GFX_API void DispatchComputeProgram (ComputeProgramHandle /*cpHandle*/, unsigned /*threadsX*/, unsigned /*threadsY*/, unsigned /*threadsZ*/) { } + + GFX_API void DrawNullGeometry (GfxPrimitiveType /*topology*/, int /*vertexCount*/, int /*instanceCount*/) { }; + GFX_API void DrawNullGeometryIndirect (GfxPrimitiveType /*topology*/, ComputeBufferID /*bufferHandle*/, UInt32 /*bufferOffset*/) { }; + DepthBufferFormat GetFramebufferDepthFormat() const { return m_FramebufferDepthFormat; } + void SetFramebufferDepthFormat(DepthBufferFormat depthFormat) { m_FramebufferDepthFormat = depthFormat; } + +protected: + void SetupVertexLightParams(int light, const GfxVertexLight& data); + +private: + + #if !GFX_DEVICE_VIRTUAL + GfxDeviceImpl* impl; + #endif + +protected: + void OnCreate(); + void OnDelete(); + void OnCreateVBO(VBO* vbo); + void OnDeleteVBO(VBO* vbo); + + // Mutable state + BuiltinShaderParamValues m_BuiltinParamValues; + GfxFogParams m_FogParams; + GfxDeviceStats m_Stats; + GfxDeviceStats m_SavedStats; + bool m_InsideFrame; + bool m_IsRecording; + bool m_IsThreadable; + RenderTexture* m_ActiveRenderTexture; + const BuiltinShaderParamIndices* m_BuiltinParamIndices[kShaderTypeCount]; + BuiltinShaderParamIndices m_NullParamIndices; + MaterialPropertyBlock m_MaterialProperties; + + // Immutable data + GfxDeviceRenderer m_Renderer; + bool m_UsesOpenGLTextureCoords; + bool m_UsesHalfTexelOffset; + int m_MaxBufferedFrames; + DepthBufferFormat m_FramebufferDepthFormat; + + + RenderSurfaceHandle m_BackBufferColor; + RenderSurfaceHandle m_BackBufferDepth; + + +private: + + VBOList* m_VBOList; + static volatile int ms_TextureIDGenerator; + static volatile int ms_ComputeBufferIDGenerator; + + typedef std::map<TextureID, size_t> TextureIDToSizeMap; + TextureIDToSizeMap m_TextureSizes; +}; + +class GfxThreadableDevice : public GfxDevice +{ +public: + //! Called by the worker thread on thread startup + GFX_API void OnDeviceCreated (bool /*callingFromRenderThread*/) { } + + //! IsCombineModeSupported() exists because we want CreateTextureCombiners() failure to happen + //! on the main thread, not the render thread where we can't do anything about it. + //! When it returns true then creating combiners *should* succeed + GFX_API bool IsCombineModeSupported( unsigned int combiner ) GFX_PURE; + + GFX_API void SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ) GFX_PURE; + GFX_API void SetShadersMainThread (ShaderLab::SubProgram* programs[kShaderTypeCount], const ShaderLab::PropertySheet* props); + GFX_API void SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]) { }; + + //! CreateShaderParameters() exists because the main thread needs to know which parameters a shader takes, and on + //! GL-like platforms it can vary with different fog modes because we recompile shaders when the mode was changed. + GFX_API void CreateShaderParameters( ShaderLab::SubProgram* /*program*/, FogMode /*fogMode*/ ) { } +}; + +bool IsGfxDevice(); +EXPORT_COREMODULE GfxDevice& GetGfxDevice(); +GfxDevice& GetUncheckedGfxDevice(); +void SetGfxDevice(GfxDevice* device); +void DestroyGfxDevice(); + +GfxDevice& GetRealGfxDevice(); +bool IsRealGfxDeviceThreadOwner(); +#if ENABLE_MULTITHREADED_CODE +void SetRealGfxDevice(GfxDevice* device); +void SetRealGfxDeviceThreadOwnership(); +void DestroyRealGfxDevice(); +void SetGfxThreadingMode(GfxThreadingMode mode); +GfxThreadingMode GetGfxThreadingMode(); +#endif + +class AutoGfxDeviceAcquireThreadOwnership +{ +public: + AutoGfxDeviceAcquireThreadOwnership(); + ~AutoGfxDeviceAcquireThreadOwnership(); + +private: + bool m_WasOwner; +}; + +class AutoGfxDeviceBeginEndFrame +{ +public: + AutoGfxDeviceBeginEndFrame(); + ~AutoGfxDeviceBeginEndFrame(); + + void End(); + bool GetSuccess() const { return m_Success; } + +private: + bool m_Success; + bool m_NeedsEndFrame; +}; + +void CalculateDeviceProjectionMatrix (Matrix4x4f& m, bool usesOpenGLTextureCoords, bool invertY); + +inline AutoGfxDeviceAcquireThreadOwnership::AutoGfxDeviceAcquireThreadOwnership() +{ + m_WasOwner = IsRealGfxDeviceThreadOwner(); + if (!m_WasOwner) + GetGfxDevice().AcquireThreadOwnership(); +} + +inline AutoGfxDeviceAcquireThreadOwnership::~AutoGfxDeviceAcquireThreadOwnership() +{ + if (!m_WasOwner) + GetGfxDevice().ReleaseThreadOwnership(); +} + +inline AutoGfxDeviceBeginEndFrame::AutoGfxDeviceBeginEndFrame() : +m_Success(true), m_NeedsEndFrame(false) +{ + GfxDevice& device = GetGfxDevice(); + if (!device.IsInsideFrame()) + { + device.BeginFrame(); + m_Success = device.IsValidState(); + m_NeedsEndFrame = true; + } +} + +inline AutoGfxDeviceBeginEndFrame::~AutoGfxDeviceBeginEndFrame() +{ + End(); +} + +inline void AutoGfxDeviceBeginEndFrame::End() +{ + if (m_NeedsEndFrame) + GetGfxDevice().EndFrame(); + m_NeedsEndFrame = false; +} + + +inline DepthBufferFormat DepthBufferFormatFromBits(int bits) +{ + if( bits <= 0 ) + return kDepthFormatNone; + else if( bits <= 16 ) + return kDepthFormat16; + else + return kDepthFormat24; +} + +#if UNITY_EDITOR +extern VertexComponent kSuitableVertexComponentForChannel[]; +#endif + + +class SetAndRestoreWireframeMode { +public: + SetAndRestoreWireframeMode() { + GfxDevice& device = GetGfxDevice(); + m_SavedWireframe = device.GetWireframe(); + } + SetAndRestoreWireframeMode(bool wireframe) { + GfxDevice& device = GetGfxDevice(); + m_SavedWireframe = device.GetWireframe(); + device.SetWireframe(wireframe); + } + ~SetAndRestoreWireframeMode() { + GfxDevice& device = GetGfxDevice(); + device.SetWireframe(m_SavedWireframe); + } +private: + bool m_SavedWireframe; +}; + +void ApplyTexEnvData (unsigned int texUnit, unsigned int samplerUnit, const TexEnvData& data); + diff --git a/Runtime/GfxDevice/GfxDeviceConfigure.h b/Runtime/GfxDevice/GfxDeviceConfigure.h new file mode 100644 index 0000000..58ba4a5 --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceConfigure.h @@ -0,0 +1,40 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" + +#if UNITY_IPHONE || UNITY_ANDROID || UNITY_BB10 || UNITY_TIZEN +# define GFX_SUPPORTS_DXT_COMPRESSION 0 +# define GFX_SUPPORTS_DISPLAY_LISTS 0 +#elif (UNITY_LINUX && GFX_SUPPORTS_OPENGLES20) +#warning Linux: determine the real configs here +# define GFX_SUPPORTS_DXT_COMPRESSION 1 +# define GFX_SUPPORTS_DISPLAY_LISTS 0 +#elif (UNITY_WII) +# define GFX_SUPPORTS_DXT_COMPRESSION 0 +# define GFX_SUPPORTS_DISPLAY_LISTS 0 +#else +# define GFX_SUPPORTS_DXT_COMPRESSION 1 +# define GFX_SUPPORTS_DISPLAY_LISTS 1 +#endif + +#define GFX_ENABLE_DRAW_CALL_BATCHING (!ENABLE_GFXDEVICE_REMOTE_PROCESS && (UNITY_OSX || UNITY_WIN || UNITY_IPHONE || UNITY_ANDROID || UNITY_PEPPER || UNITY_LINUX || UNITY_FLASH || UNITY_XENON || UNITY_BB10 || UNITY_WEBGL || UNITY_TIZEN)) +#define GFX_HAS_NO_FIXED_FUNCTION (UNITY_PS3 || UNITY_XENON || ((GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30) && GFX_OPENGLESxx_ONLY))) + +#define GFX_SUPPORTS_RENDERLOOP_PREPASS (!UNITY_WII && !UNITY_FLASH && !UNITY_WEBGL && !UNITY_BB10 && !UNITY_TIZEN) + +#define GFX_ALL_BUFFERS_CAN_BECOME_LOST (UNITY_FLASH || GFX_SUPPORTS_OPENGLES20) +#define GFX_CAN_UNLOAD_MESH_DATA (GAMERELEASE && !UNITY_PEPPER && !UNITY_PS3 && !UNITY_WP8 && !GFX_ALL_BUFFERS_CAN_BECOME_LOST) + +#define GFX_SUPPORTS_TRISTRIPS (!UNITY_FLASH) + +#define GFX_EMULATES_NPOT_RENDERTEXTURES (UNITY_FLASH) + +#define NV_STATE_FILTERING UNITY_ANDROID + + + +#define GFX_ENABLE_SHADOW_BATCHING (GFX_ENABLE_DRAW_CALL_BATCHING && 1) + +#define GFX_SUPPORTS_CONSTANT_BUFFERS (GFX_SUPPORTS_D3D11 || GFX_SUPPORTS_OPENGLES30) + +#define GFX_USE_SPHERE_FOR_POINT_LIGHT (!UNITY_PS3) diff --git a/Runtime/GfxDevice/GfxDeviceObjects.h b/Runtime/GfxDevice/GfxDeviceObjects.h new file mode 100644 index 0000000..756f6df --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceObjects.h @@ -0,0 +1,145 @@ +#pragma once + +#include "Runtime/Camera/Lighting.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/Math/Vector4.h" +#include "GfxDeviceTypes.h" + +// -------------------------------------------------------------------------- + +// A type safe opaque pointer to something. +// ID type is used just so that you can have handles to different types, all type safe. +template<typename ID, typename ObjectPtrType=void*> +struct ObjectHandle +{ + explicit ObjectHandle(ObjectPtrType obj = 0) : object(obj) {} + bool IsValid() const { return object != 0; } + void Reset() { object = 0; } + bool operator==( const ObjectHandle<ID,ObjectPtrType>& o ) const { return object == o.object; } + bool operator!=( const ObjectHandle<ID,ObjectPtrType>& o ) const { return object != o.object; } + + ObjectPtrType object; +}; + +#define OBJECT_FROM_HANDLE(handle,type) reinterpret_cast<type*>((handle).object) + + +// -------------------------------------------------------------------------- + +struct RenderSurfaceBase; +struct RenderSurface_Tag; +typedef ObjectHandle<RenderSurface_Tag, RenderSurfaceBase*> RenderSurfaceHandle; + +struct GraphicsContext_Tag; +typedef ObjectHandle<GraphicsContext_Tag> GraphicsContextHandle; + +struct TextureCombiners_Tag; +typedef ObjectHandle<TextureCombiners_Tag> TextureCombinersHandle; + +struct ComputeProgram_Tag; +typedef ObjectHandle<ComputeProgram_Tag> ComputeProgramHandle; + +struct ConstantBuffer_Tag; +typedef ObjectHandle<ConstantBuffer_Tag> ConstantBufferHandle; + +// -------------------------------------------------------------------------- + + +struct SimpleVec4 +{ + float val[4]; + + void set( const float *v ) + { + val[0] = v[0]; + val[1] = v[1]; + val[2] = v[2]; + val[3] = v[3]; + } + void set( float v0, float v1, float v2, float v3 ) + { + val[0] = v0; + val[1] = v1; + val[2] = v2; + val[3] = v3; + } + + bool operator==(const SimpleVec4& o) const { + return val[0] == o.val[0] && val[1] == o.val[1] && val[2] == o.val[2] && val[3] == o.val[3]; + } + bool operator!=(const SimpleVec4& o) const { + return val[0] != o.val[0] || val[1] != o.val[1] || val[2] != o.val[2] || val[3] != o.val[3]; + } + bool operator==(const float* o) const { + return val[0] == o[0] && val[1] == o[1] && val[2] == o[2] && val[3] == o[3]; + } + bool operator!=(const float* o) const { + return val[0] != o[0] || val[1] != o[1] || val[2] != o[2] || val[3] != o[3]; + } + + const float* GetPtr() const { return val; } +}; + + + +// -------------------------------------------------------------------------- + + +struct GfxVertexLight +{ + Vector4f position; // directional: direction (w=0); others: position (w=1) + Vector4f spotDirection; // w = 0 + Vector4f color; // diffuse&specular color + float range; // range + float quadAtten; // quadratic attenuation (constant = 1, linear = 0) + float spotAngle; // in degrees of full cone; -1 if not spot light + LightType type; + + GfxVertexLight() + : position(Vector3f::zero,1.0f) + , spotDirection (Vector3f::zAxis,1.0f) + , color (Vector3f::zero,1.0f) + , range (0.0f) + , quadAtten (0.0f) + , spotAngle (0.0f) + , type (kLightDirectional) + {} +}; + + +struct GfxMaterialParams +{ + Vector4f ambient; + Vector4f diffuse; + Vector4f specular; + Vector4f emissive; + float shininess; + + void Invalidate() + { + ambient.Set( -1, -1, -1, -1 ); + diffuse.Set( -1, -1, -1, -1 ); + specular.Set( -1, -1, -1, -1 ); + emissive.Set( -1, -1, -1, -1 ); + shininess = -1.0f; + } +}; + + +struct GfxFogParams +{ + FogMode mode; + Vector4f color; + float start; + float end; + float density; + + void Invalidate() + { + mode = kFogUnknown; + color.Set( -1, -1, -1, -1 ); + start = -1.0f; + end = -1.0f; + density = -1.0f; + } +}; diff --git a/Runtime/GfxDevice/GfxDeviceRecreate.cpp b/Runtime/GfxDevice/GfxDeviceRecreate.cpp new file mode 100644 index 0000000..6447cc3 --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceRecreate.cpp @@ -0,0 +1,291 @@ +#include "UnityPrefix.h" +#include "GfxDeviceRecreate.h" +#include "Runtime/Camera/RenderSettings.h" +#include "Runtime/Filters/Deformation/SkinnedMeshFilter.h" +#include "Runtime/Filters/Mesh/LodMesh.h" +#include "Runtime/Dynamics/ClothRenderer.h" +#include "Runtime/Filters/Misc/Font.h" +#include "Runtime/Filters/Misc/TextMesh.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/GfxDeviceSetup.h" +#include "Runtime/Graphics/GeneratedTextures.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Graphics/Texture.h" +#include "Runtime/IMGUI/TextMeshGenerator2.h" +#include "Runtime/Shaders/Shader.h" +#include "Runtime/Shaders/ComputeShader.h" +#if ENABLE_PROFILER +#include "Runtime/Profiler/ProfilerImpl.h" +#endif +#if UNITY_EDITOR +#include "Editor/Platform/Interface/EditorWindows.h" +#include "Editor/Src/Application.h" +#endif + +#if ENABLE_TERRAIN +#include "Runtime/Interfaces/ITerrainManager.h" +#endif + +#if ENABLE_WEBCAM +#include "Runtime/Video/VideoTexture.h" +#endif + +static void UnloadAllTextures() +{ + #if ENABLE_WEBCAM + BaseVideoTexture::SuspendVideoTextures (); + #endif + + Texture::ReloadAll (true, false, true); +} + +static void LoadAllTextures() +{ + Texture::ReloadAll (false, true); + + #if ENABLE_WEBCAM + BaseVideoTexture::ResumeVideoTextures (); + #endif +} + +static void UnloadAllShaders() +{ + std::vector<SInt32> allShaders; + Shader::DeleteAllShaders(allShaders); + Shader::UnloadDefaultShaderLabShader(); + + // Now, some shaders might have been unsupported, which means they were pointing to default + // ShaderLab shader. Go over all of them and make sure ShaderLab shaders are NULL everywhere. + for (std::vector<SInt32>::iterator i = allShaders.begin(); i != allShaders.end(); ++i) + { + Shader *s = PPtr<Shader> (*i); + if (s) + s->ResetInternalPointersToNull(); + } +} + +static void LoadAllShaders() +{ + // Default pink shader is handled specially in shader load/unload because it's shared + // between multiple shader objects. We have to recreate it here. + Shader::LoadDefaultShaderLabShader(); + + std::vector<SInt32> allShaders; + Object::FindAllDerivedObjects (ClassID (Shader), &allShaders); + Shader::RecreateAllShaders(allShaders); +} + +static void UnloadAllComputeShaders() +{ + vector<SInt32> objs; + Object::FindAllDerivedObjects (ClassID (ComputeShader), &objs); + for (size_t i = 0, n = objs.size(); i != n; ++i) + { + ComputeShader* obj = PPtr<ComputeShader> (objs[i]); + obj->UnloadFromGfxDevice(); + } +} + +static void LoadAllComputeShaders() +{ + vector<SInt32> objs; + Object::FindAllDerivedObjects (ClassID (ComputeShader), &objs); + for (size_t i = 0, n = objs.size(); i != n; ++i) + { + ComputeShader* obj = PPtr<ComputeShader> (objs[i]); + obj->ReloadToGfxDevice(); + } +} + +static void UnloadAllMeshes() +{ + vector<SInt32> meshes; + Object::FindAllDerivedObjects (ClassID (Mesh), &meshes, true); + for (size_t i = 0, n = meshes.size(); i != n; ++i) + { + Mesh* mesh = PPtr<Mesh> (meshes[i]); + mesh->UnloadVBOFromGfxDevice(); + } +} + +static void LoadAllMeshes() +{ + vector<SInt32> meshes; + Object::FindAllDerivedObjects (ClassID (Mesh), &meshes, true); + for (size_t i = 0, n = meshes.size(); i != n; ++i) + { + Mesh* mesh = PPtr<Mesh> (meshes[i]); + mesh->ReloadVBOToGfxDevice(); + } +} + +// Note: nothing needs to be done to "unload" fonts +static void LoadAllFonts() +{ + vector<SInt32> fonts; + Object::FindAllDerivedObjects (ClassID (Font), &fonts, true); + for (size_t i = 0, n = fonts.size(); i != n; ++i) + { + Font* font = PPtr<Font> (fonts[i]); + font->ResetCachedTexture(); + } +} + +static void UnloadAllSkins() +{ + vector<SInt32> skins; + Object::FindAllDerivedObjects (ClassID (SkinnedMeshRenderer), &skins, true); + for (size_t i = 0, n = skins.size(); i != n; ++i) + { + SkinnedMeshRenderer* skin = PPtr<SkinnedMeshRenderer> (skins[i]); + skin->UnloadVBOFromGfxDevice(); + } +} + +static void LoadAllSkins() +{ + vector<SInt32> skins; + Object::FindAllDerivedObjects (ClassID (SkinnedMeshRenderer), &skins, true); + for (size_t i = 0, n = skins.size(); i != n; ++i) + { + SkinnedMeshRenderer* skin = PPtr<SkinnedMeshRenderer> (skins[i]); + skin->ReloadVBOToGfxDevice(); + } +} + + +static void UnloadAllCloths() +{ +# if ENABLE_CLOTH + vector<SInt32> cloths; + Object::FindAllDerivedObjects (ClassID (ClothRenderer), &cloths, true); + for (size_t i = 0, n = cloths.size(); i != n; ++i) + { + ClothRenderer* cloth = PPtr<ClothRenderer> (cloths[i]); + cloth->UnloadVBOFromGfxDevice(); + } +# endif // #if ENABLE_CLOTH +} + +static void LoadAllCloths() +{ +# if ENABLE_CLOTH + vector<SInt32> cloths; + Object::FindAllDerivedObjects (ClassID (ClothRenderer), &cloths, true); + for (size_t i = 0, n = cloths.size(); i != n; ++i) + { + ClothRenderer* cloth = PPtr<ClothRenderer> (cloths[i]); + cloth->ReloadVBOToGfxDevice(); + } +# endif // #if ENABLE_CLOTH +} + +#if ENABLE_TERRAIN +static void UnloadAllTerrains() +{ + GetITerrainManager()->UnloadTerrainsFromGfxDevice(); +} + +static void LoadAllTerrains() +{ + GetITerrainManager()->ReloadTerrainsToGfxDevice(); +} +#endif + +static void AwakeFromLoadTextMeshes() +{ + vector<SInt32> textMeshes; + Object::FindAllDerivedObjects (ClassID (TextMesh), &textMeshes, true); + for (size_t i = 0, n = textMeshes.size(); i != n; ++i) + { + TextMesh* textMesh = PPtr<TextMesh> (textMeshes[i]); + textMesh->AwakeFromLoad(kDefaultAwakeFromLoad); + } +} + +void CleanupAllGfxDeviceResources() +{ + #if UNITY_EDITOR && UNITY_WIN // GfxWindow thing only exists on Windows right now + ReleaseGfxWindowOnAllGUIViews(); + #endif + + TextMeshGenerator2::Flush(); + RenderTexture::ReleaseAll(); + ComputeBuffer::UnloadAllFromGfxDevice(); + UnloadAllComputeShaders(); + UnloadAllCloths(); + UnloadAllSkins(); + UnloadAllShaders(); + UnloadAllTextures(); + UnloadAllMeshes(); + +#if ENABLE_TERRAIN + UnloadAllTerrains(); +#endif + +#if ENABLE_PROFILER + UnityProfiler::CleanupGfx(); +#endif + + GetGfxDevice().FinishRendering(); + + DestroyGfxDevice(); +} + +void RecreateAllGfxDeviceResources() +{ + // Reinitialize graphics caps + gGraphicsCaps = GraphicsCaps(); + #if UNITY_EDITOR + gGraphicsCaps.ResetOriginalEmulationCaps(); + #endif + + InitializeGfxDevice(); + + LoadAllMeshes(); + LoadAllTextures(); + LoadAllShaders(); + LoadAllFonts(); + LoadAllSkins(); + LoadAllCloths(); + LoadAllComputeShaders(); + ComputeBuffer::ReloadAllToGfxDevice(); + +#if ENABLE_TERRAIN + LoadAllTerrains(); +#endif + + // Neet to re-setup buit-in texture props on the new gfx device + builtintex::ReinitBuiltinTextures(); + + // Need to re-setup fog values etc. + GetRenderSettings().AwakeFromLoad(kDefaultAwakeFromLoad); + + // Resetup text meshes, because dynamic font textures were reset + AwakeFromLoadTextMeshes(); + + #if UNITY_EDITOR && UNITY_WIN // GfxWindow thing only exists on Windows right now + GetApplication().UpdateMainWindowTitle(); + CreateGfxWindowOnAllGUIViews(); + GUIView::RepaintAll(true); + #endif + + // Reload current scene in the editor, so that any scripts that depend on the gfx device + // capabilities are reinitialized. + #if UNITY_EDITOR + GetApplication().OpenScene(GetApplication().GetCurrentScene()); + #endif +} + +void RecreateGfxDevice() +{ + CleanupAllGfxDeviceResources(); + RecreateAllGfxDeviceResources(); +} + +void RecreateSkinnedMeshResources() +{ + UnloadAllSkins(); + LoadAllSkins(); +} + diff --git a/Runtime/GfxDevice/GfxDeviceRecreate.h b/Runtime/GfxDevice/GfxDeviceRecreate.h new file mode 100644 index 0000000..9dce6ac --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceRecreate.h @@ -0,0 +1,10 @@ +#pragma once + +// Cleanup and recreate as separate steps +void CleanupAllGfxDeviceResources(); +void RecreateAllGfxDeviceResources(); + +// Cleanup and recreate as a single step +void RecreateGfxDevice(); + +void RecreateSkinnedMeshResources(); diff --git a/Runtime/GfxDevice/GfxDeviceResources.h b/Runtime/GfxDevice/GfxDeviceResources.h new file mode 100644 index 0000000..9cb7825 --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceResources.h @@ -0,0 +1,129 @@ +#pragma once + +#include "GfxDeviceTypes.h" + +template<typename T> +struct memcmp_less +{ + bool operator () (const T& lhs, const T& rhs) const + { + return memcmp(&lhs, &rhs, sizeof(T)) < 0; + } +}; + + +struct GfxBlendState +{ + BlendMode srcBlend; + BlendMode dstBlend; + BlendMode srcBlendAlpha; + BlendMode dstBlendAlpha; + BlendOp blendOp; + BlendOp blendOpAlpha; + UInt32 renderTargetWriteMask; + CompareFunction alphaTest; + bool alphaToMask; + + GfxBlendState() + { + memset(this, 0, sizeof(*this)); + srcBlend = kBlendOne; + dstBlend = kBlendZero; + srcBlendAlpha = kBlendOne; + dstBlendAlpha = kBlendZero; + blendOp = kBlendOpAdd; + blendOpAlpha = kBlendOpAdd; + renderTargetWriteMask = KColorWriteAll; + alphaTest = kFuncDisabled; + alphaToMask = false; + } +}; + + +struct GfxRasterState +{ + CullMode cullMode; + int depthBias; + float slopeScaledDepthBias; + + GfxRasterState() + { + memset(this, 0, sizeof(*this)); + cullMode = kCullBack; + depthBias = 0; + slopeScaledDepthBias = 0.0f; + } +}; + + +struct GfxDepthState +{ + bool depthWrite; + CompareFunction depthFunc; + + GfxDepthState() + { + memset(this, 0, sizeof(*this)); + depthWrite = true; + depthFunc = kFuncLess; + } +}; + +struct GfxStencilState +{ + bool stencilEnable; + UInt8 readMask; + UInt8 writeMask; + CompareFunction stencilFuncFront; + StencilOp stencilPassOpFront; // stencil and depth pass + StencilOp stencilFailOpFront; // stencil fail (depth irrelevant) + StencilOp stencilZFailOpFront; // stencil pass, depth fail + CompareFunction stencilFuncBack; + StencilOp stencilPassOpBack; + StencilOp stencilFailOpBack; + StencilOp stencilZFailOpBack; + + GfxStencilState() + { + memset(this, 0, sizeof(*this)); + stencilEnable = false; + readMask = 0xFF; + writeMask = 0xFF; + stencilFuncFront = kFuncAlways; + stencilFailOpFront = kStencilOpKeep; + stencilZFailOpFront = kStencilOpKeep; + stencilPassOpFront = kStencilOpKeep; + stencilFuncBack = kFuncAlways; + stencilFailOpBack = kStencilOpKeep; + stencilZFailOpBack = kStencilOpKeep; + stencilPassOpBack = kStencilOpKeep; + } +}; + +struct DeviceBlendState +{ + DeviceBlendState(const GfxBlendState& src) : sourceState(src) {} + DeviceBlendState() {} + GfxBlendState sourceState; +}; + +struct DeviceDepthState +{ + DeviceDepthState(const GfxDepthState& src) : sourceState(src) {} + DeviceDepthState() {} + GfxDepthState sourceState; +}; + +struct DeviceStencilState +{ + DeviceStencilState(const GfxStencilState& src) : sourceState(src) {} + DeviceStencilState() {} + GfxStencilState sourceState; +}; + +struct DeviceRasterState +{ + DeviceRasterState(const GfxRasterState& src) : sourceState(src) {} + DeviceRasterState() {} + GfxRasterState sourceState; +}; diff --git a/Runtime/GfxDevice/GfxDeviceSetup.cpp b/Runtime/GfxDevice/GfxDeviceSetup.cpp new file mode 100644 index 0000000..1ce7fa7 --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceSetup.cpp @@ -0,0 +1,396 @@ +#include "UnityPrefix.h" +#include "GfxDeviceSetup.h" +#include "GfxDevice.h" +#include "threaded/GfxDeviceClient.h" +#include "Configuration/UnityConfigure.h" +#include "../Misc/SystemInfo.h" +#include "Runtime/Utilities/Argv.h" +#include "Runtime/Misc/PlayerSettings.h" +#include "Runtime/Misc/BuildSettings.h" +#if UNITY_WIN +#include "Runtime/GfxDevice/opengl/GLContext.h" +#if GFX_SUPPORTS_D3D9 +#include "Runtime/GfxDevice/d3d/D3D9Context.h" +#endif +#include "PlatformDependent/Win/WinUtils.h" +#include "PlatformDependent/Win/WinUnicode.h" +#endif +#if UNITY_WII +#include "PlatformDependent/wii/WiiDeviceContext.h" +#endif +#if GFX_SUPPORTS_GCM +#include "PS3/GfxDevicePS3.h" +#endif +#if UNITY_EDITOR +#include "Runtime/Utilities/PlayerPrefs.h" +#endif + +#if ENABLE_FORCE_GFX_RENDERER +GfxDeviceRenderer g_ForcedGfxRenderer = (GfxDeviceRenderer)-1; +#if GFX_SUPPORTS_D3D9 +bool g_ForceD3D9RefDevice; +#endif +#endif + +GfxThreadingMode g_ForcedGfxThreadingMode = kGfxThreadingModeAutoDetect; + + +#if GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30 +int gDefaultFBO = -1; +#endif + + +bool IsThreadableGfxDevice (GfxDeviceRenderer renderer) +{ + switch (renderer) { + case kGfxRendererD3D9: + case kGfxRendererD3D11: +#if UNITY_WIN || UNITY_LINUX || UNITY_ANDROID + // Multithreaded gles30 renderer currently only tested on windows simulator + case kGfxRendererOpenGLES30: +#endif +#if UNITY_ANDROID + case kGfxRendererOpenGLES20Mobile: +#endif +#if !UNITY_WIN + // Multithreaded OpenGL is broken in Windows editor/player + // Editor used to work when creating real GfxDevice on render thread + case kGfxRendererOpenGL: +#endif + case kGfxRendererXenon: + return true; + default: + break; + } + return false; +} + +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT +GfxDevice* CreateRealGfxDevice (GfxDeviceRenderer renderer, bool forceRef) +{ + #if GFX_SUPPORTS_D3D9 + if (renderer == kGfxRendererD3D9) + { + GfxThreadableDevice* CreateD3D9GfxDevice(bool forceREF); + return CreateD3D9GfxDevice(forceRef); + } + #endif + #if GFX_SUPPORTS_OPENGL + if (renderer == kGfxRendererOpenGL) + { + GfxThreadableDevice* CreateGLGfxDevice(); + return CreateGLGfxDevice(); + } + #endif + #if GFX_SUPPORTS_XENON + if (renderer == kGfxRendererXenon) + { + GfxThreadableDevice* CreateXenonGfxDevice(); + return CreateXenonGfxDevice(); + } + #endif + + #if GFX_SUPPORTS_D3D11 + if (renderer == kGfxRendererD3D11) + { + GfxDevice* CreateD3D11GfxDevice(); + return CreateD3D11GfxDevice(); + } + #endif + + #if GFX_SUPPORTS_NULL + if (renderer == kGfxRendererNull) + { + GfxDevice* CreateNullGfxDevice(); + return CreateNullGfxDevice(); + } + #endif + + #if GFX_SUPPORTS_OPENGLES20 + if (renderer == kGfxRendererOpenGLES20Mobile) + { + extern GfxDevice* CreateGLES20GfxDevice(); + return CreateGLES20GfxDevice(); + } + #endif + + #if GFX_SUPPORTS_OPENGLES30 + if (renderer = kGfxRendererOpenGLES30) + { + extern GfxDevice* CreateGLES30GfxDevice(); + return CreateGLES30GfxDevice(); + } + #endif + + AssertString ("should not happen"); + return NULL; +} +#endif + +void ParseGfxDeviceArgs () +{ + // multithreading modes + if (HasARGV("force-gfx-direct")) + { + ::g_ForcedGfxThreadingMode = kGfxThreadingModeDirect; + } + else if (HasARGV("force-gfx-st")) + { + ::g_ForcedGfxThreadingMode = kGfxThreadingModeNonThreaded; + } + else if (HasARGV("force-gfx-mt")) + { + ::g_ForcedGfxThreadingMode = kGfxThreadingModeThreaded; + } + + // forced gfx device types + #if ENABLE_FORCE_GFX_RENDERER + + #if GFX_SUPPORTS_D3D9 + if (HasARGV ("force-d3d9")) + ::g_ForcedGfxRenderer = kGfxRendererD3D9; + #endif + #if GFX_SUPPORTS_OPENGL + if (HasARGV ("force-opengl")) + ::g_ForcedGfxRenderer = kGfxRendererOpenGL; + #endif + #if GFX_SUPPORTS_D3D11 + if (HasARGV ("force-d3d11")) + ::g_ForcedGfxRenderer = kGfxRendererD3D11; + #endif + #if GFX_SUPPORTS_OPENGLES20 + if (HasARGV ("force-gles20")) + ::g_ForcedGfxRenderer = kGfxRendererOpenGLES20Mobile; + #endif + #if GFX_SUPPORTS_OPENGLES30 + if (HasARGV ("force-gles30")) + ::g_ForcedGfxRenderer = kGfxRendererOpenGLES30; + #endif + #if GFX_SUPPORTS_D3D9 + if (HasARGV("force-d3d9-ref")) + ::g_ForceD3D9RefDevice = true; + #endif + + #endif // ENABLE_FORCE_GFX_RENDERER +} + +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_WORKER +bool InitializeGfxDeviceWorkerProcess(size_t size, void *buffer) +{ + Assert (!IsGfxDevice()); + GfxDevice* device = NULL; + device = CreateClientGfxDevice (kGfxRendererOpenGL, kClientDeviceThreaded | kClientDeviceWorkerProcess, size, buffer); + SetGfxDevice(device); + + // hack to make sure FastPropertyNames are initialized on the Worker process. + ShaderLab::FastPropertyName name; + name.SetName(""); + + return device != NULL; +} +#endif + +bool InitializeGfxDevice() +{ + Assert (!IsGfxDevice()); + GfxDevice* device = NULL; + PlayerSettings* playerSettings = GetPlayerSettingsPtr(); + + #if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + + device = CreateClientGfxDevice (kGfxRendererOpenGL, kClientDeviceThreaded | kClientDeviceClientProcess); + + #else //ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + + #if ENABLE_MULTITHREADED_CODE && !UNITY_WP8 + + // Device threading mode and flags + #if !UNITY_WIN && !UNITY_OSX && !UNITY_XENON && !UNITY_LINUX && !UNITY_ANDROID + g_ForcedGfxThreadingMode = kGfxThreadingModeDirect; // direct device everywhere except where it isn't + #endif + + bool threaded = systeminfo::GetProcessorCount() > 1; // default to MT rendering on multicore + #if WEBPLUG + threaded = false; // for now, don't use MT rendering in web player; needs way more testing + #endif + #if !WEBPLUG + if (!IsHumanControllingUs()) + threaded = false; // in automated/batchmode, default to non threaded + #endif + + #if UNITY_XENON || UNITY_ANDROID + if (playerSettings && playerSettings->GetMTRenderingRuntime() == false) + threaded = false; // disabled by the user + #endif + + #if UNITY_WIN && UNITY_EDITOR + if (systeminfo::GetOperatingSystemNumeric() < 600 && g_ForcedGfxThreadingMode == kGfxThreadingModeAutoDetect) + { + printf_console("Disabled multithreaded rendering due to old version of Windows.\n"\ + "Changing input language can cause lockups with versions before Vista.\n"\ + "Use -force-gfx-mt option on the command line to override.\n"); + threaded = false; + } + #endif + + if (g_ForcedGfxThreadingMode == kGfxThreadingModeThreaded) + threaded = true; + else if (g_ForcedGfxThreadingMode == kGfxThreadingModeNonThreaded) + threaded = false; + + UInt32 deviceFlags = 0; + + if (threaded) deviceFlags |= kClientDeviceThreaded; + if (g_ForcedGfxThreadingMode == kGfxThreadingModeDirect) deviceFlags |= kClientDeviceUseRealDevice; + #if GFX_SUPPORTS_D3D9 && ENABLE_FORCE_GFX_RENDERER + if (g_ForceD3D9RefDevice) deviceFlags |= kClientDeviceForceRef; + #endif + + #endif + + +#if ENABLE_FORCE_GFX_RENDERER + +if (g_ForcedGfxRenderer >= 0) +{ + printf_console ("Forcing GfxDevice: %d\n", g_ForcedGfxRenderer); + if (!IsThreadableGfxDevice(g_ForcedGfxRenderer)) + deviceFlags |= kClientDeviceUseRealDevice; + device = CreateClientGfxDevice (g_ForcedGfxRenderer, deviceFlags); +} +#endif + + #if UNITY_WP8 + + device = CreateRealGfxDevice (kGfxRendererD3D11, false); + + #elif UNITY_WIN + // -------- Windows ----------------------------------------------------- + + // Try D3D11 if project was built with support for that + #if GFX_SUPPORTS_D3D11 + if (!device && (UNITY_WINRT || (playerSettings && playerSettings->GetUseDX11()))) + { + if (!IsThreadableGfxDevice(kGfxRendererD3D11)) + deviceFlags |= kClientDeviceUseRealDevice; + device = CreateClientGfxDevice (kGfxRendererD3D11, deviceFlags); + } + #endif + + // Try D3D9 + #if GFX_SUPPORTS_D3D9 + if (!device) + { + device = CreateClientGfxDevice (kGfxRendererD3D9, deviceFlags); + if (!device & (deviceFlags & kClientDeviceForceRef)) + { + winutils::AddErrorMessage( "Failed to initialize Direct3D 9 REF device.\r\nMake sure you have DX9 SDK installed." ); + return false; + } + } + #endif + + if (!device) + { + // Try OpenGL. Editor is dx only unless you force GL + #if GFX_SUPPORTS_OPENGL && !UNITY_EDITOR + printf_console( "D3D9 initialization failed, trying OpenGL\n" ); + device = CreateClientGfxDevice (kGfxRendererOpenGL, deviceFlags); + #endif + if (!device) + winutils::AddErrorMessage( "Failed to initialize Direct3D 9.\r\nMake sure you have DirectX 9.0c installed, have drivers for your\r\ngraphics card and have not disabled 3D acceleration\r\nin display settings." ); + } + + + #elif UNITY_OSX + // -------- Mac OS X ----------------------------------------------------- + + device = CreateClientGfxDevice (kGfxRendererOpenGL, deviceFlags); + + #elif UNITY_WII + + GfxDevice* CreateWiiGfxDevice(); + device = CreateWiiGfxDevice(); + + #elif UNITY_XENON + + GfxThreadableDevice* CreateXenonGfxDevice(); + device = CreateClientGfxDevice(kGfxRendererXenon, deviceFlags); + + #elif UNITY_PS3 + + GfxDevice* CreateGCMGfxDevice(); + device = CreateGCMGfxDevice(); + SetGfxDevice(device); + ((GfxDevicePS3*)device)->Init(); + + #elif UNITY_IPHONE + + extern GfxDevice* CreateUniversalGLESGfxDevice(); + device = CreateUniversalGLESGfxDevice(); + + #elif UNITY_ANDROID + + if (!device) + { + GfxDeviceRenderer renderer = + playerSettings->GetTargetGlesGraphics() + 1 == 2 ? kGfxRendererOpenGLES20Mobile : + playerSettings->GetTargetGlesGraphics() + 1 == 3 ? kGfxRendererOpenGLES30 : + kGfxRendererNull; + + if (!IsThreadableGfxDevice(renderer)) + deviceFlags |= kClientDeviceUseRealDevice; + device = CreateClientGfxDevice(renderer, deviceFlags); + } + + #elif UNITY_BB10 + + GfxDevice* CreateGLES20GfxDevice(); + device = CreateGLES20GfxDevice(); + + #elif UNITY_TIZEN + + GfxDevice* CreateGLES20GfxDevice(); + device = CreateGLES20GfxDevice(); + + #elif UNITY_PEPPER + + GfxDevice* CreateGLES20GfxDevice(); + device = CreateGLES20GfxDevice(); + #elif UNITY_WEBGL + + GfxDevice* CreateGLES20GfxDevice(); + device = CreateGLES20GfxDevice(); + + #elif UNITY_LINUX && GFX_SUPPORTS_OPENGL + + if (NULL == device) { + GfxThreadableDevice* CreateGLGfxDevice(); + device = CreateGLGfxDevice(); + } + + #elif UNITY_LINUX && GFX_SUPPORTS_OPENGLES20 + + GfxDevice* CreateGLES20GfxDevice(); + device = CreateGLES20GfxDevice(); + + #elif UNITY_LINUX && !SUPPORT_X11 + + GfxDevice* CreateNullGfxDevice(); + device = CreateNullGfxDevice(); + + #elif UNITY_FLASH + GfxDevice* CreateMolehillGfxDevice(); + device = CreateMolehillGfxDevice(); + + #else + #error "Unknown platform" + #endif + #endif //ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + + SetGfxDevice(device); + + gGraphicsCaps.SharedCapsPostInitialize (); + + return device != NULL; +} diff --git a/Runtime/GfxDevice/GfxDeviceSetup.h b/Runtime/GfxDevice/GfxDeviceSetup.h new file mode 100644 index 0000000..53efa2f --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceSetup.h @@ -0,0 +1,30 @@ +#pragma once + +#include "GfxDeviceTypes.h" +class GfxDevice; + +bool InitializeGfxDevice(); + +bool InitializeGfxDeviceWorkerProcess(size_t size, void *buffer); + +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT +GfxDevice* CreateRealGfxDevice (GfxDeviceRenderer renderer, bool forceRef); +#endif +bool IsThreadableGfxDevice (GfxDeviceRenderer renderer); +void ParseGfxDeviceArgs (); + +#define ENABLE_FORCE_GFX_RENDERER ((UNITY_WIN && !UNITY_WP8) || UNITY_LINUX || UNITY_ANDROID) + +#if ENABLE_FORCE_GFX_RENDERER +extern GfxDeviceRenderer g_ForcedGfxRenderer; +#if GFX_SUPPORTS_D3D9 +extern bool g_ForceD3D9RefDevice; +#endif +#endif + +extern GfxThreadingMode g_ForcedGfxThreadingMode; + + +#if GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30 +extern int gDefaultFBO; +#endif diff --git a/Runtime/GfxDevice/GfxDeviceStats.cpp b/Runtime/GfxDevice/GfxDeviceStats.cpp new file mode 100644 index 0000000..2b002a0 --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceStats.cpp @@ -0,0 +1,170 @@ +#include "UnityPrefix.h" +#include "GfxDevice.h" +#include "GfxDeviceStats.h" +#include "Runtime/Graphics/Texture.h" +#include "Runtime/Input/TimeManager.h" + +#if UNITY_IPHONE + #include <mach/mach_time.h> +#elif UNITY_ANDROID + #include <sys/time.h> +#endif +#include "Runtime/Profiler/MemoryProfiler.h" + +GfxDeviceStats::GfxDeviceStats() +{ + #if ENABLE_PROFILER + m_StatsEnabled = false; // off by default! + m_ClientFrameTime = 0.0f; + m_RenderFrameTime = 0.0f; + m_EnableStartTime = 0.0; + #endif + + // just initialize to some sane values + SetScreenParams( 64, 64, 4, 4, 4, 0 ); + m_Memory.renderTextureBytes = 0; +} + + +void GfxDeviceStats::StateStats::Reset() +{ + renderTexture = 0; + vboUploads = 0; + vboUploadBytes = 0; + ibUploads = 0; + ibUploadBytes = 0; +} + +void GfxDeviceStats::ClientStats::Reset() +{ + shadowCasters = 0; + + ABSOLUTE_TIME_INIT(cullingDt); + ABSOLUTE_TIME_INIT(clearDt); +} + +void GfxDeviceStats::DrawStats::Reset() +{ + calls = 0; + tris = 0; + trisSent = 0; + verts = 0; + batches = 0; + batchedCalls = 0; + batchedTris = 0; + batchedVerts = 0; + + ABSOLUTE_TIME_INIT(dt); + ABSOLUTE_TIME_INIT(batchDt); + + usedTextureCount = 0; + usedTextureBytes = 0; + + #if ENABLE_PROFILER + usedTextures.clear(); + #endif +} + +void GfxDeviceStats::AccumulateUsedTextureUsage() +{ +#if ENABLE_PROFILER + m_Draw.usedTextureCount += m_Draw.usedTextures.size(); + #if ENABLE_MEM_PROFILER + for (GfxDeviceStats::DrawStats::TextureIDSet::const_iterator i=m_Draw.usedTextures.begin();i != m_Draw.usedTextures.end();i++) + m_Draw.usedTextureBytes += GetMemoryProfiler()->GetRelatedIDMemorySize(i->m_ID); + #endif + m_Draw.usedTextures.clear(); +#endif +} + +void GfxDeviceStats::ResetFrame() +{ + m_Changes.Reset(); + m_Draw.Reset(); + m_Client.Reset(); + #if ENABLE_PROFILER + m_ClientFrameTime = 0.0f; + m_RenderFrameTime = 0.0f; + #endif +} + +void GfxDeviceStats::ResetClientStats() +{ + m_Client.Reset(); + m_ClientFrameTime = 0.0f; +} + +#if ENABLE_PROFILER +void GfxDeviceStats::AddUsedTexture(TextureID tex) +{ + CHECK_STATS_ENABLED + if(m_Draw.usedTextures.find(tex) == m_Draw.usedTextures.end()) + m_Draw.usedTextures.insert(tex); +} +#endif + +void GfxDeviceStats::SetScreenParams( int width, int height, int backbufferBPP, int frontbufferBPP, int depthBPP, int fsaa ) +{ + m_Memory.screenWidth = width; + m_Memory.screenHeight = height; + + // can pass -1 for BPP params to keep current ones + if (frontbufferBPP >= 0) + m_Memory.screenFrontBPP = frontbufferBPP; + if (backbufferBPP >= 0) + m_Memory.screenBackBPP = backbufferBPP; + if (depthBPP >= 0) + m_Memory.screenDepthBPP = depthBPP; + if (fsaa >= 0) + m_Memory.screenFSAA = fsaa; + + m_Memory.screenBytes = width * height * (std::max(m_Memory.screenFSAA,1) * (m_Memory.screenBackBPP + m_Memory.screenDepthBPP) + m_Memory.screenFrontBPP); + //printf_console("set screen params: %ix%i %ixAA mem=%.1fMB\n", width, height, fsaa, m_Memory.screenBytes/1024.0f/1024.0f); +} + +void GfxDeviceStats::BeginFrameStats() +{ + m_StatsEnabled = true; + m_EnableStartTime = GetTimeSinceStartup(); +} + +void GfxDeviceStats::EndClientFrameStats() +{ + m_StatsEnabled = false; + m_ClientFrameTime += GetTimeSinceStartup() - m_EnableStartTime; +} + +void GfxDeviceStats::EndRenderFrameStats() +{ + m_StatsEnabled = false; + m_RenderFrameTime += GetTimeSinceStartup() - m_EnableStartTime; +} + +void GfxDeviceStats::CopyAllDrawStats( const GfxDeviceStats& s ) +{ + m_Draw = s.m_Draw; + m_Changes = s.m_Changes; + m_RenderFrameTime = s.m_RenderFrameTime; +} + +void GfxDeviceStats::CopyClientStats( const GfxDeviceStats& s ) +{ + m_Client = s.m_Client; + m_ClientFrameTime = s.m_ClientFrameTime; +} + +#if UNITY_IPHONE || UNITY_ANDROID +ABSOLUTE_TIME GfxDeviceStats::GetHighResolutionAbsTime () +{ +#if UNITY_IPHONE + return mach_absolute_time (); +#elif UNITY_ANDROID + timespec ts; + clock_gettime (CLOCK_REALTIME, &ts); + long long nanosecs = ts.tv_sec; + nanosecs <<= 32; + nanosecs |= ts.tv_nsec; + return nanosecs; +#endif +} +#endif diff --git a/Runtime/GfxDevice/GfxDeviceStats.h b/Runtime/GfxDevice/GfxDeviceStats.h new file mode 100644 index 0000000..688993c --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceStats.h @@ -0,0 +1,154 @@ +#pragma once + +#include "GfxDeviceTypes.h" +#include "Runtime/Profiler/TimeHelper.h" + +#if UNITY_IPHONE || UNITY_ANDROID || UNITY_WII +#define CHECK_STATS_ENABLED +#else +#define CHECK_STATS_ENABLED if( !m_StatsEnabled ) return; +#endif + +class GfxDeviceStats { +public: + struct StateStats { + void Reset(); + + int renderTexture; + int vboUploads; + int vboUploadBytes; + int ibUploads; + int ibUploadBytes; + }; + struct ClientStats { + // Main thread stats + void Reset(); + + int shadowCasters; + + ABSOLUTE_TIME cullingDt; + ABSOLUTE_TIME clearDt; + }; + struct DrawStats { + // Render thread stats + void Reset(); + + int calls; + int tris, trisSent; + int verts; + int batches; + int batchedCalls; + int batchedTris; + int batchedVerts; + + ABSOLUTE_TIME dt; + ABSOLUTE_TIME batchDt; + + int usedTextureCount; + int usedTextureBytes; + + #if ENABLE_PROFILER + typedef std::set<TextureID, std::less<TextureID>, STL_ALLOCATOR(kMemProfiler, TextureID) > TextureIDSet; + TextureIDSet usedTextures; + #endif + }; + struct MemoryStats { + int screenWidth, screenHeight; + int screenFrontBPP, screenBackBPP, screenDepthBPP; + int screenFSAA; // actual level of anti-aliasing used + int screenBytes; // memory for backbuffer + frontbuffer + SInt64 renderTextureBytes; + }; + + GfxDeviceStats(); + + void AddRenderTextureChange() { CHECK_STATS_ENABLED ++m_Changes.renderTexture; } + void AddUploadVBO(int vertexData) { CHECK_STATS_ENABLED ++m_Changes.vboUploads; m_Changes.vboUploadBytes += vertexData; } + void AddUploadIB(int indexData) { CHECK_STATS_ENABLED ++m_Changes.ibUploads; m_Changes.ibUploadBytes += indexData; } + #if ENABLE_PROFILER + void AddUsedTexture(TextureID tex); + #else + void AddUsedTexture(TextureID tex) {} + #endif + + void AddDrawCall( int tris, int verts, ABSOLUTE_TIME dt, int trisSent = -1) { CHECK_STATS_ENABLED + ++m_Draw.calls; m_Draw.tris += tris; m_Draw.verts += verts; m_Draw.dt = COMBINED_TIME(m_Draw.dt, dt); + m_Draw.trisSent += ((trisSent > 0)? trisSent: tris); + } + void AddDrawCall( int tris, int verts, int trisSent = -1) { CHECK_STATS_ENABLED + ABSOLUTE_TIME dt; + ABSOLUTE_TIME_INIT(dt); + AddDrawCall(tris, verts, dt, trisSent); + } + void AddBatch(int trisSent, int batchedVerts, int batchedCalls, ABSOLUTE_TIME batchDt) { CHECK_STATS_ENABLED + m_Draw.batches++; + m_Draw.batchedCalls += batchedCalls; m_Draw.batchDt = COMBINED_TIME(m_Draw.batchDt, batchDt); + m_Draw.batchedTris += trisSent; + m_Draw.batchedVerts += batchedVerts; + } + void AddCulling(ABSOLUTE_TIME cullingDt) { CHECK_STATS_ENABLED + m_Client.cullingDt = COMBINED_TIME(m_Client.cullingDt, cullingDt); + } + void AddClear(ABSOLUTE_TIME clearDt) { CHECK_STATS_ENABLED + m_Client.clearDt = COMBINED_TIME(m_Client.clearDt, clearDt); + } + void AddShadowCaster() { CHECK_STATS_ENABLED + m_Client.shadowCasters++; + } + void AddShadowCasters(int count) { CHECK_STATS_ENABLED + m_Client.shadowCasters+=count; + } + + + virtual void SetScreenParams( int width, int height, int backbufferBPP, int frontbufferBPP, int depthBPP, int fsaa ); + + void ChangeRenderTextureBytes (int deltaBytes) + { + SInt64 deltaBytes64 = static_cast<SInt64>(deltaBytes); + m_Memory.renderTextureBytes += deltaBytes64; + Assert (m_Memory.renderTextureBytes >= 0); + } + + const StateStats& GetStateChanges() const { return m_Changes; } + const DrawStats& GetDrawStats() const { return m_Draw; } + const ClientStats& GetClientStats() const { return m_Client; } + const MemoryStats& GetMemoryStats() const { return m_Memory; } + + float GetClientFrameTime() const { return m_ClientFrameTime; } + float GetRenderFrameTime() const { return m_RenderFrameTime; } + void AddToClientFrameTime (float dt) { m_ClientFrameTime += dt; } + + // Calculates texture memory usage, and clears the set (to avoid copying the set in multithreaded rendering) + virtual void AccumulateUsedTextureUsage(); + +#if UNITY_IPHONE || UNITY_ANDROID + ABSOLUTE_TIME GetHighResolutionAbsTime (); +#endif + +private: + friend class GfxDevice; + friend class GfxDeviceClient; + friend class GfxDeviceWorker; + + // Changing stats from the application should always be done through the device + void ResetFrame(); + void ResetClientStats(); + void BeginFrameStats(); + void EndClientFrameStats(); + void EndRenderFrameStats(); + + // Saves/restores everything except the memory stats (those have to be properly tracked + // all the time). + void CopyAllDrawStats( const GfxDeviceStats& s ); + void CopyClientStats( const GfxDeviceStats& s ); + +private: + StateStats m_Changes; + DrawStats m_Draw; + ClientStats m_Client; + MemoryStats m_Memory; + double m_EnableStartTime; + float m_ClientFrameTime; + float m_RenderFrameTime; + bool m_StatsEnabled; +}; diff --git a/Runtime/GfxDevice/GfxDeviceTypes.h b/Runtime/GfxDevice/GfxDeviceTypes.h new file mode 100644 index 0000000..9468a7e --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceTypes.h @@ -0,0 +1,616 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" +#include "GfxDeviceConfigure.h" +#include "Runtime/Math/Matrix4x4.h" + +// Never change the enum values! +// They are used in low level native plugin interface. +enum GfxDeviceRenderer +{ + kGfxRendererOpenGL = 0, + kGfxRendererD3D9 = 1, + kGfxRendererD3D11 = 2, + kGfxRendererGCM = 3, + kGfxRendererNull = 4, + kGfxRendererHollywood = 5, + kGfxRendererXenon = 6, + //kGfxRendererOpenGLES = 7, // removed + kGfxRendererOpenGLES20Mobile = 8, + kGfxRendererMolehill = 9, + kGfxRendererOpenGLES20Desktop = 10, + kGfxRendererOpenGLES30 = 11, + kGfxRendererCount = 12 +}; + +enum GfxThreadingMode +{ + kGfxThreadingModeDirect, + kGfxThreadingModeThreaded, + kGfxThreadingModeNonThreaded, + kGfxThreadingModeAutoDetect +}; + +#if UNITY_WIN +typedef HWND NativeWindow; +#else +typedef unsigned long NativeWindow; +#endif + +enum +{ + #if GFX_OPENGLESxx_ONLY || GFX_SUPPORTS_MOLEHILL + kMaxSupportedTextureUnits = 8, + #else + kMaxSupportedTextureUnits = 16, + #endif + kMaxSupportedTextureUnitsGLES = 8, + + kMaxSupportedVertexLights = 8, + kMaxSupportedTextureCoords = 8, + + kMaxSupportedRenderTargets = 4, + kMaxSupportedConstantBuffers = 16, + kMaxSupportedComputeResources = 16, +}; + + +enum TextureDimension +{ + kTexDimUnknown = -1, // unknown + kTexDimNone = 0, // no texture + kTexDimDeprecated1D, // not used anymore, value there for backwards compatibility in serialization + kTexDim2D, + kTexDim3D, + kTexDimCUBE, + kTexDimAny, + + kTexDimCount, // keep this last! + kTexDimForce32Bit = 0x7fffffff +}; + + +// this is kept as UInt32 because it's serialized in some places; to ensure that it's 32 +// bits everywhere. + + +typedef UInt32 TextureFormat; +enum +{ + kTexFormatAlpha8 = 1, + kTexFormatARGB4444 = 2, + kTexFormatRGB24 = 3, + kTexFormatRGBA32 = 4, + kTexFormatARGB32 = 5, + kTexFormatARGBFloat = 6, // only for internal use at runtime + kTexFormatRGB565 = 7, + kTexFormatBGR24 = 8, + // This one is for internal use; storage is 16 bits/pixel; samples + // as Alpha (OpenGL) or RGB (D3D9). Can be reduced to 8 bit alpha/luminance on lower hardware. + // Why it's not Luminance on GL: for some reason alpha seems to be faster. + kTexFormatAlphaLum16 = 9, + kTexFormatDXT1 = 10, + kTexFormatDXT3 = 11, + kTexFormatDXT5 = 12, + kTexFormatRGBA4444 = 13, + + kTexFormatPCCount = 14, + + kTexReserved1 = 14, // Use reservedX when adding a new 'PC' texture format + kTexReserved2 = 15, + kTexReserved3 = 16, + kTexReserved4 = 17, + kTexReserved5 = 18, + kTexReserved6 = 19, + // [20..27] used to be Wii-specific formats before Unity 4.0 + kTexReserved11 = 28, + kTexReserved12 = 29, + + // iPhone + kTexFormatPVRTC_RGB2 = 30, + kTexFormatPVRTC_RGBA2 = 31, + + kTexFormatPVRTC_RGB4 = 32, + kTexFormatPVRTC_RGBA4 = 33, + + kTexFormatETC_RGB4 = 34, + + kTexFormatATC_RGB4 = 35, + kTexFormatATC_RGBA8 = 36, + + // Pixels returned by iPhone camera + kTexFormatBGRA32 = 37, + + kTexFormatFlashATF_RGB_DXT1 = 38, + kTexFormatFlashATF_RGBA_JPG = 39, + kTexFormatFlashATF_RGB_JPG = 40, + + // EAC and ETC2 compressed formats, mandated by OpenGL ES 3.0 + kTexFormatEAC_R = 41, + kTexFormatEAC_R_SIGNED = 42, + kTexFormatEAC_RG = 43, + kTexFormatEAC_RG_SIGNED = 44, + kTexFormatETC2_RGB = 45, + kTexFormatETC2_RGBA1 = 46, + kTexFormatETC2_RGBA8 = 47, + + // ASTC. The RGB and RGBA formats are internally identical, we just need to carry the has-alpha information somehow + kTexFormatASTC_RGB_4x4 = 48, + kTexFormatASTC_RGB_5x5 = 49, + kTexFormatASTC_RGB_6x6 = 50, + kTexFormatASTC_RGB_8x8 = 51, + kTexFormatASTC_RGB_10x10 = 52, + kTexFormatASTC_RGB_12x12 = 53, + + kTexFormatASTC_RGBA_4x4 = 54, + kTexFormatASTC_RGBA_5x5 = 55, + kTexFormatASTC_RGBA_6x6 = 56, + kTexFormatASTC_RGBA_8x8 = 57, + kTexFormatASTC_RGBA_10x10 = 58, + kTexFormatASTC_RGBA_12x12 = 59, + + kTexFormatTotalCount = 60 // keep this last! +}; + + +enum TextureUsageMode +{ + kTexUsageNone = 0, + kTexUsageLightmapDoubleLDR, + kTexUsageLightmapRGBM, + kTexUsageNormalmapDXT5nm, + kTexUsageNormalmapPlain, +}; + + +enum TextureColorSpace +{ + kTexColorSpaceLinear = 0, + kTexColorSpaceSRGB, + kTexColorSpaceSRGBXenon +}; + + +enum TextureFilterMode +{ + kTexFilterNearest = 0, + kTexFilterBilinear, + kTexFilterTrilinear, + kTexFilterCount // keep this last! +}; + + +enum TextureWrapMode +{ + kTexWrapRepeat, + kTexWrapClamp, + kTexWrapCount // keep this last! +}; + + +#if UNITY_EDITOR +// enum values to match 0..100 scale used on some platforms +enum TextureCompressionQuality +{ + kTexCompressionFast = 0, + kTexCompressionNormal = 50, + kTexCompressionBest = 100 +}; +#endif + + +enum RenderTextureFormat +{ + kRTFormatARGB32 = 0, // ARGB, 8 bit/channel + kRTFormatDepth, // whatever is for "depth texture": Depth16 on GL, R32F on D3D9, ... + kRTFormatARGBHalf, // ARGB, 16 bit floating point/channel + kRTFormatShadowMap, // whatever is "native" (with built-in comparisons) shadow map format + kRTFormatRGB565, + kRTFormatARGB4444, + kRTFormatARGB1555, + kRTFormatDefault, + kRTFormatA2R10G10B10, + kRTFormatDefaultHDR, + kRTFormatARGB64, + kRTFormatARGBFloat, + kRTFormatRGFloat, + kRTFormatRGHalf, + kRTFormatRFloat, + kRTFormatRHalf, + kRTFormatR8, + kRTFormatARGBInt, + kRTFormatRGInt, + kRTFormatRInt, + kRTFormatBGRA32, + kRTFormatCount // keep this last! +}; + + +enum RenderTextureReadWrite +{ + kRTReadWriteDefault = 0, // The 'correct' state for the given position in the render pipeline + kRTReadWriteLinear, // No sRGB read / write + kRTReadWriteSRGB, // sRGB read / write + kRTSRGBCount // keep this last! +}; + + +enum DepthBufferFormat +{ + kDepthFormatNone = 0, // no depth buffer + kDepthFormat16, // 16 bit depth buffer + kDepthFormat24, // 24 bit depth buffer + kDepthFormatCount // keep this last! +}; + + +enum SurfaceCreateFlags +{ + // unused (1<<0), + kSurfaceCreateMipmap = (1<<1), + kSurfaceCreateSRGB = (1<<2), + kSurfaceCreateShadowmap = (1<<3), + kSurfaceCreateRandomWrite = (1<<4), + kSurfaceCreateSampleOnly = (1<<5), + kSurfaceCreateNeverUsed = (1<<6), + kSurfaceCreateAutoGenMips = (1<<7), +}; + + +enum StencilOp +{ + kStencilOpKeep = 0, + kStencilOpZero, + kStencilOpReplace, + kStencilOpIncrSat, + kStencilOpDecrSat, + kStencilOpInvert, + kStencilOpIncrWrap, + kStencilOpDecrWrap, + kStencilOpCount +}; + + +enum BlendOp +{ + kBlendOpAdd = 0, + kBlendOpSub, + kBlendOpRevSub, + kBlendOpMin, + kBlendOpMax, + kBlendOpLogicalClear, + kBlendOpLogicalSet, + kBlendOpLogicalCopy, + kBlendOpLogicalCopyInverted, + kBlendOpLogicalNoop, + kBlendOpLogicalInvert, + kBlendOpLogicalAnd, + kBlendOpLogicalNand, + kBlendOpLogicalOr, + kBlendOpLogicalNor, + kBlendOpLogicalXor, + kBlendOpLogicalEquiv, + kBlendOpLogicalAndReverse, + kBlendOpLogicalAndInverted, + kBlendOpLogicalOrReverse, + kBlendOpLogicalOrInverted, + kBlendOpCount, +}; + + +enum BlendMode +{ + kBlendZero = 0, + kBlendOne, + kBlendDstColor, + kBlendSrcColor, + kBlendOneMinusDstColor, + kBlendSrcAlpha, + kBlendOneMinusSrcColor, + kBlendDstAlpha, + kBlendOneMinusDstAlpha, + kBlendSrcAlphaSaturate, + kBlendOneMinusSrcAlpha, + kBlendCount +}; + + +enum CompareFunction +{ + kFuncUnknown = -1, + kFuncDisabled = 0, + kFuncNever, + kFuncLess, + kFuncEqual, + kFuncLEqual, + kFuncGreater, + kFuncNotEqual, + kFuncGEqual, + kFuncAlways, + kFuncCount +}; + + +enum CullMode +{ + kCullUnknown = -1, + kCullOff = 0, + kCullFront, + kCullBack, + kCullCount +}; + + +enum ColorWriteMask +{ + kColorWriteA = 1, + kColorWriteB = 2, + kColorWriteG = 4, + kColorWriteR = 8, + KColorWriteAll = (kColorWriteR|kColorWriteG|kColorWriteB|kColorWriteA) +}; + + +enum ColorMaterialMode +{ + kColorMatUnknown = -1, + kColorMatDisabled = 0, + kColorMatEmission, + kColorMatAmbientAndDiffuse, + kColorMatTypeCount +}; + + +enum TexGenMode +{ + kTexGenUnknown = -1, + kTexGenDisabled = 0, + kTexGenSphereMap, // Spherical reflection map + kTexGenObject, // Object space + kTexGenEyeLinear, // Projected Eye space + kTexGenCubeReflect, // Cubemap reflection calculation + kTexGenCubeNormal, // Cubemap normal calculation + kTexGenCount +}; + + +enum ShaderType // bit masks! +{ + kShaderNone = 0, + kShaderVertex = 1, + kShaderFragment = 2, + kShaderGeometry = 3, + kShaderHull = 4, + kShaderDomain = 5, + kShaderTypeCount // keep this last! +}; + +enum ShaderImplType +{ + kShaderImplUndefined = -1, + + // Must match ShaderType! + kShaderImplVertex = 1, // Vertex shader + kShaderImplFragment = 2, // Fragment shader + kShaderImplGeometry = 3, + kShaderImplHull = 4, + kShaderImplDomain = 5, + + + kShaderImplBoth = 6, // Vertex+fragment (e.g. GLSL) +}; + + +enum ShaderParamType +{ + kShaderParamFloat = 0, + kShaderParamInt, + kShaderParamBool, + kShaderParamTypeCount +}; + + +// Ordering is like this so it matches valid D3D9 FVF layouts +// Range must fit into an SInt8 +enum ShaderChannel +{ + kShaderChannelNone = -1, + kShaderChannelVertex = 0, // Vertex (vector3) + kShaderChannelNormal, // Normal (vector3) + kShaderChannelColor, // Vertex color + kShaderChannelTexCoord0, // UV set 0 (vector2) + kShaderChannelTexCoord1, // UV set 1 (vector2) + kShaderChannelTangent, // Tangent (vector4) + kShaderChannelCount, // Keep this last! +}; + + +enum ShaderChannelMask +{ + kShaderChannelsAll = ( (1<<kShaderChannelVertex) | (1<<kShaderChannelNormal) | (1<<kShaderChannelColor) | (1<<kShaderChannelTexCoord0) | (1<<kShaderChannelTexCoord1) | (1<<kShaderChannelTangent) ), + kShaderChannelsHot = ( (1<<kShaderChannelVertex) | (1<<kShaderChannelNormal) | (1<<kShaderChannelTangent) ), + kShaderChannelsCold= ( (1<<kShaderChannelColor) | (1<<kShaderChannelTexCoord0) | (1<<kShaderChannelTexCoord1) ), +}; + + +enum VertexComponent +{ + kVertexCompNone = 0, + kVertexCompVertex, + kVertexCompColor, + kVertexCompNormal, + kVertexCompTexCoord, + kVertexCompTexCoord0, kVertexCompTexCoord1, kVertexCompTexCoord2, kVertexCompTexCoord3, + kVertexCompTexCoord4, kVertexCompTexCoord5, kVertexCompTexCoord6, kVertexCompTexCoord7, + kVertexCompAttrib0, kVertexCompAttrib1, kVertexCompAttrib2, kVertexCompAttrib3, + kVertexCompAttrib4, kVertexCompAttrib5, kVertexCompAttrib6, kVertexCompAttrib7, + kVertexCompAttrib8, kVertexCompAttrib9, kVertexCompAttrib10, kVertexCompAttrib11, + kVertexCompAttrib12, kVertexCompAttrib13, kVertexCompAttrib14, kVertexCompAttrib15, + kVertexCompCount // keep this last! +}; + + +enum VertexChannelFormat +{ + kChannelFormatFloat = 0, + kChannelFormatFloat16, + kChannelFormatColor, + kChannelFormatByte, + kChannelFormatCount +}; + + +enum FogMode +{ + kFogUnknown = -1, + kFogDisabled = 0, + kFogLinear, + kFogExp, + kFogExp2, + kFogModeCount // keep this last! +}; + + +enum NormalizationMode +{ + kNormalizationUnknown = -1, + kNormalizationDisabled = 0, + kNormalizationScale = 1, // = kUniformScaleTransform, + kNormalizationFull = 2 // = kNonUniformScaleTransform +}; + + +enum CubemapFace +{ + kCubeFaceUnknown = -1, + kCubeFacePX = 0, + kCubeFaceNX, + kCubeFacePY, + kCubeFaceNY, + kCubeFacePZ, + kCubeFaceNZ, +}; + + +enum GfxPrimitiveType +{ + kPrimitiveTriangles = 0, + kPrimitiveTriangleStripDeprecated, + kPrimitiveQuads, + kPrimitiveLines, + kPrimitiveLineStrip, + kPrimitivePoints, + + kPrimitiveTypeCount, // keep this last! + kPrimitiveForce32BitInt = 0x7fffffff // force 32 bit enum size +}; + + +enum GfxImmediateType +{ + kImmediateVertex, + kImmediateNormal, + kImmediateColor, + kImmediateTexCoordAll, + kImmediateTexCoord, +}; + + +enum GfxClearFlags +{ + kGfxClearColor = (1<<0), + kGfxClearDepth = (1<<1), + kGfxClearStencil = (1<<2), + kGfxClearDepthStencil = kGfxClearDepth | kGfxClearStencil, + kGfxClearAll = kGfxClearColor | kGfxClearDepth | kGfxClearStencil, +}; + + +struct TextureID +{ + explicit TextureID() : m_ID(0) { } + explicit TextureID(unsigned int i) : m_ID(i) { } + bool operator==(const TextureID& o) const { return m_ID==o.m_ID; } + bool operator!=(const TextureID& o) const { return m_ID!=o.m_ID; } + bool operator < (const TextureID& o) const { return m_ID<o.m_ID; } + unsigned int m_ID; +}; + + +struct ComputeBufferID { + explicit ComputeBufferID() : m_ID(0) { } + explicit ComputeBufferID(unsigned int i) : m_ID(i) { } + bool IsValid() const { return m_ID != 0; } + bool operator==(const ComputeBufferID& o) const { return m_ID==o.m_ID; } + bool operator!=(const ComputeBufferID& o) const { return m_ID!=o.m_ID; } + bool operator < (const ComputeBufferID& o) const { return m_ID<o.m_ID; } + unsigned int m_ID; +}; + + +#define VERTEX_FORMAT1(a) (1 << kShaderChannel##a) +#define VERTEX_FORMAT2(a,b) ((1 << kShaderChannel##a) | (1 << kShaderChannel##b)) +#define VERTEX_FORMAT3(a,b,c) ((1 << kShaderChannel##a) | (1 << kShaderChannel##b) | (1 << kShaderChannel##c)) +#define VERTEX_FORMAT4(a,b,c,d) ((1 << kShaderChannel##a) | (1 << kShaderChannel##b) | (1 << kShaderChannel##c) | (1 << kShaderChannel##d)) +#define VERTEX_FORMAT5(a,b,c,d,e) ((1 << kShaderChannel##a) | (1 << kShaderChannel##b) | (1 << kShaderChannel##c) | (1 << kShaderChannel##d) | (1 << kShaderChannel##e)) +#define VERTEX_FORMAT6(a,b,c,d,e,f) ((1 << kShaderChannel##a) | (1 << kShaderChannel##b) | (1 << kShaderChannel##c) | (1 << kShaderChannel##d) | (1 << kShaderChannel##e) | (1 << kShaderChannel##f)) + +#define kMaxVertexStreams 4 + + +enum ComputeBufferFlags +{ + kCBFlagNone = 0, + kCBFlagRaw = (1<<0), + kCBFlagAppend = (1<<1), + kCBFlagCounter = (1<<2), + kCBFlagTypeMask = kCBFlagRaw | kCBFlagAppend | kCBFlagCounter, + + kCBFlagDrawIndirect = (1<<8), +}; + +enum BuiltinSamplerState +{ + kSamplerPointClamp = 0, + kSamplerLinearClamp, + kSamplerPointRepeat, + kSamplerLinearRepeat, + + kBuiltinSamplerStateCount, // keep this last! + kBuiltinSamplerStateForce32Bit = 0x7fffffff +}; + +struct TexEnvProperties +{ + TextureID textureID; // 4 + int texturePropertyID; // 4 + float mipBias; // 4 + UInt32 texDim : 4; // 4 + UInt32 texGen : 4; + UInt32 identityMatrix : 1; + // ---- 16 bytes +}; + +struct TexEnvData : public TexEnvProperties // 16 +{ + Matrix4x4f matrix; // 64 + // ---- 80 bytes +}; + +#if !UNITY_SPU +#include "GfxDeviceResources.h" +#endif + +#if UNITY_XENON +enum HiZstate +{ + kHiZDisable = 0, + kHiZEnable, + kHiZAuto +}; +enum HiSflush +{ + kHiSflush_async = 0, + kHiSflush_sync +}; +#endif diff --git a/Runtime/GfxDevice/GfxDeviceWindow.cpp b/Runtime/GfxDevice/GfxDeviceWindow.cpp new file mode 100644 index 0000000..c6e4933 --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceWindow.cpp @@ -0,0 +1,55 @@ +#include "UnityPrefix.h" +#include "GfxDeviceWindow.h" + + +GfxDeviceWindow::GfxDeviceWindow (NativeWindow window, int width, int height, DepthBufferFormat depthFormat, int antiAlias) + : m_Window (window) + , m_Width (0) + , m_Height (0) + , m_InvalidState (true) + , m_CanUseBlitOptimization (false) +{ + //Reshape (width, height, depthFormat, antiAlias); +} + +GfxDeviceWindow::~GfxDeviceWindow () +{ +} + +bool GfxDeviceWindow::Reshape (int width, int height, DepthBufferFormat depthFormat, int antiAlias) +{ + m_InvalidState = false; + + AssertIf (!m_Window); + + m_Width = width; + m_Height = height; + + if (m_Width <= 0 || m_Height <= 0) + { + m_InvalidState = true; + } + + return !m_InvalidState; +} + + +bool GfxDeviceWindow::BeginRendering () +{ + if (m_InvalidState) + { + return false; + } + + return true; +} + +bool GfxDeviceWindow::EndRendering (bool presentContent) +{ + if (m_InvalidState) + { + return false; + } + + return true; +} diff --git a/Runtime/GfxDevice/GfxDeviceWindow.h b/Runtime/GfxDevice/GfxDeviceWindow.h new file mode 100644 index 0000000..0b8b022 --- /dev/null +++ b/Runtime/GfxDevice/GfxDeviceWindow.h @@ -0,0 +1,36 @@ +#ifndef GFXDEVICEWINDOW_H +#define GFXDEVICEWINDOW_H + +#include "GfxDeviceTypes.h" + +class GfxDeviceWindow +{ +protected: + NativeWindow m_Window; + int m_Width; + int m_Height; + bool m_InvalidState; + bool m_CanUseBlitOptimization; +public: + GfxDeviceWindow (NativeWindow window, int width, int height, DepthBufferFormat depthFormat, int antiAlias); + virtual ~GfxDeviceWindow(); + + //Returns true if reshaping was successful + virtual bool Reshape( int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + + //Returns true if succeeded to prepare for rendering + virtual bool BeginRendering(); + + virtual void SetAsActiveWindow () { }; + + //Returns true if succeeded to finish rendering + virtual bool EndRendering( bool presentContent ); + + inline bool CanUseBlitOptimization() const { return m_CanUseBlitOptimization; } + + inline int GetWidth() const { return m_Width; } + inline int GetHeight() const { return m_Height; } + inline NativeWindow GetHandle () const { return m_Window; } +}; + +#endif diff --git a/Runtime/GfxDevice/GfxDisplayList.h b/Runtime/GfxDevice/GfxDisplayList.h new file mode 100644 index 0000000..d245abf --- /dev/null +++ b/Runtime/GfxDevice/GfxDisplayList.h @@ -0,0 +1,9 @@ +#pragma once + +#include "Runtime/Threads/ThreadSharedObject.h" + +class GfxDisplayList : public ThreadSharedObject +{ +public: + virtual void Call() = 0; +}; diff --git a/Runtime/GfxDevice/GfxPatchInfo.cpp b/Runtime/GfxDevice/GfxPatchInfo.cpp new file mode 100644 index 0000000..8ba76f1 --- /dev/null +++ b/Runtime/GfxDevice/GfxPatchInfo.cpp @@ -0,0 +1,99 @@ +#include "UnityPrefix.h" +#include "GfxPatchInfo.h" +#include "External/shaderlab/Library/shaderlab.h" + + +void GfxPatchInfo::Reset() +{ + for (int pt = 0; pt < GfxPatch::kTypeCount; pt++) + m_Patches[pt].resize_uninitialized(0); + m_TexEnvPatches.resize_uninitialized(0); +} + +void GfxPatchInfo::AddPatchableFloat(const ShaderLab::FloatVal& val, float& dest, const void* bufferStart, + const ShaderLab::PropertySheet* props) +{ + if (val.var.IsValid()) + { + using namespace ShaderLab::shaderprops; + PropertyLocation location; + bool missing; + const float& src = GetFloat(props, val.var, location); + dest = src; + if (IsPatchable(location, missing)) + { + size_t patchOffset = reinterpret_cast<UInt8*>(&dest) - static_cast<const UInt8*>(bufferStart); + AddPatch(GfxPatch::kTypeFloat, GfxPatch(val.var, missing ? NULL : &src, patchOffset)); + } + } + else + dest = val.val; +} + +void GfxPatchInfo::AddPatchableVector(const ShaderLab::VectorVal& val, Vector4f& dest, const void* bufferStart, + const ShaderLab::PropertySheet* props) +{ + if (val.var.IsValid()) + { + using namespace ShaderLab::shaderprops; + PropertyLocation location; + bool missing; + const Vector4f& src = GetVector(props, val.var, location); + dest = src; + if (IsPatchable(location, missing)) + { + size_t patchOffset = reinterpret_cast<UInt8*>(&dest) - static_cast<const UInt8*>(bufferStart); + AddPatch(GfxPatch::kTypeVector, GfxPatch(val.var, missing ? NULL : &src, patchOffset)); + } + } + else + { + AddPatchableFloat(val.x, dest.x, bufferStart, props); + AddPatchableFloat(val.y, dest.y, bufferStart, props); + AddPatchableFloat(val.z, dest.z, bufferStart, props); + AddPatchableFloat(val.w, dest.w, bufferStart, props); + } +} + +bool GfxPatchInfo::AddPatchableTexEnv(const ShaderLab::FastPropertyName& name, const ShaderLab::FastPropertyName& matrixName, + TextureDimension dim, TexEnvData* dest, const void* bufferStart, const ShaderLab::PropertySheet* props) +{ + using ShaderLab::TexEnv; + using namespace ShaderLab::shaderprops; + + // Get TexEnv and prepare data + PropertyLocation texEnvLocation; + TexEnv* texEnv = GetTexEnv(props, name, dim, texEnvLocation); + Assert(texEnv != NULL); + texEnv->PrepareData(name.index, matrixName, props, dest); + + bool missing; + bool patchable = IsPatchable(texEnvLocation, missing); + if (!missing) + { + UInt32 patchFlags = 0; + if (patchable) + patchFlags |= GfxTexEnvPatch::kPatchProperties; + + if (matrixName.IsValid() || texEnv->GetMatrixName().IsValid()) + { + ShaderLab::FastPropertyName finalMatrixName = matrixName.IsValid() ? matrixName : texEnv->GetMatrixName(); + PropertyLocation matLocation; + int size; + GetValueProp (props, finalMatrixName, 16, &size, matLocation); + bool matMissing; + if (IsPatchable(matLocation, matMissing)) + { + patchFlags |= GfxTexEnvPatch::kPatchMatrix; + } + } + if (patchFlags != 0) + { + size_t offset = reinterpret_cast<const UInt8*>(dest) - static_cast<const UInt8*>(bufferStart); + GfxTexEnvPatch patch(name, matrixName, texEnv, dim, offset, patchFlags); + AddTexEnvPatch(patch); + } + return true; + } + return false; +} diff --git a/Runtime/GfxDevice/GfxPatchInfo.h b/Runtime/GfxDevice/GfxPatchInfo.h new file mode 100644 index 0000000..355b4d5 --- /dev/null +++ b/Runtime/GfxDevice/GfxPatchInfo.h @@ -0,0 +1,78 @@ +#pragma once + +#include "GfxDeviceTypes.h" +#include "External/shaderlab/Library/shadertypes.h" +#include "External/shaderlab/Library/texenv.h" +#include "Runtime/Utilities/dynamic_array.h" + +struct GfxPatch +{ + GfxPatch(const ShaderLab::FastPropertyName& name, const void* src, size_t ofs) + : nameIndex(name.index), source(src), patchOffset(ofs) {} + + enum Type + { + kTypeFloat, + kTypeVector, + kTypeMatrix, + kTypeBuffer, + kTypeCount + }; + + int nameIndex; + const void* source; + size_t patchOffset; +}; + +struct GfxTexEnvPatch +{ + GfxTexEnvPatch(const ShaderLab::FastPropertyName& name, const ShaderLab::FastPropertyName& matName, + ShaderLab::TexEnv* tex, TextureDimension dim, size_t ofs, UInt32 flags) + : nameIndex(name.index), matrixName(matName), texEnv(tex), texDim(dim), patchOffset(ofs), patchFlags(flags) {} + + enum PatchFlag + { + kPatchProperties = 1 << 0, + kPatchMatrix = 1 << 1 + }; + + //ShaderLab::FastPropertyName textureName; + int nameIndex; + ShaderLab::FastPropertyName matrixName; + ShaderLab::TexEnv* texEnv; + TextureDimension texDim; + size_t patchOffset; + UInt32 patchFlags; +}; + +class GfxPatchInfo +{ +public: + FORCE_INLINE size_t GetPatchCount(GfxPatch::Type type) const { return m_Patches[type].size(); } + FORCE_INLINE const GfxPatch& GetPatch(GfxPatch::Type type, int index) const { return m_Patches[type][index]; } + FORCE_INLINE GfxPatch& GetPatch(GfxPatch::Type type, int index) { return m_Patches[type][index]; } + FORCE_INLINE void AddPatch(GfxPatch::Type type, const GfxPatch& p) { m_Patches[type].push_back(p); } + + FORCE_INLINE size_t GetTexEnvPatchCount() const { return m_TexEnvPatches.size(); } + FORCE_INLINE const GfxTexEnvPatch& GetTexEnvPatch(int index) const { return m_TexEnvPatches[index]; } + FORCE_INLINE GfxTexEnvPatch& GetTexEnvPatch(int index) { return m_TexEnvPatches[index]; } + FORCE_INLINE void AddTexEnvPatch(const GfxTexEnvPatch& p) { m_TexEnvPatches.push_back(p); } + + void Reset(); + + void AddPatchableFloat(const ShaderLab::FloatVal& val, float& dest, const void* bufferStart, + const ShaderLab::PropertySheet* props); + + void AddPatchableVector(const ShaderLab::VectorVal& val, Vector4f& dest, const void* bufferStart, + const ShaderLab::PropertySheet* props); + + bool AddPatchableTexEnv(const ShaderLab::FastPropertyName& name, const ShaderLab::FastPropertyName& matrixName, + TextureDimension dim, TexEnvData* dest, const void* bufferStart, const ShaderLab::PropertySheet* props); + +private: + typedef dynamic_array<GfxPatch> PatchArray; + typedef dynamic_array<GfxTexEnvPatch> TexEnvPatchArray; + PatchArray m_Patches[GfxPatch::kTypeCount]; + TexEnvPatchArray m_TexEnvPatches; +}; + diff --git a/Runtime/GfxDevice/GfxTimerQuery.h b/Runtime/GfxDevice/GfxTimerQuery.h new file mode 100644 index 0000000..bba5174 --- /dev/null +++ b/Runtime/GfxDevice/GfxTimerQuery.h @@ -0,0 +1,23 @@ +#ifndef GFXTIMERQUERY_H +#define GFXTIMERQUERY_H + +#include "Runtime/Profiler/TimeHelper.h" +#include "Runtime/Utilities/LinkedList.h" + +class GfxTimerQuery : public ListElement +{ +public: + virtual ~GfxTimerQuery() {} + + enum + { + kWaitRenderThread = 1 << 0, + kWaitClientThread = 1 << 1, + kWaitAll = (kWaitClientThread | kWaitRenderThread) + }; + + virtual void Measure() = 0; + virtual ProfileTimeFormat GetElapsed(UInt32 flags) = 0; +}; + +#endif diff --git a/Runtime/GfxDevice/GpuProgram.cpp b/Runtime/GfxDevice/GpuProgram.cpp new file mode 100644 index 0000000..688fdc7 --- /dev/null +++ b/Runtime/GfxDevice/GpuProgram.cpp @@ -0,0 +1,695 @@ +#include "UnityPrefix.h" +#include "GpuProgram.h" +#include "GfxPatchInfo.h" +#include "External/shaderlab/Library/ShaderLabErrors.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/texenv.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "GfxDevice.h" + +#if GFX_SUPPORTS_OPENGL +#include "Runtime/GfxDevice/opengl/GpuProgramsGL.h" +#include "Runtime/GfxDevice/opengl/ArbGpuProgamGL.h" +#endif +#if GFX_SUPPORTS_OPENGLES30 +#include "Runtime/GfxDevice/opengles30/GpuProgramsGLES30.h" +#endif +#if GFX_SUPPORTS_OPENGLES20 +#include "Runtime/GfxDevice/opengles20/GpuProgramsGLES20.h" +#endif +#if GFX_SUPPORTS_D3D9 +#include "Runtime/GfxDevice/d3d/GpuProgramsD3D.h" +#endif +#if GFX_SUPPORTS_D3D11 +#include "d3d11/GpuProgramsD3D11.h" +#endif +#if GFX_SUPPORTS_GCM +#include "GpuProgramPS3.h" +#endif +#if GFX_SUPPORTS_XENON +#include "GpuProgramsXenon.h" +#endif +#if GFX_SUPPORTS_MOLEHILL +#include "Runtime/GfxDevice/molehill/GpuProgramsMH.h" +#endif + + +// -------------------------------------------------------------------------- +void GpuProgramParameters::AddValueParam (const ValueParameter& param) +{ + m_ValueParams.push_back (param); + m_ValuesSize += param.m_ArraySize * param.m_RowCount * param.m_ColCount * sizeof(float); + m_Status = kDirty; +} + +void GpuProgramParameters::AddTextureParam (const TextureParameter& param) +{ + m_TextureParams.push_back (param); + m_ValuesSize += sizeof(TexEnvData); + m_Status = kDirty; +} + +void GpuProgramParameters::AddVectorParam (int index, ShaderParamType type, int dimension, const char* nameStr, int cbIndex, PropertyNamesSet* outNames) +{ + int cbNameID = -1; + #if GFX_SUPPORTS_CONSTANT_BUFFERS + if (cbIndex >= 0) + cbNameID = m_ConstantBuffers[cbIndex].m_Name.index; + #endif + if (m_BuiltinParams.CheckVectorParam (nameStr, index, dimension, cbNameID)) + return; + + ValueParameterArray& params = GetValuesArray(cbIndex); + const FastPropertyName name = ShaderLab::Property(nameStr); + params.push_back (ValueParameter (name, type, index, 1, 1, dimension)); + const UInt32 size = sizeof(Vector4f); + m_ValuesSize += size; + m_Status = kDirty; + + if (outNames && !name.IsBuiltin() && outNames->names.insert(name.index).second) + outNames->valueSize += size; +} + +void GpuProgramParameters::AddMatrixParam (int index, const char* nameStr, int rowCount, int colCount, int cbIndex, PropertyNamesSet* outNames) +{ + Assert(rowCount <= 4); + + int cbNameID = -1; + #if GFX_SUPPORTS_CONSTANT_BUFFERS + if (cbIndex >= 0) + cbNameID = m_ConstantBuffers[cbIndex].m_Name.index; + #endif + + if (m_BuiltinParams.CheckMatrixParam (nameStr, index, rowCount, colCount, cbNameID)) + return; + + ValueParameterArray& params = GetValuesArray(cbIndex); + const FastPropertyName name = ShaderLab::Property(nameStr); + params.push_back (ValueParameter (name, kShaderParamFloat, index, 1, rowCount, colCount)); + const UInt32 size = sizeof(int) + sizeof(Matrix4x4f); + m_ValuesSize += size; + m_Status = kDirty; + + if (outNames && !name.IsBuiltin() && outNames->names.insert(name.index).second) + outNames->valueSize += size; +} + +void GpuProgramParameters::AddTextureParam (int index, int samplerIndex, const char* nameStr, TextureDimension dim, PropertyNamesSet* outNames) +{ + const FastPropertyName name = ShaderLab::Property(nameStr); + m_TextureParams.push_back (TextureParameter (name, index, samplerIndex, dim)); + const UInt32 size = sizeof(TexEnvData); + m_ValuesSize += size; + m_Status = kDirty; + + if (outNames && !name.IsBuiltin() && outNames->names.insert(name.index).second) + outNames->valueSize += size; +} + +void GpuProgramParameters::AddBufferParam (int index, const char* nameStr, PropertyNamesSet* outNames) +{ + const FastPropertyName name = ShaderLab::Property(nameStr); + m_BufferParams.push_back (BufferParameter (name, index)); + const UInt32 size = sizeof(ComputeBufferID); + m_ValuesSize += size; + + if (outNames && !name.IsBuiltin() && outNames->names.insert(name.index).second) + outNames->valueSize += size; +} + +const GpuProgramParameters::ValueParameterArray& GpuProgramParameters::GetValueParams() const +{ + if (IsDirty()) + const_cast<GpuProgramParameters*>(this)->MakeReady(); + return m_ValueParams; +} + +const GpuProgramParameters::TextureParameter* GpuProgramParameters::FindTextureParam(const FastPropertyName& name, TextureDimension dim) const +{ + for (TextureParameterList::const_iterator it = m_TextureParams.begin(), itEnd = m_TextureParams.end(); it != itEnd; ++it) + { + const TextureParameter& tex = *it; + if (tex.m_Name == name && tex.m_Dim == dim) + return &tex; + } + return NULL; +} + + +const GpuProgramParameters::ValueParameter* GpuProgramParameters::FindParam (const FastPropertyName& name, int* outCBIndex) const +{ + DebugAssert(!IsDirty()); + NameToValueIndex key = { name.index, 0, 0 }; + // Binary search using lower_bound should be faster, but seems slower... + //NameToValueIndexMap::const_iterator pos = std::lower_bound(m_NamedParams.begin(), m_NamedParams.end(), key); + NameToValueIndexMap::const_iterator pos = std::find(m_NamedParams.begin(), m_NamedParams.end(), key); + const GpuProgramParameters::ValueParameter* param = NULL; + if (pos != m_NamedParams.end()) + { + const ValueParameterArray& params = GetValuesArray(pos->cbIndex); + param = ¶ms[pos->valueIndex]; + DebugAssert(name.index == param->m_Name.index); + + #if GFX_SUPPORTS_CONSTANT_BUFFERS + if (outCBIndex) + *outCBIndex = pos->cbIndex; + #endif + } + return param; +} + + +template <typename T> +static inline UInt8* PushToBuffer (UInt8* buffer, const T& val) +{ + memcpy (buffer, &val, sizeof(val)); + return buffer + sizeof(val); +} + +static UInt8* PrepareValueParameters ( + const GpuProgramParameters::ValueParameterArray& valueParams, + const ShaderLab::PropertySheet* props, + UInt8* buffer, + const UInt8* bufferStart, + GfxPatchInfo* outPatchInfo) +{ + using namespace ShaderLab; + using namespace ShaderLab::shaderprops; + PropertyLocation location; + bool missing; + + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for (GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i) + { + FastPropertyName name = i->m_Name; + int rows = i->m_RowCount; + int cols = i->m_ColCount; + int arrSize = i->m_ArraySize; + if (rows == 1 && arrSize <= 1) + { + // single floats and vectors + if (cols == 1) { + const float& src = GetFloat(props, name, location); + if (outPatchInfo && IsPatchable(location, missing)) { + outPatchInfo->AddPatch(GfxPatch::kTypeFloat, + GfxPatch(name, missing ? NULL : &src, buffer - bufferStart)); + } + Vector4f val(src,0,0,0); + buffer = PushToBuffer (buffer, val); + } else { + const Vector4f& src = GetVector(props, name, location); + if (outPatchInfo && IsPatchable(location, missing)) { + outPatchInfo->AddPatch(GfxPatch::kTypeVector, + GfxPatch(name, missing ? NULL : &src, buffer - bufferStart)); + } + buffer = PushToBuffer (buffer, src); + } + } + else + { + // matrices, arrays etc. + int expectSize = arrSize * rows * cols; + + //@TODO: for now, arrays are not really supported yet; and a bunch of + // other code around us expect matrices to always be 4x4, even if + // actual shader uses less. Right now this is only a problematic case + // for Xbox360, since on other platforms the compiler never "strips away" + // unreferenced matrix constant slots. + // When we actually add shader parameter array support, this place, + // and a ton of other places, would have to remove 4x4 assumptions. + if (expectSize < 16) + expectSize = 16; + + int gotSize; + const float* src = GetValueProp (props, name, expectSize, &gotSize, location); + DebugAssert (gotSize <= expectSize); + memcpy (buffer, &gotSize, sizeof(gotSize)); buffer += sizeof(gotSize); // size + if (outPatchInfo && IsPatchable(location, missing)) { + //@TODO: once we have arrays here, it's not necessarily matrix anymore! + outPatchInfo->AddPatch(GfxPatch::kTypeMatrix, + GfxPatch(name, missing ? NULL : src, buffer - bufferStart)); + } + memcpy (buffer, src, gotSize*sizeof(float)); buffer += gotSize*sizeof(float); // value + } + } + return buffer; +} + +UInt8* GpuProgramParameters::PrepareValues ( + const ShaderLab::PropertySheet* props, + UInt8* buffer, + const UInt8* bufferStart, + GfxPatchInfo* outPatchInfo, + bool* outMissingTextures) const +{ + using namespace ShaderLab; + using namespace ShaderLab::shaderprops; + + // Value parameters + + buffer = PrepareValueParameters (GetValueParams(), props, buffer, bufferStart, outPatchInfo); + + #if GFX_SUPPORTS_CONSTANT_BUFFERS + for (size_t i = 0; i < m_ConstantBuffers.size(); ++i) + { + buffer = PrepareValueParameters (m_ConstantBuffers[i].m_ValueParams, props, buffer, bufferStart, outPatchInfo); + } + #endif + + // textures + TextureParameterList::const_iterator textureParamsEnd = m_TextureParams.end(); + for (TextureParameterList::const_iterator i = m_TextureParams.begin(); i != textureParamsEnd; ++i) + { + const GpuProgramParameters::TextureParameter& t = *i; + FastPropertyName name = t.m_Name; + TextureDimension dim = t.m_Dim; + TexEnvData* dest = reinterpret_cast<TexEnvData*>(buffer); + if (outPatchInfo) + { + DebugAssert(outMissingTextures); + if (!outPatchInfo->AddPatchableTexEnv(name, FastPropertyName(), t.m_Dim, dest, bufferStart, props)) + *outMissingTextures = true; + } + else + { + TexEnv* src = GetTexEnv(props, name, dim); + src->PrepareData(name.index, FastPropertyName(), props, dest); + } + buffer += sizeof(TexEnvData); + } + + // buffers + bool missing; + BufferParameterArray::const_iterator bufferParamsEnd = m_BufferParams.end(); + for (BufferParameterArray::const_iterator i = m_BufferParams.begin(); i != bufferParamsEnd; ++i) + { + const BufferParameter& t = *i; + + PropertyLocation location; + const ComputeBufferID& buf = shaderprops::GetComputeBuffer(props, t.m_Name, location); + if (outPatchInfo && IsPatchable(location, missing)) { + outPatchInfo->AddPatch(GfxPatch::kTypeBuffer, + GfxPatch(t.m_Name, missing ? NULL : &buf, buffer - bufferStart)); + } + + ComputeBufferID* destPtr = reinterpret_cast<ComputeBufferID*>(buffer); + *destPtr = buf; buffer += sizeof(ComputeBufferID); + } + + return buffer; +} + +void GpuProgramParameters::MakeValueParamsReady (ValueParameterArray& values, int cbIndex) +{ + std::sort (values.begin(), values.end()); + int size = values.size(); + for (int i = 0; i < size; i++) + { + const ValueParameter& param = values[i]; + NameToValueIndex key = { param.m_Name.index, cbIndex, i }; + m_NamedParams.push_back(key); + } +} + + +void GpuProgramParameters::MakeReady() +{ + if (IsDirty()) + { + m_NamedParams.clear(); + MakeValueParamsReady (m_ValueParams, -1); + #if GFX_SUPPORTS_CONSTANT_BUFFERS + for (size_t cb = 0; cb < m_ConstantBuffers.size(); ++cb) + MakeValueParamsReady (m_ConstantBuffers[cb].m_ValueParams, cb); + #endif + std::sort(m_NamedParams.begin(), m_NamedParams.end()); + } + m_Status = kReady; +} + +// -------------------------------------------------------------------------- + + +bool CheckGpuProgramUsable (const char* str) +{ + GfxDeviceRenderer rendererType = GetGfxDevice().GetRenderer(); + + // Pretend program is usable if we are building shaders in "nographics" mode + if( rendererType == kGfxRendererNull ) + return true; + + // determine the kind of program from the start of the string + if( !strncmp (str, "!!ARBvp1.0", 10) || !strncmp (str, "3.0-!!ARBvp1.0", 14) ) { + #if GFX_SUPPORTS_OPENGL + if( rendererType == kGfxRendererOpenGL ) + return true; + #endif + return false; + } else if( !strncmp (str, "!!ARBfp1.0", 10) || !strncmp (str, "3.0-!!ARBfp1.0", 14) ) { + #if GFX_SUPPORTS_OPENGL + if( rendererType == kGfxRendererOpenGL ) + return true; + #endif + return false; + } else if (!strncmp (str, "!!GLSL", 6)) { + #if GFX_SUPPORTS_OPENGL + if( rendererType == kGfxRendererOpenGL ) + return true; + #endif + return false; + } else if (!strncmp (str, "!!GLES3", 7)) { + #if GFX_SUPPORTS_OPENGLES30 + if( rendererType = kGfxRendererOpenGLES30 ) + return true; + #endif + return false; + } else if (!strncmp (str, "!!GLES", 6)) { + #if GFX_SUPPORTS_OPENGLES20 + if( rendererType == kGfxRendererOpenGLES20Mobile || rendererType == kGfxRendererOpenGLES20Desktop ) + return true; + #endif + #if GFX_SUPPORTS_OPENGLES30 + if( rendererType = kGfxRendererOpenGLES30 ) + return true; + #endif + return false; + } else if (!strncmp (str, "!!ATIfs1.0", 10)) { + printf_console ("@TODO: found ATIfs1.0 shader; those are not supported anymore\n"); + return false; + } else if (!strncmp (str, "vs_1_1", 6) || !strncmp (str, "vs_2_0", 6) || !strncmp (str, "vs_3_0", 6)) { + #if GFX_SUPPORTS_D3D9 + if( rendererType == kGfxRendererD3D9 ) + return true; + #endif + return false; + } else if (!strncmp (str, "ps_2_0", 6) || !strncmp (str, "ps_3_0", 6)) { + #if GFX_SUPPORTS_D3D9 + if( rendererType == kGfxRendererD3D9 ) + return true; + #endif + return false; + } else if (!strncmp (str, "vs_4_0_level_9", strlen("vs_4_0_level_9"))) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0 ) + return true; + #endif + return false; + } else if (!strncmp (str, "ps_4_0_level_9", strlen("ps_4_0_level_9"))) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0 ) + return true; + #endif + return false; + } else if (!strncmp (str, "vs_dx11", 7) || !strncmp (str, "vs_4_0", 6) || !strncmp (str, "vs_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ) + return true; + #endif + return false; + } else if (!strncmp (str, "ps_dx11", 7) || !strncmp (str, "ps_4_0", 6) || !strncmp (str, "ps_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ) + return true; + #endif + return false; + } else if (!strncmp (str, "gs_4_0", 6) || !strncmp (str, "gs_5_0", 6) || !strncmp (str, "hs_5_0", 6) || !strncmp (str, "ds_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ) + return true; + #endif + return false; + } else if (!strncmp (str, "vs_360", 6)) { + #if GFX_SUPPORTS_XENON + if( rendererType == kGfxRendererXenon ) + return true; + #endif + return false; + } else if (!strncmp (str, "ps_360", 6)) { + #if GFX_SUPPORTS_XENON + if( rendererType == kGfxRendererXenon ) + return true; + #endif + return false; + } else if (!strncmp (str, "sce_vp_rsx", 10)) { + #if GFX_SUPPORTS_GCM + if( rendererType == kGfxRendererGCM ) + return true; + #endif + return false; + } else if (!strncmp (str, "sce_fp_rsx", 10)) { + #if GFX_SUPPORTS_GCM + if( rendererType == kGfxRendererGCM ) + return true; + #endif + return false; + } else if (!strncmp (str, "agal_vs", 7)) { + #if GFX_SUPPORTS_MOLEHILL + if (rendererType == kGfxRendererMolehill) + return true; + #endif + return false; + } else if (!strncmp (str, "agal_ps", 7)) { + #if GFX_SUPPORTS_MOLEHILL + if (rendererType == kGfxRendererMolehill) + return true; + #endif + return false; + } + + // If we got here, it's something unrecognized. Return that it's usable, + // this will make current SubShader be not supported. + return true; +} + +GpuProgram* CreateGpuProgram( const std::string& source, CreateGpuProgramOutput& output ) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + GpuProgram* program = NULL; + + // determine the kind of program from the start of the string + GfxDeviceRenderer rendererType = GetRealGfxDevice().GetRenderer(); + + if( !strncmp (source.c_str(), "!!ARBvp1.0", 10) || !strncmp (source.c_str(), "3.0-!!ARBvp1.0", 14) ) { + #if GFX_SUPPORTS_OPENGL + if( rendererType == kGfxRendererOpenGL ) + program = new ArbGpuProgram( source, kShaderVertex, kShaderImplVertex ); + #endif + } else if( !strncmp (source.c_str(), "!!ARBfp1.0", 10) || !strncmp (source.c_str(), "3.0-!!ARBfp1.0", 14) ) { + #if GFX_SUPPORTS_OPENGL + if( rendererType == kGfxRendererOpenGL ) + program = new ArbGpuProgram( source, kShaderFragment, kShaderImplFragment ); + #endif + } else if (!strncmp (source.c_str(), "!!GLSL", 6)) { + #if GFX_SUPPORTS_OPENGL + if( rendererType == kGfxRendererOpenGL ) + program = new GlslGpuProgram( source.substr(6,source.size()-6), output ); + #endif + } else if (!strncmp (source.c_str(), "!!GLES3", 7)) { + #if GFX_SUPPORTS_OPENGLES30 + if( rendererType == kGfxRendererOpenGLES30 ) + program = new GlslGpuProgramGLES30(source.substr(7,source.size()-7), output); + #endif + } else if (!strncmp (source.c_str(), "!!GLES", 6)) { + #if GFX_SUPPORTS_OPENGLES20 + if( rendererType == kGfxRendererOpenGLES20Mobile || rendererType == kGfxRendererOpenGLES20Desktop ) + program = new GlslGpuProgramGLES20( source.substr(6,source.size()-6), output ); + #endif + #if GFX_SUPPORTS_OPENGLES30 + if( rendererType == kGfxRendererOpenGLES30 ) + program = new GlslGpuProgramGLES30( source.substr(6,source.size()-6), output); + #endif + } else if (!strncmp (source.c_str(), "!!ATIfs1.0", 10)) { + printf_console ("@TODO: found ATIfs1.0 shader; those are not supported anymore\n"); + } else if (!strncmp (source.c_str(), "vs_1_1", 6) || !strncmp (source.c_str(), "vs_2_0", 6) || !strncmp (source.c_str(), "vs_3_0", 6)) { + #if GFX_SUPPORTS_D3D9 + if( rendererType == kGfxRendererD3D9 ) + program = new D3D9VertexShader( source ); + #endif + } else if (!strncmp (source.c_str(), "ps_2_0", 6) || !strncmp (source.c_str(), "ps_3_0", 6)) { + #if GFX_SUPPORTS_D3D9 + if( rendererType == kGfxRendererD3D9 ) + program = new D3D9PixelShader( source ); + #endif + } else if (!strncmp (source.c_str(), "vs_4_0_level_9", strlen("vs_4_0_level_9"))) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0 ) + program = new D3D11VertexShader( source ); + #endif + } else if (!strncmp (source.c_str(), "ps_4_0_level_9", strlen("ps_4_0_level_9"))) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0 ) + program = new D3D11PixelShader( source ); + #endif + } else if (!strncmp (source.c_str(), "vs_dx11", 7) || !strncmp (source.c_str(), "vs_4_0", 6) || !strncmp (source.c_str(), "vs_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ) + program = new D3D11VertexShader( source ); + #endif + } else if (!strncmp (source.c_str(), "ps_dx11", 7) || !strncmp (source.c_str(), "ps_4_0", 6) || !strncmp (source.c_str(), "ps_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if( rendererType == kGfxRendererD3D11 && gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ) + program = new D3D11PixelShader( source ); + #endif + } else if (!strncmp (source.c_str(), "gs_4_0", 6) || !strncmp (source.c_str(), "gs_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if (rendererType == kGfxRendererD3D11) + program = new D3D11GeometryShader(source); + #endif + } else if (!strncmp (source.c_str(), "hs_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if (rendererType == kGfxRendererD3D11) + program = new D3D11HullShader(source); + #endif + } else if (!strncmp (source.c_str(), "ds_5_0", 6)) { + #if GFX_SUPPORTS_D3D11 + if (rendererType == kGfxRendererD3D11) + program = new D3D11DomainShader(source); + #endif + } else if (!strncmp (source.c_str(), "vs_360", 6)) { + #if GFX_SUPPORTS_XENON + if( rendererType == kGfxRendererXenon ) + program = new XenonVertexShader (source); + #endif + } else if (!strncmp (source.c_str(), "ps_360", 6)) { + #if GFX_SUPPORTS_XENON + if( rendererType == kGfxRendererXenon ) + program = new XenonPixelShader (source); + #endif + } else if (!strncmp (source.c_str(), "sce_vp_rsx", 10)) { + #if GFX_SUPPORTS_GCM + if( rendererType == kGfxRendererGCM ) + program = new GcmGpuProgram( source ); + #endif + } else if (!strncmp (source.c_str(), "sce_fp_rsx", 10)) { + #if GFX_SUPPORTS_GCM + if( rendererType == kGfxRendererGCM ) + program = new GcmGpuProgram( source ); + #endif + } else if (!strncmp (source.c_str(), "agal_vs", 7)) { + #if GFX_SUPPORTS_MOLEHILL + if (rendererType == kGfxRendererMolehill) + program = new GpuProgramMH (source, kShaderVertex); + #endif + } else if (!strncmp (source.c_str(), "agal_ps", 7)) { + #if GFX_SUPPORTS_MOLEHILL + if (rendererType == kGfxRendererMolehill) + program = new GpuProgramMH (source, kShaderFragment); + #endif + } else { + if( source == "!!error" ) + { + // we've got a program that had errors when compiling. Silently fail, errors + // were dumped before + printf_console( "Shader had programs with errors, disabling subshader\n" ); + } + else if( source.empty() ) + { + output.CreateShaderErrors().AddShaderError ("Empty program string", -1, false); + } + else + { + const int kProgramStartChars = 10; + int len = source.size() < kProgramStartChars ? source.size() : kProgramStartChars; + output.CreateShaderErrors().AddShaderError (Format("Unrecognized program string: %s ...", source.substr(0,len).c_str()), -1, false); + } + } + + // TODO: immediately check if not supported? + + return program; +#else + return NULL; +#endif +} + + +// -------------------------------------------------------------------------- + +GpuProgram::GpuProgram() +{ + m_ImplType = kShaderImplUndefined; + m_GpuProgramLevel = kGpuProgramNone; + m_NotSupported = false; + m_WasDestroyed = false; +} + +GpuProgram::~GpuProgram () +{ +} + +bool GpuProgram::IsSupported () const +{ + if (m_NotSupported) + return false; + + // OpenGL specific caps check + #if GFX_SUPPORTS_OPENGL + if( GetGfxDevice().GetRenderer() == kGfxRendererOpenGL ) + { + switch (m_ImplType) { + case kShaderImplBoth: + if( !gGraphicsCaps.gl.hasGLSL ) return false; + break; + default: + break; + } + } + #endif + + return true; +} + +// -------------------------------------------------------------------------- + +CreateGpuProgramOutput::CreateGpuProgramOutput() +: m_PerFogModeParamsEnabled(false) +, m_Params(NULL) +, m_ShaderErrors(NULL) +, m_ChannelAssigns(NULL) +{ +} + +CreateGpuProgramOutput::~CreateGpuProgramOutput() +{ + delete m_Params; + delete m_ShaderErrors; + delete m_ChannelAssigns; +} + +GpuProgramParameters& CreateGpuProgramOutput::CreateParams() +{ + Assert(!m_Params); + m_Params = new GpuProgramParameters; + return *m_Params; +} + +ShaderErrors& CreateGpuProgramOutput::CreateShaderErrors() +{ + Assert(!m_ShaderErrors); + m_ShaderErrors = new ShaderErrors; + return *m_ShaderErrors; +} + +ChannelAssigns& CreateGpuProgramOutput::CreateChannelAssigns() +{ + Assert(!m_ChannelAssigns); + m_ChannelAssigns = new ChannelAssigns; + return *m_ChannelAssigns; +} + + +#if GFX_SUPPORTS_OPENGL || GFX_SUPPORTS_OPENGLES20 + +GpuProgramGL::GpuProgramGL() +: GpuProgram() +{ + for (int i = 0; i < kFogModeCount; ++i) + m_Programs[i] = 0; +} + +GpuProgramGL::~GpuProgramGL() +{ +} + +#endif diff --git a/Runtime/GfxDevice/GpuProgram.h b/Runtime/GfxDevice/GpuProgram.h new file mode 100644 index 0000000..192d32b --- /dev/null +++ b/Runtime/GfxDevice/GpuProgram.h @@ -0,0 +1,278 @@ +#pragma once + +#include <string> +#include "External/shaderlab/Library/FastPropertyName.h" +#include "GfxDeviceTypes.h" +#include "External/shaderlab/Library/shadertypes.h" +#include "Runtime/Utilities/dynamic_array.h" +#include "Runtime/Utilities/vector_set.h" +#include "BuiltinShaderParams.h" +#include "GfxDeviceConfigure.h" +#include "Runtime/GfxDevice/threaded/ClientIDMapper.h" + +class ShaderErrors; +class GpuProgram; +class GpuProgramParameters; +class CreateGpuProgramOutput; +class GfxPatchInfo; +class ChannelAssigns; +using ShaderLab::FastPropertyName; +namespace ShaderLab { class PropertySheet; class SubProgram; } + + +enum GpuProgramLevel { + kGpuProgramNone = 0, // fixed function + kGpuProgramSM1, + kGpuProgramSM2, + kGpuProgramSM3, + kGpuProgramSM4, + kGpuProgramSM5, + kGpuProgramCount // keep this last +}; + + +struct PropertyNamesSet { + PropertyNamesSet() : valueSize(0) { } + vector_set<int> names; // IDs of shader property names + UInt32 valueSize; // Buffer size needed to hold all property values of the above +}; + + +// ------------------------------------------------------------------------ + +bool CheckGpuProgramUsable (const char* str); + +// Create GPU programs with this function. This can return NULL if the program is not +// recognized. When done with a program call Release() on it, never delete directly. +GpuProgram* CreateGpuProgram( const std::string& source, CreateGpuProgramOutput& output ); + + +// ------------------------------------------------------------------------ + +class GpuProgramParameters { +public: + struct ValueParameter { + FastPropertyName m_Name; // The name of the value to look up. + int m_Index; // The index of the first parameter to upload to + int m_ArraySize; // The index of the first parameter to upload to + ShaderParamType m_Type; + UInt8 m_RowCount; + UInt8 m_ColCount; + ValueParameter (FastPropertyName n, ShaderParamType type, int idx, int arraySize, int rowCount, int colCount) : m_Name(n), m_Index(idx), m_ArraySize(arraySize), m_Type(type), m_RowCount(rowCount), m_ColCount(colCount) {} + ValueParameter () : m_Index(0), m_ArraySize(0), m_RowCount(0), m_ColCount(0) {} + bool operator == (const ValueParameter& other) const { return m_Name.index == other.m_Name.index; } + bool operator < (const ValueParameter& other) const { return m_Name.index < other.m_Name.index; } + }; + typedef dynamic_array<ValueParameter> ValueParameterArray; + + struct TextureParameter { + FastPropertyName m_Name; + int m_Index; + int m_SamplerIndex; + TextureDimension m_Dim; + TextureParameter (FastPropertyName n, int idx, int samplerIdx, TextureDimension dim) : m_Name(n), m_Index(idx), m_SamplerIndex(samplerIdx), m_Dim(dim) { } + TextureParameter () : m_Index(0), m_SamplerIndex(0), m_Dim(kTexDimNone) {} + }; + typedef std::vector<TextureParameter> TextureParameterList; + + struct BufferParameter { + FastPropertyName m_Name; + int m_Index; + BufferParameter (FastPropertyName n, int idx) : m_Name(n), m_Index(idx) { } + BufferParameter () : m_Index(0) {} + }; + typedef dynamic_array<BufferParameter> BufferParameterArray; + + + #if GFX_SUPPORTS_CONSTANT_BUFFERS + struct ConstantBuffer { + FastPropertyName m_Name; + ValueParameterArray m_ValueParams; + int m_Size; + int m_BindIndex; + }; + typedef std::vector<ConstantBuffer> ConstantBufferList; + #endif + +public: + GpuProgramParameters () : m_ValuesSize(0), m_Status(kBlank) +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + ,m_InternalHandle(0) +#endif + { } + + void AddValueParam (const ValueParameter& param); + void AddTextureParam (const TextureParameter& param); + void AddVectorParam (int index, ShaderParamType type, int dimension, const char* nameStr, int cbIndex, PropertyNamesSet* outNames); + void AddMatrixParam (int index, const char* nameStr, int rowCount, int colCount, int cbIndex, PropertyNamesSet* outNames); + void AddTextureParam (int index, int samplerIndex, const char* nameStr, TextureDimension dim, PropertyNamesSet* outNames); + void AddBufferParam (int index, const char* nameStr, PropertyNamesSet* outNames); + const ValueParameterArray& GetValueParams() const; + const TextureParameterList& GetTextureParams() const { return m_TextureParams; } + TextureParameterList& GetTextureParams() { return m_TextureParams; } + const BufferParameterArray& GetBufferParams() const { return m_BufferParams; } + + const ValueParameter* FindParam(const FastPropertyName& name, int* outCBIndex = NULL) const; + const TextureParameter* FindTextureParam(const FastPropertyName& name, TextureDimension dim) const; + + #if GFX_SUPPORTS_CONSTANT_BUFFERS + const ConstantBufferList& GetConstantBuffers() const { return m_ConstantBuffers; } + ConstantBufferList& GetConstantBuffers() { return m_ConstantBuffers; } + void SetConstantBufferCount (size_t count) + { + m_ConstantBuffers.resize (count); + } + #endif + + const BuiltinShaderParamIndices& GetBuiltinParams() const { return m_BuiltinParams; } + + int GetValuesSize() const { return m_ValuesSize; } + UInt8* PrepareValues ( + const ShaderLab::PropertySheet* props, + UInt8* buffer, + const UInt8* bufferStart = NULL, + GfxPatchInfo* outPatchInfo = NULL, + bool* outMissingTextures = NULL) const; + + bool IsReady() const { return m_Status == kReady; } + bool IsDirty() const { return m_Status == kDirty; } + + virtual void MakeReady(); + +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + // Reference to the created GpuPogramParameters on the worker. + ClientIDWrapper(GpuProgramParameters) m_InternalHandle; +#endif + +private: + enum State { + kBlank, + kDirty, + kReady + }; + + struct NameToValueIndex { + int nameIndex; + SInt16 cbIndex; + UInt16 valueIndex; + bool operator == (const NameToValueIndex& other) const { return nameIndex == other.nameIndex; } + bool operator < (const NameToValueIndex& other) const { return nameIndex < other.nameIndex; } + }; + + void MakeValueParamsReady (ValueParameterArray& values, int cbIndex); + ValueParameterArray& GetValuesArray (int cbIndex) { + ValueParameterArray* values = &m_ValueParams; + #if GFX_SUPPORTS_CONSTANT_BUFFERS + if (cbIndex >= 0) + { + DebugAssert (cbIndex < m_ConstantBuffers.size()); + values = &m_ConstantBuffers[cbIndex].m_ValueParams; + } + #endif + return *values; + } + const ValueParameterArray& GetValuesArray (int cbIndex) const { + const ValueParameterArray* values = &m_ValueParams; + #if GFX_SUPPORTS_D3D11 + if (cbIndex >= 0) + { + DebugAssert (cbIndex < m_ConstantBuffers.size()); + values = &m_ConstantBuffers[cbIndex].m_ValueParams; + } + #endif + return *values; + } + +private: + + typedef dynamic_array<NameToValueIndex> NameToValueIndexMap; + ValueParameterArray m_ValueParams; + NameToValueIndexMap m_NamedParams; + TextureParameterList m_TextureParams; + BufferParameterArray m_BufferParams; + + #if GFX_SUPPORTS_CONSTANT_BUFFERS + ConstantBufferList m_ConstantBuffers; + #endif + + BuiltinShaderParamIndices m_BuiltinParams; + int m_ValuesSize; + State m_Status; +}; + + +// ------------------------------------------------------------------------ + + +// Base class for GPU programs. +class GpuProgram { +public: + virtual ~GpuProgram(); + + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) = 0; + + ShaderImplType GetImplType() const { return m_ImplType; } + virtual bool IsSupported () const; + GpuProgramLevel GetLevel() const { return m_GpuProgramLevel; } + + void SetNotSupported (bool v) { m_NotSupported = v; } + +protected: + GpuProgram(); + +protected: + ShaderImplType m_ImplType; // Actual implementation type + bool m_NotSupported; + bool m_WasDestroyed; + GpuProgramLevel m_GpuProgramLevel; +}; + + +class CreateGpuProgramOutput +{ +public: + CreateGpuProgramOutput(); + ~CreateGpuProgramOutput(); + + bool GetPerFogModeParamsEnabled() const { return m_PerFogModeParamsEnabled; } + void SetPerFogModeParamsEnabled(bool enable) { m_PerFogModeParamsEnabled = enable; } + + const GpuProgramParameters* GetParams() const { return m_Params; } + GpuProgramParameters& CreateParams(); + + const ShaderErrors* GetShaderErrors() const { return m_ShaderErrors; } + ShaderErrors& CreateShaderErrors(); + + PropertyNamesSet* GetOutNames() const { return m_OutNames; } + const void SetOutNames(PropertyNamesSet* value) { m_OutNames = value; } + + const ChannelAssigns* GetChannelAssigns() const { return m_ChannelAssigns; } + ChannelAssigns& CreateChannelAssigns(); + +private: + bool m_PerFogModeParamsEnabled; + GpuProgramParameters* m_Params; + ShaderErrors* m_ShaderErrors; + ChannelAssigns* m_ChannelAssigns; + PropertyNamesSet* m_OutNames; +}; + +#if GFX_SUPPORTS_OPENGL || GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30 + +typedef unsigned int GLShaderID; + +class GpuProgramGL : public GpuProgram { +public: + virtual ~GpuProgramGL(); + + GLShaderID GetGLProgramIfCreated(FogMode fog) const { return m_Programs[fog]; } + +protected: + GpuProgramGL(); + +protected: + std::string m_SourceForFog; // original source, used for fog patching if needed + GLShaderID m_Programs[kFogModeCount]; +}; + +#endif diff --git a/Runtime/GfxDevice/GpuProgramParamsApply.h b/Runtime/GfxDevice/GpuProgramParamsApply.h new file mode 100644 index 0000000..4ac5ad0 --- /dev/null +++ b/Runtime/GfxDevice/GpuProgramParamsApply.h @@ -0,0 +1,130 @@ +#pragma once + + +template<typename SetValuesFunctor> +void ApplyMaterialPropertyBlockValues( + MaterialPropertyBlock& propblock, + GpuProgram* activeGpuProgram[kShaderTypeCount], + const GpuProgramParameters* activeGpuProgramParams[kShaderTypeCount], + SetValuesFunctor& functor) +{ + const MaterialPropertyBlock::Property* curProp = propblock.GetPropertiesBegin(); + const MaterialPropertyBlock::Property* propEnd = propblock.GetPropertiesEnd(); + const float* propBuffer = propblock.GetBufferBegin(); + while (curProp != propEnd) + { + FastPropertyName name; + name.index = curProp->nameIndex; + for (int shaderType = kShaderVertex; shaderType < kShaderTypeCount; ++shaderType) + { + GpuProgram* GpuProgram = activeGpuProgram[shaderType]; + if (!GpuProgram) + continue; + const GpuProgramParameters* params = activeGpuProgramParams[shaderType]; + + if (curProp->texDim != kTexDimNone) + { + // texture parameter + const GpuProgramParameters::TextureParameter* param = params->FindTextureParam(name, (TextureDimension)curProp->texDim); + if (!param) + continue; + const float* val = &propBuffer[curProp->offset]; + functor.SetTextureVal ((ShaderType)shaderType, param->m_Index, param->m_SamplerIndex, param->m_Dim, TextureID(*(unsigned int*)val)); + } + else + { + // value parameter + int cbIndex; + const GpuProgramParameters::ValueParameter* param = params->FindParam(name, &cbIndex); + if (!param) + continue; + if (curProp->rows == 1) + { + const float* src = &propBuffer[curProp->offset]; + Vector4f val; + if (curProp->cols == 4) + val = Vector4f(src); + else + { + DebugAssert(curProp->cols == 1); + val = Vector4f(*src, 0, 0, 0); + } + functor.SetVectorVal ((ShaderType)shaderType, param->m_Type, param->m_Index, val.GetPtr(), curProp->cols, *params, cbIndex); + } + else if (curProp->rows == 4) + { + DebugAssert(curProp->cols == 4); + const Matrix4x4f* src = (const Matrix4x4f*)&propBuffer[curProp->offset]; + functor.SetMatrixVal ((ShaderType)shaderType, param->m_Index, src, param->m_RowCount, *params, cbIndex); + } + else + { + AssertString("Unknown property dimensions"); + } + } + } + ++curProp; + } + + propblock.Clear(); +} + + +// GL ES is different from everyone else, in that shader variables are always for the whole +// "program" (all shader stages at once). +template<typename SetValuesFunctor> +void ApplyMaterialPropertyBlockValuesES( + MaterialPropertyBlock& propblock, + const GpuProgram* activeProgram, + const GpuProgramParameters* activeProgramParams, + SetValuesFunctor& functor) +{ + if (activeProgram) + { + const MaterialPropertyBlock::Property* curProp = propblock.GetPropertiesBegin(); + const MaterialPropertyBlock::Property* propEnd = propblock.GetPropertiesEnd(); + const float* propBuffer = propblock.GetBufferBegin(); + while (curProp != propEnd) + { + FastPropertyName name; + name.index = curProp->nameIndex; + + if (curProp->texDim != kTexDimNone) + { + // texture parameter + const GpuProgramParameters::TextureParameter* param = activeProgramParams->FindTextureParam(name, (TextureDimension)curProp->texDim); + if (param) + { + const float* val = &propBuffer[curProp->offset]; + functor.SetTextureVal (kShaderFragment, param->m_Index, param->m_SamplerIndex, param->m_Dim, TextureID(*(unsigned int*)val)); + } + } + else + { + // value parameter + const GpuProgramParameters::ValueParameter* param = activeProgramParams->FindParam(name); + if (param && curProp->rows == param->m_RowCount) + { + if (curProp->rows == 1) + { + const float* src = &propBuffer[curProp->offset]; + functor.SetVectorVal (param->m_Type, param->m_Index, src, param->m_ColCount); + } + else if (curProp->rows == 4) + { + DebugAssert(curProp->cols == 4); + const Matrix4x4f* src = (const Matrix4x4f*)&propBuffer[curProp->offset]; + functor.SetMatrixVal (param->m_Index, src, param->m_RowCount); + } + else + { + AssertString("Unknown property dimensions"); + } + } + } + ++curProp; + } + } + + propblock.Clear(); +} diff --git a/Runtime/GfxDevice/ShaderConstantCache.h b/Runtime/GfxDevice/ShaderConstantCache.h new file mode 100644 index 0000000..35b54eb --- /dev/null +++ b/Runtime/GfxDevice/ShaderConstantCache.h @@ -0,0 +1,142 @@ +#pragma once + +#include "GfxDeviceTypes.h" +#include "Runtime/Math/Vector4.h" +//#include "Runtime/Utilities/fixed_bitset.h" +#include "D3D9Utils.h" + + +template<int SIZE> +class ShaderConstantCache2 { +public: + ShaderConstantCache2() { memset(m_Values, 0, sizeof(m_Values)); Invalidate(); } + + void SetValues( int index, const float* values, int count ) + { + DebugAssert( index >= 0 && count > 0 && (index + count) <= SIZE ); + float* dest = m_Values[index].GetPtr(); + UInt8 andedFlags = m_Flags[index]; + for (int i = 1; i < count; i++) + andedFlags &= m_Flags[index + i]; + // Not worth filtering values bigger than one register + if (andedFlags == kValid && count == 1) + { + // We have a valid value which is not dirty + UInt32* destInt32 = reinterpret_cast<UInt32*>(dest); + int sizeInt32 = count * sizeof(Vector4f) / sizeof(UInt32); + if (CompareArrays(destInt32, reinterpret_cast<const UInt32*>(values), sizeInt32)) + return; + } + memcpy(dest, values, count * sizeof(Vector4f)); + // If all values are marked as dirty we are done + if (andedFlags & kDirty) + return; + // Update flags + for (int i = 0; i < count; i++) + m_Flags[index + i] = kValid | kDirty; + // Add dirty range or append to last range + if (!m_DirtyRanges.empty() && m_DirtyRanges.back().second == index) + m_DirtyRanges.back().second += count; + else + m_DirtyRanges.push_back(Range(index, index + count)); + } + + void Invalidate() + { + memset(m_Flags, 0, sizeof(m_Flags)); + } + + void CommitVertexConstants() + { + IDirect3DDevice9* dev = GetD3DDevice(); + int numRanges = m_DirtyRanges.size(); + for (int i = 0; i < numRanges; i++) + { + const Range& range = m_DirtyRanges[i]; + int size = range.second - range.first; + D3D9_CALL(dev->SetVertexShaderConstantF( range.first, m_Values[range.first].GetPtr(), size )); + // Update flags + for (int i = 0; i < size; i++) + m_Flags[range.first + i] = kValid; + } + m_DirtyRanges.clear(); + } + + void CommitPixelConstants() + { + IDirect3DDevice9* dev = GetD3DDevice(); + int numRanges = m_DirtyRanges.size(); + for (int i = 0; i < numRanges; i++) + { + const Range& range = m_DirtyRanges[i]; + int size = range.second - range.first; + D3D9_CALL(dev->SetPixelShaderConstantF( range.first, m_Values[range.first].GetPtr(), size )); + // Update flags + for (int i = 0; i < size; i++) + m_Flags[range.first + i] = kValid; + } + m_DirtyRanges.clear(); + } + +private: + enum + { + kValid = 1 << 0, + kDirty = 1 << 1 + }; + UInt8 m_Flags[SIZE]; + Vector4f m_Values[SIZE]; + typedef std::pair<int,int> Range; + std::vector<Range> m_DirtyRanges; +}; + + +template<int SIZE> +class ShaderConstantCache { +public: + ShaderConstantCache() { Invalidate(); } + + bool CheckCache( int index, const float value[4] ) + { + DebugAssertIf( index < 0 ); + if( index >= SIZE ) + return false; + + if( m_Values[index] == value ) + return true; + + m_Values[index].Set( value ); + return false; + } + + bool CheckCache( int index, const float* values, int count ) + { + DebugAssertIf( index < 0 ); + + // Checking whole range for validity seems to be overkill from profiling (just slows it down a bit) + // So just invalidate those cache entries. + + if( index + count > SIZE ) + count = SIZE-index; + + for( int i = 0; i < count; ++i ) + { + m_Values[index+i].x = -std::numeric_limits<float>::infinity(); + } + return false; + } + + void Invalidate() + { + for (int i = 0; i < SIZE; ++i) + m_Values[i].x = -std::numeric_limits<float>::infinity(); + } + +private: + Vector4f m_Values[SIZE]; +}; + + +typedef ShaderConstantCache2<256> VertexShaderConstantCache; +typedef ShaderConstantCache2<256> PixelShaderConstantCache; + diff --git a/Runtime/GfxDevice/TextureIdMap.cpp b/Runtime/GfxDevice/TextureIdMap.cpp new file mode 100644 index 0000000..0f750f3 --- /dev/null +++ b/Runtime/GfxDevice/TextureIdMap.cpp @@ -0,0 +1,31 @@ +#include "UnityPrefix.h" +#include "TextureIdMap.h" + + +void TextureIdMap::Initialize() +{ + if(!s_Inited) + { + s_Textures.set_empty_key(TextureID(-1)); + s_Textures.set_deleted_key(TextureID(-2)); + + s_Inited = true; + } +} + +void TextureIdMap::Uninitialize() +{ + if (!s_Inited) + return; + + //@TODO: make sure all textures are cleaned up properly and re-enabled the assert + //#if 0 // was !UNITY_EDITOR + //Assert(s_Textures.empty()); + //#endif + + // Note, do not set s_Inited to false; would make it impossible to reload GfxDevice + // since the hash map object stays the same but we can't set the empty key again. +} + +TextureIdMap::TextureMap TextureIdMap::s_Textures; +bool TextureIdMap::s_Inited = false; diff --git a/Runtime/GfxDevice/TextureIdMap.h b/Runtime/GfxDevice/TextureIdMap.h new file mode 100644 index 0000000..9b1061c --- /dev/null +++ b/Runtime/GfxDevice/TextureIdMap.h @@ -0,0 +1,70 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" + +#include "Runtime/Utilities/dense_hash_map.h" +#include "Runtime/Utilities/LogAssert.h" + +#include "Runtime/GfxDevice/GfxDeviceConfigure.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +class +TextureIdMap +{ +public: + + static void Initialize(); + static void Uninitialize(); + + static void UpdateTexture(TextureID texid, intptr_t nativeTex); + static void RemoveTexture(TextureID texid); + + static intptr_t QueryNativeTexture(TextureID texid); + + +private: + + struct TextureIDHashFunctor + { + inline size_t operator()(TextureID x) const + { + UInt32 a = x.m_ID; + a = (a+0x7ed55d16) + (a<<12); + a = (a^0xc761c23c) ^ (a>>19); + a = (a+0x165667b1) + (a<<5); + a = (a+0xd3a2646c) ^ (a<<9); + a = (a+0xfd7046c5) + (a<<3); + a = (a^0xb55a4f09) ^ (a>>16); + return a; + } + }; + + + typedef pair<const TextureID, intptr_t> TextureIdToTexturePair; + typedef dense_hash_map< TextureID, intptr_t, TextureIDHashFunctor, std::equal_to<TextureID>, STL_ALLOCATOR(kMemSTL, TextureIdToTexturePair) > TextureMap; + + static TextureMap s_Textures; + + // some devices call OnCreate twice - easier to workaround here + static bool s_Inited; +}; + +inline void TextureIdMap::UpdateTexture(TextureID texid, intptr_t nativeTex) +{ + TextureMap::iterator it = s_Textures.find(texid); + if(it != s_Textures.end()) + it->second = nativeTex; + else + s_Textures.insert(std::make_pair(texid, nativeTex)); +} + +inline void TextureIdMap::RemoveTexture(TextureID texid) +{ + s_Textures.erase(texid); +} + +inline intptr_t TextureIdMap::QueryNativeTexture(TextureID texid) +{ + TextureMap::iterator it = s_Textures.find(texid); + return it == s_Textures.end() ? 0 : it->second; +} diff --git a/Runtime/GfxDevice/TextureUploadUtils.h b/Runtime/GfxDevice/TextureUploadUtils.h new file mode 100644 index 0000000..8543552 --- /dev/null +++ b/Runtime/GfxDevice/TextureUploadUtils.h @@ -0,0 +1,254 @@ +#pragma once + +#include "External/ProphecySDK/include/prcore/surface.hpp" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Graphics/S3Decompression.h" +#include "Runtime/Graphics/FlashATFDecompression.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "GfxDevice.h" +#include "VramLimits.h" + +extern bool IsNPOTTextureAllowed(bool hasMipMap); + +const int kDoubleLDRAlpha = 255 * 0.25f; + + +inline bool SkipLevelsForMasterTextureLimit ( + int masterTextureLimit, + TextureFormat dataFormat, TextureFormat uploadFormat, + int mipCount, + bool uploadIsCompressed, + UInt8** srcData, int* width, int* height, + int* baseLevel, int* maxLevel, int* texWidth, int* texHeight, size_t* textureSize) +{ + bool wasScaledDown = false; + + // For compressed textures, stop applying masterTextureLimit if texture size drops below 4 + if( uploadIsCompressed ) + { + while( masterTextureLimit > 0 && ((*width >> masterTextureLimit) < 4 || (*height >> masterTextureLimit) < 4) ) + { + --masterTextureLimit; + } + } + + // skip several levels in data based on masterTextureLimit + *maxLevel = mipCount - 1; + *baseLevel = std::min( masterTextureLimit, *maxLevel ); + int level; + for( level = 0; level < *baseLevel; ++level ) + { + *srcData += CalculateImageSize (*width, *height, dataFormat); + AssertIf( *width == 1 && *height == 1 && level != *maxLevel ); + *width = std::max( *width / 2, 1 ); + *height = std::max( *height / 2, 1 ); + } + + // Now estimate VRAM usage for the texture + *textureSize = CalculateImageSize (*width, *height, uploadFormat); + if (mipCount > 1) + *textureSize += *textureSize / 3; + int textureSizeKB = *textureSize / 1024; + + const int vramSizeKB = gGraphicsCaps.videoMemoryMB * 1024; + const GfxDeviceStats::MemoryStats& memoryStats = GetRealGfxDevice().GetFrameStats().GetMemoryStats(); + const int currentVramUsageKB = (memoryStats.screenBytes + memoryStats.renderTextureBytes) / 1024; + const int allowedVramUsageKB = std::max( (vramSizeKB - currentVramUsageKB) * kVRAMMaxFreePortionForTexture, 1.0f ); + + // While texture is too large for hardware limits, or too large to sanely fit into VRAM, skip + // mip levels. If it's non-mipmapped one, we have to reduce it and scale it into size that fits. + // Don't do fitting into VRAM for Alpha8 textures (those are used for dynamic fonts, and + // everything can break down if we scale them down). + *texWidth = *width; + *texHeight = *height; + while ( + *texWidth > gGraphicsCaps.maxTextureSize || + *texHeight > gGraphicsCaps.maxTextureSize || + (textureSizeKB > allowedVramUsageKB && dataFormat != kTexFormatAlpha8)) + { + printf_console("Texture2D %ix%i won't fit, reducing size (needed mem=%i used mem=%i allowedmem=%i)\n", *texWidth, *texHeight, textureSizeKB, currentVramUsageKB, allowedVramUsageKB); + if (*baseLevel < *maxLevel) + { + *srcData += CalculateImageSize (*texWidth, *texHeight, dataFormat); + *width = std::max (*width / 2, 1); + *height = std::max (*height / 2, 1); + ++*baseLevel; + } + *texWidth = std::max( *texWidth / 2, 1 ); + *texHeight = std::max( *texHeight / 2, 1 ); + textureSizeKB /= 4; + *textureSize /= 4; + wasScaledDown = true; + if( *texWidth <= 4 && *texHeight <= 4 ) + break; + } + + return wasScaledDown; +} + + +inline void HandleFormatDecompression ( + TextureFormat format, + TextureUsageMode* usageMode, + TextureColorSpace colorSpace, + bool* uploadIsCompressed, + bool* decompressOnTheFly + ) +{ + // Figure out whether we'll upload compressed or decompress on the fly + + ///@TODO: This looks wrong. What the fuck??? + *uploadIsCompressed = IsCompressedDXTTextureFormat(format); + + switch (*usageMode) + { + case kTexUsageLightmapRGBM: + // No special processing for RGBM if we support it + if (*usageMode == kTexUsageLightmapRGBM && gGraphicsCaps.SupportsRGBM()) + *usageMode = kTexUsageNone; + break; + case kTexUsageLightmapDoubleLDR: + // Never any special processing of DoubleLDR in players. + // + // In the editor, we'll add a dummy 0.25f alpha channel to the doubleLDR lightmap. + // When we're in GLES20 emulation mode in the editor we're using pixel shaders compiled + // for the platform the editor is currently running on and that forces RGBM decoding. + // So we get (8.0 * 0.25) * color.rgb -- which is doubleLDR decoding. +#if !UNITY_EDITOR + *usageMode = kTexUsageNone; +#endif + break; + case kTexUsageNormalmapPlain: + // Never any special processing of plain normal maps in players. + // + // In the editor, we'll put .r into .a to make it work with shaders that expect DXT5nm + // encoding. +#if !UNITY_EDITOR + *usageMode = kTexUsageNone; +#endif + break; + default: + *usageMode = kTexUsageNone; + } + + ////@TODO: BIG WTF??? We always decompress on the fly for pvrtc etc atc and wii formats???? + + // Decompress on the fly when the device cannot handle + // the compressed format or we have to do any special processing based on usage mode. + *decompressOnTheFly = (*uploadIsCompressed && (!gGraphicsCaps.hasS3TCCompression || *usageMode != kTexUsageNone)) || + IsCompressedPVRTCTextureFormat(format) || + IsCompressedETCTextureFormat(format) || + IsCompressedATCTextureFormat(format) || + IsCompressedETC2TextureFormat(format) || + IsCompressedASTCTextureFormat(format) || + IsCompressedFlashATFTextureFormat(format); + +# if !UNITY_XENON + //If we are not on Xenon and the texture color space is xenon decompress on the fly + if (*uploadIsCompressed && colorSpace == kTexColorSpaceSRGBXenon) + { + *decompressOnTheFly |= *uploadIsCompressed && colorSpace == kTexColorSpaceSRGBXenon; + } +#endif +} + + +inline void InitImageBuffer (int width, int height, UInt8*& buffer, TextureFormat textureFormat) +{ + int imageSize = CalculateImageSize( width, height, textureFormat ); + if( buffer == NULL ) + buffer = new UInt8[imageSize]; +} + + +inline void PerformUploadConversions ( + int width, int height, + UInt8* dstBuffer, int dstPitch, + TextureUsageMode usageMode, + TextureColorSpace colorSpace, + const prcore::PixelFormat& pf + ) +{ + if (usageMode == kTexUsageLightmapRGBM) + DecodeRGBM (width, height, dstBuffer, dstPitch, pf); +#if UNITY_EDITOR + if (usageMode == kTexUsageLightmapDoubleLDR) + SetAlphaChannel (width, height, dstBuffer, dstPitch, pf, kDoubleLDRAlpha); + if (usageMode == kTexUsageNormalmapPlain) + SetAlphaToRedChannel (width, height, dstBuffer, dstPitch, pf); + if (colorSpace == kTexColorSpaceSRGBXenon) + XenonToNormalSRGBTexture(width, height, dstBuffer, dstPitch, pf); +#endif +} + + +inline void ConvertCompressedTextureUpload ( + int width, int height, + TextureFormat format, + const UInt8* srcData, + UInt8*& decompressBuffer, int& tempBufferPitch, + TextureUsageMode usageMode, + TextureColorSpace colorSpace, + int mipLevel) +{ + int dstWidth = std::max( width, 4 ); + int dstHeight = std::max( height, 4 ); + + InitImageBuffer (dstWidth, dstHeight, decompressBuffer, kTexFormatRGBA32); + tempBufferPitch = GetRowBytesFromWidthAndFormat(width, kTexFormatRGBA32); + + DecompressNativeTextureFormatWithMipLevel (format, width, height, mipLevel, (UInt32*)srcData, dstWidth, dstHeight, (UInt32*)decompressBuffer); + + PerformUploadConversions (width, height, decompressBuffer, tempBufferPitch, usageMode, colorSpace, GetProphecyPixelFormat(kTexFormatRGBA32)); +} + + +inline bool ConvertUncompressedTextureUpload ( + prcore::Surface& srcSurface, + prcore::Surface& dstSurface, + prcore::Surface::BlitMode blitMode, + TextureFormat uploadFormat, + TextureUsageMode usageMode, + TextureColorSpace colorSpace, + int width, int height, UInt8* inplaceData, int pitch, const prcore::PixelFormat& pf, + UInt8*& tempBuffer, int& tempBufferPitch + ) +{ + if (usageMode != kTexUsageNone || colorSpace == kTexColorSpaceSRGBXenon) + { + if (uploadFormat == kTexFormatRGBA32 || uploadFormat == kTexFormatARGB32) + { + // Copy to locked rect + dstSurface.BlitImage( srcSurface, blitMode ); + // Process in place + PerformUploadConversions (width, height, inplaceData, pitch, usageMode, colorSpace, pf); + } + else + { + InitImageBuffer (width, height, tempBuffer, kTexFormatRGBA32); + tempBufferPitch = GetRowBytesFromWidthAndFormat(width, kTexFormatRGBA32); + + // Copy to a temporary buffer so we can process the texture in place + prcore::Surface tempSurface( width, height, tempBufferPitch, pf, tempBuffer ); + tempSurface.BlitImage( srcSurface, blitMode ); + + // Process in place in the temp surface + PerformUploadConversions (width, height, tempBuffer, tempBufferPitch, usageMode, colorSpace, pf); + + // Copy to locked rect + dstSurface.BlitImage( tempSurface, blitMode ); + } + return true; + } + return false; +} + + +inline void AdvanceToNextMipLevel (TextureFormat format, UInt8*& srcData, int& width, int& height, int& texWidth, int& texHeight) +{ + srcData += CalculateImageSize (width, height, format); + width = std::max( width / 2, 1 ); + height = std::max( height / 2, 1 ); + texWidth = std::max( texWidth / 2, 1 ); + texHeight = std::max( texHeight / 2, 1 ); +} diff --git a/Runtime/GfxDevice/TransformState.h b/Runtime/GfxDevice/TransformState.h new file mode 100644 index 0000000..ef56382 --- /dev/null +++ b/Runtime/GfxDevice/TransformState.h @@ -0,0 +1,64 @@ +#pragma once + +#include "GfxDeviceTypes.h" +#include "Runtime/Math/Matrix4x4.h" +#include "BuiltinShaderParams.h" + +struct TransformState +{ + enum { + kWorldDirty = (1<<0), + kViewDirty = (1<<1), + kProjDirty = (1<<2), + + kWorldViewDirty = (kWorldDirty | kViewDirty), + kViewProjDirty = (kViewDirty | kProjDirty), + kWorldViewProjDirty = (kWorldDirty | kViewDirty | kProjDirty), + }; + + Matrix4x4f worldMatrix; + Matrix4x4f projectionMatrixOriginal; // Originally set from Unity code + + Matrix4x4f texMatrices[kMaxSupportedTextureCoords]; + + // cache + mutable Matrix4x4f worldViewMatrix; + + mutable volatile UInt32 dirtyFlags; + +public: + void Invalidate(BuiltinShaderParamValues& builtins); + void UpdateWorldViewMatrix (const BuiltinShaderParamValues& builtins) const; + void SetViewMatrix (const float matrix[16], BuiltinShaderParamValues& builtins); +}; + +inline void TransformState::Invalidate(BuiltinShaderParamValues& builtins) +{ + worldViewMatrix.SetIdentity(); + worldMatrix.SetIdentity(); + builtins.GetWritableMatrixParam(kShaderMatView).SetIdentity(); + builtins.GetWritableMatrixParam(kShaderMatProj).SetIdentity(); + builtins.GetWritableMatrixParam(kShaderMatViewProj).SetIdentity(); + projectionMatrixOriginal.SetIdentity(); + dirtyFlags = kWorldViewProjDirty; +} + +inline void TransformState::UpdateWorldViewMatrix (const BuiltinShaderParamValues& builtins) const +{ + if (dirtyFlags & kWorldViewDirty) + { + MultiplyMatrices4x4 (&builtins.GetMatrixParam(kShaderMatView), &worldMatrix, &worldViewMatrix); + dirtyFlags &= ~kWorldViewDirty; + } +} + +inline void TransformState::SetViewMatrix (const float matrix[16], BuiltinShaderParamValues& builtins) +{ + dirtyFlags |= TransformState::kWorldViewDirty; + Matrix4x4f& viewMat = builtins.GetWritableMatrixParam(kShaderMatView); + const Matrix4x4f& projMat = builtins.GetMatrixParam(kShaderMatProj); + Matrix4x4f& viewProjMat = builtins.GetWritableMatrixParam(kShaderMatViewProj); + CopyMatrix (matrix, viewMat.GetPtr()); + MultiplyMatrices4x4 (&projMat, &viewMat, &viewProjMat); + worldMatrix = Matrix4x4f::identity; +} diff --git a/Runtime/GfxDevice/VramLimits.cpp b/Runtime/GfxDevice/VramLimits.cpp new file mode 100644 index 0000000..36bfe50 --- /dev/null +++ b/Runtime/GfxDevice/VramLimits.cpp @@ -0,0 +1,39 @@ +#include "UnityPrefix.h" +#include "VramLimits.h" +#include "Runtime/Shaders/GraphicsCaps.h" + + +int ChooseSuitableFSAALevel( int width, int height, int backbufferBPP, int frontbufferBPP, int depthBPP, int fsaa ) +{ + // no AA support? + if( !gGraphicsCaps.hasMultiSample ) + return 0; + + // figure out appropriate AA level based on VRAM and screen size + int vramKB = int(gGraphicsCaps.videoMemoryMB * 1024); + + const int vramAllowedByPortion = int(vramKB * 0.5f); // allow max. 50% of total VRAM for screen + const int vramAllowedMax = 256 * 1024; // max 256MB for screen + // Make sure at least this amount of free of VRAM left after the screen. + // E.g. on a 32MB VRAM PPC MacMini, going 1280x960 2xAA still corrupts the screen (VRAM taken: 23.5MB). + // So we need to keep somewhat more free than 8MB... 16MB works. + const int vramAllowedWithKeepingSomeFree = int(vramKB - 16*1024); + + int vramAllowedKB = std::min(vramAllowedByPortion, std::min(vramAllowedMax,vramAllowedWithKeepingSomeFree)); + int vramNeededKB; + do { + vramNeededKB = width * height * (std::max(fsaa,1) * (backbufferBPP+depthBPP) + frontbufferBPP) / 1024; + if( vramNeededKB < vramAllowedKB ) + break; + + #if !UNITY_RELEASE + printf_console("Screen %ix%i at %ixAA won't fit, reducing AA (needed mem=%i allowedmem=%i)\n", width, height, fsaa, vramNeededKB, vramAllowedKB ); + #endif + fsaa /= 2; + } while( fsaa > 1 ); + + if( fsaa == 1 ) + fsaa = 0; + + return fsaa; +} diff --git a/Runtime/GfxDevice/VramLimits.h b/Runtime/GfxDevice/VramLimits.h new file mode 100644 index 0000000..238f260 --- /dev/null +++ b/Runtime/GfxDevice/VramLimits.h @@ -0,0 +1,11 @@ +#pragma once + +// Various limits for what we can do based on VRAM size + +#define kVRAMEnoughForLargeShadowmaps 480 // VRAM MB after which we allow even higher resolution shadow maps + +#define kVRAMMaxFreePortionForShadowMap 0.3f // allow single shadowmap to take 30% of possibly free VRAM +#define kVRAMMaxFreePortionForTexture 0.4f // allow single texture to take 40% of possibly free VRAM + + +int ChooseSuitableFSAALevel( int width, int height, int backbufferBPP, int frontbufferBPP, int depthBPP, int fsaa ); diff --git a/Runtime/GfxDevice/d3d/CombinerD3D.cpp b/Runtime/GfxDevice/d3d/CombinerD3D.cpp new file mode 100644 index 0000000..2be2b47 --- /dev/null +++ b/Runtime/GfxDevice/d3d/CombinerD3D.cpp @@ -0,0 +1,600 @@ +#include "UnityPrefix.h" +#include "CombinerD3D.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/pass.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "D3D9Context.h" +#include "Runtime/Utilities/BitUtility.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "External/DirectX/builds/dx9include/d3dx9.h" + + +// -------------------------------------------------------------------------- +// Combiners to fixed function texture stages + +// NOTE: not all GL combiner modes are representable in TSS: +// * per-stage constants +// * DOUBLE/QUAD on arbitrary operations +// * a*b+-c, a*b-c +// So what we do is: if hardware supports ps_1_1, we generate pixel shaders on the fly, see below. + +static D3DTEXTUREOP kCombinerFuncTable[3][8] = { + { D3DTOP_SELECTARG1, D3DTOP_MODULATE, D3DTOP_ADD, D3DTOP_ADDSIGNED, D3DTOP_SUBTRACT, D3DTOP_LERP, D3DTOP_DOTPRODUCT3, D3DTOP_DOTPRODUCT3 }, + { D3DTOP_ADD, D3DTOP_MODULATE2X, D3DTOP_DISABLE, D3DTOP_ADDSIGNED2X, D3DTOP_DISABLE, D3DTOP_DISABLE, D3DTOP_DISABLE, D3DTOP_DISABLE }, + { D3DTOP_DISABLE, D3DTOP_MODULATE4X, D3DTOP_DISABLE, D3DTOP_DISABLE, D3DTOP_DISABLE, D3DTOP_DISABLE, D3DTOP_DISABLE, D3DTOP_DISABLE }, +}; +static DWORD kCombinerFuncCapsTable[3][8] = { + { D3DTEXOPCAPS_SELECTARG1, D3DTEXOPCAPS_MODULATE, D3DTEXOPCAPS_ADD, D3DTEXOPCAPS_ADDSIGNED, D3DTEXOPCAPS_SUBTRACT, D3DTEXOPCAPS_LERP, D3DTEXOPCAPS_DOTPRODUCT3, D3DTEXOPCAPS_DOTPRODUCT3 }, + { D3DTEXOPCAPS_ADD, D3DTEXOPCAPS_MODULATE2X, 0, D3DTEXOPCAPS_ADDSIGNED2X, 0, 0, 0, 0 }, + { 0, D3DTEXOPCAPS_MODULATE4X, 0, 0, 0, 0, 0, 0 }, +}; + +void InitializeCombinerCapsD3D9() +{ + DWORD texOpCaps = gGraphicsCaps.d3d.d3dcaps.TextureOpCaps; + for( int r = 0; r < 3; ++r ) { + for( int c = 0; c < 8; ++c ) { + if( kCombinerFuncCapsTable[r][c] ) { + if( !(texOpCaps & kCombinerFuncCapsTable[r][c]) ) + kCombinerFuncTable[r][c] = D3DTOP_DISABLE; + } + } + } +} + +static int kCombinerSourceTable[4] = { + D3DTA_CURRENT, D3DTA_TEXTURE, D3DTA_TFACTOR, D3DTA_DIFFUSE // TODO: TFACTOR is global, not per-stage! +}; +static const int kCombinerOperandModTableRGB[4] = { + 0, D3DTA_ALPHAREPLICATE, D3DTA_COMPLEMENT, D3DTA_ALPHAREPLICATE | D3DTA_COMPLEMENT +}; +static const int kCombinerOperandModTableAlpha[4] = { + 0, 0, D3DTA_COMPLEMENT, D3DTA_COMPLEMENT +}; + + + +static bool CombinerToTextureStage( UInt32 comb, D3DTEXTUREOP& outOp, int outArgs[3], bool alpha ) +{ + int s0 = (comb >> combiner::kSrcZeroShift) & 0xFF; + + int cf = COMBINER_GET_FUNC(comb); + int s1 = (comb) & 0xFF; + int scale = HighestBit( (comb >> combiner::kScaleShift) ); + AssertIf( scale < 0 || scale > 2 ); + + const int* kCombinerOperandModTable = alpha ? kCombinerOperandModTableAlpha : kCombinerOperandModTableRGB; + int source0 = kCombinerSourceTable[s0 & combiner::kSourceMask] | kCombinerOperandModTable[s0 >> combiner::kOperandShift]; + int source1 = kCombinerSourceTable[s1 & combiner::kSourceMask] | kCombinerOperandModTable[s1 >> combiner::kOperandShift]; + if( !(cf & combiner::kBlendFuncMask) ) + { + outOp = kCombinerFuncTable[scale][cf]; + if( outOp == D3DTOP_DISABLE ) + return false; + // we emulate "source double" with "source + source" + if( cf == 0 ) + source1 = source0; + outArgs[0] = source0; + outArgs[1] = source1; + outArgs[2] = D3DTA_CURRENT; + } + else + { + int blendF = COMBINER_GET_BLEND_FUNC_INDEX(cf); + int src2 = cf & combiner::kSourceMask; + int oper2 = ((cf & combiner::kOperandTwo) >> combiner::kOperandShift) | 1; + int source2 = kCombinerSourceTable[src2] | kCombinerOperandModTable[oper2]; + + DWORD texOpCaps = gGraphicsCaps.d3d.d3dcaps.TextureOpCaps; + + switch( blendF ) + { + case 0: + // src0 lerp(src2 alpha) src1 + if( (scale != 0) || !(texOpCaps & D3DTEXOPCAPS_LERP) ) + return false; + outOp = D3DTOP_LERP; + outArgs[0] = source0; + outArgs[1] = source1; + outArgs[2] = source2; + break; + case 1: + // src0 * src2 alpha + src1 + if( texOpCaps & D3DTEXOPCAPS_MULTIPLYADD ) { + if( scale != 0 ) + return false; + outOp = D3DTOP_MULTIPLYADD; + outArgs[0] = source0; + outArgs[1] = source2; + outArgs[2] = source1; + } else { + // TODO + return false; + } + break; + case 2: + // src0 * src2 alpha +- src1 + // not supported! + return false; + case 3: + // src0 * src2 alpha - src1 + // not supported! + return false; + default: + AssertString( "Unknown combiner blend function" ); + return false; + } + AssertIf( outOp <= D3DTOP_DISABLE || outOp > D3DTOP_LERP ); + } + + return true; +} + +static bool CombinerToTextureStage( const ShaderLab::TextureBinding& te, D3DTextureStage& stage, bool& outTFactorUsed ) +{ + int combColor = te.m_CombColor; + if( !CombinerToTextureStage( combColor, stage.colorOp, stage.colorArgs, false ) ) + return false; + + // For DOT3 operation, we have to force using no function on alpha + // However, on some old cards this has no effect; they always replicate DOT3 to all channels + // (e.g. GeForce 2). Oh well. + int combColorFunc = COMBINER_GET_FUNC(combColor); + int combAlpha = te.m_CombAlpha; + if( combColorFunc == 6 ) { // DOT3 + combAlpha &= ~(0xFF << combiner::kFuncShift); + } + if( !CombinerToTextureStage( combAlpha, stage.alphaOp, stage.alphaArgs, true ) ) + return false; + + if( te.IsTexColorUsed() ) + { + outTFactorUsed = true; + } + + return true; +} + + +// -------------------------------------------------------------------------- +// Combiners to pixel shader 1.1 + + +// Supports up to 4 texture stages. +// Each stage outputs into r0 register. +// Per-stage constants are stored in corresponding constant registers [c0..c3]. +// "Color" command (TFACTOR equivalent) should store in c4. +// r1 is used in some cases to load & process some constants (e.g. where we'd want to do a c4_bias, we first load it into r1 and then do r1_bias) + + +// Cache for generated pixel shaders. +struct CombinersCacheEntry +{ + UInt32 combColor[kMaxD3DTextureStagesForPS]; + UInt32 combAlpha[kMaxD3DTextureStagesForPS]; + IDirect3DPixelShader9* pixelShader; + bool specular; + + bool Equals( int count, const ShaderLab::TextureBinding* texEnvs, bool specular ) const + { + AssertIf( count > kMaxD3DTextureStagesForPS ); + if( specular != this->specular ) + return false; + for( int i = 0; i < count; ++i ) + { + if( texEnvs[i].m_CombColor != combColor[i] ) + return false; + if( texEnvs[i].m_CombAlpha != combAlpha[i] ) + return false; + } + return true; + } +}; +// Not a map on purpose - comparison is cheap and we want to store everything in a single block. +static std::vector<CombinersCacheEntry> s_CombinersCache[kMaxD3DTextureStagesForPS][2]; // [2] = lighting off, lighting on + +void TextureCombinersD3D::CleanupCombinerCache() +{ + for( int i = 0; i < kMaxD3DTextureStagesForPS; ++i ) + { + for( int j = 0; j < 2; ++j ) + { + std::vector<CombinersCacheEntry>& cache = s_CombinersCache[i][j]; + for( int k = 0; k < cache.size(); ++k ) + { + IDirect3DPixelShader9* ps = cache[k].pixelShader; + if( ps ) { + ULONG refCount = ps->Release(); + AssertIf( refCount != 0 ); + } + } + cache.clear(); + cache.swap(std::vector<CombinersCacheEntry>()); + } + } +} + +static const char* kPSDestRegRGBA[3] = { " r0", "_x2 r0", "_x4 r0" }; +static const char* kPSDestRegRGB [3] = { " r0.rgb", "_x2 r0.rgb", "_x4 r0.rgb" }; +static const char* kPSDestRegA [3] = { " r0.a", "_x2 r0.a", "_x4 r0.a" }; + +static const char* kPSOperandPrefixTable[4] = { + "", "", "1-", "1-", +}; +static const char* kPSOperandSuffixTableRGB[4] = { + "", ".a", "", ".a", +}; + +static std::string CombinerSrcPS( combiner::Source source, int stage, bool lighting ) +{ + switch( source ) + { + case combiner::kSrcPrevious: + if( stage == 0 ) + return lighting ? "v0" : "c4"; + else + return "r0"; + case combiner::kSrcTexture: + return 't' + IntToString(stage); + case combiner::kSrcConstant: + return 'c' + IntToString(stage); + case combiner::kSrcPrimaryColor: + return lighting ? "v0" : "c4"; + default: + AssertString( "Unknown source" ); + return ""; + } +} + +static void FixupForConstantModifiers( std::string& source, std::string& outFixup, UInt32 operand, bool alpha, bool dot3 ) +{ + if( source.size() >= 4 && source[0]=='1' && source[1]=='-' && source[2] == 'c' ) + { + std::string sub = source.substr( 3, source.size()-3 ); + outFixup += std::string( alpha ? "+mov_sat r1.a, c" : "mov_sat r1.rgb, c" ) + sub + '\n'; + source = "1-r1"; + if( !alpha ) + source += kPSOperandSuffixTableRGB[operand]; + } + if( dot3 && source.size() >= 2 && source[0]=='c' ) + { + std::string sub = source.substr( 1, source.size()-1 ); + outFixup += std::string( alpha ? "+mov_sat r1.a, c" : "mov_sat r1.rgb, c" ) + sub + '\n'; + source = "r1"; + if( !alpha ) + source += kPSOperandSuffixTableRGB[operand]; + } +} + +static void CombinerToPixelShaderText( int stage, bool lighting, UInt32 comb, bool alpha, std::string& outInstruction, std::string& outPrevFixup, bool& outPrevSat, bool& outSkipAlpha ) +{ + outSkipAlpha = false; + + int s0 = (comb >> combiner::kSrcZeroShift) & 0xFF; + + int cf = COMBINER_GET_FUNC(comb); + int s1 = (comb) & 0xFF; + int scale = HighestBit( (comb >> combiner::kScaleShift) ); + AssertIf( scale < 0 || scale > 2 ); + + combiner::Source src0 = static_cast<combiner::Source>(s0 & combiner::kSourceMask); + combiner::Source src1 = static_cast<combiner::Source>(s1 & combiner::kSourceMask); + UInt32 oper0 = s0 >> combiner::kOperandShift; + UInt32 oper1 = s1 >> combiner::kOperandShift; + std::string source0 = kPSOperandPrefixTable[oper0] + CombinerSrcPS( src0, stage, lighting ); + if( !alpha ) + source0 += kPSOperandSuffixTableRGB[oper0]; + std::string source1 = kPSOperandPrefixTable[oper1] + CombinerSrcPS( src1, stage, lighting ); + std::string suffix1 = alpha ? "" : kPSOperandSuffixTableRGB[oper1]; + const char** kPSDestReg = (cf == 7) ? kPSDestRegRGBA : (alpha ? kPSDestRegA : kPSDestRegRGB); + std::string destReg = kPSDestReg[scale]; + + std::string text; + + // Some special rules: + // * For bias modifier or a lerp, a previous instruction should saturate the result + // * For negate modifier, a previous instruction can't saturate the result (hence can't just saturate everything) + // * 1-x or x_bias not allowed on constants. So if we detect such case, we try to load it into r1 + // with additional instruction. + // * Emulating DOT3 requires _bx2 modifier, which is not allowed on constants. So we also detect + // that and load it into r1 with additional instruction. + + bool dot3 = (cf == 6 || cf == 7); + FixupForConstantModifiers( source0, outPrevFixup, oper0, alpha, dot3 ); + FixupForConstantModifiers( source1, outPrevFixup, oper1, alpha, dot3 ); + + bool addSatOnPrevious = false; // should we add "saturate" on previous instruction? + if( !(cf & combiner::kBlendFuncMask) ) + { + switch( cf ) + { + case 0: text = "mov" + destReg + ", " + source0; break; + case 1: text = "mul" + destReg + ", " + source0 + ", " + source1 + suffix1; break; + case 2: text = "add" + destReg + ", " + source0 + ", " + source1 + suffix1; break; + case 3: + if( source1[0] == 'c' ) + { + std::string sub = source1.substr( 1, source1.size()-1 ); + outPrevFixup += std::string( alpha ? "+mov_sat r1.a, c" : "mov_sat r1.rgb, c" ) + sub + '\n'; + source1 = "r1"; + } + text = "add" + destReg + ", " + source0 + ", " + source1 + "_bias" + suffix1; + if( (s1 & combiner::kSourceMask) == 0 ) // if source1 is "previous", need to saturate previous instruction + addSatOnPrevious = true; + break; + case 4: text = "sub" + destReg + ", " + source0 + ", " + source1 + suffix1; break; + case 5: AssertIf(false); break; + case 6: + // DOT3: for rgb do the dot, for alpha just use source0 + if( alpha ) + text += "mov" + destReg + ", " + source0; + else + text = "dp3" + destReg + ", " + source0 + "_bx2, " + source1 + "_bx2" + suffix1; break; + case 7: + // DOT3RGBA: do the dot into all four channels, and do not issue co-issued alpha + // instructions for this stage. + text = "dp3" + destReg + ", " + source0 + "_bx2, " + source1 + "_bx2" + suffix1; + outSkipAlpha = true; + break; + } + } + else + { + int blendF = COMBINER_GET_BLEND_FUNC_INDEX(cf); + combiner::Source src2 = static_cast<combiner::Source>(cf & combiner::kSourceMask); + int oper2 = ((cf & combiner::kOperandTwo) >> combiner::kOperandShift) | 1; + std::string source2 = kPSOperandPrefixTable[oper2] + CombinerSrcPS(src2, stage, lighting); + if( !alpha ) + source2 += kPSOperandSuffixTableRGB[oper2]; + + FixupForConstantModifiers( source2, outPrevFixup, oper2, alpha, false ); + + switch( blendF ) + { + case 0: + // src0 lerp(src2 alpha) src1 + text = "lrp" + destReg + ", " + source2 + ", " + source0 + ", " + source1 + suffix1; + if( src2 == combiner::kSrcPrevious ) // if src2 is "previous", need to saturate previous instruction + addSatOnPrevious = true; + break; + case 1: + // src0 * src2 alpha + src1 + text = "mad" + destReg + ", " + source0 + ", " + source2 + ", " + source1 + suffix1; + break; + case 2: + // src0 * src2 alpha +- src1 + if( source1[0] == 'c' ) + { + std::string sub = source1.substr( 1, source1.size()-1 ); + outPrevFixup += std::string( alpha ? "+mov_sat r1.a, c" : "mov_sat r1.rgb, c" ) + sub + '\n'; + source1 = "r1"; + } + text = "mad" + destReg + ", " + source0 + ", " + source2 + ", " + source1 + "_bias" + suffix1; + if( (s1 & combiner::kSourceMask) == 0 ) // if source1 is "previous", need to saturate previous instruction + addSatOnPrevious = true; + break; + case 3: + // src0 * src2 alpha - src1 + text = "mad" + destReg + ", " + source0 + ", " + source2 + ", -" + source1 + suffix1; + break; + default: + AssertString( "Unknown combiner blend function" ); + break; + } + } + + // if we're not the first instruction and we need to modify previous one - do it. + int typeIndex = alpha ? 1 : 0; + outPrevSat = false; + if( stage != 0 && addSatOnPrevious ) + outPrevSat = true; + + if( alpha ) + outInstruction += '+'; + outInstruction += text; + outInstruction += '\n'; +} + + +// GpuProgramsD3D.cpp +ID3DXBuffer* AssembleD3DShader( const std::string& source ); + + +static IDirect3DPixelShader9* CombinersToPixelShader( int count, const ShaderLab::TextureBinding* texEnvs, bool lighting, bool addSpecular ) +{ + AssertIf( count < 1 ); + + // ps_1_1 supports only 4 textures + if (count > kMaxD3DTextureStagesForPS) + return NULL; + + // look for such combiner setup in cache + int lightingIdx = lighting ? 1 : 0; + int cacheCount = s_CombinersCache[count-1][lightingIdx].size(); + for( int i = 0; i < cacheCount; ++i ) + { + CombinersCacheEntry& ce = s_CombinersCache[count-1][lightingIdx][i]; + if( ce.Equals( count, texEnvs, addSpecular ) ) + { + AssertIf( !ce.pixelShader ); + return ce.pixelShader; + } + } + + std::string text = "ps_1_1\n"; + // sample textures + for( int i = 0; i < count; ++i ) + { + text += "tex t" + IntToString(i) + '\n'; + } + + // do combiner operations + CombinersCacheEntry cacheEntry; + int previousInstructions[2] = { 0, 0 }; + for( int i = 0; i < count; ++i ) + { + UInt32 combColor = texEnvs[i].m_CombColor; + UInt32 combAlpha = texEnvs[i].m_CombAlpha; + cacheEntry.combColor[i] = combColor; + cacheEntry.combAlpha[i] = combAlpha; + cacheEntry.specular = addSpecular; + std::string instruction, fixup; + bool satPrevious, skipAlpha; + // color + CombinerToPixelShaderText( i, lighting, combColor, false, instruction, fixup, satPrevious, skipAlpha ); + if( satPrevious ) { + while( text[previousInstructions[0]] != ' ' ) + ++previousInstructions[0]; + text.insert( previousInstructions[0], "_sat" ); + previousInstructions[1] += 4; // move the other pointer forward by _sat length as well + } + int colorInstructionLength = instruction.size(); + // alpha + if( !skipAlpha ) + { + CombinerToPixelShaderText( i, lighting, combAlpha, true, instruction, fixup, satPrevious, skipAlpha ); + if( satPrevious ) { + while( text[previousInstructions[1]] != ' ' ) + ++previousInstructions[1]; + text.insert( previousInstructions[1], "_sat" ); + previousInstructions[0] += 4; // move the other pointer forward by _sat length as well + } + } + + text += fixup; + previousInstructions[0] = text.size(); + previousInstructions[1] = text.size() + (skipAlpha ? 0 : colorInstructionLength); + text += instruction; + } + + // add specular at the end if needed + if( addSpecular ) + { + text += "add r0.rgb, r0, v1"; + } + + // compile pixel shader + HRESULT hr; + IDirect3DDevice9* dev = GetD3DDevice(); + + // assemble shader + ID3DXBuffer *compiledShader = AssembleD3DShader( text ); + IDirect3DPixelShader9* ps = NULL; + if( compiledShader ) + { + // create shader + hr = dev->CreatePixelShader( (const DWORD*)compiledShader->GetBufferPointer(), &ps ); + compiledShader->Release(); + if( FAILED(hr) ) + { + ErrorStringMsg ("D3D9 Combiners: failed to create pixel shader representation: %s", text.c_str()); + } + } + AssertIf( !ps ); + + // insert into cache + cacheEntry.pixelShader = ps; + s_CombinersCache[count-1][lightingIdx].push_back( cacheEntry ); + + return ps; +} + + +// -------------------------------------------------------------------------- + + + +TextureCombinersD3D* TextureCombinersD3D::Create( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) +{ + static int uniqueIDCounter = 1; + + static bool combinerCapsInitialized = false; + if( !combinerCapsInitialized ) + { + InitializeCombinerCapsD3D9(); + combinerCapsInitialized = true; + } + + // For threaded rendering this check is done on the client side (and we get NULL here) + if (props) + { + // check texgen modes & texture dimension are supported + for( int i = 0; i < count; ++i ) { + TextureDimension texDim; + TexGenMode texGen; + GetTexEnvInfoFromName( texEnvs[i].m_TextureName, texDim, texGen, props ); + if( !ShaderLab::IsTexEnvSupported( texEnvs[i].m_TextureName, texDim, texGen ) ) + return NULL; + } + } + + bool canConvertToStages = true; + + // "primary" in the combiner might refer to diffuse or texture factor, depending on + // whether lighting is on or vertex colors are bound + kCombinerSourceTable[3] = hasVertexColorOrLighting ? D3DTA_DIFFUSE : D3DTA_TFACTOR; + + TextureCombinersD3D* d3dte = new TextureCombinersD3D(); + d3dte->uniqueID = ++uniqueIDCounter; + d3dte->envCount = count; + d3dte->texEnvs = texEnvs; + d3dte->pixelShader = NULL; + d3dte->textureFactorIndex = -1; + + // special case: when no SetTextures are present, setup to do { combine primary } equivalent + if( count == 0 ) + { + d3dte->stages[0].colorOp = D3DTOP_SELECTARG1; + d3dte->stages[0].colorArgs[0] = d3dte->stages[0].colorArgs[1] = d3dte->stages[0].colorArgs[2] = kCombinerSourceTable[3]; + d3dte->stages[0].alphaOp = D3DTOP_SELECTARG1; + d3dte->stages[0].alphaArgs[0] = d3dte->stages[0].alphaArgs[1] = d3dte->stages[0].alphaArgs[2] = kCombinerSourceTable[3]; + d3dte->stages[1].colorOp = D3DTOP_DISABLE; + d3dte->stageCount = 1; + return d3dte; + } + + // try to convert to pixel shader and use that if everything is ok + d3dte->pixelShader = CombinersToPixelShader( count, texEnvs, hasVertexColorOrLighting, usesAddSpecular ); + + // if don't have pixel shader, convert to TSS setup + if( !d3dte->pixelShader ) + { + if( count > gGraphicsCaps.d3d.d3dcaps.MaxSimultaneousTextures ) + { + // In theory we could convert more; if most of combiner stages do not actually + // use the texture. In practice we just cap it at MaxSimultaneousTextures; + // it will match GL behaviour as well. + canConvertToStages = false; + } + else + { + for( int i = 0; i < count; ++i ) + { + const ShaderLab::TextureBinding& te = texEnvs[i]; + D3DTextureStage& stage = d3dte->stages[i]; + bool textureFactorUsed = false; + if( !CombinerToTextureStage(te, stage, textureFactorUsed) ) + { + canConvertToStages = false; + break; + } + if (textureFactorUsed) + { + d3dte->textureFactorIndex = i; + } + } + d3dte->stages[count].colorOp = D3DTOP_DISABLE; + } + + // no can't do + if( !canConvertToStages ) + { + delete d3dte; + return NULL; + } + } + + d3dte->stageCount = count; + return d3dte; +} diff --git a/Runtime/GfxDevice/d3d/CombinerD3D.h b/Runtime/GfxDevice/d3d/CombinerD3D.h new file mode 100644 index 0000000..6f7fb05 --- /dev/null +++ b/Runtime/GfxDevice/d3d/CombinerD3D.h @@ -0,0 +1,37 @@ +#pragma once + +#include "D3D9Includes.h" +#include "External/shaderlab/Library/shadertypes.h" + +namespace ShaderLab { + struct TextureBinding; + class TexEnv; +} + + +const int kMaxD3DTextureStages = 8; +const int kMaxD3DTextureStagesForPS = 4; + +struct D3DTextureStage +{ + D3DTEXTUREOP colorOp; + int colorArgs[3]; + D3DTEXTUREOP alphaOp; + int alphaArgs[3]; +}; + +struct TextureCombinersD3D +{ + static TextureCombinersD3D* Create( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + static void CleanupCombinerCache(); + + D3DTextureStage stages[kMaxD3DTextureStages+1]; + int envCount, stageCount; // these might be different! + IDirect3DPixelShader9* pixelShader; + const ShaderLab::TextureBinding* texEnvs; + + int textureFactorIndex; + bool textureFactorUsed; + + int uniqueID; +}; diff --git a/Runtime/GfxDevice/d3d/D3D9Context.cpp b/Runtime/GfxDevice/d3d/D3D9Context.cpp new file mode 100644 index 0000000..e192ad8 --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Context.cpp @@ -0,0 +1,629 @@ +#include "UnityPrefix.h" +#include "D3D9Context.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "D3D9Enumeration.h" +#include "D3D9Utils.h" +#include "GfxDeviceD3D9.h" +#include "TimerQueryD3D9.h" +#include "PlatformDependent/Win/WinUtils.h" +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Threads/ThreadSharedObject.h" +#include "Runtime/Misc/Plugins.h" +#if UNITY_EDITOR +#include "Runtime/GfxDevice/GfxDeviceSetup.h" +#include "Runtime/Misc/QualitySettings.h" +#include "Runtime/Camera/RenderManager.h" +#include "D3D9Window.h" +#endif + +#if WEBPLUG +#define ENABLE_NV_PERFHUD 0 +#else +#define ENABLE_NV_PERFHUD 1 +#endif + +#define ENABLE_D3D_WINDOW_LOGGING 1 + +static IDirect3D9* s_D3D = NULL; +static IDirect3DDevice9* s_Device = NULL; + +static RenderColorSurfaceD3D9 s_BackBuffer; +static RenderDepthSurfaceD3D9 s_DepthStencil; +static HWND s_Window = NULL; +static HINSTANCE s_D3DDll = NULL; +static D3DPRESENT_PARAMETERS s_PresentParams; +static D3D9FormatCaps* s_FormatCaps = NULL; +static bool s_CurrentlyWindowed = true; +static D3DDISPLAYMODE s_LastWindowedMode; +bool g_D3DUsesMixedVP = false; +bool g_D3DHasDepthStencil = true; +D3DFORMAT g_D3DDepthStencilFormat = D3DFMT_D16; +D3DDEVTYPE g_D3DDevType; +DWORD g_D3DAdapter = D3DADAPTER_DEFAULT; + +#if WEBPLUG +extern bool gInsideFullscreenToggle; +#endif + +typedef IDirect3D9* (WINAPI* Direct3DCreate9Func)(UINT); + +GfxDeviceD3D9& GetD3D9GfxDevice(); +void SetD3D9DeviceLost( bool lost ); // GfxDeviceD3D9.cpp +bool IsD3D9DeviceLost(); +void ResetDynamicResourcesD3D9(); + +#if ENABLE_PROFILER +D3DPERF_BeginEventFunc g_D3D9BeginEventFunc; +D3DPERF_EndEventFunc g_D3D9EndEventFunc; +#endif + + +bool InitializeD3D(D3DDEVTYPE devtype) +{ + AssertIf( s_D3D || s_Device || s_Window || s_D3DDll || s_FormatCaps ); + g_D3DDevType = devtype; + + s_D3DDll = LoadLibrary( "d3d9.dll" ); + if( !s_D3DDll ) + { + printf_console( "d3d: no D3D9 installed\n" ); + return false; // no d3d9 installed + } + + Direct3DCreate9Func createFunc = (Direct3DCreate9Func)GetProcAddress( s_D3DDll, "Direct3DCreate9" ); + if( !createFunc ) + { + printf_console( "d3d: Direct3DCreate9 not found\n" ); + FreeLibrary( s_D3DDll ); + s_D3DDll = NULL; + return false; // for some reason Direct3DCreate9 not found + } + + #if ENABLE_PROFILER + g_D3D9BeginEventFunc = (D3DPERF_BeginEventFunc)GetProcAddress(s_D3DDll, "D3DPERF_BeginEvent"); + g_D3D9EndEventFunc = (D3DPERF_EndEventFunc)GetProcAddress(s_D3DDll, "D3DPERF_EndEvent"); + #endif + + // create D3D object + s_D3D = createFunc( D3D_SDK_VERSION ); + if( !s_D3D ) + { + printf_console( "d3d: no 9.0c available\n" ); + FreeLibrary( s_D3DDll ); + s_D3DDll = NULL; + return false; // D3D initialization failed + } + + // validate the adapter ordinal + UINT adapterCount = s_D3D->GetAdapterCount(); + if ( g_D3DAdapter >= adapterCount ) + g_D3DAdapter = D3DADAPTER_DEFAULT; + + // check whether we have a HAL device + D3DDISPLAYMODE mode; + HRESULT hr; + if (FAILED(hr = s_D3D->GetAdapterDisplayMode(g_D3DAdapter, &mode))) + { + printf_console ("d3d: failed to get adapter mode (adapter %d error 0x%08x)\n", g_D3DAdapter, hr); + s_D3D->Release(); + s_D3D = NULL; + FreeLibrary( s_D3DDll ); + s_D3DDll = NULL; + return false; // failed to get adapter mode + } + if( FAILED( s_D3D->CheckDeviceType( g_D3DAdapter, g_D3DDevType, mode.Format, mode.Format, TRUE ) ) ) + { + printf_console( "d3d: no support for this device type (accelerated/ref)\n" ); + s_D3D->Release(); + s_D3D = NULL; + FreeLibrary( s_D3DDll ); + s_D3DDll = NULL; + return false; // no HAL driver available + } + + // enumerate all formats, multi sample types and whatnot + s_FormatCaps = new D3D9FormatCaps(); + if( !s_FormatCaps->Enumerate( *s_D3D ) ) + { + printf_console( "d3d: no video modes available\n" ); + return false; + } + + return true; +} + +IDirect3D9* GetD3DObject() +{ + AssertIf( !s_D3D ); + return s_D3D; +} +D3D9FormatCaps* GetD3DFormatCaps() +{ + AssertIf( !s_FormatCaps ); + return s_FormatCaps; +} + +void CleanupD3D() +{ + AssertIf( s_Device || s_Window ); + + delete s_FormatCaps; + s_FormatCaps = NULL; + + if( s_D3D ) + { + s_D3D->Release(); + s_D3D = NULL; + } + if( s_D3DDll ) + { + FreeLibrary( s_D3DDll ); + s_D3DDll = NULL; + } +} + +D3DFORMAT GetD3DFormatForChecks() +{ + AssertIf( !s_FormatCaps ); + return s_FormatCaps->GetAdapterFormatForChecks(); +} + +static void SetFramebufferDepthFormat(GfxDevice* realDevice, D3DFORMAT format) +{ + // Not the most robust way to figure out the format, but should do. + int depthBPP = GetBPPFromD3DFormat(format); + DepthBufferFormat depthFormat = kDepthFormatNone; + if (depthBPP == 16) + depthFormat = kDepthFormat16; + else if (depthBPP == 32) + depthFormat = kDepthFormat24; + realDevice->SetFramebufferDepthFormat(depthFormat); + + // Set it on the client device as well, if we're changing resolutions + // and the property hasn't been propagated by copying from the real to client device. + if (IsGfxDevice()) + GetGfxDevice().SetFramebufferDepthFormat(depthFormat); +} + +bool InitializeOrResetD3DDevice( + class GfxDevice* device, + HWND window, int width, int height, + int refreshRate, bool fullscreen, int vBlankCount, int fsaa, + int& outBackbufferBPP, int& outFrontbufferBPP, int& outDepthBPP, int& outFSAA ) +{ + AssertIf( !s_D3D ); + + outBackbufferBPP = 4; + outFrontbufferBPP = 4; + outDepthBPP = 4; + outFSAA = 0; + + width = std::max(width, 1); + height = std::max(height, 1); + + D3DDISPLAYMODE mode; + if( s_CurrentlyWindowed ) + { + HRESULT hr = s_D3D->GetAdapterDisplayMode( g_D3DAdapter, &mode ); + if( FAILED( hr ) ) + { + printf_console( "d3d initialize: failed to get adapter display mode [%s]\n", GetD3D9Error(hr) ); + return false; + } + s_LastWindowedMode = mode; + } + else + { + // If we are fullscreen right now, use last checked Windowed mode format + // to choose compatible formats. Otherwise we won't be able to switch to 16 bit + // desktop mode after a 32 bit fullscreen one. + mode = s_LastWindowedMode; + } + + D3DPRESENT_PARAMETERS& pparams = s_PresentParams; + ZeroMemory (&pparams, sizeof(D3DPRESENT_PARAMETERS)); + pparams.BackBufferWidth = width; + pparams.BackBufferHeight = height; + pparams.BackBufferCount = 1; + pparams.hDeviceWindow = window; + pparams.FullScreen_RefreshRateInHz = fullscreen ? refreshRate : 0; + + pparams.EnableAutoDepthStencil = FALSE; + g_D3DHasDepthStencil = true; + + pparams.Windowed = fullscreen ? FALSE : TRUE; + pparams.SwapEffect = D3DSWAPEFFECT_DISCARD; + + // fullscreen FSAA might be buggy + if( fullscreen && gGraphicsCaps.buggyFullscreenFSAA ) + fsaa = 1; + + s_FormatCaps->FindBestPresentationParams( width, height, mode.Format, !fullscreen, vBlankCount, fsaa, pparams ); + + outBackbufferBPP = GetBPPFromD3DFormat(pparams.BackBufferFormat)/8; + outFrontbufferBPP = GetBPPFromD3DFormat(mode.Format)/8; + outDepthBPP = GetBPPFromD3DFormat(pparams.AutoDepthStencilFormat)/8; + outFSAA = (pparams.MultiSampleType == D3DMULTISAMPLE_NONMASKABLE) ? pparams.MultiSampleQuality : pparams.MultiSampleType; + g_D3DDepthStencilFormat = pparams.AutoDepthStencilFormat; + device->SetCurrentTargetSize(pparams.BackBufferWidth, pparams.BackBufferHeight); + SetFramebufferDepthFormat(device, pparams.AutoDepthStencilFormat); + + bool deviceInLostState = false; + if( !s_Device ) + { + AssertIf( s_Window ); + + UINT adapterIndex = g_D3DAdapter; + D3DDEVTYPE devType = g_D3DDevType; + + #if ENABLE_NV_PERFHUD + UINT adapterCount = s_D3D->GetAdapterCount(); + D3DADAPTER_IDENTIFIER9 perfHudID; + memset( &perfHudID, 0, sizeof(perfHudID) ); + s_D3D->GetAdapterIdentifier( adapterCount-1, 0, &perfHudID ); + perfHudID.Description[MAX_DEVICE_IDENTIFIER_STRING-1] = 0; + if( strstr( perfHudID.Description, "PerfHUD" ) != NULL ) + { + adapterIndex = adapterCount-1; + devType = D3DDEVTYPE_REF; + } + #endif + + const int kShaderVersion11 = (1 << 8) + 1; + bool hasHardwareTL = gGraphicsCaps.d3d.d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT; + bool hasVS11 = LOWORD(gGraphicsCaps.d3d.d3dcaps.VertexShaderVersion) >= kShaderVersion11; + DWORD behaviourFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; + if( !hasVS11 ) + behaviourFlags = D3DCREATE_MIXED_VERTEXPROCESSING; + if( !hasHardwareTL ) + behaviourFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; + g_D3DUsesMixedVP = (behaviourFlags == D3DCREATE_MIXED_VERTEXPROCESSING); + + if( GetGfxThreadingMode() == kGfxThreadingModeThreaded ) + behaviourFlags |= D3DCREATE_MULTITHREADED; + + // Preserve FPU mode. Benchmarking both in hardware and software vertex processing does not + // reveal any real differences. If FPU mode is not preserved, bad things will happen, like: + // * doubles will act like floats + // * on Firefox/Safari, some JavaScript libraries will stop working (spect.aculo.us, dojo) - case 17513 + // * some random funky FPU exceptions will happen + HRESULT hr = s_D3D->CreateDevice( adapterIndex, devType, window, behaviourFlags | D3DCREATE_FPU_PRESERVE, &pparams, &s_Device ); + if( FAILED( hr ) ) + { + printf_console( "d3d: creation params: flags=%x swap=%i vsync=%x w=%i h=%i fmt=%i bbcount=%i dsformat=%i pflags=%x\n", + behaviourFlags, pparams.SwapEffect, pparams.PresentationInterval, + pparams.BackBufferWidth, pparams.BackBufferHeight, pparams.BackBufferFormat, pparams.BackBufferCount, + pparams.AutoDepthStencilFormat, pparams.Flags ); + printf_console( "d3d: failed to create device [%s]\n", GetD3D9Error(hr) ); + if (devType == D3DDEVTYPE_REF) + { + winutils::AddErrorMessage("Reference Rasterizer was requested but is not available.\nPlease make sure you have DirectX SDK installed."); + winutils::DisplayErrorMessagesAndQuit ("REFRAST not available"); + } + return false; + } + s_CurrentlyWindowed = pparams.Windowed ? true : false; + + gGraphicsCaps.hasTimerQuery = + (GetD3DDevice()->CreateQuery(D3DQUERYTYPE_TIMESTAMPFREQ, NULL) != D3DERR_NOTAVAILABLE) && + (GetD3DDevice()->CreateQuery(D3DQUERYTYPE_TIMESTAMP,NULL) != D3DERR_NOTAVAILABLE); + } + else + { + AssertIf( !s_Window ); + + // If we're resetting device mid-frame (e.g. script calls Screen.SetResolution), + // we need to end scene, reset and begin scene again. + bool wasInsideFrame = GetD3D9GfxDevice().IsInsideFrame(); + if( wasInsideFrame ) + { + s_Device->EndScene(); + GetD3D9GfxDevice().SetInsideFrame(false); + } + + // cleanup + s_BackBuffer.Release(); + s_DepthStencil.Release(); + + PluginsSetGraphicsDevice (s_Device, kGfxRendererD3D9, kGfxDeviceEventBeforeReset); + + D3DPRESENT_PARAMETERS ppcopy = pparams; // copy them, as Reset changes some values + HRESULT hr = s_Device->Reset( &ppcopy ); + if( FAILED(hr) ) + { + if( hr == D3DERR_DEVICELOST ) + { + deviceInLostState = true; + SetD3D9DeviceLost( true ); + } + else + { + ErrorString( Format("D3D device reset failed [%s]", GetD3D9Error(hr)) ); + return false; + } + } + + PluginsSetGraphicsDevice (s_Device, kGfxRendererD3D9, kGfxDeviceEventAfterReset); + + s_CurrentlyWindowed = ppcopy.Windowed ? true : false; + if( wasInsideFrame && !deviceInLostState ) + { + s_Device->BeginScene(); + GetD3D9GfxDevice().SetInsideFrame(true); + } + +#if ENABLE_PROFILER + if (gGraphicsCaps.hasTimerQuery) + GetD3D9GfxDevice().GetTimerQueries().RecreateAllQueries(); +#endif + } + + s_Window = window; + if( !deviceInLostState ) + { + s_Device->GetRenderTarget (0, &s_BackBuffer.m_Surface); + s_BackBuffer.width = pparams.BackBufferWidth; + s_BackBuffer.height = pparams.BackBufferHeight; + // create depth stencil + D3D9DepthStencilTexture depthStencil = CreateDepthStencilTextureD3D9 (s_Device, pparams.BackBufferWidth, pparams.BackBufferHeight, pparams.AutoDepthStencilFormat, pparams.MultiSampleType, pparams.MultiSampleQuality, TRUE); + if (depthStencil.m_Surface) + { + s_DepthStencil.m_Surface = depthStencil.m_Surface; + s_DepthStencil.m_Texture = depthStencil.m_Texture; + s_DepthStencil.width = pparams.BackBufferWidth; + s_DepthStencil.height = pparams.BackBufferHeight; + s_DepthStencil.depthFormat = kDepthFormat16; //@TODO? + } + + s_BackBuffer.backBuffer = true; + s_DepthStencil.backBuffer = true; + + #if !UNITY_EDITOR + RenderSurfaceHandle bbHandle(&s_BackBuffer), dsHandle(&s_DepthStencil); + device->SetRenderTargets(1, &bbHandle, dsHandle); + #endif + s_Device->SetRenderState (D3DRS_ZENABLE, TRUE); + } + + return true; +} + +void GetBackBuffersAfterDeviceReset() +{ + AssertIf (!s_Device); + AssertIf (!s_DepthStencil.m_Surface); + s_BackBuffer.Release(); + s_Device->GetRenderTarget (0, &s_BackBuffer.m_Surface); + s_BackBuffer.backBuffer = true; +} + +#if UNITY_EDITOR +void EditorInitializeD3D(GfxDevice* device) +{ + int dummy; + if( !InitializeOrResetD3DDevice( device, s_HiddenWindowD3D, 32, 32, 0, false, 0, 0, dummy, dummy, dummy, dummy ) ) + { + winutils::AddErrorMessage( "Failed to create master Direct3D window" ); + DestroyGfxDevice(); + winutils::DisplayErrorMessagesAndQuit( "Failed to initialize 3D graphics" ); + } + + // Disable D3D Debug runtime in editor release mode: + // VERTEXSTATS query is only available in Debug runtime. + #if UNITY_RELEASE + if (CheckD3D9DebugRuntime(GetD3DDevice())) + { + winutils::AddErrorMessage ( + "You are using Direct3D Debug Runtime, this is not supported by\r\n" + "Unity. Switch to Retail runtime in DirectX Control Panel."); + DestroyGfxDevice(); + winutils::DisplayErrorMessagesAndQuit ("D3D9 Debug Runtime is not supported"); + } + #endif +} +#endif + +bool FullResetD3DDevice() +{ + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("FullResetD3DDevice\n"); + #endif + // destroy dynamic VBO / render textures and reset the device + ResetDynamicResourcesD3D9(); + bool ok = ResetD3DDevice(); + if( ok ) + SetD3D9DeviceLost( false ); + return ok; +} + +bool HandleD3DDeviceLost() +{ + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("HandleD3DDeviceLost\n"); + #endif + HRESULT hr = s_Device->TestCooperativeLevel(); + bool ok = false; + switch( hr ) + { + // Is device actually lost? + case D3D_OK: + { + ok = true; + break; + } + // If device was lost, do not render until we get it back + case D3DERR_DEVICELOST: + { + #if ENABLE_D3D_WINDOW_LOGGING + printf_console(" HandleD3DDeviceLost: still lost\n"); + #endif + break; + } + // If device needs to be reset, do that + case D3DERR_DEVICENOTRESET: + { + #if ENABLE_D3D_WINDOW_LOGGING + printf_console(" HandleD3DDeviceLost: needs reset, doing it\n"); + #endif + ok = FullResetD3DDevice(); + break; + } + } + + if( !ok ) + return false; + + // device is not lost anymore, proceed + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("D3Dwindow device not lost anymore\n"); + #endif + GetBackBuffersAfterDeviceReset(); + SetD3D9DeviceLost( false ); + + return true; +} + +bool ResetD3DDevice() +{ + AssertIf( !s_D3D || !s_Device || !s_Window ); + + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("ResetD3DDevice\n"); + #endif + + // cleanup + s_BackBuffer.Release(); + s_DepthStencil.Release(); + + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("dev->Reset\n"); + #endif + + D3DPRESENT_PARAMETERS ppcopy = s_PresentParams; // copy them, as Reset changes some values + + #if WEBPLUG + // Reset sends WM_ACTIVATE message which makes Web Player exit fullscreen (unless gInsideFullscreenToggle is set). + bool insideFullscreenToggle = gInsideFullscreenToggle; + gInsideFullscreenToggle = true; + #endif + + PluginsSetGraphicsDevice (s_Device, kGfxRendererD3D9, kGfxDeviceEventBeforeReset); + + HRESULT hr = s_Device->Reset( &ppcopy ); + + #if WEBPLUG + gInsideFullscreenToggle = insideFullscreenToggle; + #endif + + bool setToLost = false; + if( FAILED(hr) ) + { + if( hr == D3DERR_DEVICELOST ) + { + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("set device to lost\n"); + #endif + SetD3D9DeviceLost( true ); + setToLost = true; + } + else + { + ErrorString( Format("D3D device reset failed [%s]", GetD3D9Error(hr)) ); + return false; + } + } + else + { + PluginsSetGraphicsDevice (s_Device, kGfxRendererD3D9, kGfxDeviceEventAfterReset); + + s_Device->GetRenderTarget (0, &s_BackBuffer.m_Surface); + s_BackBuffer.width = ppcopy.BackBufferWidth; + s_BackBuffer.height = ppcopy.BackBufferHeight; + // create depth stencil + D3D9DepthStencilTexture depthStencil = CreateDepthStencilTextureD3D9 (s_Device, ppcopy.BackBufferWidth, ppcopy.BackBufferHeight, ppcopy.AutoDepthStencilFormat, ppcopy.MultiSampleType, ppcopy.MultiSampleQuality, TRUE); + if (depthStencil.m_Surface) + { + s_DepthStencil.m_Surface = depthStencil.m_Surface; + s_DepthStencil.m_Texture = depthStencil.m_Texture; + s_DepthStencil.width = ppcopy.BackBufferWidth; + s_DepthStencil.height = ppcopy.BackBufferHeight; + s_DepthStencil.depthFormat = kDepthFormat16; //@TODO? + } + + s_BackBuffer.backBuffer = true; + s_DepthStencil.backBuffer = true; + + #if !UNITY_EDITOR + RenderSurfaceHandle bbHandle(&s_BackBuffer), dsHandle(&s_DepthStencil); + GetRealGfxDevice().SetRenderTargets(1, &bbHandle, dsHandle); + #endif + s_Device->SetRenderState (D3DRS_ZENABLE, TRUE); + } + s_CurrentlyWindowed = ppcopy.Windowed ? true : false; + + return !setToLost; +} + +void DestroyD3DDevice() +{ + // This can happen when quiting from screen selector - window is not set up yet + if( !s_Window || !s_Device ) + return; + + // cleanup + s_BackBuffer.Release(); + s_DepthStencil.Release(); + s_Device->Release(); + s_Device = NULL; + s_Window = NULL; +} + +IDirect3DDevice9* GetD3DDevice() +{ + AssertIf( !s_Device ); + return s_Device; +} + +IDirect3DDevice9* GetD3DDeviceNoAssert() +{ + return s_Device; +} + + + +#if UNITY_EDITOR + +#include "PlatformDependent/Win/WinUtils.h" + +HWND s_HiddenWindowD3D = NULL; + +bool CreateHiddenWindowD3D() +{ + AssertIf( s_HiddenWindowD3D ); + + // Dummy master window is 64x64 in size. Seems that 32x32 is too small for Rage cards (produces internal driver errors in CreateDevice). + s_HiddenWindowD3D = CreateWindowW( + L"STATIC", + L"UnityHiddenWindow", + WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + 0, 0, 64, 64, + NULL, NULL, + winutils::GetInstanceHandle(), NULL ); + if( !s_HiddenWindowD3D ) + { + winutils::AddErrorMessage( "Failed to create hidden window: %s", WIN_LAST_ERROR_TEXT ); + return false; + } + + return true; +} + +void DestroyHiddenWindowD3D() +{ + AssertIf( !s_HiddenWindowD3D ); + DestroyWindow( s_HiddenWindowD3D ); + s_HiddenWindowD3D = NULL; +} + +#endif diff --git a/Runtime/GfxDevice/d3d/D3D9Context.h b/Runtime/GfxDevice/d3d/D3D9Context.h new file mode 100644 index 0000000..370a1c7 --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Context.h @@ -0,0 +1,44 @@ +#pragma once + +#include "D3D9Includes.h" +#include "D3D9Enumeration.h" + +bool InitializeD3D(D3DDEVTYPE devtype); +void CleanupD3D(); +bool InitializeOrResetD3DDevice( + class GfxDevice* device, + HWND window, int width, int height, + int refreshRate, bool fullscreen, int vBlankCount, int fsaa, + int& outBackbufferBPP, int& outFrontbufferBPP, int& outDepthBPP, int& outFSAA ); +void GetBackBuffersAfterDeviceReset(); +bool ResetD3DDevice(); +#if UNITY_EDITOR +void EditorInitializeD3D(GfxDevice* device); +#endif +bool FullResetD3DDevice(); +bool HandleD3DDeviceLost(); +void DestroyD3DDevice(); +extern D3DDEVTYPE g_D3DDevType; +extern DWORD g_D3DAdapter; +extern bool g_D3DUsesMixedVP; +extern bool g_D3DHasDepthStencil; +extern D3DFORMAT g_D3DDepthStencilFormat; + +IDirect3DDevice9* GetD3DDevice(); +IDirect3DDevice9* GetD3DDeviceNoAssert(); +IDirect3D9* GetD3DObject(); +D3D9FormatCaps* GetD3DFormatCaps(); +D3DFORMAT GetD3DFormatForChecks(); + +typedef int (WINAPI* D3DPERF_BeginEventFunc)(D3DCOLOR, LPCWSTR); +typedef int (WINAPI* D3DPERF_EndEventFunc)(); +extern D3DPERF_BeginEventFunc g_D3D9BeginEventFunc; +extern D3DPERF_EndEventFunc g_D3D9EndEventFunc; + + +#if UNITY_EDITOR +bool CreateHiddenWindowD3D(); +void DestroyHiddenWindowD3D(); +extern HWND s_HiddenWindowD3D; +#endif + diff --git a/Runtime/GfxDevice/d3d/D3D9Enumeration.cpp b/Runtime/GfxDevice/d3d/D3D9Enumeration.cpp new file mode 100644 index 0000000..b78433e --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Enumeration.cpp @@ -0,0 +1,344 @@ +#include "UnityPrefix.h" +#include "D3D9Enumeration.h" +#include "D3D9Utils.h" +#include "Runtime/GfxDevice/VramLimits.h" + +// --------------------------------------------------------------------------- + + +const int kMinDisplayWidth = 512; +const int kMinDisplayHeight = 384; +const int kMinColorBits = 4; +const int kMinAlphaBits = 0; + +extern D3DDEVTYPE g_D3DDevType; +extern DWORD g_D3DAdapter; + +// --------------------------------------------------------------------------- + +static int GetFormatColorBits( D3DFORMAT fmt ) { + switch( fmt ) { + case D3DFMT_A2B10G10R10: + case D3DFMT_A2R10G10B10: return 10; + case D3DFMT_R8G8B8: + case D3DFMT_A8R8G8B8: + case D3DFMT_X8R8G8B8: return 8; + case D3DFMT_R5G6B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_A1R5G5B5: return 5; + case D3DFMT_A4R4G4B4: + case D3DFMT_X4R4G4B4: return 4; + case D3DFMT_R3G3B2: + case D3DFMT_A8R3G3B2: return 2; + default: return 0; + } +} + +static int GetFormatAlphaBits( D3DFORMAT fmt ) { + switch( fmt ) { + case D3DFMT_R8G8B8: + case D3DFMT_X8R8G8B8: + case D3DFMT_R5G6B5: + case D3DFMT_X1R5G5B5: + case D3DFMT_R3G3B2: + case D3DFMT_X4R4G4B4: return 0; + case D3DFMT_A8R8G8B8: + case D3DFMT_A8R3G3B2: return 8; + case D3DFMT_A1R5G5B5: return 1; + case D3DFMT_A4R4G4B4: return 4; + case D3DFMT_A2B10G10R10: + case D3DFMT_A2R10G10B10: return 2; + default: return 0; + } +} + +int GetFormatDepthBits( D3DFORMAT fmt ) { + switch( fmt ) { + case D3DFMT_D16: return 16; + case D3DFMT_D15S1: return 15; + case D3DFMT_D24X8: + case D3DFMT_D24S8: + case D3DFMT_D24X4S4: return 24; + case D3DFMT_D32: return 32; + default: return 0; + } +} + +static D3DFORMAT ConvertToAlphaFormat( D3DFORMAT fmt ) +{ + if( fmt == D3DFMT_X8R8G8B8 ) + fmt = D3DFMT_A8R8G8B8; + else if( fmt == D3DFMT_X4R4G4B4 ) + fmt = D3DFMT_A4R4G4B4; + else if( fmt == D3DFMT_X1R5G5B5 ) + fmt = D3DFMT_A1R5G5B5; + return fmt; +} + +// ----------------------------------------------------------------------------- + + +static UInt32 buildVertexProcessings( const D3DCAPS9& caps ) +{ + UInt32 result = 0; + + // TODO: check vertex shader version + + DWORD devCaps = caps.DevCaps; + if( devCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) { + if( devCaps & D3DDEVCAPS_PUREDEVICE ) { + result |= (1<<kVPPureHardware); + } + result |= (1<<kVPHardware); + result |= (1<<kVPMixed); + } + + result |= (1<<kVPSoftware); + + return result; +} + + +static void buildDepthStencilFormats( IDirect3D9& d3d, D3DDeviceCombo& devCombo ) +{ + const D3DFORMAT dsFormats[] = { + D3DFMT_D24S8, D3DFMT_D24X8, D3DFMT_D24X4S4, D3DFMT_D16, D3DFMT_D15S1, D3DFMT_D32, + }; + const int dsFormatCount = sizeof(dsFormats) / sizeof(dsFormats[0]); + + for( int idsf = 0; idsf < dsFormatCount; ++idsf ) { + D3DFORMAT format = dsFormats[idsf]; + if( SUCCEEDED( d3d.CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, devCombo.adapterFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, format ) ) ) + { + if( SUCCEEDED( d3d.CheckDepthStencilMatch( g_D3DAdapter, g_D3DDevType, devCombo.adapterFormat, devCombo.backBufferFormat, format ) ) ) + { + devCombo.depthStencilFormats.push_back( format ); + } + } + } +} + + +static void buildMultiSampleTypes( IDirect3D9& d3d, D3DDeviceCombo& devCombo ) +{ + const size_t kMaxSamples = 16; + devCombo.multiSampleTypes.reserve( kMaxSamples ); + devCombo.multiSampleTypes.push_back( D3DMULTISAMPLE_NONE ); + + for( int samples = 2; samples <= kMaxSamples; ++samples ) { + D3DMULTISAMPLE_TYPE msType = GetD3DMultiSampleType( samples ); + DWORD msQuality; + if( SUCCEEDED( d3d.CheckDeviceMultiSampleType( g_D3DAdapter, g_D3DDevType, devCombo.backBufferFormat, devCombo.isWindowed, msType, NULL ) ) ) + devCombo.multiSampleTypes.push_back( samples ); + } +} + + +static void buildConflicts( IDirect3D9& d3d, D3DDeviceCombo& devCombo ) +{ + for( size_t ids = 0; ids < devCombo.depthStencilFormats.size(); ++ids ) { + D3DFORMAT format = (D3DFORMAT)devCombo.depthStencilFormats[ids]; + for( size_t ims = 0; ims < devCombo.multiSampleTypes.size(); ++ims ) { + D3DMULTISAMPLE_TYPE msType = (D3DMULTISAMPLE_TYPE)devCombo.multiSampleTypes[ims]; + if( FAILED( d3d.CheckDeviceMultiSampleType( + g_D3DAdapter, g_D3DDevType, + format, devCombo.isWindowed, msType, NULL ) ) ) + { + D3DDeviceCombo::MultiSampleConflict conflict; + conflict.format = format; + conflict.type = msType; + devCombo.conflicts.push_back( conflict ); + } + } + } +} + + +static bool enumerateDeviceCombos( IDirect3D9& d3d, const D3DCAPS9& caps, const DwordVector& adapterFormats, D3DDeviceComboVector& outCombos ) +{ + const D3DFORMAT bbufferFormats[] = { + D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, D3DFMT_A2R10G10B10, + D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, D3DFMT_X1R5G5B5 + }; + const int bbufferFormatCount = sizeof(bbufferFormats) / sizeof(bbufferFormats[0]); + + bool isWindowedArray[] = { false, true }; + + // see which adapter formats are supported by this device + for( size_t iaf = 0; iaf < adapterFormats.size(); ++iaf ) + { + D3DFORMAT format = (D3DFORMAT)adapterFormats[iaf]; + for( int ibbf = 0; ibbf < bbufferFormatCount; ibbf++ ) + { + D3DFORMAT bbufferFormat = bbufferFormats[ibbf]; + if( GetFormatAlphaBits(bbufferFormat) < kMinAlphaBits ) + continue; + for( int iiw = 0; iiw < 2; ++iiw ) { + bool isWindowed = isWindowedArray[iiw]; + if( FAILED( d3d.CheckDeviceType( g_D3DAdapter, g_D3DDevType, format, bbufferFormat, isWindowed ) ) ) + continue; + + // Here, we have an adapter format / backbuffer format/ windowed + // combo that is supported by the system. We still need to find one or + // more suitable depth/stencil buffer format, multisample type, + // vertex processing type, and vsync. + D3DDeviceCombo devCombo; + + devCombo.adapterFormat = format; + devCombo.backBufferFormat = bbufferFormat; + devCombo.isWindowed = isWindowed; + devCombo.presentationIntervals = caps.PresentationIntervals; + + buildDepthStencilFormats( d3d, devCombo ); + if( devCombo.depthStencilFormats.empty() ) + continue; + + buildMultiSampleTypes( d3d, devCombo ); + if( devCombo.multiSampleTypes.empty() ) + continue; + + buildConflicts( d3d, devCombo ); + + outCombos.push_back( devCombo ); + } + } + } + + return !outCombos.empty(); +} + + +bool D3D9FormatCaps::Enumerate( IDirect3D9& d3d ) +{ + AssertIf( !m_Combos.empty() ); + HRESULT hr; + + const D3DFORMAT allowedFormats[] = { + D3DFMT_X8R8G8B8, D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_A2R10G10B10 + }; + const int allowedFormatCount = sizeof(allowedFormats) / sizeof(allowedFormats[0]); + + m_AdapterFormatForChecks = D3DFMT_UNKNOWN; + + // build a list of all display adapter formats + DwordVector adapterFormatList; // D3DFORMAT + + for( size_t ifmt = 0; ifmt < allowedFormatCount; ++ifmt ) + { + D3DFORMAT format = allowedFormats[ifmt]; + int modeCount = d3d.GetAdapterModeCount( g_D3DAdapter, format ); + for( int mode = 0; mode < modeCount; ++mode ) { + D3DDISPLAYMODE dm; + d3d.EnumAdapterModes( g_D3DAdapter, format, mode, &dm ); + if( dm.Width < (UINT)kMinDisplayWidth || dm.Height < (UINT)kMinDisplayHeight || GetFormatColorBits(dm.Format) < kMinColorBits ) + continue; + // adapterInfo->displayModes.push_back( dm ); + if( std::find(adapterFormatList.begin(),adapterFormatList.end(),dm.Format) == adapterFormatList.end() ) { + adapterFormatList.push_back( dm.Format ); + if( m_AdapterFormatForChecks == D3DFMT_UNKNOWN ) + m_AdapterFormatForChecks = format; + } + } + } + + if( m_AdapterFormatForChecks == D3DFMT_UNKNOWN ) // for some reason no format was selected for checks, use default + m_AdapterFormatForChecks = allowedFormats[0]; + + // get info for device on this adapter + D3DCAPS9 caps; + if( FAILED( d3d.GetDeviceCaps( g_D3DAdapter, g_D3DDevType, &caps ) ) ) + return false; + + // find suitable vertex processing modes (if any) + m_VertexProcessings = buildVertexProcessings( caps ); + AssertIf( !m_VertexProcessings ); + + // get info for each device combo on this device + if( !enumerateDeviceCombos( d3d, caps, adapterFormatList, m_Combos ) ) + return false; + + return true; +} + + +void D3D9FormatCaps::FindBestPresentationParams( int width, int height, D3DFORMAT desktopMode, bool windowed, int vBlankCount, int multiSample, D3DPRESENT_PARAMETERS& outParams ) const +{ + const D3DDeviceCombo* bestCombo = NULL; + int bestScore = -1; + + for( size_t idc = 0; idc < m_Combos.size(); ++idc ) + { + const D3DDeviceCombo& devCombo = m_Combos[idc]; + if( windowed && !devCombo.isWindowed ) + continue; + if( !windowed && devCombo.isWindowed ) + continue; + if( windowed ) + { + if( devCombo.adapterFormat != desktopMode ) + continue; + } + + int score = 0; + + bool matchesBB = (devCombo.backBufferFormat == ConvertToAlphaFormat(devCombo.adapterFormat)); + bool matchesDesktop = (devCombo.adapterFormat == desktopMode); + + if( matchesBB ) + score += 1; + if( matchesDesktop ) + score += 1; + if( GetFormatAlphaBits(devCombo.backBufferFormat) > 0 ) + score += 1; + + if( score > bestScore ) + { + bestScore = score; + bestCombo = &devCombo; + } + } + + if( !bestCombo ) + { + // This can happen if we're debugging force-16BPP modes on a 32BPP desktop, and so on + outParams.BackBufferFormat = desktopMode; + outParams.AutoDepthStencilFormat = D3DFMT_D16; + outParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + outParams.MultiSampleType = D3DMULTISAMPLE_NONE; + outParams.MultiSampleQuality = 0; + return; + } + + outParams.BackBufferFormat = bestCombo->backBufferFormat; + outParams.AutoDepthStencilFormat = (D3DFORMAT)bestCombo->depthStencilFormats[0]; + + // No support for intervals above 1 in windowed mode (case 497116) + if (windowed && vBlankCount > 1) + vBlankCount = 1; + + // best possible vsync parameter (if device doesn't support 2 fall back to 1) + DWORD intervals = bestCombo->presentationIntervals; + outParams.PresentationInterval = ( vBlankCount >= 2 ) && ( intervals & D3DPRESENT_INTERVAL_TWO ) ? D3DPRESENT_INTERVAL_TWO : + ( vBlankCount >= 1 ) && ( intervals & D3DPRESENT_INTERVAL_ONE ) ? D3DPRESENT_INTERVAL_ONE : + ( vBlankCount == 0 ) && ( intervals & D3DPRESENT_INTERVAL_IMMEDIATE ) ? D3DPRESENT_INTERVAL_IMMEDIATE : + D3DPRESENT_INTERVAL_DEFAULT; + + // Here we already know backbuffer, depth buffer formats and so on, so we can also clamp used FSAA to sane VRAM limits. + int backbufferBPP = GetBPPFromD3DFormat(outParams.BackBufferFormat)/8; + int frontbufferBPP = GetBPPFromD3DFormat(desktopMode)/8; + int depthBPP = GetBPPFromD3DFormat(outParams.AutoDepthStencilFormat)/8; + multiSample = ChooseSuitableFSAALevel( width, height, backbufferBPP, frontbufferBPP, depthBPP, multiSample ); + + // Find out best matched multi sample type. + int msIdx = 0; + if( multiSample > 1 ) + { + while( msIdx < bestCombo->multiSampleTypes.size() && bestCombo->multiSampleTypes[msIdx] <= multiSample ) + ++msIdx; + --msIdx; + AssertIf( msIdx < 0 ); + } + outParams.MultiSampleType = GetD3DMultiSampleType(bestCombo->multiSampleTypes[msIdx]); + outParams.MultiSampleQuality = 0; +} + diff --git a/Runtime/GfxDevice/d3d/D3D9Enumeration.h b/Runtime/GfxDevice/d3d/D3D9Enumeration.h new file mode 100644 index 0000000..240bb89 --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Enumeration.h @@ -0,0 +1,64 @@ +#pragma once + +#include "D3D9Includes.h" + + +struct D3DDeviceCombo; + +typedef std::vector<DWORD> DwordVector; +typedef std::vector<D3DDeviceCombo> D3DDeviceComboVector; + + +enum D3DVertexProcessing { + kVPPureHardware, + kVPHardware, + kVPMixed, + kVPSoftware, +}; + + +//--------------------------------------------------------------------------- + +// A combo of adapter format, back buffer format, and windowed/fulscreen that +// is compatible with a D3D device. +struct D3DDeviceCombo { +public: + // A depth/stencil buffer format that is incompatible with a multisample type. + struct MultiSampleConflict { + D3DFORMAT format; + D3DMULTISAMPLE_TYPE type; + }; + typedef std::vector<MultiSampleConflict> MultiSampleConflictVector; +public: + D3DFORMAT adapterFormat; + D3DFORMAT backBufferFormat; + bool isWindowed; + DWORD presentationIntervals; + + DwordVector depthStencilFormats; + DwordVector multiSampleTypes; + MultiSampleConflictVector conflicts; +}; + + +//--------------------------------------------------------------------------- + +class D3D9FormatCaps { +public: + D3D9FormatCaps() : m_VertexProcessings(0) { } + + bool Enumerate( IDirect3D9& d3d ); + + // Fills in BackBufferFormat, AutoDepthStencilFormat, PresentationInterval, + // MultiSampleType, MultiSampleQuality. + void FindBestPresentationParams( int width, int height, D3DFORMAT desktopMode, bool windowed, int vBlankCount, int multiSample, D3DPRESENT_PARAMETERS& outParams ) const; + + // Gets adapter format for doing CheckDeviceFormat checks. + // Usually D3DFMT_X8R8G8B8, except for really old cards that can't do 32 bpp. + D3DFORMAT GetAdapterFormatForChecks() const { return m_AdapterFormatForChecks; } + +public: + D3DDeviceComboVector m_Combos; + UInt32 m_VertexProcessings; // bitmask + D3DFORMAT m_AdapterFormatForChecks; +}; diff --git a/Runtime/GfxDevice/d3d/D3D9Includes.h b/Runtime/GfxDevice/d3d/D3D9Includes.h new file mode 100644 index 0000000..84596ff --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Includes.h @@ -0,0 +1,7 @@ +#ifndef D3DINCLUDES_H +#define D3DINCLUDES_H + +//#define D3D_DEBUG_INFO +#include "External/DirectX/builds/dx9include/d3d9.h" + +#endif diff --git a/Runtime/GfxDevice/d3d/D3D9Utils.cpp b/Runtime/GfxDevice/d3d/D3D9Utils.cpp new file mode 100644 index 0000000..3e25633 --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Utils.cpp @@ -0,0 +1,169 @@ +#include "UnityPrefix.h" +#include "D3D9Utils.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Shaders/GraphicsCaps.h" + + +#ifdef DUMMY_D3D9_CALLS +HRESULT CallDummyD3D9Function() +{ + return S_OK; +} +#endif + +struct D3D9Error { + HRESULT hr; + const char* message; +}; + +static D3D9Error s_D3DErrors[] = { + { D3DOK_NOAUTOGEN, "no mipmap autogen" }, + { D3DERR_WRONGTEXTUREFORMAT, "wrong texture format" }, + { D3DERR_UNSUPPORTEDCOLOROPERATION, "unsupported color op" }, + { D3DERR_UNSUPPORTEDCOLORARG, "unsupported color arg" }, + { D3DERR_UNSUPPORTEDALPHAOPERATION, "unsupported alpha op" }, + { D3DERR_UNSUPPORTEDALPHAARG, "unsupported alpha arg" }, + { D3DERR_TOOMANYOPERATIONS, "too many texture operations" }, + { D3DERR_CONFLICTINGTEXTUREFILTER, "conflicting texture filters" }, + { D3DERR_UNSUPPORTEDFACTORVALUE, "unsupported factor value" }, + { D3DERR_CONFLICTINGRENDERSTATE, "conflicting render states" }, + { D3DERR_UNSUPPORTEDTEXTUREFILTER, "unsupported texture filter" }, + { D3DERR_CONFLICTINGTEXTUREPALETTE, "conflicting texture palettes" }, + { D3DERR_DRIVERINTERNALERROR, "internal driver error" }, + { D3DERR_NOTFOUND, "requested item not found" }, + { D3DERR_MOREDATA, "more data than fits into buffer" }, + { D3DERR_DEVICELOST, "device lost" }, + { D3DERR_DEVICENOTRESET, "device not reset" }, + { D3DERR_NOTAVAILABLE, "queried technique not available" }, + { D3DERR_OUTOFVIDEOMEMORY, "out of VRAM" }, + { D3DERR_INVALIDDEVICE, "invalid device" }, + { D3DERR_INVALIDCALL, "invalid call" }, + { D3DERR_DRIVERINVALIDCALL, "driver invalid call" }, + { D3DERR_WASSTILLDRAWING, "was still drawing" }, + { S_OK, "S_OK" }, + { E_FAIL, "E_FAIL" }, + { E_INVALIDARG, "E_INVALIDARG" }, + { E_OUTOFMEMORY, "out of memory" }, +}; + +const char* GetD3D9Error( HRESULT hr ) +{ + for( int i = 0; i < ARRAY_SIZE(s_D3DErrors); ++i ) + { + if( hr == s_D3DErrors[i].hr ) + return s_D3DErrors[i].message; + } + + static char buffer[1000]; + sprintf( buffer, "unknown error, code 0x%X", hr ); + return buffer; +} + +int GetBPPFromD3DFormat( D3DFORMAT format ) +{ + switch( format ) { + case D3DFMT_UNKNOWN: + case kD3D9FormatNULL: + return 0; + case D3DFMT_X8R8G8B8: + case D3DFMT_A8R8G8B8: + case D3DFMT_A2R10G10B10: + case D3DFMT_A2B10G10R10: + case D3DFMT_R8G8B8: + case D3DFMT_A8B8G8R8: + case D3DFMT_R32F: + case D3DFMT_D24X8: + case D3DFMT_D24S8: + case D3DFMT_D24X4S4: + case kD3D9FormatINTZ: + case kD3D9FormatRAWZ: + return 32; + case D3DFMT_X1R5G5B5: + case D3DFMT_A1R5G5B5: + case D3DFMT_A4R4G4B4: + case D3DFMT_X4R4G4B4: + case D3DFMT_R5G6B5: + case D3DFMT_R16F: + case D3DFMT_D16: + case D3DFMT_D15S1: + case D3DFMT_D16_LOCKABLE: + case D3DFMT_L16: + case D3DFMT_A8L8: + case kD3D9FormatDF16: + return 16; + case D3DFMT_A16B16G16R16F: + return 64; + case D3DFMT_A32B32G32R32F: + return 128; + case D3DFMT_DXT1: + return 4; + case D3DFMT_A8: + case D3DFMT_L8: + case D3DFMT_DXT3: + case D3DFMT_DXT5: + return 8; + default: + ErrorString( Format("Unknown D3D format %x", format) ); + return 32; + } +} + +int GetStencilBitsFromD3DFormat (D3DFORMAT fmt) +{ + switch( fmt ) { + case D3DFMT_D15S1: return 1; + case D3DFMT_D24S8: return 8; + case D3DFMT_D24X4S4: return 4; + default: return 0; + } +} + +D3DMULTISAMPLE_TYPE GetD3DMultiSampleType (int samples) +{ + // Optimizer should take care of this, since value of D3DMULTISAMPLE_N_SAMPLES is N + switch( samples ) { + case 0: + case 1: return D3DMULTISAMPLE_NONE; + case 2: return D3DMULTISAMPLE_2_SAMPLES; + case 3: return D3DMULTISAMPLE_3_SAMPLES; + case 4: return D3DMULTISAMPLE_4_SAMPLES; + case 5: return D3DMULTISAMPLE_5_SAMPLES; + case 6: return D3DMULTISAMPLE_6_SAMPLES; + case 7: return D3DMULTISAMPLE_7_SAMPLES; + case 8: return D3DMULTISAMPLE_8_SAMPLES; + case 9: return D3DMULTISAMPLE_9_SAMPLES; + case 10: return D3DMULTISAMPLE_10_SAMPLES; + case 11: return D3DMULTISAMPLE_11_SAMPLES; + case 12: return D3DMULTISAMPLE_12_SAMPLES; + case 13: return D3DMULTISAMPLE_13_SAMPLES; + case 14: return D3DMULTISAMPLE_14_SAMPLES; + case 15: return D3DMULTISAMPLE_15_SAMPLES; + case 16: return D3DMULTISAMPLE_16_SAMPLES; + default: + ErrorString("Unknown sample count"); + return D3DMULTISAMPLE_NONE; + } +} + +bool CheckD3D9DebugRuntime (IDirect3DDevice9* dev) +{ + IDirect3DQuery9* query = NULL; + HRESULT hr = dev->CreateQuery (D3DQUERYTYPE_VERTEXSTATS, &query); + if( SUCCEEDED(hr) ) + { + query->Release (); + return true; + } + return false; +} + + +D3D9DepthStencilTexture CreateDepthStencilTextureD3D9 (IDirect3DDevice9* dev, int width, int height, D3DFORMAT format, D3DMULTISAMPLE_TYPE msType, DWORD msQuality, BOOL discardable) +{ + D3D9DepthStencilTexture tex; + + HRESULT hr = dev->CreateDepthStencilSurface (width, height, format, msType, msQuality, discardable, &tex.m_Surface, NULL); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(tex.m_Surface, width * height * GetBPPFromD3DFormat(format), NULL); + + return tex; +} diff --git a/Runtime/GfxDevice/d3d/D3D9Utils.h b/Runtime/GfxDevice/d3d/D3D9Utils.h new file mode 100644 index 0000000..529e58b --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Utils.h @@ -0,0 +1,69 @@ +#pragma once + +#include "D3D9Includes.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +//#define DUMMY_D3D9_CALLS + +#ifndef DUMMY_D3D9_CALLS +#define D3D9_CALL(x) x +#define D3D9_CALL_HR(x) x +#else +HRESULT CallDummyD3D9Function(); +#define D3D9_CALL(x) CallDummyD3D9Function() +#define D3D9_CALL_HR(x) CallDummyD3D9Function() +#endif + + +const char* GetD3D9Error( HRESULT hr ); +int GetBPPFromD3DFormat( D3DFORMAT format ); +int GetStencilBitsFromD3DFormat (D3DFORMAT fmt); +D3DMULTISAMPLE_TYPE GetD3DMultiSampleType (int samples); + +bool CheckD3D9DebugRuntime (IDirect3DDevice9* dev); + +struct D3D9DepthStencilTexture { + D3D9DepthStencilTexture() : m_Texture(NULL), m_Surface(NULL) {} + + IDirect3DTexture9* m_Texture; + IDirect3DSurface9* m_Surface; + + void Release() { + if (m_Texture) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_Texture); + m_Texture->Release(); + m_Texture = NULL; + } + if (m_Surface) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_Surface); + m_Surface->Release(); + m_Surface = NULL; + } + } +}; + +const D3DFORMAT kD3D9FormatDF16 = (D3DFORMAT)MAKEFOURCC('D','F','1','6'); +const D3DFORMAT kD3D9FormatINTZ = (D3DFORMAT)MAKEFOURCC('I','N','T','Z'); +const D3DFORMAT kD3D9FormatRAWZ = (D3DFORMAT)MAKEFOURCC('R','A','W','Z'); +const D3DFORMAT kD3D9FormatNULL = (D3DFORMAT)MAKEFOURCC('N','U','L','L'); +const D3DFORMAT kD3D9FormatRESZ = (D3DFORMAT)MAKEFOURCC('R','E','S','Z'); + + +D3D9DepthStencilTexture CreateDepthStencilTextureD3D9 ( + IDirect3DDevice9* dev, int width, int height, D3DFORMAT format, + D3DMULTISAMPLE_TYPE msType, DWORD msQuality, BOOL discardable ); + +static inline DWORD GetD3D9SamplerIndex (ShaderType type, int unit) +{ + switch (type) { + case kShaderVertex: + DebugAssert (unit >= 0 && unit < 4); // DX9 has limit of 4 vertex samplers + return unit + D3DVERTEXTEXTURESAMPLER0; + case kShaderFragment: + DebugAssert (unit >= 0 && unit < kMaxSupportedTextureUnits); + return unit; + default: + Assert ("Unsupported shader type for sampler"); + return 0; + } +} diff --git a/Runtime/GfxDevice/d3d/D3D9VBO.cpp b/Runtime/GfxDevice/d3d/D3D9VBO.cpp new file mode 100644 index 0000000..19cc409 --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9VBO.cpp @@ -0,0 +1,815 @@ +#include "UnityPrefix.h" +#include "D3D9VBO.h" +#include "D3D9Context.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "D3D9Utils.h" +#include "GfxDeviceD3D9.h" +#include "Runtime/Profiler/MemoryProfiler.h" + + +// defined in GfxDeviceD3D9.cpp +IDirect3DVertexDeclaration9* GetD3DVertexDeclaration( UInt32 shaderChannelsMap ); +void UpdateChannelBindingsD3D( const ChannelAssigns& channels ); + + +// Define this to 1 to make VBO operations randomly fail. +// Use this to test error checking code. +#define DEBUG_RANDOMLY_FAIL_D3D_VBO 0 + + +#if !DEBUGMODE && DEBUG_RANDOMLY_FAIL_D3D_VBO +#error Never enable random VBO failures on release code! +#endif + +#if DEBUG_RANDOMLY_FAIL_D3D_VBO +#define RANDOM_FAIL_FOR_DEBUG - ((rand()%8==0) ? 100000000 : 0) +#else +#define RANDOM_FAIL_FOR_DEBUG +#endif + + +static const D3DPRIMITIVETYPE kTopologyD3D9[kPrimitiveTypeCount] = +{ + D3DPT_TRIANGLELIST, + D3DPT_TRIANGLESTRIP, + D3DPT_TRIANGLELIST, //@TODO: make work + D3DPT_LINELIST, + D3DPT_LINESTRIP, + D3DPT_POINTLIST, +}; + + +// ----------------------------------------------------------------------------- + +IDirect3DIndexBuffer9* D3D9VBO::ms_CustomIB = NULL; +int D3D9VBO::ms_CustomIBSize = 0; +UInt32 D3D9VBO::ms_CustomIBUsedBytes = 0; + +D3D9VBO::D3D9VBO() +: m_IB(NULL) +, m_IBSize(0) +{ + memset(m_VertexDecls, 0, sizeof(m_VertexDecls)); + memset(m_VBStreams, 0, sizeof(m_VBStreams)); +} + +D3D9VBO::~D3D9VBO () +{ + for( int s = 0; s < kMaxVertexStreams; s++ ) + { + if( m_VBStreams[s] ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VBStreams[s]); + ULONG refCount = m_VBStreams[s]->Release(); + AssertIf( refCount != 0 ); + m_VBStreams[s] = NULL; + } + } + if( m_IB ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + ULONG refCount = m_IB->Release(); + AssertIf( refCount != 0 ); + m_IB = NULL; + } + +} + + +void D3D9VBO::ResetDynamicVB() +{ + // Gets called on all VBs and ignores non-dynamic ones + for( int s = 0; s < kMaxVertexStreams; s++ ) + { + if( m_StreamModes[s] == kStreamModeDynamic ) + { + // Vertex buffer can be null when switching fullscreen in web player. + // There we lose device a couple of times, and ResetDynamicVB is called several + // times in succession. + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VBStreams[s]); + SAFE_RELEASE( m_VBStreams[s] ); + } + } +} + +void D3D9VBO::CleanupSharedIndexBuffer() +{ + if( ms_CustomIB ) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(ms_CustomIB); + ULONG refCount = ms_CustomIB->Release(); + AssertIf( refCount != 0 ); + ms_CustomIBSize = 0; + ms_CustomIBUsedBytes = 0; + ms_CustomIB = NULL; + } +} + +void D3D9VBO::BindVertexStreams( IDirect3DDevice9* dev, const ChannelAssigns& channels ) +{ + int freeStream = -1; + for( int s = 0; s < kMaxVertexStreams; s++ ) + { + if( m_VBStreams[s] ) + D3D9_CALL( dev->SetStreamSource( s, m_VBStreams[s], 0, m_Streams[s].stride ) ); + else + freeStream = s; + } + int declIndex = kVertexDeclDefault; + if ((channels.GetSourceMap() & VERTEX_FORMAT1(Color)) && !m_ChannelInfo[kShaderChannelColor].IsValid()) + { + if (freeStream != -1) + { + declIndex = kVertexDeclAllWhiteStream; + if (!m_VertexDecls[declIndex]) + { + ChannelInfoArray channelInfo; + memcpy(&channelInfo, m_ChannelInfo, sizeof(channelInfo)); + ChannelInfo& colorInfo = channelInfo[kShaderChannelColor]; + colorInfo.stream = freeStream; + colorInfo.offset = 0; + colorInfo.format = kChannelFormatColor; + colorInfo.dimension = 1; + m_VertexDecls[declIndex] = GetD3D9GfxDevice().GetVertexDecls().GetVertexDecl( channelInfo ); + } + IDirect3DVertexBuffer9* whiteVB = GetD3D9GfxDevice().GetAllWhiteVertexStream(); + D3D9_CALL( dev->SetStreamSource( freeStream, whiteVB, 0, sizeof(D3DCOLOR) ) ); + } + else + ErrorString("Need a free stream to add default vertex colors!"); + } + D3D9_CALL( dev->SetVertexDeclaration( m_VertexDecls[declIndex] ) ); + UpdateChannelBindingsD3D( channels ); +} + +void D3D9VBO::UpdateVertexStream( const VertexBufferData& sourceData, unsigned stream ) +{ + DebugAssert( !m_IsStreamMapped[stream] ); + const StreamInfo& srcStream = sourceData.streams[stream]; + int oldSize = CalculateVertexStreamSize(m_Streams[stream], m_VertexCount); + int newSize = CalculateVertexStreamSize(srcStream, sourceData.vertexCount); + m_Streams[stream] = srcStream; + if (newSize == 0) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VBStreams[stream]); + SAFE_RELEASE( m_VBStreams[stream] ); + return; + } + + const bool isDynamic = (m_StreamModes[stream] == kStreamModeDynamic); + DWORD usage = isDynamic ? (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY) : (D3DUSAGE_WRITEONLY); + D3DPOOL pool = isDynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED; + + if( m_VBStreams[stream] == NULL || newSize != oldSize ) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VBStreams[stream]); + SAFE_RELEASE( m_VBStreams[stream] ); + IDirect3DDevice9* dev = GetD3DDevice(); + HRESULT hr = dev->CreateVertexBuffer( newSize RANDOM_FAIL_FOR_DEBUG, usage, 0, pool, &m_VBStreams[stream], NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_VBStreams[stream],newSize,this); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to create vertex buffer of size %d [%s]\n", newSize, GetD3D9Error(hr) ); + return; + } + } + + // Don't update contents if there is no source data. + // This is used to update the vertex declaration only, leaving buffer intact. + // Also to create an empty buffer that is written to later. + if (!sourceData.buffer) + return; + + UInt8* buffer; + HRESULT hr = m_VBStreams[stream]->Lock( 0 RANDOM_FAIL_FOR_DEBUG, 0, (void**)&buffer, isDynamic ? D3DLOCK_DISCARD : 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock vertex buffer %p [%s]\n", m_VBStreams[stream], GetD3D9Error(hr) ); + return; + } + CopyVertexStream( sourceData, buffer, stream ); + + m_VBStreams[stream]->Unlock(); +} + + +void D3D9VBO::UpdateIndexBufferData (const IndexBufferData& sourceData) +{ + if( !sourceData.indices ) + { + m_IBSize = 0; + return; + } + + AssertIf( !m_IB ); + UInt8* buffer; + HRESULT hr = m_IB->Lock( 0 RANDOM_FAIL_FOR_DEBUG, 0, (void**)&buffer, 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock index buffer %p [%s]\n", m_IB, GetD3D9Error(hr) ); + return; + } + + memcpy (buffer, sourceData.indices, sourceData.count * kVBOIndexSize); + + m_IB->Unlock(); +} + +bool D3D9VBO::MapVertexStream( VertexStreamData& outData, unsigned stream ) +{ + if( m_VBStreams[stream] == NULL ) + { + printf_console( "d3d: attempt to map null vertex buffer\n" ); + return false; + } + DebugAssertIf( IsVertexBufferLost() ); + AssertIf( m_IsStreamMapped[stream] ); + + const bool isDynamic = (m_StreamModes[stream] == kStreamModeDynamic); + + UInt8* buffer; + int vbSize = CalculateVertexStreamSize(m_Streams[stream], m_VertexCount); + HRESULT hr = m_VBStreams[stream]->Lock( 0 RANDOM_FAIL_FOR_DEBUG, 0, (void**)&buffer, isDynamic ? D3DLOCK_DISCARD : 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to map vertex buffer %p of size %i [%s]\n", m_VBStreams[stream], vbSize, GetD3D9Error(hr) ); + return false; + } + m_IsStreamMapped[stream] = true; + + outData.buffer = buffer; + outData.channelMask = m_Streams[stream].channelMask; + outData.stride = m_Streams[stream].stride; + outData.vertexCount = m_VertexCount; + + GetRealGfxDevice().GetFrameStats().AddUploadVBO( vbSize ); + + return true; +} + +void D3D9VBO::UnmapVertexStream( unsigned stream ) +{ + DebugAssert( m_VBStreams[stream] ); + AssertIf( !m_IsStreamMapped[stream] ); + m_IsStreamMapped[stream] = false; + m_VBStreams[stream]->Unlock(); +} + +bool D3D9VBO::IsVertexBufferLost() const +{ + for( int s = 0; s < kMaxVertexStreams; s++ ) + if( m_Streams[s].channelMask && !m_VBStreams[s] ) + return true; + + return false; +} + +int D3D9VBO::GetRuntimeMemorySize() const +{ +#if ENABLE_MEM_PROFILER + return GetMemoryProfiler()->GetRelatedMemorySize(this) + + GetMemoryProfiler()->GetRelatedIDMemorySize((UInt32)this); +#else + return 0; +#endif +/* int vertexSize = 0; + for( int s = 0; s < kMaxVertexStreams; s++ ) + vertexSize += m_Streams[s].stride; + + return vertexSize * m_VertexCount + m_IBSize;*/ +} + + +void D3D9VBO::DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount) +{ + // just return if no indices + if( m_IBSize == 0 ) + return; + + HRESULT hr; + + if( m_VBStreams[0] == NULL || m_IB == NULL ) + { + printf_console( "d3d: VB or IB is null\n" ); + return; + } + + GfxDevice& device = GetRealGfxDevice(); + IDirect3DDevice9* dev = GetD3DDevice(); + + BindVertexStreams( dev, channels ); + device.BeforeDrawCall( false ); + + if (topology == kPrimitiveQuads) + { + UInt32 ibBytesLocked; + UInt16* ibPtr = MapDynamicIndexBuffer (indexCount/4*6, ibBytesLocked); + if (!ibPtr) + return; + const UInt16* ibSrc = NULL; + hr = m_IB->Lock (firstIndexByte, indexCount*kVBOIndexSize, (void**)&ibSrc, D3DLOCK_READONLY); + if (FAILED(hr)) + { + UnmapDynamicIndexBuffer(); + return; + } + FillIndexBufferForQuads (ibPtr, ibBytesLocked, ibSrc, indexCount/4); + m_IB->Unlock (); + UnmapDynamicIndexBuffer (); + firstIndexByte = ms_CustomIBUsedBytes; + ms_CustomIBUsedBytes += ibBytesLocked; + D3D9_CALL(dev->SetIndices(ms_CustomIB)); + } + else + { + D3D9_CALL(dev->SetIndices( m_IB )); + } + + // draw + D3DPRIMITIVETYPE primType = kTopologyD3D9[topology]; + int primCount = GetPrimitiveCount (indexCount, topology, false); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitive (primType, 0, firstVertex, vertexCount, firstIndexByte/2, primCount)); + Assert(SUCCEEDED(hr)); + + device.GetFrameStats().AddDrawCall (primCount, vertexCount); +} + +UInt16* D3D9VBO::MapDynamicIndexBuffer (int indexCount, UInt32& outBytesUsed) +{ + HRESULT hr; + const UInt32 kMaxIndices = 64000; // Smaller threshold than absolutely necessary + Assert (indexCount <= kMaxIndices); + indexCount = std::min<UInt32>(indexCount, kMaxIndices); + int ibCapacity = indexCount * kVBOIndexSize; + int newIBSize = std::max (ibCapacity, 32*1024); // 32k IB at least + + if (newIBSize > ms_CustomIBSize) + { + if (ms_CustomIB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(ms_CustomIB); + ms_CustomIB->Release(); + } + ms_CustomIBSize = newIBSize; + ms_CustomIBUsedBytes = 0; + + IDirect3DDevice9* dev = GetD3DDevice(); + HRESULT hr = dev->CreateIndexBuffer (ms_CustomIBSize RANDOM_FAIL_FOR_DEBUG, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFMT_INDEX16, D3DPOOL_DEFAULT , &ms_CustomIB, NULL); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(ms_CustomIB,ms_CustomIBSize,0); + + if( FAILED(hr) ) + { + printf_console ("d3d: failed to create custom index buffer of size %d [%s]\n", newIBSize, GetD3D9Error(hr)); + return NULL; + } + } + + UInt16* buffer; + if (ms_CustomIBUsedBytes + ibCapacity > ms_CustomIBSize) + { + hr = ms_CustomIB->Lock (0 RANDOM_FAIL_FOR_DEBUG, ibCapacity, (void**)&buffer, D3DLOCK_DISCARD); + if (FAILED(hr)) + { + printf_console ("d3d: failed to lock shared index buffer with discard [%s]\n", GetD3D9Error(hr)); + return NULL; + } + ms_CustomIBUsedBytes = 0; + } + else + { + hr = ms_CustomIB->Lock (ms_CustomIBUsedBytes RANDOM_FAIL_FOR_DEBUG, ibCapacity, (void**)&buffer, D3DLOCK_NOOVERWRITE); + if (FAILED(hr)) + { + printf_console ("d3d: failed to lock shared index buffer, offset %i size %i [%s]\n", ms_CustomIBUsedBytes, ibCapacity, GetD3D9Error(hr)); + return NULL; + } + } + outBytesUsed = ibCapacity; + + return buffer; +} + +void D3D9VBO::UnmapDynamicIndexBuffer () +{ + ms_CustomIB->Unlock(); +} + + +#if GFX_ENABLE_DRAW_CALL_BATCHING + void D3D9VBO::DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ) + { + Assert(!m_IsStreamMapped[0]); + + if (m_VBStreams[0] == NULL) + { + printf_console( "d3d: VB is null\n" ); + return; + } + UInt32 ibBytesUsed; + UInt16* ibPtr = MapDynamicIndexBuffer (indexCount, ibBytesUsed); + if (!ibPtr) + return; + memcpy (ibPtr, indices, ibBytesUsed); + UnmapDynamicIndexBuffer (); + + GfxDevice& device = GetRealGfxDevice(); + IDirect3DDevice9* dev = GetD3DDevice(); + HRESULT hr; + + BindVertexStreams( dev, channels ); + device.BeforeDrawCall( false ); + + D3D9_CALL(dev->SetIndices( ms_CustomIB )); + + D3DPRIMITIVETYPE primType = kTopologyD3D9[topology]; + int primCount = GetPrimitiveCount (indexCount, topology, false); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitive(primType, 0, vertexRangeBegin, vertexRangeEnd-vertexRangeBegin, ms_CustomIBUsedBytes / kVBOIndexSize, primCount)); + Assert(SUCCEEDED(hr)); + ms_CustomIBUsedBytes += ibBytesUsed; + + device.GetFrameStats().AddDrawCall (primCount, drawVertexCount); + } +#endif + + +void D3D9VBO::UpdateVertexData( const VertexBufferData& buffer ) +{ + // Old vertex count and streams are still used here + for (unsigned stream = 0; stream < kMaxVertexStreams; stream++) + UpdateVertexStream( buffer, stream ); + + memcpy( m_ChannelInfo, buffer.channels, sizeof(m_ChannelInfo) ); + memset( m_VertexDecls, 0, sizeof(m_VertexDecls) ); + m_VertexDecls[kVertexDeclDefault] = GetD3D9GfxDevice().GetVertexDecls().GetVertexDecl( m_ChannelInfo ); + m_VertexCount = buffer.vertexCount; +} + +void D3D9VBO::UpdateIndexData (const IndexBufferData& buffer) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + int newSize = CalculateIndexBufferSize(buffer); + + if( !m_IB ) + { + // initially, create a static buffer + HRESULT hr = dev->CreateIndexBuffer( newSize RANDOM_FAIL_FOR_DEBUG, (buffer.hasTopologies & (1<<kPrimitiveQuads)) ? 0 : D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_IB, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_IB,newSize,this); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to create index buffer of size %d [%s]\n", newSize, GetD3D9Error(hr) ); + return; + } + } + else + { + if( newSize != m_IBSize ) + { + IDirect3DIndexBuffer9* oldIB = m_IB; + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + m_IB->Release(); + HRESULT hr = dev->CreateIndexBuffer( newSize RANDOM_FAIL_FOR_DEBUG, (buffer.hasTopologies & (1<<kPrimitiveQuads)) ? 0 : D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_IB, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_IB,newSize,this); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to resize index buffer %p to size %d [%s]\n", oldIB, newSize, GetD3D9Error(hr) ); + return; + } + } + } + m_IBSize = newSize; + UpdateIndexBufferData(buffer); +} + +// ----------------------------------------------------------------------------- + + +DynamicD3D9VBO::DynamicD3D9VBO( UInt32 vbSize, UInt32 ibSize ) +: DynamicVBO() +, m_VBSize(vbSize) +, m_VBUsedBytes(0) +, m_IBSize(ibSize) +, m_IBUsedBytes(0) +, m_VB(NULL) +, m_IB(NULL) +, m_VertexDecl(NULL) +, m_LastChunkStartVertex(0) +, m_LastChunkStartIndex(0) +, m_QuadsIB(NULL) +, m_QuadsIBFailed(false) +{ +} + +DynamicD3D9VBO::~DynamicD3D9VBO () +{ + if( m_VB ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VB); + ULONG refCount = m_VB->Release(); + AssertIf( refCount != 0 ); + } + if( m_IB ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + ULONG refCount = m_IB->Release(); + AssertIf( refCount != 0 ); + } + if( m_QuadsIB ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_QuadsIB); + ULONG refCount = m_QuadsIB->Release(); + AssertIf( refCount != 0 ); + } +} + +void DynamicD3D9VBO::InitializeQuadsIB() +{ + AssertIf( m_QuadsIB ); + + IDirect3DDevice9* dev = GetD3DDevice(); + HRESULT hr = dev->CreateIndexBuffer( VBO::kMaxQuads * 6 * kVBOIndexSize RANDOM_FAIL_FOR_DEBUG, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_QuadsIB, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_QuadsIB,VBO::kMaxQuads * 6 * kVBOIndexSize,this); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to create quads index buffer [%s]\n", GetD3D9Error(hr) ); + m_QuadsIBFailed = true; + return; + } + UInt16* ib = NULL; + hr = m_QuadsIB->Lock( 0 RANDOM_FAIL_FOR_DEBUG, 0, (void**)&ib, 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock quads index buffer [%s]\n", GetD3D9Error(hr) ); + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_QuadsIB); + m_QuadsIB->Release(); + m_QuadsIB = NULL; + m_QuadsIBFailed = true; + return; + } + + UInt32 baseIndex = 0; + for( int i = 0; i < VBO::kMaxQuads; ++i ) + { + ib[0] = baseIndex + 1; + ib[1] = baseIndex + 2; + ib[2] = baseIndex; + ib[3] = baseIndex + 2; + ib[4] = baseIndex + 3; + ib[5] = baseIndex; + baseIndex += 4; + ib += 6; + } + + m_QuadsIB->Unlock(); +} + +void DynamicD3D9VBO::DrawChunk (const ChannelAssigns& channels) +{ + // just return if nothing to render + if( !m_LastChunkShaderChannelMask ) + return; + + HRESULT hr; + + AssertIf( !m_LastChunkShaderChannelMask || !m_LastChunkStride ); + AssertIf( m_LendedChunk ); + + GfxDevice& device = GetRealGfxDevice(); + IDirect3DDevice9* dev = GetD3DDevice(); + + // setup VBO + DebugAssertIf( !m_VB ); + D3D9_CALL(dev->SetStreamSource( 0, m_VB, 0, m_LastChunkStride )); + D3D9_CALL(dev->SetVertexDeclaration( m_VertexDecl )); + UpdateChannelBindingsD3D( channels ); + device.BeforeDrawCall( false ); + + // draw + GfxDeviceStats& stats = device.GetFrameStats(); + int primCount = 0; + if( m_LastRenderMode == kDrawTriangleStrip ) + { + hr = D3D9_CALL_HR(dev->DrawPrimitive( D3DPT_TRIANGLESTRIP, m_LastChunkStartVertex, m_LastChunkVertices-2 )); + primCount = m_LastChunkVertices-2; + } + else if (m_LastRenderMode == kDrawIndexedTriangleStrip) + { + DebugAssertIf( !m_IB ); + D3D9_CALL(dev->SetIndices( m_IB )); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, m_LastChunkStartVertex, 0, m_LastChunkVertices, m_LastChunkStartIndex, m_LastChunkIndices-2 )); + primCount = m_LastChunkIndices-2; + } + else if( m_LastRenderMode == kDrawQuads ) + { + // initialize quads index buffer if needed + if( !m_QuadsIB ) + InitializeQuadsIB(); + // if quads index buffer has valid data, draw with it + if( !m_QuadsIBFailed ) + { + D3D9_CALL(dev->SetIndices( m_QuadsIB )); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, m_LastChunkStartVertex, 0, m_LastChunkVertices, 0, m_LastChunkVertices/2 )); + primCount = m_LastChunkVertices/2; + } + } + else if (m_LastRenderMode == kDrawIndexedLines) + { + DebugAssertIf( !m_IB ); + D3D9_CALL(dev->SetIndices( m_IB )); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitive( D3DPT_LINELIST, m_LastChunkStartVertex, 0, m_LastChunkVertices, m_LastChunkStartIndex, m_LastChunkIndices/2 )); + primCount = m_LastChunkIndices/2; + } + else if (m_LastRenderMode == kDrawIndexedPoints) + { + DebugAssertIf( !m_IB ); + D3D9_CALL(dev->SetIndices( m_IB )); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitive( D3DPT_POINTLIST, m_LastChunkStartVertex, 0, m_LastChunkVertices, m_LastChunkStartIndex, m_LastChunkIndices )); + primCount = m_LastChunkIndices; + } + else + { + DebugAssertIf( !m_IB ); + D3D9_CALL(dev->SetIndices( m_IB )); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, m_LastChunkStartVertex, 0, m_LastChunkVertices, m_LastChunkStartIndex, m_LastChunkIndices/3 )); + primCount = m_LastChunkIndices/3; + } + stats.AddDrawCall (primCount, m_LastChunkVertices); + AssertIf(FAILED(hr)); +} + +bool DynamicD3D9VBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ) +{ + Assert( !m_LendedChunk ); + Assert( maxVertices < 65536 && maxIndices < 65536*3 ); + Assert(!((renderMode == kDrawQuads) && (VBO::kMaxQuads*4 < maxVertices))); + DebugAssertMsg(outVB != NULL && maxVertices > 0, "DynamicD3D9VBO::GetChunk - outVB: 0x%08x maxVertices: %d", outVB, maxVertices); + DebugAssertMsg( + (renderMode == kDrawIndexedQuads && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedPoints && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedLines && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangles && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangleStrip && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawTriangleStrip && (outIB == NULL && maxIndices == 0)) || + (renderMode == kDrawQuads && (outIB == NULL && maxIndices == 0)), + "DynamicD3D9VBO::GetChunk - renderMode: %d outIB: 0x%08x maxIndices: %d", renderMode, outIB, maxIndices); + HRESULT hr; + bool success = true; + + m_LendedChunk = true; + m_LastRenderMode = renderMode; + + if( maxVertices == 0 ) + maxVertices = 8; + + m_LastChunkStride = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( shaderChannelMask & (1<<i) ) + m_LastChunkStride += VBO::GetDefaultChannelByteSize(i); + } + if (shaderChannelMask != m_LastChunkShaderChannelMask) + { + m_VertexDecl = GetD3DVertexDeclaration( shaderChannelMask ); + m_LastChunkShaderChannelMask = shaderChannelMask; + } + IDirect3DDevice9* dev = GetD3DDevice(); + + // -------- vertex buffer + + DebugAssertIf( !outVB ); + UInt32 vbCapacity = maxVertices * m_LastChunkStride; + // check if requested chunk is larger than current buffer + if( vbCapacity > m_VBSize ) { + m_VBSize = vbCapacity * 2; // allocate more up front + if( m_VB ){ + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VB); + m_VB->Release(); + } + m_VB = NULL; + } + // allocate buffer if don't have it yet + if( !m_VB ) { + hr = dev->CreateVertexBuffer( m_VBSize RANDOM_FAIL_FOR_DEBUG, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_VB, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_VB,m_VBSize,this); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to create dynamic vertex buffer of size %d [%s]\n", m_VBSize, GetD3D9Error(hr) ); + success = false; + *outVB = NULL; + } + } + + // lock, making sure the offset we lock is multiple of vertex stride + if( m_VB ) + { + m_VBUsedBytes = ((m_VBUsedBytes + (m_LastChunkStride-1)) / m_LastChunkStride) * m_LastChunkStride; + if( m_VBUsedBytes + vbCapacity > m_VBSize ) { + hr = m_VB->Lock( 0 RANDOM_FAIL_FOR_DEBUG, 0, outVB, D3DLOCK_DISCARD ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock dynamic vertex buffer with discard [%s]\n", GetD3D9Error(hr) ); + *outVB = NULL; + success = false; + } + m_VBUsedBytes = 0; + } else { + hr = m_VB->Lock( m_VBUsedBytes RANDOM_FAIL_FOR_DEBUG, vbCapacity, outVB, D3DLOCK_NOOVERWRITE ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock vertex index buffer, offset %i size %i [%s]\n", m_VBUsedBytes, vbCapacity, GetD3D9Error(hr) ); + *outVB = NULL; + success = false; + } + } + m_LastChunkStartVertex = m_VBUsedBytes / m_LastChunkStride; + DebugAssertIf( m_LastChunkStartVertex * m_LastChunkStride != m_VBUsedBytes ); + } + + // -------- index buffer + + const bool indexed = (renderMode != kDrawQuads) && (renderMode != kDrawTriangleStrip); + if( success && maxIndices && indexed ) + { + UInt32 ibCapacity = maxIndices * kVBOIndexSize; + // check if requested chunk is larger than current buffer + if( ibCapacity > m_IBSize ) { + m_IBSize = ibCapacity * 2; // allocate more up front + if( m_IB ){ + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + m_IB->Release(); + } + m_IB = NULL; + } + // allocate buffer if don't have it yet + if( !m_IB ) { + hr = dev->CreateIndexBuffer( m_IBSize RANDOM_FAIL_FOR_DEBUG, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_IB, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_IB,m_IBSize,this); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to create dynamic index buffer of size %d [%s]\n", m_IBSize, GetD3D9Error(hr) ); + if( m_VB ) + m_VB->Unlock(); + } + } + // lock it if we have IB created successfully + if( m_IB ) + { + if( m_IBUsedBytes + ibCapacity > m_IBSize ) { + hr = m_IB->Lock( 0 RANDOM_FAIL_FOR_DEBUG, 0, outIB, D3DLOCK_DISCARD ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock dynamic index buffer with discard [%s]\n", GetD3D9Error(hr) ); + *outIB = NULL; + success = false; + if( m_VB ) + m_VB->Unlock(); + } + m_IBUsedBytes = 0; + } else { + hr = m_IB->Lock( m_IBUsedBytes RANDOM_FAIL_FOR_DEBUG, ibCapacity, outIB, D3DLOCK_NOOVERWRITE ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock dynamic index buffer, offset %i size %i [%s]\n", m_IBUsedBytes, ibCapacity, GetD3D9Error(hr) ); + *outIB = NULL; + success = false; + if( m_VB ) + m_VB->Unlock(); + } + } + m_LastChunkStartIndex = m_IBUsedBytes / 2; + } + else + { + *outIB = NULL; + success = false; + } + } + + if( !success ) + m_LendedChunk = false; + + return success; +} + +void DynamicD3D9VBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ) +{ + Assert( m_LendedChunk ); + Assert( m_LastRenderMode == kDrawIndexedTriangleStrip || m_LastRenderMode == kDrawIndexedQuads || m_LastRenderMode == kDrawIndexedPoints || m_LastRenderMode == kDrawIndexedLines || actualIndices % 3 == 0 ); + m_LendedChunk = false; + + const bool indexed = (m_LastRenderMode != kDrawQuads) && (m_LastRenderMode != kDrawTriangleStrip); + + m_LastChunkVertices = actualVertices; + m_LastChunkIndices = actualIndices; + + // unlock buffers + m_VB->Unlock(); + if( indexed ) + m_IB->Unlock(); + + if( !actualVertices || (indexed && !actualIndices) ) { + m_LastChunkShaderChannelMask = 0; + return; + } + + UInt32 actualVBSize = actualVertices * m_LastChunkStride; + m_VBUsedBytes += actualVBSize; + UInt32 actualIBSize = actualIndices * kVBOIndexSize; + m_IBUsedBytes += actualIBSize; +} + + diff --git a/Runtime/GfxDevice/d3d/D3D9VBO.h b/Runtime/GfxDevice/d3d/D3D9VBO.h new file mode 100644 index 0000000..71c0da9 --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9VBO.h @@ -0,0 +1,86 @@ +#pragma once + +#include "D3D9Includes.h" +#include "Runtime/Shaders/VBO.h" + + +// Implements Direct3D9 VBO +class D3D9VBO : public VBO { +public: + D3D9VBO(); + virtual ~D3D9VBO(); + + virtual void UpdateVertexData( const VertexBufferData& buffer ); + virtual void UpdateIndexData (const IndexBufferData& buffer); + virtual void DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount); + #if GFX_ENABLE_DRAW_CALL_BATCHING + virtual void DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ); + #endif + virtual bool MapVertexStream( VertexStreamData& outData, unsigned stream ); + virtual void UnmapVertexStream( unsigned stream ); + virtual bool IsVertexBufferLost() const; + + virtual void ResetDynamicVB(); + + virtual int GetRuntimeMemorySize() const; + + static void CleanupSharedIndexBuffer(); + +private: + void BindVertexStreams( IDirect3DDevice9* dev, const ChannelAssigns& channels ); + void UpdateVertexStream( const VertexBufferData& sourceData, unsigned stream ); + void UpdateIndexBufferData (const IndexBufferData& sourceData); + static UInt16* MapDynamicIndexBuffer (int indexCount, UInt32& outBytesUsed); + static void UnmapDynamicIndexBuffer (); + +private: + int m_VertexCount; + + enum + { + kVertexDeclDefault, + kVertexDeclAllWhiteStream, + kVertexDeclCount + }; + + IDirect3DVertexBuffer9* m_VBStreams[kMaxVertexStreams]; + IDirect3DIndexBuffer9* m_IB; + IDirect3DVertexDeclaration9* m_VertexDecls[kVertexDeclCount]; + ChannelInfoArray m_ChannelInfo; + int m_IBSize; + + static IDirect3DIndexBuffer9* ms_CustomIB; + static int ms_CustomIBSize; + static UInt32 ms_CustomIBUsedBytes; +}; + +class DynamicD3D9VBO : public DynamicVBO { +public: + DynamicD3D9VBO( UInt32 vbSize, UInt32 ibSize ); + virtual ~DynamicD3D9VBO(); + + virtual bool GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode mode, void** outVB, void** outIB ); + virtual void ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ); + virtual void DrawChunk (const ChannelAssigns& channels); + +private: + void InitializeQuadsIB(); + +private: + UInt32 m_VBSize; + UInt32 m_VBUsedBytes; + UInt32 m_IBSize; + UInt32 m_IBUsedBytes; + + IDirect3DVertexBuffer9* m_VB; + IDirect3DIndexBuffer9* m_IB; + IDirect3DVertexDeclaration9* m_VertexDecl; // vertex declaration for the last chunk + + UInt32 m_LastChunkStartVertex; + UInt32 m_LastChunkStartIndex; + + IDirect3DIndexBuffer9* m_QuadsIB; // static IB for drawing quads + bool m_QuadsIBFailed; +}; + diff --git a/Runtime/GfxDevice/d3d/D3D9Window.cpp b/Runtime/GfxDevice/d3d/D3D9Window.cpp new file mode 100644 index 0000000..b568b34 --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Window.cpp @@ -0,0 +1,272 @@ +#include "UnityPrefix.h" +#include "D3D9Window.h" +#include "GfxDeviceD3D9.h" +#include "RenderTextureD3D.h" +#include "Runtime/Misc/QualitySettings.h" +#include "Runtime/Threads/ThreadSharedObject.h" +#include "Runtime/GfxDevice/GfxDevice.h" + + +#if UNITY_EDITOR + +bool IsD3D9DeviceLost(); +void SetD3D9DeviceLost( bool lost ); + +static bool s_OldHasDepthFlag = false; +static D3D9Window* s_CurrentD3DWindow = NULL; +static int s_CurrentD3DFSAALevel = 0; + +int GetCurrentD3DFSAALevel() { return s_CurrentD3DFSAALevel; } + +void SetNoRenderTextureActiveEditor(); // RenderTexture.cpp + + +D3D9Window::D3D9Window(IDirect3DDevice9* device, HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) +: GfxDeviceWindow(window, width, height, depthFormat, antiAlias) +, m_SwapChain(NULL) +, m_FSAALevel(0) +{ + m_Device = device; + Reshape( width, height, depthFormat, antiAlias ); +} + +D3D9Window::~D3D9Window() +{ + if( s_CurrentD3DWindow == this ) + { + s_CurrentD3DWindow = NULL; + s_CurrentD3DFSAALevel = 0; + } + + DestroyRenderSurfaceD3D9(&m_DepthStencil); + DestroyRenderSurfaceD3D9(&m_BackBuffer); + SAFE_RELEASE(m_SwapChain); +} + +bool D3D9Window::Reshape( int width, int height, DepthBufferFormat depthFormat, int antiAlias ) +{ + if(GfxDeviceWindow::Reshape(width, height, depthFormat, antiAlias)==false)return false; + + + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("D3Dwindow %x Reshape %ix%i d=%i aa=%i\n", this, width, height, depthFormat, antiAlias); + #endif + // release old + m_DepthStencil.Release(); + m_BackBuffer.Release(); + SAFE_RELEASE(m_SwapChain); + + HRESULT hr; + + + // Choose presentation params + if( antiAlias == -1 ) + antiAlias = GetQualitySettings().GetCurrent().antiAliasing; + + D3DDISPLAYMODE mode; + hr = GetD3DObject()->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &mode ); + D3DPRESENT_PARAMETERS params; + + ZeroMemory( ¶ms, sizeof(params) ); + params.BackBufferWidth = m_Width; + params.BackBufferHeight = m_Height; + params.BackBufferCount = 1; + params.hDeviceWindow = m_Window; + params.FullScreen_RefreshRateInHz = 0; + params.Windowed = TRUE; + params.SwapEffect = D3DSWAPEFFECT_COPY; + params.BackBufferFormat = D3DFMT_A8R8G8B8; + params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + params.EnableAutoDepthStencil = FALSE; + GetD3DFormatCaps()->FindBestPresentationParams( width, height, mode.Format, true, 0, antiAlias, params ); + if( params.MultiSampleType != D3DMULTISAMPLE_NONE ) { + params.SwapEffect = D3DSWAPEFFECT_DISCARD; + m_CanUseBlitOptimization = false; + } else { + m_CanUseBlitOptimization = true; + } + m_FSAALevel = (params.MultiSampleType == D3DMULTISAMPLE_NONMASKABLE) ? params.MultiSampleQuality : params.MultiSampleType; + + hr = m_Device->CreateAdditionalSwapChain( ¶ms, &m_SwapChain ); + if( FAILED(hr) ) { + printf_console( "d3d: swap chain: swap=%i vsync=%x w=%i h=%i fmt=%i bbcount=%i dsformat=%i pflags=%x\n", + params.SwapEffect, params.PresentationInterval, + params.BackBufferWidth, params.BackBufferHeight, params.BackBufferFormat, params.BackBufferCount, + params.AutoDepthStencilFormat, params.Flags ); + printf_console( "d3d: failed to create swap chain [%s]\n", GetD3D9Error(hr) ); + m_InvalidState = true; + return !m_InvalidState; + } + + IDirect3DSurface9* backBuffer = NULL; + hr = m_SwapChain->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer ); + if( FAILED(hr) ) { + AssertString( "Failed to get back buffer for D3DWindow" ); + m_SwapChain->Release(); + m_SwapChain = NULL; + m_InvalidState = true; + return !m_InvalidState; + } + + m_BackBuffer.backBuffer = true; + m_DepthStencil.backBuffer = true; + + m_BackBuffer.m_Surface = backBuffer; + m_BackBuffer.width = params.BackBufferWidth; + m_BackBuffer.height = params.BackBufferHeight; + m_BackBuffer.format = kRTFormatARGB32; + + // Depth format + bool needsDepth = false; + m_DepthStencilFormat = D3DFMT_UNKNOWN; + switch( depthFormat ) { + case kDepthFormatNone: + needsDepth = false; + m_DepthStencilFormat = D3DFMT_UNKNOWN; + break; + case kDepthFormat16: + needsDepth = true; + m_DepthStencilFormat = D3DFMT_D16; + break; + case kDepthFormat24: + needsDepth = true; + m_DepthStencilFormat = D3DFMT_D24S8; + break; + default: + ErrorString("Unknown depth format"); + } + + if( needsDepth ) + { + D3D9DepthStencilTexture depthStencil = CreateDepthStencilTextureD3D9 (m_Device, m_Width, m_Height, m_DepthStencilFormat, params.MultiSampleType, params.MultiSampleQuality, FALSE); + m_Device->SetRenderState (D3DRS_ZENABLE, TRUE); + if (!depthStencil.m_Surface) + { + AssertString( "Failed to create depth/stencil for D3DWindow" ); + m_SwapChain->Release(); + m_SwapChain = NULL; + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_BackBuffer.m_Surface); + m_BackBuffer.m_Surface->Release(); + m_BackBuffer.m_Surface = NULL; + m_InvalidState = true; + return !m_InvalidState; + } + m_DepthStencil.m_Surface = depthStencil.m_Surface; + m_DepthStencil.m_Texture = depthStencil.m_Texture; + m_DepthStencil.width = m_Width; + m_DepthStencil.height = m_Height; + m_DepthStencil.depthFormat = depthFormat; + } + + return !m_InvalidState; +} + +void D3D9Window::SetAsActiveWindow () +{ + GetRealGfxDevice().SetRenderTargets(1, &GetBackBuffer(), GetDepthStencil()); + GetRealGfxDevice().SetActiveRenderTexture(NULL); + GetRealGfxDevice().SetCurrentWindowSize(m_Width, m_Height); + GetRealGfxDevice().SetInvertProjectionMatrix(false); + + s_OldHasDepthFlag = g_D3DHasDepthStencil; + g_D3DHasDepthStencil = (m_DepthStencil.m_Surface != NULL); + + s_CurrentD3DWindow = this; + s_CurrentD3DFSAALevel = m_FSAALevel; + + // not entirely correct but better not touch anything if we don't have depth + if(m_DepthStencil.m_Surface != NULL) + g_D3DDepthStencilFormat = m_DepthStencilFormat; +} + +bool D3D9Window::BeginRendering() +{ + if (GfxDeviceWindow::BeginRendering()) + { + HRESULT hr; + + // Handle lost devices + if (!GetRealGfxDevice().IsValidState()) + { + return false; + } + + // begin scene + if (IsD3D9DeviceLost()) + { + ErrorString ("GUI Window tries to begin rendering while D3D9 device is lost!"); + } + GfxDeviceD3D9& device = static_cast<GfxDeviceD3D9&>( GetRealGfxDevice() ); + if (device.IsInsideFrame()) + { + ErrorString ("GUI Window tries to begin rendering while something else has not finished rendering! Either you have a recursive OnGUI rendering, or previous OnGUI did not clean up properly."); + } + + m_Device->BeginScene(); + SetAsActiveWindow (); + + device.SetInsideFrame(true); + return true; + } + else + { + #if ENABLE_D3D_WINDOW_LOGGING + printf_console("D3Dwindow %ix%i BeginRendering: invalid state\n", m_Width, m_Height); + #endif + return false; + } +} + +bool D3D9Window::EndRendering( bool presentContent ) +{ + if(GfxDeviceWindow::EndRendering(presentContent)) + { + + g_D3DHasDepthStencil = s_OldHasDepthFlag; + s_CurrentD3DWindow = NULL; + s_CurrentD3DWindow = 0; + + if( IsD3D9DeviceLost() ) + return false; + + HRESULT hr; + GfxDeviceD3D9& device = static_cast<GfxDeviceD3D9&>( GetRealGfxDevice() ); + Assert( device.IsInsideFrame() ); + hr = m_Device->EndScene(); + device.SetInsideFrame(false); + if( m_SwapChain && presentContent ) + { + hr = m_SwapChain->Present( NULL, NULL, NULL, NULL, 0 ); + device.PushEventQuery(); + // When D3DERR_DRIVERINTERNALERROR is returned from Present(), + // the application can do one of the following, try recovering just as + // from the lost device. + if( hr == D3DERR_DEVICELOST || hr == D3DERR_DRIVERINTERNALERROR ) + { + SetD3D9DeviceLost( true ); + return false; + } + } + return true; + } + else + { + return false; + } +} + +RenderSurfaceHandle D3D9Window::GetBackBuffer() +{ + RenderSurfaceHandle handle; + handle.object = &m_BackBuffer; + return handle; +} + +RenderSurfaceHandle D3D9Window::GetDepthStencil() +{ + RenderSurfaceHandle handle; + handle.object = &m_DepthStencil; + return handle; +} + +#endif diff --git a/Runtime/GfxDevice/d3d/D3D9Window.h b/Runtime/GfxDevice/d3d/D3D9Window.h new file mode 100644 index 0000000..038b59f --- /dev/null +++ b/Runtime/GfxDevice/d3d/D3D9Window.h @@ -0,0 +1,39 @@ +#ifndef D3D9WINDOW_H +#define D3D9WINDOW_H + +#include "D3D9Includes.h" +#include "Runtime/GfxDevice/GfxDeviceWindow.h" +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "D3D9Utils.h" +#include "TexturesD3D9.h" + +class D3D9Window : public GfxDeviceWindow +{ +private: + IDirect3DDevice9* m_Device; + IDirect3DSwapChain9* m_SwapChain; + RenderColorSurfaceD3D9 m_BackBuffer; + RenderDepthSurfaceD3D9 m_DepthStencil; + D3DFORMAT m_DepthStencilFormat; + int m_FSAALevel; +public: + D3D9Window( IDirect3DDevice9* device, HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + ~D3D9Window(); + + bool Reshape( int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + + bool BeginRendering(); + bool EndRendering( bool presentContent ); + void SetAsActiveWindow (); + + D3DFORMAT GetDepthStencilFormat() const { return m_DepthStencilFormat; } + + RenderSurfaceHandle GetBackBuffer(); + RenderSurfaceHandle GetDepthStencil(); +}; + +#if UNITY_EDITOR +int GetCurrentD3DFSAALevel(); +#endif + +#endif diff --git a/Runtime/GfxDevice/d3d/GfxDeviceD3D9.cpp b/Runtime/GfxDevice/d3d/GfxDeviceD3D9.cpp new file mode 100644 index 0000000..77fe956 --- /dev/null +++ b/Runtime/GfxDevice/d3d/GfxDeviceD3D9.cpp @@ -0,0 +1,3009 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "GfxDeviceD3D9.h" +#include "D3D9Context.h" +#include "Runtime/Math/FloatConversion.h" +#include "D3D9VBO.h" +#include "CombinerD3D.h" +#include "External/shaderlab/Library/program.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "External/shaderlab/Library/texenv.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "External/shaderlab/Library/pass.h" +#include "Runtime/GfxDevice/BuiltinShaderParams.h" +#include "Runtime/GfxDevice/GpuProgramParamsApply.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Graphics/ScreenManager.h" +#include "PlatformDependent/Win/SmartComPointer.h" +#include "PlatformDependent/Win/WinUnicode.h" +#include "Runtime/Allocator/LinearAllocator.h" +#include "Runtime/Utilities/Utility.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Threads/Thread.h" +#include "Runtime/Misc/Plugins.h" +#include "D3D9Utils.h" +#include "D3D9Window.h" +#include "RenderTextureD3D.h" +#include "GpuProgramsD3D.h" +#include "TimerQueryD3D9.h" +#include "GfxDeviceD3D9.h" + + +// -------------------------------------------------------------------------- + +bool IsActiveRenderTargetWithColorD3D9(); + +typedef std::list<IDirect3DQuery9*> D3D9QueryList; +static D3D9QueryList s_EventQueries; + +static void PushEventQuery (int maxBuffer); +static void CleanupEventQueries (); + + + +static const D3DBLEND kBlendModeD3D9[] = { + D3DBLEND_ZERO, D3DBLEND_ONE, D3DBLEND_DESTCOLOR, D3DBLEND_SRCCOLOR, D3DBLEND_INVDESTCOLOR, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCCOLOR, + D3DBLEND_DESTALPHA, D3DBLEND_INVDESTALPHA, D3DBLEND_SRCALPHASAT, D3DBLEND_INVSRCALPHA, +}; + +static const D3DBLENDOP kBlendOpD3D9[] = { + D3DBLENDOP_ADD, D3DBLENDOP_SUBTRACT, D3DBLENDOP_REVSUBTRACT, D3DBLENDOP_MIN, D3DBLENDOP_MAX, +}; + +static const D3DCMPFUNC kCmpFuncD3D9[] = { + D3DCMP_ALWAYS, D3DCMP_NEVER, D3DCMP_LESS, D3DCMP_EQUAL, D3DCMP_LESSEQUAL, D3DCMP_GREATER, D3DCMP_NOTEQUAL, D3DCMP_GREATEREQUAL, D3DCMP_ALWAYS +}; + +static const D3DSTENCILOP kStencilOpD3D9[] = { + D3DSTENCILOP_KEEP, D3DSTENCILOP_ZERO, D3DSTENCILOP_REPLACE, D3DSTENCILOP_INCRSAT, + D3DSTENCILOP_DECRSAT, D3DSTENCILOP_INVERT, D3DSTENCILOP_INCR, D3DSTENCILOP_DECR +}; + +static D3DCULL kCullModeD3D9[] = { + D3DCULL_NONE, D3DCULL_CW, D3DCULL_CCW +}; + +// -------------------------------------------------------------------------- + + +static inline D3DCOLOR ColorToD3D( const float color[4] ) +{ + return D3DCOLOR_RGBA( NormalizedToByte(color[0]), NormalizedToByte(color[1]), NormalizedToByte(color[2]), NormalizedToByte(color[3]) ); +} + + + +// -------------------------------------------------------------------------- + +enum { + kNeedsSoftwareVPVertexShader = (1<<0), + kNeedsSoftwareVPTexGen = (1<<1), +}; + +class GfxDeviceD3D9; + +static void ApplyBackfaceMode( DeviceStateD3D& state ); +static void ApplyStencilFuncAndOp( DeviceStateD3D& state ); + + + + + +void DeviceStateD3D::Invalidate( GfxDeviceD3D9& device ) +{ + int i; + + depthFunc = kFuncUnknown; + depthWrite = -1; + + blending = -1; // unknown + srcBlend = destBlend = srcBlendAlpha = destBlendAlpha = -1; // won't match any D3D mode + blendOp = blendOpAlpha = -1; // won't match any D3D mode + alphaFunc = kFuncUnknown; + alphaValue = -1.0f; + + culling = kCullUnknown; + d3dculling = D3DCULL_FORCE_DWORD; + scissor = -1; + + offsetFactor = offsetUnits = -1000.0f; + for( i = 0; i < kShaderTypeCount; ++i ) + { + activeGpuProgramParams[i] = NULL; + activeGpuProgram[i] = NULL; + activeShader[i] = NULL; + } + fixedFunctionPS = 0; + + colorWriteMask = -1; // TBD ? + m_StencilRef = -1; + + for (i = 0; i < ARRAY_SIZE(texturesPS); ++i) + texturesPS[i].Invalidate(); + for (i = 0; i < ARRAY_SIZE(texturesVS); ++i) + texturesVS[i].Invalidate(); + + m_SoftwareVP = false; + m_NeedsSofwareVPFlags = 0; + + IDirect3DDevice9* dev = GetD3DDeviceNoAssert(); + if( dev && !m_DeviceLost ) + { + D3D9_CALL(dev->SetVertexShader( NULL )); + D3D9_CALL(dev->SetPixelShader( NULL )); + + ApplyBackfaceMode( *this ); + + if( g_D3DUsesMixedVP ) + D3D9_CALL(dev->SetSoftwareVertexProcessing( FALSE )); + + // misc. state + D3D9_CALL(dev->SetRenderState( D3DRS_LOCALVIEWER, TRUE )); + + #if UNITY_EDITOR + D3D9_CALL(dev->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID )); + #endif + } +} + + +void UpdateChannelBindingsD3D( const ChannelAssigns& channels ) +{ + // Texture coordinate index bindings + GfxDeviceD3D9& device = (GfxDeviceD3D9&)GetRealGfxDevice(); + if( device.IsShaderActive(kShaderVertex) ) + return; + DeviceStateD3D& state = device.GetState(); + IDirect3DDevice9* dev = GetD3DDevice(); + + const int maxTexCoords = gGraphicsCaps.maxTexCoords; // fetch here once + + VertexPipeConfig& config = device.GetVertexPipeConfig(); + UInt32 textureSources = config.textureSources; + for( int i = 0; i < maxTexCoords; ++i ) + { + UInt32 source = (textureSources >> (i*3)) & 0x7; + if( source > kTexSourceUV1 ) + continue; + ShaderChannel texCoordChannel = channels.GetSourceForTarget( (VertexComponent)(kVertexCompTexCoord0 + i) ); + if( texCoordChannel == kShaderChannelTexCoord0 ) + textureSources = textureSources & ~(7<<i*3) | (kTexSourceUV0<<i*3); + else if( texCoordChannel == kShaderChannelTexCoord1 ) + textureSources = textureSources & ~(7<<i*3) | (kTexSourceUV1<<i*3); + else if( texCoordChannel != kShaderChannelNone ) { + AssertString( "Bad texcoord index" ); + } + } + config.textureSources = textureSources; + + config.hasVertexColor = (channels.GetTargetMap() & (1<<kVertexCompColor)) ? 1 : 0; +} + + +struct SetValuesFunctorD3D9 +{ + SetValuesFunctorD3D9(GfxDevice& device, VertexShaderConstantCache& vs, PixelShaderConstantCache& ps) : m_Device(device), vscache(vs), pscache(ps) { } + GfxDevice& m_Device; + VertexShaderConstantCache& vscache; + PixelShaderConstantCache& pscache; + void SetVectorVal (ShaderType shaderType, ShaderParamType type, int index, const float* ptr, int cols, const GpuProgramParameters& params, int cbIndex) + { + if (shaderType == kShaderVertex) + vscache.SetValues(index, ptr, 1); + else + pscache.SetValues(index, ptr, 1); + } + void SetMatrixVal (ShaderType shaderType, int index, const Matrix4x4f* ptr, int rows, const GpuProgramParameters& params, int cbIndex) + { + DebugAssert(rows == 4); + Matrix4x4f mat; + TransposeMatrix4x4 (ptr, &mat); + if (shaderType == kShaderVertex) + vscache.SetValues(index, mat.GetPtr(), 4); + else + pscache.SetValues(index, mat.GetPtr(), 4); + } + void SetTextureVal (ShaderType shaderType, int index, int samplerIndex, TextureDimension dim, TextureID texID) + { + m_Device.SetTexture (shaderType, index, samplerIndex, texID, dim, std::numeric_limits<float>::infinity()); + } +}; + + +// Compute/Update any deferred state before each draw call +void GfxDeviceD3D9::BeforeDrawCall( bool immediateMode ) +{ + VertexShaderConstantCache& vscache = GetVertexShaderConstantCache(); + PixelShaderConstantCache& pscache = GetPixelShaderConstantCache(); + DeviceStateD3D& state = m_State; + IDirect3DDevice9* dev = GetD3DDevice(); + bool usesVertexShader = (state.activeShader[kShaderVertex] != NULL); + + //@TODO: remove TESTING CODE + static bool oldTnL = false; + if( oldTnL != (!immediateMode) ) + { + m_VertexPrevious.config.Reset (); + m_VertexPrevious.ambient.set(-1,-1,-1,-1); + oldTnL = !immediateMode; + } + + m_TransformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + + // Deferred setup of fixed function stuff + if (!immediateMode) + SetupVertexShaderD3D9( dev, m_TransformState, m_BuiltinParamValues, m_VertexConfig, m_VertexData, m_VertexPrevious, vscache, usesVertexShader, immediateMode ); + else + SetupFixedFunctionD3D9( dev, m_TransformState, m_BuiltinParamValues, m_VertexConfig, m_VertexData, m_VertexPrevious, usesVertexShader, immediateMode ); + + + // update GL equivalents of built-in shader state + + const BuiltinShaderParamIndices& paramsVS = *m_BuiltinParamIndices[kShaderVertex]; + const BuiltinShaderParamIndices& paramsPS = *m_BuiltinParamIndices[kShaderFragment]; + int gpuIndexVS, gpuIndexPS; + +#define SET_BUILTIN_MATRIX_BEGIN(idx) \ + gpuIndexVS = paramsVS.mat[idx].gpuIndex; gpuIndexPS = paramsPS.mat[idx].gpuIndex; if (gpuIndexVS >= 0 || gpuIndexPS >= 0) + +#define SET_BUILTIN_MATRIX_END(name) \ + if (gpuIndexVS >= 0) vscache.SetValues(gpuIndexVS, name.GetPtr(), 4); \ + if (gpuIndexPS >= 0) pscache.SetValues(gpuIndexPS, name.GetPtr(), 4) + + // MVP matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatMVP) + { + Matrix4x4f matMul; + MultiplyMatrices4x4 (&m_BuiltinParamValues.GetMatrixParam(kShaderMatProj), &m_TransformState.worldViewMatrix, &matMul); + Matrix4x4f mat; + TransposeMatrix4x4 (&matMul, &mat); + SET_BUILTIN_MATRIX_END(mat); + } + // MV matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatMV) + { + Matrix4x4f mat; + TransposeMatrix4x4 (&m_TransformState.worldViewMatrix, &mat); + SET_BUILTIN_MATRIX_END(mat); + } + // Transpose MV matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatTransMV) + { + const Matrix4x4f& mat = m_TransformState.worldViewMatrix; + SET_BUILTIN_MATRIX_END(mat); + } + // Inverse transpose of MV matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatInvTransMV) + { + Matrix4x4f mat; + Matrix4x4f::Invert_Full (m_TransformState.worldViewMatrix, mat); + if (m_VertexData.normalization == kNormalizationScale) + { + // Inverse transpose of modelview should be scaled by uniform + // normal scale (this will match state.matrix.invtrans.modelview + // and gl_NormalMatrix in OpenGL) + float scale = Magnitude (m_TransformState.worldMatrix.GetAxisX()); + mat.Get (0, 0) *= scale; + mat.Get (1, 0) *= scale; + mat.Get (2, 0) *= scale; + mat.Get (0, 1) *= scale; + mat.Get (1, 1) *= scale; + mat.Get (2, 1) *= scale; + mat.Get (0, 2) *= scale; + mat.Get (1, 2) *= scale; + mat.Get (2, 2) *= scale; + } + SET_BUILTIN_MATRIX_END(mat); + } + // M matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatM) + { + Matrix4x4f mat; + TransposeMatrix4x4 (&m_TransformState.worldMatrix, &mat); + SET_BUILTIN_MATRIX_END(mat); + } + // Inverse M matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatInvM) + { + Matrix4x4f mat = m_TransformState.worldMatrix; + if (m_VertexData.normalization == kNormalizationScale) + { + // Kill scale in the world matrix before inverse + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + mat.Get (0, 0) *= invScale; + mat.Get (1, 0) *= invScale; + mat.Get (2, 0) *= invScale; + mat.Get (0, 1) *= invScale; + mat.Get (1, 1) *= invScale; + mat.Get (2, 1) *= invScale; + mat.Get (0, 2) *= invScale; + mat.Get (1, 2) *= invScale; + mat.Get (2, 2) *= invScale; + } + Matrix4x4f inverseMat; + Matrix4x4f::Invert_General3D (mat, inverseMat); + TransposeMatrix4x4 (&inverseMat, &mat); + SET_BUILTIN_MATRIX_END(mat); + } + + // Set instance vector parameters + for (int i = 0; i < kShaderInstanceVecCount; ++i) + { + gpuIndexVS = paramsVS.vec[i].gpuIndex; + if (gpuIndexVS >= 0) + vscache.SetValues(gpuIndexVS, m_BuiltinParamValues.GetInstanceVectorParam((ShaderBuiltinInstanceVectorParam)i).GetPtr(), 1); + gpuIndexPS = paramsPS.vec[i].gpuIndex; + if (gpuIndexPS >= 0) + pscache.SetValues(gpuIndexPS, m_BuiltinParamValues.GetInstanceVectorParam((ShaderBuiltinInstanceVectorParam)i).GetPtr(), 1); + } + + // Texture matrices for vertex shader + for( int i = 0; i < 8; ++i ) + { + if( paramsVS.mat[kShaderInstanceMatTexture0 + i].gpuIndex >= 0 ) + { + Matrix4x4f mat; + TransposeMatrix4x4 (&m_TransformState.texMatrices[i], &mat); + const int index = paramsVS.mat[kShaderInstanceMatTexture0 + i].gpuIndex; + vscache.SetValues( index, mat.GetPtr(), 4 ); + } + } + + // Software VP flags + if( g_D3DUsesMixedVP ) + { + if( state.m_NeedsSofwareVPFlags ) + { + if( state.m_SoftwareVP == false ) + { + D3D9_CALL(dev->SetSoftwareVertexProcessing( TRUE )); + state.m_SoftwareVP = true; + } + } + else + { + if( state.m_SoftwareVP == true ) + { + D3D9_CALL(dev->SetSoftwareVertexProcessing( FALSE )); + state.m_SoftwareVP = false; + } + } + } + + SetValuesFunctorD3D9 setValuesFunc(*this, vscache, pscache); + ApplyMaterialPropertyBlockValues(m_MaterialProperties, m_State.activeGpuProgram ,m_State.activeGpuProgramParams, setValuesFunc); + + vscache.CommitVertexConstants(); + pscache.CommitPixelConstants(); +} + + +DeviceBlendState* GfxDeviceD3D9::CreateBlendState(const GfxBlendState& state) +{ + std::pair<CachedBlendStates::iterator, bool> result = m_CachedBlendStates.insert(std::make_pair(state, DeviceBlendStateD3D9())); + if (!result.second) + return &result.first->second; + + DeviceBlendStateD3D9& d3dstate = result.first->second; + memcpy(&d3dstate.sourceState, &state, sizeof(GfxBlendState)); + DWORD d3dmask = 0; + const UInt8 mask = state.renderTargetWriteMask; + if( mask & kColorWriteR ) d3dmask |= D3DCOLORWRITEENABLE_RED; + if( mask & kColorWriteG ) d3dmask |= D3DCOLORWRITEENABLE_GREEN; + if( mask & kColorWriteB ) d3dmask |= D3DCOLORWRITEENABLE_BLUE; + if( mask & kColorWriteA ) d3dmask |= D3DCOLORWRITEENABLE_ALPHA; + d3dstate.renderTargetWriteMask = d3dmask; + + DebugAssertIf(kFuncUnknown==state.alphaTest); + d3dstate.alphaFunc = kCmpFuncD3D9[state.alphaTest]; + return &result.first->second; +} + + +DeviceDepthState* GfxDeviceD3D9::CreateDepthState(const GfxDepthState& state) +{ + std::pair<CachedDepthStates::iterator, bool> result = m_CachedDepthStates.insert(std::make_pair(state, DeviceDepthStateD3D9())); + if (!result.second) + return &result.first->second; + + DeviceDepthStateD3D9& d3dstate = result.first->second; + memcpy(&d3dstate.sourceState, &state, sizeof(GfxDepthState)); + d3dstate.depthFunc = kCmpFuncD3D9[state.depthFunc]; + return &result.first->second; +} + +DeviceStencilState* GfxDeviceD3D9::CreateStencilState(const GfxStencilState& state) +{ + std::pair<CachedStencilStates::iterator, bool> result = m_CachedStencilStates.insert(std::make_pair(state, DeviceStencilStateD3D9())); + if (!result.second) + return &result.first->second; + + DeviceStencilStateD3D9& st = result.first->second; + memcpy(&st.sourceState, &state, sizeof(state)); + st.stencilFuncFront = kCmpFuncD3D9[state.stencilFuncFront]; + st.stencilFailOpFront = kStencilOpD3D9[state.stencilFailOpFront]; + st.depthFailOpFront = kStencilOpD3D9[state.stencilZFailOpFront]; + st.depthPassOpFront = kStencilOpD3D9[state.stencilPassOpFront]; + st.stencilFuncBack = kCmpFuncD3D9[state.stencilFuncBack]; + st.stencilFailOpBack = kStencilOpD3D9[state.stencilFailOpBack]; + st.depthFailOpBack = kStencilOpD3D9[state.stencilZFailOpBack]; + st.depthPassOpBack = kStencilOpD3D9[state.stencilPassOpBack]; + return &result.first->second; +} + + + +DeviceRasterState* GfxDeviceD3D9::CreateRasterState(const GfxRasterState& state) +{ + std::pair<CachedRasterStates::iterator, bool> result = m_CachedRasterStates.insert(std::make_pair(state, DeviceRasterState())); + if (!result.second) + return &result.first->second; + + DeviceRasterState& d3dstate = result.first->second; + memcpy(&d3dstate.sourceState, &state, sizeof(DeviceRasterState)); + + return &result.first->second; +} + + +void GfxDeviceD3D9::SetBlendState(const DeviceBlendState* state, float alphaRef) +{ + DeviceBlendStateD3D9* devstate = (DeviceBlendStateD3D9*)state; + + if (m_CurrBlendState == devstate && alphaRef == m_State.alphaValue) + return; + + m_CurrBlendState = devstate; + if (!m_CurrBlendState) + return; + + UInt32 colMask = devstate->renderTargetWriteMask; + if (!IsActiveRenderTargetWithColorD3D9()) + colMask = 0; + + if(colMask != m_State.colorWriteMask) + { + IDirect3DDevice9* dev = GetD3DDeviceNoAssert(); + D3D9_CALL(dev->SetRenderState(D3DRS_COLORWRITEENABLE, colMask)); + m_State.colorWriteMask = colMask; + } + + const GfxBlendState& desc = state->sourceState; + const CompareFunction mode = state->sourceState.alphaTest; + const D3DBLEND d3dsrc = kBlendModeD3D9[desc.srcBlend]; + const D3DBLEND d3ddst = kBlendModeD3D9[desc.dstBlend]; + const D3DBLEND d3dsrca = kBlendModeD3D9[desc.srcBlendAlpha]; + const D3DBLEND d3ddsta = kBlendModeD3D9[desc.dstBlendAlpha]; + const D3DBLENDOP d3dop = kBlendOpD3D9[desc.blendOp]; + const D3DBLENDOP d3dopa = kBlendOpD3D9[desc.blendOpAlpha]; + + const bool blendDisabled = (d3dsrc == D3DBLEND_ONE && d3ddst == D3DBLEND_ZERO && d3dsrca == D3DBLEND_ONE && d3ddsta == D3DBLEND_ZERO); + + IDirect3DDevice9* dev = GetD3DDevice(); + if(blendDisabled) + { + if( m_State.blending != 0 ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE )); + m_State.blending = 0; + } + } + else + { + if( d3dsrc != m_State.srcBlend || d3ddst != m_State.destBlend ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_SRCBLEND, d3dsrc )); + D3D9_CALL(dev->SetRenderState( D3DRS_DESTBLEND, d3ddst )); + m_State.srcBlend = d3dsrc; + m_State.destBlend = d3ddst; + } + + if (d3dop != m_State.blendOp) + { + bool supports = true; + if( (d3dop == D3DBLENDOP_SUBTRACT || d3dop == D3DBLENDOP_REVSUBTRACT) && !gGraphicsCaps.hasBlendSub ) + supports = false; + if( (d3dop == D3DBLENDOP_MIN || d3dop == D3DBLENDOP_MAX) && !gGraphicsCaps.hasBlendMinMax ) + supports = false; + + if(supports) + { + D3D9_CALL(dev->SetRenderState(D3DRS_BLENDOP, d3dop)); + m_State.blendOp = d3dop; + } + } + if (gGraphicsCaps.hasSeparateAlphaBlend) + { + if( d3dsrca != m_State.srcBlendAlpha || d3ddsta != m_State.destBlendAlpha || d3dopa != m_State.blendOpAlpha ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_SEPARATEALPHABLENDENABLE, d3dsrc != d3dsrca || d3ddst != d3ddsta || d3dopa != d3dop)); + D3D9_CALL(dev->SetRenderState( D3DRS_SRCBLENDALPHA, d3dsrca )); + D3D9_CALL(dev->SetRenderState( D3DRS_DESTBLENDALPHA, d3ddsta )); + m_State.srcBlendAlpha = d3dsrca; + m_State.destBlendAlpha = d3ddsta; + + bool supports = true; + if( (d3dopa == D3DBLENDOP_SUBTRACT || d3dopa == D3DBLENDOP_REVSUBTRACT) && !gGraphicsCaps.hasBlendSub ) + supports = false; + if( (d3dopa == D3DBLENDOP_MIN || d3dopa == D3DBLENDOP_MAX) && !gGraphicsCaps.hasBlendMinMax ) + supports = false; + + if (supports) + { + D3D9_CALL(dev->SetRenderState(D3DRS_BLENDOPALPHA, d3dopa)); + m_State.blendOpAlpha = d3dopa; + } + } + } + if( m_State.blending != 1 ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE )); + m_State.blending = 1; + } + } + + DebugAssertIf(mode==kFuncUnknown); +#if UNITY_EDITOR // gles2.0 doesn't have FF alpha testing(only discard/clip on shader side), so disable on editor while emulating + bool skipAlphaTestFF = (gGraphicsCaps.IsEmulatingGLES20() && IsShaderActive(kShaderFragment)); + // possible that vertex shader will be used with FF "frag shader" (like Transparent/vertexlit.shader), + // which will change alphatesting. So later on when real frag shaders come, we need to force disable alpha + // testing or enjoy nasty artefacts (like active alpha testing messing up the whole scene). + if ( skipAlphaTestFF && m_State.alphaFunc!=kFuncDisabled ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE )); + m_State.alphaFunc = kFuncDisabled; + } + + if ( !skipAlphaTestFF ) + { +#endif + if( mode != m_State.alphaFunc || alphaRef != m_State.alphaValue ) + { + if( mode != kFuncDisabled ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE )); + D3D9_CALL(dev->SetRenderState( D3DRS_ALPHAFUNC, kCmpFuncD3D9[mode] )); + D3D9_CALL(dev->SetRenderState( D3DRS_ALPHAREF, alphaRef * 255.0f )); + } + else + { + D3D9_CALL(dev->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE )); + } + + m_State.alphaFunc = mode; + m_State.alphaValue = alphaRef; + } +#if UNITY_EDITOR + } +#endif + // TODO: ATI/NVIDIA hacks +} + + +void GfxDeviceD3D9::SetRasterState(const DeviceRasterState* state) +{ + DeviceRasterState* devstate = (DeviceRasterState*)state; + if(!devstate) + { + m_CurrRasterState = NULL; + return; + } + + m_CurrRasterState = devstate; + + IDirect3DDevice9* dev = GetD3DDeviceNoAssert(); + CullMode cull = devstate->sourceState.cullMode; + D3DCULL d3dcull = kCullModeD3D9[cull]; + if( d3dcull != m_State.d3dculling ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_CULLMODE, d3dcull )); + m_State.culling = cull; + m_State.d3dculling = d3dcull; + } + + float zFactor = devstate->sourceState.slopeScaledDepthBias; + float zUnits = devstate->sourceState.depthBias; + if( zFactor != m_State.offsetFactor || zUnits != m_State.offsetUnits ) + { + m_State.offsetFactor = zFactor; + m_State.offsetUnits = zUnits; + + // In D3D9 the values are in floating point, with 1 meaning "full depth range". + // In theory the offset should depend on depth buffer bit count, and on 24 bit depth buffer a value close to 4.8e-7 should be used + // (see Lengyel's GDC2007 "projection matrix tricks"). + // However, it looks like even on 16 bit depth buffer, a value as-if-24-bit should be used (tested on Radeon HD 3850, GeForce 8600, Intel 945). + const double kOneBit = 4.8e-7; + + // It looks like generally we need twice the one bit (PolygonOff2 unit test, on Radeon 3850 and GeForce 8600). + // To be somewhat more safer, we make it trhee times the one bit. Still looks quite okay. + const float kBiasMultiplier = 3.0 * kOneBit; + + if( gGraphicsCaps.d3d.d3dcaps.RasterCaps & D3DPRASTERCAPS_DEPTHBIAS ) + { + zUnits *= kBiasMultiplier; + D3D9_CALL(dev->SetRenderState( D3DRS_DEPTHBIAS, *(DWORD*)&zUnits )); + } + if( gGraphicsCaps.d3d.d3dcaps.RasterCaps & D3DPRASTERCAPS_SLOPESCALEDEPTHBIAS ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_SLOPESCALEDEPTHBIAS, *(DWORD*)&zFactor )); + } + } +} + + +void GfxDeviceD3D9::SetDepthState(const DeviceDepthState* state) +{ + IDirect3DDevice9* dev = GetD3DDeviceNoAssert(); + DeviceDepthStateD3D9* devstate = (DeviceDepthStateD3D9*)state; + if (m_CurrDepthState == devstate) + return; + + m_CurrDepthState = devstate; + + if (!m_CurrDepthState) + return; + + if( devstate->sourceState.depthFunc != m_State.depthFunc ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_ZFUNC, devstate->depthFunc )); + m_State.depthFunc = devstate->sourceState.depthFunc; + } + + int d3dDepthWriteMode = devstate->sourceState.depthWrite ? TRUE : FALSE; + if( d3dDepthWriteMode != m_State.depthWrite ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_ZWRITEENABLE, d3dDepthWriteMode )); + m_State.depthWrite = d3dDepthWriteMode; + } +} + +void GfxDeviceD3D9::SetStencilState(const DeviceStencilState* state, int stencilRef) +{ + if (m_CurrStencilState == state && m_State.m_StencilRef == stencilRef) + return; + const DeviceStencilStateD3D9* st = static_cast<const DeviceStencilStateD3D9*>(state); + m_CurrStencilState = st; + if (!m_CurrStencilState) + return; + + IDirect3DDevice9* dev = GetD3DDevice(); + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILENABLE, st->sourceState.stencilEnable)); + D3D9_CALL (dev->SetRenderState (D3DRS_TWOSIDEDSTENCILMODE, TRUE)); + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILMASK, st->sourceState.readMask)); + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILWRITEMASK, st->sourceState.writeMask)); + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILREF, stencilRef)); + + m_State.stencilFunc[0] = st->stencilFuncFront; + m_State.stencilFailOp[0] = st->stencilFailOpFront; + m_State.depthFailOp[0] = st->depthFailOpFront; + m_State.depthPassOp[0] = st->depthPassOpFront; + m_State.stencilFunc[1] = st->stencilFuncBack; + m_State.stencilFailOp[1] = st->stencilFailOpBack; + m_State.depthFailOp[1] = st->depthFailOpBack; + m_State.depthPassOp[1] = st->depthPassOpBack; + ApplyStencilFuncAndOp(m_State); + + m_State.m_StencilRef = stencilRef; +} + +static void ApplyStencilFuncAndOp (DeviceStateD3D& state) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + // Normally [0] is front and [1] back stencil state, but when rendering + // upside-down, the winding order flips, so flip the state as well. + const int cw = state.invertProjMatrix ? 1 : 0; + const int ccw = (cw + 1)%2; + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILFUNC, state.stencilFunc[cw])); + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILFAIL, state.stencilFailOp[cw])); + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILZFAIL, state.depthFailOp[cw])); + D3D9_CALL (dev->SetRenderState (D3DRS_STENCILPASS, state.depthPassOp[cw])); + D3D9_CALL (dev->SetRenderState (D3DRS_CCW_STENCILFUNC, state.stencilFunc[ccw])); + D3D9_CALL (dev->SetRenderState (D3DRS_CCW_STENCILFAIL, state.stencilFailOp[ccw])); + D3D9_CALL (dev->SetRenderState (D3DRS_CCW_STENCILZFAIL, state.depthFailOp[ccw])); + D3D9_CALL (dev->SetRenderState (D3DRS_CCW_STENCILPASS, state.depthPassOp[ccw])); +} + +void GfxDeviceD3D9::SetSRGBWrite (bool enable) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + D3D9_CALL (dev->SetRenderState (D3DRS_SRGBWRITEENABLE, enable)); +} + +bool GfxDeviceD3D9::GetSRGBWrite () +{ + IDirect3DDevice9* dev = GetD3DDevice(); + DWORD v; + D3D9_CALL (dev->GetRenderState (D3DRS_SRGBWRITEENABLE, &v)); + return (v==TRUE); +} + +GfxThreadableDevice* CreateD3D9GfxDevice(bool forceREF) +{ + if( !InitializeD3D(forceREF ? D3DDEVTYPE_REF : D3DDEVTYPE_HAL) ) + return NULL; + + #if UNITY_EDITOR + if (!CreateHiddenWindowD3D()) + return NULL; + #endif + + gGraphicsCaps.InitD3D9(); + + GfxDeviceD3D9* device = UNITY_NEW_AS_ROOT(GfxDeviceD3D9(), kMemGfxDevice, "D3D9GfxDevice", ""); + +#if UNITY_EDITOR + EditorInitializeD3D(device); +#else + ScreenManagerWin& screenMgr = GetScreenManager(); + HWND window = screenMgr.GetWindow(); + int width = screenMgr.GetWidth(); + int height = screenMgr.GetHeight(); + int dummy; + if (!InitializeOrResetD3DDevice(device, window, width, height, 0, false, 0, 0, dummy, dummy, dummy, dummy)) + { + UNITY_DELETE(device, kMemGfxDevice); + device = NULL; + } +#endif + + return device; +} + +GfxDeviceD3D9& GetD3D9GfxDevice() +{ + GfxDevice& device = GetRealGfxDevice(); + Assert( device.GetRenderer() == kGfxRendererD3D9 ); + return static_cast<GfxDeviceD3D9&>(device); +} + +bool IsD3D9DeviceLost() +{ + GfxDeviceD3D9& device = static_cast<GfxDeviceD3D9&>( GetRealGfxDevice() ); + AssertIf( device.GetRenderer() != kGfxRendererD3D9 ); + return device.GetState().m_DeviceLost; +} + +void SetD3D9DeviceLost( bool lost ) +{ + GfxDeviceD3D9& device = static_cast<GfxDeviceD3D9&>( GetRealGfxDevice() ); + AssertIf( device.GetRenderer() != kGfxRendererD3D9 ); + device.GetState().m_DeviceLost = lost; +} + + +GfxDeviceD3D9::GfxDeviceD3D9() +{ + m_State.m_DeviceLost = false; + m_DynamicVBO = NULL; + + m_State.appBackfaceMode = false; + m_State.userBackfaceMode = false; + m_State.invertProjMatrix = false; + m_State.wireframe = false; + + InvalidateState(); + ResetFrameStats(); + + m_Renderer = kGfxRendererD3D9; + m_UsesOpenGLTextureCoords = false; + m_UsesHalfTexelOffset = true; + m_IsThreadable = true; + + m_MaxBufferedFrames = 1; // -1 means no limiting, default is 1 + + m_State.viewport[0] = m_State.viewport[1] = m_State.viewport[2] = m_State.viewport[3] = 0; + m_State.scissorRect[0] = m_State.scissorRect[1] = m_State.scissorRect[2] = m_State.scissorRect[3] = 0; + + m_CurrBlendState = 0; + m_CurrDepthState = 0; + m_CurrStencilState = 0; + m_CurrRasterState = 0; + m_CurrTargetWidth = 0; + m_CurrTargetHeight = 0; + m_CurrWindowWidth = 0; + m_CurrWindowHeight = 0; + + m_AllWhiteVertexStream = NULL; + + extern RenderSurfaceBase* DummyColorBackBuferD3D9(); + SetBackBufferColorSurface(DummyColorBackBuferD3D9()); + + extern RenderSurfaceBase* DummyDepthBackBuferD3D9(); + SetBackBufferDepthSurface(DummyDepthBackBuferD3D9()); +} + +GfxDeviceD3D9::~GfxDeviceD3D9() +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_WORKER + PluginsSetGraphicsDevice (GetD3DDevice(), kGfxRendererD3D9, kGfxDeviceEventShutdown); +#endif + + D3D9VBO::CleanupSharedIndexBuffer(); + + CleanupEventQueries (); +#if ENABLE_PROFILER + m_TimerQueriesD3D9.ReleaseAllQueries(); +#endif + + if( m_DynamicVBO ) + delete m_DynamicVBO; + + SAFE_RELEASE(m_AllWhiteVertexStream); + SAFE_RELEASE(m_Imm.m_ImmVertexDecl); + m_VertexDecls.Clear(); + TextureCombinersD3D::CleanupCombinerCache(); + CleanupVertexShadersD3D9 (); + DestroyD3DDevice(); + + #if UNITY_EDITOR + DestroyHiddenWindowD3D(); + #endif + + CleanupD3D(); +} + +void GfxDeviceD3D9::InvalidateState() +{ + IDirect3DDevice9* dev = GetD3DDeviceNoAssert(); + if( m_State.m_DeviceLost ) + dev = NULL; + + ResetVertexPipeStateD3D9 (dev, m_TransformState, m_BuiltinParamValues, m_VertexConfig, m_VertexData, m_VertexPrevious); + m_FogParams.Invalidate(); + m_State.Invalidate(*this); + m_Imm.Invalidate(); + m_VSConstantCache.Invalidate(); + m_PSConstantCache.Invalidate(); + + m_CurrBlendState = NULL; + m_CurrDepthState = NULL; + m_CurrStencilState = NULL; + m_CurrRasterState = NULL; +} + + +void GfxDeviceD3D9::Clear(UInt32 clearFlags, const float color[4], float depth, int stencil) +{ + if( !g_D3DHasDepthStencil ) + clearFlags &= ~kGfxClearDepthStencil; + if (!IsActiveRenderTargetWithColorD3D9()) + clearFlags &= ~kGfxClearColor; + + DWORD flags = 0; + if (clearFlags & kGfxClearColor) flags |= D3DCLEAR_TARGET; + if (clearFlags & kGfxClearDepth) flags |= D3DCLEAR_ZBUFFER; + if (clearFlags & kGfxClearStencil && GetStencilBitsFromD3DFormat (g_D3DDepthStencilFormat) > 0) { + flags |= D3DCLEAR_STENCIL; + } + GetD3DDevice()->Clear (0, NULL, flags, ColorToD3D(color), depth, stencil); +} + + +static void ApplyBackfaceMode( DeviceStateD3D& state ) +{ + if( (state.appBackfaceMode == state.userBackfaceMode) == state.invertProjMatrix ) + { + kCullModeD3D9[kCullFront] = D3DCULL_CCW; + kCullModeD3D9[kCullBack] = D3DCULL_CW; + } + else + { + kCullModeD3D9[kCullFront] = D3DCULL_CW; + kCullModeD3D9[kCullBack] = D3DCULL_CCW; + } + + if( state.culling != kCullUnknown ) + { + IDirect3DDevice9* dev = GetD3DDevice(); + D3DCULL d3dcull = kCullModeD3D9[state.culling]; + if( d3dcull != state.d3dculling ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_CULLMODE, d3dcull )); + state.d3dculling = d3dcull; + } + } +} + +void GfxDeviceD3D9::SetUserBackfaceMode( bool enable ) +{ + if( m_State.userBackfaceMode == enable ) + return; + m_State.userBackfaceMode = enable; + ApplyBackfaceMode( m_State ); +} + + +void GfxDeviceD3D9::SetWireframe( bool wire ) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + D3D9_CALL(dev->SetRenderState( D3DRS_FILLMODE, wire ? D3DFILL_WIREFRAME : D3DFILL_SOLID )); + m_State.wireframe = wire; +} + +bool GfxDeviceD3D9::GetWireframe() const +{ + return m_State.wireframe; +} + + + +// Even with programmable shaders, some things need fixed function D3DTS_PROJECTION to be set up; +// most notably fixed function fog (shader model 2.0). +static void SetFFProjectionMatrixD3D9 (const Matrix4x4f& m) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + Matrix4x4f projFlip; + projFlip.m_Data[ 0] = m.m_Data[ 0]; + projFlip.m_Data[ 1] = m.m_Data[ 1]; + projFlip.m_Data[ 2] = m.m_Data[ 2]; + projFlip.m_Data[ 3] = m.m_Data[ 3]; + projFlip.m_Data[ 4] = m.m_Data[ 4]; + projFlip.m_Data[ 5] = m.m_Data[ 5]; + projFlip.m_Data[ 6] = m.m_Data[ 6]; + projFlip.m_Data[ 7] = m.m_Data[ 7]; + projFlip.m_Data[ 8] = -m.m_Data[ 8]; + projFlip.m_Data[ 9] = -m.m_Data[ 9]; + projFlip.m_Data[10] = -m.m_Data[10]; + projFlip.m_Data[11] = -m.m_Data[11]; + projFlip.m_Data[12] = m.m_Data[12]; + projFlip.m_Data[13] = m.m_Data[13]; + projFlip.m_Data[14] = m.m_Data[14]; + projFlip.m_Data[15] = m.m_Data[15]; + D3D9_CALL(dev->SetTransform (D3DTS_PROJECTION, (const D3DMATRIX*)projFlip.GetPtr())); +} + + +void GfxDeviceD3D9::SetInvertProjectionMatrix( bool enable ) +{ + if( m_State.invertProjMatrix == enable ) + return; + + m_State.invertProjMatrix = enable; + ApplyBackfaceMode( m_State ); + ApplyStencilFuncAndOp( m_State ); + + // When setting up "invert" flag, invert the matrix as well. + Matrix4x4f& m = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj); + m.Get(1,1) = -m.Get(1,1); + m.Get(1,3) = -m.Get(1,3); + m_TransformState.dirtyFlags |= TransformState::kProjDirty; + SetFFProjectionMatrixD3D9 (m); +} + +bool GfxDeviceD3D9::GetInvertProjectionMatrix() const +{ + return m_State.invertProjMatrix; +} + +void GfxDeviceD3D9::SetWorldMatrix( const float matrix[16] ) +{ + CopyMatrix (matrix, m_TransformState.worldMatrix.GetPtr()); + m_TransformState.dirtyFlags |= TransformState::kWorldDirty; +} + +void GfxDeviceD3D9::SetViewMatrix( const float matrix[16] ) +{ + m_TransformState.SetViewMatrix (matrix, m_BuiltinParamValues); +} + +void GfxDeviceD3D9::SetProjectionMatrix(const Matrix4x4f& matrix) +{ + Matrix4x4f& m = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj); + CopyMatrix (matrix.GetPtr(), m.GetPtr()); + CopyMatrix (matrix.GetPtr(), m_TransformState.projectionMatrixOriginal.GetPtr()); + + CalculateDeviceProjectionMatrix (m, m_UsesOpenGLTextureCoords, m_State.invertProjMatrix); + SetFFProjectionMatrixD3D9 (m); + + m_TransformState.dirtyFlags |= TransformState::kProjDirty; +} + + +void GfxDeviceD3D9::GetMatrix(float outMatrix[16]) const +{ + m_TransformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + CopyMatrix (m_TransformState.worldViewMatrix.GetPtr(), outMatrix); +} + +const float* GfxDeviceD3D9::GetWorldMatrix() const +{ + return m_TransformState.worldMatrix.GetPtr(); +} + +const float* GfxDeviceD3D9::GetViewMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatView).GetPtr(); +} + +const float* GfxDeviceD3D9::GetProjectionMatrix() const +{ + return m_TransformState.projectionMatrixOriginal.GetPtr(); +} + +const float* GfxDeviceD3D9::GetDeviceProjectionMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatProj).GetPtr(); +} + +void GfxDeviceD3D9::SetNormalizationBackface( NormalizationMode mode, bool backface ) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + if( mode != m_VertexData.normalization ) + { + m_VertexData.normalization = mode; + m_VertexConfig.hasNormalization = (mode == kNormalizationFull); + } + if( m_State.appBackfaceMode != backface ) + { + m_State.appBackfaceMode = backface; + ApplyBackfaceMode( m_State ); + } +} + +void GfxDeviceD3D9::SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) +{ + m_VertexConfig.hasLighting = on ? 1 : 0; + m_VertexConfig.hasSpecular = separateSpecular ? 1 : 0; + DebugAssertIf(colorMaterial==kColorMatUnknown); + m_VertexConfig.colorMaterial = colorMaterial; +} + +void GfxDeviceD3D9::SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) +{ + D3DMATERIAL9& mat = m_VertexData.material; + mat.Ambient = *(D3DCOLORVALUE*)ambient; + mat.Diffuse = *(D3DCOLORVALUE*)diffuse; + mat.Specular = *(D3DCOLORVALUE*)specular; + mat.Emissive = *(D3DCOLORVALUE*)emissive; + mat.Power = std::max<float>( std::min<float>(shininess,1.0f), 0.0f) * 128.0f; +} + + +void GfxDeviceD3D9::SetColor( const float color[4] ) +{ + // If we have pixel shader set up, do nothing; fixed function + // constant color can't be possibly used there + if (m_State.activeShader[kShaderFragment] != 0) // inlined IsShaderActive(kShaderFragment) + return; + + // There's no really good place to make a glColor equivalent, put it into + // TFACTOR... Additionally put that into c4 register for ps_1_1 combiner emulation + IDirect3DDevice9* dev = GetD3DDevice(); + D3D9_CALL(dev->SetRenderState( D3DRS_TEXTUREFACTOR, ColorToD3D(color) )); + m_PSConstantCache.SetValues( kMaxD3DTextureStagesForPS, color, 1 ); +} + + +void GfxDeviceD3D9::SetViewport( int x, int y, int width, int height ) +{ + m_State.viewport[0] = x; + m_State.viewport[1] = y; + m_State.viewport[2] = width; + m_State.viewport[3] = height; + + IDirect3DDevice9* dev = GetD3DDeviceNoAssert(); + if( !dev ) // happens on startup, when deleting all render textures + return; + D3DVIEWPORT9 view; + view.X = x; + view.Y = y; + view.Width = width; + view.Height = height; + view.MinZ = 0.0f; + view.MaxZ = 1.0f; + dev->SetViewport( &view ); +} + +void GfxDeviceD3D9::GetViewport( int* port ) const +{ + port[0] = m_State.viewport[0]; + port[1] = m_State.viewport[1]; + port[2] = m_State.viewport[2]; + port[3] = m_State.viewport[3]; +} + + +void GfxDeviceD3D9::SetScissorRect( int x, int y, int width, int height ) +{ + if (m_State.scissor != 1) + { + if (gGraphicsCaps.d3d.d3dcaps.RasterCaps & D3DPRASTERCAPS_SCISSORTEST ) + { + GetD3DDevice()->SetRenderState( D3DRS_SCISSORTESTENABLE, TRUE ); + } + m_State.scissor = 1; + } + + + m_State.scissorRect[0] = x; + m_State.scissorRect[1] = y; + m_State.scissorRect[2] = width; + m_State.scissorRect[3] = height; + + RECT rc; + rc.left = x; + rc.top = y; + rc.right = x + width; + rc.bottom = y + height; + GetD3DDevice()->SetScissorRect( &rc ); + +} +void GfxDeviceD3D9::DisableScissor() +{ + if (m_State.scissor != 0) + { + if( gGraphicsCaps.d3d.d3dcaps.RasterCaps & D3DPRASTERCAPS_SCISSORTEST ) + { + GetD3DDevice()->SetRenderState( D3DRS_SCISSORTESTENABLE, FALSE); + } + m_State.scissor = 0; + } +} +bool GfxDeviceD3D9::IsScissorEnabled() const +{ + return m_State.scissor == 1; +} + +void GfxDeviceD3D9::GetScissorRect( int scissor[4] ) const +{ + scissor[0] = m_State.scissorRect[0]; + scissor[1] = m_State.scissorRect[1]; + scissor[2] = m_State.scissorRect[2]; + scissor[3] = m_State.scissorRect[3]; +} + +bool GfxDeviceD3D9::IsCombineModeSupported( unsigned int combiner ) +{ + return true; +} + +TextureCombinersHandle GfxDeviceD3D9::CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) +{ + TextureCombinersD3D* implD3D = TextureCombinersD3D::Create( count, texEnvs, props, hasVertexColorOrLighting, usesAddSpecular ); + return TextureCombinersHandle( implD3D ); +} + +void GfxDeviceD3D9::DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ) +{ + TextureCombinersD3D* implD3D = OBJECT_FROM_HANDLE(textureCombiners, TextureCombinersD3D); + delete implD3D; + textureCombiners.Reset(); +} + +void GfxDeviceD3D9::SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ) +{ + TextureCombinersD3D* implD3D = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersD3D); + AssertIf( !implD3D ); + IDirect3DDevice9* dev = GetD3DDevice(); + + AssertIf (IsShaderActive( kShaderFragment )); + + const int maxTexUnits = gGraphicsCaps.maxTexUnits; // fetch here once + + // set textures + int i = 0; + for( ; i < maxTexUnits && i < implD3D->envCount; ++i ) + { + ApplyTexEnvData (i, i, texEnvData[i]); + } + + // clear unused textures + for (; i < maxTexUnits; ++i) + { + if (i < kMaxSupportedTextureCoords) + m_VertexConfig.ClearTextureUnit(i); + + TextureUnitStateD3D& currTex = m_State.texturesPS[i]; + if (currTex.texID.m_ID != 0) + { + D3D9_CALL(dev->SetTexture( GetD3D9SamplerIndex(kShaderFragment,i), NULL )); + currTex.texID.m_ID = 0; + } + } + + // setup texture stages + if( implD3D->pixelShader ) + { + for( i = 0; i < implD3D->stageCount; ++i ) + { + const ShaderLab::TextureBinding& binding = implD3D->texEnvs[i]; + const Vector4f& texcolorVal = texColors[i]; + m_PSConstantCache.SetValues( i, texcolorVal.GetPtr(), 1 ); + } + if( m_State.fixedFunctionPS != implD3D->uniqueID ) + { + D3D9_CALL(dev->SetPixelShader( implD3D->pixelShader )); + m_State.fixedFunctionPS = implD3D->uniqueID; + } + } + else + { + if( implD3D->textureFactorIndex != -1 ) + { + const Vector4f& color = texColors[implD3D->textureFactorIndex]; + D3D9_CALL(dev->SetRenderState( D3DRS_TEXTUREFACTOR, ColorToD3D( color.GetPtr() ) )); + } + for( i = 0; i < implD3D->stageCount; ++i ) + { + // TODO: cache! + const D3DTextureStage& stage = implD3D->stages[i]; + AssertIf( stage.colorOp == D3DTOP_DISABLE || stage.alphaOp == D3DTOP_DISABLE ); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_COLOROP, stage.colorOp )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_COLORARG1, stage.colorArgs[0] )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_COLORARG2, stage.colorArgs[1] )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_COLORARG0, stage.colorArgs[2] )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_ALPHAOP, stage.alphaOp )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_ALPHAARG1, stage.alphaArgs[0] )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_ALPHAARG2, stage.alphaArgs[1] )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_ALPHAARG0, stage.alphaArgs[2] )); + } + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_COLOROP, D3DTOP_DISABLE )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_ALPHAOP, D3DTOP_DISABLE )); + D3D9_CALL(dev->SetPixelShader( NULL )); + m_State.fixedFunctionPS = 0; + } +} + + +void GfxDeviceD3D9::SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ) +{ + TextureCombinersD3D* implD3D = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersD3D); + AssertIf( !implD3D ); + + int count = std::min(implD3D->envCount, gGraphicsCaps.maxTexUnits); + + // Fill in arrays + TexEnvData* texEnvData; + ALLOC_TEMP (texEnvData, TexEnvData, count); + for( int i = 0; i < count; ++i ) + { + ShaderLab::TexEnv *te = ShaderLab::GetTexEnvForBinding( implD3D->texEnvs[i], props ); + Assert( te != NULL ); + te->PrepareData (implD3D->texEnvs[i].m_TextureName.index, implD3D->texEnvs[i].m_MatrixName, props, &texEnvData[i]); + } + + Vector4f* texColors; + ALLOC_TEMP (texColors, Vector4f, implD3D->envCount); + for( int i = 0; i < implD3D->envCount; ++i ) + { + const ShaderLab::TextureBinding& binding = implD3D->texEnvs[i]; + texColors[i] = binding.GetTexColor().Get (props); + } + GfxDeviceD3D9::SetTextureCombinersThreadable(textureCombiners, texEnvData, texColors); +} + + +void GfxDeviceD3D9::SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) +{ + DebugAssertIf( dim < kTexDim2D || dim > kTexDimCUBE ); + DebugAssertIf (unit < 0 || unit >= kMaxSupportedTextureUnits); + + if (unit < kMaxSupportedTextureCoords) + m_VertexConfig.SetTextureUnit(unit); + + TextureUnitStateD3D* currTex = NULL; + if (shaderType == kShaderFragment) + currTex = &m_State.texturesPS[unit]; + else if (shaderType == kShaderVertex) + currTex = &m_State.texturesVS[unit]; + else + { + AssertString ("Unsupported shader type for SetTexture"); + return; + } + + if (texture != currTex->texID) + { + if (m_Textures.SetTexture (shaderType, unit, texture)) + currTex->texID = texture; + } + m_Stats.AddUsedTexture(texture); + if (gGraphicsCaps.hasMipLevelBias && bias != currTex->bias && shaderType == kShaderFragment) + { + D3D9_CALL(GetD3DDevice()->SetSamplerState( unit, D3DSAMP_MIPMAPLODBIAS, *(DWORD*)&bias )); + currTex->bias = bias; + } +} + + + +void GfxDeviceD3D9::SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16] ) +{ + Assert (unit >= 0 && unit < kMaxSupportedTextureCoords); + + m_State.m_NeedsSofwareVPFlags &= ~kNeedsSoftwareVPTexGen; + + // -------- texture matrix + + float* mat = m_TransformState.texMatrices[unit].GetPtr(); + CopyMatrix( matrix, mat ); + + // In OpenGL all texture reads are projective, and matrices are always 4x4, and z/w defaults to 0/1. + // In D3D everything is different. So here we try to figure out how many components need to be transformed, + // munge the matrix and enable projective texturing if needed. + + TextureMatrixMode matrixMode; + int projectedTexture = 0; + if( identity ) + { + // matrix guaranteed to be identity: disable transformation + matrixMode = kTexMatrixNone; + } + else if( dim == kTexDimCUBE || dim == kTexDim3D ) + { + // for cube/volume texture: count3 + matrixMode = kTexMatrix3; + } + else + { + // detect projected matrix + projectedTexture = (mat[3] != 0.0f || mat[7] != 0.0f || mat[11] != 0.0f || mat[15] != 1.0f) ? 1 : 0; + // Cards that do support projected textures or cubemaps seem to want + // Count3 flags for object/eyelinear transforms. Cards that don't support + // projection nor cubemaps will have to use Count2 - fixes GUI text rendering! + bool is3DTexGen = (texGen != kTexGenDisabled && texGen != kTexGenSphereMap); + + if( projectedTexture ) + { + matrixMode = kTexMatrix4; + } + else if( is3DTexGen ) + { + matrixMode = kTexMatrix3; + } + else + { + // regular texture: count2, and move matrix' 4th row into 3rd one + matrixMode = kTexMatrix2; + mat[ 8] = mat[12]; + mat[ 9] = mat[13]; + mat[10] = mat[14]; + mat[11] = mat[15]; + } + } + + m_VertexConfig.textureMatrixModes = m_VertexConfig.textureMatrixModes & ~(3<<(unit*2)) | (matrixMode<<(unit*2)); + m_VertexData.projectedTextures = m_VertexData.projectedTextures & ~(1<<unit) | (projectedTexture<<unit); + + // -------- texture coordinate generation + + TextureSourceMode texSource = texGen == kTexGenDisabled ? kTexSourceUV0 : static_cast<TextureSourceMode>(texGen + 1); + m_VertexConfig.textureSources = m_VertexConfig.textureSources & ~(7<<(unit*3)) | (texSource<<(unit*3)); + + if( texGen == kTexGenSphereMap && !IsShaderActive(kShaderVertex) ) + { + if( g_D3DUsesMixedVP && !(gGraphicsCaps.d3d.d3dcaps.VertexProcessingCaps & D3DVTXPCAPS_TEXGEN_SPHEREMAP) ) + m_State.m_NeedsSofwareVPFlags |= kNeedsSoftwareVPTexGen; + } +} + +void GfxDeviceD3D9::SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + m_Textures.SetTextureParams( texture, texDim, filter, wrap, anisoLevel, hasMipMap, colorSpace ); + + // we'll need to set texture sampler states, so invalidate current texture cache + // invalidate texture unit states that used this texture + for (int i = 0; i < ARRAY_SIZE(m_State.texturesPS); ++i) + { + TextureUnitStateD3D& currTex = m_State.texturesPS[i]; + if( currTex.texID == texture ) + currTex.Invalidate(); + } + for (int i = 0; i < ARRAY_SIZE(m_State.texturesVS); ++i) + { + TextureUnitStateD3D& currTex = m_State.texturesVS[i]; + if (currTex.texID == texture) + currTex.Invalidate(); + } +} + + +void GfxDeviceD3D9::SetShadersThreadable( GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]) +{ + GpuProgram* vertexProgram = programs[kShaderVertex]; + GpuProgram* fragmentProgram = programs[kShaderFragment]; + + IDirect3DDevice9* dev = GetD3DDevice(); + + // vertex shader + if( vertexProgram && vertexProgram->GetImplType() == kShaderImplVertex ) + { + // set the shader + bool resetToNoFog = false; + IDirect3DVertexShader9* shader = static_cast<D3D9VertexShader&>(*vertexProgram).GetShader(m_FogParams.mode, resetToNoFog); + // Note: get pixel shader to match actually used fog mode from VS. If VS was too complex + // to patch for fog, for example, then we want PS to not have fog as well. + if (resetToNoFog) + m_FogParams.mode = kFogDisabled; + DebugAssert (shader); + + if( m_State.activeShader[kShaderVertex] != shader ) + { + D3D9_CALL(dev->SetVertexShader( shader )); + if (m_State.activeShader[kShaderVertex] == NULL) + { + for( int i = 0; i < kMaxSupportedTextureCoords; ++i ) + { + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXCOORDINDEX, i )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTSS_TCI_PASSTHRU )); + } + } + + m_VertexPrevious.vertexShader = NULL; + m_VertexPrevious.ambient.set(-1,-1,-1,-1); + + m_State.activeShader[kShaderVertex] = shader; + } + + if( g_D3DUsesMixedVP ) + m_State.m_NeedsSofwareVPFlags |= kNeedsSoftwareVPVertexShader; + + m_BuiltinParamIndices[kShaderVertex] = ¶ms[kShaderVertex]->GetBuiltinParams(); + } + else + { + // clear the shader + DebugAssertIf( vertexProgram != 0 ); + if( m_State.activeShader[kShaderVertex] != 0 ) + { + D3D9_CALL(dev->SetVertexShader( NULL )); + m_State.activeShader[kShaderVertex] = 0; + } + + if( g_D3DUsesMixedVP ) + m_State.m_NeedsSofwareVPFlags &= ~kNeedsSoftwareVPVertexShader; + + m_BuiltinParamIndices[kShaderVertex] = &m_NullParamIndices; + } + + // pixel shader + if( fragmentProgram && fragmentProgram->GetImplType() == kShaderImplFragment ) + { + // set the shader + IDirect3DPixelShader9* shader = static_cast<D3D9PixelShader&>(*fragmentProgram).GetShader(m_FogParams.mode, *params[kShaderFragment]); + DebugAssert (shader); + + if( m_State.activeShader[kShaderFragment] != shader ) + { + D3D9_CALL(dev->SetPixelShader( shader )); + m_State.activeShader[kShaderFragment] = shader; + m_State.fixedFunctionPS = 0; + } + + m_BuiltinParamIndices[kShaderFragment] = ¶ms[kShaderFragment]->GetBuiltinParams(); + } + else + { + // clear the shader + DebugAssertIf( fragmentProgram != 0 ); + if( m_State.activeShader[kShaderFragment] != 0 ) + { + D3D9_CALL(dev->SetPixelShader( NULL )); + m_State.activeShader[kShaderFragment] = 0; + m_State.fixedFunctionPS = 0; + } + + m_BuiltinParamIndices[kShaderFragment] = &m_NullParamIndices; + } + + for (int pt = 0; pt < kShaderTypeCount; ++pt) + { + if (programs[pt]) + { + m_State.activeGpuProgramParams[pt] = params[pt]; + m_State.activeGpuProgram[pt] = programs[pt]; + programs[pt]->ApplyGpuProgram (*params[pt], paramsBuffer[pt]); + } + else + { + m_State.activeGpuProgramParams[pt] = NULL; + m_State.activeGpuProgram[pt] = NULL; + } + } +} + + +bool GfxDeviceD3D9::IsShaderActive( ShaderType type ) const +{ + return m_State.activeShader[type] != 0; +} + +void GfxDeviceD3D9::DestroySubProgram( ShaderLab::SubProgram* subprogram ) +{ + GpuProgram* program = &subprogram->GetGpuProgram(); + if (program->GetImplType() == kShaderImplVertex) + { + for (int i = 0; i < kFogModeCount; ++i) + { + IUnknown* shader = static_cast<D3D9VertexShader*>(program)->GetShaderAtFogIndex(static_cast<FogMode>(i)); + if (m_State.activeShader[kShaderVertex] == shader) + m_State.activeShader[kShaderVertex] = NULL; + } + } + else if (program->GetImplType() == kShaderImplFragment) + { + for (int i = 0; i < kFogModeCount; ++i) + { + IUnknown* shader = static_cast<D3D9PixelShader*>(program)->GetShaderAtFogIndex(static_cast<FogMode>(i)); + if (m_State.activeShader[kShaderFragment] == shader) + m_State.activeShader[kShaderFragment] = NULL; + } + } + delete subprogram; +} + +void GfxDeviceD3D9::DisableLights( int startLight ) +{ + m_VertexData.vertexLightCount = startLight; + + const Vector4f black(0.0F, 0.0F, 0.0F, 0.0F); + for (int i = startLight; i < gGraphicsCaps.maxLights; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + i), black); + } +} + +void GfxDeviceD3D9::SetLight( int light, const GfxVertexLight& data) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + DebugAssert(light >= 0 && light < kMaxSupportedVertexLights); + + DebugAssertIf( (data.position.w == 0.0f) != (data.type == kLightDirectional) ); // directional lights should have 0 in position.w + DebugAssertIf( (data.spotAngle != -1.0f) != (data.type == kLightSpot) ); // non-spot lights should have -1 in spot angle + + GfxVertexLight& dest = m_VertexData.lights[light]; + dest = data; + + const Matrix4x4f& viewMat = m_BuiltinParamValues.GetMatrixParam(kShaderMatView); + + if (data.type == kLightDirectional) + { + dest.position.Set(0.0f,0.0f,0.0f,0.0f); + Vector3f v = viewMat.MultiplyVector3((const Vector3f&)data.position); + dest.spotDirection.Set( v.x, v.y, v.z, 0.0f ); + } + else + { + Vector3f v = viewMat.MultiplyPoint3((const Vector3f&)data.position); + dest.position.Set( v.x, v.y, v.z, 1.0f ); + Vector3f d = viewMat.MultiplyVector3((const Vector3f&)data.spotDirection); + dest.spotDirection.Set( d.x, d.y, d.z, 0.0f ); + } + + SetupVertexLightParams (light, data); +} + +void GfxDeviceD3D9::SetAmbient( const float ambient[4] ) +{ + if( m_VertexData.ambient != ambient ) + { + m_VertexData.ambient.set( ambient ); + m_VertexData.ambientClamped.set( clamp01(ambient[0]), clamp01(ambient[1]), clamp01(ambient[2]), clamp01(ambient[3]) ); + m_BuiltinParamValues.SetVectorParam(kShaderVecLightModelAmbient, Vector4f(ambient)); + } +} + + +static D3DFOGMODE s_D3DFogModes[kFogModeCount] = { D3DFOG_NONE, D3DFOG_LINEAR, D3DFOG_EXP, D3DFOG_EXP2 }; + +void GfxDeviceD3D9::EnableFog(const GfxFogParams& fog) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + DebugAssertIf( fog.mode <= kFogDisabled ); + if( m_FogParams.mode != fog.mode ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_FOGTABLEMODE, s_D3DFogModes[fog.mode] )); // TODO: or maybe vertex fog? + D3D9_CALL(dev->SetRenderState( D3DRS_FOGENABLE, TRUE )); + m_FogParams.mode = fog.mode; + } + if( m_FogParams.start != fog.start ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_FOGSTART, *(DWORD*)&fog.start )); + m_FogParams.start = fog.start; + } + if( m_FogParams.end != fog.end ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_FOGEND, *(DWORD*)&fog.end )); + m_FogParams.end = fog.end; + } + if( m_FogParams.density != fog.density ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_FOGDENSITY, *(DWORD*)&fog.density )); + m_FogParams.density = fog.density; + } + if( m_FogParams.color != fog.color ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_FOGCOLOR, ColorToD3D(fog.color.GetPtr()) )); + m_FogParams.color = fog.color; + } +} + +void GfxDeviceD3D9::DisableFog() +{ + IDirect3DDevice9* dev = GetD3DDevice(); + if( m_FogParams.mode != kFogDisabled ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_FOGENABLE, FALSE )); + m_FogParams.mode = kFogDisabled; + } +} + +VBO* GfxDeviceD3D9::CreateVBO() +{ + VBO* vbo = new D3D9VBO(); + OnCreateVBO(vbo); + return vbo; +} + +void GfxDeviceD3D9::DeleteVBO( VBO* vbo ) +{ + OnDeleteVBO(vbo); + delete vbo; +} + +DynamicVBO& GfxDeviceD3D9::GetDynamicVBO() +{ + if( !m_DynamicVBO ) { + m_DynamicVBO = new DynamicD3D9VBO( 1024 * 1024, 65536 ); // initial 1 MiB VB, 64 KiB IB + } + return *m_DynamicVBO; +} + +IDirect3DVertexBuffer9* GfxDeviceD3D9::GetAllWhiteVertexStream() +{ + if( !m_AllWhiteVertexStream ) + { + int maxVerts = 0x10000; + int size = maxVerts * sizeof(D3DCOLOR); + HRESULT hr = GetD3DDevice()->CreateVertexBuffer( size, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &m_AllWhiteVertexStream, NULL ); + if( !SUCCEEDED(hr) ) + return NULL; + void* buffer; + hr = m_AllWhiteVertexStream->Lock( 0 , 0, &buffer, 0 ); + if( !SUCCEEDED(hr) ) + { + SAFE_RELEASE( m_AllWhiteVertexStream ); + return NULL; + } + D3DCOLOR* dest = (D3DCOLOR*)buffer; + for( int i = 0; i < maxVerts; i++ ) + dest[i] = D3DCOLOR_ARGB(255, 255, 255, 255); + m_AllWhiteVertexStream->Unlock(); + } + return m_AllWhiteVertexStream; +} + +void GfxDeviceD3D9::ResetDynamicResources() +{ + delete m_DynamicVBO; + m_DynamicVBO = NULL; + + CleanupEventQueries (); + ResetDynamicVBs (); + + #if ENABLE_PROFILER + m_TimerQueriesD3D9.ReleaseAllQueries(); + #endif + + D3D9VBO::CleanupSharedIndexBuffer(); +} + + +void ResetDynamicResourcesD3D9() +{ + AutoGfxDeviceAcquireThreadOwnership autoOwner; + GetD3D9GfxDevice().ResetDynamicResources(); +} + +IDirect3DVertexDeclaration9* GetD3DVertexDeclaration( UInt32 shaderChannelsMap ) +{ + ChannelInfoArray channels; + int offset = 0; + for (int i = 0; i < kShaderChannelCount; i++) + { + ChannelInfo& info = channels[i]; + if (shaderChannelsMap & (1 << i)) + { + info.stream = 0; + info.offset = offset; + info.format = VBO::GetDefaultChannelFormat( i ); + info.dimension = VBO::GetDefaultChannelDimension( i ); + offset += VBO::GetDefaultChannelByteSize( i ); +} + else + info.Reset(); + } + return GetD3D9GfxDevice().GetVertexDecls().GetVertexDecl( channels ); +} + +VertexShaderConstantCache& GetD3D9VertexShaderConstantCache() +{ + return GetD3D9GfxDevice().GetVertexShaderConstantCache(); +} + +PixelShaderConstantCache& GetD3D9PixelShaderConstantCache() +{ + return GetD3D9GfxDevice().GetPixelShaderConstantCache(); +} + + +// ---------- render textures + +RenderSurfaceHandle GfxDeviceD3D9::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) +{ + return CreateRenderColorSurfaceD3D9 (textureID, width, height, samples, dim, createFlags, format, m_Textures); +} +RenderSurfaceHandle GfxDeviceD3D9::CreateRenderDepthSurface(TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) +{ + return CreateRenderDepthSurfaceD3D9 (textureID, width, height, samples, depthFormat, createFlags, m_Textures); +} +void GfxDeviceD3D9::DestroyRenderSurface(RenderSurfaceHandle& rs) +{ + DestroyRenderSurfaceD3D9( rs, m_Textures ); +} +void GfxDeviceD3D9::SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face) +{ + bool isBackBuffer; + m_CurrTargetWidth = m_CurrWindowWidth; + m_CurrTargetHeight = m_CurrWindowHeight; + if (SetRenderTargetD3D9 (count, colorHandles, depthHandle, mipLevel, face, m_CurrTargetWidth, m_CurrTargetHeight, isBackBuffer)) + { + // changing render target might mean different color clear flags; so reset current state + m_CurrBlendState = NULL; + } +} +void GfxDeviceD3D9::ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle) +{ + Assert (gGraphicsCaps.d3d.hasDepthResolveRESZ); + + RenderSurfaceD3D9* depthSurf = reinterpret_cast<RenderSurfaceD3D9*>(depthHandle.object); + + IDirect3DDevice9* dev = GetD3DDevice(); + // Important: change point size render state to something else than RESZ + // before the dummy draw call; otherwise RESZ state set will be filtered out + // by non-PURE D3D device. + dev->SetRenderState (D3DRS_POINTSIZE, 0); + + // Bind destination as texture + SetTexture (kShaderFragment, 0, 0, depthSurf->textureID, kTexDim2D, 0.0f); + + // Dummy draw call + float dummy[3] = {0,0,0}; + dev->DrawPrimitiveUP (D3DPT_POINTLIST, 1, dummy, 12); + + // RESZ to trigger depth buffer copy + dev->SetRenderState (D3DRS_POINTSIZE, 0x7fa05000); +} + + +void GfxDeviceD3D9::ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) +{ + Assert (srcHandle.IsValid()); + Assert (dstHandle.IsValid()); + RenderColorSurfaceD3D9* src = reinterpret_cast<RenderColorSurfaceD3D9*>(srcHandle.object); + RenderColorSurfaceD3D9* dst = reinterpret_cast<RenderColorSurfaceD3D9*>(dstHandle.object); + if (!src->colorSurface || !dst->colorSurface) + { + WarningString("RenderTexture: Resolving non-color surfaces."); + return; + } + if (!src->m_Surface || !dst->m_Surface) + { + WarningString("RenderTexture: Resolving NULL surfaces."); + return; + } + if (src->dim != dst->dim) + { + WarningString("RenderTexture: Resolving surfaces of different types."); + return; + } + if (src->format != dst->format) + { + WarningString("RenderTexture: Resolving surfaces of different formats."); + return; + } + if (src->width != dst->width || src->height != dst->height) + { + WarningString("RenderTexture: Resolving surfaces of different sizes."); + return; + } + + IDirect3DDevice9* dev = GetD3DDevice(); + dev->StretchRect (src->m_Surface, NULL, dst->m_Surface, NULL, D3DTEXF_NONE); +} + +RenderSurfaceHandle GfxDeviceD3D9::GetActiveRenderColorSurface (int index) +{ + return GetActiveRenderColorSurfaceD3D9(index); +} +RenderSurfaceHandle GfxDeviceD3D9::GetActiveRenderDepthSurface() +{ + return GetActiveRenderDepthSurfaceD3D9(); +} +void GfxDeviceD3D9::SetSurfaceFlags (RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags) +{ +} + + +// ---------- uploading textures + +void GfxDeviceD3D9::UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + m_Textures.UploadTexture2D( texture, dimension, srcData, width, height, format, mipCount, uploadFlags, skipMipLevels, usageMode, colorSpace ); +} +void GfxDeviceD3D9::UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + m_Textures.UploadTextureSubData2D( texture, srcData, mipLevel, x, y, width, height, format, colorSpace ); +} +void GfxDeviceD3D9::UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + m_Textures.UploadTextureCube( texture, srcData, faceDataSize, size, format, mipCount, uploadFlags, colorSpace ); +} +void GfxDeviceD3D9::UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + m_Textures.UploadTexture3D( texture, srcData, width, height, depth, format, mipCount, uploadFlags ); +} + +void GfxDeviceD3D9::DeleteTexture( TextureID texture ) +{ + m_Textures.DeleteTexture( texture ); + + // invalidate texture unit states that used this texture + for (int i = 0; i < ARRAY_SIZE(m_State.texturesPS); ++i) + { + TextureUnitStateD3D& currTex = m_State.texturesPS[i]; + if( currTex.texID == texture ) + currTex.Invalidate(); + } + for (int i = 0; i < ARRAY_SIZE(m_State.texturesVS); ++i) + { + TextureUnitStateD3D& currTex = m_State.texturesVS[i]; + if (currTex.texID == texture) + currTex.Invalidate(); + } +} + +void UnbindTextureD3D9( TextureID texture ) +{ + GfxDeviceD3D9& device = static_cast<GfxDeviceD3D9&>( GetRealGfxDevice() ); + IDirect3DDevice9* dev = GetD3DDevice(); + + // invalidate texture unit states that used this texture + for (int i = 0; i < ARRAY_SIZE(device.GetState().texturesPS); ++i) + { + TextureUnitStateD3D& currTex = device.GetState().texturesPS[i]; + if( currTex.texID == texture ) + { + D3D9_CALL(dev->SetTexture(GetD3D9SamplerIndex(kShaderFragment,i), NULL)); + currTex.Invalidate(); + } + } + for (int i = 0; i < ARRAY_SIZE(device.GetState().texturesVS); ++i) + { + TextureUnitStateD3D& currTex = device.GetState().texturesVS[i]; + if (currTex.texID == texture) + { + D3D9_CALL(dev->SetTexture(GetD3D9SamplerIndex(kShaderVertex,i), NULL)); + currTex.Invalidate(); + } + } +} + + +// ---------- context + +GfxDevice::PresentMode GfxDeviceD3D9::GetPresentMode() +{ + return kPresentBeforeUpdate; +} + +void GfxDeviceD3D9::BeginFrame() +{ + if( m_State.m_DeviceLost ) + return; + + // begin scene + Assert( !m_InsideFrame ); + GetD3DDevice()->BeginScene(); + m_InsideFrame = true; + +} + +void GfxDeviceD3D9::EndFrame() +{ + // Check if we're inside scene in case BeginFrame() failed + if( !m_InsideFrame ) + return; + + GetD3DDevice()->EndScene(); + m_InsideFrame = false; +} + +bool GfxDeviceD3D9::IsValidState() +{ + return !m_State.m_DeviceLost; +} + +bool GfxDeviceD3D9::HandleInvalidState() +{ +#if ENABLE_MULTITHREADED_CODE + // Reset render textures owned by the main thread + if (Thread::CurrentThreadIsMainThread()) + CommonReloadResources(kReleaseRenderTextures); +#endif + + ResetDynamicResourcesD3D9(); + + bool success = HandleD3DDeviceLost(); + +#if ENABLE_PROFILER + if (success) + m_TimerQueriesD3D9.RecreateAllQueries(); +#endif + + InvalidateState(); + return success; +} + +static void CleanupEventQueries () +{ + D3D9QueryList::iterator itEnd = s_EventQueries.end(); + for (D3D9QueryList::iterator it = s_EventQueries.begin(); it != itEnd; ++it) + { + IDirect3DQuery9* query = *it; + if (query != NULL) + { + query->Release(); + } + } + s_EventQueries.clear(); +} + +static void PopEventQuery () +{ + AssertIf (s_EventQueries.empty()); + + IDirect3DQuery9* query = s_EventQueries.front(); + AssertIf (query == NULL); + + while (S_FALSE == query->GetData (NULL, 0, D3DGETDATA_FLUSH)) + { + Sleep (1); + } + query->Release(); + + s_EventQueries.pop_front(); +} + +void GfxDeviceD3D9::PushEventQuery () +{ + if (m_MaxBufferedFrames < 0) + return; + + IDirect3DQuery9* query = NULL; + HRESULT hr = GetD3DDevice()->CreateQuery (D3DQUERYTYPE_EVENT, &query); + if (query != NULL) + { + if (SUCCEEDED(query->Issue(D3DISSUE_END))) + s_EventQueries.push_back (query); + else + query->Release(); + } + + // don't exceed maximum lag... instead we'll deterministically block here until the GPU has done enough work + while (!s_EventQueries.empty() && s_EventQueries.size() > m_MaxBufferedFrames) + { + PopEventQuery(); + } +} + +void GfxDeviceD3D9::PresentFrame() +{ + if( m_State.m_DeviceLost ) + return; + + HRESULT hr = GetD3DDevice()->Present( NULL, NULL, NULL, NULL ); + PushEventQuery(); + // When D3DERR_DRIVERINTERNALERROR is returned from Present(), + // the application can do one of the following, try recovering just as + // from the lost device. + if( hr == D3DERR_DEVICELOST || hr == D3DERR_DRIVERINTERNALERROR ) + { + m_State.m_DeviceLost = true; + } +} + +void GfxDeviceD3D9::FinishRendering() +{ + // not needed on D3D +} + + + +// ---------- immediate mode rendering + +// we break very large immediate mode submissions into multiple batches internally +const int kMaxImmediateVerticesPerDraw = 8192; + + +ImmediateModeD3D::ImmediateModeD3D() +: m_ImmVertexDecl(NULL) +{ + m_QuadsIB = new UInt16[kMaxImmediateVerticesPerDraw*6]; + UInt32 baseIndex = 0; + UInt16* ibPtr = m_QuadsIB; + for( int i = 0; i < kMaxImmediateVerticesPerDraw; ++i ) + { + ibPtr[0] = baseIndex + 1; + ibPtr[1] = baseIndex + 2; + ibPtr[2] = baseIndex; + ibPtr[3] = baseIndex + 2; + ibPtr[4] = baseIndex + 3; + ibPtr[5] = baseIndex; + baseIndex += 4; + ibPtr += 6; + } +} + +ImmediateModeD3D::~ImmediateModeD3D() +{ + delete[] m_QuadsIB; +} + + +void ImmediateModeD3D::Invalidate() +{ + m_Vertices.clear(); + memset( &m_Current, 0, sizeof(m_Current) ); +} + +void GfxDeviceD3D9::ImmediateVertex( float x, float y, float z ) +{ + // If the current batch is becoming too large, internally end it and begin it again. + size_t currentSize = m_Imm.m_Vertices.size(); + if( currentSize >= kMaxImmediateVerticesPerDraw - 4 ) + { + GfxPrimitiveType mode = m_Imm.m_Mode; + // For triangles, break batch when multiple of 3's is reached. + if( mode == kPrimitiveTriangles && currentSize % 3 == 0 ) + { + ImmediateEnd(); + ImmediateBegin( mode ); + } + // For other primitives, break on multiple of 4's. + // NOTE: This won't quite work for triangle strips, but we'll just pretend + // that will never happen. + else if( mode != kPrimitiveTriangles && currentSize % 4 == 0 ) + { + ImmediateEnd(); + ImmediateBegin( mode ); + } + } + D3DVECTOR& vert = m_Imm.m_Current.vertex; + vert.x = x; + vert.y = y; + vert.z = z; + m_Imm.m_Vertices.push_back( m_Imm.m_Current ); +} + +void GfxDeviceD3D9::ImmediateNormal( float x, float y, float z ) +{ + m_Imm.m_Current.normal.x = x; + m_Imm.m_Current.normal.y = y; + m_Imm.m_Current.normal.z = z; +} + +void GfxDeviceD3D9::ImmediateColor( float r, float g, float b, float a ) +{ + float color[4] = { r, g, b, a }; + m_Imm.m_Current.color = ColorToD3D( color ); +} + +void GfxDeviceD3D9::ImmediateTexCoordAll( float x, float y, float z ) +{ + for( int i = 0; i < 8; ++i ) + { + D3DVECTOR& uv = m_Imm.m_Current.texCoords[i]; + uv.x = x; + uv.y = y; + uv.z = z; + } +} + +void GfxDeviceD3D9::ImmediateTexCoord( int unit, float x, float y, float z ) +{ + if( unit < 0 || unit >= 8 ) + { + ErrorString( "Invalid unit for texcoord" ); + return; + } + D3DVECTOR& uv = m_Imm.m_Current.texCoords[unit]; + uv.x = x; + uv.y = y; + uv.z = z; +} + +void GfxDeviceD3D9::ImmediateBegin( GfxPrimitiveType type ) +{ + m_Imm.m_Mode = type; + m_Imm.m_Vertices.clear(); +} + +void GfxDeviceD3D9::ImmediateEnd() +{ + if( m_Imm.m_Vertices.empty() ) + return; + + // lazily create vertex declaration + IDirect3DDevice9* dev = GetD3DDevice(); + HRESULT hr = S_OK; + if( !m_Imm.m_ImmVertexDecl ) + { + static const D3DVERTEXELEMENT9 elements[] = { + // stream, offset, data type, processing, semantics, index + { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // position + { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, // normal + { 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 }, // color + { 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // UVs + { 0, 40, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, + { 0, 52, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 }, + { 0, 64, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3 }, + { 0, 76, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 4 }, + { 0, 88, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 5 }, + { 0, 100, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 6 }, + { 0, 112, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 7 }, + D3DDECL_END() + }; + hr = dev->CreateVertexDeclaration( elements, &m_Imm.m_ImmVertexDecl ); + if( FAILED(hr) ) { + // TODO: error + } + } + + // draw + D3D9_CALL(dev->SetVertexDeclaration( m_Imm.m_ImmVertexDecl )); + + BeforeDrawCall( true ); + + int vertexCount = m_Imm.m_Vertices.size(); + const ImmediateVertexD3D* vb = &m_Imm.m_Vertices[0]; + switch( m_Imm.m_Mode ) + { + case kPrimitiveTriangles: + hr = D3D9_CALL_HR(dev->DrawPrimitiveUP( D3DPT_TRIANGLELIST, vertexCount / 3, vb, sizeof(ImmediateVertexD3D) )); + m_Stats.AddDrawCall( vertexCount / 3, vertexCount ); + break; + case kPrimitiveTriangleStripDeprecated: + hr = D3D9_CALL_HR(dev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, vertexCount - 2, vb, sizeof(ImmediateVertexD3D) )); + m_Stats.AddDrawCall( vertexCount - 2, vertexCount ); + break; + case kPrimitiveQuads: + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitiveUP( D3DPT_TRIANGLELIST, 0, vertexCount, vertexCount / 4 * 2, m_Imm.m_QuadsIB, D3DFMT_INDEX16, vb, sizeof(ImmediateVertexD3D) )); + m_Stats.AddDrawCall( vertexCount / 4 * 2, vertexCount ); + break; + case kPrimitiveLines: + hr = D3D9_CALL_HR(dev->DrawPrimitiveUP( D3DPT_LINELIST, vertexCount / 2, vb, sizeof(ImmediateVertexD3D) )); + m_Stats.AddDrawCall( vertexCount / 2, vertexCount ); + break; + default: + AssertString("ImmediateEnd: unknown draw mode"); + } + AssertIf( FAILED(hr) ); + // TODO: stats + + // clear vertices + m_Imm.m_Vertices.clear(); +} + + + +bool GfxDeviceD3D9::CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ) +{ + HRESULT hr; + IDirect3DDevice9* dev = GetD3DDevice(); + + SurfacePointer renderTarget; + hr = dev->GetRenderTarget( 0, &renderTarget ); + if( !renderTarget || FAILED(hr) ) + return false; + + D3DSURFACE_DESC rtDesc; + renderTarget->GetDesc( &rtDesc ); + + SurfacePointer resolvedSurface; + if( rtDesc.MultiSampleType != D3DMULTISAMPLE_NONE ) + { + hr = dev->CreateRenderTarget( rtDesc.Width, rtDesc.Height, rtDesc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &resolvedSurface, NULL ); + if( FAILED(hr) ) + return false; + hr = dev->StretchRect( renderTarget, NULL, resolvedSurface, NULL, D3DTEXF_NONE ); + if( FAILED(hr) ) + return false; + renderTarget = resolvedSurface; + } + + SurfacePointer offscreenSurface; + hr = dev->CreateOffscreenPlainSurface( rtDesc.Width, rtDesc.Height, rtDesc.Format, D3DPOOL_SYSTEMMEM, &offscreenSurface, NULL ); + if( FAILED(hr) ) + return false; + + hr = dev->GetRenderTargetData( renderTarget, offscreenSurface ); + bool ok = SUCCEEDED(hr); + if( ok ) + { + rgba32 += (height-1) * width * sizeof(UInt32); + if( rtDesc.Format == D3DFMT_A8R8G8B8 || rtDesc.Format == D3DFMT_X8R8G8B8 ) + { + // Backbuffer is 32 bit + D3DLOCKED_RECT lr; + RECT rect; + rect.left = left; + rect.right = left + width; + rect.top = rtDesc.Height - bottom - height; + rect.bottom = rtDesc.Height - bottom; + hr = offscreenSurface->LockRect( &lr, &rect, D3DLOCK_READONLY ); + if( SUCCEEDED(hr) ) + { + const UInt8* src = (const UInt8*)lr.pBits; + for( int y = 0; y < height; ++y ) + { + const UInt32* srcPtr = (const UInt32*)src; + UInt32* dstPtr = (UInt32*)rgba32; + for( int x = 0; x < width; ++x ) + { + UInt32 argbCol = *srcPtr; + UInt32 abgrCol = (argbCol&0xFF00FF00) | ((argbCol&0x00FF0000)>>16) | ((argbCol&0x000000FF)<<16); + *dstPtr = abgrCol; + ++srcPtr; + ++dstPtr; + } + rgba32 -= width * sizeof(UInt32); + src += lr.Pitch; + } + } + else + { + ok = false; + } + offscreenSurface->UnlockRect(); + } + else if( rtDesc.Format == D3DFMT_R5G6B5 ) + { + // Backbuffer is 16 bit 565 + D3DLOCKED_RECT lr; + RECT rect; + rect.left = left; + rect.right = left + width; + rect.top = rtDesc.Height - bottom - height; + rect.bottom = rtDesc.Height - bottom; + hr = offscreenSurface->LockRect( &lr, &rect, D3DLOCK_READONLY ); + if( SUCCEEDED(hr) ) + { + const UInt8* src = (const UInt8*)lr.pBits; + for( int y = 0; y < height; ++y ) + { + const UInt16* srcPtr = (const UInt16*)src; + UInt32* dstPtr = (UInt32*)rgba32; + for( int x = 0; x < width; ++x ) + { + UInt16 rgbCol = *srcPtr; + UInt32 abgrCol = 0xFF000000 | ((rgbCol&0xF800)>>8) | ((rgbCol&0x07E0)<<5) | ((rgbCol&0x001F)<<19); + *dstPtr = abgrCol; + ++srcPtr; + ++dstPtr; + } + rgba32 -= width * sizeof(UInt32); + src += lr.Pitch; + } + } + else + { + ok = false; + } + offscreenSurface->UnlockRect(); + } + else if( rtDesc.Format == D3DFMT_X1R5G5B5 || rtDesc.Format == D3DFMT_A1R5G5B5 ) + { + // Backbuffer is 15 bit 555 + D3DLOCKED_RECT lr; + RECT rect; + rect.left = left; + rect.right = left + width; + rect.top = rtDesc.Height - bottom - height; + rect.bottom = rtDesc.Height - bottom; + hr = offscreenSurface->LockRect( &lr, &rect, D3DLOCK_READONLY ); + if( SUCCEEDED(hr) ) + { + const UInt8* src = (const UInt8*)lr.pBits; + for( int y = 0; y < height; ++y ) + { + const UInt16* srcPtr = (const UInt16*)src; + UInt32* dstPtr = (UInt32*)rgba32; + for( int x = 0; x < width; ++x ) + { + UInt16 rgbCol = *srcPtr; + UInt32 abgrCol = ((rgbCol&0x8000)<<16) | ((rgbCol&0x7C00)>>7) | ((rgbCol&0x03E0)<<6) | ((rgbCol&0x001F)<<19); + *dstPtr = abgrCol; + ++srcPtr; + ++dstPtr; + } + rgba32 -= width * sizeof(UInt32); + src += lr.Pitch; + } + } + else + { + ok = false; + } + offscreenSurface->UnlockRect(); + } + else + { + // TODO: handle more conversions! + ok = false; + } + } + + return ok; +} + + + +bool GfxDeviceD3D9::ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) +{ + // TODO: make it work in all different situations + + AssertIf( image.GetFormat() != kTexFormatARGB32 && image.GetFormat() != kTexFormatRGB24 ); + + HRESULT hr; + IDirect3DDevice9* dev = GetD3DDevice(); + SurfacePointer renderTarget; + hr = dev->GetRenderTarget( 0, &renderTarget ); + if( !renderTarget || FAILED(hr) ) + return false; + + D3DSURFACE_DESC rtDesc; + renderTarget->GetDesc( &rtDesc ); + + SurfacePointer resolvedSurface; + if( rtDesc.MultiSampleType != D3DMULTISAMPLE_NONE ) + { + hr = dev->CreateRenderTarget( rtDesc.Width, rtDesc.Height, rtDesc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &resolvedSurface, NULL ); + if( FAILED(hr) ) + return false; + hr = dev->StretchRect( renderTarget, NULL, resolvedSurface, NULL, D3DTEXF_NONE ); + if( FAILED(hr) ) + return false; + renderTarget = resolvedSurface; + } + + SurfacePointer offscreenSurface; + hr = dev->CreateOffscreenPlainSurface( rtDesc.Width, rtDesc.Height, rtDesc.Format, D3DPOOL_SYSTEMMEM, &offscreenSurface, NULL ); + if( FAILED(hr) ) + return false; + if (width <= 0 || left < 0 || left + width > rtDesc.Width) + { + ErrorString("Trying to read pixel out of bounds"); + return false; + } + if (height <= 0 || bottom < 0 || bottom + height > rtDesc.Height) + { + ErrorString("Trying to read pixel out of bounds"); + return false; + } + + hr = dev->GetRenderTargetData( renderTarget, offscreenSurface ); + bool ok = SUCCEEDED(hr); + if( ok ) + { + if( rtDesc.Format == D3DFMT_A8R8G8B8 || rtDesc.Format == D3DFMT_X8R8G8B8 ) + { + // Render target is 32 bit + D3DLOCKED_RECT lr; + RECT rect; + rect.left = left; + rect.right = left + width; + rect.top = rtDesc.Height - bottom - height; + rect.bottom = rtDesc.Height - bottom; + hr = offscreenSurface->LockRect( &lr, &rect, D3DLOCK_READONLY ); + if( SUCCEEDED(hr) ) + { + const UInt8* src = (const UInt8*)lr.pBits; + if( image.GetFormat() == kTexFormatARGB32 ) + { + for( int y = height-1; y >= 0; --y ) + { + const UInt32* srcPtr = (const UInt32*)src; + UInt32* dstPtr = (UInt32*)(image.GetRowPtr(destY+y) + destX * 4); + for( int x = 0; x < width; ++x ) + { + UInt32 argbCol = *srcPtr; + UInt32 bgraCol = ((argbCol&0xFF000000)>>24) | ((argbCol&0x00FF0000)>>8) | ((argbCol&0x0000FF00)<<8) | ((argbCol&0x000000FF)<<24); + *dstPtr = bgraCol; + ++srcPtr; + ++dstPtr; + } + src += lr.Pitch; + } + } + else if( image.GetFormat() == kTexFormatRGB24 ) + { + for( int y = height-1; y >= 0; --y ) + { + const UInt32* srcPtr = (const UInt32*)src; + UInt8* dstPtr = image.GetRowPtr(destY+y) + destX * 3; + for( int x = 0; x < width; ++x ) + { + UInt32 argbCol = *srcPtr; + dstPtr[0] = (argbCol & 0x00FF0000) >> 16; + dstPtr[1] = (argbCol & 0x0000FF00) >> 8; + dstPtr[2] = (argbCol & 0x000000FF); + ++srcPtr; + dstPtr += 3; + } + src += lr.Pitch; + } + } + else + { + AssertString( "Invalid image format" ); + } + } + else + { + ok = false; + } + offscreenSurface->UnlockRect(); + } + else if( rtDesc.Format == D3DFMT_R5G6B5 ) + { + // Render target is 16 bit 565 + D3DLOCKED_RECT lr; + RECT rect; + rect.left = left; + rect.right = left + width; + rect.top = rtDesc.Height - bottom - height; + rect.bottom = rtDesc.Height - bottom; + hr = offscreenSurface->LockRect( &lr, &rect, D3DLOCK_READONLY ); + if( SUCCEEDED(hr) ) + { + const UInt8* src = (const UInt8*)lr.pBits; + if( image.GetFormat() == kTexFormatARGB32 ) + { + for( int y = height-1; y >= 0; --y ) + { + const UInt16* srcPtr = (const UInt16*)src; + UInt32* dstPtr = (UInt32*)(image.GetRowPtr(destY+y) + destX * 4); + for( int x = 0; x < width; ++x ) + { + UInt16 argbCol = *srcPtr; + UInt32 bgraCol = 0x000000FF | (argbCol&0xF800) | ((argbCol&0x07E0)<<13) | ((argbCol&0x001F)<<27); + *dstPtr = bgraCol; + ++srcPtr; + ++dstPtr; + } + src += lr.Pitch; + } + } + else if( image.GetFormat() == kTexFormatRGB24 ) + { + for( int y = height-1; y >= 0; --y ) + { + const UInt16* srcPtr = (const UInt16*)src; + UInt8* dstPtr = image.GetRowPtr(destY+y) + destX * 3; + for( int x = 0; x < width; ++x ) + { + UInt16 argbCol = *srcPtr; + dstPtr[0] = (argbCol & 0xF800) >> 8; + dstPtr[1] = (argbCol & 0x07E0) >> 3; + dstPtr[2] = (argbCol & 0x001F) << 3; + ++srcPtr; + dstPtr += 3; + } + src += lr.Pitch; + } + } + else + { + AssertString( "Invalid image format" ); + } + } + else + { + ok = false; + } + offscreenSurface->UnlockRect(); + } + else if( rtDesc.Format == D3DFMT_A1R5G5B5 || rtDesc.Format == D3DFMT_X1R5G5B5 ) + { + // Render target is 15 bit 555 + D3DLOCKED_RECT lr; + RECT rect; + rect.left = left; + rect.right = left + width; + rect.top = rtDesc.Height - bottom - height; + rect.bottom = rtDesc.Height - bottom; + hr = offscreenSurface->LockRect( &lr, &rect, D3DLOCK_READONLY ); + if( SUCCEEDED(hr) ) + { + const UInt8* src = (const UInt8*)lr.pBits; + if( image.GetFormat() == kTexFormatARGB32 ) + { + for( int y = height-1; y >= 0; --y ) + { + const UInt16* srcPtr = (const UInt16*)src; + UInt32* dstPtr = (UInt32*)(image.GetRowPtr(destY+y) + destX * 4); + for( int x = 0; x < width; ++x ) + { + UInt16 argbCol = *srcPtr; + UInt32 bgraCol = ((argbCol&0x8000)>>8) | ((argbCol&0x7C00)<<1) | ((argbCol&0x03E0)<<14) | ((argbCol&0x001F)<<27); + *dstPtr = bgraCol; + ++srcPtr; + ++dstPtr; + } + src += lr.Pitch; + } + } + else if( image.GetFormat() == kTexFormatRGB24 ) + { + for( int y = height-1; y >= 0; --y ) + { + const UInt16* srcPtr = (const UInt16*)src; + UInt8* dstPtr = image.GetRowPtr(destY+y) + destX * 3; + for( int x = 0; x < width; ++x ) + { + UInt16 argbCol = *srcPtr; + dstPtr[0] = (argbCol & 0x7C00) >> 7; + dstPtr[1] = (argbCol & 0x03E0) >> 2; + dstPtr[2] = (argbCol & 0x001F) << 3; + ++srcPtr; + dstPtr += 3; + } + src += lr.Pitch; + } + } + else + { + AssertString( "Invalid image format" ); + } + } + else + { + ok = false; + } + offscreenSurface->UnlockRect(); + } + else + { + // TODO: handle more conversions! + ok = false; + } + } + + return ok; +} + +void GfxDeviceD3D9::GrabIntoRenderTexture(RenderSurfaceHandle rtHandle, RenderSurfaceHandle rd, int x, int y, int width, int height ) +{ + if( !rtHandle.IsValid() ) + return; + + RenderColorSurfaceD3D9* renderTexture = reinterpret_cast<RenderColorSurfaceD3D9*>( rtHandle.object ); + + HRESULT hr; + IDirect3DDevice9* dev = GetD3DDevice(); + SurfacePointer currentRenderTarget; + hr = dev->GetRenderTarget( 0, ¤tRenderTarget ); + if( !currentRenderTarget || FAILED(hr) ) + return; + + D3DSURFACE_DESC rtDesc; + currentRenderTarget->GetDesc( &rtDesc ); + + IDirect3DTexture9* texturePointer = static_cast<IDirect3DTexture9*>(m_Textures.GetTexture (renderTexture->textureID)); + if( !texturePointer ) + return; + + SurfacePointer textureSurface; + hr = texturePointer->GetSurfaceLevel( 0, &textureSurface ); + if( !textureSurface || FAILED(hr) ) + return; + + RECT rc; + rc.left = x; + rc.top = rtDesc.Height - (y + height); + rc.right = x + width; + rc.bottom = rtDesc.Height - (y); + hr = dev->StretchRect( currentRenderTarget, &rc, textureSurface, NULL, D3DTEXF_NONE ); +} + + +void* GfxDeviceD3D9::GetNativeGfxDevice() +{ + return GetD3DDevice(); +} + +void* GfxDeviceD3D9::GetNativeTexturePointer(TextureID id) +{ + return m_Textures.GetTexture (id); +} + +intptr_t GfxDeviceD3D9::CreateExternalTextureFromNative(intptr_t nativeTex) +{ + return m_Textures.RegisterNativeTexture((IDirect3DBaseTexture9*)nativeTex); +} + +void GfxDeviceD3D9::UpdateExternalTextureFromNative(TextureID tex, intptr_t nativeTex) +{ + m_Textures.UpdateNativeTexture(tex, (IDirect3DBaseTexture9*)nativeTex); +} + + +#if ENABLE_PROFILER + +void GfxDeviceD3D9::BeginProfileEvent (const char* name) +{ + if (g_D3D9BeginEventFunc) + { + wchar_t wideName[100]; + UTF8ToWide (name, wideName, 100); + g_D3D9BeginEventFunc (0, wideName); + } +} + +void GfxDeviceD3D9::EndProfileEvent () +{ + if (g_D3D9EndEventFunc) + { + g_D3D9EndEventFunc (); + } +} + +GfxTimerQuery* GfxDeviceD3D9::CreateTimerQuery() +{ + Assert(gGraphicsCaps.hasTimerQuery); + return m_TimerQueriesD3D9.CreateTimerQuery(); +} + +void GfxDeviceD3D9::DeleteTimerQuery(GfxTimerQuery* query) +{ + delete query; +} + +void GfxDeviceD3D9::BeginTimerQueries() +{ + if(!gGraphicsCaps.hasTimerQuery) + return; + + m_TimerQueriesD3D9.BeginTimerQueries(); +} + +void GfxDeviceD3D9::EndTimerQueries() +{ + if(!gGraphicsCaps.hasTimerQuery) + return; + + m_TimerQueriesD3D9.EndTimerQueries(); +} + +/* +SInt32 GfxDeviceD3D9::GetTimerQueryIdentifier() +{ + if(!gGraphicsCaps.hasTimerQuery) + return -1; + // Allocate more queries + if(m_QueryCount[m_CurrentQueryBuffer] >= m_GPUQueries[m_CurrentQueryBuffer].size()) + { + int count = std::max (m_QueryCount[m_CurrentQueryBuffer], 100); + IDirect3DQuery9* d3dQuery; + for( int i = 0; i < count; i++) + { + GetD3DDevice()->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &d3dQuery); + // initialze more Query objects + m_GPUQueries[m_CurrentQueryBuffer].push_back(d3dQuery); + } + } + int index = m_QueryCount[m_CurrentQueryBuffer]++; + IDirect3DQuery9* currentQuery = m_GPUQueries[m_CurrentQueryBuffer][index]; + currentQuery ->Issue(D3DISSUE_END); + return index; +} + +ProfileTimeFormat GfxDeviceD3D9::GetTimerQueryData(SInt32 identifier, bool wait) +{ + if(!gGraphicsCaps.hasTimerQuery) + return 0; + + if(m_GPUQueries[m_CurrentQueryBuffer].size()<=identifier) + return 0; + + UINT64 time; + while (S_OK != m_GPUQueries[m_CurrentQueryBuffer][identifier]->GetData(&time, sizeof(time), D3DGETDATA_FLUSH)) {} + return (double)time * m_TimeMultiplier; +} + +void GfxDeviceD3D9::CleanupTimerQueries () +{ + if(!gGraphicsCaps.hasTimerQuery) + return; + + for(int buffer = 0; buffer < 2; buffer++) + { + for(int i = 0; i < m_GPUQueries[buffer].size(); i++) + m_GPUQueries[buffer][i]->Release(); + m_GPUQueries[buffer].clear(); + if(m_FrequencyQuery[buffer]) + m_FrequencyQuery[buffer]->Release(); + m_FrequencyQuery[buffer] = NULL; + m_QueryCount[buffer] = 0; + } +} +*/ + +#endif // ENABLE_PROFILER + + +// -------- editor only functions + +#if UNITY_EDITOR +void GfxDeviceD3D9::SetAntiAliasFlag( bool aa ) +{ + #pragma message("! implement SetAntiAliasFlag") +} + + +void GfxDeviceD3D9::DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ) +{ + if( vertexCount == 0 ) + return; + + AssertIf(vertexCount > 60000); // TODO: handle this by multi-batching + + AssertIf( !data || vertexCount < 0 || vertexChannels == 0 ); + + IDirect3DDevice9* dev = GetD3DDevice(); + + IDirect3DVertexDeclaration9* vertexDecl = GetD3DVertexDeclaration( vertexChannels ); + + ChannelAssigns channels; + for( int i = 0; i < kShaderChannelCount; ++i ) + { + if( !( vertexChannels & (1<<i) ) ) + continue; + VertexComponent destComponent = kSuitableVertexComponentForChannel[i]; + channels.Bind( (ShaderChannel)i, destComponent ); + } + D3D9_CALL(dev->SetVertexDeclaration( vertexDecl )); + UpdateChannelBindingsD3D( channels ); + BeforeDrawCall(false); + + HRESULT hr; + switch( type ) { + case kPrimitiveTriangles: + hr = D3D9_CALL_HR(dev->DrawPrimitiveUP( D3DPT_TRIANGLELIST, vertexCount/3, data, stride )); + m_Stats.AddDrawCall( vertexCount / 3, vertexCount ); + break; + case kPrimitiveQuads: + while (vertexCount > 0) + { + int vcount = std::min(vertexCount,kMaxImmediateVerticesPerDraw); + hr = D3D9_CALL_HR(dev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, vcount, vcount / 4 * 2, m_Imm.m_QuadsIB, D3DFMT_INDEX16, data, stride)); + m_Stats.AddDrawCall(vcount / 4 * 2, vcount); + data = (const UInt8*)data + vcount * stride; + vertexCount -= vcount; + } + break; + case kPrimitiveLines: + hr = D3D9_CALL_HR(dev->DrawPrimitiveUP( D3DPT_LINELIST, vertexCount/2, data, stride )); + m_Stats.AddDrawCall( vertexCount / 2, vertexCount ); + break; + case kPrimitiveLineStrip: + hr = D3D9_CALL_HR(dev->DrawPrimitiveUP( D3DPT_LINESTRIP, vertexCount-1, data, stride )); + m_Stats.AddDrawCall( vertexCount-1, vertexCount ); + break; + default: + ErrorString("Primitive type not supported"); + return; + } + Assert(SUCCEEDED(hr)); +} + +int GfxDeviceD3D9::GetCurrentTargetAA() const +{ + return GetCurrentD3DFSAALevel(); +} + +GfxDeviceWindow* GfxDeviceD3D9::CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) +{ + return new D3D9Window( GetD3DDevice(), window, width, height, depthFormat, antiAlias); +} + +#endif + +int GfxDeviceD3D9::GetCurrentTargetWidth() const +{ + return m_CurrTargetWidth; +} + +int GfxDeviceD3D9::GetCurrentTargetHeight() const +{ + return m_CurrTargetHeight; +} + +void GfxDeviceD3D9::SetCurrentTargetSize(int width, int height) +{ + m_CurrTargetWidth = width; + m_CurrTargetHeight = height; +} + +void GfxDeviceD3D9::SetCurrentWindowSize(int width, int height) +{ + m_CurrWindowWidth = m_CurrTargetWidth = width; + m_CurrWindowHeight = m_CurrTargetHeight = height; +} + + +#if UNITY_EDITOR + +static IDirect3DTexture9* FindD3D9TextureByID (TextureID tid) +{ + GfxDevice& device = GetRealGfxDevice(); + if (device.GetRenderer() != kGfxRendererD3D9) + return NULL; + GfxDeviceD3D9& dev = static_cast<GfxDeviceD3D9&>(device); + IDirect3DBaseTexture9* basetex = dev.GetTextures().GetTexture (tid); + if (!basetex) + return NULL; + if (basetex->GetType() != D3DRTYPE_TEXTURE) + return NULL; + return static_cast<IDirect3DTexture9*>(basetex); +} + +// In the editor, for drawing directly into HDC of D3D texture. +// Functions not defined in any header; declare prototypes manually: +// HDC AcquireHDCForTextureD3D9 (TextureID tid, int& outWidth, int& outHeight); +// void ReleaseHDCForTextureD3D9 (TextureID tid, HDC dc); +// AcquireHDCForTextureD3D9 _can_ return NULL if it can't get to DC (not D3D9, no +// texture, wrong texture format, ...). + +HDC AcquireHDCForTextureD3D9 (TextureID tid, int& outWidth, int& outHeight) +{ + IDirect3DTexture9* tex = FindD3D9TextureByID (tid); + if (!tex) + return NULL; + SurfacePointer surface; + if (FAILED(tex->GetSurfaceLevel(0,&surface))) + return NULL; + D3DSURFACE_DESC desc; + if (FAILED(surface->GetDesc (&desc))) + return NULL; + outWidth = desc.Width; + outHeight = desc.Height; + HDC dc = NULL; + if (FAILED(surface->GetDC(&dc))) + return NULL; + return dc; +} + +void ReleaseHDCForTextureD3D9 (TextureID tid, HDC dc) +{ + IDirect3DTexture9* tex = FindD3D9TextureByID (tid); + if (!tex) + return; + SurfacePointer surface; + if (FAILED(tex->GetSurfaceLevel(0,&surface))) + return; + surface->ReleaseDC (dc); +} + +#endif + + +// ---------------------------------------------------------------------- +// verification of state + +#if GFX_DEVICE_VERIFY_ENABLE + +#include "Runtime/Utilities/Utility.h" + +void VerifyStateF(D3DRENDERSTATETYPE rs, float val, const char *str); +#define VERIFYF(s,t) VerifyState (s, t, #s " (" #t ")") +void VerifyStateI(D3DRENDERSTATETYPE rs, int val, const char *str); +#define VERIFYI(s,t) VerifyStateI (s, t, #s " (" #t ")") +void VerifyEnabled(D3DRENDERSTATETYPE rs, bool val, const char *str); +#define VERIFYENAB(s,t) VerifyEnabled ( s, t, #s " (" #t ")") + +static void VERIFY_PRINT( const char* format, ... ) +{ + ErrorString( VFormat( format, va_list(&format + 1) ) ); +} + +const float kVerifyDelta = 0.0001f; + +void VerifyStateF(D3DRENDERSTATETYPE rs, float val, const char *str) +{ + float temp = 0; + GetD3DDevice()->GetRenderState(rs,(DWORD*)&temp); + if( !CompareApproximately(temp,val,kVerifyDelta) ) { + VERIFY_PRINT ("%s differs from cache (%f != %f)\n", str, val, temp); + } +} + +void VerifyStateI(D3DRENDERSTATETYPE rs, int val, const char *str) +{ + int temp; + GetD3DDevice()->GetRenderState(rs,(DWORD*)&temp); + if (temp != val) { + VERIFY_PRINT ("%s differs from cache (%i != %i)\n", str, val, temp); + } +} + +void VerifyEnabled(D3DRENDERSTATETYPE rs, bool val, const char *str) +{ + DWORD v; + GetD3DDevice()->GetRenderState(rs,&v); + bool temp = v==TRUE ? true : false; + if (temp != val) { + VERIFY_PRINT ("%s differs from cache (%d != %d)\n", str, val, temp); + } +} + +void GfxDeviceD3D9::VerifyState() +{ + // check if current state blocks match internal state + if (m_CurrBlendState != NULL) { + if (m_State.blending == 0) { + Assert (D3DBLEND_ONE == kBlendModeD3D9[m_CurrBlendState->sourceState.srcBlend]); + Assert (D3DBLEND_ZERO == kBlendModeD3D9[m_CurrBlendState->sourceState.dstBlend]); + } else { + Assert (m_State.srcBlend == kBlendModeD3D9[m_CurrBlendState->sourceState.srcBlend]); + Assert (m_State.destBlend == kBlendModeD3D9[m_CurrBlendState->sourceState.dstBlend]); + } + #if !UNITY_EDITOR // Editor does some funkiness when emulating alpha test, see SetBlendState + Assert (kCmpFuncD3D9[m_State.alphaFunc] == m_CurrBlendState->alphaFunc); + #endif + } + + m_State.Verify(); +} + + + +void DeviceStateD3D::Verify() +{ + #ifdef DUMMY_D3D9_CALLS + return; + #endif + if( !GetD3DDevice() ) { + ErrorString("Verify: no D3D device"); + return; + } + + if( depthFunc != kFuncUnknown ) { + VERIFYI( D3DRS_ZFUNC, kCmpFuncD3D9[depthFunc] ); + } + if( depthWrite != -1 ) { + VERIFYI( D3DRS_ZWRITEENABLE, (depthWrite ? TRUE : FALSE) ); + } + if( blending != -1 ) { + VERIFYENAB( D3DRS_ALPHABLENDENABLE, blending != 0 ); + if( blending ) { + VERIFYI( D3DRS_SRCBLEND, srcBlend ); + VERIFYI( D3DRS_DESTBLEND, destBlend ); + } + } + + if( alphaFunc != kFuncUnknown ) { + VERIFYENAB( D3DRS_ALPHATESTENABLE, alphaFunc != kFuncDisabled ); + if( alphaFunc != kFuncDisabled ) { + VERIFYI( D3DRS_ALPHAFUNC, kCmpFuncD3D9[alphaFunc] ); + if( alphaValue != -1 ) + VERIFYI( D3DRS_ALPHAREF, alphaValue*255.0f ); + } + } +} + +#endif // GFX_DEVICE_VERIFY_ENABLE + diff --git a/Runtime/GfxDevice/d3d/GfxDeviceD3D9.h b/Runtime/GfxDevice/d3d/GfxDeviceD3D9.h new file mode 100644 index 0000000..f648a35 --- /dev/null +++ b/Runtime/GfxDevice/d3d/GfxDeviceD3D9.h @@ -0,0 +1,361 @@ +#pragma once + +#include "D3D9Includes.h" +#include "VertexDeclarations.h" +#include "TexturesD3D9.h" +#include "Runtime/GfxDevice/ShaderConstantCache.h" +#include "Runtime/Shaders/MaterialProperties.h" +#include "VertexPipeD3D9.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "D3D9Context.h" +#include "Runtime/Math/FloatConversion.h" +#include "D3D9VBO.h" +#include "CombinerD3D.h" +#include "External/shaderlab/Library/program.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "External/shaderlab/Library/texenv.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/GfxDevice/BuiltinShaderParams.h" +#include "Runtime/Graphics/Image.h" +#include "PlatformDependent/Win/SmartComPointer.h" +#include "Runtime/Utilities/Utility.h" +#include "D3D9Utils.h" +#include "D3D9Window.h" +#include "GpuProgramsD3D.h" +#include "TimerQueryD3D9.h" + +typedef SmartComPointer<IDirect3DSurface9> SurfacePointer; + +struct TextureUnitStateD3D +{ + TextureID texID; + float bias; + + void Invalidate() + { + texID.m_ID = -1; + bias = 1.0e6f; + } +}; + +class GfxDeviceD3D9; + +struct DeviceStateD3D +{ + int viewport[4]; + int scissorRect[4]; + + CompareFunction depthFunc; + int depthWrite; // 0/1 or -1 + + int blending; + int srcBlend, destBlend, srcBlendAlpha, destBlendAlpha; // D3D modes + int blendOp, blendOpAlpha; // D3D modes + CompareFunction alphaFunc; + float alphaValue; + + CullMode culling; + D3DCULL d3dculling; + bool appBackfaceMode, userBackfaceMode, invertProjMatrix; + bool wireframe; + int scissor; + + // [0] is front, [1] is back, unless invertProjMatrix is true + D3DCMPFUNC stencilFunc[2]; + D3DSTENCILOP stencilFailOp[2], depthFailOp[2], depthPassOp[2]; + + float offsetFactor, offsetUnits; + + GpuProgram* activeGpuProgram[kShaderTypeCount]; + const GpuProgramParameters* activeGpuProgramParams[kShaderTypeCount]; + IUnknown* activeShader[kShaderTypeCount]; + + int colorWriteMask; // ColorWriteMask combinations + + int m_StencilRef; + + TextureUnitStateD3D texturesPS[kMaxSupportedTextureUnits]; + TextureUnitStateD3D texturesVS[4]; + + int fixedFunctionPS; + + bool m_DeviceLost; + + bool m_SoftwareVP; + UInt32 m_NeedsSofwareVPFlags; + + void Invalidate( GfxDeviceD3D9& device ); + void Verify(); +}; + +// TODO: optimize this. Right now we just send off whole 8 float3 UVs with each +// immediate mode vertex. We could at least detect the number of them used from +// ImmediateTexCoord calls. +struct ImmediateVertexD3D { + D3DVECTOR vertex; + D3DVECTOR normal; + D3DCOLOR color; + D3DVECTOR texCoords[8]; +}; + +struct ImmediateModeD3D { + std::vector<ImmediateVertexD3D> m_Vertices; + ImmediateVertexD3D m_Current; + GfxPrimitiveType m_Mode; + IDirect3DVertexDeclaration9* m_ImmVertexDecl; + UInt16* m_QuadsIB; + + ImmediateModeD3D(); + ~ImmediateModeD3D(); + void Invalidate(); +}; + +class GfxDeviceD3D9 : public GfxThreadableDevice +{ +public: + struct DeviceBlendStateD3D9 : public DeviceBlendState + { + UInt8 renderTargetWriteMask; + D3DCMPFUNC alphaFunc; + }; + + struct DeviceDepthStateD3D9 : public DeviceDepthState + { + D3DCMPFUNC depthFunc; + }; + + struct DeviceStencilStateD3D9 : public DeviceStencilState + { + D3DCMPFUNC stencilFuncFront; + D3DSTENCILOP stencilFailOpFront; + D3DSTENCILOP depthFailOpFront; + D3DSTENCILOP depthPassOpFront; + D3DCMPFUNC stencilFuncBack; + D3DSTENCILOP stencilFailOpBack; + D3DSTENCILOP depthFailOpBack; + D3DSTENCILOP depthPassOpBack; + }; + + + typedef std::map< GfxBlendState, DeviceBlendStateD3D9, memcmp_less<GfxBlendState> > CachedBlendStates; + typedef std::map< GfxDepthState, DeviceDepthStateD3D9, memcmp_less<GfxDepthState> > CachedDepthStates; + typedef std::map< GfxStencilState, DeviceStencilStateD3D9, memcmp_less<GfxStencilState> > CachedStencilStates; + typedef std::map< GfxRasterState, DeviceRasterState, memcmp_less<GfxRasterState> > CachedRasterStates; + + +public: + GfxDeviceD3D9(); + GFX_API ~GfxDeviceD3D9(); + + GFX_API void InvalidateState(); + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState(); + #endif + + GFX_API void Clear(UInt32 clearFlags, const float color[4], float depth, int stencil); + GFX_API void SetUserBackfaceMode( bool enable ); + GFX_API void SetWireframe(bool wire); + GFX_API bool GetWireframe() const; + GFX_API void SetInvertProjectionMatrix( bool enable ); + GFX_API bool GetInvertProjectionMatrix() const; + + GFX_API GPUSkinningInfo *CreateGPUSkinningInfo() { return NULL; } + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info) { AssertBreak(false); } + GFX_API void SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ) { AssertBreak(false); } + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) { AssertBreak(false); } + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) { AssertBreak(false); } + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state); + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state); + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state); + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state); + + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef); + GFX_API void SetRasterState(const DeviceRasterState* state); + GFX_API void SetDepthState(const DeviceDepthState* state); + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef); + GFX_API void SetSRGBWrite (const bool); + GFX_API bool GetSRGBWrite (); + + GFX_API void SetWorldMatrix( const float matrix[16] ); + GFX_API void SetViewMatrix( const float matrix[16] ); + GFX_API void SetProjectionMatrix(const Matrix4x4f& matrix); + GFX_API void GetMatrix( float outMatrix[16] ) const; + + GFX_API const float* GetWorldMatrix() const ; + GFX_API const float* GetViewMatrix() const ; + GFX_API const float* GetProjectionMatrix() const ; + GFX_API const float* GetDeviceProjectionMatrix() const; + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ); + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ); + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ); + GFX_API void SetColor( const float color[4] ); + GFX_API void SetViewport( int x, int y, int width, int height ); + GFX_API void GetViewport( int* port ) const; + + GFX_API void SetScissorRect( int x, int y, int width, int height ); + GFX_API void DisableScissor(); + GFX_API bool IsScissorEnabled() const; + GFX_API void GetScissorRect( int values[4] ) const; + + GFX_API bool IsCombineModeSupported( unsigned int combiner ); + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ); + GFX_API void SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ); + GFX_API void SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ); + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias); + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]); + GFX_API void SetTextureName ( TextureID texture, const char* name ) { } + + GFX_API void SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]); + GFX_API bool IsShaderActive( ShaderType type ) const; + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ); + + GFX_API void DisableLights( int startLight ); + GFX_API void SetLight( int light, const GfxVertexLight& data); + GFX_API void SetAmbient( const float ambient[4] ); + + GFX_API void EnableFog(const GfxFogParams& fog); + GFX_API void DisableFog(); + + GFX_API VBO* CreateVBO(); + GFX_API void DeleteVBO( VBO* vbo ); + GFX_API DynamicVBO& GetDynamicVBO(); + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags); + GFX_API RenderSurfaceHandle CreateRenderDepthSurface(TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags); + GFX_API void DestroyRenderSurface(RenderSurfaceHandle& rs); + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face = kCubeFaceUnknown); + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle); + GFX_API void ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle); + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface(int index); + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface(); + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags); + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ); + GFX_API void DeleteTexture( TextureID texture ); + + GFX_API PresentMode GetPresentMode(); + + GFX_API void BeginFrame(); + GFX_API void EndFrame(); + GFX_API void PresentFrame(); + GFX_API bool IsValidState(); + GFX_API bool HandleInvalidState(); + GFX_API void FinishRendering(); + + // Immediate mode rendering + GFX_API void ImmediateVertex( float x, float y, float z ); + GFX_API void ImmediateNormal( float x, float y, float z ); + GFX_API void ImmediateColor( float r, float g, float b, float a ); + GFX_API void ImmediateTexCoordAll( float x, float y, float z ); + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ); + GFX_API void ImmediateBegin( GfxPrimitiveType type ); + GFX_API void ImmediateEnd(); + + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ); + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); + GFX_API void GrabIntoRenderTexture(RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height); + + GFX_API void BeforeDrawCall( bool immediateMode ); + + GFX_API bool IsPositionRequiredForTexGen(int texStageIndex) const { return false; } + GFX_API bool IsNormalRequiredForTexGen(int texStageIndex) const { return false; } + GFX_API bool IsPositionRequiredForTexGen() const { return false; } + GFX_API bool IsNormalRequiredForTexGen() const { return false; } + + GFX_API void DiscardContents (RenderSurfaceHandle& rs) {} + +#if ENABLE_PROFILER + GFX_API void BeginProfileEvent (const char* name); + GFX_API void EndProfileEvent (); + + TimerQueriesD3D9& GetTimerQueries() {return m_TimerQueriesD3D9;} + GFX_API GfxTimerQuery* CreateTimerQuery(); + GFX_API void DeleteTimerQuery(GfxTimerQuery* query); + GFX_API void BeginTimerQueries(); + GFX_API void EndTimerQueries(); + #endif + + #if UNITY_EDITOR + GFX_API void SetAntiAliasFlag( bool aa ); + GFX_API void DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ); + GFX_API int GetCurrentTargetAA() const; + GFX_API GfxDeviceWindow* CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + #endif + + GFX_API int GetCurrentTargetWidth() const; + GFX_API int GetCurrentTargetHeight() const; + GFX_API void SetCurrentTargetSize(int width, int height); + GFX_API void SetCurrentWindowSize(int width, int height); + + GFX_API void* GetNativeGfxDevice(); + GFX_API void* GetNativeTexturePointer(TextureID id); + GFX_API intptr_t CreateExternalTextureFromNative(intptr_t nativeTex); + GFX_API void UpdateExternalTextureFromNative(TextureID tex, intptr_t nativeTex); + + GFX_API void ResetDynamicResources(); + + IDirect3DVertexBuffer9* GetAllWhiteVertexStream(); + + VertexDeclarations& GetVertexDecls() { return m_VertexDecls; } + + const DeviceStateD3D& GetState() const { return m_State; } + DeviceStateD3D& GetState() { return m_State; } + VertexShaderConstantCache& GetVertexShaderConstantCache() { return m_VSConstantCache; } + PixelShaderConstantCache& GetPixelShaderConstantCache() { return m_PSConstantCache; } + + const VertexPipeConfig& GetVertexPipeConfig() const { return m_VertexConfig; } + VertexPipeConfig& GetVertexPipeConfig() { return m_VertexConfig; } + const VertexPipeDataD3D9& GetVertexPipeData() const { return m_VertexData; } + VertexPipeDataD3D9& GetVertexPipeData() { return m_VertexData; } + TexturesD3D9& GetTextures() { return m_Textures; } + + void PushEventQuery(); + +private: + + DeviceStateD3D m_State; + ImmediateModeD3D m_Imm; + VertexPipeConfig m_VertexConfig; + TransformState m_TransformState; + VertexPipeDataD3D9 m_VertexData; + VertexPipePrevious m_VertexPrevious; + + DeviceBlendStateD3D9* m_CurrBlendState; + DeviceDepthStateD3D9* m_CurrDepthState; + const DeviceStencilStateD3D9* m_CurrStencilState; + DeviceRasterState* m_CurrRasterState; + int m_CurrTargetWidth; + int m_CurrTargetHeight; + int m_CurrWindowWidth; + int m_CurrWindowHeight; + + IDirect3DVertexBuffer9* m_AllWhiteVertexStream; + + VertexDeclarations m_VertexDecls; + TexturesD3D9 m_Textures; + DynamicVBO* m_DynamicVBO; + + CachedBlendStates m_CachedBlendStates; + CachedDepthStates m_CachedDepthStates; + CachedStencilStates m_CachedStencilStates; + CachedRasterStates m_CachedRasterStates; + + VertexShaderConstantCache m_VSConstantCache; + PixelShaderConstantCache m_PSConstantCache; + +#if ENABLE_PROFILER + TimerQueriesD3D9 m_TimerQueriesD3D9; +#endif +}; + +GfxDeviceD3D9& GetD3D9GfxDevice(); diff --git a/Runtime/GfxDevice/d3d/GpuProgramsD3D.cpp b/Runtime/GfxDevice/d3d/GpuProgramsD3D.cpp new file mode 100644 index 0000000..9a67a54 --- /dev/null +++ b/Runtime/GfxDevice/d3d/GpuProgramsD3D.cpp @@ -0,0 +1,474 @@ +#include "UnityPrefix.h" +#include "GpuProgramsD3D.h" +#include "External/shaderlab/Library/ShaderLabErrors.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Math/Vector4.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/DirectX/builds/dx9include/d3dx9.h" +#include "D3D9Context.h" +#include "Runtime/GfxDevice/ShaderConstantCache.h" +#include "D3D9Utils.h" +#include "ShaderPatchingD3D9.h" + +#define ENABLE_GPU_PROGRAM_STATS 0 + + +#if ENABLE_GPU_PROGRAM_STATS +typedef std::map<ShaderLab::FastPropertyName, int> PropertyCount; +PropertyCount s_StatCounts[kShaderTypeCount]; +void PrintDebugGpuProgramStats () +{ + typedef std::pair<std::string, int> NameIntPair; + struct Sorter { + bool operator() (const NameIntPair& a, const NameIntPair& b) const { + return a.second > b.second; + } + }; + for (int i = kShaderVertex; i < kShaderTypeCount; ++i) + { + std::vector<NameIntPair> sorted; + sorted.reserve (s_StatCounts[i].size()); + int totalCount = 0; + for (PropertyCount::const_iterator it = s_StatCounts[i].begin(); it != s_StatCounts[i].end(); ++it) + { + sorted.push_back (std::make_pair(it->first.GetName(), it->second)); + totalCount += it->second; + } + std::sort (sorted.begin(), sorted.end(), Sorter()); + printf_console ("%i Shader Stats: %i props, %i requests\n", i, sorted.size(), totalCount); + for (size_t j = 0; j < sorted.size(); ++j) + { + printf_console (" %-25s %6i %5.1f%%\n", sorted[j].first.c_str(), sorted[j].second, sorted[j].second*100.0/totalCount); + } + s_StatCounts[i].clear(); + } +} +#define ADD_TO_VS_STATS(name) ++s_StatCounts[kShaderVertex][name] +#define ADD_TO_PS_STATS(name) ++s_StatCounts[kShaderFragment][name] +#else +#define ADD_TO_VS_STATS(name) +#define ADD_TO_PS_STATS(name) +#endif + + +VertexShaderConstantCache& GetD3D9VertexShaderConstantCache(); // GfxDeviceD3D9.cpp +PixelShaderConstantCache& GetD3D9PixelShaderConstantCache(); // GfxDeviceD3D9.cpp + + +// non static; used by CombinerD3D.cpp and VertexPipeD3D9.cpp +ID3DXBuffer* AssembleD3DShader (const std::string& source) +{ + ID3DXBuffer *compiledShader, *compileErrors; + + // Skip validation of shaders at assembly time when in release mode. Saves + // some time when loading them. + DWORD flags = D3DXSHADER_SKIPVALIDATION; + #if DEBUGMODE + flags = 0; + #endif + + HRESULT hr = D3DXAssembleShader( source.c_str(), source.size(), NULL, NULL, flags, &compiledShader, &compileErrors ); + if( FAILED(hr) ) + { + if (compileErrors && compileErrors->GetBufferSize() > 0) + { + std::string error = Format ("Shader error in '%s': D3D shader assembly failed with: %s\nShader Assembly: %s", g_LastParsedShaderName.c_str(), (const char*)compileErrors->GetBufferPointer(), source.c_str()); + compileErrors->Release(); + ErrorString (error); + } + if( compiledShader ) + compiledShader->Release(); + return NULL; + } + + return compiledShader; +} + +// -------------------------------------------------------------------------- + +template <typename CACHE> +static const UInt8* ApplyValueParametersD3D9 (CACHE& constantCache, const UInt8* buffer, const GpuProgramParameters::ValueParameterArray& valueParams) +{ + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for (GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i) + { + if (i->m_RowCount == 1 && i->m_ArraySize == 1) + { + // Apply vector parameters + const Vector4f* val = reinterpret_cast<const Vector4f*>(buffer); + constantCache.SetValues(i->m_Index, val->GetPtr(), 1); + buffer += sizeof(Vector4f); + } + else + { + // matrix/array + int size = *reinterpret_cast<const int*>(buffer); buffer += sizeof(int); + Assert (i->m_RowCount == 4 && size == 16); + const Matrix4x4f* val = reinterpret_cast<const Matrix4x4f*>(buffer); + Matrix4x4f transposed; + TransposeMatrix4x4 (val, &transposed); + const float *ptr = transposed.GetPtr(); + constantCache.SetValues (i->m_Index, ptr, 4); + buffer += size * sizeof(float); + } + } + return buffer; +} + + + +// -------------------------------------------------------------------------- + +D3D9VertexShader::D3D9VertexShader( const std::string& source ) +: m_FogFailed(0) +{ + for (int i = 0; i < kFogModeCount; ++i) + { + m_Shaders[i] = NULL; + } + m_ImplType = kShaderImplVertex; + if( !Create(source) ) + m_NotSupported = true; +} + +D3D9VertexShader::~D3D9VertexShader () +{ + for (int i = 0; i < kFogModeCount; ++i) + { + if( m_Shaders[i] ) + { + ULONG refCount = m_Shaders[i]->Release(); + AssertIf( refCount != 0 ); + } + } +} + + +bool D3D9VertexShader::Create( const std::string& source ) +{ + // fast skip 3.0 shaders on unsupporting hardware + bool isShaderModel3 = !strncmp(source.c_str(), "vs_3_0", 6); + if( gGraphicsCaps.shaderCaps < kShaderLevel3 && isShaderModel3 ) + return false; + + if (isShaderModel3) + m_GpuProgramLevel = kGpuProgramSM3; + else + { + bool isShaderModel1 = !strncmp(source.c_str(), "vs_1_1", 6); + m_GpuProgramLevel = isShaderModel1 ? kGpuProgramSM1 : kGpuProgramSM2; + } + + HRESULT hr; + IDirect3DDevice9* dev = GetD3DDevice(); + + // assemble shader + ID3DXBuffer *compiledShader = AssembleD3DShader( source ); + if( !compiledShader ) + { + return false; + } + + // create shader + hr = dev->CreateVertexShader( (const DWORD*)compiledShader->GetBufferPointer(), &m_Shaders[0] ); + compiledShader->Release(); + if( FAILED(hr) ) + { + printf_console( "D3D shader create error for shader %s\n", source.c_str() ); + return false; + } + + if (isShaderModel3) + { + m_SourceForFog = source; + } + + return true; +} + +void D3D9VertexShader::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + GfxDevice& device = GetRealGfxDevice(); + IDirect3DDevice9* dev = GetD3DDevice(); + VertexShaderConstantCache& constantCache = GetD3D9VertexShaderConstantCache(); + + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + buffer = ApplyValueParametersD3D9<VertexShaderConstantCache>(constantCache, buffer, valueParams); + + // Apply textures + if (gGraphicsCaps.hasVertexTextures) + { + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + const GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for( GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i ) + { + const GpuProgramParameters::TextureParameter& t = *i; + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + device.SetTexture (kShaderVertex, t.m_Index, 0, texdata->textureID, static_cast<TextureDimension>(texdata->texDim), 0); + buffer += sizeof(*texdata); + } + } +} + +IDirect3DVertexShader9* D3D9VertexShader::GetShader (FogMode fog, bool& outResetToNoFog) +{ + int index = 0; + outResetToNoFog = false; + if (fog > kFogDisabled && !m_SourceForFog.empty()) + { + Assert (fog >= 0 && fog < kFogModeCount); + + if (m_Shaders[fog]) + { + // already have patched fog shader + index = fog; + } + else if (!(m_FogFailed & (1<<fog))) + { + // patch fog shader on demand + std::string src = m_SourceForFog; + + if (PatchVertexShaderFogD3D9 (src)) + { + // assemble & create the shader + ID3DXBuffer *compiledShader = AssembleD3DShader (src); + if (compiledShader) + { + HRESULT hr = GetD3DDevice()->CreateVertexShader ((const DWORD*)compiledShader->GetBufferPointer(), &m_Shaders[fog]); + compiledShader->Release(); + if (SUCCEEDED(hr)) + { + index = fog; + } + else + { + printf_console ("D3D vertex shader create error for patched fog mode %d shader %s\n", (int)fog, src.c_str()); + } + } + } + } + if (index == 0) + { + outResetToNoFog = true; + m_FogFailed |= (1<<fog); + } + } + return m_Shaders[index]; +} + +// -------------------------------------------------------------------------- + +D3D9PixelShader::D3D9PixelShader( const std::string& source ) +: m_FogFailed(0) +{ + for (int i = 0; i < kFogModeCount; ++i) + { + m_Shaders[i] = NULL; + m_FogRegisters[i] = NULL; + } + m_ImplType = kShaderImplFragment; + if( !Create(source) ) + m_NotSupported = true; +} + +D3D9PixelShader::~D3D9PixelShader () +{ + for (int i = 0; i < kFogModeCount; ++i) + { + if( m_Shaders[i] ) + { + ULONG refCount = m_Shaders[i]->Release(); + AssertIf( refCount != 0 ); + } + } +} + +bool D3D9PixelShader::Create( const std::string& source ) +{ + // fast skip 3.0 shaders on unsupporting hardware + bool isShaderModel3 = !strncmp(source.c_str(), "ps_3_0", 6); + if( gGraphicsCaps.shaderCaps < kShaderLevel3 && isShaderModel3 ) + return false; + + m_GpuProgramLevel = isShaderModel3 ? kGpuProgramSM3 : kGpuProgramSM2; + + HRESULT hr; + IDirect3DDevice9* dev = GetD3DDevice(); + + // assemble shader + ID3DXBuffer *compiledShader = AssembleD3DShader( source ); + if( !compiledShader ) + { + return false; + } + + // create shader + hr = dev->CreatePixelShader( (const DWORD*)compiledShader->GetBufferPointer(), &m_Shaders[0] ); + compiledShader->Release(); + if( FAILED(hr) ) + { + printf_console( "D3D shader create error for shader %s\n", source.c_str() ); + return false; + } + + if (isShaderModel3) + { + m_SourceForFog = source; + } + + return true; +} + +void D3D9PixelShader::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + GfxDevice& device = GetRealGfxDevice(); + IDirect3DDevice9* dev = GetD3DDevice(); + PixelShaderConstantCache& constantCache = GetD3D9PixelShaderConstantCache(); + + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + buffer = ApplyValueParametersD3D9<PixelShaderConstantCache>(constantCache, buffer, valueParams); + + // Apply textures + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for( GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i ) + { + const GpuProgramParameters::TextureParameter& t = *i; + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + ApplyTexEnvData (t.m_Index, t.m_SamplerIndex, *texdata); + buffer += sizeof(*texdata); + } + + // Apply fog parameters if needed + if (!m_SourceForFog.empty()) + { + const GfxFogParams& fog = device.GetFogParams(); + if (fog.mode > kFogDisabled && !(m_FogFailed & (1<<fog.mode))) + { + int reg = m_FogRegisters[fog.mode]; + constantCache.SetValues (reg, fog.color.GetPtr(), 1); + float params[4]; + params[0] = fog.density * 1.2011224087f ; // density / sqrt(ln(2)) + params[1] = fog.density * 1.4426950408f; // density / ln(2) + if (fog.mode == kFogLinear) + { + float diff = fog.end - fog.start; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + params[2] = -invDiff; + params[3] = fog.end * invDiff; + } + else + { + params[2] = 0.0f; + params[3] = 0.0f; + } + constantCache.SetValues (reg+1, params, 1); + } + } +} + +static int FindUnusedConstantRegister (const std::string& src, const GpuProgramParameters& params) +{ + int maxRegisterUsed = -1; + + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + for (GpuProgramParameters::ValueParameterArray::const_iterator it = valueParams.begin(), itEnd = valueParams.end(); it != itEnd; ++it) + { + int idx = it->m_Index + it->m_RowCount - 1; + if (idx > maxRegisterUsed) + maxRegisterUsed = idx; + } + + // Built-ins + const BuiltinShaderParamIndices& builtins = params.GetBuiltinParams(); + for (int i = 0; i < kShaderInstanceMatCount; ++i) + { + int index = builtins.mat[i].gpuIndex; + if (index >= 0 && index + 3 > maxRegisterUsed) + maxRegisterUsed = index + 3; + } + + // Explicit constants in the shader ("def c*") + size_t pos = 0; + const size_t n = src.size(); + while ((pos = src.find("def c", pos)) != std::string::npos) + { + pos += 5; // skip "def c" + int reg = -1; + sscanf(src.c_str() + pos, "%d", ®); + if (reg > maxRegisterUsed) + maxRegisterUsed = reg; + } + + return maxRegisterUsed + 1; +} + +IDirect3DPixelShader9* D3D9PixelShader::GetShader(FogMode fog, const GpuProgramParameters& params) +{ + int index = 0; + if (fog > kFogDisabled && !m_SourceForFog.empty()) + { + Assert (fog >= 0 && fog < kFogModeCount); + + if (m_Shaders[fog]) + { + // already have patched fog shader + index = fog; + } + else if (!(m_FogFailed & (1<<fog))) + { + // patch fog shader on demand + std::string src = m_SourceForFog; + + // find constant register that we'll use to store fog params + int reg = FindUnusedConstantRegister (src, params); + m_FogRegisters[fog] = reg; + + if (PatchPixelShaderFogD3D9 (src, fog, reg, reg+1)) + { + // assemble & create the shader + ID3DXBuffer *compiledShader = AssembleD3DShader (src); + if (compiledShader) + { + HRESULT hr = GetD3DDevice()->CreatePixelShader ((const DWORD*)compiledShader->GetBufferPointer(), &m_Shaders[fog]); + compiledShader->Release(); + if (SUCCEEDED(hr)) + { + index = fog; + } + else + { + printf_console ("D3D pixel shader create error for patched fog mode %d shader %s\n", (int)fog, src.c_str()); + } + } + } + + if (index == 0) + m_FogFailed |= (1<<fog); + } + } + return m_Shaders[index]; +} + + + +// -------------------------------------------------------------------------- + +#if ENABLE_UNIT_TESTS +#include "External/UnitTest++/src/UnitTest++.h" +SUITE (GpuProgramsD3DTests) +{ + +TEST(FindUnusedConstantRegisterCanHandleUnsortedParams) +{ + GpuProgramParameters pp; + pp.AddVectorParam(1,kShaderParamFloat,4,"A",-1,NULL); + pp.AddVectorParam(0,kShaderParamFloat,4,"B",-1,NULL); + pp.MakeReady(); // this does sort, but sorts by name; NOT the GPU index! + CHECK_EQUAL(2,FindUnusedConstantRegister("", pp)); +} + +} // SUITE +#endif // ENABLE_UNIT_TESTS diff --git a/Runtime/GfxDevice/d3d/GpuProgramsD3D.h b/Runtime/GfxDevice/d3d/GpuProgramsD3D.h new file mode 100644 index 0000000..6b21fa9 --- /dev/null +++ b/Runtime/GfxDevice/d3d/GpuProgramsD3D.h @@ -0,0 +1,40 @@ +#pragma once + +#include "D3D9Includes.h" +#include "Runtime/GfxDevice/GpuProgram.h" + + +class D3D9VertexShader : public GpuProgram { +public: + D3D9VertexShader( const std::string& source ); + virtual ~D3D9VertexShader(); + + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); + IDirect3DVertexShader9* GetShader(FogMode fog, bool& outResetToNoFog); + IDirect3DVertexShader9* GetShaderAtFogIndex(FogMode fog) { return m_Shaders[fog]; } + +private: + bool Create( const std::string& source ); + + std::string m_SourceForFog; // original source, used for fog patching if needed + IDirect3DVertexShader9* m_Shaders[kFogModeCount]; + unsigned m_FogFailed; // bit per fog mode +}; + +class D3D9PixelShader : public GpuProgram { +public: + D3D9PixelShader( const std::string& source ); + virtual ~D3D9PixelShader(); + + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); + IDirect3DPixelShader9* GetShader(FogMode fog, const GpuProgramParameters& params); + IDirect3DPixelShader9* GetShaderAtFogIndex(FogMode fog) { return m_Shaders[fog]; } + +private: + bool Create( const std::string& source ); + + std::string m_SourceForFog; // original source, used for fog patching if needed + IDirect3DPixelShader9* m_Shaders[kFogModeCount]; + int m_FogRegisters[kFogModeCount]; + unsigned m_FogFailed; // bit per fog mode +}; diff --git a/Runtime/GfxDevice/d3d/GraphicsCapsD3D9.cpp b/Runtime/GfxDevice/d3d/GraphicsCapsD3D9.cpp new file mode 100644 index 0000000..f1d95c8 --- /dev/null +++ b/Runtime/GfxDevice/d3d/GraphicsCapsD3D9.cpp @@ -0,0 +1,384 @@ +#include "UnityPrefix.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "D3D9Context.h" +#include "Runtime/Utilities/Utility.h" +#include "PlatformDependent/Win/WinDriverUtils.h" +#include "D3D9Utils.h" +#include <Shlwapi.h> + +#define CAPS_DEBUG_DISABLE_RT 0 + + +extern D3DFORMAT kD3D9RenderTextureFormats[kRTFormatCount]; + + +extern D3DDEVTYPE g_D3DDevType; +extern DWORD g_D3DAdapter; + +static bool IsTextureFormatSupported( D3DFORMAT format ) +{ + if( format == D3DFMT_UNKNOWN ) + return false; + HRESULT hr = GetD3DObject()->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), 0, D3DRTYPE_TEXTURE, format ); + return SUCCEEDED( hr ); +} +static bool IsSRGBTextureReadSupported( D3DFORMAT format ) +{ + if( format == D3DFMT_UNKNOWN ) + return false; + HRESULT hr = GetD3DObject()->CheckDeviceFormat (g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_QUERY_SRGBREAD, D3DRTYPE_TEXTURE, format); + return SUCCEEDED( hr ); +} +static bool IsSRGBTextureWriteSupported( D3DFORMAT format ) +{ + if( format == D3DFMT_UNKNOWN ) + return false; + HRESULT hr = GetD3DObject()->CheckDeviceFormat (g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_QUERY_SRGBWRITE, D3DRTYPE_TEXTURE, format); + return SUCCEEDED( hr ); +} +static bool IsRenderTextureFormatSupported( D3DFORMAT format ) +{ + if( format == D3DFMT_UNKNOWN ) + return false; + HRESULT hr = GetD3DObject()->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, format ); + return SUCCEEDED( hr ); +} + +D3DFORMAT GetD3D9TextureFormat( TextureFormat inFormat ); // TexturesD3D9.cpp + + +enum { + kVendorDummyRef = 0x0000, + kVendor3DLabs = 0x3d3d, + kVendorMatrox = 0x102b, + kVendorS3 = 0x5333, + kVendorSIS = 0x1039, + kVendorXGI = 0x18ca, + kVendorIntel = 0x8086, + kVendorATI = 0x1002, + kVendorNVIDIA = 0x10de, + kVendorTrident = 0x1023, + kVendorImgTech = 0x104a, + kVendorVIAS3G = 0x1106, + kVendor3dfx = 0x121a, + kVendorParallels= 0x1ab8, + kVendorMicrosoft= 0x1414, + kVendorVMWare = 0x15ad, +}; +struct KnownVendors { + DWORD vendorId; + const char* name; +}; +static KnownVendors s_KnownVendors[] = { + { kVendorDummyRef, "REFERENCE" }, + { kVendor3DLabs, "3dLabs" }, + { kVendorMatrox, "Matrox" }, + { kVendorS3, "S3" }, + { kVendorSIS, "SIS" }, + { kVendorXGI, "XGI" }, + { kVendorIntel, "Intel" }, + { kVendorATI, "ATI" }, + { kVendorNVIDIA, "NVIDIA" }, + { kVendorTrident, "Trident" }, + { kVendorImgTech, "Imagination Technologies" }, + { kVendorVIAS3G, "VIA/S3" }, + { kVendor3dfx, "3dfx" }, + { kVendorParallels, "Parallels" }, + { kVendorMicrosoft, "Microsoft" }, + { kVendorVMWare, "VMWare" }, +}; +static int kKnownVendorsSize = sizeof(s_KnownVendors)/sizeof(s_KnownVendors[0]); + + +void GraphicsCaps::InitD3D9() +{ + IDirect3D9* d3dobject = GetD3DObject(); + d3dobject->GetDeviceCaps( g_D3DAdapter, g_D3DDevType, &d3d.d3dcaps ); + + // get renderer, vendor & driver information + D3DADAPTER_IDENTIFIER9 adapterInfo; + d3dobject->GetAdapterIdentifier( g_D3DAdapter, 0, &adapterInfo ); + adapterInfo.Driver[MAX_DEVICE_IDENTIFIER_STRING-1] = 0; + adapterInfo.Description[MAX_DEVICE_IDENTIFIER_STRING-1] = 0; + adapterInfo.DeviceName[31] = 0; + rendererString = adapterInfo.Description; + + if (g_D3DDevType == D3DDEVTYPE_REF) + { + adapterInfo.VendorId = kVendorDummyRef; + rendererString = "REF on " + rendererString; + } + + int i; + for( i = 0; i < kKnownVendorsSize; ++i ) + { + if( s_KnownVendors[i].vendorId == adapterInfo.VendorId ) + { + vendorString = s_KnownVendors[i].name; + break; + } + } + if( i == kKnownVendorsSize ) + { + vendorString = Format( "Unknown (ID=%x)", adapterInfo.VendorId ); + } + windriverutils::VersionInfo driverVersion( HIWORD(adapterInfo.DriverVersion.HighPart), LOWORD(adapterInfo.DriverVersion.HighPart), + HIWORD(adapterInfo.DriverVersion.LowPart), LOWORD(adapterInfo.DriverVersion.LowPart) ); + driverVersionString = Format( "%s %i.%i.%i.%i", adapterInfo.Driver, + HIWORD(adapterInfo.DriverVersion.HighPart), LOWORD(adapterInfo.DriverVersion.HighPart), + HIWORD(adapterInfo.DriverVersion.LowPart), LOWORD(adapterInfo.DriverVersion.LowPart) ); + driverLibraryString = driverVersionString; + fixedVersionString = "Direct3D 9.0c [" + driverVersionString + ']'; + + rendererID = adapterInfo.DeviceId; + vendorID = adapterInfo.VendorId; + + // We can't use GetAvailableTextureMem here because the device is not created yet! + // And besides that, it would return much more than VRAM on Vista (virtualization and so on). + // Use WMI instead. + int vramMB; + const char* vramMethod = ""; + if (g_D3DDevType != D3DDEVTYPE_REF) + vramMB = windriverutils::GetVideoMemorySizeMB (d3dobject->GetAdapterMonitor(g_D3DAdapter), &vramMethod); + else + vramMB = 128; + videoMemoryMB = vramMB; + + // On windows, we always output D3D info. There is so much variety that it always helps! + printf_console( "Direct3D:\n" ); + printf_console( " Version: %s\n", fixedVersionString.c_str() ); + printf_console( " Renderer: %s\n", rendererString.c_str() ); + printf_console( " Vendor: %s\n", vendorString.c_str() ); + printf_console( " VRAM: %i MB (via %s)\n", (int)videoMemoryMB, vramMethod ); + + maxVSyncInterval = 0; + if( d3d.d3dcaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE ) + { + maxVSyncInterval = 1; + if( d3d.d3dcaps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO ) + maxVSyncInterval = 2; + } + + DWORD declTypesFloat16 = D3DDTCAPS_FLOAT16_2 | D3DDTCAPS_FLOAT16_4; + has16BitFloatVertex = (d3d.d3dcaps.DeclTypes & declTypesFloat16) == declTypesFloat16; + needsToSwizzleVertexColors = true; + + bool usesSoftwareVP = !(d3d.d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT); + if( usesSoftwareVP ) + maxLights = 8; // software T&L always has 8 lights + else + maxLights = clamp<unsigned int>( d3d.d3dcaps.MaxActiveLights, 0, 8 ); + + // Texture sizes + maxTextureSize = std::min( d3d.d3dcaps.MaxTextureWidth, d3d.d3dcaps.MaxTextureHeight ); + maxRenderTextureSize = maxTextureSize; + maxCubeMapSize = maxTextureSize; + + has3DTexture = d3d.d3dcaps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP; + maxTexUnits = d3d.d3dcaps.MaxSimultaneousTextures; + maxTexImageUnits = 16; + maxTexCoords = d3d.d3dcaps.MaxSimultaneousTextures; + if (maxTexCoords > 8) + maxTexCoords = 8; + + // In theory, vertex texturing is texture format dependent. However, in practice the caps lie, + // especially on NVIDIA hardware. + // + // ATI cards: all DX10+ GPUs report all texture formats as vertex texture capable (good!) + // Intel cards: all SM3.0+ GPUs report all texture formats as vertex texture capable (good!) + // NV cards: all DX10+ GPUs report only floating point formats as capable, but all others actually work as well. + // GeForce 6&7 only report R32F and A32R32G32B32F, and only those work. + // + // So we check for R16F support; this will return true on all GPUs that can handle ALL + // texture formats. + hasVertexTextures = ((LOWORD(d3d.d3dcaps.VertexShaderVersion) >= (3<<8)+0)) && + SUCCEEDED(d3dobject->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F)); + + hasAnisoFilter = d3d.d3dcaps.RasterCaps & D3DPRASTERCAPS_ANISOTROPY; + maxAnisoLevel = hasAnisoFilter ? d3d.d3dcaps.MaxAnisotropy : 1; + hasMipLevelBias = d3d.d3dcaps.RasterCaps & D3DPRASTERCAPS_MIPMAPLODBIAS; + + for( i = 0; i < kTexFormatPCCount; ++i ) + { + d3d.hasBaseTextureFormat[i] = IsTextureFormatSupported( GetD3D9TextureFormat( static_cast<TextureFormat>(i) ) ); + supportsTextureFormat[i] = d3d.hasBaseTextureFormat[i]; + } + + hasS3TCCompression = IsTextureFormatSupported(D3DFMT_DXT1) && IsTextureFormatSupported(D3DFMT_DXT3) && IsTextureFormatSupported(D3DFMT_DXT5); + d3d.hasTextureFormatA8 = IsTextureFormatSupported(D3DFMT_A8); + d3d.hasTextureFormatL8 = IsTextureFormatSupported(D3DFMT_L8); + d3d.hasTextureFormatA8L8 = IsTextureFormatSupported(D3DFMT_A8L8); + d3d.hasTextureFormatL16 = IsTextureFormatSupported(D3DFMT_L16); + + if (!(d3d.d3dcaps.TextureCaps & D3DPTEXTURECAPS_POW2)) + npot = kNPOTFull; + else if (d3d.d3dcaps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL) + npot = kNPOTRestricted; + else + npot = kNPOTNone; + + npotRT = npot; + + hasSRGBReadWrite = + IsSRGBTextureReadSupported(GetD3D9TextureFormat(static_cast<TextureFormat>(kTexFormatRGB24))) + && IsSRGBTextureReadSupported(GetD3D9TextureFormat(static_cast<TextureFormat>(kTexFormatRGBA32))) + && IsSRGBTextureReadSupported(GetD3D9TextureFormat(static_cast<TextureFormat>(kTexFormatARGB32))) + && IsSRGBTextureReadSupported(GetD3D9TextureFormat(static_cast<TextureFormat>(kTexFormatBGR24))) + && IsSRGBTextureReadSupported(GetD3D9TextureFormat(static_cast<TextureFormat>(kTexFormatDXT1))) + && IsSRGBTextureReadSupported(GetD3D9TextureFormat(static_cast<TextureFormat>(kTexFormatDXT3))) + && IsSRGBTextureReadSupported(GetD3D9TextureFormat(static_cast<TextureFormat>(kTexFormatDXT5))); + + // we only do sRGB writes to an 8 bit buffer ... + hasSRGBReadWrite = hasSRGBReadWrite && IsSRGBTextureWriteSupported(D3DFMT_A8R8G8B8); + + hasInstancing = false; //@TODO: instancing! + + hasBlendSquare = (d3d.d3dcaps.SrcBlendCaps & D3DPBLENDCAPS_SRCCOLOR) && (d3d.d3dcaps.DestBlendCaps & D3DPBLENDCAPS_DESTCOLOR); + hasSeparateAlphaBlend = d3d.d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND; + hasBlendSub = hasBlendMinMax = d3d.d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_BLENDOP; + + hasAutoMipMapGeneration = d3d.d3dcaps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP; + + for (int i = 0; i < kRTFormatCount; ++i) + { + if (i == kRTFormatDefault || i == kRTFormatDefaultHDR || i == kRTFormatShadowMap) + continue; + supportsRenderTextureFormat[i] = IsRenderTextureFormatSupported(kD3D9RenderTextureFormats[i]); + } + hasRenderToTexture = supportsRenderTextureFormat[kRTFormatARGB32]; + supportsRenderTextureFormat[kRTFormatDefault] = hasRenderToTexture; + + hasRenderToCubemap = hasRenderToTexture; + hasStencil = true; + hasRenderTargetStencil = true; + hasTwoSidedStencil = d3d.d3dcaps.StencilCaps & D3DSTENCILCAPS_TWOSIDED; + maxMRTs = clamp<int> (d3d.d3dcaps.NumSimultaneousRTs, 1, kMaxSupportedRenderTargets); + if (!(d3d.d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING)) + maxMRTs = 1; + + d3d.hasATIDepthFormat16 = SUCCEEDED( d3dobject->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, kD3D9FormatDF16 ) ); + supportsRenderTextureFormat[kRTFormatDepth] |= d3d.hasATIDepthFormat16; + d3d.hasNVDepthFormatINTZ = SUCCEEDED( d3dobject->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, kD3D9FormatINTZ ) ); + supportsRenderTextureFormat[kRTFormatDepth] |= d3d.hasNVDepthFormatINTZ; + d3d.hasNVDepthFormatRAWZ = SUCCEEDED( d3dobject->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, kD3D9FormatRAWZ ) ); + d3d.hasNULLFormat = SUCCEEDED( d3dobject->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, kD3D9FormatNULL ) ); + d3d.hasDepthResolveRESZ = SUCCEEDED( d3dobject->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, kD3D9FormatRESZ ) ); + + hasNativeDepthTexture = d3d.hasATIDepthFormat16 || d3d.hasNVDepthFormatINTZ; + hasStencilInDepthTexture = d3d.hasNVDepthFormatINTZ; + hasNativeShadowMap = SUCCEEDED( d3dobject->CheckDeviceFormat( g_D3DAdapter, g_D3DDevType, GetD3DFormatForChecks(), D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, D3DFMT_D16 ) ); + supportsRenderTextureFormat[kRTFormatShadowMap] = hasRenderToTexture && hasNativeShadowMap; + + #if CAPS_DEBUG_DISABLE_RT + hasRenderToTexture = hasRenderToCubemap = false; + for (int i = 0; i < kRTFormatCount; ++i) + supportsRenderTextureFormat[i] = false; + maxMRTs = 1; + #endif + + // This is somewhat dummy; actual resolving of FSAA levels and types supported happens later when choosing presentation parameters. + hasMultiSample = true; + + // Driver bugs/workarounds following + DetectDriverBugsD3D9( adapterInfo.VendorId, driverVersion ); + + // safeguards + maxRenderTextureSize = std::min( maxRenderTextureSize, maxTextureSize ); + maxCubeMapSize = std::min( maxCubeMapSize, maxTextureSize ); + + // in the very end, figure out shader capabilities level (after all workarounds are applied) + if( LOWORD(d3d.d3dcaps.PixelShaderVersion) < (3<<8)+0 ) + { + // no ps3.0: 2.x shaders + shaderCaps = kShaderLevel2; + } + else + { + // has everything we care about! + shaderCaps = kShaderLevel3; + } + + // Print overall caps & D3D9 hacks used + printf_console( " Caps: Shader=%i DepthRT=%i NativeDepth=%i NativeShadow=%i DF16=%i INTZ=%i RAWZ=%i NULL=%i RESZ=%i SlowINTZ=%i\n", + shaderCaps, + supportsRenderTextureFormat[kRTFormatDepth], hasNativeDepthTexture, hasNativeShadowMap, + d3d.hasATIDepthFormat16, + d3d.hasNVDepthFormatINTZ, d3d.hasNVDepthFormatRAWZ, + d3d.hasNULLFormat, d3d.hasDepthResolveRESZ, + d3d.slowINTZSampling + ); +} + + +enum WindowsVersion { + kWindows2000 = 50, // 5.0 + kWindowsXP = 51, // 5.1 + kWindows2003 = 52, // 5.2 + kWindowsVista = 60, // 6.0 +}; + +static int GetWindowsVersion() +{ + OSVERSIONINFO osinfo; + osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if( !GetVersionEx(&osinfo) ) + return 0; + + if( osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) + return osinfo.dwMajorVersion * 10 + osinfo.dwMinorVersion % 10; + else + return 0; +} + + +void GraphicsCaps::DetectDriverBugsD3D9( UInt32 vendorCode, const windriverutils::VersionInfo& driverVersion ) +{ + d3d.slowINTZSampling = false; + + + if( vendorCode == kVendorNVIDIA ) + { + // GeForceFX and earlier have sort-of-buggy render to cubemap. E.g. skybox draws correctly, + // but objects do not appear. Huh. + const int kShaderVersion30 = (3 << 8) + 0; + bool isFXOrEarlier = LOWORD(gGraphicsCaps.d3d.d3dcaps.PixelShaderVersion) < kShaderVersion30; + if( isFXOrEarlier ) + { + printf_console( "D3D: disabling render to cubemap on pre-GeForce6\n" ); + buggyCameraRenderToCubemap = true; + } + + // Also, native shadow maps seem to have problems on GeForce FX; perhaps it needs to use tex2Dproj instead of tex2D, + // or something (FX 5200). Since FX cards are really dying, and the only left ones are FX 5200/5500, + // let's just turn shadows off. You don't want them on those cards anyway! + if (isFXOrEarlier) + { + printf_console ("D3D: disabling shadows on pre-GeForce6\n"); + hasNativeShadowMap = false; + hasNativeDepthTexture = false; + supportsRenderTextureFormat[kRTFormatDepth] = false; + } + + // GeForceFX on 6.14.10.9147 drivers has buggy fullscreen FSAA. + // It displays everything stretched, as if AA samples map to pixels directly. + if( isFXOrEarlier && driverVersion <= windriverutils::VersionInfo(6,14,10,9147) ) + { + printf_console( "D3D: disabling fullscreen AA (buggy pre-GeForce6 driver)\n" ); + buggyFullscreenFSAA = true; + } + } + if( vendorCode == kVendorATI ) + { + // On D3D9 Radeon HD cards have big performance hit when using INTZ texture for both sampling & depth testing + // (Radeon HD 3xxx-5xxx, Catalyst 9.10 to 10.5). Talking with AMD, we found that using RESZ to copy it into a separate + // texture is a decent workaround that results in ok performance. + if (d3d.hasDepthResolveRESZ) + d3d.slowINTZSampling = true; + } + + // Sanitize VRAM amount + if( videoMemoryMB < 32 ) { + printf_console("D3D: VRAM amount suspiciously low (less than 32MB)\n"); + videoMemoryMB = 32; + } +} diff --git a/Runtime/GfxDevice/d3d/RenderTextureD3D.cpp b/Runtime/GfxDevice/d3d/RenderTextureD3D.cpp new file mode 100644 index 0000000..0d444b3 --- /dev/null +++ b/Runtime/GfxDevice/d3d/RenderTextureD3D.cpp @@ -0,0 +1,583 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Graphics/ScreenManager.h" +#include "Runtime/Graphics/Image.h" +#include "D3D9Context.h" +#include "TexturesD3D9.h" +#include "RenderTextureD3D.h" +#include "D3D9Utils.h" + + +// defined in GfxDeviceD3D9.cpp +void UnbindTextureD3D9( TextureID texture ); + + +// define to 1 to print lots of activity info +#define DEBUG_RENDER_TEXTURES 0 + + +D3DFORMAT kD3D9RenderTextureFormats[kRTFormatCount] = { + D3DFMT_A8R8G8B8, + D3DFMT_R32F, // Depth + D3DFMT_A16B16G16R16F, + D3DFMT_D16, // Shadowmap + D3DFMT_R5G6B5, + D3DFMT_A4R4G4B4, + D3DFMT_A1R5G5B5, + (D3DFORMAT)-1, // Default + D3DFMT_A2R10G10B10, + (D3DFORMAT)-1, // DefaultHDR + D3DFMT_A16B16G16R16, + D3DFMT_A32B32G32R32F, + D3DFMT_G32R32F, + D3DFMT_G16R16F, + D3DFMT_R32F, + D3DFMT_R16F, + D3DFMT_L8, // R8 + (D3DFORMAT)-1, // ARGBInt + (D3DFORMAT)-1, // RGInt + (D3DFORMAT)-1, // RInt + (D3DFORMAT)-1, // BGRA32 +}; + + +static D3DMULTISAMPLE_TYPE FindSupportedD3DMultiSampleType (D3DFORMAT d3dformat, int maxSamples) +{ + BOOL windowed = !GetScreenManager().IsFullScreen(); + for (int samples = maxSamples; samples >= 1; samples--) + { + D3DMULTISAMPLE_TYPE msaa = GetD3DMultiSampleType( samples ); + HRESULT hr = GetD3DObject()->CheckDeviceMultiSampleType( g_D3DAdapter, g_D3DDevType, d3dformat, windowed, msaa, NULL ); + if (SUCCEEDED(hr)) + return msaa; + } + return D3DMULTISAMPLE_NONE; +} + +static bool InitD3DRenderColorSurface (RenderColorSurfaceD3D9& rs, TexturesD3D9& textures) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + + HRESULT hr; + DWORD usage; + + if (rs.textureID.m_ID) + { + // Regular render texture + usage = D3DUSAGE_RENDERTARGET; + int mipCount = 1; + if (rs.flags & kSurfaceCreateMipmap && !IsDepthRTFormat(rs.format)) + { + Assert(gGraphicsCaps.hasAutoMipMapGeneration); + if (rs.flags & kSurfaceCreateAutoGenMips) + usage |= D3DUSAGE_AUTOGENMIPMAP; + else + mipCount = CalculateMipMapCount3D (rs.width, rs.height, 1); + } + if (rs.dim == kTexDim2D) + { + IDirect3DTexture9* rt; + D3DFORMAT d3dformat = D3DFMT_UNKNOWN; + d3dformat = kD3D9RenderTextureFormats[rs.format]; + hr = dev->CreateTexture (rs.width, rs.height, mipCount, usage, d3dformat, D3DPOOL_DEFAULT, &rt, NULL); + if( FAILED(hr) ) + { + ErrorString( Format( "RenderTexture creation error: CreateTexture failed [%s]", GetD3D9Error(hr) ) ); + return false; + } + rs.m_Texture = rt; + rt->GetSurfaceLevel( 0, &rs.m_Surface ); + } + else if (rs.dim == kTexDimCUBE) + { + Assert(rs.width == rs.height); + IDirect3DCubeTexture9* rt; + hr = dev->CreateCubeTexture (rs.width, mipCount, usage, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &rt, NULL); + if( FAILED(hr) ) + { + ErrorString( Format( "RenderTexture creation error: CreateCubeTexture failed [%s]", GetD3D9Error(hr) ) ); + return false; + } + rs.m_Texture = rt; + } + else + { + ErrorString("RenderTexture creation error: D3D9 only supports 2D or CUBE textures"); + return false; + } + } + else + { + D3DFORMAT d3dformat = D3DFMT_UNKNOWN; + D3DMULTISAMPLE_TYPE msaa = D3DMULTISAMPLE_NONE; + if (!(rs.flags & kSurfaceCreateNeverUsed)) + { + // Create surface without texture to resolve from + // Find supported MSAA type based on device and format + d3dformat = kD3D9RenderTextureFormats[rs.format]; + msaa = FindSupportedD3DMultiSampleType( d3dformat, rs.samples ); + } + else + { + // Dummy render target surface (only needed to make D3D runtime happy) + d3dformat = gGraphicsCaps.d3d.hasNULLFormat ? kD3D9FormatNULL : D3DFMT_A8R8G8B8; + } + IDirect3DSurface9* ds = NULL; + hr = dev->CreateRenderTarget( rs.width, rs.height, d3dformat, msaa, 0, FALSE, &ds, NULL ); + if (FAILED(hr)) + { + ErrorString( Format( "RenderTexture creation error: CreateRenderTarget failed [%s]", GetD3D9Error(hr) ) ); + return false; + } + rs.m_Surface = ds; + } + + // add to textures map + if (rs.textureID.m_ID) + textures.AddTexture( rs.textureID, rs.m_Texture ); + + return true; +} + +static bool InitD3DRenderDepthSurface (RenderDepthSurfaceD3D9& rs, TexturesD3D9& textures) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + + HRESULT hr; + + if (!rs.textureID.m_ID) + { + // Create depth buffer surface + if( rs.depthFormat == kDepthFormatNone ) + { + rs.m_Surface = NULL; + } + else + { + // Create surface without texture to resolve from + // Find supported MSAA type based on device and format + D3DFORMAT d3dformat = (rs.depthFormat == kDepthFormat16 ? D3DFMT_D16 : D3DFMT_D24S8); + D3DMULTISAMPLE_TYPE msaa = FindSupportedD3DMultiSampleType( d3dformat, rs.samples ); + hr = dev->CreateDepthStencilSurface( rs.width, rs.height, d3dformat, msaa, 0, TRUE, &rs.m_Surface, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(rs.m_Surface, rs.width * rs.height * GetBPPFromD3DFormat(d3dformat), &rs); + if( FAILED(hr) ) + { + ErrorString( Format( "RenderTexture creation error: CreateDepthStencilSurface failed [%s]", GetD3D9Error(hr) ) ); + return false; + } + } + } + else + { + // Create depth buffer as texture + D3DFORMAT d3dformat = D3DFMT_UNKNOWN; + if (rs.flags & kSurfaceCreateShadowmap) + { + Assert (rs.depthFormat == kDepthFormat16); + Assert (gGraphicsCaps.hasNativeShadowMap); + d3dformat = D3DFMT_D16; + } + else + { + Assert (gGraphicsCaps.hasNativeDepthTexture); + if (gGraphicsCaps.d3d.hasNVDepthFormatINTZ) + d3dformat = kD3D9FormatINTZ; + else if (gGraphicsCaps.d3d.hasATIDepthFormat16) + d3dformat = kD3D9FormatDF16; + else + { + AssertString ("No available native depth format"); + } + } + IDirect3DTexture9* texture = NULL; + hr = dev->CreateTexture (rs.width, rs.height, 1, D3DUSAGE_DEPTHSTENCIL, d3dformat, D3DPOOL_DEFAULT, &texture, NULL); + if( FAILED(hr) ) + { + ErrorString( Format( "RenderTexture creation error: CreateTexture failed [%s]", GetD3D9Error(hr) ) ); + return false; + } + rs.m_Texture = texture; + texture->GetSurfaceLevel (0, &rs.m_Surface); + } + + if (rs.textureID.m_ID) + textures.AddTexture( rs.textureID, rs.m_Texture ); + + return true; +} + + +static RenderColorSurfaceD3D9* s_ActiveColorTargets[kMaxSupportedRenderTargets]; +static int s_ActiveColorTargetCount; +static RenderDepthSurfaceD3D9* s_ActiveDepthTarget = NULL; +static int s_ActiveMip = 0; +static CubemapFace s_ActiveFace = kCubeFaceUnknown; + +static RenderColorSurfaceD3D9* s_ActiveColorBackBuffer = NULL; +static RenderDepthSurfaceD3D9* s_ActiveDepthBackBuffer = NULL; + +// on dx editor we can switch swapchain underneath +// so lets do smth like gl's default FBO +// it will be used only from "user" code and we will select proper swap chain here +static RenderColorSurfaceD3D9* s_DummyColorBackBuffer = NULL; +static RenderDepthSurfaceD3D9* s_DummyDepthBackBuffer = NULL; + +RenderSurfaceBase* DummyColorBackBuferD3D9() +{ + if(s_DummyColorBackBuffer == 0) + { + static RenderColorSurfaceD3D9 __bb; + RenderSurfaceBase_InitColor(__bb); + __bb.backBuffer = true; + + s_DummyColorBackBuffer = &__bb; + } + return s_DummyColorBackBuffer; +} + +RenderSurfaceBase* DummyDepthBackBuferD3D9() +{ + if(s_DummyDepthBackBuffer == 0) + { + static RenderDepthSurfaceD3D9 __bb; + RenderSurfaceBase_InitDepth(__bb); + __bb.backBuffer = true; + + s_DummyDepthBackBuffer = &__bb; + } + return s_DummyDepthBackBuffer; +} + +bool SetRenderTargetD3D9 (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, int& outRenderTargetWidth, int& outRenderTargetHeight, bool& outIsBackBuffer) +{ + RenderColorSurfaceD3D9* rcolorZero = reinterpret_cast<RenderColorSurfaceD3D9*>(colorHandles[0].object); + RenderDepthSurfaceD3D9* rdepth = reinterpret_cast<RenderDepthSurfaceD3D9*>( depthHandle.object ); + + #if DEBUG_RENDER_TEXTURES + printf_console( "RT: SetRenderTargetD3D9 color=%i depth=%i (%x) mip=%i face=%i\n", + rcolorZero ? rcolorZero->textureID.m_ID : 0, + rdepth ? rdepth->textureID.m_ID : 0, rdepth ? rdepth->m_Surface : 0, + mipLevel, face ); + #endif + + outIsBackBuffer = false; + + if (count == s_ActiveColorTargetCount && s_ActiveDepthTarget == rdepth && s_ActiveMip == mipLevel && s_ActiveFace == face) + { + bool colorsSame = true; + for (int i = 0; i < count; ++i) + { + if (s_ActiveColorTargets[i] != reinterpret_cast<RenderColorSurfaceD3D9*>(colorHandles[i].object)) + colorsSame = false; + } + if (colorsSame) + return false; + } + + IDirect3DDevice9* dev = GetD3DDeviceNoAssert(); + // Happens at startup, when deleting all RenderTextures + if( !dev ) + { + Assert (!rcolorZero && !rdepth); + return false; + } + + HRESULT hr = S_FALSE; + + Assert(colorHandles[0].IsValid() && depthHandle.IsValid()); + Assert(rcolorZero->backBuffer == rdepth->backBuffer); + + outIsBackBuffer = rcolorZero->backBuffer; + if (!outIsBackBuffer) + GetRealGfxDevice().GetFrameStats().AddRenderTextureChange(); // stats + + if(rcolorZero->backBuffer && rcolorZero == s_DummyColorBackBuffer) + colorHandles[0].object = rcolorZero = s_ActiveColorBackBuffer; + if(rdepth->backBuffer && rdepth == s_DummyDepthBackBuffer) + depthHandle.object = rdepth = s_ActiveDepthBackBuffer; + + + // color surfaces + for (int i = 0; i < count; ++i) + { + RenderColorSurfaceD3D9* rcolor = reinterpret_cast<RenderColorSurfaceD3D9*>(colorHandles[i].object); + if(rcolor) + { + // color surface + Assert (rcolor->colorSurface); + // Make sure this texture is not used when setting it as render target + if (rcolor->textureID.m_ID) + UnbindTextureD3D9( rcolor->textureID ); + + // Set color surface + IDirect3DSurface9* surface = NULL; + bool needsRelease = false; + if( !rcolor->m_Texture ) + { + Assert (rcolor->m_Surface); + surface = rcolor->m_Surface; + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: color buffer plain\n" ); + #endif + } + else if (rcolor->dim == kTexDimCUBE) + { + Assert (rcolor->m_Texture); + IDirect3DCubeTexture9* rt = static_cast<IDirect3DCubeTexture9*>( rcolor->m_Texture ); + hr = rt->GetCubeMapSurface((D3DCUBEMAP_FACES)(D3DCUBEMAP_FACE_POSITIVE_X + clamp<int>(face,0,5)), mipLevel, &surface); + needsRelease = true; + } + else + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: color buffer texture %i\n", rcolor->textureID.m_ID ); + #endif + Assert (rcolor->m_Texture); + IDirect3DTexture9* rt = static_cast<IDirect3DTexture9*>( rcolor->m_Texture ); + hr = rt->GetSurfaceLevel (mipLevel, &surface); + needsRelease = true; + } + + if( surface ) + { + hr = dev->SetRenderTarget (i, surface); + if( FAILED(hr) ) { + ErrorString( Format("RenderTexture error: failed to set render target [%s]", GetD3D9Error(hr)) ); + } + if (needsRelease) + surface->Release(); + } + else + { + ErrorString( Format("RenderTexture error: failed to retrieve color surface [%s]", GetD3D9Error(hr)) ); + } + outRenderTargetWidth = rcolor->width; + outRenderTargetHeight = rcolor->height; + } + else + { + hr = dev->SetRenderTarget (i, NULL); + } + } + for (int i = count; i < s_ActiveColorTargetCount; ++i) + { + hr = dev->SetRenderTarget (i, NULL); + } + + + // depth surface + Assert (!rdepth || !rdepth->colorSurface); + + if (rdepth && rdepth->m_Surface) + { + // Make sure this texture is not used when setting it as render target + if (rdepth->textureID.m_ID) + UnbindTextureD3D9( rdepth->textureID ); + + // Set depth surface + if( rdepth->m_Surface ) + { + #if DEBUG_RENDER_TEXTURES + if (rdepth->textureID.m_ID) + printf_console( " RT: depth buffer texture %i\n", rdepth->textureID.m_ID ); + else + printf_console( " RT: depth buffer plain %x\n", rdepth->m_Surface ); + #endif + hr = dev->SetDepthStencilSurface( rdepth->m_Surface ); + if( FAILED(hr) ) { + ErrorString( Format("RenderTexture error: failed to set depth stencil [%s]", GetD3D9Error(hr)) ); + } + g_D3DHasDepthStencil = true; + D3DSURFACE_DESC desc; + desc.Format = D3DFMT_D16; + rdepth->m_Surface->GetDesc( &desc ); + g_D3DDepthStencilFormat = desc.Format; + } + } + else + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: depth buffer none\n" ); + #endif + dev->SetDepthStencilSurface( NULL ); + g_D3DHasDepthStencil = false; + g_D3DDepthStencilFormat = D3DFMT_UNKNOWN; + } + + for (int i = 0; i < count; ++i) + s_ActiveColorTargets[i] = reinterpret_cast<RenderColorSurfaceD3D9*>(colorHandles[i].object); + s_ActiveColorTargetCount = count; + s_ActiveDepthTarget = rdepth; + s_ActiveFace = face; + s_ActiveMip = mipLevel; + + if (outIsBackBuffer) + { + s_ActiveColorBackBuffer = (RenderColorSurfaceD3D9*)colorHandles[0].object; + s_ActiveDepthBackBuffer = (RenderDepthSurfaceD3D9*)depthHandle.object; + + // we are rendering to "default FBO", so current target is dummy + // as a side effect, if we change swap chain, it will be set correctly, and active remain valid + s_ActiveColorTargets[0] = s_DummyColorBackBuffer; + s_ActiveDepthTarget = s_DummyDepthBackBuffer; + } + return true; +} + +RenderSurfaceHandle GetActiveRenderColorSurfaceD3D9(int index) +{ + return RenderSurfaceHandle(s_ActiveColorTargets[index]); +} +RenderSurfaceHandle GetActiveRenderDepthSurfaceD3D9() +{ + return RenderSurfaceHandle(s_ActiveDepthTarget); +} + +bool IsActiveRenderTargetWithColorD3D9() +{ + return !s_ActiveColorTargets[0] || s_ActiveColorTargets[0]->backBuffer || !(s_ActiveColorTargets[0]->flags & kSurfaceCreateNeverUsed); +} + + +RenderSurfaceHandle CreateRenderColorSurfaceD3D9( TextureID textureID, int width, int height, int samples, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, TexturesD3D9& textures ) +{ + RenderSurfaceHandle rsHandle; + + if( !gGraphicsCaps.hasRenderToTexture ) + return rsHandle; + if( !gGraphicsCaps.supportsRenderTextureFormat[format] ) + return rsHandle; + + RenderColorSurfaceD3D9* rs = new RenderColorSurfaceD3D9; + rs->width = width; + rs->height = height; + rs->samples = samples; + rs->format = format; + rs->textureID = textureID; + rs->dim = dim; + rs->flags = createFlags; + + // Create it + if (!InitD3DRenderColorSurface(*rs, textures)) + { + delete rs; + return rsHandle; + } + + rsHandle.object = rs; + return rsHandle; +} + +RenderSurfaceHandle CreateRenderDepthSurfaceD3D9( TextureID textureID, int width, int height, int samples, DepthBufferFormat depthFormat, UInt32 createFlags, TexturesD3D9& textures ) +{ + RenderSurfaceHandle rsHandle; + + if( !gGraphicsCaps.hasRenderToTexture ) + return rsHandle; + + RenderDepthSurfaceD3D9* rs = new RenderDepthSurfaceD3D9; + rs->width = width; + rs->height = height; + rs->samples = samples; + rs->depthFormat = depthFormat; + rs->textureID = textureID; + rs->flags = createFlags; + + // Create it + if (!InitD3DRenderDepthSurface( *rs, textures)) + { + delete rs; + return rsHandle; + } + + rsHandle.object = rs; + return rsHandle; +} + + +void DestroyRenderSurfaceD3D9 (RenderSurfaceD3D9* rs) +{ + Assert(rs); + + if(rs == s_ActiveColorBackBuffer || rs == s_ActiveDepthBackBuffer) + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: Destroying main %s buffer.\n", s == s_ActiveColorBackBuffer ? "color" : "depth" ); + #endif + s_ActiveColorBackBuffer = NULL; + s_ActiveDepthBackBuffer = NULL; + } + + RenderSurfaceHandle defaultColor(s_DummyColorBackBuffer); + RenderSurfaceHandle defaultDepth(s_DummyDepthBackBuffer); + + if (s_ActiveDepthTarget == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + int targetWidth, targetHeight; + bool isBackBuffer; + SetRenderTargetD3D9 (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, targetWidth, targetHeight, isBackBuffer); + } + for (int i = 0; i < s_ActiveColorTargetCount; ++i) + { + if (s_ActiveColorTargets[i] == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + int targetWidth, targetHeight; + bool isBackBuffer; + SetRenderTargetD3D9 (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, targetWidth, targetHeight, isBackBuffer); + } + } + + if (rs->m_Surface) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(rs->m_Surface); + ULONG refCount = rs->m_Surface->Release(); + Assert(refCount == (rs->m_Texture ? 1 : 0)); + rs->m_Surface = NULL; + } + if( rs->m_Texture ) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(rs->m_Texture); + ULONG refCount = rs->m_Texture->Release(); + Assert(refCount == 0); + rs->m_Texture = NULL; + } +} + +void DestroyRenderSurfaceD3D9 (RenderSurfaceHandle& rsHandle, TexturesD3D9& textures) +{ + if( !rsHandle.IsValid() ) + return; + + RenderSurfaceD3D9* rs = reinterpret_cast<RenderSurfaceD3D9*>( rsHandle.object ); + DestroyRenderSurfaceD3D9( rs ); + + if (rs->m_Texture || rs->textureID.m_ID) + textures.RemoveTexture (rs->textureID); + + delete rs; + rsHandle.object = NULL; +} + + + +// -------------------------------------------------------------------------- + + +#if ENABLE_UNIT_TESTS +#include "External/UnitTest++/src/UnitTest++.h" + +SUITE ( RenderTextureD3DTests ) +{ +TEST(RenderTextureD3DTests_FormatTableCorrect) +{ + // checks that you did not forget to update format table when adding a new format :) + for (int i = 0; i < kRTFormatCount; ++i) + { + CHECK(kD3D9RenderTextureFormats[i] != 0); + } +} +} +#endif diff --git a/Runtime/GfxDevice/d3d/RenderTextureD3D.h b/Runtime/GfxDevice/d3d/RenderTextureD3D.h new file mode 100644 index 0000000..255e89d --- /dev/null +++ b/Runtime/GfxDevice/d3d/RenderTextureD3D.h @@ -0,0 +1,17 @@ +#pragma once + +#include "D3D9Includes.h" + + +RenderSurfaceHandle CreateRenderColorSurfaceD3D9 (TextureID textureID, int width, int height, int samples, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, TexturesD3D9& textures); +RenderSurfaceHandle CreateRenderDepthSurfaceD3D9 (TextureID textureID, int width, int height, int samples, DepthBufferFormat depthFormat, UInt32 createFlags, TexturesD3D9& textures); +void DestroyRenderSurfaceD3D9 (RenderSurfaceD3D9* rs); +void DestroyRenderSurfaceD3D9 (RenderSurfaceHandle& rsHandle, TexturesD3D9& textures); +bool SetRenderTargetD3D9 (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, int& outRenderTargetWidth, int& outRenderTargetHeight, bool& outIsBackBuffer); +RenderSurfaceHandle GetActiveRenderColorSurfaceD3D9(int index); +RenderSurfaceHandle GetActiveRenderDepthSurfaceD3D9(); + +RenderSurfaceHandle GetBackBufferColorSurfaceD3D9(); +RenderSurfaceHandle GetBackBufferDepthSurfaceD3D9(); +void SetBackBufferColorSurfaceD3D9(RenderSurfaceBase* color); +void SetBackBufferDepthSurfaceD3D9(RenderSurfaceBase* depth); diff --git a/Runtime/GfxDevice/d3d/ShaderGenerator.cpp b/Runtime/GfxDevice/d3d/ShaderGenerator.cpp new file mode 100644 index 0000000..b62e5c7 --- /dev/null +++ b/Runtime/GfxDevice/d3d/ShaderGenerator.cpp @@ -0,0 +1,948 @@ +#include "UnityPrefix.h" +#include <stdlib.h> +#include <string> +#include <vector> +#include <algorithm> +#include <assert.h> +#include "ShaderGenerator.h" +#include "Runtime/Utilities/Word.h" + +enum ShaderInputRegister { + kInputPosition, + kInputNormal, + kInputUV0, + kInputUV1, + kInputColor, + kInputCount +}; + +const char* kShaderInputNames[kInputCount] = { + "$IPOS", + "$INOR", + "$IUV0", + "$IUV1", + "$ICOL", +}; + +const char* kShaderInputDecls[kInputCount] = { + "dcl_position", + "dcl_normal", + "dcl_texcoord0", + "dcl_texcoord1", + "dcl_color", +}; + + + +enum ShaderFragmentOptions { + kOptionHasTexMatrix = (1<<0), +}; + +const int kConstantLocations[kConstCount] = { + 0, // kConstMatrixMVP + 4, // kConstMatrixMV + 8, // kConstMatrixMV_IT + 12, // kConstMatrixTexture + 44, // kConstAmbient + 57, // kConstColorMatAmbient + 45, // kConstLightMisc + 46, // kConstMatDiffuse + 47, // kConstMatSpecular + 48, // kConstLightIndexes +}; + +enum CommonDependencies { + kDep_CamSpacePos, + kDep_CamSpaceN, + kDep_ViewVector, + kDep_ReflVector, + kDep_Normal, + kDepCount +}; + + +// -------------------------------------------------------------------------- + +// transform position +const ShaderFragment kVS_Pos = { + (1<<kInputPosition), // input + (1<<kConstMatrixMVP), // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + NULL, // outs + "dp4 oPos.x, $IPOS, c0\n" + "dp4 oPos.y, $IPOS, c1\n" + "dp4 oPos.z, $IPOS, c2\n" + "dp4 oPos.w, $IPOS, c3\n", +}; + +// -------------------------------------------------------------------------- +// temps + +// NORM = vertex normal +const ShaderFragment kVS_Load_Normal = { + (1<<kInputNormal), // input + 0, // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + "NORM", // outs + "mov $O_NORM, $INOR\n" +}; + +// NORM = normalized vertex normal +const ShaderFragment kVS_Normalize_Normal = { + 0, // input + 0, // constants + (1<<kDep_Normal), // deps + 0, // options + 1, // temps + "NORM", // ins + "NORM", // outs + "nrm $TMP0.xyz, $O_NORM\n" + "mov $O_NORM.xyz, $TMP0\n" +}; + + +// OPOS = input position of the vertex +const ShaderFragment kVS_Temp_ObjSpacePos = { + (1<<kInputPosition), // input + 0, // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + "OPOS", // outs + "mov $O_OPOS, $IPOS\n" +}; + +// CPOS = camera space position of the vertex +const ShaderFragment kVS_Temp_CamSpacePos = { + (1<<kInputPosition), // input + (1<<kConstMatrixMV), // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + "CPOS", // outs + "mul $O_CPOS, $IPOS.y, c5\n" + "mad $O_CPOS, c4, $IPOS.x, $O_CPOS\n" + "mad $O_CPOS, c6, $IPOS.z, $O_CPOS\n" + "mad $O_CPOS, c7, $IPOS.w, $O_CPOS\n", +}; + +// CNOR = camera space normal of the vertex +const ShaderFragment kVS_Temp_CamSpaceN = { + 0, // input + (1<<kConstMatrixMV_IT), // constants + (1<<kDep_Normal), // deps + 0, // options + 0, // temps + "NORM", // ins + "CNOR", // outs + "mul $O_CNOR, $O_NORM.y, c9\n" + "mad $O_CNOR, c8, $O_NORM.x, $O_CNOR\n" + "mad $O_CNOR, c10, $O_NORM.z, $O_CNOR\n", +}; + +// VIEW = normalized vertex-to-eye vector +const ShaderFragment kVS_Temp_ViewVector = { + 0, // input + 0, // constants + (1<<kDep_CamSpacePos), // deps + 0, // options + 0, // temps + "CPOS", // ins + "VIEW", // outs + "dp3 $O_VIEW.w, $O_CPOS, $O_CPOS\n" + "rsq $O_VIEW.w, $O_VIEW.w\n" + "mul $O_VIEW, -$O_CPOS, $O_VIEW.w\n", +}; + +// REFL = camera space reflection vector: 2*dot(V,N)*N-V +const ShaderFragment kVS_Temp_CamSpaceRefl = { + 0, // input + 0, // constants + (1<<kDep_CamSpaceN) | (1<<kDep_ViewVector), // deps + 0, // options + 0, // temps + "CNOR VIEW", // ins + "REFL", // outs + "mov $O_REFL.xyz, $O_VIEW\n" + "dp3 $O_REFL.w, $O_REFL, $O_CNOR\n" + "add $O_REFL.w, $O_REFL.w, $O_REFL.w\n" + "mad $O_REFL.xyz, $O_REFL.w, $O_CNOR, -$O_REFL\n" +}; + +// cheap version +// SPHR = sphere map: N*0.5+0.5 +//const ShaderFragment kVS_Temp_SphereMap = { +// 0, // input +// (1<<kConstLightMisc), // constants +// (1<<kDep_CamSpaceN), // deps +// 0, // options +// 0, // temps +// "CNOR", // ins +// "SPHR", // outs +// "mad $O_SPHR.xyz, $O_CNOR, c45.w, c45.w" +//}; + +// SPHR = sphere map. R = reflection vector +// m = 2*sqrt(Rx*Rx + Ry*Ry + (Rz+1)*(Rz+1)) +// SPHR = Rx/m + 0.5, Ry/m + 0.5 +const ShaderFragment kVS_Temp_SphereMap = { + 0, // input + (1<<kConstLightMisc), // constants + (1<<kDep_ReflVector), // deps + 0, // options + 1, // temps + "REFL", // ins + "SPHR", // outs + "mul $TMP0.xy, $O_REFL, $O_REFL\n" // Rx*Rx, Ry*Ry + "add $O_SPHR.w, $TMP0.y, $TMP0.x\n" // Rx*Rx + Ry*Ry + "add $O_SPHR.z, $O_REFL.z, c45.z\n" // Rz+1 + "mad $O_SPHR.z, $O_SPHR.z, $O_SPHR.z, $O_SPHR.w\n" // (Rz+1)*(Rz+1) + Rx*Rx + Ry*Ry + "mul $O_SPHR.z, $O_SPHR.z, c45.y\n" // * 4 + "rsq $O_SPHR.z, $O_SPHR.z\n" // m + "mad $O_SPHR.xy, $O_REFL, $O_SPHR.z, c45.w\n" // R/m+0.5 +}; + +// -------------------------------------------------------------------------- +// Texture coordinates + +const ShaderFragment kVS_Load_UV0 = { + (1<<kInputUV0), // input + 0, // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + "UV0", // outs + "mov $O_UV0, $IUV0\n" +}; + +const ShaderFragment kVS_Load_UV1 = { + (1<<kInputUV1), // input + 0, // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + "UV1", // outs + "mov $O_UV1, $IUV1\n" +}; + +const ShaderFragment kVS_Out_TexCoord = { + 0, // input + 0, // constants + 0, // deps + 0, // options + 0, // temps + "$0", // ins + NULL, // outs + "mov oT$PARAM, $I_0\n" +}; + + +const ShaderFragment kVS_Out_Matrix2 = { + 0, // input + (1<<kConstMatrixTexture), // constants + 0, // deps + kOptionHasTexMatrix, // options + 1, // temps + "$0", // ins + NULL, // outs + "mul $TMP0, $I_0.y, $TMPARAM1\n" + "mad $TMP0, $TMPARAM0, $I_0.x, $TMP0\n" + "add oT$PARAM, $TMPARAM3, $TMP0\n" +}; + +const ShaderFragment kVS_Out_Matrix3 = { + 0, // input + (1<<kConstMatrixTexture), // constants + 0, // deps + kOptionHasTexMatrix, // options + 1, // temps + "$0", // ins + NULL, // outs + "mul $TMP0, $I_0.y, $TMPARAM1\n" + "mad $TMP0, $TMPARAM0, $I_0.x, $TMP0\n" + "mad $TMP0, $TMPARAM2, $I_0.z, $TMP0\n" + "add oT$PARAM, $TMPARAM3, $TMP0\n" +}; + +// -------------------------------------------------------------------------- +// Lighting + +const ShaderFragment kVS_Out_Diffuse_VertexColor= { + (1<<kInputColor), // input + 0, // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + NULL, // outs + "mov oD0, $ICOL\n" +}; + +const ShaderFragment kVS_Light_Diffuse_Pre = { + 0, // input + (1<<kConstLightMisc), // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + "DIFF", // outs + + "mov $O_DIFF, c45.xxxz\n" // diffuse = 0 +}; + +const ShaderFragment kVS_Light_Diffuse_Dir = { + 0, // input + (1<<kConstLightMisc) | (1<<kConstLightIndexes), // constants + (1<<kDep_CamSpaceN), // deps + 0, // options + 1, // temps + "CNOR", // ins + "DIFF", // outs + + "mov $O_CNOR.w, c48.y\n" // CNOR.w is reused as light data index + "rep i1\n" + " mova a0.x, $O_CNOR.w\n" + " dp3 $TMP0.x, $O_CNOR, c61[a0.x]\n" // NdotL + " slt $TMP0.w, c45.x, $TMP0.x\n" // clamp = NdotL > 0 + " mul $TMP0.xyz, $TMP0.x, c62[a0.x]\n" // doff = NdotL * lightColor + " mad $O_DIFF.xyz, $TMP0.w, $TMP0, $O_DIFF\n" // diffuse += diff * clamp + " add $O_CNOR.w, $O_CNOR.w, c45.y\n" // index += 4 + "endrep\n" +}; + +const ShaderFragment kVS_Light_Diffuse_Point = { + 0, // input + (1<<kConstLightMisc) | (1<<kConstLightIndexes), // constants + (1<<kDep_CamSpaceN) | (1<<kDep_CamSpacePos), // deps + 0, // options + 3, // temps + "CNOR CPOS", // ins + "DIFF", // outs + + "mov $O_CNOR.w, c48.z\n" // CNOR.w is reused as light data index + "rep i2\n" + " mova a0.x, $O_CNOR.w\n" + " add $TMP1.xyz, -$O_CPOS, c60[a0.x]\n" // toLight in view space + " dp3 $TMP0.w, $TMP1, $TMP1\n" // lightDirection = normalize(toLight) + " rsq $TMP1.w, $TMP0.w\n" + " mul $TMP1.xyz, $TMP1, $TMP1.w\n" + " dp3 $TMP1.x, $O_CNOR, $TMP1\n" // NdotL + " slt $TMP1.y, c63[a0.x].z, $TMP0.w\n" // range = range2 < toLight2 + " mov $TMP1.z, c45.z\n" // 1 + " mad $TMP0.w, c63[a0.x].w, $TMP0.w, $TMP1.z\n" // 1 + toLight2 * quadAttenuation + " rcp $TMP0.w, $TMP0.w\n" // attenuation + " mad $TMP0.w, $TMP1.y, -$TMP0.w, $TMP0.w\n" // attenuation = 0 if out of range + " sge $TMP1.y, $TMP1.x, c45.x\n" // clamp = NdotL > 0 + " mul $TMP2, $TMP1.x, c62[a0.x]\n" // diff = NdotL * lightColor + " mul $TMP2, $TMP0.w, $TMP2\n" // diff *= attenuation + " mad $O_DIFF.xyz, $TMP1.y, $TMP2, $O_DIFF\n" // diffuse += diff * clamp + " add $O_CNOR.w, $O_CNOR.w, c45.y\n" // index += 4 + "endrep\n" +}; + + + +const ShaderFragment kVS_Light_Diffuse_Spot = { + 0, // input + (1<<kConstLightMisc) | (1<<kConstLightIndexes), // constants + (1<<kDep_CamSpaceN) | (1<<kDep_CamSpacePos), // deps + 0, // options + 3, // temps + "CNOR CPOS", // ins + "DIFF", // outs + + "mov $O_CNOR.w, c48.x\n" // CNOR.w is reused as light data index + "rep i0\n" + " mova a0.x, $O_CNOR.w\n" + " add $TMP1.xyz, -$O_CPOS, c60[a0.x]\n" // toLight in view space + " dp3 $TMP0.w, $TMP1, $TMP1\n" // lightDirection = normalize(toLight) + " rsq $TMP1.w, $TMP0.w\n" + " mul $TMP1.xyz, $TMP1, $TMP1.w\n" + " dp3 $TMP1.w, $O_CNOR, $TMP1\n" // NdotL + " dp3 $TMP1.x, $TMP1, c61[a0.x]\n" // rho = dot(L,lightAxisDirection) + " add $TMP1.x, $TMP1.x, -c63[a0.x].y\n" // rho-cos(phi/2) + " mul $TMP1.x, $TMP1.x, c63[a0.x].x\n" // spotAtten = (rho-cos(phi/2)) / (cos(theta/2)-cos(phi/2)) + " mov $TMP1.z, c45.z\n" // 1 + " mad $TMP1.y, c63[a0.x].w, $TMP0.w, $TMP1.z\n" // 1 + toLight2 * quadAttenuation + " rcp $TMP1.y, $TMP1.y\n" // attenuation + " slt $TMP0.w, c63[a0.x].z, $TMP0.w\n" // range = range2 < toLight2 + " mad $TMP0.w, $TMP0.w, -$TMP1.y, $TMP1.y\n" // attenuation = 0 if out of range + " max $TMP1.x, $TMP1.x, c45.x\n" // spotAtten = saturate(spotAtten) + " min $TMP1.x, $TMP1.x, c45.z\n" + " mul $TMP0.w, $TMP0.w, $TMP1.x\n" // attenuation *= spotAtten + " sge $TMP1.x, $TMP1.w, c45.x\n" // clamp = NdotL > 0 + " mul $TMP2, $TMP1.w, c62[a0.x]\n" // diff = NdotL * lightColor + " mul $TMP2, $TMP0.w, $TMP2\n" // diff *= attenuation + " mad $O_DIFF.xyz, $TMP1.x, $TMP2, $O_DIFF\n" // diffuse += diff * clamp + " add $O_CNOR.w, $O_CNOR.w, c45.y\n" // index += 4 + "endrep\n" +}; + + +const ShaderFragment kVS_Light_Specular_Pre = { + 0, // input + (1<<kConstLightMisc), // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + "DIFF SPEC", // outs + "mov $O_DIFF, c45.xxxz\n" // diffuse = 0 + "mov $O_SPEC, c45.x\n" // specular = 0 +}; + + +const ShaderFragment kVS_Light_Specular_Dir = { + 0, // input + (1<<kConstLightMisc) | (1<<kConstLightIndexes) | (1<<kConstMatSpecular), // constants + (1<<kDep_CamSpaceN) | (1<<kDep_ViewVector), // deps + 0, // options + 2, // temps + "CNOR VIEW", // ins + "DIFF SPEC", // outs + + "mov $O_CNOR.w, c48.y\n" // CNOR.w is reused as light data index + "rep i1\n" + " mova a0.x, $O_CNOR.w\n" + " mov $TMP0.xyz, c61[a0.x]\n" // L = lightDirection + // diffuse + " dp3 $TMP1.x, $O_CNOR, $TMP0\n" // NdotL + " slt $TMP0.w, c45.x, $TMP1.x\n" // clamp = NdotL > 0 + " mul $TMP1, $TMP1.x, c62[a0.x]\n" // diff = NdotL * lightColor + " mad $O_DIFF.xyz, $TMP0.w, $TMP1, $O_DIFF\n" // diffuse += diff * clamp + // spec + " add $TMP0.xyz, $TMP0, $O_VIEW\n" // L + V + " nrm $TMP1.xyz, $TMP0\n" // H = normalize(L + V) + " dp3 $TMP1.w, $TMP1, $O_CNOR\n" // H dot N + " max $TMP1.w, $TMP1.w, c45.x\n" // sp = max(H dot N, 0) + " pow $TMP1.w, $TMP1.w, c47.w\n" // sp = pow(sp, exponent) + " mul $TMP1.w, $TMP1.w, $TMP0.w\n" // sp *= clamp + " mad $O_SPEC.xyz, $TMP1.w, c62[a0.x], $O_SPEC\n" // spec += sp * lightColor + + " add $O_CNOR.w, $O_CNOR.w, c45.y\n" // index += 4 + "endrep\n" +}; + + +const ShaderFragment kVS_Light_Specular_Point = { + 0, // input + (1<<kConstLightMisc) | (1<<kConstLightIndexes) | (1<<kConstMatSpecular), // constants + (1<<kDep_CamSpaceN) | (1<<kDep_CamSpacePos) | (1<<kDep_ViewVector), // deps + 0, // options + 3, // temps + "CNOR CPOS VIEW", // ins + "DIFF SPEC", // outs + + "mov $O_CNOR.w, c48.z\n" // CNOR.w is reused as light data index + "rep i2\n" + " mova a0.x, $O_CNOR.w\n" + " add $TMP1.xyz, -$O_CPOS, c60[a0.x]\n" // toLight in view space + " dp3 $TMP0.w, $TMP1, $TMP1\n" // L = normalize(toLight) + " rsq $TMP1.w, $TMP0.w\n" + " mul $TMP1.xyz, $TMP1, $TMP1.w\n" + // diffuse + " dp3 $TMP0.x, $O_CNOR, $TMP1\n" // NdotL + " slt $TMP0.y, c63[a0.x].z, $TMP0.w\n" // range = range2 < toLight2 + " mov $TMP0.z, c45.z\n" // 1 + " mad $TMP0.w, c63[a0.x].w, $TMP0.w, $TMP0.z\n" // 1 + toLight2 * quadAttenuation + " rcp $TMP0.w, $TMP0.w\n" // attenuation + " mad $TMP0.w, $TMP0.y, -$TMP0.w, $TMP0.w\n" // attenuation = 0 if out of range + " sge $TMP0.y, $TMP0.x, c45.x\n" // clamp = NdotL > 0 + " mul $TMP2, $TMP0.x, c62[a0.x]\n" // diff = NdotL * lightColor + " mul $TMP2, $TMP0.w, $TMP2\n" // diff *= attenuation + " mad $O_DIFF.xyz, $TMP0.y, $TMP2, $O_DIFF\n" // diffuse += diff * clamp + // spec + " add $TMP2.xyz, $TMP1, $O_VIEW\n" // L + V + " nrm $TMP1.xyz, $TMP2\n" // H = normalize(L + V) + " dp3 $TMP1.w, $TMP1, $O_CNOR\n" // H dot N + " max $TMP1.w, $TMP1.w, c45.x\n" // sp = max(H dot N, 0) + " pow $TMP1.w, $TMP1.w, c47.w\n" // sp = pow(sp, exponent) + " mul $TMP1.w, $TMP1.w, $TMP0.w\n" // sp *= attenuation + " mul $TMP1.w, $TMP1.w, $TMP0.y\n" // sp *= clamp + " mad $O_SPEC.xyz, $TMP1.w, c62[a0.x], $O_SPEC\n" // spec += sp * lightColor + + " add $O_CNOR.w, $O_CNOR.w, c45.y\n" // index += 4 + "endrep\n" +}; + +const ShaderFragment kVS_Light_Specular_Spot = { + 0, // input + (1<<kConstLightMisc) | (1<<kConstLightIndexes) | (1<<kConstMatSpecular), // constants + (1<<kDep_CamSpaceN) | (1<<kDep_CamSpacePos) | (1<<kDep_ViewVector), // deps + 0, // options + 3, // temps + "CNOR CPOS VIEW", // ins + "DIFF SPEC", // outs + + "mov $O_CNOR.w, c48.x\n" // CNOR.w is reused as light data index + "rep i0\n" + " mova a0.x, $O_CNOR.w\n" + " add $TMP1.xyz, -$O_CPOS, c60[a0.x]\n" // toLight in view space + " dp3 $TMP0.w, $TMP1, $TMP1\n" // lightDirection = normalize(toLight) + " rsq $TMP1.w, $TMP0.w\n" + " mul $TMP1.xyz, $TMP1, $TMP1.w\n" + // diffuse + " dp3 $TMP1.w, $O_CNOR, $TMP1\n" // NdotL + " dp3 $TMP0.x, $TMP1, c61[a0.x]\n" // rho = dot(L,lightAxisDirection) + " add $TMP0.x, $TMP0.x, -c63[a0.x].y\n" // rho-cos(phi/2) + " mul $TMP0.x, $TMP0.x, c63[a0.x].x\n" // spotAtten = (rho-cos(phi/2)) / (cos(theta/2)-cos(phi/2)) + " mov $TMP0.z, c45.z\n" // 1 + " mad $TMP0.y, c63[a0.x].w, $TMP0.w, $TMP0.z\n" // 1 + toLight2 * quadAttenuation + " rcp $TMP0.y, $TMP0.y\n" // attenuation + " slt $TMP0.w, c63[a0.x].z, $TMP0.w\n" // range = range2 < toLight2 + " mad $TMP0.w, $TMP0.w, -$TMP0.y, $TMP0.y\n" // attenuation = 0 if out of range + " max $TMP0.x, $TMP0.x, c45.x\n" // spotAtten = saturate(spotAtten) + " min $TMP0.x, $TMP0.x, c45.z\n" + " mul $TMP0.w, $TMP0.w, $TMP0.x\n" // attenuation *= spotAtten + " sge $TMP0.x, $TMP1.w, c45.x\n" // clamp = NdotL > 0 + " mul $TMP2, $TMP1.w, c62[a0.x]\n" // diff = NdotL * lightColor + " mul $TMP2, $TMP0.w, $TMP2\n" // diff *= attenuation + " mad $O_DIFF.xyz, $TMP0.x, $TMP2, $O_DIFF\n" // diffuse += diff * clamp + // spec + " add $TMP2.xyz, $TMP1, $O_VIEW\n" // L + V + " nrm $TMP1.xyz, $TMP2\n" // H = normalize(L + V) + " dp3 $TMP1.w, $TMP1, $O_CNOR\n" // H dot N + " max $TMP1.w, $TMP1.w, c45.x\n" // sp = max(H dot N, 0) + " pow $TMP2.x, $TMP1.w, c47.w\n" // sp = pow(sp, exponent) + " mul $TMP2.x, $TMP2.x, $TMP0.w\n" // sp *= attenuation + " mul $TMP2.x, $TMP2.x, $TMP0.x\n" // sp *= clamp + " mad $O_SPEC.xyz, $TMP2.x, c62[a0.x], $O_SPEC\n" // spec += sp * lightColor + + " add $O_CNOR.w, $O_CNOR.w, c45.y\n" // index += 4 + "endrep\n" +}; + + +const ShaderFragment kVS_Out_Diffuse_Lighting = { + 0, // input + (1<<kConstAmbient) | (1<<kConstMatDiffuse) | (1<<kConstLightMisc), // constants + 0, // deps + 0, // options + 0, // temps + "DIFF", // ins + NULL, // outs + "mul $O_DIFF, $O_DIFF, c46\n" // diffuse *= materialDiffuse + "add $O_DIFF.xyz, $O_DIFF, c44\n" // diffuse += ambient + "min oD0, $O_DIFF, c45.z\n" // diffuse = max(diffuse,1) +}; + +const ShaderFragment kVS_Out_Specular_Lighting = { + 0, // input + (1<<kConstMatSpecular) | (1<<kConstLightMisc), // constants + 0, // deps + 0, // options + 0, // temps + "SPEC", // ins + NULL, // outs + "mul $O_SPEC, $O_SPEC, c47\n" // specular *= materialSpecular + "min oD1, $O_SPEC, c45.z\n" // specular = max(specular,1) +}; + +const ShaderFragment kVS_Out_Diffuse_Lighting_ColorDiffuseAmbient = { + (1<<kInputColor), // input + (1<<kConstColorMatAmbient) | (1<<kConstAmbient) | (1<<kConstLightMisc), // constants + 0, // deps + 0, // options + 0, // temps + "DIFF", // ins + NULL, // outs + "mul $O_DIFF, $O_DIFF, $ICOL\n" // diffuse *= vertexColor + "mad $O_DIFF.xyz, $ICOL, c57, $O_DIFF\n" // diffuse += ambient * vertexColor + "add $O_DIFF.xyz, $O_DIFF, c44\n" // diffuse += emissive + "min oD0, $O_DIFF, c45.z\n" // diffuse = max(diffuse,1) +}; + +const ShaderFragment kVS_Out_Diffuse_Lighting_ColorEmission = { + (1<<kInputColor), // input + (1<<kConstAmbient) | (1<<kConstMatDiffuse) | (1<<kConstLightMisc), // constants + 0, // deps + 0, // options + 0, // temps + "DIFF", // ins + NULL, // outs + "mul $O_DIFF, $O_DIFF, c46\n" // diffuse *= materialDiffuse + "add $O_DIFF.xyz, c44, $O_DIFF\n" // diffuse += ambient + "add $O_DIFF, $O_DIFF, $ICOL\n" // diffuse += vertex color + "min oD0, $O_DIFF, c45.z\n" // diffuse = max(diffuse,1) +}; + + +const ShaderFragment kVS_Out_Diffuse_White = { + 0, // input + (1<<kConstLightMisc), // constants + 0, // deps + 0, // options + 0, // temps + NULL, // ins + NULL, // outs + "mov oD0, c45.z\n" +}; + + +// -------------------------------------------------------------------------- + + +static const ShaderFragment* kCommonDependencies[kDepCount] = { + &kVS_Temp_CamSpacePos, + &kVS_Temp_CamSpaceN, + &kVS_Temp_ViewVector, + &kVS_Temp_CamSpaceRefl, + &kVS_Load_Normal, +}; + +static bool IsAlNum( char c ) { + return c=='$' || c>='A' && c<='Z' || c>='0' && c<='9'; +} + +static const char* SkipTokens( const char* p, int count ) { + while( count-- ) { + while( IsAlNum(*p++) ) ; + if( *p == 0 ) + return p; + ++p; + } + return p; +} + +static std::string ExtractToken( const char** text ) { + const char* ptr = *text; + char c = *ptr; + while( IsAlNum(c) ) { + ++ptr; + c = *ptr; + } + + if( ptr == *text ) + return std::string(); + + // result + std::string res(*text, ptr); + + // skip space after result + ++ptr; + *text = ptr; + + return res; +} + +void ShaderGenerator::AddFragment( const ShaderFragment* fragment, const char* inputNames, int param ) +{ + // is already added? + FragmentData data(fragment, inputNames, param); + for( int i = 0; i < m_FragmentCount; ++i ) { + if( m_Fragments[i] == data ) + return; + } + + // add it's dependencies first + if( fragment->dependencies ) { + for( int i = 0; i < kDepCount; ++i ) { + // has this dependency? + if( !(fragment->dependencies & (1<<i)) ) + continue; + AddFragment( kCommonDependencies[i] ); + } + } + + // add itself + m_Fragments[m_FragmentCount] = data; + m_FragmentCount++; + assert( m_FragmentCount < kMaxShaderFragments ); +} + +// Register plus it's living range - first and last shader fragment indices +// on where it can be used. +struct SavedRegister { + std::string name; + int firstUse; + int lastUse; + int regIndex; +}; +typedef std::vector<SavedRegister> SavedRegisters; + +static inline int FindSavedRegister( const SavedRegisters& regs, const std::string& name ) +{ + int n = regs.size(); + for( int i = 0; i < n; ++i ) + if( regs[i].name == name ) + return i; + return -1; +} + +void ShaderGenerator::GenerateShader( std::string& output, unsigned int& usedConstants ) +{ + unsigned int usedConstantsMask = 0; + + output.clear(); + output.reserve(1024); + //debug.clear(); + + // shader input mappings + int inputMapping[kInputCount]; + for( int i = 0; i < kInputCount; ++i ) + inputMapping[i] = -1; + int usedInputStack[kInputCount]; + int usedInputs = 0; + + // saved registers across fragments + SavedRegisters savedRegisters; + + // go over fragments and figure out inputs, saved registers and used constants + int maxTemps = 0; + for( int fi = 0; fi < m_FragmentCount; ++fi ) { + const ShaderFragment& frag = *m_Fragments[fi].fragment; + + // fragment vertex inputs + for( int i = 0; i < kInputCount; ++i ) { + // does fragment use this input? + if( frag.inputs & (1<<i) ) { + // add to inputs list of in there yet + if( inputMapping[i] == -1 ) { + usedInputStack[usedInputs] = i; + inputMapping[i] = usedInputs; + ++usedInputs; + } + } + } + + // remember output registers + if( frag.outs ) { + const char* outputs = frag.outs; + std::string token; + while( !(token = ExtractToken(&outputs)).empty() ) { + token = "$O_" + token; + //TODO: check that text has that token. + //TODO: check that text has no $O_ tokens that are not in the output + // add to list if not there yet + int savedIndex = FindSavedRegister( savedRegisters, token ); + if( savedIndex == -1 ) + { + SavedRegister r; + r.name = token; + r.firstUse = fi; + r.lastUse = fi; + r.regIndex = -1; + savedRegisters.push_back( r ); + } + else + { + savedRegisters[savedIndex].lastUse = fi; + assert(savedRegisters[savedIndex].firstUse <= savedRegisters[savedIndex].lastUse); + } + } + } + + // from fragment input registers, determine last use of saved registers + if( frag.ins ) { + const char* inputs = frag.ins; + std::string token; + while( !(token = ExtractToken(&inputs)).empty() ) { + // a parametrized token? + if( token[0] == '$' ) { + assert(token.size()==2); + assert(token[1]>='0' && token[1]<='9'); + int index = token[1]-'0'; + const char* inputNames = m_Fragments[fi].inputNames; + inputNames = SkipTokens( inputNames, index ); + token = ExtractToken(&inputNames); + } + token = "$O_" + token; + + //TODO: check that text has that token. + //TODO: check that text has no $O_ tokens that are not in the input + int savedIndex = FindSavedRegister( savedRegisters, token ); + assert(savedIndex != -1); + assert(savedRegisters[savedIndex].lastUse <= fi); + savedRegisters[savedIndex].lastUse = fi; + } + } + + maxTemps = std::max(maxTemps, frag.temps); + + // used constants + usedConstantsMask |= frag.constants; + } + + assert( savedRegisters.size() <= kMaxSavedRegisters ); + + // assign register indices to saved registers + int mapFragmentRegister[kMaxShaderFragments][kMaxTempRegisters]; // [fragment][index] = used or not? + memset(mapFragmentRegister, 0, sizeof(mapFragmentRegister)); + for( size_t i = 0; i < savedRegisters.size(); ++i ) { + // find unused register over whole lifetime, and assign it + SavedRegister& sr = savedRegisters[i]; + assert(sr.regIndex == -1); + for( int regIndex = 0; regIndex < kMaxTempRegisters; ++regIndex ) { + bool unused = true; + for( int fi = sr.firstUse; fi <= sr.lastUse; ++fi ) { + if( mapFragmentRegister[fi][regIndex] != 0 ) { + unused = false; + break; + } + } + if( unused ) { + for( int fi = sr.firstUse; fi <= sr.lastUse; ++fi ) + mapFragmentRegister[fi][regIndex] = 1; + sr.regIndex = regIndex; + break; + } + } + assert(sr.regIndex != -1); + } + + // generate prolog with declarations + output += "vs_2_0\n"; + for( int i = 0; i < usedInputs; ++i ) { + output += kShaderInputDecls[usedInputStack[i]]; + output += " v"; + assert(i<=9); + output += ('0' + i); + output += '\n'; + } + + // go over fragments, transform register names and output + for( int fi = 0; fi < m_FragmentCount; ++fi ) { + const ShaderFragment& frag = *m_Fragments[fi].fragment; + int param = m_Fragments[fi].param; + + output += '\n'; + std::string text = frag.text; + + std::string regname("r0"); + std::string regname2("r00"); + + // input registers + regname[0] = 'v'; + for( int i = 0; i < usedInputs; ++i ) { + int inputIndex = usedInputStack[i]; + assert(i<=9); + regname[1] = '0' + i; + replace_string(text, kShaderInputNames[inputIndex], regname); + } + + // fragment inputs + if( frag.ins ) { + const char* inputs = frag.ins; + std::string token; + while( !(token = ExtractToken(&inputs)).empty() ) { + std::string searchName; + std::string savedName; + // a parametrized token? + if( token[0] == '$' ) { + assert(token.size()==2); + assert(token[1]>='0' && token[1]<='9'); + int index = token[1]-'0'; + const char* inputNames = m_Fragments[fi].inputNames; + inputNames = SkipTokens( inputNames, index ); + token = ExtractToken(&inputNames); + searchName = std::string("$I_") + char('0'+index); + } else { + searchName = "$O_" + token; + } + savedName = "$O_" + token; + + // Assign register index to this saved reg + SavedRegisters::iterator it, itEnd = savedRegisters.end(); + for( it = savedRegisters.begin(); it != itEnd; ++it ) { + const SavedRegister& sr = *it; + if( sr.name == savedName ) + { + // replace with register value + regname[0] = 'r'; + assert(sr.regIndex<=9); + regname[1] = '0' + sr.regIndex; + replace_string(text, searchName, regname); + break; + } + } + assert( it != itEnd ); + } + } + + // saved registers + if( frag.outs ) { + regname[0] = 'r'; + SavedRegisters::iterator it, itEnd = savedRegisters.end(); + for( it = savedRegisters.begin(); it != itEnd; ++it ) { + const SavedRegister& sr = *it; + assert(sr.regIndex<=9); + regname[1] = '0' + sr.regIndex; + replace_string(text, sr.name, regname); + } + } + + // fragment-private temporary registers + regname[0] = 'r'; + regname2[0] = 'r'; + std::string tmpname("$TMP0"); + int regIndex = 0; + for( int i = 0; i < frag.temps; ++i ) { + assert(i<=9); + tmpname[4] = '0' + i; + // find unused register at this fragment + while( regIndex < kMaxTempRegisters && mapFragmentRegister[fi][regIndex] != 0 ) + ++regIndex; + assert(regIndex < kMaxTempRegisters); + if( regIndex > 9 ) { + regname2[1] = '1'; + regname2[2] = '0' + (regIndex-10); + replace_string(text, tmpname, regname2); + } else { + regname[1] = '0' + regIndex; + replace_string(text, tmpname, regname); + } + ++regIndex; + } + + // parameter + if( param >= 0 ) { + std::string paramString("0"); + assert(param<=9); + paramString[0] = '0'+param; + replace_string(text, "$PARAM", paramString); + } + + // texture matrix parameters + if( frag.options & kOptionHasTexMatrix ) { + std::string tmpstring("$TMPARAM0"); + std::string paramString("c00"); + for( int i = 0; i < 4; ++i ) { + assert(i<=9); + tmpstring[8] = '0' + i; + int constant = kConstantLocations[kConstMatrixTexture] + param*4 + i; + paramString[1] = '0' + constant/10; + paramString[2] = '0' + constant%10; + replace_string(text, tmpstring, paramString); + } + } + + output += text; + } + + + usedConstants = usedConstantsMask; + + // checks + + // should be no '$' left + assert( output.find('$') == std::string::npos ); + + // debug info + //char buffer[1000]; + //_snprintf_s( buffer, 1000, "Fragments: %i SavedRegs: %i\n", m_FragmentCount, maxTemps ); + //debug += buffer; + //for( size_t i = 0; i < savedRegisters.size(); ++i ) { + // _snprintf_s( buffer, 1000, " saved %s [%i..%i] r%i\n", savedRegisters[i].name.c_str(), savedRegisters[i].firstUse, savedRegisters[i].lastUse, savedRegisters[i].regIndex ); + // debug += buffer; + //} +} diff --git a/Runtime/GfxDevice/d3d/ShaderGenerator.h b/Runtime/GfxDevice/d3d/ShaderGenerator.h new file mode 100644 index 0000000..ccc52b7 --- /dev/null +++ b/Runtime/GfxDevice/d3d/ShaderGenerator.h @@ -0,0 +1,100 @@ +#pragma once +#include <string> + +enum ShaderConstant { + kConstMatrixMVP, // model*view*proj + kConstMatrixMV, // model*view + kConstMatrixMV_IT, // model*view inverse transpose + kConstMatrixTexture,// texture matrix + kConstAmbient, // materialEmissive + sceneAmbient * materialAmbient + kConstColorMatAmbient, // various combos of kConstAmbient, based on color material mode + kConstLightMisc, // 0, 4, 1, 0.5 + kConstMatDiffuse, // material diffuse + kConstMatSpecular, // material specular + kConstLightIndexes, // light start indexes * 4 + kConstCount +}; + +extern const int kConstantLocations[kConstCount]; + + +struct ShaderFragment +{ + unsigned int inputs; + unsigned int constants; + unsigned int dependencies; + unsigned int options; + int temps; + const char* ins; + const char* outs; + const char* text; +}; + + +class ShaderGenerator +{ +public: + enum { + kMaxShaderFragments = 32, + kMaxTempRegisters = 12, + kMaxSavedRegisters = 16, + }; + +private: + struct FragmentData { + FragmentData() : fragment(NULL), inputNames(NULL), param(0) { } + FragmentData( const ShaderFragment* f, const char* inames, int p ) : fragment(f), inputNames(inames), param(p) { } + bool operator==( const FragmentData& rhs ) const { + return + fragment==rhs.fragment && + param==rhs.param && + ((inputNames==NULL && rhs.inputNames==NULL) || (inputNames && rhs.inputNames && !strcmp(inputNames, rhs.inputNames))); + } + + const ShaderFragment* fragment; + const char* inputNames; + int param; + }; + +public: + + ShaderGenerator() : m_FragmentCount(0) + { + } + + void AddFragment( const ShaderFragment* fragment, const char* inputNames = NULL, int param = -1 ); + void GenerateShader( std::string& output, unsigned int& usedConstants ); + +private: + int m_FragmentCount; + FragmentData m_Fragments[kMaxShaderFragments]; +}; + + +extern const ShaderFragment kVS_Pos; +extern const ShaderFragment kVS_Light_Diffuse_Pre; +extern const ShaderFragment kVS_Light_Diffuse_Dir; +extern const ShaderFragment kVS_Light_Diffuse_Point; +extern const ShaderFragment kVS_Light_Diffuse_Spot; +extern const ShaderFragment kVS_Light_Specular_Pre; +extern const ShaderFragment kVS_Light_Specular_Dir; +extern const ShaderFragment kVS_Light_Specular_Point; +extern const ShaderFragment kVS_Light_Specular_Spot; +extern const ShaderFragment kVS_Out_Diffuse_Lighting; +extern const ShaderFragment kVS_Out_Specular_Lighting; +extern const ShaderFragment kVS_Out_Diffuse_Lighting_ColorDiffuseAmbient; +extern const ShaderFragment kVS_Out_Diffuse_Lighting_ColorEmission; +extern const ShaderFragment kVS_Out_Diffuse_VertexColor; +extern const ShaderFragment kVS_Out_Diffuse_White; +extern const ShaderFragment kVS_Load_UV0; +extern const ShaderFragment kVS_Load_UV1; +extern const ShaderFragment kVS_Load_Normal; +extern const ShaderFragment kVS_Normalize_Normal; +extern const ShaderFragment kVS_Out_TexCoord; +extern const ShaderFragment kVS_Out_Matrix2; +extern const ShaderFragment kVS_Out_Matrix3; +extern const ShaderFragment kVS_Temp_CamSpacePos; +extern const ShaderFragment kVS_Temp_CamSpaceN; +extern const ShaderFragment kVS_Temp_CamSpaceRefl; +extern const ShaderFragment kVS_Temp_ObjSpacePos; +extern const ShaderFragment kVS_Temp_SphereMap; diff --git a/Runtime/GfxDevice/d3d/ShaderPatchingD3D9.cpp b/Runtime/GfxDevice/d3d/ShaderPatchingD3D9.cpp new file mode 100644 index 0000000..87f8e17 --- /dev/null +++ b/Runtime/GfxDevice/d3d/ShaderPatchingD3D9.cpp @@ -0,0 +1,376 @@ +#include "UnityPrefix.h" +#include "ShaderPatchingD3D9.h" +#include "Runtime/Utilities/BitUtility.h" +#include "Runtime/Utilities/Word.h" + +#define DEBUG_FOG_PATCHING 0 + + +static inline bool IsNewline( char c ) { return c == '\n' || c == '\r'; } + +static int FindMaxUsedDclIndex (const std::string& src, char registerName) +{ + size_t n = src.size(); + size_t pos = 0; + int maxDcl = -1; + while ((pos = src.find("dcl_", pos)) != std::string::npos) + { + // skip "dcl_" + pos += 4; + + // skip until end of dcl_* + while (pos < n && !isspace(src[pos])) + ++pos; + // skip space + while (pos < n && isspace(src[pos])) + ++pos; + // is this an needed register type? + if (pos < n && src[pos] == registerName) { + int number = -1; + sscanf (src.c_str() + pos + 1, "%d", &number); + if (number > maxDcl) + maxDcl = number; + } + } + return maxDcl; +} + + +static bool InsertFogDcl (std::string& src, const std::string& registerName) +{ + // insert dcl_fog after vs_3_0/ps_3_0 line + size_t pos = 6; + while (pos < src.size() && !IsNewline(src[pos])) // skip until newline + ++pos; + while (pos < src.size() && IsNewline(src[pos])) // skip newlines + ++pos; + if (pos >= src.size()) + return false; + src.insert (pos, Format("dcl_fog %s\n", registerName.c_str())); + return true; +} + + +bool PatchPixelShaderFogD3D9 (std::string& src, FogMode fog, int fogColorReg, int fogParamsReg) +{ + const bool isPS3 = !strncmp(src.c_str(), "ps_3_0", 6); + if (!isPS3) + return true; // nothing to do + + #if DEBUG_FOG_PATCHING + printf_console ("D3D9 fog patching: original pixel shader:\n%s\n", src.c_str()); + #endif + + // SM3.0 has 10 input registers (v0..v9). + + const int maxDclReg = FindMaxUsedDclIndex (src, 'v'); + if (maxDclReg >= 9) + { + // out of registers + return false; + } + const int fogReg = 9; + if (!InsertFogDcl (src, Format("v%d.x", fogReg))) + { + DebugAssert (!"failed to insert fog dcl"); + return false; + } + + // Remap writes to oC0 with r30 + const int colorReg = 30; + const int tempReg = 31; + replace_string (src, "oC0", "r30"); + + // make sure source ends with a newline + if (!IsNewline(src[src.size()-1])) + src += '\n'; + + // inject fog handling code + if (fog == kFogExp2) + { + // fog = exp(-(density*z)^2) + src += Format("mul r%d.x, c%d.x, v%d.x\n", tempReg, fogParamsReg, fogReg); // tmp = (density/sqrt(ln(2))) * fog + src += Format("mul r%d.x, r%d.x, r%d.x\n", tempReg, tempReg, tempReg); // tmp = tmp * tmp + src += Format("exp_sat r%d.x, -r%d.x\n", tempReg, tempReg); // tmp = saturate (exp2 (-tmp)) + src += Format("lrp r%d.rgb, r%d.x, r%d, c%d\n", colorReg, tempReg, colorReg, fogColorReg); // color.rgb = lerp (color, fogColor, tmp) + } + else if (fog == kFogExp) + { + // fog = exp(-density*z) + src += Format("mul r%d.x, c%d.y, v%d.x\n", tempReg, fogParamsReg, fogReg); // tmp = (density/ln(2)) * fog + src += Format("exp_sat r%d.x, -r%d.x\n", tempReg, tempReg); // tmp = saturate (exp2 (-tmp)) + src += Format("lrp r%d.rgb, r%d.x, r%d, c%d\n", colorReg, tempReg, colorReg, fogColorReg); // color.rgb = lerp (color, fogColor, tmp) + } + else if (fog == kFogLinear) + { + // fog = (end-z)/(end-start) + src += Format("mad_sat r%d.x, c%d.z, v%d.x, c%d.w\n", tempReg, fogParamsReg, fogReg, fogParamsReg); // tmp = (-1/(end-start)) * fog + (end/(end-start)) + src += Format("lrp r%d.rgb, r%d.x, r%d, c%d\n", colorReg, tempReg, colorReg, fogColorReg); // color.rgb = lerp (color, fogColor, tmp) + } + + + // append final move into oC0 + src += Format("mov oC0, r%d\n", colorReg); + + #if DEBUG_FOG_PATCHING + printf_console ("D3D9 fog patching: after patching, fog mode %d:\n%s\n", fog, src.c_str()); + #endif + + return true; +} + + +bool PatchVertexShaderFogD3D9 (std::string& src) +{ + const bool isVS3 = !strncmp(src.c_str(), "vs_3_0", 6); + if (!isVS3) + return true; // nothing to do + + #if DEBUG_FOG_PATCHING + printf_console ("D3D9 fog patching: original vertex shader:\n%s\n", src.c_str()); + #endif + + // SM3.0 has 12 output registers (o0..o11), but the pixel shader only has 10 input ones. + // Play it safe and let's assume we only have 10 here. + + const int maxDclReg = FindMaxUsedDclIndex (src, 'o'); + if (maxDclReg >= 9) + { + // out of registers + return false; + } + const int fogReg = 9; + std::string fogRegName = Format("o%d", fogReg); + if (!InsertFogDcl (src, fogRegName)) + { + DebugAssert (!"failed to insert fog dcl"); + return false; + } + + // find write to o0, and do the same for oFog + size_t posWrite = src.find ("o0.z,"); + bool writesFullPos = false; + if (posWrite == std::string::npos) + { + posWrite = src.find ("o0,"); + if (posWrite == std::string::npos) + { + DebugAssert (!"couldn't find write to o0"); + return false; + } + writesFullPos = true; + } + + // get whole line + size_t n = src.size(); + size_t posWriteStart = posWrite, posWriteEnd = posWrite; + while (posWriteStart > 0 && !IsNewline(src[posWriteStart])) --posWriteStart; + ++posWriteStart; + while (posWriteEnd < n && !IsNewline(src[posWriteEnd])) ++posWriteEnd; + + std::string instr = src.substr (posWriteStart, posWriteEnd-posWriteStart); + if (writesFullPos) + { + replace_string (instr, "o0", fogRegName, 0); + instr += ".z"; + } + else + { + replace_string (instr, "o0.z", fogRegName, 0); + } + instr += '\n'; + + // insert fog code just after write to position + src.insert (posWriteEnd+1, instr); + + #if DEBUG_FOG_PATCHING + printf_console ("D3D9 fog patching: after patching:\n%s\n", src.c_str()); + #endif + + return true; +} + + +// -------------------------------------------------------------------------- + +#if ENABLE_UNIT_TESTS + +#include "External/UnitTest++/src/UnitTest++.h" + +SUITE (ShaderPatchingD3D9Tests) +{ + +TEST(FindMaxDclIndexNotPresent) +{ + CHECK_EQUAL (-1, FindMaxUsedDclIndex("", 'v')); + CHECK_EQUAL (-1, FindMaxUsedDclIndex("foobar", 'v')); + CHECK_EQUAL (-1, FindMaxUsedDclIndex("dcl_", 'v')); + CHECK_EQUAL (-1, FindMaxUsedDclIndex("dcl_foo", 'v')); + CHECK_EQUAL (-1, FindMaxUsedDclIndex("dcl_foo ", 'v')); + CHECK_EQUAL (-1, FindMaxUsedDclIndex("dcl_foo v", 'v')); +} +TEST(FindMaxDclIndexOne) +{ + CHECK_EQUAL (0, FindMaxUsedDclIndex("dcl_foobar v0", 'v')); + CHECK_EQUAL (1, FindMaxUsedDclIndex("dcl_foobar v1", 'v')); + CHECK_EQUAL (2, FindMaxUsedDclIndex("dcl_foobar v2.x", 'v')); + CHECK_EQUAL (3, FindMaxUsedDclIndex("dcl_foobar v3.rgb", 'v')); + CHECK_EQUAL (6, FindMaxUsedDclIndex("dcl_foobar v6", 'v')); + CHECK_EQUAL (10, FindMaxUsedDclIndex("dcl_foobar v10", 'v')); + CHECK_EQUAL (0, FindMaxUsedDclIndex("ps_3_0\ndcl_foobar v0\nmov oC0, v0", 'v')); +} +TEST(FindMaxDclIndexMultiple) +{ + CHECK_EQUAL (2, FindMaxUsedDclIndex("dcl_foobar v0\ndcl_foobar v2", 'v')); + CHECK_EQUAL (3, FindMaxUsedDclIndex("dcl_foobar v3\ndcl_foobar v1", 'v')); +} + +TEST(PatchVSZWrite) +{ + std::string s; + s = "vs_3_0\n" + "dcl_position o0\n" + "dp4 o0.z, c0, c1\n" + ; + CHECK (PatchVertexShaderFogD3D9(s)); + CHECK_EQUAL( + "vs_3_0\n" + "dcl_fog o9\n" + "dcl_position o0\n" + "dp4 o0.z, c0, c1\n" + "dp4 o9, c0, c1\n" + , s); +} +TEST(PatchVSFullWrite) +{ + std::string s; + s = "vs_3_0\n" + "dcl_position o0\n" + "mov o0, c0\n" + ; + CHECK (PatchVertexShaderFogD3D9(s)); + CHECK_EQUAL( + "vs_3_0\n" + "dcl_fog o9\n" + "dcl_position o0\n" + "mov o0, c0\n" + "mov o9, c0.z\n" + , s); +} +TEST(PatchVSWriteNotAtEnd) +{ + std::string s; + s = "vs_3_0\n" + "dcl_position o0\n" + "mov o0, r0\n" + "mov r0, r1\n" + ; + CHECK (PatchVertexShaderFogD3D9(s)); + CHECK_EQUAL( + "vs_3_0\n" + "dcl_fog o9\n" + "dcl_position o0\n" + "mov o0, r0\n" + "mov o9, r0.z\n" + "mov r0, r1\n" + , s); +} +TEST(PatchPSDisjointColorAlphaWrite) +{ + std::string s = + "ps_3_0\n" + "; 31 ALU, 2 TEX\n" + "dcl_2d s0\n" + "dcl_2d s1\n" + "def c5, 0.0, 128.0, 2.0, 0\n" + "dcl_texcoord0 v0.xy\n" + "dcl_texcoord1 v1.xyz\n" + "dcl_texcoord2 v2.xyz\n" + "dcl_texcoord3 v3.xyz\n" + "dcl_texcoord4 v4\n" + "texldp r3.x, v4, s1\n" + "dp3_pp r0.x, v3, v3\n" + "rsq_pp r0.x, r0.x\n" + "mad_pp r0.xyz, r0.x, v3, c0\n" + "dp3_pp r0.w, r0, r0\n" + "rsq_pp r0.w, r0.w\n" + "mul_pp r0.xyz, r0.w, r0\n" + "mov_pp r0.w, c4.x\n" + "dp3_pp r0.x, v1, r0\n" + "dp3_pp r2.x, v1, c0\n" + "mul_pp r1.y, c5, r0.w\n" + "max_pp r1.x, r0, c5\n" + "pow r0, r1.x, r1.y\n" + "mov r1.x, r0\n" + "texld r0, v0, s0\n" + "mul r1.w, r0, r1.x\n" + "mul_pp r1.xyz, r0, c3\n" + "mul_pp r0.xyz, r1, c1\n" + "max_pp r2.x, r2, c5\n" + "mul_pp r2.xyz, r0, r2.x\n" + "mov_pp r0.xyz, c1\n" + "mul_pp r0.xyz, c2, r0\n" + "mad r0.xyz, r0, r1.w, r2\n" + "mul_pp r2.w, r3.x, c5.z\n" + "mul r0.xyz, r0, r2.w\n" + "mad_pp oC0.xyz, r1, v2, r0\n" // color RGB + "mov_pp r2.x, c1.w\n" + "mul_pp r0.x, c2.w, r2\n" + "mul_pp r0.y, r0.w, c3.w\n" + "mul r0.x, r1.w, r0\n" + "mad oC0.w, r3.x, r0.x, r0.y\n"; // color A + std::string exps = + "ps_3_0\n" + "dcl_fog v9.x\n" + "; 31 ALU, 2 TEX\n" + "dcl_2d s0\n" + "dcl_2d s1\n" + "def c5, 0.0, 128.0, 2.0, 0\n" + "dcl_texcoord0 v0.xy\n" + "dcl_texcoord1 v1.xyz\n" + "dcl_texcoord2 v2.xyz\n" + "dcl_texcoord3 v3.xyz\n" + "dcl_texcoord4 v4\n" + "texldp r3.x, v4, s1\n" + "dp3_pp r0.x, v3, v3\n" + "rsq_pp r0.x, r0.x\n" + "mad_pp r0.xyz, r0.x, v3, c0\n" + "dp3_pp r0.w, r0, r0\n" + "rsq_pp r0.w, r0.w\n" + "mul_pp r0.xyz, r0.w, r0\n" + "mov_pp r0.w, c4.x\n" + "dp3_pp r0.x, v1, r0\n" + "dp3_pp r2.x, v1, c0\n" + "mul_pp r1.y, c5, r0.w\n" + "max_pp r1.x, r0, c5\n" + "pow r0, r1.x, r1.y\n" + "mov r1.x, r0\n" + "texld r0, v0, s0\n" + "mul r1.w, r0, r1.x\n" + "mul_pp r1.xyz, r0, c3\n" + "mul_pp r0.xyz, r1, c1\n" + "max_pp r2.x, r2, c5\n" + "mul_pp r2.xyz, r0, r2.x\n" + "mov_pp r0.xyz, c1\n" + "mul_pp r0.xyz, c2, r0\n" + "mad r0.xyz, r0, r1.w, r2\n" + "mul_pp r2.w, r3.x, c5.z\n" + "mul r0.xyz, r0, r2.w\n" + "mad_pp r30.xyz, r1, v2, r0\n" + "mov_pp r2.x, c1.w\n" + "mul_pp r0.x, c2.w, r2\n" + "mul_pp r0.y, r0.w, c3.w\n" + "mul r0.x, r1.w, r0\n" + "mad r30.w, r3.x, r0.x, r0.y\n" + "mul r31.x, c7.x, v9.x\n" + "mul r31.x, r31.x, r31.x\n" + "exp_sat r31.x, -r31.x\n" + "lrp r30.rgb, r31.x, r30, c6\n" + "mov oC0, r30\n"; + CHECK (PatchPixelShaderFogD3D9(s, kFogExp2, 6, 7)); + CHECK_EQUAL(exps, s); +} + +} // SUITE + +#endif // ENABLE_UNIT_TESTS diff --git a/Runtime/GfxDevice/d3d/ShaderPatchingD3D9.h b/Runtime/GfxDevice/d3d/ShaderPatchingD3D9.h new file mode 100644 index 0000000..e36a619 --- /dev/null +++ b/Runtime/GfxDevice/d3d/ShaderPatchingD3D9.h @@ -0,0 +1,7 @@ +#pragma once + +#include <string> +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +bool PatchVertexShaderFogD3D9 (std::string& src); +bool PatchPixelShaderFogD3D9 (std::string& src, FogMode fog, int fogColorReg, int fogParamsReg); diff --git a/Runtime/GfxDevice/d3d/TexturesD3D9.cpp b/Runtime/GfxDevice/d3d/TexturesD3D9.cpp new file mode 100644 index 0000000..d2baef9 --- /dev/null +++ b/Runtime/GfxDevice/d3d/TexturesD3D9.cpp @@ -0,0 +1,696 @@ +#include "UnityPrefix.h" +#include "TexturesD3D9.h" +#include "Runtime/Graphics/TextureFormat.h" +#include "Runtime/Graphics/Image.h" +#include "D3D9Context.h" +#include "Runtime/Allocator/FixedSizeAllocator.h" +#include "Runtime/Utilities/BitUtility.h" +#include "Runtime/Graphics/S3Decompression.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "D3D9Utils.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/VramLimits.h" +#include "Runtime/GfxDevice/TextureUploadUtils.h" +#include "Runtime/GfxDevice/TextureIdMap.h" +#include "External/ProphecySDK/include/prcore/Surface.hpp" +#include "Runtime/Profiler/MemoryProfiler.h" +#include "Runtime/Utilities/InitializeAndCleanup.h" + +struct D3DTexture +{ + explicit D3DTexture( IDirect3DBaseTexture9* tex ) + : texture(tex), wrapMode(D3DTADDRESS_CLAMP), minFilter(D3DTEXF_POINT), magFilter(D3DTEXF_POINT), mipFilter(D3DTEXF_NONE), aniso(1), sRGB(0) { } + + IDirect3DBaseTexture9* texture; + D3DTEXTUREADDRESS wrapMode; + D3DTEXTUREFILTERTYPE minFilter; + D3DTEXTUREFILTERTYPE magFilter; + D3DTEXTUREFILTERTYPE mipFilter; + int aniso; + bool sRGB; +}; + +typedef FixedSizeAllocator<sizeof(D3DTexture)> TextureAllocator; +static TextureAllocator* _TextureAlloc = NULL; + +namespace TextureD3D9Alloc +{ + void StaticInitialize() + { + _TextureAlloc = UNITY_NEW_AS_ROOT(TextureAllocator(kMemGfxDevice),kMemGfxDevice, "TextureStructs", ""); + } + + void StaticDestroy() + { + UNITY_DELETE(_TextureAlloc, kMemGfxDevice); + } +} + +static RegisterRuntimeInitializeAndCleanup s_TextureAllocManagerCallbacks(TextureD3D9Alloc::StaticInitialize, TextureD3D9Alloc::StaticDestroy); + +static inline intptr_t AllocD3DTexture(IDirect3DBaseTexture9* tex) +{ + return (intptr_t)(new (_TextureAlloc->alloc()) D3DTexture(tex)); +} + +static inline D3DTexture* QueryD3DTexture(TextureID textureID) +{ + return (D3DTexture*)TextureIdMap::QueryNativeTexture(textureID); +} + + +static D3DCOLOR ColorToD3D( const float color[4] ) +{ + return D3DCOLOR_RGBA( NormalizedToByte(color[0]), NormalizedToByte(color[1]), NormalizedToByte(color[2]), NormalizedToByte(color[3]) ); +} + + +struct FormatDesc { + TextureFormat unityformat; + D3DFORMAT d3dformat; + int bpp; + prcore::PixelFormat prformat; +}; + +const static FormatDesc kTextureFormatTable[kTexFormatPCCount+2] = // +1 for A8L8 case +{ + { kTexFormatPCCount, D3DFMT_UNKNOWN, 0, prcore::PixelFormat() }, + { kTexFormatAlpha8, D3DFMT_A8, 1, prcore::PixelFormat(8,0,0xff) }, // Alpha8 + { kTexFormatARGB4444, D3DFMT_A4R4G4B4, 2, prcore::PixelFormat(16,0x00000f00,0x000000f0,0x0000000f,0x0000f000) }, // ARGB4444 + { kTexFormatRGB24, D3DFMT_X8R8G8B8, 4, prcore::PixelFormat(32,0x00ff0000,0x0000ff00,0x000000ff,0xff000000) }, // RGB24 + { kTexFormatRGBA32, D3DFMT_A8R8G8B8, 4, prcore::PixelFormat(32,0x00ff0000,0x0000ff00,0x000000ff,0xff000000) }, // RGBA32 + { kTexFormatARGB32, D3DFMT_A8R8G8B8, 4, prcore::PixelFormat(32,0x00ff0000,0x0000ff00,0x000000ff,0xff000000) }, // ARGB32 + { kTexFormatARGBFloat, D3DFMT_UNKNOWN, 0, prcore::PixelFormat() }, // ARGBFloat + { kTexFormatRGB565, D3DFMT_R5G6B5, 2, prcore::PixelFormat(16,0x0000f800,0x000007e0,0x0000001f,0x00000000) }, // RGB565 + { kTexFormatBGR24, D3DFMT_X8R8G8B8, 4, prcore::PixelFormat(32,0x00ff0000,0x0000ff00,0x000000ff,0xff000000) }, // BGR24 + { kTexFormatAlphaLum16, D3DFMT_L16, 0, prcore::PixelFormat() }, // AlphaLum16 + { kTexFormatDXT1, D3DFMT_DXT1, 0, prcore::PixelFormat() }, // DXT1 + { kTexFormatDXT3, D3DFMT_DXT3, 0, prcore::PixelFormat() }, // DXT3 + { kTexFormatDXT5, D3DFMT_DXT5, 0, prcore::PixelFormat() }, // DXT5 + { kTexFormatRGBA4444, D3DFMT_A4R4G4B4, 2, prcore::PixelFormat(16,0x00000f00,0x000000f0,0x0000000f,0x0000f000) }, // RGBA4444 + + // following are not Unity formats, but might be used as fallbacks for some unsupported formats + { kTexFormatAlphaLum16, D3DFMT_A8L8, 2, prcore::PixelFormat(16,0x00ff,0xff00) }, // A8L8, used on cards that don't support A8; alpha -> alpha +}; + +const static FormatDesc kTextureFormatETC = +{ + kTexFormatETC_RGB4, D3DFMT_X8R8G8B8, 4, prcore::PixelFormat(32,0x00ff0000,0x0000ff00,0x000000ff,0xff000000) +}; + +const static FormatDesc kTextureFormatATC[2] = +{ + { kTexFormatATC_RGB4, D3DFMT_X8R8G8B8, 4, prcore::PixelFormat(32,0x00ff0000,0x0000ff00,0x000000ff,0xff000000) }, // RGB24 + { kTexFormatATC_RGBA8, D3DFMT_A8R8G8B8, 4, prcore::PixelFormat(32,0x00ff0000,0x0000ff00,0x000000ff,0xff000000) }, // RGBA32 +}; + + +D3DFORMAT GetD3D9TextureFormat( TextureFormat inFormat ) +{ + return kTextureFormatTable[inFormat].d3dformat; +} + +static const FormatDesc& GetUploadFormat( TextureFormat inFormat, bool forceFallbackFormat = false ) +{ + if (forceFallbackFormat) + { + return kTextureFormatTable[kTexFormatARGB32]; + } + else if( inFormat == kTexFormatAlpha8 && !gGraphicsCaps.d3d.hasTextureFormatA8 ) + { + // A8 not supported: A8L8 or fallback one depending on support + if( gGraphicsCaps.d3d.hasTextureFormatA8L8 ) + return kTextureFormatTable[ kTexFormatPCCount ]; // return A8L8 option, see table above + else + return kTextureFormatTable[kTexFormatARGB32]; + } + else if( IsCompressedDXTTextureFormat(inFormat) && !gGraphicsCaps.hasS3TCCompression ) + { + // Compressed format not supported: decompress into fallback format + return kTextureFormatTable[kTexFormatARGB32]; + } + else if ( IsCompressedETCTextureFormat(inFormat) ) + { + return kTextureFormatETC; + } + else if ( IsCompressedATCTextureFormat(inFormat) ) + { + return kTextureFormatATC[ HasAlphaTextureFormat(inFormat)? 1 : 0 ]; + } + else if (!gGraphicsCaps.d3d.hasBaseTextureFormat[inFormat]) + { + // This format not supported in general: convert to fallback format + return kTextureFormatTable[kTexFormatARGB32]; + } + + // All ok, return incoming format + return kTextureFormatTable[inFormat]; +} + +intptr_t TexturesD3D9::RegisterNativeTexture(IDirect3DBaseTexture9* texture) const +{ + return AllocD3DTexture(texture); +} + +void TexturesD3D9::UpdateNativeTexture(TextureID textureID, IDirect3DBaseTexture9* texture) +{ + D3DTexture* target = QueryD3DTexture(textureID); + if(target) + target->texture = texture; + else + AddTexture(textureID, texture); +} + +void TexturesD3D9::AddTexture( TextureID textureID, IDirect3DBaseTexture9* texture ) +{ + TextureIdMap::UpdateTexture(textureID, AllocD3DTexture(texture)); +} + +void TexturesD3D9::RemoveTexture( TextureID textureID ) +{ + D3DTexture* target = QueryD3DTexture(textureID); + if(target) + { + target->~D3DTexture(); + _TextureAlloc->free(target); + } + TextureIdMap::RemoveTexture(textureID); +} + +IDirect3DBaseTexture9* TexturesD3D9::GetTexture( TextureID textureID ) const +{ + D3DTexture* target = QueryD3DTexture(textureID); + return target ? target->texture : 0; +} + + + +static void BlitAlphaLum16 (int width, int height, D3DFORMAT d3dFormat, const UInt8* srcData, UInt8* destData, int pitch) +{ + // Handle AlphaLum16 case. ProphecySDK does not support 16 bit/channel formats, + // so we blit manually. + UInt32 rowBytes = GetRowBytesFromWidthAndFormat(width,kTexFormatAlphaLum16); + const UInt8* srcRowData = srcData; + UInt8* destRowData = destData; + if( d3dFormat == D3DFMT_L16 ) + { + for( int r = 0; r < height; ++r ) + { + memcpy( destRowData, srcRowData, rowBytes ); + srcRowData += rowBytes; + destRowData += pitch; + } + } + else if( d3dFormat == D3DFMT_L8 ) + { + for( int r = 0; r < height; ++r ) + { + for( int c = 0; c < width; ++c ) + destRowData[c] = srcRowData[c*2+1]; + srcRowData += rowBytes; + destRowData += pitch; + } + } + else + { + AssertIf( d3dFormat != D3DFMT_A8R8G8B8 ); + for( int r = 0; r < height; ++r ) + { + for( int c = 0; c < width; ++c ) + { + DWORD val = srcRowData[c*2+1]; + ((D3DCOLOR*)destRowData)[c] = 0xFF000000 | (val<<16) | (val<<8) | (val); + } + srcRowData += rowBytes; + destRowData += pitch; + } + } +} + +void InitRGBA32Buffer(int width, int height, UInt8*& buffer, int& srcPitch, prcore::PixelFormat& pf) +{ + int imageSize = CalculateImageSize( width, height, kTexFormatRGBA32 ); + if( buffer == NULL ) + buffer = new UInt8[imageSize]; + srcPitch = GetRowBytesFromWidthAndFormat(width, kTexFormatRGBA32); + pf = GetProphecyPixelFormat(kTexFormatRGBA32); +} + +void TexturesD3D9::UploadTexture2D( + TextureID tid, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + + AssertIf( srcData == NULL ); + AssertIf( (!IsPowerOfTwo(width) || !IsPowerOfTwo(height)) && !IsNPOTTextureAllowed(mipCount > 1) ); + + if( dimension != kTexDim2D ) + { + ErrorString( "Incorrect texture dimension!" ); + return; + } + + // Nothing to do here. Early out instead of failing, empty textures are serialized by dynamic fonts. + if( width == 0 || height == 0 ) + return; + + bool uploadIsCompressed, decompressOnTheFly; + HandleFormatDecompression (format, &usageMode, colorSpace, &uploadIsCompressed, &decompressOnTheFly); + + if( decompressOnTheFly ) + uploadIsCompressed = false; + + const FormatDesc& uploadFormat = GetUploadFormat (decompressOnTheFly ? kTexFormatRGBA32 : format, usageMode != kTexUsageNone); + D3DFORMAT d3dFormat = uploadFormat.d3dformat; + + if( format == kTexFormatAlphaLum16 && !gGraphicsCaps.d3d.hasTextureFormatL16 ) + { + // AlphaLum16 requires some trickery if hardware does not support L16: + // first we try to do L8 instead, then fallback to A8R8G8B8. + if( gGraphicsCaps.d3d.hasTextureFormatL8 ) + d3dFormat = D3DFMT_L8; + else + d3dFormat = D3DFMT_A8R8G8B8; + } + + int baseLevel, maxLevel, texWidth, texHeight; + size_t textureSize; + prcore::Surface::BlitMode blitMode = prcore::Surface::BLIT_COPY; + if (SkipLevelsForMasterTextureLimit (masterTextureLimit, format, uploadFormat.unityformat, mipCount, uploadIsCompressed, &srcData, &width, &height, &baseLevel, &maxLevel, &texWidth, &texHeight, &textureSize)) + blitMode = prcore::Surface::BLIT_SCALE; + + // if we don't support mip maps - don't use them + if( !(gGraphicsCaps.d3d.d3dcaps.TextureCaps & D3DPTEXTURECAPS_MIPMAP) ) + { + mipCount = 1; + baseLevel = 0; + } + + // create texture if it does not exist already + IDirect3DTexture9* texture = NULL; + + D3DTexture* target = QueryD3DTexture(tid); + if(!target) + { + HRESULT hr = dev->CreateTexture( texWidth, texHeight, mipCount - baseLevel, 0, d3dFormat, D3DPOOL_MANAGED, &texture, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texture, CalculateImageSize(texWidth, texHeight,format)*(mipCount>1?1.33:1),tid.m_ID); + if( FAILED(hr) ) + printf_console( "d3d: failed to create 2D texture id=%i w=%i h=%i mips=%i d3dfmt=%i [%s]\n", tid, texWidth, texHeight, mipCount-baseLevel, d3dFormat, GetD3D9Error(hr) ); + TextureIdMap::UpdateTexture(tid, AllocD3DTexture(texture)); + } + else + { + texture = (IDirect3DTexture9*)target->texture; + } + + if( !texture ) + { + AssertString( "failed to create 2D texture" ); + return; + } + + UInt8* decompressBuffer = NULL; + UInt8* tempBuffer = NULL; + int bufferPitch; + + // Upload the mip levels + for( int level = baseLevel; level <= maxLevel; ++level ) + { + D3DLOCKED_RECT lr; + HRESULT hr = texture->LockRect( level-baseLevel, &lr, NULL, 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock level %i of texture %i [%s]\n", level-baseLevel, tid, GetD3D9Error(hr) ); + if( decompressBuffer ) + delete[] decompressBuffer; + return; + } + + if( decompressOnTheFly ) + { + ConvertCompressedTextureUpload (width, height, format, srcData, decompressBuffer, bufferPitch, usageMode, colorSpace, level); + + prcore::Surface srcSurface( width, height, bufferPitch, GetProphecyPixelFormat(kTexFormatRGBA32), decompressBuffer ); + prcore::Surface dstSurface( texWidth, texHeight, lr.Pitch, uploadFormat.prformat, lr.pBits ); + dstSurface.BlitImage( srcSurface, blitMode ); + } + else if( format == kTexFormatAlphaLum16 ) + { + BlitAlphaLum16( width, height, d3dFormat, srcData, (UInt8*)lr.pBits, lr.Pitch ); + } + else if( !uploadIsCompressed ) + { + prcore::Surface srcSurface( width, height, GetRowBytesFromWidthAndFormat( width,format ), GetProphecyPixelFormat(format), srcData ); + prcore::Surface dstSurface( texWidth, texHeight, lr.Pitch, uploadFormat.prformat, lr.pBits ); + + if (!ConvertUncompressedTextureUpload(srcSurface, dstSurface, blitMode, uploadFormat.unityformat, usageMode, colorSpace, width, height, (UInt8*)lr.pBits, lr.Pitch, uploadFormat.prformat, tempBuffer, bufferPitch)) + { + dstSurface.BlitImage( srcSurface, blitMode ); + } + } + else + { + if( width == texWidth && height == texHeight ) + { + BlitCopyCompressedImage( format, srcData, width, height, (UInt8*)lr.pBits, width, height, false ); + } + else + { + // TODO: fill with garbage? + } + } + + texture->UnlockRect( level-baseLevel ); + + // Go to next level + AssertIf( width == 1 && height == 1 && level != maxLevel ); + AdvanceToNextMipLevel (format, srcData, width, height, texWidth, texHeight); + } + + delete[] decompressBuffer; +} + +void TexturesD3D9::UploadTextureSubData2D( + TextureID tid, UInt8* srcData, int mipLevel, + int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + if( !dev ) + return; + + // if we don't support mip maps and want to change higher level - don't + if( !(gGraphicsCaps.d3d.d3dcaps.TextureCaps & D3DPTEXTURECAPS_MIPMAP) && mipLevel != 0 ) + return; + + AssertIf( srcData == NULL ); + AssertIf( IsCompressedDXTTextureFormat( format ) ); + + // find the texture + D3DTexture* target = QueryD3DTexture(tid); + if(target == 0) + { + AssertString( "Texture not found" ); + return; + } + + const FormatDesc& uploadFormat = GetUploadFormat( format ); + IDirect3DTexture9* texture = (IDirect3DTexture9*)target->texture; + AssertIf( !texture ); + + RECT rect; + rect.left = x; + rect.top = y; + rect.right = x + width; + rect.bottom = y + height; + D3DLOCKED_RECT lr; + HRESULT hr = texture->LockRect( mipLevel, &lr, &rect, 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock sub level %i of texture %i [%s]\n", mipLevel, tid, GetD3D9Error(hr) ); + return; + } + + // TODO: handle other format conversions + + prcore::Surface srcSurface( width, height, GetRowBytesFromWidthAndFormat(width,format), GetProphecyPixelFormat(format), srcData ); + prcore::Surface dstSurface( width, height, lr.Pitch, uploadFormat.prformat, lr.pBits ); + dstSurface.BlitImage( srcSurface, prcore::Surface::BLIT_COPY ); + + texture->UnlockRect( mipLevel ); +} + + +void TexturesD3D9::UploadTextureCube( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + if (!dev) + return; + + // if we don't support cube mip maps - don't use them + if( !(gGraphicsCaps.d3d.d3dcaps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP) ) + mipCount = 1; + + const FormatDesc& uploadFormat = GetUploadFormat(format); + IDirect3DCubeTexture9* texture = NULL; + + D3DTexture* target = QueryD3DTexture(tid); + if(!target) + { + HRESULT hr = dev->CreateCubeTexture( size, mipCount, 0, uploadFormat.d3dformat, D3DPOOL_MANAGED, &texture, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texture, 6*CalculateImageSize(size, size, format)*(mipCount>1?1.33:1),tid.m_ID); + if( FAILED(hr) ) + printf_console( "d3d: failed to create cubemap id=%i size=%i mips=%i d3dfmt=%i [%s]\n", tid, size, mipCount, uploadFormat.d3dformat, GetD3D9Error(hr) ); + TextureIdMap::UpdateTexture(tid, AllocD3DTexture(texture)); + } + else + { + texture = (IDirect3DCubeTexture9*)target->texture; + } + if( !texture ) + { + AssertString( "failed to create cubemap" ); + return; + } + + // Upload data + bool uploadIsCompressed = IsCompressedDXTTextureFormat(format); // TODO: handle when we don't have DXT + + static const D3DCUBEMAP_FACES faces[6] = + { + D3DCUBEMAP_FACE_POSITIVE_X, + D3DCUBEMAP_FACE_NEGATIVE_X, + D3DCUBEMAP_FACE_POSITIVE_Y, + D3DCUBEMAP_FACE_NEGATIVE_Y, + D3DCUBEMAP_FACE_POSITIVE_Z, + D3DCUBEMAP_FACE_NEGATIVE_Z, + }; + + int maxLevel = mipCount - 1; + for (int face=0;face<6;face++) + { + int mipSize = size; + UInt8* data = srcData + face * faceDataSize; + + // Upload the mip levels + for( int level = 0; level <= maxLevel; ++level ) + { + D3DLOCKED_RECT lr; + HRESULT hr = texture->LockRect( faces[face], level, &lr, NULL, 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock level %i of face %i of cubemap %i [%s]\n", level, face, tid, GetD3D9Error(hr) ); + return; + } + + // TODO: handle DXT decompression on the fly + // TODO: handle other format conversions + + if( !uploadIsCompressed ) + { + prcore::Surface srcSurface( mipSize, mipSize, GetRowBytesFromWidthAndFormat(mipSize,format), GetProphecyPixelFormat(format), data ); + prcore::Surface dstSurface( mipSize, mipSize, lr.Pitch, uploadFormat.prformat, lr.pBits ); + dstSurface.BlitImage( srcSurface, prcore::Surface::BLIT_COPY ); + } + else + { + BlitCopyCompressedImage( format, data, mipSize, mipSize, (UInt8*)lr.pBits, mipSize /* TODO */, mipSize, false ); + } + + texture->UnlockRect( faces[face], level ); + + // Go to next level + data += CalculateImageSize( mipSize, mipSize, format ); + AssertIf( mipSize == 1 && level != maxLevel ); + + mipSize = std::max( mipSize / 2, 1 ); + } + } +} + +void TexturesD3D9::UploadTexture3D( + TextureID tid, UInt8* srcData, int width, int height, int depth, + TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + if (!dev || !gGraphicsCaps.has3DTexture) + return; + + // if we don't support volume mip maps - don't use them + if( !(gGraphicsCaps.d3d.d3dcaps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) ) + mipCount = 1; + + + const FormatDesc& uploadFormat = GetUploadFormat( format ); + D3DFORMAT d3dFormat = uploadFormat.d3dformat; + if( format == kTexFormatAlphaLum16 ) + { + // AlphaLum16 requires some trickery if hardware does not support L16: + // first we try to do L8 instead, then fallback to A8R8G8B8. + if( !gGraphicsCaps.d3d.hasTextureFormatL16 && gGraphicsCaps.d3d.hasTextureFormatL8 ) + d3dFormat = D3DFMT_L8; + else + d3dFormat = D3DFMT_A8R8G8B8; + } + + IDirect3DVolumeTexture9* texture = NULL; + + D3DTexture* target = QueryD3DTexture(tid); + if(!target) + { + HRESULT hr = dev->CreateVolumeTexture( width, height, depth, mipCount, 0, d3dFormat, D3DPOOL_MANAGED, &texture, NULL ); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texture, depth*CalculateImageSize(width, height, format)*(mipCount>1?1.33:1),tid.m_ID); + if( FAILED(hr) ) + printf_console( "d3d: failed to create 3D texture id=%i w=%i h=%i d=%i mips=%i d3dfmt=%i [%s]\n", tid, width, height, depth, mipCount, d3dFormat, GetD3D9Error(hr) ); + TextureIdMap::UpdateTexture(tid, AllocD3DTexture(texture)); + } + else + { + texture = (IDirect3DVolumeTexture9*)target->texture; + } + if( !texture ) + { + AssertString( "failed to create 3D texture" ); + return; + } + + int maxLevel = mipCount - 1; + for( int level=0; level <= maxLevel; ++level ) + { + D3DLOCKED_BOX lr; + HRESULT hr = texture->LockBox( level, &lr, NULL, 0 ); + if( FAILED(hr) ) + { + printf_console( "d3d: failed to lock level %i of 3D texture %i [%s]\n", level, tid, GetD3D9Error(hr) ); + return; + } + + UInt8* destData = (UInt8*)lr.pBits; + const int sliceSize = CalculateImageSize(width, height, format); + for( int slice = 0; slice < depth; ++slice ) + { + if( format == kTexFormatAlphaLum16 ) + { + BlitAlphaLum16 (width, height, d3dFormat, srcData, destData, lr.RowPitch); + } + else + { + // Regular ProphecySDK blit + prcore::Surface srcSurface( width, height, GetRowBytesFromWidthAndFormat(width,format), GetProphecyPixelFormat(format), srcData ); + prcore::Surface dstSurface( width, height, lr.RowPitch, uploadFormat.prformat, destData ); + dstSurface.BlitImage( srcSurface, prcore::Surface::BLIT_COPY ); + } + srcData += sliceSize; + destData += lr.SlicePitch; + } + + texture->UnlockBox( level ); + + AssertIf( width == 1 && height == 1 && level != maxLevel ); + + width = std::max( width / 2, 1 ); + height = std::max( height / 2, 1 ); + depth = std::max( depth / 2, 1 ); + } +} + + + +bool TexturesD3D9::SetTexture (ShaderType shaderType, int unit, TextureID textureID) +{ + IDirect3DDevice9* dev = GetD3DDevice(); + + D3DTexture* target = QueryD3DTexture(textureID); + if(target) + { + const D3DTexture& texture = *target; + DWORD d3dUnit = GetD3D9SamplerIndex (shaderType, unit); + D3D9_CALL(dev->SetTexture( d3dUnit, texture.texture )); + // TODO: caching of those! + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_ADDRESSU, texture.wrapMode )); + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_ADDRESSV, texture.wrapMode )); + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_ADDRESSW, texture.wrapMode )); + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_MINFILTER, texture.minFilter )); + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_MAGFILTER, texture.magFilter )); + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_MIPFILTER, texture.mipFilter )); + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_MAXANISOTROPY, texture.aniso )); + D3D9_CALL(dev->SetSamplerState( d3dUnit, D3DSAMP_SRGBTEXTURE, texture.sRGB )); + return true; + } + else + { + // Ok, just don't complain here. Mostly with render textures, once in a while it + // happens that RT is not created yet, and someone tries to render with it. + // Just silently ignore that case. + //ErrorString( Format("SetTexture with unknown texture %i", textureID) ); + return false; + } +} + +static D3DTEXTUREADDRESS s_D3DWrapModes[kTexWrapCount] = { + D3DTADDRESS_WRAP, + D3DTADDRESS_CLAMP, +}; +static D3DTEXTUREFILTERTYPE s_D3DMinMagFilters[kTexFilterCount] = { + D3DTEXF_POINT, + D3DTEXF_LINEAR, + D3DTEXF_LINEAR, +}; +static D3DTEXTUREFILTERTYPE s_D3DMipFilters[kTexFilterCount] = { + D3DTEXF_POINT, + D3DTEXF_POINT, + D3DTEXF_LINEAR, +}; + + +void TexturesD3D9::SetTextureParams( TextureID textureID, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + D3DTexture* target = QueryD3DTexture(textureID); + if(!target) + return; + + D3DTexture& texture = *target; + AssertIf( !texture.texture ); + + if( gGraphicsCaps.hasAnisoFilter && texDim != kTexDim3D ) + texture.aniso = std::min( anisoLevel, gGraphicsCaps.maxAnisoLevel ); + else + texture.aniso = 1; + texture.wrapMode = s_D3DWrapModes[wrap]; + + if( !hasMipMap && filter == kTexFilterTrilinear ) + filter = kTexFilterBilinear; + + texture.minFilter = texture.magFilter = s_D3DMinMagFilters[filter]; + if( texture.aniso > 1 ) + { + texture.minFilter = D3DTEXF_ANISOTROPIC; + // some cards (notably GeForces) can do min anisotropic filter, but not mag anisotropic filter + if( gGraphicsCaps.d3d.d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC ) + texture.magFilter = D3DTEXF_ANISOTROPIC; + } + texture.mipFilter = s_D3DMipFilters[filter]; + + //sRGB + texture.sRGB = colorSpace == kTexColorSpaceSRGB || colorSpace == kTexColorSpaceSRGBXenon; + // actual setting of sampler states will happen in SetTexture +} + + +void TexturesD3D9::DeleteTexture( TextureID textureID ) +{ + D3DTexture* target = QueryD3DTexture(textureID); + if(!target) + return; + + // texture can be null if texture creation failed. At least don't make it crash here + if( target->texture ) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(target->texture); + ULONG refCount = target->texture->Release(); + AssertIf( refCount != 0 ); + } + TextureIdMap::RemoveTexture(textureID); +} diff --git a/Runtime/GfxDevice/d3d/TexturesD3D9.h b/Runtime/GfxDevice/d3d/TexturesD3D9.h new file mode 100644 index 0000000..113434c --- /dev/null +++ b/Runtime/GfxDevice/d3d/TexturesD3D9.h @@ -0,0 +1,90 @@ +#pragma once + +#include "D3D9Includes.h" +#include "Runtime/Graphics/TextureFormat.h" +#include "Runtime/Graphics/RenderSurface.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Threads/AtomicOps.h" +#include <map> + +class ImageReference; + +class TexturesD3D9 +{ +public: + TexturesD3D9() {} + ~TexturesD3D9() {} + bool SetTexture (ShaderType shaderType, int unit, TextureID textureID); + void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + + void DeleteTexture( TextureID textureID ); + + void UploadTexture2D( + TextureID tid, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + + void UploadTextureSubData2D( + TextureID tid, UInt8* srcData, int mipLevel, + int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + + void UploadTextureCube( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + + void UploadTexture3D( + TextureID tid, UInt8* srcData, int width, int height, int depth, + TextureFormat format, int mipCount, UInt32 uploadFlags ); + + void AddTexture( TextureID textureID, IDirect3DBaseTexture9* texture ); + void RemoveTexture( TextureID textureID ); + IDirect3DBaseTexture9* GetTexture( TextureID textureID ) const; + + intptr_t RegisterNativeTexture(IDirect3DBaseTexture9* texture) const; + void UpdateNativeTexture(TextureID textureID, IDirect3DBaseTexture9* texture); +}; + +struct RenderSurfaceD3D9 : RenderSurfaceBase +{ + RenderSurfaceD3D9() + : m_Texture(NULL) + , m_Surface(NULL) + { + RenderSurfaceBase_Init(*this); + } + void Release() { + if (m_Texture) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_Texture); + m_Texture->Release(); + m_Texture = NULL; + } + if (m_Surface) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_Surface); + m_Surface->Release(); + m_Surface = NULL; + } + } + IDirect3DBaseTexture9* m_Texture; + IDirect3DSurface9* m_Surface; +}; + +struct RenderColorSurfaceD3D9 : public RenderSurfaceD3D9 +{ + RenderColorSurfaceD3D9() + : format(kRTFormatARGB32) + , dim(kTexDim2D) + { + RenderSurfaceBase_InitColor(*this); + } + RenderTextureFormat format; + TextureDimension dim; +}; + +struct RenderDepthSurfaceD3D9 : public RenderSurfaceD3D9 +{ + RenderDepthSurfaceD3D9() + : depthFormat(kDepthFormatNone) + { + RenderSurfaceBase_InitDepth(*this); + } + DepthBufferFormat depthFormat; +}; diff --git a/Runtime/GfxDevice/d3d/TimerQueryD3D9.cpp b/Runtime/GfxDevice/d3d/TimerQueryD3D9.cpp new file mode 100644 index 0000000..70f9ed7 --- /dev/null +++ b/Runtime/GfxDevice/d3d/TimerQueryD3D9.cpp @@ -0,0 +1,196 @@ +#include "UnityPrefix.h" +#if ENABLE_PROFILER +#include "GfxDeviceD3D9.h" +#include "TimerQueryD3D9.h" + + +TimerQueryD3D9::TimerQueryD3D9() + : m_Query(NULL), m_Time(0), m_Active(false) +{ + GetD3DDevice()->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &m_Query); + m_TimeMultiplier = 0.0f; +} + +TimerQueryD3D9::~TimerQueryD3D9() +{ + SAFE_RELEASE(m_Query); +} + +void TimerQueryD3D9::Measure() +{ + // Flush previous result + GetElapsed(kWaitRenderThread); + + TimerQueriesD3D9& queries = GetD3D9GfxDevice().GetTimerQueries(); + if (m_Query && queries.HasFrequencyQuery()) + { + queries.AddActiveTimerQuery(this); + m_Query->Issue(D3DISSUE_END); + m_Active = true; + m_Time = kInvalidProfileTime; + } + else + m_Time = 0; + m_TimeMultiplier = 0.0f; +} + +ProfileTimeFormat TimerQueryD3D9::GetElapsed(UInt32 flags) +{ + while (m_Active) + { + bool wait = (flags & kWaitRenderThread) != 0; + if (!GetD3D9GfxDevice().GetTimerQueries().PollNextTimerQuery(wait)) + break; + } + return m_Time; +} + +bool TimerQueryD3D9::PollResult(UInt64& prevTime, bool wait) +{ + for (;;) + { + UINT64 time; + DWORD flags = wait ? D3DGETDATA_FLUSH : 0; + HRESULT hr = m_Query->GetData(&time, sizeof(time), flags); + if (hr == S_OK) + { + UInt64 elapsed = prevTime ? (time - prevTime) : 0; + m_Time = ProfileTimeFormat(elapsed * m_TimeMultiplier); + prevTime = time; + return true; + } + // Stop polling on unknown result (e.g D3DERR_DEVICELOST) + if (hr != S_FALSE) + { + m_Time = 0; + prevTime = 0; + return true; + } + if (!wait) + break; + } + return false; +} + +TimerQueriesD3D9::TimerQueriesD3D9() +{ + m_LastQueryTime = 0; + m_FrequencyQuery = NULL; + memset(m_StartTimeQueries, 0, sizeof(m_StartTimeQueries)); + m_StartTimeQueryIndex = 0; +} + +void TimerQueriesD3D9::ReleaseAllQueries() +{ + SAFE_RELEASE(m_FrequencyQuery); + for (int i = 0; i < kStartTimeQueryCount; i++) + { + delete m_StartTimeQueries[i]; + m_StartTimeQueries[i] = NULL; + } + m_InactiveTimerQueries.append(m_ActiveTimerQueries); + m_InactiveTimerQueries.append(m_PolledTimerQueries); + TimerQueryList& queries = m_InactiveTimerQueries; + for (TimerQueryList::iterator it = queries.begin(); it != queries.end(); ++it) + { + TimerQueryD3D9& query = *it; + query.m_Active = false; + query.m_Time = 0; + SAFE_RELEASE(query.m_Query); + } +} + +void TimerQueriesD3D9::RecreateAllQueries() +{ + Assert(m_ActiveTimerQueries.empty()); + Assert(m_PolledTimerQueries.empty()); + TimerQueryList& queries = m_InactiveTimerQueries; + for (TimerQueryList::iterator it = queries.begin(); it != queries.end(); ++it) + { + TimerQueryD3D9& query = *it; + GetD3DDevice()->CreateQuery(D3DQUERYTYPE_TIMESTAMP, &query.m_Query); + } +} + +void TimerQueriesD3D9::BeginTimerQueries() +{ + // Poll queries from previous frames + PollTimerQueries(); + + if (m_FrequencyQuery == NULL) + { + GetD3DDevice()->CreateQuery(D3DQUERYTYPE_TIMESTAMPFREQ, &m_FrequencyQuery); + } + if (m_FrequencyQuery) + m_FrequencyQuery->Issue(D3DISSUE_END); + + int& index = m_StartTimeQueryIndex; + if (m_StartTimeQueries[index] == NULL) + { + m_StartTimeQueries[index] = new TimerQueryD3D9; + } + m_StartTimeQueries[index]->Measure(); + index = (index + 1) % kStartTimeQueryCount; +} + +void TimerQueriesD3D9::EndTimerQueries() +{ + if(m_FrequencyQuery == NULL) + return; + + HRESULT hr; + UINT64 freq; + do + { + hr = m_FrequencyQuery->GetData(&freq, sizeof(freq), D3DGETDATA_FLUSH); + } while (hr == S_FALSE); + if (hr == S_OK) + { + float timeMult = float(1000000000.0 / (double)freq); + TimerQueryList::iterator query, queryEnd = m_ActiveTimerQueries.end(); + for (query = m_ActiveTimerQueries.begin(); query != queryEnd; ++query) + query->SetTimeMultiplier(timeMult); + } + // Move queries from active to polled list + m_PolledTimerQueries.append(m_ActiveTimerQueries); +} + +TimerQueryD3D9* TimerQueriesD3D9::CreateTimerQuery() +{ + TimerQueryD3D9* query = new TimerQueryD3D9; + m_InactiveTimerQueries.push_back(*query); + return query; +} + +void TimerQueriesD3D9::AddActiveTimerQuery(TimerQueryD3D9* query) +{ + query->RemoveFromList(); + m_ActiveTimerQueries.push_back(*query); +} + +void TimerQueriesD3D9::PollTimerQueries() +{ + for (;;) + { + if (!PollNextTimerQuery(false)) + break; + } +} + +bool TimerQueriesD3D9::PollNextTimerQuery(bool wait) +{ + if (m_PolledTimerQueries.empty()) + return false; + + TimerQueryD3D9& query = m_PolledTimerQueries.front(); + if (query.PollResult(m_LastQueryTime, wait)) + { + query.m_Active = false; + query.RemoveFromList(); + m_InactiveTimerQueries.push_back(query); + return true; + } + return false; +} + +#endif diff --git a/Runtime/GfxDevice/d3d/TimerQueryD3D9.h b/Runtime/GfxDevice/d3d/TimerQueryD3D9.h new file mode 100644 index 0000000..ecc4a94 --- /dev/null +++ b/Runtime/GfxDevice/d3d/TimerQueryD3D9.h @@ -0,0 +1,67 @@ +#ifndef TIMERQUERYD3D9_H +#define TIMERQUERYD3D9_H + +#if ENABLE_PROFILER + +#include "Runtime/GfxDevice/GfxTimerQuery.h" + +class TimerQueriesD3D9; + +class TimerQueryD3D9 : public GfxTimerQuery +{ +public: + ~TimerQueryD3D9(); + + virtual void Measure(); + virtual ProfileTimeFormat GetElapsed(UInt32 flags); + + bool PollResult(UInt64& prevTime, bool wait); + void SetTimeMultiplier(float tm) { m_TimeMultiplier = tm; } + +private: + friend TimerQueriesD3D9; + TimerQueryD3D9(); + + IDirect3DQuery9* m_Query; + ProfileTimeFormat m_Time; + float m_TimeMultiplier; + bool m_Active; +}; + +class TimerQueriesD3D9 +{ +public: + TimerQueriesD3D9(); + + void ReleaseAllQueries(); + void RecreateAllQueries(); + + void BeginTimerQueries(); + void EndTimerQueries(); + + TimerQueryD3D9* CreateTimerQuery(); + + void AddActiveTimerQuery(TimerQueryD3D9* query); + void PollTimerQueries(); + bool PollNextTimerQuery(bool wait); + + bool HasFrequencyQuery() const { return m_FrequencyQuery != NULL; } + +private: + enum + { + kStartTimeQueryCount = 3 + }; + + UInt64 m_LastQueryTime; + IDirect3DQuery9* m_FrequencyQuery; + TimerQueryD3D9* m_StartTimeQueries[kStartTimeQueryCount]; + int m_StartTimeQueryIndex; + typedef List<TimerQueryD3D9> TimerQueryList; + TimerQueryList m_InactiveTimerQueries; + TimerQueryList m_ActiveTimerQueries; + TimerQueryList m_PolledTimerQueries; +}; + +#endif +#endif diff --git a/Runtime/GfxDevice/d3d/VertexDeclarations.cpp b/Runtime/GfxDevice/d3d/VertexDeclarations.cpp new file mode 100644 index 0000000..180a105 --- /dev/null +++ b/Runtime/GfxDevice/d3d/VertexDeclarations.cpp @@ -0,0 +1,124 @@ +#include "UnityPrefix.h" +#include "VertexDeclarations.h" +#include "D3D9Context.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +bool VertexDeclarations::KeyType::operator < (const KeyType& rhs) const +{ + return memcmp(channels, rhs.channels, sizeof(channels)) < 0; +} + +VertexDeclarations::VertexDeclarations() +{ +} + +VertexDeclarations::~VertexDeclarations() +{ + Clear(); +} + +struct D3DVertexSemantics +{ + UInt8 usage; + UInt8 index; +}; + +static D3DVertexSemantics kChannelVertexSemantics[kShaderChannelCount] = +{ + { D3DDECLUSAGE_POSITION, 0 }, // position + { D3DDECLUSAGE_NORMAL, 0 }, // normal + { D3DDECLUSAGE_COLOR, 0 }, // color + { D3DDECLUSAGE_TEXCOORD, 0 }, // uv + { D3DDECLUSAGE_TEXCOORD, 1 }, // uv2 + { D3DDECLUSAGE_TANGENT, 0 }, // tangent +}; + +static FORCE_INLINE D3DDECLTYPE GetD3DVertexDeclType(const ChannelInfo& info) +{ + switch (info.format) + { + case kChannelFormatFloat: + { + switch (info.dimension) + { + case 1: return D3DDECLTYPE_FLOAT1; + case 2: return D3DDECLTYPE_FLOAT2; + case 3: return D3DDECLTYPE_FLOAT3; + case 4: return D3DDECLTYPE_FLOAT4; + } + break; + } + case kChannelFormatFloat16: + { + switch (info.dimension) + { + case 2: return D3DDECLTYPE_FLOAT16_2; + case 4: return D3DDECLTYPE_FLOAT16_4; + } + break; + } + case kChannelFormatColor: + { + return D3DDECLTYPE_D3DCOLOR; + } + } + Assert("No matching D3D vertex decl type!"); + return D3DDECLTYPE_UNUSED; +} + +IDirect3DVertexDeclaration9* VertexDeclarations::GetVertexDecl( const ChannelInfoArray channels ) +{ + KeyType key; + memcpy(key.channels, channels, sizeof(key.channels)); + + // already have vertex declaration for these formats? + VertexDeclMap::iterator it = m_VertexDeclMap.find( key ); + if( it != m_VertexDeclMap.end() ) + return it->second; + + // don't have this declaration yet - create one + // KD: not sure if elements need to be ordered by stream, playing it safe + D3DVERTEXELEMENT9 elements[kShaderChannelCount+1]; + int elIndex = 0; + for( int stream = 0; stream < kMaxVertexStreams; stream++ ) + { + for( int chan = 0; chan < kShaderChannelCount; chan++ ) + { + if( channels[chan].stream == stream && channels[chan].IsValid() ) + { + DebugAssert(elIndex < kShaderChannelCount); + D3DVERTEXELEMENT9& elem = elements[elIndex]; + elem.Stream = stream; + elem.Offset = channels[chan].offset; + elem.Type = GetD3DVertexDeclType(channels[chan]); + elem.Method = D3DDECLMETHOD_DEFAULT; + elem.Usage = kChannelVertexSemantics[chan].usage; + elem.UsageIndex = kChannelVertexSemantics[chan].index; + ++elIndex; + } + } + } + D3DVERTEXELEMENT9 declEnd = D3DDECL_END(); + elements[elIndex] = declEnd; + + IDirect3DVertexDeclaration9* decl = NULL; + HRESULT hr = GetD3DDevice()->CreateVertexDeclaration( elements, &decl ); + if( FAILED(hr) ) { + // TODO: error! + } + m_VertexDeclMap[key] = decl; + return decl; +} + +void VertexDeclarations::Clear() +{ + VertexDeclMap::iterator it; + for( it = m_VertexDeclMap.begin(); it != m_VertexDeclMap.end(); ++it ) + { + if( it->second ) { + ULONG refCount = it->second->Release(); + AssertIf( refCount != 0 ); + } + } + m_VertexDeclMap.clear(); +} diff --git a/Runtime/GfxDevice/d3d/VertexDeclarations.h b/Runtime/GfxDevice/d3d/VertexDeclarations.h new file mode 100644 index 0000000..f737f5a --- /dev/null +++ b/Runtime/GfxDevice/d3d/VertexDeclarations.h @@ -0,0 +1,26 @@ +#pragma once + +#include "D3D9Includes.h" +#include "Runtime\Filters\Mesh\VertexData.h" +#include <map> + + +class VertexDeclarations +{ +public: + VertexDeclarations(); + ~VertexDeclarations(); + + IDirect3DVertexDeclaration9* GetVertexDecl( const ChannelInfoArray channels ); + void Clear(); + +private: + struct KeyType + { + bool operator < (const KeyType& rhs) const; + ChannelInfoArray channels; + }; + + typedef UNITY_MAP(kMemVertexData, KeyType, IDirect3DVertexDeclaration9*) VertexDeclMap; + VertexDeclMap m_VertexDeclMap; +}; diff --git a/Runtime/GfxDevice/d3d/VertexPipeD3D9.cpp b/Runtime/GfxDevice/d3d/VertexPipeD3D9.cpp new file mode 100644 index 0000000..8a91f74 --- /dev/null +++ b/Runtime/GfxDevice/d3d/VertexPipeD3D9.cpp @@ -0,0 +1,705 @@ +#include "UnityPrefix.h" +#include "VertexPipeD3D9.h" +#include "ShaderGenerator.h" +#include "D3D9Utils.h" +#include "Runtime/GfxDevice/BuiltinShaderParams.h" +#include "External/DirectX/builds/dx9include/d3dx9.h" +#include <map> + + + +#define PRINT_VERTEX_PIPE_STATS 0 + +#define PRINT_AMD_SHADER_ANALYZER_OUTPUT 0 + + + + +// GpuProgramsD3D.cpp +ID3DXBuffer* AssembleD3DShader( const std::string& source ); + + +#if PRINT_AMD_SHADER_ANALYZER_OUTPUT +void PrintAMDShaderAnalyzer( const std::string& source ) +{ + const char* kPath = "C:\\Program Files\\AMD\\GPU ShaderAnalyzer 1.45\\GPUShaderAnalyzer.exe"; + const char* kInputPath = "ShaderInput.txt"; + const char* kOutputPath = "ShaderOutput.txt"; + DeleteFileA(kInputPath); + DeleteFileA(kOutputPath); + FILE* fout = fopen(kInputPath, "wt"); + fwrite(source.c_str(), source.size(), 1, fout); + fclose(fout); + + std::string commandLine = std::string(kPath) + " " + kInputPath + " -Analyze " + kOutputPath + " -Module Latest -ASIC HD3870"; + + STARTUPINFOA si; + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + + PROCESS_INFORMATION pi; + ZeroMemory( &pi, sizeof(pi) ); + + if( CreateProcessA( + NULL, // name of executable module + (char*)commandLine.c_str(), // command line string + NULL, // process attributes + NULL, // thread attributes + FALSE, // handle inheritance option + 0, // creation flags + NULL, // new environment block + NULL, // current directory name + &si, // startup information + &pi ) ) // process information + { + WaitForSingleObject( pi.hProcess, INFINITE ); + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + + FILE* fin = fopen(kOutputPath, "rt"); + if( fin ) { + fseek(fin, 0, SEEK_END); + int length = ftell(fin); + fseek(fin, 0, SEEK_SET); + char* buffer = new char[length+1]; + memset(buffer, 0,length+1); + fread(buffer, length, 1, fin); + fclose(fin); + } + } + //DeleteFileA(kInputPath); + //DeleteFileA(kOutputPath); +} +#endif + + + +static inline D3DCOLOR ColorToD3D( const float color[4] ) +{ + return D3DCOLOR_RGBA( NormalizedToByte(color[0]), NormalizedToByte(color[1]), NormalizedToByte(color[2]), NormalizedToByte(color[3]) ); +} + + +static void ResetDeviceVertexPipeStateD3D9 (IDirect3DDevice9* dev, const TransformState& state, const BuiltinShaderParamValues& builtins, const VertexPipeConfig& config, const VertexPipeDataD3D9& data) +{ + DebugAssertIf (!dev); + + data.haveToResetDeviceState = false; + + dev->SetTransform( D3DTS_WORLD, (const D3DMATRIX*)state.worldViewMatrix.GetPtr() ); + Matrix4x4f dummyViewMatrix; + dummyViewMatrix.SetIdentity(); dummyViewMatrix.Get(2,2) = -1.0f; + dev->SetTransform( D3DTS_VIEW, (const D3DMATRIX*)dummyViewMatrix.GetPtr() ); + dev->SetTransform( D3DTS_PROJECTION, (const D3DMATRIX*)builtins.GetMatrixParam(kShaderMatProj).GetPtr() ); + + dev->SetRenderState( D3DRS_COLORVERTEX, FALSE ); + + for( int i = 0; i < kMaxSupportedVertexLights; ++i ) + dev->LightEnable( i, FALSE ); + + dev->SetRenderState( D3DRS_AMBIENT, 0 ); + dev->SetRenderState( D3DRS_LIGHTING, FALSE ); + dev->SetRenderState( D3DRS_SPECULARENABLE, FALSE ); + + for( int i = 0; i < kMaxSupportedTextureCoords; ++i ) { + dev->SetTextureStageState( i, D3DTSS_TEXCOORDINDEX, i ); + dev->SetTextureStageState( i, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTSS_TCI_PASSTHRU ); + } +} + +void ResetVertexPipeStateD3D9 (IDirect3DDevice9* dev, TransformState& state, BuiltinShaderParamValues& builtins, VertexPipeConfig& config, VertexPipeDataD3D9& data, VertexPipePrevious& previous) +{ + config.Reset(); + data.Reset(); + state.Invalidate(builtins); + previous.Reset(); + + data.haveToResetDeviceState = true; + if (dev) + ResetDeviceVertexPipeStateD3D9 (dev, state, builtins, config, data); +} + + +void SetupFixedFunctionD3D9 ( + IDirect3DDevice9* dev, + TransformState& state, + BuiltinShaderParamValues& builtins, + const VertexPipeConfig& config, + const VertexPipeDataD3D9& data, + VertexPipePrevious& previous, + bool vsActive, bool immediateMode) +{ + if (dev && data.haveToResetDeviceState) + ResetDeviceVertexPipeStateD3D9 (dev, state, builtins, config, data); + + // matrices + if (!vsActive) + { + D3D9_CALL(dev->SetTransform( D3DTS_WORLD, (const D3DMATRIX*)state.worldViewMatrix.GetPtr() )); + } + + // set color material first, then material, then color + if( config.colorMaterial != previous.config.colorMaterial ) + { + if( config.colorMaterial != kColorMatDisabled ) + { + D3DMATERIALCOLORSOURCE srcAmbient, srcDiffuse, srcEmission; + switch( config.colorMaterial ) + { + case kColorMatEmission: + srcAmbient = D3DMCS_MATERIAL; + srcDiffuse = D3DMCS_MATERIAL; + srcEmission = D3DMCS_COLOR1; + break; + case kColorMatAmbientAndDiffuse: + srcAmbient = D3DMCS_COLOR1; + srcDiffuse = D3DMCS_COLOR1; + srcEmission = D3DMCS_MATERIAL; + break; + default: + return; + } + D3D9_CALL(dev->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, srcAmbient )); + D3D9_CALL(dev->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, srcDiffuse )); + D3D9_CALL(dev->SetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL )); + D3D9_CALL(dev->SetRenderState( D3DRS_EMISSIVEMATERIALSOURCE, srcEmission )); + D3D9_CALL(dev->SetRenderState( D3DRS_COLORVERTEX, TRUE )); + } + else + { + D3D9_CALL(dev->SetRenderState( D3DRS_COLORVERTEX, FALSE )); + } + } + + // material + if( !vsActive && config.hasLighting ) + D3D9_CALL(dev->SetMaterial( &data.material )); + + // lights + D3DLIGHT9 d3dlight; + d3dlight.Ambient.r = d3dlight.Ambient.g = d3dlight.Ambient.b = d3dlight.Ambient.a = 0.0f; + d3dlight.Falloff = 1.0f; + d3dlight.Attenuation0 = 1.0f; + d3dlight.Attenuation1 = 0.0f; + + const UInt32 lightsEnabled = (1<<data.vertexLightCount)-1; + const UInt32 lightsPrevious = (1<<previous.vertexLightCount)-1; + const UInt32 lightsDifferent = lightsPrevious ^ lightsEnabled; + UInt32 lightMask = 1; + for (int i = 0; i < kMaxSupportedVertexLights; ++i, lightMask <<= 1) + { + const UInt32 lightDiff = lightsDifferent & lightMask; + if( lightsEnabled & lightMask ) + { + const GfxVertexLight& l = data.lights[i]; + static D3DLIGHTTYPE kD3DTypes[kLightTypeCount] = { D3DLIGHT_SPOT, D3DLIGHT_DIRECTIONAL, D3DLIGHT_POINT }; + d3dlight.Type = kD3DTypes[l.type]; + d3dlight.Diffuse = *(const D3DCOLORVALUE*)&l.color; + d3dlight.Specular = *(const D3DCOLORVALUE*)&l.color; + d3dlight.Position = *(const D3DVECTOR*)&l.position; + d3dlight.Direction = *(const D3DVECTOR*)&l.spotDirection; + d3dlight.Range = l.range; + d3dlight.Attenuation2 = l.quadAtten; + d3dlight.Theta = Deg2Rad(l.spotAngle) * 0.5f; + d3dlight.Phi = Deg2Rad(l.spotAngle); + D3D9_CALL(dev->SetLight (i,&d3dlight)); + if (lightDiff) + D3D9_CALL(dev->LightEnable (i,TRUE)); + } + else + { + if (lightDiff) + D3D9_CALL(dev->LightEnable (i, FALSE)); + } + } + previous.vertexLightCount = data.vertexLightCount; + + + // ambient, lighting & specular + if( data.ambient != previous.ambient ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_AMBIENT, ColorToD3D(data.ambient.GetPtr()) )); + previous.ambient = data.ambient; + } + if( config.hasLighting != previous.config.hasLighting ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_LIGHTING, config.hasLighting ? TRUE : FALSE )); + } + if( config.hasSpecular != previous.config.hasSpecular ) + { + D3D9_CALL(dev->SetRenderState( D3DRS_SPECULARENABLE, config.hasSpecular ? TRUE : FALSE )); + } + if (config.hasNormalization != previous.config.hasNormalization) + { + D3D9_CALL(dev->SetRenderState (D3DRS_NORMALIZENORMALS, config.hasNormalization ? TRUE : FALSE)); + } + + + UInt32 textureMatrixModes = config.textureMatrixModes; + UInt32 projectedTextures = data.projectedTextures; + UInt32 textureSources = config.textureSources; + for( int i = 0; i < config.texCoordCount; ++i ) + { + // texgen + UInt32 texSource = (textureSources >> (i*3)) & 0x7; + if( !vsActive ) + { + static DWORD kTexSourceFlags[kTexSourceTypeCount] = { 0, 1, D3DTSS_TCI_SPHEREMAP, D3DTSS_TCI_CAMERASPACEPOSITION, D3DTSS_TCI_CAMERASPACEPOSITION, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR, D3DTSS_TCI_CAMERASPACENORMAL }; + DWORD d3dsource = kTexSourceFlags[texSource]; + if( immediateMode && texSource <= kTexSourceUV1 ) + d3dsource = i; + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXCOORDINDEX, d3dsource )); + } + else + { + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXCOORDINDEX, i )); + } + + // matrix + unsigned matmode = (textureMatrixModes >> (i*2)) & 3; + static DWORD kTexFlags[kTexMatrixTypeCount] = { D3DTTFF_DISABLE, D3DTTFF_COUNT2, D3DTTFF_COUNT3, D3DTTFF_COUNT4 }; + DWORD textureTransformFlags = kTexFlags[matmode]; + if (projectedTextures & (1<<i)) + textureTransformFlags |= D3DTTFF_PROJECTED; + if (vsActive) + textureTransformFlags = D3DTTFF_DISABLE; + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXTURETRANSFORMFLAGS, textureTransformFlags )); + + if( !vsActive ) + { + if( texSource == kTexSourceObject ) + { + // D3D has no "object space" texture generation. + // So instead we use camera space, and multiply the matrix so it matches: + // newMatrix = matrix * inverse(modelview) * mirrorZ + // Mirror along Z is required to match OpenGL's generation (eye space Z is negative). + Matrix4x4f mv = state.worldViewMatrix; + mv.Invert_Full(); + // Negate Z axis (mv = mv * Scale(1,1,-1)) + mv.Get(0,2) = -mv.Get(0,2); + mv.Get(1,2) = -mv.Get(1,2); + mv.Get(2,2) = -mv.Get(2,2); + mv.Get(3,2) = -mv.Get(3,2); + Matrix4x4f texmat; + MultiplyMatrices4x4 (&state.texMatrices[i], &mv, &texmat); + D3D9_CALL(dev->SetTransform( (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0 + i), (const D3DMATRIX*)texmat.GetPtr() )); + } + else + { + D3D9_CALL(dev->SetTransform( (D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0 + i), (const D3DMATRIX*)state.texMatrices[i].GetPtr() )); + } + } + } + if( config.texCoordCount != previous.config.texCoordCount ) + { + for( int i = config.texCoordCount; i < kMaxSupportedTextureCoords; ++i ) + { + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXCOORDINDEX, i )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE )); + } + } + + if( !vsActive ) + D3D9_CALL(dev->SetVertexShader(NULL)); + previous.vertexShader = NULL; + previous.config = config; +} + + + + + +// ---------------------------------------------------------------------- + + + + +struct VSLightData { + Vector4f pos; + Vector4f dir; + Vector4f color; + Vector4f params; +}; + +struct ShaderData { + IDirect3DVertexShader9* shader; + unsigned int usedConstants; + std::string text; + //std::string debug; +}; + + +struct VertexPipeKeyCompare { + union { + VertexPipeConfig key; + UInt64 asint; + } u; + VertexPipeKeyCompare() { u.asint = 0; } + bool operator <( const VertexPipeKeyCompare& r ) const { return u.asint < r.u.asint; } +}; + +typedef std::map<VertexPipeKeyCompare, ShaderData> ShaderCache; +static ShaderCache g_Shaders; + + +static IDirect3DVertexShader9* GetShaderForConfig( const VertexPipeConfig& config, IDirect3DDevice9* dev, unsigned int& usedConstants ) +{ + VertexPipeKeyCompare key; + key.u.key = config; + ShaderCache::iterator it = g_Shaders.find(key); + if( it != g_Shaders.end() ) { + const ShaderData& sdata = it->second; + usedConstants = sdata.usedConstants; + return sdata.shader; + } + + ShaderGenerator gen; + gen.AddFragment( &kVS_Pos ); + + // lighting + if( config.hasLighting ) + { + // normalize normals? + if (config.hasNormalization) + gen.AddFragment (&kVS_Normalize_Normal); + + UInt32 hasLightType = config.hasLightType; + if( config.hasSpecular ) + { + gen.AddFragment( &kVS_Light_Specular_Pre ); + if( hasLightType & (1<<kLightDirectional) ) + gen.AddFragment( &kVS_Light_Specular_Dir ); + if( hasLightType & (1<<kLightPoint) ) + gen.AddFragment( &kVS_Light_Specular_Point ); + if( hasLightType & (1<<kLightSpot) ) + gen.AddFragment( &kVS_Light_Specular_Spot ); + } + else + { + gen.AddFragment( &kVS_Light_Diffuse_Pre ); + if( hasLightType & (1<<kLightDirectional) ) + gen.AddFragment( &kVS_Light_Diffuse_Dir ); + if( hasLightType & (1<<kLightPoint) ) + gen.AddFragment( &kVS_Light_Diffuse_Point ); + if( hasLightType & (1<<kLightSpot) ) + gen.AddFragment( &kVS_Light_Diffuse_Spot ); + } + + const ShaderFragment* frag = NULL; + if( config.hasVertexColor ) { + switch( config.colorMaterial ) { + case kColorMatAmbientAndDiffuse: frag = &kVS_Out_Diffuse_Lighting_ColorDiffuseAmbient; break; + case kColorMatEmission: frag = &kVS_Out_Diffuse_Lighting_ColorEmission; break; + default: frag = &kVS_Out_Diffuse_Lighting; break; + } + } else { + frag = &kVS_Out_Diffuse_Lighting; + } + gen.AddFragment( frag ); + + if( config.hasSpecular ) { + gen.AddFragment( &kVS_Out_Specular_Lighting ); + } + + } + else + { + if( config.hasVertexColor ) + gen.AddFragment( &kVS_Out_Diffuse_VertexColor ); + else + gen.AddFragment( &kVS_Out_Diffuse_White ); + } + // texgen + static const ShaderFragment* kFragSources[kTexSourceTypeCount] = { + &kVS_Load_UV0, + &kVS_Load_UV1, + &kVS_Temp_SphereMap, + &kVS_Temp_ObjSpacePos, + &kVS_Temp_CamSpacePos, + &kVS_Temp_CamSpaceRefl, + &kVS_Temp_CamSpaceN, + }; + static const char* kFragSourceNames[kTexSourceTypeCount] = { + "UV0", + "UV1", + "SPHR", + "OPOS", + "CPOS", + "REFL", + "CNOR", + }; + static const ShaderFragment* kFragMatrices[kTexMatrixTypeCount] = { + &kVS_Out_TexCoord, + &kVS_Out_Matrix2, + &kVS_Out_Matrix3, + &kVS_Out_Matrix3 + }; + for( int i = 0; i < config.texCoordCount; ++i ) + { + unsigned src = (config.textureSources >> (i*3)) & 7; + // normalize normals? + if (config.hasNormalization) + { + if (src == kTexSourceSphereMap || src == kTexSourceCubeReflect || src == kTexSourceCubeNormal) + gen.AddFragment (&kVS_Normalize_Normal); + } + gen.AddFragment( kFragSources[src] ); + } + for( int i = 0; i < config.texCoordCount; ++i ) + { + unsigned src = (config.textureSources >> (i*3)) & 7; + unsigned matmode = (config.textureMatrixModes >> (i*2)) & 3; + gen.AddFragment (kFragMatrices[matmode], kFragSourceNames[src], i); + } + ShaderData data; + data.shader = NULL; + gen.GenerateShader( data.text, data.usedConstants ); + + ID3DXBuffer* compiledShader = AssembleD3DShader( data.text ); + if( compiledShader ) { + dev->CreateVertexShader( (const DWORD*)compiledShader->GetBufferPointer(), &data.shader ); + compiledShader->Release(); + } + + AssertIf(!data.shader); + g_Shaders.insert( std::make_pair(key, data) ); + + #if PRINT_AMD_SHADER_ANALYZER_OUTPUT + PrintAMDShaderAnalyzer( data.text ); + #endif + + usedConstants = data.usedConstants; + return data.shader; +} + +void SetupVertexShaderD3D9 ( + IDirect3DDevice9* dev, + TransformState& state, + const BuiltinShaderParamValues& builtins, + VertexPipeConfig& config, + const VertexPipeDataD3D9& data, + VertexPipePrevious& previous, + VertexShaderConstantCache& cache, + bool vsActive, bool immediateMode) +{ + if( vsActive ) + return; + + D3D9_CALL(dev->SetTransform( D3DTS_WORLD, (const D3DMATRIX*)state.worldViewMatrix.GetPtr() )); + + // figure out which light types do we have + if( !config.hasLighting ) { + config.hasLightType = 0; + } else { + UInt32 hasLightType = 0; + for (int i = 0; i < data.vertexLightCount; ++i) + { + hasLightType |= (1<<data.lights[i].type); + } + config.hasLightType = hasLightType; + } + + // create vertex shader + unsigned int usedConstants; + IDirect3DVertexShader9* shader = GetShaderForConfig(config, dev, usedConstants); + AssertIf(!shader); + + // set shader + if( shader != previous.vertexShader ) + { + D3D9_CALL(dev->SetVertexShader( shader )); + previous.vertexShader = shader; + } + + // matrices + Matrix4x4f mvp; + MultiplyMatrices4x4 (&builtins.GetMatrixParam(kShaderMatProj), &state.worldViewMatrix, &mvp ); + mvp.Transpose(); + cache.SetValues( kConstantLocations[kConstMatrixMVP], mvp.GetPtr(), 4 ); + + const Matrix4x4f& mv = state.worldViewMatrix; + cache.SetValues( kConstantLocations[kConstMatrixMV], mv.GetPtr(), 4 ); + + if( usedConstants & (1<<kConstMatrixMV_IT) ) + { + Matrix4x4f matrixTemp; + Matrix4x4f::Invert_General3D( mv, matrixTemp ); + matrixTemp.Transpose(); + if (data.normalization == kNormalizationScale) + { + // Inverse transpose of modelview is only used to transform the normals + // in our generated shader. We can just stuff mesh scale in there. + float scale = Magnitude (state.worldMatrix.GetAxisX()); + matrixTemp.Get (0, 0) *= scale; + matrixTemp.Get (1, 0) *= scale; + matrixTemp.Get (2, 0) *= scale; + matrixTemp.Get (0, 1) *= scale; + matrixTemp.Get (1, 1) *= scale; + matrixTemp.Get (2, 1) *= scale; + matrixTemp.Get (0, 2) *= scale; + matrixTemp.Get (1, 2) *= scale; + matrixTemp.Get (2, 2) *= scale; + } + cache.SetValues( kConstantLocations[kConstMatrixMV_IT], matrixTemp.GetPtr(), 4 ); + } + + // misc + float misc[4] = { 0, 4, 1, 0.5f }; + cache.SetValues( kConstantLocations[kConstLightMisc], misc, 1 ); + + // if lighting is used: + if( config.hasLighting ) + { + // ambient + if( config.colorMaterial != kColorMatAmbientAndDiffuse ) + { + SimpleVec4 amb; + amb.val[0] = data.ambientClamped.val[0] * data.material.Ambient.r; + amb.val[1] = data.ambientClamped.val[1] * data.material.Ambient.g; + amb.val[2] = data.ambientClamped.val[2] * data.material.Ambient.b; + amb.val[3] = data.ambientClamped.val[3] * data.material.Ambient.a; + if( config.colorMaterial != kColorMatEmission ) { + amb.val[0] += data.material.Emissive.r; + amb.val[1] += data.material.Emissive.g; + amb.val[2] += data.material.Emissive.b; + amb.val[3] += data.material.Emissive.a; + } + cache.SetValues( kConstantLocations[kConstAmbient], amb.GetPtr(), 1 ); + } + else + { + cache.SetValues( kConstantLocations[kConstColorMatAmbient], data.ambientClamped.GetPtr(), 1 ); + cache.SetValues( kConstantLocations[kConstAmbient], &data.material.Emissive.r, 1 ); + } + previous.ambient = data.ambient; + + // material + cache.SetValues( kConstantLocations[kConstMatDiffuse], &data.material.Diffuse.r, 1 ); + D3D9_CALL(dev->SetVertexShaderConstantF( kConstantLocations[kConstMatDiffuse], &data.material.Diffuse.r, 1 )); + if( usedConstants & (1<<kConstMatSpecular) ) + { + D3DCOLORVALUE specAndPower = data.material.Specular; + specAndPower.a = data.material.Power; + cache.SetValues( kConstantLocations[kConstMatSpecular], &specAndPower.r, 1 ); + } + + // pack the lights + int lightCounts[kLightTypeCount]; + float lightStart[kLightTypeCount]; + int lightsTotal = 0; + float lightsTotalF = 0; + memset(lightCounts, 0, sizeof(lightCounts)); + memset(lightStart, 0, sizeof(lightStart)); + VSLightData lights[kMaxSupportedVertexLights]; + for( int t = 0; t < kLightTypeCount; ++t ) + { + lightStart[t] = lightsTotalF; + for( int i = 0; i < data.vertexLightCount; ++i ) + { + const GfxVertexLight& src = data.lights[i]; + if( src.type != t ) + continue; + + VSLightData& dst = lights[lightsTotal]; + // position + dst.pos.Set( src.position.x, src.position.y, src.position.z, 1.0f ); + // direction + dst.dir.Set( -src.spotDirection.x, -src.spotDirection.y, -src.spotDirection.z, 0.0f ); + // color + dst.color.Set( src.color.x, src.color.y, src.color.z, 1.0f ); + // params: 1/(cos(theta/2)-cos(phi/2), cos(phi/2), range^2, d^2 attenuation + float sqrRange = src.range * src.range; + if( src.type == kLightSpot ) + { + float cosTheta = cosf(Deg2Rad(src.spotAngle)*0.25f); + float cosPhi = cosf(Deg2Rad(src.spotAngle)*0.5f); + float cosDiff = cosTheta - cosPhi; + dst.params.Set( + cosDiff != 0.0f ? 1.0f / cosDiff : 0.0f, + cosPhi, + src.range * src.range, + src.quadAtten + ); + } + else + { + dst.params.Set( + 0.0f, + 0.0f, + src.range * src.range, + src.quadAtten + ); + } + + ++lightCounts[t]; + ++lightsTotal; + ++lightsTotalF; + } + } + + // light indices + int miscI[kLightTypeCount][4]; + for( int t = 0; t < kLightTypeCount; ++t ) { + miscI[t][0] = lightCounts[t]; + miscI[t][1] = 0; + miscI[t][2] = 0; + miscI[t][3] = 0; + } + D3D9_CALL(dev->SetVertexShaderConstantI( 0, miscI[0], kLightTypeCount )); + + if (lightsTotal) + cache.SetValues( 60, (const float*)lights, 4*lightsTotal ); + misc[0] = lightStart[0] * 4.0f; + misc[1] = lightStart[1] * 4.0f; + misc[2] = lightStart[2] * 4.0f; + misc[3] = 0.0f; + cache.SetValues(kConstantLocations[kConstLightIndexes], misc, 1); + } + + // texture matrices & transform flags + UInt32 matrixModes = config.textureMatrixModes; + UInt32 projectedTextures = data.projectedTextures; + UInt32 textureSources = config.textureSources; + for( int i = 0; i < config.texCoordCount; ++i ) + { + unsigned matmode = (matrixModes >> (i*2)) & 0x3; + if( matmode != kTexMatrixNone ) + { + cache.SetValues(kConstantLocations[kConstMatrixTexture]+i*4, state.texMatrices[i].GetPtr(), 4); + } + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXCOORDINDEX, i )); + // projected texture flag + DWORD textureTransformFlags = (projectedTextures & (1<<i)) ? D3DTTFF_PROJECTED : D3DTTFF_DISABLE; + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXTURETRANSFORMFLAGS, textureTransformFlags )); + } + + if( config.texCoordCount != previous.config.texCoordCount ) + { + for( int i = config.texCoordCount; i < kMaxSupportedTextureCoords; ++i ) + { + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXCOORDINDEX, i )); + D3D9_CALL(dev->SetTextureStageState( i, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE )); + } + } + + previous.config = config; +} + + +void CleanupVertexShadersD3D9 () +{ + #if PRINT_VERTEX_PIPE_STATS + printf_console("Vertex pipe shader cache: %i shaders generated\n", g_Shaders.size()); + #endif + ShaderCache::iterator it, itEnd = g_Shaders.end(); + for( it = g_Shaders.begin(); it != itEnd; ++it ) + { + IDirect3DVertexShader9* vs = it->second.shader; + if( vs ) { + ULONG refCount = vs->Release(); + AssertIf( refCount != 0 ); + } + } + g_Shaders.clear (); +} + diff --git a/Runtime/GfxDevice/d3d/VertexPipeD3D9.h b/Runtime/GfxDevice/d3d/VertexPipeD3D9.h new file mode 100644 index 0000000..af9d8d3 --- /dev/null +++ b/Runtime/GfxDevice/d3d/VertexPipeD3D9.h @@ -0,0 +1,139 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/Math/Vector4.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/GfxDevice/ShaderConstantCache.h" +#include "Runtime/GfxDevice/TransformState.h" +#include "D3D9Includes.h" + +class BuiltinShaderParamValues; + +enum TextureSourceMode { + kTexSourceUV0, + kTexSourceUV1, + // match the order of TexGenMode! + kTexSourceSphereMap, + kTexSourceObject, + kTexSourceEyeLinear, + kTexSourceCubeReflect, + kTexSourceCubeNormal, + kTexSourceTypeCount +}; + +enum TextureMatrixMode { + kTexMatrixNone, + kTexMatrix2, + kTexMatrix3, + kTexMatrix4, + kTexMatrixTypeCount +}; + +struct VertexPipeConfig { + // 2 bytes + UInt64 textureMatrixModes : 16; // TextureMatrixMode: 2 bits for each unit + // 3 bytes + UInt64 textureSources : 24; // TextureSourceMode: 3 bits for each unit + // 1 byte + UInt64 colorMaterial : 3; // ColorMaterialMode + UInt64 texCoordCount : 4; // number of texture coordinates + UInt64 hasVertexColor : 1; // is vertex color coming from per-vertex data? + // 1 byte + UInt64 hasLighting : 1; // lighting on? + UInt64 hasSpecular : 1; // specular on? + UInt64 hasLightType : 3; // has light of given type? (bit per type) + UInt64 hasNormalization : 1; // needs to normalize normals? + // 10 bits left + + void Reset() { + memset(this, 0, sizeof(*this)); + } + + void SetTextureUnit( UInt32 unit ) { + Assert (unit < 8); + UInt32 tc = texCoordCount; + if( unit >= tc ) { + tc = unit+1; + texCoordCount = tc; + } + } + void ClearTextureUnit( UInt32 unit ) { + Assert (unit < 8); + UInt32 tc = texCoordCount; + if( unit < tc ) { + tc = unit; + texCoordCount = tc; + } + } +}; + + +struct VertexPipeDataD3D9 +{ + GfxVertexLight lights[kMaxSupportedVertexLights]; + D3DMATERIAL9 material; + SimpleVec4 ambient; + SimpleVec4 ambientClamped; + int vertexLightCount; + UInt32 projectedTextures; // 1 bit per unit + + + NormalizationMode normalization; + + mutable bool haveToResetDeviceState; + + void Reset() { + memset (&material, 0, sizeof(material)); + ambient.set (0,0,0,0); + ambientClamped.set (0,0,0,0); + vertexLightCount = 0; + projectedTextures = 0; + normalization = kNormalizationUnknown; + haveToResetDeviceState = false; + } +}; + + +struct VertexPipePrevious { + VertexPipeConfig config; + SimpleVec4 ambient; + int vertexLightCount; + IDirect3DVertexShader9* vertexShader; + + void Reset() { + config.Reset (); + ambient.set(-1,-1,-1,-1); + vertexLightCount = 0; + vertexShader = NULL; + } +}; + +void ResetVertexPipeStateD3D9 ( + IDirect3DDevice9* dev, + TransformState& state, + BuiltinShaderParamValues& builtins, + VertexPipeConfig& config, + VertexPipeDataD3D9& data, + VertexPipePrevious& previous); + +void SetupFixedFunctionD3D9 ( + IDirect3DDevice9* dev, + TransformState& state, + BuiltinShaderParamValues& builtins, + const VertexPipeConfig& config, + const VertexPipeDataD3D9& data, + VertexPipePrevious& previous, + bool vsActive, bool immediateMode); + +void SetupVertexShaderD3D9 ( + IDirect3DDevice9* dev, + TransformState& state, + const BuiltinShaderParamValues& builtins, + VertexPipeConfig& config, + const VertexPipeDataD3D9& data, + VertexPipePrevious& previous, + VertexShaderConstantCache& cache, + bool vsActive, bool immediateMode); + +void CleanupVertexShadersD3D9 (); diff --git a/Runtime/GfxDevice/d3d11/ConstantBuffersD3D11.cpp b/Runtime/GfxDevice/d3d11/ConstantBuffersD3D11.cpp new file mode 100644 index 0000000..fe61e06 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/ConstantBuffersD3D11.cpp @@ -0,0 +1,368 @@ +#include "UnityPrefix.h" +#include "ConstantBuffersD3D11.h" +#include "D3D11Context.h" +#include "D3D11Utils.h" + + +// NEVER enable this for release! Turns off all CB caching and makes things +// very slow, for debugging. +#define DEBUG_DISABLE_CONSTANT_BUFFER_CACHES (0 && !UNITY_RELEASE) + + +#if DEBUG_D3D11_CONSTANT_BUFFER_STATS +#include "External/shaderlab/Library/FastPropertyName.h" +extern std::string g_LastParsedShaderName; +#endif + + +ConstantBuffersD3D11::ConstantBuffersD3D11() +{ + InvalidateState(); +} + +void ConstantBuffersD3D11::InvalidateState() +{ + memset (m_ActiveBuffers, 0, sizeof(m_ActiveBuffers)); +} + + +void ConstantBuffersD3D11::Clear() +{ + memset (m_ActiveBuffers, 0, sizeof(m_ActiveBuffers)); + for (size_t i = 0; i < m_Buffers.size(); ++i) + { + ConstBuffer& cb = m_Buffers[i]; + delete[] cb.data; + if (cb.buffer) + { + cb.buffer->Release(); + REGISTER_EXTERNAL_GFX_DEALLOCATION(cb.buffer); + } + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + delete[] cb.changeCounts; + delete[] cb.tryCounts; + #endif + } + m_Buffers.clear(); + m_BufferKeys.clear(); +} + + +void ConstantBuffersD3D11::SetCBInfo (int id, int size) +{ + size_t n = m_Buffers.size(); + Assert (m_BufferKeys.size() == n); + UInt32 key = id | (size<<16); + for (size_t i = 0; i < n; ++i) + { + if (m_BufferKeys[i] == key) + return; + } + + // not found, create one + ConstBuffer cb; + cb.data = new UInt8[size]; + memset (cb.data, 0, size); + cb.dirty = true; + for (int i = 0; i < kShaderTypeCount; ++i) + cb.bindIndex[i] = -1; + cb.bindStages = 0; + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + cb.statsDirty = 0; + for (int i = 0; i < kShaderTypeCount; ++i) + cb.stats[i] = 0; + ShaderLab::FastPropertyName name; + name.index = id; + printf_console ("DX11 Constant Buffer Info: new %s size=%i shader=%s\n", name.GetName(), size, g_LastParsedShaderName.c_str()); + cb.changeCounts = new int[size/4]; + memset (cb.changeCounts, 0, size); + cb.tryCounts = new int[size/4]; + memset (cb.tryCounts, 0, size); + #endif + + ID3D11Device* dev = GetD3D11Device(); + // Default usage and using UpdateSubresource is seemingly preferred path in drivers + // over dynamic buffer with Map. + D3D11_BUFFER_DESC desc; + desc.ByteWidth = size; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + + HRESULT hr = dev->CreateBuffer (&desc, NULL, &cb.buffer); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(cb.buffer,size,this); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (cb.buffer, Format("ConstantBuffer-%d-%d", id, size)); + + m_Buffers.push_back (cb); + m_BufferKeys.push_back (key); +} + +void ConstantBuffersD3D11::SetBuiltinCBConstant (int id, int offset, const void* data, int size) +{ + int idx = GetCBIndexByID (id); + ConstBuffer& cb = m_Buffers[idx]; + Assert (offset >= 0 && offset+size <= (m_BufferKeys[idx]>>16) && size > 0); + + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.tryCounts[i]; + #endif + + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || memcmp(cb.data+offset, data, size) != 0) + { + memcpy (cb.data+offset, data, size); + cb.dirty = true; + + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.changeCounts[i]; + #endif + } +} + +void ConstantBuffersD3D11::SetCBConstant (int idx, int offset, const void* data, int size) +{ + Assert (idx >= 0 && idx < m_Buffers.size()); + ConstBuffer& cb = m_Buffers[idx]; + Assert (offset >= 0 && offset+size <= (m_BufferKeys[idx]>>16) && size > 0); + + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.tryCounts[i]; + #endif + + if (size == 4) + { + UInt32* dstData = (UInt32*)(cb.data+offset); + UInt32 srcData = *(UInt32*)data; + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || *dstData != srcData) + { + *dstData = srcData; + cb.dirty = true; + + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.changeCounts[i]; + #endif + } + } + else + { + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || memcmp(cb.data+offset, data, size) != 0) + { + memcpy (cb.data+offset, data, size); + cb.dirty = true; + + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.changeCounts[i]; + #endif + } + } +} + +int ConstantBuffersD3D11::FindAndBindCB (int id, ShaderType shaderType, int bind, int size) +{ + UInt32 key = id | (size<<16); + int idx = 0; + for (ConstBufferKeys::const_iterator it = m_BufferKeys.begin(), itEnd = m_BufferKeys.end(); it != itEnd; ++it, ++idx) + { + if (*it == key) + { + ConstBuffer& cb = m_Buffers[idx]; + if (bind >= 0) + { + cb.bindIndex[shaderType] = bind; + cb.bindStages |= (1<<shaderType); + } + return idx; + } + } + Assert (false); + return -1; +} + +void ConstantBuffersD3D11::ResetBinds(ShaderType shaderType) +{ + for (ConstBuffers::iterator it = m_Buffers.begin(), itEnd = m_Buffers.end(); it != itEnd; ++it) + { + it->bindIndex[shaderType] = -1; + it->bindStages &= ~(1<<shaderType); + } +} + + +void ConstantBuffersD3D11::UpdateBuffers () +{ + ID3D11DeviceContext* ctx = GetD3D11Context(); + + D3D11_MAPPED_SUBRESOURCE mapped; + HRESULT hr; + size_t n = m_Buffers.size(); + + #if !UNITY_RELEASE + // check if we have duplicate buffers bound to the same slot (should never happen!) + UInt32 bound[kShaderTypeCount] = {0}; + for (size_t i = 0; i < n; ++i) + { + ConstBuffer& cb = m_Buffers[i]; + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) + { + int bind = cb.bindIndex[pt]; + if (bind >= 0 && bind < 32) + { + Assert (!(bound[pt] & (1<<bind))); + bound[pt] |= (1<<bind); + } + } + } + #endif + + + for (size_t i = 0; i < n; ++i) + { + ConstBuffer& cb = m_Buffers[i]; + if (!DEBUG_DISABLE_CONSTANT_BUFFER_CACHES && cb.bindStages == 0) + continue; + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || cb.dirty) + { + ctx->UpdateSubresource (cb.buffer, 0, NULL, cb.data, (m_BufferKeys[i]>>16), 1); + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + ++cb.statsDirty; + #endif + } + + int bindIndex; + + // Bind to used stages + // WP8 seems to be buggy with constant buffers; we need to always rebind them. Hence UNITY_WP8 test below. + #define BIND_CB(cbShaderType,dxCall) \ + bindIndex = cb.bindIndex[cbShaderType]; \ + if (bindIndex >= 0 && (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || UNITY_WP8 || m_ActiveBuffers[cbShaderType][bindIndex] != cb.buffer)) { \ + ctx->dxCall (bindIndex, 1, &cb.buffer); \ + m_ActiveBuffers[cbShaderType][bindIndex] = cb.buffer; \ + } + + BIND_CB(kShaderVertex,VSSetConstantBuffers); + BIND_CB(kShaderFragment,PSSetConstantBuffers); + BIND_CB(kShaderGeometry,GSSetConstantBuffers); + BIND_CB(kShaderHull,HSSetConstantBuffers); + BIND_CB(kShaderDomain,DSSetConstantBuffers); + cb.dirty = false; + } +} + + +#if DEBUG_D3D11_CONSTANT_BUFFER_STATS + +static void WriteTGAFile (const char* filename, int width, int height, const UInt8* bgr) +{ + FILE* f = fopen(filename, "wb"); + // header + putc(0,f); + putc(0,f); + putc(2,f); // uncompressed RGB + putc(0,f); putc(0,f); + putc(0,f); putc(0,f); + putc(0,f); + putc(0,f); putc(0,f); + putc(0,f); putc(0,f); + putc((width & 0x00FF),f); + putc((width & 0xFF00)>>8,f); + putc((height & 0x00FF),f); + putc((height & 0xFF00)>>8,f); + putc(24,f); // 24 bit + putc(0x20,f); // vertical flip + // data + fwrite (bgr, 3, width*height, f); + fclose (f); +} + +static void DensityToBGR (int density, UInt8* bgr) +{ + if (density < 1) + { + bgr[0] = bgr[1] = bgr[2] = 0; + return; + } + bgr[0] = clamp(40+density/4, 0, 255); + bgr[1] = clamp(40+density/4, 0, 255); + bgr[2] = clamp(40+density/4, 0, 255); +} + +static void PutBGRPixelBlock (UInt8* img, int imgWidth, int x, int y, const UInt8* bgr) +{ + for (int i = 0; i < 4; ++i) + { + UInt8* ptr = img + ((y+i)*imgWidth+x) * 3; + for (int j = 0; j < 4; ++j, ptr += 3) + { + ptr[0] = bgr[0]; + ptr[1] = bgr[1]; + ptr[2] = bgr[2]; + } + } +} + + +void ConstantBuffersD3D11::NewFrame() +{ + if (GetAsyncKeyState(VK_F7)) + { + printf_console ("DX11 Constant Buffer stats:\n"); + float traffic = 0.0f; + int uploads = 0; + int maxSize = 0; + for (size_t i = 0; i < m_BufferKeys.size(); ++i) + maxSize = std::max(int(m_BufferKeys[i]>>16), maxSize); + + int imgWidth = maxSize+1; + int imgHeight = m_Buffers.size()*3*4; + UInt8* imgData = new UInt8[imgWidth*imgHeight*3]; + memset (imgData, 0, imgWidth*imgHeight*3); + + for (size_t i = 0; i < m_Buffers.size(); ++i) + { + ConstBuffer& cb = m_Buffers[i]; + int cbId = (m_BufferKeys[i]&0xFFFF); + int cbSize = (m_BufferKeys[i]>>16); + ShaderLab::FastPropertyName name; + name.index = cbId; + traffic += (cbSize*cb.statsDirty)/1024.0f; + uploads += cb.statsDirty; + printf_console (" %s size:%i (%.1fkB in %i upl) vs:%i ps:%i\n", name.GetName(), cbSize, (cbSize*cb.statsDirty)/1024.0f, cb.statsDirty, cb.statsVS, cb.statsPS); + if (cb.statsDirty > 0) + { + for (int j = 0; j < cbSize/4; ++j) + { + UInt8 bgr[3]; + DensityToBGR (cb.tryCounts[j], bgr); + PutBGRPixelBlock (imgData, imgWidth, j*4, i*3*4, bgr); + DensityToBGR (cb.changeCounts[j], bgr); + PutBGRPixelBlock (imgData, imgWidth, j*4, i*3*4+4, bgr); + } + } + for (int j = 0; j < 8; ++j) + { + imgData[((i*3*4+j)*imgWidth + cbSize)*3 + 1] = 255; + } + } + WriteTGAFile ("cbStats.tga", imgWidth, imgHeight, imgData); + delete[] imgData; + printf_console (" =%i uploads, %.1fkB traffic\n\n", uploads, traffic); + } + + // reset stats + for (size_t i = 0; i < m_Buffers.size(); ++i) + { + ConstBuffer& cb = m_Buffers[i]; + int cbSize = (m_BufferKeys[i]>>16); + cb.statsDirty = cb.statsVS = cb.statsPS = 0; + memset (cb.changeCounts, 0, cbSize/4*4); + memset (cb.tryCounts, 0, cbSize/4*4); + } +} +#endif diff --git a/Runtime/GfxDevice/d3d11/ConstantBuffersD3D11.h b/Runtime/GfxDevice/d3d11/ConstantBuffersD3D11.h new file mode 100644 index 0000000..7c2a3eb --- /dev/null +++ b/Runtime/GfxDevice/d3d11/ConstantBuffersD3D11.h @@ -0,0 +1,74 @@ +#pragma once + +#include "D3D11Includes.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + + +#define DEBUG_D3D11_CONSTANT_BUFFER_STATS 0 + +#if DEBUG_D3D11_CONSTANT_BUFFER_STATS +#include <map> +#endif + + +class ConstantBuffersD3D11 +{ +public: + ConstantBuffersD3D11(); + ~ConstantBuffersD3D11() { Clear(); } + + void Clear(); + void InvalidateState(); + + struct ConstBuffer { + int bindIndex[kShaderTypeCount]; + unsigned bindStages; + bool dirty; + UInt8* data; + ID3D11Buffer* buffer; + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + int statsDirty; + int stats[kShaderTypeCount] + int* tryCounts; + int* changeCounts; + #endif + }; + + void SetCBInfo (int id, int size); + int FindAndBindCB (int id, ShaderType shaderType, int bind, int size); + void ResetBinds (ShaderType shaderType); + + void SetBuiltinCBConstant (int id, int offset, const void* data, int size); + void SetCBConstant (int index, int offset, const void* data, int size); + + void UpdateBuffers(); + void NewFrame(); + +private: + inline int GetCBIndexByID (int id) const + { + UInt32 key = id; + int n = m_BufferKeys.size(); + for (int i = 0; i < n; ++i) + { + if ((m_BufferKeys[i]&0xFFFF) == key) + return i; + } + Assert (false); + return -1; + } + +private: + typedef std::vector<UInt32> ConstBufferKeys; + typedef std::vector<ConstBuffer> ConstBuffers; + ConstBufferKeys m_BufferKeys; + ConstBuffers m_Buffers; + + ID3D11Buffer* m_ActiveBuffers[kShaderTypeCount][16]; +}; + + +#if !DEBUG_D3D11_CONSTANT_BUFFER_STATS +inline void ConstantBuffersD3D11::NewFrame() { } +#endif + diff --git a/Runtime/GfxDevice/d3d11/D3D11ByteCode.cpp b/Runtime/GfxDevice/d3d11/D3D11ByteCode.cpp new file mode 100644 index 0000000..8ec6c6a --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11ByteCode.cpp @@ -0,0 +1,2237 @@ +#include "UnityPrefix.h" +#include "D3D11ByteCode.h" +#include "D3D11Includes.h" +#include "Runtime/Utilities/BitUtility.h" +#include "External/DirectX/builds/dx9include/d3d9.h" + +// Some things in this file are based on Mesa3d DX11 state tracker: + +/************************************************************************** + * + * Copyright 2010 Luca Barbieri + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + + + +enum SM4SystemValue +{ + kSM4SV_UNDEFINED, + kSM4SV_POSITION, + kSM4SV_CLIP_DISTANCE, + kSM4SV_CULL_DISTANCE, + kSM4SV_RENDER_TARGET_ARRAY_INDEX, + kSM4SV_VIEWPORT_ARRAY_INDEX, + kSM4SV_VERTEX_ID, + kSM4SV_PRIMITIVE_ID, + kSM4SV_INSTANCE_ID, + kSM4SV_IS_FRONT_FACE, + kSM4SV_SAMPLE_INDEX, + kSM4SV_FINAL_QUAD_U_EQ_0_EDGE_TESSFACTOR, + kSM4SV_FINAL_QUAD_V_EQ_0_EDGE_TESSFACTOR, + kSM4SV_FINAL_QUAD_U_EQ_1_EDGE_TESSFACTOR, + kSM4SV_FINAL_QUAD_V_EQ_1_EDGE_TESSFACTOR, + kSM4SV_FINAL_QUAD_U_INSIDE_TESSFACTOR, + kSM4SV_FINAL_QUAD_V_INSIDE_TESSFACTOR, + kSM4SV_FINAL_TRI_U_EQ_0_EDGE_TESSFACTOR, + kSM4SV_FINAL_TRI_V_EQ_0_EDGE_TESSFACTOR, + kSM4SV_FINAL_TRI_W_EQ_0_EDGE_TESSFACTOR, + kSM4SV_FINAL_TRI_INSIDE_TESSFACTOR, + kSM4SV_FINAL_LINE_DETAIL_TESSFACTOR, + kSM4SV_FINAL_LINE_DENSITY_TESSFACTOR, + kSM4SV_COUNT +}; + +enum SM4InstrExtype +{ + SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_EMPTY, + SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_SAMPLE_CONTROLS, + SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_DIM, + SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_RETURN_TYPE, + SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_COUNT +}; + +enum SM4OperExtype +{ + SM4_TOKEN_OPERAND_EXTENDED_TYPE_EMPTY, + SM4_TOKEN_OPERAND_EXTENDED_TYPE_MODIFIER, + SM4_TOKEN_OPERAND_EXTENDED_TYPE_COUNT +}; + +enum SM4ReturnType +{ + kSM4RetType_UNORM = 1, + kSM4RetType_SNORM = 2, + kSM4RetType_SINT = 3, + kSM4RetType_UINT = 4, + kSM4RetType_FLOAT = 5, + kSM4RetType_MIXED = 6, +}; + + +const char* kSM4OpcodeNames[kSM4Op_COUNT] = { + "add", + "and", + "break", + "breakc", + "call", + "callc", + "case", + "continue", + "continuec", + "cut", + "default", + "deriv_rtx", + "deriv_rty", + "discard", + "div", + "dp2", + "dp3", + "dp4", + "else", + "emit", + "emitthencut", + "endif", + "endloop", + "endswitch", + "eq", + "exp", + "frc", + "ftoi", + "ftou", + "ge", + "iadd", + "if", + "ieq", + "ige", + "ilt", + "imad", + "imax", + "imin", + "imul", + "ine", + "ineg", + "ishl", + "ishr", + "itof", + "label", + "ld", + "ldms", + "log", + "loop", + "lt", + "mad", + "min", + "max", + "customdata", + "mov", + "movc", + "mul", + "ne", + "nop", + "not", + "or", + "resinfo", + "ret", + "retc", + "round_ne", + "round_ni", + "round_pi", + "round_z", + "rsq", + "sample", + "sample_c", + "sample_c_lz", + "sample_l", + "sample_d", + "sample_b", + "sqrt", + "switch", + "sincos", + "udiv", + "ult", + "uge", + "umul", + "umad", + "umax", + "umin", + "ushr", + "utof", + "xor", + "dcl_resource", + "dcl_constant_buffer", + "dcl_sampler", + "dcl_index_range", + "dcl_gs_output_primitive_topology", + "dcl_gs_input_primitive", + "dcl_max_output_vertex_count", + "dcl_input", + "dcl_input_sgv", + "dcl_input_siv", + "dcl_input_ps", + "dcl_input_ps_sgv", + "dcl_input_ps_siv", + "dcl_output", + "dcl_output_sgv", + "dcl_output_siv", + "dcl_temps", + "dcl_indexable_temp", + "dcl_global_flags", + "d3d10_count", + "lod", + "gather4", + "sample_pos", + "sample_info", + "d3d10_1_count", + "hs_decls", + "hs_control_point_phase", + "hs_fork_phase", + "hs_join_phase", + "emit_stream", + "cut_stream", + "emitthencut_stream", + "interface_call", + "bufinfo", + "deriv_rtx_coarse", + "deriv_rtx_fine", + "deriv_rty_coarse", + "deriv_rty_fine", + "gather4_c", + "gather4_po", + "gather4_po_c", + "rcp", + "f32tof16", + "f16tof32", + "uaddc", + "usubb", + "countbits", + "firstbit_hi", + "firstbit_lo", + "firstbit_shi", + "ubfe", + "ibfe", + "bfi", + "bfrev", + "swapc", + "dcl_stream", + "dcl_function_body", + "dcl_function_table", + "dcl_interface", + "dcl_input_control_point_count", + "dcl_output_control_point_count", + "dcl_tess_domain", + "dcl_tess_partitioning", + "dcl_tess_output_primitive", + "dcl_hs_max_tessfactor", + "dcl_hs_fork_phase_instance_count", + "dcl_hs_join_phase_instance_count", + "dcl_thread_group", + "dcl_unordered_access_view_typed", + "dcl_unordered_access_view_raw", + "dcl_unordered_access_view_structured", + "dcl_thread_group_shared_memory_raw", + "dcl_thread_group_shared_memory_structured", + "dcl_resource_raw", + "dcl_resource_structured", + "ld_uav_typed", + "store_uav_typed", + "ld_raw", + "store_raw", + "ld_structured", + "store_structured", + "atomic_and", + "atomic_or", + "atomic_xor", + "atomic_cmp_store", + "atomic_iadd", + "atomic_imax", + "atomic_imin", + "atomic_umax", + "atomic_umin", + "imm_atomic_alloc", + "imm_atomic_consume", + "imm_atomic_iadd", + "imm_atomic_and", + "imm_atomic_or", + "imm_atomic_xor", + "imm_atomic_exch", + "imm_atomic_cmp_exch", + "imm_atomic_imax", + "imm_atomic_imin", + "imm_atomic_umax", + "imm_atomic_umin", + "sync", + "dadd", + "dmax", + "dmin", + "dmul", + "deq", + "dge", + "dlt", + "dne", + "dmov", + "dmovc", + "dtof", + "ftod", + "eval_snapped", + "eval_sample_index", + "eval_centroid", + "dcl_gs_instance_count", +}; + +struct SM4TokVersion +{ + unsigned minor : 4; + unsigned major : 4; + unsigned format : 8; + unsigned type : 16; +}; + + + +struct SM4TokResourceReturnType +{ + unsigned x : 4; + unsigned y : 4; + unsigned z : 4; + unsigned w : 4; +}; + + +#define SM4_OPERAND_SEL_MASK(sel) ((sel) & 0xf) +#define SM4_OPERAND_SEL_SWZ(sel, i) (((sel) >> ((i) * 2)) & 3) +#define SM4_OPERAND_SEL_SCALAR(sel) ((sel) & 3) + +struct SM4TokOperandEx +{ + union { + UInt32 dword; + struct { + unsigned type : 6; + unsigned neg : 1; + unsigned abs : 1; + }; + }; +}; + +struct SM4TokResourceRetType +{ + union { + UInt32 dword; + struct { + unsigned x : 4; + unsigned y : 4; + unsigned z : 4; + unsigned w : 4; + unsigned reserved : 16; + }; + }; +}; + + +union SM4Any +{ + float f32; + SInt64 i64; + SInt32 i32; +}; + +struct SM4Op; +struct SM4Instr; +struct SM4Decl; +struct SM4Program; + + +struct SM4Op +{ + UInt8 mode; + UInt8 comps; + UInt8 mask; + UInt8 num_indices; + UInt8 swizzle[4]; + SM4RegFile file; + SM4Any imm_values[4]; + bool neg; + bool abs; + struct + { + SInt64 disp; + std::auto_ptr<SM4Op> reg; + } indices[3]; + + bool is_index_simple(unsigned i) const + { + return !indices[i].reg.get() && indices[i].disp >= 0 && (SInt64)(SInt32)indices[i].disp == indices[i].disp; + } + + bool has_simple_index() const + { + return num_indices == 1 && is_index_simple(0); + } + + SM4Op() + { + memset(this, 0, sizeof(*this)); + } + +private: + SM4Op(const SM4Op& op) + {} +}; + +/* for sample_d */ +#define SM4_MAX_OPS 6 + +struct SM4Instr : public SM4TokInstruction +{ + SInt8 sample_offset[3]; + UInt8 resource_target; + UInt8 resource_return_type[4]; + + unsigned num; + unsigned num_ops; + std::auto_ptr<SM4Op> ops[SM4_MAX_OPS]; + + SM4Instr() + { + memset(this, 0, sizeof(*this)); + } + +private: + SM4Instr(const SM4Instr& op) + {} +}; + +struct SM4Decl : public SM4TokInstruction +{ + std::auto_ptr<SM4Op> op; + union + { + unsigned num; + float f32; + SM4SystemValue sv; + struct + { + unsigned id; + unsigned expected_function_table_length; + unsigned table_length; + unsigned array_length; + } intf; + unsigned thread_group_size[3]; + SM4TokResourceReturnType rrt; + struct + { + unsigned num; + unsigned comps; + } indexable_temp; + struct + { + unsigned stride; + unsigned count; + } structured; + }; + + void* data; + + SM4Decl() + { + memset(this, 0, sizeof(*this)); + } + + ~SM4Decl() + { + free(data); + } + +private: + SM4Decl(const SM4Decl& op) + {} +}; + +struct _D3D11_SIGNATURE_PARAMETER_DESC; + +struct SM4Program +{ + SM4TokVersion version; + dynamic_array<SM4Decl*> dcls; + dynamic_array<SM4Instr*> insns; + + SM4Program() + { + memset(&version, 0, sizeof(version)); + } + + ~SM4Program() + { + for(dynamic_array<SM4Decl*>::iterator i = dcls.begin(), e = dcls.end(); i != e; ++i) + delete *i; + for(dynamic_array<SM4Instr*>::iterator i = insns.begin(), e = insns.end(); i != e; ++i) + delete *i; + } + +private: + SM4Program(const SM4Decl& op) + {} +}; + +SM4Program* sm4_parse(const void* tokens, int size); + + + + +struct DXBCHeader +{ + UInt32 fourcc; + UInt32 hash[4]; + UInt32 one; + UInt32 total_size; + UInt32 chunk_count; +}; + + +static inline DXBCChunkHeader* dxbc_find_shader_bytecode(const void* data, int size) +{ + DXBCChunkHeader* chunk; + chunk = dxbc_find_chunk(data, size, kFOURCC_SHDR); + if(!chunk) + chunk = dxbc_find_chunk(data, size, kFOURCC_SHEX); + return chunk; +} + +#define DXBC_FIND_INPUT_SIGNATURE 0 +#define DXBC_FIND_OUTPUT_SIGNATURE 1 +#define DXBC_FIND_PATCH_SIGNATURE 2 + +static inline DXBCChunkSig* dxbc_find_signature(const void* data, int size, unsigned kind) +{ + unsigned fourcc; + switch(kind) { + case DXBC_FIND_INPUT_SIGNATURE: fourcc = kFOURCC_ISGN; break; + case DXBC_FIND_OUTPUT_SIGNATURE: fourcc = kFOURCC_OSGN; break; + case DXBC_FIND_PATCH_SIGNATURE: fourcc = kFOURCC_PCSG; break; + default: + return NULL; + } + return (DXBCChunkSig*)dxbc_find_chunk(data, size, fourcc); +} + +std::pair<void*, size_t> dxbc_assemble(struct DXBCChunkHeader** chunks, unsigned num_chunks); + + +DXBCContainer* dxbc_parse(const void* data, int size) +{ + std::auto_ptr<DXBCContainer> container(new DXBCContainer()); + container->data = data; + DXBCHeader* header = (DXBCHeader*)data; + UInt32* chunk_offsets = (UInt32*)(header + 1); + if(header->fourcc != kFOURCC_DXBC) + return 0; + unsigned num_chunks = header->chunk_count; + for(unsigned i = 0; i < num_chunks; ++i) + { + unsigned offset = chunk_offsets[i]; + DXBCChunkHeader* chunk = (DXBCChunkHeader*)((char*)data + offset); + unsigned fourcc = chunk->fourcc; + container->chunks.push_back(chunk); + } + return container.release(); +} + +DXBCChunkHeader* dxbc_find_chunk(const void* data, int size, unsigned fourcc) +{ + DXBCHeader* header = (DXBCHeader*)data; + UInt32* chunk_offsets = (UInt32*)(header + 1); + if(header->fourcc != kFOURCC_DXBC) + return 0; + unsigned num_chunks = header->chunk_count; + for(unsigned i = 0; i < num_chunks; ++i) + { + unsigned offset = chunk_offsets[i]; + DXBCChunkHeader* chunk = (DXBCChunkHeader*)((char*)data + offset); + if(chunk->fourcc == fourcc) + return chunk; + } + return 0; +} + +static void print_binary_chunk (const DXBCChunkHeader& chk, int perLine = 16) +{ + const char* kHex = "0123456789abcdef"; + const UInt8* ptr = ((const UInt8*)&chk) + sizeof(DXBCChunkHeader); + std::string res; + for (unsigned i = 0; i < chk.size; ++i) + { + if (i != 0 && i%perLine == 0) + res += '\n'; + if ((i & 3) == 0) + res += ' '; + UInt8 b = ptr[i]; + res += kHex[b>>4]; + res += kHex[b&0xF]; + } + printf_console ("%s\n", res.c_str()); +} + +static void print_sm4_program (const SM4Program& prog) +{ +} + +void dxbc_print(const DXBCContainer* dxbc) +{ + printf_console ("DXBC dump:\n"); + if (!dxbc) + { + printf_console ("null\n"); + return; + } + + printf_console ("chunk count: %d\n", (int)dxbc->chunks.size()); + for (size_t i = 0; i < dxbc->chunks.size(); ++i) + { + const DXBCChunkHeader& chk = *dxbc->chunks[i]; + printf_console ("chunk #%i: %c%c%c%c size %u\n", (int)i, chk.fourcc&0xFF, (chk.fourcc>>8)&0xFF, (chk.fourcc>>16)&0xFF, (chk.fourcc>>24)&0xFF, chk.size); + if (chk.fourcc == kFOURCC_ISGN || chk.fourcc == kFOURCC_OSGN) + { + print_binary_chunk (chk); + const DXBCChunkSig* sig = (const DXBCChunkSig*)&chk; + D3D11_SIGNATURE_PARAMETER_DESC* params; + int count = dxbc_parse_signature (sig, ¶ms); + for (int j = 0; j < count; ++j) + { + const D3D11_SIGNATURE_PARAMETER_DESC& p = params[j]; + printf_console (" #%i: %s/%u reg %u sv %u type %u mask %x rwmask %x stream %u\n", + j, p.SemanticName, p.SemanticIndex, p.Register, p.SystemValueType, p.ComponentType, p.Mask, p.ReadWriteMask, p.Stream); + } + free (params); + } + else if (chk.fourcc == kFOURCC_SHDR || chk.fourcc == kFOURCC_SHEX) + { + printf_console ("shader code:\n"); + print_binary_chunk (chk); + SM4Program* prog = sm4_parse((&chk)+1, chk.size); + if (prog) + { + print_sm4_program(*prog); + delete prog; + } + } + } +} + + +int dxbc_parse_signature(const DXBCChunkSig* sig, D3D11_SIGNATURE_PARAMETER_DESC** params) +{ + unsigned count = sig->count; + *params = (D3D11_SIGNATURE_PARAMETER_DESC*)malloc(sizeof(D3D11_SIGNATURE_PARAMETER_DESC) * count); + + for (unsigned i = 0; i < count; ++i) + { + D3D11_SIGNATURE_PARAMETER_DESC& param = (*params)[i]; + param.SemanticName = (char*)&sig->count + sig->elements[i].name_offset; + param.SemanticIndex = sig->elements[i].semantic_index; + param.SystemValueType = (D3D_NAME)sig->elements[i].system_value_type; + param.ComponentType = (D3D_REGISTER_COMPONENT_TYPE)sig->elements[i].component_type; + param.Register = sig->elements[i].register_num; + param.Mask = sig->elements[i].mask; + param.ReadWriteMask = sig->elements[i].read_write_mask; + param.Stream = sig->elements[i].stream; + } + return count; +} + +// sm4_parse.cpp + +struct SM4Parser +{ + const unsigned* tokens; + const unsigned* tokens_end; + SM4Program& program; + + SM4Parser(SM4Program& program, const void* p_tokens, unsigned size) + : program(program) + { + tokens = (const unsigned*)p_tokens; + tokens_end = (const unsigned*)((const char*)p_tokens + size); + } + + UInt32 read32() + { + Assert(tokens < tokens_end); + return *tokens++; + } + + template<typename T> + void read_token(T* tok) + { + *(unsigned*)tok = read32(); + } + + UInt64 read64() + { + unsigned a = read32(); + unsigned b = read32(); + return (UInt64)a | ((UInt64)b << 32); + } + + void skip(unsigned toskip) + { + tokens += toskip; + } + + bool read_op(SM4Op* pop) + { + SM4Op& op = *pop; + SM4TokOperand optok; + read_token(&optok); + if (optok.file >= kSM4File_COUNT) + { + AssertString ("DXBC: unknown register type"); + return false; + } + op.swizzle[0] = 0; + op.swizzle[1] = 1; + op.swizzle[2] = 2; + op.swizzle[3] = 3; + op.mask = 0xf; + switch(optok.comps_enum) + { + case kSM4OperComp0: + op.comps = 0; + break; + case kSM4OperComp1: + op.comps = 1; + op.swizzle[1] = op.swizzle[2] = op.swizzle[3] = 0; + break; + case kSM4OperComp4: + op.comps = 4; + op.mode = optok.mode; + switch(optok.mode) + { + case SM4_OPERAND_MODE_MASK: + op.mask = SM4_OPERAND_SEL_MASK(optok.sel); + break; + case SM4_OPERAND_MODE_SWIZZLE: + op.swizzle[0] = SM4_OPERAND_SEL_SWZ(optok.sel, 0); + op.swizzle[1] = SM4_OPERAND_SEL_SWZ(optok.sel, 1); + op.swizzle[2] = SM4_OPERAND_SEL_SWZ(optok.sel, 2); + op.swizzle[3] = SM4_OPERAND_SEL_SWZ(optok.sel, 3); + break; + case SM4_OPERAND_MODE_SCALAR: + op.swizzle[0] = op.swizzle[1] = op.swizzle[2] = op.swizzle[3] = SM4_OPERAND_SEL_SCALAR(optok.sel); + break; + } + break; + case kSM4OperCompN: + AssertString("Unhandled operand component type"); + return false; + break; + } + op.file = (SM4RegFile)optok.file; + op.num_indices = optok.num_indices; + + if(optok.extended) + { + SM4TokOperandEx optokext; + read_token(&optokext); + if(optokext.type == 0) + {} + else if(optokext.type == 1) + { + op.neg = optokext.neg; + op.abs= optokext.abs; + } + else + { + AssertString("Unhandled extended operand token type"); + return false; + } + } + + for(unsigned i = 0; i < op.num_indices; ++i) + { + unsigned repr; + if(i == 0) + repr = optok.index0_repr; + else if(i == 1) + repr = optok.index1_repr; + else if(i == 2) + repr = optok.index2_repr; + else + { + AssertString("Unhandled operand index representation"); + return false; + } + op.indices[i].disp = 0; + // TODO: is disp supposed to be signed here?? + switch(repr) + { + case SM4_OPERAND_INDEX_REPR_IMM32: + op.indices[i].disp = (SInt32)read32(); + break; + case SM4_OPERAND_INDEX_REPR_IMM64: + op.indices[i].disp = read64(); + break; + case SM4_OPERAND_INDEX_REPR_REG: +relative: + op.indices[i].reg.reset(new SM4Op()); + if (!read_op(&*op.indices[i].reg)) + return false; + break; + case SM4_OPERAND_INDEX_REPR_REG_IMM32: + op.indices[i].disp = (SInt32)read32(); + goto relative; + case SM4_OPERAND_INDEX_REPR_REG_IMM64: + op.indices[i].disp = read64(); + goto relative; + } + } + + if(op.file == kSM4File_IMMEDIATE32) + { + for(unsigned i = 0; i < op.comps; ++i) + op.imm_values[i].i32 = read32(); + } + else if(op.file == kSM4File_IMMEDIATE64) + { + for(unsigned i = 0; i < op.comps; ++i) + op.imm_values[i].i64 = read64(); + } + return true; + } + + bool parse() + { + read_token(&program.version); + + unsigned lentok = read32(); + tokens_end = tokens - 2 + lentok; + + while(tokens != tokens_end) + { + SM4TokInstruction insntok; + read_token(&insntok); + const unsigned* insn_end = tokens - 1 + insntok.length; + SM4Opcode opcode = (SM4Opcode)insntok.opcode; + if (opcode >= kSM4Op_COUNT) + { + AssertString ("Unknown DXBC opcode"); + return false; + } + + if(opcode == kSM4Op_CUSTOMDATA) + { + // immediate constant buffer data + unsigned customlen = read32() - 2; + + SM4Decl& dcl = *new SM4Decl; + program.dcls.push_back(&dcl); + + dcl.opcode = kSM4Op_CUSTOMDATA; + dcl.num = customlen; + dcl.data = malloc(customlen * sizeof(tokens[0])); + + memcpy(dcl.data, &tokens[0], customlen * sizeof(tokens[0])); + + skip(customlen); + continue; + } + + if(opcode == kSM4Op_HS_FORK_PHASE || opcode == kSM4Op_HS_JOIN_PHASE) + { + // need to interleave these with the declarations or we cannot + // assign fork/join phase instance counts to phases + SM4Decl& dcl = *new SM4Decl; + program.dcls.push_back(&dcl); + dcl.opcode = opcode; + } + + if((opcode >= kSM4Op_DCL_RESOURCE && opcode <= kSM4Op_DCL_GLOBAL_FLAGS) + || (opcode >= kSM4Op_DCL_STREAM && opcode <= kSM4Op_DCL_RESOURCE_STRUCTURED)) + { + SM4Decl& dcl = *new SM4Decl; + program.dcls.push_back(&dcl); + (SM4TokInstruction&)dcl = insntok; + + SM4TokInstructionEx exttok; + memcpy(&exttok, &insntok, sizeof(exttok)); + while(exttok.extended) + { + read_token(&exttok); + } + +#define READ_OP_ANY dcl.op.reset(new SM4Op()); if (!read_op(&*dcl.op)) return false; +#define READ_OP(FILE) READ_OP_ANY + //Assert(dcl.op->file == kSM4File_##FILE); + + switch(opcode) + { + case kSM4Op_DCL_GLOBAL_FLAGS: + break; + case kSM4Op_DCL_RESOURCE: + READ_OP(RESOURCE); + read_token(&dcl.rrt); + break; + case kSM4Op_DCL_SAMPLER: + READ_OP(SAMPLER); + break; + case kSM4Op_DCL_INPUT: + case kSM4Op_DCL_INPUT_PS: + READ_OP(INPUT); + break; + case kSM4Op_DCL_INPUT_SIV: + case kSM4Op_DCL_INPUT_SGV: + case kSM4Op_DCL_INPUT_PS_SIV: + case kSM4Op_DCL_INPUT_PS_SGV: + READ_OP(INPUT); + dcl.sv = (SM4SystemValue)(UInt16)read32(); + break; + case kSM4Op_DCL_OUTPUT: + READ_OP(OUTPUT); + break; + case kSM4Op_DCL_OUTPUT_SIV: + case kSM4Op_DCL_OUTPUT_SGV: + READ_OP(OUTPUT); + dcl.sv = (SM4SystemValue)(UInt16)read32(); + break; + case kSM4Op_DCL_INDEX_RANGE: + READ_OP_ANY; + Assert(dcl.op->file == kSM4File_INPUT || dcl.op->file == kSM4File_OUTPUT); + dcl.num = read32(); + break; + case kSM4Op_DCL_TEMPS: + dcl.num = read32(); + break; + case kSM4Op_DCL_INDEXABLE_TEMP: + READ_OP(INDEXABLE_TEMP); + dcl.indexable_temp.num = read32(); + dcl.indexable_temp.comps = read32(); + break; + case kSM4Op_DCL_CONSTANT_BUFFER: + READ_OP(CONSTANT_BUFFER); + break; + case kSM4Op_DCL_GS_INPUT_PRIMITIVE: + case kSM4Op_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY: + break; + case kSM4Op_DCL_MAX_OUTPUT_VERTEX_COUNT: + dcl.num = read32(); + break; + case kSM4Op_DCL_GS_INSTANCE_COUNT: + dcl.num = read32(); + break; + case kSM4Op_DCL_INPUT_CONTROL_POINT_COUNT: + case kSM4Op_DCL_OUTPUT_CONTROL_POINT_COUNT: + case kSM4Op_DCL_TESS_DOMAIN: + case kSM4Op_DCL_TESS_PARTITIONING: + case kSM4Op_DCL_TESS_OUTPUT_PRIMITIVE: + break; + case kSM4Op_DCL_HS_MAX_TESSFACTOR: + dcl.f32 = read32(); + break; + case kSM4Op_DCL_HS_FORK_PHASE_INSTANCE_COUNT: + dcl.num = read32(); + break; + case kSM4Op_DCL_FUNCTION_BODY: + dcl.num = read32(); + break; + case kSM4Op_DCL_FUNCTION_TABLE: + dcl.num = read32(); + dcl.data = malloc(dcl.num * sizeof(UInt32)); + for(unsigned i = 0; i < dcl.num; ++i) + ((UInt32*)dcl.data)[i] = read32(); + break; + case kSM4Op_DCL_INTERFACE: + dcl.intf.id = read32(); + dcl.intf.expected_function_table_length = read32(); + { + UInt32 v = read32(); + dcl.intf.table_length = v & 0xffff; + dcl.intf.array_length = v >> 16; + } + dcl.data = malloc(dcl.intf.table_length * sizeof(UInt32)); + for(unsigned i = 0; i < dcl.intf.table_length; ++i) + ((UInt32*)dcl.data)[i] = read32(); + break; + case kSM4Op_DCL_THREAD_GROUP: + dcl.thread_group_size[0] = read32(); + dcl.thread_group_size[1] = read32(); + dcl.thread_group_size[2] = read32(); + break; + case kSM4Op_DCL_UNORDERED_ACCESS_VIEW_TYPED: + READ_OP(UNORDERED_ACCESS_VIEW); + read_token(&dcl.rrt); + break; + case kSM4Op_DCL_UNORDERED_ACCESS_VIEW_RAW: + READ_OP(UNORDERED_ACCESS_VIEW); + break; + case kSM4Op_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED: + READ_OP(UNORDERED_ACCESS_VIEW); + dcl.structured.stride = read32(); + break; + case kSM4Op_DCL_THREAD_GROUP_SHARED_MEMORY_RAW: + READ_OP(THREAD_GROUP_SHARED_MEMORY); + dcl.num = read32(); + break; + case kSM4Op_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED: + READ_OP(THREAD_GROUP_SHARED_MEMORY); + dcl.structured.stride = read32(); + dcl.structured.count = read32(); + break; + case kSM4Op_DCL_RESOURCE_RAW: + READ_OP(RESOURCE); + break; + case kSM4Op_DCL_RESOURCE_STRUCTURED: + READ_OP(RESOURCE); + dcl.structured.stride = read32(); + break; + case kSM4Op_DCL_STREAM: + // TODO: dcl_stream is undocumented: what is it? + AssertString("DXBC: Unhandled dcl_stream since it's undocumented"); + return false; + break; + default: + AssertString("DXBC: Unhandled declaration type"); + return false; + } + + if (tokens != insn_end) + { + AssertString("DXBC: token size mismatch"); + return false; + } + } + else + { + SM4Instr& insn = *new SM4Instr; + program.insns.push_back(&insn); + (SM4TokInstruction&)insn = insntok; + + SM4TokInstructionEx exttok; + memcpy(&exttok, &insntok, sizeof(exttok)); + while(exttok.extended) + { + read_token(&exttok); + if(exttok.type == SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_SAMPLE_CONTROLS) + { + insn.sample_offset[0] = exttok.sample_controls.offset_u; + insn.sample_offset[1] = exttok.sample_controls.offset_v; + insn.sample_offset[2] = exttok.sample_controls.offset_w; + } + else if(exttok.type == SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_DIM) + insn.resource_target = exttok.resource_target.target; + else if(exttok.type == SM4_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_RETURN_TYPE) + { + insn.resource_return_type[0] = exttok.resource_return_type.x; + insn.resource_return_type[1] = exttok.resource_return_type.y; + insn.resource_return_type[2] = exttok.resource_return_type.z; + insn.resource_return_type[3] = exttok.resource_return_type.w; + } + } + + switch(opcode) + { + case kSM4Op_INTERFACE_CALL: + insn.num = read32(); + break; + default: + break; + } + + unsigned op_num = 0; + while(tokens != insn_end) + { + if (tokens >= insn_end) + { + AssertString ("DXBC: token size mismatch"); + return false; + } + if (op_num >= SM4_MAX_OPS) + { + AssertString ("DXBC: too many operands"); + return false; + } + insn.ops[op_num].reset(new SM4Op); + if (!read_op(&*insn.ops[op_num])) + return false; + ++op_num; + } + insn.num_ops = op_num; + } + } + return true; + } +}; + +SM4Program* sm4_parse(const void* tokens, int size) +{ + SM4Program* program = new SM4Program; + SM4Parser parser(*program, tokens, size); + if(parser.parse()) + return program; + delete program; + return 0; +} + +static void dxbc_create_internal(struct DXBCChunkHeader** chunks, unsigned num_chunks, void* buffer, unsigned total_size) +{ + DXBCHeader* header = (DXBCHeader*)buffer; + + header->fourcc = kFOURCC_DXBC; + memset(header->hash, 0, sizeof(header->hash)); + + header->one = 1; + header->total_size = total_size; + header->chunk_count = num_chunks; + + UInt32* chunk_offsets = (UInt32*)(header + 1); + UInt32 off = sizeof(struct DXBCHeader) + num_chunks * sizeof(UInt32); + for(unsigned i = 0; i < num_chunks; ++i) + { + chunk_offsets[i] = off; + unsigned chunk_full_size = sizeof(DXBCChunkHeader) + chunks[i]->size; + memcpy((char*)header + off, chunks[i], chunk_full_size); + off += chunk_full_size; + } + + void D3DHash (const unsigned char* data, unsigned size, unsigned char res[16]); + D3DHash ((const UInt8*)&header->one, total_size-20, (UInt8*)header->hash); +} + + +static std::pair<void*, size_t> dxbc_create(struct DXBCChunkHeader** chunks, unsigned num_chunks) +{ + size_t data_size = 0; + for(unsigned i = 0; i < num_chunks; ++i) + data_size += sizeof(UInt32) + sizeof(DXBCChunkHeader) + chunks[i]->size; + const size_t total_size = sizeof(DXBCHeader) + data_size; + + void* buffer = malloc(total_size); + if (!buffer) + return std::make_pair((void*)0, 0); + + dxbc_create_internal (chunks, num_chunks, buffer, total_size); + + return std::make_pair(buffer, total_size); +} + + +void dxbc_create(struct DXBCChunkHeader** chunks, unsigned num_chunks, dynamic_array<UInt8>& out) +{ + size_t data_size = 0; + for(unsigned i = 0; i < num_chunks; ++i) + data_size += sizeof(UInt32) + sizeof(DXBCChunkHeader) + chunks[i]->size; + const size_t total_size = sizeof(DXBCHeader) + data_size; + + out.resize_uninitialized (total_size); + + dxbc_create_internal (chunks, num_chunks, out.data(), total_size); +} + + + + +// ------------------------------------------------------------------- + +enum DXBCBuilderChunks { + kBuilderChunkInput = 0, + kBuilderChunkOutput, + kBuilderChunkCode, + kBuilderChunkSM20, + kBuilderChunkCount +}; +struct SigElement { + const char* name; + int index; + int reg; + int mask; +}; + +struct DXBCCodeBuilder +{ + DXBCCodeBuilder(dynamic_array<UInt32>& destArray) + : insns(destArray) + , curInsnIndex(-1) + , tempCount(0) + , opcode(kSM4Op_MOV) + , opcode2(kSM2Op_MOV) + , saturate(0) + { } + dynamic_array<UInt32>& insns; // reference to actual output array! + int curInsnIndex; + int tempCount; + + SM4Opcode opcode; + SM2Opcode opcode2; + + int saturate; + char dstRegType; + int dstRegIndex; + unsigned dstRegMask; + unsigned dstRegComps; + int tmpSatRegIndex; +}; + +struct DXBCBuilder +{ + DXBCBuilder() : codeBuilder(insns) { } + DXBCCodeBuilder codeBuilder; + dynamic_array<SigElement> inputs; + dynamic_array<SigElement> outputs; + dynamic_array<UInt32> insns; + dynamic_array<UInt32> dcls; + //sm20 stuff + dynamic_array<UInt32> inputs2; + dynamic_array<UInt32> defs2; + dynamic_array<UInt32> insns2; + std::map<UInt32,UInt32> outputMap; + std::map<UInt32,UInt32> inputMap; + + int numTextures2; + int curInsnIndex2; + + SM4TokVersion version; + DXBCChunkHeader* chunks[kBuilderChunkCount]; +}; + +DXBCCodeBuilder* dxb_create_code(dynamic_array<UInt32>& destArray) +{ + DXBCCodeBuilder* b = new DXBCCodeBuilder(destArray); + return b; +} + +void dxb_destroy_code(DXBCCodeBuilder* b) +{ + delete b; +} + +const UInt32* dxb_get_code(DXBCCodeBuilder* b, size_t* outSize) +{ + *outSize = b->insns.size(); + return b->insns.data(); +} + + +DXBCBuilder* dxb_create(int major, int minor, SM4ShaderType type) +{ + DXBCBuilder* b = new DXBCBuilder(); + memset (b->chunks, 0, sizeof(b->chunks)); + b->version.major = major; + b->version.minor = minor; + b->version.type = type; + b->version.format = 0; //@TODO? + b->numTextures2 = 0; + + return b; +} +void dxb_destroy(DXBCBuilder* b) +{ + if (b) + { + for (int i = 0; i < kBuilderChunkCount; ++i) + if (b->chunks[i]) + free(b->chunks[i]); + } + delete b; +} + +DXBCCodeBuilder* dxb_get_code_builder(DXBCBuilder* b) +{ + return &b->codeBuilder; +} + + +void dxb_dcl_input (DXBCBuilder* b, const char* name, int index, int reg, int mask) +{ + SigElement el; + el.name = name; + el.index = index; + el.reg = reg; + el.mask = mask; + b->inputs.push_back (el); + + dxb_dcl_input2(b,name,index,reg,mask); +} + +void dxb_dcl_output (DXBCBuilder* b, const char* name, int index, int reg, int mask) +{ + SigElement el; + el.name = name; + el.index = index; + el.reg = reg; + el.mask = mask; + b->outputs.push_back (el); + + dxb_dcl_output2(b,name,index,reg,mask); +} + + +void dxb_dcl_tex (DXBCBuilder* b, int index, SM4Target dim) +{ + SM4TokInstruction dcl; + dcl.dword = 0; + dcl.opcode = kSM4Op_DCL_SAMPLER; + dcl.length = 3; + b->dcls.push_back (dcl.dword); + SM4TokOperand op; + op.dword = 0; + op.file = kSM4File_SAMPLER; + op.num_indices = 1; + b->dcls.push_back (op.dword); + b->dcls.push_back (index); + + dcl.dword = 0; + dcl.opcode = kSM4Op_DCL_RESOURCE; + dcl.length = 4; + dcl.dcl_resource.target = dim; + b->dcls.push_back (dcl.dword); + op.dword = 0; + op.file = kSM4File_RESOURCE; + op.num_indices = 1; + SM4TokResourceRetType ret; + ret.dword = 0; + ret.x = ret.y = ret.z = ret.w = kSM4RetType_FLOAT; + b->dcls.push_back (op.dword); + b->dcls.push_back (index); + b->dcls.push_back (ret.dword); + + dxb_dcl_tex2 (b, index, dim); +} + + +void dxb_dcl_cb (DXBCBuilder* b, int index, int size) +{ + SM4TokInstruction dcl; + dcl.dword = 0; + dcl.opcode = kSM4Op_DCL_CONSTANT_BUFFER; + dcl.length = 4; + dcl.dcl_constant_buffer.dynamic = 0; + b->dcls.push_back (dcl.dword); + SM4TokOperand op; + op.dword = 0; + op.comps_enum = kSM4OperComp4; + op.file = kSM4File_CONSTANT_BUFFER; + op.num_indices = 2; + b->dcls.push_back (op.dword); + b->dcls.push_back (index); + b->dcls.push_back (size); +} + + +static void dxbc_update_insn_length (DXBCCodeBuilder* b, int len) +{ + DebugAssert (b->curInsnIndex >= 0 && b->curInsnIndex < b->insns.size()); + SM4TokInstruction* tok = (SM4TokInstruction*)&b->insns[b->curInsnIndex]; + tok->length += len; +} + +void dxb_op (DXBCCodeBuilder* b, SM4Opcode op, bool sat) +{ + b->opcode = op; + b->curInsnIndex = b->insns.size(); + SM4TokInstruction tok; + tok.dword = 0; + tok.opcode = op; + tok.insn.sat = sat ? 1 : 0; + tok.length = 1; + if (op == kSM4Op_DISCARD) // discard instructions emitted by HLSL have nz flag set + tok.insn.test_nz = 1; + b->insns.push_back (tok.dword); +} + +static inline SM4RegFile dxb_reg_type(char c) +{ + switch (c) + { + case 'r': return kSM4File_TEMP; + case 'v': return kSM4File_INPUT; + case 'o': return kSM4File_OUTPUT; + case 'c': return kSM4File_CONSTANT_BUFFER; + case 's': return kSM4File_SAMPLER; + case 't': return kSM4File_RESOURCE; + default: AssertString("unknown register type"); return kSM4File_TEMP; + } +} + + +void dxb_reg (DXBCCodeBuilder* b, char rchar, int reg, unsigned mask) +{ + b->dstRegMask = mask; + b->dstRegComps = BitsInMask(mask); + + SM4RegFile rtype = dxb_reg_type(rchar); + dxbc_update_insn_length (b, 2); + SM4TokOperand op; + op.dword = 0; + op.comps_enum = rtype==kSM4File_SAMPLER ? kSM4OperComp0 : kSM4OperComp4; + + // discard only has 1 parameter which is similar to a source register argument: + // if it's one channel only, then emit it as a "scalar channel index" + op.mode = (b->dstRegComps==1 && b->opcode==kSM4Op_DISCARD) ? SM4_OPERAND_MODE_SCALAR : SM4_OPERAND_MODE_MASK; + op.sel = (b->dstRegComps==1 && b->opcode==kSM4Op_DISCARD) ? HighestBit(mask) : mask; + if (rtype==kSM4File_SAMPLER) + op.sel = 0; + op.file = rtype; + op.num_indices = 1; + b->insns.push_back (op.dword); + b->insns.push_back (reg); + if (rtype == kSM4File_TEMP) + b->tempCount = std::max (b->tempCount, reg+1); +} + + +static unsigned adjust_swizzle (DXBCCodeBuilder* b, unsigned swizzle, bool sm2) +{ + // For DP3 with "no swizzle", SM2 expects to not have the swizzle, while SM4 expects xyzx + if (b->opcode == kSM4Op_DP3 && swizzle == kSM4SwzNone && !sm2) + swizzle = kSM4SwzXYZX; + + // arguments for single-channel destinations in SM4 should be emitted as "1 channel index" + // instead of "swizzle that replicates all channels" + if (!sm2 && b->dstRegComps==1) + { + if (swizzle == kSM4SwzRepX) + swizzle = 0; + else if (swizzle == kSM4SwzRepY) + swizzle = 1; + else if (swizzle == kSM4SwzRepZ) + swizzle = 2; + else if (swizzle == kSM4SwzRepW) + swizzle = 3; + } + return swizzle; +} + + +void dxb_swz (DXBCCodeBuilder* b, char rchar, int reg, unsigned swizzle, bool neg) +{ + swizzle = adjust_swizzle (b, swizzle, false); + + SM4RegFile rtype = dxb_reg_type(rchar); + int len = 2; + if (neg) ++len; + if (rtype==kSM4File_CONSTANT_BUFFER) ++len; + dxbc_update_insn_length (b, len); + SM4TokOperand op; + op.dword = 0; + op.comps_enum = rtype==kSM4File_SAMPLER ? kSM4OperComp0 : kSM4OperComp4; + op.mode = (b->dstRegComps==1 && swizzle<4) ? SM4_OPERAND_MODE_SCALAR : SM4_OPERAND_MODE_SWIZZLE; + op.sel = swizzle; + op.file = rtype; + op.num_indices = rtype==kSM4File_CONSTANT_BUFFER ? 2 : 1; + op.extended = neg ? 1 : 0; + b->insns.push_back (op.dword); + if (neg) + { + SM4TokOperandEx opex; + opex.dword = 0; + opex.type = 1; + opex.neg = 1; + b->insns.push_back (opex.dword); + } + if (rtype==kSM4File_CONSTANT_BUFFER) + { + b->insns.push_back (reg >> 16); + b->insns.push_back (reg & 0xFFFF); + } + else + { + b->insns.push_back (reg); + } + if (rtype == kSM4File_TEMP) + b->tempCount = std::max (b->tempCount, reg+1); +} + +void dxb_float1 (DXBCCodeBuilder* b, float v) +{ + dxbc_update_insn_length (b, 2); + SM4TokOperand op; + op.dword = 0; + op.comps_enum = kSM4OperComp1; + op.file = kSM4File_IMMEDIATE32; + b->insns.push_back (op.dword); + union { float f; UInt32 i; } f2i; + f2i.f = v; + b->insns.push_back (f2i.i); +} + +void dxb_int1 (DXBCCodeBuilder* b, int i) +{ + dxbc_update_insn_length (b, 2); + SM4TokOperand op; + op.dword = 0; + op.comps_enum = kSM4OperComp1; + op.file = kSM4File_IMMEDIATE32; + b->insns.push_back (op.dword); + b->insns.push_back (i); +} + + +void dxb_float4 (DXBCCodeBuilder* b, float v0, float v1, float v2, float v3) +{ + dxbc_update_insn_length (b, 5); + SM4TokOperand op; + op.dword = 0; + op.comps_enum = kSM4OperComp4; + op.file = kSM4File_IMMEDIATE32; + b->insns.push_back (op.dword); + union { float f; UInt32 i; } f2i; + f2i.f = v0; b->insns.push_back (f2i.i); + f2i.f = v1; b->insns.push_back (f2i.i); + f2i.f = v2; b->insns.push_back (f2i.i); + f2i.f = v3; b->insns.push_back (f2i.i); +} + + + +static void dxbc_builder_build_sig (DXBCBuilder* b, bool input) +{ + int chunkIdx = input ? kBuilderChunkInput : kBuilderChunkOutput; + const dynamic_array<SigElement>& sigs = input ? b->inputs : b->outputs; + const int nsigs = sigs.size(); + + // size = 8 (header) + 8 (sig chunk header) + count * DXBCSignatureElement + names + unsigned size = 16 + nsigs * sizeof(DXBCSignatureElement); + unsigned namesOffset = size; + for (int i = 0; i < nsigs; ++i) + size += strlen(sigs[i].name) + 1; + size = (size + 3) & ~3; // align to next dword + + UInt8* buf = (UInt8*)malloc(size); + DXBCChunkSig* chunk = (DXBCChunkSig*)buf; + memset (chunk, 0xAB, size); + + chunk->fourcc = input ? kFOURCC_ISGN : kFOURCC_OSGN; + chunk->size = size-8; + chunk->count = nsigs; + chunk->unk8 = 8; + for (int i = 0; i < nsigs; ++i) + { + DXBCSignatureElement* s = &chunk->elements[i]; + s->name_offset = namesOffset-8; + int len = strlen(sigs[i].name) + 1; + memcpy (buf + namesOffset, sigs[i].name, len); + namesOffset += len; + const bool outputPos = !strcmp(sigs[i].name,"SV_POSITION"); + unsigned mask = sigs[i].mask; + s->semantic_index = sigs[i].index; + s->system_value_type = outputPos ? 1 : 0; + s->component_type = 3; // float + s->register_num = sigs[i].reg; + s->mask = mask; // mask of channels used + if (input) + s->read_write_mask = mask; + else + s->read_write_mask = ~mask & 0xF; + s->stream = 0; + s->unused = 0; + + + SM4TokInstruction dcl; + dcl.dword = 0; + dcl.opcode = input ? + (b->version.type == kSM4Shader_Pixel ? kSM4Op_DCL_INPUT_PS : kSM4Op_DCL_INPUT) : + (outputPos ? kSM4Op_DCL_OUTPUT_SIV : kSM4Op_DCL_OUTPUT); + dcl.length = outputPos ? 4 : 3; + if (dcl.opcode == kSM4Op_DCL_INPUT_PS) + dcl.dcl_input_ps.interpolation = kSM4Interp_LINEAR; + b->dcls.push_back (dcl.dword); + SM4TokOperand op; + op.dword = 0; + op.comps_enum = kSM4OperComp4; + op.mode = SM4_OPERAND_MODE_MASK; + op.sel = mask; + op.file = input ? kSM4File_INPUT : kSM4File_OUTPUT; + op.num_indices = 1; + op.index0_repr = SM4_OPERAND_INDEX_REPR_IMM32; + b->dcls.push_back (op.dword); + b->dcls.push_back (sigs[i].reg); + if (outputPos) + b->dcls.push_back (s->system_value_type); + } + + b->chunks[chunkIdx] = chunk; +} + + +static void dxbc_builder_build_code (DXBCBuilder* b) +{ + const unsigned n = b->dcls.size() + b->insns.size(); + + // size = 8 (header) + 8 (code chunk header) + tokens + unsigned size = 16 + n*4; + + UInt8* buf = (UInt8*)malloc(size); + DXBCChunkCode* chunk = (DXBCChunkCode*)buf; + + chunk->fourcc = kFOURCC_SHDR; + chunk->size = size-8; + chunk->version = *(UInt32*)&b->version; + chunk->length = n+2; + + UInt8* codePtr = (UInt8*)(chunk+1); + if (!b->dcls.empty()) + { + size_t size = b->dcls.size()*sizeof(b->dcls[0]); + memcpy (codePtr, &b->dcls[0], size); + codePtr += size; + } + if (!b->insns.empty()) + { + size_t size = b->insns.size()*sizeof(b->insns[0]); + memcpy (codePtr, &b->insns[0], size); + codePtr += size; + } + DebugAssert (buf + size == codePtr); + + b->chunks[kBuilderChunkCode] = chunk; +} + +void dxbc_builder_build_code2 (DXBCBuilder* b); + +void* dxb_build (DXBCBuilder* b, size_t& outSize) +{ + dxbc_builder_build_sig (b, true); + dxbc_builder_build_sig (b, false); + if (b->codeBuilder.tempCount > 0) + { + SM4TokInstruction tok; + tok.dword = 0; + tok.opcode = kSM4Op_DCL_TEMPS; + tok.length = 2; + b->dcls.push_back (tok.dword); + b->dcls.push_back (b->codeBuilder.tempCount); + } + dxbc_builder_build_code (b); + dxbc_builder_build_code2(b); + + std::pair<void*,size_t> dxbc = dxbc_create (b->chunks, kBuilderChunkCount); + outSize = dxbc.second; + + return dxbc.first; +} + + + +//------------------------------------------------------------------------------------ +//SM 2.0 stuff + + +//table format was reversed and is still not 100% known +static dynamic_array<UInt32> dxbc_builder_build_mapping_table2 (DXBCBuilder* b) +{ + const unsigned shader_size = b->inputs2.size() + b->insns2.size() + b->defs2.size() + 1; + dynamic_array<UInt32> table; + + const unsigned rmap_offset = 0x24; + const unsigned cmap_offset = rmap_offset + b->numTextures2*4; + const unsigned imap_offset = cmap_offset + 3*4; + const unsigned shdr_offset = imap_offset + (b->version.type == kSM4Shader_Vertex ? 4 : 0); + + unsigned t = b->version.type == kSM4Shader_Pixel ? 4 : 0; + table.push_back(b->version.type == kSM4Shader_Pixel ? 0xffff0200 : 0xfffe0200); + table.push_back(shader_size*4); + table.push_back(shdr_offset); + table.push_back(1|(cmap_offset<<16)); + table.push_back(shdr_offset<<16); + table.push_back(shdr_offset<<16); + table.push_back(b->numTextures2|(rmap_offset<<16)); + table.push_back((b->version.type == kSM4Shader_Pixel ? 0 : 1)|(imap_offset<<16)); + + // Sampler mapping: 16-23 bits target sampler, 8-15 bits source sampler, 0-7 bits source resource + for (int n = 0;n < b->numTextures2;n++) + table.push_back(n|(n<<8)|(n<<16)); + + //constant to CB mapping + //CBn:CBoff; always zero + table.push_back(0); + //REGnum:REGn + table.push_back(b->version.type == kSM4Shader_Pixel ? 10 : 63); //k11VertexSize or k11PixelSize + //convert mode 8:8:8:8; always zero + table.push_back(0); + + //input mapping; always one constant for vertex shader with pixel offset: oPos.xy += offset.xy * oPos.w; + if (b->version.type == kSM4Shader_Vertex) + table.push_back(64<<16); //k11VertexPosOffset9x + + return table; +} + + +static unsigned swizzle_from_mask (unsigned mask) +{ + if (mask == 1) + return kSM4SwzRepX; + if (mask == 2) + return kSM4SwzRepY; + if (mask == 4) + return kSM4SwzRepZ; + if (mask == 8) + return kSM4SwzRepW; + //@TODO: more? + return kSM4SwzNone; +} + +static void dxb_handle_saturate2 (DXBCBuilder* b) +{ + if (!b->codeBuilder.saturate || b->version.type == kSM4Shader_Pixel) + return; + + // previous instruction had saturate on destination, so insert manual min/max instructions + const int tmpReg = b->codeBuilder.tmpSatRegIndex; + DebugAssert(tmpReg >= 0); + b->codeBuilder.saturate = 0; + + const int constReg = dxb_imm_f4 (b, 0, 1, 0, 0); + const unsigned mask = b->codeBuilder.dstRegMask; + const unsigned swz = swizzle_from_mask(mask); + + dxb_op2(b, kSM2Op_MAX, false); + dxb_reg2(b,'r',tmpReg,mask); + dxb_swz2(b,'r',tmpReg,swz); + dxb_swz2(b,'c',constReg,kSM4SwzRepX); + dxb_op2(b, kSM2Op_MIN, false); + dxb_reg2(b,b->codeBuilder.dstRegType,b->codeBuilder.dstRegIndex,mask); + dxb_swz2(b,'r',tmpReg,swz); + dxb_swz2(b,'c',constReg,kSM4SwzRepY); +} + +static void dxbc_builder_build_code2 (DXBCBuilder* b) +{ + dxb_handle_saturate2(b); // handle possible saturate on the last instruction + + dynamic_array<UInt32> table = dxbc_builder_build_mapping_table2(b); + + const unsigned shader_size = b->inputs2.size() + b->insns2.size() + b->defs2.size() + 1; + + // size = 8 (header) + 8 (code chunk header) + tokens + unsigned size = 12 + 4*table.size() + shader_size*4; + + UInt8* buf = (UInt8*)malloc(size); + DXBCChunkSM20* chunk = (DXBCChunkSM20*)buf; + + chunk->fourcc = kFOURCC_SM20; + chunk->size = size - 8; + chunk->length = chunk->size; + + UInt8* codePtr = (UInt8*)(chunk+1); + if (!table.empty()) + { + size_t size = table.size()*sizeof(table[0]); + memcpy (codePtr, &table[0], size); + codePtr += size; + } + + *(UInt32*)codePtr = b->version.type == kSM4Shader_Pixel ? 0xffff0201 : 0xfffe0201; + codePtr += 4; + + if (!b->defs2.empty()) + { + size_t size = b->defs2.size()*sizeof(b->defs2[0]); + memcpy (codePtr, &b->defs2[0], size); + codePtr += size; + } + if (!b->inputs2.empty()) + { + size_t size = b->inputs2.size()*sizeof(b->inputs2[0]); + memcpy (codePtr, &b->inputs2[0], size); + codePtr += size; + } + if (!b->insns2.empty()) + { + size_t size = b->insns2.size()*sizeof(b->insns2[0]); + memcpy (codePtr, &b->insns2[0], size); + codePtr += size; + } + + b->chunks[kBuilderChunkSM20] = chunk; +} + + +struct SM2TokSrc +{ + union { + UInt32 dword; + struct { + unsigned reg_num : 11; + unsigned reg_type34 : 2; + unsigned _res0 : 1; + unsigned _res1 : 2; + unsigned swizzle : 8; + unsigned src_mod : 4; + unsigned reg_type02 : 3; + unsigned _one : 1; + }; + }; +}; + +static inline UInt32 dxb_reg_split2(UInt32 n) +{ + return ((n<<D3DSP_REGTYPE_SHIFT)&D3DSP_REGTYPE_MASK)|((n<<(D3DSP_REGTYPE_SHIFT2))&D3DSP_REGTYPE_MASK2); +} + +static inline UInt32 dxb_reg_type2(char c) +{ + switch (c) + { + case 'r': return D3DSPR_TEMP; + case 'v': return D3DSPR_INPUT; + case 'c': return D3DSPR_CONST; + //should be D3DSPR_TEXTURE, however, I'm replacing + //t swizzle with sampler source and removing s source reg + //to convert sm40 sample to sm20 texld on-fly + case 't': return D3DSPR_SAMPLER; + // case 's': return D3DSPR_SAMPLER; + + case 'x': return D3DSPR_RASTOUT; + case 'y': return D3DSPR_TEXCRDOUT; + + case 'o': return D3DSPR_RASTOUT; + + default: AssertString("unknown register type"); return D3DSPR_TEMP; + } +} + +static void dxbc_update_insn_length2 (DXBCBuilder* b, int len) +{ + DebugAssert (b->curInsnIndex2 >= 0 && b->curInsnIndex2 < b->insns2.size()); + SM2TokInstruction* tok = (SM2TokInstruction*)&b->insns2[b->curInsnIndex2]; + tok->length += len; +} + +struct SNameToID +{ + const char* name; + UInt32 id; +}; + + +//SM4.0 semantic to SM2.0 VS usage mapping +static const SNameToID s_VSDeclNames[] = +{ + {"POSITION", D3DDECLUSAGE_POSITION}, + {"NORMAL", D3DDECLUSAGE_NORMAL}, + {"TEXCOORD", D3DDECLUSAGE_TEXCOORD}, + {"COLOR", D3DDECLUSAGE_COLOR}, + {"FOG", D3DDECLUSAGE_FOG}, + + {"SV_POSITION", 0}, + + {NULL, 0}, +}; + + +//SM4.0 semantic to SM2.0 PS register file mapping +static const SNameToID s_PSDeclNames[] = +{ + {"TEXCOORD", D3DSPR_TEXTURE}, + {"COLOR", D3DSPR_INPUT}, + + {"SV_Target", D3DSPR_COLOROUT}, + + {NULL, 0}, +}; + + +//SM4.0 semantic to SM2.0 register file mapping +static const SNameToID s_OutNames[] = +{ + {"POSITION", D3DSPR_RASTOUT}, + {"SV_POSITION", D3DSPR_RASTOUT}, + {"FOG", D3DSPR_RASTOUT}, + {"TEXCOORD", D3DSPR_TEXCRDOUT}, + {"COLOR", D3DSPR_ATTROUT}, + + {"SV_Target", D3DSPR_COLOROUT}, + + {NULL, 0}, +}; + + +static UInt32 find_dcl_by_name(const char* name,const SNameToID* p=s_VSDeclNames) +{ + while (p->name) + { + if (0 == strcmp(p->name,name)) + return p->id; + p++; + } + + Assert(0 || "DCL name not found!"); + + return -1; +} + +void dxb_dcl_tex2 (DXBCBuilder* b, int index, SM4Target dim) +{ + UInt32 tok2 = 0x80000000; + + switch (dim) + { + case kSM4Target_TEXTURE2D: + tok2 |= D3DSTT_2D; + break; + case kSM4Target_TEXTURE3D: + tok2 |= D3DSTT_VOLUME; + break; + case kSM4Target_TEXTURECUBE: + tok2 |= D3DSTT_CUBE; + break; + default: + Assert(0 || "Wrong texture type!"); + }; + + SM2TokInstruction tok; + tok.dword = 0; + tok.opcode = kSM2Op_DCL; + tok.length = 2; + + b->inputs2.push_back (tok.dword); + b->inputs2.push_back (tok2); + + SM2TokDst op; + op.dword = dxb_reg_split2(D3DSPR_SAMPLER); + op.reg_num = index; + op.write_mask = 0xf; + op._one = 1; + b->inputs2.push_back (op.dword); + + b->numTextures2++; +} + +//CAVEAT: DX11 feature level 9.x vertex shaders use texcoord semantics for _all_ attributes +int dxb_find_input_by_name2(DXBCBuilder* b,const char* name, int index) +{ + int index2 = 0; + while (0 != strcmp(b->inputs[index2].name,name) || b->inputs[index2].index != index) + index2++; + + return index2; +} + +int dxb_find_output_by_name2(DXBCBuilder* b,const char* name, int index) +{ + int index2 = 0; + while (0 != strcmp(b->outputs[index2].name,name) || b->outputs[index2].index != index) + index2++; + + return index2; +} + + +//CAVEAT1: DX11 feature level 9.x vertex shaders use texcoord semantics for _all_ attributes +//CAVEAT2: [Qualcomm] DX11 feature level 9.x uses texcoord interpolators for _all_ varyings +void dxb_dcl_input2 (DXBCBuilder* b, const char* name, int index, int reg, int mask) +{ + //TODO: this is not needed anymore. + UInt32 decl = find_dcl_by_name(name,b->version.type == kSM4Shader_Vertex ? s_VSDeclNames : s_PSDeclNames); + UInt32 reg_type = b->version.type == kSM4Shader_Vertex ? dxb_reg_type2('v') : (decl); + + SM2TokInstruction tok; + tok.dword = 0; + tok.opcode = kSM2Op_DCL; + tok.length = 2; + + b->inputs2.push_back (tok.dword); + + UInt32 tok2 = 0x80000000; + //CAVEAT1 + if (b->version.type == kSM4Shader_Vertex) + tok2 |= D3DDECLUSAGE_TEXCOORD|(dxb_find_input_by_name2(b,name,index)<<16); + b->inputs2.push_back (tok2); + +#if 1 + //CAVEAT2 + if (b->version.type == kSM4Shader_Pixel) + { + index = dxb_find_input_by_name2(b,name,index); + reg_type = D3DSPR_TEXTURE; + } +#endif + + SM2TokDst op; + op.dword = dxb_reg_split2(reg_type); + op.reg_num = b->version.type == kSM4Shader_Vertex ? reg : index; + op.write_mask = mask; + op._one = 1; + op._res0 = 0; + op._res1 = 0; + b->inputs2.push_back (op.dword); + + if (b->version.type == kSM4Shader_Pixel) + { + op.write_mask = 0; + b->inputMap[reg] = op.dword; + } +} + +void dxb_dcl_output2 (DXBCBuilder* b, const char* name, int index, int reg, int mask) +{ + UInt32 reg_type = find_dcl_by_name(name,s_OutNames); +#if 1 + //CAVEAT2. Excluding POSITION + if (b->version.type == kSM4Shader_Vertex && NULL == strstr(name,"POSITION")) + { + index = dxb_find_output_by_name2(b,name,index); + reg_type = D3DSPR_TEXCRDOUT; + } +#else + //special case in raster reg. file + if (0 == strcmp(name,"FOG")) + index = 2; +#endif + + SM2TokDst op; + op.dword = dxb_reg_split2(reg_type); + op.reg_num = index; + + b->outputMap[reg] = op.dword; +} + +static UInt32 dxb_find_output2 (DXBCBuilder* b, int reg) +{ + Assert (b->outputMap.find(reg) != b->outputMap.end()); + return b->outputMap[reg]; +} + +static UInt32 dxb_find_input2 (DXBCBuilder* b, int reg) +{ + Assert (b->inputMap.find(reg) != b->inputMap.end()); + return b->inputMap[reg]; +} + + +void dxb_op2 (DXBCBuilder* b, SM2Opcode op, bool sat, int scratchTmpRegForSat) +{ + dxb_handle_saturate2 (b); + + b->codeBuilder.opcode2 = op; + b->curInsnIndex2 = b->insns2.size(); + + SM2TokInstruction tok; + tok.dword = 0; + tok.opcode = op; + tok.specific = op>>16; + tok.length = 0; + + b->insns2.push_back (tok.dword); + b->codeBuilder.saturate = sat; + b->codeBuilder.tmpSatRegIndex = scratchTmpRegForSat; +} + +void dxb_reg2 (DXBCBuilder* b, char rchar, int reg,unsigned mask) +{ + b->codeBuilder.dstRegMask = mask; + b->codeBuilder.dstRegComps = BitsInMask(mask); + if (b->codeBuilder.saturate) + { + b->codeBuilder.dstRegType = rchar; + b->codeBuilder.dstRegIndex = reg; + if (b->version.type != kSM4Shader_Pixel) + { + rchar = 'r'; + reg = b->codeBuilder.tmpSatRegIndex; + } + } + + //for sm20 sampler will be emitted by texture coords swizzle source op + if ('s' == rchar && b->version.type == kSM4Shader_Pixel) + return; + + dxbc_update_insn_length2 (b, 1); + SM2TokDst op; + + if ('o' == rchar) + op.dword = dxb_find_output2(b,reg); + else if ('v' == rchar && b->version.type == kSM4Shader_Pixel) + op.dword = dxb_find_input2(b,reg); + else + { + op.dword = dxb_reg_split2(dxb_reg_type2(rchar)); + op.reg_num = reg; + } + + op.res_mod = 0; + if (b->codeBuilder.saturate && b->version.type == kSM4Shader_Pixel) + { + op.res_mod = D3DSPDM_SATURATE>>D3DSP_DSTMOD_SHIFT; + b->codeBuilder.saturate = 0; + } + + op.write_mask = mask; + op._one = 1; + op._res0 = 0; + op._res1 = 0; + + b->insns2.push_back (op.dword); +} + +void dxb_swz2 (DXBCBuilder* b, char rchar, int reg, unsigned swizzle, bool neg) +{ + swizzle = adjust_swizzle (&b->codeBuilder, swizzle, true); + + UInt32 rtype = dxb_reg_type2(rchar); + dxbc_update_insn_length2 (b, 1); + + SM2TokSrc op; + if ('o' == rchar) + op.dword = dxb_find_output2(b,reg); + else if ('v' == rchar && b->version.type == kSM4Shader_Pixel) + op.dword = dxb_find_input2(b,reg); + else + { + op.dword = dxb_reg_split2(dxb_reg_type2(rchar)); + op.reg_num = reg; + } + + //texld must not swizzle + if ('s' != rchar && 't' != rchar)// && op.reg_type02 != D3DSPR_TEXTURE) + { + op.swizzle = swizzle; + op.src_mod = neg ? 1 : 0; + } + else + op.swizzle = kSM4SwzNone; + + op._one = 1; + op._res0 = 0; + op._res1 = 0; + + b->insns2.push_back (op.dword); +} + +//find a constant, define a constant if not found +int dxb_imm_f4 (DXBCBuilder* b, float v0, float v1, float v2, float v3) +{ + union { float f; UInt32 i; } f2i; + //TODO: do not hardcode! + int reg = b->version.type == kSM4Shader_Pixel ? 10 : 63 + 2; + dynamic_array<UInt32>::const_iterator it = b->defs2.begin(); + for (;it != b->defs2.end();it += 6, reg++) + { + f2i.f = v0; + if (f2i.i != *(it + 2)) + continue; + f2i.f = v1; + if (f2i.i != *(it + 3)) + continue; + f2i.f = v2; + if (f2i.i != *(it + 4)) + continue; + f2i.f = v3; + if (f2i.i != *(it + 5)) + continue; + + break; + } + + if (it == b->defs2.end()) + { + SM2TokInstruction tok; + tok.dword = 0; + tok.opcode = kSM2Op_DEF; + tok.specific = 0; + tok.length = 5; + b->defs2.push_back (tok.dword); + + SM2TokDst op; + op.dword = dxb_reg_split2(dxb_reg_type2('c')); + op.reg_num = reg; + op.write_mask = 0xF; + op._one = 1; + b->defs2.push_back (op.dword); + + f2i.f = v0; b->defs2.push_back (f2i.i); + f2i.f = v1; b->defs2.push_back (f2i.i); + f2i.f = v2; b->defs2.push_back (f2i.i); + f2i.f = v3; b->defs2.push_back (f2i.i); + } + + return reg; +} + +SM2Opcode dxb_to_sm2 (SM4Opcode op) +{ + switch (op) + { + case kSM4Op_SQRT: + break; + case kSM4Op_DIV: + break; + case kSM4Op_RSQ: + return kSM2Op_RSQ; + case kSM4Op_LOG: + return kSM2Op_LOG; + case kSM4Op_EXP: + return kSM2Op_EXP; + case kSM4Op_RCP: + return kSM2Op_RCP; + + case kSM4Op_MOV: + return kSM2Op_MOV; + case kSM4Op_MOVC: + break; + + case kSM4Op_MAD: + return kSM2Op_MAD; + case kSM4Op_DP2: + break; + case kSM4Op_DP3: + return kSM2Op_DP3; + case kSM4Op_DP4: + return kSM2Op_DP4; + case kSM4Op_MUL: + return kSM2Op_MUL; + case kSM4Op_ADD: + return kSM2Op_ADD; + case kSM4Op_AND: + break; + case kSM4Op_MIN: + return kSM2Op_MIN; + case kSM4Op_MAX: + return kSM2Op_MAX; + + case kSM4Op_SAMPLE: + return kSM2Op_TEX; + case kSM4Op_DISCARD: + return kSM2Op_TEXKILL; + + case kSM4Op_LT: + return kSM2Op_SLT; + case kSM4Op_GE: + return kSM2Op_SGE; + case kSM4Op_NE: + break; + case kSM4Op_EQ: + break; + + case kSM4Op_RET: + return kSM2Op_END; + } + + AssertString("unknown SM4 opcode"); + __debugbreak(); + + return kSM2Op_NOP; +} + + diff --git a/Runtime/GfxDevice/d3d11/D3D11ByteCode.h b/Runtime/GfxDevice/d3d11/D3D11ByteCode.h new file mode 100644 index 0000000..020a8c1 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11ByteCode.h @@ -0,0 +1,856 @@ +#pragma once + +#include "Runtime/Utilities/dynamic_array.h" + +struct _D3D11_SIGNATURE_PARAMETER_DESC; +typedef struct _D3D11_SIGNATURE_PARAMETER_DESC D3D11_SIGNATURE_PARAMETER_DESC; + + + +#define MAKE_FOURCC(a, b, c, d) ((UInt32)(UInt8)(a) | ((UInt32)(UInt8)(b) << 8) | ((UInt32)(UInt8)(c) << 16) | ((UInt32)(UInt8)(d) << 24 )) +#define kFOURCC_DXBC MAKE_FOURCC('D', 'X', 'B', 'C') + +// Reflection or debug information? stripped shaders don't have this chunk +#define kFOURCC_RDEF MAKE_FOURCC('R', 'D', 'E', 'F') +// Shader input signature +#define kFOURCC_ISGN MAKE_FOURCC('I', 'S', 'G', 'N') +// Shader output signature +#define kFOURCC_OSGN MAKE_FOURCC('O', 'S', 'G', 'N') +// Shader code +#define kFOURCC_SHDR MAKE_FOURCC('S', 'H', 'D', 'R') +#define kFOURCC_SHEX MAKE_FOURCC('S', 'H', 'E', 'X') +// Statistics? stripped shaders don't have this chunk +#define kFOURCC_STAT MAKE_FOURCC('S', 'T', 'A', 'T') +// Patch information? +#define kFOURCC_PCSG MAKE_FOURCC('P', 'C', 'S', 'G') +//FL 9.x SM 2.0 shader magic signature +#define kFOURCC_SM20 MAKE_FOURCC('A', 'o', 'n', '9') + + +struct DXBCChunkHeader +{ + unsigned fourcc; + unsigned size; +}; + + +struct DXBCContainer +{ + const void* data; + dynamic_array<DXBCChunkHeader*> chunks; +}; + +struct DXBCSignatureElement +{ + UInt32 name_offset; + UInt32 semantic_index; + UInt32 system_value_type; + UInt32 component_type; + UInt32 register_num; + UInt8 mask; + UInt8 read_write_mask; + UInt8 stream; + UInt8 unused; +}; + +struct DXBCChunkSig : public DXBCChunkHeader +{ + UInt32 count; + UInt32 unk8; // always has 8? + DXBCSignatureElement elements[1]; +}; + +struct DXBCChunkCode : public DXBCChunkHeader +{ + UInt32 version; + UInt32 length; // length in dword tokens +}; + +struct DXBCChunkSM20 : public DXBCChunkHeader +{ + UInt32 length; // length in bytes +}; + + +struct SM4TokInstruction +{ + // not an union directly because unions can't be inherited from + union + { + UInt32 dword; + // length and extended are always present, but they are only here to reduce duplication + struct + { + unsigned opcode : 11; + unsigned _11_23 : 13; + unsigned length : 7; + unsigned extended : 1; + }; + struct + { + unsigned opcode : 11; + unsigned resinfo_return_type : 2; + unsigned sat : 1; + unsigned _14_17 : 4; + unsigned test_nz : 1; // bit 18 + unsigned precise_mask : 4; + unsigned _23 : 1; + unsigned length : 7; + unsigned extended : 1; + } insn; + struct + { + unsigned opcode : 11; + unsigned threads_in_group : 1; + unsigned shared_memory : 1; + unsigned uav_group : 1; + unsigned uav_global : 1; + unsigned _15_17 : 3; + } sync; + struct + { + unsigned opcode : 11; + unsigned allow_refactoring : 1; + unsigned fp64 : 1; + unsigned early_depth_stencil : 1; + unsigned enable_raw_and_structured_in_non_cs : 1; + } dcl_global_flags; + struct + { + unsigned opcode : 11; + unsigned target : 5; + unsigned nr_samples : 7; + } dcl_resource; + struct + { + unsigned opcode : 11; + unsigned shadow : 1; + unsigned mono : 1; + } dcl_sampler; + struct + { + unsigned opcode : 11; + unsigned interpolation : 5; + } dcl_input_ps; + struct + { + unsigned opcode : 11; + unsigned dynamic : 1; + } dcl_constant_buffer; + struct + { + unsigned opcode : 11; + unsigned primitive : 6; + } dcl_gs_input_primitive; + struct + { + unsigned opcode : 11; + unsigned primitive_topology : 7; + } dcl_gs_output_primitive_topology; + struct + { + unsigned opcode : 11; + unsigned control_points : 6; + } dcl_input_control_point_count; + struct + { + unsigned opcode : 11; + unsigned control_points : 6; + } dcl_output_control_point_count; + struct + { + unsigned opcode : 11; + unsigned domain : 3; /* D3D_TESSELLATOR_DOMAIN */ + } dcl_tess_domain; + struct + { + unsigned opcode : 11; + unsigned partitioning : 3; /* D3D_TESSELLATOR_PARTITIONING */ + } dcl_tess_partitioning; + struct + { + unsigned opcode : 11; + unsigned primitive : 3; /* D3D_TESSELLATOR_OUTPUT_PRIMITIVE */ + } dcl_tess_output_primitive; + }; +}; + +union SM4TokInstructionEx +{ + UInt32 dword; + struct + { + unsigned type : 6; + unsigned _6_30 : 25; + unsigned extended :1; + }; + struct + { + unsigned type : 6; + unsigned _6_8 : 3; + int offset_u : 4; + int offset_v : 4; + int offset_w : 4; + } sample_controls; + struct + { + unsigned type : 6; + unsigned target : 5; + } resource_target; + struct + { + unsigned type : 6; + unsigned x : 4; + unsigned y : 4; + unsigned z : 4; + unsigned w : 4; + } resource_return_type; +}; + +struct SM4TokOperand +{ + union { + UInt32 dword; + struct { + unsigned comps_enum : 2; /* sm4_operands_comps */ + unsigned mode : 2; /* SM4OperMode */ + unsigned sel : 8; + unsigned file : 8; /* SM4RegFile */ + unsigned num_indices : 2; + unsigned index0_repr : 3; /* SM4OperIndexRepr */ + unsigned index1_repr : 3; /* SM4OperIndexRepr */ + unsigned index2_repr : 3; /* SM4OperIndexRepr */ + unsigned extended : 1; + }; + }; +}; + +struct SM2TokInstruction +{ + union + { + UInt32 dword; + struct + { + unsigned opcode : 16; + unsigned specific : 8; + unsigned length : 4; + unsigned predicated : 1; + unsigned _res0 : 1; + unsigned _res1 : 1; + unsigned _res2 : 1; + }; + struct + { + unsigned minor : 8; + unsigned major : 8; + unsigned _magic : 16; + } version; + }; +}; + +struct SM2TokDst +{ + union { + UInt32 dword; + struct { + unsigned reg_num : 11; + unsigned reg_type34 : 2; + unsigned _res0 : 1; + unsigned _res1 : 2; + unsigned write_mask : 4; + unsigned res_mod : 4; + unsigned shift_scl : 4; + unsigned reg_type02 : 3; + unsigned _one : 1; + }; + }; +}; + +void dxbc_create(struct DXBCChunkHeader** chunks, unsigned num_chunks, dynamic_array<UInt8>& out); + + +DXBCContainer* dxbc_parse(const void* data, int size); +DXBCChunkHeader* dxbc_find_chunk(const void* data, int size, unsigned fourcc); +void dxbc_print(const DXBCContainer* dxbc); +int dxbc_parse_signature(const DXBCChunkSig* sig, D3D11_SIGNATURE_PARAMETER_DESC** params); + + +enum SM2Opcode +{ + kSM2Op_NOP = 0, + kSM2Op_MOV , + kSM2Op_ADD , + kSM2Op_SUB , + kSM2Op_MAD , + kSM2Op_MUL , + kSM2Op_RCP , + kSM2Op_RSQ , + kSM2Op_DP3 , + kSM2Op_DP4 , + kSM2Op_MIN , + kSM2Op_MAX , + kSM2Op_SLT , + kSM2Op_SGE , + kSM2Op_EXP , + kSM2Op_LOG , + kSM2Op_LIT , + kSM2Op_DST , + kSM2Op_LRP , + kSM2Op_FRC , + kSM2Op_M4x4 , + kSM2Op_M4x3 , + kSM2Op_M3x4 , + kSM2Op_M3x3 , + kSM2Op_M3x2 , + kSM2Op_CALL , + kSM2Op_CALLNZ , + kSM2Op_LOOP , + kSM2Op_RET , + kSM2Op_ENDLOOP , + kSM2Op_LABEL , + kSM2Op_DCL , + kSM2Op_POW , + kSM2Op_CRS , + kSM2Op_SGN , + kSM2Op_ABS , + kSM2Op_NRM , + kSM2Op_SINCOS , + kSM2Op_REP , + kSM2Op_ENDREP , + kSM2Op_IF , + kSM2Op_IFC , + kSM2Op_ELSE , + kSM2Op_ENDIF , + kSM2Op_BREAK , + kSM2Op_BREAKC , + kSM2Op_MOVA , + kSM2Op_DEFB , + kSM2Op_DEFI , + + kSM2Op_TEXCOORD = 64, + kSM2Op_TEXKILL , + kSM2Op_TEX , + kSM2Op_TEXBEM , + kSM2Op_TEXBEML , + kSM2Op_TEXREG2AR , + kSM2Op_TEXREG2GB , + kSM2Op_TEXM3x2PAD , + kSM2Op_TEXM3x2TEX , + kSM2Op_TEXM3x3PAD , + kSM2Op_TEXM3x3TEX , + kSM2Op_RESERVED0 , + kSM2Op_TEXM3x3SPEC , + kSM2Op_TEXM3x3VSPEC , + kSM2Op_EXPP , + kSM2Op_LOGP , + kSM2Op_CND , + kSM2Op_DEF , + kSM2Op_TEXREG2RGB , + kSM2Op_TEXDP3TEX , + kSM2Op_TEXM3x2DEPTH , + kSM2Op_TEXDP3 , + kSM2Op_TEXM3x3 , + kSM2Op_TEXDEPTH , + kSM2Op_CMP , + kSM2Op_BEM , + kSM2Op_DP2ADD , + kSM2Op_DSX , + kSM2Op_DSY , + kSM2Op_TEXLDD , + kSM2Op_SETP , + kSM2Op_TEXLDL , + kSM2Op_BREAKP , + + kSM2Op_PHASE = 0xFFFD, + kSM2Op_COMMENT = 0xFFFE, + kSM2Op_END = 0xFFFF, +}; + +enum SM4ShaderType +{ + kSM4Shader_Pixel, + kSM4Shader_Vertex, +}; + +enum SM4Opcode +{ + kSM4Op_ADD, + kSM4Op_AND, + kSM4Op_BREAK, + kSM4Op_BREAKC, + kSM4Op_CALL, + kSM4Op_CALLC, + kSM4Op_CASE, + kSM4Op_CONTINUE, + kSM4Op_CONTINUEC, + kSM4Op_CUT, + kSM4Op_DEFAULT, + kSM4Op_DERIV_RTX, + kSM4Op_DERIV_RTY, + kSM4Op_DISCARD, + kSM4Op_DIV, + kSM4Op_DP2, + kSM4Op_DP3, + kSM4Op_DP4, + kSM4Op_ELSE, + kSM4Op_EMIT, + kSM4Op_EMITTHENCUT, + kSM4Op_ENDIF, + kSM4Op_ENDLOOP, + kSM4Op_ENDSWITCH, + kSM4Op_EQ, + kSM4Op_EXP, + kSM4Op_FRC, + kSM4Op_FTOI, + kSM4Op_FTOU, + kSM4Op_GE, + kSM4Op_IADD, + kSM4Op_IF, + kSM4Op_IEQ, + kSM4Op_IGE, + kSM4Op_ILT, + kSM4Op_IMAD, + kSM4Op_IMAX, + kSM4Op_IMIN, + kSM4Op_IMUL, + kSM4Op_INE, + kSM4Op_INEG, + kSM4Op_ISHL, + kSM4Op_ISHR, + kSM4Op_ITOF, + kSM4Op_LABEL, + kSM4Op_LD, + kSM4Op_LD_MS, + kSM4Op_LOG, + kSM4Op_LOOP, + kSM4Op_LT, + kSM4Op_MAD, + kSM4Op_MIN, + kSM4Op_MAX, + kSM4Op_CUSTOMDATA, + kSM4Op_MOV, + kSM4Op_MOVC, + kSM4Op_MUL, + kSM4Op_NE, + kSM4Op_NOP, + kSM4Op_NOT, + kSM4Op_OR, + kSM4Op_RESINFO, + kSM4Op_RET, + kSM4Op_RETC, + kSM4Op_ROUND_NE, + kSM4Op_ROUND_NI, + kSM4Op_ROUND_PI, + kSM4Op_ROUND_Z, + kSM4Op_RSQ, + kSM4Op_SAMPLE, + kSM4Op_SAMPLE_C, + kSM4Op_SAMPLE_C_LZ, + kSM4Op_SAMPLE_L, + kSM4Op_SAMPLE_D, + kSM4Op_SAMPLE_B, + kSM4Op_SQRT, + kSM4Op_SWITCH, + kSM4Op_SINCOS, + kSM4Op_UDIV, + kSM4Op_ULT, + kSM4Op_UGE, + kSM4Op_UMUL, + kSM4Op_UMAD, + kSM4Op_UMAX, + kSM4Op_UMIN, + kSM4Op_USHR, + kSM4Op_UTOF, + kSM4Op_XOR, + kSM4Op_DCL_RESOURCE, + kSM4Op_DCL_CONSTANT_BUFFER, + kSM4Op_DCL_SAMPLER, + kSM4Op_DCL_INDEX_RANGE, + kSM4Op_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY, + kSM4Op_DCL_GS_INPUT_PRIMITIVE, + kSM4Op_DCL_MAX_OUTPUT_VERTEX_COUNT, + kSM4Op_DCL_INPUT, + kSM4Op_DCL_INPUT_SGV, + kSM4Op_DCL_INPUT_SIV, + kSM4Op_DCL_INPUT_PS, + kSM4Op_DCL_INPUT_PS_SGV, + kSM4Op_DCL_INPUT_PS_SIV, + kSM4Op_DCL_OUTPUT, + kSM4Op_DCL_OUTPUT_SGV, + kSM4Op_DCL_OUTPUT_SIV, + kSM4Op_DCL_TEMPS, + kSM4Op_DCL_INDEXABLE_TEMP, + kSM4Op_DCL_GLOBAL_FLAGS, + kSM4Op_D3D10_COUNT, + kSM4Op_LOD, + kSM4Op_GATHER4, + kSM4Op_SAMPLE_POS, + kSM4Op_SAMPLE_INFO, + kSM4Op_D3D10_1_COUNT, + kSM4Op_HS_DECLS, + kSM4Op_HS_CONTROL_POINT_PHASE, + kSM4Op_HS_FORK_PHASE, + kSM4Op_HS_JOIN_PHASE, + kSM4Op_EMIT_STREAM, + kSM4Op_CUT_STREAM, + kSM4Op_EMITTHENCUT_STREAM, + kSM4Op_INTERFACE_CALL, + kSM4Op_BUFINFO, + kSM4Op_DERIV_RTX_COARSE, + kSM4Op_DERIV_RTX_FINE, + kSM4Op_DERIV_RTY_COARSE, + kSM4Op_DERIV_RTY_FINE, + kSM4Op_GATHER4_C, + kSM4Op_GATHER4_PO, + kSM4Op_GATHER4_PO_C, + kSM4Op_RCP, + kSM4Op_F32TOF16, + kSM4Op_F16TOF32, + kSM4Op_UADDC, + kSM4Op_USUBB, + kSM4Op_COUNTBITS, + kSM4Op_FIRSTBIT_HI, + kSM4Op_FIRSTBIT_LO, + kSM4Op_FIRSTBIT_SHI, + kSM4Op_UBFE, + kSM4Op_IBFE, + kSM4Op_BFI, + kSM4Op_BFREV, + kSM4Op_SWAPC, + kSM4Op_DCL_STREAM, + kSM4Op_DCL_FUNCTION_BODY, + kSM4Op_DCL_FUNCTION_TABLE, + kSM4Op_DCL_INTERFACE, + kSM4Op_DCL_INPUT_CONTROL_POINT_COUNT, + kSM4Op_DCL_OUTPUT_CONTROL_POINT_COUNT, + kSM4Op_DCL_TESS_DOMAIN, + kSM4Op_DCL_TESS_PARTITIONING, + kSM4Op_DCL_TESS_OUTPUT_PRIMITIVE, + kSM4Op_DCL_HS_MAX_TESSFACTOR, + kSM4Op_DCL_HS_FORK_PHASE_INSTANCE_COUNT, + kSM4Op_DCL_HS_JOIN_PHASE_INSTANCE_COUNT, + kSM4Op_DCL_THREAD_GROUP, + kSM4Op_DCL_UNORDERED_ACCESS_VIEW_TYPED, + kSM4Op_DCL_UNORDERED_ACCESS_VIEW_RAW, + kSM4Op_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED, + kSM4Op_DCL_THREAD_GROUP_SHARED_MEMORY_RAW, + kSM4Op_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED, + kSM4Op_DCL_RESOURCE_RAW, + kSM4Op_DCL_RESOURCE_STRUCTURED, + kSM4Op_LD_UAV_TYPED, + kSM4Op_STORE_UAV_TYPED, + kSM4Op_LD_RAW, + kSM4Op_STORE_RAW, + kSM4Op_LD_STRUCTURED, + kSM4Op_STORE_STRUCTURED, + kSM4Op_ATOMIC_AND, + kSM4Op_ATOMIC_OR, + kSM4Op_ATOMIC_XOR, + kSM4Op_ATOMIC_CMP_STORE, + kSM4Op_ATOMIC_IADD, + kSM4Op_ATOMIC_IMAX, + kSM4Op_ATOMIC_IMIN, + kSM4Op_ATOMIC_UMAX, + kSM4Op_ATOMIC_UMIN, + kSM4Op_IMM_ATOMIC_ALLOC, + kSM4Op_IMM_ATOMIC_CONSUME, + kSM4Op_IMM_ATOMIC_IADD, + kSM4Op_IMM_ATOMIC_AND, + kSM4Op_IMM_ATOMIC_OR, + kSM4Op_IMM_ATOMIC_XOR, + kSM4Op_IMM_ATOMIC_EXCH, + kSM4Op_IMM_ATOMIC_CMP_EXCH, + kSM4Op_IMM_ATOMIC_IMAX, + kSM4Op_IMM_ATOMIC_IMIN, + kSM4Op_IMM_ATOMIC_UMAX, + kSM4Op_IMM_ATOMIC_UMIN, + kSM4Op_SYNC, + kSM4Op_DADD, + kSM4Op_DMAX, + kSM4Op_DMIN, + kSM4Op_DMUL, + kSM4Op_DEQ, + kSM4Op_DGE, + kSM4Op_DLT, + kSM4Op_DNE, + kSM4Op_DMOV, + kSM4Op_DMOVC, + kSM4Op_DTOF, + kSM4Op_FTOD, + kSM4Op_EVAL_SNAPPED, + kSM4Op_EVAL_SAMPLE_INDEX, + kSM4Op_EVAL_CENTROID, + kSM4Op_DCL_GS_INSTANCE_COUNT, + kSM4Op_COUNT +}; + + +enum SM4Interpolation +{ + kSM4Interp_UNDEFINED, + kSM4Interp_CONSTANT, + kSM4Interp_LINEAR, + kSM4Interp_LINEAR_CENTROID, + kSM4Interp_LINEAR_NOPERSPECTIVE, + kSM4Interp_LINEAR_NOPERSPECTIVE_CENTROID, + kSM4Interp_LINEAR_SAMPLE, + kSM4Interp_LINEAR_NOPERSPECTIVE_SAMPLE, + kSM4Interp_COUNT +}; + + +enum SM4OperCompnum +{ + kSM4OperComp0, + kSM4OperComp1, + kSM4OperComp4, + kSM4OperCompN, + kSM4OperComp, + kSM4OperCompCOUNT +}; + +enum SM4OperMode +{ + SM4_OPERAND_MODE_MASK, + SM4_OPERAND_MODE_SWIZZLE, + SM4_OPERAND_MODE_SCALAR, + SM4_OPERAND_MODE_, + SM4_OPERAND_MODE_COUNT +}; + +enum SM4OperIndexRepr +{ + SM4_OPERAND_INDEX_REPR_IMM32, + SM4_OPERAND_INDEX_REPR_IMM64, + SM4_OPERAND_INDEX_REPR_REG, + SM4_OPERAND_INDEX_REPR_REG_IMM32, + SM4_OPERAND_INDEX_REPR_REG_IMM64, + SM4_OPERAND_INDEX_REPR_COUNT +}; + + +enum SM4RegFile +{ + kSM4File_TEMP, + kSM4File_INPUT, + kSM4File_OUTPUT, + kSM4File_INDEXABLE_TEMP, + kSM4File_IMMEDIATE32, + kSM4File_IMMEDIATE64, + kSM4File_SAMPLER, + kSM4File_RESOURCE, + kSM4File_CONSTANT_BUFFER, + kSM4File_IMMEDIATE_CONSTANT_BUFFER, + kSM4File_LABEL, + kSM4File_INPUT_PRIMITIVEID, + kSM4File_OUTPUT_DEPTH, + kSM4File_NULL, + kSM4File_RASTERIZER, + kSM4File_OUTPUT_COVERAGE_MASK, + kSM4File_STREAM, + kSM4File_FUNCTION_BODY, + kSM4File_FUNCTION_TABLE, + kSM4File_INTERFACE, + kSM4File_FUNCTION_INPUT, + kSM4File_FUNCTION_OUTPUT, + kSM4File_OUTPUT_CONTROL_POINT_ID, + kSM4File_INPUT_FORK_INSTANCE_ID, + kSM4File_INPUT_JOIN_INSTANCE_ID, + kSM4File_INPUT_CONTROL_POINT, + kSM4File_OUTPUT_CONTROL_POINT, + kSM4File_INPUT_PATCH_CONSTANT, + kSM4File_INPUT_DOMAIN_POINT, + kSM4File_THIS_POINTER, + kSM4File_UNORDERED_ACCESS_VIEW, + kSM4File_THREAD_GROUP_SHARED_MEMORY, + kSM4File_INPUT_THREAD_ID, + kSM4File_INPUT_THREAD_GROUP_ID, + kSM4File_INPUT_THREAD_ID_IN_GROUP, + kSM4File_INPUT_COVERAGE_MASK, + kSM4File_INPUT_THREAD_ID_IN_GROUP_FLATTENED, + kSM4File_INPUT_GS_INSTANCE_ID, + kSM4File_OUTPUT_DEPTH_GREATER_EQUAL, + kSM4File_OUTPUT_DEPTH_LESS_EQUAL, + kSM4File_CYCLE_COUNTER, + kSM4File_COUNT +}; + + +extern const char* kSM4OpcodeNames[kSM4Op_COUNT]; + + +enum SM4Swizzle { + kSM4SwzNone = 0xE4, // 11.10.01.00 + kSM4SwzRepX = 0x00, // 00.00.00.00 + kSM4SwzRepY = 0x55, // 01.01.01.01 + kSM4SwzRepZ = 0xAA, // 10.10.10.10 + kSM4SwzRepW = 0xFF, // 11.11.11.11 + kSM4SwzXYZZ = 0xA4, // 10.10.01.00 + kSM4SwzXYYY = 0x54, // 01.01.01.00 + kSM4SwzXYXX = 0x04, // 00.00.01.00 + kSM4SwzXYXY = 0x44, // 01.00.01.00 + kSM4SwzZWZW = 0xEE, // 11.10.11.10 + kSM4SwzZWWW = 0xFE, // 11.11.11.10 + kSM4SwzYYYZ = 0x95, // 10.01.01.01 + kSM4SwzXYZX = 0x24, // 00.10.01.00 + kSM4SwzXYZY = 0x64, // 01.10.01.00 + kSM4SwzYZWY = 0x79, // 01.11.10.01 +}; + +enum SM4Target +{ + kSM4Target_UNKNOWN, + kSM4Target_BUFFER, + kSM4Target_TEXTURE1D, + kSM4Target_TEXTURE2D, + kSM4Target_TEXTURE2DMS, + kSM4Target_TEXTURE3D, + kSM4Target_TEXTURECUBE, + kSM4Target_TEXTURE1DARRAY, + kSM4Target_TEXTURE2DARRAY, + kSM4Target_TEXTURE2DMSARRAY, + kSM4Target_TEXTURECUBEARRAY, + kSM4Target_RAW_BUFFER, + kSM4Target_STRUCTURED_BUFFER, + kSM4Target_COUNT +}; + + +struct DXBCBuilder; +DXBCBuilder* dxb_create(int major, int minor, SM4ShaderType type); +void dxb_destroy(DXBCBuilder* b); + + +struct DXBCCodeBuilder; +DXBCCodeBuilder* dxb_get_code_builder(DXBCBuilder* b); +DXBCCodeBuilder* dxb_create_code(dynamic_array<UInt32>& destArray); +void dxb_destroy_code(DXBCCodeBuilder* b); + +// result must be free()'d +void* dxb_build (DXBCBuilder* b, size_t& outSize); + +void dxb_dcl_input (DXBCBuilder* b, const char* name, int index, int reg, int mask = 0xF); +void dxb_dcl_output (DXBCBuilder* b, const char* name, int index, int reg, int mask = 0xF); +void dxb_dcl_tex (DXBCBuilder* b, int index, SM4Target dim); +void dxb_dcl_cb (DXBCBuilder* b, int index, int size); + +void dxb_op (DXBCCodeBuilder* b, SM4Opcode op, bool sat); +void dxb_reg (DXBCCodeBuilder* b, char rchar, int reg, unsigned mask = 0xF); +void dxb_swz (DXBCCodeBuilder* b, char rchar, int reg, unsigned swiz = kSM4SwzNone, bool neg=false); +void dxb_float1 (DXBCCodeBuilder* b, float v); +void dxb_int1 (DXBCCodeBuilder* b, int i); +void dxb_float4 (DXBCCodeBuilder* b, float v0, float v1, float v2, float v3); + +//------------------------------------------------------------------------------------ +//SM 2.0 stuff +void dxb_dcl_input2 (DXBCBuilder* b, const char* name, int index, int reg, int mask); +void dxb_dcl_output2 (DXBCBuilder* b, const char* name, int index, int reg, int mask); +void dxb_dcl_tex2 (DXBCBuilder* b, int index, SM4Target dim); +void dxb_op2 (DXBCBuilder* b, SM2Opcode op, bool sat, int scratchTmpRegForSat = -1); +void dxb_reg2 (DXBCBuilder* b, char rchar, int reg, unsigned mask = 0xF); +void dxb_swz2 (DXBCBuilder* b, char rchar, int reg, unsigned swiz = kSM4SwzNone, bool neg=false); +int dxb_imm_f4 (DXBCBuilder* b, float v0, float v1, float v2, float v3); +SM2Opcode dxb_to_sm2 (SM4Opcode op); + + +struct DXBCBuilderStream +{ + //no shader builder and no auto SM20 code for raw code works + DXBCBuilderStream (DXBCCodeBuilder* b) : builder(NULL), bldcode(b), noSM2(true) { } + DXBCBuilderStream (DXBCBuilder* b) : builder(b), bldcode(dxb_get_code_builder(b)), noSM2(false) { } + + DXBCBuilderStream& op(SM4Opcode op) + { + dxb_op(bldcode, op, false); + if (!noSM2 && builder) + dxb_op2(builder, dxb_to_sm2(op), false); + return *this; + } + DXBCBuilderStream& op_sat(SM4Opcode op, int scratchTmpRegForSM2) + { + dxb_op(bldcode, op, true); + if (!noSM2 && builder) + dxb_op2(builder, dxb_to_sm2(op), true, scratchTmpRegForSM2); + return *this; + } + DXBCBuilderStream& reg (char rchar, int reg, unsigned mask = 0xF) + { + dxb_reg(bldcode, rchar, reg, mask); + if (!noSM2 && builder) + dxb_reg2(builder, rchar, reg, mask); + return *this; + } + DXBCBuilderStream& swz (char rchar, int reg, unsigned swiz = kSM4SwzNone, bool neg=false) + { + dxb_swz(bldcode, rchar, reg, swiz, neg); + if (!noSM2 && builder) + dxb_swz2(builder, rchar, reg, swiz, neg); + return *this; + } + DXBCBuilderStream& float1 (float v) + { + dxb_float1(bldcode, v); + + if (!noSM2 && builder) + { + const int reg = dxb_imm_f4 (builder, v, v, v, v); + dxb_swz2(builder, 'c', reg, kSM4SwzRepX); + } + return *this; + } + // float1 constant for SM2 only + DXBCBuilderStream& float1_2 (float v) + { + if (builder) + { + const int reg = dxb_imm_f4 (builder, v, v, v, v); + dxb_swz2(builder, 'c', reg, kSM4SwzRepX); + } + return *this; + } + DXBCBuilderStream& float4 (float v0, float v1, float v2, float v3) + { + dxb_float4(bldcode, v0, v1, v2, v3); + + if (!noSM2 && builder) + { + const int reg = dxb_imm_f4 (builder, v0, v1, v2, v3); + dxb_swz2(builder, 'c', reg); + } + return *this; + } + + + //------------------------------------------------------------------------------------ + //SM 2.0 stuff + + DXBCBuilderStream& op2(SM2Opcode op) + { + dxb_op2(builder, op, false); + return *this; + } + DXBCBuilderStream& reg2 (char rchar, int reg, unsigned mask = 0xF) + { + dxb_reg2(builder, rchar, reg, mask); + return *this; + } + DXBCBuilderStream& swz2 (char rchar, int reg, unsigned swiz = kSM4SwzNone, bool neg=false) + { + dxb_swz2(builder, rchar, reg, swiz, neg); + return *this; + } + void noAutoSM2(bool _noSM2=true) + { + noSM2 = _noSM2; + } + void autoSM2() + { + noSM2 = false; + } + + DXBCBuilder* builder; + DXBCCodeBuilder* bldcode; + bool noSM2; +}; + diff --git a/Runtime/GfxDevice/d3d11/D3D11Compiler.cpp b/Runtime/GfxDevice/d3d11/D3D11Compiler.cpp new file mode 100644 index 0000000..5cda3d7 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Compiler.cpp @@ -0,0 +1,2 @@ +#include "UnityPrefix.h" +#include "D3D11Compiler.h" diff --git a/Runtime/GfxDevice/d3d11/D3D11Compiler.h b/Runtime/GfxDevice/d3d11/D3D11Compiler.h new file mode 100644 index 0000000..93284b2 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Compiler.h @@ -0,0 +1,117 @@ +#pragma once + +#if UNITY_WIN + +#if UNITY_WP8 + +#pragma message("WP8 TODO: implement") // ?!- + +#define kD3D11CompilerDLL "dummy.dll" // ?!- + +struct D3D11Compiler // ?!- +{ +public: + void Initialize (const char* dllName) {} + void Shutdown () {} + bool IsValid() const { return false; } +}; + +#else + +#if UNITY_WINRT +#include <d3dcompiler.h> +#else +#include "External/DirectX/builds/dx11include/d3d11.h" +#endif + +#if UNITY_WINRT +#define kD3D11CompilerDLL "D3DCompiler_45.dll" +#else +#define kD3D11CompilerDLL "D3DCompiler_43.dll" +#endif + +struct D3D11Compiler +{ +public: + #if UNITY_WINRT + typedef HRESULT (WINAPI* D3DCompileFunc)( + _In_reads_bytes_(SrcDataSize) LPCVOID pSrcData, + _In_ SIZE_T SrcDataSize, + _In_opt_ LPCSTR pSourceName, + _In_reads_opt_(_Inexpressible_(pDefines->Name != NULL)) CONST D3D_SHADER_MACRO* pDefines, + _In_opt_ ID3DInclude* pInclude, + _In_ LPCSTR pEntrypoint, + _In_ LPCSTR pTarget, + _In_ UINT Flags1, + _In_ UINT Flags2, + _Out_ ID3DBlob** ppCode, + _Out_opt_ ID3DBlob** ppErrorMsgs); + + typedef HRESULT (WINAPI* D3DStripShaderFunc)( + _In_reads_bytes_(BytecodeLength) LPCVOID pShaderBytecode, + _In_ SIZE_T BytecodeLength, + _In_ UINT uStripFlags, + _Out_ ID3DBlob** ppStrippedBlob); + + typedef HRESULT (WINAPI* D3DReflectFunc)( + _In_reads_bytes_(SrcDataSize) LPCVOID pSrcData, + _In_ SIZE_T SrcDataSize, + _In_ REFIID pInterface, + _Out_ void** ppReflector); + #else + typedef HRESULT (WINAPI *D3DCompileFunc)( + const void* pSrcData, + unsigned long SrcDataSize, + const char* pFileName, + const D3D10_SHADER_MACRO* pDefines, + ID3D10Include* pInclude, + const char* pEntrypoint, + const char* pTarget, + UINT Flags1, + UINT Flags2, + ID3D10Blob** ppCode, + ID3D10Blob** ppErrorMsgs); + + typedef HRESULT (WINAPI *D3DStripShaderFunc)( + __in_bcount(BytecodeLength) const void* pShaderBytecode, + __in unsigned long BytecodeLength, + __in unsigned int uStripFlags, + __out ID3D10Blob** ppStrippedBlob); + + typedef HRESULT (WINAPI *D3DReflectFunc)( + __in_bcount(SrcDataSize) const void* pSrcData, + __in unsigned long SrcDataSize, + __in REFIID pInterface, + __out void** ppReflector); + #endif + + typedef HRESULT (WINAPI *D3DDisassembleFunc)( + __in const void* pSrcData, + __in SIZE_T SrcDataSize, + __in UINT Flags, + __in const char* szComments, + __out ID3D10Blob** ppDisassembly); + + typedef HRESULT (WINAPI *D3DCreateBlobFunc)(SIZE_T size, ID3D10Blob** blob); + +public: + void Initialize (const char* dllName); + void Shutdown (); + bool IsValid() const { return compileFunc && reflectFunc; } + +public: + #if !UNITY_WINRT + HINSTANCE dll; + #endif + D3DCompileFunc compileFunc; + D3DStripShaderFunc stripShaderFunc; + D3DReflectFunc reflectFunc; + D3DDisassembleFunc disassembleFunc; + D3DCreateBlobFunc createBlobFunc; +}; + +extern GUID kIID_ID3D11ShaderReflection; + +#endif + +#endif // UNITY_WIN diff --git a/Runtime/GfxDevice/d3d11/D3D11Context.cpp b/Runtime/GfxDevice/d3d11/D3D11Context.cpp new file mode 100644 index 0000000..06abd9b --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Context.cpp @@ -0,0 +1,610 @@ +#include "UnityPrefix.h" + +#if !UNITY_WP8 && !UNITY_METRO + +#include "D3D11Context.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Profiler/ExternalGraphicsProfiler.h" +#include "D3D11Includes.h" +#include "D3D11Utils.h" +#include "TexturesD3D11.h" +#include "TimerQueryD3D11.h" +#include "Runtime/Misc/QualitySettings.h" +#include "Runtime/Math/ColorSpaceConversion.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Utilities/LogUtility.h" +#include "PlatformDependent/Win/ComPtr.h" +#include "Runtime/Utilities/Argv.h" + + +SupportedFeatureLevels GetSupportedFeatureLevels() +{ + SupportedFeatureLevels features; + + if (HasARGV("force-feature-level-9-1")) features.push_back(D3D_FEATURE_LEVEL_9_1); + if (HasARGV("force-feature-level-9-2")) features.push_back(D3D_FEATURE_LEVEL_9_2); + if (HasARGV("force-feature-level-9-3")) features.push_back(D3D_FEATURE_LEVEL_9_3); + if (HasARGV("force-feature-level-10-0")) features.push_back(D3D_FEATURE_LEVEL_10_0); + if (HasARGV("force-feature-level-10-1")) features.push_back(D3D_FEATURE_LEVEL_10_1); + if (HasARGV("force-feature-level-11-0")) features.push_back(D3D_FEATURE_LEVEL_11_0); + + features.push_back(D3D_FEATURE_LEVEL_11_0); + features.push_back(D3D_FEATURE_LEVEL_10_1); + features.push_back(D3D_FEATURE_LEVEL_10_0); + + return features; +} + +#if ENABLE_PROFILER +D3D11PERF_BeginEventFunc g_D3D11BeginEventFunc = NULL; +D3D11PERF_EndEventFunc g_D3D11EndEventFunc = NULL; +#endif + +using namespace win; + +#if !UNITY_RELEASE +#define UNITY_DX11_CREATE_FLAGS D3D11_CREATE_DEVICE_DEBUG +#else +#define UNITY_DX11_CREATE_FLAGS 0 +#endif + + +static D3D_FEATURE_LEVEL kSupportedFeatureLevels[] = { + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, +}; + + +bool InitD3D11RenderDepthSurface (RenderDepthSurfaceD3D11& rs, TexturesD3D11* textures, bool sampleOnly); + + +static ComPtr<ID3D11Device> s_Device = NULL; +// DX11.1 runtime only. On older runtimes this will stay null. Internally accessed by GetGfxDevice11_1(). +static ComPtr<ID3D11Device1> s_Device11_1; + +static ID3D11DeviceContext* s_Context = NULL; +static IDXGIFactory* s_DXGIFactory = NULL; +IDXGIFactory* GetDXGIFactory() { return s_DXGIFactory; } +static IDXGISwapChain* s_SwapChain = NULL; +static IDXGIOutput* s_Output = NULL; +static int s_SwapChainAA = -1; +IDXGISwapChain* GetD3D11SwapChain() { return s_SwapChain; } + +static int s_SyncInterval = 0; +int GetD3D11SyncInterval() { return s_SyncInterval; } + +static RenderColorSurfaceD3D11 s_BackBuffer; +static RenderDepthSurfaceD3D11 s_DepthStencil; + +ID3D11RenderTargetView* g_D3D11CurrRT; +ID3D11DepthStencilView* g_D3D11CurrDS; +ID3D11Resource* g_D3D11CurrRTResource; +ID3D11Resource* g_D3D11CurrDSResource; +RenderColorSurfaceD3D11* g_D3D11CurrColorRT; +RenderDepthSurfaceD3D11* g_D3D11CurrDepthRT; +int g_D3D11Adapter = 0; +int g_D3D11Output = 0; + +static HWND s_Window = NULL; +static HINSTANCE s_D3DDll = NULL; +static HINSTANCE s_D3D9Dll = NULL; +static HINSTANCE s_DXGIDll = NULL; +static bool s_CurrentlyWindowed = true; + +typedef HRESULT (WINAPI* D3D11CreateDeviceFunc)( + IDXGIAdapter *pAdapter, + D3D_DRIVER_TYPE DriverType, + HMODULE Software, + UINT Flags, + CONST D3D_FEATURE_LEVEL *pFeatureLevels, + UINT FeatureLevels, + UINT SDKVersion, + ID3D11Device **ppDevice, + D3D_FEATURE_LEVEL *pFeatureLevel, + ID3D11DeviceContext **ppImmediateContext +); + +typedef HRESULT (WINAPI* CreateDXGIFactoryFunc)( + REFIID ridd, + void** ppFactory +); + +// Either selects default adapter (NULL) or n-th one, +// defined by adapterIndex. Returned adapter +// must be released if not NULL! +static IDXGIAdapter* SelectAdapter (int adapterIndex) +{ + s_DXGIDll = LoadLibrary( "dxgi.dll" ); + if( !s_DXGIDll ) + return NULL; + + CreateDXGIFactoryFunc createDXGIFactory = (CreateDXGIFactoryFunc)GetProcAddress( s_DXGIDll, "CreateDXGIFactory" ); + if( !createDXGIFactory ) + return NULL; + + IDXGIAdapter* adapter = NULL; + if ( SUCCEEDED(createDXGIFactory(__uuidof(IDXGIFactory), (void**)&s_DXGIFactory)) ) + { + for ( int i = 0; SUCCEEDED(s_DXGIFactory->EnumAdapters(i, &adapter)); ++i ) + { + if ( i == adapterIndex ) + break; + else + adapter->Release(); + } + } + + return adapter; +} + +// Selects default output (NULL) or the one defined by outputIndex. +// Result must be released! +static IDXGIOutput* SelectOutput (IDXGIAdapter* adapter, int outputIndex) +{ + if (outputIndex == 0) + return NULL; + + Assert(adapter); + + IDXGIOutput* output = NULL; + for ( int i = 0; SUCCEEDED(adapter->EnumOutputs(i, &output)); ++i ) + { + if ( i == outputIndex ) + break; + else + output->Release(); + } + + return output; +} + +bool InitializeD3D11 () +{ + AssertIf (s_Device || s_Context || s_Window || s_D3DDll || s_D3D9Dll || s_DXGIDll); + + SupportedFeatureLevels features = GetSupportedFeatureLevels(); + IDXGIAdapter* adapter = NULL; + + s_D3DDll = LoadLibrary( "d3d11.dll" ); + if (!s_D3DDll) + { + printf_console ("d3d11: no D3D11 installed\n"); + goto _cleanup; + } + + D3D11CreateDeviceFunc createFunc = (D3D11CreateDeviceFunc)GetProcAddress( s_D3DDll, "D3D11CreateDevice" ); + if( !createFunc ) + { + printf_console ("d3d11: D3D11CreateDevice not found\n"); + goto _cleanup; + } + + + DWORD d3d11CreateFlags = 0; + if (!HasARGV("force-d3d11-no-singlethreaded")) + { + d3d11CreateFlags |= D3D11_CREATE_DEVICE_SINGLETHREADED; + } + + adapter = SelectAdapter (g_D3D11Adapter); + if (adapter) + s_Output = SelectOutput (adapter, g_D3D11Output); + + // create D3D device & immediate context, + // with debug layer in Debug config + HRESULT hr = E_FAIL; + D3D_FEATURE_LEVEL level; + D3D_DRIVER_TYPE driverType = adapter ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE; + #if !UNITY_RELEASE + hr = createFunc ( + adapter, driverType, NULL, + d3d11CreateFlags | D3D11_CREATE_DEVICE_DEBUG, + &features[0], + features.size(), + D3D11_SDK_VERSION, &s_Device, &level, &s_Context + ); + #endif + // create without debug layer if the above failed or was not called at all + if (FAILED(hr)) + { + hr = createFunc ( + adapter, driverType, NULL, + d3d11CreateFlags, + &features[0], features.size(), + D3D11_SDK_VERSION, &s_Device, &level, &s_Context + ); + } + if (FAILED(hr)) + { + printf_console( "d3d11: failed to create D3D11 device (0x%08x)\n", hr ); + goto _cleanup; + } + + SAFE_RELEASE(adapter); + + // Query DX11.1 interface, may well fail for older runtimes and is silently ignored. + s_Device->QueryInterface(&s_Device11_1); + + // Create DXGIFactory if it isn't already created by SelectAdapter + if (!s_DXGIFactory) + { + IDXGIDevice* dxgiDevice = NULL; + hr = s_Device->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); + IDXGIAdapter* dxgiAdapter = NULL; + hr = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&dxgiAdapter); + hr = dxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&s_DXGIFactory); + dxgiAdapter->Release(); + dxgiDevice->Release(); + } + + + #if ENABLE_PROFILER + // Even on D3D11, PIX event marker functions are in D3D9 DLL + s_D3D9Dll = LoadLibrary ("d3d9.dll"); + if (s_D3D9Dll) + { + g_D3D11BeginEventFunc = (D3D11PERF_BeginEventFunc)GetProcAddress(s_D3D9Dll, "D3DPERF_BeginEvent"); + g_D3D11EndEventFunc = (D3D11PERF_EndEventFunc)GetProcAddress(s_D3D9Dll, "D3DPERF_EndEvent"); + } + #endif + + return true; + +_cleanup: + SAFE_RELEASE(adapter); + SAFE_RELEASE(s_Output); + SAFE_RELEASE(s_DXGIFactory); + + s_Device11_1.Free(); + s_Device.Free(); + + SAFE_RELEASE(s_Context); + + if (s_D3DDll) { + FreeLibrary (s_D3DDll); + s_D3DDll = NULL; + } + if (s_D3D9Dll) { + FreeLibrary (s_D3D9Dll); + s_D3D9Dll = NULL; + } + if (s_DXGIDll) { + FreeLibrary (s_DXGIDll); + s_DXGIDll = NULL; + } + return false; +} + + +void CleanupD3D11() +{ + AssertIf (((ID3D11Device *)s_Device) || s_Context || s_Window); + + if (s_D3DDll) + { + FreeLibrary (s_D3DDll); + s_D3DDll = NULL; + } + if (s_D3D9Dll) + { + FreeLibrary (s_D3D9Dll); + s_D3D9Dll = NULL; + } + if (s_DXGIDll) { + FreeLibrary (s_DXGIDll); + s_DXGIDll = NULL; + } +} + +static void ReleaseBackbufferResources() +{ + //NESTED_LOG("DX11 debug", "ReleaseBackbufferResources"); + + Assert(s_Device && s_Context); + + #if ENABLE_PROFILER + g_TimerQueriesD3D11.ReleaseAllQueries(); + #endif + + SAFE_RELEASE(s_DepthStencil.m_Texture); + SAFE_RELEASE(s_DepthStencil.m_SRView); + SAFE_RELEASE(s_DepthStencil.m_DSView); + s_BackBuffer.Reset(); + + if (s_Context) + s_Context->OMSetRenderTargets(0, NULL, NULL); +} + + +static void CreateBackbufferResources(GfxDevice* device, int width, int height, int antiAlias, DXGI_FORMAT swapFormat, bool sRGB) +{ + //NESTED_LOG("DX11 debug", "CreateBackbufferResources %ix%i", width, height); + + HRESULT hr; + + // Set the Backbuffer primary format flags + s_BackBuffer.flags = sRGB ? (s_BackBuffer.flags | kSurfaceCreateSRGB) : (s_BackBuffer.flags & ~kSurfaceCreateSRGB); + + // Backbuffer + s_BackBuffer.width = width; + s_BackBuffer.height = height; + s_BackBuffer.samples = antiAlias; + s_BackBuffer.backBuffer = true; + s_BackBuffer.format = kRTFormatARGB32; + + hr = s_SwapChain->GetBuffer (0, __uuidof(*s_BackBuffer.m_Texture), (void**)&s_BackBuffer.m_Texture); + Assert(SUCCEEDED(hr)); + SetDebugNameD3D11 (s_BackBuffer.m_Texture, Format("SwapChain-BackBuffer-Texture-%dx%d", width, height)); + + // Create the primary backbuffer view + ID3D11RenderTargetView* rtv = NULL; + D3D11_RENDER_TARGET_VIEW_DESC rtDesc; + rtDesc.Format = sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + rtDesc.ViewDimension = antiAlias > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D; + rtDesc.Texture2D.MipSlice = 0; + hr = s_Device->CreateRenderTargetView (s_BackBuffer.m_Texture, &rtDesc, &rtv); + s_BackBuffer.SetRTV (0, 0, false, rtv); + Assert(SUCCEEDED(hr)); + SetDebugNameD3D11 (rtv, Format("SwapChain-BackBuffer-RTV-%dx%d", width, height)); + + // Create the secondary backbuffer view + D3D11_RENDER_TARGET_VIEW_DESC rtDescSecondary; + rtDescSecondary.Format = !sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + rtDescSecondary.ViewDimension = antiAlias > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D; + rtDescSecondary.Texture2D.MipSlice = 0; + hr = s_Device->CreateRenderTargetView (s_BackBuffer.m_Texture, &rtDescSecondary, &rtv); + s_BackBuffer.SetRTV (0, 0, true, rtv); + Assert(SUCCEEDED(hr)); + SetDebugNameD3D11 (rtv, Format("SwapChain-BackBuffer-RTVSec-%dx%d", width, height)); + + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) + { + // Create shader resource view + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + srvDesc.Format = swapFormat; + srvDesc.ViewDimension = antiAlias > 1 ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MostDetailedMip = 0; + srvDesc.Texture2D.MipLevels = 1; + + ID3D11ShaderResourceView* srView = NULL; + hr = s_Device->CreateShaderResourceView (s_BackBuffer.m_Texture, &srvDesc, &s_BackBuffer.m_SRView); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (s_BackBuffer.m_SRView, Format("SwapChain-BackBuffer-SRV-%dx%d", width, height)); + } + + // Depth stencil + s_DepthStencil.width = width; + s_DepthStencil.height = height; + s_DepthStencil.samples = antiAlias; + s_DepthStencil.dim = kTexDim2D; + s_DepthStencil.backBuffer = true; + s_DepthStencil.depthFormat = device->GetFramebufferDepthFormat(); + { + bool dsOk = InitD3D11RenderDepthSurface (s_DepthStencil, NULL, false); + Assert (dsOk); + } + +#if !UNITY_EDITOR + RenderSurfaceHandle bbHandle(&s_BackBuffer), dsHandle(&s_DepthStencil); + device->SetRenderTargets(1, &bbHandle, dsHandle); +#endif + + #if ENABLE_PROFILER + if (gGraphicsCaps.hasTimerQuery) + g_TimerQueriesD3D11.RecreateAllQueries(); + #endif +} + + +bool InitializeOrResetD3D11SwapChain( + class GfxDevice* device, + HWND window, int width, int height, + int refreshRate, bool fullscreen, int vsynccount, int antiAlias, + int& outBackbufferBPP, int& outFrontbufferBPP, int& outDepthBPP, int& outFSAA ) +{ + Assert(s_Device && s_Context); + + ReleaseBackbufferResources(); + + outBackbufferBPP = 4; + outFrontbufferBPP = 4; + outDepthBPP = 4; + outFSAA = 0; + + device->SetCurrentWindowSize (width, height); + + // pick supported AA level + if (antiAlias == -1) + antiAlias = GetQualitySettings().GetCurrent().antiAliasing; + while (antiAlias > 1 && !(gGraphicsCaps.d3d11.msaa & (1<<antiAlias))) + --antiAlias; + antiAlias = std::max(antiAlias, 1); + + const bool sRGB = GetActiveColorSpace() == kLinearColorSpace; + + // Release old swap chain if we need to change AA + if (s_SwapChain && s_SwapChainAA != antiAlias) + { + // swap chain must go out of fullscreen before releasing it + s_SwapChain->SetFullscreenState (FALSE, NULL); + SAFE_RELEASE(s_SwapChain); + } + + // Create Swap Chain + HRESULT hr; + + DWORD swapFlags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + DXGI_FORMAT swapFormat = sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + s_SwapChainAA = antiAlias; + s_SyncInterval = vsynccount; + if (!s_SwapChain) + { + //NESTED_LOG("DX11 debug", "InitializeOrResetD3D11SwapChain, init %ix%i, window %p", width, height, window); + + DXGI_SWAP_CHAIN_DESC sd; + ZeroMemory (&sd, sizeof(sd)); + sd.BufferCount = 1; + sd.BufferDesc.Width = width; + sd.BufferDesc.Height = height; + sd.BufferDesc.Format = swapFormat; + sd.BufferDesc.RefreshRate.Numerator = refreshRate; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) + sd.BufferUsage |= DXGI_USAGE_SHADER_INPUT; + sd.Flags = swapFlags; + sd.OutputWindow = window; + sd.SampleDesc.Count = antiAlias; + sd.SampleDesc.Quality = 0; + // Docs suggest always setting this to true and then doing SetFullscreenState + sd.Windowed = TRUE; + hr = s_DXGIFactory->CreateSwapChain (s_Device, &sd, &s_SwapChain); + Assert(SUCCEEDED(hr)); + + // We'll handle Alt-Enter and other things ourselves + DWORD dxgiFlags = DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES; + s_DXGIFactory->MakeWindowAssociation (window, dxgiFlags); + + if (fullscreen) + s_SwapChain->SetFullscreenState(TRUE, s_Output); + + CreateBackbufferResources(device, width, height, antiAlias, swapFormat, sRGB); + } + else + { + DXGI_MODE_DESC mode; + mode.Width = width; + mode.Height = height; + mode.RefreshRate.Numerator = refreshRate; + mode.RefreshRate.Denominator = 1; + mode.Format = swapFormat; + mode.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; + mode.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; + + //NESTED_LOG("DX11 debug", "InitializeOrResetD3D11SwapChain, resize %ix%i, fs=%i, window %p", width, height, fullscreen, window); + + // Note: the following will often call WM_SIZE on us, which will handle actual resizing (since size might be slightly different!), + // which will go into ResizeSwapD3D11SwapChain. + + { + //NESTED_LOG("DX11 debug", "ResizeTarget 1st"); + s_SwapChain->ResizeTarget (&mode); + } + { + //NESTED_LOG("DX11 debug", "SetFullscreenState"); + s_SwapChain->SetFullscreenState (fullscreen, fullscreen ? s_Output : NULL); + } + + // according to "DXGI: Best Practices" on MSDN, advisable + // to call resize target again with refresh rate zeroed out. + mode.RefreshRate.Numerator = 0; + mode.RefreshRate.Denominator = 0; + if (fullscreen) + { + //NESTED_LOG("DX11 debug", "ResizeTarget 2nd"); + s_SwapChain->ResizeTarget (&mode); + } + + // In some cases above calls do not post WM_SIZE, so ResizeSwapD3D11SwapChain is not called, + // which means we won't get back buffer. + // If we still don't have back buffer here, just set it up. + if (!s_BackBuffer.m_Texture) + { + CreateBackbufferResources (device, width, height, s_SwapChainAA, swapFormat, sRGB); + } + } + + return true; +} + + +void ResizeSwapD3D11SwapChain (class GfxDevice* device, HWND window, int width, int height) +{ + if (!s_SwapChain) + return; + + const bool hadBackBuffer = (s_DepthStencil.m_Texture != NULL); + if (hadBackBuffer) + ReleaseBackbufferResources(); + + device->SetCurrentWindowSize (width, height); + + const bool sRGB = GetActiveColorSpace() == kLinearColorSpace; + DWORD swapFlags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + DXGI_FORMAT swapFormat = sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + + //NESTED_LOG("DX11 debug", "ResizeSwapD3D11SwapChain, resize %ix%i", width, height); + s_SwapChain->ResizeBuffers (1, width, height, sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM, swapFlags); + + CreateBackbufferResources (device, width, height, s_SwapChainAA, swapFormat, sRGB); +} + + + +void DestroyD3D11Device() +{ + // This can happen when quiting from screen selector - window is not set up yet + if( !((ID3D11Device *)s_Device)|| !s_Context || !s_DXGIFactory ) + return; + + // swap chain must go out of fullscreen before releasing it + if (s_SwapChain) + { + s_SwapChain->SetFullscreenState (FALSE, NULL); + } + + // cleanup + SAFE_RELEASE(s_DepthStencil.m_Texture); + SAFE_RELEASE(s_DepthStencil.m_SRView); + SAFE_RELEASE(s_DepthStencil.m_DSView); + s_BackBuffer.Reset(); + SAFE_RELEASE(s_SwapChain); + + s_Context->ClearState(); + s_Context->Flush(); + + s_Context->Release(); + s_Context = NULL; + + /* + // Helper code to report any live objects + ID3D11Debug *d3dDebug = NULL; + if (SUCCEEDED(s_Device->QueryInterface(__uuidof(ID3D11Debug), (void**)&d3dDebug))) + { + d3dDebug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL | D3D11_RLDO_SUMMARY); + d3dDebug->Release(); + } + */ + + s_Device11_1.Free(); + s_Device.Free(); + + SAFE_RELEASE(s_Output); + SAFE_RELEASE(s_DXGIFactory); + + s_Window = NULL; +} + +ID3D11Device* GetD3D11Device() +{ + AssertIf( !((ID3D11Device *)s_Device) ); + return s_Device; +} + +ID3D11Device1* GetD3D11_1Device() +{ + return s_Device11_1; +} + + +ID3D11DeviceContext* GetD3D11Context(bool expectNull) +{ + if (!expectNull) + Assert( s_Context ); + return s_Context; +} + +#endif + diff --git a/Runtime/GfxDevice/d3d11/D3D11Context.h b/Runtime/GfxDevice/d3d11/D3D11Context.h new file mode 100644 index 0000000..16134ce --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Context.h @@ -0,0 +1,65 @@ +#pragma once + +#include "D3D11Includes.h" + +#if UNITY_METRO +#include <windows.ui.xaml.media.dxinterop.h> +#endif + +struct D3D11Compiler; + +bool InitializeD3D11(); +void CleanupD3D11(); +#if UNITY_WP8 +HRESULT UpdateD3D11Device(ID3D11Device1* device, ID3D11DeviceContext1* deviceContext, ID3D11RenderTargetView* renderTargetView, int& width, int& height); +void ActivateD3D11BackBuffer(class GfxDevice* device); +#elif UNITY_METRO +IDXGISwapChain1* CreateSwapChainForXAML(ISwapChainBackgroundPanelNative* panel, int width, int height); +#if UNITY_METRO_VS2013 +IDXGIDevice3* GetIDXGIDevice3(); +#endif +IDXGISwapChain1* CreateSwapChainForD3D(IUnknown* coreWindow, int width, int height); +bool InitializeOrResetD3D11SwapChain( + class GfxDevice* device, + IDXGISwapChain1* chain, int width, int height, int vsynccount, + int& outBackbufferBPP, int& outFrontbufferBPP, int& outDepthBPP, int& outFSAA); +void ActivateD3D11BackBuffer(class GfxDevice* device); +#else +bool InitializeOrResetD3D11SwapChain( + class GfxDevice* device, + HWND window, int width, int height, + int refreshRate, bool fullscreen, int vsynccount, int fsaa, + int& outBackbufferBPP, int& outFrontbufferBPP, int& outDepthBPP, int& outFSAA); +void ResizeSwapD3D11SwapChain (class GfxDevice* device, HWND window, int width, int height); + +#endif + +typedef std::vector<D3D_FEATURE_LEVEL> SupportedFeatureLevels; +SupportedFeatureLevels GetSupportedFeatureLevels(); + +void DestroyD3D11Device(); + +ID3D11Device* GetD3D11Device(); +ID3D11Device1* GetD3D11_1Device(); +ID3D11DeviceContext* GetD3D11Context(bool expectNull = false); + +IDXGIFactory* GetDXGIFactory(); +IDXGISwapChain* GetD3D11SwapChain(); +int GetD3D11SyncInterval(); + +#if ENABLE_DX11_FRAME_LATENCY_WAITABLE_OBJECT +HANDLE GetFrameLatencyWaitableObject(); +void WaitOnSwapChain(); +#endif + +extern ID3D11RenderTargetView* g_D3D11CurrRT; +extern ID3D11DepthStencilView* g_D3D11CurrDS; +struct RenderColorSurfaceD3D11; +struct RenderDepthSurfaceD3D11; +extern RenderColorSurfaceD3D11* g_D3D11CurrColorRT; +extern RenderDepthSurfaceD3D11* g_D3D11CurrDepthRT; + +typedef int (WINAPI* D3D11PERF_BeginEventFunc)(DWORD, LPCWSTR); +typedef int (WINAPI* D3D11PERF_EndEventFunc)(); +extern D3D11PERF_BeginEventFunc g_D3D11BeginEventFunc; +extern D3D11PERF_EndEventFunc g_D3D11EndEventFunc; diff --git a/Runtime/GfxDevice/d3d11/D3D11Context_Metro.cpp b/Runtime/GfxDevice/d3d11/D3D11Context_Metro.cpp new file mode 100644 index 0000000..4c285ff --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Context_Metro.cpp @@ -0,0 +1,484 @@ +#include "UnityPrefix.h" + +#if UNITY_METRO +#include "D3D11Context.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Profiler/ExternalGraphicsProfiler.h" +#include "D3D11Includes.h" +#include "D3D11Utils.h" +#include "TexturesD3D11.h" +#include "TimerQueryD3D11.h" +#include "Runtime/Misc/QualitySettings.h" +#include "Runtime/Math/ColorSpaceConversion.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Utilities/LogUtility.h" +#include "PlatformDependent/Win/ComPtr.h" +#include "PlatformDependent/MetroPlayer/AppCallbacks.h" +#include "Runtime/Utilities/Argv.h" + +SupportedFeatureLevels GetSupportedFeatureLevels() +{ + SupportedFeatureLevels features; + + if (HasARGV("force-feature-level-9-1")) features.push_back(D3D_FEATURE_LEVEL_9_1); + if (HasARGV("force-feature-level-9-2")) features.push_back(D3D_FEATURE_LEVEL_9_2); + if (HasARGV("force-feature-level-9-3")) features.push_back(D3D_FEATURE_LEVEL_9_3); + if (HasARGV("force-feature-level-10-0")) features.push_back(D3D_FEATURE_LEVEL_10_0); + if (HasARGV("force-feature-level-10-1")) features.push_back(D3D_FEATURE_LEVEL_10_1); + if (HasARGV("force-feature-level-11-0")) features.push_back(D3D_FEATURE_LEVEL_11_0); + + features.push_back(D3D_FEATURE_LEVEL_11_0); + features.push_back(D3D_FEATURE_LEVEL_10_1); + features.push_back(D3D_FEATURE_LEVEL_10_0); + features.push_back(D3D_FEATURE_LEVEL_9_3); + features.push_back(D3D_FEATURE_LEVEL_9_2); + features.push_back(D3D_FEATURE_LEVEL_9_1); + + return features; +} + +#if ENABLE_PROFILER +D3D11PERF_BeginEventFunc g_D3D11BeginEventFunc = NULL; +D3D11PERF_EndEventFunc g_D3D11EndEventFunc = NULL; +#endif + +using namespace win; + +#if !UNITY_RELEASE && !defined(__arm__) +#define UNITY_DX11_CREATE_FLAGS D3D11_CREATE_DEVICE_DEBUG +#else +#define UNITY_DX11_CREATE_FLAGS 0 +#endif + + +static ComPtr<ID3D11Device1> s_Device; +static ComPtr<ID3D11DeviceContext1> s_Context; +static ComPtr<IDXGIFactory2> s_DXGIFactory; +static IDXGISwapChain1* s_SwapChain = NULL; +#if UNITY_METRO_VS2013 +static IDXGIDevice3* s_DXGIDevice3 = NULL; +#endif +IDXGISwapChain* GetD3D11SwapChain() { return s_SwapChain; } + +static int s_SyncInterval = 0; +int GetD3D11SyncInterval() { return s_SyncInterval; } + +static RenderColorSurfaceD3D11 s_BackBuffer; +static RenderDepthSurfaceD3D11 s_DepthStencil; + +ID3D11RenderTargetView* g_D3D11CurrRT; +ID3D11DepthStencilView* g_D3D11CurrDS; +ID3D11Resource* g_D3D11CurrRTResource; +ID3D11Resource* g_D3D11CurrDSResource; +RenderColorSurfaceD3D11* g_D3D11CurrColorRT; +RenderDepthSurfaceD3D11* g_D3D11CurrDepthRT; + +static const int kSwapChainBackBufferCount = 2; +#if ENABLE_DX11_FRAME_LATENCY_WAITABLE_OBJECT +static bool s_EnableLowLatencyPresentationAPI = true; +static HANDLE s_FrameLatencyWaitableObject = NULL; +static UINT kSwapChainFlags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; +#else +static UINT kSwapChainFlags = 0; +#endif +static const DXGI_FORMAT kSwapChainBackBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM; + +#define DX_CHECK(HR, ...) if (FAILED(hr)) {ErrorStringMsg(__VA_ARGS__); goto error; } + +bool InitializeD3D11() +{ + HRESULT hr; + + ComPtr<ID3D11Device> device; + ComPtr<ID3D11DeviceContext> context; + ComPtr<IDXGIDevice1> dxgiDevice; + ComPtr<IDXGIAdapter> dxgiAdapter; + + #if UNITY_DX11_CREATE_FLAGS + ComPtr<ID3D11Debug> debug; + #endif + + Assert(!s_Device); + Assert(!s_Context); + Assert(!s_DXGIFactory); + + SupportedFeatureLevels features = GetSupportedFeatureLevels(); + + D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_HARDWARE; + + if (HasARGV("force-driver-type-warp")) + { + driverType = D3D_DRIVER_TYPE_WARP; + } + + DWORD d3d11CreateFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; + if (!HasARGV("force-d3d11-no-singlethreaded")) + { + d3d11CreateFlags |= D3D11_CREATE_DEVICE_SINGLETHREADED; + } +#if ENABLE_DX11_FRAME_LATENCY_WAITABLE_OBJECT + if (HasARGV("disable-low-latency-presentation-api")) + { + printf_console("Disabling Low Latency presentation API.\n"); + s_EnableLowLatencyPresentationAPI = false; + kSwapChainFlags = 0; + } +#endif + + D3D_FEATURE_LEVEL level; + hr = D3D11CreateDevice( + nullptr, + driverType, + nullptr, + (d3d11CreateFlags | UNITY_DX11_CREATE_FLAGS), + &features[0], + features.size(), + D3D11_SDK_VERSION, + &device, + &level, + &context); + + if (FAILED(hr) && driverType != D3D_DRIVER_TYPE_WARP) + { + WarningStringMsg("D3D11 failed to create with D3D_DRIVER_TYPE_HARDWARE, fallbacking D3D_DRIVER_TYPE_WARP..."); + driverType = D3D_DRIVER_TYPE_WARP; + hr = D3D11CreateDevice( + nullptr, + driverType, + nullptr, + (d3d11CreateFlags | UNITY_DX11_CREATE_FLAGS), + &features[0], + features.size(), + D3D11_SDK_VERSION, + &device, + &level, + &context); + } + + DX_CHECK(hr, "D3D11CreateDevice failed with error 0x%08x ", hr); + + hr = device->QueryInterface(&s_Device); + DX_CHECK(hr, "device->QueryInterface(&s_Device) failed with error 0x%08x ", hr); + + hr = context->QueryInterface(&s_Context); + DX_CHECK(hr, "context->QueryInterface(&s_Context) failed with error 0x%08x ", hr); + + #if UNITY_DX11_CREATE_FLAGS + hr = s_Device->QueryInterface(&debug); + AssertMsg(SUCCEEDED(hr), "s_Device->QueryInterface(&debug) failed failed with error 0x%08x", hr); + + if (SUCCEEDED(hr)) + { + hr = debug->SetFeatureMask(D3D11_DEBUG_FEATURE_FLUSH_PER_RENDER_OP); + AssertMsg(SUCCEEDED(hr), "debug->SetFeatureMask(D3D11_DEBUG_FEATURE_FLUSH_PER_RENDER_OP) failed with error 0x%08x", hr); + } + + #endif + #if UNITY_METRO_VS2013 + hr = s_Device->QueryInterface(__uuidof(IDXGIDevice3), (void**) &s_DXGIDevice3); + DX_CHECK(hr, "s_Device->QueryInterface(__uuidof(IDXGIDevice3), (void**) &s_DXGIDevice3) with error 0x%08x ", hr); + #endif + + hr = s_Device->QueryInterface(&dxgiDevice); + DX_CHECK(hr, "s_Device->QueryInterface(&dxgiDevice) failed with error 0x%08x ", hr); + +#if ENABLE_DX11_FRAME_LATENCY_WAITABLE_OBJECT + // The maximum frame latency should be 1, if game is running at 60 FPS, but because + // most games will probably be running around 30, I guess it's better to set 2 + hr = dxgiDevice->SetMaximumFrameLatency(s_EnableLowLatencyPresentationAPI ? 2 : 1); +#else + hr = dxgiDevice->SetMaximumFrameLatency(1); +#endif + DX_CHECK(hr, "dxgiDevice->SetMaximumFrameLatency(1)) failed with error 0x%08x ", hr); + + hr = dxgiDevice->GetAdapter(&dxgiAdapter); + DX_CHECK(hr, "dxgiDevice->GetAdapter(&dxgiAdapter) failed with error 0x%08x ", hr); + + hr = dxgiAdapter->GetParent(__uuidof(s_DXGIFactory), reinterpret_cast<void**>(&s_DXGIFactory)); // ??? + DX_CHECK(hr, "dxgiAdapter->GetParent(...) failed with error 0x%08x ", hr); + + return true; + + + +error: + + s_DXGIFactory.Free(); + s_Context.Free(); + s_Device.Free(); + + return false; +} + +void GetSwapChainDesc1(DXGI_SWAP_CHAIN_DESC1& sd) +{ + // Found on forums, why BGRA is used here instead of RGBA: + // Microsoft dude - "I believe there are some flip optimizatoin benefits to using BGR rather than RGB." + // Update: So I changed the format to DXGI_FORMAT_R8G8B8A8_UNORM, checked the FPS in one of the games, didn't see any FPS loss + // But because all D3D11 gfxdevice was origanlly tested with DXGI_FORMAT_R8G8B8A8_UNORM, I think it makes sense to have this format instead + // It also makes image effects work correctly, for ex., it fixes bug - https://fogbugz.unity3d.com/default.asp?492440 + sd.Format = kSwapChainBackBufferFormat; + sd.Stereo = FALSE; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.BufferCount = kSwapChainBackBufferCount; + sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; + sd.Flags = kSwapChainFlags; + sd.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; +} +IDXGISwapChain1* CreateSwapChainForXAML(ISwapChainBackgroundPanelNative* panel, int width, int height) +{ + IDXGISwapChain1* chain; + DXGI_SWAP_CHAIN_DESC1 sd; + GetSwapChainDesc1(sd); + + sd.Width = width; + sd.Height = height; + + HRESULT hr; + sd.Scaling = DXGI_SCALING_STRETCH; + hr = s_DXGIFactory->CreateSwapChainForComposition(s_Device, &sd, nullptr, &chain); + DX_CHECK(hr, "CreateSwapChainForComposition failed with error 0x%08x", hr); + +#if UNITY_METRO_VS2013 + UnityPlayer::AppCallbacks::Instance->InvokeOnUIThread(ref new UnityPlayer::AppCallbackItem([panel, chain]() + { + HRESULT hr = panel->SetSwapChain(chain); + if (FAILED(hr)) FatalErrorMsg("SetSwapChain failed with error 0x%08x", hr); + } + ), false); +#else + hr = panel->SetSwapChain(chain); + if (FAILED(hr)) FatalErrorMsg("SetSwapChain failed with error 0x%08x", hr); +#endif + + return chain; +error: + return NULL; +} +IDXGISwapChain1* CreateSwapChainForD3D(IUnknown* coreWindow, int width, int height) +{ + IDXGISwapChain1* chain; + DXGI_SWAP_CHAIN_DESC1 sd; + GetSwapChainDesc1(sd); + + sd.Width = width; + sd.Height = height; + + HRESULT hr; + + sd.Scaling = DXGI_SCALING_STRETCH; + hr = s_DXGIFactory->CreateSwapChainForCoreWindow(s_Device, coreWindow, &sd, nullptr, &chain); + DX_CHECK(hr, "CreateSwapChainForCoreWindow failed with error 0x%08x", hr); + + return chain; +error: + return NULL; +} +bool InitializeOrResetD3D11SwapChain(GfxDevice* device, IDXGISwapChain1* chain, int width, int height, int vsynccount, int& outBackbufferBPP, int& outFrontbufferBPP, int& outDepthBPP, int& outFSAA) +{ + HRESULT hr; + Microsoft::WRL::ComPtr<ID3D11Texture2D> backBuffer; + Microsoft::WRL::ComPtr<ID3D11Texture2D> depthStencil; + + // + + Assert(nullptr != device); + Assert(nullptr != s_Device); + Assert(nullptr != s_Context); + Assert(nullptr != s_DXGIFactory); + + // + + outBackbufferBPP = 4; + outFrontbufferBPP = 4; + outDepthBPP = 4; + outFSAA = 0; + + + SAFE_RELEASE(s_DepthStencil.m_Texture); + SAFE_RELEASE(s_DepthStencil.m_SRView); + SAFE_RELEASE(s_DepthStencil.m_DSView); + s_BackBuffer.Reset(); + + // + + s_Context->OMSetRenderTargets(0, nullptr, nullptr); + s_Context->Flush(); + + s_SyncInterval = vsynccount; + + if (nullptr == s_SwapChain) + { + s_SwapChain = chain; +#if ENABLE_DX11_FRAME_LATENCY_WAITABLE_OBJECT + s_FrameLatencyWaitableObject = s_EnableLowLatencyPresentationAPI ? + ((IDXGISwapChain2*) s_SwapChain)->GetFrameLatencyWaitableObject() : + NULL; +#endif + } + else + { + // Use efficient DX 11.2 swap chain scaling if available +#if 0 && UNITY_METRO_VS2013 + + // Check if new resolution fits into already allocated swap chain + DXGI_SWAP_CHAIN_DESC swapChainDesc; + s_SwapChain->GetDesc(&swapChainDesc); + if (width <= swapChainDesc.BufferDesc.Width && height <= swapChainDesc.BufferDesc.Height) + { + hr = ((IDXGISwapChain2*)s_SwapChain)->SetSourceSize(width, height); + DX_CHECK(hr, "SetSourceSize failed with error 0x%08x", hr); + } + else +#endif + { + // Note: If you set third parameter as DXGI_FORMAT_UNKNOWN, D3D11 debugger incorrectly captures frame when swap chain is resized, for ex., when you perform snapping + hr = s_SwapChain->ResizeBuffers(kSwapChainBackBufferCount, width, height, kSwapChainBackBufferFormat, kSwapChainFlags); + DX_CHECK(hr, "ResizeBuffers failed with error 0x%08x", hr); + } + } + + hr = s_SwapChain->GetBuffer(0, __uuidof(backBuffer), reinterpret_cast<void**>(backBuffer.GetAddressOf())); + DX_CHECK(hr, "s_SwapChain->GetBuffer failed with error 0x%08x", hr); + + D3D11_TEXTURE2D_DESC backBufferDesc; + backBuffer->GetDesc(&backBufferDesc); + + width = backBufferDesc.Width; + height = backBufferDesc.Height; + + s_BackBuffer.m_Texture = backBuffer.Detach(); + s_BackBuffer.width = width; + s_BackBuffer.height = height; + s_BackBuffer.format = kRTFormatARGB32; + + device->SetCurrentWindowSize(width, height); + + ID3D11RenderTargetView* rtv = 0; + hr = s_Device->CreateRenderTargetView(s_BackBuffer.m_Texture, nullptr, &rtv); + DX_CHECK(hr, "CreateRenderTargetView failed with error 0x%08x", hr); + s_BackBuffer.SetRTV(0,0,false,rtv); + + hr = s_Device->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_D24_UNORM_S8_UINT, width, height, 1, 1, D3D11_BIND_DEPTH_STENCIL), nullptr, &depthStencil); + DX_CHECK(hr, "CreateTexture2D failed with error 0x%08x", hr); + + device->SetFramebufferDepthFormat(kDepthFormat24); + if (IsGfxDevice()) + GetGfxDevice().SetFramebufferDepthFormat(kDepthFormat24); + + s_DepthStencil.m_Texture = depthStencil.Get(); + + hr = s_Device->CreateDepthStencilView(depthStencil.Get(), &CD3D11_DEPTH_STENCIL_VIEW_DESC(D3D11_DSV_DIMENSION_TEXTURE2D), &s_DepthStencil.m_DSView); // ??? + DX_CHECK(hr, "CreateDepthStencilView failed with error 0x%08x", hr); + + s_BackBuffer.backBuffer = true; + s_DepthStencil.backBuffer = true; + + ActivateD3D11BackBuffer(device); + + return true; + +error: + + SAFE_RELEASE(s_DepthStencil.m_Texture); + SAFE_RELEASE(s_DepthStencil.m_SRView); + SAFE_RELEASE(s_DepthStencil.m_DSView); + s_BackBuffer.Reset(); + + SAFE_RELEASE(s_SwapChain); +#if UNITY_METRO_VS2013 + SAFE_RELEASE(s_DXGIDevice3); +#endif + return false; +} + +void ActivateD3D11BackBuffer(GfxDevice* device) +{ + Assert(nullptr != device); + device->SetRenderTargets(1, &RenderSurfaceHandle(&s_BackBuffer), RenderSurfaceHandle(&s_DepthStencil)); +} + +void DestroyD3D11Device() +{ + // This can happen when quiting from screen selector - window is not set up yet + if( !s_Device || !s_Context || !s_DXGIFactory) + return; + + // swap chain must go out of fullscreen before releasing it + if (s_SwapChain) + { + s_SwapChain->SetFullscreenState (FALSE, NULL); + } + + // cleanup + SAFE_RELEASE(s_DepthStencil.m_Texture); + SAFE_RELEASE(s_DepthStencil.m_SRView); + SAFE_RELEASE(s_DepthStencil.m_DSView); + s_BackBuffer.Reset(); + SAFE_RELEASE(s_SwapChain); +#if UNITY_METRO_VS2013 + SAFE_RELEASE(s_DXGIDevice3); +#endif + s_Context->ClearState(); + s_Context->Flush(); + + s_Context->Release(); + s_Context = NULL; + s_Device->Release(); + s_Device = NULL; + s_DXGIFactory->Release(); + s_DXGIFactory = NULL; +} + +void CleanupD3D11() +{ + AssertIf (s_Device || s_Context); +} + +ID3D11Device* GetD3D11Device() +{ + AssertIf( !s_Device ); + return s_Device; +} + +ID3D11Device1* GetD3D11_1Device() +{ + AssertIf( !s_Device ); + return s_Device; +} + + +ID3D11DeviceContext* GetD3D11Context(bool expectNull) +{ + if (!expectNull) + Assert( s_Context ); + return s_Context; +} +#if ENABLE_DX11_FRAME_LATENCY_WAITABLE_OBJECT +HANDLE GetFrameLatencyWaitableObject() +{ + return s_FrameLatencyWaitableObject; +} +void WaitOnSwapChain() +{ + if (s_EnableLowLatencyPresentationAPI) + { + DWORD result = WaitForSingleObjectEx( + s_FrameLatencyWaitableObject, + 1000, // 1 second timeout (shouldn't ever occur) + true + ); + } +} +#endif + +#if UNITY_METRO_VS2013 +IDXGIDevice3* GetIDXGIDevice3() +{ + return s_DXGIDevice3; +} +#endif +#endif diff --git a/Runtime/GfxDevice/d3d11/D3D11Context_WP8.cpp b/Runtime/GfxDevice/d3d11/D3D11Context_WP8.cpp new file mode 100644 index 0000000..dbf8613 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Context_WP8.cpp @@ -0,0 +1,233 @@ +#include "UnityPrefix.h" + +#if UNITY_WP8 + +#include "D3D11Context.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Profiler/ExternalGraphicsProfiler.h" +#include "D3D11Includes.h" +#include "D3D11Utils.h" +#include "TexturesD3D11.h" +#include "TimerQueryD3D11.h" +#include "Runtime/Misc/Plugins.h" +#include "Runtime/Misc/QualitySettings.h" +#include "Runtime/Math/ColorSpaceConversion.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Utilities/LogUtility.h" +#include "Runtime/Utilities/Argv.h" +#include "Runtime/Graphics/ScreenManager.h" + +SupportedFeatureLevels GetSupportedFeatureLevels() +{ + SupportedFeatureLevels features; + + features.push_back(D3D_FEATURE_LEVEL_9_3); + + return features; +} + +#if ENABLE_PROFILER +D3D11PERF_BeginEventFunc g_D3D11BeginEventFunc = NULL; +D3D11PERF_EndEventFunc g_D3D11EndEventFunc = NULL; +#endif + +using namespace Microsoft::WRL; + + +static ComPtr<ID3D11Device1> s_Device; +static ComPtr<ID3D11DeviceContext1> s_Context; + +static RenderColorSurfaceD3D11 s_BackBuffer; +static RenderDepthSurfaceD3D11 s_DepthStencil; + +ID3D11RenderTargetView* g_D3D11CurrRT; +ID3D11DepthStencilView* g_D3D11CurrDS; +ID3D11Resource* g_D3D11CurrRTResource; +ID3D11Resource* g_D3D11CurrDSResource; +RenderColorSurfaceD3D11* g_D3D11CurrColorRT; +RenderDepthSurfaceD3D11* g_D3D11CurrDepthRT; + + +HRESULT UpdateD3D11Device(ID3D11Device1* device, ID3D11DeviceContext1* deviceContext, ID3D11RenderTargetView* renderTargetView, int& width, int& height) +{ + HRESULT hr; + + Assert(device); + + // update device context + + if (deviceContext) + s_Context = deviceContext; + else + device->GetImmediateContext1(s_Context.ReleaseAndGetAddressOf()); + + // update device + + if (s_Device.Get() != device) + { + s_Context->OMSetRenderTargets(0, nullptr, nullptr); + s_BackBuffer.Reset(); + s_DepthStencil.Reset(); + + //@TODO: have to recreate all graphics resources, + // Runtime/GfxDevice/GfxDeviceRecreate.h + // + // CleanupAllGfxDeviceResources should be called while the "old device" is still active; + // RecreateAllGfxDeviceResources should be called when the "new device" is ready. + // + // Right now that works fine (tm) for switching editor between dx9 & dx11 in player settings, + // but possibly needs some adjustment for WP8. + + s_Device = device; + PluginsSetGraphicsDevice(device, kGfxRendererD3D11, kGfxDeviceEventInitialize); + + void RecreateAllGfxDeviceResources(); + + if (deviceContext) + RecreateAllGfxDeviceResources(); + } + + // update render target + + if (renderTargetView) + { + // get back buffer + + ComPtr<ID3D11Texture2D> backBuffer; + + { + ComPtr<ID3D11Resource> resource; + renderTargetView->GetResource(resource.GetAddressOf()); + + hr = resource.As(&backBuffer); + Assert(SUCCEEDED(hr)); + } + + // get description + + D3D11_TEXTURE2D_DESC backBufferDesc; + backBuffer->GetDesc(&backBufferDesc); + + // get actual resolution + + width = backBufferDesc.Width; + height = backBufferDesc.Height; + + bool const sizeChanged = ((s_BackBuffer.width != backBufferDesc.Width) || (s_BackBuffer.height != backBufferDesc.Height)); + + // update back buffer + + s_Context->OMSetRenderTargets(0, nullptr, nullptr); + Assert(DXGI_FORMAT_B8G8R8A8_UNORM == backBufferDesc.Format); + + s_BackBuffer.Reset(); + s_BackBuffer.width = backBufferDesc.Width; + s_BackBuffer.height = backBufferDesc.Height; + s_BackBuffer.backBuffer = true; + s_BackBuffer.format = kRTFormatARGB32; + s_BackBuffer.backBuffer = true; + s_BackBuffer.m_Texture = backBuffer.Detach(); + + s_BackBuffer.SetRTV(0, 0, false, renderTargetView); + renderTargetView->AddRef(); + + // update depth/stencil buffer if sice changed + + if (sizeChanged) + { + s_DepthStencil.Reset(); + + // create depth/stencil texture + + ComPtr<ID3D11Texture2D> depthStencil; + + hr = s_Device->CreateTexture2D(&CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_D24_UNORM_S8_UINT, backBufferDesc.Width, backBufferDesc.Height, 1, 1, D3D11_BIND_DEPTH_STENCIL), nullptr, &depthStencil); + Assert(SUCCEEDED(hr)); + + if (FAILED(hr)) + return hr; + + // create depth/stencil view + + hr = s_Device->CreateDepthStencilView(depthStencil.Get(), &CD3D11_DEPTH_STENCIL_VIEW_DESC(D3D11_DSV_DIMENSION_TEXTURE2D), &s_DepthStencil.m_DSView); // ??? + Assert(SUCCEEDED(hr)); + + if (FAILED(hr)) + return hr; + + // store depth/stencil buffer + + s_DepthStencil.m_Texture = depthStencil.Detach(); + s_DepthStencil.width = backBufferDesc.Width; + s_DepthStencil.height = backBufferDesc.Height; + s_DepthStencil.backBuffer = true; // ?!- + s_DepthStencil.depthFormat = kDepthFormat24; + + GetGfxDevice().SetFramebufferDepthFormat(kDepthFormat24); + } + + // set active render target + + ActivateD3D11BackBuffer(&GetGfxDevice()); // ?!- + } + + return S_OK; +} + +bool InitializeD3D11() +{ + Assert(s_Device); + Assert(s_Context); + return true; +} + +void CleanupD3D11() +{ + Assert(!s_Device); + Assert(!s_Context); +} + +void ActivateD3D11BackBuffer(GfxDevice* device) +{ + Assert(nullptr != device); + device->SetRenderTargets(1, &RenderSurfaceHandle(&s_BackBuffer), RenderSurfaceHandle(&s_DepthStencil)); +} + +void DestroyD3D11Device() +{ + if (!s_Device || !s_Context) + return; + + SAFE_RELEASE(s_DepthStencil.m_Texture); + SAFE_RELEASE(s_DepthStencil.m_SRView); + SAFE_RELEASE(s_DepthStencil.m_DSView); + s_BackBuffer.Reset(); + + s_Context->ClearState(); + s_Context->Flush(); + + s_Context.Reset(); + s_Device.Reset(); +} + +ID3D11Device* GetD3D11Device() +{ + AssertIf(!s_Device); + return s_Device.Get(); +} + +ID3D11Device1* GetD3D11_1Device() +{ + AssertIf( !s_Device ); + return s_Device.Get(); +} + +ID3D11DeviceContext* GetD3D11Context(bool expectNull) +{ + if (!expectNull) + Assert(s_Context); + return s_Context.Get(); +} + +#endif diff --git a/Runtime/GfxDevice/d3d11/D3D11Debug.cpp b/Runtime/GfxDevice/d3d11/D3D11Debug.cpp new file mode 100644 index 0000000..f6ed253 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Debug.cpp @@ -0,0 +1,282 @@ +#include "UnityPrefix.h" +#include "Configuration/UnityConfigure.h" +#include "D3D11Includes.h" + + +#if ENABLE_DX11_DEBUGGING +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "D3D11VBO.h" + + +static bool s_DX11LoggingEnabled = true; +static UInt32 s_DX11CommandCount = 0; +static UInt32 s_Indentation = 0; +static DbgFrameDebugType s_FrameDebugType = kFrameDebugOutputDX11Commands; +//static DbgFrameDebugType s_FrameDebugType = kFrameDebugOutputNone; +static bool s_BreakpointReached = FALSE; + + +void DbgDX11DisableLogging() +{ + s_DX11LoggingEnabled = false; +} +void DbgDX11EnableLogging() +{ + s_DX11LoggingEnabled = true; +} +void DbgDX11LogOutput(const char* format,...) +{ + if (!s_DX11LoggingEnabled || s_FrameDebugType == kFrameDebugOutputNone) return; + + va_list va; + va_start (va, format); + char buffer [1024 * 10]; + vsnprintf (buffer, sizeof(buffer), format, va); + va_end (va); + printf_console("%*s[%d]%s\n", s_Indentation, "", ++s_DX11CommandCount, buffer); + +} + +void DbgDX11IncreaseIndentation() +{ + s_Indentation++; +} +void DbgDX11DecreaseIndentation() +{ + s_Indentation--; +} +void DbgDX11PostOperation() +{ + if (!s_DX11LoggingEnabled) return; +} +void DbgDX11MarkDrawing(UInt32 triCount, UInt32 vertexCount) +{ + if (s_FrameDebugType != kFrameDebugOutputDX11CommandsWithStepping) return; + + printf_console("Submitted draw call, triangle count: %d, vertex count: %d\n", triCount, vertexCount); + printf_console("------------------------------------------------------------------------------------------------\n"); + DbgDX11ShowCurrentGfxState(); + printf_console("------------------------------------------------------------------------------------------------\n"); + + /* + RenderColorSurfaceWiiU* colorSurface = InternalGetActiveRenderColorSurfaceWiiU(0); + if (colorSurface != NULL) + { + DX11SwapBuffers(&colorSurface->colorBuffer); + } + else + { + DX11SwapBuffers(cafe::GetColorBuffer()); + } +// DX11_CHK (DX11SwapBuffers(&s_ColorBuffer)); + + cafe::SetContextState(); + + DX11_CHK (DX11Flush()); + printf_console("A - Contine, B - Cancel, + - Capture screenshot\n"); + + bool done = false; + + while (!done) + { + + switch (cafe::DbgWaitForKey()) + { + case KPAD_BUTTON_A: + done = true; + break; + case KPAD_BUTTON_B: + DbgDX11SetFrameDebug(kFrameDebugOutputNone); + break; + case KPAD_BUTTON_PLUS: + cafe::DbgCaptureScreenshot(); + break; + default: + #if ENABLE_DX11_METRICS + DbgDX11SetBreakpoint(); + DX11ClearGPMetric(); + #endif + break; + } + } + */ +} +void DbgDX11SetFrameDebug(DbgFrameDebugType type) +{ + s_DX11CommandCount = 0; + + switch (s_FrameDebugType) + { + case kFrameDebugOutputDX11CommandsWithStepping: + break; + } + + s_FrameDebugType = type; + + switch (s_FrameDebugType) + { + case kFrameDebugOutputDX11CommandsWithStepping: + break; + } +} + +void DbgDX11MarkFrameBegin() +{ + switch (s_FrameDebugType) + { + case kFrameDebugOutputDX11CommandsWithStepping: + break; + } +} +void DbgDX11MarkFrameEnd() +{ + DbgDX11SetFrameDebug(kFrameDebugOutputNone); +} + + +const char* DbgDX11GetShaderChannelName(ShaderChannel channel) +{ + const char* kShaderChannelStrings[kShaderChannelCount] = { + "kShaderChannelVertex", + "kShaderChannelNormal", + "kShaderChannelColor", + "kShaderChannelTexCoord0", + "kShaderChannelTexCoord1", + "kShaderChannelTangent" + }; + return kShaderChannelStrings[channel]; +} +const char* DbgDX11GetVertexComponentName(VertexComponent comp) +{ + const char* kVertexComponentStrings[kVertexCompCount] = { + "kVertexCompVertex", + "kVertexCompColor", + "kVertexCompNormal", + "kVertexCompTexCoord", + "kVertexCompTexCoord0", "kVertexCompTexCoord1", "kVertexCompTexCoord2", "kVertexCompTexCoord3", + "kVertexCompTexCoord4", "kVertexCompTexCoord5", "kVertexCompTexCoord6", "kVertexCompTexCoord7", + "kVertexCompAttrib0", "kVertexCompAttrib1", "kVertexCompAttrib2", "kVertexCompAttrib3", + "kVertexCompAttrib4", "kVertexCompAttrib5", "kVertexCompAttrib6", "kVertexCompAttrib7", + "kVertexCompAttrib8", "kVertexCompAttrib9", "kVertexCompAttrib10", "kVertexCompAttrib11", + "kVertexCompAttrib12", "kVertexCompAttrib13", "kVertexCompAttrib14", "kVertexCompAttrib15" + }; + return kVertexComponentStrings[comp]; +} +void DbgDX11ShowChannelBindings(const ChannelAssigns& channels, VertexBufferData& data) +{ + /* + DX11_LOG_OUTPUT("VBO layout, VertexStride: %d", data.vertexStride); + for (int i = 0; i < kShaderChannelCount; i++) + { + DX11_LOG_OUTPUT(" [%d] - 0x%08x, Stride: %d (%s)", i, data.channel[i], data.channelStrides[i], DbgDX11GetShaderChannelName((ShaderChannel)i)); + } + for (int i = kVertexCompVertex; i < kVertexCompCount; i++) + { + ShaderChannel sh = channels.GetSourceForTarget((VertexComponent)i); + if (sh != kShaderChannelNone) + { + DX11_LOG_OUTPUT(" Vertex component %d targets %s", i, DbgDX11GetShaderChannelName((ShaderChannel)sh)); + } + } + */ +} +void DbgDX11ShowStridedVertexData(const VertexBufferData& data, void* rawData) +{ + /* + DX11_LOG_OUTPUT("VBO has %d vertices with stride %d", data.vertexCount, data.vertexStride); + + UInt8* p = (UInt8*) rawData; + + int offset[kShaderChannelCount]; + int curOffset = 0; + for (int i = 0; i < kShaderChannelCount; i++) + { + if (data.channel[i] == NULL) offset[i] = -1; + else + { + offset[i] = curOffset; + curOffset += VBO::GetChannelByteSize(i); + } + } + Assert (VBO::GetChannelByteSize(kShaderChannelVertex) == sizeof(Vector3f)); + Assert (VBO::GetChannelByteSize(kShaderChannelNormal) == sizeof(Vector3f)); + Assert (VBO::GetChannelByteSize(kShaderChannelColor) == sizeof(ColorRGBA32)); + Assert (VBO::GetChannelByteSize(kShaderChannelTexCoord0) == sizeof(Vector2f)); + Assert (VBO::GetChannelByteSize(kShaderChannelTexCoord1) == sizeof(Vector2f)); + Assert (VBO::GetChannelByteSize(kShaderChannelTangent) == sizeof(Vector4f)); + for (int i = 0; i < data.vertexCount; i++) + { + if (offset[kShaderChannelVertex] != -1) + { + Vector3f v = *(Vector3f*)(p + offset[kShaderChannelVertex] + i * data.vertexStride); + DX11_LOG_OUTPUT("[%d - Vertex] - %.2f %.2f %.2f", i, v.x, v.y, v.z); + } + + if (offset[kShaderChannelNormal] != -1) + { + Vector3f n = *(Vector3f*)(p + offset[kShaderChannelNormal] + i * data.vertexStride); + DX11_LOG_OUTPUT("[%d - Normal] - %.2f %.2f %.2f", i, n.x, n.y, n.z); + } + if (offset[kShaderChannelColor] != -1) + { + ColorRGBA32 c = *(ColorRGBA32*)(p + offset[kShaderChannelColor] + i * data.vertexStride); + DX11_LOG_OUTPUT("[%d - Color] - %d %d %d %d", i, c.r, c.g, c.b, c.a); + } + if (offset[kShaderChannelTexCoord0] != -1) + { + Vector2f uv = *(Vector2f*)(p + offset[kShaderChannelTexCoord0] + i * data.vertexStride); + DX11_LOG_OUTPUT("[%d - UV0] - %.2f %.2f", i, uv.x, uv.x, uv.y); + } + if (offset[kShaderChannelTexCoord1] != -1) + { + Vector2f uv = *(Vector2f*)(p + offset[kShaderChannelTexCoord1] + i * data.vertexStride); + DX11_LOG_OUTPUT("[%d - UV1] - %.2f %.2f", i, uv.x, uv.x, uv.y); + } + if (offset[kShaderChannelTangent] != -1) + { + Vector4f t = *(Vector4f*)(p + offset[kShaderChannelTangent] + i * data.vertexStride); + DX11_LOG_OUTPUT("[%d - Tangent] - %.2f %.2f %.2f %.2f", i, t.x, t.y, t.z, t.w); + } + } + */ + FatalErrorMsg("Stop"); +} +void DbgDX11ShowStridedIndexData(const IndexBufferData& data, void* rawData) +{ + /* + DX11_LOG_OUTPUT("VBO has %d indices with stride %d", data.count, data.stride); + UInt8* p = (UInt8*) rawData; + for (int i = 0; i < data.count; i++) + { + Assert (data.stride == sizeof(UInt16)); + DX11_LOG_OUTPUT("[%d] - %d", i, *(UInt16*)(p + data.stride * i)); + } + */ + FatalErrorMsg("Stop"); +} + + + +void DbgDX11ShowCurrentGfxState() +{ + /* + const DeviceStateWiiU& state = GetWiiUDeviceState(GetGfxDevice()); + + int blendingEnabled = state.currBlendState->blendingEnabled; + DbgDX11ShowColorControlReg(state.colorControlReg, blendingEnabled); + if (blendingEnabled > 0) + { + DbgDX11ShowBlendControlReg(state.blendControlReg); + } + + DbgDX11ShowTargetChannelMaskReg(state.targetChannelMaskReg); + DbgDX11ShowAlphaTestReg(state.alphaTestReg); + DbgDX11ShowPolygonControlReg(state.polygonControlReg); + //DbgDX11ShowPolygonOffsetReg(state.polygonOffsetReg); + DbgDX11ShowDepthStencilControlReg(state.depthStencilReg); + */ +} + + +#endif diff --git a/Runtime/GfxDevice/d3d11/D3D11Debug.h b/Runtime/GfxDevice/d3d11/D3D11Debug.h new file mode 100644 index 0000000..1f57adf --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Debug.h @@ -0,0 +1,54 @@ +#pragma once + +#define ENABLE_DX11_DEBUGGING (!UNITY_RELEASE && UNITY_METRO) && 0 + +#if ENABLE_DX11_DEBUGGING + + enum DbgFrameDebugType + { + kFrameDebugOutputNone, + kFrameDebugOutputDX11Commands, + kFrameDebugOutputDX11CommandsWithStepping + }; + + void DbgDX11DisableLogging(); + void DbgDX11EnableLogging(); + void DbgDX11LogOutput(const char* format,...); + void DbgDX11IncreaseIndentation(); + void DbgDX11DecreaseIndentation(); + void DbgDX11MarkDrawing(UInt32 triCount, UInt32 vertexCount); + void DbgDX11MarkFrameBegin(); + void DbgDX11MarkFrameEnd(); + void DbgDX11ShowCurrentGfxState(); + + class DbgDX11AutoIndentation + { + public: + DbgDX11AutoIndentation() {DbgDX11IncreaseIndentation();} + ~DbgDX11AutoIndentation() {DbgDX11DecreaseIndentation();} + }; + + inline const char* GetDX11BoolString (bool val) {return val == true ? "true" : "false";} + + #define DX11_DISABLE_LOGGING() DbgDX11DisableLogging() + #define DX11_ENABLE_LOGGING() DbgDX11EnableLogging() + #define DX11_LOG_OUTPUT(...) DbgDX11LogOutput(__VA_ARGS__); + #define DX11_LOG_ENTER_FUNCTION(...) DbgDX11LogOutput(__VA_ARGS__); DbgDX11AutoIndentation sDbgDX11AutoIndentation; + #define DX11_MARK_DRAWING(TriCount, VertexCount) DbgDX11MarkDrawing(TriCount, VertexCount); + #define DX11_MARK_FRAME_BEGIN() DbgDX11MarkFrameBegin(); + #define DX11_MARK_FRAME_END() DbgDX11MarkFrameEnd(); + #define DX11_CHK(x) {DbgDX11LogOutput(#x); x; } + +#else + #define DX11_DISABLE_LOGGING() {} + #define DX11_ENABLE_LOGGING() {} + #define DX11_LOG_OUTPUT(...) {} + #define DX11_LOG_OUTPUT_MTX3x4(m) {} + #define DX11_LOG_OUTPUT_MTX4x4(m) {} + #define DX11_LOG_ENTER_FUNCTION(...) {} + #define DX11_MARK_FRAME_BEGIN() {} + #define DX11_MARK_FRAME_END() {} + #define DX11_CHK(x) x + #define DX11_MARK_DRAWING(TriCount, VertexCount) {} + #define DX11_SET_FRAME_DEBUG(Type) {} +#endif diff --git a/Runtime/GfxDevice/d3d11/D3D11Hash.cpp b/Runtime/GfxDevice/d3d11/D3D11Hash.cpp new file mode 100644 index 0000000..f4f692f --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Hash.cpp @@ -0,0 +1,326 @@ +// Original MD5 implementation put into public domain +// by Alexander Peslyak, see comment below. +// Modifications for D3D hash by Aras Pranckevicius, public domain. + +// D3D shader hash seems to be almost MD5, except small differences in +// the final step (MD5_Final in OpenSSL). Look for "CHANGE FROM MD5". + + +/* + * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. + * MD5 Message-Digest Algorithm (RFC 1321). + * + * Homepage: + * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 + * + * Author: + * Alexander Peslyak, better known as Solar Designer <solar at openwall.com> + * + * This software was written by Alexander Peslyak in 2001. No copyright is + * claimed, and the software is hereby placed in the public domain. + * In case this attempt to disclaim copyright and place the software in the + * public domain is deemed null and void, then the software is + * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * + * (This is a heavily cut-down "BSD license".) + * + * This differs from Colin Plumb's older public domain implementation in that + * no exactly 32-bit integer data type is required (any 32-bit or wider + * unsigned integer data type will do), there's no compile-time endianness + * configuration, and the function prototypes match OpenSSL's. No code from + * Colin Plumb's implementation has been reused; this comment merely compares + * the properties of the two independent implementations. + * + * The primary goals of this implementation are portability and ease of use. + * It is meant to be fast, but not as fast as possible. Some known + * optimizations are not included to reduce source code size and avoid + * compile-time configuration. + */ + +/* Any 32-bit or wider unsigned integer data type will do */ +typedef unsigned int MD5_u32plus; + +typedef struct { + MD5_u32plus a, b, c, d; + MD5_u32plus hi; + MD5_u32plus lo; // CHANGE FROM MD5: need to have "lo" go directly before the buffer + unsigned char buffer[64]; + MD5_u32plus block[16]; +} MD5_CTX; + +extern void MD5_Init(MD5_CTX *ctx); +extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size); +extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); + + +#include <string.h> + +/* + * The basic MD5 functions. + * + * F and G are optimized compared to their RFC 1321 definitions for + * architectures that lack an AND-NOT instruction, just like in Colin Plumb's + * implementation. + */ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | ~(z))) + +/* + * The MD5 transformation for all four rounds. + */ +#define STEP(f, a, b, c, d, x, t, s) \ + (a) += f((b), (c), (d)) + (x) + (t); \ + (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ + (a) += (b); + +/* + * SET reads 4 input bytes in little-endian byte order and stores them + * in a properly aligned word in host byte order. + * + * The check for little-endian architectures that tolerate unaligned + * memory accesses is just an optimization. Nothing will break if it + * doesn't work. + */ +#if defined(__i386__) || defined(__x86_64__) || defined(__vax__) || defined(_MSC_VER) +#define SET(n) \ + (*(MD5_u32plus *)&ptr[(n) * 4]) +#define GET(n) \ + SET(n) +#else +#define SET(n) \ + (ctx->block[(n)] = \ + (MD5_u32plus)ptr[(n) * 4] | \ + ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ + ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ + ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) +#define GET(n) \ + (ctx->block[(n)]) +#endif + +/* + * This processes one or more 64-byte data blocks, but does NOT update + * the bit counters. There are no alignment requirements. + */ +static void *body(MD5_CTX *ctx, void *data, unsigned long size) +{ + unsigned char *ptr; + MD5_u32plus a, b, c, d; + MD5_u32plus saved_a, saved_b, saved_c, saved_d; + + ptr = (unsigned char*)data; + + a = ctx->a; + b = ctx->b; + c = ctx->c; + d = ctx->d; + + do { + saved_a = a; + saved_b = b; + saved_c = c; + saved_d = d; + +/* Round 1 */ + STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) + STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12) + STEP(F, c, d, a, b, SET(2), 0x242070db, 17) + STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22) + STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7) + STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12) + STEP(F, c, d, a, b, SET(6), 0xa8304613, 17) + STEP(F, b, c, d, a, SET(7), 0xfd469501, 22) + STEP(F, a, b, c, d, SET(8), 0x698098d8, 7) + STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12) + STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17) + STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22) + STEP(F, a, b, c, d, SET(12), 0x6b901122, 7) + STEP(F, d, a, b, c, SET(13), 0xfd987193, 12) + STEP(F, c, d, a, b, SET(14), 0xa679438e, 17) + STEP(F, b, c, d, a, SET(15), 0x49b40821, 22) + +/* Round 2 */ + STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5) + STEP(G, d, a, b, c, GET(6), 0xc040b340, 9) + STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14) + STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20) + STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5) + STEP(G, d, a, b, c, GET(10), 0x02441453, 9) + STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14) + STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20) + STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5) + STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9) + STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14) + STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20) + STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5) + STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9) + STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14) + STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20) + +/* Round 3 */ + STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4) + STEP(H, d, a, b, c, GET(8), 0x8771f681, 11) + STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16) + STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23) + STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4) + STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11) + STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16) + STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23) + STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4) + STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11) + STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16) + STEP(H, b, c, d, a, GET(6), 0x04881d05, 23) + STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4) + STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11) + STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16) + STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23) + +/* Round 4 */ + STEP(I, a, b, c, d, GET(0), 0xf4292244, 6) + STEP(I, d, a, b, c, GET(7), 0x432aff97, 10) + STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15) + STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21) + STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6) + STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10) + STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15) + STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21) + STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6) + STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10) + STEP(I, c, d, a, b, GET(6), 0xa3014314, 15) + STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21) + STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6) + STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10) + STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15) + STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21) + + a += saved_a; + b += saved_b; + c += saved_c; + d += saved_d; + + ptr += 64; + } while (size -= 64); + + ctx->a = a; + ctx->b = b; + ctx->c = c; + ctx->d = d; + + return ptr; +} + +void MD5_Init(MD5_CTX *ctx) +{ + ctx->a = 0x67452301; + ctx->b = 0xefcdab89; + ctx->c = 0x98badcfe; + ctx->d = 0x10325476; + + ctx->lo = 0; + ctx->hi = 0; +} + +void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size) +{ + MD5_u32plus saved_lo; + unsigned long used, free; + + saved_lo = ctx->lo; + if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) + ctx->hi++; + ctx->hi += size >> 29; + + used = saved_lo & 0x3f; + + if (used) { + free = 64 - used; + + if (size < free) { + memcpy(&ctx->buffer[used], data, size); + return; + } + + memcpy(&ctx->buffer[used], data, free); + data = (unsigned char *)data + free; + size -= free; + body(ctx, ctx->buffer, 64); + } + + if (size >= 64) { + data = body(ctx, data, size & ~(unsigned long)0x3f); + size &= 0x3f; + } + + memcpy(ctx->buffer, data, size); +} + +void MD5_Final(unsigned char *result, MD5_CTX *ctx) +{ + unsigned long used, free; + + used = ctx->lo & 0x3f; + + ctx->buffer[used++] = 0x80; + + free = 64 - used; + + if (free < 8) { + memset(&ctx->buffer[used], 0, free); + body(ctx, ctx->buffer, 64); + used = 0; + free = 64; + } + + memset(&ctx->buffer[used], 0, free - 8); + + // CHANGE FROM MD5: put lo*2|1 instead of ctx->lo at buffer[56] + MD5_u32plus lo2 = ctx->lo * 2 | 1; + ctx->lo <<= 3; + ctx->buffer[56] = lo2; + ctx->buffer[57] = lo2 >> 8; + ctx->buffer[58] = lo2 >> 16; + ctx->buffer[59] = lo2 >> 24; + ctx->buffer[60] = ctx->hi; + ctx->buffer[61] = ctx->hi >> 8; + ctx->buffer[62] = ctx->hi >> 16; + ctx->buffer[63] = ctx->hi >> 24; + + // CHANGE FROM MD5: pass buffer-4 (that contains lo) + // instead of buffer. Essentially the buffer is shifted by 4 bytes + body(ctx, &ctx->lo, 64); + + result[0] = ctx->a; + result[1] = ctx->a >> 8; + result[2] = ctx->a >> 16; + result[3] = ctx->a >> 24; + result[4] = ctx->b; + result[5] = ctx->b >> 8; + result[6] = ctx->b >> 16; + result[7] = ctx->b >> 24; + result[8] = ctx->c; + result[9] = ctx->c >> 8; + result[10] = ctx->c >> 16; + result[11] = ctx->c >> 24; + result[12] = ctx->d; + result[13] = ctx->d >> 8; + result[14] = ctx->d >> 16; + result[15] = ctx->d >> 24; + + memset(ctx, 0, sizeof(*ctx)); +} + + +void D3DHash (const unsigned char* data, unsigned size, unsigned char res[16]) +{ + MD5_CTX ctx; + MD5_Init (&ctx); + MD5_Update (&ctx, (void*)data, size); + MD5_Final (res, &ctx); +} diff --git a/Runtime/GfxDevice/d3d11/D3D11Includes.h b/Runtime/GfxDevice/d3d11/D3D11Includes.h new file mode 100644 index 0000000..7629ef7 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Includes.h @@ -0,0 +1,49 @@ +#pragma once + + +#if UNITY_WP8 + +#include <initguid.h> + +#include <dxgi1_2.h> +#include <d3d11_1.h> + +typedef struct _D3D11_SIGNATURE_PARAMETER_DESC +{ + LPCSTR SemanticName; // Name of the semantic + UINT SemanticIndex; // Index of the semantic + UINT Register; // Number of member variables + D3D_NAME SystemValueType;// A predefined system value, or D3D_NAME_UNDEFINED if not applicable + D3D_REGISTER_COMPONENT_TYPE ComponentType; // Scalar type (e.g. uint, float, etc.) + BYTE Mask; // Mask to indicate which components of the register + // are used (combination of D3D10_COMPONENT_MASK values) + BYTE ReadWriteMask; // Mask to indicate whether a given component is + // never written (if this is an output signature) or + // always read (if this is an input signature). + // (combination of D3D10_COMPONENT_MASK values) + UINT Stream; // Stream index + D3D_MIN_PRECISION MinPrecision; // Minimum desired interpolation precision +} D3D11_SIGNATURE_PARAMETER_DESC; + +#elif UNITY_METRO + +#include <dxgi1_2.h> +#include <d3d11_1.h> +#if UNITY_METRO_VS2013 +#include <d3d11_2.h> +#endif +#include <d3d11shader.h> + +#else + +#include "External/DirectX/builds/dx11include/DXGI.h" +#include "External/DirectX/builds/dx11include/D3D11.h" +#include "External/DirectX/builds/dx11include/d3d11_1.h" +#include "External/DirectX/builds/dx11include/D3D11Shader.h" + +#define D3D_NAME D3D10_NAME +#define D3D_REGISTER_COMPONENT_TYPE D3D10_REGISTER_COMPONENT_TYPE + +#endif + +#include "D3D11Debug.h" diff --git a/Runtime/GfxDevice/d3d11/D3D11Utils.cpp b/Runtime/GfxDevice/d3d11/D3D11Utils.cpp new file mode 100644 index 0000000..55535f3 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Utils.cpp @@ -0,0 +1,85 @@ +#include "UnityPrefix.h" +#include "D3D11Utils.h" + + +#ifdef DUMMY_D3D11_CALLS +HRESULT CallDummyD3D11Function() +{ + return S_OK; +} +#endif + +void ReportLiveObjectsD3D11 (ID3D11Device* dev) +{ + ID3D11Debug* dbg = NULL; + if (FAILED(dev->QueryInterface(IID_ID3D11Debug, (void**)&dbg))) + return; + if (!dbg) + return; + + dbg->ReportLiveDeviceObjects (D3D11_RLDO_DETAIL); + dbg->Release(); +} + + +void SetDebugNameD3D11 (ID3D11DeviceChild* obj, const std::string& name) +{ + if (obj) + obj->SetPrivateData (WKPDID_D3DDebugObjectName, name.size(), name.c_str()); +} + +std::string GetDebugNameD3D11 (ID3D11DeviceChild* obj) +{ + if (obj) + { + char tmp[1024]; + int maxLength = sizeof(tmp) - 1; + UINT size = maxLength; + obj->GetPrivateData (WKPDID_D3DDebugObjectName, &size, tmp); + tmp[size] = '\0'; + tmp[maxLength] = '\0'; + return tmp; + } + return ""; +} + + + +int GetBPPFromDXGIFormat (DXGI_FORMAT fmt) +{ + if (fmt == DXGI_FORMAT_UNKNOWN) + return 0; + if (fmt >= DXGI_FORMAT_R32G32B32A32_TYPELESS && fmt <= DXGI_FORMAT_R32G32B32A32_SINT) + return 128; + if (fmt >= DXGI_FORMAT_R32G32B32_TYPELESS && fmt <= DXGI_FORMAT_R32G32B32_SINT) + return 96; + if (fmt >= DXGI_FORMAT_R16G16B16A16_TYPELESS && fmt <= DXGI_FORMAT_X32_TYPELESS_G8X24_UINT) + return 64; + if (fmt >= DXGI_FORMAT_R10G10B10A2_TYPELESS && fmt <= DXGI_FORMAT_X24_TYPELESS_G8_UINT) + return 32; + if (fmt >= DXGI_FORMAT_R8G8_TYPELESS && fmt <= DXGI_FORMAT_R16_SINT) + return 16; + if (fmt >= DXGI_FORMAT_R8_TYPELESS && fmt <= DXGI_FORMAT_A8_UNORM) + return 8; + if (fmt == DXGI_FORMAT_R1_UNORM) + return 1; + if (fmt >= DXGI_FORMAT_R9G9B9E5_SHAREDEXP && fmt <= DXGI_FORMAT_G8R8_G8B8_UNORM) + return 32; + if (fmt >= DXGI_FORMAT_BC1_TYPELESS && fmt <= DXGI_FORMAT_BC1_UNORM_SRGB) // DXT1 + return 4; + if (fmt >= DXGI_FORMAT_BC2_TYPELESS && fmt <= DXGI_FORMAT_BC3_UNORM_SRGB) // DXT3/5 + return 8; + if (fmt >= DXGI_FORMAT_BC4_TYPELESS && fmt <= DXGI_FORMAT_BC4_SNORM) + return 4; + if (fmt >= DXGI_FORMAT_BC5_TYPELESS && fmt <= DXGI_FORMAT_BC5_SNORM) + return 8; + if (fmt >= DXGI_FORMAT_B5G6R5_UNORM && fmt <= DXGI_FORMAT_B5G5R5A1_UNORM) + return 16; + if (fmt >= DXGI_FORMAT_B8G8R8A8_UNORM && fmt <= DXGI_FORMAT_B8G8R8X8_UNORM_SRGB) + return 32; + if (fmt >= DXGI_FORMAT_BC6H_TYPELESS && fmt <= DXGI_FORMAT_BC7_UNORM_SRGB) + return 8; + AssertString ("Unknown DXGI format"); + return 0; +} + diff --git a/Runtime/GfxDevice/d3d11/D3D11Utils.h b/Runtime/GfxDevice/d3d11/D3D11Utils.h new file mode 100644 index 0000000..69c5f44 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Utils.h @@ -0,0 +1,20 @@ +#pragma once + +#include "D3D11Includes.h" + +//#define DUMMY_D3D11_CALLS + +#ifndef DUMMY_D3D11_CALLS +#define D3D11_CALL(x) x +#define D3D11_CALL_HR(x) x +#else +HRESULT CallDummyD3D11Function(); +#define D3D11_CALL(x) CallDummyD3D11Function() +#define D3D11_CALL_HR(x) CallDummyD3D11Function() +#endif + +int GetBPPFromDXGIFormat (DXGI_FORMAT fmt); +void ReportLiveObjectsD3D11 (ID3D11Device* dev); +void SetDebugNameD3D11 (ID3D11DeviceChild* obj, const std::string& name); +std::string GetDebugNameD3D11 (ID3D11DeviceChild* obj); + diff --git a/Runtime/GfxDevice/d3d11/D3D11VBO.cpp b/Runtime/GfxDevice/d3d11/D3D11VBO.cpp new file mode 100644 index 0000000..e0beaf1 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11VBO.cpp @@ -0,0 +1,1193 @@ +#include "UnityPrefix.h" +#include "D3D11VBO.h" +#include "D3D11Context.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Graphics/TriStripper.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "D3D11Utils.h" + + + +// defined in GfxDeviceD3D11.cpp +ID3D11InputLayout* GetD3D11VertexDeclaration (const ChannelInfoArray& channels); +void UpdateChannelBindingsD3D11 (const ChannelAssigns& channels); + +ID3D11InputLayout* g_ActiveInputLayoutD3D11; +D3D11_PRIMITIVE_TOPOLOGY g_ActiveTopologyD3D11 = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; + + + +static const D3D11_PRIMITIVE_TOPOLOGY kTopologyD3D11[kPrimitiveTypeCount] = +{ + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + D3D11_PRIMITIVE_TOPOLOGY_LINELIST, + D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, + D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, +}; + +static const D3D11_PRIMITIVE_TOPOLOGY kTopologyD3D11Tess[kPrimitiveTypeCount] = +{ + D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, + D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, + D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST, +}; + + +void SetInputLayoutD3D11 (ID3D11DeviceContext* ctx, ID3D11InputLayout* layout) +{ + if (g_ActiveInputLayoutD3D11 != layout) + { + g_ActiveInputLayoutD3D11 = layout; + D3D11_CALL (ctx->IASetInputLayout (layout)); + } +} + + +static ID3D11InputLayout* GetD3D11VertexDeclaration (UInt32 shaderChannelsMap) +{ + ChannelInfoArray channels; + int offset = 0; + for (int i = 0; i < kShaderChannelCount; i++) + { + ChannelInfo& info = channels[i]; + if (shaderChannelsMap & (1 << i)) + { + info.stream = 0; + info.offset = offset; + info.format = VBO::GetDefaultChannelFormat( i ); + info.dimension = VBO::GetDefaultChannelDimension( i ); + offset += VBO::GetDefaultChannelByteSize( i ); + } + else + info.Reset(); + } + return GetD3D11VertexDeclaration (channels); +} + + +// ----------------------------------------------------------------------------- + +ID3D11Buffer* D3D11VBO::ms_CustomIB = NULL; +int D3D11VBO::ms_CustomIBSize = 0; +UInt32 D3D11VBO::ms_CustomIBUsedBytes = 0; + +ID3D11Buffer* D3D11VBO::ms_AllWhiteBuffer = NULL; + + +D3D11VBO::D3D11VBO() +: m_IB(NULL) +, m_StagingIB(NULL) +, m_IBReadable(NULL) +, m_IBSize(0) +, m_useForSO(false) +{ + memset(m_VBStreams, 0, sizeof(m_VBStreams)); + memset(m_StagingVB, 0, sizeof(m_StagingVB)); +} + +D3D11VBO::~D3D11VBO () +{ + for (int s = 0; s < kMaxVertexStreams; ++s) + { + //std::string tmp = GetDebugNameD3D11(m_StagingVB[s]); + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VBStreams[s]); + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_StagingVB[s]); + SAFE_RELEASE(m_VBStreams[s]); + SAFE_RELEASE(m_StagingVB[s]); + } + if (m_IB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + SAFE_RELEASE(m_IB); + } + if (m_StagingIB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_StagingIB); + SAFE_RELEASE(m_StagingIB); + } + delete[] m_IBReadable; +} + + +static ID3D11Buffer* CreateStagingBuffer (int size) +{ + ID3D11Device* dev = GetD3D11Device(); + D3D11_BUFFER_DESC desc; + desc.ByteWidth = size; + desc.Usage = D3D11_USAGE_STAGING; + desc.BindFlags = 0; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + + ID3D11Buffer* buffer = NULL; + HRESULT hr = dev->CreateBuffer (&desc, NULL, &buffer); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(buffer,size,NULL); + AssertIf (FAILED(hr)); + return buffer; +} + +void D3D11VBO::CleanupSharedBuffers() +{ + REGISTER_EXTERNAL_GFX_DEALLOCATION(ms_CustomIB); + REGISTER_EXTERNAL_GFX_DEALLOCATION(ms_AllWhiteBuffer); + SAFE_RELEASE (ms_CustomIB); + SAFE_RELEASE (ms_AllWhiteBuffer); + ms_CustomIBSize = 0; + ms_CustomIBUsedBytes = 0; +} + + +void D3D11VBO::UpdateVertexStream (const VertexBufferData& sourceData, unsigned stream) +{ + DebugAssert (!m_IsStreamMapped[stream]); + const StreamInfo& srcStream = sourceData.streams[stream]; + const int oldSize = CalculateVertexStreamSize(m_Streams[stream], m_VertexCount); + +#if UNITY_METRO + #pragma message("Fix ugly hack CreateStagingBuffer") + // So honestly I don't how what's happening here, but when running on ARM (Surface) with Feature Level 9.1 and if we create a vertex buffer with size 144 + // Sometimes we crash in D3D11VBO dtor in this line SAFE_RELEASE(m_StagingVB[s]); + // Sometimes we get an access violation but sometimes it's Data misalignment exception like below + // First-chance exception at 0x75499B2A (setupapi.dll) in Drift Mania Championship 2.exe: 0x80000002: Datatype misalignment + // Repro case 495782 + // Not reproducible on Win32 running Feature Level 9.1 + + // In any case it seems increasing min size up to 256, solves this issue for now + int newSize = CalculateVertexStreamSize(srcStream, sourceData.vertexCount); + int addon = 1; + while (newSize > 0 && newSize < 256) + { + newSize = CalculateVertexStreamSize(srcStream, sourceData.vertexCount + addon); + addon++; + } + +#else + const int newSize = CalculateVertexStreamSize(srcStream, sourceData.vertexCount); +#endif + + + m_Streams[stream] = srcStream; + if (newSize == 0) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VBStreams[stream]); + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_StagingVB[stream]); + SAFE_RELEASE (m_VBStreams[stream]); + SAFE_RELEASE (m_StagingVB[stream]); + return; + } + + const bool isDynamic = (m_StreamModes[stream] == kStreamModeDynamic); + const bool useStaging = !isDynamic; + + if (m_VBStreams[stream] == NULL || newSize != oldSize) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VBStreams[stream]); + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_StagingVB[stream]); + SAFE_RELEASE (m_VBStreams[stream]); + SAFE_RELEASE (m_StagingVB[stream]); // release staging VB as well here + + ID3D11Device* dev = GetD3D11Device(); + D3D11_BUFFER_DESC desc; + desc.ByteWidth = newSize; + desc.Usage = isDynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + if ( m_useForSO ) + desc.BindFlags |= D3D11_BIND_STREAM_OUTPUT; + desc.CPUAccessFlags = isDynamic ? D3D11_CPU_ACCESS_WRITE : 0; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + HRESULT hr = dev->CreateBuffer (&desc, NULL, &m_VBStreams[stream]); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_VBStreams[stream],newSize,this); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to create vertex buffer of size %d [0x%X]\n", newSize, hr); + return; + } + SetDebugNameD3D11 (m_VBStreams[stream], Format("VertexBuffer-%d", newSize)); + + if (useStaging) + { + m_StagingVB[stream] = CreateStagingBuffer (newSize); + SetDebugNameD3D11 (m_StagingVB[stream], Format("StagingVertexBuffer-%d", newSize)); + } + } + + // Don't update contents if there is no source data. + // This is used to update the vertex declaration only, leaving buffer intact. + // Also to create an empty buffer that is written to later. + if (!sourceData.buffer) + return; + + HRESULT hr; + + ID3D11Buffer* mapVB = NULL; + D3D11_MAP mapType; + + if (useStaging) + { + mapVB = m_StagingVB[stream]; + mapType = D3D11_MAP_WRITE; + } + else + { + mapVB = m_VBStreams[stream]; + mapType = D3D11_MAP_WRITE_DISCARD; + } + + Assert (mapVB); + + ID3D11DeviceContext* ctx = GetD3D11Context(); + + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (mapVB, 0, mapType, 0, &mapped); + Assert (SUCCEEDED(hr)); + CopyVertexStream (sourceData, reinterpret_cast<UInt8*>(mapped.pData), stream); + ctx->Unmap (mapVB, 0); + + if (useStaging) + ctx->CopyResource (m_VBStreams[stream], m_StagingVB[stream]); +} + + +void D3D11VBO::UpdateIndexBufferData (const IndexBufferData& sourceData) +{ + if( !sourceData.indices ) + { + m_IBSize = 0; + return; + } + + Assert (m_IB); + HRESULT hr; + + int size = sourceData.count * kVBOIndexSize; + if (sourceData.hasTopologies & ((1<<kPrimitiveTriangleStripDeprecated) | (1<<kPrimitiveQuads))) + { + delete[] m_IBReadable; + m_IBReadable = new UInt16[sourceData.count]; + memcpy (m_IBReadable, sourceData.indices, size); + } + + const D3D11_MAP mapType = m_IndicesDynamic ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE; + ID3D11Buffer* mapIB; + if (m_IndicesDynamic) + mapIB = m_IB; + else + { + if (!m_StagingIB) + m_StagingIB = CreateStagingBuffer(m_IBSize); + mapIB = m_StagingIB; + } + + ID3D11DeviceContext* ctx = GetD3D11Context(); + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (mapIB, 0, mapType, 0, &mapped); + Assert (SUCCEEDED(hr)); + + memcpy (mapped.pData, sourceData.indices, size); + + ctx->Unmap (mapIB, 0); + if (!m_IndicesDynamic) + ctx->CopyResource (m_IB, m_StagingIB); +} + +bool D3D11VBO::MapVertexStream( VertexStreamData& outData, unsigned stream ) +{ + if (m_VBStreams[stream] == NULL) + { + printf_console ("d3d11: attempt to map null vertex buffer\n"); + return false; + } + DebugAssert(!IsVertexBufferLost()); + Assert(!m_IsStreamMapped[stream]); + + const int vbSize = CalculateVertexStreamSize(m_Streams[stream], m_VertexCount); + + const bool dynamic = (m_StreamModes[stream]==kStreamModeDynamic); + + D3D11_MAPPED_SUBRESOURCE mapped; + ID3D11Buffer* mapVB = dynamic ? m_VBStreams[stream] : m_StagingVB[stream]; + D3D11_MAP mapType = dynamic ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE; + HRESULT hr = GetD3D11Context()->Map (mapVB, 0, mapType, 0, &mapped); + if( FAILED(hr) ) + { + printf_console ("d3d11: failed to map vertex buffer %p of size %i [%x]\n", mapVB, vbSize, hr); + return false; + } + m_IsStreamMapped[stream] = true; + + UInt8* buffer = (UInt8*)mapped.pData; + + outData.buffer = buffer; + outData.channelMask = m_Streams[stream].channelMask; + outData.stride = m_Streams[stream].stride; + outData.vertexCount = m_VertexCount; + + GetRealGfxDevice().GetFrameStats().AddUploadVBO(vbSize); + + return true; +} + +void D3D11VBO::UnmapVertexStream (unsigned stream) +{ + DebugAssert(m_VBStreams[stream]); + Assert(m_IsStreamMapped[stream]); + m_IsStreamMapped[stream] = false; + ID3D11DeviceContext* ctx = GetD3D11Context(); + + const bool dynamic = (m_StreamModes[stream]==kStreamModeDynamic); + ID3D11Buffer* mapVB = dynamic ? m_VBStreams[stream] : m_StagingVB[stream]; + ctx->Unmap (mapVB, 0); + + if (!dynamic) + ctx->CopyResource (m_VBStreams[stream], m_StagingVB[stream]); +} + +bool D3D11VBO::IsVertexBufferLost() const +{ + for (int s = 0; s < kMaxVertexStreams; ++s) + if (m_Streams[s].channelMask && !m_VBStreams[s]) + return true; + return false; +} + +int D3D11VBO::GetRuntimeMemorySize() const +{ + int vertexSize = 0; + for( int s = 0; s < kMaxVertexStreams; s++ ) + vertexSize += m_Streams[s].stride; + return vertexSize * m_VertexCount + m_IBSize; +} + + +bool SetTopologyD3D11 (GfxPrimitiveType topology, GfxDevice& device, ID3D11DeviceContext* ctx) +{ + bool tessellation = device.IsShaderActive (kShaderHull) || device.IsShaderActive (kShaderDomain); + D3D11_PRIMITIVE_TOPOLOGY topod3d = tessellation ? kTopologyD3D11Tess[topology] : kTopologyD3D11[topology]; + if (topod3d == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED) + return false; + + if (topod3d != g_ActiveTopologyD3D11) + { + g_ActiveTopologyD3D11 = topod3d; + D3D11_CALL (ctx->IASetPrimitiveTopology (topod3d)); + } + return true; +} + + +ID3D11Buffer* D3D11VBO::GetAllWhiteBuffer() +{ + if (!ms_AllWhiteBuffer) + { + int maxVerts = 0x10000; + int size = maxVerts * sizeof(UInt32); + UInt8* data = new UInt8[size]; + memset (data, 0xFF, size); + + D3D11_BUFFER_DESC desc; + desc.ByteWidth = size; + desc.Usage = D3D11_USAGE_IMMUTABLE; + desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + D3D11_SUBRESOURCE_DATA sdata; + sdata.pSysMem = data; + sdata.SysMemPitch = 0; + sdata.SysMemSlicePitch = 0; + HRESULT hr = GetD3D11Device()->CreateBuffer (&desc, &sdata, &ms_AllWhiteBuffer); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(ms_AllWhiteBuffer,size,NULL); + delete[] data; + } + return ms_AllWhiteBuffer; +} + + +void D3D11VBO::BindVertexStreams(GfxDevice& device, ID3D11DeviceContext* ctx, const ChannelAssigns& channels) +{ + DX11_LOG_ENTER_FUNCTION("D3D11VBO::BindVertexStreams"); + int freeStream = -1; + for (int s = 0; s < kMaxVertexStreams; ++s) + { + if (m_VBStreams[s]) + { + UINT offset = 0; + UINT stride = m_Streams[s].stride; + D3D11_CALL (ctx->IASetVertexBuffers(s, 1, &m_VBStreams[s], &stride, &offset)); + } + else + freeStream = s; + } + + UpdateChannelBindingsD3D11(channels); + + device.BeforeDrawCall( false ); + + const ChannelInfoArray* channelInfo = &m_ChannelInfo; + if ((channels.GetSourceMap() & VERTEX_FORMAT1(Color)) && !m_ChannelInfo[kShaderChannelColor].IsValid()) + { + if (freeStream != -1) + { + static ChannelInfoArray colorChannelInfo; + memcpy(&colorChannelInfo, m_ChannelInfo, sizeof(colorChannelInfo)); + ChannelInfo& colorInfo = colorChannelInfo[kShaderChannelColor]; + colorInfo.stream = freeStream; + colorInfo.offset = 0; + colorInfo.format = kChannelFormatColor; + colorInfo.dimension = 1; + channelInfo = &colorChannelInfo; + ID3D11Buffer* whiteVB = GetAllWhiteBuffer(); + UINT stride = 4; + UINT offset = 0; + D3D11_CALL (ctx->IASetVertexBuffers(freeStream, 1, &whiteVB, &stride, &offset)); + } + else + ErrorString("Need a free stream to add default vertex colors!"); + } + ID3D11InputLayout* inputLayout = GetD3D11VertexDeclaration(m_ChannelInfo); + SetInputLayoutD3D11 (ctx, inputLayout); +} + +void D3D11VBO::BindToStreamOutput() +{ + const UINT offsets[] = { 0 }; + GetD3D11Context()->SOSetTargets(1, m_VBStreams, offsets); +} + +void D3D11VBO::UnbindFromStreamOutput() +{ + ID3D11Buffer* const buffers[] = { 0 }; + const UINT offsets[] = { 0 }; + GetD3D11Context()->SOSetTargets(1, buffers, offsets); +} + + +void D3D11VBO::DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount) +{ + DX11_LOG_ENTER_FUNCTION("D3D11VBO::DrawVBO"); + // just return if no indices + if( m_IBSize == 0 ) + return; + + Assert(!m_IsStreamMapped[0]); + if (m_VBStreams[0] == 0 || m_IB == 0) + { + printf_console( "d3d: VB or IB is null\n" ); + return; + } + + GfxDevice& device = GetRealGfxDevice(); + ID3D11DeviceContext* ctx = GetD3D11Context(); + BindVertexStreams (device, ctx, channels); + + bool tessellation = device.IsShaderActive (kShaderHull) || device.IsShaderActive (kShaderDomain); + if (tessellation && topology == kPrimitiveTriangleStripDeprecated) + { + if (!m_IBReadable) + return; + + const UInt16* ibSrc = (const UInt16*)((const UInt8*)m_IBReadable + firstIndexByte); + const int triCount = CountTrianglesInStrip (ibSrc, indexCount); + + UInt32 ibBytesLocked; + UInt16* ibPtr = MapDynamicIndexBuffer (triCount*3, ibBytesLocked); + if (!ibPtr) + return; + Destripify (ibSrc, indexCount, ibPtr, triCount*3); + UnmapDynamicIndexBuffer (); + firstIndexByte = ms_CustomIBUsedBytes; + ms_CustomIBUsedBytes += ibBytesLocked; + D3D11_CALL (ctx->IASetIndexBuffer (ms_CustomIB, DXGI_FORMAT_R16_UINT, 0)); + indexCount = ibBytesLocked/kVBOIndexSize; + topology = kPrimitiveTriangles; + } + else if (topology == kPrimitiveQuads && !tessellation) + { + if (!m_IBReadable) + return; + UInt32 ibBytesLocked; + UInt16* ibPtr = MapDynamicIndexBuffer (indexCount/4*6, ibBytesLocked); + if (!ibPtr) + return; + const UInt16* ibSrc = (const UInt16*)((const UInt8*)m_IBReadable + firstIndexByte); + FillIndexBufferForQuads (ibPtr, ibBytesLocked, ibSrc, indexCount/4); + UnmapDynamicIndexBuffer (); + firstIndexByte = ms_CustomIBUsedBytes; + ms_CustomIBUsedBytes += ibBytesLocked; + D3D11_CALL (ctx->IASetIndexBuffer (ms_CustomIB, DXGI_FORMAT_R16_UINT, 0)); + indexCount = ibBytesLocked/kVBOIndexSize; + } + else + { + D3D11_CALL (ctx->IASetIndexBuffer (m_IB, DXGI_FORMAT_R16_UINT, 0)); + } + + // draw + if (!SetTopologyD3D11 (topology, device, ctx)) + return; + D3D11_CALL (ctx->DrawIndexed (indexCount, firstIndexByte/2, 0)); + device.GetFrameStats().AddDrawCall (GetPrimitiveCount(indexCount,topology,false), vertexCount); + DX11_MARK_DRAWING(GetPrimitiveCount(indexCount,topology,false), vertexCount); + +} + +UInt16* D3D11VBO::MapDynamicIndexBuffer (int indexCount, UInt32& outBytesUsed) +{ + HRESULT hr; + const UInt32 maxIndices = 64000; + Assert (indexCount <= maxIndices); + indexCount = std::min<UInt32>(indexCount, maxIndices); + + int ibCapacity = indexCount * kVBOIndexSize; + int newIBSize = std::max (ibCapacity, 32*1024); // 32k IB at least + + if (newIBSize > ms_CustomIBSize) + { + if (ms_CustomIB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(ms_CustomIB); + ms_CustomIB->Release(); + } + ms_CustomIBSize = newIBSize; + ms_CustomIBUsedBytes = 0; + + ID3D11Device* dev = GetD3D11Device(); + + D3D11_BUFFER_DESC desc; + desc.ByteWidth = newIBSize; + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_INDEX_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + hr = dev->CreateBuffer (&desc, NULL, &ms_CustomIB); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(ms_CustomIB,newIBSize,NULL); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to create custom index buffer of size %d [%x]\n", newIBSize, hr); + return NULL; + } + SetDebugNameD3D11 (ms_CustomIB, Format("IndexBufferCustomDynamic-%d", newIBSize)); + } + + ID3D11DeviceContext* ctx = GetD3D11Context(); + D3D11_MAPPED_SUBRESOURCE mapped; + if (ms_CustomIBUsedBytes + ibCapacity > ms_CustomIBSize) + { + hr = ctx->Map (ms_CustomIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to lock shared index buffer with discard [%x]\n", hr); + return NULL; + } + ms_CustomIBUsedBytes = 0; + } + else + { + hr = ctx->Map (ms_CustomIB, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped); + if (FAILED(hr)) + { + printf_console( "d3d11: failed to lock shared index buffer, offset %i size %i [%x]\n", ms_CustomIBUsedBytes, ibCapacity, hr); + return NULL; + } + } + outBytesUsed = ibCapacity; + + return (UInt16*)((UInt8*)mapped.pData + ms_CustomIBUsedBytes); +} + +void D3D11VBO::UnmapDynamicIndexBuffer () +{ + GetD3D11Context()->Unmap (ms_CustomIB, 0); +} + + +#if GFX_ENABLE_DRAW_CALL_BATCHING +void D3D11VBO::DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ) +{ + HRESULT hr; + Assert (!m_IsStreamMapped[0]); + + if (m_VBStreams[0] == 0) + { + printf_console( "d3d11: VB is null\n" ); + return; + } + + ID3D11DeviceContext* ctx = GetD3D11Context(); + + UInt32 ibBytesUsed; + UInt16* ibPtr = MapDynamicIndexBuffer (indexCount, ibBytesUsed); + if (!ibPtr) + return; + memcpy (ibPtr, indices, ibBytesUsed); + UnmapDynamicIndexBuffer (); + + // draw + GfxDevice& device = GetRealGfxDevice(); + BindVertexStreams(device, ctx, channels); + + D3D11_CALL (ctx->IASetIndexBuffer (ms_CustomIB, DXGI_FORMAT_R16_UINT, 0)); + + // draw + if (!SetTopologyD3D11 (topology, device, ctx)) + return; + D3D11_CALL (ctx->DrawIndexed (indexCount, ms_CustomIBUsedBytes / kVBOIndexSize, 0)); + device.GetFrameStats().AddDrawCall (GetPrimitiveCount(indexCount,topology,false), drawVertexCount); + + ms_CustomIBUsedBytes += ibBytesUsed; +} + +#endif // GFX_ENABLE_DRAW_CALL_BATCHING + + + +void D3D11VBO::UpdateVertexData( const VertexBufferData& buffer ) +{ + for (unsigned stream = 0; stream < kMaxVertexStreams; stream++) + UpdateVertexStream (buffer, stream); + + memcpy (m_ChannelInfo, buffer.channels, sizeof(m_ChannelInfo)); + m_VertexCount = buffer.vertexCount; +} + +void D3D11VBO::UpdateIndexData (const IndexBufferData& buffer) +{ + int newSize = CalculateIndexBufferSize(buffer); + + // If we have old buffer, but need different size: delete old one + if (newSize != m_IBSize) + { + if (m_IB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + SAFE_RELEASE(m_IB); + } + if (m_StagingIB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_StagingIB); + SAFE_RELEASE(m_StagingIB); + } + } + + // Create buffer if we need to + if (!m_IB) + { + ID3D11Device* dev = GetD3D11Device(); + D3D11_BUFFER_DESC desc; + desc.ByteWidth = newSize; + desc.Usage = m_IndicesDynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_INDEX_BUFFER; + desc.CPUAccessFlags = m_IndicesDynamic ? D3D11_CPU_ACCESS_WRITE : 0; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + HRESULT hr = dev->CreateBuffer (&desc, NULL, &m_IB); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_IB,newSize,this); + if( FAILED(hr) ) + { + printf_console( "d3d11: failed to create index buffer of size %d [0x%X]\n", newSize, hr ); + return; + } + SetDebugNameD3D11 (m_IB, Format("IndexBuffer-%d", newSize)); + } + + m_IBSize = newSize; + UpdateIndexBufferData(buffer); +} + +void D3D11VBO::SetIndicesDynamic(bool dynamic) +{ + // do nothing if a no-op + if (dynamic == m_IndicesDynamic) + return; + + VBO::SetIndicesDynamic(dynamic); + + // release current index buffers + if (m_IB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + SAFE_RELEASE(m_IB); + } + if (m_StagingIB) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_StagingIB); + SAFE_RELEASE(m_StagingIB); + } +} + + + +// ----------------------------------------------------------------------------- + + +DynamicD3D11VBO::DynamicD3D11VBO( UInt32 vbSize, UInt32 ibSize ) +: DynamicVBO() +, m_VBSize(vbSize) +, m_VBUsedBytes(0) +, m_IBSize(ibSize) +, m_IBUsedBytes(0) +, m_VB(NULL) +, m_IB(NULL) +, m_LastChunkStartVertex(0) +, m_LastChunkStartIndex(0) +, m_QuadsIB(NULL) +{ +} + +DynamicD3D11VBO::~DynamicD3D11VBO () +{ + if( m_VB ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VB); + ULONG refCount = m_VB->Release(); + AssertIf( refCount != 0 ); + } + if( m_IB ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + ULONG refCount = m_IB->Release(); + AssertIf( refCount != 0 ); + } + if( m_QuadsIB ) { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_QuadsIB); + ULONG refCount = m_QuadsIB->Release(); + AssertIf( refCount != 0 ); + } +} + +void DynamicD3D11VBO::InitializeQuadsIB() +{ + AssertIf( m_QuadsIB ); + + const int kMaxQuads = 65536/4 - 4; // so we fit into 16 bit indices, minus some more just in case + + UInt16* data = new UInt16[kMaxQuads*6]; + UInt16* ib = data; + UInt32 baseIndex = 0; + for( int i = 0; i < kMaxQuads; ++i ) + { + ib[0] = baseIndex + 1; + ib[1] = baseIndex + 2; + ib[2] = baseIndex; + ib[3] = baseIndex + 2; + ib[4] = baseIndex + 3; + ib[5] = baseIndex; + baseIndex += 4; + ib += 6; + } + + ID3D11Device* dev = GetD3D11Device(); + D3D11_BUFFER_DESC desc; + desc.ByteWidth = kMaxQuads * 6 * kVBOIndexSize; + desc.Usage = D3D11_USAGE_IMMUTABLE; + desc.BindFlags = D3D11_BIND_INDEX_BUFFER; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + D3D11_SUBRESOURCE_DATA srData; + srData.pSysMem = data; + srData.SysMemPitch = 0; + srData.SysMemSlicePitch = 0; + HRESULT hr = dev->CreateBuffer (&desc, &srData, &m_QuadsIB); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_QuadsIB,desc.ByteWidth,this); + delete[] data; + if (FAILED(hr)) + { + printf_console ("d3d11: failed to create quads index buffer [%x]\n", hr); + } + SetDebugNameD3D11 (m_QuadsIB, "IndexBufferQuads"); +} + + +void DynamicD3D11VBO::DrawChunk (const ChannelAssigns& channels) +{ + DX11_LOG_ENTER_FUNCTION("DynamicD3D11VBO::DrawChunk"); + // just return if nothing to render + if( !m_LastChunkShaderChannelMask ) + return; + + HRESULT hr; + + AssertIf( !m_LastChunkShaderChannelMask || !m_LastChunkStride ); + AssertIf( m_LendedChunk ); + + GfxDevice& device = GetRealGfxDevice(); + ID3D11DeviceContext* ctx = GetD3D11Context(); + + // setup VBO + DebugAssert (m_VB); + UINT strides = m_LastChunkStride; + UINT offsets = 0; + D3D11_CALL (ctx->IASetVertexBuffers(0, 1, &m_VB, &strides, &offsets)); + + UpdateChannelBindingsD3D11(channels); + device.BeforeDrawCall (false); + + ID3D11InputLayout* inputLayout = GetD3D11VertexDeclaration (m_LastChunkShaderChannelMask); + SetInputLayoutD3D11 (ctx, inputLayout); + + // draw + GfxDeviceStats& stats = device.GetFrameStats(); + int primCount = 0; + if (m_LastRenderMode == kDrawTriangleStrip) + { + if (!SetTopologyD3D11(kPrimitiveTriangleStripDeprecated,device,ctx)) + return; + D3D11_CALL (ctx->Draw (m_LastChunkVertices, m_LastChunkStartVertex)); + primCount = m_LastChunkVertices-2; + } + else if (m_LastRenderMode == kDrawIndexedTriangleStrip) + { + DebugAssert (m_IB); + if (!SetTopologyD3D11(kPrimitiveTriangleStripDeprecated,device,ctx)) + return; + D3D11_CALL (ctx->IASetIndexBuffer (m_IB, DXGI_FORMAT_R16_UINT, 0)); + D3D11_CALL (ctx->DrawIndexed (m_LastChunkIndices, m_LastChunkStartIndex, m_LastChunkStartVertex)); + primCount = m_LastChunkIndices-2; + } + else if( m_LastRenderMode == kDrawQuads ) + { + if (!SetTopologyD3D11(kPrimitiveTriangles,device,ctx)) + return; + // initialize quads index buffer if needed + if (!m_QuadsIB) + InitializeQuadsIB(); + // if quads index buffer has valid data, draw with it + if (m_QuadsIB) + { + D3D11_CALL (ctx->IASetIndexBuffer (m_QuadsIB, DXGI_FORMAT_R16_UINT, 0)); + D3D11_CALL (ctx->DrawIndexed (m_LastChunkVertices/4*6, 0, m_LastChunkStartVertex)); + primCount = m_LastChunkVertices/2; + } + } + else if (m_LastRenderMode == kDrawIndexedLines) + { + DebugAssert( m_IB ); + if (!SetTopologyD3D11(kPrimitiveLines,device,ctx)) + return; + D3D11_CALL (ctx->IASetIndexBuffer (m_IB, DXGI_FORMAT_R16_UINT, 0)); + D3D11_CALL (ctx->DrawIndexed (m_LastChunkIndices, m_LastChunkStartIndex, m_LastChunkStartVertex)); + primCount = m_LastChunkIndices/2; + } + else if (m_LastRenderMode == kDrawIndexedPoints) + { + DebugAssert (m_IB); + D3D11_CALL (ctx->IASetIndexBuffer (m_IB, DXGI_FORMAT_R16_UINT, 0)); + if (!SetTopologyD3D11 (kPrimitivePoints, device, ctx)) + return; + D3D11_CALL (ctx->DrawIndexed (m_LastChunkIndices, m_LastChunkStartIndex, m_LastChunkStartVertex)); + primCount = m_LastChunkIndices; + } + else + { + DebugAssert (m_IB); + D3D11_CALL (ctx->IASetIndexBuffer (m_IB, DXGI_FORMAT_R16_UINT, 0)); + if (!SetTopologyD3D11 (kPrimitiveTriangles, device, ctx)) + return; + D3D11_CALL (ctx->DrawIndexed (m_LastChunkIndices, m_LastChunkStartIndex, m_LastChunkStartVertex)); + primCount = m_LastChunkIndices/3; + } + stats.AddDrawCall (primCount, m_LastChunkVertices); + DX11_MARK_DRAWING(primCount, m_LastChunkVertices); +} + + +#if UNITY_EDITOR +void DynamicD3D11VBO::DrawChunkUserPrimitives (GfxPrimitiveType type) +{ + // just return if nothing to render + if( !m_LastChunkShaderChannelMask ) + return; + + HRESULT hr; + + AssertIf( !m_LastChunkShaderChannelMask || !m_LastChunkStride ); + AssertIf( m_LendedChunk ); + + ChannelAssigns channels; + for( int i = 0; i < kShaderChannelCount; ++i ) + { + if (!(m_LastChunkShaderChannelMask & (1<<i))) + continue; + VertexComponent destComponent = kSuitableVertexComponentForChannel[i]; + channels.Bind ((ShaderChannel)i, destComponent); + } + + GfxDevice& device = GetRealGfxDevice(); + ID3D11DeviceContext* ctx = GetD3D11Context(); + + // setup VBO + DebugAssert (m_VB); + UINT strides = m_LastChunkStride; + UINT offsets = 0; + D3D11_CALL (ctx->IASetVertexBuffers(0, 1, &m_VB, &strides, &offsets)); + + UpdateChannelBindingsD3D11(channels); + device.BeforeDrawCall (false); + + ID3D11InputLayout* inputLayout = GetD3D11VertexDeclaration (m_LastChunkShaderChannelMask); + SetInputLayoutD3D11 (ctx, inputLayout); + + // draw + GfxDeviceStats& stats = device.GetFrameStats(); + int primCount = 0; + switch (type) + { + case kPrimitiveTriangles: + if (!SetTopologyD3D11(kPrimitiveTriangles,device,ctx)) + return; + D3D11_CALL (ctx->Draw (m_LastChunkVertices, m_LastChunkStartVertex)); + primCount = m_LastChunkVertices/3; + break; + case kPrimitiveQuads: + if (!SetTopologyD3D11(kPrimitiveTriangles,device,ctx)) + return; + // initialize quads index buffer if needed + if (!m_QuadsIB) + InitializeQuadsIB(); + // if quads index buffer has valid data, draw with it + if (m_QuadsIB) + { + D3D11_CALL (ctx->IASetIndexBuffer (m_QuadsIB, DXGI_FORMAT_R16_UINT, 0)); + D3D11_CALL (ctx->DrawIndexed (m_LastChunkVertices/4*6, 0, m_LastChunkStartVertex)); + primCount = m_LastChunkVertices/2; + } + break; + case kPrimitiveLines: + if (!SetTopologyD3D11(kPrimitiveLines,device,ctx)) + return; + D3D11_CALL (ctx->Draw (m_LastChunkVertices, m_LastChunkStartVertex)); + primCount = m_LastChunkVertices/2; + break; + case kPrimitiveLineStrip: + if (!SetTopologyD3D11(kPrimitiveLineStrip,device,ctx)) + return; + D3D11_CALL (ctx->Draw (m_LastChunkVertices, m_LastChunkStartVertex)); + primCount = m_LastChunkVertices-1; + break; + default: + ErrorString("Primitive type not supported"); + return; + } + stats.AddDrawCall (primCount, m_LastChunkVertices); +} +#endif // UNITY_EDITOR + + +bool DynamicD3D11VBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ) +{ + Assert( !m_LendedChunk ); + Assert( maxVertices < 65536 && maxIndices < 65536*3 ); + DebugAssertMsg(outVB != NULL && maxVertices > 0, "DynamicD3D11VBO::GetChunk - outVB: 0x%08x maxVertices: %d", outVB, maxVertices); + DebugAssertMsg( + (renderMode == kDrawIndexedQuads && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedPoints && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedLines && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangles && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangleStrip && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawTriangleStrip && (outIB == NULL && maxIndices == 0)) || + (renderMode == kDrawQuads && (outIB == NULL && maxIndices == 0)), + "DynamicD3D11VBO::GetChunk - renderMode: %d outIB: 0x%08x maxIndices: %d", renderMode, outIB, maxIndices); + + HRESULT hr; + bool success = true; + + m_LendedChunk = true; + m_LastChunkShaderChannelMask = shaderChannelMask; + m_LastRenderMode = renderMode; + + if( maxVertices == 0 ) + maxVertices = 8; + + m_LastChunkStride = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( shaderChannelMask & (1<<i) ) + m_LastChunkStride += VBO::GetDefaultChannelByteSize(i); + } + ID3D11Device* dev = GetD3D11Device(); + ID3D11DeviceContext* ctx = GetD3D11Context(); + + // -------- vertex buffer + + DebugAssertIf( !outVB ); + UInt32 vbCapacity = maxVertices * m_LastChunkStride; + // check if requested chunk is larger than current buffer + if( vbCapacity > m_VBSize ) { + m_VBSize = vbCapacity * 2; // allocate more up front + if( m_VB ) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VB); + m_VB->Release(); + } + m_VB = NULL; + } + // allocate buffer if don't have it yet + if( !m_VB ) + { + D3D11_BUFFER_DESC desc; + desc.ByteWidth = m_VBSize; + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + hr = dev->CreateBuffer (&desc, NULL, &m_VB); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_VB,m_VBSize,this); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to create dynamic vertex buffer of size %d [%x]\n", m_VBSize, hr); + success = false; + *outVB = NULL; + } + SetDebugNameD3D11 (m_VB, Format("VertexBufferDynamic-%d", m_VBSize)); + } + + // map, making sure the offset we lock is multiple of vertex stride + if (m_VB) + { + m_VBUsedBytes = ((m_VBUsedBytes + (m_LastChunkStride-1)) / m_LastChunkStride) * m_LastChunkStride; + if (m_VBUsedBytes + vbCapacity > m_VBSize) + { + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (m_VB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to lock dynamic vertex buffer with discard [%x]\n", hr); + *outVB = NULL; + success = false; + } + *outVB = mapped.pData; + m_VBUsedBytes = 0; + } else { + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (m_VB, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to lock vertex index buffer, offset %i size %i [%x]\n", m_VBUsedBytes, vbCapacity, hr); + *outVB = NULL; + success = false; + } + *outVB = ((UInt8*)mapped.pData) + m_VBUsedBytes; + } + m_LastChunkStartVertex = m_VBUsedBytes / m_LastChunkStride; + DebugAssertIf( m_LastChunkStartVertex * m_LastChunkStride != m_VBUsedBytes ); + } + + // -------- index buffer + + const bool indexed = (renderMode != kDrawQuads) && (renderMode != kDrawTriangleStrip); + if( success && maxIndices && indexed ) + { + UInt32 ibCapacity = maxIndices * kVBOIndexSize; + // check if requested chunk is larger than current buffer + if( ibCapacity > m_IBSize ) { + m_IBSize = ibCapacity * 2; // allocate more up front + if( m_IB ) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_IB); + m_IB->Release(); + } + m_IB = NULL; + } + // allocate buffer if don't have it yet + if( !m_IB ) + { + D3D11_BUFFER_DESC desc; + desc.ByteWidth = m_IBSize; + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_INDEX_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + hr = dev->CreateBuffer (&desc, NULL, &m_IB); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_IB,m_IBSize,this); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to create dynamic index buffer of size %d [%x]\n", m_IBSize, hr); + if (m_VB) + ctx->Unmap (m_VB, 0); + } + SetDebugNameD3D11 (m_IB, Format("IndexBufferDynamic-%d", m_IBSize)); + } + // lock it if we have IB created successfully + if( m_IB ) + { + if( m_IBUsedBytes + ibCapacity > m_IBSize ) + { + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (m_IB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to lock dynamic index buffer with discard [%x]\n", hr); + *outIB = NULL; + success = false; + if (m_VB) + ctx->Unmap (m_VB, 0); + } + *outIB = mapped.pData; + m_IBUsedBytes = 0; + } else { + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (m_IB, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to lock dynamic index buffer, offset %i size %i [%x]\n", m_IBUsedBytes, ibCapacity, hr); + *outIB = NULL; + success = false; + if (m_VB) + ctx->Unmap (m_VB, 0); + } + *outIB = ((UInt8*)mapped.pData) + m_IBUsedBytes; + } + m_LastChunkStartIndex = m_IBUsedBytes / 2; + } + else + { + *outIB = NULL; + success = false; + } + } + + if( !success ) + m_LendedChunk = false; + + return success; +} + +void DynamicD3D11VBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ) +{ + Assert( m_LendedChunk ); + Assert( m_LastRenderMode == kDrawIndexedTriangleStrip || m_LastRenderMode == kDrawIndexedQuads || m_LastRenderMode == kDrawIndexedPoints || m_LastRenderMode == kDrawIndexedLines || actualIndices % 3 == 0 ); + m_LendedChunk = false; + + const bool indexed = (m_LastRenderMode != kDrawQuads) && (m_LastRenderMode != kDrawTriangleStrip); + + m_LastChunkVertices = actualVertices; + m_LastChunkIndices = actualIndices; + + // unlock buffers + ID3D11DeviceContext* ctx = GetD3D11Context(); + ctx->Unmap (m_VB, 0); + if (indexed) + ctx->Unmap (m_IB, 0); + + if( !actualVertices || (indexed && !actualIndices) ) { + m_LastChunkShaderChannelMask = 0; + return; + } + + UInt32 actualVBSize = actualVertices * m_LastChunkStride; + m_VBUsedBytes += actualVBSize; + UInt32 actualIBSize = actualIndices * kVBOIndexSize; + m_IBUsedBytes += actualIBSize; +} + + diff --git a/Runtime/GfxDevice/d3d11/D3D11VBO.h b/Runtime/GfxDevice/d3d11/D3D11VBO.h new file mode 100644 index 0000000..9c0d0d2 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11VBO.h @@ -0,0 +1,99 @@ +#pragma once + +#include "Runtime/Shaders/VBO.h" +#include "D3D11Includes.h" + +class GfxDevice; + +class D3D11VBO : public VBO { +public: + D3D11VBO(); + virtual ~D3D11VBO(); + + virtual void UpdateVertexData( const VertexBufferData& buffer ); + virtual void UpdateIndexData (const IndexBufferData& buffer); + virtual void DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ); + #if GFX_ENABLE_DRAW_CALL_BATCHING + virtual void DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ) ; + #endif + virtual bool MapVertexStream( VertexStreamData& outData, unsigned stream ); + virtual void UnmapVertexStream( unsigned stream ); + virtual bool IsVertexBufferLost() const; + + virtual void SetIndicesDynamic(bool dynamic); + + virtual int GetRuntimeMemorySize() const; + + static void CleanupSharedBuffers(); + + virtual void UseAsStreamOutput() { m_useForSO = true; } + void BindToStreamOutput(); + void UnbindFromStreamOutput(); + +private: + void UpdateVertexStream (const VertexBufferData& sourceData, unsigned stream); + void UpdateIndexBufferData (const IndexBufferData& sourceData); + void BindVertexStreams (GfxDevice& device, ID3D11DeviceContext* ctx, const ChannelAssigns& channels); + + static UInt16* MapDynamicIndexBuffer (int indexCount, UInt32& outBytesUsed); + static void UnmapDynamicIndexBuffer (); + + static ID3D11Buffer* GetAllWhiteBuffer(); + +private: + int m_VertexCount; + + ID3D11Buffer* m_VBStreams[kMaxVertexStreams]; + ChannelInfoArray m_ChannelInfo; + ID3D11Buffer* m_StagingVB[kMaxVertexStreams]; + ID3D11Buffer* m_IB; + ID3D11Buffer* m_StagingIB; + UInt16* m_IBReadable; + int m_IBSize; + bool m_useForSO; + + static ID3D11Buffer* ms_CustomIB; + static int ms_CustomIBSize; + static UInt32 ms_CustomIBUsedBytes; + static ID3D11Buffer* ms_AllWhiteBuffer; +}; + + +class DynamicD3D11VBO : public DynamicVBO { +public: + DynamicD3D11VBO( UInt32 vbSize, UInt32 ibSize ); + virtual ~DynamicD3D11VBO(); + + virtual bool GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode mode, void** outVB, void** outIB ); + virtual void ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ); + virtual void DrawChunk (const ChannelAssigns& channels); + + ID3D11Buffer* GetQuadsIB() + { + if (!m_QuadsIB) + InitializeQuadsIB(); + return m_QuadsIB; + } + + #if UNITY_EDITOR + void DrawChunkUserPrimitives (GfxPrimitiveType type); + #endif + +private: + void InitializeQuadsIB(); + +private: + UInt32 m_VBSize; + UInt32 m_VBUsedBytes; + UInt32 m_IBSize; + UInt32 m_IBUsedBytes; + + ID3D11Buffer* m_VB; + ID3D11Buffer* m_IB; + + UInt32 m_LastChunkStartVertex; + UInt32 m_LastChunkStartIndex; + + ID3D11Buffer* m_QuadsIB; +}; diff --git a/Runtime/GfxDevice/d3d11/D3D11Window.cpp b/Runtime/GfxDevice/d3d11/D3D11Window.cpp new file mode 100644 index 0000000..bdf2e1f --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Window.cpp @@ -0,0 +1,220 @@ +#include "UnityPrefix.h" +#include "D3D11Window.h" +#include "D3D11Context.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Math/ColorSpaceConversion.h" +#include "Runtime/Misc/QualitySettings.h" + + +#if UNITY_EDITOR + +static D3D11Window* s_CurrentD3D11Window = NULL; +static int s_CurrentD3D11AA = 0; + +void SetNoRenderTextureActiveEditor(); // RenderTexture.cpp +void InternalDestroyRenderSurfaceD3D11 (RenderSurfaceD3D11* rs, TexturesD3D11* textures); // RenderTextureD3D11.cpp +bool InitD3D11RenderDepthSurface (RenderDepthSurfaceD3D11& rs, TexturesD3D11* textures, bool sampleOnly); + + +D3D11Window::D3D11Window (HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias) +: GfxDeviceWindow(window, width, height, depthFormat, antiAlias) +, m_SwapChain(NULL) +, m_AntiAlias(0) +{ + Reshape (width, height, depthFormat, antiAlias); +} + +D3D11Window::~D3D11Window() +{ + if (s_CurrentD3D11Window == this) + { + s_CurrentD3D11Window = NULL; + s_CurrentD3D11AA = 0; + } + + InternalDestroyRenderSurfaceD3D11 (&m_DepthStencil, NULL); + InternalDestroyRenderSurfaceD3D11 (&m_BackBuffer, NULL); + SAFE_RELEASE (m_SwapChain); +} + +bool D3D11Window::Reshape (int width, int height, DepthBufferFormat depthFormat, int antiAlias) +{ + if (!GfxDeviceWindow::Reshape(width, height, depthFormat, antiAlias)) + return false; + + // release old + SAFE_RELEASE(m_DepthStencil.m_Texture); + SAFE_RELEASE(m_DepthStencil.m_SRView); + SAFE_RELEASE(m_DepthStencil.m_DSView); + m_BackBuffer.Reset(); + SAFE_RELEASE(m_SwapChain); + + // pick supported AA level + if (antiAlias == -1) + antiAlias = GetQualitySettings().GetCurrent().antiAliasing; + while (antiAlias > 1 && !(gGraphicsCaps.d3d11.msaa & (1<<antiAlias))) + --antiAlias; + antiAlias = std::max(antiAlias, 1); + + HRESULT hr; + + const bool sRGB = GetActiveColorSpace() == kLinearColorSpace; + + const bool createSRV = (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0); // swap chain can't have SRV before 10.0, it seems + + DXGI_SWAP_CHAIN_DESC sd; + ZeroMemory (&sd, sizeof(DXGI_SWAP_CHAIN_DESC)); + sd.BufferCount = 1; + sd.BufferDesc.Width = m_Width; + sd.BufferDesc.Height = m_Height; + sd.BufferDesc.Format = sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 0; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + if (createSRV) + sd.BufferUsage |= DXGI_USAGE_SHADER_INPUT; + sd.OutputWindow = m_Window; + sd.SampleDesc.Count = antiAlias; + sd.SampleDesc.Quality = 0; + sd.Windowed = TRUE; + + hr = GetDXGIFactory()->CreateSwapChain (GetD3D11Device(), &sd, &m_SwapChain); + Assert(SUCCEEDED(hr)); + + if (FAILED(hr)) + { + printf_console ("d3d11: swap chain: w=%i h=%i fmt=%i\n", + sd.BufferDesc.Width, sd.BufferDesc.Height, sd.BufferDesc.Format); + printf_console ("d3d11: failed to create swap chain [0x%x]\n", hr); + m_InvalidState = true; + return !m_InvalidState; + } + + //@TODO: false if AA is used? + m_CanUseBlitOptimization = true; + m_AntiAlias = 0; + + // Swap Chain + ID3D11Texture2D* backBufferTexture; + hr = m_SwapChain->GetBuffer (0, __uuidof(*backBufferTexture), (void**)&backBufferTexture); + Assert(SUCCEEDED(hr)); + + // Set the primary backbuffer view + ID3D11RenderTargetView* rtView; + D3D11_RENDER_TARGET_VIEW_DESC rtDesc; + rtDesc.Format = sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + rtDesc.ViewDimension = antiAlias > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D; + rtDesc.Texture2D.MipSlice = 0; + hr = GetD3D11Device()->CreateRenderTargetView (backBufferTexture, &rtDesc, &rtView); + Assert(SUCCEEDED(hr)); + + // Set the secondary backbuffer view + ID3D11RenderTargetView* rtViewSecondary; + D3D11_RENDER_TARGET_VIEW_DESC rtDescSecondary; + rtDescSecondary.Format = !sRGB ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + rtDescSecondary.ViewDimension = antiAlias > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D; + rtDescSecondary.Texture2D.MipSlice = 0; + hr = GetD3D11Device()->CreateRenderTargetView (backBufferTexture, &rtDescSecondary, &rtViewSecondary); + Assert(SUCCEEDED(hr)); + + // Create shader resource view + if (createSRV) + { + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + srvDesc.Format = sd.BufferDesc.Format; + srvDesc.ViewDimension = antiAlias > 1 ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MostDetailedMip = 0; + srvDesc.Texture2D.MipLevels = 1; + ID3D11ShaderResourceView* srView = NULL; + hr = GetD3D11Device()->CreateShaderResourceView (backBufferTexture, &srvDesc, &m_BackBuffer.m_SRView); + Assert (SUCCEEDED(hr)); + } + + //Pass through flags + m_BackBuffer.m_Texture = backBufferTexture; + m_BackBuffer.SetRTV (0, 0, false, rtView); + m_BackBuffer.SetRTV (0, 0, true, rtViewSecondary); + m_BackBuffer.width = sd.BufferDesc.Width; + m_BackBuffer.height = sd.BufferDesc.Height; + m_BackBuffer.samples = antiAlias; + m_BackBuffer.format = kRTFormatARGB32; + m_BackBuffer.backBuffer = true; + m_BackBuffer.flags = sRGB ? (m_BackBuffer.flags | kSurfaceCreateSRGB) : (m_BackBuffer.flags & ~kSurfaceCreateSRGB); + + // Depth stencil + m_DepthStencil.width = m_Width; + m_DepthStencil.height = m_Height; + m_DepthStencil.samples = antiAlias; + m_DepthStencil.depthFormat = depthFormat; + m_DepthStencil.backBuffer = true; + + bool dsOk = InitD3D11RenderDepthSurface (m_DepthStencil, NULL, false); + Assert (dsOk); + + return !m_InvalidState; +} + +void D3D11Window::SetAsActiveWindow () +{ + GfxDevice& device = GetRealGfxDevice(); + device.SetRenderTargets(1, &GetBackBuffer(), GetDepthStencil()); + device.SetActiveRenderTexture(NULL); + device.SetCurrentWindowSize(m_Width, m_Height); + device.SetInvertProjectionMatrix(false); + + s_CurrentD3D11Window = this; + s_CurrentD3D11AA = m_AntiAlias; +} + +bool D3D11Window::BeginRendering() +{ + if (!GfxDeviceWindow::BeginRendering()) + return false; + + SetAsActiveWindow (); + + GfxDevice& device = GetRealGfxDevice(); + if (device.IsInsideFrame()) + { + ErrorString ("GUI Window tries to begin rendering while something else has not finished rendering! Either you have a recursive OnGUI rendering, or previous OnGUI did not clean up properly."); + } + device.SetInsideFrame(true); + + return true; +} + +bool D3D11Window::EndRendering( bool presentContent ) +{ + if (!GfxDeviceWindow::EndRendering(presentContent)) + return false; + + GfxDevice& device = GetRealGfxDevice(); + Assert(device.IsInsideFrame()); + device.SetInsideFrame(false); + + s_CurrentD3D11Window = NULL; + + HRESULT hr; + if (m_SwapChain && presentContent) + { + HRESULT hr = m_SwapChain->Present (0, 0); + Assert (SUCCEEDED(hr)); + } + return true; +} + +RenderSurfaceHandle D3D11Window::GetBackBuffer() +{ + RenderSurfaceHandle handle; + handle.object = &m_BackBuffer; + return handle; +} + +RenderSurfaceHandle D3D11Window::GetDepthStencil() +{ + RenderSurfaceHandle handle; + handle.object = &m_DepthStencil; + return handle; +} + +#endif diff --git a/Runtime/GfxDevice/d3d11/D3D11Window.h b/Runtime/GfxDevice/d3d11/D3D11Window.h new file mode 100644 index 0000000..e269cf2 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/D3D11Window.h @@ -0,0 +1,28 @@ +#pragma once + +#include "External/DirectX/builds/dx11include/d3d11.h" +#include "Runtime/GfxDevice/GfxDeviceWindow.h" +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "TexturesD3D11.h" + +class D3D11Window : public GfxDeviceWindow +{ +private: + IDXGISwapChain* m_SwapChain; + RenderColorSurfaceD3D11 m_BackBuffer; + RenderDepthSurfaceD3D11 m_DepthStencil; + int m_AntiAlias; + +public: + D3D11Window (HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias); + ~D3D11Window (); + + bool Reshape (int width, int height, DepthBufferFormat depthFormat, int antiAlias); + + bool BeginRendering (); + bool EndRendering (bool presentContent); + void SetAsActiveWindow (); + + RenderSurfaceHandle GetBackBuffer(); + RenderSurfaceHandle GetDepthStencil(); +}; diff --git a/Runtime/GfxDevice/d3d11/FixedFunctionStateD3D11.h b/Runtime/GfxDevice/d3d11/FixedFunctionStateD3D11.h new file mode 100644 index 0000000..e174f26 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/FixedFunctionStateD3D11.h @@ -0,0 +1,98 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + + +enum TextureSourceD3D11 { + kTexSourceUV0, + kTexSourceUV1, + kTexSourceUV2, + kTexSourceUV3, + kTexSourceUV4, + kTexSourceUV5, + kTexSourceUV6, + kTexSourceUV7, + // match the order of TexGenMode! + kTexSourceSphereMap, + kTexSourceObject, + kTexSourceEyeLinear, + kTexSourceCubeReflect, + kTexSourceCubeNormal, + kTexSourceTypeCount +}; + +#define CMP_STATE(member) { \ + if (a.member < b.member) \ + return true; \ + else if (b.member < a.member) \ + return false; \ + } + + +struct FixedFunctionStateD3D11 +{ + FixedFunctionStateD3D11() + : texUnitSources(0) + , texUnitCube(0) + , texUnit3D(0) + , texUnitProjected(0) + , texUnitCount(0) + , alphaTest(kFuncDisabled) + , useUniformInsteadOfVertexColor(false) + , lightingEnabled(false) + , specularEnabled(false) + , lightCount(0) + , colorMaterial(kColorMatDisabled) + , fogMode(kFogDisabled) + { + for (int i = 0; i < kMaxSupportedTextureUnits; ++i) + { + texUnitColorCombiner[i] = ~0U; + texUnitAlphaCombiner[i] = ~0U; + } + } + + UInt64 texUnitSources; // 4 bits for each unit + UInt32 texUnitColorCombiner[kMaxSupportedTextureUnits]; + UInt32 texUnitAlphaCombiner[kMaxSupportedTextureUnits]; + UInt32 texUnitCube; // bit per unit + UInt32 texUnit3D; // bit per unit + UInt32 texUnitProjected; // bit per unit + + int texUnitCount; + CompareFunction alphaTest; + + bool useUniformInsteadOfVertexColor; + bool lightingEnabled; + bool specularEnabled; + int lightCount; + ColorMaterialMode colorMaterial; + FogMode fogMode; +}; + + +struct FixedFuncStateCompareD3D11 +{ + bool operator() (const FixedFunctionStateD3D11& a, const FixedFunctionStateD3D11& b) const + { + CMP_STATE(lightingEnabled); + CMP_STATE(specularEnabled); + CMP_STATE(lightCount); + CMP_STATE(texUnitCount); + CMP_STATE(texUnitSources); + CMP_STATE(texUnitCube); + CMP_STATE(texUnit3D); + CMP_STATE(texUnitProjected); + CMP_STATE(alphaTest); + for (int i = 0; i < a.texUnitCount; i++) + { + CMP_STATE(texUnitColorCombiner[i]) + CMP_STATE(texUnitAlphaCombiner[i]) + } + CMP_STATE(useUniformInsteadOfVertexColor); + CMP_STATE(colorMaterial); + CMP_STATE(fogMode); + + return false; + } +}; diff --git a/Runtime/GfxDevice/d3d11/GfxDeviceD3D11.cpp b/Runtime/GfxDevice/d3d11/GfxDeviceD3D11.cpp new file mode 100644 index 0000000..237ae6c --- /dev/null +++ b/Runtime/GfxDevice/d3d11/GfxDeviceD3D11.cpp @@ -0,0 +1,3133 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "D3D11Context.h" +#include "D3D11VBO.h" +#include "External/shaderlab/Library/program.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/GfxDevice/GpuProgramParamsApply.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "External/shaderlab/Library/properties.h" +#include "D3D11Utils.h" +#include "GpuProgramsD3D11.h" +#include "ShaderPatchingD3D11.h" +#include "TimerQueryD3D11.h" +#include "PlatformDependent/Win/SmartComPointer.h" +#include "PlatformDependent/Win/WinUnicode.h" +#include "Runtime/Camera/CameraUtil.h" +#include "Runtime/Graphics/GraphicsHelper.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Misc/Plugins.h" +#if UNITY_EDITOR +#include "D3D11Window.h" +#endif +#include "Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.h" + +class GfxDeviceD3D11; + +namespace ShaderLab { + TexEnv* GetTexEnvForBinding( const TextureBinding& binding, const PropertySheet* props ); // pass.cpp +} + + +#include "GfxDeviceD3D11.h" + +extern const InputSignatureD3D11* g_CurrentVSInputD3D11; +extern ID3D11InputLayout* g_ActiveInputLayoutD3D11; +extern D3D11_PRIMITIVE_TOPOLOGY g_ActiveTopologyD3D11; + + +static ShaderLab::FastPropertyName kSLPropFogCB = ShaderLab::Property ("UnityFogPatchCB"); + + + +static const D3D11_COMPARISON_FUNC kCmpFuncD3D11[] = { + D3D11_COMPARISON_ALWAYS, D3D11_COMPARISON_NEVER, D3D11_COMPARISON_LESS, D3D11_COMPARISON_EQUAL, D3D11_COMPARISON_LESS_EQUAL, D3D11_COMPARISON_GREATER, D3D11_COMPARISON_NOT_EQUAL, D3D11_COMPARISON_GREATER_EQUAL, D3D11_COMPARISON_ALWAYS +}; + +static const D3D11_STENCIL_OP kStencilOpD3D11[] = { + D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_ZERO, D3D11_STENCIL_OP_REPLACE, D3D11_STENCIL_OP_INCR_SAT, + D3D11_STENCIL_OP_DECR_SAT, D3D11_STENCIL_OP_INVERT, D3D11_STENCIL_OP_INCR, D3D11_STENCIL_OP_DECR +}; + +// Graphics device requires access to reset render textures +bool RebindActiveRenderTargets (TexturesD3D11* textures); + +DXGI_FORMAT GetRenderTextureFormat (RenderTextureFormat format, bool sRGB); +DXGI_FORMAT GetShaderResourceViewFormat (RenderTextureFormat format, bool sRGB); +extern DXGI_FORMAT kD3D11RenderResourceFormats[kRTFormatCount]; +extern DXGI_FORMAT kD3D11RenderTextureFormatsNorm[kRTFormatCount]; + + +bool SetTopologyD3D11 (GfxPrimitiveType topology, GfxDevice& device, ID3D11DeviceContext* ctx); +void SetInputLayoutD3D11 (ID3D11DeviceContext* ctx, ID3D11InputLayout* layout); + + +// -------------------------------------------------------------------------- + + +ResolveTexturePool::ResolveTexturePool() +: m_UseCounter(0) +{ + memset (m_Entries, 0, sizeof(m_Entries)); +} + +void ResolveTexturePool::Clear() +{ + for (int i = 0; i < ARRAY_SIZE(m_Entries); ++i) + { + SAFE_RELEASE(m_Entries[i].texture); + SAFE_RELEASE(m_Entries[i].srv); + } +} + +ResolveTexturePool::Entry* ResolveTexturePool::GetResolveTexture (int width, int height, RenderTextureFormat fmt, bool sRGB) +{ + ++m_UseCounter; + + // check if we have a suitable temporary resolve texture already? + int newIndex = -1; + int lruIndex = 0; + int lruScore = 0; + for (int i = 0; i < ARRAY_SIZE(m_Entries); ++i) + { + Entry& e = m_Entries[i]; + if (e.width == width && e.height == height && e.format == fmt && e.sRGB == sRGB) + { + Assert (e.texture); + Assert (e.srv); + e.lastUse = m_UseCounter; + return &e; + } + + if (e.width == 0) + { + // unused slot + Assert (e.height == 0 && !e.texture && !e.srv); + if (newIndex == -1) + newIndex = i; + } + else + { + // used slot + if (m_UseCounter - e.lastUse > lruScore) + { + lruIndex = i; + lruScore = m_UseCounter - e.lastUse; + } + } + } + + // if all slots are used; release least recently used + if (newIndex == -1) + { + Entry& e = m_Entries[lruIndex]; + Assert (e.texture); + e.width = e.height = 0; + SAFE_RELEASE(e.texture); + SAFE_RELEASE(e.srv); + newIndex = lruIndex; + } + + Entry& ee = m_Entries[newIndex]; + + // create texture & SRV in this slot + + ID3D11Device* dev = GetD3D11Device(); + D3D11_TEXTURE2D_DESC tDesc; + tDesc.Width = width; + tDesc.Height = height; + tDesc.MipLevels = 1; + tDesc.ArraySize = 1; + tDesc.Format = (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ? kD3D11RenderResourceFormats[fmt] : kD3D11RenderTextureFormatsNorm[fmt]); + + tDesc.SampleDesc.Count = 1; + tDesc.SampleDesc.Quality = 0; + tDesc.Usage = D3D11_USAGE_DEFAULT; + tDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + // 9.x feature levels require the resolved texture to also have a render target flag, otherwise + // CopySubresourceRegion will silently corrupt runtime/driver state. + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0) + tDesc.BindFlags |= D3D11_BIND_RENDER_TARGET; + + tDesc.CPUAccessFlags = 0; + tDesc.MiscFlags = 0; + + HRESULT hr = dev->CreateTexture2D (&tDesc, NULL, &ee.texture); + if (FAILED(hr)) + return NULL; + SetDebugNameD3D11 (ee.texture, Format("ResolveTexture2D-%dx%d", width, height)); + + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + srvDesc.Format = GetShaderResourceViewFormat (fmt, (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) ? sRGB : false); + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MostDetailedMip = 0; + srvDesc.Texture2D.MipLevels = 1; + hr = dev->CreateShaderResourceView (ee.texture, &srvDesc, &ee.srv); + if (FAILED(hr)) + return NULL; + SetDebugNameD3D11 (ee.srv, Format("ResolveTexture2D-SRV-%dx%d", width, height)); + + ee.width = width; + ee.height = height; + ee.format = fmt; + ee.sRGB = sRGB; + ee.lastUse = m_UseCounter; + + return ⅇ +} + + +// -------------------------------------------------------------------------- + + +static FixedFunctionProgramD3D11* GetFixedFunctionProgram11 (FFProgramCacheD3D11& cache, const FixedFunctionStateD3D11& state) +{ + // Do we have one for this state already? + FFProgramCacheD3D11::iterator cachedProgIt = cache.find (state); + if (cachedProgIt != cache.end()) + return cachedProgIt->second; + + // Don't have one yet, create it + FixedFunctionProgramD3D11* ffProg = new FixedFunctionProgramD3D11 (state); + cache.insert (std::make_pair(state, ffProg)); + return ffProg; +} + + + +// -------------------------------------------------------------------------- + + + +void GfxDeviceD3D11::SetupDeferredDepthStencilState () +{ + ID3D11DepthStencilState* dss = m_CurrDSState; + if (!dss) + { + DepthStencilState state; + memset (&state, 0, sizeof(state)); + if (m_CurrDepthState) + state.d = *m_CurrDepthState; + if (m_CurrStencilState) + state.s = *m_CurrStencilState; + + CachedDepthStencilStates::iterator it = m_CachedDepthStencilStates.find(state); + if (it == m_CachedDepthStencilStates.end()) + { + D3D11_DEPTH_STENCIL_DESC desc; + memset (&desc, 0, sizeof(desc)); + if (m_CurrDepthState) + { + desc.DepthEnable = TRUE; + desc.DepthWriteMask = (m_CurrDepthState->sourceState.depthWrite ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO); + desc.DepthFunc = kCmpFuncD3D11[m_CurrDepthState->sourceState.depthFunc]; + } + if (m_CurrStencilState) + { + desc.StencilEnable = m_CurrStencilState->sourceState.stencilEnable; + desc.StencilReadMask = m_CurrStencilState->sourceState.readMask; + desc.StencilWriteMask = m_CurrStencilState->sourceState.writeMask; + desc.FrontFace.StencilFunc = kCmpFuncD3D11[m_CurrStencilState->sourceState.stencilFuncFront]; + desc.FrontFace.StencilFailOp = kStencilOpD3D11[m_CurrStencilState->sourceState.stencilFailOpFront]; + desc.FrontFace.StencilDepthFailOp = kStencilOpD3D11[m_CurrStencilState->sourceState.stencilZFailOpFront]; + desc.FrontFace.StencilPassOp = kStencilOpD3D11[m_CurrStencilState->sourceState.stencilPassOpFront]; + desc.BackFace.StencilFunc = kCmpFuncD3D11[m_CurrStencilState->sourceState.stencilFuncBack]; + desc.BackFace.StencilFailOp = kStencilOpD3D11[m_CurrStencilState->sourceState.stencilFailOpBack]; + desc.BackFace.StencilDepthFailOp = kStencilOpD3D11[m_CurrStencilState->sourceState.stencilZFailOpBack]; + desc.BackFace.StencilPassOp = kStencilOpD3D11[m_CurrStencilState->sourceState.stencilPassOpBack]; + } + + ID3D11DepthStencilState* d3dstate = NULL; + HRESULT hr = GetD3D11Device()->CreateDepthStencilState (&desc, &d3dstate); + Assert(SUCCEEDED(hr)); + SetDebugNameD3D11 (d3dstate, Format("DepthStencilState-%d-%d", desc.DepthWriteMask, desc.DepthFunc)); + it = m_CachedDepthStencilStates.insert (std::make_pair(state, d3dstate)).first; + } + dss = it->second; + } + if (dss != m_CurrDSState || m_StencilRef != m_CurrStencilRef) + { + GetD3D11Context()->OMSetDepthStencilState (dss, m_StencilRef); + m_CurrDSState = dss; + m_CurrStencilRef = m_StencilRef; + } +} + +void GfxDeviceD3D11::SetupDeferredRasterState () +{ + // raster state; needs to be deferred due to cull winding / scissor / wireframe + // not known at creation time + if (!m_CurrRasterState) + return; + + ID3D11RasterizerState* rss = m_CurrRSState; + if (!rss) + { + FinalRasterState11 rsKey; + memcpy (&rsKey.raster, &m_CurrRasterState->sourceState, sizeof(rsKey.raster)); + rsKey.backface = (m_CurrRasterState->sourceState.cullMode != kCullOff) && ((m_AppBackfaceMode==m_UserBackfaceMode) == m_InvertProjMatrix); + rsKey.wireframe = m_Wireframe; + rsKey.scissor = m_Scissor; + + CachedFinalRasterStates::iterator it = m_CachedFinalRasterStates.find(rsKey); + if (it == m_CachedFinalRasterStates.end()) + { + D3D11_RASTERIZER_DESC desc; + memset (&desc, 0, sizeof(desc)); + + desc.FrontCounterClockwise = rsKey.backface ? TRUE : FALSE; + //TODO: wtf??? DepthBias doesn't work at 9.1 + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) + desc.DepthBias = rsKey.raster.sourceState.depthBias; + desc.SlopeScaledDepthBias = rsKey.raster.sourceState.slopeScaledDepthBias; + desc.ScissorEnable = m_Scissor; + desc.MultisampleEnable = TRUE; // only applies to line drawing in MSAA; if set to FALSE lines will be aliased even when MSAA is used + desc.DepthClipEnable = TRUE; + desc.FillMode = rsKey.wireframe ? D3D11_FILL_WIREFRAME : D3D11_FILL_SOLID; + switch (rsKey.raster.sourceState.cullMode) + { + case kCullOff: desc.CullMode = D3D11_CULL_NONE; break; + case kCullFront: desc.CullMode = D3D11_CULL_FRONT; break; + case kCullBack: desc.CullMode = D3D11_CULL_BACK; break; + default: AssertIf("Unsupported cull mode!"); + } + ID3D11RasterizerState* d3dstate = NULL; + HRESULT hr = GetD3D11Device()->CreateRasterizerState (&desc, &d3dstate); + Assert(SUCCEEDED(hr)); + SetDebugNameD3D11 (d3dstate, Format("RasterizerState-%d-%d", desc.FrontCounterClockwise, desc.FillMode)); + it = m_CachedFinalRasterStates.insert (std::make_pair(rsKey, d3dstate)).first; + } + rss = it->second; + } + if (rss != m_CurrRSState) + { + GetD3D11Context()->RSSetState (rss); + m_CurrRSState = rss; + } +} + + +void UpdateChannelBindingsD3D11 (const ChannelAssigns& channels) +{ + DX11_LOG_ENTER_FUNCTION("UpdateChannelBindingsD3D11"); + GfxDeviceD3D11& device = static_cast<GfxDeviceD3D11&>(GetRealGfxDevice()); + if (!device.IsShaderActive(kShaderVertex)) + { + const int maxTexCoords = gGraphicsCaps.maxTexCoords; // fetch here once + UInt64 textureSources = device.m_FFState.texUnitSources; + for (int i = 0; i < maxTexCoords; ++i) + { + UInt32 source = (textureSources >> (i*4)) & 0xF; + if (source > kTexSourceUV7) + continue; + ShaderChannel texCoordChannel = channels.GetSourceForTarget ((VertexComponent)(kVertexCompTexCoord0 + i)); + if (texCoordChannel == kShaderChannelTexCoord0) + textureSources = textureSources & ~(0xFUL<<i*4) | (UInt64(kTexSourceUV0)<<i*4); + else if (texCoordChannel == kShaderChannelTexCoord1) + textureSources = textureSources & ~(0xFUL<<i*4) | (UInt64(kTexSourceUV1)<<i*4); + else if (texCoordChannel != kShaderChannelNone) { + AssertString( "Bad texcoord index" ); + } + } + device.m_FFState.texUnitSources = textureSources; + } + + device.m_FFState.useUniformInsteadOfVertexColor = !(channels.GetTargetMap() & (1<<kVertexCompColor)); +} + + +struct SetValuesFunctorD3D11 +{ + SetValuesFunctorD3D11(GfxDevice& device, ConstantBuffersD3D11& cbs) : m_Device(device), m_CBs(cbs) { } + GfxDevice& m_Device; + ConstantBuffersD3D11& m_CBs; + void SetVectorVal (ShaderType shaderType, ShaderParamType type, int index, const float* ptr, int cols, const GpuProgramParameters& params, int cbIndex) + { + const GpuProgramParameters::ConstantBuffer& cb = params.GetConstantBuffers()[cbIndex]; + int idx = m_CBs.FindAndBindCB (cb.m_Name.index, shaderType, cb.m_BindIndex, cb.m_Size); + if (type != kShaderParamInt) + m_CBs.SetCBConstant (idx, index, ptr, cols*4); + else + { + int vali[4] = {ptr[0], ptr[1], ptr[2], ptr[3]}; + m_CBs.SetCBConstant (idx, index, vali, cols*4); + } + } + void SetMatrixVal (ShaderType shaderType, int index, const Matrix4x4f* ptr, int rows, const GpuProgramParameters& params, int cbIndex) + { + DebugAssert(rows == 4); + const GpuProgramParameters::ConstantBuffer& cb = params.GetConstantBuffers()[cbIndex]; + int idx = m_CBs.FindAndBindCB (cb.m_Name.index, shaderType, cb.m_BindIndex, cb.m_Size); + m_CBs.SetCBConstant (idx, index, ptr, 64); + } + void SetTextureVal (ShaderType shaderType, int index, int samplerIndex, TextureDimension dim, TextureID texID) + { + m_Device.SetTexture (shaderType, index, samplerIndex, texID, dim, std::numeric_limits<float>::infinity()); + } +}; + + +void GfxDeviceD3D11::BeforeDrawCall( bool immediateMode ) +{ + DX11_LOG_ENTER_FUNCTION("GfxDeviceD3D11::BeforeDrawCall"); + ID3D11DeviceContext* ctx = GetD3D11Context(); + HRESULT hr; + + SetupDeferredSRGBWrite (); + SetupDeferredDepthStencilState (); + SetupDeferredRasterState (); + + m_TransformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + + if (m_FogParams.mode != kFogDisabled) + { + float diff = m_FogParams.mode == kFogLinear ? m_FogParams.end - m_FogParams.start : 0.0f; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + Vector4f fogParams(m_FogParams.density * 1.2011224087f, + m_FogParams.density * 1.4426950408f, + m_FogParams.mode == kFogLinear ? -invDiff : 0.0f, + m_FogParams.mode == kFogLinear ? m_FogParams.end * invDiff : 0.0f + ); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogParams, fogParams); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogColor, m_FogParams.color); + } + + void* shader[kShaderTypeCount]; + for (int pt = 0; pt < kShaderTypeCount; ++pt) + { + shader[pt] = NULL; + m_BuiltinParamIndices[pt] = &m_NullParamIndices; + } + + if (m_ActiveGpuProgram[kShaderVertex] && m_ActiveGpuProgram[kShaderFragment]) + { + // Programmable shaders + const bool haveDomainShader = m_ActiveGpuProgram[kShaderDomain]; + bool resetToNoFog = false; + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) + { + if (m_ActiveGpuProgram[pt]) + { + DebugAssert (!m_ActiveGpuProgram[pt] || m_ActiveGpuProgram[pt]->GetImplType() == pt); + m_BuiltinParamIndices[pt] = &m_ActiveGpuProgramParams[pt]->GetBuiltinParams(); + D3D11CommonShader* prog = static_cast<D3D11CommonShader*>(m_ActiveGpuProgram[pt]); + shader[pt] = prog->GetShader(m_FogParams.mode, haveDomainShader, resetToNoFog); + if (resetToNoFog) + m_FogParams.mode = kFogDisabled; + } + } + + // Apply fog parameters if needed + if (m_FogParams.mode > kFogDisabled) + { + const int cbIndex = m_CBs.FindAndBindCB (kSLPropFogCB.index, kShaderFragment, k11FogConstantBufferBind, k11FogSize*16); + + m_CBs.SetCBConstant (cbIndex, k11FogColor*16, m_FogParams.color.GetPtr(), 16); + + float params[4]; + params[0] = m_FogParams.density * 1.2011224087f ; // density / sqrt(ln(2)) + params[1] = m_FogParams.density * 1.4426950408f; // density / ln(2) + if (m_FogParams.mode == kFogLinear) + { + float diff = m_FogParams.end - m_FogParams.start; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + params[2] = -invDiff; + params[3] = m_FogParams.end * invDiff; + } + else + { + params[2] = 0.0f; + params[3] = 0.0f; + } + m_CBs.SetCBConstant (cbIndex, k11FogParams*16, params, 16); + } + } + else + { + // Emulate fixed function + m_FFState.fogMode = m_FogParams.mode; + FixedFunctionProgramD3D11* program = GetFixedFunctionProgram11 (m_FFPrograms, m_FFState); + + shader[kShaderVertex] = program->GetVertexShader(); + shader[kShaderFragment] = program->GetPixelShader(); + + program->ApplyFFGpuProgram (m_BuiltinParamValues, m_CBs); + + m_BuiltinParamIndices[kShaderVertex] = &program->GetVPMatrices(); + } + + // Set D3D shaders + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) + { + if (m_ActiveShaders[pt] == shader[pt]) + continue; + switch (pt) { + case kShaderVertex: D3D11_CALL(ctx->VSSetShader ((ID3D11VertexShader*)shader[pt], NULL, 0)); break; + case kShaderFragment: D3D11_CALL(ctx->PSSetShader ((ID3D11PixelShader*)shader[pt], NULL, 0)); break; + case kShaderGeometry: D3D11_CALL(ctx->GSSetShader ((ID3D11GeometryShader*)shader[pt], NULL, 0)); break; + case kShaderHull: D3D11_CALL(ctx->HSSetShader ((ID3D11HullShader*)shader[pt], NULL, 0)); break; + case kShaderDomain: D3D11_CALL(ctx->DSSetShader ((ID3D11DomainShader*)shader[pt], NULL, 0)); break; + } + m_ActiveShaders[pt] = shader[pt]; + } + + // Set Unity built-in parameters + bool anyGpuIndexValid; + int gpuIndex[kShaderTypeCount]; + +#define SET_BUILTIN_MATRIX_BEGIN(idx) \ + anyGpuIndexValid = false; \ + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) { \ + int gi = m_BuiltinParamIndices[pt]->mat[idx].gpuIndex; \ + if (gi >= 0) anyGpuIndexValid = true; \ + gpuIndex[pt] = gi; \ + } \ + if (anyGpuIndexValid) + +#define SET_BUILTIN_MATRIX_END(idx,mtx) \ + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) { \ + int gi = gpuIndex[pt]; \ + if (gi >= 0) m_CBs.SetBuiltinCBConstant (m_BuiltinParamIndices[pt]->mat[idx].cbID, gi, mtx.GetPtr(), sizeof(mtx)); \ + } + + + // MVP matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatMVP) + { + Matrix4x4f mat; + MultiplyMatrices4x4 (&m_BuiltinParamValues.GetMatrixParam(kShaderMatProj), &m_TransformState.worldViewMatrix, &mat); + SET_BUILTIN_MATRIX_END(kShaderInstanceMatMVP,mat); + } + // MV matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatMV) + { + Matrix4x4f& mat = m_TransformState.worldViewMatrix; + SET_BUILTIN_MATRIX_END(kShaderInstanceMatMV,mat); + } + // Transpose MV matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatTransMV) + { + Matrix4x4f mat; + TransposeMatrix4x4 (&m_TransformState.worldViewMatrix, &mat); + SET_BUILTIN_MATRIX_END(kShaderInstanceMatTransMV,mat); + } + // Inverse transpose of MV matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatInvTransMV) + { + Matrix4x4f mat; + Matrix4x4f::Invert_Full (m_TransformState.worldViewMatrix, mat); + if (true) //@TODO m_VertexData.normalization == kNormalizationScale) + { + // Inverse transpose of modelview should be scaled by uniform + // normal scale (this will match state.matrix.invtrans.modelview + // and gl_NormalMatrix in OpenGL) + float scale = Magnitude (m_TransformState.worldMatrix.GetAxisX()); + mat.Get (0, 0) *= scale; + mat.Get (1, 0) *= scale; + mat.Get (2, 0) *= scale; + mat.Get (0, 1) *= scale; + mat.Get (1, 1) *= scale; + mat.Get (2, 1) *= scale; + mat.Get (0, 2) *= scale; + mat.Get (1, 2) *= scale; + mat.Get (2, 2) *= scale; + } + Matrix4x4f transposed; + TransposeMatrix4x4 (&mat, &transposed); + SET_BUILTIN_MATRIX_END(kShaderInstanceMatInvTransMV,transposed); + } + // M matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatM) + { + Matrix4x4f& mat = m_TransformState.worldMatrix; + SET_BUILTIN_MATRIX_END(kShaderInstanceMatM,mat); + } + // Inverse M matrix + SET_BUILTIN_MATRIX_BEGIN(kShaderInstanceMatInvM) + { + Matrix4x4f mat = m_TransformState.worldMatrix; + if (true) //@TODO m_VertexData.normalization == kNormalizationScale) + { + // Kill scale in the world matrix before inverse + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + mat.Get (0, 0) *= invScale; + mat.Get (1, 0) *= invScale; + mat.Get (2, 0) *= invScale; + mat.Get (0, 1) *= invScale; + mat.Get (1, 1) *= invScale; + mat.Get (2, 1) *= invScale; + mat.Get (0, 2) *= invScale; + mat.Get (1, 2) *= invScale; + mat.Get (2, 2) *= invScale; + } + Matrix4x4f inverseMat; + Matrix4x4f::Invert_General3D (mat, inverseMat); + SET_BUILTIN_MATRIX_END(kShaderInstanceMatInvM,inverseMat); + } + + // Set instance vector parameters + for (int i = 0; i < kShaderInstanceVecCount; ++i) + { + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) + { + int gi = m_BuiltinParamIndices[pt]->vec[i].gpuIndex; + if (gi >= 0) + { + m_CBs.SetBuiltinCBConstant (m_BuiltinParamIndices[pt]->vec[i].cbID, gi, m_BuiltinParamValues.GetInstanceVectorParam((ShaderBuiltinInstanceVectorParam)i).GetPtr(), m_BuiltinParamIndices[pt]->vec[i].dim*4); + } + } + } + + // Texture matrices for vertex shader + for( int i = 0; i < 8; ++i ) + { + const BuiltinShaderParamIndices::MatrixParamData* matParam = &m_BuiltinParamIndices[kShaderVertex]->mat[kShaderInstanceMatTexture0 + i]; + if (matParam->gpuIndex >= 0) + { + const Matrix4x4f& mat = m_TextureUnits[i].matrix; + m_CBs.SetBuiltinCBConstant (matParam->cbID, matParam->gpuIndex, mat.GetPtr(), sizeof(mat)); + } + } + + // Material properties + SetValuesFunctorD3D11 setValuesFunc(*this, m_CBs); + ApplyMaterialPropertyBlockValues(m_MaterialProperties, m_ActiveGpuProgram, m_ActiveGpuProgramParams, setValuesFunc); + + ///@TODO the rest + + m_CBs.UpdateBuffers (); +} + +static const D3D11_BLEND kBlendModeD3D11[] = { + D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_INV_DEST_COLOR, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_COLOR, + D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_SRC_ALPHA_SAT, D3D11_BLEND_INV_SRC_ALPHA, +}; +static const D3D11_BLEND kBlendModeAlphaD3D11[] = { + D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, + D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_SRC_ALPHA_SAT, D3D11_BLEND_INV_SRC_ALPHA, +}; +static const D3D11_BLEND_OP kBlendOpD3D11[] = { + D3D11_BLEND_OP_ADD, D3D11_BLEND_OP_SUBTRACT, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_BLEND_OP_MIN, D3D11_BLEND_OP_MAX, + /* ADD for all the logic op modes, used for fallback.*/ + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + D3D11_BLEND_OP_ADD, + +}; + +static const D3D11_LOGIC_OP kLogicOpD3D11[] = { + /* Zeroes for the blend modes */ + D3D11_LOGIC_OP_CLEAR, + D3D11_LOGIC_OP_CLEAR, + D3D11_LOGIC_OP_CLEAR, + D3D11_LOGIC_OP_CLEAR, + D3D11_LOGIC_OP_CLEAR, + /* Actual logic ops */ + D3D11_LOGIC_OP_CLEAR, + D3D11_LOGIC_OP_SET, + D3D11_LOGIC_OP_COPY, + D3D11_LOGIC_OP_COPY_INVERTED, + D3D11_LOGIC_OP_NOOP, + D3D11_LOGIC_OP_INVERT, + D3D11_LOGIC_OP_AND, + D3D11_LOGIC_OP_NAND, + D3D11_LOGIC_OP_OR, + D3D11_LOGIC_OP_NOR, + D3D11_LOGIC_OP_XOR, + D3D11_LOGIC_OP_EQUIV, + D3D11_LOGIC_OP_AND_REVERSE, + D3D11_LOGIC_OP_AND_INVERTED, + D3D11_LOGIC_OP_OR_REVERSE, + D3D11_LOGIC_OP_OR_INVERTED +}; + + + +DeviceBlendState* GfxDeviceD3D11::CreateBlendState (const GfxBlendState& state) +{ + std::pair<CachedBlendStates::iterator, bool> result = m_CachedBlendStates.insert(std::make_pair(state, DeviceBlendStateD3D11())); + if (!result.second) + return &result.first->second; + + DeviceBlendStateD3D11& d3dstate = result.first->second; + memcpy (&d3dstate.sourceState, &state, sizeof(d3dstate.sourceState)); + + // DX11.1 logic ops, falls through to ADD blendop if not supported + if(state.blendOp >= kBlendOpLogicalClear && state.blendOp <= kBlendOpLogicalOrInverted + && gGraphicsCaps.hasBlendLogicOps) + { + D3D11_BLEND_DESC1 desc; + memset (&desc, 0, sizeof(desc)); + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) + desc.AlphaToCoverageEnable = state.alphaToMask; + + desc.IndependentBlendEnable = FALSE; + + D3D11_RENDER_TARGET_BLEND_DESC1& dst = desc.RenderTarget[0]; + + dst.BlendEnable = false; + dst.LogicOpEnable = true; + + dst.LogicOp = kLogicOpD3D11[state.blendOp]; + + DWORD d3dmask = 0; + const UInt8 mask = state.renderTargetWriteMask; + if( mask & kColorWriteR ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_RED; + if( mask & kColorWriteG ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_GREEN; + if( mask & kColorWriteB ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_BLUE; + if( mask & kColorWriteA ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_ALPHA; + dst.RenderTargetWriteMask = d3dmask; + // GetD3D11_1Device cannot return null if we're running on DX11 and have gGraphicsCaps.hasBlendLogicOps, so no need to check. + + ID3D11BlendState1 *blendObj = NULL; + HRESULT hr = GetD3D11_1Device()->CreateBlendState1 (&desc, &blendObj); + d3dstate.deviceState = blendObj; + AssertIf(FAILED(hr)); + SetDebugNameD3D11 (d3dstate.deviceState, Format("BlendState-%d-%d", dst.SrcBlend, dst.DestBlend)); + + } + else + { + D3D11_BLEND_DESC desc; + memset (&desc, 0, sizeof(desc)); + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) + desc.AlphaToCoverageEnable = state.alphaToMask; + desc.IndependentBlendEnable = FALSE; + + D3D11_RENDER_TARGET_BLEND_DESC& dst = desc.RenderTarget[0]; + dst.BlendEnable = state.srcBlend != kBlendOne || state.dstBlend != kBlendZero || state.srcBlendAlpha != kBlendOne || state.dstBlendAlpha != kBlendZero; + dst.SrcBlend = kBlendModeD3D11[state.srcBlend]; + dst.DestBlend = kBlendModeD3D11[state.dstBlend]; + dst.BlendOp = kBlendOpD3D11[state.blendOp]; + dst.SrcBlendAlpha = kBlendModeAlphaD3D11[state.srcBlendAlpha]; + dst.DestBlendAlpha = kBlendModeAlphaD3D11[state.dstBlendAlpha]; + dst.BlendOpAlpha = kBlendOpD3D11[state.blendOpAlpha]; + + DWORD d3dmask = 0; + const UInt8 mask = state.renderTargetWriteMask; + if( mask & kColorWriteR ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_RED; + if( mask & kColorWriteG ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_GREEN; + if( mask & kColorWriteB ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_BLUE; + if( mask & kColorWriteA ) d3dmask |= D3D11_COLOR_WRITE_ENABLE_ALPHA; + dst.RenderTargetWriteMask = d3dmask; + HRESULT hr = GetD3D11Device()->CreateBlendState (&desc, &d3dstate.deviceState); + AssertIf(FAILED(hr)); + SetDebugNameD3D11 (d3dstate.deviceState, Format("BlendState-%d-%d", dst.SrcBlend, dst.DestBlend)); + + } + + + return &result.first->second; +} + + +DeviceDepthState* GfxDeviceD3D11::CreateDepthState(const GfxDepthState& state) +{ + std::pair<CachedDepthStates::iterator, bool> result = m_CachedDepthStates.insert(std::make_pair(state, DeviceDepthState())); + if (!result.second) + return &result.first->second; + + DeviceDepthState& st = result.first->second; + memcpy(&st.sourceState, &state, sizeof(st.sourceState)); + return &result.first->second; +} + +DeviceStencilState* GfxDeviceD3D11::CreateStencilState(const GfxStencilState& state) +{ + std::pair<CachedStencilStates::iterator, bool> result = m_CachedStencilStates.insert(std::make_pair(state, DeviceStencilState())); + if (!result.second) + return &result.first->second; + + DeviceStencilState& st = result.first->second; + memcpy(&st.sourceState, &state, sizeof(state)); + return &result.first->second; +} + + +DeviceRasterState* GfxDeviceD3D11::CreateRasterState(const GfxRasterState& state) +{ + std::pair<CachedRasterStates::iterator, bool> result = m_CachedRasterStates.insert(std::make_pair(state, DeviceRasterState())); + if (!result.second) + return &result.first->second; + + DeviceRasterState& st = result.first->second; + memcpy(&st.sourceState, &state, sizeof(state)); + return &result.first->second; +} + + +void GfxDeviceD3D11::SetBlendState(const DeviceBlendState* state, float alphaRef) +{ + if (state != m_CurrBlendState) + { + m_CurrBlendState = state; + DeviceBlendStateD3D11* devstate = (DeviceBlendStateD3D11*)state; + GetD3D11Context()->OMSetBlendState (devstate->deviceState, NULL, 0xFFFFFFFF); + } + + // alpha test + m_FFState.alphaTest = state->sourceState.alphaTest; + m_BuiltinParamValues.SetVectorParam(kShaderVecFFAlphaTestRef, Vector4f(alphaRef, alphaRef, alphaRef, alphaRef)); +} + + +void GfxDeviceD3D11::SetRasterState(const DeviceRasterState* state) +{ + if (m_CurrRasterState != state) + { + m_CurrRasterState = state; + m_CurrRSState = NULL; + } +} + + +void GfxDeviceD3D11::SetDepthState (const DeviceDepthState* state) +{ + if (m_CurrDepthState != state) + { + m_CurrDepthState = state; + m_CurrDSState = NULL; + } +} + +void GfxDeviceD3D11::SetStencilState(const DeviceStencilState* state, int stencilRef) +{ + if (m_CurrStencilState != state) + { + m_CurrStencilState = state; + m_CurrDSState = NULL; + } + m_StencilRef = stencilRef; +} + +void GfxDeviceD3D11::SetupDeferredSRGBWrite() +{ + if (m_SRGBWrite == m_ActualSRGBWrite) + return; + + // sRGB write is not just a render state on DX11; we need to actually rebind the render target views with + // a different format. Looks like some drivers do not optimize useless RT changes away, causing + // a lot of performance being wasted. So only apply sRGB write change when actually needed. + m_ActualSRGBWrite = m_SRGBWrite; + RebindActiveRenderTargets (&m_Textures); +} + +void GfxDeviceD3D11::SetSRGBWrite (bool enable) +{ + m_SRGBWrite = enable; +} + +bool GfxDeviceD3D11::GetSRGBWrite () +{ + return m_SRGBWrite; +} + +void GfxDeviceD3D11::DiscardContents (RenderSurfaceHandle& rs) +{ +# if UNITY_WINRT // WSA/WP8 guaranteed to have DX11.1 runtime, needed for DiscardResource + + if(!rs.IsValid()) + return; + + RenderSurfaceD3D11 *surf = reinterpret_cast<RenderSurfaceD3D11*>( rs.object ); + if (surf->m_Texture) + { + ID3D11DeviceContext1 * ctx = (ID3D11DeviceContext1 *)GetD3D11Context(); + DX11_CHK(ctx->DiscardResource(surf->m_Texture)); + } + +# endif +} + +GfxDevice* CreateD3D11GfxDevice() +{ + if( !InitializeD3D11() ) + return NULL; + + gGraphicsCaps.InitD3D11(); + + GfxDeviceD3D11* device = UNITY_NEW_AS_ROOT(GfxDeviceD3D11(), kMemGfxDevice, "D3D11GfxDevice", ""); + return device; +} + + +GfxDeviceD3D11::GfxDeviceD3D11() +{ + m_DynamicVBO = NULL; + InvalidateState(); + ResetFrameStats(); + + m_Renderer = kGfxRendererD3D11; + m_UsesOpenGLTextureCoords = false; + m_UsesHalfTexelOffset = false; + m_IsThreadable = true; + + m_MaxBufferedFrames = -1; // no limiting + + m_Viewport[0] = m_Viewport[1] = m_Viewport[2] = m_Viewport[3] = 0; + m_ScissorRect[0] = m_ScissorRect[1] = m_ScissorRect[2] = m_ScissorRect[3] = 0; + m_CurrTargetWidth = 0; + m_CurrTargetHeight = 0; + m_CurrWindowWidth = 0; + m_CurrWindowHeight = 0; + + m_InvertProjMatrix = false; + m_AppBackfaceMode = false; + m_UserBackfaceMode = false; + m_Wireframe = false; + m_Scissor = false; + m_SRGBWrite = false; + m_ActualSRGBWrite = false; + + m_FramebufferDepthFormat = kDepthFormat24; + + // constant buffer for fog params + m_CBs.SetCBInfo (kSLPropFogCB.index, k11FogSize*16); + + extern RenderSurfaceBase* DummyColorBackBuferD3D11(); + SetBackBufferColorSurface(DummyColorBackBuferD3D11()); + + extern RenderSurfaceBase* DummyDepthBackBuferD3D11(); + SetBackBufferDepthSurface(DummyDepthBackBuferD3D11()); +} + +GfxDeviceD3D11::~GfxDeviceD3D11() +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_WORKER + PluginsSetGraphicsDevice (GetD3D11Device(), kGfxRendererD3D11, kGfxDeviceEventShutdown); +#endif + + StreamOutSkinningInfo::CleanUp(); + +#if ENABLE_PROFILER + g_TimerQueriesD3D11.ReleaseAllQueries(); +#endif + + D3D11VBO::CleanupSharedBuffers(); + if( m_DynamicVBO ) + delete m_DynamicVBO; + for (FFProgramCacheD3D11::iterator it = m_FFPrograms.begin(); it != m_FFPrograms.end(); ++it) + delete it->second; + for (CachedBlendStates::iterator it = m_CachedBlendStates.begin(); it != m_CachedBlendStates.end(); ++it) + it->second.deviceState->Release(); + for (CachedDepthStencilStates::iterator it = m_CachedDepthStencilStates.begin(); it != m_CachedDepthStencilStates.end(); ++it) + it->second->Release(); + for (CachedFinalRasterStates::iterator it = m_CachedFinalRasterStates.begin(); it != m_CachedFinalRasterStates.end(); ++it) + it->second->Release(); + m_Imm.Cleanup(); + m_VertexDecls.Clear(); + m_CBs.Clear(); + m_Textures.ClearTextureResources(); + m_Resolves.Clear(); + DestroyD3D11Device(); + CleanupD3D11(); +} + + +void GfxDeviceD3D11::InvalidateState() +{ + g_ActiveInputLayoutD3D11 = NULL; + g_CurrentVSInputD3D11 = NULL; + g_ActiveTopologyD3D11 = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; + + m_TransformState.Invalidate(m_BuiltinParamValues); + + m_FogParams.Invalidate(); + + //m_State.Invalidate(*this); + m_Imm.Invalidate(); + //m_VSConstantCache.Invalidate(); + //m_PSConstantCache.Invalidate(); + + memset (&m_FFState, 0, sizeof(m_FFState)); + m_FFState.useUniformInsteadOfVertexColor = true; + + m_CurrBlendState = NULL; + m_CurrRasterState = NULL; + m_CurrDepthState = NULL; + m_CurrStencilState = NULL; + m_CurrRSState = NULL; + m_CurrDSState = NULL; + m_CurrStencilRef = -1; + + for (int pt = 0; pt < kShaderTypeCount; ++pt) + { + m_ActiveGpuProgram[pt] = NULL; + m_ActiveGpuProgramParams[pt] = NULL; + m_ActiveShaders[pt] = NULL; + for (int i = 0; i < kMaxSupportedTextureUnits; ++i) + { + m_ActiveTextures[pt][i].m_ID = -1; + m_ActiveSamplers[pt][i].m_ID = -1; + } + } + + m_Textures.InvalidateSamplers(); + m_CBs.InvalidateState(); + + ID3D11DeviceContext* ctx = GetD3D11Context(true); + if (ctx) + { + D3D11_CALL(ctx->VSSetShader (NULL, NULL, 0)); + D3D11_CALL(ctx->PSSetShader (NULL, NULL, 0)); + D3D11_CALL(ctx->GSSetShader (NULL, NULL, 0)); + D3D11_CALL(ctx->HSSetShader (NULL, NULL, 0)); + D3D11_CALL(ctx->DSSetShader (NULL, NULL, 0)); + } +} + + +void GfxDeviceD3D11::Clear (UInt32 clearFlags, const float color[4], float depth, int stencil) +{ + DX11_LOG_ENTER_FUNCTION("Clear(%d, (%.2f, %.2f, %.2f, %.2f), %.2f, %d)", clearFlags, color[0], color[1], color[2], color[3], depth, stencil); + SetupDeferredSRGBWrite (); + ID3D11DeviceContext* ctx = GetD3D11Context(); + + if ((clearFlags & kGfxClearColor) && g_D3D11CurrRT) + DX11_CHK(ctx->ClearRenderTargetView (g_D3D11CurrRT, color)); + if ((clearFlags & kGfxClearDepthStencil) && g_D3D11CurrDS) + { + UINT flags = 0; + if (clearFlags & kGfxClearDepth) + flags |= D3D11_CLEAR_DEPTH; + if (clearFlags & kGfxClearStencil) + flags |= D3D11_CLEAR_STENCIL; + DX11_CHK(ctx->ClearDepthStencilView (g_D3D11CurrDS, flags, depth, stencil)); + } +} + +void GfxDeviceD3D11::SetUserBackfaceMode( bool enable ) +{ + if (m_UserBackfaceMode != enable) + { + m_UserBackfaceMode = enable; + m_CurrRSState = NULL; + } +} + +void GfxDeviceD3D11::SetWireframe (bool wire) +{ + if (m_Wireframe != wire) + { + m_Wireframe = wire; + m_CurrRSState = NULL; + } +} + +bool GfxDeviceD3D11::GetWireframe() const +{ + return m_Wireframe; +} + + + +void GfxDeviceD3D11::SetInvertProjectionMatrix( bool enable ) +{ + if (m_InvertProjMatrix == enable) + return; + + m_InvertProjMatrix = enable; + + // When setting up "invert" flag, invert the matrix as well. + Matrix4x4f& m = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj); + m.Get(1,1) = -m.Get(1,1); + m.Get(1,3) = -m.Get(1,3); + m_TransformState.dirtyFlags |= TransformState::kProjDirty; + + m_CurrRSState = NULL; +} + +bool GfxDeviceD3D11::GetInvertProjectionMatrix() const +{ + return m_InvertProjMatrix; +} + +void GfxDeviceD3D11::SetWorldMatrix( const float matrix[16] ) +{ + CopyMatrix( matrix, m_TransformState.worldMatrix.GetPtr() ); + m_TransformState.dirtyFlags |= TransformState::kWorldDirty; +} + +void GfxDeviceD3D11::SetViewMatrix( const float matrix[16] ) +{ + m_TransformState.SetViewMatrix (matrix, m_BuiltinParamValues); +} + +void GfxDeviceD3D11::SetProjectionMatrix (const Matrix4x4f& matrix) +{ + Matrix4x4f& m = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj); + CopyMatrix (matrix.GetPtr(), m.GetPtr()); + CopyMatrix (matrix.GetPtr(), m_TransformState.projectionMatrixOriginal.GetPtr()); + CalculateDeviceProjectionMatrix (m, m_UsesOpenGLTextureCoords, m_InvertProjMatrix); + m_TransformState.dirtyFlags |= TransformState::kProjDirty; +} + +void GfxDeviceD3D11::GetMatrix( float outMatrix[16] ) const +{ + m_TransformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + CopyMatrix (m_TransformState.worldViewMatrix.GetPtr(), outMatrix); +} + +const float* GfxDeviceD3D11::GetWorldMatrix() const +{ + return m_TransformState.worldMatrix.GetPtr(); +} + +const float* GfxDeviceD3D11::GetViewMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatView).GetPtr(); +} + +const float* GfxDeviceD3D11::GetProjectionMatrix() const +{ + return m_TransformState.projectionMatrixOriginal.GetPtr(); +} + +const float* GfxDeviceD3D11::GetDeviceProjectionMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatProj).GetPtr(); +} + + +void GfxDeviceD3D11::SetNormalizationBackface( NormalizationMode mode, bool backface ) +{ + if (m_AppBackfaceMode != backface) + { + m_AppBackfaceMode = backface; + m_CurrRSState = NULL; + } +} + +void GfxDeviceD3D11::SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) +{ + DX11_LOG_ENTER_FUNCTION("SetFFLighting(%s, %s, %d)", GetDX11BoolString(on), GetDX11BoolString(separateSpecular), colorMaterial); + DebugAssert(colorMaterial!=kColorMatUnknown); + m_FFState.lightingEnabled = on; + m_FFState.specularEnabled = on && separateSpecular; + m_FFState.colorMaterial = colorMaterial; +} + +void GfxDeviceD3D11::SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) +{ + DX11_LOG_ENTER_FUNCTION("SetMaterial((%.2f, %.2f, %.2f, %.2f), (%.2f, %.2f, %.2f, %.2f), (%.2f, %.2f, %.2f, %.2f), (%.2f, %.2f, %.2f, %.2f), %.2f)", + ambient[0], ambient[1], ambient[2], ambient[3], + diffuse[0], diffuse[1], diffuse[2], diffuse[3], + specular[0], specular[1], specular[2], specular[3], + emissive[0], emissive[1], emissive[2], emissive[3], + shininess); + + float glshine = clamp01 (shininess) * 128.0f; + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatAmbient, Vector4f(ambient[0], ambient[1], ambient[2], 1.0F)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatDiffuse, Vector4f(diffuse)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatSpecular, Vector4f(specular[0], specular[1], specular[2], glshine)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatEmission, Vector4f(emissive[0], emissive[1], emissive[2], 1.0F)); +} + + +void GfxDeviceD3D11::SetColor( const float color[4] ) +{ + m_BuiltinParamValues.SetVectorParam(kShaderVecFFColor, Vector4f(color)); +} + + + +void GfxDeviceD3D11::SetViewport( int x, int y, int width, int height ) +{ + DX11_LOG_ENTER_FUNCTION("SetViewport(%d, %d, %d, %d)", x, y, width, height); + m_Viewport[0] = x; + m_Viewport[1] = y; + m_Viewport[2] = width; + m_Viewport[3] = height; + + D3D11_VIEWPORT view; + view.TopLeftX = x; + view.TopLeftY = y; + view.Width = width; + view.Height = height; + view.MinDepth = 0.0f; + view.MaxDepth = 1.0f; + ID3D11DeviceContext* ctx = GetD3D11Context(); + //@TODO + //if( !dev ) // happens on startup, when deleting all render textures + // return; + ctx->RSSetViewports (1, &view); +} + +void GfxDeviceD3D11::GetViewport( int* port ) const +{ + port[0] = m_Viewport[0]; + port[1] = m_Viewport[1]; + port[2] = m_Viewport[2]; + port[3] = m_Viewport[3]; +} + + +void GfxDeviceD3D11::SetScissorRect (int x, int y, int width, int height) +{ + DX11_LOG_ENTER_FUNCTION("SetScissorRect(%d, %d, %d, %d)", x, y, width, height); + if (!m_Scissor) + { + m_Scissor = true; + m_CurrRSState = NULL; + } + + m_ScissorRect[0] = x; + m_ScissorRect[1] = y; + m_ScissorRect[2] = width; + m_ScissorRect[3] = height; + + D3D11_RECT rc; + rc.left = x; + rc.top = y; + rc.right = x + width; + rc.bottom = y + height; + GetD3D11Context()->RSSetScissorRects (1, &rc); +} + +void GfxDeviceD3D11::DisableScissor() +{ + if (m_Scissor) + { + m_Scissor = false; + m_CurrRSState = NULL; + } +} + +bool GfxDeviceD3D11::IsScissorEnabled() const +{ + return m_Scissor; +} + +void GfxDeviceD3D11::GetScissorRect (int scissor[4]) const +{ + scissor[0] = m_ScissorRect[0]; + scissor[1] = m_ScissorRect[1]; + scissor[2] = m_ScissorRect[2]; + scissor[3] = m_ScissorRect[3]; +} + + +struct TextureCombiners11 +{ + const ShaderLab::TextureBinding* texEnvs; + int count; +}; + +bool GfxDeviceD3D11::IsCombineModeSupported( unsigned int combiner ) +{ + return true; +} + +TextureCombinersHandle GfxDeviceD3D11::CreateTextureCombiners (int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular) +{ + DX11_LOG_ENTER_FUNCTION("CreateTextureCombiners()"); + if (count > gGraphicsCaps.maxTexUnits) + return TextureCombinersHandle(NULL); + + TextureCombiners11* combiners = new TextureCombiners11(); + combiners->texEnvs = texEnvs; + combiners->count = count; + return TextureCombinersHandle(combiners); +} + +void GfxDeviceD3D11::DeleteTextureCombiners (TextureCombinersHandle& textureCombiners) +{ + DX11_LOG_ENTER_FUNCTION("DeleteTextureCombiners()"); + TextureCombiners11* combiners = OBJECT_FROM_HANDLE(textureCombiners,TextureCombiners11); + delete combiners; + textureCombiners.Reset(); +} + +void GfxDeviceD3D11::SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ) +{ + DX11_LOG_ENTER_FUNCTION("SetTextureCombinersThreadable()"); + TextureCombiners11* combiners = OBJECT_FROM_HANDLE(textureCombiners,TextureCombiners11); + Assert (combiners); + + const int count = std::min(combiners->count, gGraphicsCaps.maxTexUnits); + m_FFState.texUnitCount = count; + for (int i = 0; i < count; ++i) + { + const ShaderLab::TextureBinding& binding = combiners->texEnvs[i]; + ApplyTexEnvData (i, i, texEnvData[i]); + m_BuiltinParamValues.SetVectorParam ((BuiltinShaderVectorParam)(kShaderVecFFTextureEnvColor0 + i), texColors[i]); + m_FFState.texUnitColorCombiner[i] = binding.m_CombColor; + m_FFState.texUnitAlphaCombiner[i] = binding.m_CombAlpha; + } + + // unused textures + UInt32 mask = (1<<count)-1; + m_FFState.texUnitCube &= mask; + m_FFState.texUnit3D &= mask; + m_FFState.texUnitProjected &= mask; +} + +void GfxDeviceD3D11::SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ) +{ + DX11_LOG_ENTER_FUNCTION("SetTextureCombiners()"); + TextureCombiners11* combiners = OBJECT_FROM_HANDLE(textureCombiners,TextureCombiners11); + Assert(combiners); + + const int count = std::min(combiners->count, gGraphicsCaps.maxTexUnits); + + // Fill in arrays + TexEnvData* texEnvData; + ALLOC_TEMP (texEnvData, TexEnvData, count); + for (int i = 0; i < count; ++i) + { + const ShaderLab::TextureBinding& binding = combiners->texEnvs[i]; + ShaderLab::TexEnv *te = ShaderLab::GetTexEnvForBinding(binding, props); + Assert(te != NULL); + te->PrepareData (binding.m_TextureName.index, binding.m_MatrixName, props, &texEnvData[i]); + } + + Vector4f* texColors; + ALLOC_TEMP (texColors, Vector4f, count); + for (int i = 0; i < count; ++i) + { + const ShaderLab::TextureBinding& binding = combiners->texEnvs[i]; + texColors[i] = binding.GetTexColor().Get (props); + } + GfxDeviceD3D11::SetTextureCombinersThreadable (textureCombiners, texEnvData, texColors); +} + + + +void UnbindTextureD3D11 (TextureID texture) +{ + DX11_LOG_ENTER_FUNCTION("UnbindTextureD3D11(%d)", texture.m_ID); + GfxDeviceD3D11& device = static_cast<GfxDeviceD3D11&>(GetRealGfxDevice()); + ID3D11DeviceContext* ctx = GetD3D11Context(); + + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) + { + for (int i = 0; i < kMaxSupportedTextureUnits; ++i) + { + if (device.m_ActiveTextures[pt][i]==texture) + { + ID3D11ShaderResourceView* srv = NULL; + switch (pt) { + case kShaderVertex: ctx->VSSetShaderResources (i, 1, &srv); break; + case kShaderFragment: ctx->PSSetShaderResources (i, 1, &srv); break; + case kShaderGeometry: ctx->GSSetShaderResources (i, 1, &srv); break; + case kShaderHull: ctx->HSSetShaderResources (i, 1, &srv); break; + case kShaderDomain: ctx->DSSetShaderResources (i, 1, &srv); break; + default: AssertString("unknown shader type"); + } + device.m_ActiveTextures[pt][i].m_ID = -1; + } + if (device.m_ActiveSamplers[pt][i]==texture) + { + device.m_ActiveSamplers[pt][i].m_ID = -1; + } + } + } +} + + + +void GfxDeviceD3D11::SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) +{ + DebugAssertIf (dim < kTexDim2D || dim > kTexDimCUBE); + DebugAssertIf (unit < 0 || unit >= kMaxSupportedTextureUnits); + + // WP8 seems to have a driver bug (?) with occasionally losing texture state; can't do redundant bind early out here. + // Repros on Shadowgun flyby on Nokia Not For Sale. + #if !UNITY_WP8 + if (m_ActiveTextures[shaderType][unit] == texture && (samplerUnit >= 0 && m_ActiveSamplers[shaderType][samplerUnit] == texture)) + return; + #endif + + if (m_Textures.SetTexture (shaderType, unit, samplerUnit, texture, bias)) + { + m_Stats.AddUsedTexture(texture); + m_ActiveTextures[shaderType][unit] = texture; + if (samplerUnit >= 0) + m_ActiveSamplers[shaderType][samplerUnit] = texture; + } + + if (shaderType == kShaderFragment && unit < kMaxSupportedTextureCoords) + { + if (m_FFState.texUnitCount <= unit) + m_FFState.texUnitCount = unit+1; + + UInt32 mask = 1<<unit; + if (dim==kTexDimCUBE) + m_FFState.texUnitCube |= mask; + else + m_FFState.texUnitCube &= ~mask; + if (dim==kTexDim3D) + m_FFState.texUnit3D |= mask; + else + m_FFState.texUnit3D &= ~mask; + } +} + + +void GfxDeviceD3D11::SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]) +{ + Assert (unit >= 0 && unit < kMaxSupportedTextureCoords); + + TextureSourceD3D11 texSource = texGen == kTexGenDisabled ? kTexSourceUV0 : static_cast<TextureSourceD3D11>(texGen + kTexSourceUV7); + m_FFState.texUnitSources = m_FFState.texUnitSources & ~(15<<(unit*4)) | (UInt64(texSource)<<(unit*4)); + + if (identity) + m_TextureUnits[unit].matrix.SetIdentity(); + else + CopyMatrix (matrix, m_TextureUnits[unit].matrix.GetPtr()); + + // Detect if we have a projective texture matrix + m_FFState.texUnitProjected &= ~(1<<unit); + if (!identity && dim==kTexDim2D) + { + if (matrix[3] != 0.0f || matrix[7] != 0.0f || matrix[11] != 0.0f || matrix[15] != 1.0f) + m_FFState.texUnitProjected |= (1<<unit); + } +} + +void GfxDeviceD3D11::SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + UnbindTextureD3D11 (texture); + m_Textures.SetTextureParams (texture, texDim, filter, wrap, anisoLevel, hasMipMap, colorSpace); +} + + + +void GfxDeviceD3D11::SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]) +{ + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) + { + m_ActiveGpuProgram[pt] = programs[pt]; + m_ActiveGpuProgramParams[pt] = params[pt]; + } + + // Apply programmable shader parameters + if (m_ActiveGpuProgram[kShaderVertex] && m_ActiveGpuProgram[kShaderFragment]) + { + for (int pt = kShaderVertex; pt < kShaderTypeCount; ++pt) + { + if (m_ActiveGpuProgram[pt]) + { + DebugAssert (!m_ActiveGpuProgram[pt] || m_ActiveGpuProgram[pt]->GetImplType() == pt); + D3D11CommonShader* prog = static_cast<D3D11CommonShader*>(m_ActiveGpuProgram[pt]); + m_ActiveGpuProgram[pt]->ApplyGpuProgram (*params[pt], paramsBuffer[pt]); + } + } + } +} + + +bool GfxDeviceD3D11::IsShaderActive( ShaderType type ) const +{ + return (m_ActiveGpuProgram[type] != 0); +} + +void GfxDeviceD3D11::DestroySubProgram( ShaderLab::SubProgram* subprogram ) +{ + delete subprogram; +} + +void GfxDeviceD3D11::SetConstantBufferInfo (int id, int size) +{ + m_CBs.SetCBInfo (id, size); +} + +void GfxDeviceD3D11::DisableLights( int startLight ) +{ + startLight = std::min (startLight, gGraphicsCaps.maxLights); + m_FFState.lightCount = startLight; + + const Vector4f black(0.0F, 0.0F, 0.0F, 0.0F); + const Vector4f zpos(0.0F, 0.0F, 1.0F, 0.0F); + for (int i = startLight; i < gGraphicsCaps.maxLights; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Position + i), zpos); + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + i), black); + } +} + +void GfxDeviceD3D11::SetLight( int light, const GfxVertexLight& data) +{ + if (light >= gGraphicsCaps.maxLights) + return; + SetupVertexLightParams (light, data); +} + +void GfxDeviceD3D11::SetAmbient( const float ambient[4] ) +{ + m_BuiltinParamValues.SetVectorParam(kShaderVecLightModelAmbient, Vector4f(ambient)); +} + + +void GfxDeviceD3D11::EnableFog (const GfxFogParams& fog) +{ + DebugAssert (fog.mode > kFogDisabled); + m_FogParams = fog; + + //@TODO: fog DXBC patching not implemented for 9.x level; and something still wrong with FF shaders in 9.x level as well + // (e.g. crashes WARP). Just disable fog for now. + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0) + m_FogParams.mode = kFogDisabled; +} + +void GfxDeviceD3D11::DisableFog() +{ + m_FogParams.mode = kFogDisabled; + m_FogParams.density = 0.0f; +} + + +VBO* GfxDeviceD3D11::CreateVBO() +{ + VBO* vbo = new D3D11VBO(); + OnCreateVBO(vbo); + return vbo; +} + +void GfxDeviceD3D11::DeleteVBO( VBO* vbo ) +{ + OnDeleteVBO(vbo); + delete vbo; +} + +DynamicVBO& GfxDeviceD3D11::GetDynamicVBO() +{ + if( !m_DynamicVBO ) { + m_DynamicVBO = new DynamicD3D11VBO( 1024 * 1024, 65536 ); // initial 1 MiB VB, 64 KiB IB + } + return *m_DynamicVBO; +} + +/* +void GfxDeviceD3D11::ResetDynamicResources() +{ + delete m_DynamicVBO; + m_DynamicVBO = NULL; + + CleanupEventQueries (); + + for( ListIterator<D3D11VBO*> i = m_DynamicVBOs.begin(); i != m_DynamicVBOs.end(); ++i ) + { + D3D11VBO* vbo = *i; + vbo->ResetDynamicVB(); + } +} +*/ + +GfxDeviceD3D11& GetD3D11GfxDevice() +{ + GfxDevice& device = GetRealGfxDevice(); + DebugAssert(device.GetRenderer() == kGfxRendererD3D11); + return static_cast<GfxDeviceD3D11&>(device); +} + + +ID3D11InputLayout* GetD3D11VertexDeclaration (const ChannelInfoArray& channels) +{ + GfxDevice& device = GetRealGfxDevice(); + DebugAssert(device.GetRenderer() == kGfxRendererD3D11); + GfxDeviceD3D11* deviceD3D = static_cast<GfxDeviceD3D11*>( &device ); + return deviceD3D->GetVertexDecls().GetVertexDecl (channels, g_CurrentVSInputD3D11); +} + +const InputSignatureD3D11* GetD3D11InputSignature (void* code, unsigned length) +{ + GfxDevice& device = GetRealGfxDevice(); + DebugAssert(device.GetRenderer() == kGfxRendererD3D11); + GfxDeviceD3D11* deviceD3D = static_cast<GfxDeviceD3D11*>( &device ); + return deviceD3D->GetVertexDecls().GetShaderInputSignature (code, length); +} + +ConstantBuffersD3D11& GetD3D11ConstantBuffers (GfxDevice& device) +{ + Assert (device.GetRenderer() == kGfxRendererD3D11); + GfxDeviceD3D11& deviceD3D = static_cast<GfxDeviceD3D11&>(device); + return deviceD3D.GetConstantBuffers(); +} + +TexturesD3D11& GetD3D11Textures (GfxDevice& device) +{ + Assert (device.GetRenderer() == kGfxRendererD3D11); + GfxDeviceD3D11& deviceD3D = static_cast<GfxDeviceD3D11&>(device); + return deviceD3D.GetTextures(); +} + + +// ---------- render textures + + +RenderSurfaceHandle CreateRenderColorSurfaceD3D11( TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, TexturesD3D11& textures); +RenderSurfaceHandle CreateRenderDepthSurfaceD3D11( TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags, TexturesD3D11& textures); +void DestroyRenderSurfaceD3D11 (RenderSurfaceHandle& rsHandle, TexturesD3D11& textures); +bool SetRenderTargetD3D11 (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, int* outTargetWidth, int* outTargetHeight, TexturesD3D11* textures); +RenderSurfaceHandle GetActiveRenderColorSurfaceD3D11(int index); +RenderSurfaceHandle GetActiveRenderDepthSurfaceD3D11(); +RenderSurfaceHandle GetActiveRenderColorSurfaceBBD3D11(); + +RenderSurfaceHandle GfxDeviceD3D11::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) +{ + DX11_LOG_ENTER_FUNCTION("CreateRenderColorSurface(%d, %d, %d, %d, %d)", textureID.m_ID, width, height, format, createFlags); + return CreateRenderColorSurfaceD3D11 (textureID, width, height, samples, depth, dim, createFlags, format, m_Textures); +} +RenderSurfaceHandle GfxDeviceD3D11::CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) +{ + DX11_LOG_ENTER_FUNCTION("CreateRenderDepthSurface(%d, %d, %d, %d, %d, %d)", textureID.m_ID, width, height, dim, depthFormat, createFlags); + return CreateRenderDepthSurfaceD3D11 (textureID, width, height, samples, dim, depthFormat, createFlags, m_Textures); +} +void GfxDeviceD3D11::DestroyRenderSurface (RenderSurfaceHandle& rs) +{ + DX11_LOG_ENTER_FUNCTION("DestroyRenderSurface()"); + DestroyRenderSurfaceD3D11 (rs, m_Textures); +} +void GfxDeviceD3D11::SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face) +{ + DX11_LOG_ENTER_FUNCTION("SetRenderTargets(%i, c0=%p, d=%p, mip=%i, f=%i)", count, colorHandles[0].object, depthHandle.object, mipLevel, face); + SetupDeferredSRGBWrite (); + m_CurrTargetWidth = m_CurrWindowWidth; + m_CurrTargetHeight = m_CurrWindowHeight; + if (SetRenderTargetD3D11 (count, colorHandles, depthHandle, mipLevel, face, &m_CurrTargetWidth, &m_CurrTargetHeight, &m_Textures)) + { + // changing render target might mean different color clear flags; so reset current state + m_CurrBlendState = NULL; + } +} + +void GfxDeviceD3D11::ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle) +{ + DX11_LOG_ENTER_FUNCTION("ResolveDepthIntoTexture(%p, %p)", colorHandle.object, depthHandle.object); + RenderSurfaceD3D11* depthSurf = reinterpret_cast<RenderSurfaceD3D11*>(depthHandle.object); + TexturesD3D11::D3D11Texture* destTexture = m_Textures.GetTexture (depthSurf->textureID); + DebugAssert (destTexture); + if (!destTexture) + return; + DebugAssert (g_D3D11CurrDepthRT); + if (!g_D3D11CurrDepthRT || !g_D3D11CurrDepthRT->m_Texture) + return; + + GetD3D11Context()->CopyResource (destTexture->m_Texture, g_D3D11CurrDepthRT->m_Texture); +} + + +void GfxDeviceD3D11::ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) +{ + Assert (srcHandle.IsValid()); + Assert (dstHandle.IsValid()); + RenderColorSurfaceD3D11* src = reinterpret_cast<RenderColorSurfaceD3D11*>(srcHandle.object); + RenderColorSurfaceD3D11* dst = reinterpret_cast<RenderColorSurfaceD3D11*>(dstHandle.object); + if (!src->colorSurface || !dst->colorSurface) + { + WarningString("RenderTexture: Resolving non-color surfaces."); + return; + } + if (src->dim != dst->dim) + { + WarningString("RenderTexture: Resolving surfaces of different types."); + return; + } + if (src->format != dst->format) + { + WarningString("RenderTexture: Resolving surfaces of different formats."); + return; + } + if (src->width != dst->width || src->height != dst->height) + { + WarningString("RenderTexture: Resolving surfaces of different sizes."); + return; + } + + ID3D11DeviceContext* ctx = GetD3D11Context(); + if (src->samples <= 1 && dst->samples <= 1) + { + ctx->CopyResource (dst->m_Texture, src->m_Texture); + } + else + { + extern DXGI_FORMAT kD3D11RenderTextureFormatsNorm[kRTFormatCount]; + ctx->ResolveSubresource (dst->m_Texture, 0, src->m_Texture, 0, kD3D11RenderTextureFormatsNorm[dst->format]); + if ((dst->flags & kSurfaceCreateMipmap) && + (dst->flags & kSurfaceCreateAutoGenMips) && + dst->m_SRViewForMips) + { + ctx->GenerateMips (dst->m_SRViewForMips); + } + } +} + + +RenderSurfaceHandle GfxDeviceD3D11::GetActiveRenderColorSurface(int index) +{ + DX11_LOG_ENTER_FUNCTION("GetActiveRenderColorSurface(%d)", index); + return GetActiveRenderColorSurfaceD3D11(index); +} +RenderSurfaceHandle GfxDeviceD3D11::GetActiveRenderDepthSurface() +{ + DX11_LOG_ENTER_FUNCTION("GetActiveRenderDepthSurface"); + return GetActiveRenderDepthSurfaceD3D11(); +} +void GfxDeviceD3D11::SetSurfaceFlags (RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags) +{ +} + + +// ---------- uploading textures + +void GfxDeviceD3D11::UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + DX11_LOG_ENTER_FUNCTION("UploadTexture2D(%d, %d, <srcData>, %d, %d, %d, %d, %d, %d, %d)", + texture.m_ID, dimension, width, height, format, mipCount, uploadFlags, skipMipLevels, usageMode); + UnbindTextureD3D11 (texture); + m_Textures.UploadTexture2D (texture, dimension, srcData, width, height, format, mipCount, uploadFlags, skipMipLevels, usageMode, colorSpace); +} +void GfxDeviceD3D11::UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + DX11_LOG_ENTER_FUNCTION("UploadTextureSubData2D(%d, <srcData>, ...)", texture.m_ID) + m_Textures.UploadTextureSubData2D (texture, srcData, mipLevel, x, y, width, height, format, colorSpace); +} +void GfxDeviceD3D11::UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + DX11_LOG_ENTER_FUNCTION("UploadTextureCube(%d, <srcData>, ...)", texture.m_ID) + UnbindTextureD3D11 (texture); + m_Textures.UploadTextureCube (texture, srcData, faceDataSize, size, format, mipCount, uploadFlags, colorSpace); +} +void GfxDeviceD3D11::UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + DX11_LOG_ENTER_FUNCTION("UploadTexture3D(%d, <srcData>, ...)", texture.m_ID) + UnbindTextureD3D11 (texture); + m_Textures.UploadTexture3D (texture, srcData, width, height, depth, format, mipCount, uploadFlags); +} +void GfxDeviceD3D11::DeleteTexture( TextureID texture ) +{ + DX11_LOG_ENTER_FUNCTION("DeleteTexture(%d)", texture.m_ID) + UnbindTextureD3D11 (texture); + m_Textures.DeleteTexture (texture); +} + + +// ---------- context + +GfxDevice::PresentMode GfxDeviceD3D11::GetPresentMode() +{ + return kPresentBeforeUpdate; +} + +void GfxDeviceD3D11::BeginFrame() +{ + DX11_LOG_OUTPUT("*****************************************"); + DX11_LOG_OUTPUT("*****************************************"); + DX11_LOG_OUTPUT("*****************************************"); + DX11_LOG_ENTER_FUNCTION("BeginFrame()"); + DX11_MARK_FRAME_BEGIN(); + m_InsideFrame = true; + + #if UNITY_WINRT + ActivateD3D11BackBuffer(this); // ?!- + #endif +} + + + +void GfxDeviceD3D11::EndFrame() +{ + DX11_LOG_ENTER_FUNCTION("EndFrame()"); + DX11_MARK_FRAME_END(); + m_InsideFrame = false; +} + +bool GfxDeviceD3D11::IsValidState() +{ + return true; +} + +void GfxDeviceD3D11::PresentFrame() +{ + #if !UNITY_WP8 + IDXGISwapChain* swapChain = GetD3D11SwapChain(); + if (swapChain) + swapChain->Present (GetD3D11SyncInterval(), 0); + #endif + m_CBs.NewFrame(); +} + +void GfxDeviceD3D11::FinishRendering() +{ + // not needed on D3D +} + + + +// ---------- immediate mode rendering + +// we break very large immediate mode submissions into multiple batches internally +const int kMaxImmediateVerticesPerDraw = 8192; + + +ImmediateModeD3D11::ImmediateModeD3D11() +: m_VB(NULL) +, m_VBUsedBytes(0) +, m_VBStartVertex(0) +{ +} + +ImmediateModeD3D11::~ImmediateModeD3D11() +{ + Assert (!m_VB); +} + +void ImmediateModeD3D11::Cleanup() +{ + REGISTER_EXTERNAL_GFX_DEALLOCATION(m_VB); + SAFE_RELEASE(m_VB); + m_VBUsedBytes = 0; +} + + +void ImmediateModeD3D11::Invalidate() +{ + m_Vertices.clear(); + memset( &m_Current, 0, sizeof(m_Current) ); + m_HadColor = false; +} + +void GfxDeviceD3D11::ImmediateVertex( float x, float y, float z ) +{ + // If the current batch is becoming too large, internally end it and begin it again. + size_t currentSize = m_Imm.m_Vertices.size(); + if( currentSize >= kMaxImmediateVerticesPerDraw - 4 ) + { + GfxPrimitiveType mode = m_Imm.m_Mode; + // For triangles, break batch when multiple of 3's is reached. + if( mode == kPrimitiveTriangles && currentSize % 3 == 0 ) + { + bool hadColor = m_Imm.m_HadColor; + ImmediateEnd(); + ImmediateBegin( mode ); + m_Imm.m_HadColor = hadColor; + } + // For other primitives, break on multiple of 4's. + // NOTE: This won't quite work for triangle strips, but we'll just pretend + // that will never happen. + else if( mode != kPrimitiveTriangles && currentSize % 4 == 0 ) + { + bool hadColor = m_Imm.m_HadColor; + ImmediateEnd(); + ImmediateBegin( mode ); + m_Imm.m_HadColor = hadColor; + } + } + Vector3f& vert = m_Imm.m_Current.vertex; + vert.x = x; + vert.y = y; + vert.z = z; + m_Imm.m_Vertices.push_back( m_Imm.m_Current ); +} + +void GfxDeviceD3D11::ImmediateNormal( float x, float y, float z ) +{ + m_Imm.m_Current.normal.x = x; + m_Imm.m_Current.normal.y = y; + m_Imm.m_Current.normal.z = z; +} + +void GfxDeviceD3D11::ImmediateColor( float r, float g, float b, float a ) +{ + m_Imm.m_Current.color.Set (ColorRGBAf(r,g,b,a)); + m_Imm.m_HadColor = true; +} + +void GfxDeviceD3D11::ImmediateTexCoordAll( float x, float y, float z ) +{ + for( int i = 0; i < 8; ++i ) + { + Vector3f& uv = m_Imm.m_Current.texCoords[i]; + uv.x = x; + uv.y = y; + uv.z = z; + } +} + +void GfxDeviceD3D11::ImmediateTexCoord( int unit, float x, float y, float z ) +{ + if( unit < 0 || unit >= 8 ) + { + ErrorString( "Invalid unit for texcoord" ); + return; + } + Vector3f& uv = m_Imm.m_Current.texCoords[unit]; + uv.x = x; + uv.y = y; + uv.z = z; +} + +void GfxDeviceD3D11::ImmediateBegin( GfxPrimitiveType type ) +{ + m_Imm.m_Mode = type; + m_Imm.m_Vertices.clear(); + m_Imm.m_HadColor = false; +} + +bool GfxDeviceD3D11::ImmediateEndSetup() +{ + if( m_Imm.m_Vertices.empty() ) + return false; + + HRESULT hr = S_OK; + ID3D11DeviceContext* ctx = GetD3D11Context(); + + // vertex buffer + const int kImmediateVBSize = kMaxImmediateVerticesPerDraw * sizeof(ImmediateVertexD3D11); + if (!m_Imm.m_VB) + { + ID3D11Device* dev = GetD3D11Device(); + D3D11_BUFFER_DESC desc; + desc.ByteWidth = kImmediateVBSize; + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + hr = dev->CreateBuffer (&desc, NULL, &m_Imm.m_VB); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(m_Imm.m_VB,kImmediateVBSize,this); + SetDebugNameD3D11 (m_Imm.m_VB, "VertexBufferImmediate"); + m_Imm.m_VBUsedBytes = 0; + m_Imm.m_VBStartVertex = 0; + } + + const ImmediateVertexD3D11* vb = &m_Imm.m_Vertices[0]; + const int vertexCount = m_Imm.m_Vertices.size(); + const int vertexDataSize = vertexCount * sizeof(vb[0]); + D3D11_MAPPED_SUBRESOURCE mapped; + + if (m_Imm.m_VBUsedBytes + vertexDataSize > kImmediateVBSize) + { + D3D11_CALL_HR(ctx->Map (m_Imm.m_VB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped)); + m_Imm.m_VBUsedBytes = 0; + } + else + { + D3D11_CALL_HR(ctx->Map (m_Imm.m_VB, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped)); + } + m_Imm.m_VBStartVertex = m_Imm.m_VBUsedBytes / sizeof(vb[0]); + + memcpy ((UInt8*)mapped.pData + m_Imm.m_VBUsedBytes, vb, vertexDataSize); + D3D11_CALL_HR(ctx->Unmap (m_Imm.m_VB, 0)); + m_Imm.m_VBUsedBytes += vertexDataSize; + + UINT strides = sizeof(vb[0]); + UINT offsets = 0; + D3D11_CALL (ctx->IASetVertexBuffers(0, 1, &m_Imm.m_VB, &strides, &offsets)); + + + m_FFState.useUniformInsteadOfVertexColor = !m_Imm.m_HadColor; + if (!IsShaderActive(kShaderVertex)) + { + UInt64 textureSources = m_FFState.texUnitSources; + for (int i = 0; i < gGraphicsCaps.maxTexCoords; ++i) + { + UInt32 source = (textureSources >> (i*4)) & 0xF; + // In immediate mode, each texcoord binds to it's own stage, unless we have texgen + // on some of them. + if (source <= kTexSourceUV7) + { + textureSources = textureSources & ~(0xFUL<<i*4) | (UInt64(kTexSourceUV0+i) << i*4); + } + } + m_FFState.texUnitSources = textureSources; + } + + BeforeDrawCall (true); + return true; +} + + +void GfxDeviceD3D11::ImmediateEndDraw() +{ + ID3D11DeviceContext* ctx = GetD3D11Context(); + int vertexCount = m_Imm.m_Vertices.size(); + + // vertex layout + ID3D11InputLayout* inputLayout = m_VertexDecls.GetImmVertexDecl (g_CurrentVSInputD3D11); + if (inputLayout) + { + SetInputLayoutD3D11 (ctx, inputLayout); + if (SetTopologyD3D11 (m_Imm.m_Mode, *this, ctx)) + { + + // draw + switch (m_Imm.m_Mode) + { + case kPrimitiveTriangles: + D3D11_CALL(ctx->Draw (vertexCount, m_Imm.m_VBStartVertex)); + m_Stats.AddDrawCall (vertexCount / 3, vertexCount); + break; + case kPrimitiveTriangleStripDeprecated: + D3D11_CALL(ctx->Draw (vertexCount, m_Imm.m_VBStartVertex)); + m_Stats.AddDrawCall (vertexCount - 2, vertexCount); + break; + case kPrimitiveQuads: + GetDynamicVBO(); // ensure it's created + D3D11_CALL(ctx->IASetIndexBuffer (m_DynamicVBO->GetQuadsIB(), DXGI_FORMAT_R16_UINT, 0)); + D3D11_CALL(ctx->DrawIndexed (vertexCount/4*6, 0, m_Imm.m_VBStartVertex)); + m_Stats.AddDrawCall( vertexCount / 4 * 2, vertexCount ); + break; + case kPrimitiveLines: + D3D11_CALL(ctx->Draw (vertexCount, m_Imm.m_VBStartVertex)); + m_Stats.AddDrawCall( vertexCount / 2, vertexCount ); + break; + default: + AssertString("ImmediateEnd: unknown draw mode"); + } + } + } + + // clear vertices + m_Imm.m_Vertices.clear(); +} + + +void GfxDeviceD3D11::ImmediateEnd() +{ + if (ImmediateEndSetup()) + ImmediateEndDraw(); +} + + +typedef SmartComPointer<ID3D11RenderTargetView> RTVPointer; +typedef SmartComPointer<ID3D11Resource> ResourcePointer; +typedef SmartComPointer<ID3D11Texture2D> Texture2DPointer; + + +bool GfxDeviceD3D11::CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ) +{ + DX11_LOG_ENTER_FUNCTION("CaptureScreenshot(%d, %d, %dx%d)", left, bottom, width, height); + HRESULT hr; + ID3D11DeviceContext* ctx = GetD3D11Context(); + + SetupDeferredSRGBWrite (); + + RenderSurfaceHandle currColorSurface = GetActiveRenderColorSurfaceBBD3D11(); + RenderColorSurfaceD3D11* colorSurf = reinterpret_cast<RenderColorSurfaceD3D11*>(currColorSurface.object); + if (!colorSurf) + return false; + + RTVPointer rtView; + ctx->OMGetRenderTargets (1, &rtView, NULL); + if (!rtView) + return false; + + ResourcePointer rtRes; + rtView->GetResource (&rtRes); + if (!rtRes) + return false; + + D3D11_RESOURCE_DIMENSION rtType; + rtRes->GetType (&rtType); + if (rtType != D3D11_RESOURCE_DIMENSION_TEXTURE2D) + return false; + + ID3D11Texture2D* rtTex = static_cast<ID3D11Texture2D*>((ID3D11Resource*)rtRes); + D3D11_TEXTURE2D_DESC rtDesc; + rtTex->GetDesc (&rtDesc); + if (rtDesc.Format != DXGI_FORMAT_R8G8B8A8_UNORM && + rtDesc.Format != DXGI_FORMAT_R8G8B8A8_TYPELESS && + rtDesc.Format != DXGI_FORMAT_R8G8B8A8_UNORM_SRGB && + rtDesc.Format != DXGI_FORMAT_B8G8R8A8_UNORM) + return false; + + ID3D11Device* dev = GetD3D11Device(); + ResolveTexturePool::Entry* resolved = NULL; + if (rtDesc.SampleDesc.Count != 1) + { + resolved = m_Resolves.GetResolveTexture (rtDesc.Width, rtDesc.Height, colorSurf->format, m_SRGBWrite); + if (!resolved) + return false; + + ctx->ResolveSubresource (resolved->texture, 0, rtTex, 0, rtDesc.Format); + rtTex = resolved->texture; + } + + Texture2DPointer stagingTex; + D3D11_TEXTURE2D_DESC stagingDesc; + stagingDesc.Width = width; + stagingDesc.Height = height; + stagingDesc.MipLevels = 1; + stagingDesc.ArraySize = 1; + + bool useRGBA = rtDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM || + rtDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS || + rtDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + + stagingDesc.Format = useRGBA ? DXGI_FORMAT_R8G8B8A8_UNORM : DXGI_FORMAT_B8G8R8A8_UNORM; + stagingDesc.SampleDesc.Count = 1; + stagingDesc.SampleDesc.Quality = 0; + stagingDesc.Usage = D3D11_USAGE_STAGING; + stagingDesc.BindFlags = 0; + stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + stagingDesc.MiscFlags = 0; + hr = dev->CreateTexture2D (&stagingDesc, NULL, &stagingTex); + if (FAILED(hr)) + return false; + SetDebugNameD3D11 (stagingTex, Format("CaptureScreenshot-Texture2D-%dx%d", width, height)); + + D3D11_BOX srcBox; + srcBox.left = left; + srcBox.right = left + width; +#if UNITY_WP8 + /* In WP8 m_CurrTargetHeight seems not to match + * ID3D11DeviceContext height */ + srcBox.top = bottom; + srcBox.bottom = bottom + height; +#else + srcBox.top = m_CurrTargetHeight - (bottom + height); + srcBox.bottom = m_CurrTargetHeight - (bottom); +#endif + srcBox.front = 0; + srcBox.back = 1; + ctx->CopySubresourceRegion (stagingTex, 0, 0, 0, 0, rtTex, 0, &srcBox); + + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (stagingTex, 0, D3D11_MAP_READ, 0, &mapped); + if (FAILED(hr)) + return false; + + rgba32 += (height-1) * width * sizeof(UInt32); + const UInt8* src = (const UInt8*)mapped.pData; + for (int y = 0; y < height; ++y) + { + if (useRGBA) + { + memcpy (rgba32, src, width*4); + } + else + { + for (int x = 0; x < width*4; x +=4) + { + rgba32[x] = src[x + 2]; + rgba32[x + 1] = src[x + 1]; + rgba32[x + 2] = src[x + 0]; + rgba32[x + 3] = src[x + 3]; + } + } + + rgba32 -= width * sizeof(UInt32); + src += mapped.RowPitch; + } + + + ctx->Unmap (stagingTex, 0); + return true; +} + + + +bool GfxDeviceD3D11::ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) +{ + Assert (image.GetFormat() == kTexFormatARGB32 || image.GetFormat() == kTexFormatRGB24); + + SetupDeferredSRGBWrite (); + + HRESULT hr; + ID3D11DeviceContext* ctx = GetD3D11Context(); + + RenderSurfaceHandle currColorSurface = GetActiveRenderColorSurfaceBBD3D11(); + RenderColorSurfaceD3D11* colorSurf = reinterpret_cast<RenderColorSurfaceD3D11*>(currColorSurface.object); + if (!colorSurf) + return false; + + RTVPointer rtView; + ctx->OMGetRenderTargets (1, &rtView, NULL); + if (!rtView) + return false; + + ResourcePointer rtRes; + rtView->GetResource (&rtRes); + if (!rtRes) + return false; + + D3D11_RESOURCE_DIMENSION rtType; + rtRes->GetType (&rtType); + if (rtType != D3D11_RESOURCE_DIMENSION_TEXTURE2D) + return false; + + ID3D11Texture2D* rtTex = static_cast<ID3D11Texture2D*>((ID3D11Resource*)rtRes); + D3D11_TEXTURE2D_DESC rtDesc; + rtTex->GetDesc (&rtDesc); + if (rtDesc.Format != DXGI_FORMAT_R8G8B8A8_UNORM && rtDesc.Format != DXGI_FORMAT_R8G8B8A8_TYPELESS && rtDesc.Format != DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) + return false; + + ID3D11Device* dev = GetD3D11Device(); + ResolveTexturePool::Entry* resolved = NULL; + if (rtDesc.SampleDesc.Count != 1) + { + resolved = m_Resolves.GetResolveTexture (rtDesc.Width, rtDesc.Height, colorSurf->format, m_SRGBWrite); + if (!resolved) + return false; + + ctx->ResolveSubresource (resolved->texture, 0, rtTex, 0, rtDesc.Format); + rtTex = resolved->texture; + } + + Texture2DPointer stagingTex; + D3D11_TEXTURE2D_DESC stagingDesc; + stagingDesc.Width = width; + stagingDesc.Height = height; + stagingDesc.MipLevels = 1; + stagingDesc.ArraySize = 1; + stagingDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + stagingDesc.SampleDesc.Count = 1; + stagingDesc.SampleDesc.Quality = 0; + stagingDesc.Usage = D3D11_USAGE_STAGING; + stagingDesc.BindFlags = 0; + stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + stagingDesc.MiscFlags = 0; + hr = dev->CreateTexture2D (&stagingDesc, NULL, &stagingTex); + if (FAILED(hr)) + return false; + SetDebugNameD3D11 (stagingTex, Format("Readback-Texture2D-%dx%d", width, height)); + + D3D11_BOX srcBox; + srcBox.left = left; + srcBox.right = left + width; + srcBox.top = m_CurrTargetHeight - (bottom + height); + srcBox.bottom = m_CurrTargetHeight - (bottom); + srcBox.front = 0; + srcBox.back = 1; + ctx->CopySubresourceRegion (stagingTex, 0, 0, 0, 0, rtTex, 0, &srcBox); + + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (stagingTex, 0, D3D11_MAP_READ, 0, &mapped); + if (FAILED(hr)) + return false; + + const UInt8* src = (const UInt8*)mapped.pData; + + if (image.GetFormat() == kTexFormatARGB32) + { + for (int y = height-1; y >= 0; --y) + { + const UInt32* srcPtr = (const UInt32*)src; + UInt32* dstPtr = (UInt32*)(image.GetRowPtr(destY+y) + destX * 4); + for (int x = 0; x < width; ++x) + { + UInt32 abgrCol = *srcPtr; + UInt32 bgraCol = ((abgrCol & 0x00FFFFFF) << 8) | ((abgrCol&0xFF000000) >> 24); + *dstPtr = bgraCol; + ++srcPtr; + ++dstPtr; + } + src += mapped.RowPitch; + } + } + else if (image.GetFormat() == kTexFormatRGB24) + { + for (int y = height-1; y >= 0; --y) + { + const UInt32* srcPtr = (const UInt32*)src; + UInt8* dstPtr = image.GetRowPtr(destY+y) + destX * 3; + for (int x = 0; x < width; ++x) + { + UInt32 abgrCol = *srcPtr; + dstPtr[0] = (abgrCol & 0x000000FF); + dstPtr[1] = (abgrCol & 0x0000FF00) >> 8; + dstPtr[2] = (abgrCol & 0x00FF0000) >> 16; + ++srcPtr; + dstPtr += 3; + } + src += mapped.RowPitch; + } + } + ctx->Unmap (stagingTex, 0); + return true; +} + +void GfxDeviceD3D11::GrabIntoRenderTexture(RenderSurfaceHandle rtHandle, RenderSurfaceHandle rd, int x, int y, int width, int height) +{ + DX11_LOG_ENTER_FUNCTION("GrabIntoRenderTexture(%p, %p, %d, %d, %dx%d)", rtHandle.object, rd.object, x, y, width, height); + if (!rtHandle.IsValid()) + return; + if (!g_D3D11CurrColorRT) + return; + RenderSurfaceHandle currColorSurface = GetActiveRenderColorSurfaceBBD3D11(); + RenderColorSurfaceD3D11* colorSurf = reinterpret_cast<RenderColorSurfaceD3D11*>(currColorSurface.object); + if (!colorSurf) + return; + const bool sRGB = (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) ? (colorSurf->flags & kSurfaceCreateSRGB) : false; + + RenderColorSurfaceD3D11* renderTexture = reinterpret_cast<RenderColorSurfaceD3D11*>(rtHandle.object); + TexturesD3D11::D3D11Texture* texturePointer = m_Textures.GetTexture (renderTexture->textureID); + if (!texturePointer) + return; + + SetupDeferredSRGBWrite (); + + ID3D11Resource* srcResource = g_D3D11CurrColorRT->m_Texture; + ID3D11Texture2D* srcTex = static_cast<ID3D11Texture2D*>(srcResource); + D3D11_TEXTURE2D_DESC rtDesc; + srcTex->GetDesc (&rtDesc); + Assert (rtDesc.Width == colorSurf->width && rtDesc.Height == colorSurf->height); + + ID3D11DeviceContext* ctx = GetD3D11Context(); + ResolveTexturePool::Entry* resolved = NULL; + if (rtDesc.SampleDesc.Count != 1) + { + resolved = m_Resolves.GetResolveTexture (rtDesc.Width, rtDesc.Height, colorSurf->format, sRGB); + if (!resolved) + return; + + ctx->ResolveSubresource (resolved->texture, 0, srcResource, 0, GetRenderTextureFormat(colorSurf->format, sRGB)); + srcResource = resolved->texture; + } + + ID3D11Texture2D* dstTex = static_cast<ID3D11Texture2D*>(texturePointer->m_Texture); + D3D11_TEXTURE2D_DESC dstDesc; + dstTex->GetDesc (&dstDesc); + + if (GetBPPFromDXGIFormat(rtDesc.Format) == GetBPPFromDXGIFormat(dstDesc.Format)) + { + D3D11_BOX srcBox; + srcBox.left = x; + srcBox.right = x + width; + srcBox.top = m_CurrTargetHeight - (y + height); + srcBox.bottom = m_CurrTargetHeight - (y); + srcBox.front = 0; + srcBox.back = 1; + + ctx->CopySubresourceRegion (texturePointer->m_Texture, 0, 0, 0, 0, srcResource, 0, &srcBox); + } + else + { + // formats not compatible; have to draw a quad into destination, sampling the source texture + RenderColorSurfaceD3D11* currRT = g_D3D11CurrColorRT; + int oldTargetHeight = m_CurrTargetHeight; + int oldView[4]; + GetViewport (oldView); + bool oldScissor = IsScissorEnabled(); + int oldScissorRect[4]; + GetScissorRect (oldScissorRect); + + SetViewport (0, 0, dstDesc.Width, dstDesc.Height); + DisableScissor (); + + RenderSurfaceHandle currColor = GetActiveRenderColorSurface(0); + RenderSurfaceHandle currDepth = GetActiveRenderDepthSurface(); + SetRenderTargets (1, &rtHandle, rd, 0, kCubeFaceUnknown); + + const float u0 = x / float(rtDesc.Width); + const float u1 = (x+width) / float(rtDesc.Width); + const float v0 = (rtDesc.Height - y) / float(rtDesc.Height); + const float v1 = (rtDesc.Height - (y+height)) / float(rtDesc.Height); + + ID3D11ShaderResourceView* srv = currRT ? currRT->m_SRView : NULL; + if (resolved) + srv = resolved->srv; + + DrawQuad (u0, v0, u1, v1, 0.0f, srv); + SetRenderTargets (1, &currColor, currDepth, 0, kCubeFaceUnknown); + SetViewport (oldView[0], oldView[1], oldView[2], oldView[3]); + if (oldScissor) + SetScissorRect (oldScissorRect[0], oldScissorRect[1], oldScissorRect[2], oldScissorRect[3]); + } +} + +void GfxDeviceD3D11::DrawQuad (float u0, float v0, float u1, float v1, float z, ID3D11ShaderResourceView* texture) +{ + // Can't use DeviceMVPMatricesState since that tries to get potentially threaded device. + // We need to access our own device directly. + Matrix4x4f m_World, m_View, m_Proj; + CopyMatrix(GetViewMatrix(), m_View.GetPtr()); + CopyMatrix(GetWorldMatrix(), m_World.GetPtr()); + CopyMatrix(GetProjectionMatrix(), m_Proj.GetPtr()); + + // Can't use LoadFullScreenOrthoMatrix for the same reason. + Matrix4x4f matrix; + matrix.SetOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 100.0f); + SetProjectionMatrix (matrix); + SetViewMatrix (Matrix4x4f::identity.GetPtr()); // implicitly sets world to identity + + DisableFog (); + + SetFFLighting (false, false, kColorMatDisabled); + DisableLights (0); + + ShaderLab::SubProgram* programs[kShaderTypeCount] = {0}; + GraphicsHelper::SetShaders (*this, programs, NULL); + + GfxBlendState blendDesc; + DeviceBlendState* blendState = CreateBlendState(blendDesc); + SetBlendState (blendState, 0.0f); + + GfxDepthState depthDesc; depthDesc.depthWrite = false; depthDesc.depthFunc = kFuncAlways; + DeviceDepthState* depthState = CreateDepthState(depthDesc); + SetDepthState (depthState); + + GfxRasterState rasterDesc; rasterDesc.cullMode = kCullOff; + DeviceRasterState* rasterState = CreateRasterState(rasterDesc); + SetRasterState (rasterState); + + ShaderLab::TextureBinding texEnv; + texEnv.m_TextureName.index = kShaderTexEnvWhite | ShaderLab::FastPropertyName::kBuiltinTexEnvMask; + TextureCombinersHandle combiners = CreateTextureCombiners (1, &texEnv, NULL, false, false); + + // Can't call SetTextureCombiners here since that expects to be called on main thread, + // and we might be on the device thread here. So do the work manually and call + // SetTextureCombinersThreadable. + + TexEnvData texEnvData; + memset(&texEnvData, 0, sizeof(texEnvData)); + texEnvData.textureID = TextureID(); + texEnvData.texDim = kTexDim2D; + texEnvData.texGen = kTexGenDisabled; + texEnvData.identityMatrix = true; + Vector4f texColors; + texColors.Set(1,1,1,1); + SetTextureCombinersThreadable (combiners, &texEnvData, &texColors); + + ImmediateBegin (kPrimitiveQuads); + ImmediateTexCoord(0,u0,v0,0.0f); ImmediateVertex (0.0f, 0.0f, z); + ImmediateTexCoord(0,u0,v1,0.0f); ImmediateVertex (0.0f, 1.0f, z); + ImmediateTexCoord(0,u1,v1,0.0f); ImmediateVertex (1.0f, 1.0f, z); + ImmediateTexCoord(0,u1,v0,0.0f); ImmediateVertex (1.0f, 0.0f, z); + if (ImmediateEndSetup ()) + { + ID3D11SamplerState* sampler = m_Textures.GetSampler (kSamplerPointClamp); + Assert (sampler); + ID3D11DeviceContext* ctx = GetD3D11Context(); + ctx->PSSetShaderResources (0, 1, &texture); + ctx->PSSetSamplers (0, 1, &sampler); + m_Textures.InvalidateSampler (kShaderFragment, 0); + m_ActiveTextures[kShaderFragment][0].m_ID = -1; + m_ActiveSamplers[kShaderFragment][0].m_ID = -1; + + ImmediateEndDraw (); + + ID3D11ShaderResourceView* nullTex = NULL; + ctx->PSSetShaderResources (0, 1, &nullTex); + } + + // restore matrices + SetViewMatrix(m_View.GetPtr()); + SetWorldMatrix(m_World.GetPtr()); + SetProjectionMatrix(m_Proj); +} + +void* GfxDeviceD3D11::GetNativeGfxDevice() +{ + return GetD3D11Device(); +} + +void* GfxDeviceD3D11::GetNativeTexturePointer(TextureID id) +{ + TexturesD3D11::D3D11Texture* tex = m_Textures.GetTexture(id); + if (!tex) + return NULL; + return tex->m_Texture; +} + +intptr_t GfxDeviceD3D11::CreateExternalTextureFromNative(intptr_t nativeTex) +{ + return m_Textures.RegisterNativeTexture((ID3D11ShaderResourceView*)nativeTex); +} + +void GfxDeviceD3D11::UpdateExternalTextureFromNative(TextureID tex, intptr_t nativeTex) +{ + m_Textures.UpdateNativeTexture(tex, (ID3D11ShaderResourceView*)nativeTex); +} + + +#if ENABLE_PROFILER + +void GfxDeviceD3D11::BeginProfileEvent (const char* name) +{ + if (g_D3D11BeginEventFunc) + { + wchar_t wideName[100]; + UTF8ToWide (name, wideName, 100); + g_D3D11BeginEventFunc (0, wideName); + } +} + +void GfxDeviceD3D11::EndProfileEvent () +{ + if (g_D3D11EndEventFunc) + { + g_D3D11EndEventFunc (); + } +} + +GfxTimerQuery* GfxDeviceD3D11::CreateTimerQuery() +{ + Assert(gGraphicsCaps.hasTimerQuery); + return g_TimerQueriesD3D11.CreateTimerQuery(); +} + +void GfxDeviceD3D11::DeleteTimerQuery(GfxTimerQuery* query) +{ + delete query; +} + +void GfxDeviceD3D11::BeginTimerQueries() +{ + if(!gGraphicsCaps.hasTimerQuery) + return; + + g_TimerQueriesD3D11.BeginTimerQueries(); + } + +void GfxDeviceD3D11::EndTimerQueries() +{ + if(!gGraphicsCaps.hasTimerQuery) + return; + + g_TimerQueriesD3D11.EndTimerQueries(); +} + +#endif // ENABLE_PROFILER + + +// -------- editor only functions + +#if UNITY_EDITOR + +void GfxDeviceD3D11::SetAntiAliasFlag (bool aa) +{ +} + + +void GfxDeviceD3D11::DrawUserPrimitives (GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride) +{ + if (vertexCount == 0) + return; + + Assert(vertexCount <= 60000); // TODO: handle this by multi-batching + + Assert(data && vertexCount >= 0 && vertexChannels != 0); + + DynamicD3D11VBO& vbo = static_cast<DynamicD3D11VBO&>(GetDynamicVBO()); + + void* vbPtr; + //@TODO: hack to pass kDrawTriangleStrip, but we only need that to determine if we need index buffer or not (we don't) + if (!vbo.GetChunk(vertexChannels, vertexCount, 0, DynamicVBO::kDrawTriangleStrip, &vbPtr, NULL)) + return; + memcpy (vbPtr, data, vertexCount * stride); + vbo.ReleaseChunk (vertexCount, 0); + + vbo.DrawChunkUserPrimitives (type); +} + +int GfxDeviceD3D11::GetCurrentTargetAA() const +{ + return 0; //@TODO +} + +GfxDeviceWindow* GfxDeviceD3D11::CreateGfxWindow (HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias) +{ + return new D3D11Window(window, width, height, depthFormat, antiAlias); +} + +static ID3D11Texture2D* FindD3D11TextureByID (TextureID tid) +{ + GfxDevice& device = GetRealGfxDevice(); + if (device.GetRenderer() != kGfxRendererD3D11) + return NULL; + GfxDeviceD3D11& dev = static_cast<GfxDeviceD3D11&>(device); + TexturesD3D11::D3D11Texture* basetex = dev.GetTextures().GetTexture(tid); + if (!basetex || !basetex->m_Texture) + return NULL; + D3D11_RESOURCE_DIMENSION dim = D3D11_RESOURCE_DIMENSION_UNKNOWN; + basetex->m_Texture->GetType(&dim); + if (dim != D3D11_RESOURCE_DIMENSION_TEXTURE2D) + return NULL; + return static_cast<ID3D11Texture2D*>(basetex->m_Texture); +} + +HDC AcquireHDCForTextureD3D11 (TextureID tid, int& outWidth, int& outHeight) +{ + ID3D11Texture2D* tex = FindD3D11TextureByID (tid); + if (!tex) + return NULL; + + D3D11_TEXTURE2D_DESC desc; + tex->GetDesc (&desc); + outWidth = desc.Width; + outHeight = desc.Height; + + IDXGISurface1* dxgiSurface = NULL; + tex->QueryInterface(__uuidof(IDXGISurface1), (void**)(&dxgiSurface)); + HDC dc = NULL; + if (dxgiSurface) + { + dxgiSurface->GetDC (false, &dc); + dxgiSurface->Release(); + } + return dc; +} + +void ReleaseHDCForTextureD3D11 (TextureID tid, HDC dc) +{ + ID3D11Texture2D* tex = FindD3D11TextureByID (tid); + if (!tex) + return; + + IDXGISurface1* dxgiSurface = NULL; + tex->QueryInterface(__uuidof(IDXGISurface1), (void**)(&dxgiSurface)); + if (dxgiSurface) + { + dxgiSurface->ReleaseDC(NULL); + dxgiSurface->Release(); + } +} + +#endif // UNITY_EDITOR + + +int GfxDeviceD3D11::GetCurrentTargetWidth() const +{ + return m_CurrTargetWidth; +} + +int GfxDeviceD3D11::GetCurrentTargetHeight() const +{ + return m_CurrTargetHeight; +} + +void GfxDeviceD3D11::SetCurrentTargetSize(int width, int height) +{ + m_CurrTargetWidth = width; + m_CurrTargetHeight = height; +} + +void GfxDeviceD3D11::SetCurrentWindowSize(int width, int height) +{ + m_CurrWindowWidth = m_CurrTargetWidth = width; + m_CurrWindowHeight = m_CurrTargetHeight = height; +} + + +// ---------------------------------------------------------------------- + +void GfxDeviceD3D11::SetComputeBuffer11 (ShaderType shaderType, int unit, ComputeBufferID bufferHandle) +{ + ComputeBuffer11* buffer = m_Textures.GetComputeBuffer(bufferHandle); + ID3D11ShaderResourceView* srv = buffer ? buffer->srv : NULL; + ID3D11DeviceContext* ctx = GetD3D11Context(); + switch (shaderType) { + case kShaderVertex: ctx->VSSetShaderResources (unit, 1, &srv); break; + case kShaderFragment: ctx->PSSetShaderResources (unit, 1, &srv); break; + case kShaderGeometry: ctx->GSSetShaderResources (unit, 1, &srv); break; + case kShaderHull: ctx->HSSetShaderResources (unit, 1, &srv); break; + case kShaderDomain: ctx->DSSetShaderResources (unit, 1, &srv); break; + default: AssertString("unknown shader type"); + } + m_ActiveTextures[shaderType][unit].m_ID = 0; +} + + +void GfxDeviceD3D11::SetComputeBufferData (ComputeBufferID bufferHandle, const void* data, size_t size) +{ + if (!data || !size) + return; + ComputeBuffer11* buffer = m_Textures.GetComputeBuffer(bufferHandle); + if (!buffer || !buffer->buffer) + return; + + ID3D11DeviceContext* ctx = GetD3D11Context(); + D3D11_BOX box; + box.left = 0; + box.top = 0; + box.front = 0; + box.right = size; + box.bottom = 1; + box.back = 1; + ctx->UpdateSubresource (buffer->buffer, 0, &box, data, 0, 0); +} + + +void GfxDeviceD3D11::GetComputeBufferData (ComputeBufferID bufferHandle, void* dest, size_t destSize) +{ + if (!dest || !destSize) + return; + ComputeBuffer11* buffer = m_Textures.GetComputeBuffer(bufferHandle); + if (!buffer || !buffer->buffer) + return; + + ID3D11DeviceContext* ctx = GetD3D11Context(); + + ID3D11Buffer* cpuBuffer = NULL; + D3D11_BUFFER_DESC desc; + ZeroMemory (&desc, sizeof(desc)); + buffer->buffer->GetDesc (&desc); + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + desc.Usage = D3D11_USAGE_STAGING; + desc.BindFlags = 0; + desc.MiscFlags = 0; + HRESULT hr = GetD3D11Device()->CreateBuffer(&desc, NULL, &cpuBuffer); + if (FAILED(hr)) + return; + SetDebugNameD3D11 (cpuBuffer, Format("CSGetData-Staging-%d", desc.ByteWidth)); + + ctx->CopyResource (cpuBuffer, buffer->buffer); + + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map (cpuBuffer, 0, D3D11_MAP_READ, 0, &mapped); + if (SUCCEEDED(hr)) + { + memcpy (dest, mapped.pData, destSize); + ctx->Unmap (cpuBuffer, 0); + } + SAFE_RELEASE (cpuBuffer); +} + + + +void GfxDeviceD3D11::CopyComputeBufferCount (ComputeBufferID srcBuffer, ComputeBufferID dstBuffer, UInt32 dstOffset) +{ + ComputeBuffer11* src = m_Textures.GetComputeBuffer(srcBuffer); + if (!src || !src->uav) + return; + ComputeBuffer11* dst = m_Textures.GetComputeBuffer(dstBuffer); + if (!dst || !dst->buffer) + return; + ID3D11DeviceContext* ctx = GetD3D11Context(); + ctx->CopyStructureCount (dst->buffer, dstOffset, src->uav); +} + + + +void GfxDeviceD3D11::SetRandomWriteTargetTexture (int index, TextureID tid) +{ + void SetRandomWriteTargetTextureD3D11 (int index, TextureID tid); + SetRandomWriteTargetTextureD3D11 (index, tid); +} + +void GfxDeviceD3D11::SetRandomWriteTargetBuffer (int index, ComputeBufferID bufferHandle) +{ + void SetRandomWriteTargetBufferD3D11 (int index, ComputeBufferID bufferHandle); + SetRandomWriteTargetBufferD3D11 (index, bufferHandle); +} + +void GfxDeviceD3D11::ClearRandomWriteTargets () +{ + void ClearRandomWriteTargetsD3D11 (TexturesD3D11* textures); + ClearRandomWriteTargetsD3D11 (&m_Textures); +} + + +ComputeProgramHandle GfxDeviceD3D11::CreateComputeProgram (const UInt8* code, size_t codeSize) +{ + ComputeProgramHandle cpHandle; + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level11_0) + return cpHandle; + + ID3D11Device* dev = GetD3D11Device(); + HRESULT hr; + ID3D11ComputeShader* cs = NULL; + hr = dev->CreateComputeShader (code, codeSize, NULL, &cs); + if (FAILED(hr)) + return cpHandle; + SetDebugNameD3D11 (cs, Format("ComputeShader-%d", (int)codeSize)); + + cpHandle.object = cs; + return cpHandle; +} + +void GfxDeviceD3D11::DestroyComputeProgram (ComputeProgramHandle& cpHandle) +{ + if (!cpHandle.IsValid()) + return; + + ID3D11ComputeShader* cs = reinterpret_cast<ID3D11ComputeShader*>(cpHandle.object); + SAFE_RELEASE(cs); + cpHandle.Reset(); +} + +void GfxDeviceD3D11::CreateComputeConstantBuffers (unsigned count, const UInt32* sizes, ConstantBufferHandle* outCBs) +{ + ID3D11Device* dev = GetD3D11Device(); + HRESULT hr; + + D3D11_BUFFER_DESC desc; + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + desc.StructureByteStride = 0; + for (unsigned i = 0; i < count; ++i) + { + desc.ByteWidth = sizes[i]; + ID3D11Buffer* cb = NULL; + hr = dev->CreateBuffer (&desc, NULL, &cb); + if (cb) + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(cb,sizes[i],this); + Assert (SUCCEEDED(hr)); + outCBs[i].object = cb; + + SetDebugNameD3D11 (cb, Format("CSConstantBuffer-%d-%d", i, sizes[i])); + } +} + +void GfxDeviceD3D11::DestroyComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs) +{ + for (unsigned i = 0; i < count; ++i) + { + ID3D11Buffer* cb = reinterpret_cast<ID3D11Buffer*>(cbs[i].object); + REGISTER_EXTERNAL_GFX_DEALLOCATION(cb); + SAFE_RELEASE(cb); + cbs[i].Reset(); + } +} + + +void GfxDeviceD3D11::CreateComputeBuffer (ComputeBufferID id, size_t count, size_t stride, UInt32 flags) +{ + ComputeBuffer11 buffer; + buffer.buffer = NULL; + buffer.srv = NULL; + buffer.uav = NULL; + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0) + return; + + ID3D11Device* dev = GetD3D11Device(); + HRESULT hr; + + // buffer + D3D11_BUFFER_DESC bufferDesc; + memset (&bufferDesc, 0, sizeof(bufferDesc)); + bufferDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level11_0) + bufferDesc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS; + bufferDesc.ByteWidth = count * stride; + if (flags & kCBFlagDrawIndirect) + bufferDesc.MiscFlags = (gGraphicsCaps.d3d11.featureLevel >= kDX11Level11_0 ? D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS : 0); + else if (flags & kCBFlagRaw) + bufferDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; + else + bufferDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + bufferDesc.StructureByteStride = stride; + bufferDesc.Usage = D3D11_USAGE_DEFAULT; + hr = dev->CreateBuffer (&bufferDesc, NULL, &buffer.buffer); + if (buffer.buffer) + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(buffer.buffer,count * stride,this); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (buffer.buffer, Format("ComputeBuffer-%dx%d", (int)count, (int)stride)); + + // unordered access view, only on DX11+ HW + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level11_0 && !(flags & kCBFlagDrawIndirect)) + { + D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc; + memset (&uavDesc, 0, sizeof(uavDesc)); + uavDesc.Format = (flags & kCBFlagRaw) ? DXGI_FORMAT_R32_TYPELESS : DXGI_FORMAT_UNKNOWN; + uavDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; + uavDesc.Buffer.FirstElement = 0; + uavDesc.Buffer.NumElements = count; + uavDesc.Buffer.Flags = flags & kCBFlagTypeMask; + hr = dev->CreateUnorderedAccessView (buffer.buffer, &uavDesc, &buffer.uav); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (buffer.uav, Format("ComputeBuffer-UAV-%dx%d", (int)count, (int)stride)); + + // shader resource view + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; + memset (&srvDesc, 0, sizeof(srvDesc)); + if (flags & kCBFlagRaw) + { + srvDesc.Format = DXGI_FORMAT_R32_TYPELESS; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX; + srvDesc.BufferEx.FirstElement = 0; + srvDesc.BufferEx.NumElements = count; + srvDesc.BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW; + } + else + { + srvDesc.Format = DXGI_FORMAT_UNKNOWN; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; + srvDesc.Buffer.FirstElement = 0; + srvDesc.Buffer.NumElements = count; + } + hr = dev->CreateShaderResourceView (buffer.buffer, &srvDesc, &buffer.srv); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (buffer.uav, Format("ComputeBuffer-SRV-%dx%d", (int)count, (int)stride)); + } + + m_Textures.AddComputeBuffer (id, buffer); +} + + +void GfxDeviceD3D11::DestroyComputeBuffer (ComputeBufferID handle) +{ + if (!handle.IsValid()) + return; + + ComputeBuffer11* buffer = m_Textures.GetComputeBuffer(handle); + if (buffer) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(buffer->buffer); + SAFE_RELEASE(buffer->buffer); + SAFE_RELEASE(buffer->srv); + SAFE_RELEASE(buffer->uav); + } + m_Textures.RemoveComputeBuffer (handle); +} + + +void GfxDeviceD3D11::UpdateComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs, UInt32 cbDirty, size_t dataSize, const UInt8* data, const UInt32* cbSizes, const UInt32* cbOffsets, const int* bindPoints) +{ + ID3D11DeviceContext* ctx = GetD3D11Context(); + + // go over constant buffers in use + for (unsigned i = 0; i < count; ++i) + { + if (bindPoints[i] < 0) + continue; // CB not going to be used, no point in updating it + + ID3D11Buffer* cb = reinterpret_cast<ID3D11Buffer*>(cbs[i].object); + + // update buffer if dirty + UInt32 dirtyMask = (1<<i); + if (cbDirty & dirtyMask) + { + D3D11_MAPPED_SUBRESOURCE mapped; + HRESULT hr; + hr = ctx->Map (cb, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped); + Assert (SUCCEEDED(hr)); + memcpy (mapped.pData, data + cbOffsets[i], cbSizes[i]); + ctx->Unmap (cb, 0); + } + + // bind it + ctx->CSSetConstantBuffers (bindPoints[i], 1, &cb); + } +} + + + +void GfxDeviceD3D11::UpdateComputeResources ( + unsigned texCount, const TextureID* textures, const int* texBindPoints, + unsigned samplerCount, const unsigned* samplers, + unsigned inBufferCount, const ComputeBufferID* inBuffers, const int* inBufferBindPoints, + unsigned outBufferCount, const ComputeBufferID* outBuffers, const TextureID* outTextures, const UInt32* outBufferBindPoints) +{ + ID3D11DeviceContext* ctx = GetD3D11Context(); + + for (unsigned i = 0; i < texCount; ++i) + { + if (textures[i].m_ID == 0) + continue; + TexturesD3D11::D3D11Texture* tex = m_Textures.GetTexture (textures[i]); + if (!tex) + continue; + + // if texture is bound as render target: unbind it (set backbuffer as RT) + if ((g_D3D11CurrColorRT && g_D3D11CurrColorRT->m_Texture == tex->m_Texture) || + (g_D3D11CurrDepthRT && g_D3D11CurrDepthRT->m_Texture == tex->m_Texture)) + { + RenderSurfaceHandle defaultColor = GetBackBufferColorSurface(); + RenderSurfaceHandle defaultDepth = GetBackBufferDepthSurface(); + SetRenderTargets (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown); + } + ctx->CSSetShaderResources (texBindPoints[i] & 0xFFFF, 1, &tex->m_SRV); + unsigned samplerBindPoint = (texBindPoints[i] >> 16) & 0xFFFF; + if (samplerBindPoint != 0xFFFF) + { + ID3D11SamplerState* smp = m_Textures.GetSampler(tex->m_Sampler); + ctx->CSSetSamplers (samplerBindPoint, 1, &smp); + } + } + + for (unsigned i = 0; i < samplerCount; ++i) + { + BuiltinSamplerState type = (BuiltinSamplerState)((samplers[i] & 0xFFFF0000) >> 16); + unsigned bindPoint = samplers[i] & 0xFFFF; + ID3D11SamplerState* smp = m_Textures.GetSampler (type); + Assert (smp); + ctx->CSSetSamplers (bindPoint, 1, &smp); + } + + for (unsigned i = 0; i < inBufferCount; ++i) + { + ComputeBuffer11* buffer = m_Textures.GetComputeBuffer(inBuffers[i]); + if (!buffer) + continue; + ctx->CSSetShaderResources (inBufferBindPoints[i], 1, &buffer->srv); + } + + for (unsigned i = 0; i < outBufferCount; ++i) + { + ID3D11UnorderedAccessView* uav = NULL; + if (outBufferBindPoints[i] & 0x80000000) + { + // UAV comes from texture + if (outTextures[i].m_ID == 0) + continue; + TexturesD3D11::D3D11Texture* tex = m_Textures.GetTexture (outTextures[i]); + if (!tex || !tex->m_UAV) + continue; + uav = tex->m_UAV; + } + else + { + // UAV is raw buffer + if (!outBuffers[i].IsValid()) + continue; + ComputeBuffer11* buffer = m_Textures.GetComputeBuffer(outBuffers[i]); + if (!buffer) + continue; + uav = buffer->uav; + } + UINT uavInitialCounts[] = { -1 }; // keeps current offsets for Appendable/Consumeable UAVs + ctx->CSSetUnorderedAccessViews (outBufferBindPoints[i] & 0x7FFFFFFF, 1, &uav, uavInitialCounts); + } +} + + + +void GfxDeviceD3D11::DispatchComputeProgram (ComputeProgramHandle cpHandle, unsigned threadsX, unsigned threadsY, unsigned threadsZ) +{ + if (!cpHandle.IsValid()) + return; + + ID3D11DeviceContext* ctx = GetD3D11Context(); + ID3D11ComputeShader* cs = reinterpret_cast<ID3D11ComputeShader*>(cpHandle.object); + ctx->CSSetShader (cs, NULL, 0); + ctx->Dispatch (threadsX, threadsY, threadsZ); + + + // DEBUG: readback output UAV contents + #if 0 && !UNITY_RELEASE + ID3D11UnorderedAccessView* uav; + ctx->CSGetUnorderedAccessViews (0, 1, &uav); + ID3D11Buffer* res; + uav->GetResource ((ID3D11Resource**)&res); + + ID3D11Buffer* debugbuf = NULL; + D3D11_BUFFER_DESC desc; + ZeroMemory (&desc, sizeof(desc)); + res->GetDesc (&desc); + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + desc.Usage = D3D11_USAGE_STAGING; + desc.BindFlags = 0; + desc.MiscFlags = 0; + GetD3D11Device()->CreateBuffer(&desc, NULL, &debugbuf); + ctx->CopyResource (debugbuf, res); + + D3D11_MAPPED_SUBRESOURCE mapped; + ctx->Map(debugbuf, 0, D3D11_MAP_READ, 0, &mapped); + ctx->Unmap(debugbuf, 0); + SAFE_RELEASE(debugbuf); + #endif + + ID3D11UnorderedAccessView* nullUAVs[8] = {0}; + ctx->CSSetUnorderedAccessViews (0, 8, nullUAVs, NULL); +} + + +// ---------------------------------------------------------------------- + + +void GfxDeviceD3D11::DrawNullGeometry (GfxPrimitiveType topology, int vertexCount, int instanceCount) +{ + ID3D11DeviceContext* ctx = GetD3D11Context(); + UINT strides = 0; + UINT offsets = 0; + ID3D11Buffer* vb = NULL; + D3D11_CALL (ctx->IASetVertexBuffers(0, 1, &vb, &strides, &offsets)); + + BeforeDrawCall (false); + + // vertex layout + SetInputLayoutD3D11 (ctx, NULL); + + // draw + if (!SetTopologyD3D11 (topology, *this, ctx)) + return; + if (instanceCount > 1) + { + D3D11_CALL (ctx->DrawInstanced (vertexCount, instanceCount, 0, 0)); + } + else + { + D3D11_CALL (ctx->Draw (vertexCount, 0)); + } +} + +void GfxDeviceD3D11::DrawNullGeometryIndirect (GfxPrimitiveType topology, ComputeBufferID bufferHandle, UInt32 bufferOffset) +{ + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level11_0) + return; + + ID3D11DeviceContext* ctx = GetD3D11Context(); + UINT strides = 0; + UINT offsets = 0; + ID3D11Buffer* vb = NULL; + D3D11_CALL (ctx->IASetVertexBuffers(0, 1, &vb, &strides, &offsets)); + + BeforeDrawCall (false); + + // vertex layout + SetInputLayoutD3D11 (ctx, NULL); + + // draw + if (!SetTopologyD3D11 (topology, *this, ctx)) + return; + ComputeBuffer11* buffer = m_Textures.GetComputeBuffer(bufferHandle); + if (!buffer || !buffer->buffer) + return; + D3D11_CALL (ctx->DrawInstancedIndirect (buffer->buffer, bufferOffset)); +} + + +// GPU skinning functionality +GPUSkinningInfo * GfxDeviceD3D11::CreateGPUSkinningInfo() +{ + // stream-out requires at least DX10.0 + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0) + return NULL; + + return new StreamOutSkinningInfo(); +} + +void GfxDeviceD3D11::DeleteGPUSkinningInfo(GPUSkinningInfo *info) +{ + delete reinterpret_cast<StreamOutSkinningInfo *>(info); +} + +// All actual functionality is performed in StreamOutSkinningInfo, just forward the calls +void GfxDeviceD3D11::SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ) +{ + reinterpret_cast<StreamOutSkinningInfo *>(info)->SkinMesh(lastThisFrame); +} + +void GfxDeviceD3D11::UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) +{ + reinterpret_cast<StreamOutSkinningInfo *>(info)->UpdateSourceData(vertData, skinData, dirty); +} + +void GfxDeviceD3D11::UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) +{ + reinterpret_cast<StreamOutSkinningInfo *>(info)->UpdateSourceBones(boneCount, poses); +} + + +// ---------------------------------------------------------------------- +// verification of state + +#if GFX_DEVICE_VERIFY_ENABLE + + +void GfxDeviceD3D11::VerifyState() +{ +} +#endif // GFX_DEVICE_VERIFY_ENABLE diff --git a/Runtime/GfxDevice/d3d11/GfxDeviceD3D11.h b/Runtime/GfxDevice/d3d11/GfxDeviceD3D11.h new file mode 100644 index 0000000..8a7595c --- /dev/null +++ b/Runtime/GfxDevice/d3d11/GfxDeviceD3D11.h @@ -0,0 +1,357 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/TransformState.h" +#include "D3D11Includes.h" +#include "VertexDeclarationsD3D11.h" +#include "TexturesD3D11.h" +#include "FixedFunctionStateD3D11.h" +#include "ConstantBuffersD3D11.h" +#include <map> + +class FixedFunctionProgramD3D11; +class DynamicD3D11VBO; + + +// TODO: optimize this. Right now we just send off whole 8 float3 UVs with each +// immediate mode vertex. We could at least detect the number of them used from +// ImmediateTexCoord calls. +struct ImmediateVertexD3D11 { + Vector3f vertex; + Vector3f normal; + ColorRGBA32 color; + Vector3f texCoords[8]; +}; + +struct ImmediateModeD3D11 { + std::vector<ImmediateVertexD3D11> m_Vertices; + ImmediateVertexD3D11 m_Current; + GfxPrimitiveType m_Mode; + ID3D11Buffer* m_VB; + int m_VBUsedBytes; + int m_VBStartVertex; + bool m_HadColor; + + ImmediateModeD3D11(); + ~ImmediateModeD3D11(); + void Cleanup(); + void Invalidate(); +}; + +struct TextureUnitState11 +{ + Matrix4x4f matrix; +}; + + + +typedef std::map<FixedFunctionStateD3D11, FixedFunctionProgramD3D11*, FixedFuncStateCompareD3D11> FFProgramCacheD3D11; + +struct ResolveTexturePool +{ + enum { kResolvePoolSize = 8 }; + struct Entry + { + // key + int width; + int height; + RenderTextureFormat format; + bool sRGB; + + // data + ID3D11Texture2D* texture; + ID3D11ShaderResourceView* srv; + int lastUse; + }; + + ResolveTexturePool(); + void Clear(); + + Entry* GetResolveTexture (int width, int height, RenderTextureFormat fmt, bool sRGB); + + Entry m_Entries[kResolvePoolSize]; + int m_UseCounter; +}; + +class GfxDeviceD3D11 : public GfxThreadableDevice +{ +public: + struct DeviceBlendStateD3D11 : public DeviceBlendState + { + ID3D11BlendState* deviceState; + }; + + typedef std::map< GfxBlendState, DeviceBlendStateD3D11, memcmp_less<GfxBlendState> > CachedBlendStates; + typedef std::map< GfxDepthState, DeviceDepthState, memcmp_less<GfxDepthState> > CachedDepthStates; + typedef std::map< GfxStencilState, DeviceStencilState, memcmp_less<GfxStencilState> > CachedStencilStates; + typedef std::map< GfxRasterState, DeviceRasterState, memcmp_less<GfxRasterState> > CachedRasterStates; + + struct DepthStencilState { + DeviceDepthState d; + DeviceStencilState s; + }; + typedef std::map< DepthStencilState, ID3D11DepthStencilState*, memcmp_less<DepthStencilState> > CachedDepthStencilStates; + + struct FinalRasterState11 { + DeviceRasterState raster; + bool backface; + bool wireframe; + bool scissor; + }; + typedef std::map< FinalRasterState11, ID3D11RasterizerState*, memcmp_less<FinalRasterState11> > CachedFinalRasterStates; + +public: + GfxDeviceD3D11(); + GFX_API ~GfxDeviceD3D11(); + + GFX_API void InvalidateState(); + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState(); + #endif + + GFX_API void Clear (UInt32 clearFlags, const float color[4], float depth, int stencil); + GFX_API void SetUserBackfaceMode( bool enable ); + GFX_API void SetWireframe (bool wire); + GFX_API bool GetWireframe() const; + GFX_API void SetInvertProjectionMatrix( bool enable ); + GFX_API bool GetInvertProjectionMatrix() const; + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state); + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state); + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state); + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state); + + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef); + GFX_API void SetRasterState(const DeviceRasterState* state); + GFX_API void SetDepthState(const DeviceDepthState* state); + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef); + GFX_API void SetSRGBWrite (const bool); + GFX_API bool GetSRGBWrite (); + + /* GPU Skinning functions */ + GFX_API GPUSkinningInfo *CreateGPUSkinningInfo(); + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info); + GFX_API void SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ); + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty); + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses); + + GFX_API void SetWorldMatrix( const float matrix[16] ); + GFX_API void SetViewMatrix( const float matrix[16] ); + GFX_API void SetProjectionMatrix (const Matrix4x4f& matrix); + GFX_API void GetMatrix( float outMatrix[16] ) const; + + GFX_API const float* GetWorldMatrix() const ; + GFX_API const float* GetViewMatrix() const ; + GFX_API const float* GetProjectionMatrix() const ; + GFX_API const float* GetDeviceProjectionMatrix() const; + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ); + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ); + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ); + GFX_API void SetColor( const float color[4] ); + GFX_API void SetViewport( int x, int y, int width, int height ); + GFX_API void GetViewport( int* port ) const; + + GFX_API void SetScissorRect( int x, int y, int width, int height ); + GFX_API void DisableScissor(); + GFX_API bool IsScissorEnabled() const; + GFX_API void GetScissorRect( int values[4] ) const; + + GFX_API bool IsCombineModeSupported( unsigned int combiner ); + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ); + GFX_API void SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ); + GFX_API void SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ); + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias); + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]); + GFX_API void SetTextureName ( TextureID texture, const char* name ) { } + + GFX_API void SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]); + GFX_API bool IsShaderActive( ShaderType type ) const; + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ); + GFX_API void SetConstantBufferInfo (int id, int size); + + GFX_API void DisableLights( int startLight ); + GFX_API void SetLight( int light, const GfxVertexLight& data); + GFX_API void SetAmbient( const float ambient[4] ); + + GFX_API void EnableFog (const GfxFogParams& fog); + GFX_API void DisableFog(); + + GFX_API VBO* CreateVBO(); + GFX_API void DeleteVBO( VBO* vbo ); + GFX_API DynamicVBO& GetDynamicVBO(); + + GFX_API void DiscardContents (RenderSurfaceHandle& rs); + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags); + GFX_API RenderSurfaceHandle CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags); + GFX_API void DestroyRenderSurface (RenderSurfaceHandle& rs); + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face = kCubeFaceUnknown); + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle); + GFX_API void ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle); + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface (int index); + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface (); + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags); + + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ); + GFX_API void DeleteTexture( TextureID texture ); + + GFX_API PresentMode GetPresentMode(); + + GFX_API void BeginFrame(); + GFX_API void EndFrame(); + GFX_API void PresentFrame(); + GFX_API bool IsValidState(); + + GFX_API void FinishRendering(); + + // Immediate mode rendering + GFX_API void ImmediateVertex( float x, float y, float z ); + GFX_API void ImmediateNormal( float x, float y, float z ); + GFX_API void ImmediateColor( float r, float g, float b, float a ); + GFX_API void ImmediateTexCoordAll( float x, float y, float z ); + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ); + GFX_API void ImmediateBegin( GfxPrimitiveType type ); + GFX_API void ImmediateEnd(); + + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ); + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); + GFX_API void GrabIntoRenderTexture( RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ); + + GFX_API void BeforeDrawCall( bool immediateMode ); + + GFX_API bool IsPositionRequiredForTexGen (int texStageIndex) const { return false; } + GFX_API bool IsNormalRequiredForTexGen (int texStageIndex) const { return false; } + GFX_API bool IsPositionRequiredForTexGen() const { return false; } + GFX_API bool IsNormalRequiredForTexGen() const { return false; } + + #if ENABLE_PROFILER + GFX_API void BeginProfileEvent (const char* name); + GFX_API void EndProfileEvent (); + + GFX_API GfxTimerQuery* CreateTimerQuery(); + GFX_API void DeleteTimerQuery(GfxTimerQuery* query); + GFX_API void BeginTimerQueries(); + GFX_API void EndTimerQueries(); + #endif // ENABLE_PROFILER + + #if UNITY_EDITOR + GFX_API void SetAntiAliasFlag (bool aa); + GFX_API void DrawUserPrimitives (GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride); + GFX_API int GetCurrentTargetAA() const; + GFX_API GfxDeviceWindow* CreateGfxWindow (HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias); + #endif + + GFX_API int GetCurrentTargetWidth() const; + GFX_API int GetCurrentTargetHeight() const; + GFX_API void SetCurrentTargetSize(int width, int height); + GFX_API void SetCurrentWindowSize(int width, int height); + + GFX_API void* GetNativeGfxDevice(); + GFX_API void* GetNativeTexturePointer(TextureID id); + GFX_API intptr_t CreateExternalTextureFromNative(intptr_t nativeTex); + GFX_API void UpdateExternalTextureFromNative(TextureID tex, intptr_t nativeTex); + + GFX_API void SetComputeBufferData (ComputeBufferID bufferHandle, const void* data, size_t size); + GFX_API void GetComputeBufferData (ComputeBufferID bufferHandle, void* dest, size_t destSize); + GFX_API void CopyComputeBufferCount (ComputeBufferID srcBuffer, ComputeBufferID dstBuffer, UInt32 dstOffset); + + GFX_API void SetRandomWriteTargetTexture (int index, TextureID tid); + GFX_API void SetRandomWriteTargetBuffer (int index, ComputeBufferID bufferHandle); + GFX_API void ClearRandomWriteTargets (); + + GFX_API ComputeProgramHandle CreateComputeProgram (const UInt8* code, size_t codeSize); + GFX_API void DestroyComputeProgram (ComputeProgramHandle& cpHandle); + GFX_API void CreateComputeConstantBuffers (unsigned count, const UInt32* sizes, ConstantBufferHandle* outCBs); + GFX_API void DestroyComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs); + GFX_API void CreateComputeBuffer (ComputeBufferID id, size_t count, size_t stride, UInt32 flags); + GFX_API void DestroyComputeBuffer (ComputeBufferID handle); + GFX_API void UpdateComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs, UInt32 cbDirty, size_t dataSize, const UInt8* data, const UInt32* cbSizes, const UInt32* cbOffsets, const int* bindPoints); + GFX_API void UpdateComputeResources ( + unsigned texCount, const TextureID* textures, const int* texBindPoints, + unsigned samplerCount, const unsigned* samplers, + unsigned inBufferCount, const ComputeBufferID* inBuffers, const int* inBufferBindPoints, + unsigned outBufferCount, const ComputeBufferID* outBuffers, const TextureID* outTextures, const UInt32* outBufferBindPoints); + GFX_API void DispatchComputeProgram (ComputeProgramHandle cpHandle, unsigned threadsX, unsigned threadsY, unsigned threadsZ); + + GFX_API void DrawNullGeometry (GfxPrimitiveType topology, int vertexCount, int instanceCount); + GFX_API void DrawNullGeometryIndirect (GfxPrimitiveType topology, ComputeBufferID bufferHandle, UInt32 bufferOffset); + + ID3D11Buffer* GetAllWhiteVertexStream(); + VertexDeclarationsD3D11& GetVertexDecls() { return m_VertexDecls; } + ConstantBuffersD3D11& GetConstantBuffers() { return m_CBs; } + TexturesD3D11& GetTextures() { return m_Textures; } + void SetComputeBuffer11 (ShaderType shaderType, int unit, ComputeBufferID bufferHandle); + +private: + void SetupDeferredDepthStencilState(); + void SetupDeferredRasterState(); + void SetupDeferredSRGBWrite(); + + void DrawQuad (float u0, float v0, float u1, float v1, float z, ID3D11ShaderResourceView* texture); + bool ImmediateEndSetup(); + void ImmediateEndDraw(); + +public: + ImmediateModeD3D11 m_Imm; + TransformState m_TransformState; + + ConstantBuffersD3D11 m_CBs; + VertexDeclarationsD3D11 m_VertexDecls; + TexturesD3D11 m_Textures; + DynamicD3D11VBO* m_DynamicVBO; + + FFProgramCacheD3D11 m_FFPrograms; + FixedFunctionStateD3D11 m_FFState; + + CachedBlendStates m_CachedBlendStates; + CachedDepthStates m_CachedDepthStates; + CachedStencilStates m_CachedStencilStates; + CachedRasterStates m_CachedRasterStates; + CachedFinalRasterStates m_CachedFinalRasterStates; + CachedDepthStencilStates m_CachedDepthStencilStates; + + TextureUnitState11 m_TextureUnits[kMaxSupportedTextureUnits]; + TextureID m_ActiveTextures[kShaderTypeCount][kMaxSupportedTextureUnits]; + TextureID m_ActiveSamplers[kShaderTypeCount][kMaxSupportedTextureUnits]; + + GpuProgram* m_ActiveGpuProgram[kShaderTypeCount]; + const GpuProgramParameters* m_ActiveGpuProgramParams[kShaderTypeCount]; + + void* m_ActiveShaders[kShaderTypeCount]; + + const DeviceBlendState* m_CurrBlendState; + const DeviceRasterState* m_CurrRasterState; + const DeviceDepthState* m_CurrDepthState; + const DeviceStencilState* m_CurrStencilState; + ID3D11RasterizerState* m_CurrRSState; + ID3D11DepthStencilState* m_CurrDSState; + int m_StencilRef; + int m_CurrStencilRef; + + bool m_InvertProjMatrix; + bool m_AppBackfaceMode; + bool m_UserBackfaceMode; + bool m_Wireframe; + bool m_Scissor; + bool m_SRGBWrite; + bool m_ActualSRGBWrite; + + int m_Viewport[4]; + int m_ScissorRect[4]; + int m_CurrTargetWidth; + int m_CurrTargetHeight; + int m_CurrWindowWidth; + int m_CurrWindowHeight; + + ResolveTexturePool m_Resolves; +}; + +GfxDeviceD3D11& GetD3D11GfxDevice(); diff --git a/Runtime/GfxDevice/d3d11/GpuProgramsD3D11.cpp b/Runtime/GfxDevice/d3d11/GpuProgramsD3D11.cpp new file mode 100644 index 0000000..0cb9143 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/GpuProgramsD3D11.cpp @@ -0,0 +1,703 @@ +#include "UnityPrefix.h" +#include "GpuProgramsD3D11.h" +#include "ConstantBuffersD3D11.h" +#include "D3D11Context.h" +#include "D3D11Utils.h" +#include "GfxDeviceD3D11.h" +#include "ShaderGeneratorD3D11.h" +#include "Runtime/Math/Vector4.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/ComputeShader.h" +#include "ShaderGeneratorD3D11.h" +#include "ShaderPatchingD3D11.h" +#include "FixedFunctionStateD3D11.h" +#include "External/shaderlab/Library/properties.h" + + + +ConstantBuffersD3D11& GetD3D11ConstantBuffers (GfxDevice& device); +const InputSignatureD3D11* GetD3D11InputSignature (void* code, unsigned length); + +const InputSignatureD3D11* g_CurrentVSInputD3D11; + + +static GpuProgramLevel DecodeShader (const std::string& source, dynamic_array<UInt8>& output) +{ + GpuProgramLevel level = kGpuProgramNone; + + // decode shader + int startSkip = 0; + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0) + { + if (strncmp(source.c_str()+1, "s_4_0_level_9_", strlen("s_4_0_level_9_")) == 0) + { + startSkip = strlen("vs_4_0_level_9_x") + 1; + level = kGpuProgramSM3; + } + Assert ("Unsupported shader found!"); + } + else if (strncmp(source.c_str()+1, "s_dx11", 6) == 0) + { + startSkip = 7; + level = kGpuProgramSM4; + } + else if (strncmp(source.c_str()+1, "s_4_0", 5) == 0) + { + startSkip = 6; + level = kGpuProgramSM4; + } + else if (strncmp(source.c_str()+1, "s_5_0", 5) == 0) + { + startSkip = 6; + level = kGpuProgramSM5; + } + else + { + Assert ("Unknown shader prefix"); + } + int sourceSize = source.size() - startSkip; + const char* sourcePtr = source.c_str() + startSkip; + + output.reserve (sourceSize / 2); + int i = 0; + while (i < sourceSize) + { + char c1 = sourcePtr[i]; + if (c1 >= 'a') + { + AssertIf (i+1 == sourceSize); + char c2 = sourcePtr[i+1]; + output.push_back ((c1-'a') * 16 + (c2-'a')); + i += 2; + } + else + { + ++i; + } + } + + // debug check: does our shader hashing code match D3Ds? + #if !UNITY_RELEASE + if (output.size() > 20) + { + void D3DHash (const unsigned char* data, unsigned size, unsigned char res[16]); + UInt8 hsh[16]; + D3DHash (&output[20], output.size()-20, hsh); + DebugAssert (0 == memcmp(hsh,&output[4],16)); + } + #endif + + // patch shader code to do driver workarounds + if (level < kGpuProgramSM4 && gGraphicsCaps.d3d11.buggyPartialPrecision10Level9) + { + PatchRemovePartialPrecisionD3D11 (output); + } + + // patch shader code to do driver workarounds + if (level < kGpuProgramSM4 && gGraphicsCaps.d3d11.buggyPartialPrecision10Level9) + { + PatchRemovePartialPrecisionD3D11 (output); + } + + return level; +} + +static const UInt8* ApplyValueParameters11 (ConstantBuffersD3D11& cbs, const UInt8* buffer, const GpuProgramParameters::ValueParameterArray& valueParams, int cbIndex) +{ + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for (GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i) + { + if (i->m_RowCount == 1) + { + // Vector + const Vector4f* val = reinterpret_cast<const Vector4f*>(buffer); + if (i->m_Type != kShaderParamInt) + { + cbs.SetCBConstant (cbIndex, i->m_Index, val->GetPtr(), i->m_ColCount*4); + } + else + { + int vali[4] = {val->x, val->y, val->z, val->w}; + cbs.SetCBConstant (cbIndex, i->m_Index, vali, i->m_ColCount*4); + } + buffer += sizeof(Vector4f); + } + else + { + // matrix/array + int size = *reinterpret_cast<const int*>(buffer); buffer += sizeof(int); + Assert (i->m_RowCount == 4 && size == 16); + const Matrix4x4f* val = reinterpret_cast<const Matrix4x4f*>(buffer); + cbs.SetCBConstant (cbIndex, i->m_Index, val->GetPtr(), 64); + buffer += size * sizeof(float); + } + } + return buffer; +} + +static const UInt8* ApplyBufferParameters11 (GfxDevice& device, ShaderType shaderType, const UInt8* buffer, const GpuProgramParameters::BufferParameterArray& bufferParams) +{ + GfxDeviceD3D11& device11 = static_cast<GfxDeviceD3D11&>(device); + + GpuProgramParameters::BufferParameterArray::const_iterator bufferParamsEnd = bufferParams.end(); + for (GpuProgramParameters::BufferParameterArray::const_iterator i = bufferParams.begin(); i != bufferParamsEnd; ++i) + { + ComputeBufferID buf = *reinterpret_cast<const ComputeBufferID*>(buffer); + device11.SetComputeBuffer11 (shaderType, i->m_Index, buf); + buffer += sizeof(ComputeBufferID); + } + return buffer; +} + + +// -------------------------------------------------------------------------- + + +D3D11CommonShader::~D3D11CommonShader () +{ + for (int i = 0; i < kFogModeCount; ++i) + { + SAFE_RELEASE(m_Shaders[i]); + } +} + +IUnknown* D3D11CommonShader::GetShader(FogMode fog, bool haveDomainShader, bool& outResetToNoFog) +{ + outResetToNoFog = false; + // no fog? + if (fog <= kFogDisabled) + return m_Shaders[0]; + + // already have shader for this fog mode? + Assert (fog >= 0 && fog < kFogModeCount); + if (m_Shaders[fog]) + return m_Shaders[fog]; + + // can't do fog for this mode? + unsigned fogBit = (1<<fog); + if (m_FogFailed & fogBit) + { + outResetToNoFog = true; + return m_Shaders[0]; + } + + // have domain shader and we're vertex - nothing to do; fog delegated to domain one + if (haveDomainShader && m_ImplType == kShaderImplVertex) + return m_Shaders[0]; + + // patch shader to handle fog + bool ok = PatchShaderForFog (fog); + if (!ok) + { + m_FogFailed |= fogBit; + return m_Shaders[0]; + } + + Assert(m_Shaders[fog]); + return m_Shaders[fog]; +} + +bool D3D11CommonShader::PatchShaderForFog (FogMode fog) +{ + Assert (fog > kFogDisabled && fog < kFogModeCount); + Assert (!m_Shaders[fog]); + IUnknown* s = m_Shaders[0]; + m_Shaders[fog] = s; + if (s) + s->AddRef(); + return true; +} + + +const UInt8* D3D11CommonShader::ApplyTextures (GfxDevice& device, ShaderType shaderType, const GpuProgramParameters& params, const UInt8* buffer) +{ + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + const GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for (GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i) + { + const GpuProgramParameters::TextureParameter& t = *i; + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + device.SetTexture (shaderType, t.m_Index, t.m_SamplerIndex, texdata->textureID, static_cast<TextureDimension>(texdata->texDim), 0); + buffer += sizeof(*texdata); + } + return buffer; +} + + +// -------------------------------------------------------------------------- + +D3D11VertexShader::D3D11VertexShader (const std::string& compiledSource) +: m_InputSignature(NULL) +{ + m_ImplType = kShaderImplVertex; + if (!Create(compiledSource)) + m_NotSupported = true; +} + +D3D11VertexShader::~D3D11VertexShader () +{ +} + + +bool D3D11VertexShader::Create (const std::string& compiledSource) +{ + m_GpuProgramLevel = DecodeShader (compiledSource, m_ByteCode); + + m_InputSignature = GetD3D11InputSignature (&m_ByteCode[0], m_ByteCode.size()); + + HRESULT hr = GetD3D11Device()->CreateVertexShader (&m_ByteCode[0], m_ByteCode.size(), NULL, (ID3D11VertexShader**)&m_Shaders[0]); + if( FAILED(hr) ) + { + printf_console ("D3D shader create error for shader %s\n", compiledSource.c_str()); + return false; + } + + std::string debugName = Format("VS-%d", compiledSource.size()); + hr = ((ID3D11DeviceChild*)m_Shaders[0])->SetPrivateData (WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + + return true; +} + +bool D3D11VertexShader::PatchShaderForFog (FogMode fog) +{ + // no fog patching for 9.x level yet + if (m_GpuProgramLevel < kGpuProgramSM4) + return false; + + dynamic_array<UInt8> bc = m_ByteCode; + bool ok = PatchVertexOrDomainShaderFogD3D11 (bc); + if (!ok) + { + printf_console("DX11: failed to patch vertex shader for fog mode %d\n", fog); + return false; + } + + Assert (!m_Shaders[fog]); + HRESULT hr = GetD3D11Device()->CreateVertexShader (&bc[0], bc.size(), NULL, (ID3D11VertexShader**)&m_Shaders[fog]); + if (FAILED(hr)) + { + printf_console ("D3D11 shader create error for VS with fog mode %i\n", fog); + return false; + } + + SetDebugNameD3D11 ((ID3D11DeviceChild*)m_Shaders[fog], Format("VS-%d-fog-%d", (int)bc.size(), fog)); + return true; +} + + +void D3D11VertexShader::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + g_CurrentVSInputD3D11 = m_InputSignature; + + GfxDevice& device = GetRealGfxDevice(); + ConstantBuffersD3D11& cbs = GetD3D11ConstantBuffers(device); + cbs.ResetBinds (kShaderVertex); + + for (GpuProgramParameters::ConstantBufferList::const_iterator cbi = params.GetConstantBuffers().begin(); cbi != params.GetConstantBuffers().end(); ++cbi) + { + const int cbIndex = cbs.FindAndBindCB (cbi->m_Name.index, kShaderVertex, cbi->m_BindIndex, cbi->m_Size); + buffer = ApplyValueParameters11 (cbs, buffer, cbi->m_ValueParams, cbIndex); + } + buffer = ApplyTextures (device, kShaderVertex, params, buffer); + buffer = ApplyBufferParameters11 (device, kShaderVertex, buffer, params.GetBufferParams()); +} + + +// -------------------------------------------------------------------------- + + +D3D11PixelShader::D3D11PixelShader (const std::string& compiledSource) +{ + m_ImplType = kShaderImplFragment; + if (!Create(compiledSource)) + m_NotSupported = true; +} + + +bool D3D11PixelShader::Create (const std::string& compiledSource) +{ + m_GpuProgramLevel = DecodeShader (compiledSource, m_ByteCode); + + HRESULT hr = GetD3D11Device()->CreatePixelShader (&m_ByteCode[0], m_ByteCode.size(), NULL, (ID3D11PixelShader**)&m_Shaders[0]); + if( FAILED(hr) ) + { + printf_console ("D3D shader create error for shader %s\n", compiledSource.c_str()); + return false; + } + + std::string debugName = Format("PS-%d", compiledSource.size()); + hr = ((ID3D11DeviceChild*)m_Shaders[0])->SetPrivateData (WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + + return true; +} + + +bool D3D11PixelShader::PatchShaderForFog (FogMode fog) +{ + // no fog patching for 9.x level yet + if (m_GpuProgramLevel < kGpuProgramSM4) + return false; + + dynamic_array<UInt8> bc = m_ByteCode; + bool ok = PatchPixelShaderFogD3D11 (bc, fog); + if (!ok) + { + printf_console("DX11: failed to patch pixel shader for fog mode %d\n", fog); + return false; + } + + Assert (!m_Shaders[fog]); + HRESULT hr = GetD3D11Device()->CreatePixelShader (&bc[0], bc.size(), NULL, (ID3D11PixelShader**)&m_Shaders[fog]); + if (FAILED(hr)) + { + printf_console ("D3D11 shader create error for PS with fog mode %i\n", fog); + return false; + } + + SetDebugNameD3D11 ((ID3D11DeviceChild*)m_Shaders[fog], Format("PS-%d-fog-%d", (int)bc.size(), fog)); + + return true; +} + + +void D3D11PixelShader::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + GfxDevice& device = GetRealGfxDevice(); + ConstantBuffersD3D11& cbs = GetD3D11ConstantBuffers(device); + cbs.ResetBinds (kShaderFragment); + + for (GpuProgramParameters::ConstantBufferList::const_iterator cbi = params.GetConstantBuffers().begin(); cbi != params.GetConstantBuffers().end(); ++cbi) + { + const int cbIndex = cbs.FindAndBindCB (cbi->m_Name.index, kShaderFragment, cbi->m_BindIndex, cbi->m_Size); + buffer = ApplyValueParameters11 (cbs, buffer, cbi->m_ValueParams, cbIndex); + } + + // Apply textures + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for( GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i ) + { + const GpuProgramParameters::TextureParameter& t = *i; + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + ApplyTexEnvData (t.m_Index, t.m_SamplerIndex, *texdata); + buffer += sizeof(*texdata); + } + + buffer = ApplyBufferParameters11 (device, kShaderFragment, buffer, params.GetBufferParams()); +} + + +// -------------------------------------------------------------------------- + +D3D11GeometryShader::D3D11GeometryShader (const std::string& compiledSource) +{ + m_ImplType = kShaderImplGeometry; + if (!Create(compiledSource)) + m_NotSupported = true; +} + + +bool D3D11GeometryShader::Create (const std::string& compiledSource) +{ + m_GpuProgramLevel = DecodeShader (compiledSource, m_ByteCode); + + HRESULT hr = GetD3D11Device()->CreateGeometryShader (&m_ByteCode[0], m_ByteCode.size(), NULL, (ID3D11GeometryShader**)&m_Shaders[0]); + if( FAILED(hr) ) + { + printf_console ("D3D shader create error for shader %s\n", compiledSource.c_str()); + return false; + } + + std::string debugName = Format("GS-%d", compiledSource.size()); + hr = ((ID3D11DeviceChild*)m_Shaders[0])->SetPrivateData (WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + + return true; +} + +void D3D11GeometryShader::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + GfxDevice& device = GetRealGfxDevice(); + ConstantBuffersD3D11& cbs = GetD3D11ConstantBuffers(device); + cbs.ResetBinds (kShaderGeometry); + + for (GpuProgramParameters::ConstantBufferList::const_iterator cbi = params.GetConstantBuffers().begin(); cbi != params.GetConstantBuffers().end(); ++cbi) + { + const int cbIndex = cbs.FindAndBindCB (cbi->m_Name.index, kShaderGeometry, cbi->m_BindIndex, cbi->m_Size); + buffer = ApplyValueParameters11 (cbs, buffer, cbi->m_ValueParams, cbIndex); + } + buffer = ApplyTextures (device, kShaderGeometry, params, buffer); + buffer = ApplyBufferParameters11 (device, kShaderGeometry, buffer, params.GetBufferParams()); +} + + +// -------------------------------------------------------------------------- + +D3D11HullShader::D3D11HullShader (const std::string& compiledSource) +{ + m_ImplType = kShaderImplHull; + if (!Create(compiledSource)) + m_NotSupported = true; +} + + +bool D3D11HullShader::Create (const std::string& compiledSource) +{ + m_GpuProgramLevel = DecodeShader (compiledSource, m_ByteCode); + + HRESULT hr = GetD3D11Device()->CreateHullShader (&m_ByteCode[0], m_ByteCode.size(), NULL, (ID3D11HullShader**)&m_Shaders[0]); + if( FAILED(hr) ) + { + printf_console ("D3D shader create error for shader %s\n", compiledSource.c_str()); + return false; + } + + std::string debugName = Format("HS-%d", compiledSource.size()); + hr = ((ID3D11DeviceChild*)m_Shaders[0])->SetPrivateData (WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + + return true; +} + +void D3D11HullShader::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + GfxDevice& device = GetRealGfxDevice(); + ConstantBuffersD3D11& cbs = GetD3D11ConstantBuffers(device); + cbs.ResetBinds (kShaderHull); + + for (GpuProgramParameters::ConstantBufferList::const_iterator cbi = params.GetConstantBuffers().begin(); cbi != params.GetConstantBuffers().end(); ++cbi) + { + const int cbIndex = cbs.FindAndBindCB (cbi->m_Name.index, kShaderHull, cbi->m_BindIndex, cbi->m_Size); + buffer = ApplyValueParameters11 (cbs, buffer, cbi->m_ValueParams, cbIndex); + } + buffer = ApplyTextures (device, kShaderHull, params, buffer); + buffer = ApplyBufferParameters11 (device, kShaderHull, buffer, params.GetBufferParams()); +} + + +// -------------------------------------------------------------------------- + +D3D11DomainShader::D3D11DomainShader (const std::string& compiledSource) +{ + m_ImplType = kShaderImplDomain; + if (!Create(compiledSource)) + m_NotSupported = true; +} + +bool D3D11DomainShader::Create (const std::string& compiledSource) +{ + m_GpuProgramLevel = DecodeShader (compiledSource, m_ByteCode); + + HRESULT hr = GetD3D11Device()->CreateDomainShader (&m_ByteCode[0], m_ByteCode.size(), NULL, (ID3D11DomainShader**)&m_Shaders[0]); + if( FAILED(hr) ) + { + printf_console ("D3D shader create error for shader %s\n", compiledSource.c_str()); + return false; + } + + std::string debugName = Format("DS-%d", compiledSource.size()); + hr = ((ID3D11DeviceChild*)m_Shaders[0])->SetPrivateData (WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + + return true; +} + +bool D3D11DomainShader::PatchShaderForFog (FogMode fog) +{ + // no fog patching for 9.x level yet + if (m_GpuProgramLevel < kGpuProgramSM4) + return false; + + dynamic_array<UInt8> bc = m_ByteCode; + bool ok = PatchVertexOrDomainShaderFogD3D11 (bc); + if (!ok) + { + printf_console("DX11: failed to patch domain shader for fog mode %d\n", fog); + return false; + } + + Assert (!m_Shaders[fog]); + HRESULT hr = GetD3D11Device()->CreateDomainShader (&bc[0], bc.size(), NULL, (ID3D11DomainShader**)&m_Shaders[fog]); + if (FAILED(hr)) + { + printf_console ("D3D11 shader create error for DS with fog mode %i\n", fog); + return false; + } + + SetDebugNameD3D11 ((ID3D11DeviceChild*)m_Shaders[fog], Format("DS-%d-fog-%d", (int)bc.size(), fog)); + return true; +} + + +void D3D11DomainShader::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + GfxDevice& device = GetRealGfxDevice(); + ConstantBuffersD3D11& cbs = GetD3D11ConstantBuffers(device); + cbs.ResetBinds (kShaderDomain); + + for (GpuProgramParameters::ConstantBufferList::const_iterator cbi = params.GetConstantBuffers().begin(); cbi != params.GetConstantBuffers().end(); ++cbi) + { + const int cbIndex = cbs.FindAndBindCB (cbi->m_Name.index, kShaderDomain, cbi->m_BindIndex, cbi->m_Size); + buffer = ApplyValueParameters11 (cbs, buffer, cbi->m_ValueParams, cbIndex); + } + buffer = ApplyTextures (device, kShaderDomain, params, buffer); + buffer = ApplyBufferParameters11 (device, kShaderDomain, buffer, params.GetBufferParams()); +} + + +// -------------------------------------------------------------------------- + + +void FixedFunctionProgramD3D11::ValueParameters::ApplyValues (const BuiltinShaderParamValues& values, ConstantBuffersD3D11& cbs, ShaderType shaderType) const +{ + int cbBindIndex = cbs.FindAndBindCB (m_CBID, shaderType, 0, m_CBSize); + + ValueParameterArray::const_iterator valueParamsEnd = m_Params.end(); + for (ValueParameterArray::const_iterator i = m_Params.begin(); i != valueParamsEnd; ++i) + { + const Vector4f& val = values.GetVectorParam((BuiltinShaderVectorParam)i->m_Name); + cbs.SetCBConstant (cbBindIndex, i->m_Index, &val, i->m_Bytes); + } +} + + +// -------------------------------------------------------------------------- + + +static std::string GetFixedFunctionStateDesc (const FixedFunctionStateD3D11& state) +{ + std::string res; + if (state.lightingEnabled) + { + res += Format(" lighting with %i lights\n", state.lightCount); + } + res += Format(" combiners: %i\n", state.texUnitCount); + for (int i = 0; i < state.texUnitCount; ++i) + { + res += Format (" #%i: %08x %08x uv=%i %s %s\n", + i, state.texUnitColorCombiner[i], state.texUnitAlphaCombiner[i], + unsigned((state.texUnitSources>>(i*4))&0xF), + (state.texUnitCube&(1<<i))?"cube":"2d", + (state.texUnitProjected&(1<<i))?"projected":""); + } + res += state.useUniformInsteadOfVertexColor ? " color from uniform" : " color from VBO\n"; + if (state.alphaTest != kFuncDisabled && state.alphaTest != kFuncAlways) + res += Format(" alpha test: %d\n", state.alphaTest); + return res; +} + +#if UNITY_METRO_VS2013 || (UNITY_WIN && !UNITY_WINRT) +extern bool HasD3D11Linker(); +extern void* BuildVertexShaderD3D11_Link(const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, BuiltinShaderParamIndices& matrices, size_t& outSize); +extern void* BuildFragmentShaderD3D11_Link(const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, size_t& outSize); +#endif + +FixedFunctionProgramD3D11::FixedFunctionProgramD3D11 (const FixedFunctionStateD3D11& state) +: m_VS(NULL) +, m_PS(NULL) +, m_InputSig(NULL) +{ + size_t sizeVS, sizePS; + + void* codeVS = NULL; + void* codePS = NULL; + + // Generate using DX11 shader linker if available + #if UNITY_METRO_VS2013 || (UNITY_WIN && !UNITY_WINRT) + if (HasD3D11Linker()) + { + codeVS = BuildVertexShaderD3D11_Link(state, m_VPParams, m_VPMatrices, sizeVS); + if (codeVS) + codePS = BuildFragmentShaderD3D11_Link(state, m_FPParams, sizePS); + } + #endif + + // If linker failed or not available, generate raw hlsl bytecode + if (!codeVS || !codePS) + { + if (codeVS) + free(codeVS); + if (codePS) + free(codePS); + codeVS = BuildVertexShaderD3D11(state, m_VPParams, m_VPMatrices, sizeVS); + codePS = BuildFragmentShaderD3D11(state, m_FPParams, sizePS); + } + + // Both generators failed, give up + if (!codeVS || !codePS) + { + ErrorString ("Failed to create fixed function shader pair"); + if (codeVS) + free(codeVS); + if (codePS) + free(codePS); + return; + } + + /* + // debug check: does our shader hashing code match D3Ds? + #if !UNITY_RELEASE + if (sizeVS > 20 && sizePS > 20) + { + void D3DHash (const unsigned char* data, unsigned size, unsigned char res[16]); + UInt8 hsh[16]; + D3DHash (&codeVS[20], sizeVS-20, hsh); + DebugAssert (0 == memcmp(hsh,&codeVS[4],16)); + D3DHash (&codePS[20], sizePS-20, hsh); + DebugAssert (0 == memcmp(hsh,&codePS[4],16)); + } + // dump vertex shader code + DXBCContainer* dxbc = dxbc_parse (codeVS, sizeVS); + dxbc_print (dxbc); + delete dxbc; + #endif + */ + +#if _DEBUG && !UNITY_METRO && 0 + static int s_Num = 0; + char sz[1024]; + + sprintf(sz,"dump%04d.vs",s_Num); + FILE* f = fopen(sz,"wb"); + fwrite(codeVS,sizeVS,1,f); + fclose(f); + sprintf(sz,"dump%04d.ps",s_Num); + f = fopen(sz,"wb"); + fwrite(codePS,sizePS,1,f); + fclose(f); + s_Num++; +#endif + + + ID3D11Device* dev = GetD3D11Device(); + HRESULT hr; + hr = dev->CreateVertexShader (codeVS, sizeVS, NULL, &m_VS); + Assert (SUCCEEDED(hr)); + hr = dev->CreatePixelShader (codePS, sizePS, NULL, &m_PS); + Assert (SUCCEEDED(hr)); + + std::string debugName = Format("FixedFunctionVS-%d", sizeVS); + hr = m_VS->SetPrivateData (WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + debugName = Format("FixedFunctionPS-%d", sizePS); + hr = m_PS->SetPrivateData (WKPDID_D3DDebugObjectName, debugName.size(), debugName.c_str()); + + m_InputSig = GetD3D11InputSignature (codeVS, sizeVS); + + free(codeVS); + free(codePS); +} + +FixedFunctionProgramD3D11::~FixedFunctionProgramD3D11 () +{ + SAFE_RELEASE(m_VS); + SAFE_RELEASE(m_PS); +} + + +void FixedFunctionProgramD3D11::ApplyFFGpuProgram (const BuiltinShaderParamValues& values, ConstantBuffersD3D11& cbs) const +{ + g_CurrentVSInputD3D11 = m_InputSig; + + cbs.ResetBinds (kShaderVertex); + cbs.ResetBinds (kShaderFragment); + + m_VPParams.ApplyValues (values, cbs, kShaderVertex); + m_FPParams.ApplyValues (values, cbs, kShaderFragment); +} diff --git a/Runtime/GfxDevice/d3d11/GpuProgramsD3D11.h b/Runtime/GfxDevice/d3d11/GpuProgramsD3D11.h new file mode 100644 index 0000000..305144b --- /dev/null +++ b/Runtime/GfxDevice/d3d11/GpuProgramsD3D11.h @@ -0,0 +1,125 @@ +#pragma once + +#include "Runtime/GfxDevice/GpuProgram.h" +#include "Runtime/Utilities/dynamic_array.h" +#include "D3D11Includes.h" + +class GfxDevice; + +class ConstantBuffersD3D11; +struct FixedFunctionStateD3D11; +struct InputSignatureD3D11; + +class D3D11CommonShader : public GpuProgram { +public: + virtual ~D3D11CommonShader(); + IUnknown* GetShader(FogMode fog, bool haveDomainShader, bool& outResetToNoFog); + +protected: + D3D11CommonShader () + : m_FogFailed(0) + { + for (int i = 0; i < kFogModeCount; ++i) + m_Shaders[i] = NULL; + } + + const UInt8* ApplyTextures (GfxDevice& device, ShaderType shaderType, const GpuProgramParameters& params, const UInt8* buffer); + + // default implementation just uses non-fog shader + virtual bool PatchShaderForFog (FogMode fog); + +protected: + IUnknown* m_Shaders[kFogModeCount]; + dynamic_array<UInt8> m_ByteCode; // stored for fog patching + UInt32 m_FogFailed; +}; + +class D3D11VertexShader : public D3D11CommonShader { +public: + D3D11VertexShader (const std::string& compiledSource); + virtual ~D3D11VertexShader(); + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); + +protected: + virtual bool PatchShaderForFog (FogMode fog); +private: + bool Create (const std::string& compiledSource); + const InputSignatureD3D11* m_InputSignature; +}; + +class D3D11PixelShader : public D3D11CommonShader { +public: + D3D11PixelShader (const std::string& compiledSource); + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); +protected: + virtual bool PatchShaderForFog (FogMode fog); +private: + bool Create (const std::string& compiledSource); +}; + +class D3D11GeometryShader : public D3D11CommonShader { +public: + D3D11GeometryShader (const std::string& compiledSource); + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); +private: + bool Create (const std::string& compiledSource); +}; + +class D3D11HullShader : public D3D11CommonShader { +public: + D3D11HullShader (const std::string& compiledSource); + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); +private: + bool Create (const std::string& compiledSource); +}; + +class D3D11DomainShader : public D3D11CommonShader { +public: + D3D11DomainShader (const std::string& compiledSource); + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); +protected: + virtual bool PatchShaderForFog (FogMode fog); +private: + bool Create (const std::string& compiledSource); +}; + + +class FixedFunctionProgramD3D11 +{ +public: + struct ValueParameter { + int m_Name; + int m_Index; + int m_Bytes; + ValueParameter (int n, int idx, int bytes) : m_Name(n), m_Index(idx), m_Bytes(bytes) {} + }; + typedef dynamic_array<ValueParameter> ValueParameterArray; + struct ValueParameters { + ValueParameters() : m_CBID(0), m_CBSize(0) { } + void AddVectorParam (int index, int dim, BuiltinShaderVectorParam name) { m_Params.push_back (ValueParameter (name, index, dim*4)); } + bool HasVectorParams() const { return !m_Params.empty(); } + void ApplyValues (const BuiltinShaderParamValues& values, ConstantBuffersD3D11& cbs, ShaderType shaderType) const; + ValueParameterArray m_Params; + int m_CBID; + int m_CBSize; + }; + +public: + FixedFunctionProgramD3D11 (const FixedFunctionStateD3D11& state); + ~FixedFunctionProgramD3D11 (); + + void ApplyFFGpuProgram (const BuiltinShaderParamValues& values, ConstantBuffersD3D11& cbs) const; + + const BuiltinShaderParamIndices& GetVPMatrices() const { return m_VPMatrices; } + + ID3D11VertexShader* GetVertexShader() { return m_VS; } + ID3D11PixelShader* GetPixelShader() { return m_PS; } + +private: + ValueParameters m_VPParams; + ValueParameters m_FPParams; + BuiltinShaderParamIndices m_VPMatrices; + ID3D11VertexShader* m_VS; + ID3D11PixelShader* m_PS; + const InputSignatureD3D11* m_InputSig; +}; diff --git a/Runtime/GfxDevice/d3d11/GraphicsCapsD3D11.cpp b/Runtime/GfxDevice/d3d11/GraphicsCapsD3D11.cpp new file mode 100644 index 0000000..6ad8356 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/GraphicsCapsD3D11.cpp @@ -0,0 +1,363 @@ +#include "UnityPrefix.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "D3D11Context.h" + + +extern DXGI_FORMAT kD3D11RenderTextureFormats[kRTFormatCount]; + + + +enum { + kVendorDummyRef = 0x0000, + kVendor3DLabs = 0x3d3d, + kVendorMatrox = 0x102b, + kVendorS3 = 0x5333, + kVendorSIS = 0x1039, + kVendorXGI = 0x18ca, + kVendorIntel = 0x8086, + kVendorATI = 0x1002, + kVendorNVIDIA = 0x10de, + kVendorTrident = 0x1023, + kVendorImgTech = 0x104a, + kVendorVIAS3G = 0x1106, + kVendor3dfx = 0x121a, + kVendorParallels= 0x1ab8, + kVendorMicrosoft= 0x1414, + kVendorVMWare = 0x15ad, + kVendorQualcomm = 0x4d4f4351, +}; + +enum { + kRendererIntel3150 = 0xa011, //Intel(R) Graphics Media Accelerator 3150 (Microsoft Corporation - WDDM 1.0) +}; +struct KnownVendors { + DWORD vendorId; + const char* name; +}; +static KnownVendors s_KnownVendors[] = { + { kVendorDummyRef, "REFERENCE" }, + { kVendor3DLabs, "3dLabs" }, + { kVendorMatrox, "Matrox" }, + { kVendorS3, "S3" }, + { kVendorSIS, "SIS" }, + { kVendorXGI, "XGI" }, + { kVendorIntel, "Intel" }, + { kVendorATI, "ATI" }, + { kVendorNVIDIA, "NVIDIA" }, + { kVendorTrident, "Trident" }, + { kVendorImgTech, "Imagination Technologies" }, + { kVendorVIAS3G, "VIA/S3" }, + { kVendor3dfx, "3dfx" }, + { kVendorParallels, "Parallels" }, + { kVendorMicrosoft, "Microsoft" }, + { kVendorVMWare, "VMWare" }, + { kVendorQualcomm, "Qualcomm" }, +}; +static int kKnownVendorsSize = sizeof(s_KnownVendors)/sizeof(s_KnownVendors[0]); + +DX11FeatureLevel kD3D11RenderTextureFeatureLevels[kRTFormatCount] = { + kDX11Level9_1, // ARGB32: 9.1 + kDX11Level10_0, // Depth: 10.0 + kDX11Level9_3, // ARGBHalf: 9.3 + kDX11Level10_0, // Shadowmap: 10.0 + kDX11LevelCount, // RGB565, unsupported + kDX11LevelCount, // ARGB4444, unsupported + kDX11LevelCount, // ARGB1555, unsupported + kDX11LevelCount, // Default + kDX11Level10_0, // A2RGB10: 10.0 + kDX11LevelCount, // DefaultHDR + kDX11Level10_1, // ARGB64: 10.1 + kDX11Level10_0, // ARGBFloat: 10.0 + kDX11Level10_0, // RGFloat: 10.0 + kDX11Level10_0, // RGHalf: 10.0 + kDX11Level10_0, // RFloat: 10.0 + kDX11Level10_0, // RHalf: 10.0 + kDX11Level10_0, // R8: 10.0 + kDX11Level10_0, // ARGBInt: 10.0 + kDX11Level10_0, // RGInt: 10.0 + kDX11Level10_0, // RInt: 10.0 +}; + + + +void GraphicsCaps::InitD3D11() +{ + ID3D11Device* d3d = GetD3D11Device(); + HRESULT hr; + + // get device information +#if UNITY_WINRT + DXGI_ADAPTER_DESC2 adapterDesc; + + IDXGIDevice2* dxgiDevice2; + hr = d3d->QueryInterface(__uuidof(IDXGIDevice2), (void**)&dxgiDevice2); + IDXGIAdapter* dxgiAdapter; + IDXGIAdapter2* dxgiAdapter2; + dxgiDevice2->GetAdapter (&dxgiAdapter); + dxgiAdapter->QueryInterface(__uuidof(IDXGIAdapter2), (void**)&dxgiAdapter2); + dxgiAdapter2->GetDesc2 (&adapterDesc); + dxgiAdapter2->Release(); + dxgiAdapter->Release(); + dxgiDevice2->Release(); +#else + DXGI_ADAPTER_DESC adapterDesc; + + IDXGIDevice* dxgiDevice; + IDXGIAdapter* dxgiAdapter; + hr = d3d->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); + dxgiDevice->GetAdapter (&dxgiAdapter); + dxgiAdapter->GetDesc (&adapterDesc); + dxgiAdapter->Release(); + dxgiDevice->Release(); +#endif + adapterDesc.Description[127] = 0; + + char bufUtf8[1024]; + WideCharToMultiByte (CP_UTF8, 0, adapterDesc.Description, -1, bufUtf8, 1024, NULL, NULL ); + rendererString = bufUtf8; + + int i; + for( i = 0; i < kKnownVendorsSize; ++i ) + { + if( s_KnownVendors[i].vendorId == adapterDesc.VendorId ) + { + vendorString = s_KnownVendors[i].name; + break; + } + } + if( i == kKnownVendorsSize ) + { + vendorString = Format( "Unknown (ID=%x)", adapterDesc.VendorId ); + } + + vendorID = adapterDesc.VendorId; + rendererID = adapterDesc.DeviceId; + + // No easy way to get driver information in DXGI... + driverLibraryString.clear(); + driverVersionString.clear(); + + D3D_FEATURE_LEVEL d3dlevel = d3d->GetFeatureLevel(); + DX11FeatureLevel level = kDX11Level9_1; + switch (d3dlevel) { + case D3D_FEATURE_LEVEL_9_1: level = kDX11Level9_1; break; + case D3D_FEATURE_LEVEL_9_2: level = kDX11Level9_2; break; + case D3D_FEATURE_LEVEL_9_3: level = kDX11Level9_3; break; + case D3D_FEATURE_LEVEL_10_0: level = kDX11Level10_0; break; + case D3D_FEATURE_LEVEL_10_1: level = kDX11Level10_1; break; + case D3D_FEATURE_LEVEL_11_0: level = kDX11Level11_0; break; + default: AssertString ("Unknown feature level"); + } + d3d11.featureLevel = level; + + fixedVersionString = Format("Direct3D 11.0 [level %i.%i]", + (d3dlevel & 0xF000) >> 12, + (d3dlevel & 0x0F00) >> 8); + +#if UNITY_WINRT + // Note: On Intel HD 4000, adapterDesc.DedicatedVideoMemory was returning 32 MB, which wasn't enough to even have on render texture on Surface Pro + // That's why there were bugs with shadows + // If you change something here, do check https://fogbugz.unity3d.com/default.asp?546560#1066534481 on Surface Pro, if it's still works + #if defined(__arm__) + const float kSaneMinVRAM = 64; + #else + const float kSaneMinVRAM = 128; + #endif + videoMemoryMB = (adapterDesc.DedicatedVideoMemory == 0) ? (adapterDesc.SharedSystemMemory / 2) : adapterDesc.DedicatedVideoMemory; + videoMemoryMB = std::max(videoMemoryMB / (1024 * 1024), kSaneMinVRAM); +#if UNITY_METRO && defined(__arm__) + // tested on Tegra Tablet (Tegra T300?) and Surface (Tegra 3) - tested on 2013.02.20 + gGraphicsCaps.buggyShadowMapBilinearSampling = true; +#else + gGraphicsCaps.buggyShadowMapBilinearSampling = false; +#endif +#else + videoMemoryMB = adapterDesc.DedicatedVideoMemory / 1024 / 1024; +#endif + + // Output D3D info to console + printf_console( "Direct3D:\n" ); + printf_console( " Version: %s\n", fixedVersionString.c_str() ); + printf_console( " Renderer: %s (ID=0x%x)\n", rendererString.c_str(), rendererID); + printf_console( " Vendor: %s\n", vendorString.c_str() ); + printf_console( " VRAM: %i MB\n", (int)videoMemoryMB ); + + needsToSwizzleVertexColors = false; + maxVSyncInterval = 4; + maxLights = 8; + + // Texture sizes + static const int kTextureSizes[kDX11LevelCount] = {2048, 2048, 4096, 8192, 8192, 16384}; + static const int kCubemapSizes[kDX11LevelCount] = { 512, 512, 4096, 8192, 8192, 16384}; + maxTextureSize = kTextureSizes[level]; + maxRenderTextureSize = maxTextureSize; + maxCubeMapSize = kCubemapSizes[level]; + + // Vertex/Fragment program parts + hasFixedFunction = true; +#if UNITY_METRO + // Disable fixed function shaders on crappy devices + // One fix would be to rewrite byte code emitter to target 9.1 feature level instead of 9.3... + // For now, let's just disable it on all Intel devices with feature level < 9.3 + if (vendorID == kVendorIntel && level < kDX11Level9_3) // Internal driver error occurs when first fixed function shader is loaded + { + printf_console("WARNING: Disabling fixed function shaders.\n"); + hasFixedFunction = false; + } + else +#endif + has3DTexture = true; + maxTexUnits = kMaxSupportedTextureUnits; + maxTexImageUnits = kMaxSupportedTextureUnits; + maxTexCoords = 8; + + hasAnisoFilter = true; + static const int kMaxAniso[kDX11LevelCount] = {2, 16, 16, 16, 16, 16}; + maxAnisoLevel = kMaxAniso[level]; + hasMipLevelBias = true; + + hasS3TCCompression = true; + npotRT = npot = (level >= kDX11Level10_0) ? kNPOTFull : kNPOTRestricted; + + hasBlendSquare = true; + hasSeparateAlphaBlend = level > kDX11Level9_1; +#if UNITY_WP8 + hasSeparateAlphaBlend = level > kDX11Level9_3; // WP8 uses 9.3 feature level, but seems to not support separate alpha blending +#endif + hasBlendSub = true; + hasBlendMinMax = true; + + hasBlendLogicOps = false; + if(GetD3D11_1Device()) + { + D3D11_FEATURE_DATA_D3D11_OPTIONS opt; + + HRESULT hr = GetD3D11_1Device()->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, (void *)&opt, sizeof(opt)); + if(!FAILED(hr)) + { + hasBlendLogicOps = opt.OutputMergerLogicOp; + } + + } + + hasAutoMipMapGeneration = true; + + #pragma message ("Properly implement supported formats!") + for (int q = 0; q < kTexFormatPCCount; ++q) + supportsTextureFormat[q] = true; //@TODO + + if (level < kDX11Level9_3) + { + supportsTextureFormat[kTexFormatARGBFloat] = false; + supportsTextureFormat[kTexFormatRGB565] = false; + } + // 9.1 level doesn't really support R16 format. But we pretend we do, and then do unpacking + // into R8G8B8A8 on load. + supportsTextureFormat[kTexFormatAlphaLum16] = true; + + hasRenderToTexture = true; + for (int i = 0; i < kRTFormatCount; ++i) + { + if (i == kRTFormatDefault || i == kRTFormatDefaultHDR) + continue; + supportsRenderTextureFormat[i] = (level >= kD3D11RenderTextureFeatureLevels[i]); + } + +#if UNITY_METRO // works on adreno 305 devices (nokia lumia 620) but not adreno 225 (nokia lumia 920 and samsung ativ s) + if (level < D3D_FEATURE_LEVEL_10_0) + { + D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT shadowSupport; + memset(&shadowSupport, 0, sizeof(shadowSupport)); + + // Devices which don't support this: + // * Intel 3150 + // D3D11 ERROR: ID3D11Device::CreatePixelShader: Shader uses comparision filtering with shader target ps_4_0_level_9_*, but the device does not support this . To check for support, call the CheckFeatureSupport() API with D3D11_FEATURE_D3D9_SHADOW_SUPPORT. The SupportsDepthAsTextureWithLessEqualComparisonFilter member indicates support for comparison filtering on level_9 shaders. [ STATE_CREATION ERROR #192: CREATEPIXELSHADER_INVALIDSHADERBYTECODE] + // First-chance exception at 0x74DD277C in New Unity Project 10.exe: Microsoft C++ exception: _com_error at memory location 0x0996ED90. + // Would be nice, if you could ignore such shaders if this feature is not supported. + + d3d->CheckFeatureSupport(D3D11_FEATURE_D3D9_SHADOW_SUPPORT, &shadowSupport, sizeof(shadowSupport)); + gGraphicsCaps.supportsRenderTextureFormat[kRTFormatDepth] = shadowSupport.SupportsDepthAsTextureWithLessEqualComparisonFilter; + gGraphicsCaps.supportsRenderTextureFormat[kRTFormatShadowMap] = shadowSupport.SupportsDepthAsTextureWithLessEqualComparisonFilter; + gGraphicsCaps.d3d11.hasShadows10Level9 = (shadowSupport.SupportsDepthAsTextureWithLessEqualComparisonFilter != 0); + } +#else + gGraphicsCaps.d3d11.hasShadows10Level9 = false; +#endif + + // Looks like 9.x levels can't easily render into cubemaps: + // * DepthStencil texture must be a cubemap as well (otherwise can't set a cubemap color & regular 2D depth) + // * But a cubemap doesn't support any of the depth buffer formats + // A workaround could be to create 2D resources for each cubemap face, render into them, and then blit into a face + // of the final cubemap. Bah. + hasRenderToCubemap = (level >= kDX11Level10_0); + + hasRenderTo3D = (level >= kDX11Level11_0); + hasStencil = true; + hasRenderTargetStencil = true; + hasTwoSidedStencil = true; + hasNativeDepthTexture = true; + hasStencilInDepthTexture = true; + hasNativeShadowMap = true; + + hasSRGBReadWrite = true; + + hasComputeShader = (level >= kDX11Level11_0); //@TODO: some sort of limited CS support in SM4? + hasInstancing = (level >= kDX11Level9_3); + hasNonFullscreenClear = false; + + hasMultiSample = true; + d3d11.msaa = d3d11.msaaSRGB = 0; + static const int kAASampleTests[] = { 2, 4, 8 }; + for (int i = 0; i < ARRAY_SIZE(kAASampleTests); ++i) + { + int samples = kAASampleTests[i]; + UInt32 mask = 1<<samples; + UINT levels = 0; + hr = d3d->CheckMultisampleQualityLevels (DXGI_FORMAT_R8G8B8A8_UNORM, samples, &levels); + if (SUCCEEDED(hr) && levels > 0) + d3d11.msaa |= mask; + d3d->CheckMultisampleQualityLevels (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, samples, &levels); + if (SUCCEEDED(hr) && levels > 0) + d3d11.msaaSRGB |= mask; + } + + + // Crashes on ARM tablets +#if defined(__arm__) && UNITY_WINRT + hasTimerQuery = false; +#else + // In theory just doing a query create with NULL destination, like + // CreateQuery(&disjointQueryDesc, NULL) == S_FALSE + // should be enough. But this makes NVIDIA NSight 2.1 crash, so do full query creation. + const D3D11_QUERY_DESC disjointQueryDesc = { D3D11_QUERY_TIMESTAMP_DISJOINT, 0 }; + const D3D11_QUERY_DESC timestampQueryDesc = { D3D11_QUERY_TIMESTAMP, 0 }; + ID3D11Query *query1 = NULL, *query2 = NULL; + hasTimerQuery = true; + hasTimerQuery &= SUCCEEDED(d3d->CreateQuery(&disjointQueryDesc, &query1)); + hasTimerQuery &= SUCCEEDED(d3d->CreateQuery(×tampQueryDesc, &query2)); + SAFE_RELEASE(query1); + SAFE_RELEASE(query2); +#endif + + static const int kMRTCount[kDX11LevelCount] = { 1, 1, 4, 8, 8, 8 }; + maxMRTs = std::min<int> (kMRTCount[level], kMaxSupportedRenderTargets); + + // in the very end, figure out shader capabilities level (after all workarounds are applied) + static const ShaderCapsLevel kShaderLevels[kDX11LevelCount] = {kShaderLevel2, kShaderLevel2, kShaderLevel2, kShaderLevel4, kShaderLevel4_1, kShaderLevel5}; + shaderCaps = kShaderLevels[level]; + + // Looks like mipmapped cubemaps & 3D textures are broken on 9.x level; + // can't update proper faces via CopySubresourceRegion / UpdateSubresource. + buggyMipmappedCubemaps = buggyMipmapped3DTextures = (level < kDX11Level10_0); + + d3d11.buggyPartialPrecision10Level9 = false; + if (level < kDX11Level10_0) + { + // Lumia 620 crashes on partial precision (on WP8 as of 2013 March), with renderer + // string "Qualcomm Adreno 305 (WDDM v1.2)". Let's try removing partial precision + // on all Adreno 3xx. + if (rendererString.find("Adreno 3") != std::string::npos) + d3d11.buggyPartialPrecision10Level9 = true; + } +} diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/CompileShaderLib.cpp b/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/CompileShaderLib.cpp new file mode 100644 index 0000000..f25090b --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/CompileShaderLib.cpp @@ -0,0 +1,185 @@ +// This is a small program to precompile hlsl library to a header file, +// used only for fixed function shader generation with d3d11 linker. +// It also generates 8 * 4 combinations of texture sampling functions. +// +// Useful because fxc doesn't support lib_* targets, +// but once it does it's probably a good idea to deprecate this. + +#include <windows.h> +#include <d3d11.h> +#include <d3dcommon.h> +#include <d3dcompiler.h> + +#include <cstdio> +#include <cassert> + +typedef HRESULT (WINAPI *D3DCompileFunc)( + const void* pSrcData, + unsigned long SrcDataSize, + const char* pFileName, + const D3D10_SHADER_MACRO* pDefines, + void* pInclude, + const char* pEntrypoint, + const char* pTarget, + unsigned int Flags1, + unsigned int Flags2, + ID3DBlob** ppCode, + ID3DBlob** ppErrorMsgs +); + +const char* dllName = "D3DCompiler_47.dll"; + +const char* readFile(const char* path) +{ + FILE* f = fopen(path, "rb"); + if (!f) + return NULL; + + fseek(f, 0, SEEK_END); + size_t s = ftell(f); + fseek(f, 0, SEEK_SET); + char* out = (char*)malloc(s+1); + fread(out, s, 1, f); + out[s] = '\0'; + fclose(f); + return out; +} + +void printCompiledShader(ID3DBlob* shader, const char* name, FILE* out) +{ + const unsigned char* data = (const unsigned char*)shader->GetBufferPointer(); + size_t size = (size_t)shader->GetBufferSize(); + + fprintf(out, "const BYTE %s[] = { \n", name); + for(int i = 0; i < size; ++i) { + fprintf(out, ((i==size-1) ? "%d" : "%d,"), (int)data[i]); + if((i+1) % 16 == 0) + fprintf(out, "\n"); + } + fprintf(out, "\n};\n"); +} + +// type: 0 - 2d, 1 - 2d proj, 2 - 3d, 3 - cube +const char* generateTextureSamplingLib(int type, int unit) +{ + const int maxSize = 2048; + static char hlsl[maxSize]; + + const char* textureTypes[] = { "Texture2D", "Texture2D", "Texture3D", "TextureCube" }; + const char* coordTypes[] = {"float2", "float4", "float3", "float3" }; + const char* coords[] = {"uv.xy", "uv.xy/uv.w", "uv.xyz", "uv.xyz" }; + + sprintf(hlsl, + "%s<float4> Tex%d : register(t%d);\n" + "SamplerState Smp%d : register(s%d);\n" + "export float4 LoadTex%d(%s uv) { return Tex%d.Sample(Smp%d, %s); }\n", + textureTypes[type], unit, unit, unit, unit, unit, + coordTypes[type], unit, unit, coords[type] + ); + + return hlsl; +} + +const char* textureSamplingLibName(int type, int unit) +{ + static const char* typeStr[] = {"2D", "Proj", "3D", "Cube"}; + static char name[32]; + sprintf(name, "g_FFSampleTex%s%d", typeStr[type], unit); + return name; +} + +// Since we can't bind multiple textures to the same texture register, +// we'll have to generate 4 * 8 sampling functions and link the correct ones +// at runtime. +void printTextureSampling(D3DCompileFunc compileFunc, FILE* out) +{ + // Print compiled shaders + for (int type = 0; type < 4; ++type) + { + for (int unit = 0; unit < 8; ++unit) + { + const char* name = textureSamplingLibName(type, unit); + const char* hlsl = generateTextureSamplingLib(type, unit); + + ID3DBlob* errors; + ID3DBlob* shader; + HRESULT hr = compileFunc( + hlsl, strlen(hlsl), name, NULL, NULL, NULL, + "lib_4_0_level_9_1", D3DCOMPILE_OPTIMIZATION_LEVEL3, 0, &shader, &errors + ); + + assert(SUCCEEDED(hr)); + + printCompiledShader(shader, name, out); + + shader->Release(); + } + } + + // Print index to all shaders + fprintf(out, "const BYTE* g_FFSampleTexLib[] = { \n"); + for (int type = 0; type < 4; ++type) + for (int unit = 0; unit < 8; ++unit) + fprintf(out, "%s,\n", textureSamplingLibName(type, unit)); + fprintf(out, "};\n"); + + // Print sizes of all shaders + fprintf(out, "const size_t g_FFSampleTexLibSize[] = { \n"); + for (int type = 0; type < 4; ++type) + for (int unit = 0; unit < 8; ++unit) + fprintf(out, "sizeof(%s),\n", textureSamplingLibName(type, unit)); + fprintf(out, "};\n"); +} + +int main(int argc, const char** argv) +{ + if (argc != 3) + { + printf("Usage: CompileShaderLib.exe src.hlsl out.h\n"); + return 1; + } + + HMODULE dll = LoadLibraryA (dllName); + if (!dll) + { + printf("Can't load %s\n", dllName); + return 1; + } + + D3DCompileFunc compileFunc = (D3DCompileFunc) GetProcAddress(dll, "D3DCompile"); + if (!compileFunc) + { + printf("Can't get D3DCompile function address\n"); + return 1; + } + + const char* hlsl = readFile(argv[1]); + + ID3DBlob* errors; + ID3DBlob* shader; + HRESULT hr = compileFunc( + hlsl, strlen(hlsl), argv[1], NULL, NULL, NULL, + "lib_4_0_level_9_1", D3DCOMPILE_OPTIMIZATION_LEVEL3, 0, &shader, &errors + ); + + if (FAILED(hr)) + { + printf("Failed to compile, 0x%x:\n%s\n", hr, errors ? errors->GetBufferPointer() : ""); + return 1; + } + + free((void*)hlsl); + FILE* out = fopen(argv[2], "w"); + + fprintf(out, "// File autogenerated by CompileShaderLib.exe\n"); + + printCompiledShader(shader, "g_FFShaderLibrary", out); + shader->Release(); + + printTextureSampling(compileFunc, out); + + fclose(out); + + return 0; +} + diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/CompileShaderLib.exe b/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/CompileShaderLib.exe Binary files differnew file mode 100644 index 0000000..9452400 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/CompileShaderLib.exe diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/d3dcompiler_47.dll b/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/d3dcompiler_47.dll Binary files differnew file mode 100644 index 0000000..f8708d3 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/CompileShaderLib/d3dcompiler_47.dll diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/FFShaderLib.h b/Runtime/GfxDevice/d3d11/InternalShaders/FFShaderLib.h new file mode 100644 index 0000000..cfb7617 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/FFShaderLib.h @@ -0,0 +1,11341 @@ +// File autogenerated by CompileShaderLib.exe +const BYTE g_FFShaderLibrary[] = { +68,88,66,67,53,175,93,57,187,158,181,204,26,193,132,124, +173,199,196,230,1,0,0,0,85,80,2,0,83,0,0,0, +108,1,0,0,248,3,0,0,176,10,0,0,204,18,0,0, +32,27,0,0,140,29,0,0,136,32,0,0,60,36,0,0, +240,42,0,0,164,49,0,0,88,56,0,0,4,64,0,0, +20,68,0,0,40,72,0,0,100,87,0,0,88,105,0,0, +104,124,0,0,192,140,0,0,116,157,0,0,204,173,0,0, +4,192,0,0,92,208,0,0,24,228,0,0,112,244,0,0, +176,9,1,0,8,26,1,0,204,48,1,0,36,65,1,0, +72,89,1,0,160,105,1,0,200,108,1,0,232,116,1,0, +164,119,1,0,96,122,1,0,224,124,1,0,0,132,1,0, +24,140,1,0,48,148,1,0,72,156,1,0,96,164,1,0, +232,166,1,0,112,169,1,0,248,171,1,0,128,174,1,0, +72,179,1,0,48,182,1,0,248,185,1,0,192,189,1,0, +136,193,1,0,80,197,1,0,24,201,1,0,224,204,1,0, +168,208,1,0,112,212,1,0,68,215,1,0,36,218,1,0, +4,221,1,0,140,223,1,0,160,226,1,0,172,229,1,0, +64,233,1,0,88,236,1,0,20,240,1,0,72,244,1,0, +84,248,1,0,228,251,1,0,120,255,1,0,140,3,2,0, +44,6,2,0,8,9,2,0,72,12,2,0,96,15,2,0, +88,23,2,0,116,31,2,0,136,39,2,0,156,44,2,0, +28,47,2,0,92,51,2,0,172,55,2,0,236,59,2,0, +48,64,2,0,132,68,2,0,196,72,2,0,76,73,66,70, +132,2,0,0,68,88,66,67,97,223,247,81,192,181,190,245, +62,154,200,24,62,42,44,199,1,0,0,0,132,2,0,0, +6,0,0,0,56,0,0,0,132,0,0,0,208,0,0,0, +16,1,0,0,140,1,0,0,0,2,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,86,76,32,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,1,0,0,2,0,0,15,224, +0,0,228,144,255,255,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,80,76,32,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,15,176,1,0,0,2,0,0,15,224,0,0,228,176, +255,255,0,0,83,72,68,82,56,0,0,0,64,0,240,255, +14,0,0,0,95,0,0,3,242,16,16,0,0,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,54,0,0,5, +242,32,16,0,0,0,0,0,70,30,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,124,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,120,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,86,101,114,116,101,120,67,111, +108,111,114,0,118,99,0,171,76,73,66,70,176,6,0,0, +68,88,66,67,193,45,92,32,38,130,119,195,162,50,75,220, +113,111,147,34,1,0,0,0,176,6,0,0,6,0,0,0, +56,0,0,0,132,0,0,0,208,0,0,0,24,1,0,0, +148,1,0,0,88,6,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,86,76,20,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,8,0,1,0,0,0,0,0,0,0, +0,2,86,76,1,0,0,2,0,0,15,224,0,0,228,160, +255,255,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,80,76,20,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +0,0,8,0,1,0,0,0,0,0,0,0,0,2,80,76, +1,0,0,2,0,0,15,224,0,0,228,160,255,255,0,0, +83,72,68,82,64,0,0,0,64,0,240,255,16,0,0,0, +89,0,0,4,70,142,32,0,0,0,0,0,9,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,54,0,0,6, +242,32,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +8,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,2,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,0,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,0,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,0,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,0,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,80,0,0,0, +1,0,0,0,8,0,0,0,56,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,76,111,97,100,86,101,114,116, +101,120,67,111,108,111,114,85,110,105,102,111,114,109,0,171, +76,73,66,70,20,8,0,0,68,88,66,67,29,191,205,137, +232,73,220,57,32,180,48,231,114,9,102,236,1,0,0,0, +20,8,0,0,6,0,0,0,56,0,0,0,208,0,0,0, +116,1,0,0,80,2,0,0,204,2,0,0,144,7,0,0, +65,111,110,57,144,0,0,0,144,0,0,0,0,2,86,76, +96,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,4,0, +4,0,0,0,0,0,0,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,5,0,0,3,0,0,7,128, +0,0,85,144,1,0,228,160,4,0,0,4,0,0,7,128, +0,0,228,160,0,0,0,144,0,0,228,128,4,0,0,4, +0,0,7,128,2,0,228,160,0,0,170,144,0,0,228,128, +4,0,0,4,0,0,7,224,3,0,228,160,0,0,255,144, +0,0,228,128,255,255,0,0,65,111,110,57,156,0,0,0, +156,0,0,0,0,2,80,76,108,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,4,0,4,0,0,0,0,0,0,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,15,176, +5,0,0,3,0,0,7,128,0,0,85,176,1,0,228,160, +4,0,0,4,0,0,7,128,0,0,228,160,0,0,0,176, +0,0,228,128,4,0,0,4,0,0,7,128,2,0,228,160, +0,0,170,176,0,0,228,128,4,0,0,4,0,0,7,128, +3,0,228,160,0,0,255,176,0,0,228,128,1,0,0,2, +0,0,7,224,0,0,228,128,255,255,0,0,83,72,68,82, +212,0,0,0,64,0,240,255,53,0,0,0,89,0,0,4, +70,142,32,0,0,0,0,0,8,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,101,0,0,3,114,32,16,0, +0,0,0,0,104,0,0,2,1,0,0,0,56,0,0,8, +114,0,16,0,0,0,0,0,86,21,16,0,0,0,0,0, +70,130,32,0,0,0,0,0,5,0,0,0,50,0,0,10, +114,0,16,0,0,0,0,0,70,130,32,0,0,0,0,0, +4,0,0,0,6,16,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,50,0,0,10,114,0,16,0,0,0,0,0, +70,130,32,0,0,0,0,0,6,0,0,0,166,26,16,0, +0,0,0,0,70,2,16,0,0,0,0,0,50,0,0,10, +114,32,16,0,0,0,0,0,70,130,32,0,0,0,0,0, +7,0,0,0,246,31,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +5,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0, +4,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,2,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,0,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,0,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,0,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,0,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,124,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,115,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,76,111,97,100,69,121,101,80, +111,115,0,118,101,114,116,101,120,0,171,171,76,73,66,70, +76,8,0,0,68,88,66,67,108,68,195,40,106,156,44,20, +245,155,105,169,96,77,47,194,1,0,0,0,76,8,0,0, +6,0,0,0,56,0,0,0,232,0,0,0,132,1,0,0, +132,2,0,0,0,3,0,0,196,7,0,0,65,111,110,57, +168,0,0,0,168,0,0,0,0,2,86,76,120,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,0,0,4,0,3,0,0,0, +0,0,0,0,0,2,86,76,31,0,0,2,5,0,0,128, +0,0,15,144,5,0,0,3,0,0,7,128,0,0,85,144, +1,0,228,160,4,0,0,4,0,0,7,128,0,0,228,160, +0,0,0,144,0,0,228,128,4,0,0,4,0,0,7,128, +2,0,228,160,0,0,170,144,0,0,228,128,8,0,0,3, +0,0,8,128,0,0,228,128,0,0,228,128,7,0,0,2, +0,0,8,128,0,0,255,128,5,0,0,3,0,0,7,224, +0,0,255,128,0,0,228,128,255,255,0,0,65,111,110,57, +148,0,0,0,148,0,0,0,0,2,80,76,100,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,0,0,4,0,3,0,0,0, +0,0,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,5,0,0,3,0,0,7,128,0,0,85,176, +1,0,228,160,4,0,0,4,0,0,7,128,0,0,228,160, +0,0,0,176,0,0,228,128,4,0,0,4,0,0,7,128, +2,0,228,160,0,0,170,176,0,0,228,128,36,0,0,2, +1,0,7,128,0,0,228,128,1,0,0,2,0,0,7,224, +1,0,228,128,255,255,0,0,83,72,68,82,248,0,0,0, +64,0,240,255,62,0,0,0,89,0,0,4,70,142,32,0, +0,0,0,0,7,0,0,0,95,0,0,3,114,16,16,0, +0,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,56,0,0,8,114,0,16,0, +0,0,0,0,86,21,16,0,0,0,0,0,70,130,32,0, +0,0,0,0,5,0,0,0,50,0,0,10,114,0,16,0, +0,0,0,0,70,130,32,0,0,0,0,0,4,0,0,0, +6,16,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +50,0,0,10,114,0,16,0,0,0,0,0,70,130,32,0, +0,0,0,0,6,0,0,0,166,26,16,0,0,0,0,0, +70,2,16,0,0,0,0,0,16,0,0,7,130,0,16,0, +0,0,0,0,70,2,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,68,0,0,5,130,0,16,0,0,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,114,32,16,0, +0,0,0,0,246,15,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +7,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0, +6,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,2,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,0,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,0,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,0,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,0,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,128,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,118,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,76,111,97,100,69,121,101,78, +111,114,109,97,108,0,110,111,114,109,97,108,0,171,171,171, +76,73,66,70,100,2,0,0,68,88,66,67,13,191,80,101, +135,3,145,74,141,73,23,109,153,81,118,66,1,0,0,0, +100,2,0,0,6,0,0,0,56,0,0,0,144,0,0,0, +232,0,0,0,40,1,0,0,164,1,0,0,24,2,0,0, +65,111,110,57,80,0,0,0,80,0,0,0,0,2,86,76, +44,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +81,0,0,5,0,0,15,160,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,2,0,0,7,224, +0,0,0,160,255,255,0,0,65,111,110,57,80,0,0,0, +80,0,0,0,0,2,80,76,44,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,81,0,0,5,0,0,15,160, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,2,0,0,7,224,0,0,0,160,255,255,0,0, +83,72,68,82,56,0,0,0,64,0,240,255,14,0,0,0, +101,0,0,3,114,32,16,0,0,0,0,0,54,0,0,8, +114,32,16,0,0,0,0,0,2,64,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,60,0,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,68,0,0,0,1,0,0,0,8,0,0,0, +56,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +76,111,97,100,90,101,114,111,0,171,171,171,76,73,66,70, +244,2,0,0,68,88,66,67,53,78,34,111,89,96,24,187, +132,251,160,114,111,40,100,183,1,0,0,0,244,2,0,0, +6,0,0,0,56,0,0,0,144,0,0,0,232,0,0,0, +128,1,0,0,252,1,0,0,112,2,0,0,65,111,110,57, +80,0,0,0,80,0,0,0,0,2,86,76,44,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,36,0,0,2,0,0,7,128, +0,0,228,144,1,0,0,2,0,0,7,224,0,0,228,129, +255,255,0,0,65,111,110,57,80,0,0,0,80,0,0,0, +0,2,80,76,44,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,7,176, +36,0,0,2,0,0,7,128,0,0,228,176,1,0,0,2, +0,0,7,224,0,0,228,129,255,255,0,0,83,72,68,82, +144,0,0,0,64,0,240,255,36,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,114,32,16,0, +0,0,0,0,104,0,0,2,1,0,0,0,16,0,0,7, +18,0,16,0,0,0,0,0,70,18,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,68,0,0,5,18,0,16,0, +0,0,0,0,10,0,16,0,0,0,0,0,56,0,0,7, +114,0,16,0,0,0,0,0,6,0,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,54,0,0,6,114,32,16,0, +0,0,0,0,70,2,16,128,65,0,0,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,5,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,4,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,124,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,116,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,86,105,101,119,68,105,114,0, +101,121,101,80,111,115,0,171,76,73,66,70,172,3,0,0, +68,88,66,67,254,31,22,103,65,178,142,215,125,145,113,223, +36,2,176,21,1,0,0,0,172,3,0,0,6,0,0,0, +56,0,0,0,196,0,0,0,92,1,0,0,252,1,0,0, +120,2,0,0,236,2,0,0,65,111,110,57,132,0,0,0, +132,0,0,0,0,2,86,76,96,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,31,0,0,2,5,0,0,128, +0,0,15,144,31,0,0,2,5,0,1,128,1,0,15,144, +1,0,0,2,0,0,7,128,0,0,228,144,8,0,0,3, +0,0,8,128,0,0,228,128,1,0,228,144,2,0,0,3, +0,0,8,128,0,0,255,128,0,0,255,128,4,0,0,4, +0,0,7,224,0,0,255,128,1,0,228,144,0,0,228,129, +255,255,0,0,65,111,110,57,144,0,0,0,144,0,0,0, +0,2,80,76,108,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,7,176, +31,0,0,2,0,0,0,128,1,0,7,176,1,0,0,2, +0,0,7,128,0,0,228,176,8,0,0,3,0,0,8,128, +0,0,228,128,1,0,228,176,2,0,0,3,0,0,8,128, +0,0,255,128,0,0,255,128,4,0,0,4,0,0,7,128, +0,0,255,128,1,0,228,176,0,0,228,129,1,0,0,2, +0,0,7,224,0,0,228,128,255,255,0,0,83,72,68,82, +152,0,0,0,64,0,240,255,38,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,16,0,0,7,18,0,16,0, +0,0,0,0,70,18,16,0,0,0,0,0,70,18,16,0, +1,0,0,0,0,0,0,7,18,0,16,0,0,0,0,0, +10,0,16,0,0,0,0,0,10,0,16,0,0,0,0,0, +50,0,0,10,114,32,16,0,0,0,0,0,6,0,16,0, +0,0,0,0,70,18,16,0,1,0,0,0,70,18,16,128, +65,0,0,0,0,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,4,0,0,0,1,0,0,0,0,0,0,0, +3,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,108,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,60,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +184,0,0,0,3,0,0,0,8,0,0,0,152,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,164,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,172,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,76,111,97,100, +69,121,101,82,101,102,108,0,118,105,101,119,68,105,114,0, +101,121,101,78,111,114,109,97,108,0,171,171,76,73,66,70, +172,6,0,0,68,88,66,67,200,162,94,107,60,63,213,125, +45,223,136,185,236,153,37,63,1,0,0,0,172,6,0,0, +6,0,0,0,56,0,0,0,132,0,0,0,208,0,0,0, +24,1,0,0,148,1,0,0,88,6,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,86,76,20,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,0,0,43,0,1,0,0,0, +0,0,0,0,0,2,86,76,1,0,0,2,0,0,15,224, +0,0,228,160,255,255,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,80,76,20,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,43,0,1,0,0,0,0,0,0,0, +0,2,80,76,1,0,0,2,0,0,15,224,0,0,228,160, +255,255,0,0,83,72,68,82,64,0,0,0,64,0,240,255, +16,0,0,0,89,0,0,4,70,142,32,0,0,0,0,0, +44,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +54,0,0,6,242,32,16,0,0,0,0,0,70,142,32,0, +0,0,0,0,43,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,188,4,0,0, +1,0,0,0,108,0,0,0,1,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,142,4,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,92,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,85,110,105,116, +121,70,70,86,101,114,116,101,120,0,171,171,92,0,0,0, +14,0,0,0,132,0,0,0,240,3,0,0,0,0,0,0, +0,0,0,0,180,2,0,0,0,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,240,2,0,0, +64,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,253,2,0,0,128,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,56,3,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,71,3,0,0,160,0,0,0,128,0,0,0, +0,0,0,0,88,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,124,3,0,0, +32,1,0,0,128,0,0,0,0,0,0,0,140,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,176,3,0,0,160,1,0,0,128,0,0,0, +0,0,0,0,192,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,228,3,0,0, +32,2,0,0,128,0,0,0,0,0,0,0,244,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,24,4,0,0,160,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,39,4,0,0, +176,2,0,0,16,0,0,0,2,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,54,4,0,0,192,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,66,4,0,0, +208,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,82,4,0,0,224,2,0,0,0,1,0,0, +0,0,0,0,96,4,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,132,4,0,0, +224,3,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +112,0,102,108,111,97,116,52,120,52,0,171,3,0,3,0, +4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,0,102,102,95, +118,101,99,95,99,111,108,111,114,0,102,108,111,97,116,52, +0,171,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,118,101,99,95,97, +109,98,105,101,110,116,0,102,102,95,108,105,103,104,116,95, +99,111,108,111,114,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,112,111,115,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,97,116,116,101,110,0,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,115,112,111, +116,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,109,97,116,95,100, +105,102,102,117,115,101,0,102,102,95,109,97,116,95,97,109, +98,105,101,110,116,0,102,102,95,109,97,116,95,115,112,101, +99,0,102,102,95,109,97,116,95,101,109,105,115,115,105,111, +110,0,102,102,95,109,97,116,114,105,120,95,116,101,120,0, +3,0,3,0,4,0,4,0,4,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,102,111,103,95,118,115,0,77,105, +99,114,111,115,111,102,116,32,40,82,41,32,72,76,83,76, +32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114, +32,54,46,51,46,57,52,49,53,46,48,0,76,70,83,48, +76,0,0,0,1,0,0,0,8,0,0,0,56,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,76,111,97,100, +65,109,98,105,101,110,116,67,111,108,111,114,0,171,171,171, +76,73,66,70,172,6,0,0,68,88,66,67,146,119,135,218, +29,151,113,93,178,158,120,136,238,224,122,235,1,0,0,0, +172,6,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,24,1,0,0,148,1,0,0,88,6,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +20,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,42,0, +1,0,0,0,0,0,0,0,0,2,86,76,1,0,0,2, +0,0,15,224,0,0,228,160,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,20,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,0,0,42,0,1,0,0,0, +0,0,0,0,0,2,80,76,1,0,0,2,0,0,15,224, +0,0,228,160,255,255,0,0,83,72,68,82,64,0,0,0, +64,0,240,255,16,0,0,0,89,0,0,4,70,142,32,0, +0,0,0,0,43,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,54,0,0,6,242,32,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,42,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,0,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,0,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,0,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,0,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,2,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,0,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,76,0,0,0,1,0,0,0,8,0,0,0, +56,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +76,111,97,100,68,105,102,102,117,115,101,67,111,108,111,114, +0,171,171,171,76,73,66,70,172,6,0,0,68,88,66,67, +94,177,69,203,112,152,93,11,209,9,165,81,59,198,204,73, +1,0,0,0,172,6,0,0,6,0,0,0,56,0,0,0, +132,0,0,0,208,0,0,0,24,1,0,0,148,1,0,0, +88,6,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,86,76,20,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +0,0,45,0,1,0,0,0,0,0,0,0,0,2,86,76, +1,0,0,2,0,0,15,224,0,0,228,160,255,255,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,80,76, +20,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,45,0, +1,0,0,0,0,0,0,0,0,2,80,76,1,0,0,2, +0,0,15,224,0,0,228,160,255,255,0,0,83,72,68,82, +64,0,0,0,64,0,240,255,16,0,0,0,89,0,0,4, +70,142,32,0,0,0,0,0,46,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,54,0,0,6,242,32,16,0, +0,0,0,0,70,142,32,0,0,0,0,0,45,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,188,4,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +142,4,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,86,101,114,116,101, +120,0,171,171,92,0,0,0,14,0,0,0,132,0,0,0, +240,3,0,0,0,0,0,0,0,0,0,0,180,2,0,0, +0,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,240,2,0,0,64,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,253,2,0,0, +128,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,3,0,0,144,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,71,3,0,0, +160,0,0,0,128,0,0,0,0,0,0,0,88,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,124,3,0,0,32,1,0,0,128,0,0,0, +0,0,0,0,140,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,176,3,0,0, +160,1,0,0,128,0,0,0,0,0,0,0,192,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,228,3,0,0,32,2,0,0,128,0,0,0, +0,0,0,0,244,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,24,4,0,0, +160,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,39,4,0,0,176,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,54,4,0,0, +192,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,66,4,0,0,208,2,0,0,16,0,0,0, +2,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,82,4,0,0, +224,2,0,0,0,1,0,0,0,0,0,0,96,4,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,132,4,0,0,224,3,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,112,0,102,108,111,97,116,52, +120,52,0,171,3,0,3,0,4,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,0,102,102,95,118,101,99,95,99,111,108,111, +114,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,118,101,99,95,97,109,98,105,101,110,116,0,102, +102,95,108,105,103,104,116,95,99,111,108,111,114,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,112,111,115, +0,171,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,97,116,116,101,110,0,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,115,112,111,116,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,109,97,116,95,100,105,102,102,117,115,101,0,102, +102,95,109,97,116,95,97,109,98,105,101,110,116,0,102,102, +95,109,97,116,95,115,112,101,99,0,102,102,95,109,97,116, +95,101,109,105,115,115,105,111,110,0,102,102,95,109,97,116, +114,105,120,95,116,101,120,0,3,0,3,0,4,0,4,0, +4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,102, +111,103,95,118,115,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,76,0,0,0,1,0,0,0, +8,0,0,0,56,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,76,111,97,100,69,109,105,115,115,105,111,110, +67,111,108,111,114,0,171,171,76,73,66,70,164,7,0,0, +68,88,66,67,15,22,159,155,21,14,178,159,161,27,46,101, +18,246,102,242,1,0,0,0,164,7,0,0,6,0,0,0, +56,0,0,0,176,0,0,0,52,1,0,0,164,1,0,0, +32,2,0,0,228,6,0,0,65,111,110,57,112,0,0,0, +112,0,0,0,0,2,86,76,64,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,9,0,1,0,0,0,0,0,0,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,1,0,0,2, +0,0,7,128,1,0,228,144,4,0,0,4,0,0,7,224, +0,0,228,128,0,0,228,160,0,0,228,144,255,255,0,0, +65,111,110,57,124,0,0,0,124,0,0,0,0,2,80,76, +76,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,9,0, +1,0,0,0,0,0,0,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,7,176,31,0,0,2,0,0,0,128, +1,0,7,176,1,0,0,2,0,0,7,128,1,0,228,176, +4,0,0,4,0,0,7,128,0,0,228,128,0,0,228,160, +0,0,228,176,1,0,0,2,0,0,7,224,0,0,228,128, +255,255,0,0,83,72,68,82,104,0,0,0,64,0,240,255, +26,0,0,0,89,0,0,4,70,142,32,0,0,0,0,0, +10,0,0,0,95,0,0,3,114,16,16,0,0,0,0,0, +95,0,0,3,114,16,16,0,1,0,0,0,101,0,0,3, +114,32,16,0,0,0,0,0,50,0,0,10,114,32,16,0, +0,0,0,0,70,18,16,0,1,0,0,0,70,130,32,0, +0,0,0,0,9,0,0,0,70,18,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,188,4,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +142,4,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,86,101,114,116,101, +120,0,171,171,92,0,0,0,14,0,0,0,132,0,0,0, +240,3,0,0,0,0,0,0,0,0,0,0,180,2,0,0, +0,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,240,2,0,0,64,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,253,2,0,0, +128,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,3,0,0,144,0,0,0,16,0,0,0, +2,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,71,3,0,0, +160,0,0,0,128,0,0,0,0,0,0,0,88,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,124,3,0,0,32,1,0,0,128,0,0,0, +0,0,0,0,140,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,176,3,0,0, +160,1,0,0,128,0,0,0,0,0,0,0,192,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,228,3,0,0,32,2,0,0,128,0,0,0, +0,0,0,0,244,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,24,4,0,0, +160,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,39,4,0,0,176,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,54,4,0,0, +192,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,66,4,0,0,208,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,82,4,0,0, +224,2,0,0,0,1,0,0,0,0,0,0,96,4,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,132,4,0,0,224,3,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,112,0,102,108,111,97,116,52, +120,52,0,171,3,0,3,0,4,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,0,102,102,95,118,101,99,95,99,111,108,111, +114,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,118,101,99,95,97,109,98,105,101,110,116,0,102, +102,95,108,105,103,104,116,95,99,111,108,111,114,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,112,111,115, +0,171,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,97,116,116,101,110,0,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,115,112,111,116,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,109,97,116,95,100,105,102,102,117,115,101,0,102, +102,95,109,97,116,95,97,109,98,105,101,110,116,0,102,102, +95,109,97,116,95,115,112,101,99,0,102,102,95,109,97,116, +95,101,109,105,115,115,105,111,110,0,102,102,95,109,97,116, +114,105,120,95,116,101,120,0,3,0,3,0,4,0,4,0, +4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,102, +111,103,95,118,115,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,184,0,0,0,3,0,0,0, +8,0,0,0,152,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,167,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,176,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,73,110,105,116,76,105,103,104,116,67,111,108, +111,114,0,101,109,105,115,115,105,111,110,0,97,109,98,105, +101,110,116,0,76,73,66,70,8,4,0,0,68,88,66,67, +217,57,65,149,73,15,7,156,48,31,51,6,237,141,183,152, +1,0,0,0,8,4,0,0,6,0,0,0,56,0,0,0, +156,0,0,0,0,1,0,0,108,1,0,0,232,1,0,0, +92,2,0,0,65,111,110,57,92,0,0,0,92,0,0,0, +0,2,86,76,56,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,31,0,0,2,5,0,4,128,4,0,15,144, +31,0,0,2,5,0,5,128,5,0,15,144,1,0,0,2, +0,0,7,224,5,0,228,144,1,0,0,2,1,0,7,224, +4,0,228,144,255,255,0,0,65,111,110,57,92,0,0,0, +92,0,0,0,0,2,80,76,56,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,31,0,0,2,0,0,0,128, +4,0,7,176,31,0,0,2,0,0,0,128,5,0,7,176, +1,0,0,2,0,0,7,224,5,0,228,176,1,0,0,2, +1,0,7,224,4,0,228,176,255,255,0,0,83,72,68,82, +100,0,0,0,64,0,240,255,25,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,54,0,0,5, +114,32,16,0,0,0,0,0,70,18,16,0,5,0,0,0, +54,0,0,5,114,32,16,0,1,0,0,0,70,18,16,0, +4,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,164,1,0,0, +7,0,0,0,8,0,0,0,88,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,106,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,118,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,128,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,136,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,149,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,159,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,112,117,116,101,83, +112,111,116,76,105,103,104,116,48,0,101,121,101,80,111,115, +105,116,105,111,110,0,101,121,101,78,111,114,109,97,108,0, +118,105,101,119,68,105,114,0,100,105,102,102,117,115,101,67, +111,108,111,114,0,115,112,101,99,67,111,108,111,114,0,97, +109,98,0,171,76,73,66,70,12,4,0,0,68,88,66,67, +168,113,54,160,157,176,131,165,153,237,223,53,171,61,110,8, +1,0,0,0,12,4,0,0,6,0,0,0,56,0,0,0, +156,0,0,0,0,1,0,0,108,1,0,0,232,1,0,0, +92,2,0,0,65,111,110,57,92,0,0,0,92,0,0,0, +0,2,86,76,56,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,31,0,0,2,5,0,4,128,4,0,15,144, +31,0,0,2,5,0,5,128,5,0,15,144,1,0,0,2, +0,0,7,224,5,0,228,144,1,0,0,2,1,0,7,224, +4,0,228,144,255,255,0,0,65,111,110,57,92,0,0,0, +92,0,0,0,0,2,80,76,56,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,31,0,0,2,0,0,0,128, +4,0,7,176,31,0,0,2,0,0,0,128,5,0,7,176, +1,0,0,2,0,0,7,224,5,0,228,176,1,0,0,2, +1,0,7,224,4,0,228,176,255,255,0,0,83,72,68,82, +100,0,0,0,64,0,240,255,25,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,54,0,0,5, +114,32,16,0,0,0,0,0,70,18,16,0,5,0,0,0, +54,0,0,5,114,32,16,0,1,0,0,0,70,18,16,0, +4,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,168,1,0,0, +7,0,0,0,8,0,0,0,88,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,110,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,122,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,132,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,140,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,153,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,163,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,112,117,116,101,83, +112,111,116,76,105,103,104,116,83,112,101,99,48,0,101,121, +101,80,111,115,105,116,105,111,110,0,101,121,101,78,111,114, +109,97,108,0,118,105,101,119,68,105,114,0,100,105,102,102, +117,115,101,67,111,108,111,114,0,115,112,101,99,67,111,108, +111,114,0,97,109,98,0,171,76,73,66,70,52,15,0,0, +68,88,66,67,19,20,51,10,247,197,70,16,164,41,109,237, +111,182,64,127,1,0,0,0,52,15,0,0,6,0,0,0, +56,0,0,0,156,2,0,0,248,4,0,0,72,8,0,0, +196,8,0,0,136,13,0,0,65,111,110,57,92,2,0,0, +92,2,0,0,0,2,86,76,8,2,0,0,84,0,0,0, +4,0,36,0,0,0,84,0,0,0,84,0,0,0,36,0, +0,0,84,0,0,0,10,0,1,0,0,0,0,0,0,0, +0,0,18,0,1,0,1,0,0,0,0,0,0,0,26,0, +1,0,2,0,0,0,0,0,0,0,34,0,1,0,3,0, +0,0,0,0,0,2,86,76,81,0,0,5,4,0,15,160, +0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,3,128, +3,0,15,144,31,0,0,2,5,0,4,128,4,0,15,144, +31,0,0,2,5,0,5,128,5,0,15,144,5,0,0,3, +0,0,1,128,1,0,255,160,1,0,255,160,12,0,0,3, +0,0,1,128,0,0,0,129,0,0,0,128,4,0,0,4, +0,0,14,128,0,0,144,144,1,0,255,161,1,0,144,160, +8,0,0,3,1,0,1,128,0,0,249,128,0,0,249,128, +12,0,0,3,1,0,2,128,2,0,255,160,1,0,0,128, +5,0,0,3,0,0,1,128,0,0,0,128,1,0,85,128, +1,0,0,2,2,0,1,128,4,0,0,160,4,0,0,4, +1,0,2,128,2,0,170,160,1,0,0,128,2,0,0,128, +7,0,0,2,1,0,1,128,1,0,0,128,5,0,0,3, +0,0,14,128,0,0,228,128,1,0,0,128,6,0,0,2, +1,0,1,128,1,0,85,128,4,0,0,4,0,0,1,128, +0,0,0,128,1,0,0,129,1,0,0,128,8,0,0,3, +1,0,1,128,0,0,249,128,3,0,228,160,8,0,0,3, +0,0,2,128,1,0,228,144,0,0,249,128,11,0,0,3, +0,0,2,128,0,0,85,128,4,0,85,160,5,0,0,3, +0,0,14,128,0,0,85,128,3,0,144,144,5,0,0,3, +0,0,14,128,0,0,228,128,0,0,144,160,11,0,0,3, +1,0,1,128,1,0,0,128,4,0,85,160,2,0,0,3, +1,0,1,128,1,0,0,128,2,0,0,161,5,0,0,3, +1,0,1,128,1,0,0,128,2,0,85,160,11,0,0,3, +1,0,1,128,1,0,0,128,4,0,85,160,10,0,0,3, +1,0,1,128,1,0,0,128,4,0,0,160,5,0,0,3, +0,0,1,128,0,0,0,128,1,0,0,128,5,0,0,3, +0,0,7,128,0,0,0,128,0,0,249,128,10,0,0,3, +0,0,7,128,0,0,228,128,4,0,0,160,2,0,0,3, +0,0,7,224,0,0,228,128,5,0,228,144,1,0,0,2, +1,0,7,224,4,0,228,144,255,255,0,0,65,111,110,57, +84,2,0,0,84,2,0,0,0,2,80,76,0,2,0,0, +84,0,0,0,4,0,36,0,0,0,84,0,0,0,84,0, +0,0,36,0,0,0,84,0,0,0,10,0,1,0,0,0, +0,0,0,0,0,0,18,0,1,0,1,0,0,0,0,0, +0,0,26,0,1,0,2,0,0,0,0,0,0,0,34,0, +1,0,3,0,0,0,0,0,0,2,80,76,81,0,0,5, +4,0,15,160,0,0,128,63,0,0,0,128,0,0,128,191, +0,0,0,0,31,0,0,2,0,0,0,128,0,0,7,176, +31,0,0,2,0,0,0,128,1,0,7,176,31,0,0,2, +0,0,0,128,3,0,7,176,31,0,0,2,0,0,0,128, +4,0,7,176,31,0,0,2,0,0,0,128,5,0,7,176, +4,0,0,4,0,0,7,128,0,0,228,176,1,0,255,161, +1,0,228,160,8,0,0,3,0,0,8,128,0,0,228,128, +0,0,228,128,7,0,0,2,1,0,8,128,0,0,255,128, +5,0,0,3,0,0,7,128,0,0,228,128,1,0,255,128, +8,0,0,3,1,0,1,128,0,0,228,128,3,0,228,160, +8,0,0,3,0,0,1,128,1,0,228,176,0,0,228,128, +11,0,0,3,0,0,2,128,1,0,0,128,4,0,255,160, +2,0,0,3,0,0,2,128,0,0,85,128,2,0,0,161, +5,0,0,3,0,0,18,128,0,0,85,128,2,0,85,160, +1,0,0,2,1,0,1,128,4,0,0,160,4,0,0,4, +0,0,4,128,2,0,170,160,0,0,255,128,1,0,0,128, +2,0,0,3,0,0,8,128,0,0,255,129,2,0,255,160, +88,0,0,4,0,0,8,128,0,0,255,128,4,0,85,160, +4,0,170,160,6,0,0,2,0,0,4,128,0,0,170,128, +5,0,0,3,0,0,2,128,0,0,85,128,0,0,170,128, +5,0,0,3,0,0,4,128,1,0,255,160,1,0,255,160, +88,0,0,4,0,0,4,128,0,0,170,129,4,0,255,160, +0,0,255,128,88,0,0,4,0,0,2,128,0,0,170,128, +0,0,85,128,4,0,255,160,5,0,0,3,1,0,7,128, +0,0,0,128,3,0,228,176,5,0,0,3,1,0,7,128, +1,0,228,128,0,0,228,160,88,0,0,4,1,0,7,128, +0,0,0,128,1,0,228,128,4,0,255,160,5,0,0,3, +0,0,7,128,0,0,85,128,1,0,228,128,10,0,0,3, +1,0,7,128,0,0,228,128,4,0,0,160,2,0,0,3, +0,0,7,128,1,0,228,128,5,0,228,176,1,0,0,2, +0,0,7,224,0,0,228,128,1,0,0,2,1,0,7,224, +4,0,228,176,255,255,0,0,83,72,68,82,72,3,0,0, +64,0,240,255,210,0,0,0,89,0,0,4,70,142,32,0, +0,0,0,0,35,0,0,0,95,0,0,3,114,16,16,0, +0,0,0,0,95,0,0,3,114,16,16,0,1,0,0,0, +95,0,0,3,114,16,16,0,3,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,104,0,0,2, +2,0,0,0,57,0,0,8,18,0,16,0,0,0,0,0, +58,128,32,0,0,0,0,0,18,0,0,0,1,64,0,0, +0,0,0,0,50,0,0,12,226,0,16,0,0,0,0,0, +6,25,16,128,65,0,0,0,0,0,0,0,246,143,32,0, +0,0,0,0,18,0,0,0,6,137,32,0,0,0,0,0, +18,0,0,0,16,0,0,7,18,0,16,0,1,0,0,0, +150,7,16,0,0,0,0,0,150,7,16,0,0,0,0,0, +49,0,0,8,34,0,16,0,1,0,0,0,58,128,32,0, +0,0,0,0,26,0,0,0,10,0,16,0,1,0,0,0, +1,0,0,7,18,0,16,0,0,0,0,0,10,0,16,0, +0,0,0,0,26,0,16,0,1,0,0,0,50,0,0,10, +34,0,16,0,1,0,0,0,42,128,32,0,0,0,0,0, +26,0,0,0,10,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,68,0,0,5,18,0,16,0,1,0,0,0, +10,0,16,0,1,0,0,0,56,0,0,7,226,0,16,0, +0,0,0,0,86,14,16,0,0,0,0,0,6,0,16,0, +1,0,0,0,14,0,0,10,18,0,16,0,1,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,128,63,26,0,16,0,1,0,0,0,55,0,0,9, +18,0,16,0,0,0,0,0,10,0,16,0,0,0,0,0, +1,64,0,0,0,0,0,0,10,0,16,0,1,0,0,0, +16,0,0,8,18,0,16,0,1,0,0,0,150,7,16,0, +0,0,0,0,70,130,32,0,0,0,0,0,34,0,0,0, +16,0,0,7,34,0,16,0,0,0,0,0,70,18,16,0, +1,0,0,0,150,7,16,0,0,0,0,0,52,0,0,7, +34,0,16,0,0,0,0,0,26,0,16,0,0,0,0,0, +1,64,0,0,0,0,0,0,56,0,0,7,226,0,16,0, +0,0,0,0,86,5,16,0,0,0,0,0,6,25,16,0, +3,0,0,0,56,0,0,8,226,0,16,0,0,0,0,0, +86,14,16,0,0,0,0,0,6,137,32,0,0,0,0,0, +10,0,0,0,52,0,0,7,18,0,16,0,1,0,0,0, +10,0,16,0,1,0,0,0,1,64,0,0,0,0,0,0, +0,0,0,9,18,0,16,0,1,0,0,0,10,0,16,0, +1,0,0,0,10,128,32,128,65,0,0,0,0,0,0,0, +26,0,0,0,56,32,0,8,18,0,16,0,1,0,0,0, +10,0,16,0,1,0,0,0,26,128,32,0,0,0,0,0, +26,0,0,0,56,0,0,7,18,0,16,0,0,0,0,0, +10,0,16,0,0,0,0,0,10,0,16,0,1,0,0,0, +56,0,0,7,114,0,16,0,0,0,0,0,6,0,16,0, +0,0,0,0,150,7,16,0,0,0,0,0,51,0,0,10, +114,0,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,0,0,0,0,0,7,114,32,16,0,0,0,0,0, +70,2,16,0,0,0,0,0,70,18,16,0,5,0,0,0, +54,0,0,5,114,32,16,0,1,0,0,0,70,18,16,0, +4,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +24,0,0,0,2,0,0,0,0,0,0,0,7,0,0,0, +20,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,2,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,2,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,2,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,2,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,164,1,0,0, +7,0,0,0,8,0,0,0,88,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,106,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,118,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,128,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,136,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,149,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,159,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,112,117,116,101,83, +112,111,116,76,105,103,104,116,49,0,101,121,101,80,111,115, +105,116,105,111,110,0,101,121,101,78,111,114,109,97,108,0, +118,105,101,119,68,105,114,0,100,105,102,102,117,115,101,67, +111,108,111,114,0,115,112,101,99,67,111,108,111,114,0,97, +109,98,0,171,76,73,66,70,236,17,0,0,68,88,66,67, +216,144,48,14,233,134,86,193,213,85,149,228,66,253,63,44, +1,0,0,0,236,17,0,0,6,0,0,0,56,0,0,0, +60,3,0,0,52,6,0,0,252,10,0,0,120,11,0,0, +60,16,0,0,65,111,110,57,252,2,0,0,252,2,0,0, +0,2,86,76,156,2,0,0,96,0,0,0,5,0,36,0, +0,0,96,0,0,0,96,0,0,0,36,0,0,0,96,0, +0,0,10,0,1,0,0,0,0,0,0,0,0,0,18,0, +1,0,1,0,0,0,0,0,0,0,26,0,1,0,2,0, +0,0,0,0,0,0,34,0,1,0,3,0,0,0,0,0, +0,0,44,0,1,0,4,0,0,0,0,0,0,2,86,76, +81,0,0,5,5,0,15,160,0,0,128,63,0,0,0,0, +0,0,0,0,0,0,0,0,31,0,0,2,5,0,0,128, +0,0,15,144,31,0,0,2,5,0,1,128,1,0,15,144, +31,0,0,2,5,0,2,128,2,0,15,144,31,0,0,2, +5,0,3,128,3,0,15,144,31,0,0,2,5,0,4,128, +4,0,15,144,31,0,0,2,5,0,5,128,5,0,15,144, +5,0,0,3,0,0,1,128,1,0,255,160,1,0,255,160, +12,0,0,3,0,0,1,128,0,0,0,129,0,0,0,128, +4,0,0,4,0,0,14,128,0,0,144,144,1,0,255,161, +1,0,144,160,8,0,0,3,1,0,1,128,0,0,249,128, +0,0,249,128,12,0,0,3,1,0,2,128,2,0,255,160, +1,0,0,128,5,0,0,3,0,0,1,128,0,0,0,128, +1,0,85,128,1,0,0,2,2,0,1,128,5,0,0,160, +4,0,0,4,1,0,2,128,2,0,170,160,1,0,0,128, +2,0,0,128,7,0,0,2,1,0,1,128,1,0,0,128, +6,0,0,2,1,0,2,128,1,0,85,128,4,0,0,4, +0,0,1,128,0,0,0,128,1,0,85,129,1,0,85,128, +5,0,0,3,1,0,14,128,0,0,228,128,1,0,0,128, +4,0,0,4,0,0,14,128,0,0,228,128,1,0,0,128, +2,0,144,144,36,0,0,2,2,0,7,128,0,0,249,128, +8,0,0,3,0,0,2,128,1,0,228,144,2,0,228,128, +11,0,0,3,0,0,2,128,0,0,85,128,5,0,85,160, +32,0,0,3,1,0,1,128,0,0,85,128,4,0,255,160, +10,0,0,3,0,0,2,128,1,0,0,128,5,0,0,160, +8,0,0,3,0,0,4,128,1,0,249,128,3,0,228,160, +8,0,0,3,0,0,8,128,1,0,228,144,1,0,249,128, +11,0,0,3,0,0,12,128,0,0,228,128,5,0,85,160, +2,0,0,3,0,0,4,128,0,0,170,128,2,0,0,161, +5,0,0,3,0,0,4,128,0,0,170,128,2,0,85,160, +11,0,0,3,0,0,4,128,0,0,170,128,5,0,85,160, +10,0,0,3,0,0,4,128,0,0,170,128,5,0,0,160, +5,0,0,3,0,0,1,128,0,0,170,128,0,0,0,128, +5,0,0,3,0,0,2,128,0,0,85,128,0,0,0,128, +5,0,0,3,1,0,7,128,0,0,85,128,0,0,228,160, +12,0,0,3,0,0,2,128,5,0,85,160,0,0,255,128, +5,0,0,3,2,0,7,128,0,0,255,128,3,0,228,144, +5,0,0,3,2,0,7,128,2,0,228,128,0,0,228,160, +5,0,0,3,0,0,13,128,0,0,0,128,2,0,148,128, +10,0,0,3,0,0,13,128,0,0,228,128,5,0,0,160, +2,0,0,3,0,0,7,224,0,0,248,128,5,0,228,144, +4,0,0,4,1,0,7,224,0,0,85,128,1,0,228,128, +4,0,228,144,255,255,0,0,65,111,110,57,240,2,0,0, +240,2,0,0,0,2,80,76,144,2,0,0,96,0,0,0, +5,0,36,0,0,0,96,0,0,0,96,0,0,0,36,0, +0,0,96,0,0,0,10,0,1,0,0,0,0,0,0,0, +0,0,18,0,1,0,1,0,0,0,0,0,0,0,26,0, +1,0,2,0,0,0,0,0,0,0,34,0,1,0,3,0, +0,0,0,0,0,0,44,0,1,0,4,0,0,0,0,0, +0,2,80,76,81,0,0,5,5,0,15,160,0,0,128,63, +0,0,0,128,0,0,128,191,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,7,176,31,0,0,2,0,0,0,128, +1,0,7,176,31,0,0,2,0,0,0,128,2,0,7,176, +31,0,0,2,0,0,0,128,3,0,7,176,31,0,0,2, +0,0,0,128,4,0,7,176,31,0,0,2,0,0,0,128, +5,0,7,176,4,0,0,4,0,0,7,128,0,0,228,176, +1,0,255,161,1,0,228,160,8,0,0,3,0,0,8,128, +0,0,228,128,0,0,228,128,7,0,0,2,1,0,8,128, +0,0,255,128,5,0,0,3,1,0,7,128,0,0,228,128, +1,0,255,128,4,0,0,4,0,0,7,128,0,0,228,128, +1,0,255,128,2,0,228,176,36,0,0,2,2,0,7,128, +0,0,228,128,8,0,0,3,1,0,8,128,1,0,228,176, +2,0,228,128,11,0,0,3,0,0,1,128,1,0,255,128, +5,0,255,160,32,0,0,3,1,0,24,128,0,0,0,128, +4,0,255,160,8,0,0,3,0,0,1,128,1,0,228,128, +3,0,228,160,8,0,0,3,0,0,2,128,1,0,228,176, +1,0,228,128,11,0,0,3,1,0,1,128,0,0,85,128, +5,0,255,160,11,0,0,3,1,0,2,128,0,0,0,128, +5,0,255,160,2,0,0,3,0,0,1,128,1,0,85,128, +2,0,0,161,5,0,0,3,0,0,17,128,0,0,0,128, +2,0,85,160,1,0,0,2,2,0,1,128,5,0,0,160, +4,0,0,4,0,0,2,128,2,0,170,160,0,0,255,128, +2,0,0,128,2,0,0,3,0,0,4,128,0,0,255,129, +2,0,255,160,88,0,0,4,0,0,4,128,0,0,170,128, +5,0,85,160,5,0,170,160,6,0,0,2,0,0,2,128, +0,0,85,128,5,0,0,3,0,0,1,128,0,0,0,128, +0,0,85,128,5,0,0,3,0,0,2,128,1,0,255,160, +1,0,255,160,88,0,0,4,0,0,2,128,0,0,85,129, +5,0,255,160,0,0,170,128,88,0,0,4,0,0,1,128, +0,0,85,128,0,0,0,128,5,0,255,160,5,0,0,3, +0,0,14,128,1,0,0,128,3,0,27,176,5,0,0,3, +0,0,14,128,0,0,228,128,0,0,27,160,5,0,0,3, +0,0,14,128,0,0,0,128,0,0,228,128,5,0,0,3, +0,0,1,128,1,0,255,128,0,0,0,128,4,0,0,4, +1,0,14,128,0,0,0,128,0,0,27,160,4,0,27,176, +88,0,0,4,1,0,7,128,1,0,0,129,4,0,228,176, +1,0,27,128,1,0,0,2,1,0,7,224,1,0,228,128, +10,0,0,3,1,0,7,128,0,0,27,128,5,0,0,160, +2,0,0,3,0,0,7,128,1,0,228,128,5,0,228,176, +1,0,0,2,0,0,7,224,0,0,228,128,255,255,0,0, +83,72,68,82,192,4,0,0,64,0,240,255,48,1,0,0, +89,0,0,4,70,142,32,0,0,0,0,0,45,0,0,0, +95,0,0,3,114,16,16,0,0,0,0,0,95,0,0,3, +114,16,16,0,1,0,0,0,95,0,0,3,114,16,16,0, +2,0,0,0,95,0,0,3,114,16,16,0,3,0,0,0, +95,0,0,3,114,16,16,0,4,0,0,0,95,0,0,3, +114,16,16,0,5,0,0,0,101,0,0,3,114,32,16,0, +0,0,0,0,101,0,0,3,114,32,16,0,1,0,0,0, +104,0,0,2,2,0,0,0,57,0,0,8,18,0,16,0, +0,0,0,0,58,128,32,0,0,0,0,0,18,0,0,0, +1,64,0,0,0,0,0,0,50,0,0,12,226,0,16,0, +0,0,0,0,6,25,16,128,65,0,0,0,0,0,0,0, +246,143,32,0,0,0,0,0,18,0,0,0,6,137,32,0, +0,0,0,0,18,0,0,0,16,0,0,7,18,0,16,0, +1,0,0,0,150,7,16,0,0,0,0,0,150,7,16,0, +0,0,0,0,49,0,0,8,34,0,16,0,1,0,0,0, +58,128,32,0,0,0,0,0,26,0,0,0,10,0,16,0, +1,0,0,0,1,0,0,7,18,0,16,0,0,0,0,0, +10,0,16,0,0,0,0,0,26,0,16,0,1,0,0,0, +50,0,0,10,34,0,16,0,1,0,0,0,42,128,32,0, +0,0,0,0,26,0,0,0,10,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,68,0,0,5,18,0,16,0, +1,0,0,0,10,0,16,0,1,0,0,0,14,0,0,10, +34,0,16,0,1,0,0,0,2,64,0,0,0,0,128,63, +0,0,128,63,0,0,128,63,0,0,128,63,26,0,16,0, +1,0,0,0,55,0,0,9,18,0,16,0,0,0,0,0, +10,0,16,0,0,0,0,0,1,64,0,0,0,0,0,0, +26,0,16,0,1,0,0,0,56,0,0,7,226,0,16,0, +1,0,0,0,86,14,16,0,0,0,0,0,6,0,16,0, +1,0,0,0,50,0,0,9,226,0,16,0,0,0,0,0, +86,14,16,0,0,0,0,0,6,0,16,0,1,0,0,0, +6,25,16,0,2,0,0,0,16,0,0,8,18,0,16,0, +1,0,0,0,150,7,16,0,1,0,0,0,70,130,32,0, +0,0,0,0,34,0,0,0,16,0,0,7,34,0,16,0, +1,0,0,0,70,18,16,0,1,0,0,0,150,7,16,0, +1,0,0,0,52,0,0,10,50,0,16,0,1,0,0,0, +70,0,16,0,1,0,0,0,2,64,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9, +18,0,16,0,1,0,0,0,10,0,16,0,1,0,0,0, +10,128,32,128,65,0,0,0,0,0,0,0,26,0,0,0, +56,32,0,8,18,0,16,0,1,0,0,0,10,0,16,0, +1,0,0,0,26,128,32,0,0,0,0,0,26,0,0,0, +56,0,0,7,18,0,16,0,0,0,0,0,10,0,16,0, +0,0,0,0,10,0,16,0,1,0,0,0,56,0,0,7, +210,0,16,0,1,0,0,0,86,5,16,0,1,0,0,0, +6,25,16,0,3,0,0,0,49,0,0,7,34,0,16,0, +1,0,0,0,1,64,0,0,0,0,0,0,26,0,16,0, +1,0,0,0,56,0,0,8,210,0,16,0,1,0,0,0, +6,14,16,0,1,0,0,0,6,137,32,0,0,0,0,0, +10,0,0,0,56,0,0,7,210,0,16,0,1,0,0,0, +6,0,16,0,0,0,0,0,6,14,16,0,1,0,0,0, +51,0,0,10,210,0,16,0,1,0,0,0,6,14,16,0, +1,0,0,0,2,64,0,0,0,0,128,63,0,0,0,0, +0,0,128,63,0,0,128,63,0,0,0,7,114,32,16,0, +0,0,0,0,134,3,16,0,1,0,0,0,70,18,16,0, +5,0,0,0,16,0,0,7,18,0,16,0,1,0,0,0, +150,7,16,0,0,0,0,0,150,7,16,0,0,0,0,0, +68,0,0,5,18,0,16,0,1,0,0,0,10,0,16,0, +1,0,0,0,56,0,0,7,226,0,16,0,0,0,0,0, +86,14,16,0,0,0,0,0,6,0,16,0,1,0,0,0, +16,0,0,7,34,0,16,0,0,0,0,0,70,18,16,0, +1,0,0,0,150,7,16,0,0,0,0,0,52,0,0,7, +34,0,16,0,0,0,0,0,26,0,16,0,0,0,0,0, +1,64,0,0,0,0,0,0,47,0,0,5,34,0,16,0, +0,0,0,0,26,0,16,0,0,0,0,0,56,0,0,8, +34,0,16,0,0,0,0,0,26,0,16,0,0,0,0,0, +58,128,32,0,0,0,0,0,44,0,0,0,25,0,0,5, +34,0,16,0,0,0,0,0,26,0,16,0,0,0,0,0, +51,0,0,7,34,0,16,0,0,0,0,0,26,0,16,0, +0,0,0,0,1,64,0,0,0,0,128,63,56,0,0,7, +18,0,16,0,0,0,0,0,26,0,16,0,0,0,0,0, +10,0,16,0,0,0,0,0,50,0,0,10,114,0,16,0, +0,0,0,0,6,0,16,0,0,0,0,0,70,130,32,0, +0,0,0,0,10,0,0,0,70,18,16,0,4,0,0,0, +55,0,0,9,114,32,16,0,1,0,0,0,86,5,16,0, +1,0,0,0,70,2,16,0,0,0,0,0,70,18,16,0, +4,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +36,0,0,0,2,0,0,0,0,0,0,0,8,0,0,0, +32,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,2,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,2,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,2,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,2,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,2,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,168,1,0,0, +7,0,0,0,8,0,0,0,88,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,110,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,122,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,132,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,140,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,153,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,163,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,112,117,116,101,83, +112,111,116,76,105,103,104,116,83,112,101,99,49,0,101,121, +101,80,111,115,105,116,105,111,110,0,101,121,101,78,111,114, +109,97,108,0,118,105,101,119,68,105,114,0,100,105,102,102, +117,115,101,67,111,108,111,114,0,115,112,101,99,67,111,108, +111,114,0,97,109,98,0,171,76,73,66,70,8,19,0,0, +68,88,66,67,162,247,150,119,108,183,177,195,169,152,12,225, +187,188,175,22,1,0,0,0,8,19,0,0,6,0,0,0, +56,0,0,0,32,4,0,0,252,7,0,0,28,12,0,0, +152,12,0,0,92,17,0,0,65,111,110,57,224,3,0,0, +224,3,0,0,0,2,86,76,140,3,0,0,84,0,0,0, +4,0,36,0,0,0,84,0,0,0,84,0,0,0,36,0, +0,0,84,0,0,0,10,0,2,0,0,0,0,0,0,0, +0,0,18,0,2,0,2,0,0,0,0,0,0,0,26,0, +2,0,4,0,0,0,0,0,0,0,34,0,2,0,6,0, +0,0,0,0,0,2,86,76,81,0,0,5,8,0,15,160, +0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,3,128, +3,0,15,144,31,0,0,2,5,0,4,128,4,0,15,144, +31,0,0,2,5,0,5,128,5,0,15,144,5,0,0,3, +0,0,1,128,2,0,255,160,2,0,255,160,12,0,0,3, +0,0,1,128,0,0,0,129,0,0,0,128,4,0,0,4, +0,0,14,128,0,0,144,144,2,0,255,161,2,0,144,160, +8,0,0,3,1,0,1,128,0,0,249,128,0,0,249,128, +12,0,0,3,1,0,2,128,4,0,255,160,1,0,0,128, +5,0,0,3,0,0,1,128,0,0,0,128,1,0,85,128, +1,0,0,2,2,0,1,128,8,0,0,160,4,0,0,4, +1,0,2,128,4,0,170,160,1,0,0,128,2,0,0,128, +7,0,0,2,1,0,1,128,1,0,0,128,5,0,0,3, +0,0,14,128,0,0,228,128,1,0,0,128,6,0,0,2, +1,0,1,128,1,0,85,128,4,0,0,4,0,0,1,128, +0,0,0,128,1,0,0,129,1,0,0,128,8,0,0,3, +1,0,1,128,0,0,249,128,6,0,228,160,8,0,0,3, +0,0,2,128,1,0,228,144,0,0,249,128,11,0,0,3, +0,0,2,128,0,0,85,128,8,0,85,160,5,0,0,3, +0,0,14,128,0,0,85,128,3,0,144,144,5,0,0,3, +0,0,14,128,0,0,228,128,0,0,144,160,11,0,0,3, +1,0,1,128,1,0,0,128,8,0,85,160,2,0,0,3, +1,0,1,128,1,0,0,128,4,0,0,161,5,0,0,3, +1,0,1,128,1,0,0,128,4,0,85,160,11,0,0,3, +1,0,1,128,1,0,0,128,8,0,85,160,10,0,0,3, +1,0,1,128,1,0,0,128,8,0,0,160,5,0,0,3, +0,0,1,128,0,0,0,128,1,0,0,128,5,0,0,3, +0,0,7,128,0,0,0,128,0,0,249,128,10,0,0,3, +0,0,7,128,0,0,228,128,8,0,0,160,2,0,0,3, +0,0,7,128,0,0,228,128,5,0,228,144,5,0,0,3, +0,0,8,128,3,0,255,160,3,0,255,160,12,0,0,3, +0,0,8,128,0,0,255,129,0,0,255,128,4,0,0,4, +1,0,7,128,0,0,228,144,3,0,255,161,3,0,228,160, +8,0,0,3,1,0,8,128,1,0,228,128,1,0,228,128, +12,0,0,3,2,0,2,128,5,0,255,160,1,0,255,128, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,85,128, +4,0,0,4,2,0,1,128,5,0,170,160,1,0,255,128, +2,0,0,128,7,0,0,2,1,0,8,128,1,0,255,128, +5,0,0,3,1,0,7,128,1,0,255,128,1,0,228,128, +6,0,0,2,1,0,8,128,2,0,0,128,4,0,0,4, +0,0,8,128,0,0,255,128,1,0,255,129,1,0,255,128, +8,0,0,3,1,0,8,128,1,0,228,128,7,0,228,160, +8,0,0,3,1,0,1,128,1,0,228,144,1,0,228,128, +11,0,0,3,1,0,9,128,1,0,228,128,8,0,85,160, +5,0,0,3,1,0,7,128,1,0,0,128,3,0,228,144, +5,0,0,3,1,0,7,128,1,0,228,128,1,0,228,160, +2,0,0,3,1,0,8,128,1,0,255,128,5,0,0,161, +5,0,0,3,1,0,8,128,1,0,255,128,5,0,85,160, +11,0,0,3,1,0,8,128,1,0,255,128,8,0,85,160, +10,0,0,3,1,0,8,128,1,0,255,128,8,0,0,160, +5,0,0,3,0,0,8,128,0,0,255,128,1,0,255,128, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,1,0,7,128,1,0,228,128,8,0,0,160, +2,0,0,3,0,0,7,224,0,0,228,128,1,0,228,128, +1,0,0,2,1,0,7,224,4,0,228,144,255,255,0,0, +65,111,110,57,212,3,0,0,212,3,0,0,0,2,80,76, +128,3,0,0,84,0,0,0,4,0,36,0,0,0,84,0, +0,0,84,0,0,0,36,0,0,0,84,0,0,0,10,0, +2,0,0,0,0,0,0,0,0,0,18,0,2,0,2,0, +0,0,0,0,0,0,26,0,2,0,4,0,0,0,0,0, +0,0,34,0,2,0,6,0,0,0,0,0,0,2,80,76, +81,0,0,5,8,0,15,160,0,0,128,63,0,0,0,128, +0,0,128,191,0,0,0,0,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,128,1,0,7,176, +31,0,0,2,0,0,0,128,3,0,7,176,31,0,0,2, +0,0,0,128,4,0,7,176,31,0,0,2,0,0,0,128, +5,0,7,176,4,0,0,4,0,0,7,128,0,0,228,176, +2,0,255,161,2,0,228,160,8,0,0,3,0,0,8,128, +0,0,228,128,0,0,228,128,7,0,0,2,1,0,8,128, +0,0,255,128,5,0,0,3,0,0,7,128,0,0,228,128, +1,0,255,128,8,0,0,3,1,0,1,128,0,0,228,128, +6,0,228,160,8,0,0,3,0,0,1,128,1,0,228,176, +0,0,228,128,11,0,0,3,0,0,2,128,1,0,0,128, +8,0,255,160,2,0,0,3,0,0,2,128,0,0,85,128, +4,0,0,161,5,0,0,3,0,0,18,128,0,0,85,128, +4,0,85,160,1,0,0,2,1,0,1,128,8,0,0,160, +4,0,0,4,0,0,4,128,4,0,170,160,0,0,255,128, +1,0,0,128,2,0,0,3,0,0,8,128,0,0,255,129, +4,0,255,160,88,0,0,4,0,0,8,128,0,0,255,128, +8,0,85,160,8,0,170,160,6,0,0,2,0,0,4,128, +0,0,170,128,5,0,0,3,0,0,2,128,0,0,85,128, +0,0,170,128,5,0,0,3,0,0,4,128,2,0,255,160, +2,0,255,160,88,0,0,4,0,0,4,128,0,0,170,129, +8,0,255,160,0,0,255,128,88,0,0,4,0,0,2,128, +0,0,170,128,0,0,85,128,8,0,255,160,5,0,0,3, +1,0,14,128,0,0,0,128,3,0,27,176,5,0,0,3, +1,0,14,128,1,0,228,128,0,0,27,160,88,0,0,4, +1,0,14,128,0,0,0,128,1,0,228,128,8,0,255,160, +5,0,0,3,0,0,7,128,0,0,85,128,1,0,27,128, +10,0,0,3,1,0,14,128,0,0,27,128,8,0,0,160, +2,0,0,3,0,0,7,128,1,0,27,128,5,0,228,176, +4,0,0,4,2,0,7,128,0,0,228,176,3,0,255,161, +3,0,228,160,8,0,0,3,0,0,8,128,2,0,228,128, +2,0,228,128,7,0,0,2,2,0,8,128,0,0,255,128, +5,0,0,3,2,0,7,128,2,0,255,128,2,0,228,128, +8,0,0,3,2,0,8,128,2,0,228,128,7,0,228,160, +8,0,0,3,1,0,2,128,1,0,228,176,2,0,228,128, +11,0,0,3,1,0,4,128,2,0,255,128,8,0,255,160, +2,0,0,3,1,0,4,128,1,0,170,128,5,0,0,161, +5,0,0,3,1,0,20,128,1,0,170,128,5,0,85,160, +4,0,0,4,1,0,1,128,5,0,170,160,0,0,255,128, +1,0,0,128,2,0,0,3,0,0,8,128,0,0,255,129, +5,0,255,160,88,0,0,4,0,0,8,128,0,0,255,128, +8,0,85,160,8,0,170,160,6,0,0,2,1,0,1,128, +1,0,0,128,5,0,0,3,1,0,1,128,1,0,170,128, +1,0,0,128,5,0,0,3,1,0,4,128,3,0,255,160, +3,0,255,160,88,0,0,4,0,0,8,128,1,0,170,129, +8,0,255,160,0,0,255,128,88,0,0,4,0,0,8,128, +0,0,255,128,1,0,0,128,8,0,255,160,5,0,0,3, +2,0,7,128,1,0,85,128,3,0,228,176,5,0,0,3, +2,0,7,128,2,0,228,128,1,0,228,160,88,0,0,4, +1,0,7,128,1,0,85,128,2,0,228,128,8,0,255,160, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,2,0,7,128,1,0,228,128,8,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,2,0,228,128, +1,0,0,2,0,0,7,224,0,0,228,128,1,0,0,2, +1,0,7,224,4,0,228,176,255,255,0,0,83,72,68,82, +24,4,0,0,64,0,240,255,6,1,0,0,89,8,0,4, +70,142,32,0,0,0,0,0,37,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,95,0,0,3,114,16,16,0,3,0,0,0, +95,0,0,3,114,16,16,0,4,0,0,0,95,0,0,3, +114,16,16,0,5,0,0,0,101,0,0,3,114,32,16,0, +0,0,0,0,101,0,0,3,114,32,16,0,1,0,0,0, +104,0,0,2,3,0,0,0,54,0,0,5,114,0,16,0, +0,0,0,0,70,18,16,0,5,0,0,0,54,0,0,5, +130,0,16,0,0,0,0,0,1,64,0,0,0,0,0,0, +48,0,0,1,33,0,0,7,18,0,16,0,1,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,2,0,0,0, +3,0,4,3,10,0,16,0,1,0,0,0,50,0,0,16, +114,0,16,0,1,0,0,0,70,18,16,128,65,0,0,0, +0,0,0,0,246,143,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,70,130,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,50,0,0,12,18,0,16,0, +2,0,0,0,42,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,14,0,0,10,18,0,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,128,63,10,0,16,0,2,0,0,0, +57,0,0,10,34,0,16,0,2,0,0,0,1,64,0,0, +0,0,0,0,58,128,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,49,0,0,10,66,0,16,0, +2,0,0,0,58,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,0,0,7,34,0,16,0,2,0,0,0,42,0,16,0, +2,0,0,0,26,0,16,0,2,0,0,0,55,0,0,9, +18,0,16,0,2,0,0,0,26,0,16,0,2,0,0,0, +1,64,0,0,0,0,0,0,10,0,16,0,2,0,0,0, +68,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,7,114,0,16,0,1,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +16,0,0,10,130,0,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,70,130,32,6,0,0,0,0,34,0,0,0, +58,0,16,0,0,0,0,0,52,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,0,0,0,0,0,11,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,10,128,32,134,65,0,0,0, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,32,0,10,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,26,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,10,0,16,0, +2,0,0,0,16,0,0,7,18,0,16,0,1,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +52,0,0,7,18,0,16,0,1,0,0,0,10,0,16,0, +1,0,0,0,1,64,0,0,0,0,0,0,56,0,0,7, +114,0,16,0,1,0,0,0,6,0,16,0,1,0,0,0, +70,18,16,0,3,0,0,0,56,0,0,10,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,130,32,6, +0,0,0,0,10,0,0,0,58,0,16,0,0,0,0,0, +56,0,0,7,114,0,16,0,1,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,51,0,0,10, +114,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,0,0,0,0,0,7,114,0,16,0,0,0,0,0, +70,2,16,0,0,0,0,0,70,2,16,0,1,0,0,0, +30,0,0,7,130,0,16,0,0,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,1,0,0,0,22,0,0,1, +54,0,0,5,114,32,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,54,0,0,5,114,32,16,0,1,0,0,0, +70,18,16,0,4,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,32,0,0,0,3,0,0,0,0,0,0,0, +7,0,0,0,20,0,0,0,2,0,0,0,1,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +4,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,188,4,0,0, +1,0,0,0,108,0,0,0,1,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,142,4,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,92,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,85,110,105,116, +121,70,70,86,101,114,116,101,120,0,171,171,92,0,0,0, +14,0,0,0,132,0,0,0,240,3,0,0,0,0,0,0, +0,0,0,0,180,2,0,0,0,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,240,2,0,0, +64,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,253,2,0,0,128,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,56,3,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,71,3,0,0,160,0,0,0,128,0,0,0, +2,0,0,0,88,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,124,3,0,0, +32,1,0,0,128,0,0,0,2,0,0,0,140,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,176,3,0,0,160,1,0,0,128,0,0,0, +2,0,0,0,192,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,228,3,0,0, +32,2,0,0,128,0,0,0,2,0,0,0,244,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,24,4,0,0,160,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,39,4,0,0, +176,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,54,4,0,0,192,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,66,4,0,0, +208,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,82,4,0,0,224,2,0,0,0,1,0,0, +0,0,0,0,96,4,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,132,4,0,0, +224,3,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +112,0,102,108,111,97,116,52,120,52,0,171,3,0,3,0, +4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,0,102,102,95, +118,101,99,95,99,111,108,111,114,0,102,108,111,97,116,52, +0,171,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,118,101,99,95,97, +109,98,105,101,110,116,0,102,102,95,108,105,103,104,116,95, +99,111,108,111,114,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,112,111,115,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,97,116,116,101,110,0,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,115,112,111, +116,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,109,97,116,95,100, +105,102,102,117,115,101,0,102,102,95,109,97,116,95,97,109, +98,105,101,110,116,0,102,102,95,109,97,116,95,115,112,101, +99,0,102,102,95,109,97,116,95,101,109,105,115,115,105,111, +110,0,102,102,95,109,97,116,114,105,120,95,116,101,120,0, +3,0,3,0,4,0,4,0,4,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,102,111,103,95,118,115,0,77,105, +99,114,111,115,111,102,116,32,40,82,41,32,72,76,83,76, +32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114, +32,54,46,51,46,57,52,49,53,46,48,0,76,70,83,48, +164,1,0,0,7,0,0,0,8,0,0,0,88,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,106,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,118,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,128,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,136,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,149,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,159,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,50,0,101,121, +101,80,111,115,105,116,105,111,110,0,101,121,101,78,111,114, +109,97,108,0,118,105,101,119,68,105,114,0,100,105,102,102, +117,115,101,67,111,108,111,114,0,115,112,101,99,67,111,108, +111,114,0,97,109,98,0,171,76,73,66,70,80,16,0,0, +68,88,66,67,247,83,83,41,89,91,110,3,164,72,197,192, +107,184,230,166,1,0,0,0,80,16,0,0,5,0,0,0, +52,0,0,0,156,3,0,0,96,9,0,0,220,9,0,0, +160,14,0,0,65,111,110,57,96,3,0,0,96,3,0,0, +0,2,86,76,48,3,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +0,0,0,0,45,0,0,0,0,0,0,0,0,2,86,76, +81,0,0,5,45,0,15,160,0,0,0,0,0,0,0,0, +0,0,128,63,0,0,0,0,48,0,0,5,0,0,15,240, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,2,128, +2,0,15,144,31,0,0,2,5,0,3,128,3,0,15,144, +31,0,0,2,5,0,4,128,4,0,15,144,31,0,0,2, +5,0,5,128,5,0,15,144,1,0,0,2,0,0,7,128, +4,0,228,144,1,0,0,2,1,0,7,128,5,0,228,144, +27,0,0,2,0,8,228,240,0,0,228,240,4,0,0,6, +2,0,7,128,0,0,228,144,18,32,255,161,0,8,228,240, +18,32,228,160,0,8,228,240,8,0,0,3,0,0,8,128, +2,0,228,128,2,0,228,128,7,0,0,2,1,0,8,128, +0,0,255,128,4,0,0,4,3,0,7,128,2,0,228,128, +1,0,255,128,2,0,228,144,36,0,0,2,4,0,7,128, +3,0,228,128,8,0,0,3,2,0,8,128,1,0,228,144, +4,0,228,128,5,0,0,5,3,0,1,128,18,32,255,160, +0,8,228,240,18,32,255,160,0,8,228,240,12,0,0,3, +3,0,1,128,3,0,0,129,3,0,0,128,12,0,0,4, +3,0,2,128,26,32,255,160,0,8,228,240,0,0,255,128, +5,0,0,3,3,0,1,128,3,0,85,128,3,0,0,128, +5,0,0,4,0,0,8,128,0,0,255,128,26,32,170,160, +0,8,228,240,2,0,0,3,0,0,8,128,0,0,255,128, +45,0,170,160,6,0,0,2,0,0,8,128,0,0,255,128, +4,0,0,4,0,0,8,128,3,0,0,128,0,0,255,129, +0,0,255,128,11,0,0,3,2,0,8,128,2,0,255,128, +45,0,85,160,32,0,0,3,3,0,1,128,2,0,255,128, +44,0,255,160,10,0,0,3,2,0,8,128,3,0,0,128, +45,0,170,160,5,0,0,3,2,0,7,128,1,0,255,128, +2,0,228,128,8,0,0,3,1,0,8,128,1,0,228,144, +2,0,228,128,8,0,0,4,2,0,1,128,2,0,228,128, +34,32,228,160,0,8,228,240,11,0,0,3,2,0,1,128, +2,0,0,128,45,0,85,160,2,0,0,4,2,0,1,128, +2,0,0,128,26,32,0,161,0,8,228,240,5,0,0,4, +2,0,1,128,2,0,0,128,26,32,85,160,0,8,228,240, +11,0,0,3,2,0,1,128,2,0,0,128,45,0,85,160, +10,0,0,3,2,0,1,128,2,0,0,128,45,0,170,160, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,0,128, +11,0,0,3,1,0,8,128,1,0,255,128,45,0,85,160, +12,0,0,3,2,0,1,128,45,0,85,160,1,0,255,128, +5,0,0,3,2,0,2,128,2,0,255,128,0,0,255,128, +5,0,0,4,2,0,14,128,2,0,85,128,10,32,144,160, +0,8,228,240,4,0,0,4,0,0,7,128,2,0,0,128, +2,0,249,128,0,0,228,128,5,0,0,3,2,0,7,128, +1,0,255,128,3,0,228,144,5,0,0,4,2,0,7,128, +2,0,228,128,10,32,228,160,0,8,228,240,5,0,0,3, +2,0,7,128,0,0,255,128,2,0,228,128,10,0,0,3, +2,0,7,128,2,0,228,128,45,0,170,160,2,0,0,3, +1,0,7,128,1,0,228,128,2,0,228,128,29,0,0,0, +1,0,0,2,1,0,7,224,0,0,228,128,1,0,0,2, +0,0,7,224,1,0,228,128,255,255,0,0,83,72,68,82, +188,5,0,0,64,0,240,255,111,1,0,0,89,8,0,4, +70,142,32,0,0,0,0,0,45,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,95,0,0,3,114,16,16,0,2,0,0,0, +95,0,0,3,114,16,16,0,3,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,104,0,0,2, +4,0,0,0,54,0,0,5,114,0,16,0,0,0,0,0, +70,18,16,0,4,0,0,0,54,0,0,5,114,0,16,0, +1,0,0,0,70,18,16,0,5,0,0,0,54,0,0,5, +130,0,16,0,0,0,0,0,1,64,0,0,0,0,0,0, +48,0,0,1,33,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,2,0,0,0, +3,0,4,3,58,0,16,0,1,0,0,0,50,0,0,16, +114,0,16,0,2,0,0,0,70,18,16,128,65,0,0,0, +0,0,0,0,246,143,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,70,130,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,50,0,0,12,130,0,16,0, +2,0,0,0,42,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,14,0,0,10,130,0,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,128,63,58,0,16,0,2,0,0,0, +57,0,0,10,18,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,58,128,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,49,0,0,10,34,0,16,0, +3,0,0,0,58,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,0,0,7,18,0,16,0,3,0,0,0,26,0,16,0, +3,0,0,0,10,0,16,0,3,0,0,0,55,0,0,9, +130,0,16,0,2,0,0,0,10,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,58,0,16,0,2,0,0,0, +68,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,7,114,0,16,0,3,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +16,0,0,10,130,0,16,0,3,0,0,0,70,2,16,0, +3,0,0,0,70,130,32,6,0,0,0,0,34,0,0,0, +58,0,16,0,0,0,0,0,52,0,0,7,130,0,16,0, +3,0,0,0,58,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,0,0,0,11,130,0,16,0,3,0,0,0, +58,0,16,0,3,0,0,0,10,128,32,134,65,0,0,0, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,32,0,10,130,0,16,0,3,0,0,0,58,0,16,0, +3,0,0,0,26,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,130,0,16,0, +2,0,0,0,58,0,16,0,2,0,0,0,58,0,16,0, +3,0,0,0,16,0,0,7,18,0,16,0,3,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,3,0,0,0, +52,0,0,7,18,0,16,0,3,0,0,0,10,0,16,0, +3,0,0,0,1,64,0,0,0,0,0,0,56,0,0,7, +226,0,16,0,3,0,0,0,6,0,16,0,3,0,0,0, +6,25,16,0,3,0,0,0,56,0,0,10,226,0,16,0, +3,0,0,0,86,14,16,0,3,0,0,0,6,137,32,6, +0,0,0,0,10,0,0,0,58,0,16,0,0,0,0,0, +49,0,0,7,18,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,10,0,16,0,3,0,0,0,31,0,4,3, +10,0,16,0,3,0,0,0,50,0,0,9,114,0,16,0, +2,0,0,0,70,2,16,0,2,0,0,0,246,15,16,0, +1,0,0,0,70,18,16,0,2,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,68,0,0,5,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,56,0,0,7, +114,0,16,0,2,0,0,0,246,15,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,18,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,52,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,0,0, +47,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,8,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,58,128,32,0,0,0,0,0, +44,0,0,0,25,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,51,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,56,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,58,0,16,0,2,0,0,0, +50,0,0,12,114,0,16,0,0,0,0,0,246,15,16,0, +1,0,0,0,70,130,32,6,0,0,0,0,10,0,0,0, +58,0,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +21,0,0,1,56,0,0,7,114,0,16,0,2,0,0,0, +246,15,16,0,2,0,0,0,150,7,16,0,3,0,0,0, +51,0,0,10,114,0,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,0,0,0,0,0,7,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,30,0,0,7,130,0,16,0,0,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,1,0,0,0, +22,0,0,1,54,0,0,5,114,32,16,0,1,0,0,0, +70,2,16,0,0,0,0,0,54,0,0,5,114,32,16,0, +0,0,0,0,70,2,16,0,1,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,48,0,0,0,4,0,0,0, +0,0,0,0,8,0,0,0,33,0,0,0,2,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,5,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,2,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,2,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,2,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,2,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,2,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,0,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,168,1,0,0,7,0,0,0,8,0,0,0, +88,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +110,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +122,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +132,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +2,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +140,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +153,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +163,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +5,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +67,111,109,112,117,116,101,83,112,111,116,76,105,103,104,116, +83,112,101,99,50,0,101,121,101,80,111,115,105,116,105,111, +110,0,101,121,101,78,111,114,109,97,108,0,118,105,101,119, +68,105,114,0,100,105,102,102,117,115,101,67,111,108,111,114, +0,115,112,101,99,67,111,108,111,114,0,97,109,98,0,171, +76,73,66,70,172,16,0,0,68,88,66,67,196,226,164,1, +85,73,127,248,194,26,134,144,141,122,227,103,1,0,0,0, +172,16,0,0,5,0,0,0,52,0,0,0,160,5,0,0, +192,9,0,0,60,10,0,0,0,15,0,0,65,111,110,57, +100,5,0,0,100,5,0,0,0,2,86,76,16,5,0,0, +84,0,0,0,4,0,36,0,0,0,84,0,0,0,84,0, +0,0,36,0,0,0,84,0,0,0,10,0,3,0,0,0, +0,0,0,0,0,0,18,0,3,0,3,0,0,0,0,0, +0,0,26,0,3,0,6,0,0,0,0,0,0,0,34,0, +3,0,9,0,0,0,0,0,0,2,86,76,81,0,0,5, +12,0,15,160,0,0,128,63,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,31,0,0,2, +5,0,3,128,3,0,15,144,31,0,0,2,5,0,4,128, +4,0,15,144,31,0,0,2,5,0,5,128,5,0,15,144, +5,0,0,3,0,0,1,128,3,0,255,160,3,0,255,160, +12,0,0,3,0,0,1,128,0,0,0,129,0,0,0,128, +4,0,0,4,0,0,14,128,0,0,144,144,3,0,255,161, +3,0,144,160,8,0,0,3,1,0,1,128,0,0,249,128, +0,0,249,128,12,0,0,3,1,0,2,128,6,0,255,160, +1,0,0,128,5,0,0,3,0,0,1,128,0,0,0,128, +1,0,85,128,1,0,0,2,2,0,1,128,12,0,0,160, +4,0,0,4,1,0,2,128,6,0,170,160,1,0,0,128, +2,0,0,128,7,0,0,2,1,0,1,128,1,0,0,128, +5,0,0,3,0,0,14,128,0,0,228,128,1,0,0,128, +6,0,0,2,1,0,1,128,1,0,85,128,4,0,0,4, +0,0,1,128,0,0,0,128,1,0,0,129,1,0,0,128, +8,0,0,3,1,0,1,128,0,0,249,128,9,0,228,160, +8,0,0,3,0,0,2,128,1,0,228,144,0,0,249,128, +11,0,0,3,0,0,2,128,0,0,85,128,12,0,85,160, +5,0,0,3,0,0,14,128,0,0,85,128,3,0,144,144, +5,0,0,3,0,0,14,128,0,0,228,128,0,0,144,160, +11,0,0,3,1,0,1,128,1,0,0,128,12,0,85,160, +2,0,0,3,1,0,1,128,1,0,0,128,6,0,0,161, +5,0,0,3,1,0,1,128,1,0,0,128,6,0,85,160, +11,0,0,3,1,0,1,128,1,0,0,128,12,0,85,160, +10,0,0,3,1,0,1,128,1,0,0,128,12,0,0,160, +5,0,0,3,0,0,1,128,0,0,0,128,1,0,0,128, +5,0,0,3,0,0,7,128,0,0,0,128,0,0,249,128, +10,0,0,3,0,0,7,128,0,0,228,128,12,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,5,0,228,144, +5,0,0,3,0,0,8,128,4,0,255,160,4,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,4,0,255,161, +4,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,7,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,2,128,7,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,85,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +10,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +12,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +1,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +7,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +7,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +12,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +12,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +12,0,0,160,2,0,0,3,0,0,7,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,8,128,5,0,255,160, +5,0,255,160,12,0,0,3,0,0,8,128,0,0,255,129, +0,0,255,128,4,0,0,4,1,0,7,128,0,0,228,144, +5,0,255,161,5,0,228,160,8,0,0,3,1,0,8,128, +1,0,228,128,1,0,228,128,12,0,0,3,2,0,2,128, +8,0,255,160,1,0,255,128,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,85,128,4,0,0,4,2,0,1,128, +8,0,170,160,1,0,255,128,2,0,0,128,7,0,0,2, +1,0,8,128,1,0,255,128,5,0,0,3,1,0,7,128, +1,0,255,128,1,0,228,128,6,0,0,2,1,0,8,128, +2,0,0,128,4,0,0,4,0,0,8,128,0,0,255,128, +1,0,255,129,1,0,255,128,8,0,0,3,1,0,8,128, +1,0,228,128,11,0,228,160,8,0,0,3,1,0,1,128, +1,0,228,144,1,0,228,128,11,0,0,3,1,0,9,128, +1,0,228,128,12,0,85,160,5,0,0,3,1,0,7,128, +1,0,0,128,3,0,228,144,5,0,0,3,1,0,7,128, +1,0,228,128,2,0,228,160,2,0,0,3,1,0,8,128, +1,0,255,128,8,0,0,161,5,0,0,3,1,0,8,128, +1,0,255,128,8,0,85,160,11,0,0,3,1,0,8,128, +1,0,255,128,12,0,85,160,10,0,0,3,1,0,8,128, +1,0,255,128,12,0,0,160,5,0,0,3,0,0,8,128, +0,0,255,128,1,0,255,128,5,0,0,3,1,0,7,128, +0,0,255,128,1,0,228,128,10,0,0,3,1,0,7,128, +1,0,228,128,12,0,0,160,2,0,0,3,0,0,7,224, +0,0,228,128,1,0,228,128,1,0,0,2,1,0,7,224, +4,0,228,144,255,255,0,0,83,72,68,82,24,4,0,0, +64,0,240,255,6,1,0,0,89,8,0,4,70,142,32,0, +0,0,0,0,38,0,0,0,95,0,0,3,114,16,16,0, +0,0,0,0,95,0,0,3,114,16,16,0,1,0,0,0, +95,0,0,3,114,16,16,0,3,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,104,0,0,2, +3,0,0,0,54,0,0,5,114,0,16,0,0,0,0,0, +70,18,16,0,5,0,0,0,54,0,0,5,130,0,16,0, +0,0,0,0,1,64,0,0,0,0,0,0,48,0,0,1, +33,0,0,7,18,0,16,0,1,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,3,0,0,0,3,0,4,3, +10,0,16,0,1,0,0,0,50,0,0,16,114,0,16,0, +1,0,0,0,70,18,16,128,65,0,0,0,0,0,0,0, +246,143,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,70,130,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,50,0,0,12,18,0,16,0,2,0,0,0, +42,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,14,0,0,10,18,0,16,0,2,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,128,63,10,0,16,0,2,0,0,0,57,0,0,10, +34,0,16,0,2,0,0,0,1,64,0,0,0,0,0,0, +58,128,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,49,0,0,10,66,0,16,0,2,0,0,0, +58,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,0,0,7, +34,0,16,0,2,0,0,0,42,0,16,0,2,0,0,0, +26,0,16,0,2,0,0,0,55,0,0,9,18,0,16,0, +2,0,0,0,26,0,16,0,2,0,0,0,1,64,0,0, +0,0,0,0,10,0,16,0,2,0,0,0,68,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +56,0,0,7,114,0,16,0,1,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,16,0,0,10, +130,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +70,130,32,6,0,0,0,0,34,0,0,0,58,0,16,0, +0,0,0,0,52,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,0,0, +0,0,0,11,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,10,128,32,134,65,0,0,0,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,56,32,0,10, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +26,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,56,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,10,0,16,0,2,0,0,0, +16,0,0,7,18,0,16,0,1,0,0,0,70,18,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,52,0,0,7, +18,0,16,0,1,0,0,0,10,0,16,0,1,0,0,0, +1,64,0,0,0,0,0,0,56,0,0,7,114,0,16,0, +1,0,0,0,6,0,16,0,1,0,0,0,70,18,16,0, +3,0,0,0,56,0,0,10,114,0,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,70,130,32,6,0,0,0,0, +10,0,0,0,58,0,16,0,0,0,0,0,56,0,0,7, +114,0,16,0,1,0,0,0,246,15,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,51,0,0,10,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,2,64,0,0, +0,0,128,63,0,0,128,63,0,0,128,63,0,0,0,0, +0,0,0,7,114,0,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,70,2,16,0,1,0,0,0,30,0,0,7, +130,0,16,0,0,0,0,0,58,0,16,0,0,0,0,0, +1,64,0,0,1,0,0,0,22,0,0,1,54,0,0,5, +114,32,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +54,0,0,5,114,32,16,0,1,0,0,0,70,18,16,0, +4,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +32,0,0,0,3,0,0,0,0,0,0,0,7,0,0,0, +20,0,0,0,2,0,0,0,1,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,2,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,2,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,2,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,2,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,164,1,0,0, +7,0,0,0,8,0,0,0,88,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,106,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,118,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,128,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,136,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,149,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,159,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,112,117,116,101,83, +112,111,116,76,105,103,104,116,51,0,101,121,101,80,111,115, +105,116,105,111,110,0,101,121,101,78,111,114,109,97,108,0, +118,105,101,119,68,105,114,0,100,105,102,102,117,115,101,67, +111,108,111,114,0,115,112,101,99,67,111,108,111,114,0,97, +109,98,0,171,76,73,66,70,80,16,0,0,68,88,66,67, +170,38,218,251,246,216,107,194,180,253,56,94,218,55,46,138, +1,0,0,0,80,16,0,0,5,0,0,0,52,0,0,0, +156,3,0,0,96,9,0,0,220,9,0,0,160,14,0,0, +65,111,110,57,96,3,0,0,96,3,0,0,0,2,86,76, +48,3,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,0,0, +45,0,0,0,0,0,0,0,0,2,86,76,81,0,0,5, +45,0,15,160,0,0,0,0,0,0,0,0,0,0,128,63, +0,0,0,0,48,0,0,5,0,0,15,240,3,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,31,0,0,2,5,0,1,128, +1,0,15,144,31,0,0,2,5,0,2,128,2,0,15,144, +31,0,0,2,5,0,3,128,3,0,15,144,31,0,0,2, +5,0,4,128,4,0,15,144,31,0,0,2,5,0,5,128, +5,0,15,144,1,0,0,2,0,0,7,128,4,0,228,144, +1,0,0,2,1,0,7,128,5,0,228,144,27,0,0,2, +0,8,228,240,0,0,228,240,4,0,0,6,2,0,7,128, +0,0,228,144,18,32,255,161,0,8,228,240,18,32,228,160, +0,8,228,240,8,0,0,3,0,0,8,128,2,0,228,128, +2,0,228,128,7,0,0,2,1,0,8,128,0,0,255,128, +4,0,0,4,3,0,7,128,2,0,228,128,1,0,255,128, +2,0,228,144,36,0,0,2,4,0,7,128,3,0,228,128, +8,0,0,3,2,0,8,128,1,0,228,144,4,0,228,128, +5,0,0,5,3,0,1,128,18,32,255,160,0,8,228,240, +18,32,255,160,0,8,228,240,12,0,0,3,3,0,1,128, +3,0,0,129,3,0,0,128,12,0,0,4,3,0,2,128, +26,32,255,160,0,8,228,240,0,0,255,128,5,0,0,3, +3,0,1,128,3,0,85,128,3,0,0,128,5,0,0,4, +0,0,8,128,0,0,255,128,26,32,170,160,0,8,228,240, +2,0,0,3,0,0,8,128,0,0,255,128,45,0,170,160, +6,0,0,2,0,0,8,128,0,0,255,128,4,0,0,4, +0,0,8,128,3,0,0,128,0,0,255,129,0,0,255,128, +11,0,0,3,2,0,8,128,2,0,255,128,45,0,85,160, +32,0,0,3,3,0,1,128,2,0,255,128,44,0,255,160, +10,0,0,3,2,0,8,128,3,0,0,128,45,0,170,160, +5,0,0,3,2,0,7,128,1,0,255,128,2,0,228,128, +8,0,0,3,1,0,8,128,1,0,228,144,2,0,228,128, +8,0,0,4,2,0,1,128,2,0,228,128,34,32,228,160, +0,8,228,240,11,0,0,3,2,0,1,128,2,0,0,128, +45,0,85,160,2,0,0,4,2,0,1,128,2,0,0,128, +26,32,0,161,0,8,228,240,5,0,0,4,2,0,1,128, +2,0,0,128,26,32,85,160,0,8,228,240,11,0,0,3, +2,0,1,128,2,0,0,128,45,0,85,160,10,0,0,3, +2,0,1,128,2,0,0,128,45,0,170,160,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,0,128,11,0,0,3, +1,0,8,128,1,0,255,128,45,0,85,160,12,0,0,3, +2,0,1,128,45,0,85,160,1,0,255,128,5,0,0,3, +2,0,2,128,2,0,255,128,0,0,255,128,5,0,0,4, +2,0,14,128,2,0,85,128,10,32,144,160,0,8,228,240, +4,0,0,4,0,0,7,128,2,0,0,128,2,0,249,128, +0,0,228,128,5,0,0,3,2,0,7,128,1,0,255,128, +3,0,228,144,5,0,0,4,2,0,7,128,2,0,228,128, +10,32,228,160,0,8,228,240,5,0,0,3,2,0,7,128, +0,0,255,128,2,0,228,128,10,0,0,3,2,0,7,128, +2,0,228,128,45,0,170,160,2,0,0,3,1,0,7,128, +1,0,228,128,2,0,228,128,29,0,0,0,1,0,0,2, +1,0,7,224,0,0,228,128,1,0,0,2,0,0,7,224, +1,0,228,128,255,255,0,0,83,72,68,82,188,5,0,0, +64,0,240,255,111,1,0,0,89,8,0,4,70,142,32,0, +0,0,0,0,45,0,0,0,95,0,0,3,114,16,16,0, +0,0,0,0,95,0,0,3,114,16,16,0,1,0,0,0, +95,0,0,3,114,16,16,0,2,0,0,0,95,0,0,3, +114,16,16,0,3,0,0,0,95,0,0,3,114,16,16,0, +4,0,0,0,95,0,0,3,114,16,16,0,5,0,0,0, +101,0,0,3,114,32,16,0,0,0,0,0,101,0,0,3, +114,32,16,0,1,0,0,0,104,0,0,2,4,0,0,0, +54,0,0,5,114,0,16,0,0,0,0,0,70,18,16,0, +4,0,0,0,54,0,0,5,114,0,16,0,1,0,0,0, +70,18,16,0,5,0,0,0,54,0,0,5,130,0,16,0, +0,0,0,0,1,64,0,0,0,0,0,0,48,0,0,1, +33,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,3,0,0,0,3,0,4,3, +58,0,16,0,1,0,0,0,50,0,0,16,114,0,16,0, +2,0,0,0,70,18,16,128,65,0,0,0,0,0,0,0, +246,143,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,70,130,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,50,0,0,12,130,0,16,0,2,0,0,0, +42,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,14,0,0,10,130,0,16,0,2,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,128,63,58,0,16,0,2,0,0,0,57,0,0,10, +18,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +58,128,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,49,0,0,10,34,0,16,0,3,0,0,0, +58,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,0,0,7, +18,0,16,0,3,0,0,0,26,0,16,0,3,0,0,0, +10,0,16,0,3,0,0,0,55,0,0,9,130,0,16,0, +2,0,0,0,10,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,58,0,16,0,2,0,0,0,68,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +56,0,0,7,114,0,16,0,3,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,16,0,0,10, +130,0,16,0,3,0,0,0,70,2,16,0,3,0,0,0, +70,130,32,6,0,0,0,0,34,0,0,0,58,0,16,0, +0,0,0,0,52,0,0,7,130,0,16,0,3,0,0,0, +58,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +0,0,0,11,130,0,16,0,3,0,0,0,58,0,16,0, +3,0,0,0,10,128,32,134,65,0,0,0,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,56,32,0,10, +130,0,16,0,3,0,0,0,58,0,16,0,3,0,0,0, +26,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,56,0,0,7,130,0,16,0,2,0,0,0, +58,0,16,0,2,0,0,0,58,0,16,0,3,0,0,0, +16,0,0,7,18,0,16,0,3,0,0,0,70,18,16,0, +1,0,0,0,70,2,16,0,3,0,0,0,52,0,0,7, +18,0,16,0,3,0,0,0,10,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,56,0,0,7,226,0,16,0, +3,0,0,0,6,0,16,0,3,0,0,0,6,25,16,0, +3,0,0,0,56,0,0,10,226,0,16,0,3,0,0,0, +86,14,16,0,3,0,0,0,6,137,32,6,0,0,0,0, +10,0,0,0,58,0,16,0,0,0,0,0,49,0,0,7, +18,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +10,0,16,0,3,0,0,0,31,0,4,3,10,0,16,0, +3,0,0,0,50,0,0,9,114,0,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,246,15,16,0,1,0,0,0, +70,18,16,0,2,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,68,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,56,0,0,7,114,0,16,0, +2,0,0,0,246,15,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,16,0,0,7,130,0,16,0,1,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +52,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,1,64,0,0,0,0,0,0,47,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +56,0,0,8,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,58,128,32,0,0,0,0,0,44,0,0,0, +25,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,51,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,128,63, +56,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,58,0,16,0,2,0,0,0,50,0,0,12, +114,0,16,0,0,0,0,0,246,15,16,0,1,0,0,0, +70,130,32,6,0,0,0,0,10,0,0,0,58,0,16,0, +0,0,0,0,70,2,16,0,0,0,0,0,21,0,0,1, +56,0,0,7,114,0,16,0,2,0,0,0,246,15,16,0, +2,0,0,0,150,7,16,0,3,0,0,0,51,0,0,10, +114,0,16,0,2,0,0,0,70,2,16,0,2,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,0,0,0,0,0,7,114,0,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +30,0,0,7,130,0,16,0,0,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,1,0,0,0,22,0,0,1, +54,0,0,5,114,32,16,0,1,0,0,0,70,2,16,0, +0,0,0,0,54,0,0,5,114,32,16,0,0,0,0,0, +70,2,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,48,0,0,0,4,0,0,0,0,0,0,0, +8,0,0,0,33,0,0,0,2,0,0,0,1,0,0,0, +1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +5,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,188,4,0,0, +1,0,0,0,108,0,0,0,1,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,142,4,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,92,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,85,110,105,116, +121,70,70,86,101,114,116,101,120,0,171,171,92,0,0,0, +14,0,0,0,132,0,0,0,240,3,0,0,0,0,0,0, +0,0,0,0,180,2,0,0,0,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,240,2,0,0, +64,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,253,2,0,0,128,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,56,3,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,71,3,0,0,160,0,0,0,128,0,0,0, +2,0,0,0,88,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,124,3,0,0, +32,1,0,0,128,0,0,0,2,0,0,0,140,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,176,3,0,0,160,1,0,0,128,0,0,0, +2,0,0,0,192,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,228,3,0,0, +32,2,0,0,128,0,0,0,2,0,0,0,244,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,24,4,0,0,160,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,39,4,0,0, +176,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,54,4,0,0,192,2,0,0,16,0,0,0, +2,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,66,4,0,0, +208,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,82,4,0,0,224,2,0,0,0,1,0,0, +0,0,0,0,96,4,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,132,4,0,0, +224,3,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +112,0,102,108,111,97,116,52,120,52,0,171,3,0,3,0, +4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,0,102,102,95, +118,101,99,95,99,111,108,111,114,0,102,108,111,97,116,52, +0,171,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,118,101,99,95,97, +109,98,105,101,110,116,0,102,102,95,108,105,103,104,116,95, +99,111,108,111,114,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,112,111,115,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,97,116,116,101,110,0,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,115,112,111, +116,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,109,97,116,95,100, +105,102,102,117,115,101,0,102,102,95,109,97,116,95,97,109, +98,105,101,110,116,0,102,102,95,109,97,116,95,115,112,101, +99,0,102,102,95,109,97,116,95,101,109,105,115,115,105,111, +110,0,102,102,95,109,97,116,114,105,120,95,116,101,120,0, +3,0,3,0,4,0,4,0,4,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,102,111,103,95,118,115,0,77,105, +99,114,111,115,111,102,116,32,40,82,41,32,72,76,83,76, +32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114, +32,54,46,51,46,57,52,49,53,46,48,0,76,70,83,48, +168,1,0,0,7,0,0,0,8,0,0,0,88,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,110,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,122,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,132,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,140,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,153,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,163,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,83,112,101,99, +51,0,101,121,101,80,111,115,105,116,105,111,110,0,101,121, +101,78,111,114,109,97,108,0,118,105,101,119,68,105,114,0, +100,105,102,102,117,115,101,67,111,108,111,114,0,115,112,101, +99,67,111,108,111,114,0,97,109,98,0,171,76,73,66,70, +48,18,0,0,68,88,66,67,2,125,230,23,98,206,70,179, +136,149,189,146,48,38,11,143,1,0,0,0,48,18,0,0, +5,0,0,0,52,0,0,0,36,7,0,0,68,11,0,0, +192,11,0,0,132,16,0,0,65,111,110,57,232,6,0,0, +232,6,0,0,0,2,86,76,148,6,0,0,84,0,0,0, +4,0,36,0,0,0,84,0,0,0,84,0,0,0,36,0, +0,0,84,0,0,0,10,0,4,0,0,0,0,0,0,0, +0,0,18,0,4,0,4,0,0,0,0,0,0,0,26,0, +4,0,8,0,0,0,0,0,0,0,34,0,4,0,12,0, +0,0,0,0,0,2,86,76,81,0,0,5,16,0,15,160, +0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,3,128, +3,0,15,144,31,0,0,2,5,0,4,128,4,0,15,144, +31,0,0,2,5,0,5,128,5,0,15,144,5,0,0,3, +0,0,1,128,4,0,255,160,4,0,255,160,12,0,0,3, +0,0,1,128,0,0,0,129,0,0,0,128,4,0,0,4, +0,0,14,128,0,0,144,144,4,0,255,161,4,0,144,160, +8,0,0,3,1,0,1,128,0,0,249,128,0,0,249,128, +12,0,0,3,1,0,2,128,8,0,255,160,1,0,0,128, +5,0,0,3,0,0,1,128,0,0,0,128,1,0,85,128, +1,0,0,2,2,0,1,128,16,0,0,160,4,0,0,4, +1,0,2,128,8,0,170,160,1,0,0,128,2,0,0,128, +7,0,0,2,1,0,1,128,1,0,0,128,5,0,0,3, +0,0,14,128,0,0,228,128,1,0,0,128,6,0,0,2, +1,0,1,128,1,0,85,128,4,0,0,4,0,0,1,128, +0,0,0,128,1,0,0,129,1,0,0,128,8,0,0,3, +1,0,1,128,0,0,249,128,12,0,228,160,8,0,0,3, +0,0,2,128,1,0,228,144,0,0,249,128,11,0,0,3, +0,0,2,128,0,0,85,128,16,0,85,160,5,0,0,3, +0,0,14,128,0,0,85,128,3,0,144,144,5,0,0,3, +0,0,14,128,0,0,228,128,0,0,144,160,11,0,0,3, +1,0,1,128,1,0,0,128,16,0,85,160,2,0,0,3, +1,0,1,128,1,0,0,128,8,0,0,161,5,0,0,3, +1,0,1,128,1,0,0,128,8,0,85,160,11,0,0,3, +1,0,1,128,1,0,0,128,16,0,85,160,10,0,0,3, +1,0,1,128,1,0,0,128,16,0,0,160,5,0,0,3, +0,0,1,128,0,0,0,128,1,0,0,128,5,0,0,3, +0,0,7,128,0,0,0,128,0,0,249,128,10,0,0,3, +0,0,7,128,0,0,228,128,16,0,0,160,2,0,0,3, +0,0,7,128,0,0,228,128,5,0,228,144,5,0,0,3, +0,0,8,128,5,0,255,160,5,0,255,160,12,0,0,3, +0,0,8,128,0,0,255,129,0,0,255,128,4,0,0,4, +1,0,7,128,0,0,228,144,5,0,255,161,5,0,228,160, +8,0,0,3,1,0,8,128,1,0,228,128,1,0,228,128, +12,0,0,3,2,0,2,128,9,0,255,160,1,0,255,128, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,85,128, +4,0,0,4,2,0,2,128,9,0,170,160,1,0,255,128, +2,0,0,128,7,0,0,2,1,0,8,128,1,0,255,128, +5,0,0,3,1,0,7,128,1,0,255,128,1,0,228,128, +6,0,0,2,1,0,8,128,2,0,85,128,4,0,0,4, +0,0,8,128,0,0,255,128,1,0,255,129,1,0,255,128, +8,0,0,3,1,0,8,128,1,0,228,128,13,0,228,160, +8,0,0,3,1,0,1,128,1,0,228,144,1,0,228,128, +11,0,0,3,1,0,9,128,1,0,228,128,16,0,85,160, +5,0,0,3,1,0,7,128,1,0,0,128,3,0,228,144, +5,0,0,3,1,0,7,128,1,0,228,128,1,0,228,160, +2,0,0,3,1,0,8,128,1,0,255,128,9,0,0,161, +5,0,0,3,1,0,8,128,1,0,255,128,9,0,85,160, +11,0,0,3,1,0,8,128,1,0,255,128,16,0,85,160, +10,0,0,3,1,0,8,128,1,0,255,128,16,0,0,160, +5,0,0,3,0,0,8,128,0,0,255,128,1,0,255,128, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,1,0,7,128,1,0,228,128,16,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,1,0,228,128, +5,0,0,3,0,0,8,128,6,0,255,160,6,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,6,0,255,161, +6,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,10,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,2,128,10,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,85,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +14,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +16,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +2,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +10,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +10,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +16,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +16,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +16,0,0,160,2,0,0,3,0,0,7,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,8,128,7,0,255,160, +7,0,255,160,12,0,0,3,0,0,8,128,0,0,255,129, +0,0,255,128,4,0,0,4,1,0,7,128,0,0,228,144, +7,0,255,161,7,0,228,160,8,0,0,3,1,0,8,128, +1,0,228,128,1,0,228,128,12,0,0,3,2,0,2,128, +11,0,255,160,1,0,255,128,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,85,128,4,0,0,4,2,0,1,128, +11,0,170,160,1,0,255,128,2,0,0,128,7,0,0,2, +1,0,8,128,1,0,255,128,5,0,0,3,1,0,7,128, +1,0,255,128,1,0,228,128,6,0,0,2,1,0,8,128, +2,0,0,128,4,0,0,4,0,0,8,128,0,0,255,128, +1,0,255,129,1,0,255,128,8,0,0,3,1,0,8,128, +1,0,228,128,15,0,228,160,8,0,0,3,1,0,1,128, +1,0,228,144,1,0,228,128,11,0,0,3,1,0,9,128, +1,0,228,128,16,0,85,160,5,0,0,3,1,0,7,128, +1,0,0,128,3,0,228,144,5,0,0,3,1,0,7,128, +1,0,228,128,3,0,228,160,2,0,0,3,1,0,8,128, +1,0,255,128,11,0,0,161,5,0,0,3,1,0,8,128, +1,0,255,128,11,0,85,160,11,0,0,3,1,0,8,128, +1,0,255,128,16,0,85,160,10,0,0,3,1,0,8,128, +1,0,255,128,16,0,0,160,5,0,0,3,0,0,8,128, +0,0,255,128,1,0,255,128,5,0,0,3,1,0,7,128, +0,0,255,128,1,0,228,128,10,0,0,3,1,0,7,128, +1,0,228,128,16,0,0,160,2,0,0,3,0,0,7,224, +0,0,228,128,1,0,228,128,1,0,0,2,1,0,7,224, +4,0,228,144,255,255,0,0,83,72,68,82,24,4,0,0, +64,0,240,255,6,1,0,0,89,8,0,4,70,142,32,0, +0,0,0,0,39,0,0,0,95,0,0,3,114,16,16,0, +0,0,0,0,95,0,0,3,114,16,16,0,1,0,0,0, +95,0,0,3,114,16,16,0,3,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,104,0,0,2, +3,0,0,0,54,0,0,5,114,0,16,0,0,0,0,0, +70,18,16,0,5,0,0,0,54,0,0,5,130,0,16,0, +0,0,0,0,1,64,0,0,0,0,0,0,48,0,0,1, +33,0,0,7,18,0,16,0,1,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,4,0,0,0,3,0,4,3, +10,0,16,0,1,0,0,0,50,0,0,16,114,0,16,0, +1,0,0,0,70,18,16,128,65,0,0,0,0,0,0,0, +246,143,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,70,130,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,50,0,0,12,18,0,16,0,2,0,0,0, +42,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,14,0,0,10,18,0,16,0,2,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,128,63,10,0,16,0,2,0,0,0,57,0,0,10, +34,0,16,0,2,0,0,0,1,64,0,0,0,0,0,0, +58,128,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,49,0,0,10,66,0,16,0,2,0,0,0, +58,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,0,0,7, +34,0,16,0,2,0,0,0,42,0,16,0,2,0,0,0, +26,0,16,0,2,0,0,0,55,0,0,9,18,0,16,0, +2,0,0,0,26,0,16,0,2,0,0,0,1,64,0,0, +0,0,0,0,10,0,16,0,2,0,0,0,68,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +56,0,0,7,114,0,16,0,1,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,16,0,0,10, +130,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +70,130,32,6,0,0,0,0,34,0,0,0,58,0,16,0, +0,0,0,0,52,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,0,0, +0,0,0,11,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,10,128,32,134,65,0,0,0,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,56,32,0,10, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +26,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,56,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,10,0,16,0,2,0,0,0, +16,0,0,7,18,0,16,0,1,0,0,0,70,18,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,52,0,0,7, +18,0,16,0,1,0,0,0,10,0,16,0,1,0,0,0, +1,64,0,0,0,0,0,0,56,0,0,7,114,0,16,0, +1,0,0,0,6,0,16,0,1,0,0,0,70,18,16,0, +3,0,0,0,56,0,0,10,114,0,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,70,130,32,6,0,0,0,0, +10,0,0,0,58,0,16,0,0,0,0,0,56,0,0,7, +114,0,16,0,1,0,0,0,246,15,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,51,0,0,10,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,2,64,0,0, +0,0,128,63,0,0,128,63,0,0,128,63,0,0,0,0, +0,0,0,7,114,0,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,70,2,16,0,1,0,0,0,30,0,0,7, +130,0,16,0,0,0,0,0,58,0,16,0,0,0,0,0, +1,64,0,0,1,0,0,0,22,0,0,1,54,0,0,5, +114,32,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +54,0,0,5,114,32,16,0,1,0,0,0,70,18,16,0, +4,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +32,0,0,0,3,0,0,0,0,0,0,0,7,0,0,0, +20,0,0,0,2,0,0,0,1,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,2,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,2,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,2,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,2,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,164,1,0,0, +7,0,0,0,8,0,0,0,88,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,106,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,118,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,128,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,136,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,149,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,159,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,112,117,116,101,83, +112,111,116,76,105,103,104,116,52,0,101,121,101,80,111,115, +105,116,105,111,110,0,101,121,101,78,111,114,109,97,108,0, +118,105,101,119,68,105,114,0,100,105,102,102,117,115,101,67, +111,108,111,114,0,115,112,101,99,67,111,108,111,114,0,97, +109,98,0,171,76,73,66,70,80,16,0,0,68,88,66,67, +50,83,242,196,114,66,252,96,155,185,91,130,235,4,7,30, +1,0,0,0,80,16,0,0,5,0,0,0,52,0,0,0, +156,3,0,0,96,9,0,0,220,9,0,0,160,14,0,0, +65,111,110,57,96,3,0,0,96,3,0,0,0,2,86,76, +48,3,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,0,0, +45,0,0,0,0,0,0,0,0,2,86,76,81,0,0,5, +45,0,15,160,0,0,0,0,0,0,0,0,0,0,128,63, +0,0,0,0,48,0,0,5,0,0,15,240,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,31,0,0,2,5,0,1,128, +1,0,15,144,31,0,0,2,5,0,2,128,2,0,15,144, +31,0,0,2,5,0,3,128,3,0,15,144,31,0,0,2, +5,0,4,128,4,0,15,144,31,0,0,2,5,0,5,128, +5,0,15,144,1,0,0,2,0,0,7,128,4,0,228,144, +1,0,0,2,1,0,7,128,5,0,228,144,27,0,0,2, +0,8,228,240,0,0,228,240,4,0,0,6,2,0,7,128, +0,0,228,144,18,32,255,161,0,8,228,240,18,32,228,160, +0,8,228,240,8,0,0,3,0,0,8,128,2,0,228,128, +2,0,228,128,7,0,0,2,1,0,8,128,0,0,255,128, +4,0,0,4,3,0,7,128,2,0,228,128,1,0,255,128, +2,0,228,144,36,0,0,2,4,0,7,128,3,0,228,128, +8,0,0,3,2,0,8,128,1,0,228,144,4,0,228,128, +5,0,0,5,3,0,1,128,18,32,255,160,0,8,228,240, +18,32,255,160,0,8,228,240,12,0,0,3,3,0,1,128, +3,0,0,129,3,0,0,128,12,0,0,4,3,0,2,128, +26,32,255,160,0,8,228,240,0,0,255,128,5,0,0,3, +3,0,1,128,3,0,85,128,3,0,0,128,5,0,0,4, +0,0,8,128,0,0,255,128,26,32,170,160,0,8,228,240, +2,0,0,3,0,0,8,128,0,0,255,128,45,0,170,160, +6,0,0,2,0,0,8,128,0,0,255,128,4,0,0,4, +0,0,8,128,3,0,0,128,0,0,255,129,0,0,255,128, +11,0,0,3,2,0,8,128,2,0,255,128,45,0,85,160, +32,0,0,3,3,0,1,128,2,0,255,128,44,0,255,160, +10,0,0,3,2,0,8,128,3,0,0,128,45,0,170,160, +5,0,0,3,2,0,7,128,1,0,255,128,2,0,228,128, +8,0,0,3,1,0,8,128,1,0,228,144,2,0,228,128, +8,0,0,4,2,0,1,128,2,0,228,128,34,32,228,160, +0,8,228,240,11,0,0,3,2,0,1,128,2,0,0,128, +45,0,85,160,2,0,0,4,2,0,1,128,2,0,0,128, +26,32,0,161,0,8,228,240,5,0,0,4,2,0,1,128, +2,0,0,128,26,32,85,160,0,8,228,240,11,0,0,3, +2,0,1,128,2,0,0,128,45,0,85,160,10,0,0,3, +2,0,1,128,2,0,0,128,45,0,170,160,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,0,128,11,0,0,3, +1,0,8,128,1,0,255,128,45,0,85,160,12,0,0,3, +2,0,1,128,45,0,85,160,1,0,255,128,5,0,0,3, +2,0,2,128,2,0,255,128,0,0,255,128,5,0,0,4, +2,0,14,128,2,0,85,128,10,32,144,160,0,8,228,240, +4,0,0,4,0,0,7,128,2,0,0,128,2,0,249,128, +0,0,228,128,5,0,0,3,2,0,7,128,1,0,255,128, +3,0,228,144,5,0,0,4,2,0,7,128,2,0,228,128, +10,32,228,160,0,8,228,240,5,0,0,3,2,0,7,128, +0,0,255,128,2,0,228,128,10,0,0,3,2,0,7,128, +2,0,228,128,45,0,170,160,2,0,0,3,1,0,7,128, +1,0,228,128,2,0,228,128,29,0,0,0,1,0,0,2, +1,0,7,224,0,0,228,128,1,0,0,2,0,0,7,224, +1,0,228,128,255,255,0,0,83,72,68,82,188,5,0,0, +64,0,240,255,111,1,0,0,89,8,0,4,70,142,32,0, +0,0,0,0,45,0,0,0,95,0,0,3,114,16,16,0, +0,0,0,0,95,0,0,3,114,16,16,0,1,0,0,0, +95,0,0,3,114,16,16,0,2,0,0,0,95,0,0,3, +114,16,16,0,3,0,0,0,95,0,0,3,114,16,16,0, +4,0,0,0,95,0,0,3,114,16,16,0,5,0,0,0, +101,0,0,3,114,32,16,0,0,0,0,0,101,0,0,3, +114,32,16,0,1,0,0,0,104,0,0,2,4,0,0,0, +54,0,0,5,114,0,16,0,0,0,0,0,70,18,16,0, +4,0,0,0,54,0,0,5,114,0,16,0,1,0,0,0, +70,18,16,0,5,0,0,0,54,0,0,5,130,0,16,0, +0,0,0,0,1,64,0,0,0,0,0,0,48,0,0,1, +33,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,4,0,0,0,3,0,4,3, +58,0,16,0,1,0,0,0,50,0,0,16,114,0,16,0, +2,0,0,0,70,18,16,128,65,0,0,0,0,0,0,0, +246,143,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,70,130,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,50,0,0,12,130,0,16,0,2,0,0,0, +42,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,14,0,0,10,130,0,16,0,2,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,128,63,58,0,16,0,2,0,0,0,57,0,0,10, +18,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +58,128,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,49,0,0,10,34,0,16,0,3,0,0,0, +58,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,58,0,16,0,1,0,0,0,1,0,0,7, +18,0,16,0,3,0,0,0,26,0,16,0,3,0,0,0, +10,0,16,0,3,0,0,0,55,0,0,9,130,0,16,0, +2,0,0,0,10,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,58,0,16,0,2,0,0,0,68,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +56,0,0,7,114,0,16,0,3,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,16,0,0,10, +130,0,16,0,3,0,0,0,70,2,16,0,3,0,0,0, +70,130,32,6,0,0,0,0,34,0,0,0,58,0,16,0, +0,0,0,0,52,0,0,7,130,0,16,0,3,0,0,0, +58,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +0,0,0,11,130,0,16,0,3,0,0,0,58,0,16,0, +3,0,0,0,10,128,32,134,65,0,0,0,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,56,32,0,10, +130,0,16,0,3,0,0,0,58,0,16,0,3,0,0,0, +26,128,32,6,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,56,0,0,7,130,0,16,0,2,0,0,0, +58,0,16,0,2,0,0,0,58,0,16,0,3,0,0,0, +16,0,0,7,18,0,16,0,3,0,0,0,70,18,16,0, +1,0,0,0,70,2,16,0,3,0,0,0,52,0,0,7, +18,0,16,0,3,0,0,0,10,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,56,0,0,7,226,0,16,0, +3,0,0,0,6,0,16,0,3,0,0,0,6,25,16,0, +3,0,0,0,56,0,0,10,226,0,16,0,3,0,0,0, +86,14,16,0,3,0,0,0,6,137,32,6,0,0,0,0, +10,0,0,0,58,0,16,0,0,0,0,0,49,0,0,7, +18,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +10,0,16,0,3,0,0,0,31,0,4,3,10,0,16,0, +3,0,0,0,50,0,0,9,114,0,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,246,15,16,0,1,0,0,0, +70,18,16,0,2,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,68,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,56,0,0,7,114,0,16,0, +2,0,0,0,246,15,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,16,0,0,7,130,0,16,0,1,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +52,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,1,64,0,0,0,0,0,0,47,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +56,0,0,8,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,58,128,32,0,0,0,0,0,44,0,0,0, +25,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,51,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,128,63, +56,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,58,0,16,0,2,0,0,0,50,0,0,12, +114,0,16,0,0,0,0,0,246,15,16,0,1,0,0,0, +70,130,32,6,0,0,0,0,10,0,0,0,58,0,16,0, +0,0,0,0,70,2,16,0,0,0,0,0,21,0,0,1, +56,0,0,7,114,0,16,0,2,0,0,0,246,15,16,0, +2,0,0,0,150,7,16,0,3,0,0,0,51,0,0,10, +114,0,16,0,2,0,0,0,70,2,16,0,2,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,0,0,0,0,0,7,114,0,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +30,0,0,7,130,0,16,0,0,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,1,0,0,0,22,0,0,1, +54,0,0,5,114,32,16,0,1,0,0,0,70,2,16,0, +0,0,0,0,54,0,0,5,114,32,16,0,0,0,0,0, +70,2,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,48,0,0,0,4,0,0,0,0,0,0,0, +8,0,0,0,33,0,0,0,2,0,0,0,1,0,0,0, +1,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +5,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,188,4,0,0, +1,0,0,0,108,0,0,0,1,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,142,4,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,92,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,85,110,105,116, +121,70,70,86,101,114,116,101,120,0,171,171,92,0,0,0, +14,0,0,0,132,0,0,0,240,3,0,0,0,0,0,0, +0,0,0,0,180,2,0,0,0,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,240,2,0,0, +64,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,253,2,0,0,128,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,56,3,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,71,3,0,0,160,0,0,0,128,0,0,0, +2,0,0,0,88,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,124,3,0,0, +32,1,0,0,128,0,0,0,2,0,0,0,140,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,176,3,0,0,160,1,0,0,128,0,0,0, +2,0,0,0,192,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,228,3,0,0, +32,2,0,0,128,0,0,0,2,0,0,0,244,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,24,4,0,0,160,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,39,4,0,0, +176,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,54,4,0,0,192,2,0,0,16,0,0,0, +2,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,66,4,0,0, +208,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,82,4,0,0,224,2,0,0,0,1,0,0, +0,0,0,0,96,4,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,132,4,0,0, +224,3,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +112,0,102,108,111,97,116,52,120,52,0,171,3,0,3,0, +4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,0,102,102,95, +118,101,99,95,99,111,108,111,114,0,102,108,111,97,116,52, +0,171,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,118,101,99,95,97, +109,98,105,101,110,116,0,102,102,95,108,105,103,104,116,95, +99,111,108,111,114,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,112,111,115,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,97,116,116,101,110,0,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,115,112,111, +116,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,109,97,116,95,100, +105,102,102,117,115,101,0,102,102,95,109,97,116,95,97,109, +98,105,101,110,116,0,102,102,95,109,97,116,95,115,112,101, +99,0,102,102,95,109,97,116,95,101,109,105,115,115,105,111, +110,0,102,102,95,109,97,116,114,105,120,95,116,101,120,0, +3,0,3,0,4,0,4,0,4,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,102,111,103,95,118,115,0,77,105, +99,114,111,115,111,102,116,32,40,82,41,32,72,76,83,76, +32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114, +32,54,46,51,46,57,52,49,53,46,48,0,76,70,83,48, +168,1,0,0,7,0,0,0,8,0,0,0,88,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,110,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,122,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,132,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,140,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,153,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,163,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,83,112,101,99, +52,0,101,121,101,80,111,115,105,116,105,111,110,0,101,121, +101,78,111,114,109,97,108,0,118,105,101,119,68,105,114,0, +100,105,102,102,117,115,101,67,111,108,111,114,0,115,112,101, +99,67,111,108,111,114,0,97,109,98,0,171,76,73,66,70, +180,19,0,0,68,88,66,67,240,160,5,118,168,200,121,161, +74,215,24,12,8,202,65,250,1,0,0,0,180,19,0,0, +5,0,0,0,52,0,0,0,168,8,0,0,200,12,0,0, +68,13,0,0,8,18,0,0,65,111,110,57,108,8,0,0, +108,8,0,0,0,2,86,76,24,8,0,0,84,0,0,0, +4,0,36,0,0,0,84,0,0,0,84,0,0,0,36,0, +0,0,84,0,0,0,10,0,5,0,0,0,0,0,0,0, +0,0,18,0,5,0,5,0,0,0,0,0,0,0,26,0, +5,0,10,0,0,0,0,0,0,0,34,0,5,0,15,0, +0,0,0,0,0,2,86,76,81,0,0,5,20,0,15,160, +0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,3,128, +3,0,15,144,31,0,0,2,5,0,4,128,4,0,15,144, +31,0,0,2,5,0,5,128,5,0,15,144,5,0,0,3, +0,0,1,128,5,0,255,160,5,0,255,160,12,0,0,3, +0,0,1,128,0,0,0,129,0,0,0,128,4,0,0,4, +0,0,14,128,0,0,144,144,5,0,255,161,5,0,144,160, +8,0,0,3,1,0,1,128,0,0,249,128,0,0,249,128, +12,0,0,3,1,0,2,128,10,0,255,160,1,0,0,128, +5,0,0,3,0,0,1,128,0,0,0,128,1,0,85,128, +1,0,0,2,2,0,1,128,20,0,0,160,4,0,0,4, +1,0,2,128,10,0,170,160,1,0,0,128,2,0,0,128, +7,0,0,2,1,0,1,128,1,0,0,128,5,0,0,3, +0,0,14,128,0,0,228,128,1,0,0,128,6,0,0,2, +1,0,1,128,1,0,85,128,4,0,0,4,0,0,1,128, +0,0,0,128,1,0,0,129,1,0,0,128,8,0,0,3, +1,0,1,128,0,0,249,128,15,0,228,160,8,0,0,3, +0,0,2,128,1,0,228,144,0,0,249,128,11,0,0,3, +0,0,2,128,0,0,85,128,20,0,85,160,5,0,0,3, +0,0,14,128,0,0,85,128,3,0,144,144,5,0,0,3, +0,0,14,128,0,0,228,128,0,0,144,160,11,0,0,3, +1,0,1,128,1,0,0,128,20,0,85,160,2,0,0,3, +1,0,1,128,1,0,0,128,10,0,0,161,5,0,0,3, +1,0,1,128,1,0,0,128,10,0,85,160,11,0,0,3, +1,0,1,128,1,0,0,128,20,0,85,160,10,0,0,3, +1,0,1,128,1,0,0,128,20,0,0,160,5,0,0,3, +0,0,1,128,0,0,0,128,1,0,0,128,5,0,0,3, +0,0,7,128,0,0,0,128,0,0,249,128,10,0,0,3, +0,0,7,128,0,0,228,128,20,0,0,160,2,0,0,3, +0,0,7,128,0,0,228,128,5,0,228,144,5,0,0,3, +0,0,8,128,6,0,255,160,6,0,255,160,12,0,0,3, +0,0,8,128,0,0,255,129,0,0,255,128,4,0,0,4, +1,0,7,128,0,0,228,144,6,0,255,161,6,0,228,160, +8,0,0,3,1,0,8,128,1,0,228,128,1,0,228,128, +12,0,0,3,2,0,2,128,11,0,255,160,1,0,255,128, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,85,128, +4,0,0,4,2,0,2,128,11,0,170,160,1,0,255,128, +2,0,0,128,7,0,0,2,1,0,8,128,1,0,255,128, +5,0,0,3,1,0,7,128,1,0,255,128,1,0,228,128, +6,0,0,2,1,0,8,128,2,0,85,128,4,0,0,4, +0,0,8,128,0,0,255,128,1,0,255,129,1,0,255,128, +8,0,0,3,1,0,8,128,1,0,228,128,16,0,228,160, +8,0,0,3,1,0,1,128,1,0,228,144,1,0,228,128, +11,0,0,3,1,0,9,128,1,0,228,128,20,0,85,160, +5,0,0,3,1,0,7,128,1,0,0,128,3,0,228,144, +5,0,0,3,1,0,7,128,1,0,228,128,1,0,228,160, +2,0,0,3,1,0,8,128,1,0,255,128,11,0,0,161, +5,0,0,3,1,0,8,128,1,0,255,128,11,0,85,160, +11,0,0,3,1,0,8,128,1,0,255,128,20,0,85,160, +10,0,0,3,1,0,8,128,1,0,255,128,20,0,0,160, +5,0,0,3,0,0,8,128,0,0,255,128,1,0,255,128, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,1,0,7,128,1,0,228,128,20,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,1,0,228,128, +5,0,0,3,0,0,8,128,7,0,255,160,7,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,7,0,255,161, +7,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,12,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,2,128,12,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,85,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +17,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +20,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +2,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +12,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +12,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +20,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +20,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +20,0,0,160,2,0,0,3,0,0,7,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,8,128,8,0,255,160, +8,0,255,160,12,0,0,3,0,0,8,128,0,0,255,129, +0,0,255,128,4,0,0,4,1,0,7,128,0,0,228,144, +8,0,255,161,8,0,228,160,8,0,0,3,1,0,8,128, +1,0,228,128,1,0,228,128,12,0,0,3,2,0,2,128, +13,0,255,160,1,0,255,128,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,85,128,4,0,0,4,2,0,2,128, +13,0,170,160,1,0,255,128,2,0,0,128,7,0,0,2, +1,0,8,128,1,0,255,128,5,0,0,3,1,0,7,128, +1,0,255,128,1,0,228,128,6,0,0,2,1,0,8,128, +2,0,85,128,4,0,0,4,0,0,8,128,0,0,255,128, +1,0,255,129,1,0,255,128,8,0,0,3,1,0,8,128, +1,0,228,128,18,0,228,160,8,0,0,3,1,0,1,128, +1,0,228,144,1,0,228,128,11,0,0,3,1,0,9,128, +1,0,228,128,20,0,85,160,5,0,0,3,1,0,7,128, +1,0,0,128,3,0,228,144,5,0,0,3,1,0,7,128, +1,0,228,128,3,0,228,160,2,0,0,3,1,0,8,128, +1,0,255,128,13,0,0,161,5,0,0,3,1,0,8,128, +1,0,255,128,13,0,85,160,11,0,0,3,1,0,8,128, +1,0,255,128,20,0,85,160,10,0,0,3,1,0,8,128, +1,0,255,128,20,0,0,160,5,0,0,3,0,0,8,128, +0,0,255,128,1,0,255,128,5,0,0,3,1,0,7,128, +0,0,255,128,1,0,228,128,10,0,0,3,1,0,7,128, +1,0,228,128,20,0,0,160,2,0,0,3,0,0,7,128, +0,0,228,128,1,0,228,128,5,0,0,3,0,0,8,128, +9,0,255,160,9,0,255,160,12,0,0,3,0,0,8,128, +0,0,255,129,0,0,255,128,4,0,0,4,1,0,7,128, +0,0,228,144,9,0,255,161,9,0,228,160,8,0,0,3, +1,0,8,128,1,0,228,128,1,0,228,128,12,0,0,3, +2,0,2,128,14,0,255,160,1,0,255,128,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,85,128,4,0,0,4, +2,0,1,128,14,0,170,160,1,0,255,128,2,0,0,128, +7,0,0,2,1,0,8,128,1,0,255,128,5,0,0,3, +1,0,7,128,1,0,255,128,1,0,228,128,6,0,0,2, +1,0,8,128,2,0,0,128,4,0,0,4,0,0,8,128, +0,0,255,128,1,0,255,129,1,0,255,128,8,0,0,3, +1,0,8,128,1,0,228,128,19,0,228,160,8,0,0,3, +1,0,1,128,1,0,228,144,1,0,228,128,11,0,0,3, +1,0,9,128,1,0,228,128,20,0,85,160,5,0,0,3, +1,0,7,128,1,0,0,128,3,0,228,144,5,0,0,3, +1,0,7,128,1,0,228,128,4,0,228,160,2,0,0,3, +1,0,8,128,1,0,255,128,14,0,0,161,5,0,0,3, +1,0,8,128,1,0,255,128,14,0,85,160,11,0,0,3, +1,0,8,128,1,0,255,128,20,0,85,160,10,0,0,3, +1,0,8,128,1,0,255,128,20,0,0,160,5,0,0,3, +0,0,8,128,0,0,255,128,1,0,255,128,5,0,0,3, +1,0,7,128,0,0,255,128,1,0,228,128,10,0,0,3, +1,0,7,128,1,0,228,128,20,0,0,160,2,0,0,3, +0,0,7,224,0,0,228,128,1,0,228,128,1,0,0,2, +1,0,7,224,4,0,228,144,255,255,0,0,83,72,68,82, +24,4,0,0,64,0,240,255,6,1,0,0,89,8,0,4, +70,142,32,0,0,0,0,0,40,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,95,0,0,3,114,16,16,0,3,0,0,0, +95,0,0,3,114,16,16,0,4,0,0,0,95,0,0,3, +114,16,16,0,5,0,0,0,101,0,0,3,114,32,16,0, +0,0,0,0,101,0,0,3,114,32,16,0,1,0,0,0, +104,0,0,2,3,0,0,0,54,0,0,5,114,0,16,0, +0,0,0,0,70,18,16,0,5,0,0,0,54,0,0,5, +130,0,16,0,0,0,0,0,1,64,0,0,0,0,0,0, +48,0,0,1,33,0,0,7,18,0,16,0,1,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,5,0,0,0, +3,0,4,3,10,0,16,0,1,0,0,0,50,0,0,16, +114,0,16,0,1,0,0,0,70,18,16,128,65,0,0,0, +0,0,0,0,246,143,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,70,130,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,50,0,0,12,18,0,16,0, +2,0,0,0,42,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,14,0,0,10,18,0,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,128,63,10,0,16,0,2,0,0,0, +57,0,0,10,34,0,16,0,2,0,0,0,1,64,0,0, +0,0,0,0,58,128,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,49,0,0,10,66,0,16,0, +2,0,0,0,58,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,0,0,7,34,0,16,0,2,0,0,0,42,0,16,0, +2,0,0,0,26,0,16,0,2,0,0,0,55,0,0,9, +18,0,16,0,2,0,0,0,26,0,16,0,2,0,0,0, +1,64,0,0,0,0,0,0,10,0,16,0,2,0,0,0, +68,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,7,114,0,16,0,1,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +16,0,0,10,130,0,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,70,130,32,6,0,0,0,0,34,0,0,0, +58,0,16,0,0,0,0,0,52,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,0,0,0,0,0,11,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,10,128,32,134,65,0,0,0, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,32,0,10,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,26,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,10,0,16,0, +2,0,0,0,16,0,0,7,18,0,16,0,1,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +52,0,0,7,18,0,16,0,1,0,0,0,10,0,16,0, +1,0,0,0,1,64,0,0,0,0,0,0,56,0,0,7, +114,0,16,0,1,0,0,0,6,0,16,0,1,0,0,0, +70,18,16,0,3,0,0,0,56,0,0,10,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,130,32,6, +0,0,0,0,10,0,0,0,58,0,16,0,0,0,0,0, +56,0,0,7,114,0,16,0,1,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,51,0,0,10, +114,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,0,0,0,0,0,7,114,0,16,0,0,0,0,0, +70,2,16,0,0,0,0,0,70,2,16,0,1,0,0,0, +30,0,0,7,130,0,16,0,0,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,1,0,0,0,22,0,0,1, +54,0,0,5,114,32,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,54,0,0,5,114,32,16,0,1,0,0,0, +70,18,16,0,4,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,32,0,0,0,3,0,0,0,0,0,0,0, +7,0,0,0,20,0,0,0,2,0,0,0,1,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +4,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,188,4,0,0, +1,0,0,0,108,0,0,0,1,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,142,4,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,92,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,85,110,105,116, +121,70,70,86,101,114,116,101,120,0,171,171,92,0,0,0, +14,0,0,0,132,0,0,0,240,3,0,0,0,0,0,0, +0,0,0,0,180,2,0,0,0,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,240,2,0,0, +64,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,253,2,0,0,128,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,56,3,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,71,3,0,0,160,0,0,0,128,0,0,0, +2,0,0,0,88,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,124,3,0,0, +32,1,0,0,128,0,0,0,2,0,0,0,140,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,176,3,0,0,160,1,0,0,128,0,0,0, +2,0,0,0,192,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,228,3,0,0, +32,2,0,0,128,0,0,0,2,0,0,0,244,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,24,4,0,0,160,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,39,4,0,0, +176,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,54,4,0,0,192,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,66,4,0,0, +208,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,82,4,0,0,224,2,0,0,0,1,0,0, +0,0,0,0,96,4,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,132,4,0,0, +224,3,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +112,0,102,108,111,97,116,52,120,52,0,171,3,0,3,0, +4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,0,102,102,95, +118,101,99,95,99,111,108,111,114,0,102,108,111,97,116,52, +0,171,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,118,101,99,95,97, +109,98,105,101,110,116,0,102,102,95,108,105,103,104,116,95, +99,111,108,111,114,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,112,111,115,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,97,116,116,101,110,0,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,115,112,111, +116,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,109,97,116,95,100, +105,102,102,117,115,101,0,102,102,95,109,97,116,95,97,109, +98,105,101,110,116,0,102,102,95,109,97,116,95,115,112,101, +99,0,102,102,95,109,97,116,95,101,109,105,115,115,105,111, +110,0,102,102,95,109,97,116,114,105,120,95,116,101,120,0, +3,0,3,0,4,0,4,0,4,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,102,111,103,95,118,115,0,77,105, +99,114,111,115,111,102,116,32,40,82,41,32,72,76,83,76, +32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114, +32,54,46,51,46,57,52,49,53,46,48,0,76,70,83,48, +164,1,0,0,7,0,0,0,8,0,0,0,88,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,106,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,118,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,128,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,136,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,149,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,159,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,53,0,101,121, +101,80,111,115,105,116,105,111,110,0,101,121,101,78,111,114, +109,97,108,0,118,105,101,119,68,105,114,0,100,105,102,102, +117,115,101,67,111,108,111,114,0,115,112,101,99,67,111,108, +111,114,0,97,109,98,0,171,76,73,66,70,80,16,0,0, +68,88,66,67,89,78,131,151,228,245,82,121,136,215,111,193, +160,210,121,165,1,0,0,0,80,16,0,0,5,0,0,0, +52,0,0,0,156,3,0,0,96,9,0,0,220,9,0,0, +160,14,0,0,65,111,110,57,96,3,0,0,96,3,0,0, +0,2,86,76,48,3,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +0,0,0,0,45,0,0,0,0,0,0,0,0,2,86,76, +81,0,0,5,45,0,15,160,0,0,0,0,0,0,0,0, +0,0,128,63,0,0,0,0,48,0,0,5,0,0,15,240, +5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,2,128, +2,0,15,144,31,0,0,2,5,0,3,128,3,0,15,144, +31,0,0,2,5,0,4,128,4,0,15,144,31,0,0,2, +5,0,5,128,5,0,15,144,1,0,0,2,0,0,7,128, +4,0,228,144,1,0,0,2,1,0,7,128,5,0,228,144, +27,0,0,2,0,8,228,240,0,0,228,240,4,0,0,6, +2,0,7,128,0,0,228,144,18,32,255,161,0,8,228,240, +18,32,228,160,0,8,228,240,8,0,0,3,0,0,8,128, +2,0,228,128,2,0,228,128,7,0,0,2,1,0,8,128, +0,0,255,128,4,0,0,4,3,0,7,128,2,0,228,128, +1,0,255,128,2,0,228,144,36,0,0,2,4,0,7,128, +3,0,228,128,8,0,0,3,2,0,8,128,1,0,228,144, +4,0,228,128,5,0,0,5,3,0,1,128,18,32,255,160, +0,8,228,240,18,32,255,160,0,8,228,240,12,0,0,3, +3,0,1,128,3,0,0,129,3,0,0,128,12,0,0,4, +3,0,2,128,26,32,255,160,0,8,228,240,0,0,255,128, +5,0,0,3,3,0,1,128,3,0,85,128,3,0,0,128, +5,0,0,4,0,0,8,128,0,0,255,128,26,32,170,160, +0,8,228,240,2,0,0,3,0,0,8,128,0,0,255,128, +45,0,170,160,6,0,0,2,0,0,8,128,0,0,255,128, +4,0,0,4,0,0,8,128,3,0,0,128,0,0,255,129, +0,0,255,128,11,0,0,3,2,0,8,128,2,0,255,128, +45,0,85,160,32,0,0,3,3,0,1,128,2,0,255,128, +44,0,255,160,10,0,0,3,2,0,8,128,3,0,0,128, +45,0,170,160,5,0,0,3,2,0,7,128,1,0,255,128, +2,0,228,128,8,0,0,3,1,0,8,128,1,0,228,144, +2,0,228,128,8,0,0,4,2,0,1,128,2,0,228,128, +34,32,228,160,0,8,228,240,11,0,0,3,2,0,1,128, +2,0,0,128,45,0,85,160,2,0,0,4,2,0,1,128, +2,0,0,128,26,32,0,161,0,8,228,240,5,0,0,4, +2,0,1,128,2,0,0,128,26,32,85,160,0,8,228,240, +11,0,0,3,2,0,1,128,2,0,0,128,45,0,85,160, +10,0,0,3,2,0,1,128,2,0,0,128,45,0,170,160, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,0,128, +11,0,0,3,1,0,8,128,1,0,255,128,45,0,85,160, +12,0,0,3,2,0,1,128,45,0,85,160,1,0,255,128, +5,0,0,3,2,0,2,128,2,0,255,128,0,0,255,128, +5,0,0,4,2,0,14,128,2,0,85,128,10,32,144,160, +0,8,228,240,4,0,0,4,0,0,7,128,2,0,0,128, +2,0,249,128,0,0,228,128,5,0,0,3,2,0,7,128, +1,0,255,128,3,0,228,144,5,0,0,4,2,0,7,128, +2,0,228,128,10,32,228,160,0,8,228,240,5,0,0,3, +2,0,7,128,0,0,255,128,2,0,228,128,10,0,0,3, +2,0,7,128,2,0,228,128,45,0,170,160,2,0,0,3, +1,0,7,128,1,0,228,128,2,0,228,128,29,0,0,0, +1,0,0,2,1,0,7,224,0,0,228,128,1,0,0,2, +0,0,7,224,1,0,228,128,255,255,0,0,83,72,68,82, +188,5,0,0,64,0,240,255,111,1,0,0,89,8,0,4, +70,142,32,0,0,0,0,0,45,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,95,0,0,3,114,16,16,0,2,0,0,0, +95,0,0,3,114,16,16,0,3,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,104,0,0,2, +4,0,0,0,54,0,0,5,114,0,16,0,0,0,0,0, +70,18,16,0,4,0,0,0,54,0,0,5,114,0,16,0, +1,0,0,0,70,18,16,0,5,0,0,0,54,0,0,5, +130,0,16,0,0,0,0,0,1,64,0,0,0,0,0,0, +48,0,0,1,33,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,5,0,0,0, +3,0,4,3,58,0,16,0,1,0,0,0,50,0,0,16, +114,0,16,0,2,0,0,0,70,18,16,128,65,0,0,0, +0,0,0,0,246,143,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,70,130,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,50,0,0,12,130,0,16,0, +2,0,0,0,42,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,14,0,0,10,130,0,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,128,63,58,0,16,0,2,0,0,0, +57,0,0,10,18,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,58,128,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,49,0,0,10,34,0,16,0, +3,0,0,0,58,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,0,0,7,18,0,16,0,3,0,0,0,26,0,16,0, +3,0,0,0,10,0,16,0,3,0,0,0,55,0,0,9, +130,0,16,0,2,0,0,0,10,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,58,0,16,0,2,0,0,0, +68,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,7,114,0,16,0,3,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +16,0,0,10,130,0,16,0,3,0,0,0,70,2,16,0, +3,0,0,0,70,130,32,6,0,0,0,0,34,0,0,0, +58,0,16,0,0,0,0,0,52,0,0,7,130,0,16,0, +3,0,0,0,58,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,0,0,0,11,130,0,16,0,3,0,0,0, +58,0,16,0,3,0,0,0,10,128,32,134,65,0,0,0, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,32,0,10,130,0,16,0,3,0,0,0,58,0,16,0, +3,0,0,0,26,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,130,0,16,0, +2,0,0,0,58,0,16,0,2,0,0,0,58,0,16,0, +3,0,0,0,16,0,0,7,18,0,16,0,3,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,3,0,0,0, +52,0,0,7,18,0,16,0,3,0,0,0,10,0,16,0, +3,0,0,0,1,64,0,0,0,0,0,0,56,0,0,7, +226,0,16,0,3,0,0,0,6,0,16,0,3,0,0,0, +6,25,16,0,3,0,0,0,56,0,0,10,226,0,16,0, +3,0,0,0,86,14,16,0,3,0,0,0,6,137,32,6, +0,0,0,0,10,0,0,0,58,0,16,0,0,0,0,0, +49,0,0,7,18,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,10,0,16,0,3,0,0,0,31,0,4,3, +10,0,16,0,3,0,0,0,50,0,0,9,114,0,16,0, +2,0,0,0,70,2,16,0,2,0,0,0,246,15,16,0, +1,0,0,0,70,18,16,0,2,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,68,0,0,5,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,56,0,0,7, +114,0,16,0,2,0,0,0,246,15,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,18,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,52,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,0,0, +47,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,8,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,58,128,32,0,0,0,0,0, +44,0,0,0,25,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,51,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,56,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,58,0,16,0,2,0,0,0, +50,0,0,12,114,0,16,0,0,0,0,0,246,15,16,0, +1,0,0,0,70,130,32,6,0,0,0,0,10,0,0,0, +58,0,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +21,0,0,1,56,0,0,7,114,0,16,0,2,0,0,0, +246,15,16,0,2,0,0,0,150,7,16,0,3,0,0,0, +51,0,0,10,114,0,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,0,0,0,0,0,7,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,30,0,0,7,130,0,16,0,0,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,1,0,0,0, +22,0,0,1,54,0,0,5,114,32,16,0,1,0,0,0, +70,2,16,0,0,0,0,0,54,0,0,5,114,32,16,0, +0,0,0,0,70,2,16,0,1,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,48,0,0,0,4,0,0,0, +0,0,0,0,8,0,0,0,33,0,0,0,2,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,5,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,2,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,2,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,2,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,2,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,2,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,0,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,168,1,0,0,7,0,0,0,8,0,0,0, +88,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +110,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +122,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +132,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +2,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +140,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +153,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +163,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +5,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +67,111,109,112,117,116,101,83,112,111,116,76,105,103,104,116, +83,112,101,99,53,0,101,121,101,80,111,115,105,116,105,111, +110,0,101,121,101,78,111,114,109,97,108,0,118,105,101,119, +68,105,114,0,100,105,102,102,117,115,101,67,111,108,111,114, +0,115,112,101,99,67,111,108,111,114,0,97,109,98,0,171, +76,73,66,70,56,21,0,0,68,88,66,67,116,246,90,100, +53,210,241,155,159,216,173,93,60,139,208,144,1,0,0,0, +56,21,0,0,5,0,0,0,52,0,0,0,44,10,0,0, +76,14,0,0,200,14,0,0,140,19,0,0,65,111,110,57, +240,9,0,0,240,9,0,0,0,2,86,76,156,9,0,0, +84,0,0,0,4,0,36,0,0,0,84,0,0,0,84,0, +0,0,36,0,0,0,84,0,0,0,10,0,6,0,0,0, +0,0,0,0,0,0,18,0,6,0,6,0,0,0,0,0, +0,0,26,0,6,0,12,0,0,0,0,0,0,0,34,0, +6,0,18,0,0,0,0,0,0,2,86,76,81,0,0,5, +24,0,15,160,0,0,128,63,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,31,0,0,2, +5,0,3,128,3,0,15,144,31,0,0,2,5,0,4,128, +4,0,15,144,31,0,0,2,5,0,5,128,5,0,15,144, +5,0,0,3,0,0,1,128,6,0,255,160,6,0,255,160, +12,0,0,3,0,0,1,128,0,0,0,129,0,0,0,128, +4,0,0,4,0,0,14,128,0,0,144,144,6,0,255,161, +6,0,144,160,8,0,0,3,1,0,1,128,0,0,249,128, +0,0,249,128,12,0,0,3,1,0,2,128,12,0,255,160, +1,0,0,128,5,0,0,3,0,0,1,128,0,0,0,128, +1,0,85,128,1,0,0,2,2,0,1,128,24,0,0,160, +4,0,0,4,1,0,2,128,12,0,170,160,1,0,0,128, +2,0,0,128,7,0,0,2,1,0,1,128,1,0,0,128, +5,0,0,3,0,0,14,128,0,0,228,128,1,0,0,128, +6,0,0,2,1,0,1,128,1,0,85,128,4,0,0,4, +0,0,1,128,0,0,0,128,1,0,0,129,1,0,0,128, +8,0,0,3,1,0,1,128,0,0,249,128,18,0,228,160, +8,0,0,3,0,0,2,128,1,0,228,144,0,0,249,128, +11,0,0,3,0,0,2,128,0,0,85,128,24,0,85,160, +5,0,0,3,0,0,14,128,0,0,85,128,3,0,144,144, +5,0,0,3,0,0,14,128,0,0,228,128,0,0,144,160, +11,0,0,3,1,0,1,128,1,0,0,128,24,0,85,160, +2,0,0,3,1,0,1,128,1,0,0,128,12,0,0,161, +5,0,0,3,1,0,1,128,1,0,0,128,12,0,85,160, +11,0,0,3,1,0,1,128,1,0,0,128,24,0,85,160, +10,0,0,3,1,0,1,128,1,0,0,128,24,0,0,160, +5,0,0,3,0,0,1,128,0,0,0,128,1,0,0,128, +5,0,0,3,0,0,7,128,0,0,0,128,0,0,249,128, +10,0,0,3,0,0,7,128,0,0,228,128,24,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,5,0,228,144, +5,0,0,3,0,0,8,128,7,0,255,160,7,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,7,0,255,161, +7,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,13,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,2,128,13,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,85,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +19,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +24,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +1,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +13,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +13,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +24,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +24,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +24,0,0,160,2,0,0,3,0,0,7,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,8,128,8,0,255,160, +8,0,255,160,12,0,0,3,0,0,8,128,0,0,255,129, +0,0,255,128,4,0,0,4,1,0,7,128,0,0,228,144, +8,0,255,161,8,0,228,160,8,0,0,3,1,0,8,128, +1,0,228,128,1,0,228,128,12,0,0,3,2,0,2,128, +14,0,255,160,1,0,255,128,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,85,128,4,0,0,4,2,0,2,128, +14,0,170,160,1,0,255,128,2,0,0,128,7,0,0,2, +1,0,8,128,1,0,255,128,5,0,0,3,1,0,7,128, +1,0,255,128,1,0,228,128,6,0,0,2,1,0,8,128, +2,0,85,128,4,0,0,4,0,0,8,128,0,0,255,128, +1,0,255,129,1,0,255,128,8,0,0,3,1,0,8,128, +1,0,228,128,20,0,228,160,8,0,0,3,1,0,1,128, +1,0,228,144,1,0,228,128,11,0,0,3,1,0,9,128, +1,0,228,128,24,0,85,160,5,0,0,3,1,0,7,128, +1,0,0,128,3,0,228,144,5,0,0,3,1,0,7,128, +1,0,228,128,2,0,228,160,2,0,0,3,1,0,8,128, +1,0,255,128,14,0,0,161,5,0,0,3,1,0,8,128, +1,0,255,128,14,0,85,160,11,0,0,3,1,0,8,128, +1,0,255,128,24,0,85,160,10,0,0,3,1,0,8,128, +1,0,255,128,24,0,0,160,5,0,0,3,0,0,8,128, +0,0,255,128,1,0,255,128,5,0,0,3,1,0,7,128, +0,0,255,128,1,0,228,128,10,0,0,3,1,0,7,128, +1,0,228,128,24,0,0,160,2,0,0,3,0,0,7,128, +0,0,228,128,1,0,228,128,5,0,0,3,0,0,8,128, +9,0,255,160,9,0,255,160,12,0,0,3,0,0,8,128, +0,0,255,129,0,0,255,128,4,0,0,4,1,0,7,128, +0,0,228,144,9,0,255,161,9,0,228,160,8,0,0,3, +1,0,8,128,1,0,228,128,1,0,228,128,12,0,0,3, +2,0,2,128,15,0,255,160,1,0,255,128,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,85,128,4,0,0,4, +2,0,2,128,15,0,170,160,1,0,255,128,2,0,0,128, +7,0,0,2,1,0,8,128,1,0,255,128,5,0,0,3, +1,0,7,128,1,0,255,128,1,0,228,128,6,0,0,2, +1,0,8,128,2,0,85,128,4,0,0,4,0,0,8,128, +0,0,255,128,1,0,255,129,1,0,255,128,8,0,0,3, +1,0,8,128,1,0,228,128,21,0,228,160,8,0,0,3, +1,0,1,128,1,0,228,144,1,0,228,128,11,0,0,3, +1,0,9,128,1,0,228,128,24,0,85,160,5,0,0,3, +1,0,7,128,1,0,0,128,3,0,228,144,5,0,0,3, +1,0,7,128,1,0,228,128,3,0,228,160,2,0,0,3, +1,0,8,128,1,0,255,128,15,0,0,161,5,0,0,3, +1,0,8,128,1,0,255,128,15,0,85,160,11,0,0,3, +1,0,8,128,1,0,255,128,24,0,85,160,10,0,0,3, +1,0,8,128,1,0,255,128,24,0,0,160,5,0,0,3, +0,0,8,128,0,0,255,128,1,0,255,128,5,0,0,3, +1,0,7,128,0,0,255,128,1,0,228,128,10,0,0,3, +1,0,7,128,1,0,228,128,24,0,0,160,2,0,0,3, +0,0,7,128,0,0,228,128,1,0,228,128,5,0,0,3, +0,0,8,128,10,0,255,160,10,0,255,160,12,0,0,3, +0,0,8,128,0,0,255,129,0,0,255,128,4,0,0,4, +1,0,7,128,0,0,228,144,10,0,255,161,10,0,228,160, +8,0,0,3,1,0,8,128,1,0,228,128,1,0,228,128, +12,0,0,3,2,0,2,128,16,0,255,160,1,0,255,128, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,85,128, +4,0,0,4,2,0,2,128,16,0,170,160,1,0,255,128, +2,0,0,128,7,0,0,2,1,0,8,128,1,0,255,128, +5,0,0,3,1,0,7,128,1,0,255,128,1,0,228,128, +6,0,0,2,1,0,8,128,2,0,85,128,4,0,0,4, +0,0,8,128,0,0,255,128,1,0,255,129,1,0,255,128, +8,0,0,3,1,0,8,128,1,0,228,128,22,0,228,160, +8,0,0,3,1,0,1,128,1,0,228,144,1,0,228,128, +11,0,0,3,1,0,9,128,1,0,228,128,24,0,85,160, +5,0,0,3,1,0,7,128,1,0,0,128,3,0,228,144, +5,0,0,3,1,0,7,128,1,0,228,128,4,0,228,160, +2,0,0,3,1,0,8,128,1,0,255,128,16,0,0,161, +5,0,0,3,1,0,8,128,1,0,255,128,16,0,85,160, +11,0,0,3,1,0,8,128,1,0,255,128,24,0,85,160, +10,0,0,3,1,0,8,128,1,0,255,128,24,0,0,160, +5,0,0,3,0,0,8,128,0,0,255,128,1,0,255,128, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,1,0,7,128,1,0,228,128,24,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,1,0,228,128, +5,0,0,3,0,0,8,128,11,0,255,160,11,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,11,0,255,161, +11,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,17,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,1,128,17,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,0,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +23,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +24,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +5,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +17,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +17,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +24,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +24,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +24,0,0,160,2,0,0,3,0,0,7,224,0,0,228,128, +1,0,228,128,1,0,0,2,1,0,7,224,4,0,228,144, +255,255,0,0,83,72,68,82,24,4,0,0,64,0,240,255, +6,1,0,0,89,8,0,4,70,142,32,0,0,0,0,0, +41,0,0,0,95,0,0,3,114,16,16,0,0,0,0,0, +95,0,0,3,114,16,16,0,1,0,0,0,95,0,0,3, +114,16,16,0,3,0,0,0,95,0,0,3,114,16,16,0, +4,0,0,0,95,0,0,3,114,16,16,0,5,0,0,0, +101,0,0,3,114,32,16,0,0,0,0,0,101,0,0,3, +114,32,16,0,1,0,0,0,104,0,0,2,3,0,0,0, +54,0,0,5,114,0,16,0,0,0,0,0,70,18,16,0, +5,0,0,0,54,0,0,5,130,0,16,0,0,0,0,0, +1,64,0,0,0,0,0,0,48,0,0,1,33,0,0,7, +18,0,16,0,1,0,0,0,58,0,16,0,0,0,0,0, +1,64,0,0,6,0,0,0,3,0,4,3,10,0,16,0, +1,0,0,0,50,0,0,16,114,0,16,0,1,0,0,0, +70,18,16,128,65,0,0,0,0,0,0,0,246,143,32,6, +0,0,0,0,18,0,0,0,58,0,16,0,0,0,0,0, +70,130,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,16,0,0,7,130,0,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +50,0,0,12,18,0,16,0,2,0,0,0,42,128,32,6, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,128,63, +14,0,0,10,18,0,16,0,2,0,0,0,2,64,0,0, +0,0,128,63,0,0,128,63,0,0,128,63,0,0,128,63, +10,0,16,0,2,0,0,0,57,0,0,10,34,0,16,0, +2,0,0,0,1,64,0,0,0,0,0,0,58,128,32,6, +0,0,0,0,18,0,0,0,58,0,16,0,0,0,0,0, +49,0,0,10,66,0,16,0,2,0,0,0,58,128,32,6, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +58,0,16,0,1,0,0,0,1,0,0,7,34,0,16,0, +2,0,0,0,42,0,16,0,2,0,0,0,26,0,16,0, +2,0,0,0,55,0,0,9,18,0,16,0,2,0,0,0, +26,0,16,0,2,0,0,0,1,64,0,0,0,0,0,0, +10,0,16,0,2,0,0,0,68,0,0,5,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,56,0,0,7, +114,0,16,0,1,0,0,0,246,15,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,16,0,0,10,130,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,130,32,6, +0,0,0,0,34,0,0,0,58,0,16,0,0,0,0,0, +52,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,1,64,0,0,0,0,0,0,0,0,0,11, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +10,128,32,134,65,0,0,0,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,32,0,10,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,26,128,32,6, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,10,0,16,0,2,0,0,0,16,0,0,7, +18,0,16,0,1,0,0,0,70,18,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,52,0,0,7,18,0,16,0, +1,0,0,0,10,0,16,0,1,0,0,0,1,64,0,0, +0,0,0,0,56,0,0,7,114,0,16,0,1,0,0,0, +6,0,16,0,1,0,0,0,70,18,16,0,3,0,0,0, +56,0,0,10,114,0,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,70,130,32,6,0,0,0,0,10,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,114,0,16,0, +1,0,0,0,246,15,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,51,0,0,10,114,0,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,2,64,0,0,0,0,128,63, +0,0,128,63,0,0,128,63,0,0,0,0,0,0,0,7, +114,0,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +70,2,16,0,1,0,0,0,30,0,0,7,130,0,16,0, +0,0,0,0,58,0,16,0,0,0,0,0,1,64,0,0, +1,0,0,0,22,0,0,1,54,0,0,5,114,32,16,0, +0,0,0,0,70,2,16,0,0,0,0,0,54,0,0,5, +114,32,16,0,1,0,0,0,70,18,16,0,4,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,32,0,0,0, +3,0,0,0,0,0,0,0,7,0,0,0,20,0,0,0, +2,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,4,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,188,4,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +142,4,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,86,101,114,116,101, +120,0,171,171,92,0,0,0,14,0,0,0,132,0,0,0, +240,3,0,0,0,0,0,0,0,0,0,0,180,2,0,0, +0,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,240,2,0,0,64,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,253,2,0,0, +128,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,3,0,0,144,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,71,3,0,0, +160,0,0,0,128,0,0,0,2,0,0,0,88,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,124,3,0,0,32,1,0,0,128,0,0,0, +2,0,0,0,140,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,176,3,0,0, +160,1,0,0,128,0,0,0,2,0,0,0,192,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,228,3,0,0,32,2,0,0,128,0,0,0, +2,0,0,0,244,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,24,4,0,0, +160,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,39,4,0,0,176,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,54,4,0,0, +192,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,66,4,0,0,208,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,82,4,0,0, +224,2,0,0,0,1,0,0,0,0,0,0,96,4,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,132,4,0,0,224,3,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,112,0,102,108,111,97,116,52, +120,52,0,171,3,0,3,0,4,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,0,102,102,95,118,101,99,95,99,111,108,111, +114,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,118,101,99,95,97,109,98,105,101,110,116,0,102, +102,95,108,105,103,104,116,95,99,111,108,111,114,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,112,111,115, +0,171,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,97,116,116,101,110,0,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,115,112,111,116,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,109,97,116,95,100,105,102,102,117,115,101,0,102, +102,95,109,97,116,95,97,109,98,105,101,110,116,0,102,102, +95,109,97,116,95,115,112,101,99,0,102,102,95,109,97,116, +95,101,109,105,115,115,105,111,110,0,102,102,95,109,97,116, +114,105,120,95,116,101,120,0,3,0,3,0,4,0,4,0, +4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,102, +111,103,95,118,115,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,164,1,0,0,7,0,0,0, +8,0,0,0,88,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,106,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,118,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,128,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,2,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,136,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,149,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +3,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,159,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,5,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,67,111,109,112,117,116,101,83,112,111,116,76, +105,103,104,116,54,0,101,121,101,80,111,115,105,116,105,111, +110,0,101,121,101,78,111,114,109,97,108,0,118,105,101,119, +68,105,114,0,100,105,102,102,117,115,101,67,111,108,111,114, +0,115,112,101,99,67,111,108,111,114,0,97,109,98,0,171, +76,73,66,70,80,16,0,0,68,88,66,67,234,246,83,85, +128,3,122,132,33,202,50,54,82,138,167,19,1,0,0,0, +80,16,0,0,5,0,0,0,52,0,0,0,156,3,0,0, +96,9,0,0,220,9,0,0,160,14,0,0,65,111,110,57, +96,3,0,0,96,3,0,0,0,2,86,76,48,3,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,0,0,0,0,45,0,0,0, +0,0,0,0,0,2,86,76,81,0,0,5,45,0,15,160, +0,0,0,0,0,0,0,0,0,0,128,63,0,0,0,0, +48,0,0,5,0,0,15,240,6,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,31,0,0,2,5,0,0,128, +0,0,15,144,31,0,0,2,5,0,1,128,1,0,15,144, +31,0,0,2,5,0,2,128,2,0,15,144,31,0,0,2, +5,0,3,128,3,0,15,144,31,0,0,2,5,0,4,128, +4,0,15,144,31,0,0,2,5,0,5,128,5,0,15,144, +1,0,0,2,0,0,7,128,4,0,228,144,1,0,0,2, +1,0,7,128,5,0,228,144,27,0,0,2,0,8,228,240, +0,0,228,240,4,0,0,6,2,0,7,128,0,0,228,144, +18,32,255,161,0,8,228,240,18,32,228,160,0,8,228,240, +8,0,0,3,0,0,8,128,2,0,228,128,2,0,228,128, +7,0,0,2,1,0,8,128,0,0,255,128,4,0,0,4, +3,0,7,128,2,0,228,128,1,0,255,128,2,0,228,144, +36,0,0,2,4,0,7,128,3,0,228,128,8,0,0,3, +2,0,8,128,1,0,228,144,4,0,228,128,5,0,0,5, +3,0,1,128,18,32,255,160,0,8,228,240,18,32,255,160, +0,8,228,240,12,0,0,3,3,0,1,128,3,0,0,129, +3,0,0,128,12,0,0,4,3,0,2,128,26,32,255,160, +0,8,228,240,0,0,255,128,5,0,0,3,3,0,1,128, +3,0,85,128,3,0,0,128,5,0,0,4,0,0,8,128, +0,0,255,128,26,32,170,160,0,8,228,240,2,0,0,3, +0,0,8,128,0,0,255,128,45,0,170,160,6,0,0,2, +0,0,8,128,0,0,255,128,4,0,0,4,0,0,8,128, +3,0,0,128,0,0,255,129,0,0,255,128,11,0,0,3, +2,0,8,128,2,0,255,128,45,0,85,160,32,0,0,3, +3,0,1,128,2,0,255,128,44,0,255,160,10,0,0,3, +2,0,8,128,3,0,0,128,45,0,170,160,5,0,0,3, +2,0,7,128,1,0,255,128,2,0,228,128,8,0,0,3, +1,0,8,128,1,0,228,144,2,0,228,128,8,0,0,4, +2,0,1,128,2,0,228,128,34,32,228,160,0,8,228,240, +11,0,0,3,2,0,1,128,2,0,0,128,45,0,85,160, +2,0,0,4,2,0,1,128,2,0,0,128,26,32,0,161, +0,8,228,240,5,0,0,4,2,0,1,128,2,0,0,128, +26,32,85,160,0,8,228,240,11,0,0,3,2,0,1,128, +2,0,0,128,45,0,85,160,10,0,0,3,2,0,1,128, +2,0,0,128,45,0,170,160,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,0,128,11,0,0,3,1,0,8,128, +1,0,255,128,45,0,85,160,12,0,0,3,2,0,1,128, +45,0,85,160,1,0,255,128,5,0,0,3,2,0,2,128, +2,0,255,128,0,0,255,128,5,0,0,4,2,0,14,128, +2,0,85,128,10,32,144,160,0,8,228,240,4,0,0,4, +0,0,7,128,2,0,0,128,2,0,249,128,0,0,228,128, +5,0,0,3,2,0,7,128,1,0,255,128,3,0,228,144, +5,0,0,4,2,0,7,128,2,0,228,128,10,32,228,160, +0,8,228,240,5,0,0,3,2,0,7,128,0,0,255,128, +2,0,228,128,10,0,0,3,2,0,7,128,2,0,228,128, +45,0,170,160,2,0,0,3,1,0,7,128,1,0,228,128, +2,0,228,128,29,0,0,0,1,0,0,2,1,0,7,224, +0,0,228,128,1,0,0,2,0,0,7,224,1,0,228,128, +255,255,0,0,83,72,68,82,188,5,0,0,64,0,240,255, +111,1,0,0,89,8,0,4,70,142,32,0,0,0,0,0, +45,0,0,0,95,0,0,3,114,16,16,0,0,0,0,0, +95,0,0,3,114,16,16,0,1,0,0,0,95,0,0,3, +114,16,16,0,2,0,0,0,95,0,0,3,114,16,16,0, +3,0,0,0,95,0,0,3,114,16,16,0,4,0,0,0, +95,0,0,3,114,16,16,0,5,0,0,0,101,0,0,3, +114,32,16,0,0,0,0,0,101,0,0,3,114,32,16,0, +1,0,0,0,104,0,0,2,4,0,0,0,54,0,0,5, +114,0,16,0,0,0,0,0,70,18,16,0,4,0,0,0, +54,0,0,5,114,0,16,0,1,0,0,0,70,18,16,0, +5,0,0,0,54,0,0,5,130,0,16,0,0,0,0,0, +1,64,0,0,0,0,0,0,48,0,0,1,33,0,0,7, +130,0,16,0,1,0,0,0,58,0,16,0,0,0,0,0, +1,64,0,0,6,0,0,0,3,0,4,3,58,0,16,0, +1,0,0,0,50,0,0,16,114,0,16,0,2,0,0,0, +70,18,16,128,65,0,0,0,0,0,0,0,246,143,32,6, +0,0,0,0,18,0,0,0,58,0,16,0,0,0,0,0, +70,130,32,6,0,0,0,0,18,0,0,0,58,0,16,0, +0,0,0,0,16,0,0,7,130,0,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,70,2,16,0,2,0,0,0, +50,0,0,12,130,0,16,0,2,0,0,0,42,128,32,6, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,128,63, +14,0,0,10,130,0,16,0,2,0,0,0,2,64,0,0, +0,0,128,63,0,0,128,63,0,0,128,63,0,0,128,63, +58,0,16,0,2,0,0,0,57,0,0,10,18,0,16,0, +3,0,0,0,1,64,0,0,0,0,0,0,58,128,32,6, +0,0,0,0,18,0,0,0,58,0,16,0,0,0,0,0, +49,0,0,10,34,0,16,0,3,0,0,0,58,128,32,6, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +58,0,16,0,1,0,0,0,1,0,0,7,18,0,16,0, +3,0,0,0,26,0,16,0,3,0,0,0,10,0,16,0, +3,0,0,0,55,0,0,9,130,0,16,0,2,0,0,0, +10,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +58,0,16,0,2,0,0,0,68,0,0,5,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,56,0,0,7, +114,0,16,0,3,0,0,0,246,15,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,16,0,0,10,130,0,16,0, +3,0,0,0,70,2,16,0,3,0,0,0,70,130,32,6, +0,0,0,0,34,0,0,0,58,0,16,0,0,0,0,0, +52,0,0,7,130,0,16,0,3,0,0,0,58,0,16,0, +3,0,0,0,1,64,0,0,0,0,0,0,0,0,0,11, +130,0,16,0,3,0,0,0,58,0,16,0,3,0,0,0, +10,128,32,134,65,0,0,0,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,32,0,10,130,0,16,0, +3,0,0,0,58,0,16,0,3,0,0,0,26,128,32,6, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,0,0,7,130,0,16,0,2,0,0,0,58,0,16,0, +2,0,0,0,58,0,16,0,3,0,0,0,16,0,0,7, +18,0,16,0,3,0,0,0,70,18,16,0,1,0,0,0, +70,2,16,0,3,0,0,0,52,0,0,7,18,0,16,0, +3,0,0,0,10,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,56,0,0,7,226,0,16,0,3,0,0,0, +6,0,16,0,3,0,0,0,6,25,16,0,3,0,0,0, +56,0,0,10,226,0,16,0,3,0,0,0,86,14,16,0, +3,0,0,0,6,137,32,6,0,0,0,0,10,0,0,0, +58,0,16,0,0,0,0,0,49,0,0,7,18,0,16,0, +3,0,0,0,1,64,0,0,0,0,0,0,10,0,16,0, +3,0,0,0,31,0,4,3,10,0,16,0,3,0,0,0, +50,0,0,9,114,0,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,246,15,16,0,1,0,0,0,70,18,16,0, +2,0,0,0,16,0,0,7,130,0,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,70,2,16,0,2,0,0,0, +68,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,7,114,0,16,0,2,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +16,0,0,7,130,0,16,0,1,0,0,0,70,18,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,52,0,0,7, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,0,0,47,0,0,5,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,56,0,0,8, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +58,128,32,0,0,0,0,0,44,0,0,0,25,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +51,0,0,7,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,1,64,0,0,0,0,128,63,56,0,0,7, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +58,0,16,0,2,0,0,0,50,0,0,12,114,0,16,0, +0,0,0,0,246,15,16,0,1,0,0,0,70,130,32,6, +0,0,0,0,10,0,0,0,58,0,16,0,0,0,0,0, +70,2,16,0,0,0,0,0,21,0,0,1,56,0,0,7, +114,0,16,0,2,0,0,0,246,15,16,0,2,0,0,0, +150,7,16,0,3,0,0,0,51,0,0,10,114,0,16,0, +2,0,0,0,70,2,16,0,2,0,0,0,2,64,0,0, +0,0,128,63,0,0,128,63,0,0,128,63,0,0,0,0, +0,0,0,7,114,0,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,30,0,0,7, +130,0,16,0,0,0,0,0,58,0,16,0,0,0,0,0, +1,64,0,0,1,0,0,0,22,0,0,1,54,0,0,5, +114,32,16,0,1,0,0,0,70,2,16,0,0,0,0,0, +54,0,0,5,114,32,16,0,0,0,0,0,70,2,16,0, +1,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +48,0,0,0,4,0,0,0,0,0,0,0,8,0,0,0, +33,0,0,0,2,0,0,0,1,0,0,0,1,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,2,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,2,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,2,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,2,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,2,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,168,1,0,0, +7,0,0,0,8,0,0,0,88,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,110,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,122,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,132,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,140,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,153,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,163,1,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,5,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,112,117,116,101,83, +112,111,116,76,105,103,104,116,83,112,101,99,54,0,101,121, +101,80,111,115,105,116,105,111,110,0,101,121,101,78,111,114, +109,97,108,0,118,105,101,119,68,105,114,0,100,105,102,102, +117,115,101,67,111,108,111,114,0,115,112,101,99,67,111,108, +111,114,0,97,109,98,0,171,76,73,66,70,188,22,0,0, +68,88,66,67,203,163,211,164,74,232,227,110,255,5,54,13, +127,129,226,75,1,0,0,0,188,22,0,0,5,0,0,0, +52,0,0,0,176,11,0,0,208,15,0,0,76,16,0,0, +16,21,0,0,65,111,110,57,116,11,0,0,116,11,0,0, +0,2,86,76,32,11,0,0,84,0,0,0,4,0,36,0, +0,0,84,0,0,0,84,0,0,0,36,0,0,0,84,0, +0,0,10,0,7,0,0,0,0,0,0,0,0,0,18,0, +7,0,7,0,0,0,0,0,0,0,26,0,7,0,14,0, +0,0,0,0,0,0,34,0,7,0,21,0,0,0,0,0, +0,2,86,76,81,0,0,5,28,0,15,160,0,0,128,63, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,31,0,0,2,5,0,1,128, +1,0,15,144,31,0,0,2,5,0,3,128,3,0,15,144, +31,0,0,2,5,0,4,128,4,0,15,144,31,0,0,2, +5,0,5,128,5,0,15,144,5,0,0,3,0,0,1,128, +7,0,255,160,7,0,255,160,12,0,0,3,0,0,1,128, +0,0,0,129,0,0,0,128,4,0,0,4,0,0,14,128, +0,0,144,144,7,0,255,161,7,0,144,160,8,0,0,3, +1,0,1,128,0,0,249,128,0,0,249,128,12,0,0,3, +1,0,2,128,14,0,255,160,1,0,0,128,5,0,0,3, +0,0,1,128,0,0,0,128,1,0,85,128,1,0,0,2, +2,0,1,128,28,0,0,160,4,0,0,4,1,0,2,128, +14,0,170,160,1,0,0,128,2,0,0,128,7,0,0,2, +1,0,1,128,1,0,0,128,5,0,0,3,0,0,14,128, +0,0,228,128,1,0,0,128,6,0,0,2,1,0,1,128, +1,0,85,128,4,0,0,4,0,0,1,128,0,0,0,128, +1,0,0,129,1,0,0,128,8,0,0,3,1,0,1,128, +0,0,249,128,21,0,228,160,8,0,0,3,0,0,2,128, +1,0,228,144,0,0,249,128,11,0,0,3,0,0,2,128, +0,0,85,128,28,0,85,160,5,0,0,3,0,0,14,128, +0,0,85,128,3,0,144,144,5,0,0,3,0,0,14,128, +0,0,228,128,0,0,144,160,11,0,0,3,1,0,1,128, +1,0,0,128,28,0,85,160,2,0,0,3,1,0,1,128, +1,0,0,128,14,0,0,161,5,0,0,3,1,0,1,128, +1,0,0,128,14,0,85,160,11,0,0,3,1,0,1,128, +1,0,0,128,28,0,85,160,10,0,0,3,1,0,1,128, +1,0,0,128,28,0,0,160,5,0,0,3,0,0,1,128, +0,0,0,128,1,0,0,128,5,0,0,3,0,0,7,128, +0,0,0,128,0,0,249,128,10,0,0,3,0,0,7,128, +0,0,228,128,28,0,0,160,2,0,0,3,0,0,7,128, +0,0,228,128,5,0,228,144,5,0,0,3,0,0,8,128, +8,0,255,160,8,0,255,160,12,0,0,3,0,0,8,128, +0,0,255,129,0,0,255,128,4,0,0,4,1,0,7,128, +0,0,228,144,8,0,255,161,8,0,228,160,8,0,0,3, +1,0,8,128,1,0,228,128,1,0,228,128,12,0,0,3, +2,0,2,128,15,0,255,160,1,0,255,128,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,85,128,4,0,0,4, +2,0,2,128,15,0,170,160,1,0,255,128,2,0,0,128, +7,0,0,2,1,0,8,128,1,0,255,128,5,0,0,3, +1,0,7,128,1,0,255,128,1,0,228,128,6,0,0,2, +1,0,8,128,2,0,85,128,4,0,0,4,0,0,8,128, +0,0,255,128,1,0,255,129,1,0,255,128,8,0,0,3, +1,0,8,128,1,0,228,128,22,0,228,160,8,0,0,3, +1,0,1,128,1,0,228,144,1,0,228,128,11,0,0,3, +1,0,9,128,1,0,228,128,28,0,85,160,5,0,0,3, +1,0,7,128,1,0,0,128,3,0,228,144,5,0,0,3, +1,0,7,128,1,0,228,128,1,0,228,160,2,0,0,3, +1,0,8,128,1,0,255,128,15,0,0,161,5,0,0,3, +1,0,8,128,1,0,255,128,15,0,85,160,11,0,0,3, +1,0,8,128,1,0,255,128,28,0,85,160,10,0,0,3, +1,0,8,128,1,0,255,128,28,0,0,160,5,0,0,3, +0,0,8,128,0,0,255,128,1,0,255,128,5,0,0,3, +1,0,7,128,0,0,255,128,1,0,228,128,10,0,0,3, +1,0,7,128,1,0,228,128,28,0,0,160,2,0,0,3, +0,0,7,128,0,0,228,128,1,0,228,128,5,0,0,3, +0,0,8,128,9,0,255,160,9,0,255,160,12,0,0,3, +0,0,8,128,0,0,255,129,0,0,255,128,4,0,0,4, +1,0,7,128,0,0,228,144,9,0,255,161,9,0,228,160, +8,0,0,3,1,0,8,128,1,0,228,128,1,0,228,128, +12,0,0,3,2,0,2,128,16,0,255,160,1,0,255,128, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,85,128, +4,0,0,4,2,0,2,128,16,0,170,160,1,0,255,128, +2,0,0,128,7,0,0,2,1,0,8,128,1,0,255,128, +5,0,0,3,1,0,7,128,1,0,255,128,1,0,228,128, +6,0,0,2,1,0,8,128,2,0,85,128,4,0,0,4, +0,0,8,128,0,0,255,128,1,0,255,129,1,0,255,128, +8,0,0,3,1,0,8,128,1,0,228,128,23,0,228,160, +8,0,0,3,1,0,1,128,1,0,228,144,1,0,228,128, +11,0,0,3,1,0,9,128,1,0,228,128,28,0,85,160, +5,0,0,3,1,0,7,128,1,0,0,128,3,0,228,144, +5,0,0,3,1,0,7,128,1,0,228,128,2,0,228,160, +2,0,0,3,1,0,8,128,1,0,255,128,16,0,0,161, +5,0,0,3,1,0,8,128,1,0,255,128,16,0,85,160, +11,0,0,3,1,0,8,128,1,0,255,128,28,0,85,160, +10,0,0,3,1,0,8,128,1,0,255,128,28,0,0,160, +5,0,0,3,0,0,8,128,0,0,255,128,1,0,255,128, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,1,0,7,128,1,0,228,128,28,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,1,0,228,128, +5,0,0,3,0,0,8,128,10,0,255,160,10,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,10,0,255,161, +10,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,17,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,2,128,17,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,85,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +24,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +28,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +3,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +17,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +17,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +28,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +28,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +28,0,0,160,2,0,0,3,0,0,7,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,8,128,11,0,255,160, +11,0,255,160,12,0,0,3,0,0,8,128,0,0,255,129, +0,0,255,128,4,0,0,4,1,0,7,128,0,0,228,144, +11,0,255,161,11,0,228,160,8,0,0,3,1,0,8,128, +1,0,228,128,1,0,228,128,12,0,0,3,2,0,2,128, +18,0,255,160,1,0,255,128,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,85,128,4,0,0,4,2,0,2,128, +18,0,170,160,1,0,255,128,2,0,0,128,7,0,0,2, +1,0,8,128,1,0,255,128,5,0,0,3,1,0,7,128, +1,0,255,128,1,0,228,128,6,0,0,2,1,0,8,128, +2,0,85,128,4,0,0,4,0,0,8,128,0,0,255,128, +1,0,255,129,1,0,255,128,8,0,0,3,1,0,8,128, +1,0,228,128,25,0,228,160,8,0,0,3,1,0,1,128, +1,0,228,144,1,0,228,128,11,0,0,3,1,0,9,128, +1,0,228,128,28,0,85,160,5,0,0,3,1,0,7,128, +1,0,0,128,3,0,228,144,5,0,0,3,1,0,7,128, +1,0,228,128,4,0,228,160,2,0,0,3,1,0,8,128, +1,0,255,128,18,0,0,161,5,0,0,3,1,0,8,128, +1,0,255,128,18,0,85,160,11,0,0,3,1,0,8,128, +1,0,255,128,28,0,85,160,10,0,0,3,1,0,8,128, +1,0,255,128,28,0,0,160,5,0,0,3,0,0,8,128, +0,0,255,128,1,0,255,128,5,0,0,3,1,0,7,128, +0,0,255,128,1,0,228,128,10,0,0,3,1,0,7,128, +1,0,228,128,28,0,0,160,2,0,0,3,0,0,7,128, +0,0,228,128,1,0,228,128,5,0,0,3,0,0,8,128, +12,0,255,160,12,0,255,160,12,0,0,3,0,0,8,128, +0,0,255,129,0,0,255,128,4,0,0,4,1,0,7,128, +0,0,228,144,12,0,255,161,12,0,228,160,8,0,0,3, +1,0,8,128,1,0,228,128,1,0,228,128,12,0,0,3, +2,0,2,128,19,0,255,160,1,0,255,128,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,85,128,4,0,0,4, +2,0,2,128,19,0,170,160,1,0,255,128,2,0,0,128, +7,0,0,2,1,0,8,128,1,0,255,128,5,0,0,3, +1,0,7,128,1,0,255,128,1,0,228,128,6,0,0,2, +1,0,8,128,2,0,85,128,4,0,0,4,0,0,8,128, +0,0,255,128,1,0,255,129,1,0,255,128,8,0,0,3, +1,0,8,128,1,0,228,128,26,0,228,160,8,0,0,3, +1,0,1,128,1,0,228,144,1,0,228,128,11,0,0,3, +1,0,9,128,1,0,228,128,28,0,85,160,5,0,0,3, +1,0,7,128,1,0,0,128,3,0,228,144,5,0,0,3, +1,0,7,128,1,0,228,128,5,0,228,160,2,0,0,3, +1,0,8,128,1,0,255,128,19,0,0,161,5,0,0,3, +1,0,8,128,1,0,255,128,19,0,85,160,11,0,0,3, +1,0,8,128,1,0,255,128,28,0,85,160,10,0,0,3, +1,0,8,128,1,0,255,128,28,0,0,160,5,0,0,3, +0,0,8,128,0,0,255,128,1,0,255,128,5,0,0,3, +1,0,7,128,0,0,255,128,1,0,228,128,10,0,0,3, +1,0,7,128,1,0,228,128,28,0,0,160,2,0,0,3, +0,0,7,128,0,0,228,128,1,0,228,128,5,0,0,3, +0,0,8,128,13,0,255,160,13,0,255,160,12,0,0,3, +0,0,8,128,0,0,255,129,0,0,255,128,4,0,0,4, +1,0,7,128,0,0,228,144,13,0,255,161,13,0,228,160, +8,0,0,3,1,0,8,128,1,0,228,128,1,0,228,128, +12,0,0,3,2,0,2,128,20,0,255,160,1,0,255,128, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,85,128, +4,0,0,4,2,0,1,128,20,0,170,160,1,0,255,128, +2,0,0,128,7,0,0,2,1,0,8,128,1,0,255,128, +5,0,0,3,1,0,7,128,1,0,255,128,1,0,228,128, +6,0,0,2,1,0,8,128,2,0,0,128,4,0,0,4, +0,0,8,128,0,0,255,128,1,0,255,129,1,0,255,128, +8,0,0,3,1,0,8,128,1,0,228,128,27,0,228,160, +8,0,0,3,1,0,1,128,1,0,228,144,1,0,228,128, +11,0,0,3,1,0,9,128,1,0,228,128,28,0,85,160, +5,0,0,3,1,0,7,128,1,0,0,128,3,0,228,144, +5,0,0,3,1,0,7,128,1,0,228,128,6,0,228,160, +2,0,0,3,1,0,8,128,1,0,255,128,20,0,0,161, +5,0,0,3,1,0,8,128,1,0,255,128,20,0,85,160, +11,0,0,3,1,0,8,128,1,0,255,128,28,0,85,160, +10,0,0,3,1,0,8,128,1,0,255,128,28,0,0,160, +5,0,0,3,0,0,8,128,0,0,255,128,1,0,255,128, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,1,0,7,128,1,0,228,128,28,0,0,160, +2,0,0,3,0,0,7,224,0,0,228,128,1,0,228,128, +1,0,0,2,1,0,7,224,4,0,228,144,255,255,0,0, +83,72,68,82,24,4,0,0,64,0,240,255,6,1,0,0, +89,8,0,4,70,142,32,0,0,0,0,0,42,0,0,0, +95,0,0,3,114,16,16,0,0,0,0,0,95,0,0,3, +114,16,16,0,1,0,0,0,95,0,0,3,114,16,16,0, +3,0,0,0,95,0,0,3,114,16,16,0,4,0,0,0, +95,0,0,3,114,16,16,0,5,0,0,0,101,0,0,3, +114,32,16,0,0,0,0,0,101,0,0,3,114,32,16,0, +1,0,0,0,104,0,0,2,3,0,0,0,54,0,0,5, +114,0,16,0,0,0,0,0,70,18,16,0,5,0,0,0, +54,0,0,5,130,0,16,0,0,0,0,0,1,64,0,0, +0,0,0,0,48,0,0,1,33,0,0,7,18,0,16,0, +1,0,0,0,58,0,16,0,0,0,0,0,1,64,0,0, +7,0,0,0,3,0,4,3,10,0,16,0,1,0,0,0, +50,0,0,16,114,0,16,0,1,0,0,0,70,18,16,128, +65,0,0,0,0,0,0,0,246,143,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,70,130,32,6, +0,0,0,0,18,0,0,0,58,0,16,0,0,0,0,0, +16,0,0,7,130,0,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,50,0,0,12, +18,0,16,0,2,0,0,0,42,128,32,6,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,58,0,16,0, +1,0,0,0,1,64,0,0,0,0,128,63,14,0,0,10, +18,0,16,0,2,0,0,0,2,64,0,0,0,0,128,63, +0,0,128,63,0,0,128,63,0,0,128,63,10,0,16,0, +2,0,0,0,57,0,0,10,34,0,16,0,2,0,0,0, +1,64,0,0,0,0,0,0,58,128,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,49,0,0,10, +66,0,16,0,2,0,0,0,58,128,32,6,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,58,0,16,0, +1,0,0,0,1,0,0,7,34,0,16,0,2,0,0,0, +42,0,16,0,2,0,0,0,26,0,16,0,2,0,0,0, +55,0,0,9,18,0,16,0,2,0,0,0,26,0,16,0, +2,0,0,0,1,64,0,0,0,0,0,0,10,0,16,0, +2,0,0,0,68,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,56,0,0,7,114,0,16,0, +1,0,0,0,246,15,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,16,0,0,10,130,0,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,70,130,32,6,0,0,0,0, +34,0,0,0,58,0,16,0,0,0,0,0,52,0,0,7, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,0,0,0,0,0,11,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,10,128,32,134, +65,0,0,0,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,56,32,0,10,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,26,128,32,6,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,56,0,0,7, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +10,0,16,0,2,0,0,0,16,0,0,7,18,0,16,0, +1,0,0,0,70,18,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,52,0,0,7,18,0,16,0,1,0,0,0, +10,0,16,0,1,0,0,0,1,64,0,0,0,0,0,0, +56,0,0,7,114,0,16,0,1,0,0,0,6,0,16,0, +1,0,0,0,70,18,16,0,3,0,0,0,56,0,0,10, +114,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +70,130,32,6,0,0,0,0,10,0,0,0,58,0,16,0, +0,0,0,0,56,0,0,7,114,0,16,0,1,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +51,0,0,10,114,0,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,0,0,0,0,0,7,114,0,16,0, +0,0,0,0,70,2,16,0,0,0,0,0,70,2,16,0, +1,0,0,0,30,0,0,7,130,0,16,0,0,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,1,0,0,0, +22,0,0,1,54,0,0,5,114,32,16,0,0,0,0,0, +70,2,16,0,0,0,0,0,54,0,0,5,114,32,16,0, +1,0,0,0,70,18,16,0,4,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,32,0,0,0,3,0,0,0, +0,0,0,0,7,0,0,0,20,0,0,0,2,0,0,0, +1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,4,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,2,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,2,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,2,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,2,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,0,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,164,1,0,0,7,0,0,0,8,0,0,0, +88,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +106,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +118,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +128,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +2,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +136,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +149,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +159,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +5,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +67,111,109,112,117,116,101,83,112,111,116,76,105,103,104,116, +55,0,101,121,101,80,111,115,105,116,105,111,110,0,101,121, +101,78,111,114,109,97,108,0,118,105,101,119,68,105,114,0, +100,105,102,102,117,115,101,67,111,108,111,114,0,115,112,101, +99,67,111,108,111,114,0,97,109,98,0,171,76,73,66,70, +80,16,0,0,68,88,66,67,54,132,209,166,254,167,118,10, +196,111,133,126,129,212,65,104,1,0,0,0,80,16,0,0, +5,0,0,0,52,0,0,0,156,3,0,0,96,9,0,0, +220,9,0,0,160,14,0,0,65,111,110,57,96,3,0,0, +96,3,0,0,0,2,86,76,48,3,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,0,0,45,0,0,0,0,0,0,0, +0,2,86,76,81,0,0,5,45,0,15,160,0,0,0,0, +0,0,0,0,0,0,128,63,0,0,0,0,48,0,0,5, +0,0,15,240,7,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,31,0,0,2, +5,0,2,128,2,0,15,144,31,0,0,2,5,0,3,128, +3,0,15,144,31,0,0,2,5,0,4,128,4,0,15,144, +31,0,0,2,5,0,5,128,5,0,15,144,1,0,0,2, +0,0,7,128,4,0,228,144,1,0,0,2,1,0,7,128, +5,0,228,144,27,0,0,2,0,8,228,240,0,0,228,240, +4,0,0,6,2,0,7,128,0,0,228,144,18,32,255,161, +0,8,228,240,18,32,228,160,0,8,228,240,8,0,0,3, +0,0,8,128,2,0,228,128,2,0,228,128,7,0,0,2, +1,0,8,128,0,0,255,128,4,0,0,4,3,0,7,128, +2,0,228,128,1,0,255,128,2,0,228,144,36,0,0,2, +4,0,7,128,3,0,228,128,8,0,0,3,2,0,8,128, +1,0,228,144,4,0,228,128,5,0,0,5,3,0,1,128, +18,32,255,160,0,8,228,240,18,32,255,160,0,8,228,240, +12,0,0,3,3,0,1,128,3,0,0,129,3,0,0,128, +12,0,0,4,3,0,2,128,26,32,255,160,0,8,228,240, +0,0,255,128,5,0,0,3,3,0,1,128,3,0,85,128, +3,0,0,128,5,0,0,4,0,0,8,128,0,0,255,128, +26,32,170,160,0,8,228,240,2,0,0,3,0,0,8,128, +0,0,255,128,45,0,170,160,6,0,0,2,0,0,8,128, +0,0,255,128,4,0,0,4,0,0,8,128,3,0,0,128, +0,0,255,129,0,0,255,128,11,0,0,3,2,0,8,128, +2,0,255,128,45,0,85,160,32,0,0,3,3,0,1,128, +2,0,255,128,44,0,255,160,10,0,0,3,2,0,8,128, +3,0,0,128,45,0,170,160,5,0,0,3,2,0,7,128, +1,0,255,128,2,0,228,128,8,0,0,3,1,0,8,128, +1,0,228,144,2,0,228,128,8,0,0,4,2,0,1,128, +2,0,228,128,34,32,228,160,0,8,228,240,11,0,0,3, +2,0,1,128,2,0,0,128,45,0,85,160,2,0,0,4, +2,0,1,128,2,0,0,128,26,32,0,161,0,8,228,240, +5,0,0,4,2,0,1,128,2,0,0,128,26,32,85,160, +0,8,228,240,11,0,0,3,2,0,1,128,2,0,0,128, +45,0,85,160,10,0,0,3,2,0,1,128,2,0,0,128, +45,0,170,160,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,0,128,11,0,0,3,1,0,8,128,1,0,255,128, +45,0,85,160,12,0,0,3,2,0,1,128,45,0,85,160, +1,0,255,128,5,0,0,3,2,0,2,128,2,0,255,128, +0,0,255,128,5,0,0,4,2,0,14,128,2,0,85,128, +10,32,144,160,0,8,228,240,4,0,0,4,0,0,7,128, +2,0,0,128,2,0,249,128,0,0,228,128,5,0,0,3, +2,0,7,128,1,0,255,128,3,0,228,144,5,0,0,4, +2,0,7,128,2,0,228,128,10,32,228,160,0,8,228,240, +5,0,0,3,2,0,7,128,0,0,255,128,2,0,228,128, +10,0,0,3,2,0,7,128,2,0,228,128,45,0,170,160, +2,0,0,3,1,0,7,128,1,0,228,128,2,0,228,128, +29,0,0,0,1,0,0,2,1,0,7,224,0,0,228,128, +1,0,0,2,0,0,7,224,1,0,228,128,255,255,0,0, +83,72,68,82,188,5,0,0,64,0,240,255,111,1,0,0, +89,8,0,4,70,142,32,0,0,0,0,0,45,0,0,0, +95,0,0,3,114,16,16,0,0,0,0,0,95,0,0,3, +114,16,16,0,1,0,0,0,95,0,0,3,114,16,16,0, +2,0,0,0,95,0,0,3,114,16,16,0,3,0,0,0, +95,0,0,3,114,16,16,0,4,0,0,0,95,0,0,3, +114,16,16,0,5,0,0,0,101,0,0,3,114,32,16,0, +0,0,0,0,101,0,0,3,114,32,16,0,1,0,0,0, +104,0,0,2,4,0,0,0,54,0,0,5,114,0,16,0, +0,0,0,0,70,18,16,0,4,0,0,0,54,0,0,5, +114,0,16,0,1,0,0,0,70,18,16,0,5,0,0,0, +54,0,0,5,130,0,16,0,0,0,0,0,1,64,0,0, +0,0,0,0,48,0,0,1,33,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,0,0,0,0,1,64,0,0, +7,0,0,0,3,0,4,3,58,0,16,0,1,0,0,0, +50,0,0,16,114,0,16,0,2,0,0,0,70,18,16,128, +65,0,0,0,0,0,0,0,246,143,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,70,130,32,6, +0,0,0,0,18,0,0,0,58,0,16,0,0,0,0,0, +16,0,0,7,130,0,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,70,2,16,0,2,0,0,0,50,0,0,12, +130,0,16,0,2,0,0,0,42,128,32,6,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,58,0,16,0, +1,0,0,0,1,64,0,0,0,0,128,63,14,0,0,10, +130,0,16,0,2,0,0,0,2,64,0,0,0,0,128,63, +0,0,128,63,0,0,128,63,0,0,128,63,58,0,16,0, +2,0,0,0,57,0,0,10,18,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,58,128,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,49,0,0,10, +34,0,16,0,3,0,0,0,58,128,32,6,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,58,0,16,0, +1,0,0,0,1,0,0,7,18,0,16,0,3,0,0,0, +26,0,16,0,3,0,0,0,10,0,16,0,3,0,0,0, +55,0,0,9,130,0,16,0,2,0,0,0,10,0,16,0, +3,0,0,0,1,64,0,0,0,0,0,0,58,0,16,0, +2,0,0,0,68,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,56,0,0,7,114,0,16,0, +3,0,0,0,246,15,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,16,0,0,10,130,0,16,0,3,0,0,0, +70,2,16,0,3,0,0,0,70,130,32,6,0,0,0,0, +34,0,0,0,58,0,16,0,0,0,0,0,52,0,0,7, +130,0,16,0,3,0,0,0,58,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,0,0,0,11,130,0,16,0, +3,0,0,0,58,0,16,0,3,0,0,0,10,128,32,134, +65,0,0,0,0,0,0,0,26,0,0,0,58,0,16,0, +0,0,0,0,56,32,0,10,130,0,16,0,3,0,0,0, +58,0,16,0,3,0,0,0,26,128,32,6,0,0,0,0, +26,0,0,0,58,0,16,0,0,0,0,0,56,0,0,7, +130,0,16,0,2,0,0,0,58,0,16,0,2,0,0,0, +58,0,16,0,3,0,0,0,16,0,0,7,18,0,16,0, +3,0,0,0,70,18,16,0,1,0,0,0,70,2,16,0, +3,0,0,0,52,0,0,7,18,0,16,0,3,0,0,0, +10,0,16,0,3,0,0,0,1,64,0,0,0,0,0,0, +56,0,0,7,226,0,16,0,3,0,0,0,6,0,16,0, +3,0,0,0,6,25,16,0,3,0,0,0,56,0,0,10, +226,0,16,0,3,0,0,0,86,14,16,0,3,0,0,0, +6,137,32,6,0,0,0,0,10,0,0,0,58,0,16,0, +0,0,0,0,49,0,0,7,18,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,10,0,16,0,3,0,0,0, +31,0,4,3,10,0,16,0,3,0,0,0,50,0,0,9, +114,0,16,0,2,0,0,0,70,2,16,0,2,0,0,0, +246,15,16,0,1,0,0,0,70,18,16,0,2,0,0,0, +16,0,0,7,130,0,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,70,2,16,0,2,0,0,0,68,0,0,5, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +56,0,0,7,114,0,16,0,2,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,2,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,18,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,52,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,0,0,47,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,56,0,0,8,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,58,128,32,0, +0,0,0,0,44,0,0,0,25,0,0,5,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,51,0,0,7, +130,0,16,0,1,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,56,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,58,0,16,0, +2,0,0,0,50,0,0,12,114,0,16,0,0,0,0,0, +246,15,16,0,1,0,0,0,70,130,32,6,0,0,0,0, +10,0,0,0,58,0,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,21,0,0,1,56,0,0,7,114,0,16,0, +2,0,0,0,246,15,16,0,2,0,0,0,150,7,16,0, +3,0,0,0,51,0,0,10,114,0,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,2,64,0,0,0,0,128,63, +0,0,128,63,0,0,128,63,0,0,0,0,0,0,0,7, +114,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,30,0,0,7,130,0,16,0, +0,0,0,0,58,0,16,0,0,0,0,0,1,64,0,0, +1,0,0,0,22,0,0,1,54,0,0,5,114,32,16,0, +1,0,0,0,70,2,16,0,0,0,0,0,54,0,0,5, +114,32,16,0,0,0,0,0,70,2,16,0,1,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,48,0,0,0, +4,0,0,0,0,0,0,0,8,0,0,0,33,0,0,0, +2,0,0,0,1,0,0,0,1,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,5,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,188,4,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +142,4,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,86,101,114,116,101, +120,0,171,171,92,0,0,0,14,0,0,0,132,0,0,0, +240,3,0,0,0,0,0,0,0,0,0,0,180,2,0,0, +0,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,240,2,0,0,64,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,253,2,0,0, +128,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,3,0,0,144,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,71,3,0,0, +160,0,0,0,128,0,0,0,2,0,0,0,88,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,124,3,0,0,32,1,0,0,128,0,0,0, +2,0,0,0,140,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,176,3,0,0, +160,1,0,0,128,0,0,0,2,0,0,0,192,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,228,3,0,0,32,2,0,0,128,0,0,0, +2,0,0,0,244,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,24,4,0,0, +160,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,39,4,0,0,176,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,54,4,0,0, +192,2,0,0,16,0,0,0,2,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,66,4,0,0,208,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,82,4,0,0, +224,2,0,0,0,1,0,0,0,0,0,0,96,4,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,132,4,0,0,224,3,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,112,0,102,108,111,97,116,52, +120,52,0,171,3,0,3,0,4,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,0,102,102,95,118,101,99,95,99,111,108,111, +114,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,118,101,99,95,97,109,98,105,101,110,116,0,102, +102,95,108,105,103,104,116,95,99,111,108,111,114,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,112,111,115, +0,171,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,97,116,116,101,110,0,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,115,112,111,116,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,109,97,116,95,100,105,102,102,117,115,101,0,102, +102,95,109,97,116,95,97,109,98,105,101,110,116,0,102,102, +95,109,97,116,95,115,112,101,99,0,102,102,95,109,97,116, +95,101,109,105,115,115,105,111,110,0,102,102,95,109,97,116, +114,105,120,95,116,101,120,0,3,0,3,0,4,0,4,0, +4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,102, +111,103,95,118,115,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,168,1,0,0,7,0,0,0, +8,0,0,0,88,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,110,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,122,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,132,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,2,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,140,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,153,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +3,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,163,1,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,5,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,67,111,109,112,117,116,101,83,112,111,116,76, +105,103,104,116,83,112,101,99,55,0,101,121,101,80,111,115, +105,116,105,111,110,0,101,121,101,78,111,114,109,97,108,0, +118,105,101,119,68,105,114,0,100,105,102,102,117,115,101,67, +111,108,111,114,0,115,112,101,99,67,111,108,111,114,0,97, +109,98,0,171,76,73,66,70,28,24,0,0,68,88,66,67, +86,133,213,195,182,2,158,132,118,12,245,138,38,54,53,58, +1,0,0,0,28,24,0,0,5,0,0,0,52,0,0,0, +16,13,0,0,48,17,0,0,172,17,0,0,112,22,0,0, +65,111,110,57,212,12,0,0,212,12,0,0,0,2,86,76, +164,12,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,10,0, +32,0,0,0,0,0,0,0,0,2,86,76,81,0,0,5, +32,0,15,160,0,0,128,63,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,31,0,0,2, +5,0,3,128,3,0,15,144,31,0,0,2,5,0,4,128, +4,0,15,144,31,0,0,2,5,0,5,128,5,0,15,144, +5,0,0,3,0,0,1,128,8,0,255,160,8,0,255,160, +12,0,0,3,0,0,1,128,0,0,0,129,0,0,0,128, +4,0,0,4,0,0,14,128,0,0,144,144,8,0,255,161, +8,0,144,160,8,0,0,3,1,0,1,128,0,0,249,128, +0,0,249,128,12,0,0,3,1,0,2,128,16,0,255,160, +1,0,0,128,5,0,0,3,0,0,1,128,0,0,0,128, +1,0,85,128,1,0,0,2,2,0,1,128,32,0,0,160, +4,0,0,4,1,0,2,128,16,0,170,160,1,0,0,128, +2,0,0,128,7,0,0,2,1,0,1,128,1,0,0,128, +5,0,0,3,0,0,14,128,0,0,228,128,1,0,0,128, +6,0,0,2,1,0,1,128,1,0,85,128,4,0,0,4, +0,0,1,128,0,0,0,128,1,0,0,129,1,0,0,128, +8,0,0,3,1,0,1,128,0,0,249,128,24,0,228,160, +8,0,0,3,0,0,2,128,1,0,228,144,0,0,249,128, +11,0,0,3,0,0,2,128,0,0,85,128,32,0,85,160, +5,0,0,3,0,0,14,128,0,0,85,128,3,0,144,144, +5,0,0,3,0,0,14,128,0,0,228,128,0,0,144,160, +11,0,0,3,1,0,1,128,1,0,0,128,32,0,85,160, +2,0,0,3,1,0,1,128,1,0,0,128,16,0,0,161, +5,0,0,3,1,0,1,128,1,0,0,128,16,0,85,160, +11,0,0,3,1,0,1,128,1,0,0,128,32,0,85,160, +10,0,0,3,1,0,1,128,1,0,0,128,32,0,0,160, +5,0,0,3,0,0,1,128,0,0,0,128,1,0,0,128, +5,0,0,3,0,0,7,128,0,0,0,128,0,0,249,128, +10,0,0,3,0,0,7,128,0,0,228,128,32,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,5,0,228,144, +5,0,0,3,0,0,8,128,9,0,255,160,9,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,9,0,255,161, +9,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,17,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,2,128,17,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,85,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +25,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +32,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +1,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +17,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +17,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +32,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +32,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +32,0,0,160,2,0,0,3,0,0,7,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,8,128,10,0,255,160, +10,0,255,160,12,0,0,3,0,0,8,128,0,0,255,129, +0,0,255,128,4,0,0,4,1,0,7,128,0,0,228,144, +10,0,255,161,10,0,228,160,8,0,0,3,1,0,8,128, +1,0,228,128,1,0,228,128,12,0,0,3,2,0,2,128, +18,0,255,160,1,0,255,128,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,85,128,4,0,0,4,2,0,2,128, +18,0,170,160,1,0,255,128,2,0,0,128,7,0,0,2, +1,0,8,128,1,0,255,128,5,0,0,3,1,0,7,128, +1,0,255,128,1,0,228,128,6,0,0,2,1,0,8,128, +2,0,85,128,4,0,0,4,0,0,8,128,0,0,255,128, +1,0,255,129,1,0,255,128,8,0,0,3,1,0,8,128, +1,0,228,128,26,0,228,160,8,0,0,3,1,0,1,128, +1,0,228,144,1,0,228,128,11,0,0,3,1,0,9,128, +1,0,228,128,32,0,85,160,5,0,0,3,1,0,7,128, +1,0,0,128,3,0,228,144,5,0,0,3,1,0,7,128, +1,0,228,128,2,0,228,160,2,0,0,3,1,0,8,128, +1,0,255,128,18,0,0,161,5,0,0,3,1,0,8,128, +1,0,255,128,18,0,85,160,11,0,0,3,1,0,8,128, +1,0,255,128,32,0,85,160,10,0,0,3,1,0,8,128, +1,0,255,128,32,0,0,160,5,0,0,3,0,0,8,128, +0,0,255,128,1,0,255,128,5,0,0,3,1,0,7,128, +0,0,255,128,1,0,228,128,10,0,0,3,1,0,7,128, +1,0,228,128,32,0,0,160,2,0,0,3,0,0,7,128, +0,0,228,128,1,0,228,128,5,0,0,3,0,0,8,128, +11,0,255,160,11,0,255,160,12,0,0,3,0,0,8,128, +0,0,255,129,0,0,255,128,4,0,0,4,1,0,7,128, +0,0,228,144,11,0,255,161,11,0,228,160,8,0,0,3, +1,0,8,128,1,0,228,128,1,0,228,128,12,0,0,3, +2,0,2,128,19,0,255,160,1,0,255,128,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,85,128,4,0,0,4, +2,0,2,128,19,0,170,160,1,0,255,128,2,0,0,128, +7,0,0,2,1,0,8,128,1,0,255,128,5,0,0,3, +1,0,7,128,1,0,255,128,1,0,228,128,6,0,0,2, +1,0,8,128,2,0,85,128,4,0,0,4,0,0,8,128, +0,0,255,128,1,0,255,129,1,0,255,128,8,0,0,3, +1,0,8,128,1,0,228,128,27,0,228,160,8,0,0,3, +1,0,1,128,1,0,228,144,1,0,228,128,11,0,0,3, +1,0,9,128,1,0,228,128,32,0,85,160,5,0,0,3, +1,0,7,128,1,0,0,128,3,0,228,144,5,0,0,3, +1,0,7,128,1,0,228,128,3,0,228,160,2,0,0,3, +1,0,8,128,1,0,255,128,19,0,0,161,5,0,0,3, +1,0,8,128,1,0,255,128,19,0,85,160,11,0,0,3, +1,0,8,128,1,0,255,128,32,0,85,160,10,0,0,3, +1,0,8,128,1,0,255,128,32,0,0,160,5,0,0,3, +0,0,8,128,0,0,255,128,1,0,255,128,5,0,0,3, +1,0,7,128,0,0,255,128,1,0,228,128,10,0,0,3, +1,0,7,128,1,0,228,128,32,0,0,160,2,0,0,3, +0,0,7,128,0,0,228,128,1,0,228,128,5,0,0,3, +0,0,8,128,12,0,255,160,12,0,255,160,12,0,0,3, +0,0,8,128,0,0,255,129,0,0,255,128,4,0,0,4, +1,0,7,128,0,0,228,144,12,0,255,161,12,0,228,160, +8,0,0,3,1,0,8,128,1,0,228,128,1,0,228,128, +12,0,0,3,2,0,2,128,20,0,255,160,1,0,255,128, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,85,128, +4,0,0,4,2,0,2,128,20,0,170,160,1,0,255,128, +2,0,0,128,7,0,0,2,1,0,8,128,1,0,255,128, +5,0,0,3,1,0,7,128,1,0,255,128,1,0,228,128, +6,0,0,2,1,0,8,128,2,0,85,128,4,0,0,4, +0,0,8,128,0,0,255,128,1,0,255,129,1,0,255,128, +8,0,0,3,1,0,8,128,1,0,228,128,28,0,228,160, +8,0,0,3,1,0,1,128,1,0,228,144,1,0,228,128, +11,0,0,3,1,0,9,128,1,0,228,128,32,0,85,160, +5,0,0,3,1,0,7,128,1,0,0,128,3,0,228,144, +5,0,0,3,1,0,7,128,1,0,228,128,4,0,228,160, +2,0,0,3,1,0,8,128,1,0,255,128,20,0,0,161, +5,0,0,3,1,0,8,128,1,0,255,128,20,0,85,160, +11,0,0,3,1,0,8,128,1,0,255,128,32,0,85,160, +10,0,0,3,1,0,8,128,1,0,255,128,32,0,0,160, +5,0,0,3,0,0,8,128,0,0,255,128,1,0,255,128, +5,0,0,3,1,0,7,128,0,0,255,128,1,0,228,128, +10,0,0,3,1,0,7,128,1,0,228,128,32,0,0,160, +2,0,0,3,0,0,7,128,0,0,228,128,1,0,228,128, +5,0,0,3,0,0,8,128,13,0,255,160,13,0,255,160, +12,0,0,3,0,0,8,128,0,0,255,129,0,0,255,128, +4,0,0,4,1,0,7,128,0,0,228,144,13,0,255,161, +13,0,228,160,8,0,0,3,1,0,8,128,1,0,228,128, +1,0,228,128,12,0,0,3,2,0,2,128,21,0,255,160, +1,0,255,128,5,0,0,3,0,0,8,128,0,0,255,128, +2,0,85,128,4,0,0,4,2,0,2,128,21,0,170,160, +1,0,255,128,2,0,0,128,7,0,0,2,1,0,8,128, +1,0,255,128,5,0,0,3,1,0,7,128,1,0,255,128, +1,0,228,128,6,0,0,2,1,0,8,128,2,0,85,128, +4,0,0,4,0,0,8,128,0,0,255,128,1,0,255,129, +1,0,255,128,8,0,0,3,1,0,8,128,1,0,228,128, +29,0,228,160,8,0,0,3,1,0,1,128,1,0,228,144, +1,0,228,128,11,0,0,3,1,0,9,128,1,0,228,128, +32,0,85,160,5,0,0,3,1,0,7,128,1,0,0,128, +3,0,228,144,5,0,0,3,1,0,7,128,1,0,228,128, +5,0,228,160,2,0,0,3,1,0,8,128,1,0,255,128, +21,0,0,161,5,0,0,3,1,0,8,128,1,0,255,128, +21,0,85,160,11,0,0,3,1,0,8,128,1,0,255,128, +32,0,85,160,10,0,0,3,1,0,8,128,1,0,255,128, +32,0,0,160,5,0,0,3,0,0,8,128,0,0,255,128, +1,0,255,128,5,0,0,3,1,0,7,128,0,0,255,128, +1,0,228,128,10,0,0,3,1,0,7,128,1,0,228,128, +32,0,0,160,2,0,0,3,0,0,7,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,8,128,14,0,255,160, +14,0,255,160,12,0,0,3,0,0,8,128,0,0,255,129, +0,0,255,128,4,0,0,4,1,0,7,128,0,0,228,144, +14,0,255,161,14,0,228,160,8,0,0,3,1,0,8,128, +1,0,228,128,1,0,228,128,12,0,0,3,2,0,2,128, +22,0,255,160,1,0,255,128,5,0,0,3,0,0,8,128, +0,0,255,128,2,0,85,128,4,0,0,4,2,0,2,128, +22,0,170,160,1,0,255,128,2,0,0,128,7,0,0,2, +1,0,8,128,1,0,255,128,5,0,0,3,1,0,7,128, +1,0,255,128,1,0,228,128,6,0,0,2,1,0,8,128, +2,0,85,128,4,0,0,4,0,0,8,128,0,0,255,128, +1,0,255,129,1,0,255,128,8,0,0,3,1,0,8,128, +1,0,228,128,30,0,228,160,8,0,0,3,1,0,1,128, +1,0,228,144,1,0,228,128,11,0,0,3,1,0,9,128, +1,0,228,128,32,0,85,160,5,0,0,3,1,0,7,128, +1,0,0,128,3,0,228,144,5,0,0,3,1,0,7,128, +1,0,228,128,6,0,228,160,2,0,0,3,1,0,8,128, +1,0,255,128,22,0,0,161,5,0,0,3,1,0,8,128, +1,0,255,128,22,0,85,160,11,0,0,3,1,0,8,128, +1,0,255,128,32,0,85,160,10,0,0,3,1,0,8,128, +1,0,255,128,32,0,0,160,5,0,0,3,0,0,8,128, +0,0,255,128,1,0,255,128,5,0,0,3,1,0,7,128, +0,0,255,128,1,0,228,128,10,0,0,3,1,0,7,128, +1,0,228,128,32,0,0,160,2,0,0,3,0,0,7,128, +0,0,228,128,1,0,228,128,5,0,0,3,0,0,8,128, +15,0,255,160,15,0,255,160,12,0,0,3,0,0,8,128, +0,0,255,129,0,0,255,128,4,0,0,4,1,0,7,128, +0,0,228,144,15,0,255,161,15,0,228,160,8,0,0,3, +1,0,8,128,1,0,228,128,1,0,228,128,12,0,0,3, +2,0,2,128,23,0,255,160,1,0,255,128,5,0,0,3, +0,0,8,128,0,0,255,128,2,0,85,128,4,0,0,4, +2,0,1,128,23,0,170,160,1,0,255,128,2,0,0,128, +7,0,0,2,1,0,8,128,1,0,255,128,5,0,0,3, +1,0,7,128,1,0,255,128,1,0,228,128,6,0,0,2, +1,0,8,128,2,0,0,128,4,0,0,4,0,0,8,128, +0,0,255,128,1,0,255,129,1,0,255,128,8,0,0,3, +1,0,8,128,1,0,228,128,31,0,228,160,8,0,0,3, +1,0,1,128,1,0,228,144,1,0,228,128,11,0,0,3, +1,0,9,128,1,0,228,128,32,0,85,160,5,0,0,3, +1,0,7,128,1,0,0,128,3,0,228,144,5,0,0,3, +1,0,7,128,1,0,228,128,7,0,228,160,2,0,0,3, +1,0,8,128,1,0,255,128,23,0,0,161,5,0,0,3, +1,0,8,128,1,0,255,128,23,0,85,160,11,0,0,3, +1,0,8,128,1,0,255,128,32,0,85,160,10,0,0,3, +1,0,8,128,1,0,255,128,32,0,0,160,5,0,0,3, +0,0,8,128,0,0,255,128,1,0,255,128,5,0,0,3, +1,0,7,128,0,0,255,128,1,0,228,128,10,0,0,3, +1,0,7,128,1,0,228,128,32,0,0,160,2,0,0,3, +0,0,7,224,0,0,228,128,1,0,228,128,1,0,0,2, +1,0,7,224,4,0,228,144,255,255,0,0,83,72,68,82, +24,4,0,0,64,0,240,255,6,1,0,0,89,8,0,4, +70,142,32,0,0,0,0,0,42,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,95,0,0,3,114,16,16,0,3,0,0,0, +95,0,0,3,114,16,16,0,4,0,0,0,95,0,0,3, +114,16,16,0,5,0,0,0,101,0,0,3,114,32,16,0, +0,0,0,0,101,0,0,3,114,32,16,0,1,0,0,0, +104,0,0,2,3,0,0,0,54,0,0,5,114,0,16,0, +0,0,0,0,70,18,16,0,5,0,0,0,54,0,0,5, +130,0,16,0,0,0,0,0,1,64,0,0,0,0,0,0, +48,0,0,1,33,0,0,7,18,0,16,0,1,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,8,0,0,0, +3,0,4,3,10,0,16,0,1,0,0,0,50,0,0,16, +114,0,16,0,1,0,0,0,70,18,16,128,65,0,0,0, +0,0,0,0,246,143,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,70,130,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +70,2,16,0,1,0,0,0,50,0,0,12,18,0,16,0, +2,0,0,0,42,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,14,0,0,10,18,0,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,128,63,10,0,16,0,2,0,0,0, +57,0,0,10,34,0,16,0,2,0,0,0,1,64,0,0, +0,0,0,0,58,128,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,49,0,0,10,66,0,16,0, +2,0,0,0,58,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,0,0,7,34,0,16,0,2,0,0,0,42,0,16,0, +2,0,0,0,26,0,16,0,2,0,0,0,55,0,0,9, +18,0,16,0,2,0,0,0,26,0,16,0,2,0,0,0, +1,64,0,0,0,0,0,0,10,0,16,0,2,0,0,0, +68,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,7,114,0,16,0,1,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +16,0,0,10,130,0,16,0,1,0,0,0,70,2,16,0, +1,0,0,0,70,130,32,6,0,0,0,0,34,0,0,0, +58,0,16,0,0,0,0,0,52,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,0,0,0,0,0,11,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,10,128,32,134,65,0,0,0, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,32,0,10,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,26,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,10,0,16,0, +2,0,0,0,16,0,0,7,18,0,16,0,1,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +52,0,0,7,18,0,16,0,1,0,0,0,10,0,16,0, +1,0,0,0,1,64,0,0,0,0,0,0,56,0,0,7, +114,0,16,0,1,0,0,0,6,0,16,0,1,0,0,0, +70,18,16,0,3,0,0,0,56,0,0,10,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,130,32,6, +0,0,0,0,10,0,0,0,58,0,16,0,0,0,0,0, +56,0,0,7,114,0,16,0,1,0,0,0,246,15,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,51,0,0,10, +114,0,16,0,1,0,0,0,70,2,16,0,1,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,0,0,0,0,0,7,114,0,16,0,0,0,0,0, +70,2,16,0,0,0,0,0,70,2,16,0,1,0,0,0, +30,0,0,7,130,0,16,0,0,0,0,0,58,0,16,0, +0,0,0,0,1,64,0,0,1,0,0,0,22,0,0,1, +54,0,0,5,114,32,16,0,0,0,0,0,70,2,16,0, +0,0,0,0,54,0,0,5,114,32,16,0,1,0,0,0, +70,18,16,0,4,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,32,0,0,0,3,0,0,0,0,0,0,0, +7,0,0,0,20,0,0,0,2,0,0,0,1,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +4,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,188,4,0,0, +1,0,0,0,108,0,0,0,1,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,142,4,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,92,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,85,110,105,116, +121,70,70,86,101,114,116,101,120,0,171,171,92,0,0,0, +14,0,0,0,132,0,0,0,240,3,0,0,0,0,0,0, +0,0,0,0,180,2,0,0,0,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,240,2,0,0, +64,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,253,2,0,0,128,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,56,3,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,71,3,0,0,160,0,0,0,128,0,0,0, +2,0,0,0,88,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,124,3,0,0, +32,1,0,0,128,0,0,0,2,0,0,0,140,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,176,3,0,0,160,1,0,0,128,0,0,0, +2,0,0,0,192,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,228,3,0,0, +32,2,0,0,128,0,0,0,2,0,0,0,244,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,24,4,0,0,160,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,39,4,0,0, +176,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,54,4,0,0,192,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,66,4,0,0, +208,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,82,4,0,0,224,2,0,0,0,1,0,0, +0,0,0,0,96,4,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,132,4,0,0, +224,3,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +112,0,102,108,111,97,116,52,120,52,0,171,3,0,3,0, +4,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,0,102,102,95, +118,101,99,95,99,111,108,111,114,0,102,108,111,97,116,52, +0,171,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,118,101,99,95,97, +109,98,105,101,110,116,0,102,102,95,108,105,103,104,116,95, +99,111,108,111,114,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,112,111,115,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,97,116,116,101,110,0,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,115,112,111, +116,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,109,97,116,95,100, +105,102,102,117,115,101,0,102,102,95,109,97,116,95,97,109, +98,105,101,110,116,0,102,102,95,109,97,116,95,115,112,101, +99,0,102,102,95,109,97,116,95,101,109,105,115,115,105,111, +110,0,102,102,95,109,97,116,114,105,120,95,116,101,120,0, +3,0,3,0,4,0,4,0,4,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,102,111,103,95,118,115,0,77,105, +99,114,111,115,111,102,116,32,40,82,41,32,72,76,83,76, +32,83,104,97,100,101,114,32,67,111,109,112,105,108,101,114, +32,54,46,51,46,57,52,49,53,46,48,0,76,70,83,48, +164,1,0,0,7,0,0,0,8,0,0,0,88,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,106,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,118,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,128,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,136,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,149,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,159,1,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,56,0,101,121, +101,80,111,115,105,116,105,111,110,0,101,121,101,78,111,114, +109,97,108,0,118,105,101,119,68,105,114,0,100,105,102,102, +117,115,101,67,111,108,111,114,0,115,112,101,99,67,111,108, +111,114,0,97,109,98,0,171,76,73,66,70,80,16,0,0, +68,88,66,67,235,115,185,156,43,13,47,75,143,138,114,228, +61,12,79,253,1,0,0,0,80,16,0,0,5,0,0,0, +52,0,0,0,156,3,0,0,96,9,0,0,220,9,0,0, +160,14,0,0,65,111,110,57,96,3,0,0,96,3,0,0, +0,2,86,76,48,3,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +0,0,0,0,45,0,0,0,0,0,0,0,0,2,86,76, +81,0,0,5,45,0,15,160,0,0,0,0,0,0,0,0, +0,0,128,63,0,0,0,0,48,0,0,5,0,0,15,240, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,2,128, +2,0,15,144,31,0,0,2,5,0,3,128,3,0,15,144, +31,0,0,2,5,0,4,128,4,0,15,144,31,0,0,2, +5,0,5,128,5,0,15,144,1,0,0,2,0,0,7,128, +4,0,228,144,1,0,0,2,1,0,7,128,5,0,228,144, +27,0,0,2,0,8,228,240,0,0,228,240,4,0,0,6, +2,0,7,128,0,0,228,144,18,32,255,161,0,8,228,240, +18,32,228,160,0,8,228,240,8,0,0,3,0,0,8,128, +2,0,228,128,2,0,228,128,7,0,0,2,1,0,8,128, +0,0,255,128,4,0,0,4,3,0,7,128,2,0,228,128, +1,0,255,128,2,0,228,144,36,0,0,2,4,0,7,128, +3,0,228,128,8,0,0,3,2,0,8,128,1,0,228,144, +4,0,228,128,5,0,0,5,3,0,1,128,18,32,255,160, +0,8,228,240,18,32,255,160,0,8,228,240,12,0,0,3, +3,0,1,128,3,0,0,129,3,0,0,128,12,0,0,4, +3,0,2,128,26,32,255,160,0,8,228,240,0,0,255,128, +5,0,0,3,3,0,1,128,3,0,85,128,3,0,0,128, +5,0,0,4,0,0,8,128,0,0,255,128,26,32,170,160, +0,8,228,240,2,0,0,3,0,0,8,128,0,0,255,128, +45,0,170,160,6,0,0,2,0,0,8,128,0,0,255,128, +4,0,0,4,0,0,8,128,3,0,0,128,0,0,255,129, +0,0,255,128,11,0,0,3,2,0,8,128,2,0,255,128, +45,0,85,160,32,0,0,3,3,0,1,128,2,0,255,128, +44,0,255,160,10,0,0,3,2,0,8,128,3,0,0,128, +45,0,170,160,5,0,0,3,2,0,7,128,1,0,255,128, +2,0,228,128,8,0,0,3,1,0,8,128,1,0,228,144, +2,0,228,128,8,0,0,4,2,0,1,128,2,0,228,128, +34,32,228,160,0,8,228,240,11,0,0,3,2,0,1,128, +2,0,0,128,45,0,85,160,2,0,0,4,2,0,1,128, +2,0,0,128,26,32,0,161,0,8,228,240,5,0,0,4, +2,0,1,128,2,0,0,128,26,32,85,160,0,8,228,240, +11,0,0,3,2,0,1,128,2,0,0,128,45,0,85,160, +10,0,0,3,2,0,1,128,2,0,0,128,45,0,170,160, +5,0,0,3,0,0,8,128,0,0,255,128,2,0,0,128, +11,0,0,3,1,0,8,128,1,0,255,128,45,0,85,160, +12,0,0,3,2,0,1,128,45,0,85,160,1,0,255,128, +5,0,0,3,2,0,2,128,2,0,255,128,0,0,255,128, +5,0,0,4,2,0,14,128,2,0,85,128,10,32,144,160, +0,8,228,240,4,0,0,4,0,0,7,128,2,0,0,128, +2,0,249,128,0,0,228,128,5,0,0,3,2,0,7,128, +1,0,255,128,3,0,228,144,5,0,0,4,2,0,7,128, +2,0,228,128,10,32,228,160,0,8,228,240,5,0,0,3, +2,0,7,128,0,0,255,128,2,0,228,128,10,0,0,3, +2,0,7,128,2,0,228,128,45,0,170,160,2,0,0,3, +1,0,7,128,1,0,228,128,2,0,228,128,29,0,0,0, +1,0,0,2,1,0,7,224,0,0,228,128,1,0,0,2, +0,0,7,224,1,0,228,128,255,255,0,0,83,72,68,82, +188,5,0,0,64,0,240,255,111,1,0,0,89,8,0,4, +70,142,32,0,0,0,0,0,45,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,95,0,0,3,114,16,16,0,2,0,0,0, +95,0,0,3,114,16,16,0,3,0,0,0,95,0,0,3, +114,16,16,0,4,0,0,0,95,0,0,3,114,16,16,0, +5,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,1,0,0,0,104,0,0,2, +4,0,0,0,54,0,0,5,114,0,16,0,0,0,0,0, +70,18,16,0,4,0,0,0,54,0,0,5,114,0,16,0, +1,0,0,0,70,18,16,0,5,0,0,0,54,0,0,5, +130,0,16,0,0,0,0,0,1,64,0,0,0,0,0,0, +48,0,0,1,33,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,8,0,0,0, +3,0,4,3,58,0,16,0,1,0,0,0,50,0,0,16, +114,0,16,0,2,0,0,0,70,18,16,128,65,0,0,0, +0,0,0,0,246,143,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,70,130,32,6,0,0,0,0, +18,0,0,0,58,0,16,0,0,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,50,0,0,12,130,0,16,0, +2,0,0,0,42,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,64,0,0,0,0,128,63,14,0,0,10,130,0,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,128,63,58,0,16,0,2,0,0,0, +57,0,0,10,18,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,58,128,32,6,0,0,0,0,18,0,0,0, +58,0,16,0,0,0,0,0,49,0,0,10,34,0,16,0, +3,0,0,0,58,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,58,0,16,0,1,0,0,0, +1,0,0,7,18,0,16,0,3,0,0,0,26,0,16,0, +3,0,0,0,10,0,16,0,3,0,0,0,55,0,0,9, +130,0,16,0,2,0,0,0,10,0,16,0,3,0,0,0, +1,64,0,0,0,0,0,0,58,0,16,0,2,0,0,0, +68,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,7,114,0,16,0,3,0,0,0, +246,15,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +16,0,0,10,130,0,16,0,3,0,0,0,70,2,16,0, +3,0,0,0,70,130,32,6,0,0,0,0,34,0,0,0, +58,0,16,0,0,0,0,0,52,0,0,7,130,0,16,0, +3,0,0,0,58,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,0,0,0,11,130,0,16,0,3,0,0,0, +58,0,16,0,3,0,0,0,10,128,32,134,65,0,0,0, +0,0,0,0,26,0,0,0,58,0,16,0,0,0,0,0, +56,32,0,10,130,0,16,0,3,0,0,0,58,0,16,0, +3,0,0,0,26,128,32,6,0,0,0,0,26,0,0,0, +58,0,16,0,0,0,0,0,56,0,0,7,130,0,16,0, +2,0,0,0,58,0,16,0,2,0,0,0,58,0,16,0, +3,0,0,0,16,0,0,7,18,0,16,0,3,0,0,0, +70,18,16,0,1,0,0,0,70,2,16,0,3,0,0,0, +52,0,0,7,18,0,16,0,3,0,0,0,10,0,16,0, +3,0,0,0,1,64,0,0,0,0,0,0,56,0,0,7, +226,0,16,0,3,0,0,0,6,0,16,0,3,0,0,0, +6,25,16,0,3,0,0,0,56,0,0,10,226,0,16,0, +3,0,0,0,86,14,16,0,3,0,0,0,6,137,32,6, +0,0,0,0,10,0,0,0,58,0,16,0,0,0,0,0, +49,0,0,7,18,0,16,0,3,0,0,0,1,64,0,0, +0,0,0,0,10,0,16,0,3,0,0,0,31,0,4,3, +10,0,16,0,3,0,0,0,50,0,0,9,114,0,16,0, +2,0,0,0,70,2,16,0,2,0,0,0,246,15,16,0, +1,0,0,0,70,18,16,0,2,0,0,0,16,0,0,7, +130,0,16,0,1,0,0,0,70,2,16,0,2,0,0,0, +70,2,16,0,2,0,0,0,68,0,0,5,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,56,0,0,7, +114,0,16,0,2,0,0,0,246,15,16,0,1,0,0,0, +70,2,16,0,2,0,0,0,16,0,0,7,130,0,16,0, +1,0,0,0,70,18,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,52,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,1,64,0,0,0,0,0,0, +47,0,0,5,130,0,16,0,1,0,0,0,58,0,16,0, +1,0,0,0,56,0,0,8,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,58,128,32,0,0,0,0,0, +44,0,0,0,25,0,0,5,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,51,0,0,7,130,0,16,0, +1,0,0,0,58,0,16,0,1,0,0,0,1,64,0,0, +0,0,128,63,56,0,0,7,130,0,16,0,1,0,0,0, +58,0,16,0,1,0,0,0,58,0,16,0,2,0,0,0, +50,0,0,12,114,0,16,0,0,0,0,0,246,15,16,0, +1,0,0,0,70,130,32,6,0,0,0,0,10,0,0,0, +58,0,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +21,0,0,1,56,0,0,7,114,0,16,0,2,0,0,0, +246,15,16,0,2,0,0,0,150,7,16,0,3,0,0,0, +51,0,0,10,114,0,16,0,2,0,0,0,70,2,16,0, +2,0,0,0,2,64,0,0,0,0,128,63,0,0,128,63, +0,0,128,63,0,0,0,0,0,0,0,7,114,0,16,0, +1,0,0,0,70,2,16,0,1,0,0,0,70,2,16,0, +2,0,0,0,30,0,0,7,130,0,16,0,0,0,0,0, +58,0,16,0,0,0,0,0,1,64,0,0,1,0,0,0, +22,0,0,1,54,0,0,5,114,32,16,0,1,0,0,0, +70,2,16,0,0,0,0,0,54,0,0,5,114,32,16,0, +0,0,0,0,70,2,16,0,1,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,48,0,0,0,4,0,0,0, +0,0,0,0,8,0,0,0,33,0,0,0,2,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,5,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,2,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,2,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,2,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,2,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,2,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,0,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,168,1,0,0,7,0,0,0,8,0,0,0, +88,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +110,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +122,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +132,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +2,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +140,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +3,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +153,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,3,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +163,1,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +5,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +67,111,109,112,117,116,101,83,112,111,116,76,105,103,104,116, +83,112,101,99,56,0,101,121,101,80,111,115,105,116,105,111, +110,0,101,121,101,78,111,114,109,97,108,0,118,105,101,119, +68,105,114,0,100,105,102,102,117,115,101,67,111,108,111,114, +0,115,112,101,99,67,111,108,111,114,0,97,109,98,0,171, +76,73,66,70,32,3,0,0,68,88,66,67,131,242,33,177, +67,199,181,81,188,12,223,170,153,36,248,104,1,0,0,0, +32,3,0,0,6,0,0,0,56,0,0,0,156,0,0,0, +12,1,0,0,108,1,0,0,232,1,0,0,92,2,0,0, +65,111,110,57,92,0,0,0,92,0,0,0,0,2,86,76, +56,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,1,0,0,2,0,0,7,224, +0,0,228,144,1,0,0,2,0,0,8,224,1,0,255,144, +255,255,0,0,65,111,110,57,104,0,0,0,104,0,0,0, +0,2,80,76,68,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,7,176, +31,0,0,2,0,0,0,128,1,0,8,176,1,0,0,2, +0,0,7,128,0,0,228,176,1,0,0,2,0,0,8,128, +1,0,255,176,1,0,0,2,0,0,15,224,0,0,228,128, +255,255,0,0,83,72,68,82,88,0,0,0,64,0,240,255, +22,0,0,0,95,0,0,3,114,16,16,0,0,0,0,0, +95,0,0,3,130,16,16,0,1,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,54,0,0,5,114,32,16,0, +0,0,0,0,70,18,16,0,0,0,0,0,54,0,0,5, +130,32,16,0,0,0,0,0,58,16,16,0,1,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,3,0,0,0, +0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,188,0,0,0,3,0,0,0, +8,0,0,0,152,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,170,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,177,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,76,105,103,104,116,105,110,103, +67,111,108,111,114,0,108,99,111,108,111,114,0,100,105,102, +102,99,111,108,111,114,0,171,76,73,66,70,24,8,0,0, +68,88,66,67,172,130,85,234,66,7,19,66,150,202,205,16, +164,226,78,167,1,0,0,0,24,8,0,0,6,0,0,0, +56,0,0,0,208,0,0,0,116,1,0,0,80,2,0,0, +204,2,0,0,144,7,0,0,65,111,110,57,144,0,0,0, +144,0,0,0,0,2,86,76,96,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,0,0,4,0,0,0,0,0,0,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +5,0,0,3,0,0,15,128,0,0,85,144,1,0,228,160, +4,0,0,4,0,0,15,128,0,0,228,160,0,0,0,144, +0,0,228,128,4,0,0,4,0,0,15,128,2,0,228,160, +0,0,170,144,0,0,228,128,4,0,0,4,0,0,15,224, +3,0,228,160,0,0,255,144,0,0,228,128,255,255,0,0, +65,111,110,57,156,0,0,0,156,0,0,0,0,2,80,76, +108,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,0,0, +4,0,0,0,0,0,0,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,5,0,0,3,0,0,15,128, +0,0,85,176,1,0,228,160,4,0,0,4,0,0,15,128, +0,0,228,160,0,0,0,176,0,0,228,128,4,0,0,4, +0,0,15,128,2,0,228,160,0,0,170,176,0,0,228,128, +4,0,0,4,0,0,15,128,3,0,228,160,0,0,255,176, +0,0,228,128,1,0,0,2,0,0,15,224,0,0,228,128, +255,255,0,0,83,72,68,82,212,0,0,0,64,0,240,255, +53,0,0,0,89,0,0,4,70,142,32,0,0,0,0,0, +4,0,0,0,95,0,0,3,242,16,16,0,0,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,104,0,0,2, +1,0,0,0,56,0,0,8,242,0,16,0,0,0,0,0, +86,21,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +1,0,0,0,50,0,0,10,242,0,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,0,0,0,0,6,16,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,50,0,0,10, +242,0,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +2,0,0,0,166,26,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,50,0,0,10,242,32,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,3,0,0,0,246,31,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,5,0,0,0,1,0,0,0, +0,0,0,0,2,0,0,0,4,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,2,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,0,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,0,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,0,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,0,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,0,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,128,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +120,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +84,114,97,110,115,102,111,114,109,86,101,114,116,101,120,0, +118,101,114,116,101,120,0,171,76,73,66,70,180,2,0,0, +68,88,66,67,62,110,178,176,113,161,39,113,135,74,135,255, +184,2,122,27,1,0,0,0,180,2,0,0,6,0,0,0, +56,0,0,0,176,0,0,0,8,1,0,0,72,1,0,0, +196,1,0,0,56,2,0,0,65,111,110,57,112,0,0,0, +112,0,0,0,0,2,86,76,76,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,81,0,0,5,0,0,15,160, +0,0,0,0,0,0,128,63,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,11,0,0,3, +0,0,15,128,0,0,228,144,0,0,0,160,10,0,0,3, +0,0,15,224,0,0,228,128,0,0,85,160,255,255,0,0, +65,111,110,57,80,0,0,0,80,0,0,0,0,2,80,76, +44,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,80,76, +31,0,0,2,0,0,0,128,0,0,15,176,1,0,0,2, +0,0,31,128,0,0,228,176,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,56,0,0,0, +64,0,240,255,14,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +54,32,0,5,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,116,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,114,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,83,97,116,117,114,97,116,101, +52,0,99,0,76,73,66,70,180,2,0,0,68,88,66,67, +240,200,99,27,197,129,185,234,49,50,47,69,172,40,172,184, +1,0,0,0,180,2,0,0,6,0,0,0,56,0,0,0, +176,0,0,0,8,1,0,0,72,1,0,0,196,1,0,0, +56,2,0,0,65,111,110,57,112,0,0,0,112,0,0,0, +0,2,86,76,76,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,81,0,0,5,0,0,15,160,0,0,0,0, +0,0,128,63,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,11,0,0,3,0,0,7,128, +0,0,228,144,0,0,0,160,10,0,0,3,0,0,7,224, +0,0,228,128,0,0,85,160,255,255,0,0,65,111,110,57, +80,0,0,0,80,0,0,0,0,2,80,76,44,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,7,176,1,0,0,2,0,0,23,128, +0,0,228,176,1,0,0,2,0,0,7,224,0,0,228,128, +255,255,0,0,83,72,68,82,56,0,0,0,64,0,240,255, +14,0,0,0,95,0,0,3,114,16,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,0,0,0,0,54,32,0,5, +114,32,16,0,0,0,0,0,70,18,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,114,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,83,97,116,117,114,97,116,101,51,0,99,0, +76,73,66,70,120,2,0,0,68,88,66,67,138,49,223,44, +107,242,58,167,5,75,190,32,216,167,145,36,1,0,0,0, +120,2,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,16,1,0,0,140,1,0,0,0,2,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +32,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +31,0,0,2,5,0,0,128,0,0,15,144,1,0,0,2, +0,0,7,224,0,0,228,144,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,32,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,7,176,1,0,0,2,0,0,7,224, +0,0,228,176,255,255,0,0,83,72,68,82,56,0,0,0, +64,0,240,255,14,0,0,0,95,0,0,3,114,16,16,0, +0,0,0,0,101,0,0,3,114,32,16,0,0,0,0,0, +54,0,0,5,114,32,16,0,0,0,0,0,70,18,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,112,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,110,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,76,111,97,100,51,0,99,0, +76,73,66,70,24,7,0,0,68,88,66,67,113,18,103,154, +83,56,52,120,187,13,106,3,58,124,196,9,1,0,0,0, +24,7,0,0,6,0,0,0,56,0,0,0,148,0,0,0, +252,0,0,0,88,1,0,0,212,1,0,0,152,6,0,0, +65,111,110,57,84,0,0,0,84,0,0,0,0,2,86,76, +36,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,44,0, +1,0,0,0,0,0,0,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,5,0,0,3,0,0,7,224, +0,0,228,144,0,0,228,160,255,255,0,0,65,111,110,57, +96,0,0,0,96,0,0,0,0,2,80,76,48,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,0,0,44,0,1,0,0,0, +0,0,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,5,0,0,3,0,0,7,128,0,0,228,176, +0,0,228,160,1,0,0,2,0,0,7,224,0,0,228,128, +255,255,0,0,83,72,68,82,84,0,0,0,64,0,240,255, +21,0,0,0,89,0,0,4,70,142,32,0,0,0,0,0, +45,0,0,0,95,0,0,3,114,16,16,0,0,0,0,0, +101,0,0,3,114,32,16,0,0,0,0,0,56,0,0,8, +114,32,16,0,0,0,0,0,70,18,16,0,0,0,0,0, +70,130,32,0,0,0,0,0,44,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,2,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,0,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,0,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,0,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,0,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,2,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,0,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,120,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +117,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,3,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +77,111,100,117,108,97,116,101,83,112,101,99,0,99,0,171, +76,73,66,70,16,8,0,0,68,88,66,67,38,168,251,188, +91,77,207,32,129,166,165,241,221,147,229,117,1,0,0,0, +16,8,0,0,6,0,0,0,56,0,0,0,208,0,0,0, +116,1,0,0,80,2,0,0,204,2,0,0,144,7,0,0, +65,111,110,57,144,0,0,0,144,0,0,0,0,2,86,76, +96,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,46,0, +4,0,0,0,0,0,0,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,5,0,0,3,0,0,15,128, +0,0,85,144,1,0,228,160,4,0,0,4,0,0,15,128, +0,0,228,160,0,0,0,144,0,0,228,128,4,0,0,4, +0,0,15,128,2,0,228,160,0,0,170,144,0,0,228,128, +4,0,0,4,0,0,15,224,3,0,228,160,0,0,255,144, +0,0,228,128,255,255,0,0,65,111,110,57,156,0,0,0, +156,0,0,0,0,2,80,76,108,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,46,0,4,0,0,0,0,0,0,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,15,176, +5,0,0,3,0,0,15,128,0,0,85,176,1,0,228,160, +4,0,0,4,0,0,15,128,0,0,228,160,0,0,0,176, +0,0,228,128,4,0,0,4,0,0,15,128,2,0,228,160, +0,0,170,176,0,0,228,128,4,0,0,4,0,0,15,128, +3,0,228,160,0,0,255,176,0,0,228,128,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +212,0,0,0,64,0,240,255,53,0,0,0,89,0,0,4, +70,142,32,0,0,0,0,0,50,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,104,0,0,2,1,0,0,0,56,0,0,8, +242,0,16,0,0,0,0,0,86,21,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,47,0,0,0,50,0,0,10, +242,0,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +46,0,0,0,6,16,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,50,0,0,10,242,0,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,48,0,0,0,166,26,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,50,0,0,10, +242,32,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +49,0,0,0,246,31,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +5,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0, +4,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,0,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,0,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,0,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,0,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,2,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,120,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,116,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,77,117,108,116,105,112,108,121, +85,86,48,0,117,118,0,171,76,73,66,70,16,8,0,0, +68,88,66,67,89,231,147,186,246,126,177,127,29,163,1,103, +12,212,226,6,1,0,0,0,16,8,0,0,6,0,0,0, +56,0,0,0,208,0,0,0,116,1,0,0,80,2,0,0, +204,2,0,0,144,7,0,0,65,111,110,57,144,0,0,0, +144,0,0,0,0,2,86,76,96,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,50,0,4,0,0,0,0,0,0,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +5,0,0,3,0,0,15,128,0,0,85,144,1,0,228,160, +4,0,0,4,0,0,15,128,0,0,228,160,0,0,0,144, +0,0,228,128,4,0,0,4,0,0,15,128,2,0,228,160, +0,0,170,144,0,0,228,128,4,0,0,4,0,0,15,224, +3,0,228,160,0,0,255,144,0,0,228,128,255,255,0,0, +65,111,110,57,156,0,0,0,156,0,0,0,0,2,80,76, +108,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,50,0, +4,0,0,0,0,0,0,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,5,0,0,3,0,0,15,128, +0,0,85,176,1,0,228,160,4,0,0,4,0,0,15,128, +0,0,228,160,0,0,0,176,0,0,228,128,4,0,0,4, +0,0,15,128,2,0,228,160,0,0,170,176,0,0,228,128, +4,0,0,4,0,0,15,128,3,0,228,160,0,0,255,176, +0,0,228,128,1,0,0,2,0,0,15,224,0,0,228,128, +255,255,0,0,83,72,68,82,212,0,0,0,64,0,240,255, +53,0,0,0,89,0,0,4,70,142,32,0,0,0,0,0, +54,0,0,0,95,0,0,3,242,16,16,0,0,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,104,0,0,2, +1,0,0,0,56,0,0,8,242,0,16,0,0,0,0,0, +86,21,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +51,0,0,0,50,0,0,10,242,0,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,50,0,0,0,6,16,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,50,0,0,10, +242,0,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +52,0,0,0,166,26,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,50,0,0,10,242,32,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,53,0,0,0,246,31,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,5,0,0,0,1,0,0,0, +0,0,0,0,2,0,0,0,4,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,0,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,0,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,0,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,0,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,2,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,120,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +116,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +77,117,108,116,105,112,108,121,85,86,49,0,117,118,0,171, +76,73,66,70,16,8,0,0,68,88,66,67,41,244,254,181, +196,180,14,116,129,203,162,222,199,240,214,248,1,0,0,0, +16,8,0,0,6,0,0,0,56,0,0,0,208,0,0,0, +116,1,0,0,80,2,0,0,204,2,0,0,144,7,0,0, +65,111,110,57,144,0,0,0,144,0,0,0,0,2,86,76, +96,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,54,0, +4,0,0,0,0,0,0,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,5,0,0,3,0,0,15,128, +0,0,85,144,1,0,228,160,4,0,0,4,0,0,15,128, +0,0,228,160,0,0,0,144,0,0,228,128,4,0,0,4, +0,0,15,128,2,0,228,160,0,0,170,144,0,0,228,128, +4,0,0,4,0,0,15,224,3,0,228,160,0,0,255,144, +0,0,228,128,255,255,0,0,65,111,110,57,156,0,0,0, +156,0,0,0,0,2,80,76,108,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,54,0,4,0,0,0,0,0,0,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,15,176, +5,0,0,3,0,0,15,128,0,0,85,176,1,0,228,160, +4,0,0,4,0,0,15,128,0,0,228,160,0,0,0,176, +0,0,228,128,4,0,0,4,0,0,15,128,2,0,228,160, +0,0,170,176,0,0,228,128,4,0,0,4,0,0,15,128, +3,0,228,160,0,0,255,176,0,0,228,128,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +212,0,0,0,64,0,240,255,53,0,0,0,89,0,0,4, +70,142,32,0,0,0,0,0,58,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,104,0,0,2,1,0,0,0,56,0,0,8, +242,0,16,0,0,0,0,0,86,21,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,55,0,0,0,50,0,0,10, +242,0,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +54,0,0,0,6,16,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,50,0,0,10,242,0,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,56,0,0,0,166,26,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,50,0,0,10, +242,32,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +57,0,0,0,246,31,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +5,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0, +4,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,0,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,0,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,0,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,0,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,2,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,120,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,116,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,77,117,108,116,105,112,108,121, +85,86,50,0,117,118,0,171,76,73,66,70,16,8,0,0, +68,88,66,67,79,24,223,202,176,61,38,187,194,246,39,54, +93,187,78,10,1,0,0,0,16,8,0,0,6,0,0,0, +56,0,0,0,208,0,0,0,116,1,0,0,80,2,0,0, +204,2,0,0,144,7,0,0,65,111,110,57,144,0,0,0, +144,0,0,0,0,2,86,76,96,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,58,0,4,0,0,0,0,0,0,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +5,0,0,3,0,0,15,128,0,0,85,144,1,0,228,160, +4,0,0,4,0,0,15,128,0,0,228,160,0,0,0,144, +0,0,228,128,4,0,0,4,0,0,15,128,2,0,228,160, +0,0,170,144,0,0,228,128,4,0,0,4,0,0,15,224, +3,0,228,160,0,0,255,144,0,0,228,128,255,255,0,0, +65,111,110,57,156,0,0,0,156,0,0,0,0,2,80,76, +108,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,58,0, +4,0,0,0,0,0,0,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,5,0,0,3,0,0,15,128, +0,0,85,176,1,0,228,160,4,0,0,4,0,0,15,128, +0,0,228,160,0,0,0,176,0,0,228,128,4,0,0,4, +0,0,15,128,2,0,228,160,0,0,170,176,0,0,228,128, +4,0,0,4,0,0,15,128,3,0,228,160,0,0,255,176, +0,0,228,128,1,0,0,2,0,0,15,224,0,0,228,128, +255,255,0,0,83,72,68,82,212,0,0,0,64,0,240,255, +53,0,0,0,89,0,0,4,70,142,32,0,0,0,0,0, +62,0,0,0,95,0,0,3,242,16,16,0,0,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,104,0,0,2, +1,0,0,0,56,0,0,8,242,0,16,0,0,0,0,0, +86,21,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +59,0,0,0,50,0,0,10,242,0,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,58,0,0,0,6,16,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,50,0,0,10, +242,0,16,0,0,0,0,0,70,142,32,0,0,0,0,0, +60,0,0,0,166,26,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,50,0,0,10,242,32,16,0,0,0,0,0, +70,142,32,0,0,0,0,0,61,0,0,0,246,31,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,5,0,0,0,1,0,0,0, +0,0,0,0,2,0,0,0,4,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +188,4,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,142,4,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,86,101,114,116,101,120,0,171,171, +92,0,0,0,14,0,0,0,132,0,0,0,240,3,0,0, +0,0,0,0,0,0,0,0,180,2,0,0,0,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +240,2,0,0,64,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,253,2,0,0,128,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,3,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,71,3,0,0,160,0,0,0, +128,0,0,0,0,0,0,0,88,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +124,3,0,0,32,1,0,0,128,0,0,0,0,0,0,0, +140,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,176,3,0,0,160,1,0,0, +128,0,0,0,0,0,0,0,192,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +228,3,0,0,32,2,0,0,128,0,0,0,0,0,0,0, +244,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,24,4,0,0,160,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +39,4,0,0,176,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,54,4,0,0,192,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +66,4,0,0,208,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,82,4,0,0,224,2,0,0, +0,1,0,0,2,0,0,0,96,4,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +132,4,0,0,224,3,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,112,0,102,108,111,97,116,52,120,52,0,171, +3,0,3,0,4,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +194,2,0,0,102,102,95,109,97,116,114,105,120,95,109,118, +0,102,102,95,118,101,99,95,99,111,108,111,114,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,118, +101,99,95,97,109,98,105,101,110,116,0,102,102,95,108,105, +103,104,116,95,99,111,108,111,114,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,112,111,115,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,97,116,116, +101,110,0,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,115,112,111,116,0,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,109, +97,116,95,100,105,102,102,117,115,101,0,102,102,95,109,97, +116,95,97,109,98,105,101,110,116,0,102,102,95,109,97,116, +95,115,112,101,99,0,102,102,95,109,97,116,95,101,109,105, +115,115,105,111,110,0,102,102,95,109,97,116,114,105,120,95, +116,101,120,0,3,0,3,0,4,0,4,0,4,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,102,111,103,95,118, +115,0,77,105,99,114,111,115,111,102,116,32,40,82,41,32, +72,76,83,76,32,83,104,97,100,101,114,32,67,111,109,112, +105,108,101,114,32,54,46,51,46,57,52,49,53,46,48,0, +76,70,83,48,120,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +116,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +77,117,108,116,105,112,108,121,85,86,51,0,117,118,0,171, +76,73,66,70,128,2,0,0,68,88,66,67,70,241,160,65, +61,184,241,235,1,168,145,104,13,89,175,213,1,0,0,0, +128,2,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,16,1,0,0,140,1,0,0,0,2,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +32,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +31,0,0,2,5,0,0,128,0,0,15,144,1,0,0,2, +0,0,15,224,0,0,228,144,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,32,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,1,0,0,2,0,0,15,224, +0,0,228,176,255,255,0,0,83,72,68,82,56,0,0,0, +64,0,240,255,14,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +54,0,0,5,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,120,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,116,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,77,117,108,116,105,112,108,121, +85,86,52,0,117,118,0,171,76,73,66,70,128,2,0,0, +68,88,66,67,121,42,193,146,188,175,215,160,65,233,118,29, +149,27,229,44,1,0,0,0,128,2,0,0,6,0,0,0, +56,0,0,0,132,0,0,0,208,0,0,0,16,1,0,0, +140,1,0,0,0,2,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,86,76,32,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,31,0,0,2,5,0,0,128, +0,0,15,144,1,0,0,2,0,0,15,224,0,0,228,144, +255,255,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,80,76,32,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,15,176, +1,0,0,2,0,0,15,224,0,0,228,176,255,255,0,0, +83,72,68,82,56,0,0,0,64,0,240,255,14,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,54,0,0,5,242,32,16,0, +0,0,0,0,70,30,16,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,60,0,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,120,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +116,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +77,117,108,116,105,112,108,121,85,86,53,0,117,118,0,171, +76,73,66,70,128,2,0,0,68,88,66,67,43,144,230,30, +211,110,217,234,138,146,61,118,62,126,189,42,1,0,0,0, +128,2,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,16,1,0,0,140,1,0,0,0,2,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +32,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +31,0,0,2,5,0,0,128,0,0,15,144,1,0,0,2, +0,0,15,224,0,0,228,144,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,32,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,1,0,0,2,0,0,15,224, +0,0,228,176,255,255,0,0,83,72,68,82,56,0,0,0, +64,0,240,255,14,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +54,0,0,5,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,120,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,116,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,77,117,108,116,105,112,108,121, +85,86,54,0,117,118,0,171,76,73,66,70,128,2,0,0, +68,88,66,67,225,123,250,221,76,72,10,52,198,89,252,247, +202,18,5,35,1,0,0,0,128,2,0,0,6,0,0,0, +56,0,0,0,132,0,0,0,208,0,0,0,16,1,0,0, +140,1,0,0,0,2,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,86,76,32,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,31,0,0,2,5,0,0,128, +0,0,15,144,1,0,0,2,0,0,15,224,0,0,228,144, +255,255,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,80,76,32,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,15,176, +1,0,0,2,0,0,15,224,0,0,228,176,255,255,0,0, +83,72,68,82,56,0,0,0,64,0,240,255,14,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,54,0,0,5,242,32,16,0, +0,0,0,0,70,30,16,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,60,0,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,120,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +116,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +77,117,108,116,105,112,108,121,85,86,55,0,117,118,0,171, +76,73,66,70,192,4,0,0,68,88,66,67,55,177,167,35, +230,168,3,26,213,51,153,178,57,116,234,20,1,0,0,0, +192,4,0,0,6,0,0,0,56,0,0,0,40,1,0,0, +40,2,0,0,76,3,0,0,200,3,0,0,60,4,0,0, +65,111,110,57,232,0,0,0,232,0,0,0,0,2,86,76, +196,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +81,0,0,5,0,0,15,160,0,0,128,63,0,0,0,63, +0,0,0,0,0,0,0,0,31,0,0,2,5,0,0,128, +0,0,15,144,5,0,0,3,0,0,3,128,0,0,228,144, +0,0,228,144,2,0,0,3,0,0,1,128,0,0,85,128, +0,0,0,128,2,0,0,3,0,0,2,128,0,0,170,144, +0,0,0,160,4,0,0,4,0,0,1,128,0,0,85,128, +0,0,85,128,0,0,0,128,7,0,0,2,0,0,1,128, +0,0,0,128,6,0,0,2,0,0,1,128,0,0,0,128, +2,0,0,3,0,0,1,128,0,0,0,128,0,0,0,128, +6,0,0,2,0,0,1,128,0,0,0,128,4,0,0,4, +0,0,3,224,0,0,228,144,0,0,0,128,0,0,85,160, +1,0,0,2,0,0,12,224,0,0,36,160,255,255,0,0, +65,111,110,57,248,0,0,0,248,0,0,0,0,2,80,76, +212,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,80,76, +81,0,0,5,0,0,15,160,0,0,128,63,0,0,0,63, +0,0,0,0,0,0,128,63,31,0,0,2,0,0,0,128, +0,0,7,176,5,0,0,3,0,0,8,128,0,0,85,176, +0,0,85,176,4,0,0,4,0,0,1,128,0,0,0,176, +0,0,0,176,0,0,255,128,2,0,0,3,0,0,2,128, +0,0,170,176,0,0,0,160,4,0,0,4,0,0,1,128, +0,0,85,128,0,0,85,128,0,0,0,128,7,0,0,2, +0,0,1,128,0,0,0,128,6,0,0,2,0,0,1,128, +0,0,0,128,2,0,0,3,0,0,1,128,0,0,0,128, +0,0,0,128,6,0,0,2,0,0,1,128,0,0,0,128, +4,0,0,4,0,0,3,128,0,0,228,176,0,0,0,128, +0,0,85,160,1,0,0,2,0,0,12,128,0,0,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,28,1,0,0,64,0,240,255,71,0,0,0, +95,0,0,3,114,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,104,0,0,2,1,0,0,0, +15,0,0,7,18,0,16,0,0,0,0,0,70,16,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,0,0,0,7, +34,0,16,0,0,0,0,0,42,16,16,0,0,0,0,0, +1,64,0,0,0,0,128,63,50,0,0,9,18,0,16,0, +0,0,0,0,26,0,16,0,0,0,0,0,26,0,16,0, +0,0,0,0,10,0,16,0,0,0,0,0,75,0,0,5, +18,0,16,0,0,0,0,0,10,0,16,0,0,0,0,0, +0,0,0,7,18,0,16,0,0,0,0,0,10,0,16,0, +0,0,0,0,10,0,16,0,0,0,0,0,14,0,0,7, +50,0,16,0,0,0,0,0,70,16,16,0,0,0,0,0, +6,0,16,0,0,0,0,0,0,0,0,10,50,32,16,0, +0,0,0,0,70,0,16,0,0,0,0,0,2,64,0,0, +0,0,0,63,0,0,0,63,0,0,0,0,0,0,0,0, +54,0,0,8,194,32,16,0,0,0,0,0,2,64,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,63, +62,0,0,1,83,84,65,84,116,0,0,0,9,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,7,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,124,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,116,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,85,86,83,112,104,101,114,101,77,97,112,0, +101,121,101,82,101,102,108,0,76,73,66,70,224,2,0,0, +68,88,66,67,230,26,65,230,192,146,124,110,146,230,36,50, +205,51,213,62,1,0,0,0,224,2,0,0,6,0,0,0, +56,0,0,0,164,0,0,0,32,1,0,0,116,1,0,0, +240,1,0,0,100,2,0,0,65,111,110,57,100,0,0,0, +100,0,0,0,0,2,86,76,64,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,81,0,0,5,0,0,15,160, +0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,4,0,0,4, +0,0,15,224,0,0,36,144,0,0,64,160,0,0,21,160, +255,255,0,0,65,111,110,57,116,0,0,0,116,0,0,0, +0,2,80,76,80,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,81,0,0,5,0,0,15,160,0,0,128,63, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,7,176,1,0,0,2,0,0,7,128, +0,0,228,176,1,0,0,2,0,0,8,128,0,0,0,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,76,0,0,0,64,0,240,255,19,0,0,0, +95,0,0,3,114,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,54,0,0,5,114,32,16,0, +0,0,0,0,70,18,16,0,0,0,0,0,54,0,0,5, +130,32,16,0,0,0,0,0,1,64,0,0,0,0,128,63, +62,0,0,1,83,84,65,84,116,0,0,0,3,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,114,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,70,108,111,97,116,51,116,111,52,0,118,0, +76,73,66,70,192,3,0,0,68,88,66,67,70,116,161,59, +42,125,161,227,92,25,246,147,196,134,44,94,1,0,0,0, +192,3,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,24,1,0,0,148,1,0,0,108,3,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +20,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,1,0,0,0, +1,0,0,0,0,0,0,0,0,2,86,76,1,0,0,2, +0,0,15,224,0,0,228,160,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,20,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,1,0,0,0,1,0,0,0, +0,0,0,0,0,2,80,76,1,0,0,2,0,0,15,224, +0,0,228,160,255,255,0,0,83,72,68,82,64,0,0,0, +64,0,240,255,16,0,0,0,89,0,0,4,70,142,32,0, +1,0,0,0,1,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,54,0,0,6,242,32,16,0,0,0,0,0, +70,142,32,0,1,0,0,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +208,1,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,160,1,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,80,105,120,101,108,0,171,171,171, +92,0,0,0,3,0,0,0,132,0,0,0,160,0,0,0, +0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0, +128,0,0,0,2,0,0,0,20,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,1,0,0,128,0,0,0,4,0,0,0,0,0,0,0, +76,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,112,1,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,124,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,118,101,99,95,99,111,108,111,114,115,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,102,102,95,97, +108,112,104,97,95,114,101,102,0,102,108,111,97,116,0,171, +0,0,3,0,1,0,1,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +69,1,0,0,102,102,95,102,111,103,95,112,115,0,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,76,0,0,0,1,0,0,0, +8,0,0,0,56,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,76,111,97,100,67,111,110,115,116,97,110,116, +67,111,108,111,114,48,0,171,76,73,66,70,192,3,0,0, +68,88,66,67,20,238,20,114,172,178,29,247,21,3,60,240, +206,249,78,81,1,0,0,0,192,3,0,0,6,0,0,0, +56,0,0,0,132,0,0,0,208,0,0,0,24,1,0,0, +148,1,0,0,108,3,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,86,76,20,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,1,0,1,0,0,0,0,0,0,0, +0,2,86,76,1,0,0,2,0,0,15,224,0,0,228,160, +255,255,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,80,76,20,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +1,0,1,0,1,0,0,0,0,0,0,0,0,2,80,76, +1,0,0,2,0,0,15,224,0,0,228,160,255,255,0,0, +83,72,68,82,64,0,0,0,64,0,240,255,16,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,2,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,54,0,0,6, +242,32,16,0,0,0,0,0,70,142,32,0,1,0,0,0, +1,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,208,1,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,160,1,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,80, +105,120,101,108,0,171,171,171,92,0,0,0,3,0,0,0, +132,0,0,0,160,0,0,0,0,0,0,0,0,0,0,0, +252,0,0,0,0,0,0,0,128,0,0,0,2,0,0,0, +20,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,1,0,0,128,0,0,0, +4,0,0,0,0,0,0,0,76,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +112,1,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +124,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,118,101,99,95,99, +111,108,111,114,115,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,102,102,95,97,108,112,104,97,95,114,101,102, +0,102,108,111,97,116,0,171,0,0,3,0,1,0,1,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,69,1,0,0,102,102,95,102, +111,103,95,112,115,0,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +76,0,0,0,1,0,0,0,8,0,0,0,56,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,76,111,97,100, +67,111,110,115,116,97,110,116,67,111,108,111,114,49,0,171, +76,73,66,70,192,3,0,0,68,88,66,67,116,104,252,128, +151,194,73,196,15,52,199,114,96,200,114,242,1,0,0,0, +192,3,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,24,1,0,0,148,1,0,0,108,3,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +20,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,1,0,2,0, +1,0,0,0,0,0,0,0,0,2,86,76,1,0,0,2, +0,0,15,224,0,0,228,160,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,20,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,1,0,2,0,1,0,0,0, +0,0,0,0,0,2,80,76,1,0,0,2,0,0,15,224, +0,0,228,160,255,255,0,0,83,72,68,82,64,0,0,0, +64,0,240,255,16,0,0,0,89,0,0,4,70,142,32,0, +1,0,0,0,3,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,54,0,0,6,242,32,16,0,0,0,0,0, +70,142,32,0,1,0,0,0,2,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +208,1,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,160,1,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,80,105,120,101,108,0,171,171,171, +92,0,0,0,3,0,0,0,132,0,0,0,160,0,0,0, +0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0, +128,0,0,0,2,0,0,0,20,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,1,0,0,128,0,0,0,4,0,0,0,0,0,0,0, +76,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,112,1,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,124,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,118,101,99,95,99,111,108,111,114,115,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,102,102,95,97, +108,112,104,97,95,114,101,102,0,102,108,111,97,116,0,171, +0,0,3,0,1,0,1,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +69,1,0,0,102,102,95,102,111,103,95,112,115,0,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,76,0,0,0,1,0,0,0, +8,0,0,0,56,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,76,111,97,100,67,111,110,115,116,97,110,116, +67,111,108,111,114,50,0,171,76,73,66,70,192,3,0,0, +68,88,66,67,131,41,35,159,159,146,237,240,170,111,184,2, +39,243,88,214,1,0,0,0,192,3,0,0,6,0,0,0, +56,0,0,0,132,0,0,0,208,0,0,0,24,1,0,0, +148,1,0,0,108,3,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,86,76,20,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,3,0,1,0,0,0,0,0,0,0, +0,2,86,76,1,0,0,2,0,0,15,224,0,0,228,160, +255,255,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,80,76,20,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +1,0,3,0,1,0,0,0,0,0,0,0,0,2,80,76, +1,0,0,2,0,0,15,224,0,0,228,160,255,255,0,0, +83,72,68,82,64,0,0,0,64,0,240,255,16,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,4,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,54,0,0,6, +242,32,16,0,0,0,0,0,70,142,32,0,1,0,0,0, +3,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,208,1,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,160,1,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,80, +105,120,101,108,0,171,171,171,92,0,0,0,3,0,0,0, +132,0,0,0,160,0,0,0,0,0,0,0,0,0,0,0, +252,0,0,0,0,0,0,0,128,0,0,0,2,0,0,0, +20,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,1,0,0,128,0,0,0, +4,0,0,0,0,0,0,0,76,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +112,1,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +124,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,118,101,99,95,99, +111,108,111,114,115,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,102,102,95,97,108,112,104,97,95,114,101,102, +0,102,108,111,97,116,0,171,0,0,3,0,1,0,1,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,69,1,0,0,102,102,95,102, +111,103,95,112,115,0,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +76,0,0,0,1,0,0,0,8,0,0,0,56,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,76,111,97,100, +67,111,110,115,116,97,110,116,67,111,108,111,114,51,0,171, +76,73,66,70,192,3,0,0,68,88,66,67,3,40,62,77, +224,140,92,152,89,140,38,56,207,39,135,89,1,0,0,0, +192,3,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,24,1,0,0,148,1,0,0,108,3,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +20,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,1,0,4,0, +1,0,0,0,0,0,0,0,0,2,86,76,1,0,0,2, +0,0,15,224,0,0,228,160,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,20,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,1,0,4,0,1,0,0,0, +0,0,0,0,0,2,80,76,1,0,0,2,0,0,15,224, +0,0,228,160,255,255,0,0,83,72,68,82,64,0,0,0, +64,0,240,255,16,0,0,0,89,0,0,4,70,142,32,0, +1,0,0,0,5,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,54,0,0,6,242,32,16,0,0,0,0,0, +70,142,32,0,1,0,0,0,4,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +208,1,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,160,1,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,80,105,120,101,108,0,171,171,171, +92,0,0,0,3,0,0,0,132,0,0,0,160,0,0,0, +0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0, +128,0,0,0,2,0,0,0,20,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,1,0,0,128,0,0,0,4,0,0,0,0,0,0,0, +76,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,112,1,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,124,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,118,101,99,95,99,111,108,111,114,115,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,102,102,95,97, +108,112,104,97,95,114,101,102,0,102,108,111,97,116,0,171, +0,0,3,0,1,0,1,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +69,1,0,0,102,102,95,102,111,103,95,112,115,0,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,76,0,0,0,1,0,0,0, +8,0,0,0,56,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,76,111,97,100,67,111,110,115,116,97,110,116, +67,111,108,111,114,52,0,171,76,73,66,70,192,3,0,0, +68,88,66,67,247,173,93,73,196,111,229,44,163,237,132,230, +106,105,144,109,1,0,0,0,192,3,0,0,6,0,0,0, +56,0,0,0,132,0,0,0,208,0,0,0,24,1,0,0, +148,1,0,0,108,3,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,86,76,20,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,5,0,1,0,0,0,0,0,0,0, +0,2,86,76,1,0,0,2,0,0,15,224,0,0,228,160, +255,255,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,80,76,20,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +1,0,5,0,1,0,0,0,0,0,0,0,0,2,80,76, +1,0,0,2,0,0,15,224,0,0,228,160,255,255,0,0, +83,72,68,82,64,0,0,0,64,0,240,255,16,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,6,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,54,0,0,6, +242,32,16,0,0,0,0,0,70,142,32,0,1,0,0,0, +5,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,208,1,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,160,1,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,80, +105,120,101,108,0,171,171,171,92,0,0,0,3,0,0,0, +132,0,0,0,160,0,0,0,0,0,0,0,0,0,0,0, +252,0,0,0,0,0,0,0,128,0,0,0,2,0,0,0, +20,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,1,0,0,128,0,0,0, +4,0,0,0,0,0,0,0,76,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +112,1,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +124,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,118,101,99,95,99, +111,108,111,114,115,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,102,102,95,97,108,112,104,97,95,114,101,102, +0,102,108,111,97,116,0,171,0,0,3,0,1,0,1,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,69,1,0,0,102,102,95,102, +111,103,95,112,115,0,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +76,0,0,0,1,0,0,0,8,0,0,0,56,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,76,111,97,100, +67,111,110,115,116,97,110,116,67,111,108,111,114,53,0,171, +76,73,66,70,192,3,0,0,68,88,66,67,48,33,196,39, +86,158,25,201,60,227,193,209,75,77,76,7,1,0,0,0, +192,3,0,0,6,0,0,0,56,0,0,0,132,0,0,0, +208,0,0,0,24,1,0,0,148,1,0,0,108,3,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,86,76, +20,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,1,0,6,0, +1,0,0,0,0,0,0,0,0,2,86,76,1,0,0,2, +0,0,15,224,0,0,228,160,255,255,0,0,65,111,110,57, +68,0,0,0,68,0,0,0,0,2,80,76,20,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,1,0,6,0,1,0,0,0, +0,0,0,0,0,2,80,76,1,0,0,2,0,0,15,224, +0,0,228,160,255,255,0,0,83,72,68,82,64,0,0,0, +64,0,240,255,16,0,0,0,89,0,0,4,70,142,32,0, +1,0,0,0,7,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,54,0,0,6,242,32,16,0,0,0,0,0, +70,142,32,0,1,0,0,0,6,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +208,1,0,0,1,0,0,0,108,0,0,0,1,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,160,1,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +85,110,105,116,121,70,70,80,105,120,101,108,0,171,171,171, +92,0,0,0,3,0,0,0,132,0,0,0,160,0,0,0, +0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0, +128,0,0,0,2,0,0,0,20,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +56,1,0,0,128,0,0,0,4,0,0,0,0,0,0,0, +76,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,112,1,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,124,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,118,101,99,95,99,111,108,111,114,115,0,102,108, +111,97,116,52,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,102,102,95,97, +108,112,104,97,95,114,101,102,0,102,108,111,97,116,0,171, +0,0,3,0,1,0,1,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +69,1,0,0,102,102,95,102,111,103,95,112,115,0,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,76,0,0,0,1,0,0,0, +8,0,0,0,56,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,76,111,97,100,67,111,110,115,116,97,110,116, +67,111,108,111,114,54,0,171,76,73,66,70,192,3,0,0, +68,88,66,67,169,198,138,5,205,98,94,205,122,79,240,230, +184,15,46,76,1,0,0,0,192,3,0,0,6,0,0,0, +56,0,0,0,132,0,0,0,208,0,0,0,24,1,0,0, +148,1,0,0,108,3,0,0,65,111,110,57,68,0,0,0, +68,0,0,0,0,2,86,76,20,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,7,0,1,0,0,0,0,0,0,0, +0,2,86,76,1,0,0,2,0,0,15,224,0,0,228,160, +255,255,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,80,76,20,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +1,0,7,0,1,0,0,0,0,0,0,0,0,2,80,76, +1,0,0,2,0,0,15,224,0,0,228,160,255,255,0,0, +83,72,68,82,64,0,0,0,64,0,240,255,16,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,8,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,54,0,0,6, +242,32,16,0,0,0,0,0,70,142,32,0,1,0,0,0, +7,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,208,1,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,160,1,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,80, +105,120,101,108,0,171,171,171,92,0,0,0,3,0,0,0, +132,0,0,0,160,0,0,0,0,0,0,0,0,0,0,0, +252,0,0,0,0,0,0,0,128,0,0,0,2,0,0,0, +20,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,1,0,0,128,0,0,0, +4,0,0,0,0,0,0,0,76,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +112,1,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +124,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,118,101,99,95,99, +111,108,111,114,115,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,102,102,95,97,108,112,104,97,95,114,101,102, +0,102,108,111,97,116,0,171,0,0,3,0,1,0,1,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,69,1,0,0,102,102,95,102, +111,103,95,112,115,0,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +76,0,0,0,1,0,0,0,8,0,0,0,56,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,76,111,97,100, +67,111,110,115,116,97,110,116,67,111,108,111,114,55,0,171, +76,73,66,70,204,2,0,0,68,88,66,67,45,108,242,17, +41,178,132,75,103,221,15,167,11,128,240,127,1,0,0,0, +204,2,0,0,6,0,0,0,56,0,0,0,160,0,0,0, +20,1,0,0,96,1,0,0,220,1,0,0,80,2,0,0, +65,111,110,57,96,0,0,0,96,0,0,0,0,2,86,76, +60,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +81,0,0,5,0,0,15,160,0,0,128,63,0,0,0,0, +0,0,0,0,0,0,0,0,31,0,0,2,5,0,0,128, +0,0,15,144,2,0,0,3,0,0,1,224,0,0,0,145, +0,0,0,160,255,255,0,0,65,111,110,57,108,0,0,0, +108,0,0,0,0,2,80,76,72,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,81,0,0,5,0,0,15,160, +0,0,128,63,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,0,0,0,128,0,0,1,176,2,0,0,3, +0,0,8,128,0,0,0,177,0,0,0,160,1,0,0,2, +0,0,1,224,0,0,255,128,255,255,0,0,83,72,68,82, +68,0,0,0,64,0,240,255,17,0,0,0,95,0,0,3, +18,16,16,0,0,0,0,0,101,0,0,3,18,32,16,0, +0,0,0,0,0,0,0,8,18,32,16,0,0,0,0,0, +10,16,16,128,65,0,0,0,0,0,0,0,1,64,0,0, +0,0,128,63,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,116,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,114,0,0,0,0,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,79,110,101,77,105,110,117,115, +49,0,118,0,76,73,66,70,216,2,0,0,68,88,66,67, +158,168,1,106,99,49,31,82,200,140,198,11,9,75,78,147, +1,0,0,0,216,2,0,0,6,0,0,0,56,0,0,0, +160,0,0,0,20,1,0,0,108,1,0,0,232,1,0,0, +92,2,0,0,65,111,110,57,96,0,0,0,96,0,0,0, +0,2,86,76,60,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,81,0,0,5,0,0,15,160,0,0,128,63, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,2,0,0,3,0,0,7,224, +0,0,228,145,0,0,0,160,255,255,0,0,65,111,110,57, +108,0,0,0,108,0,0,0,0,2,80,76,72,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,81,0,0,5, +0,0,15,160,0,0,128,63,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,0,0,0,128,0,0,7,176, +2,0,0,3,0,0,7,128,0,0,228,177,0,0,0,160, +1,0,0,2,0,0,7,224,0,0,228,128,255,255,0,0, +83,72,68,82,80,0,0,0,64,0,240,255,20,0,0,0, +95,0,0,3,114,16,16,0,0,0,0,0,101,0,0,3, +114,32,16,0,0,0,0,0,0,0,0,11,114,32,16,0, +0,0,0,0,70,18,16,128,65,0,0,0,0,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,116,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,114,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,79,110,101,77,105,110,117,115, +51,0,118,0,76,73,66,70,216,2,0,0,68,88,66,67, +11,213,169,220,3,17,184,207,196,164,42,102,227,86,202,46, +1,0,0,0,216,2,0,0,6,0,0,0,56,0,0,0, +160,0,0,0,20,1,0,0,108,1,0,0,232,1,0,0, +92,2,0,0,65,111,110,57,96,0,0,0,96,0,0,0, +0,2,86,76,60,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,81,0,0,5,0,0,15,160,0,0,128,63, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,2,0,0,3,0,0,15,224, +0,0,228,145,0,0,0,160,255,255,0,0,65,111,110,57, +108,0,0,0,108,0,0,0,0,2,80,76,72,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,81,0,0,5, +0,0,15,160,0,0,128,63,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,0,0,0,128,0,0,15,176, +2,0,0,3,0,0,15,128,0,0,228,177,0,0,0,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,80,0,0,0,64,0,240,255,20,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,0,0,0,11,242,32,16,0, +0,0,0,0,70,30,16,128,65,0,0,0,0,0,0,0, +2,64,0,0,0,0,128,63,0,0,128,63,0,0,128,63, +0,0,128,63,62,0,0,1,83,84,65,84,116,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,116,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,114,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,79,110,101,77,105,110,117,115, +52,0,118,0,76,73,66,70,128,2,0,0,68,88,66,67, +187,71,126,136,198,179,185,17,98,92,175,72,62,254,64,135, +1,0,0,0,128,2,0,0,6,0,0,0,56,0,0,0, +132,0,0,0,208,0,0,0,16,1,0,0,140,1,0,0, +0,2,0,0,65,111,110,57,68,0,0,0,68,0,0,0, +0,2,86,76,32,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +1,0,0,2,0,0,15,224,0,0,228,144,255,255,0,0, +65,111,110,57,68,0,0,0,68,0,0,0,0,2,80,76, +32,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,80,76, +31,0,0,2,0,0,0,128,0,0,15,176,1,0,0,2, +0,0,15,224,0,0,228,176,255,255,0,0,83,72,68,82, +56,0,0,0,64,0,240,255,14,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,54,0,0,5,242,32,16,0,0,0,0,0, +70,30,16,0,0,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,108,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,60,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +120,0,0,0,2,0,0,0,8,0,0,0,104,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,116,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,98, +82,101,112,108,97,99,101,0,97,0,171,171,76,73,66,70, +12,3,0,0,68,88,66,67,149,143,87,109,142,38,148,229, +142,231,17,129,220,71,27,94,1,0,0,0,12,3,0,0, +6,0,0,0,56,0,0,0,160,0,0,0,20,1,0,0, +104,1,0,0,228,1,0,0,88,2,0,0,65,111,110,57, +96,0,0,0,96,0,0,0,0,2,86,76,60,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,31,0,0,2,5,0,1,128, +1,0,15,144,1,0,0,2,0,0,15,128,0,0,228,144, +5,0,0,3,0,0,15,224,0,0,228,128,1,0,228,144, +255,255,0,0,65,111,110,57,108,0,0,0,108,0,0,0, +0,2,80,76,72,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,31,0,0,2,0,0,0,128,0,0,15,176, +31,0,0,2,0,0,0,128,1,0,15,176,1,0,0,2, +0,0,15,128,0,0,228,176,5,0,0,3,0,0,15,128, +0,0,228,128,1,0,228,176,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,76,0,0,0, +64,0,240,255,19,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,95,0,0,3,242,16,16,0,1,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,56,0,0,7, +242,32,16,0,0,0,0,0,70,30,16,0,0,0,0,0, +70,30,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,108,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,60,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +172,0,0,0,3,0,0,0,8,0,0,0,152,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,165,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,167,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,98, +77,111,100,117,108,97,116,101,0,97,0,98,0,171,171,171, +76,73,66,70,4,3,0,0,68,88,66,67,230,76,60,128, +196,190,237,250,58,85,119,85,43,12,167,22,1,0,0,0, +4,3,0,0,6,0,0,0,56,0,0,0,160,0,0,0, +20,1,0,0,104,1,0,0,228,1,0,0,88,2,0,0, +65,111,110,57,96,0,0,0,96,0,0,0,0,2,86,76, +60,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,1,0,0,2,0,0,15,128, +0,0,228,144,2,0,0,3,0,0,15,224,0,0,228,128, +1,0,228,144,255,255,0,0,65,111,110,57,108,0,0,0, +108,0,0,0,0,2,80,76,72,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,15,176,31,0,0,2,0,0,0,128,1,0,15,176, +1,0,0,2,0,0,15,128,0,0,228,176,2,0,0,3, +0,0,15,128,0,0,228,128,1,0,228,176,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +76,0,0,0,64,0,240,255,19,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,95,0,0,3,242,16,16,0, +1,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +0,0,0,7,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,70,30,16,0,1,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,60,0,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,164,0,0,0,3,0,0,0,8,0,0,0, +152,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +160,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +162,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +67,111,109,98,65,100,100,0,97,0,98,0,76,73,66,70, +140,3,0,0,68,88,66,67,152,199,141,230,40,126,172,158, +226,182,226,112,150,175,84,205,1,0,0,0,140,3,0,0, +6,0,0,0,56,0,0,0,200,0,0,0,100,1,0,0, +232,1,0,0,100,2,0,0,216,2,0,0,65,111,110,57, +136,0,0,0,136,0,0,0,0,2,86,76,100,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,86,76,81,0,0,5, +0,0,15,160,0,0,0,191,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,1,0,0,2, +0,0,15,128,0,0,228,144,2,0,0,3,0,0,15,128, +0,0,228,128,1,0,228,144,2,0,0,3,0,0,15,224, +0,0,228,128,0,0,0,160,255,255,0,0,65,111,110,57, +148,0,0,0,148,0,0,0,0,2,80,76,112,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,81,0,0,5, +0,0,15,160,0,0,0,191,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,0,0,0,128,0,0,15,176, +31,0,0,2,0,0,0,128,1,0,15,176,1,0,0,2, +0,0,15,128,0,0,228,176,2,0,0,3,0,0,15,128, +0,0,228,128,1,0,228,176,2,0,0,3,0,0,15,128, +0,0,228,128,0,0,0,160,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,124,0,0,0, +64,0,240,255,31,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,95,0,0,3,242,16,16,0,1,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,104,0,0,2, +1,0,0,0,0,0,0,7,242,0,16,0,0,0,0,0, +70,30,16,0,0,0,0,0,70,30,16,0,1,0,0,0, +0,0,0,10,242,32,16,0,0,0,0,0,70,14,16,0, +0,0,0,0,2,64,0,0,0,0,0,191,0,0,0,191, +0,0,0,191,0,0,0,191,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +3,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,108,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,60,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +172,0,0,0,3,0,0,0,8,0,0,0,152,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,166,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,168,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,98, +65,100,100,83,105,103,110,101,100,0,97,0,98,0,171,171, +76,73,66,70,16,3,0,0,68,88,66,67,183,114,174,20, +132,250,51,162,45,140,19,76,71,64,111,25,1,0,0,0, +16,3,0,0,6,0,0,0,56,0,0,0,160,0,0,0, +20,1,0,0,108,1,0,0,232,1,0,0,92,2,0,0, +65,111,110,57,96,0,0,0,96,0,0,0,0,2,86,76, +60,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,86,76, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,1,0,0,2,0,0,15,128, +0,0,228,144,2,0,0,3,0,0,15,224,0,0,228,128, +1,0,228,145,255,255,0,0,65,111,110,57,108,0,0,0, +108,0,0,0,0,2,80,76,72,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,15,176,31,0,0,2,0,0,0,128,1,0,15,176, +1,0,0,2,0,0,15,128,0,0,228,176,2,0,0,3, +0,0,15,128,0,0,228,128,1,0,228,177,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +80,0,0,0,64,0,240,255,20,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,95,0,0,3,242,16,16,0, +1,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +0,0,0,8,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,70,30,16,128,65,0,0,0,1,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,172,0,0,0,3,0,0,0, +8,0,0,0,152,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,165,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,167,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,67,111,109,98,83,117,98,116,114,97,99,116, +0,97,0,98,0,171,171,171,76,73,66,70,180,3,0,0, +68,88,66,67,152,163,17,37,211,107,50,197,55,83,131,3, +147,212,251,180,1,0,0,0,180,3,0,0,6,0,0,0, +56,0,0,0,192,0,0,0,84,1,0,0,228,1,0,0, +96,2,0,0,212,2,0,0,65,111,110,57,128,0,0,0, +128,0,0,0,0,2,86,76,92,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,31,0,0,2,5,0,0,128, +0,0,15,144,31,0,0,2,5,0,1,128,1,0,15,144, +31,0,0,2,5,0,2,128,2,0,15,144,1,0,0,2, +0,0,15,128,1,0,228,144,2,0,0,3,1,0,15,128, +0,0,228,129,0,0,228,144,4,0,0,4,0,0,15,224, +2,0,255,144,1,0,228,128,0,0,228,128,255,255,0,0, +65,111,110,57,140,0,0,0,140,0,0,0,0,2,80,76, +104,0,0,0,36,0,0,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,2,80,76, +31,0,0,2,0,0,0,128,0,0,15,176,31,0,0,2, +0,0,0,128,1,0,15,176,31,0,0,2,0,0,0,128, +2,0,8,176,1,0,0,2,0,0,15,128,1,0,228,176, +2,0,0,3,1,0,15,128,0,0,228,129,0,0,228,176, +4,0,0,4,0,0,15,128,2,0,255,176,1,0,228,128, +0,0,228,128,1,0,0,2,0,0,15,224,0,0,228,128, +255,255,0,0,83,72,68,82,136,0,0,0,64,0,240,255, +34,0,0,0,95,0,0,3,242,16,16,0,0,0,0,0, +95,0,0,3,242,16,16,0,1,0,0,0,95,0,0,3, +130,16,16,0,2,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,104,0,0,2,1,0,0,0,0,0,0,8, +242,0,16,0,0,0,0,0,70,30,16,0,0,0,0,0, +70,30,16,128,65,0,0,0,1,0,0,0,50,0,0,9, +242,32,16,0,0,0,0,0,246,31,16,0,2,0,0,0, +70,14,16,0,0,0,0,0,70,30,16,0,1,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,3,0,0,0, +1,0,0,0,0,0,0,0,4,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,216,0,0,0,4,0,0,0, +8,0,0,0,200,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,209,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,211,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,213,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,2,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,67,111,109,98,76,101,114,112,0,97,0,98, +0,99,0,171,76,73,66,70,44,4,0,0,68,88,66,67, +51,90,121,247,48,76,173,77,104,101,2,120,144,179,245,77, +1,0,0,0,44,4,0,0,6,0,0,0,56,0,0,0, +232,0,0,0,164,1,0,0,140,2,0,0,8,3,0,0, +124,3,0,0,65,111,110,57,168,0,0,0,168,0,0,0, +0,2,86,76,132,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,81,0,0,5,0,0,15,160,0,0,0,191, +0,0,128,64,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,31,0,0,2,5,0,1,128, +1,0,15,144,2,0,0,3,0,0,7,128,0,0,228,144, +0,0,0,160,2,0,0,3,1,0,7,128,1,0,228,144, +0,0,0,160,8,0,0,3,0,0,1,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,7,224,0,0,0,128, +0,0,85,160,1,0,0,2,0,0,8,224,0,0,255,144, +255,255,0,0,65,111,110,57,180,0,0,0,180,0,0,0, +0,2,80,76,144,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,81,0,0,5,0,0,15,160,0,0,0,191, +0,0,128,64,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,15,176,31,0,0,2,0,0,0,128, +1,0,7,176,2,0,0,3,0,0,7,128,0,0,228,176, +0,0,0,160,2,0,0,3,1,0,7,128,1,0,228,176, +0,0,0,160,8,0,0,3,0,0,1,128,0,0,228,128, +1,0,228,128,5,0,0,3,0,0,7,128,0,0,0,128, +0,0,85,160,1,0,0,2,0,0,8,128,0,0,255,176, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,224,0,0,0,64,0,240,255,56,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,95,0,0,3, +114,16,16,0,1,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,104,0,0,2,2,0,0,0,0,0,0,10, +114,0,16,0,0,0,0,0,70,18,16,0,0,0,0,0, +2,64,0,0,0,0,0,191,0,0,0,191,0,0,0,191, +0,0,0,0,0,0,0,10,114,0,16,0,1,0,0,0, +70,18,16,0,1,0,0,0,2,64,0,0,0,0,0,191, +0,0,0,191,0,0,0,191,0,0,0,0,16,0,0,7, +18,0,16,0,0,0,0,0,70,2,16,0,0,0,0,0, +70,2,16,0,1,0,0,0,56,0,0,10,114,32,16,0, +0,0,0,0,6,0,16,0,0,0,0,0,2,64,0,0, +0,0,128,64,0,0,128,64,0,0,128,64,0,0,0,0, +54,0,0,5,130,32,16,0,0,0,0,0,58,16,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +6,0,0,0,2,0,0,0,0,0,0,0,3,0,0,0, +4,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,168,0,0,0, +3,0,0,0,8,0,0,0,152,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,161,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,163,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,67,111,109,98,68,111,116,51, +0,97,0,98,0,171,171,171,76,73,66,70,4,4,0,0, +68,88,66,67,136,183,202,100,86,249,89,61,211,252,59,81, +134,90,81,47,1,0,0,0,4,4,0,0,6,0,0,0, +56,0,0,0,220,0,0,0,140,1,0,0,96,2,0,0, +220,2,0,0,80,3,0,0,65,111,110,57,156,0,0,0, +156,0,0,0,0,2,86,76,120,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,81,0,0,5,0,0,15,160, +0,0,0,191,0,0,128,64,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,2,0,0,3,0,0,7,128, +0,0,228,144,0,0,0,160,2,0,0,3,1,0,7,128, +1,0,228,144,0,0,0,160,8,0,0,3,0,0,1,128, +0,0,228,128,1,0,228,128,5,0,0,3,0,0,15,224, +0,0,0,128,0,0,85,160,255,255,0,0,65,111,110,57, +168,0,0,0,168,0,0,0,0,2,80,76,132,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,81,0,0,5, +0,0,15,160,0,0,0,191,0,0,128,64,0,0,0,0, +0,0,0,0,31,0,0,2,0,0,0,128,0,0,7,176, +31,0,0,2,0,0,0,128,1,0,7,176,2,0,0,3, +0,0,7,128,0,0,228,176,0,0,0,160,2,0,0,3, +1,0,7,128,1,0,228,176,0,0,0,160,8,0,0,3, +0,0,1,128,0,0,228,128,1,0,228,128,5,0,0,3, +0,0,15,128,0,0,0,128,0,0,85,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +204,0,0,0,64,0,240,255,51,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,2,0,0,0,0,0,0,10,114,0,16,0, +0,0,0,0,70,18,16,0,0,0,0,0,2,64,0,0, +0,0,0,191,0,0,0,191,0,0,0,191,0,0,0,0, +0,0,0,10,114,0,16,0,1,0,0,0,70,18,16,0, +1,0,0,0,2,64,0,0,0,0,0,191,0,0,0,191, +0,0,0,191,0,0,0,0,16,0,0,7,18,0,16,0, +0,0,0,0,70,2,16,0,0,0,0,0,70,2,16,0, +1,0,0,0,56,0,0,10,242,32,16,0,0,0,0,0, +6,0,16,0,0,0,0,0,2,64,0,0,0,0,128,64, +0,0,128,64,0,0,128,64,0,0,128,64,62,0,0,1, +83,84,65,84,116,0,0,0,5,0,0,0,2,0,0,0, +0,0,0,0,3,0,0,0,4,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,60,0,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,172,0,0,0,3,0,0,0,8,0,0,0, +152,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +165,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +167,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +67,111,109,98,68,111,116,51,114,103,98,97,0,97,0,98, +0,171,171,171,76,73,66,70,136,3,0,0,68,88,66,67, +31,76,227,248,96,59,115,47,100,193,168,174,45,34,12,208, +1,0,0,0,136,3,0,0,6,0,0,0,56,0,0,0, +188,0,0,0,76,1,0,0,180,1,0,0,48,2,0,0, +164,2,0,0,65,111,110,57,124,0,0,0,124,0,0,0, +0,2,86,76,88,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,31,0,0,2, +5,0,2,128,2,0,15,144,1,0,0,2,0,0,15,128, +0,0,228,144,1,0,0,2,1,0,8,128,2,0,255,144, +4,0,0,4,0,0,15,224,0,0,228,128,1,0,255,128, +1,0,228,144,255,255,0,0,65,111,110,57,136,0,0,0, +136,0,0,0,0,2,80,76,100,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,15,176,31,0,0,2,0,0,0,128,1,0,15,176, +31,0,0,2,0,0,0,128,2,0,8,176,1,0,0,2, +0,0,15,128,0,0,228,176,1,0,0,2,1,0,8,128, +2,0,255,176,4,0,0,4,0,0,15,128,0,0,228,128, +1,0,255,128,1,0,228,176,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,96,0,0,0, +64,0,240,255,24,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,95,0,0,3,242,16,16,0,1,0,0,0, +95,0,0,3,130,16,16,0,2,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,50,0,0,9,242,32,16,0, +0,0,0,0,70,30,16,0,0,0,0,0,246,31,16,0, +2,0,0,0,70,30,16,0,1,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,4,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,60,0,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,220,0,0,0,4,0,0,0,8,0,0,0, +200,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +211,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +213,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +215,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +2,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +67,111,109,98,77,117,108,65,100,100,0,97,0,98,0,99, +0,171,171,171,76,73,66,70,140,3,0,0,68,88,66,67, +127,205,158,183,165,163,232,169,189,8,89,19,233,185,188,242, +1,0,0,0,140,3,0,0,6,0,0,0,56,0,0,0, +188,0,0,0,76,1,0,0,184,1,0,0,52,2,0,0, +168,2,0,0,65,111,110,57,124,0,0,0,124,0,0,0, +0,2,86,76,88,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,31,0,0,2, +5,0,2,128,2,0,15,144,1,0,0,2,0,0,15,128, +0,0,228,144,1,0,0,2,1,0,8,128,2,0,255,144, +4,0,0,4,0,0,15,224,0,0,228,128,1,0,255,128, +1,0,228,145,255,255,0,0,65,111,110,57,136,0,0,0, +136,0,0,0,0,2,80,76,100,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,15,176,31,0,0,2,0,0,0,128,1,0,15,176, +31,0,0,2,0,0,0,128,2,0,8,176,1,0,0,2, +0,0,15,128,0,0,228,176,1,0,0,2,1,0,8,128, +2,0,255,176,4,0,0,4,0,0,15,128,0,0,228,128, +1,0,255,128,1,0,228,177,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,100,0,0,0, +64,0,240,255,25,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,95,0,0,3,242,16,16,0,1,0,0,0, +95,0,0,3,130,16,16,0,2,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,50,0,0,10,242,32,16,0, +0,0,0,0,70,30,16,0,0,0,0,0,246,31,16,0, +2,0,0,0,70,30,16,128,65,0,0,0,1,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,4,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,220,0,0,0,4,0,0,0, +8,0,0,0,200,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,211,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,213,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,215,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,2,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,67,111,109,98,77,117,108,83,117,98,0,97, +0,98,0,99,0,171,171,171,76,73,66,70,12,4,0,0, +68,88,66,67,83,111,20,102,197,156,233,182,54,7,106,223, +34,245,237,46,1,0,0,0,12,4,0,0,6,0,0,0, +56,0,0,0,228,0,0,0,156,1,0,0,52,2,0,0, +176,2,0,0,36,3,0,0,65,111,110,57,164,0,0,0, +164,0,0,0,0,2,86,76,128,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,81,0,0,5,0,0,15,160, +0,0,0,191,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,5,0,0,128,0,0,15,144,31,0,0,2, +5,0,1,128,1,0,15,144,31,0,0,2,5,0,2,128, +2,0,15,144,1,0,0,2,0,0,15,128,0,0,228,144, +1,0,0,2,1,0,8,128,2,0,255,144,4,0,0,4, +0,0,15,128,0,0,228,128,1,0,255,128,1,0,228,144, +2,0,0,3,0,0,15,224,0,0,228,128,0,0,0,160, +255,255,0,0,65,111,110,57,176,0,0,0,176,0,0,0, +0,2,80,76,140,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,81,0,0,5,0,0,15,160,0,0,0,191, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,15,176,31,0,0,2,0,0,0,128, +1,0,15,176,31,0,0,2,0,0,0,128,2,0,8,176, +1,0,0,2,0,0,15,128,0,0,228,176,1,0,0,2, +1,0,8,128,2,0,255,176,4,0,0,4,0,0,15,128, +0,0,228,128,1,0,255,128,1,0,228,176,2,0,0,3, +0,0,15,128,0,0,228,128,0,0,0,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +144,0,0,0,64,0,240,255,36,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,95,0,0,3,242,16,16,0, +1,0,0,0,95,0,0,3,130,16,16,0,2,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,104,0,0,2, +1,0,0,0,50,0,0,9,242,0,16,0,0,0,0,0, +70,30,16,0,0,0,0,0,246,31,16,0,2,0,0,0, +70,30,16,0,1,0,0,0,0,0,0,10,242,32,16,0, +0,0,0,0,70,14,16,0,0,0,0,0,2,64,0,0, +0,0,0,191,0,0,0,191,0,0,0,191,0,0,0,191, +62,0,0,1,83,84,65,84,116,0,0,0,3,0,0,0, +1,0,0,0,0,0,0,0,4,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,224,0,0,0,4,0,0,0, +8,0,0,0,200,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,217,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,219,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,221,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,2,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,67,111,109,98,77,117,108,65,100,100,83,105, +103,110,101,100,0,97,0,98,0,99,0,171,76,73,66,70, +152,2,0,0,68,88,66,67,104,50,51,52,155,142,16,144, +69,96,27,4,5,193,22,178,1,0,0,0,152,2,0,0, +6,0,0,0,56,0,0,0,136,0,0,0,228,0,0,0, +44,1,0,0,168,1,0,0,28,2,0,0,65,111,110,57, +72,0,0,0,72,0,0,0,0,2,86,76,36,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,86,76,31,0,0,2, +5,0,0,128,0,0,15,144,2,0,0,3,0,0,15,224, +0,0,228,144,0,0,228,144,255,255,0,0,65,111,110,57, +84,0,0,0,84,0,0,0,0,2,80,76,48,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,2,0,0,3,0,0,15,128, +0,0,228,176,0,0,228,176,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,64,0,0,0, +64,0,240,255,16,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +0,0,0,7,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,70,30,16,0,0,0,0,0,62,0,0,1, +83,84,65,84,116,0,0,0,2,0,0,0,0,0,0,0, +0,0,0,0,2,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,82,68,69,70, +108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +60,0,0,0,0,4,70,76,0,129,0,0,60,0,0,0, +82,68,49,49,60,0,0,0,24,0,0,0,32,0,0,0, +40,0,0,0,36,0,0,0,12,0,0,0,0,0,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,116,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +111,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +83,99,97,108,101,50,0,97,0,171,171,171,76,73,66,70, +212,2,0,0,68,88,66,67,57,34,29,67,178,80,106,40, +94,22,39,177,107,192,81,162,1,0,0,0,212,2,0,0, +6,0,0,0,56,0,0,0,160,0,0,0,20,1,0,0, +104,1,0,0,228,1,0,0,88,2,0,0,65,111,110,57, +96,0,0,0,96,0,0,0,0,2,86,76,60,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,86,76,81,0,0,5, +0,0,15,160,0,0,128,64,0,0,0,0,0,0,0,0, +0,0,0,0,31,0,0,2,5,0,0,128,0,0,15,144, +5,0,0,3,0,0,15,224,0,0,228,144,0,0,0,160, +255,255,0,0,65,111,110,57,108,0,0,0,108,0,0,0, +0,2,80,76,72,0,0,0,36,0,0,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,2,80,76,81,0,0,5,0,0,15,160,0,0,128,64, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,15,176,5,0,0,3,0,0,15,128, +0,0,228,176,0,0,0,160,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,76,0,0,0, +64,0,240,255,19,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +56,0,0,10,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,2,64,0,0,0,0,128,64,0,0,128,64, +0,0,128,64,0,0,128,64,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,108,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,60,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +116,0,0,0,2,0,0,0,8,0,0,0,104,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,111,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,83,99,97,108, +101,52,0,97,0,171,171,171,76,73,66,70,56,3,0,0, +68,88,66,67,20,232,184,35,253,143,9,50,109,2,17,57, +26,201,43,39,1,0,0,0,56,3,0,0,6,0,0,0, +56,0,0,0,172,0,0,0,44,1,0,0,148,1,0,0, +16,2,0,0,132,2,0,0,65,111,110,57,108,0,0,0, +108,0,0,0,0,2,86,76,72,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,31,0,0,2,5,0,0,128, +0,0,15,144,31,0,0,2,5,0,1,128,1,0,15,144, +1,0,0,2,0,0,7,128,0,0,228,144,2,0,0,3, +0,0,7,224,0,0,228,128,1,0,228,144,1,0,0,2, +0,0,8,224,0,0,255,144,255,255,0,0,65,111,110,57, +120,0,0,0,120,0,0,0,0,2,80,76,84,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,31,0,0,2,0,0,0,128, +1,0,7,176,1,0,0,2,0,0,7,128,0,0,228,176, +2,0,0,3,0,0,7,128,0,0,228,128,1,0,228,176, +1,0,0,2,0,0,8,128,0,0,255,176,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +96,0,0,0,64,0,240,255,24,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,95,0,0,3,114,16,16,0, +1,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +0,0,0,7,114,32,16,0,0,0,0,0,70,18,16,0, +0,0,0,0,70,18,16,0,1,0,0,0,54,0,0,5, +130,32,16,0,0,0,0,0,58,16,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,3,0,0,0, +0,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,108,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +60,0,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,171,171,76,70,83,48,172,0,0,0,3,0,0,0, +8,0,0,0,152,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,160,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,164,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,65,100,100,83,112,101,99,0,99,111,108,0, +115,112,101,99,0,171,171,171,76,73,66,70,16,3,0,0, +68,88,66,67,32,99,27,168,13,179,154,91,100,39,27,10, +175,105,117,37,1,0,0,0,16,3,0,0,6,0,0,0, +56,0,0,0,156,0,0,0,12,1,0,0,108,1,0,0, +232,1,0,0,92,2,0,0,65,111,110,57,92,0,0,0, +92,0,0,0,0,2,86,76,56,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,86,76,31,0,0,2,5,0,0,128, +0,0,15,144,31,0,0,2,5,0,1,128,1,0,15,144, +1,0,0,2,0,0,7,224,0,0,228,144,1,0,0,2, +0,0,8,224,1,0,255,144,255,255,0,0,65,111,110,57, +104,0,0,0,104,0,0,0,0,2,80,76,68,0,0,0, +36,0,0,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,0,36,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,7,176,31,0,0,2,0,0,0,128, +1,0,8,176,1,0,0,2,0,0,7,128,0,0,228,176, +1,0,0,2,0,0,8,128,1,0,255,176,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +88,0,0,0,64,0,240,255,22,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,95,0,0,3,130,16,16,0, +1,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +54,0,0,5,114,32,16,0,0,0,0,0,70,18,16,0, +0,0,0,0,54,0,0,5,130,32,16,0,0,0,0,0, +58,16,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,108,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,60,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +172,0,0,0,3,0,0,0,8,0,0,0,152,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,165,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,167,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,67,111,109,98, +105,110,101,65,108,112,104,97,0,99,0,97,0,171,171,171, +76,73,66,70,240,7,0,0,68,88,66,67,140,46,150,255, +109,51,190,32,65,61,106,69,213,176,193,187,1,0,0,0, +240,7,0,0,6,0,0,0,56,0,0,0,248,0,0,0, +140,1,0,0,44,2,0,0,168,2,0,0,108,7,0,0, +65,111,110,57,184,0,0,0,184,0,0,0,0,2,86,76, +136,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,62,0, +1,0,0,0,0,0,0,0,0,2,86,76,81,0,0,5, +1,0,15,160,0,0,0,0,0,0,128,63,0,0,0,0, +0,0,0,0,31,0,0,2,5,0,0,128,0,0,15,144, +8,0,0,3,0,0,1,128,0,0,228,144,0,0,228,144, +7,0,0,2,0,0,1,128,0,0,0,128,6,0,0,2, +0,0,1,128,0,0,0,128,4,0,0,4,0,0,1,128, +0,0,0,128,0,0,170,160,0,0,255,160,11,0,0,3, +0,0,1,128,0,0,0,128,1,0,0,160,10,0,0,3, +0,0,1,224,0,0,0,128,1,0,85,160,255,255,0,0, +65,111,110,57,140,0,0,0,140,0,0,0,0,2,80,76, +92,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,62,0, +1,0,0,0,0,0,0,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,7,176,8,0,0,3,0,0,8,128, +0,0,228,176,0,0,228,176,7,0,0,2,0,0,1,128, +0,0,255,128,6,0,0,2,0,0,1,128,0,0,0,128, +4,0,0,4,0,0,17,128,0,0,0,128,0,0,170,160, +0,0,255,160,1,0,0,2,0,0,1,224,0,0,0,128, +255,255,0,0,83,72,68,82,152,0,0,0,64,0,240,255, +38,0,0,0,89,0,0,4,70,142,32,0,0,0,0,0, +63,0,0,0,95,0,0,3,114,16,16,0,0,0,0,0, +101,0,0,3,18,32,16,0,0,0,0,0,104,0,0,2, +1,0,0,0,16,0,0,7,18,0,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,18,16,0,0,0,0,0, +75,0,0,5,18,0,16,0,0,0,0,0,10,0,16,0, +0,0,0,0,50,32,0,11,18,32,16,0,0,0,0,0, +10,0,16,0,0,0,0,0,42,128,32,0,0,0,0,0, +62,0,0,0,58,128,32,0,0,0,0,0,62,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,3,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,188,4,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +142,4,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,86,101,114,116,101, +120,0,171,171,92,0,0,0,14,0,0,0,132,0,0,0, +240,3,0,0,0,0,0,0,0,0,0,0,180,2,0,0, +0,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,240,2,0,0,64,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,253,2,0,0, +128,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,3,0,0,144,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,71,3,0,0, +160,0,0,0,128,0,0,0,0,0,0,0,88,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,124,3,0,0,32,1,0,0,128,0,0,0, +0,0,0,0,140,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,176,3,0,0, +160,1,0,0,128,0,0,0,0,0,0,0,192,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,228,3,0,0,32,2,0,0,128,0,0,0, +0,0,0,0,244,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,24,4,0,0, +160,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,39,4,0,0,176,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,54,4,0,0, +192,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,66,4,0,0,208,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,82,4,0,0, +224,2,0,0,0,1,0,0,0,0,0,0,96,4,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,132,4,0,0,224,3,0,0,16,0,0,0, +2,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,112,0,102,108,111,97,116,52, +120,52,0,171,3,0,3,0,4,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,0,102,102,95,118,101,99,95,99,111,108,111, +114,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,118,101,99,95,97,109,98,105,101,110,116,0,102, +102,95,108,105,103,104,116,95,99,111,108,111,114,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,112,111,115, +0,171,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,97,116,116,101,110,0,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,115,112,111,116,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,109,97,116,95,100,105,102,102,117,115,101,0,102, +102,95,109,97,116,95,97,109,98,105,101,110,116,0,102,102, +95,109,97,116,95,115,112,101,99,0,102,102,95,109,97,116, +95,101,109,105,115,115,105,111,110,0,102,102,95,109,97,116, +114,105,120,95,116,101,120,0,3,0,3,0,4,0,4,0, +4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,102, +111,103,95,118,115,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,124,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,114,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,70,111,103,76,105,110,101,97,114,0,101,121, +101,80,111,115,0,171,171,171,76,73,66,70,20,8,0,0, +68,88,66,67,214,169,140,84,231,146,163,76,182,11,101,69, +234,130,85,253,1,0,0,0,20,8,0,0,6,0,0,0, +56,0,0,0,240,0,0,0,140,1,0,0,84,2,0,0, +208,2,0,0,148,7,0,0,65,111,110,57,176,0,0,0, +176,0,0,0,0,2,86,76,128,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,0,0,62,0,1,0,0,0,0,0,0,0, +0,2,86,76,81,0,0,5,1,0,15,160,0,0,128,63, +0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,2, +5,0,0,128,0,0,15,144,8,0,0,3,0,0,1,128, +0,0,228,144,0,0,228,144,7,0,0,2,0,0,1,128, +0,0,0,128,6,0,0,2,0,0,1,128,0,0,0,128, +5,0,0,3,0,0,1,128,0,0,0,128,0,0,85,160, +14,0,0,2,0,0,1,128,0,0,0,129,10,0,0,3, +0,0,1,224,0,0,0,128,1,0,0,160,255,255,0,0, +65,111,110,57,148,0,0,0,148,0,0,0,0,2,80,76, +100,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,0,0,62,0, +1,0,0,0,0,0,0,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,7,176,8,0,0,3,0,0,8,128, +0,0,228,176,0,0,228,176,7,0,0,2,0,0,1,128, +0,0,255,128,6,0,0,2,0,0,1,128,0,0,0,128, +5,0,0,3,0,0,1,128,0,0,0,128,0,0,85,160, +14,0,0,2,0,0,17,128,0,0,0,129,1,0,0,2, +0,0,1,224,0,0,0,128,255,255,0,0,83,72,68,82, +192,0,0,0,64,0,240,255,48,0,0,0,89,0,0,4, +70,142,32,0,0,0,0,0,63,0,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,18,32,16,0, +0,0,0,0,104,0,0,2,1,0,0,0,16,0,0,7, +18,0,16,0,0,0,0,0,70,18,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,75,0,0,5,18,0,16,0, +0,0,0,0,10,0,16,0,0,0,0,0,56,0,0,8, +18,0,16,0,0,0,0,0,10,0,16,0,0,0,0,0, +26,128,32,0,0,0,0,0,62,0,0,0,25,0,0,6, +18,0,16,0,0,0,0,0,10,0,16,128,65,0,0,0, +0,0,0,0,51,0,0,7,18,32,16,0,0,0,0,0, +10,0,16,0,0,0,0,0,1,64,0,0,0,0,128,63, +62,0,0,1,83,84,65,84,116,0,0,0,6,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,5,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,188,4,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +142,4,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,86,101,114,116,101, +120,0,171,171,92,0,0,0,14,0,0,0,132,0,0,0, +240,3,0,0,0,0,0,0,0,0,0,0,180,2,0,0, +0,0,0,0,64,0,0,0,0,0,0,0,204,2,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,240,2,0,0,64,0,0,0,64,0,0,0, +0,0,0,0,204,2,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,253,2,0,0, +128,0,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,3,0,0,144,0,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,71,3,0,0, +160,0,0,0,128,0,0,0,0,0,0,0,88,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,124,3,0,0,32,1,0,0,128,0,0,0, +0,0,0,0,140,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,176,3,0,0, +160,1,0,0,128,0,0,0,0,0,0,0,192,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,228,3,0,0,32,2,0,0,128,0,0,0, +0,0,0,0,244,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,24,4,0,0, +160,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,39,4,0,0,176,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,54,4,0,0, +192,2,0,0,16,0,0,0,0,0,0,0,20,3,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,66,4,0,0,208,2,0,0,16,0,0,0, +0,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,82,4,0,0, +224,2,0,0,0,1,0,0,0,0,0,0,96,4,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,132,4,0,0,224,3,0,0,16,0,0,0, +2,0,0,0,20,3,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,112,0,102,108,111,97,116,52, +120,52,0,171,3,0,3,0,4,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,194,2,0,0,102,102,95,109,97,116,114,105, +120,95,109,118,0,102,102,95,118,101,99,95,99,111,108,111, +114,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,118,101,99,95,97,109,98,105,101,110,116,0,102, +102,95,108,105,103,104,116,95,99,111,108,111,114,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,108,105,103,104,116,95,112,111,115, +0,171,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,97,116,116,101,110,0,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,115,112,111,116,0,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,109,97,116,95,100,105,102,102,117,115,101,0,102, +102,95,109,97,116,95,97,109,98,105,101,110,116,0,102,102, +95,109,97,116,95,115,112,101,99,0,102,102,95,109,97,116, +95,101,109,105,115,115,105,111,110,0,102,102,95,109,97,116, +114,105,120,95,116,101,120,0,3,0,3,0,4,0,4,0, +4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,102, +111,103,95,118,115,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,120,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,111,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,70,111,103,69,120,112,0,101,121,101,80,111, +115,0,171,171,76,73,66,70,12,8,0,0,68,88,66,67, +220,44,237,65,218,78,106,179,241,49,18,96,157,132,44,139, +1,0,0,0,12,8,0,0,6,0,0,0,56,0,0,0, +216,0,0,0,132,1,0,0,76,2,0,0,200,2,0,0, +140,7,0,0,65,111,110,57,152,0,0,0,152,0,0,0, +0,2,86,76,104,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +0,0,62,0,1,0,0,0,0,0,0,0,0,2,86,76, +31,0,0,2,5,0,0,128,0,0,15,144,8,0,0,3, +0,0,1,128,0,0,228,144,0,0,228,144,7,0,0,2, +0,0,1,128,0,0,0,128,6,0,0,2,0,0,1,128, +0,0,0,128,5,0,0,3,0,0,1,128,0,0,0,128, +0,0,85,160,5,0,0,3,0,0,1,128,0,0,0,128, +0,0,0,129,14,0,0,2,0,0,1,224,0,0,0,128, +255,255,0,0,65,111,110,57,164,0,0,0,164,0,0,0, +0,2,80,76,116,0,0,0,48,0,0,0,1,0,36,0, +0,0,48,0,0,0,48,0,0,0,36,0,0,0,48,0, +0,0,62,0,1,0,0,0,0,0,0,0,0,2,80,76, +31,0,0,2,0,0,0,128,0,0,7,176,8,0,0,3, +0,0,8,128,0,0,228,176,0,0,228,176,7,0,0,2, +0,0,1,128,0,0,255,128,6,0,0,2,0,0,1,128, +0,0,0,128,5,0,0,3,0,0,1,128,0,0,0,128, +0,0,85,160,5,0,0,3,0,0,1,128,0,0,0,128, +0,0,0,129,14,0,0,2,0,0,1,128,0,0,0,128, +1,0,0,2,0,0,1,224,0,0,0,128,255,255,0,0, +83,72,68,82,192,0,0,0,64,0,240,255,48,0,0,0, +89,0,0,4,70,142,32,0,0,0,0,0,63,0,0,0, +95,0,0,3,114,16,16,0,0,0,0,0,101,0,0,3, +18,32,16,0,0,0,0,0,104,0,0,2,1,0,0,0, +16,0,0,7,18,0,16,0,0,0,0,0,70,18,16,0, +0,0,0,0,70,18,16,0,0,0,0,0,75,0,0,5, +18,0,16,0,0,0,0,0,10,0,16,0,0,0,0,0, +56,0,0,8,18,0,16,0,0,0,0,0,10,0,16,0, +0,0,0,0,26,128,32,0,0,0,0,0,62,0,0,0, +56,0,0,8,18,0,16,0,0,0,0,0,10,0,16,0, +0,0,0,0,10,0,16,128,65,0,0,0,0,0,0,0, +25,0,0,5,18,32,16,0,0,0,0,0,10,0,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +6,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0, +5,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,188,4,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,142,4,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,86, +101,114,116,101,120,0,171,171,92,0,0,0,14,0,0,0, +132,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0, +180,2,0,0,0,0,0,0,64,0,0,0,0,0,0,0, +204,2,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,240,2,0,0,64,0,0,0, +64,0,0,0,0,0,0,0,204,2,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +253,2,0,0,128,0,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,3,0,0,144,0,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +71,3,0,0,160,0,0,0,128,0,0,0,0,0,0,0, +88,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,124,3,0,0,32,1,0,0, +128,0,0,0,0,0,0,0,140,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +176,3,0,0,160,1,0,0,128,0,0,0,0,0,0,0, +192,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,228,3,0,0,32,2,0,0, +128,0,0,0,0,0,0,0,244,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +24,4,0,0,160,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,39,4,0,0,176,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +54,4,0,0,192,2,0,0,16,0,0,0,0,0,0,0, +20,3,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,66,4,0,0,208,2,0,0, +16,0,0,0,0,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +82,4,0,0,224,2,0,0,0,1,0,0,0,0,0,0, +96,4,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,132,4,0,0,224,3,0,0, +16,0,0,0,2,0,0,0,20,3,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +102,102,95,109,97,116,114,105,120,95,109,118,112,0,102,108, +111,97,116,52,120,52,0,171,3,0,3,0,4,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,194,2,0,0,102,102,95,109, +97,116,114,105,120,95,109,118,0,102,102,95,118,101,99,95, +99,111,108,111,114,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,118,101,99,95,97,109,98,105,101, +110,116,0,102,102,95,108,105,103,104,116,95,99,111,108,111, +114,0,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,3,0,0,102,102,95,108,105,103,104,116, +95,112,111,115,0,171,171,171,1,0,3,0,1,0,4,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,3,0,0,102,102,95,108, +105,103,104,116,95,97,116,116,101,110,0,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,3,0,0, +102,102,95,108,105,103,104,116,95,115,112,111,116,0,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,3,0,0,102,102,95,109,97,116,95,100,105,102,102,117, +115,101,0,102,102,95,109,97,116,95,97,109,98,105,101,110, +116,0,102,102,95,109,97,116,95,115,112,101,99,0,102,102, +95,109,97,116,95,101,109,105,115,115,105,111,110,0,102,102, +95,109,97,116,114,105,120,95,116,101,120,0,3,0,3,0, +4,0,4,0,4,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,194,2,0,0, +102,102,95,102,111,103,95,118,115,0,77,105,99,114,111,115, +111,102,116,32,40,82,41,32,72,76,83,76,32,83,104,97, +100,101,114,32,67,111,109,112,105,108,101,114,32,54,46,51, +46,57,52,49,53,46,48,0,76,70,83,48,120,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,112,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,3,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,70,111,103,69,120,112,50,0, +101,121,101,80,111,115,0,171,76,73,66,70,12,5,0,0, +68,88,66,67,43,165,60,118,238,80,194,137,137,145,19,237, +8,42,67,215,1,0,0,0,12,5,0,0,6,0,0,0, +56,0,0,0,192,0,0,0,84,1,0,0,4,2,0,0, +128,2,0,0,88,4,0,0,65,111,110,57,128,0,0,0, +128,0,0,0,0,2,86,76,80,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,9,0,1,0,0,0,0,0,0,0, +0,2,86,76,31,0,0,2,5,0,0,128,0,0,15,144, +31,0,0,2,5,0,1,128,1,0,15,144,2,0,0,3, +0,0,7,128,0,0,228,144,0,0,228,161,4,0,0,4, +0,0,7,224,1,0,0,144,0,0,228,128,0,0,228,160, +1,0,0,2,0,0,8,224,0,0,255,144,255,255,0,0, +65,111,110,57,140,0,0,0,140,0,0,0,0,2,80,76, +92,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,1,0,9,0, +1,0,0,0,0,0,0,0,0,2,80,76,31,0,0,2, +0,0,0,128,0,0,15,176,31,0,0,2,0,0,0,128, +1,0,1,176,2,0,0,3,0,0,7,128,0,0,228,176, +0,0,228,161,4,0,0,4,0,0,7,128,1,0,0,176, +0,0,228,128,0,0,228,160,1,0,0,2,0,0,8,128, +0,0,255,176,1,0,0,2,0,0,15,224,0,0,228,128, +255,255,0,0,83,72,68,82,168,0,0,0,64,0,240,255, +42,0,0,0,89,0,0,4,70,142,32,0,1,0,0,0, +10,0,0,0,95,0,0,3,242,16,16,0,0,0,0,0, +95,0,0,3,18,16,16,0,1,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,104,0,0,2,1,0,0,0, +0,0,0,9,114,0,16,0,0,0,0,0,70,18,16,0, +0,0,0,0,70,130,32,128,65,0,0,0,1,0,0,0, +9,0,0,0,50,0,0,10,114,32,16,0,0,0,0,0, +6,16,16,0,1,0,0,0,70,2,16,0,0,0,0,0, +70,130,32,0,1,0,0,0,9,0,0,0,54,0,0,5, +130,32,16,0,0,0,0,0,58,16,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,3,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,208,1,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +160,1,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,80,105,120,101,108, +0,171,171,171,92,0,0,0,3,0,0,0,132,0,0,0, +160,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0, +0,0,0,0,128,0,0,0,0,0,0,0,20,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,1,0,0,128,0,0,0,4,0,0,0, +0,0,0,0,76,1,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,112,1,0,0, +144,0,0,0,16,0,0,0,2,0,0,0,124,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,118,101,99,95,99,111,108,111,114, +115,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,1,0,0, +102,102,95,97,108,112,104,97,95,114,101,102,0,102,108,111, +97,116,0,171,0,0,3,0,1,0,1,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,69,1,0,0,102,102,95,102,111,103,95,112, +115,0,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,1,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,172,0,0,0, +3,0,0,0,8,0,0,0,152,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,161,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,165,0,0,0,0,0,0,0, +3,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,65,112,112,108,121,70,111,103, +0,99,111,108,0,105,102,111,103,0,171,171,76,73,66,70, +120,2,0,0,68,88,66,67,228,129,43,236,118,165,218,53, +151,25,162,98,135,202,141,31,1,0,0,0,120,2,0,0, +5,0,0,0,52,0,0,0,184,0,0,0,4,1,0,0, +128,1,0,0,244,1,0,0,65,111,110,57,124,0,0,0, +124,0,0,0,0,2,80,76,88,0,0,0,36,0,0,0, +0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0, +0,0,36,0,0,2,80,76,81,0,0,5,0,0,15,160, +0,0,128,191,0,0,0,0,0,0,0,0,0,0,0,0, +31,0,0,2,0,0,0,128,0,0,15,176,1,0,0,2, +0,0,15,128,0,0,0,160,65,0,0,1,0,0,15,128, +1,0,0,2,0,0,15,128,0,0,228,176,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +68,0,0,0,64,0,240,255,17,0,0,0,95,0,0,3, +242,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,13,0,4,3,1,64,0,0,255,255,255,255, +54,0,0,5,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,108,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,60,0,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,124,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,119,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,65,108,112,104,97,84,101,115, +116,78,101,118,101,114,0,99,111,108,0,171,76,73,66,70, +56,4,0,0,68,88,66,67,217,165,212,19,118,106,154,93, +60,2,230,192,32,38,222,58,1,0,0,0,56,4,0,0, +5,0,0,0,52,0,0,0,220,0,0,0,96,1,0,0, +220,1,0,0,180,3,0,0,65,111,110,57,160,0,0,0, +160,0,0,0,0,2,80,76,112,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,8,0,1,0,0,0,0,0,0,0, +0,2,80,76,81,0,0,5,1,0,15,160,0,0,128,191, +0,0,0,128,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,15,176,2,0,0,3,0,0,8,128, +0,0,255,176,0,0,0,161,88,0,0,4,0,0,15,128, +0,0,255,128,1,0,0,160,1,0,85,160,65,0,0,1, +0,0,15,128,1,0,0,2,0,0,15,128,0,0,228,176, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,124,0,0,0,64,0,240,255,31,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,9,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,104,0,0,2,1,0,0,0, +29,0,0,8,18,0,16,0,0,0,0,0,58,16,16,0, +0,0,0,0,10,128,32,0,1,0,0,0,8,0,0,0, +13,0,4,3,10,0,16,0,0,0,0,0,54,0,0,5, +242,32,16,0,0,0,0,0,70,30,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,208,1,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +160,1,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,80,105,120,101,108, +0,171,171,171,92,0,0,0,3,0,0,0,132,0,0,0, +160,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0, +0,0,0,0,128,0,0,0,0,0,0,0,20,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,1,0,0,128,0,0,0,4,0,0,0, +2,0,0,0,76,1,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,112,1,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,124,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,118,101,99,95,99,111,108,111,114, +115,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,1,0,0, +102,102,95,97,108,112,104,97,95,114,101,102,0,102,108,111, +97,116,0,171,0,0,3,0,1,0,1,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,69,1,0,0,102,102,95,102,111,103,95,112, +115,0,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,1,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,124,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,118,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,65,108,112,104,97,84,101,115, +116,76,101,115,115,0,99,111,108,0,171,171,76,73,66,70, +72,4,0,0,68,88,66,67,9,212,183,148,40,9,204,128, +14,203,169,16,22,156,51,83,1,0,0,0,72,4,0,0, +5,0,0,0,52,0,0,0,236,0,0,0,112,1,0,0, +236,1,0,0,196,3,0,0,65,111,110,57,176,0,0,0, +176,0,0,0,0,2,80,76,128,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,8,0,1,0,0,0,0,0,0,0, +0,2,80,76,81,0,0,5,1,0,15,160,0,0,0,128, +0,0,128,191,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,15,176,2,0,0,3,0,0,8,128, +0,0,255,176,0,0,0,161,5,0,0,3,0,0,1,128, +0,0,255,128,0,0,255,128,88,0,0,4,0,0,15,128, +0,0,0,129,1,0,0,160,1,0,85,160,65,0,0,1, +0,0,15,128,1,0,0,2,0,0,15,128,0,0,228,176, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,124,0,0,0,64,0,240,255,31,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,9,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,104,0,0,2,1,0,0,0, +57,0,0,8,18,0,16,0,0,0,0,0,58,16,16,0, +0,0,0,0,10,128,32,0,1,0,0,0,8,0,0,0, +13,0,4,3,10,0,16,0,0,0,0,0,54,0,0,5, +242,32,16,0,0,0,0,0,70,30,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,208,1,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +160,1,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,80,105,120,101,108, +0,171,171,171,92,0,0,0,3,0,0,0,132,0,0,0, +160,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0, +0,0,0,0,128,0,0,0,0,0,0,0,20,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,1,0,0,128,0,0,0,4,0,0,0, +2,0,0,0,76,1,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,112,1,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,124,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,118,101,99,95,99,111,108,111,114, +115,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,1,0,0, +102,102,95,97,108,112,104,97,95,114,101,102,0,102,108,111, +97,116,0,171,0,0,3,0,1,0,1,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,69,1,0,0,102,102,95,102,111,103,95,112, +115,0,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,1,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,124,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,119,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,65,108,112,104,97,84,101,115, +116,69,113,117,97,108,0,99,111,108,0,171,76,73,66,70, +56,4,0,0,68,88,66,67,49,14,159,37,228,78,150,41, +132,60,204,137,11,50,70,216,1,0,0,0,56,4,0,0, +5,0,0,0,52,0,0,0,220,0,0,0,96,1,0,0, +220,1,0,0,180,3,0,0,65,111,110,57,160,0,0,0, +160,0,0,0,0,2,80,76,112,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,8,0,1,0,0,0,0,0,0,0, +0,2,80,76,81,0,0,5,1,0,15,160,0,0,0,128, +0,0,128,191,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,15,176,2,0,0,3,0,0,8,128, +0,0,255,177,0,0,0,160,88,0,0,4,0,0,15,128, +0,0,255,128,1,0,0,160,1,0,85,160,65,0,0,1, +0,0,15,128,1,0,0,2,0,0,15,128,0,0,228,176, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,124,0,0,0,64,0,240,255,31,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,9,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,104,0,0,2,1,0,0,0, +49,0,0,8,18,0,16,0,0,0,0,0,10,128,32,0, +1,0,0,0,8,0,0,0,58,16,16,0,0,0,0,0, +13,0,4,3,10,0,16,0,0,0,0,0,54,0,0,5, +242,32,16,0,0,0,0,0,70,30,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,208,1,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +160,1,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,80,105,120,101,108, +0,171,171,171,92,0,0,0,3,0,0,0,132,0,0,0, +160,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0, +0,0,0,0,128,0,0,0,0,0,0,0,20,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,1,0,0,128,0,0,0,4,0,0,0, +2,0,0,0,76,1,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,112,1,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,124,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,118,101,99,95,99,111,108,111,114, +115,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,1,0,0, +102,102,95,97,108,112,104,97,95,114,101,102,0,102,108,111, +97,116,0,171,0,0,3,0,1,0,1,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,69,1,0,0,102,102,95,102,111,103,95,112, +115,0,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,1,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,124,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,120,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,65,108,112,104,97,84,101,115, +116,76,69,113,117,97,108,0,99,111,108,0,76,73,66,70, +60,4,0,0,68,88,66,67,144,90,107,7,148,126,119,93, +47,65,200,242,161,144,148,20,1,0,0,0,60,4,0,0, +5,0,0,0,52,0,0,0,220,0,0,0,96,1,0,0, +220,1,0,0,180,3,0,0,65,111,110,57,160,0,0,0, +160,0,0,0,0,2,80,76,112,0,0,0,48,0,0,0, +1,0,36,0,0,0,48,0,0,0,48,0,0,0,36,0, +0,0,48,0,1,0,8,0,1,0,0,0,0,0,0,0, +0,2,80,76,81,0,0,5,1,0,15,160,0,0,128,191, +0,0,0,128,0,0,0,0,0,0,0,0,31,0,0,2, +0,0,0,128,0,0,15,176,2,0,0,3,0,0,8,128, +0,0,255,177,0,0,0,160,88,0,0,4,0,0,15,128, +0,0,255,128,1,0,0,160,1,0,85,160,65,0,0,1, +0,0,15,128,1,0,0,2,0,0,15,128,0,0,228,176, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,124,0,0,0,64,0,240,255,31,0,0,0, +89,0,0,4,70,142,32,0,1,0,0,0,9,0,0,0, +95,0,0,3,242,16,16,0,0,0,0,0,101,0,0,3, +242,32,16,0,0,0,0,0,104,0,0,2,1,0,0,0, +29,0,0,8,18,0,16,0,0,0,0,0,10,128,32,0, +1,0,0,0,8,0,0,0,58,16,16,0,0,0,0,0, +13,0,4,3,10,0,16,0,0,0,0,0,54,0,0,5, +242,32,16,0,0,0,0,0,70,30,16,0,0,0,0,0, +62,0,0,1,83,84,65,84,116,0,0,0,4,0,0,0, +1,0,0,0,0,0,0,0,2,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +82,68,69,70,208,1,0,0,1,0,0,0,108,0,0,0, +1,0,0,0,60,0,0,0,0,4,70,76,0,129,0,0, +160,1,0,0,82,68,49,49,60,0,0,0,24,0,0,0, +32,0,0,0,40,0,0,0,36,0,0,0,12,0,0,0, +0,0,0,0,92,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0, +0,0,0,0,85,110,105,116,121,70,70,80,105,120,101,108, +0,171,171,171,92,0,0,0,3,0,0,0,132,0,0,0, +160,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0, +0,0,0,0,128,0,0,0,0,0,0,0,20,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,56,1,0,0,128,0,0,0,4,0,0,0, +2,0,0,0,76,1,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,112,1,0,0, +144,0,0,0,16,0,0,0,0,0,0,0,124,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,102,102,95,118,101,99,95,99,111,108,111,114, +115,0,102,108,111,97,116,52,0,171,171,171,1,0,3,0, +1,0,4,0,8,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,1,0,0, +102,102,95,97,108,112,104,97,95,114,101,102,0,102,108,111, +97,116,0,171,0,0,3,0,1,0,1,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,69,1,0,0,102,102,95,102,111,103,95,112, +115,0,171,171,1,0,3,0,1,0,4,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,1,0,0,77,105,99,114,111,115,111,102, +116,32,40,82,41,32,72,76,83,76,32,83,104,97,100,101, +114,32,67,111,109,112,105,108,101,114,32,54,46,51,46,57, +52,49,53,46,48,0,171,171,76,70,83,48,128,0,0,0, +2,0,0,0,8,0,0,0,104,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,2,0,0,0,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,121,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,4,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,65,108,112,104,97,84,101,115, +116,71,114,101,97,116,101,114,0,99,111,108,0,171,171,171, +76,73,66,70,76,4,0,0,68,88,66,67,197,56,7,226, +68,202,40,47,130,164,2,187,83,69,103,33,1,0,0,0, +76,4,0,0,5,0,0,0,52,0,0,0,236,0,0,0, +112,1,0,0,236,1,0,0,196,3,0,0,65,111,110,57, +176,0,0,0,176,0,0,0,0,2,80,76,128,0,0,0, +48,0,0,0,1,0,36,0,0,0,48,0,0,0,48,0, +0,0,36,0,0,0,48,0,1,0,8,0,1,0,0,0, +0,0,0,0,0,2,80,76,81,0,0,5,1,0,15,160, +0,0,128,191,0,0,0,128,0,0,0,0,0,0,0,0, +31,0,0,2,0,0,0,128,0,0,15,176,2,0,0,3, +0,0,8,128,0,0,255,176,0,0,0,161,5,0,0,3, +0,0,1,128,0,0,255,128,0,0,255,128,88,0,0,4, +0,0,15,128,0,0,0,129,1,0,0,160,1,0,85,160, +65,0,0,1,0,0,15,128,1,0,0,2,0,0,15,128, +0,0,228,176,1,0,0,2,0,0,15,224,0,0,228,128, +255,255,0,0,83,72,68,82,124,0,0,0,64,0,240,255, +31,0,0,0,89,0,0,4,70,142,32,0,1,0,0,0, +9,0,0,0,95,0,0,3,242,16,16,0,0,0,0,0, +101,0,0,3,242,32,16,0,0,0,0,0,104,0,0,2, +1,0,0,0,24,0,0,8,18,0,16,0,0,0,0,0, +58,16,16,0,0,0,0,0,10,128,32,0,1,0,0,0, +8,0,0,0,13,0,4,3,10,0,16,0,0,0,0,0, +54,0,0,5,242,32,16,0,0,0,0,0,70,30,16,0, +0,0,0,0,62,0,0,1,83,84,65,84,116,0,0,0, +4,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,82,68,69,70,208,1,0,0,1,0,0,0, +108,0,0,0,1,0,0,0,60,0,0,0,0,4,70,76, +0,129,0,0,160,1,0,0,82,68,49,49,60,0,0,0, +24,0,0,0,32,0,0,0,40,0,0,0,36,0,0,0, +12,0,0,0,0,0,0,0,92,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +1,0,0,0,0,0,0,0,85,110,105,116,121,70,70,80, +105,120,101,108,0,171,171,171,92,0,0,0,3,0,0,0, +132,0,0,0,160,0,0,0,0,0,0,0,0,0,0,0, +252,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0, +20,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,56,1,0,0,128,0,0,0, +4,0,0,0,2,0,0,0,76,1,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0, +112,1,0,0,144,0,0,0,16,0,0,0,0,0,0,0, +124,1,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +255,255,255,255,0,0,0,0,102,102,95,118,101,99,95,99, +111,108,111,114,115,0,102,108,111,97,116,52,0,171,171,171, +1,0,3,0,1,0,4,0,8,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +10,1,0,0,102,102,95,97,108,112,104,97,95,114,101,102, +0,102,108,111,97,116,0,171,0,0,3,0,1,0,1,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,69,1,0,0,102,102,95,102, +111,103,95,112,115,0,171,171,1,0,3,0,1,0,4,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,10,1,0,0,77,105,99,114, +111,115,111,102,116,32,40,82,41,32,72,76,83,76,32,83, +104,97,100,101,114,32,67,111,109,112,105,108,101,114,32,54, +46,51,46,57,52,49,53,46,48,0,171,171,76,70,83,48, +128,0,0,0,2,0,0,0,8,0,0,0,104,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,2,0,0,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,122,0,0,0, +0,0,0,0,3,0,0,0,1,0,0,0,1,0,0,0, +4,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,255,255,255,255,255,255,255,255,65,108,112,104, +97,84,101,115,116,78,111,116,69,113,117,97,108,0,99,111, +108,0,171,171,76,73,66,70,56,4,0,0,68,88,66,67, +115,13,35,167,25,6,43,221,107,197,197,253,203,93,251,92, +1,0,0,0,56,4,0,0,5,0,0,0,52,0,0,0, +220,0,0,0,96,1,0,0,220,1,0,0,180,3,0,0, +65,111,110,57,160,0,0,0,160,0,0,0,0,2,80,76, +112,0,0,0,48,0,0,0,1,0,36,0,0,0,48,0, +0,0,48,0,0,0,36,0,0,0,48,0,1,0,8,0, +1,0,0,0,0,0,0,0,0,2,80,76,81,0,0,5, +1,0,15,160,0,0,0,128,0,0,128,191,0,0,0,0, +0,0,0,0,31,0,0,2,0,0,0,128,0,0,15,176, +2,0,0,3,0,0,8,128,0,0,255,176,0,0,0,161, +88,0,0,4,0,0,15,128,0,0,255,128,1,0,0,160, +1,0,85,160,65,0,0,1,0,0,15,128,1,0,0,2, +0,0,15,128,0,0,228,176,1,0,0,2,0,0,15,224, +0,0,228,128,255,255,0,0,83,72,68,82,124,0,0,0, +64,0,240,255,31,0,0,0,89,0,0,4,70,142,32,0, +1,0,0,0,9,0,0,0,95,0,0,3,242,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,49,0,0,8,18,0,16,0, +0,0,0,0,58,16,16,0,0,0,0,0,10,128,32,0, +1,0,0,0,8,0,0,0,13,0,4,3,10,0,16,0, +0,0,0,0,54,0,0,5,242,32,16,0,0,0,0,0, +70,30,16,0,0,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,4,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,208,1,0,0, +1,0,0,0,108,0,0,0,1,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,160,1,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,92,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,0,0,0,0,85,110,105,116, +121,70,70,80,105,120,101,108,0,171,171,171,92,0,0,0, +3,0,0,0,132,0,0,0,160,0,0,0,0,0,0,0, +0,0,0,0,252,0,0,0,0,0,0,0,128,0,0,0, +0,0,0,0,20,1,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,56,1,0,0, +128,0,0,0,4,0,0,0,2,0,0,0,76,1,0,0, +0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255, +0,0,0,0,112,1,0,0,144,0,0,0,16,0,0,0, +0,0,0,0,124,1,0,0,0,0,0,0,255,255,255,255, +0,0,0,0,255,255,255,255,0,0,0,0,102,102,95,118, +101,99,95,99,111,108,111,114,115,0,102,108,111,97,116,52, +0,171,171,171,1,0,3,0,1,0,4,0,8,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,10,1,0,0,102,102,95,97,108,112,104,97, +95,114,101,102,0,102,108,111,97,116,0,171,0,0,3,0, +1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,69,1,0,0, +102,102,95,102,111,103,95,112,115,0,171,171,1,0,3,0, +1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,10,1,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,171,171, +76,70,83,48,124,0,0,0,2,0,0,0,8,0,0,0, +104,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0, +255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0, +120,0,0,0,0,0,0,0,3,0,0,0,1,0,0,0, +1,0,0,0,4,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +65,108,112,104,97,84,101,115,116,71,69,113,117,97,108,0, +99,111,108,0,76,73,66,72,137,7,0,0,1,0,0,0, +164,2,0,0,0,0,0,0,82,0,0,0,20,0,0,0, +3,0,0,0,210,2,0,0,3,0,0,0,226,2,0,0, +3,0,0,0,249,2,0,0,3,0,0,0,4,3,0,0, +3,0,0,0,18,3,0,0,3,0,0,0,27,3,0,0, +3,0,0,0,39,3,0,0,3,0,0,0,51,3,0,0, +3,0,0,0,68,3,0,0,3,0,0,0,85,3,0,0, +3,0,0,0,103,3,0,0,3,0,0,0,118,3,0,0, +3,0,0,0,136,3,0,0,3,0,0,0,158,3,0,0, +3,0,0,0,176,3,0,0,3,0,0,0,198,3,0,0, +1,0,0,0,216,3,0,0,1,0,0,0,238,3,0,0, +1,0,0,0,0,4,0,0,1,0,0,0,22,4,0,0, +1,0,0,0,40,4,0,0,1,0,0,0,62,4,0,0, +1,0,0,0,80,4,0,0,1,0,0,0,102,4,0,0, +1,0,0,0,120,4,0,0,1,0,0,0,142,4,0,0, +1,0,0,0,160,4,0,0,1,0,0,0,182,4,0,0, +1,0,0,0,200,4,0,0,3,0,0,0,222,4,0,0, +3,0,0,0,240,4,0,0,3,0,0,0,0,5,0,0, +3,0,0,0,10,5,0,0,3,0,0,0,20,5,0,0, +3,0,0,0,26,5,0,0,3,0,0,0,39,5,0,0, +3,0,0,0,51,5,0,0,3,0,0,0,63,5,0,0, +3,0,0,0,75,5,0,0,3,0,0,0,87,5,0,0, +3,0,0,0,99,5,0,0,3,0,0,0,111,5,0,0, +3,0,0,0,123,5,0,0,3,0,0,0,135,5,0,0, +3,0,0,0,147,5,0,0,3,0,0,0,157,5,0,0, +3,0,0,0,176,5,0,0,3,0,0,0,195,5,0,0, +3,0,0,0,214,5,0,0,3,0,0,0,233,5,0,0, +3,0,0,0,252,5,0,0,3,0,0,0,15,6,0,0, +3,0,0,0,34,6,0,0,3,0,0,0,53,6,0,0, +3,0,0,0,63,6,0,0,3,0,0,0,73,6,0,0, +3,0,0,0,83,6,0,0,3,0,0,0,95,6,0,0, +3,0,0,0,108,6,0,0,3,0,0,0,116,6,0,0, +3,0,0,0,130,6,0,0,3,0,0,0,143,6,0,0, +3,0,0,0,152,6,0,0,3,0,0,0,161,6,0,0, +3,0,0,0,174,6,0,0,3,0,0,0,185,6,0,0, +3,0,0,0,196,6,0,0,3,0,0,0,213,6,0,0, +3,0,0,0,220,6,0,0,3,0,0,0,227,6,0,0, +3,0,0,0,235,6,0,0,3,0,0,0,248,6,0,0, +3,0,0,0,2,7,0,0,3,0,0,0,9,7,0,0, +3,0,0,0,17,7,0,0,2,0,0,0,26,7,0,0, +2,0,0,0,41,7,0,0,2,0,0,0,55,7,0,0, +2,0,0,0,70,7,0,0,2,0,0,0,86,7,0,0, +2,0,0,0,103,7,0,0,2,0,0,0,121,7,0,0, +77,105,99,114,111,115,111,102,116,32,40,82,41,32,72,76, +83,76,32,83,104,97,100,101,114,32,67,111,109,112,105,108, +101,114,32,54,46,51,46,57,52,49,53,46,48,0,76,111, +97,100,86,101,114,116,101,120,67,111,108,111,114,0,76,111, +97,100,86,101,114,116,101,120,67,111,108,111,114,85,110,105, +102,111,114,109,0,76,111,97,100,69,121,101,80,111,115,0, +76,111,97,100,69,121,101,78,111,114,109,97,108,0,76,111, +97,100,90,101,114,111,0,76,111,97,100,86,105,101,119,68, +105,114,0,76,111,97,100,69,121,101,82,101,102,108,0,76, +111,97,100,65,109,98,105,101,110,116,67,111,108,111,114,0, +76,111,97,100,68,105,102,102,117,115,101,67,111,108,111,114, +0,76,111,97,100,69,109,105,115,115,105,111,110,67,111,108, +111,114,0,73,110,105,116,76,105,103,104,116,67,111,108,111, +114,0,67,111,109,112,117,116,101,83,112,111,116,76,105,103, +104,116,48,0,67,111,109,112,117,116,101,83,112,111,116,76, +105,103,104,116,83,112,101,99,48,0,67,111,109,112,117,116, +101,83,112,111,116,76,105,103,104,116,49,0,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,83,112,101,99, +49,0,67,111,109,112,117,116,101,83,112,111,116,76,105,103, +104,116,50,0,67,111,109,112,117,116,101,83,112,111,116,76, +105,103,104,116,83,112,101,99,50,0,67,111,109,112,117,116, +101,83,112,111,116,76,105,103,104,116,51,0,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,83,112,101,99, +51,0,67,111,109,112,117,116,101,83,112,111,116,76,105,103, +104,116,52,0,67,111,109,112,117,116,101,83,112,111,116,76, +105,103,104,116,83,112,101,99,52,0,67,111,109,112,117,116, +101,83,112,111,116,76,105,103,104,116,53,0,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,83,112,101,99, +53,0,67,111,109,112,117,116,101,83,112,111,116,76,105,103, +104,116,54,0,67,111,109,112,117,116,101,83,112,111,116,76, +105,103,104,116,83,112,101,99,54,0,67,111,109,112,117,116, +101,83,112,111,116,76,105,103,104,116,55,0,67,111,109,112, +117,116,101,83,112,111,116,76,105,103,104,116,83,112,101,99, +55,0,67,111,109,112,117,116,101,83,112,111,116,76,105,103, +104,116,56,0,67,111,109,112,117,116,101,83,112,111,116,76, +105,103,104,116,83,112,101,99,56,0,76,111,97,100,76,105, +103,104,116,105,110,103,67,111,108,111,114,0,84,114,97,110, +115,102,111,114,109,86,101,114,116,101,120,0,83,97,116,117, +114,97,116,101,52,0,83,97,116,117,114,97,116,101,51,0, +76,111,97,100,51,0,77,111,100,117,108,97,116,101,83,112, +101,99,0,77,117,108,116,105,112,108,121,85,86,48,0,77, +117,108,116,105,112,108,121,85,86,49,0,77,117,108,116,105, +112,108,121,85,86,50,0,77,117,108,116,105,112,108,121,85, +86,51,0,77,117,108,116,105,112,108,121,85,86,52,0,77, +117,108,116,105,112,108,121,85,86,53,0,77,117,108,116,105, +112,108,121,85,86,54,0,77,117,108,116,105,112,108,121,85, +86,55,0,85,86,83,112,104,101,114,101,77,97,112,0,70, +108,111,97,116,51,116,111,52,0,76,111,97,100,67,111,110, +115,116,97,110,116,67,111,108,111,114,48,0,76,111,97,100, +67,111,110,115,116,97,110,116,67,111,108,111,114,49,0,76, +111,97,100,67,111,110,115,116,97,110,116,67,111,108,111,114, +50,0,76,111,97,100,67,111,110,115,116,97,110,116,67,111, +108,111,114,51,0,76,111,97,100,67,111,110,115,116,97,110, +116,67,111,108,111,114,52,0,76,111,97,100,67,111,110,115, +116,97,110,116,67,111,108,111,114,53,0,76,111,97,100,67, +111,110,115,116,97,110,116,67,111,108,111,114,54,0,76,111, +97,100,67,111,110,115,116,97,110,116,67,111,108,111,114,55, +0,79,110,101,77,105,110,117,115,49,0,79,110,101,77,105, +110,117,115,51,0,79,110,101,77,105,110,117,115,52,0,67, +111,109,98,82,101,112,108,97,99,101,0,67,111,109,98,77, +111,100,117,108,97,116,101,0,67,111,109,98,65,100,100,0, +67,111,109,98,65,100,100,83,105,103,110,101,100,0,67,111, +109,98,83,117,98,116,114,97,99,116,0,67,111,109,98,76, +101,114,112,0,67,111,109,98,68,111,116,51,0,67,111,109, +98,68,111,116,51,114,103,98,97,0,67,111,109,98,77,117, +108,65,100,100,0,67,111,109,98,77,117,108,83,117,98,0, +67,111,109,98,77,117,108,65,100,100,83,105,103,110,101,100, +0,83,99,97,108,101,50,0,83,99,97,108,101,52,0,65, +100,100,83,112,101,99,0,67,111,109,98,105,110,101,65,108, +112,104,97,0,70,111,103,76,105,110,101,97,114,0,70,111, +103,69,120,112,0,70,111,103,69,120,112,50,0,65,112,112, +108,121,70,111,103,0,65,108,112,104,97,84,101,115,116,78, +101,118,101,114,0,65,108,112,104,97,84,101,115,116,76,101, +115,115,0,65,108,112,104,97,84,101,115,116,69,113,117,97, +108,0,65,108,112,104,97,84,101,115,116,76,69,113,117,97, +108,0,65,108,112,104,97,84,101,115,116,71,114,101,97,116, +101,114,0,65,108,112,104,97,84,101,115,116,78,111,116,69, +113,117,97,108,0,65,108,112,104,97,84,101,115,116,71,69, +113,117,97,108,0 +}; +const BYTE g_FFSampleTex2D0[] = { +68,88,66,67,186,190,133,217,122,113,117,157,223,22,77,225, +182,226,68,58,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,167,63,28,244,217,66,235,37,252,144,14,203, +197,4,28,142,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +0,0,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,0,0,0,0,88,24,0,4, +0,112,16,0,0,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,0,0,0,0, +0,96,16,0,0,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +0,0,0,0,1,0,0,0,13,0,0,0,83,109,112,48, +0,84,101,120,48,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,48,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,48,0 +}; +const BYTE g_FFSampleTex2D1[] = { +68,88,66,67,47,67,190,161,200,111,42,45,200,138,126,191, +157,88,130,65,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,254,4,120,248,75,193,95,168,115,4,59,237, +17,210,26,42,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +1,1,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,1,0,0,0,88,24,0,4, +0,112,16,0,1,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,1,0,0,0, +0,96,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +1,0,0,0,1,0,0,0,13,0,0,0,83,109,112,49, +0,84,101,120,49,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,49,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,49,0 +}; +const BYTE g_FFSampleTex2D2[] = { +68,88,66,67,180,208,133,71,201,51,63,167,99,13,252,147, +105,15,242,34,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,162,103,158,112,144,136,184,255,249,212,11,72, +140,25,192,113,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +2,2,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,2,0,0,0,88,24,0,4, +0,112,16,0,2,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,2,0,0,0, +0,96,16,0,2,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +2,0,0,0,1,0,0,0,13,0,0,0,83,109,112,50, +0,84,101,120,50,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,50,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,50,0 +}; +const BYTE g_FFSampleTex2D3[] = { +68,88,66,67,149,238,135,1,0,112,221,254,146,94,115,12, +68,5,172,135,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,196,71,209,198,86,237,243,139,237,193,9,14, +69,112,32,203,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +3,3,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,3,0,0,0,88,24,0,4, +0,112,16,0,3,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,3,0,0,0, +0,96,16,0,3,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +3,0,0,0,1,0,0,0,13,0,0,0,83,109,112,51, +0,84,101,120,51,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,51,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,51,0 +}; +const BYTE g_FFSampleTex2D4[] = { +68,88,66,67,1,143,168,112,164,72,178,93,61,206,79,16, +192,187,155,32,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,209,234,176,153,155,94,152,9,241,37,65,106, +131,216,55,96,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +4,4,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,4,0,0,0,88,24,0,4, +0,112,16,0,4,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,4,0,0,0, +0,96,16,0,4,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +4,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +4,0,0,0,1,0,0,0,13,0,0,0,83,109,112,52, +0,84,101,120,52,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,52,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,52,0 +}; +const BYTE g_FFSampleTex2D5[] = { +68,88,66,67,146,103,79,44,172,131,19,17,83,225,225,20, +193,21,8,43,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,121,249,154,239,231,85,182,236,126,123,45,2, +117,82,141,241,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +5,5,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,5,0,0,0,88,24,0,4, +0,112,16,0,5,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,5,0,0,0, +0,96,16,0,5,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +5,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +5,0,0,0,1,0,0,0,13,0,0,0,83,109,112,53, +0,84,101,120,53,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,53,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,53,0 +}; +const BYTE g_FFSampleTex2D6[] = { +68,88,66,67,240,29,95,192,17,112,54,92,138,198,156,88, +34,54,205,170,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,66,194,12,143,10,1,221,231,219,62,49,251, +254,63,175,14,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +6,6,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,6,0,0,0,88,24,0,4, +0,112,16,0,6,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,6,0,0,0, +0,96,16,0,6,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +6,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +6,0,0,0,1,0,0,0,13,0,0,0,83,109,112,54, +0,84,101,120,54,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,54,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,54,0 +}; +const BYTE g_FFSampleTex2D7[] = { +68,88,66,67,128,254,127,89,212,237,60,112,109,237,190,159, +68,41,91,237,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,26,171,200,29,118,90,223,37,168,34,191,21, +246,151,59,230,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +7,7,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,3,176,31,0,0,2,0,0,0,144,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,7,0,0,0,88,24,0,4, +0,112,16,0,7,0,0,0,85,85,0,0,95,0,0,3, +50,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,16,16,0,0,0,0,0,70,126,16,0,7,0,0,0, +0,96,16,0,7,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +7,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +7,0,0,0,1,0,0,0,13,0,0,0,83,109,112,55, +0,84,101,120,55,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,55,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,55,0 +}; +const BYTE g_FFSampleTexProj0[] = { +68,88,66,67,237,34,106,171,253,60,160,245,196,118,246,108, +124,200,6,0,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,230,60,101,10,132,76,15,42,191,248,157,64, +112,9,91,75,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +0,0,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,0,0,0,0,88,24,0,4,0,112,16,0, +0,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,0,0,0,0, +0,96,16,0,0,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +0,0,0,0,1,0,0,0,13,0,0,0,83,109,112,48, +0,84,101,120,48,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,48,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,48,0 +}; +const BYTE g_FFSampleTexProj1[] = { +68,88,66,67,4,136,237,251,219,54,28,116,17,188,142,117, +202,37,0,216,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,227,64,211,49,27,178,55,234,32,218,202,171, +120,32,81,116,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +1,1,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,1,0,0,0,88,24,0,4,0,112,16,0, +1,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,1,0,0,0, +0,96,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +1,0,0,0,1,0,0,0,13,0,0,0,83,109,112,49, +0,84,101,120,49,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,49,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,49,0 +}; +const BYTE g_FFSampleTexProj2[] = { +68,88,66,67,2,30,122,43,115,147,198,113,36,147,136,65, +91,229,165,118,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,158,195,81,208,65,178,14,56,95,97,26,50, +228,55,13,138,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +2,2,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,2,0,0,0,88,24,0,4,0,112,16,0, +2,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,2,0,0,0, +0,96,16,0,2,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +2,0,0,0,1,0,0,0,13,0,0,0,83,109,112,50, +0,84,101,120,50,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,50,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,50,0 +}; +const BYTE g_FFSampleTexProj3[] = { +68,88,66,67,198,103,138,26,135,26,62,28,241,113,110,230, +103,182,28,127,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,190,50,195,62,15,53,121,224,115,82,118,6, +11,177,14,169,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +3,3,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,3,0,0,0,88,24,0,4,0,112,16,0, +3,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,3,0,0,0, +0,96,16,0,3,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +3,0,0,0,1,0,0,0,13,0,0,0,83,109,112,51, +0,84,101,120,51,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,51,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,51,0 +}; +const BYTE g_FFSampleTexProj4[] = { +68,88,66,67,214,247,95,61,160,17,24,2,54,171,136,221, +162,93,207,123,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,230,212,227,79,165,100,103,2,70,84,103,231, +199,191,4,95,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +4,4,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,4,0,0,0,88,24,0,4,0,112,16,0, +4,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,4,0,0,0, +0,96,16,0,4,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +4,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +4,0,0,0,1,0,0,0,13,0,0,0,83,109,112,52, +0,84,101,120,52,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,52,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,52,0 +}; +const BYTE g_FFSampleTexProj5[] = { +68,88,66,67,66,189,97,195,183,152,219,151,58,228,33,211, +23,65,5,98,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,161,32,90,6,181,122,141,232,231,32,178,86, +153,147,189,100,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +5,5,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,5,0,0,0,88,24,0,4,0,112,16,0, +5,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,5,0,0,0, +0,96,16,0,5,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +5,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +5,0,0,0,1,0,0,0,13,0,0,0,83,109,112,53, +0,84,101,120,53,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,53,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,53,0 +}; +const BYTE g_FFSampleTexProj6[] = { +68,88,66,67,153,221,7,160,36,89,179,148,98,194,126,246, +177,187,106,246,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,46,167,174,151,195,138,31,77,170,240,199,31, +49,127,212,92,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +6,6,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,6,0,0,0,88,24,0,4,0,112,16,0, +6,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,6,0,0,0, +0,96,16,0,6,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +6,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +6,0,0,0,1,0,0,0,13,0,0,0,83,109,112,54, +0,84,101,120,54,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,54,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,54,0 +}; +const BYTE g_FFSampleTexProj7[] = { +68,88,66,67,54,198,9,208,91,47,140,152,149,52,162,217, +161,54,143,152,1,0,0,0,139,3,0,0,2,0,0,0, +40,0,0,0,48,3,0,0,76,73,66,70,0,3,0,0, +68,88,66,67,2,126,106,25,61,155,75,228,172,90,27,233, +211,161,173,74,1,0,0,0,0,3,0,0,5,0,0,0, +52,0,0,0,188,0,0,0,76,1,0,0,200,1,0,0, +132,2,0,0,65,111,110,57,128,0,0,0,128,0,0,0, +0,2,80,76,88,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +7,7,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,11,176,31,0,0,2,0,0,0,144,0,8,15,160, +6,0,0,2,0,0,8,128,0,0,255,176,5,0,0,3, +0,0,3,128,0,0,255,128,0,0,228,176,66,0,0,3, +0,0,15,128,0,0,228,128,0,8,228,160,1,0,0,2, +0,0,15,224,0,0,228,128,255,255,0,0,83,72,68,82, +136,0,0,0,64,0,240,255,34,0,0,0,90,0,0,3, +0,96,16,0,7,0,0,0,88,24,0,4,0,112,16,0, +7,0,0,0,85,85,0,0,95,0,0,3,178,16,16,0, +0,0,0,0,101,0,0,3,242,32,16,0,0,0,0,0, +104,0,0,2,1,0,0,0,14,0,0,7,50,0,16,0, +0,0,0,0,70,16,16,0,0,0,0,0,246,31,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,0,16,0,0,0,0,0,70,126,16,0,7,0,0,0, +0,96,16,0,7,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,3,0,0,0,1,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +7,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,4,0,0,0,255,255,255,255, +7,0,0,0,1,0,0,0,13,0,0,0,83,109,112,55, +0,84,101,120,55,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,55,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,55,0 +}; +const BYTE g_FFSampleTex3D0[] = { +68,88,66,67,206,176,17,24,163,228,56,124,213,217,89,247, +168,217,106,41,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,14,80,190,175,153,165,204,147,108,17,98,29, +189,179,225,238,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +0,0,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,0,0,0,0,88,40,0,4, +0,112,16,0,0,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,0,0,0,0, +0,96,16,0,0,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +0,0,0,0,1,0,0,0,13,0,0,0,83,109,112,48, +0,84,101,120,48,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,48,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,48,0 +}; +const BYTE g_FFSampleTex3D1[] = { +68,88,66,67,54,231,211,65,158,32,30,68,185,17,249,76, +2,7,22,248,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,171,59,174,152,183,87,216,198,114,154,0,113, +150,163,208,243,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +1,1,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,1,0,0,0,88,40,0,4, +0,112,16,0,1,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,1,0,0,0, +0,96,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +1,0,0,0,1,0,0,0,13,0,0,0,83,109,112,49, +0,84,101,120,49,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,49,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,49,0 +}; +const BYTE g_FFSampleTex3D2[] = { +68,88,66,67,153,118,160,252,192,90,141,221,27,255,54,21, +121,98,195,236,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,201,9,226,184,184,198,44,161,181,91,189,22, +164,160,102,27,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +2,2,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,2,0,0,0,88,40,0,4, +0,112,16,0,2,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,2,0,0,0, +0,96,16,0,2,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +2,0,0,0,1,0,0,0,13,0,0,0,83,109,112,50, +0,84,101,120,50,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,50,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,50,0 +}; +const BYTE g_FFSampleTex3D3[] = { +68,88,66,67,115,199,248,60,148,239,79,221,248,116,74,189, +183,197,234,230,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,184,154,16,255,1,250,209,159,118,180,70,123, +159,161,218,107,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +3,3,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,3,0,0,0,88,40,0,4, +0,112,16,0,3,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,3,0,0,0, +0,96,16,0,3,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +3,0,0,0,1,0,0,0,13,0,0,0,83,109,112,51, +0,84,101,120,51,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,51,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,51,0 +}; +const BYTE g_FFSampleTex3D4[] = { +68,88,66,67,175,88,14,186,68,209,197,62,115,210,225,43, +70,17,156,98,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,141,231,106,237,112,235,84,199,112,98,106,110, +179,136,3,131,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +4,4,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,4,0,0,0,88,40,0,4, +0,112,16,0,4,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,4,0,0,0, +0,96,16,0,4,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +4,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +4,0,0,0,1,0,0,0,13,0,0,0,83,109,112,52, +0,84,101,120,52,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,52,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,52,0 +}; +const BYTE g_FFSampleTex3D5[] = { +68,88,66,67,21,86,181,156,18,14,15,61,232,192,100,191, +113,227,128,184,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,175,14,52,173,92,80,63,137,150,55,52,202, +102,138,186,177,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +5,5,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,5,0,0,0,88,40,0,4, +0,112,16,0,5,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,5,0,0,0, +0,96,16,0,5,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +5,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +5,0,0,0,1,0,0,0,13,0,0,0,83,109,112,53, +0,84,101,120,53,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,53,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,53,0 +}; +const BYTE g_FFSampleTex3D6[] = { +68,88,66,67,238,177,249,89,9,22,115,2,214,9,191,51, +202,23,0,173,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,213,181,254,210,42,235,198,99,147,100,249,38, +66,54,186,94,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +6,6,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,6,0,0,0,88,40,0,4, +0,112,16,0,6,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,6,0,0,0, +0,96,16,0,6,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +6,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +6,0,0,0,1,0,0,0,13,0,0,0,83,109,112,54, +0,84,101,120,54,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,54,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,54,0 +}; +const BYTE g_FFSampleTex3D7[] = { +68,88,66,67,125,134,173,155,128,60,127,159,47,32,107,157, +237,228,160,55,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,207,197,246,6,50,87,29,171,224,83,43,237, +229,87,179,100,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +7,7,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,160,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,7,0,0,0,88,40,0,4, +0,112,16,0,7,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,7,0,0,0, +0,96,16,0,7,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +7,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,8,0,0,0,255,255,255,255, +7,0,0,0,1,0,0,0,13,0,0,0,83,109,112,55, +0,84,101,120,55,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,55,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,55,0 +}; +const BYTE g_FFSampleTexCube0[] = { +68,88,66,67,33,244,32,125,20,149,175,63,113,66,150,137, +236,158,74,161,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,113,62,226,192,223,150,191,199,17,37,188,138, +110,126,21,124,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +0,0,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,0,0,0,0,88,48,0,4, +0,112,16,0,0,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,0,0,0,0, +0,96,16,0,0,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +0,0,0,0,1,0,0,0,13,0,0,0,83,109,112,48, +0,84,101,120,48,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,48,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,48,0 +}; +const BYTE g_FFSampleTexCube1[] = { +68,88,66,67,22,79,13,114,141,19,54,166,178,73,140,214, +63,36,100,186,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,70,89,149,240,122,13,155,26,14,223,34,217, +148,48,93,72,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +1,1,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,1,0,0,0,88,48,0,4, +0,112,16,0,1,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,1,0,0,0, +0,96,16,0,1,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +1,0,0,0,1,0,0,0,13,0,0,0,83,109,112,49, +0,84,101,120,49,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,49,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,49,0 +}; +const BYTE g_FFSampleTexCube2[] = { +68,88,66,67,7,165,35,142,143,214,18,167,193,132,142,213, +160,150,93,133,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,98,252,179,13,153,4,140,224,14,185,204,193, +153,209,189,169,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +2,2,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,2,0,0,0,88,48,0,4, +0,112,16,0,2,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,2,0,0,0, +0,96,16,0,2,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +2,0,0,0,1,0,0,0,13,0,0,0,83,109,112,50, +0,84,101,120,50,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,50,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,50,0 +}; +const BYTE g_FFSampleTexCube3[] = { +68,88,66,67,70,205,12,245,181,82,205,63,112,32,70,85, +27,139,180,41,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,180,171,156,216,69,235,175,170,109,153,73,113, +56,216,63,162,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +3,3,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,3,0,0,0,88,48,0,4, +0,112,16,0,3,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,3,0,0,0, +0,96,16,0,3,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +3,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +3,0,0,0,1,0,0,0,13,0,0,0,83,109,112,51, +0,84,101,120,51,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,51,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,51,0 +}; +const BYTE g_FFSampleTexCube4[] = { +68,88,66,67,135,31,144,5,60,204,204,187,32,54,117,90, +26,33,4,165,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,221,103,249,252,98,213,207,165,83,169,29,179, +159,36,23,98,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +4,4,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,4,0,0,0,88,48,0,4, +0,112,16,0,4,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,4,0,0,0, +0,96,16,0,4,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +4,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +4,0,0,0,1,0,0,0,13,0,0,0,83,109,112,52, +0,84,101,120,52,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,52,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,52,0 +}; +const BYTE g_FFSampleTexCube5[] = { +68,88,66,67,9,169,174,254,19,74,128,174,170,108,76,74, +237,75,117,36,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,50,41,254,184,236,74,224,61,194,211,228,155, +17,193,157,56,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +5,5,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,5,0,0,0,88,48,0,4, +0,112,16,0,5,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,5,0,0,0, +0,96,16,0,5,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +5,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +5,0,0,0,1,0,0,0,13,0,0,0,83,109,112,53, +0,84,101,120,53,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,53,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,53,0 +}; +const BYTE g_FFSampleTexCube6[] = { +68,88,66,67,91,64,54,105,105,23,11,213,252,58,251,141, +250,247,181,206,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,123,101,100,54,254,198,63,167,228,138,15,149, +11,230,115,30,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +6,6,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,6,0,0,0,88,48,0,4, +0,112,16,0,6,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,6,0,0,0, +0,96,16,0,6,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +6,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +6,0,0,0,1,0,0,0,13,0,0,0,83,109,112,54, +0,84,101,120,54,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,54,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,54,0 +}; +const BYTE g_FFSampleTexCube7[] = { +68,88,66,67,188,238,36,82,77,132,123,123,98,251,103,197, +127,182,224,79,1,0,0,0,75,3,0,0,2,0,0,0, +40,0,0,0,240,2,0,0,76,73,66,70,192,2,0,0, +68,88,66,67,221,32,245,102,89,40,196,37,67,14,199,175, +106,249,102,241,1,0,0,0,192,2,0,0,5,0,0,0, +52,0,0,0,160,0,0,0,12,1,0,0,136,1,0,0, +68,2,0,0,65,111,110,57,100,0,0,0,100,0,0,0, +0,2,80,76,60,0,0,0,40,0,0,0,0,0,40,0, +0,0,40,0,0,0,40,0,1,0,36,0,0,0,40,0, +7,7,0,0,0,2,80,76,31,0,0,2,0,0,0,128, +0,0,7,176,31,0,0,2,0,0,0,152,0,8,15,160, +66,0,0,3,0,0,15,128,0,0,228,176,0,8,228,160, +1,0,0,2,0,0,15,224,0,0,228,128,255,255,0,0, +83,72,68,82,100,0,0,0,64,0,240,255,25,0,0,0, +90,0,0,3,0,96,16,0,7,0,0,0,88,48,0,4, +0,112,16,0,7,0,0,0,85,85,0,0,95,0,0,3, +114,16,16,0,0,0,0,0,101,0,0,3,242,32,16,0, +0,0,0,0,69,0,0,9,242,32,16,0,0,0,0,0, +70,18,16,0,0,0,0,0,70,126,16,0,7,0,0,0, +0,96,16,0,7,0,0,0,62,0,0,1,83,84,65,84, +116,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0, +2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,82,68,69,70,180,0,0,0, +0,0,0,0,0,0,0,0,2,0,0,0,60,0,0,0, +0,4,70,76,0,129,0,0,134,0,0,0,82,68,49,49, +60,0,0,0,24,0,0,0,32,0,0,0,40,0,0,0, +36,0,0,0,12,0,0,0,0,0,0,0,124,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +7,0,0,0,1,0,0,0,1,0,0,0,129,0,0,0, +2,0,0,0,5,0,0,0,9,0,0,0,255,255,255,255, +7,0,0,0,1,0,0,0,13,0,0,0,83,109,112,55, +0,84,101,120,55,0,77,105,99,114,111,115,111,102,116,32, +40,82,41,32,72,76,83,76,32,83,104,97,100,101,114,32, +67,111,109,112,105,108,101,114,32,54,46,51,46,57,52,49, +53,46,48,0,76,70,83,48,116,0,0,0,2,0,0,0, +8,0,0,0,104,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0, +2,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0, +0,0,0,0,113,0,0,0,0,0,0,0,3,0,0,0, +1,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0, +1,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +255,255,255,255,76,111,97,100,84,101,120,55,0,117,118,0, +76,73,66,72,83,0,0,0,1,0,0,0,28,0,0,0, +0,0,0,0,1,0,0,0,20,0,0,0,2,0,0,0, +74,0,0,0,77,105,99,114,111,115,111,102,116,32,40,82, +41,32,72,76,83,76,32,83,104,97,100,101,114,32,67,111, +109,112,105,108,101,114,32,54,46,51,46,57,52,49,53,46, +48,0,76,111,97,100,84,101,120,55,0 +}; +const BYTE* g_FFSampleTexLib[] = { +g_FFSampleTex2D0, +g_FFSampleTex2D1, +g_FFSampleTex2D2, +g_FFSampleTex2D3, +g_FFSampleTex2D4, +g_FFSampleTex2D5, +g_FFSampleTex2D6, +g_FFSampleTex2D7, +g_FFSampleTexProj0, +g_FFSampleTexProj1, +g_FFSampleTexProj2, +g_FFSampleTexProj3, +g_FFSampleTexProj4, +g_FFSampleTexProj5, +g_FFSampleTexProj6, +g_FFSampleTexProj7, +g_FFSampleTex3D0, +g_FFSampleTex3D1, +g_FFSampleTex3D2, +g_FFSampleTex3D3, +g_FFSampleTex3D4, +g_FFSampleTex3D5, +g_FFSampleTex3D6, +g_FFSampleTex3D7, +g_FFSampleTexCube0, +g_FFSampleTexCube1, +g_FFSampleTexCube2, +g_FFSampleTexCube3, +g_FFSampleTexCube4, +g_FFSampleTexCube5, +g_FFSampleTexCube6, +g_FFSampleTexCube7, +}; +const size_t g_FFSampleTexLibSize[] = { +sizeof(g_FFSampleTex2D0), +sizeof(g_FFSampleTex2D1), +sizeof(g_FFSampleTex2D2), +sizeof(g_FFSampleTex2D3), +sizeof(g_FFSampleTex2D4), +sizeof(g_FFSampleTex2D5), +sizeof(g_FFSampleTex2D6), +sizeof(g_FFSampleTex2D7), +sizeof(g_FFSampleTexProj0), +sizeof(g_FFSampleTexProj1), +sizeof(g_FFSampleTexProj2), +sizeof(g_FFSampleTexProj3), +sizeof(g_FFSampleTexProj4), +sizeof(g_FFSampleTexProj5), +sizeof(g_FFSampleTexProj6), +sizeof(g_FFSampleTexProj7), +sizeof(g_FFSampleTex3D0), +sizeof(g_FFSampleTex3D1), +sizeof(g_FFSampleTex3D2), +sizeof(g_FFSampleTex3D3), +sizeof(g_FFSampleTex3D4), +sizeof(g_FFSampleTex3D5), +sizeof(g_FFSampleTex3D6), +sizeof(g_FFSampleTex3D7), +sizeof(g_FFSampleTexCube0), +sizeof(g_FFSampleTexCube1), +sizeof(g_FFSampleTexCube2), +sizeof(g_FFSampleTexCube3), +sizeof(g_FFSampleTexCube4), +sizeof(g_FFSampleTexCube5), +sizeof(g_FFSampleTexCube6), +sizeof(g_FFSampleTexCube7), +}; diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/FFShaderLib.hlsl b/Runtime/GfxDevice/d3d11/InternalShaders/FFShaderLib.hlsl new file mode 100644 index 0000000..fa2a89a --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/FFShaderLib.hlsl @@ -0,0 +1,172 @@ + +cbuffer UnityFFVertex { + float4x4 ff_matrix_mvp; // 0 + float4x4 ff_matrix_mv; // 4 + float4 ff_vec_color; // 8 + float4 ff_vec_ambient; // 9 + float4 ff_light_color[8]; // 10 + float4 ff_light_pos[8]; // 18 + float4 ff_light_atten[8]; // 26 + float4 ff_light_spot[8]; // 34 + float4 ff_mat_diffuse; // 42 + float4 ff_mat_ambient; // 43 + float4 ff_mat_spec; // 44 + float4 ff_mat_emission; // 45 + float4x4 ff_matrix_tex[4]; // 46 + float4 ff_fog_vs; // 62 +}; // 62 + +cbuffer UnityFFPixel { + float4 ff_vec_colors[8]; // 0 + float ff_alpha_ref; // 8 + float4 ff_fog_ps; // 9 +}; + + +export float4 LoadVertexColor(float4 vc) { return vc; } +export float4 LoadVertexColorUniform() { return ff_vec_color; } +export float3 LoadEyePos(float4 vertex) { return mul (ff_matrix_mv, vertex).xyz; } +export float3 LoadEyeNormal(float3 normal) { return normalize (mul ((float3x3)ff_matrix_mv, normal).xyz); } //@TODO: proper normal matrix +export float3 LoadZero() { return 0.0; } +export float3 LoadViewDir(float3 eyePos) { return -normalize(eyePos); } +export float3 LoadEyeRefl(float3 viewDir, float3 eyeNormal) { return 2.0f * dot (viewDir, eyeNormal) * eyeNormal - viewDir; } +export float4 LoadAmbientColor() { return ff_mat_ambient; } +export float4 LoadDiffuseColor() { return ff_mat_diffuse; } +export float4 LoadEmissionColor() { return ff_mat_emission; } + +export float3 InitLightColor(float4 emission, float4 ambient) { return emission.rgb + ambient.rgb * ff_vec_ambient.rgb; } + +float3 ComputeLighting (int idx, float3 dirToLight, float3 eyeNormal, float3 viewDir, float4 diffuseColor, float atten, inout float3 specColor) { + float NdotL = max(dot(eyeNormal, dirToLight), 0.0); + float3 color = NdotL * diffuseColor.rgb * ff_light_color[idx].rgb; + return color * atten; +} +float3 ComputeLightingSpec (int idx, float3 dirToLight, float3 eyeNormal, float3 viewDir, float4 diffuseColor, float atten, inout float3 specColor) { + float NdotL = max(dot(eyeNormal, dirToLight), 0.0); + float3 color = NdotL * diffuseColor.rgb * ff_light_color[idx].rgb; + if (NdotL > 0.0) { + float3 h = normalize(dirToLight + viewDir); + float HdotN = max(dot(eyeNormal, h), 0.0); + float sp = saturate(pow(HdotN, ff_mat_spec.w)); + specColor += atten * sp * ff_light_color[idx].rgb; + } + return color * atten; +} +float3 ComputeSpotLight(int idx, float3 eyePosition, float3 eyeNormal, float3 viewDir, float4 diffuseColor, inout float3 specColor) { + float3 dirToLight = ff_light_pos[idx].xyz - eyePosition * ff_light_pos[idx].w; + float distSqr = dot(dirToLight, dirToLight); + float att = 1.0 / (1.0 + ff_light_atten[idx].z * distSqr); + if (ff_light_pos[idx].w != 0 && distSqr > ff_light_atten[idx].w) att = 0.0; // set to 0 if outside of range + dirToLight *= rsqrt(distSqr); + float rho = max(dot(dirToLight, ff_light_spot[idx].xyz), 0.0); + float spotAtt = (rho - ff_light_atten[idx].x) * ff_light_atten[idx].y; + spotAtt = saturate(spotAtt); + return min (ComputeLighting (idx, dirToLight, eyeNormal, viewDir, diffuseColor, att*spotAtt, specColor), 1.0); +} +float3 ComputeSpotLightSpec(int idx, float3 eyePosition, float3 eyeNormal, float3 viewDir, float4 diffuseColor, inout float3 specColor) { + float3 dirToLight = ff_light_pos[idx].xyz - eyePosition * ff_light_pos[idx].w; + float distSqr = dot(dirToLight, dirToLight); + float att = 1.0 / (1.0 + ff_light_atten[idx].z * distSqr); + if (ff_light_pos[idx].w != 0 && distSqr > ff_light_atten[idx].w) att = 0.0; // set to 0 if outside of range + dirToLight *= rsqrt(distSqr); + float rho = max(dot(dirToLight, ff_light_spot[idx].xyz), 0.0); + float spotAtt = (rho - ff_light_atten[idx].x) * ff_light_atten[idx].y; + spotAtt = saturate(spotAtt); + return min (ComputeLightingSpec (idx, dirToLight, eyeNormal, viewDir, diffuseColor, att*spotAtt, specColor), 1.0); +} +#define SPOT_LIGHT(n) \ +export float3 ComputeSpotLight##n(float3 eyePosition, float3 eyeNormal, float3 viewDir, float4 diffuseColor, inout float3 specColor, float3 amb) { \ + float3 l = amb; \ + for (int i = 0; i < n; ++i) \ + l += ComputeSpotLight(i, eyePosition, eyeNormal, viewDir, diffuseColor, specColor); \ + return l; \ +} \ +export float3 ComputeSpotLightSpec##n(float3 eyePosition, float3 eyeNormal, float3 viewDir, float4 diffuseColor, inout float3 specColor, float3 amb) { \ + float3 l = amb; \ + for (int i = 0; i < n; ++i) \ + l += ComputeSpotLightSpec(i, eyePosition, eyeNormal, viewDir, diffuseColor, specColor); \ + return l; \ +} +SPOT_LIGHT(0) +SPOT_LIGHT(1) +SPOT_LIGHT(2) +SPOT_LIGHT(3) +SPOT_LIGHT(4) +SPOT_LIGHT(5) +SPOT_LIGHT(6) +SPOT_LIGHT(7) +SPOT_LIGHT(8) + +export float4 LoadLightingColor(float3 lcolor, float4 diffcolor) { return float4(lcolor.rgb, diffcolor.a); } + +export float4 TransformVertex(float4 vertex) { return mul (ff_matrix_mvp, vertex); } + +export float4 Saturate4(float4 c) { return saturate(c); } +export float3 Saturate3(float3 c) { return saturate(c); } +export float3 Load3(float3 c) { return c; } +export float3 ModulateSpec(float3 c) { return c * ff_mat_spec.rgb; } + +export float4 MultiplyUV0(float4 uv) { return mul(ff_matrix_tex[0], uv); } +export float4 MultiplyUV1(float4 uv) { return mul(ff_matrix_tex[1], uv); } +export float4 MultiplyUV2(float4 uv) { return mul(ff_matrix_tex[2], uv); } +export float4 MultiplyUV3(float4 uv) { return mul(ff_matrix_tex[3], uv); } +export float4 MultiplyUV4(float4 uv) { return uv; } +export float4 MultiplyUV5(float4 uv) { return uv; } +export float4 MultiplyUV6(float4 uv) { return uv; } +export float4 MultiplyUV7(float4 uv) { return uv; } + +export float4 UVSphereMap(float3 eyeRefl) { return float4(eyeRefl.xy / (2.0*sqrt(eyeRefl.x*eyeRefl.x + eyeRefl.y*eyeRefl.y + (eyeRefl.z+1)*(eyeRefl.z+1))) + 0.5, 0, 1); } +export float4 Float3to4(float3 v) { return float4(v.xyz,1); } + +export float4 LoadConstantColor0() { return ff_vec_colors[0]; } +export float4 LoadConstantColor1() { return ff_vec_colors[1]; } +export float4 LoadConstantColor2() { return ff_vec_colors[2]; } +export float4 LoadConstantColor3() { return ff_vec_colors[3]; } +export float4 LoadConstantColor4() { return ff_vec_colors[4]; } +export float4 LoadConstantColor5() { return ff_vec_colors[5]; } +export float4 LoadConstantColor6() { return ff_vec_colors[6]; } +export float4 LoadConstantColor7() { return ff_vec_colors[7]; } + +export float OneMinus1(float v) { return 1.0-v; } +export float3 OneMinus3(float3 v) { return 1.0-v; } +export float4 OneMinus4(float4 v) { return 1.0-v; } + +export float4 CombReplace (float4 a) { return a; } +export float4 CombModulate (float4 a, float4 b) { return a * b; } +export float4 CombAdd (float4 a, float4 b) { return a + b; } +export float4 CombAddSigned(float4 a, float4 b) { return a + b - 0.5; } +export float4 CombSubtract (float4 a, float4 b) { return a - b; } +export float4 CombLerp (float4 a, float4 b, float4 c) { return lerp(b, a, c.a); } +export float4 CombDot3 (float4 a, float4 b) { float3 r = 4.0 * dot(a.rgb-0.5, b.rgb-0.5); return float4(r, a.a); } +export float4 CombDot3rgba (float4 a, float4 b) { return 4.0 * dot(a.rgb-0.5, b.rgb-0.5); } +export float4 CombMulAdd (float4 a, float4 b, float4 c) { return a * c.a + b; } +export float4 CombMulSub (float4 a, float4 b, float4 c) { return a * c.a - b; } +export float4 CombMulAddSigned(float4 a, float4 b, float4 c) { return a * c.a + b - 0.5; } + +export float4 Scale2(float4 a) { return a + a; } +export float4 Scale4(float4 a) { return a * 4; } + +export float4 AddSpec(float4 col, float3 spec) { col.rgb += spec; return col; } +export float4 CombineAlpha(float4 c, float4 a) { return float4(c.rgb, a.a); } + +export float FogLinear(float3 eyePos) { + return saturate(length(eyePos) * ff_fog_vs.z + ff_fog_vs.w); +} +export float FogExp(float3 eyePos) { + return saturate(exp2(-(length(eyePos) * ff_fog_vs.y))); +} +export float FogExp2(float3 eyePos) { + float f = length(eyePos) * ff_fog_vs.y; + return saturate(exp2(-f * f)); +} +export float4 ApplyFog(float4 col, float ifog) { + return float4(lerp(ff_fog_ps.rgb, col.rgb, ifog), col.a); +} + +export float4 AlphaTestNever(float4 col) { discard; return col; } +export float4 AlphaTestLess(float4 col) { if (!(col.a < ff_alpha_ref)) discard; return col; } +export float4 AlphaTestEqual(float4 col) { if (!(col.a == ff_alpha_ref)) discard; return col; } +export float4 AlphaTestLEqual(float4 col) { if (!(col.a <= ff_alpha_ref)) discard; return col; } +export float4 AlphaTestGreater(float4 col) { if (!(col.a > ff_alpha_ref)) discard; return col; } +export float4 AlphaTestNotEqual(float4 col) { if (!(col.a != ff_alpha_ref)) discard; return col; } +export float4 AlphaTestGEqual(float4 col) { if (!(col.a >= ff_alpha_ref)) discard; return col; } diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/builtin.h b/Runtime/GfxDevice/d3d11/InternalShaders/builtin.h new file mode 100644 index 0000000..737bd42 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/builtin.h @@ -0,0 +1,19755 @@ +// +// +// Autogenerated file. Do not modify! +// +// +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_1_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_1_32._fxctmp +// /EStreamOutSkinVS_Position_1_32 /D BONESPERVERTEX=1 /D BONECOUNT=32 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +imul null, r0.x, v3.x, l(3) +mov r1.xyz, v0.xyzx +mov r1.w, l(1.000000) +dp4 o0.x, r1.xyzw, cb0[r0.x + 0].xyzw +dp4 o0.y, r1.xyzw, cb0[r0.x + 1].xyzw +dp4 o0.z, r1.xyzw, cb0[r0.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 9 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_1_32[] = +{ + 68, 88, 66, 67, 172, 110, + 173, 231, 150, 179, 82, 99, + 5, 94, 37, 107, 119, 107, + 152, 219, 1, 0, 0, 0, + 220, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 96, 3, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 92, 1, 0, 0, + 64, 0, 1, 0, 87, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 96, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 38, 0, 0, 8, + 0, 208, 0, 0, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 16, 16, 0, 3, 0, + 0, 0, 1, 64, 0, 0, + 3, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 9, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 5, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_2_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_2_32._fxctmp +// /EStreamOutSkinVS_Position_2_32 /D BONESPERVERTEX=2 /D BONECOUNT=32 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_2_32[] = +{ + 68, 88, 66, 67, 78, 255, + 107, 230, 57, 57, 29, 189, + 107, 149, 130, 121, 255, 237, + 206, 251, 1, 0, 0, 0, + 252, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 128, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 84, 2, 0, 0, 64, 0, + 1, 0, 149, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 0, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 6, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_4_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_4_32._fxctmp +// /EStreamOutSkinVS_Position_4_32 /D BONESPERVERTEX=4 /D BONECOUNT=32 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 2].xyzw, r1.xyzw +mad r0.xyzw, v3.wwww, cb0[r0.w + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_4_32[] = +{ + 68, 88, 66, 67, 190, 235, + 32, 161, 70, 54, 170, 157, + 239, 18, 118, 92, 60, 255, + 126, 161, 1, 0, 0, 0, + 20, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 152, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 108, 3, 0, 0, 64, 0, + 1, 0, 219, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 2, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 1, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 0, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 6, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_1_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_1_64._fxctmp +// /EStreamOutSkinVS_Position_1_64 /D BONESPERVERTEX=1 /D BONECOUNT=64 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +imul null, r0.x, v3.x, l(3) +mov r1.xyz, v0.xyzx +mov r1.w, l(1.000000) +dp4 o0.x, r1.xyzw, cb0[r0.x + 0].xyzw +dp4 o0.y, r1.xyzw, cb0[r0.x + 1].xyzw +dp4 o0.z, r1.xyzw, cb0[r0.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 9 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_1_64[] = +{ + 68, 88, 66, 67, 147, 148, + 150, 219, 6, 76, 210, 165, + 175, 243, 177, 17, 178, 32, + 216, 209, 1, 0, 0, 0, + 220, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 96, 3, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 92, 1, 0, 0, + 64, 0, 1, 0, 87, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 192, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 38, 0, 0, 8, + 0, 208, 0, 0, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 16, 16, 0, 3, 0, + 0, 0, 1, 64, 0, 0, + 3, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 9, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 5, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_2_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_2_64._fxctmp +// /EStreamOutSkinVS_Position_2_64 /D BONESPERVERTEX=2 /D BONECOUNT=64 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_2_64[] = +{ + 68, 88, 66, 67, 2, 81, + 122, 207, 247, 163, 197, 92, + 153, 201, 157, 75, 235, 157, + 250, 13, 1, 0, 0, 0, + 252, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 128, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 84, 2, 0, 0, 64, 0, + 1, 0, 149, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 0, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 6, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_4_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_4_64._fxctmp +// /EStreamOutSkinVS_Position_4_64 /D BONESPERVERTEX=4 /D BONECOUNT=64 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 2].xyzw, r1.xyzw +mad r0.xyzw, v3.wwww, cb0[r0.w + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_4_64[] = +{ + 68, 88, 66, 67, 11, 70, + 190, 106, 178, 229, 109, 109, + 89, 69, 130, 9, 207, 137, + 221, 41, 1, 0, 0, 0, + 20, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 152, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 108, 3, 0, 0, 64, 0, + 1, 0, 219, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 2, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 1, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 0, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 6, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_1_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_1_128._fxctmp +// /EStreamOutSkinVS_Position_1_128 /D BONESPERVERTEX=1 /D BONECOUNT=128 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +imul null, r0.x, v3.x, l(3) +mov r1.xyz, v0.xyzx +mov r1.w, l(1.000000) +dp4 o0.x, r1.xyzw, cb0[r0.x + 0].xyzw +dp4 o0.y, r1.xyzw, cb0[r0.x + 1].xyzw +dp4 o0.z, r1.xyzw, cb0[r0.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 9 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_1_128[] = +{ + 68, 88, 66, 67, 7, 222, + 0, 205, 11, 21, 104, 139, + 8, 62, 57, 246, 1, 70, + 233, 230, 1, 0, 0, 0, + 220, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 96, 3, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 92, 1, 0, 0, + 64, 0, 1, 0, 87, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 128, 1, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 38, 0, 0, 8, + 0, 208, 0, 0, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 16, 16, 0, 3, 0, + 0, 0, 1, 64, 0, 0, + 3, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 9, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 5, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_2_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_2_128._fxctmp +// /EStreamOutSkinVS_Position_2_128 /D BONESPERVERTEX=2 /D BONECOUNT=128 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_2_128[] = +{ + 68, 88, 66, 67, 131, 165, + 122, 210, 205, 5, 71, 238, + 145, 203, 104, 57, 229, 1, + 240, 89, 1, 0, 0, 0, + 252, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 128, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 84, 2, 0, 0, 64, 0, + 1, 0, 149, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 0, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 6, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_4_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_4_128._fxctmp +// /EStreamOutSkinVS_Position_4_128 /D BONESPERVERTEX=4 /D BONECOUNT=128 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 2].xyzw, r1.xyzw +mad r0.xyzw, v3.wwww, cb0[r0.w + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_4_128[] = +{ + 68, 88, 66, 67, 57, 216, + 246, 73, 126, 196, 169, 105, + 89, 156, 29, 146, 202, 235, + 72, 227, 1, 0, 0, 0, + 20, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 152, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 108, 3, 0, 0, 64, 0, + 1, 0, 219, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 2, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 1, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 0, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 6, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_1_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_1_512._fxctmp +// /EStreamOutSkinVS_Position_1_512 /D BONESPERVERTEX=1 /D BONECOUNT=512 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +imul null, r0.x, v3.x, l(3) +mov r1.xyz, v0.xyzx +mov r1.w, l(1.000000) +dp4 o0.x, r1.xyzw, cb0[r0.x + 0].xyzw +dp4 o0.y, r1.xyzw, cb0[r0.x + 1].xyzw +dp4 o0.z, r1.xyzw, cb0[r0.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 9 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_1_512[] = +{ + 68, 88, 66, 67, 109, 180, + 27, 53, 43, 110, 111, 181, + 254, 232, 170, 150, 51, 248, + 173, 45, 1, 0, 0, 0, + 220, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 96, 3, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 92, 1, 0, 0, + 64, 0, 1, 0, 87, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 6, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 38, 0, 0, 8, + 0, 208, 0, 0, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 16, 16, 0, 3, 0, + 0, 0, 1, 64, 0, 0, + 3, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 9, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 5, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_2_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_2_512._fxctmp +// /EStreamOutSkinVS_Position_2_512 /D BONESPERVERTEX=2 /D BONECOUNT=512 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_2_512[] = +{ + 68, 88, 66, 67, 191, 248, + 159, 81, 159, 73, 255, 194, + 53, 47, 141, 25, 191, 205, + 45, 208, 1, 0, 0, 0, + 252, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 128, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 84, 2, 0, 0, 64, 0, + 1, 0, 149, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 0, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 6, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_4_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_4_512._fxctmp +// /EStreamOutSkinVS_Position_4_512 /D BONESPERVERTEX=4 /D BONECOUNT=512 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 2].xyzw, r1.xyzw +mad r0.xyzw, v3.wwww, cb0[r0.w + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_4_512[] = +{ + 68, 88, 66, 67, 70, 119, + 204, 225, 31, 226, 142, 0, + 115, 56, 144, 156, 34, 203, + 86, 29, 1, 0, 0, 0, + 20, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 152, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 108, 3, 0, 0, 64, 0, + 1, 0, 219, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 2, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 1, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 0, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 6, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_1_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_1_1024._fxctmp +// /EStreamOutSkinVS_Position_1_1024 /D BONESPERVERTEX=1 /D BONECOUNT=1024 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +imul null, r0.x, v3.x, l(3) +mov r1.xyz, v0.xyzx +mov r1.w, l(1.000000) +dp4 o0.x, r1.xyzw, cb0[r0.x + 0].xyzw +dp4 o0.y, r1.xyzw, cb0[r0.x + 1].xyzw +dp4 o0.z, r1.xyzw, cb0[r0.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 9 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_1_1024[] = +{ + 68, 88, 66, 67, 117, 227, + 218, 150, 67, 53, 102, 246, + 156, 73, 114, 242, 63, 65, + 53, 148, 1, 0, 0, 0, + 220, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 96, 3, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 92, 1, 0, 0, + 64, 0, 1, 0, 87, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 12, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 38, 0, 0, 8, + 0, 208, 0, 0, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 16, 16, 0, 3, 0, + 0, 0, 1, 64, 0, 0, + 3, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 9, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 5, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_2_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_2_1024._fxctmp +// /EStreamOutSkinVS_Position_2_1024 /D BONESPERVERTEX=2 /D BONECOUNT=1024 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_2_1024[] = +{ + 68, 88, 66, 67, 13, 71, + 157, 50, 29, 201, 82, 174, + 198, 214, 113, 46, 102, 98, + 97, 207, 1, 0, 0, 0, + 252, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 128, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 84, 2, 0, 0, 64, 0, + 1, 0, 149, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 0, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 6, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_4_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_4_1024._fxctmp +// /EStreamOutSkinVS_Position_4_1024 /D BONESPERVERTEX=4 /D BONECOUNT=1024 +// internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 3 +imul null, r0.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 0].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 1].xyzw, r1.xyzw +mad r1.xyzw, v3.wwww, cb0[r0.w + 1].xyzw, r1.xyzw +dp4 o0.y, r2.xyzw, r1.xyzw +mul r1.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r1.xyzw +mad r1.xyzw, v3.zzzz, cb0[r0.z + 2].xyzw, r1.xyzw +mad r0.xyzw, v3.wwww, cb0[r0.w + 2].xyzw, r1.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +mov o1.xyz, l(0,0,0,0) +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_4_1024[] = +{ + 68, 88, 66, 67, 204, 116, + 52, 195, 65, 155, 137, 172, + 38, 110, 158, 215, 19, 229, + 210, 140, 1, 0, 0, 0, + 20, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 152, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 108, 3, 0, 0, 64, 0, + 1, 0, 219, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 3, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 2, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 1, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 1, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 1, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 0, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 6, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_1_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_1_32._fxctmp +// /EStreamOutSkinVS_Position_Normal_1_32 /D BONESPERVERTEX=1 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 14 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_1_32[] = +{ + 68, 88, 66, 67, 37, 181, + 180, 243, 4, 107, 240, 75, + 171, 127, 67, 83, 143, 167, + 109, 6, 1, 0, 0, 0, + 136, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 12, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 8, 2, 0, 0, + 64, 0, 1, 0, 130, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 96, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 14, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 9, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_2_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_2_32._fxctmp +// /EStreamOutSkinVS_Position_Normal_2_32 /D BONESPERVERTEX=2 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v1.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v1.xyzx, r0.xyzx +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r1.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_2_32[] = +{ + 68, 88, 66, 67, 80, 207, + 201, 191, 158, 92, 237, 100, + 214, 39, 226, 181, 219, 93, + 192, 204, 1, 0, 0, 0, + 136, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 12, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 224, 2, 0, 0, 64, 0, + 1, 0, 184, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 242, 32, 16, 0, 2, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 20, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_4_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_4_32._fxctmp +// /EStreamOutSkinVS_Position_Normal_4_32 /D BONESPERVERTEX=4 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v1.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v1.xyzx, r1.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r2.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_4_32[] = +{ + 68, 88, 66, 67, 206, 29, + 212, 36, 176, 114, 235, 5, + 52, 112, 248, 230, 26, 143, + 41, 13, 1, 0, 0, 0, + 160, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 36, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 248, 3, 0, 0, 64, 0, + 1, 0, 254, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 7, 0, 0, 0, + 12, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_1_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_1_64._fxctmp +// /EStreamOutSkinVS_Position_Normal_1_64 /D BONESPERVERTEX=1 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 14 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_1_64[] = +{ + 68, 88, 66, 67, 50, 106, + 7, 74, 77, 162, 98, 80, + 50, 217, 99, 60, 79, 64, + 217, 67, 1, 0, 0, 0, + 136, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 12, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 8, 2, 0, 0, + 64, 0, 1, 0, 130, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 192, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 14, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 9, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_2_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_2_64._fxctmp +// /EStreamOutSkinVS_Position_Normal_2_64 /D BONESPERVERTEX=2 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v1.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v1.xyzx, r0.xyzx +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r1.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_2_64[] = +{ + 68, 88, 66, 67, 249, 238, + 191, 110, 90, 243, 91, 253, + 39, 115, 116, 175, 14, 174, + 116, 168, 1, 0, 0, 0, + 136, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 12, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 224, 2, 0, 0, 64, 0, + 1, 0, 184, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 242, 32, 16, 0, 2, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 20, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_4_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_4_64._fxctmp +// /EStreamOutSkinVS_Position_Normal_4_64 /D BONESPERVERTEX=4 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v1.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v1.xyzx, r1.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r2.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_4_64[] = +{ + 68, 88, 66, 67, 205, 190, + 48, 68, 39, 226, 36, 48, + 236, 161, 124, 195, 48, 97, + 86, 179, 1, 0, 0, 0, + 160, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 36, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 248, 3, 0, 0, 64, 0, + 1, 0, 254, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 7, 0, 0, 0, + 12, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_1_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_1_128._fxctmp +// /EStreamOutSkinVS_Position_Normal_1_128 /D BONESPERVERTEX=1 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 14 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_1_128[] = +{ + 68, 88, 66, 67, 238, 117, + 193, 23, 105, 229, 96, 236, + 185, 115, 197, 17, 52, 153, + 70, 113, 1, 0, 0, 0, + 136, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 12, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 8, 2, 0, 0, + 64, 0, 1, 0, 130, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 128, 1, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 14, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 9, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_2_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_2_128._fxctmp +// /EStreamOutSkinVS_Position_Normal_2_128 /D BONESPERVERTEX=2 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v1.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v1.xyzx, r0.xyzx +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r1.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_2_128[] = +{ + 68, 88, 66, 67, 166, 32, + 136, 74, 54, 144, 150, 156, + 117, 193, 191, 235, 43, 166, + 113, 77, 1, 0, 0, 0, + 136, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 12, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 224, 2, 0, 0, 64, 0, + 1, 0, 184, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 242, 32, 16, 0, 2, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 20, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_4_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_4_128._fxctmp +// /EStreamOutSkinVS_Position_Normal_4_128 /D BONESPERVERTEX=4 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v1.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v1.xyzx, r1.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r2.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_4_128[] = +{ + 68, 88, 66, 67, 60, 35, + 123, 52, 14, 142, 67, 125, + 230, 117, 131, 72, 141, 182, + 246, 69, 1, 0, 0, 0, + 160, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 36, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 248, 3, 0, 0, 64, 0, + 1, 0, 254, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 7, 0, 0, 0, + 12, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_1_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_1_512._fxctmp +// /EStreamOutSkinVS_Position_Normal_1_512 /D BONESPERVERTEX=1 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 14 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_1_512[] = +{ + 68, 88, 66, 67, 212, 203, + 229, 99, 44, 100, 72, 180, + 127, 187, 124, 99, 124, 29, + 226, 208, 1, 0, 0, 0, + 136, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 12, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 8, 2, 0, 0, + 64, 0, 1, 0, 130, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 6, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 14, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 9, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_2_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_2_512._fxctmp +// /EStreamOutSkinVS_Position_Normal_2_512 /D BONESPERVERTEX=2 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v1.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v1.xyzx, r0.xyzx +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r1.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_2_512[] = +{ + 68, 88, 66, 67, 204, 75, + 190, 164, 162, 21, 187, 0, + 156, 250, 209, 189, 194, 167, + 84, 205, 1, 0, 0, 0, + 136, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 12, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 224, 2, 0, 0, 64, 0, + 1, 0, 184, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 242, 32, 16, 0, 2, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 20, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_4_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_4_512._fxctmp +// /EStreamOutSkinVS_Position_Normal_4_512 /D BONESPERVERTEX=4 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v1.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v1.xyzx, r1.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r2.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_4_512[] = +{ + 68, 88, 66, 67, 167, 117, + 189, 161, 236, 51, 44, 164, + 35, 250, 193, 15, 208, 58, + 236, 51, 1, 0, 0, 0, + 160, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 36, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 248, 3, 0, 0, 64, 0, + 1, 0, 254, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 7, 0, 0, 0, + 12, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_1_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_1_1024._fxctmp +// /EStreamOutSkinVS_Position_Normal_1_1024 /D BONESPERVERTEX=1 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 14 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_1_1024[] = +{ + 68, 88, 66, 67, 133, 164, + 172, 63, 67, 0, 73, 148, + 24, 137, 147, 85, 55, 244, + 27, 171, 1, 0, 0, 0, + 136, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 12, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 8, 2, 0, 0, + 64, 0, 1, 0, 130, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 12, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 242, 32, 16, 0, + 2, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 14, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 9, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_2_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_2_1024._fxctmp +// /EStreamOutSkinVS_Position_Normal_2_1024 /D BONESPERVERTEX=2 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v1.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v1.xyzx, r0.xyzx +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r1.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_2_1024[] = +{ + 68, 88, 66, 67, 130, 225, + 168, 26, 4, 102, 26, 127, + 102, 67, 185, 3, 166, 201, + 236, 118, 1, 0, 0, 0, + 136, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 12, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 224, 2, 0, 0, 64, 0, + 1, 0, 184, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 242, 32, 16, 0, 2, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 20, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_4_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Normal_4_1024._fxctmp +// /EStreamOutSkinVS_Position_Normal_4_1024 /D BONESPERVERTEX=4 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v1.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v1.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v1.xyzx, r1.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o1.xyz, r0.xxxx, r2.xyzx +mov o2.xyzw, l(0,0,0,0) +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_4_1024[] = +{ + 68, 88, 66, 67, 32, 205, + 153, 254, 94, 143, 155, 24, + 190, 41, 240, 122, 149, 200, + 107, 78, 1, 0, 0, 0, + 160, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 36, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 0, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 248, 3, 0, 0, 64, 0, + 1, 0, 254, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 8, 242, 32, + 16, 0, 2, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 7, 0, 0, 0, + 12, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_1_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_1_32._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_1_32 /D BONESPERVERTEX=1 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_1_32[] = +{ + 68, 88, 66, 67, 183, 181, + 30, 175, 253, 170, 103, 5, + 88, 56, 199, 145, 45, 171, + 177, 63, 1, 0, 0, 0, + 72, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 204, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 200, 2, 0, 0, + 64, 0, 1, 0, 178, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 96, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 20, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 15, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_2_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_2_32._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_2_32 /D BONESPERVERTEX=2 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xy, v4.xyxx, l(3, 3, 0, 0) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_2_32[] = +{ + 68, 88, 66, 67, 181, 251, + 117, 126, 214, 41, 151, 11, + 206, 111, 25, 183, 118, 223, + 26, 216, 1, 0, 0, 0, + 40, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 172, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 128, 3, 0, 0, 64, 0, + 1, 0, 224, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 50, 0, 16, 0, 1, 0, + 0, 0, 70, 16, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 3, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 3, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 4, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 4, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 68, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 5, 0, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 0, + 18, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_4_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_4_32._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_4_32 /D BONESPERVERTEX=4 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r4.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +mad r4.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r4.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 32 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_4_32[] = +{ + 68, 88, 66, 67, 19, 221, + 121, 113, 127, 28, 29, 87, + 46, 3, 179, 249, 93, 103, + 188, 212, 1, 0, 0, 0, + 64, 7, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 196, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 152, 4, 0, 0, 64, 0, + 1, 0, 38, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 4, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 34, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 32, 0, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0, + 8, 0, 0, 0, 18, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_1_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_1_64._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_1_64 /D BONESPERVERTEX=1 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_1_64[] = +{ + 68, 88, 66, 67, 67, 223, + 94, 248, 228, 40, 152, 39, + 164, 84, 254, 169, 168, 108, + 132, 56, 1, 0, 0, 0, + 72, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 204, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 200, 2, 0, 0, + 64, 0, 1, 0, 178, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 192, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 20, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 15, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_2_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_2_64._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_2_64 /D BONESPERVERTEX=2 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xy, v4.xyxx, l(3, 3, 0, 0) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_2_64[] = +{ + 68, 88, 66, 67, 91, 181, + 220, 66, 242, 236, 115, 101, + 110, 154, 12, 56, 22, 247, + 167, 255, 1, 0, 0, 0, + 40, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 172, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 128, 3, 0, 0, 64, 0, + 1, 0, 224, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 50, 0, 16, 0, 1, 0, + 0, 0, 70, 16, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 3, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 3, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 4, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 4, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 68, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 5, 0, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 0, + 18, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_4_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_4_64._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_4_64 /D BONESPERVERTEX=4 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r4.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +mad r4.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r4.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 32 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_4_64[] = +{ + 68, 88, 66, 67, 119, 209, + 156, 16, 140, 0, 156, 224, + 87, 117, 200, 45, 39, 172, + 135, 2, 1, 0, 0, 0, + 64, 7, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 196, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 152, 4, 0, 0, 64, 0, + 1, 0, 38, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 4, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 34, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 32, 0, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0, + 8, 0, 0, 0, 18, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_1_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_1_128._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_1_128 /D BONESPERVERTEX=1 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_1_128[] = +{ + 68, 88, 66, 67, 209, 116, + 248, 215, 32, 190, 187, 116, + 43, 145, 110, 83, 6, 70, + 244, 224, 1, 0, 0, 0, + 72, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 204, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 200, 2, 0, 0, + 64, 0, 1, 0, 178, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 128, 1, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 20, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 15, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_2_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_2_128._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_2_128 /D BONESPERVERTEX=2 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xy, v4.xyxx, l(3, 3, 0, 0) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_2_128[] = +{ + 68, 88, 66, 67, 240, 99, + 184, 65, 42, 15, 79, 214, + 188, 103, 143, 167, 243, 249, + 180, 251, 1, 0, 0, 0, + 40, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 172, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 128, 3, 0, 0, 64, 0, + 1, 0, 224, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 50, 0, 16, 0, 1, 0, + 0, 0, 70, 16, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 3, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 3, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 4, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 4, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 68, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 5, 0, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 0, + 18, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_4_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_4_128._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_4_128 /D BONESPERVERTEX=4 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r4.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +mad r4.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r4.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 32 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_4_128[] = +{ + 68, 88, 66, 67, 186, 105, + 76, 213, 38, 43, 19, 216, + 240, 103, 215, 141, 162, 38, + 94, 232, 1, 0, 0, 0, + 64, 7, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 196, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 152, 4, 0, 0, 64, 0, + 1, 0, 38, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 4, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 34, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 32, 0, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0, + 8, 0, 0, 0, 18, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_1_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_1_512._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_1_512 /D BONESPERVERTEX=1 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_1_512[] = +{ + 68, 88, 66, 67, 248, 168, + 89, 63, 27, 139, 214, 175, + 110, 127, 239, 55, 216, 27, + 36, 163, 1, 0, 0, 0, + 72, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 204, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 200, 2, 0, 0, + 64, 0, 1, 0, 178, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 6, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 20, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 15, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_2_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_2_512._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_2_512 /D BONESPERVERTEX=2 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xy, v4.xyxx, l(3, 3, 0, 0) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_2_512[] = +{ + 68, 88, 66, 67, 106, 64, + 83, 181, 46, 115, 93, 157, + 45, 156, 32, 62, 119, 179, + 192, 138, 1, 0, 0, 0, + 40, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 172, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 128, 3, 0, 0, 64, 0, + 1, 0, 224, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 50, 0, 16, 0, 1, 0, + 0, 0, 70, 16, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 3, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 3, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 4, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 4, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 68, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 5, 0, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 0, + 18, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_4_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_4_512._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_4_512 /D BONESPERVERTEX=4 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r4.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +mad r4.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r4.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 32 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_4_512[] = +{ + 68, 88, 66, 67, 87, 16, + 47, 46, 228, 240, 151, 146, + 31, 201, 168, 179, 229, 105, + 94, 127, 1, 0, 0, 0, + 64, 7, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 196, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 152, 4, 0, 0, 64, 0, + 1, 0, 38, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 4, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 34, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 32, 0, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0, + 8, 0, 0, 0, 18, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_1_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_1_1024._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_1_1024 /D BONESPERVERTEX=1 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +dp3 r0.x, v1.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v1.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v1.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 20 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_1_1024[] = +{ + 68, 88, 66, 67, 77, 124, + 209, 92, 234, 48, 143, 191, + 150, 28, 205, 73, 128, 69, + 35, 47, 1, 0, 0, 0, + 72, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 204, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 200, 2, 0, 0, + 64, 0, 1, 0, 178, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 12, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 16, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 4, 0, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 130, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 130, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 68, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 20, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 15, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_2_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_2_1024._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_2_1024 /D BONESPERVERTEX=2 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xy, v4.xyxx, l(3, 3, 0, 0) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r1.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 26 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_2_1024[] = +{ + 68, 88, 66, 67, 141, 10, + 58, 114, 205, 161, 106, 233, + 192, 250, 130, 22, 138, 17, + 51, 208, 1, 0, 0, 0, + 40, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 172, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 128, 3, 0, 0, 64, 0, + 1, 0, 224, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 50, 0, 16, 0, 1, 0, + 0, 0, 70, 16, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 3, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 3, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 17, 0, + 0, 7, 34, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 4, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 4, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 66, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 68, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 68, 0, 0, 5, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 26, 0, 0, 0, + 5, 0, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 0, + 18, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Normal_Tangent_4_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 +// /FhStreamOutSkinVS_Position_Normal_Tangent_4_1024._fxctmp +// /EStreamOutSkinVS_Position_Normal_Tangent_4_1024 /D BONESPERVERTEX=4 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float xyz +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v1.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 5 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +mul r4.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r4.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r4.xyzw +mad r4.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r4.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r4.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r0.x, v1.xyzx, r2.xyzx +dp3 r2.x, v2.xyzx, r2.xyzx +dp3 r0.y, v1.xyzx, r3.xyzx +dp3 r2.y, v2.xyzx, r3.xyzx +dp3 r0.z, v1.xyzx, r1.xyzx +dp3 r2.z, v2.xyzx, r1.xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o1.xyz, r0.wwww, r0.xyzx +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 32 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Normal_Tangent_4_1024[] = +{ + 68, 88, 66, 67, 235, 12, + 76, 146, 76, 200, 134, 63, + 160, 113, 162, 246, 112, 11, + 54, 15, 1, 0, 0, 0, + 64, 7, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 196, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 7, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 152, 4, 0, 0, 64, 0, + 1, 0, 38, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 5, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 42, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 10, 242, 0, + 16, 0, 4, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 6, 16, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 4, 0, 0, 0, 166, 26, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 50, 0, + 0, 12, 242, 0, 16, 0, + 1, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 4, 0, 0, 0, 17, 0, + 0, 7, 66, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 2, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 16, 0, 0, 7, + 34, 0, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 70, 2, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 1, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 2, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 32, 0, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0, + 8, 0, 0, 0, 18, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_1_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_1_32._fxctmp +// /EStreamOutSkinVS_Position_Tangent_1_32 /D BONESPERVERTEX=1 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_1_32[] = +{ + 68, 88, 66, 67, 155, 136, + 95, 216, 115, 102, 245, 76, + 254, 126, 247, 116, 91, 41, + 64, 92, 1, 0, 0, 0, + 156, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 32, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 28, 2, 0, 0, + 64, 0, 1, 0, 135, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 96, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 9, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 10, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 66, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 9, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_2_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_2_32._fxctmp +// /EStreamOutSkinVS_Position_Tangent_2_32 /D BONESPERVERTEX=2 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v2.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v2.xyzx, r0.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r1.xyzx +mov o2.w, v2.w +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_2_32[] = +{ + 68, 88, 66, 67, 74, 166, + 39, 5, 4, 115, 242, 165, + 31, 126, 146, 216, 128, 93, + 62, 203, 1, 0, 0, 0, + 156, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 32, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 244, 2, 0, 0, 64, 0, + 1, 0, 189, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 12, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_4_32 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_4_32._fxctmp +// /EStreamOutSkinVS_Position_Tangent_4_32 /D BONESPERVERTEX=4 /D +// BONECOUNT=32 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[32]; // Offset: 0 Size: 1536 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[96], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v2.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v2.xyzx, r1.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 27 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_4_32[] = +{ + 68, 88, 66, 67, 101, 9, + 26, 176, 87, 130, 115, 71, + 112, 118, 24, 231, 13, 111, + 146, 143, 1, 0, 0, 0, + 180, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 56, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 6, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 6, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 12, 4, 0, 0, 64, 0, + 1, 0, 3, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 96, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 2, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 2, 0, + 0, 0, 58, 16, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 27, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_1_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_1_64._fxctmp +// /EStreamOutSkinVS_Position_Tangent_1_64 /D BONESPERVERTEX=1 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_1_64[] = +{ + 68, 88, 66, 67, 223, 179, + 178, 177, 55, 242, 85, 24, + 184, 123, 141, 221, 32, 76, + 190, 235, 1, 0, 0, 0, + 156, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 32, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 28, 2, 0, 0, + 64, 0, 1, 0, 135, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 192, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 9, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 10, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 66, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 9, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_2_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_2_64._fxctmp +// /EStreamOutSkinVS_Position_Tangent_2_64 /D BONESPERVERTEX=2 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v2.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v2.xyzx, r0.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r1.xyzx +mov o2.w, v2.w +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_2_64[] = +{ + 68, 88, 66, 67, 17, 28, + 161, 25, 179, 10, 98, 159, + 87, 246, 21, 62, 158, 233, + 50, 151, 1, 0, 0, 0, + 156, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 32, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 244, 2, 0, 0, 64, 0, + 1, 0, 189, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 12, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_4_64 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_4_64._fxctmp +// /EStreamOutSkinVS_Position_Tangent_4_64 /D BONESPERVERTEX=4 /D +// BONECOUNT=64 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[64]; // Offset: 0 Size: 3072 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[192], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v2.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v2.xyzx, r1.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 27 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_4_64[] = +{ + 68, 88, 66, 67, 229, 79, + 236, 197, 243, 207, 198, 124, + 162, 172, 47, 223, 207, 244, + 139, 83, 1, 0, 0, 0, + 180, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 56, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 12, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 12, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 64, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 12, 4, 0, 0, 64, 0, + 1, 0, 3, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 192, 0, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 2, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 2, 0, + 0, 0, 58, 16, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 27, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_1_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_1_128._fxctmp +// /EStreamOutSkinVS_Position_Tangent_1_128 /D BONESPERVERTEX=1 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_1_128[] = +{ + 68, 88, 66, 67, 155, 62, + 239, 20, 245, 251, 229, 47, + 64, 93, 111, 50, 202, 43, + 65, 96, 1, 0, 0, 0, + 156, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 32, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 28, 2, 0, 0, + 64, 0, 1, 0, 135, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 128, 1, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 9, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 10, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 66, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 9, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_2_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_2_128._fxctmp +// /EStreamOutSkinVS_Position_Tangent_2_128 /D BONESPERVERTEX=2 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v2.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v2.xyzx, r0.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r1.xyzx +mov o2.w, v2.w +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_2_128[] = +{ + 68, 88, 66, 67, 62, 144, + 168, 178, 158, 150, 177, 42, + 146, 79, 210, 175, 39, 30, + 191, 85, 1, 0, 0, 0, + 156, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 32, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 244, 2, 0, 0, 64, 0, + 1, 0, 189, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 12, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_4_128 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_4_128._fxctmp +// /EStreamOutSkinVS_Position_Tangent_4_128 /D BONESPERVERTEX=4 /D +// BONECOUNT=128 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[128]; // Offset: 0 Size: 6144 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[384], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v2.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v2.xyzx, r1.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 27 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_4_128[] = +{ + 68, 88, 66, 67, 137, 190, + 252, 77, 211, 109, 185, 9, + 192, 197, 98, 56, 223, 218, + 111, 4, 1, 0, 0, 0, + 180, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 56, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 24, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 24, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 128, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 12, 4, 0, 0, 64, 0, + 1, 0, 3, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 128, 1, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 2, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 2, 0, + 0, 0, 58, 16, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 27, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_1_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_1_512._fxctmp +// /EStreamOutSkinVS_Position_Tangent_1_512 /D BONESPERVERTEX=1 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_1_512[] = +{ + 68, 88, 66, 67, 129, 231, + 80, 65, 53, 30, 137, 110, + 197, 69, 143, 55, 142, 52, + 43, 188, 1, 0, 0, 0, + 156, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 32, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 28, 2, 0, 0, + 64, 0, 1, 0, 135, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 6, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 9, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 10, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 66, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 9, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_2_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_2_512._fxctmp +// /EStreamOutSkinVS_Position_Tangent_2_512 /D BONESPERVERTEX=2 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v2.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v2.xyzx, r0.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r1.xyzx +mov o2.w, v2.w +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_2_512[] = +{ + 68, 88, 66, 67, 113, 49, + 101, 137, 248, 85, 224, 14, + 56, 186, 158, 161, 211, 124, + 112, 55, 1, 0, 0, 0, + 156, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 32, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 244, 2, 0, 0, 64, 0, + 1, 0, 189, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 12, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_4_512 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_4_512._fxctmp +// /EStreamOutSkinVS_Position_Tangent_4_512 /D BONESPERVERTEX=4 /D +// BONECOUNT=512 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[512]; // Offset: 0 Size: 24576 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[1536], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v2.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v2.xyzx, r1.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 27 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_4_512[] = +{ + 68, 88, 66, 67, 123, 183, + 28, 216, 174, 74, 90, 228, + 114, 33, 239, 11, 70, 207, + 115, 126, 1, 0, 0, 0, + 180, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 56, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 96, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 96, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 2, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 12, 4, 0, 0, 64, 0, + 1, 0, 3, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 6, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 2, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 2, 0, + 0, 0, 58, 16, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 27, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_1_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_1_1024._fxctmp +// /EStreamOutSkinVS_Position_Tangent_1_1024 /D BONESPERVERTEX=1 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BONEINDEX 0 x 3 NONE int x +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.x +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 2 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.x, v3.x, l(3) +dp4 o0.x, r0.xyzw, cb0[r1.x + 0].xyzw +dp4 o0.y, r0.xyzw, cb0[r1.x + 1].xyzw +dp4 o0.z, r0.xyzw, cb0[r1.x + 2].xyzw +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, v2.xyzx, cb0[r1.x + 0].xyzx +dp3 r0.y, v2.xyzx, cb0[r1.x + 1].xyzx +dp3 r0.z, v2.xyzx, cb0[r1.x + 2].xyzx +dp3 r0.w, r0.xyzx, r0.xyzx +rsq r0.w, r0.w +mul o2.xyz, r0.wwww, r0.xyzx +mov o2.w, v2.w +ret +// Approximately 15 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_1_1024[] = +{ + 68, 88, 66, 67, 38, 248, + 167, 170, 23, 21, 153, 218, + 35, 216, 26, 106, 21, 87, + 80, 123, 1, 0, 0, 0, + 156, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 144, 1, + 0, 0, 252, 1, 0, 0, + 32, 4, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 113, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 120, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 3, 0, 0, 0, + 1, 1, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 79, + 78, 69, 73, 78, 68, 69, + 88, 0, 171, 171, 79, 83, + 71, 78, 100, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 7, 8, + 0, 0, 89, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 0, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 171, 171, 83, 72, + 68, 82, 28, 2, 0, 0, + 64, 0, 1, 0, 135, 0, + 0, 0, 89, 8, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 12, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 95, 0, 0, 3, 18, 16, + 16, 0, 3, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 0, 0, 0, 0, + 101, 0, 0, 3, 114, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 2, 0, 0, 0, + 104, 0, 0, 2, 2, 0, + 0, 0, 54, 0, 0, 5, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 38, 0, 0, 8, 0, 208, + 0, 0, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 16, + 16, 0, 3, 0, 0, 0, + 1, 64, 0, 0, 3, 0, + 0, 0, 17, 0, 0, 9, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 17, 0, 0, 10, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 17, 0, 0, 10, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 9, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 10, 34, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 130, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 10, 66, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 16, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 68, 0, 0, 5, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 2, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 2, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 15, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 6, 0, 0, 0, + 9, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_2_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_2_1024._fxctmp +// /EStreamOutSkinVS_Position_Tangent_2_1024 /D BONESPERVERTEX=2 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xy 3 NONE float xy +// BLENDINDICES 0 xy 4 NONE int xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xy +dcl_input v4.xy +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +imul null, r0.xy, v4.xyxx, l(3, 3, 0, 0) +mul r1.xyzw, v3.yyyy, cb0[r0.y + 0].xyzw +mad r1.xyzw, v3.xxxx, cb0[r0.x + 0].xyzw, r1.xyzw +mov r2.xyz, v0.xyzx +mov r2.w, l(1.000000) +dp4 o0.x, r2.xyzw, r1.xyzw +dp3 r1.x, v2.xyzx, r1.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r0.x + 1].xyzw, r3.xyzw +dp4 o0.y, r2.xyzw, r3.xyzw +dp3 r1.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r0.y + 2].xyzw +mad r0.xyzw, v3.xxxx, cb0[r0.x + 2].xyzw, r3.xyzw +dp4 o0.z, r2.xyzw, r0.xyzw +dp3 r1.z, v2.xyzx, r0.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r1.xyzx, r1.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r1.xyzx +mov o2.w, v2.w +ret +// Approximately 21 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_2_1024[] = +{ + 68, 88, 66, 67, 145, 156, + 116, 21, 77, 210, 128, 144, + 84, 248, 102, 43, 138, 123, + 120, 5, 1, 0, 0, 0, + 156, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 32, 5, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 3, 3, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 3, 3, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 244, 2, 0, 0, 64, 0, + 1, 0, 189, 0, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 38, 0, 0, 11, 0, 208, + 0, 0, 50, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 4, 0, 0, 0, + 2, 64, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 56, 0, 0, 9, + 242, 0, 16, 0, 1, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 1, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 114, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 0, + 16, 0, 2, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 17, 0, 0, 7, + 18, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 1, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 3, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 34, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 16, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 10, 242, 0, 16, 0, + 3, 0, 0, 0, 86, 21, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 6, 0, 0, + 0, 0, 2, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 12, + 242, 0, 16, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 3, 0, + 0, 0, 17, 0, 0, 7, + 66, 32, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 66, 0, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 2, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 8, 114, 32, 16, 0, + 1, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 68, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 2, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 2, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 21, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 7, 0, 0, 0, 12, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; +//-------------------------------------------------------------- +// StreamOutSkinVS_Position_Tangent_4_1024 +//-------------------------------------------------------------- +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /nologo /T vs_4_0 /FhStreamOutSkinVS_Position_Tangent_4_1024._fxctmp +// /EStreamOutSkinVS_Position_Tangent_4_1024 /D BONESPERVERTEX=4 /D +// BONECOUNT=1024 internalshaders.hlsl +// +// +// Buffer Definitions: +// +// cbuffer cbBones +// { +// +// float4x3 bones[1024]; // Offset: 0 Size: 49152 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim Slot Elements +// ------------------------------ ---------- ------- ----------- ---- -------- +// cbBones cbuffer NA NA 0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// NORMAL 0 xyz 1 NONE float +// TANGENT 0 xyzw 2 NONE float xyzw +// BLENDWEIGHT 0 xyzw 3 NONE float xyzw +// BLENDINDICES 0 xyzw 4 NONE int xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xyz 1 NONE float xyz +// TEXCOORD 1 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer cb0[3072], dynamicIndexed +dcl_input v0.xyz +dcl_input v2.xyzw +dcl_input v3.xyzw +dcl_input v4.xyzw +dcl_output o0.xyz +dcl_output o1.xyz +dcl_output o2.xyzw +dcl_temps 4 +mov r0.xyz, v0.xyzx +mov r0.w, l(1.000000) +imul null, r1.xyzw, v4.xyzw, l(3, 3, 3, 3) +mul r2.xyzw, v3.yyyy, cb0[r1.y + 0].xyzw +mad r2.xyzw, v3.xxxx, cb0[r1.x + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.zzzz, cb0[r1.z + 0].xyzw, r2.xyzw +mad r2.xyzw, v3.wwww, cb0[r1.w + 0].xyzw, r2.xyzw +dp4 o0.x, r0.xyzw, r2.xyzw +dp3 r2.x, v2.xyzx, r2.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 1].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 1].xyzw, r3.xyzw +mad r3.xyzw, v3.wwww, cb0[r1.w + 1].xyzw, r3.xyzw +dp4 o0.y, r0.xyzw, r3.xyzw +dp3 r2.y, v2.xyzx, r3.xyzx +mul r3.xyzw, v3.yyyy, cb0[r1.y + 2].xyzw +mad r3.xyzw, v3.xxxx, cb0[r1.x + 2].xyzw, r3.xyzw +mad r3.xyzw, v3.zzzz, cb0[r1.z + 2].xyzw, r3.xyzw +mad r1.xyzw, v3.wwww, cb0[r1.w + 2].xyzw, r3.xyzw +dp4 o0.z, r0.xyzw, r1.xyzw +dp3 r2.z, v2.xyzx, r1.xyzx +mov o1.xyz, l(0,0,0,0) +dp3 r0.x, r2.xyzx, r2.xyzx +rsq r0.x, r0.x +mul o2.xyz, r0.xxxx, r2.xyzx +mov o2.w, v2.w +ret +// Approximately 27 instruction slots used +#endif + +const BYTE g_StreamOutSkinVS_Position_Tangent_4_1024[] = +{ + 68, 88, 66, 67, 134, 193, + 76, 236, 200, 241, 162, 242, + 117, 255, 185, 145, 58, 140, + 105, 114, 1, 0, 0, 0, + 180, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 252, 0, 0, 0, 184, 1, + 0, 0, 36, 2, 0, 0, + 56, 6, 0, 0, 82, 68, + 69, 70, 192, 0, 0, 0, + 1, 0, 0, 0, 68, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 140, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 99, 98, 66, 111, 110, 101, + 115, 0, 60, 0, 0, 0, + 1, 0, 0, 0, 92, 0, + 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 192, + 0, 0, 2, 0, 0, 0, + 124, 0, 0, 0, 0, 0, + 0, 0, 98, 111, 110, 101, + 115, 0, 171, 171, 3, 0, + 3, 0, 4, 0, 3, 0, + 0, 4, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 57, 46, 50, 57, 46, + 57, 53, 50, 46, 51, 49, + 49, 49, 0, 171, 171, 171, + 73, 83, 71, 78, 180, 0, + 0, 0, 5, 0, 0, 0, + 8, 0, 0, 0, 128, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 7, 7, 0, 0, 137, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 7, 0, 0, 0, 144, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 15, 15, 0, 0, 152, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 164, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 4, 0, 0, 0, + 15, 15, 0, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 78, 79, 82, 77, 65, + 76, 0, 84, 65, 78, 71, + 69, 78, 84, 0, 66, 76, + 69, 78, 68, 87, 69, 73, + 71, 72, 84, 0, 66, 76, + 69, 78, 68, 73, 78, 68, + 73, 67, 69, 83, 0, 171, + 171, 171, 79, 83, 71, 78, + 100, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 7, 8, 0, 0, + 89, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 171, 171, 83, 72, 68, 82, + 12, 4, 0, 0, 64, 0, + 1, 0, 3, 1, 0, 0, + 89, 8, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 12, 0, 0, 95, 0, + 0, 3, 114, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 3, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 4, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 0, 0, 0, 0, 101, 0, + 0, 3, 114, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 4, 0, 0, 0, + 54, 0, 0, 5, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 38, 0, + 0, 11, 0, 208, 0, 0, + 242, 0, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 4, 0, 0, 0, 2, 64, + 0, 0, 3, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 56, 0, 0, 9, 242, 0, + 16, 0, 2, 0, 0, 0, + 86, 21, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 11, 242, 0, + 16, 0, 2, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 4, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 2, 0, + 0, 0, 50, 0, 0, 11, + 242, 0, 16, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 4, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 50, 0, + 0, 11, 242, 0, 16, 0, + 2, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 70, 142, 32, 4, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 2, 0, 0, 0, + 17, 0, 0, 7, 18, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 2, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 34, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 3, 0, 0, 0, 16, 0, + 0, 7, 34, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 10, + 242, 0, 16, 0, 3, 0, + 0, 0, 86, 21, 16, 0, + 3, 0, 0, 0, 70, 142, + 32, 6, 0, 0, 0, 0, + 2, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 6, 16, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 3, 0, 0, 0, + 166, 26, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 42, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 50, 0, 0, 12, 242, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 142, 32, 6, + 0, 0, 0, 0, 2, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 3, 0, 0, 0, + 17, 0, 0, 7, 66, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 1, 0, 0, 0, 16, 0, + 0, 7, 66, 0, 16, 0, + 2, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 8, + 114, 32, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 68, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 2, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 2, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 2, 0, + 0, 0, 58, 16, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 27, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 12, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; +const BYTE * g_StreamOutShaders[4][5][3] = { +{ +{ +g_StreamOutSkinVS_Position_1_32, +g_StreamOutSkinVS_Position_2_32, +g_StreamOutSkinVS_Position_4_32, +}, +{ +g_StreamOutSkinVS_Position_1_64, +g_StreamOutSkinVS_Position_2_64, +g_StreamOutSkinVS_Position_4_64, +}, +{ +g_StreamOutSkinVS_Position_1_128, +g_StreamOutSkinVS_Position_2_128, +g_StreamOutSkinVS_Position_4_128, +}, +{ +g_StreamOutSkinVS_Position_1_512, +g_StreamOutSkinVS_Position_2_512, +g_StreamOutSkinVS_Position_4_512, +}, +{ +g_StreamOutSkinVS_Position_1_1024, +g_StreamOutSkinVS_Position_2_1024, +g_StreamOutSkinVS_Position_4_1024, +}, +}, +{ +{ +g_StreamOutSkinVS_Position_Normal_1_32, +g_StreamOutSkinVS_Position_Normal_2_32, +g_StreamOutSkinVS_Position_Normal_4_32, +}, +{ +g_StreamOutSkinVS_Position_Normal_1_64, +g_StreamOutSkinVS_Position_Normal_2_64, +g_StreamOutSkinVS_Position_Normal_4_64, +}, +{ +g_StreamOutSkinVS_Position_Normal_1_128, +g_StreamOutSkinVS_Position_Normal_2_128, +g_StreamOutSkinVS_Position_Normal_4_128, +}, +{ +g_StreamOutSkinVS_Position_Normal_1_512, +g_StreamOutSkinVS_Position_Normal_2_512, +g_StreamOutSkinVS_Position_Normal_4_512, +}, +{ +g_StreamOutSkinVS_Position_Normal_1_1024, +g_StreamOutSkinVS_Position_Normal_2_1024, +g_StreamOutSkinVS_Position_Normal_4_1024, +}, +}, +{ +{ +g_StreamOutSkinVS_Position_Normal_Tangent_1_32, +g_StreamOutSkinVS_Position_Normal_Tangent_2_32, +g_StreamOutSkinVS_Position_Normal_Tangent_4_32, +}, +{ +g_StreamOutSkinVS_Position_Normal_Tangent_1_64, +g_StreamOutSkinVS_Position_Normal_Tangent_2_64, +g_StreamOutSkinVS_Position_Normal_Tangent_4_64, +}, +{ +g_StreamOutSkinVS_Position_Normal_Tangent_1_128, +g_StreamOutSkinVS_Position_Normal_Tangent_2_128, +g_StreamOutSkinVS_Position_Normal_Tangent_4_128, +}, +{ +g_StreamOutSkinVS_Position_Normal_Tangent_1_512, +g_StreamOutSkinVS_Position_Normal_Tangent_2_512, +g_StreamOutSkinVS_Position_Normal_Tangent_4_512, +}, +{ +g_StreamOutSkinVS_Position_Normal_Tangent_1_1024, +g_StreamOutSkinVS_Position_Normal_Tangent_2_1024, +g_StreamOutSkinVS_Position_Normal_Tangent_4_1024, +}, +}, +{ +{ +g_StreamOutSkinVS_Position_Tangent_1_32, +g_StreamOutSkinVS_Position_Tangent_2_32, +g_StreamOutSkinVS_Position_Tangent_4_32, +}, +{ +g_StreamOutSkinVS_Position_Tangent_1_64, +g_StreamOutSkinVS_Position_Tangent_2_64, +g_StreamOutSkinVS_Position_Tangent_4_64, +}, +{ +g_StreamOutSkinVS_Position_Tangent_1_128, +g_StreamOutSkinVS_Position_Tangent_2_128, +g_StreamOutSkinVS_Position_Tangent_4_128, +}, +{ +g_StreamOutSkinVS_Position_Tangent_1_512, +g_StreamOutSkinVS_Position_Tangent_2_512, +g_StreamOutSkinVS_Position_Tangent_4_512, +}, +{ +g_StreamOutSkinVS_Position_Tangent_1_1024, +g_StreamOutSkinVS_Position_Tangent_2_1024, +g_StreamOutSkinVS_Position_Tangent_4_1024, +}, +}, +}; +const size_t g_StreamOutShaderSizes[4][5][3] = { +{ +{ +sizeof(g_StreamOutSkinVS_Position_1_32), +sizeof(g_StreamOutSkinVS_Position_2_32), +sizeof(g_StreamOutSkinVS_Position_4_32), +}, +{ +sizeof(g_StreamOutSkinVS_Position_1_64), +sizeof(g_StreamOutSkinVS_Position_2_64), +sizeof(g_StreamOutSkinVS_Position_4_64), +}, +{ +sizeof(g_StreamOutSkinVS_Position_1_128), +sizeof(g_StreamOutSkinVS_Position_2_128), +sizeof(g_StreamOutSkinVS_Position_4_128), +}, +{ +sizeof(g_StreamOutSkinVS_Position_1_512), +sizeof(g_StreamOutSkinVS_Position_2_512), +sizeof(g_StreamOutSkinVS_Position_4_512), +}, +{ +sizeof(g_StreamOutSkinVS_Position_1_1024), +sizeof(g_StreamOutSkinVS_Position_2_1024), +sizeof(g_StreamOutSkinVS_Position_4_1024), +}, +}, +{ +{ +sizeof(g_StreamOutSkinVS_Position_Normal_1_32), +sizeof(g_StreamOutSkinVS_Position_Normal_2_32), +sizeof(g_StreamOutSkinVS_Position_Normal_4_32), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_1_64), +sizeof(g_StreamOutSkinVS_Position_Normal_2_64), +sizeof(g_StreamOutSkinVS_Position_Normal_4_64), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_1_128), +sizeof(g_StreamOutSkinVS_Position_Normal_2_128), +sizeof(g_StreamOutSkinVS_Position_Normal_4_128), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_1_512), +sizeof(g_StreamOutSkinVS_Position_Normal_2_512), +sizeof(g_StreamOutSkinVS_Position_Normal_4_512), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_1_1024), +sizeof(g_StreamOutSkinVS_Position_Normal_2_1024), +sizeof(g_StreamOutSkinVS_Position_Normal_4_1024), +}, +}, +{ +{ +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_1_32), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_2_32), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_4_32), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_1_64), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_2_64), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_4_64), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_1_128), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_2_128), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_4_128), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_1_512), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_2_512), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_4_512), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_1_1024), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_2_1024), +sizeof(g_StreamOutSkinVS_Position_Normal_Tangent_4_1024), +}, +}, +{ +{ +sizeof(g_StreamOutSkinVS_Position_Tangent_1_32), +sizeof(g_StreamOutSkinVS_Position_Tangent_2_32), +sizeof(g_StreamOutSkinVS_Position_Tangent_4_32), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Tangent_1_64), +sizeof(g_StreamOutSkinVS_Position_Tangent_2_64), +sizeof(g_StreamOutSkinVS_Position_Tangent_4_64), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Tangent_1_128), +sizeof(g_StreamOutSkinVS_Position_Tangent_2_128), +sizeof(g_StreamOutSkinVS_Position_Tangent_4_128), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Tangent_1_512), +sizeof(g_StreamOutSkinVS_Position_Tangent_2_512), +sizeof(g_StreamOutSkinVS_Position_Tangent_4_512), +}, +{ +sizeof(g_StreamOutSkinVS_Position_Tangent_1_1024), +sizeof(g_StreamOutSkinVS_Position_Tangent_2_1024), +sizeof(g_StreamOutSkinVS_Position_Tangent_4_1024), +}, +}, +}; diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/compile_all.bat b/Runtime/GfxDevice/d3d11/InternalShaders/compile_all.bat new file mode 100644 index 0000000..055f100 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/compile_all.bat @@ -0,0 +1,82 @@ +@echo off +del FFShaderLib.h +call "CompileShaderLib\CompileShaderLib.exe" FFShaderLib.hlsl FFShaderLib.h + +del builtin.h + +echo // > builtin.h +echo // >> builtin.h +echo // Autogenerated file. Do not modify! >> builtin.h +echo // >> builtin.h +echo // >> builtin.h + +echo const BYTE * g_StreamOutShaders[4][5][3] = { >tmp.h +echo const size_t g_StreamOutShaderSizes[4][5][3] = { >tmp2.h + +call:compile StreamOutSkinVS_Position +call:compile StreamOutSkinVS_Position_Normal +call:compile StreamOutSkinVS_Position_Normal_Tangent +call:compile StreamOutSkinVS_Position_Tangent + +echo }; >>tmp.h +echo }; >>tmp2.h + +type tmp.h >>builtin.h +type tmp2.h >>builtin.h + +del tmp.h +del tmp2.h + +goto:eof + +:compile + +echo { >>tmp.h +echo { >>tmp2.h + +call:compilecbvariants %~1 32 +call:compilecbvariants %~1 64 +call:compilecbvariants %~1 128 +call:compilecbvariants %~1 512 +call:compilecbvariants %~1 1024 + +echo }, >>tmp.h +echo }, >>tmp2.h + + +goto:eof + +::- Compiles all variants for a given bone constant buffer size +::- Arguments: %~1 = entrypoint name, %~2 = max bone count +:compilecbvariants + +echo { >>tmp.h +echo { >>tmp2.h + +call:compilevariant %~1 1 %~2 +call:compilevariant %~1 2 %~2 +call:compilevariant %~1 4 %~2 + +echo },>>tmp.h +echo },>>tmp2.h + + +goto:eof + +::- Compiles a single shader variant +::- Arguments: %~1 = entrypoint name %~2 = bones per vertex %~3 = max bone count +:compilevariant + +call "%DXSDK_DIR%\Utilities\bin\x64\fxc.exe" /nologo /T vs_4_0 /Fh%~1_%~2_%~3._fxctmp /E%~1_%~2_%~3 /D BONESPERVERTEX=%~2 /D BONECOUNT=%~3 internalshaders.hlsl + +echo //-------------------------------------------------------------- >> builtin.h +echo // %~1_%~2_%~3 >> builtin.h +echo //-------------------------------------------------------------- >> builtin.h + +type %~1_%~2_%~3._fxctmp >> builtin.h +del %~1_%~2_%~3._fxctmp + +echo g_%~1_%~2_%~3, >>tmp.h +echo sizeof(g_%~1_%~2_%~3), >> tmp2.h + +goto:eof diff --git a/Runtime/GfxDevice/d3d11/InternalShaders/internalshaders.hlsl b/Runtime/GfxDevice/d3d11/InternalShaders/internalshaders.hlsl new file mode 100644 index 0000000..2dce211 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/InternalShaders/internalshaders.hlsl @@ -0,0 +1,119 @@ +//-------------------------------------------------------------------------------------- +// Vertex shaders for stream-out GPU skinning. +//-------------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------------- +// Globals +//-------------------------------------------------------------------------------------- +cbuffer cbBones : register ( b0 ) +{ + float4x3 bones[BONECOUNT]; +} + +//-------------------------------------------------------------------------------------- +// Input / Output structures +//-------------------------------------------------------------------------------------- +struct VS_IN_MEX +{ + // Stream 0 + float3 Position : POSITION; + float3 Normal : NORMAL; + float4 Tangent : TANGENT; + + // Stream 1 +#if BONESPERVERTEX == 4 + float4 BoneWeights : BLENDWEIGHT; + int4 BoneIndices : BLENDINDICES; + +#elif BONESPERVERTEX == 2 + float2 BoneWeights : BLENDWEIGHT; + int2 BoneIndices : BLENDINDICES; + +#else // 1 bone per vertex + int BoneIndices : BONEINDEX; + +#endif +}; + +struct VS_OUTPUT +{ + float3 vPosition : POSITION; + float3 vNormal : TEXCOORD0; + float4 vTangent : TEXCOORD1; +}; + +// --- Bones --- +inline float4x3 FetchBoneMatrix( int boneIndex ) +{ + return (float4x3)(bones[boneIndex]); +} +//-------------------------------------------------------------------------------------- +// Vertex Shader +//-------------------------------------------------------------------------------------- +VS_OUTPUT VSMain( VS_IN_MEX Input, uniform bool useNormal, uniform bool useTangent) +{ + VS_OUTPUT Output = (VS_OUTPUT)0; + +#if BONESPERVERTEX == 4 + float boneWeights[4] = (float[4])Input.BoneWeights; + int boneIndices[4] = (int[4])Input.BoneIndices; + + float4x3 localToWorldMatrix = boneWeights[0] * FetchBoneMatrix(boneIndices[0]) + + boneWeights[1] * FetchBoneMatrix(boneIndices[1]) + + boneWeights[2] * FetchBoneMatrix(boneIndices[2]) + + boneWeights[3] * FetchBoneMatrix(boneIndices[3]); + +#elif BONESPERVERTEX == 2 + float boneWeights[2] = (float[2])Input.BoneWeights; + int boneIndices[2] = (int[2])Input.BoneIndices; + + float4x3 localToWorldMatrix = boneWeights[0] * FetchBoneMatrix(boneIndices[0]) + + boneWeights[1] * FetchBoneMatrix(boneIndices[1]); + + +#else // 1 + int boneIndex = Input.BoneIndices; + + float4x3 localToWorldMatrix = FetchBoneMatrix(boneIndex); +#endif + + // Position + Output.vPosition = mul( float4(Input.Position.xyz, 1.0), localToWorldMatrix ).xyz; + if (useNormal) + { + Output.vNormal = normalize( mul( float4(Input.Normal.xyz,0.0f), localToWorldMatrix ) ).xyz; + } + + // Tangent + if (useTangent) + { + float3 outTangent3 = normalize( mul( float4(Input.Tangent.xyz,0.0f), localToWorldMatrix ) ).xyz; + Output.vTangent = float4(outTangent3, Input.Tangent.w); + } + + return Output; +} + +// Functions are named StreamOutSkinVS_<components>_<bonespervertex>_<maxbonecount> + +#define MERGE(a, b, c, delim) a##delim##b##delim##c + +VS_OUTPUT MERGE(StreamOutSkinVS_Position,BONESPERVERTEX,BONECOUNT,_)(VS_IN_MEX Input) +{ + return VSMain(Input, false, false); +} + +VS_OUTPUT MERGE(StreamOutSkinVS_Position_Normal,BONESPERVERTEX,BONECOUNT,_)(VS_IN_MEX Input) +{ + return VSMain(Input, true, false); +} + +VS_OUTPUT MERGE(StreamOutSkinVS_Position_Normal_Tangent,BONESPERVERTEX,BONECOUNT,_)(VS_IN_MEX Input) +{ + return VSMain(Input, true, true); +} + +VS_OUTPUT MERGE(StreamOutSkinVS_Position_Tangent,BONESPERVERTEX,BONECOUNT,_)(VS_IN_MEX Input) +{ + return VSMain(Input, false, true); +} diff --git a/Runtime/GfxDevice/d3d11/RenderTextureD3D11.cpp b/Runtime/GfxDevice/d3d11/RenderTextureD3D11.cpp new file mode 100644 index 0000000..9c50172 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/RenderTextureD3D11.cpp @@ -0,0 +1,805 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "D3D11Context.h" +#include "D3D11Utils.h" +#include "TexturesD3D11.h" + +void UnbindTextureD3D11 (TextureID texture); + +//Resource format +DXGI_FORMAT kD3D11RenderResourceFormats[kRTFormatCount] = { + DXGI_FORMAT_R8G8B8A8_TYPELESS, + DXGI_FORMAT_R24G8_TYPELESS, + DXGI_FORMAT_R16G16B16A16_TYPELESS, + DXGI_FORMAT_R16_TYPELESS, + (DXGI_FORMAT)-1, // RGB565, unsupported + (DXGI_FORMAT)-1, // ARGB4444, unsupported + (DXGI_FORMAT)-1, // ARGB1555, unsupported + (DXGI_FORMAT)-1, // Default + DXGI_FORMAT_R10G10B10A2_TYPELESS, + (DXGI_FORMAT)-1, // DefaultHDR + DXGI_FORMAT_R16G16B16A16_TYPELESS, + DXGI_FORMAT_R32G32B32A32_TYPELESS, + DXGI_FORMAT_R32G32_TYPELESS, + DXGI_FORMAT_R16G16_TYPELESS, + DXGI_FORMAT_R32_TYPELESS, + DXGI_FORMAT_R16_TYPELESS, + DXGI_FORMAT_R8_TYPELESS, // R8 + DXGI_FORMAT_R32G32B32A32_TYPELESS, // ARGBInt + DXGI_FORMAT_R32G32_TYPELESS, // RGInt + DXGI_FORMAT_R32_TYPELESS, // RInt + DXGI_FORMAT_B8G8R8A8_TYPELESS, +}; + +//Standard view +DXGI_FORMAT kD3D11RenderTextureFormatsNorm[kRTFormatCount] = { + DXGI_FORMAT_R8G8B8A8_UNORM, + DXGI_FORMAT_D24_UNORM_S8_UINT, + DXGI_FORMAT_R16G16B16A16_FLOAT, + DXGI_FORMAT_D16_UNORM, + (DXGI_FORMAT)-1, // RGB565, unsupported + (DXGI_FORMAT)-1, // ARGB4444, unsupported + (DXGI_FORMAT)-1, // ARGB1555, unsupported + (DXGI_FORMAT)-1, // Default + DXGI_FORMAT_R10G10B10A2_UNORM, + (DXGI_FORMAT)-1, // DefaultHDR + DXGI_FORMAT_R16G16B16A16_UNORM, + DXGI_FORMAT_R32G32B32A32_FLOAT, + DXGI_FORMAT_R32G32_FLOAT, + DXGI_FORMAT_R16G16_FLOAT, + DXGI_FORMAT_R32_FLOAT, + DXGI_FORMAT_R16_FLOAT, + DXGI_FORMAT_R8_UNORM, // R8 + DXGI_FORMAT_R32G32B32A32_SINT, // ARGBInt + DXGI_FORMAT_R32G32_SINT, // RGInt + DXGI_FORMAT_R32_SINT, // RInt + DXGI_FORMAT_B8G8R8A8_UNORM, // BGRA32 +}; + +// SRGBView... only used for RGBA8 buffers really. +DXGI_FORMAT kD3D11RenderTextureFormatsSRGB[kRTFormatCount] = { + DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, + DXGI_FORMAT_D24_UNORM_S8_UINT, + DXGI_FORMAT_R16G16B16A16_FLOAT, + DXGI_FORMAT_D16_UNORM, + (DXGI_FORMAT)-1, // RGB565, unsupported + (DXGI_FORMAT)-1, // ARGB4444, unsupported + (DXGI_FORMAT)-1, // ARGB1555, unsupported + (DXGI_FORMAT)-1, // Default + DXGI_FORMAT_R10G10B10A2_UNORM, + (DXGI_FORMAT)-1, // DefaultHDR + DXGI_FORMAT_R16G16B16A16_UNORM, + DXGI_FORMAT_R32G32B32A32_FLOAT, + DXGI_FORMAT_R32G32_FLOAT, + DXGI_FORMAT_R16G16_FLOAT, + DXGI_FORMAT_R32_FLOAT, + DXGI_FORMAT_R16_FLOAT, + DXGI_FORMAT_R8_UNORM, // R8 + DXGI_FORMAT_R32G32B32A32_SINT, // ARGBInt + DXGI_FORMAT_R32G32_SINT, // RGInt + DXGI_FORMAT_R32_SINT, // RInt + DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, +}; + +DXGI_FORMAT GetRenderTextureFormat (RenderTextureFormat format, bool sRGB) +{ + return sRGB ? kD3D11RenderTextureFormatsSRGB[format] : kD3D11RenderTextureFormatsNorm[format]; +} + +DXGI_FORMAT GetShaderResourceViewFormat (RenderTextureFormat format, bool sRGB) +{ + if (format == kRTFormatDepth) + { + return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + } + else if (format == kRTFormatShadowMap) + { + return DXGI_FORMAT_R16_UNORM; + } + else + { + return sRGB ? kD3D11RenderTextureFormatsSRGB[format] : kD3D11RenderTextureFormatsNorm[format]; + } +} + + +static ID3D11Resource* CreateTextureD3D11 (int width, int height, int depth, int mipLevels, DXGI_FORMAT format, UINT bindFlags, TextureDimension dim, int antiAlias) +{ + if (dim == kTexDim3D) + { + if (gGraphicsCaps.buggyMipmapped3DTextures) + mipLevels = 1; + D3D11_TEXTURE3D_DESC desc; + desc.Width = width; + desc.Height = height; + desc.Depth = depth; + desc.MipLevels = mipLevels; + desc.Format = format; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + if (mipLevels > 1) desc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; + ID3D11Texture3D* res = NULL; + HRESULT hr = GetD3D11Device()->CreateTexture3D (&desc, NULL, &res); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (res, Format("RenderTexture-3D-%dx%dx%d", width, height, depth)); + return res; + } + else + { + if (dim == kTexDimCUBE && gGraphicsCaps.buggyMipmappedCubemaps) + mipLevels = 1; + D3D11_TEXTURE2D_DESC desc; + desc.Width = width; + desc.Height = height; + desc.MipLevels = mipLevels; + desc.ArraySize = dim==kTexDimCUBE ? 6 : 1; + desc.Format = format; + desc.SampleDesc.Count = antiAlias; + desc.SampleDesc.Quality = 0; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + if (dim == kTexDimCUBE) desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; + if (mipLevels > 1) desc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; + ID3D11Texture2D* res = NULL; + HRESULT hr = GetD3D11Device()->CreateTexture2D (&desc, NULL, &res); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (res, Format("RenderTexture-2D-%dx%d", width, height)); + return res; + } +} + + +static bool InitD3D11RenderColorSurface (RenderColorSurfaceD3D11& rs, TexturesD3D11& textures) +{ + HRESULT hr; + ID3D11Device* dev = GetD3D11Device(); + + bool sRGBPrimary = (rs.flags & kSurfaceCreateSRGB); + + UINT bindFlags = 0; + if (!IsDepthRTFormat (rs.format)) + bindFlags |= D3D11_BIND_RENDER_TARGET; + if (rs.textureID.m_ID) + bindFlags |= D3D11_BIND_SHADER_RESOURCE; + if (rs.flags & kSurfaceCreateRandomWrite && gGraphicsCaps.d3d11.featureLevel >= kDX11Level11_0) + bindFlags |= D3D11_BIND_UNORDERED_ACCESS; + int mipLevels = 1; + int accessibleMipLevels = 1; + if ((rs.flags & kSurfaceCreateMipmap) && !IsDepthRTFormat(rs.format)) + { + mipLevels = CalculateMipMapCount3D (rs.width, rs.height, rs.depth); + if (!(rs.flags & kSurfaceCreateAutoGenMips)) + accessibleMipLevels = mipLevels; + } + const DXGI_FORMAT texFormat = (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ? kD3D11RenderResourceFormats[rs.format] : kD3D11RenderTextureFormatsNorm[rs.format]); + if (bindFlags != 0) + rs.m_Texture = CreateTextureD3D11 (rs.width, rs.height, rs.depth, mipLevels, texFormat, bindFlags, rs.dim, rs.samples); + else + rs.m_Texture = NULL; + // Render Target View + if (!IsDepthRTFormat (rs.format)) + { + D3D11_RENDER_TARGET_VIEW_DESC desc, descSecondary; + desc.Format = GetRenderTextureFormat (rs.format, gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ? sRGBPrimary : false); + descSecondary.Format = GetRenderTextureFormat (rs.format, gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 ? !sRGBPrimary : false); + ID3D11RenderTargetView* rtv = NULL; + if (rs.dim == kTexDim2D) + { + desc.ViewDimension = descSecondary.ViewDimension = rs.samples > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D; + for (int im = 0; im < accessibleMipLevels; ++im) + { + desc.Texture2D.MipSlice = descSecondary.Texture2D.MipSlice = im; + hr = dev->CreateRenderTargetView (rs.m_Texture, &desc, &rtv); + Assert (SUCCEEDED(hr)); + rs.SetRTV (0, im, false, rtv); + hr = dev->CreateRenderTargetView (rs.m_Texture, &descSecondary, &rtv); + Assert (SUCCEEDED(hr)); + rs.SetRTV (0, im, true, rtv); + } + } + else if (rs.dim == kTexDimCUBE) + { + desc.ViewDimension = descSecondary.ViewDimension = rs.samples > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY : D3D11_RTV_DIMENSION_TEXTURE2DARRAY; + desc.Texture2DArray.ArraySize = descSecondary.Texture2DArray.ArraySize = 1; + for (int im = 0; im < accessibleMipLevels; ++im) + { + desc.Texture2DArray.MipSlice = descSecondary.Texture2DArray.MipSlice = im; + for (int i = 0; i < 6; ++i) + { + desc.Texture2DArray.FirstArraySlice = descSecondary.Texture2DArray.FirstArraySlice = i; + hr = dev->CreateRenderTargetView (rs.m_Texture, &desc, &rtv); + Assert (SUCCEEDED(hr)); + rs.SetRTV (i, im, false, rtv); + + hr = dev->CreateRenderTargetView (rs.m_Texture, &descSecondary, &rtv); + Assert (SUCCEEDED(hr)); + rs.SetRTV (i, im, true, rtv); + } + } + } + else if (rs.dim == kTexDim3D) + { + desc.ViewDimension = descSecondary.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; + desc.Texture3D.MipSlice = descSecondary.Texture3D.MipSlice = 0; + desc.Texture3D.FirstWSlice = descSecondary.Texture3D.FirstWSlice = 0; + desc.Texture3D.WSize = descSecondary.Texture3D.WSize = -1; + hr = dev->CreateRenderTargetView (rs.m_Texture, &desc, &rtv); + Assert (SUCCEEDED(hr)); + rs.SetRTV (0, 0, false, rtv); + + hr = dev->CreateRenderTargetView (rs.m_Texture, &descSecondary, &rtv); + Assert (SUCCEEDED(hr)); + rs.SetRTV (0, 0, true, rtv); + } + } + + // Shader Resource View if needed + if (rs.textureID.m_ID) + { + D3D11_SHADER_RESOURCE_VIEW_DESC desc; + desc.Format = GetShaderResourceViewFormat (rs.format, (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) ? sRGBPrimary : false); + switch (rs.dim) { + case kTexDimCUBE: desc.ViewDimension = rs.samples > 1 ? D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D11_SRV_DIMENSION_TEXTURECUBE; break; + case kTexDim3D: desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; break; + default: desc.ViewDimension = rs.samples > 1 ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D; break; + } + desc.Texture2D.MostDetailedMip = 0; + desc.Texture2D.MipLevels = mipLevels; + + ID3D11ShaderResourceView* srView = NULL; + hr = dev->CreateShaderResourceView (rs.m_Texture, &desc, &rs.m_SRView); + Assert (SUCCEEDED(hr)); + + SetDebugNameD3D11 (rs.m_SRView, Format("RenderTexture-SRV-%d-color-%dx%d", rs.textureID.m_ID, rs.width, rs.height)); + + // If we need to generate mips, create view without sRGB format. Seems like some drivers + // have slow paths for updating sRGB formats, and from reading the docs, it's not clear if + // mip update for sRGB formats is supported everywhere. + if (mipLevels > 1) + { + desc.Format = GetShaderResourceViewFormat (rs.format, false); + hr = dev->CreateShaderResourceView (rs.m_Texture, &desc, &rs.m_SRViewForMips); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (rs.m_SRViewForMips, Format("RenderTexture-SRV-%d-color-%dx%d-mips", rs.textureID.m_ID, rs.width, rs.height)); + } + } + + // UAV if needed + if (rs.flags & kSurfaceCreateRandomWrite && gGraphicsCaps.d3d11.featureLevel >= kDX11Level11_0) + { + D3D11_UNORDERED_ACCESS_VIEW_DESC desc; + desc.Format = GetShaderResourceViewFormat (rs.format, false); // UAV formats don't support sRGB + if (rs.dim == kTexDim3D) + { + desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D; + desc.Texture3D.MipSlice = 0; + desc.Texture3D.FirstWSlice = 0; + desc.Texture3D.WSize = -1; + } + else + { + desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; + desc.Texture2D.MipSlice = 0; + } + + hr = dev->CreateUnorderedAccessView (rs.m_Texture, &desc, &rs.m_UAView); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (rs.m_UAView, Format("RenderTexture-UAV-%d-color-%dx%d", rs.textureID.m_ID, rs.width, rs.height)); + } + + // add to textures map + if (rs.textureID.m_ID) + { + textures.AddTexture (rs.textureID, rs.m_Texture, rs.m_SRView, rs.m_UAView, false); + } + + return true; +} + +bool InitD3D11RenderDepthSurface (RenderDepthSurfaceD3D11& rs, TexturesD3D11* textures, bool sampleOnly) +{ + HRESULT hr; + ID3D11Device* dev = GetD3D11Device(); + + const bool shadowMap = rs.flags & kSurfaceCreateShadowmap; + const bool useTypeless = (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 || gGraphicsCaps.d3d11.hasShadows10Level9); + const bool createZ = (rs.depthFormat != kDepthFormatNone); + + rs.m_Texture = NULL; + rs.m_DSView = NULL; + rs.m_SRView = NULL; + + DXGI_FORMAT formatResource; + DXGI_FORMAT formatDSV; + DXGI_FORMAT formatSRV; + if (shadowMap) + { + formatResource = DXGI_FORMAT_R16_TYPELESS; + formatDSV = DXGI_FORMAT_D16_UNORM; + formatSRV = DXGI_FORMAT_R16_UNORM; + } + else if (rs.depthFormat == kDepthFormat16) + { + formatResource = useTypeless ? DXGI_FORMAT_R16_TYPELESS : DXGI_FORMAT_D16_UNORM; + formatDSV = DXGI_FORMAT_D16_UNORM; + formatSRV = useTypeless ? DXGI_FORMAT_R16_UNORM : DXGI_FORMAT_D16_UNORM; + } + else + { + formatResource = useTypeless ? DXGI_FORMAT_R24G8_TYPELESS : DXGI_FORMAT_D24_UNORM_S8_UINT; + formatDSV = DXGI_FORMAT_D24_UNORM_S8_UINT; + formatSRV = useTypeless ? DXGI_FORMAT_R24_UNORM_X8_TYPELESS : DXGI_FORMAT_D24_UNORM_S8_UINT; + } + + // Pre-DX11 feature level hardware can't do depth buffer sampling & have it as a depth stencil, + // but DX11 can. + if (gGraphicsCaps.d3d11.featureLevel >= kDX11Level11_0) + sampleOnly = false; + + if (rs.dim != kTexDim2D) + { + // Starting with 10.1 level, we can have a cubemap color surface and a regular 2D depth surface. Before that, + // have to create the depth surface as a fake cubemap as well. Leave dimension as cubemap only when + // cubemap was requested AND we're below 10.1 + if (rs.dim != kTexDimCUBE || gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_1) + rs.dim = kTexDim2D; + } + + if (createZ) + { + UINT bindFlags = sampleOnly ? 0 : D3D11_BIND_DEPTH_STENCIL; + if (rs.textureID.m_ID && (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 || gGraphicsCaps.d3d11.hasShadows10Level9)) + bindFlags |= D3D11_BIND_SHADER_RESOURCE; + rs.m_Texture = CreateTextureD3D11 (rs.width, rs.height, 1, 1, formatResource, bindFlags, rs.dim, rs.samples); + } + + // Depth Stencil view if needed + if (createZ && !sampleOnly) + { + D3D11_DEPTH_STENCIL_VIEW_DESC desc; + desc.Format = formatDSV; + desc.ViewDimension = rs.samples > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D; + desc.Flags = 0; + desc.Texture2D.MipSlice = 0; + hr = dev->CreateDepthStencilView (rs.m_Texture, &desc, &rs.m_DSView); + Assert (SUCCEEDED(hr)); + } + + // Shader Resource View if needed + if (createZ && rs.textureID.m_ID && (gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0 || gGraphicsCaps.d3d11.hasShadows10Level9)) + { + D3D11_SHADER_RESOURCE_VIEW_DESC desc; + desc.Format = formatSRV; + desc.ViewDimension = rs.samples > 1 ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D; + desc.Texture2D.MostDetailedMip = 0; + desc.Texture2D.MipLevels = 1; + + ID3D11ShaderResourceView* srView = NULL; + hr = dev->CreateShaderResourceView (rs.m_Texture, &desc, &rs.m_SRView); + Assert (SUCCEEDED(hr)); + SetDebugNameD3D11 (rs.m_SRView, Format("RenderTexture-SRV-%d-depth-%dx%d", rs.textureID.m_ID, rs.width, rs.height)); + } + + if (createZ && rs.textureID.m_ID && textures) + textures->AddTexture (rs.textureID, rs.m_Texture, rs.m_SRView, rs.m_UAView, rs.flags & kSurfaceCreateShadowmap); + + return true; +} + +static RenderColorSurfaceD3D11* s_ActiveColorTargets[kMaxSupportedRenderTargets]; +static int s_ActiveColorTargetCount; +static bool s_SRGBWrite; +static RenderDepthSurfaceD3D11* s_ActiveDepthTarget = NULL; +static CubemapFace s_ActiveFace = kCubeFaceUnknown; +static int s_ActiveMip = 0; + +static RenderColorSurfaceD3D11* s_ActiveColorBackBuffer = NULL; +static RenderDepthSurfaceD3D11* s_ActiveDepthBackBuffer = NULL; + +// on dx editor we can switch swapchain underneath +// so lets do smth like gl's default FBO +// it will be used only from "user" code and we will select proper swap chain here +static RenderColorSurfaceD3D11* s_DummyColorBackBuffer = NULL; +static RenderDepthSurfaceD3D11* s_DummyDepthBackBuffer = NULL; + +RenderSurfaceBase* DummyColorBackBuferD3D11() +{ + if(s_DummyColorBackBuffer == 0) + { + static RenderColorSurfaceD3D11 __bb; + RenderSurfaceBase_InitColor(__bb); + __bb.backBuffer = true; + + s_DummyColorBackBuffer = &__bb; + } + return s_DummyColorBackBuffer; +} + +RenderSurfaceBase* DummyDepthBackBuferD3D11() +{ + if(s_DummyDepthBackBuffer == 0) + { + static RenderDepthSurfaceD3D11 __bb; + RenderSurfaceBase_InitDepth(__bb); + __bb.backBuffer = true; + + s_DummyDepthBackBuffer = &__bb; + } + return s_DummyDepthBackBuffer; +} + + +static int s_UAVMaxIndex = -1; +static TextureID s_UAVTextures[kMaxSupportedRenderTargets]; +static ComputeBufferID s_UAVBuffers[kMaxSupportedRenderTargets]; + + + +static bool SetRenderTargetD3D11Internal (int count, RenderColorSurfaceD3D11** colorSurfaces, RenderDepthSurfaceD3D11* depthSurface, int mipLevel, CubemapFace face, int* outTargetWidth, int* outTargetHeight, TexturesD3D11* textures, bool forceRebind) +{ + RenderColorSurfaceD3D11* rcolorZero = colorSurfaces[0]; + + // check context is created + ID3D11DeviceContext* ctx = GetD3D11Context(); + if (!ctx) + { + Assert (!rcolorZero && !depthSurface); + return false; + } + + bool sRGBWriteDesired = GetRealGfxDevice().GetSRGBWrite(); + + // Exit if nothing to do + if (!forceRebind && count == s_ActiveColorTargetCount && sRGBWriteDesired == s_SRGBWrite && s_ActiveDepthTarget == depthSurface && s_ActiveFace == face && s_ActiveMip == mipLevel) + { + bool colorsSame = true; + for (int i = 0; i < count; ++i) + { + if (s_ActiveColorTargets[i] != colorSurfaces[i]) + colorsSame = false; + } + if (colorsSame) + { + if (rcolorZero != s_DummyColorBackBuffer) + { + if (outTargetWidth) *outTargetWidth = rcolorZero->width; + if (outTargetHeight) *outTargetHeight = rcolorZero->height; + } + return false; + } + } + + Assert(rcolorZero->backBuffer == depthSurface->backBuffer); + bool isBackBuffer = rcolorZero->backBuffer; + + + GfxDevice& device = GetRealGfxDevice(); + if (!isBackBuffer) + device.GetFrameStats().AddRenderTextureChange(); // stats + + if(rcolorZero->backBuffer && rcolorZero == s_DummyColorBackBuffer) + rcolorZero = colorSurfaces[0] = s_ActiveColorBackBuffer; + if(depthSurface->backBuffer && depthSurface == s_DummyDepthBackBuffer) + depthSurface = s_ActiveDepthBackBuffer; + + + HRESULT hr; + + if (rcolorZero) + { + if (depthSurface && depthSurface->textureID.m_ID) + UnbindTextureD3D11 (depthSurface->textureID); + + Assert (rcolorZero->colorSurface); + Assert (!depthSurface || !depthSurface->colorSurface); + + int faceIndex = clamp<int>(face, 0, 5); + ID3D11RenderTargetView* rtvs[kMaxSupportedRenderTargets]; + for (int i = 0; i < count; ++i) + { + RenderColorSurfaceD3D11* rcolor = colorSurfaces[i]; + if (rcolor->textureID.m_ID) + UnbindTextureD3D11 (rcolor->textureID); + + bool wantSecondaryView = ((rcolor->flags & kSurfaceCreateSRGB) != 0) != sRGBWriteDesired; + rtvs[i] = rcolor->GetRTV(faceIndex, mipLevel, wantSecondaryView); + } + + const int uavCount = s_UAVMaxIndex - (count-1); + if (uavCount <= 0) + { + // set render targets + ctx->OMSetRenderTargets (count, rtvs, depthSurface ? depthSurface->m_DSView : NULL); + } + else + { + DebugAssert (uavCount > 0 && uavCount <= kMaxSupportedRenderTargets); + // set render targets and UAVs + ID3D11UnorderedAccessView* uavs[kMaxSupportedRenderTargets]; + for (int i = 0; i < uavCount; ++i) + { + int idx = i + count; + DebugAssert (idx >= 0 && idx < kMaxSupportedRenderTargets); + ID3D11UnorderedAccessView* uav = NULL; + if (s_UAVTextures[idx].m_ID && textures) + { + TexturesD3D11::D3D11Texture* tex = textures->GetTexture (s_UAVTextures[idx]); + if (tex) + uav = tex->m_UAV; + } + else if (s_UAVBuffers[idx].IsValid() && textures) + { + ComputeBuffer11* cb = textures->GetComputeBuffer (s_UAVBuffers[idx]); + if (cb) + uav = cb->uav; + } + uavs[i] = uav; + } + UINT uavInitialCounts[kMaxSupportedRenderTargets]; + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + uavInitialCounts[i] = 0; // reset offsets for Countable/Appendable/Consumeable UAVs + ctx->OMSetRenderTargetsAndUnorderedAccessViews (count, rtvs, depthSurface ? depthSurface->m_DSView : NULL, count, uavCount, uavs, uavInitialCounts); + } + + g_D3D11CurrRT = rtvs[0]; + g_D3D11CurrColorRT = rcolorZero; + g_D3D11CurrDS = depthSurface ? depthSurface->m_DSView : NULL; + g_D3D11CurrDepthRT = depthSurface; + if (outTargetWidth) *outTargetWidth = rcolorZero->width; + if (outTargetHeight)*outTargetHeight = rcolorZero->height; + } + + // If we previously had a mip-mapped render texture, generate mip levels for it now. + RenderColorSurfaceD3D11* prevRT = s_ActiveColorTargets[0]; + RenderColorSurfaceD3D11* currRT = colorSurfaces[0]; + if (prevRT && + (prevRT->flags & kSurfaceCreateMipmap) && + (prevRT->flags & kSurfaceCreateAutoGenMips) && + prevRT->m_SRViewForMips && + currRT != prevRT) + { + ctx->GenerateMips (prevRT->m_SRViewForMips); + } + + for (int i = 0; i < count; ++i) + s_ActiveColorTargets[i] = colorSurfaces[i]; + + s_ActiveColorTargetCount = count; + s_ActiveDepthTarget = depthSurface; + s_ActiveFace = face; + s_ActiveMip = mipLevel; + + if (isBackBuffer) + { + s_ActiveColorBackBuffer = rcolorZero; + s_ActiveDepthBackBuffer = depthSurface; + + // we are rendering to "default FBO", so current target is dummy + // as a side effect, if we change swap chain, it will be set correctly, and active remain valid + s_ActiveColorTargets[0] = s_DummyColorBackBuffer; + s_ActiveDepthTarget = s_DummyDepthBackBuffer; + } + + s_SRGBWrite = sRGBWriteDesired; + return true; +} + +bool SetRenderTargetD3D11 (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, int* outTargetWidth, int* outTargetHeight, TexturesD3D11* textures) +{ + RenderColorSurfaceD3D11* colorTargets[kMaxSupportedRenderTargets]; + RenderDepthSurfaceD3D11* rdepth = reinterpret_cast<RenderDepthSurfaceD3D11*>( depthHandle.object ); + for (int i = 0; i < count; ++i) + { + colorTargets[i] = reinterpret_cast<RenderColorSurfaceD3D11*>(colorHandles[i].object); + } + + return SetRenderTargetD3D11Internal (count, colorTargets, rdepth, mipLevel, face, outTargetWidth, outTargetHeight, textures, false); +} + +bool RebindActiveRenderTargets(TexturesD3D11* textures) +{ + int width, height; + return SetRenderTargetD3D11Internal (s_ActiveColorTargetCount, s_ActiveColorTargets, s_ActiveDepthTarget, s_ActiveMip, s_ActiveFace, &width, &height, textures, true); +} + + +void SetRandomWriteTargetTextureD3D11 (int index, TextureID tid) +{ + Assert (index >= 0 && index < ARRAY_SIZE(s_UAVTextures)); + s_UAVMaxIndex = std::max (s_UAVMaxIndex, index); + s_UAVTextures[index] = tid; + s_UAVBuffers[index] = ComputeBufferID(); +} + +void SetRandomWriteTargetBufferD3D11 (int index, ComputeBufferID bufferHandle) +{ + Assert (index >= 0 && index < ARRAY_SIZE(s_UAVBuffers)); + s_UAVMaxIndex = std::max (s_UAVMaxIndex, index); + s_UAVBuffers[index] = bufferHandle; + s_UAVTextures[index].m_ID = 0; +} + +void ClearRandomWriteTargetsD3D11 (TexturesD3D11* textures) +{ + const bool resetRenderTargets = (s_UAVMaxIndex != -1); + + s_UAVMaxIndex = -1; + for (int i = 0; i < ARRAY_SIZE(s_UAVTextures); ++i) + s_UAVTextures[i].m_ID = 0; + for (int i = 0; i < ARRAY_SIZE(s_UAVBuffers); ++i) + s_UAVBuffers[i] = ComputeBufferID(); + + if (resetRenderTargets) + RebindActiveRenderTargets (textures); +} + + +RenderSurfaceHandle GetActiveRenderColorSurfaceD3D11(int index) +{ + return RenderSurfaceHandle(s_ActiveColorTargets[index]); +} +RenderSurfaceHandle GetActiveRenderDepthSurfaceD3D11() +{ + return RenderSurfaceHandle(s_ActiveDepthTarget); +} + +RenderSurfaceHandle GetActiveRenderColorSurfaceBBD3D11() +{ + RenderColorSurfaceD3D11* ret = s_ActiveColorTargets[0]; + if(ret == s_DummyColorBackBuffer) + ret = s_ActiveColorBackBuffer; + + return RenderSurfaceHandle(ret); +} + +bool IsActiveRenderTargetWithColorD3D11() +{ + return !s_ActiveColorTargets[0] || s_ActiveColorTargets[0]->backBuffer || s_ActiveColorTargets[0]->m_Texture; +} + +RenderSurfaceHandle CreateRenderColorSurfaceD3D11 (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, TexturesD3D11& textures) +{ + RenderSurfaceHandle rsHandle; + + if( !gGraphicsCaps.hasRenderToTexture ) + return rsHandle; + if( !gGraphicsCaps.supportsRenderTextureFormat[format] ) + return rsHandle; + + RenderColorSurfaceD3D11* rs = new RenderColorSurfaceD3D11; + rs->width = width; + rs->height = height; + rs->samples = samples; + rs->depth = depth; + rs->format = format; + rs->textureID = textureID; + rs->dim = dim; + rs->flags = createFlags; + + // Create it + if (!InitD3D11RenderColorSurface(*rs, textures)) + { + delete rs; + return rsHandle; + } + + rsHandle.object = rs; + return rsHandle; +} + +RenderSurfaceHandle CreateRenderDepthSurfaceD3D11 (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags, TexturesD3D11& textures) +{ + RenderSurfaceHandle rsHandle; + + if( !gGraphicsCaps.hasRenderToTexture ) + return rsHandle; + + RenderDepthSurfaceD3D11* rs = new RenderDepthSurfaceD3D11; + rs->width = width; + rs->height = height; + rs->samples = samples; + rs->dim = dim; + rs->depthFormat = depthFormat; + rs->textureID = textureID; + rs->flags = createFlags; + + // Create it + bool sampleOnly = (createFlags & kSurfaceCreateSampleOnly) != 0; + if (!InitD3D11RenderDepthSurface (*rs, &textures, sampleOnly)) + { + delete rs; + return rsHandle; + } + + rsHandle.object = rs; + return rsHandle; +} + +void InternalDestroyRenderSurfaceD3D11 (RenderSurfaceD3D11* rs, TexturesD3D11* textures) +{ + AssertIf( !rs ); + + if(rs == s_ActiveColorBackBuffer || rs == s_ActiveDepthBackBuffer) + { + s_ActiveColorBackBuffer = NULL; + s_ActiveDepthBackBuffer = NULL; + } + + RenderSurfaceHandle defaultColor(s_DummyColorBackBuffer); + RenderSurfaceHandle defaultDepth(s_DummyDepthBackBuffer); + + for (int i = 0; i < s_ActiveColorTargetCount; ++i) + { + if (s_ActiveColorTargets[i] == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + SetRenderTargetD3D11 (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, NULL, NULL, textures); + } + } + if (s_ActiveDepthTarget == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + SetRenderTargetD3D11 (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, NULL, NULL, textures); + } + + if (rs->m_Texture || rs->textureID.m_ID) + { + UnbindTextureD3D11 (rs->textureID); + if (textures) + textures->RemoveTexture (rs->textureID); + } + + REGISTER_EXTERNAL_GFX_DEALLOCATION(rs->m_Texture); + if (rs->colorSurface) + { + RenderColorSurfaceD3D11* colorRS = static_cast<RenderColorSurfaceD3D11*>(rs); + colorRS->Reset(); + } + else + { + RenderDepthSurfaceD3D11* depthRS = static_cast<RenderDepthSurfaceD3D11*>(rs); + depthRS->Reset(); + } +} + +void DestroyRenderSurfaceD3D11 (RenderSurfaceHandle& rsHandle, TexturesD3D11& textures) +{ + if( !rsHandle.IsValid() ) + return; + + RenderSurfaceD3D11* rs = reinterpret_cast<RenderSurfaceD3D11*>( rsHandle.object ); + InternalDestroyRenderSurfaceD3D11 (rs, &textures); + delete rs; + rsHandle.object = NULL; +} + + + +// -------------------------------------------------------------------------- + + +#if ENABLE_UNIT_TESTS +#include "External/UnitTest++/src/UnitTest++.h" + +SUITE (RenderTextureD3D11Tests) +{ +TEST(RenderTextureD3D11_FormatTableCorrect) +{ + // checks that you did not forget to update format table when adding a new format :) + for (int i = 0; i < kRTFormatCount; ++i) + { + CHECK(kD3D11RenderResourceFormats[i] != 0); + CHECK(kD3D11RenderTextureFormatsNorm[i] != 0); + CHECK(kD3D11RenderTextureFormatsSRGB[i] != 0); + } +} +} + +#endif diff --git a/Runtime/GfxDevice/d3d11/ShaderGeneratorD3D11.cpp b/Runtime/GfxDevice/d3d11/ShaderGeneratorD3D11.cpp new file mode 100644 index 0000000..4752142 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/ShaderGeneratorD3D11.cpp @@ -0,0 +1,1504 @@ +#include "UnityPrefix.h" +#include "ShaderGeneratorD3D11.h" +#include "FixedFunctionStateD3D11.h" +#include "ConstantBuffersD3D11.h" +#include "D3D11Context.h" +#include "Runtime/GfxDevice/GpuProgram.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "D3D11ByteCode.h" + +#define DEBUG_D3D11_FF_SHADERS (!UNITY_RELEASE && 0) +#define DEBUG_D3D11_COMPARE_WITH_HLSL (DEBUG_D3D11_FF_SHADERS && 0) + +ConstantBuffersD3D11& GetD3D11ConstantBuffers (GfxDevice& device); + + +// --- Debugging --------------------------------------------------------------------------------- + + +#if DEBUG_D3D11_FF_SHADERS + +#include "Runtime/GfxDevice/d3d11/D3D11Compiler.h" +#if UNITY_WINRT +#include "PlatformDependent/MetroPlayer/MetroUtils.h" +#endif + +static D3D11Compiler s_Compiler; + +static bool HasD3D11Compiler() +{ + static bool initialized = false; + if (!initialized) + { + //s_Compiler.Initialize (kD3D11CompilerDLL); + const char* dllName = kD3D11CompilerDLL; + s_Compiler.compileFunc = NULL; + s_Compiler.stripShaderFunc = NULL; + s_Compiler.reflectFunc = NULL; + s_Compiler.disassembleFunc = NULL; + s_Compiler.createBlobFunc = NULL; + + #if UNITY_WINRT + HMODULE dll = LoadPackagedLibrary (ConvertToWindowsPath(dllName)->Data(), 0); + #else + HMODULE dll = LoadLibraryA (dllName); + #endif + if (dll) + { + s_Compiler.compileFunc = (D3D11Compiler::D3DCompileFunc) GetProcAddress (dll, "D3DCompile"); + s_Compiler.stripShaderFunc = (D3D11Compiler::D3DStripShaderFunc) GetProcAddress (dll, "D3DStripShader"); + s_Compiler.reflectFunc = (D3D11Compiler::D3DReflectFunc) GetProcAddress (dll, "D3DReflect"); + s_Compiler.disassembleFunc = (D3D11Compiler::D3DDisassembleFunc) GetProcAddress (dll, "D3DDisassemble"); + s_Compiler.createBlobFunc = (D3D11Compiler::D3DCreateBlobFunc) GetProcAddress (dll, "D3DCreateBlob"); + } + } + return s_Compiler.IsValid(); +} + +#endif // #if DEBUG_D3D11_FF_SHADERS + + +#if DEBUG_D3D11_COMPARE_WITH_HLSL + +enum D3DCOMPILER_STRIP_FLAGS +{ + D3DCOMPILER_STRIP_REFLECTION_DATA = 1, + D3DCOMPILER_STRIP_DEBUG_INFO = 2, + D3DCOMPILER_STRIP_TEST_BLOBS = 4, + D3DCOMPILER_STRIP_FORCE_DWORD = 0x7fffffff, +}; + +#define D3D_DISASM_ENABLE_COLOR_CODE 1 +#define D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS 2 +#define D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING 4 +#define D3D_DISASM_ENABLE_INSTRUCTION_CYCLE 8 + +static void DebugCompileHLSLShaderD3D11 (const std::string& source, bool vertex) +{ + if (!HasD3D11Compiler()) + return; + + ID3D10Blob* shader = NULL; + ID3D10Blob* errors; + Assert (s_Compiler.compileFunc); + HRESULT hr = s_Compiler.compileFunc ( + source.c_str(), + source.size(), + "source", + NULL, + NULL, + "main", + gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0 + ? (vertex ? "vs_4_0_level_9_3" : "ps_4_0_level_9_3") + : (vertex ? "vs_4_0" : "ps_4_0"), + 0, + 0, + &shader, + &errors); + + if (FAILED(hr)) + { + printf_console ("Failed to compile D3D11 shader:\n%s\n", source.c_str()); + if (errors) + { + std::string msg (reinterpret_cast<const char*>(errors->GetBufferPointer()), errors->GetBufferSize()); + printf_console ("\nErrors:\n%s\n", msg.c_str()); + errors->Release(); + } + else + { + printf_console ("\nErrors unknown!\n"); + } + AssertString ("Failed to compile fixed function D3D11 shader"); + return; + } + + if (shader && s_Compiler.stripShaderFunc) + { + ID3D10Blob* strippedShader = NULL; + + hr = s_Compiler.stripShaderFunc (shader->GetBufferPointer(), shader->GetBufferSize(), D3DCOMPILER_STRIP_REFLECTION_DATA | D3DCOMPILER_STRIP_DEBUG_INFO | D3DCOMPILER_STRIP_TEST_BLOBS, &strippedShader); + if (SUCCEEDED(hr)) + { + SAFE_RELEASE(shader); + shader = strippedShader; + } + } + + SAFE_RELEASE(errors); + + if (shader && s_Compiler.disassembleFunc) + { + ID3D10Blob* disasm = NULL; + hr = s_Compiler.disassembleFunc (shader->GetBufferPointer(), shader->GetBufferSize(), D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS, NULL, &disasm); + if (SUCCEEDED(hr) && disasm) + { + printf_console ("disasm:\n%s\n\n", disasm->GetBufferPointer()); + } + SAFE_RELEASE(disasm); + } + + SAFE_RELEASE(shader); +} + +static inline void AddToStringList (std::string& str, const char* s) +{ + if (!str.empty()) + str += ','; + str += s; +} + +#endif // #if DEBUG_D3D11_COMPARE_WITH_HLSL + + + +// --- Constant buffers & utilities -------------------------------------------------------------- + + +static const char* kD3D11VertexCB = "UnityFFVertex"; +static const char* kD3D11PixelCB = "UnityFFPixel"; + +enum { + k11VertexMVP = 0, + k11VertexMV = 4, + k11VertexColor = 8, + k11VertexAmbient = 9, + k11VertexLightColor = 10, + k11VertexLightPos = 18, + k11VertexLightAtten = 26, + k11VertexLightSpot = 34, + k11VertexMatDiffuse = 42, + k11VertexMatAmbient = 43, + k11VertexMatSpec = 44, + k11VertexMatEmission = 45, + k11VertexTex = 46, + k11VertexFog = 62, + k11VertexSize = 63, + k11VertexPosOffset9x = k11VertexSize+1, +}; +//k11VertexPosOffset9x will be used like that: +// mad oPos.xy, v0.w, c63, v0 +// mov oPos.zw, v0 + +#if DEBUG_D3D11_COMPARE_WITH_HLSL +static const char* kD3D11VertexPrefix = + "cbuffer UnityFFVertex {\n" + " float4x4 ff_matrix_mvp;\n" // 0 + " float4x4 ff_matrix_mv;\n" // 4 + " float4 ff_vec_color;\n" // 8 + " float4 ff_vec_ambient;\n" // 9 + " float4 ff_light_color[8];\n" // 10 + " float4 ff_light_pos[8];\n" // 18 + " float4 ff_light_atten[8];\n" // 26 + " float4 ff_light_spot[8];\n" // 34 + " float4 ff_mat_diffuse;\n" // 42 + " float4 ff_mat_ambient;\n" // 43 + " float4 ff_mat_spec;\n" // 44 + " float4 ff_mat_emission;\n" // 45 + " float4x4 ff_matrix_tex[4];\n" // 46 + " float4 ff_fog;\n" // 62 + "};\n"; // 62 +#endif // #if DEBUG_D3D11_COMPARE_WITH_HLSL + + +enum { + k11PixelColors = 0, + k11PixelAlphaRef = 8, + k11PixelFog = 9, + k11PixelSize = 10 +}; +#if DEBUG_D3D11_COMPARE_WITH_HLSL +static const char* kD3D11PixelPrefix = +"cbuffer UnityFFPixel {\n" +" float4 ff_vec_colors[8];\n" // 0 +" float ff_alpha_ref;\n" // 8 +" float4 ff_fog;\n" // 9 +"};\n" +"float4 main (\n "; +#endif // # if DEBUG_D3D11_COMPARE_WITH_HLSL + + +static void* BuildShaderD3D11 (DXBCBuilder* builder, size_t& outSize) +{ + Assert(builder); + + void* dxbc = dxb_build (builder, outSize); + Assert(dxbc); + dxb_destroy (builder); + + #if DEBUG_D3D11_FF_SHADERS + if (HasD3D11Compiler() && s_Compiler.disassembleFunc) + { + ID3D10Blob* disasm = NULL; + HRESULT hr = s_Compiler.disassembleFunc (dxbc, outSize, D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS, NULL, &disasm); + if (SUCCEEDED(hr) && disasm) + { + printf_console ("disasm dxbc:\n%s\n\n", disasm->GetBufferPointer()); + } + SAFE_RELEASE(disasm); + } + #endif + + return dxbc; +} + + +// --- VERTEX program ---------------------------------------------------------------------------- + + +static void EmitMatrixMul(DXBCBuilderStream& bld, int cbIndex, char srcType, int srcIndex, char dstType, int dstIndex, int tmpIndex, bool wAlways1) +{ + bld.op(kSM4Op_MUL).reg('r',tmpIndex).swz(srcType,srcIndex,kSM4SwzRepY).swz('c',cbIndex+1); + bld.op(kSM4Op_MAD).reg('r',tmpIndex).swz('c',cbIndex+0).swz(srcType,srcIndex,kSM4SwzRepX).swz('r',tmpIndex); + bld.op(kSM4Op_MAD).reg('r',tmpIndex).swz('c',cbIndex+2).swz(srcType,srcIndex,kSM4SwzRepZ).swz('r',tmpIndex); + if (!wAlways1) + bld.op(kSM4Op_MAD).reg(dstType,dstIndex).swz('c',cbIndex+3).swz(srcType,srcIndex,kSM4SwzRepW).swz('r',tmpIndex); + else + bld.op(kSM4Op_ADD).reg(dstType,dstIndex).swz('c',cbIndex+3).swz('r',tmpIndex); +} + + +void* BuildVertexShaderD3D11 (const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, BuiltinShaderParamIndices& matrices, size_t& outSize) +{ + ShaderLab::FastPropertyName cbName; cbName.SetName(kD3D11VertexCB); + GetD3D11ConstantBuffers(GetRealGfxDevice()).SetCBInfo (cbName.index, k11VertexSize*16); + params.m_CBID = cbName.index; params.m_CBSize = k11VertexSize*16; + + DXBCBuilder* builder = dxb_create(4, 0, kSM4Shader_Vertex); + DXBCBuilderStream bld(builder); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + std::string helpers, inputs, outputs, code; + #endif + + bool hasLights = (state.lightingEnabled && state.lightCount > 0); + + bool eyePositionRequired = + hasLights || + (state.fogMode != kFogDisabled); + bool eyeNormalRequired = hasLights; + bool viewDirRequired = hasLights && state.specularEnabled; + bool eyeReflRequired = false; + { + UInt64 texSources = state.texUnitSources; + for (int i = 0; i < state.texUnitCount; i++) + { + UInt32 uvSource = texSources & 0xF; + if (uvSource == kTexSourceEyeLinear) + eyePositionRequired = true; + if (uvSource == kTexSourceCubeNormal) + eyeNormalRequired = true; + if (uvSource == kTexSourceCubeReflect || uvSource == kTexSourceSphereMap) + eyeReflRequired = viewDirRequired = eyePositionRequired = eyeNormalRequired = true; + texSources >>= 4; + } + } + if (eyePositionRequired || eyeNormalRequired || eyeReflRequired) + { + matrices.mat[kShaderInstanceMatMV].gpuIndex = k11VertexMV*16; + matrices.mat[kShaderInstanceMatMV].rows = 4; + matrices.mat[kShaderInstanceMatMV].cols = 4; + matrices.mat[kShaderInstanceMatMV].cbID = params.m_CBID; + } + + dxb_dcl_cb(builder, 0, k11VertexSize); + + int inputRegCounter = 0, outputRegCounter = 0, tempRegCounter = 0; + int inPosReg = 0, inColorReg = 0, inNormalReg = 0; + int inUVReg[8] = {0}; + int outColor0Reg = 0, outColor1Reg = 0, outPosReg = 0; + int outUVReg[8] = {0}; + int eyePosReg = 0, eyeNormalReg = 0, viewDirReg = 0, eyeReflReg = 0, lcolorReg = 0, specColorReg = 0; + + dxb_dcl_input(builder, "POSITION", 0, inPosReg = inputRegCounter++); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, "float4 vertex : POSITION"); + #endif + + // color = Vertex or uniform color + char inColorType; + if (state.useUniformInsteadOfVertexColor) + { + params.AddVectorParam (k11VertexColor*16, 4, kShaderVecFFColor); + inColorType = 'c'; + inColorReg = k11VertexColor; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float4 color = ff_vec_color;\n"; + #endif + } + else + { + inColorType = 'v'; + dxb_dcl_input(builder, "COLOR", 0, inColorReg = inputRegCounter++); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, "float4 vertexColor : COLOR"); + code += "float4 color = vertexColor;\n"; + #endif + } + + // eyePos = eye position + if (eyePositionRequired) + { + eyePosReg = tempRegCounter++; + EmitMatrixMul (bld, k11VertexMV, 'v',inPosReg, 'r',eyePosReg, eyePosReg, false); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float3 eyePos = mul (ff_matrix_mv, vertex).xyz;\n"; + #endif + } + + // eyeNormal = normalize(normalMatrix * normal) + if (eyeNormalRequired) + { + dxb_dcl_input(builder, "NORMAL", 0, inNormalReg = inputRegCounter++, 0x7); + eyeNormalReg = tempRegCounter++; + // mul + bld.op(kSM4Op_MUL).reg('r',eyeNormalReg,7).swz('v',inNormalReg,kSM4SwzRepY).swz('c',k11VertexMV+1); + bld.op(kSM4Op_MAD).reg('r',eyeNormalReg,7).swz('c',k11VertexMV+0).swz('v',inNormalReg,kSM4SwzRepX).swz('r',eyeNormalReg); + bld.op(kSM4Op_MAD).reg('r',eyeNormalReg,7).swz('c',k11VertexMV+2).swz('v',inNormalReg,kSM4SwzRepZ).swz('r',eyeNormalReg); + // normalize + bld.op(kSM4Op_DP3).reg('r',eyeNormalReg,8).swz('r',eyeNormalReg,kSM4SwzNone).swz('r',eyeNormalReg,kSM4SwzNone); + bld.op(kSM4Op_RSQ).reg('r',eyeNormalReg,8).swz('r',eyeNormalReg,kSM4SwzRepW); + bld.op(kSM4Op_MUL).reg('r',eyeNormalReg,7).swz('r',eyeNormalReg,kSM4SwzRepW).swz('r',eyeNormalReg,kSM4SwzXYZX); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, "float3 normal : NORMAL"); + code += "float3 eyeNormal = normalize (mul ((float3x3)ff_matrix_mv, normal).xyz);\n"; //@TODO: proper normal matrix + #endif + } + + // view dir + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float3 viewDir = 0.0;"; + #endif + if (viewDirRequired) + { + // viewDir = normalized vertex-to-eye + viewDirReg = tempRegCounter++; + // -normalize + bld.op(kSM4Op_DP3).reg('r',viewDirReg,8).swz('r',eyePosReg,kSM4SwzNone).swz('r',eyePosReg,kSM4SwzNone); + bld.op(kSM4Op_RSQ).reg('r',viewDirReg,8).swz('r',viewDirReg,kSM4SwzRepW); + bld.op(kSM4Op_MUL).reg('r',viewDirReg,7).swz('r',viewDirReg,kSM4SwzRepW).swz('r',eyePosReg,kSM4SwzXYZX,true); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "viewDir = -normalize (eyePos);\n"; + #endif + } + + // eyeRefl + if (eyeReflRequired) + { + DebugAssert (viewDirRequired); + // eyeRefl = reflection vector, 2*dot(V,N)*N-V + eyeReflReg = tempRegCounter++; + bld.op(kSM4Op_DP3).reg('r',eyeReflReg,8).swz('r',viewDirReg,kSM4SwzNone).swz('r',eyeNormalReg,kSM4SwzNone); + bld.op(kSM4Op_ADD).reg('r',eyeReflReg,8).swz('r',eyeReflReg,kSM4SwzRepW).swz('r',eyeReflReg,kSM4SwzRepW); + bld.op(kSM4Op_MAD).reg('r',eyeReflReg,7).swz('r',eyeReflReg,kSM4SwzRepW).swz('r',eyeNormalReg,kSM4SwzXYZX).swz('r',viewDirReg,kSM4SwzXYZX,true); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float3 eyeRefl = 2.0f * dot (viewDir, eyeNormal) * eyeNormal - viewDir;\n"; + #endif + } + + // Lighting + if (state.lightingEnabled) + { + char ambientType, diffuseType, emissionType; + int ambientReg, diffuseReg, emissionReg; + if (state.colorMaterial==kColorMatAmbientAndDiffuse) + { + ambientType = diffuseType = inColorType; + ambientReg = diffuseReg = inColorReg; + } + else + { + ambientType = diffuseType = 'c'; + ambientReg = k11VertexMatAmbient; + diffuseReg = k11VertexMatDiffuse; + } + if (state.colorMaterial==kColorMatEmission) + { + emissionType = inColorType; + emissionReg = inColorReg; + } + else + { + emissionType = 'c'; + emissionReg = k11VertexMatEmission; + } + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + std::string ambientColor = (state.colorMaterial==kColorMatAmbientAndDiffuse) ? "color" : "ff_mat_ambient"; + std::string diffuseColor = (state.colorMaterial==kColorMatAmbientAndDiffuse) ? "color" : "ff_mat_diffuse"; + std::string emissionColor = (state.colorMaterial==kColorMatEmission) ? "color" : "ff_mat_emission"; + #endif + + params.AddVectorParam (k11VertexAmbient*16, 4, kShaderVecLightModelAmbient); + params.AddVectorParam (k11VertexMatAmbient*16, 4, kShaderVecFFMatAmbient); + params.AddVectorParam (k11VertexMatDiffuse*16, 4, kShaderVecFFMatDiffuse); + params.AddVectorParam (k11VertexMatSpec*16, 4, kShaderVecFFMatSpecular); + params.AddVectorParam (k11VertexMatEmission*16, 4, kShaderVecFFMatEmission); + + lcolorReg = tempRegCounter++; + bld.op(kSM4Op_MAD).reg('r',lcolorReg,7).swz(ambientType,ambientReg,kSM4SwzXYZX).swz('c',k11VertexAmbient,kSM4SwzXYZX).swz(emissionType,emissionReg,kSM4SwzXYZX); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float3 lcolor = " + emissionColor + ".rgb + " + ambientColor + ".rgb * ff_vec_ambient.rgb;\n"; + code += "float3 specColor = 0.0;\n"; + if (state.lightCount > 0) + { + helpers += "float3 computeLighting (int idx, float3 dirToLight, float3 eyeNormal, float3 viewDir, float4 diffuseColor, float atten, inout float3 specColor) {\n"; + helpers += " float NdotL = max(dot(eyeNormal, dirToLight), 0.0);\n"; + helpers += " float3 color = NdotL * diffuseColor.rgb * ff_light_color[idx].rgb;\n"; + if (state.specularEnabled) + { + helpers += " if (NdotL > 0.0) {\n"; + helpers += " float3 h = normalize(dirToLight + viewDir);\n"; + helpers += " float HdotN = max(dot(eyeNormal, h), 0.0);\n"; + helpers += " float sp = saturate(pow(HdotN, ff_mat_spec.w));\n"; + helpers += " specColor += atten * sp * ff_light_color[idx].rgb;\n"; + helpers += " }\n"; + } + helpers += " return color * atten;\n"; + helpers += "}\n"; + + helpers += "float3 computeSpotLight(int idx, float3 eyePosition, float3 eyeNormal, float3 viewDir, float4 diffuseColor, inout float3 specColor) {\n"; + helpers += " float3 dirToLight = ff_light_pos[idx].xyz - eyePosition * ff_light_pos[idx].w;\n"; + helpers += " float distSqr = dot(dirToLight, dirToLight);\n"; + helpers += " float att = 1.0 / (1.0 + ff_light_atten[idx].z * distSqr);\n"; + helpers += " if (ff_light_pos[idx].w != 0 && distSqr > ff_light_atten[idx].w) att = 0.0;\n"; // set to 0 if outside of range + helpers += " dirToLight *= rsqrt(distSqr);\n"; + + helpers += " float rho = max(dot(dirToLight, ff_light_spot[idx].xyz), 0.0);\n"; + helpers += " float spotAtt = (rho - ff_light_atten[idx].x) * ff_light_atten[idx].y;\n"; + helpers += " spotAtt = saturate(spotAtt);\n"; + helpers += " return min (computeLighting (idx, dirToLight, eyeNormal, viewDir, diffuseColor, att*spotAtt, specColor), 1.0);\n"; + helpers += "}\n"; + } + #endif // DEBUG_D3D11_COMPARE_WITH_HLSL + + if (state.specularEnabled) + { + specColorReg = tempRegCounter++; + bld.op(kSM4Op_MOV).reg('r',specColorReg,7).float4(0,0,0,0); + } + + for (int i = 0; i < state.lightCount; ++i) + { + params.AddVectorParam ((k11VertexLightPos+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0Position+i)); + params.AddVectorParam ((k11VertexLightAtten+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0Atten+i)); + params.AddVectorParam ((k11VertexLightColor+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0Diffuse+i)); + params.AddVectorParam ((k11VertexLightSpot+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0SpotDirection+i)); + + Assert(eyePositionRequired); + Assert(eyeNormalRequired); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "lcolor += computeSpotLight(" + IntToString(i) + ", eyePos, eyeNormal, viewDir, " + diffuseColor + ", specColor);\n"; + #endif + + int ldirReg = tempRegCounter; + int miscReg = tempRegCounter+1; + int diffReg = tempRegCounter+2; + + // + // attenuation + + // float3 dirToLight = ff_light_pos[idx].xyz - eyePosition * ff_light_pos[idx].w; + // float distSqr = dot(dirToLight, dirToLight); + // float att = 1.0 / (1.0 + ff_light_atten[idx].z * distSqr); + // if (ff_light_pos[idx].w != 0 && distSqr > ff_light_atten[idx].w) att = 0.0; + // dirToLight *= rsqrt(distSqr); + // float rho = max(dot(dirToLight, ff_light_spot[idx].xyz), 0.0); + // float spotAtt = (rho - ff_light_atten[idx].x) * ff_light_atten[idx].y; + // spotAtt = saturate(spotAtt); + + // dirToLight = ff_light_pos[idx].xyz - eyePosition * ff_light_pos[idx].w + bld.op(kSM4Op_MAD).reg('r',ldirReg,7).swz('r',eyePosReg,kSM4SwzXYZX,true).swz('c',k11VertexLightPos+i,kSM4SwzRepW).swz('c',k11VertexLightPos+i,kSM4SwzXYZX); + // normalize, distSqr in miscReg.w + bld.op(kSM4Op_DP3).reg('r',miscReg,8).swz('r',ldirReg,kSM4SwzNone).swz('r',ldirReg,kSM4SwzNone); + bld.op(kSM4Op_RSQ).reg('r',ldirReg,8).swz('r',miscReg,kSM4SwzRepW); + bld.op(kSM4Op_MUL).reg('r',ldirReg,7).swz('r',ldirReg,kSM4SwzRepW).swz('r',ldirReg,kSM4SwzXYZX); + + // miscReg.z = float rho = max(dot(dirToLight, ff_light_spot[idx].xyz), 0.0) + bld.op(kSM4Op_DP3).reg('r',miscReg,4).swz('r',ldirReg,kSM4SwzNone).swz('c',k11VertexLightSpot+i,kSM4SwzNone); + bld.op(kSM4Op_MAX).reg('r',miscReg,4).swz('r',miscReg,kSM4SwzRepZ).float1(0.0f); + // miscReg.z = spotAtt = saturate ( (rho - ff_light_atten[idx].x) * ff_light_atten[idx].y ) + bld.op(kSM4Op_ADD).reg('r',miscReg,4).swz('r',miscReg,kSM4SwzRepZ).swz('c',k11VertexLightAtten+i,kSM4SwzRepX,true); + bld.op_sat(kSM4Op_MUL,miscReg).reg('r',miscReg,4).swz('r',miscReg,kSM4SwzRepZ).swz('c',k11VertexLightAtten+i,kSM4SwzRepY); + + // miscReg.y = float att = 1.0 / (1.0 + ff_light_atten[idx].z * distSqr) + bld.op(kSM4Op_MAD).reg('r',miscReg,2).swz('c',k11VertexLightAtten+i,kSM4SwzRepZ).swz('r',miscReg,kSM4SwzRepW).float1(1.0f); + bld.noAutoSM2(); + bld.op(kSM4Op_DIV).reg('r',miscReg,2).float4(1,1,1,1).swz('r',miscReg,kSM4SwzRepY); + bld.op2(kSM2Op_RCP).reg2('r',miscReg,2).swz2('r',miscReg,kSM4SwzRepY); + bld.autoSM2(); + + // miscReg.y = att * spotAtt + bld.op(kSM4Op_MUL).reg('r',miscReg,2).swz('r',miscReg,kSM4SwzRepY).swz('r',miscReg,kSM4SwzRepZ); + // if (ff_light_pos[idx].w != 0 && distSqr > ff_light_atten[idx].w) att = 0.0 + bld.noAutoSM2(); + bld.op(kSM4Op_LT).reg('r',miscReg,1).swz('c',k11VertexLightAtten+i,kSM4SwzRepW).swz('r',miscReg,kSM4SwzRepW); + bld.op(kSM4Op_NE).reg('r',miscReg,4).swz('c',k11VertexLightPos+i,kSM4SwzRepW).float1(0.0); + bld.op(kSM4Op_AND).reg('r',miscReg,1).swz('r',miscReg,kSM4SwzRepX).swz('r',miscReg,kSM4SwzRepZ); + bld.op(kSM4Op_MOVC).reg('r',miscReg,2).swz('r',miscReg,kSM4SwzRepX).float1(0.0).swz('r',miscReg,kSM4SwzRepY); + //SM2 + bld.op2(kSM2Op_SLT).reg2('r',miscReg,1).swz2('c',k11VertexLightAtten+i,kSM4SwzRepW).swz2('r',miscReg,kSM4SwzRepW); + bld.op2(kSM2Op_MUL).reg2('r',miscReg,4).swz2('c',k11VertexLightPos+i,kSM4SwzRepW).swz2('c',k11VertexLightPos+i,kSM4SwzRepW); + bld.op2(kSM2Op_SLT).reg2('r',miscReg,4).swz2('r',miscReg,kSM4SwzRepZ,true).swz2('r',miscReg,kSM4SwzRepZ); + bld.op2(kSM2Op_MUL).reg2('r',miscReg,1).swz2('r',miscReg,kSM4SwzRepX).swz2('r',miscReg,kSM4SwzRepZ); + bld.op2(kSM2Op_MAD).reg2('r',miscReg,2).swz2('r',miscReg,kSM4SwzRepX).swz2('r',miscReg,kSM4SwzRepY,true).swz2('r',miscReg,kSM4SwzRepY); + bld.autoSM2(); + + // + // diffuse + + // float NdotL = max(dot(eyeNormal, dirToLight), 0.0); + // float3 color = NdotL * diffuseColor.rgb * ff_light_color[idx].rgb; + // lcolor += color * atten + + // miscReg.z = float NdotL = max(dot(eyeNormal, dirToLight), 0.0) + bld.op(kSM4Op_DP3).reg('r',miscReg,4).swz('r',eyeNormalReg,kSM4SwzNone).swz('r',ldirReg,kSM4SwzNone); + bld.op(kSM4Op_MAX).reg('r',miscReg,4).swz('r',miscReg,kSM4SwzRepZ).float1(0.0f); + // diffReg.xyz = float3 color = NdotL * diffuseColor.rgb * ff_light_color[idx].rgb + bld.op(kSM4Op_MUL).reg('r',diffReg,7).swz('r',miscReg,kSM4SwzRepZ).swz(diffuseType,diffuseReg,kSM4SwzXYZX); + bld.op(kSM4Op_MUL).reg('r',diffReg,7).swz('r',diffReg,kSM4SwzXYZX).swz('c',k11VertexLightColor+i,kSM4SwzXYZX); + // diffReg.xyz = saturate(color*atten, 1) + bld.op_sat(kSM4Op_MUL,diffReg).reg('r',diffReg,7).swz('r',diffReg,kSM4SwzXYZX).swz('r',miscReg,kSM4SwzRepY); + // lcolor += diffReg + bld.op(kSM4Op_ADD).reg('r',lcolorReg,7).swz('r',lcolorReg,kSM4SwzXYZX).swz('r',diffReg,kSM4SwzXYZX); + + // + // specular + + if (state.specularEnabled) + { + // if (NdotL > 0.0) { + // float3 h = normalize(dirToLight + viewDir); + // float HdotN = max(dot(eyeNormal, h), 0.0); + // float sp = saturate(pow(HdotN, ff_mat_spec.w)); + // specColor += atten * sp * ff_light_color[idx].rgb; + // } + + // ldirReg.xyz = h = normalize(dirToLight + viewDir) + bld.op(kSM4Op_ADD).reg('r',ldirReg,7).swz('r',ldirReg,kSM4SwzXYZX).swz('r',viewDirReg,kSM4SwzXYZX); + bld.op(kSM4Op_DP3).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzNone).swz('r',ldirReg,kSM4SwzNone); + bld.op(kSM4Op_RSQ).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzRepW); + bld.op(kSM4Op_MUL).reg('r',ldirReg,7).swz('r',ldirReg,kSM4SwzXYZX).swz('r',ldirReg,kSM4SwzRepW); + // ldirReg.w = HdotN = max(dot(eyeNormal,h),0) + bld.op(kSM4Op_DP3).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzNone).swz('r',eyeNormalReg,kSM4SwzNone); + bld.op(kSM4Op_MAX).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzRepW).float1(0.0f); + // float sp = saturate(pow(HdotN, ff_mat_spec.w)) + bld.op(kSM4Op_LOG).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzRepW); + bld.op(kSM4Op_MUL).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzRepW).swz('c',k11VertexMatSpec,kSM4SwzRepW); + bld.op(kSM4Op_EXP).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzRepW); + bld.op(kSM4Op_MIN).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzRepW).float1(1.0f); + // atten * sp * ff_light_color[idx].rgb + bld.op(kSM4Op_MUL).reg('r',ldirReg,8).swz('r',ldirReg,kSM4SwzRepW).swz('r',miscReg,kSM4SwzRepY); + bld.op(kSM4Op_MUL).reg('r',diffReg,7).swz('r',ldirReg,kSM4SwzRepW).swz('c',k11VertexLightColor+i,kSM4SwzXYZX); + // nuke specular if NdotL <= 0 + bld.op(kSM4Op_LT).reg('r',miscReg,1).float1(0.0).swz('r',miscReg,kSM4SwzRepZ); + bld.noAutoSM2(); + bld.op(kSM4Op_AND).reg('r',diffReg,7).swz('r',diffReg,kSM4SwzXYZX).swz('r',miscReg,kSM4SwzRepX); + bld.op2(kSM2Op_MUL).reg2('r',diffReg,7).swz2('r',diffReg,kSM4SwzXYZX).swz2('r',miscReg,kSM4SwzRepX); + bld.autoSM2(); + // specColor += computed spec color + bld.op(kSM4Op_ADD).reg('r',specColorReg,7).swz('r',specColorReg,kSM4SwzXYZX).swz('r',diffReg,kSM4SwzXYZX); + } + } + + bld.op(kSM4Op_MOV).reg('r',lcolorReg,8).swz(diffuseType,diffuseReg,kSM4SwzRepW); + inColorReg = lcolorReg; + inColorType = 'r'; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "color.rgb = lcolor.rgb;\n"; + code += "color.a = " + diffuseColor + ".a;\n"; + #endif + + if (state.specularEnabled) + { + bld.op(kSM4Op_MUL).reg('r',specColorReg,7).swz('r',specColorReg,kSM4SwzXYZX).swz('c',k11VertexMatSpec,kSM4SwzXYZX); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "specColor *= ff_mat_spec.rgb;\n"; + #endif + } + } + + // Output final color + dxb_dcl_output(builder, "COLOR", 0, outColor0Reg = outputRegCounter++); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (outputs, "out float4 ocolor : COLOR0"); + #endif + + bld.op_sat(kSM4Op_MOV,tempRegCounter).reg('o',outColor0Reg).swz(inColorType,inColorReg); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ocolor = saturate(color);\n"; + #endif + + if (state.lightingEnabled && state.specularEnabled) + { + dxb_dcl_output(builder, "COLOR", 1, outColor1Reg = outputRegCounter++, 0x7); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (outputs, "out float3 ospec : COLOR1"); + #endif + + bld.op_sat(kSM4Op_MOV,tempRegCounter).reg('o',outColor1Reg,7).swz('r',specColorReg,kSM4SwzXYZX); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ospec = saturate(specColor);\n"; + #endif + } + + // we don't need temporary registers from lighting calculations anymore after this point + if (state.lightingEnabled) + --tempRegCounter; + + + // Pass & transform texture coordinates + UInt32 gotInputs = 0; + UInt32 gotOutputs = 0; + UInt64 texSources = state.texUnitSources; + for (int i = 0; i < state.texUnitCount; i++) + { + matrices.mat[kShaderInstanceMatTexture0+i].gpuIndex = (k11VertexTex+i*4)*16; + matrices.mat[kShaderInstanceMatTexture0+i].rows = 4; + matrices.mat[kShaderInstanceMatTexture0+i].cols = 4; + matrices.mat[kShaderInstanceMatTexture0+i].cbID = params.m_CBID; + + std::string iname = IntToString(i); + dxb_dcl_output(builder, "TEXCOORD", i, outUVReg[i] = outputRegCounter++); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (outputs, ("out float4 ouv" + iname + " : TEXCOORD" + iname).c_str()); + #endif + + UInt32 uvSource = texSources & 0xF; + if (uvSource >= kTexSourceUV0 && uvSource <= kTexSourceUV7) + { + unsigned uv = uvSource-kTexSourceUV0; + std::string uvStr = IntToString(uv); + if (!(gotInputs & (1<<uv))) + { + dxb_dcl_input(builder, "TEXCOORD", uv, inUVReg[uv] = inputRegCounter++); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, ("float4 uv"+uvStr+" : TEXCOORD"+uvStr).c_str()); + #endif + gotInputs |= (1<<uv); + } + EmitMatrixMul (bld, k11VertexTex+4*i, 'v',inUVReg[uv], 'o',outUVReg[i], tempRegCounter, false); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ouv"+iname + " = mul(ff_matrix_tex["+iname + "], uv"+uvStr+");\n"; + #endif + } + else if (uvSource == kTexSourceSphereMap) + { + // m = 2*sqrt(Rx*Rx + Ry*Ry + (Rz+1)*(Rz+1)) + // SPHR = Rx/m + 0.5, Ry/m + 0.5 + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ouv"+iname + " = mul(ff_matrix_tex["+iname +"], float4(\n"; + code += " eyeRefl.xy / (2.0*sqrt(eyeRefl.x*eyeRefl.x + eyeRefl.y*eyeRefl.y + (eyeRefl.z+1)*(eyeRefl.z+1))) + 0.5,\n"; + code += " 0,1));\n"; + #endif + + // HLSL generates code like: + // dp2 r0.w, r0.xyxx, r0.xyxx + // add r0.z, r0.z, l(1.0) + // mad r0.z, r0.z, r0.z, r0.w + // sqrt r0.z, r0.z + // add r0.z, r0.z, r0.z + // div r0.xy, r0.xyxx, r0.zzzz + // add r0.xy, r0.xyxx, l(0.5, 0.5, 0.0, 0.0) +#if 0 + bld.op(kSM4Op_DP2).reg('r',tempRegCounter,8).swz('r',eyeReflReg,kSM4SwzXYXX).swz('r',eyeReflReg,kSM4SwzXYXX); + bld.op(kSM4Op_ADD).reg('r',tempRegCounter,4).swz('r',eyeReflReg,kSM4SwzRepZ).float1(1.0); + bld.op(kSM4Op_MAD).reg('r',tempRegCounter,4).swz('r',tempRegCounter,kSM4SwzRepZ).swz('r',tempRegCounter,kSM4SwzRepZ).swz('r',tempRegCounter,kSM4SwzRepW); + bld.op(kSM4Op_SQRT).reg('r',tempRegCounter,4).swz('r',tempRegCounter,kSM4SwzRepZ); + bld.op(kSM4Op_ADD).reg('r',tempRegCounter,4).swz('r',tempRegCounter,kSM4SwzRepZ).swz('r',tempRegCounter,kSM4SwzRepZ); + bld.op(kSM4Op_DIV).reg('r',tempRegCounter,3).swz('r',eyeReflReg,kSM4SwzXYXX).swz('r',tempRegCounter,kSM4SwzRepZ); + bld.op(kSM4Op_ADD).reg('r',tempRegCounter,3).swz('r',tempRegCounter,kSM4SwzXYXX).float4(0.5f,0.5f,0,0); +#else + //SM2 compatible + bld.op(kSM4Op_ADD).reg('r',tempRegCounter,7).swz('r',eyeReflReg,kSM4SwzXYZX).float4(0.0f,0.0f,1.0f,0.0f); + bld.op(kSM4Op_DP3).reg('r',tempRegCounter,8).swz('r',tempRegCounter,kSM4SwzNone).swz('r',tempRegCounter,kSM4SwzNone); + bld.op(kSM4Op_RSQ).reg('r',tempRegCounter,8).swz('r',tempRegCounter,kSM4SwzRepW); + bld.op(kSM4Op_MUL).reg('r',tempRegCounter,8).swz('r',tempRegCounter,kSM4SwzRepW).float4(0.5f,0.5f,0.5f,0.5f); + bld.op(kSM4Op_MAD).reg('r',tempRegCounter,3).swz('r',eyeReflReg,kSM4SwzXYXX).swz('r',tempRegCounter,kSM4SwzRepW).float4(0.5f,0.5f,0.5f,0.5f); +#endif + EmitMatrixMul (bld, k11VertexTex+4*i, 'r',tempRegCounter, 'o',outUVReg[i], tempRegCounter+1, true); + } + else if (uvSource == kTexSourceObject) + { + EmitMatrixMul (bld, k11VertexTex+4*i, 'v',inPosReg, 'o',outUVReg[i], tempRegCounter, false); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ouv"+iname + " = mul(ff_matrix_tex["+iname +"], vertex);\n"; + #endif + } + else if (uvSource == kTexSourceEyeLinear) + { + EmitMatrixMul (bld, k11VertexTex+4*i, 'r',eyePosReg, 'o',outUVReg[i], tempRegCounter, true); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ouv"+iname + " = mul(ff_matrix_tex["+iname +"], float4(eyePos,1.0));\n"; + #endif + } + else if (uvSource == kTexSourceCubeNormal) + { + EmitMatrixMul (bld, k11VertexTex+4*i, 'r',eyeNormalReg, 'o',outUVReg[i], tempRegCounter, true); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ouv"+iname + " = mul(ff_matrix_tex["+iname +"], float4(eyeNormal,1.0));\n"; + #endif + } + else if (uvSource == kTexSourceCubeReflect) + { + EmitMatrixMul (bld, k11VertexTex+4*i, 'r',eyeReflReg, 'o',outUVReg[i], tempRegCounter, true); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ouv"+iname + " = mul(ff_matrix_tex["+iname +"], float4(eyeRefl,1.0));\n"; + #endif + } + else + { + AssertString("Unknown texgen mode"); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ouv"+iname + " = 0.5;\n"; + #endif + } + texSources >>= 4; + } + + // fog if we have a spare varying + if (state.fogMode != kFogDisabled && outputRegCounter < 8) + { + Assert(eyePositionRequired); + int outFogReg; + dxb_dcl_output(builder, "FOG", 0, outFogReg = outputRegCounter++, 0x1); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (outputs, "out float ofog : FOG0"); + #endif + + params.AddVectorParam (k11VertexFog*16, 4, kShaderVecFFFogParams); + + int fogReg = tempRegCounter++; + + // fogCoord = length(eyePosition.xyz), for radial fog + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float fogCoord = length(eyePos.xyz);\n"; + #endif + + bld.op(kSM4Op_DP3).reg('r',fogReg,1).swz('r',eyePosReg,kSM4SwzNone).swz('r',eyePosReg,kSM4SwzNone); +#if 0 + bld.op(kSM4Op_SQRT).reg('r',fogReg,1).swz('r',fogReg,kSM4SwzRepX); +#else + //SM2 compatible + bld.op(kSM4Op_RSQ).reg('r',fogReg,1).swz('r',fogReg,kSM4SwzRepX); + bld.op(kSM4Op_RCP).reg('r',fogReg,1).swz('r',fogReg,kSM4SwzRepX); +#endif + if (state.fogMode == kFogLinear) + { + // fogParams.z * fogCoord + fogParams.w + bld.op_sat(kSM4Op_MAD,tempRegCounter).reg('o',outFogReg,1).swz('r',fogReg,kSM4SwzRepX).swz('c',k11VertexFog,kSM4SwzRepZ).swz('c',k11VertexFog,kSM4SwzRepW); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ofog = saturate(fogCoord * ff_fog.z + ff_fog.w);\n"; + #endif + } + else if (state.fogMode == kFogExp) + { + // fogArg = fogParams.y * fogCoord + // exp2(-fogArg) + bld.op(kSM4Op_MUL).reg('r',fogReg,1).swz('r',fogReg,kSM4SwzRepX).swz('c',k11VertexFog,kSM4SwzRepY); + bld.op_sat(kSM4Op_EXP,tempRegCounter).reg('o',outFogReg,1).swz('r',fogReg,kSM4SwzRepX,true); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "ofog = saturate(exp2(-(fogCoord * ff_fog.y)));\n"; + #endif + } + else if (state.fogMode == kFogExp2) + { + // fogArg = fogParams.y * fogCoord + // exp2(-fogArg*fogArg) + bld.op(kSM4Op_MUL).reg('r',fogReg,1).swz('r',fogReg,kSM4SwzRepX).swz('c',k11VertexFog,kSM4SwzRepY); + bld.op(kSM4Op_MUL).reg('r',fogReg,1).swz('r',fogReg,kSM4SwzRepX).swz('r',fogReg,kSM4SwzRepX); + bld.op_sat(kSM4Op_EXP,tempRegCounter).reg('o',outFogReg,1).swz('r',fogReg,kSM4SwzRepX,true); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "fogCoord = fogCoord * ff_fog.y;\n"; + code += "ofog = saturate(exp2(-fogCoord * fogCoord));\n"; + #endif + } + --tempRegCounter; + } + + dxb_dcl_output(builder, "SV_POSITION", 0, outPosReg = outputRegCounter++); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (outputs, "out float4 overtex : SV_POSITION"); + #endif + + // Vertex transformation + matrices.mat[kShaderInstanceMatMVP].gpuIndex = k11VertexMVP*16; + matrices.mat[kShaderInstanceMatMVP].rows = 4; + matrices.mat[kShaderInstanceMatMVP].cols = 4; + matrices.mat[kShaderInstanceMatMVP].cbID = params.m_CBID; + bld.op(kSM4Op_MUL).reg('r',0).swz('v',inPosReg,kSM4SwzRepY).swz('c',k11VertexMVP+1); + bld.op(kSM4Op_MAD).reg('r',0).swz('c',k11VertexMVP+0).swz('v',inPosReg,kSM4SwzRepX).swz('r',0); + bld.op(kSM4Op_MAD).reg('r',0).swz('c',k11VertexMVP+2).swz('v',inPosReg,kSM4SwzRepZ).swz('r',0); + bld.op(kSM4Op_MAD).reg('r',0).swz('c',k11VertexMVP+3).swz('v',inPosReg,kSM4SwzRepW).swz('r',0); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "overtex = mul (ff_matrix_mvp, vertex);\n"; + #endif + + //correct output pos with Vertex Shader position offset + //mad oPos.xy, v0.w, c63, v0 + bld.op2(kSM2Op_MAD).reg2('o',outPosReg,3).swz2('r',0,kSM4SwzRepW).swz2('c',k11VertexPosOffset9x).swz2('r',0); + //mov oPos.zw, v0 + bld.op2(kSM2Op_MOV).reg2('o',outPosReg,12).swz2('r',0); + + //copy output pos for sm40 + bld.noAutoSM2(); + bld.op(kSM4Op_MOV).reg('o',outPosReg).swz('r',0); + bld.autoSM2(); + + bld.op(kSM4Op_RET); + + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + std::string src = + kD3D11VertexPrefix + + helpers + '\n' + + "void main (\n " + + inputs + ",\n " + + outputs + ") {\n" + + code + "\n}"; + printf_console ("d3d11 FF VS HLSL:\n%s\n", src.c_str()); + DebugCompileHLSLShaderD3D11 (src, true); + #endif + + + void* blob = BuildShaderD3D11 (builder, outSize); + return blob; +} + + +// --- FRAGMENT program ---------------------------------------------------------------------------- + +enum CombinerWriteMask { kCombWriteRGBA, kCombWriteRGB, kCombWriteA }; + +static bool EmitCombinerMath11 ( + int stage, + UInt32 combiner, + CombinerWriteMask writeMaskMode, + int texUnitCount, + DXBCBuilderStream& bld + #if DEBUG_D3D11_COMPARE_WITH_HLSL + , std::string& code + #endif +) +{ + Assert (texUnitCount < 10 && stage < 10); + + combiner::Source sources[3]; + combiner::Operand operands[3]; + combiner::Operation op; + int scale; + combiner::DecodeTextureCombinerDescriptor (combiner, op, sources, operands, scale, true); + + // dot3 and dot3rgba write into RGBA; alpha combiner is always ignored + if (op == combiner::kOpDot3RGB || op == combiner::kOpDot3RGBA) + { + if (writeMaskMode == kCombWriteA) + return false; + writeMaskMode = kCombWriteRGBA; + } + + unsigned tmpIdx = 1; + + bool usedConstant = false; + char regFile[3]; + unsigned regIdx[3]; + unsigned regSrcAlphaSwz[3]; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + std::string reg[3]; + #endif + for (int r = 0; r < 3; ++r) + { + combiner::Source source = sources[r]; + regSrcAlphaSwz[r] = kSM4SwzRepW; + if (stage == 0 && source == combiner::kSrcPrevious) + source = combiner::kSrcPrimaryColor; // first stage, "previous" the same as "primary" + switch (source) + { + case combiner::kSrcPrimaryColor: + regFile[r] = 'v'; regIdx[r] = 0; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + reg[r] = "icolor"; + #endif + break; + case combiner::kSrcPrevious: + regFile[r] = 'r'; regIdx[r] = 0; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + reg[r] = "col"; + #endif + break; + case combiner::kSrcTexture: + regFile[r] = 'r'; regIdx[r] = 1; tmpIdx = 2; + regSrcAlphaSwz[r] = kSM4SwzRepW; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + reg[r] = "tex"; + #endif + break; + case combiner::kSrcConstant: + usedConstant |= true; regFile[r] = 'c'; regIdx[r] = stage; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + reg[r] = std::string("ff_vec_colors[") + char('0'+stage) + ']'; + #endif + break; + default: + AssertString("unknown source"); //reg[r] = "foo"; + } + } + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + const char* writeMask = ""; + #endif + unsigned writeMaskBin = 0xF; // rgba + if (writeMaskMode == kCombWriteRGB) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + writeMask = ".rgb"; + #endif + writeMaskBin = 0x7; // rgb + } + else if (writeMaskMode == kCombWriteA) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + writeMask = ".a"; + #endif + writeMaskBin = 0x8; // a + } + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + const char* regSwizzle[3]; + #endif + unsigned regSwizzleBin[3]; + for (int r = 0; r < 3; ++r) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + regSwizzle[r] = ""; + #endif + regSwizzleBin[r] = kSM4SwzNone; + // 1-x: into tmpN and use that + if (operands[r] == combiner::kOperOneMinusSrcColor || operands[r] == combiner::kOperOneMinusSrcAlpha) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("tmp")+char('0'+r)+" = 1.0 - " + reg[r]+regSwizzle[r] + ";\n"; + reg[r] = std::string("tmp")+char('0'+r); + #endif + bld.op(kSM4Op_ADD).reg('r', tmpIdx, writeMaskBin).swz(regFile[r], regIdx[r], regSwizzleBin[r], true).float1(1.0f); + regFile[r] = 'r'; + regIdx[r] = tmpIdx; + ++tmpIdx; + } + // replicate alpha swizzle? + if (operands[r] == combiner::kOperSrcAlpha || operands[r] == combiner::kOperOneMinusSrcAlpha) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + regSwizzle[r] = ".a"; + #endif + regSwizzleBin[r] = kSM4SwzRepW; + } + } + switch (op) + { + case combiner::kOpReplace: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + ";\n"; + #endif + bld.op(kSM4Op_MOV).reg('r', 0, writeMaskBin).swz(regFile[0], regIdx[0], regSwizzleBin[0]); + break; + case combiner::kOpModulate: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + " * " + reg[1]+regSwizzle[1] + ";\n"; + #endif + bld.op(kSM4Op_MUL); + bld.reg('r', 0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + break; + case combiner::kOpAdd: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + " + " + reg[1]+regSwizzle[1] + ";\n"; + #endif + bld.op(kSM4Op_ADD); + bld.reg('r', 0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + break; + case combiner::kOpAddSigned: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + " + " + reg[1]+regSwizzle[1] + " - 0.5;\n"; + #endif + bld.op(kSM4Op_ADD); + bld.reg('r', 0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + bld.op(kSM4Op_ADD); + bld.reg('r', 0, writeMaskBin); + bld.swz('r', 0); + bld.float4(-.5f,-.5f,-.5f,-.5f); + break; + case combiner::kOpSubtract: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + " - " + reg[1]+regSwizzle[1] + ";\n"; + #endif + bld.op(kSM4Op_ADD); + bld.reg('r', 0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1], true); + break; + case combiner::kOpLerp: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = lerp (" + reg[1]+regSwizzle[1] + ", " + reg[0]+regSwizzle[0] + ", " + reg[2]+ ".a);\n"; + #endif + // tmp = r0-r1 + // res = tmp * r2 + r1 + bld.op(kSM4Op_ADD); + bld.reg('r', tmpIdx, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1], true); + bld.op(kSM4Op_MAD); + bld.reg('r', 0, writeMaskBin); + bld.swz('r', tmpIdx); + bld.swz(regFile[2], regIdx[2], regSrcAlphaSwz[2]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + ++tmpIdx; + break; + case combiner::kOpDot3RGB: + DebugAssert(writeMaskMode == kCombWriteRGBA); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col.rgb = 4.0 * dot ((") + reg[0]+regSwizzle[0] + ")-0.5, (" + reg[1]+regSwizzle[1] + ")-0.5);\n"; + code += std::string("col.a = ") + reg[0]+".a;\n"; + #endif + + // tmp+0 = r0-0.5 + bld.op(kSM4Op_ADD); + bld.reg('r', tmpIdx+0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.float4(-.5f,-.5f,-.5f,-.5f); + // tmp+1 = r1-0.5 + bld.op(kSM4Op_ADD); + bld.reg('r', tmpIdx+1, writeMaskBin); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + bld.float4(-.5f,-.5f,-.5f,-.5f); + // tmp0.rgb = dp4(tmp+0, tmp+1) + bld.op(kSM4Op_DP3); + bld.reg('r', 0, 0x7); + bld.swz('r', tmpIdx+0); + bld.swz('r', tmpIdx+1); + // tmp0.rgb *= 4 + bld.op(kSM4Op_MUL); + bld.reg('r', 0, 0x7); + bld.swz('r', 0); + bld.float4(4.0f,4.0f,4.0f,4.0f); + // tmp0.a = r0.a + bld.op(kSM4Op_MOV); + bld.reg('r', 0, 0x8); + bld.swz(regFile[0], regIdx[0], kSM4SwzRepW); + tmpIdx += 2; + break; + case combiner::kOpDot3RGBA: + DebugAssert(writeMaskMode == kCombWriteRGBA); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = 4.0 * dot ((" + reg[0]+regSwizzle[0] + ")-0.5, (" + reg[1]+regSwizzle[1] + ")-0.5);\n"; + #endif + // tmp+0 = r0-0.5 + bld.op(kSM4Op_ADD); + bld.reg('r', tmpIdx+0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.float4(-.5f,-.5f,-.5f,-.5f); + // tmp+1 = r1-0.5 + bld.op(kSM4Op_ADD); + bld.reg('r', tmpIdx+1, writeMaskBin); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + bld.float4(-.5f,-.5f,-.5f,-.5f); + // tmp0 = dp4(tmp+0, tmp+1) + bld.op(kSM4Op_DP3); + bld.reg('r', 0, writeMaskBin); + bld.swz('r', tmpIdx+0); + bld.swz('r', tmpIdx+1); + // tmp0 *= 4 + bld.op(kSM4Op_MUL); + bld.reg('r', 0, writeMaskBin); + bld.swz('r', 0); + bld.float4(4.0f,4.0f,4.0f,4.0f); + tmpIdx += 2; + break; + case combiner::kOpMulAdd: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + " * " + reg[2]+".a + " + reg[1]+regSwizzle[1] + ";\n"; + #endif + bld.op(kSM4Op_MAD); + bld.reg('r', 0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[2], regIdx[2], regSrcAlphaSwz[2]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + break; + case combiner::kOpMulSub: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + " * " + reg[2]+".a - " + reg[1]+regSwizzle[1] + ";\n"; + #endif + bld.op(kSM4Op_MAD); + bld.reg('r', 0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[2], regIdx[2], regSrcAlphaSwz[2]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1], true); + break; + case combiner::kOpMulAddSigned: + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + " * " + reg[2]+".a + " + reg[1]+regSwizzle[1] + " - 0.5;\n"; + #endif + bld.op(kSM4Op_MAD); + bld.reg('r', 0, writeMaskBin); + bld.swz(regFile[0], regIdx[0], regSwizzleBin[0]); + bld.swz(regFile[2], regIdx[2], regSrcAlphaSwz[2]); + bld.swz(regFile[1], regIdx[1], regSwizzleBin[1]); + bld.op(kSM4Op_ADD); + bld.reg('r', 0, writeMaskBin); + bld.swz('r', 0); + bld.float4(-.5f,-.5f,-.5f,-.5f); + break; + default: + AssertString ("Unknown combiner op!"); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col")+writeMask + " = " + reg[0]+regSwizzle[0] + ";\n"; + #endif + break; + } + + // scale + if (scale > 1) + { + DebugAssert (scale == 2 || scale == 4); + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("col *= ") + char('0'+scale) + ".0;\n"; + #endif + if (scale == 2) + { + bld.op(kSM4Op_ADD); + bld.reg('r', 0, writeMaskBin); + bld.swz('r', 0); + bld.swz('r', 0); + } + else if (scale == 4) + { + bld.op(kSM4Op_MUL); + bld.reg('r', 0, writeMaskBin); + bld.swz('r', 0); + bld.float4(4.0f,4.0f,4.0f,4.0f); + } + } + + return usedConstant; +} + +void* BuildFragmentShaderD3D11 (const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, size_t& outSize) +{ + ShaderLab::FastPropertyName cbName; cbName.SetName(kD3D11PixelCB); + GetD3D11ConstantBuffers(GetRealGfxDevice()).SetCBInfo (cbName.index, k11PixelSize*16); + params.m_CBID = cbName.index; params.m_CBSize = k11PixelSize*16; + + DXBCBuilder* builder = dxb_create(4, 0, kSM4Shader_Pixel); + DXBCBuilderStream bld(builder); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + std::string textures, inputs, code; + #endif + + dxb_dcl_output(builder, "SV_Target", 0, 0); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, "float4 icolor : COLOR0"); + #endif + int inputRegCounter = 0; + dxb_dcl_input(builder, "COLOR", 0, inputRegCounter++); + + if (state.lightingEnabled && state.specularEnabled) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, "float3 ispec : COLOR1"); + #endif + dxb_dcl_input(builder, "COLOR", 1, inputRegCounter++, 0x7); + } + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float4 col;\n"; + #endif + + if (state.texUnitCount == 0) + { + // No combiners is special case: output primary color + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "col = icolor;\n"; + #endif + bld.op(kSM4Op_MOV).reg('r', 0).swz('v', 0); + + // BUG, using for ex., + // SubShader { Pass { Color (1,0,0,0) } } + // produces white color instead of red on IvyBridge UltraBook + } + else + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "float4 tex, tmp0, tmp1, tmp2;\n"; + #endif + for (int i = 0; i < state.texUnitCount; i++) + { + std::string iname = IntToString(i); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, ("float4 iuv"+iname + " : TEXCOORD"+iname).c_str()); + textures += "SamplerState ff_smp"+iname + " : register(s"+iname+");\n"; + #endif + + // sample the texture into tmp1 + if (state.texUnit3D & (1<<i)) // 3D + { + dxb_dcl_input(builder, "TEXCOORD", i, inputRegCounter,0x7); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + textures += "Texture3D ff_tex"+iname + " : register(t"+iname+");\n"; + code += "tex = ff_tex"+iname + ".Sample(ff_smp"+iname + ", iuv"+iname + ".xyz);\n"; + #endif + + dxb_dcl_tex(builder, i, kSM4Target_TEXTURE3D); + bld.op(kSM4Op_SAMPLE).reg('r', 1).swz('v', inputRegCounter, kSM4SwzXYZX).swz('t', i).reg('s', i); + } + else if (state.texUnitCube & (1<<i)) // cubemap + { + dxb_dcl_input(builder, "TEXCOORD", i, inputRegCounter,0x7); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + textures += "TextureCube ff_tex"+iname + " : register(t"+iname+");\n"; + code += "tex = ff_tex"+iname + ".Sample(ff_smp"+iname + ", iuv"+iname + ".xyz);\n"; + #endif + + dxb_dcl_tex(builder, i, kSM4Target_TEXTURECUBE); + bld.op(kSM4Op_SAMPLE).reg('r', 1).swz('v', inputRegCounter, kSM4SwzXYZX).swz('t', i).reg('s', i); + } + else if (state.texUnitProjected & (1<<i)) // projected sample + { + dxb_dcl_input(builder, "TEXCOORD", i, inputRegCounter,0xB); // xyw mask + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + textures += "Texture2D ff_tex"+iname + " : register(t"+iname+");\n"; + code += "tex = ff_tex"+iname + ".Sample(ff_smp"+iname + ", iuv"+iname + ".xy / iuv"+iname + ".w);\n"; + #endif + + dxb_dcl_tex(builder, i, kSM4Target_TEXTURE2D); + + // SM4: use DIV; Intel IvyBridge seems to prefer that + bld.noAutoSM2(); + bld.op(kSM4Op_DIV).reg('r', 1, 0x3).swz('v', inputRegCounter, kSM4SwzXYXX).swz('v', inputRegCounter, kSM4SwzRepW); + bld.autoSM2(); + + // SM2: use RCP+MUL + bld.op2(kSM2Op_RCP).reg2('r', 1, 8).swz2('v', inputRegCounter, kSM4SwzRepW); + bld.op2(kSM2Op_MUL).reg2('r', 1, 0x3).swz2('v', inputRegCounter, kSM4SwzXYXX).swz2('r',1, kSM4SwzRepW); + + bld.op(kSM4Op_SAMPLE).reg('r', 1).swz('r', 1, kSM4SwzXYXX).swz('t', i).reg('s', i); + } + else // regular sample + { + dxb_dcl_input(builder, "TEXCOORD", i, inputRegCounter,0x3); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + textures += "Texture2D ff_tex"+iname + " : register(t"+iname+");\n"; + code += "tex = ff_tex"+iname + ".Sample(ff_smp"+iname + ", iuv"+iname + ".xy);\n"; + #endif + + dxb_dcl_tex(builder, i, kSM4Target_TEXTURE2D); + bld.op(kSM4Op_SAMPLE).reg('r', 1).swz('v', inputRegCounter, kSM4SwzXYXX).swz('t', i).reg('s', i); + } + + // emit color & alpha combiners; result in tmp0 + UInt32 colorComb = state.texUnitColorCombiner[i]; + UInt32 alphaComb = state.texUnitAlphaCombiner[i]; + bool usedConstant = false; + if (colorComb == alphaComb) + { + usedConstant |= EmitCombinerMath11 (i, colorComb, kCombWriteRGBA, state.texUnitCount, bld + #if DEBUG_D3D11_COMPARE_WITH_HLSL + , code + #endif + ); + } + else + { + usedConstant |= EmitCombinerMath11 (i, colorComb, kCombWriteRGB, state.texUnitCount, bld + #if DEBUG_D3D11_COMPARE_WITH_HLSL + , code + #endif + ); + usedConstant |= EmitCombinerMath11 (i, alphaComb, kCombWriteA, state.texUnitCount, bld + #if DEBUG_D3D11_COMPARE_WITH_HLSL + , code + #endif + ); + } + + if (usedConstant) + params.AddVectorParam ((k11PixelColors+i)*16, 4, BuiltinShaderVectorParam(kShaderVecFFTextureEnvColor0+i)); + ++inputRegCounter; + } + } + + // alpha test + if (state.alphaTest != kFuncDisabled && state.alphaTest != kFuncAlways) + { + params.AddVectorParam (k11PixelAlphaRef*16, 1, kShaderVecFFAlphaTestRef); + if (state.alphaTest == kFuncNever) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "discard;\n"; + #endif + bld.op(kSM4Op_DISCARD).float1(-1); // int is not sm20 compatible; old comment: HLSL emits 'l(-1)' for plain discard; with the value being integer -1 (all bits set) + } + else + { + // Reverse logic because we're using here 'discard' + #if DEBUG_D3D11_COMPARE_WITH_HLSL + static const char* kCmpOps[] = + { + "", // kFuncDisabled + "", // kFuncNever + ">=", // kFuncLess + "!=", // kFuncEqual + ">", // kFuncLEqual + "<=", // kFuncGreater + "==", // kFuncNotEqual + "<", // kFuncGEqual + "", // kFuncAlways + }; + #endif // #if DEBUG_D3D11_COMPARE_WITH_HLSL + static SM4Opcode kCmpOpcodes[] = + { + kSM4Op_ADD, // kFuncDisabled + kSM4Op_ADD, // kFuncNever + kSM4Op_GE, // kFuncLess + kSM4Op_NE, // kFuncEqual + kSM4Op_LT, // kFuncLEqual + kSM4Op_GE, // kFuncGreater + kSM4Op_EQ, // kFuncNotEqual + kSM4Op_LT, // kFuncGEqual + kSM4Op_ADD, // kFuncAlways + }; + static bool kCmpOrder[] = + { + false, // kFuncDisabled + false, // kFuncNever + true, // kFuncLess + true, // kFuncEqual + false, // kFuncLEqual + false, // kFuncGreater + true, // kFuncNotEqual + true, // kFuncGEqual + false, // kFuncAlways + }; + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += std::string("if (col.a ") + kCmpOps[state.alphaTest] + " ff_alpha_ref) discard;\n"; + #endif + + bld.noAutoSM2(); + bld.op(kCmpOpcodes[state.alphaTest]).reg('r', 1, 0x1); + if (kCmpOrder[state.alphaTest]) + { + bld.swz('r', 0, kSM4SwzRepW); + bld.swz('c', k11PixelAlphaRef, kSM4SwzRepX); + } + else + { + bld.swz('c', k11PixelAlphaRef, kSM4SwzRepX); + bld.swz('r', 0, kSM4SwzRepW); + } + bld.op(kSM4Op_DISCARD).reg('r', 1, 1); + bld.autoSM2(); + + //SM20 + static float bConst[][2] = + { + {0,0}, + {0,0}, + + {0,-1}, + {0,-1}, + {-1,0}, + {0,-1}, + {-1,0}, + {-1,0}, + + {0,0}, + }; + static bool bRefSign[] = + { + false, + false, + + false, + true, + true, + true, + true, + false, + false, + }; + + bld.op2(kSM2Op_ADD). + reg2('r',1,1). + swz2('c',k11PixelAlphaRef, kSM4SwzRepX,bRefSign[state.alphaTest]). + swz2('r', 0, kSM4SwzRepW,!bRefSign[state.alphaTest]); + if (state.alphaTest == kFuncEqual || state.alphaTest == kFuncNotEqual) + bld.op2(kSM2Op_MUL).reg2('r',1,1).swz2('r',1,kSM4SwzRepX).swz2('r',1,kSM4SwzRepX); + bld.op2(kSM2Op_CMP).reg2('r',1). + swz2('r',1,kSM4SwzRepX,state.alphaTest == kFuncEqual || state.alphaTest == kFuncNotEqual). + float1_2(bConst[state.alphaTest][0]). + float1_2(bConst[state.alphaTest][1]); + bld.op2(kSM2Op_TEXKILL).reg2('r', 1); + } + } + + // add specular + if (state.lightingEnabled && state.specularEnabled) + { + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "col.rgb += ispec;\n"; + #endif + // add r0.xyz, r0.xyz, v1.xyz + bld.op(kSM4Op_ADD).reg('r', 0, 0x7).swz('r', 0, kSM4SwzXYZX).swz('v', 1, kSM4SwzXYZX); + } + + // fog + if (state.fogMode != kFogDisabled && inputRegCounter < 8) + { + int fogVar = inputRegCounter; + dxb_dcl_input(builder, "FOG", 0, fogVar, 0x1); + params.AddVectorParam (k11PixelFog*16, 4, kShaderVecFFFogColor); + // color.rgb = lerp (fogColor.rgb, color.rgb, fogVar) = + // (color.rgb-fogColor.rgb) * fogVar + fogColor.rgb + bld.op(kSM4Op_ADD).reg('r',0,7).swz('r',0,kSM4SwzXYZX).swz('c',k11PixelFog,kSM4SwzXYZX, true); + bld.op(kSM4Op_MAD).reg('r',0,7).swz('r',0,kSM4SwzXYZX).swz('v',fogVar,kSM4SwzRepX).swz('c',k11PixelFog,kSM4SwzXYZX); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + AddToStringList (inputs, "float ifog : FOG"); + code += "col.rgb = lerp (ff_fog.rgb, col.rgb, ifog);\n"; + #endif + } + + if (params.HasVectorParams()) + dxb_dcl_cb(builder, 0, k11PixelSize); + + // mov o0.xyzw, r0.xyzw + bld.op(kSM4Op_MOV).reg('o', 0).swz('r', 0); + // ret + bld.op(kSM4Op_RET); + + #if DEBUG_D3D11_COMPARE_WITH_HLSL + code += "return col;\n"; + std::string src = textures + kD3D11PixelPrefix + inputs + ") : SV_TARGET {\n" + code + "\n}"; + printf_console ("d3d11 FF PS HLSL:\n%s\n", src.c_str()); + DebugCompileHLSLShaderD3D11 (src, false); + #endif + + void* blob = BuildShaderD3D11 (builder, outSize); + return blob; +} diff --git a/Runtime/GfxDevice/d3d11/ShaderGeneratorD3D11.h b/Runtime/GfxDevice/d3d11/ShaderGeneratorD3D11.h new file mode 100644 index 0000000..6316275 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/ShaderGeneratorD3D11.h @@ -0,0 +1,10 @@ +#pragma once + +#include "D3D11Includes.h" +#include "GpuProgramsD3D11.h" + + +struct FixedFunctionStateD3D11; + +void* BuildVertexShaderD3D11 (const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, BuiltinShaderParamIndices& matrices, size_t& outSize); +void* BuildFragmentShaderD3D11 (const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, size_t& outSize); diff --git a/Runtime/GfxDevice/d3d11/ShaderGeneratorLinkD3D11.cpp b/Runtime/GfxDevice/d3d11/ShaderGeneratorLinkD3D11.cpp new file mode 100644 index 0000000..eb64cfd --- /dev/null +++ b/Runtime/GfxDevice/d3d11/ShaderGeneratorLinkD3D11.cpp @@ -0,0 +1,985 @@ +#include "UnityPrefix.h" + +#if UNITY_METRO_VS2013 || (UNITY_WIN && !UNITY_WINRT) + +#include "ShaderGeneratorD3D11.h" +#include "FixedFunctionStateD3D11.h" +#include "ConstantBuffersD3D11.h" +#include "Runtime/GfxDevice/GpuProgram.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "PlatformDependent/Win/SmartComPointer.h" +#include "Runtime/Utilities/File.h" + +#include "Runtime/GfxDevice/d3d11/InternalShaders/FFShaderLib.h" + +#if UNITY_WINRT +#include <D3DCompiler.h> +#endif + +ConstantBuffersD3D11& GetD3D11ConstantBuffers (GfxDevice& device); + + +typedef SmartComPointer<ID3D11LinkingNode> NodePtr; +typedef SmartComPointer<ID3D11ModuleInstance> ModuleInstancePtr; +typedef SmartComPointer<ID3D11Module> ModulePtr; +typedef SmartComPointer<ID3D11Linker> LinkerPtr; +typedef SmartComPointer<ID3D11FunctionLinkingGraph> FLGPtr; +typedef SmartComPointer<ID3DBlob> BlobPtr; + +const int kMaxSignatureParams = 12; +const int kSamplingModuleCount = 32; + + +struct D3D11ShaderLinker +{ + D3D11ShaderLinker() + : createLinkerFunc(0) + , loadModuleFunc(0) + , createFunctionLinkingGraphFunc(0) + , m_Dll(0) + , m_Initialized(false) + , m_Valid(false) + { + } + + ~D3D11ShaderLinker() + { + m_Module.Release(); + m_ModuleInstanceVS.Release(); + m_ModuleInstancePS.Release(); + + for (int i = 0; i < kSamplingModuleCount; ++i) + { + m_SamplingModules[i].Release(); + m_SamplingModuleInstances[i].Release(); + } + + if (m_Dll) + FreeLibrary(m_Dll); + } + + void Initialize ( + const char* dllName, + const BYTE* shaderLibraryCode, size_t shaderLibrarySize, + const BYTE** samplingLibraryCodes, const size_t* samplingLibrarySizes); + + typedef HRESULT (WINAPI *D3DCreateLinkerFunc)(ID3D11Linker **ppLinker); + typedef HRESULT (WINAPI *D3DLoadModuleFunc)( + const void* srcData, + SIZE_T srcDataSize, + ID3D11Module** ppModule); + typedef HRESULT (WINAPI *D3DCreateFunctionLinkingGraphFunc)( + UINT uFlags, + ID3D11FunctionLinkingGraph **ppFunctionLinkingGraph); + + D3DCreateLinkerFunc createLinkerFunc; + D3DLoadModuleFunc loadModuleFunc; + D3DCreateFunctionLinkingGraphFunc createFunctionLinkingGraphFunc; + + HMODULE m_Dll; + bool m_Initialized; + bool m_Valid; + + ModulePtr m_Module; + ModuleInstancePtr m_ModuleInstanceVS, m_ModuleInstancePS; + + ModulePtr m_SamplingModules[kSamplingModuleCount]; + ModuleInstancePtr m_SamplingModuleInstances[kSamplingModuleCount]; +}; + +static D3D11ShaderLinker s_Linker; + +void D3D11ShaderLinker::Initialize ( + const char* dllName, + const BYTE* shaderLibraryCode, size_t shaderLibrarySize, + const BYTE** samplingLibraryCodes, const size_t* samplingLibrarySizes) +{ + if (m_Initialized) + return; + + m_Valid = false; + m_Initialized = true; + + // Load DLL + #if UNITY_WINRT + // We use a proper linked library on Metro Blue + //m_Dll = LoadPackagedLibrary (ConvertToWindowsPath(dllName)->Data(), 0); + #else + m_Dll = LoadLibraryA (dllName); + if (!m_Dll) + return; + #endif + + // Get functions +#if UNITY_WINRT + createLinkerFunc = (D3DCreateLinkerFunc)&D3DCreateLinker; + loadModuleFunc = (D3DLoadModuleFunc)&D3DLoadModule; + createFunctionLinkingGraphFunc = (D3DCreateFunctionLinkingGraphFunc)&D3DCreateFunctionLinkingGraph; +#else + createLinkerFunc = (D3DCreateLinkerFunc) GetProcAddress (m_Dll, "D3DCreateLinker"); + loadModuleFunc = (D3DLoadModuleFunc) GetProcAddress (m_Dll, "D3DLoadModule"); + createFunctionLinkingGraphFunc = (D3DCreateFunctionLinkingGraphFunc) GetProcAddress (m_Dll, "D3DCreateFunctionLinkingGraph"); +#endif + + if (createLinkerFunc == 0 || loadModuleFunc == 0 || createFunctionLinkingGraphFunc == 0) + return; + + HRESULT hr = loadModuleFunc(shaderLibraryCode, shaderLibrarySize, &m_Module); + if (FAILED(hr)) + { + printf("DX11: Failed to load compiled library: 0x%x\n", hr); + return; + } + + // Setup HLSL linker + hr = m_Module->CreateInstance ("", &m_ModuleInstanceVS); + if (FAILED(hr)) + { + printf("DX11: Failed to create compiled library instance: 0x%x\n", hr); + return; + } + hr = m_ModuleInstanceVS->BindConstantBufferByName("UnityFFVertex",0,0); + + hr = m_Module->CreateInstance ("", &m_ModuleInstancePS); + if (FAILED(hr)) + { + printf("DX11: Failed to create compiled library instance: 0x%x\n", hr); + return; + } + hr = m_ModuleInstancePS->BindConstantBufferByName("UnityFFPixel",0,0); + + + // Setup sampling modules + for (int i = 0; i < kSamplingModuleCount; ++i) + { + hr = loadModuleFunc(samplingLibraryCodes[i], samplingLibrarySizes[i], &m_SamplingModules[i]); + AssertIf(FAILED(hr)); + hr = m_SamplingModules[i]->CreateInstance ("", &m_SamplingModuleInstances[i]); + AssertIf(FAILED(hr)); + + int unit = i % 8; + hr = m_SamplingModuleInstances[i]->BindResource(unit, unit, 1); + hr = m_SamplingModuleInstances[i]->BindSampler(unit, unit, 1); + } + + m_Valid = true; +} + +bool HasD3D11Linker() +{ + const char* dllName = "D3DCompiler_47.dll"; + s_Linker.Initialize(dllName, g_FFShaderLibrary, sizeof(g_FFShaderLibrary), g_FFSampleTexLib, g_FFSampleTexLibSize); + return s_Linker.m_Valid; +} + + +// --- Constant buffers & utilities -------------------------------------------------------------- + + +static const char* kD3D11VertexCB = "UnityFFVertex"; +static const char* kD3D11PixelCB = "UnityFFPixel"; + +enum { + k11VertexMVP = 0, + k11VertexMV = 4, + k11VertexColor = 8, + k11VertexAmbient = 9, + k11VertexLightColor = 10, + k11VertexLightPos = 18, + k11VertexLightAtten = 26, + k11VertexLightSpot = 34, + k11VertexMatDiffuse = 42, + k11VertexMatAmbient = 43, + k11VertexMatSpec = 44, + k11VertexMatEmission = 45, + k11VertexTex = 46, + k11VertexFog = 62, + k11VertexSize = 63, +}; +enum { + k11PixelColors = 0, + k11PixelAlphaRef = 8, + k11PixelFog = 9, + k11PixelSize = 10 +}; + + +// --- VERTEX program ---------------------------------------------------------------------------- + + +static D3D11_PARAMETER_DESC CreateParamDesc(const char* name, const char* sem, int dim) +{ + D3D11_PARAMETER_DESC desc = { + name, + sem, + D3D_SVT_FLOAT, + dim == 1 ? D3D_SVC_SCALAR : D3D_SVC_VECTOR, + 1, + dim, + D3D_INTERPOLATION_UNDEFINED, + D3D_PF_NONE, + 0, 0, 0, 0 + }; + return desc; +} + + +void* BuildVertexShaderD3D11_Link (const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, BuiltinShaderParamIndices& matrices, size_t& outSize) +{ + ShaderLab::FastPropertyName cbName; cbName.SetName(kD3D11VertexCB); + GetD3D11ConstantBuffers(GetRealGfxDevice()).SetCBInfo (cbName.index, k11VertexSize*16); + params.m_CBID = cbName.index; params.m_CBSize = k11VertexSize*16; + + HRESULT hr = S_OK; + const bool hasLinker = HasD3D11Linker(); + Assert(hasLinker); + FLGPtr flg; + s_Linker.createFunctionLinkingGraphFunc (0, &flg); + D3D11_PARAMETER_DESC inputSig[kMaxSignatureParams]; + D3D11_PARAMETER_DESC outputSig[kMaxSignatureParams]; + + bool hasLights = (state.lightingEnabled && state.lightCount > 0); + + bool eyePositionRequired = + hasLights || + (state.fogMode != kFogDisabled); + bool eyeNormalRequired = hasLights; + bool viewDirRequired = hasLights && state.specularEnabled; + bool eyeReflRequired = false; + { + UInt64 texSources = state.texUnitSources; + for (int i = 0; i < state.texUnitCount; i++) + { + UInt32 uvSource = texSources & 0xF; + if (uvSource == kTexSourceEyeLinear) + eyePositionRequired = true; + if (uvSource == kTexSourceCubeNormal) + eyeNormalRequired = true; + if (uvSource == kTexSourceCubeReflect || uvSource == kTexSourceSphereMap) + eyeReflRequired = viewDirRequired = eyePositionRequired = eyeNormalRequired = true; + texSources >>= 4; + } + } + if (eyePositionRequired || eyeNormalRequired || eyeReflRequired) + { + matrices.mat[kShaderInstanceMatMV].gpuIndex = k11VertexMV*16; + matrices.mat[kShaderInstanceMatMV].rows = 4; + matrices.mat[kShaderInstanceMatMV].cols = 4; + matrices.mat[kShaderInstanceMatMV].cbID = params.m_CBID; + } + + int inputRegCounter = 0, outputRegCounter = 0; + int inPosReg = 0, inColorReg = 0, inNormalReg = 0; + int inUVReg[8] = {0}; + int outColor0Reg = 0, outColor1Reg = 0, outPosReg = 0; + int outUVReg[8] = {0}; + int outFogReg = -1; + + + // ---- Figure out input signature ---------------------------------------- + + // Position + inputSig[inPosReg = inputRegCounter++] = CreateParamDesc("vertex", "POSITION", 4); + // Vertex color + if (!state.useUniformInsteadOfVertexColor) + inputSig[inColorReg = inputRegCounter++] = CreateParamDesc("vertexColor", "COLOR", 4); + // Normal + if (eyeNormalRequired) + inputSig[inNormalReg = inputRegCounter++] = CreateParamDesc("normal", "NORMAL", 3); + // UVs + UInt32 gotInputs = 0; + static const char* kUVNames[kMaxSupportedTextureCoords] = {"uv0","uv1","uv2","uv3","uv4","uv5","uv6","uv7"}; + static const char* kUVOutNames[kMaxSupportedTextureCoords] = {"ouv0","ouv1","ouv2","ouv3","ouv4","ouv5","ouv6","ouv7"}; + static const char* kUVSemantics[kMaxSupportedTextureCoords] = {"TEXCOORD0","TEXCOORD1","TEXCOORD2","TEXCOORD3","TEXCOORD4","TEXCOORD5","TEXCOORD6","TEXCOORD7"}; + UInt64 texSources = state.texUnitSources; + for (int i = 0; i < state.texUnitCount; i++) + { + UInt32 uvSource = texSources & 0xF; + if (uvSource >= kTexSourceUV0 && uvSource <= kTexSourceUV7) + { + unsigned uv = uvSource-kTexSourceUV0; + if (!(gotInputs & (1<<uv))) + { + inputSig[inUVReg[uv] = inputRegCounter++] = CreateParamDesc(kUVNames[uv], kUVSemantics[uv], 4); + gotInputs |= (1<<uv); + } + } + texSources >>= 4; + } + + NodePtr inputNode; + Assert(inputRegCounter <= kMaxSignatureParams); + hr = flg->SetInputSignature(inputSig, inputRegCounter, &inputNode); + + + // ---- Figure out output signature --------------------------------------- + + // color + outputSig[outColor0Reg = outputRegCounter++] = CreateParamDesc("ocolor", "COLOR0", 4); + // spec color + if (state.lightingEnabled && state.specularEnabled) + outputSig[outColor1Reg = outputRegCounter++] = CreateParamDesc("ospec", "COLOR1", 3); + // UVs + for (int i = 0; i < state.texUnitCount; i++) + outputSig[outUVReg[i] = outputRegCounter++] = CreateParamDesc(kUVOutNames[i], kUVSemantics[i], 4); + // Fog + if (state.fogMode != kFogDisabled && outputRegCounter < 8) + outputSig[outFogReg = outputRegCounter++] = CreateParamDesc("ofog", "FOG0", 1); + // position + outputSig[outPosReg = outputRegCounter++] = CreateParamDesc("overtex", "SV_POSITION", 4); + + // ---- Build code -------------------------------------------------------- + + + NodePtr colorNode, eyePosNode, eyeNormalNode, viewDirNode, eyeReflNode; + NodePtr ambientNode, diffuseNode, emissionNode; + NodePtr ambientNodeToUse, diffuseNodeToUse, emissionNodeToUse; + NodePtr lightNode, specNode, fogNode; + + // color = Vertex or uniform color + if (state.useUniformInsteadOfVertexColor) + { + params.AddVectorParam (k11VertexColor*16, 4, kShaderVecFFColor); + hr = flg->CallFunction("", s_Linker.m_Module, "LoadVertexColorUniform", &colorNode); + } + else + { + hr = flg->CallFunction("", s_Linker.m_Module, "LoadVertexColor", &colorNode); + hr = flg->PassValue(inputNode, inColorReg, colorNode, 0); + } + + // eyePos = eye position + if (eyePositionRequired) + { + hr = flg->CallFunction("", s_Linker.m_Module, "LoadEyePos", &eyePosNode); + hr = flg->PassValue(inputNode, inPosReg, eyePosNode, 0); + } + + // eyeNormal = normalize(normalMatrix * normal) + if (eyeNormalRequired) + { + hr = flg->CallFunction("", s_Linker.m_Module, "LoadEyeNormal", &eyeNormalNode); + hr = flg->PassValue(inputNode, inNormalReg, eyeNormalNode, 0); + } + + // view dir + if (viewDirRequired) + { + Assert(eyePosNode); + hr = flg->CallFunction("", s_Linker.m_Module, "LoadViewDir", &viewDirNode); + hr = flg->PassValue(eyePosNode, D3D_RETURN_PARAMETER_INDEX, viewDirNode, 0); + } + else + { + hr = flg->CallFunction("", s_Linker.m_Module, "LoadZero", &viewDirNode); + } + + // eyeRefl + if (eyeReflRequired) + { + DebugAssert (viewDirRequired); + // eyeRefl = reflection vector, 2*dot(V,N)*N-V + Assert(eyeNormalNode); + Assert(viewDirNode); + hr = flg->CallFunction("", s_Linker.m_Module, "LoadEyeRefl", &eyeReflNode); + hr = flg->PassValue(viewDirNode, D3D_RETURN_PARAMETER_INDEX, eyeReflNode, 0); + hr = flg->PassValue(eyeNormalNode, D3D_RETURN_PARAMETER_INDEX, eyeReflNode, 1); + } + + // Lighting + if (state.lightingEnabled) + { + if (state.colorMaterial==kColorMatAmbientAndDiffuse) + { + ambientNodeToUse = colorNode; + diffuseNodeToUse = colorNode; + } + else + { + hr = flg->CallFunction("", s_Linker.m_Module, "LoadAmbientColor", &ambientNode); + ambientNodeToUse = ambientNode; + hr = flg->CallFunction("", s_Linker.m_Module, "LoadDiffuseColor", &diffuseNode); + diffuseNodeToUse = diffuseNode; + } + if (state.colorMaterial==kColorMatEmission) + { + emissionNodeToUse = colorNode; + } + else + { + hr = flg->CallFunction("", s_Linker.m_Module, "LoadEmissionColor", &emissionNode); + emissionNodeToUse = emissionNode; + } + + params.AddVectorParam (k11VertexAmbient*16, 4, kShaderVecLightModelAmbient); + params.AddVectorParam (k11VertexMatAmbient*16, 4, kShaderVecFFMatAmbient); + params.AddVectorParam (k11VertexMatDiffuse*16, 4, kShaderVecFFMatDiffuse); + params.AddVectorParam (k11VertexMatSpec*16, 4, kShaderVecFFMatSpecular); + params.AddVectorParam (k11VertexMatEmission*16, 4, kShaderVecFFMatEmission); + + Assert(emissionNodeToUse); + Assert(ambientNodeToUse); + hr = flg->CallFunction("", s_Linker.m_Module, "InitLightColor", &lightNode); + hr = flg->PassValue(emissionNodeToUse, D3D_RETURN_PARAMETER_INDEX, lightNode, 0); + hr = flg->PassValue(ambientNodeToUse, D3D_RETURN_PARAMETER_INDEX, lightNode, 1); + hr = flg->CallFunction("", s_Linker.m_Module, "LoadZero", &specNode); + if (state.lightCount > 0) + { + NodePtr lightCallNode; + std::string lightFuncName = state.specularEnabled ? "ComputeSpotLightSpec" : "ComputeSpotLight"; + lightFuncName += ('0' + state.lightCount); + hr = flg->CallFunction("", s_Linker.m_Module, lightFuncName.c_str(), &lightCallNode); + hr = flg->PassValue(eyePosNode, D3D_RETURN_PARAMETER_INDEX, lightCallNode, 0); + hr = flg->PassValue(eyeNormalNode, D3D_RETURN_PARAMETER_INDEX, lightCallNode, 1); + hr = flg->PassValue(viewDirNode, D3D_RETURN_PARAMETER_INDEX, lightCallNode, 2); + hr = flg->PassValue(diffuseNodeToUse, D3D_RETURN_PARAMETER_INDEX, lightCallNode, 3); + hr = flg->PassValue(specNode, D3D_RETURN_PARAMETER_INDEX, lightCallNode, 4); + hr = flg->PassValue(lightNode, D3D_RETURN_PARAMETER_INDEX, lightCallNode, 5); + + NodePtr specMoveNode; + hr = flg->CallFunction("", s_Linker.m_Module, "Load3", &specMoveNode); + hr = flg->PassValue(lightCallNode, 4, specMoveNode, 0); + specNode = specMoveNode; + + lightNode = lightCallNode; + } + + for (int i = 0; i < state.lightCount; ++i) + { + params.AddVectorParam ((k11VertexLightPos+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0Position+i)); + params.AddVectorParam ((k11VertexLightAtten+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0Atten+i)); + params.AddVectorParam ((k11VertexLightColor+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0Diffuse+i)); + params.AddVectorParam ((k11VertexLightSpot+i)*16, 4, BuiltinShaderVectorParam(kShaderVecLight0SpotDirection+i)); + } + + NodePtr finalLightColor; + hr = flg->CallFunction("", s_Linker.m_Module, "LoadLightingColor", &finalLightColor); + hr = flg->PassValue(lightNode, D3D_RETURN_PARAMETER_INDEX, finalLightColor, 0); + hr = flg->PassValue(diffuseNodeToUse, D3D_RETURN_PARAMETER_INDEX, finalLightColor, 1); + colorNode = finalLightColor; + + if (state.specularEnabled) + { + NodePtr finalSpecColor; + hr = flg->CallFunction("", s_Linker.m_Module, "ModulateSpec", &finalSpecColor); + hr = flg->PassValue(specNode, D3D_RETURN_PARAMETER_INDEX, finalSpecColor, 0); + specNode = finalSpecColor; + } + } + + // Output final color + NodePtr saturatedColorNode; + NodePtr saturatedSpecNode; + hr = flg->CallFunction("", s_Linker.m_Module, "Saturate4", &saturatedColorNode); + hr = flg->PassValue(colorNode, D3D_RETURN_PARAMETER_INDEX, saturatedColorNode, 0); + + if (state.lightingEnabled && state.specularEnabled) + { + Assert(specNode); + hr = flg->CallFunction("", s_Linker.m_Module, "Saturate3", &saturatedSpecNode); + hr = flg->PassValue(specNode, D3D_RETURN_PARAMETER_INDEX, saturatedSpecNode, 0); + } + + // Pass & transform texture coordinates + NodePtr texNodes[kMaxSupportedTextureCoords] = {0}; + + texSources = state.texUnitSources; + for (int i = 0; i < state.texUnitCount; i++) + { + matrices.mat[kShaderInstanceMatTexture0+i].gpuIndex = (k11VertexTex+i*4)*16; + matrices.mat[kShaderInstanceMatTexture0+i].rows = 4; + matrices.mat[kShaderInstanceMatTexture0+i].cols = 4; + matrices.mat[kShaderInstanceMatTexture0+i].cbID = params.m_CBID; + + std::string iname = IntToString(i); + std::string texFuncName = "MultiplyUV"; + texFuncName += iname; + + UInt32 uvSource = texSources & 0xF; + if (uvSource >= kTexSourceUV0 && uvSource <= kTexSourceUV7) + { + unsigned uv = uvSource-kTexSourceUV0; + hr = flg->CallFunction("", s_Linker.m_Module, texFuncName.c_str(), &texNodes[i]); + hr = flg->PassValue(inputNode, inUVReg[uv], texNodes[i], 0); + } + else if (uvSource == kTexSourceSphereMap) + { + // m = 2*sqrt(Rx*Rx + Ry*Ry + (Rz+1)*(Rz+1)) + // SPHR = Rx/m + 0.5, Ry/m + 0.5 + NodePtr texGenNode; + hr = flg->CallFunction("", s_Linker.m_Module, "UVSphereMap", &texGenNode); + hr = flg->PassValue(eyeReflNode, D3D_RETURN_PARAMETER_INDEX, texGenNode, 0); + hr = flg->CallFunction("", s_Linker.m_Module, texFuncName.c_str(), &texNodes[i]); + hr = flg->PassValue(texGenNode, D3D_RETURN_PARAMETER_INDEX, texNodes[i], 0); + } + else if (uvSource == kTexSourceObject) + { + NodePtr texGenNode; + hr = flg->CallFunction("", s_Linker.m_Module, texFuncName.c_str(), &texNodes[i]); + hr = flg->PassValue(inputNode, inPosReg, texNodes[i], 0); + } + else if (uvSource == kTexSourceEyeLinear) + { + NodePtr texGenNode; + hr = flg->CallFunction("", s_Linker.m_Module, "Float3to4", &texGenNode); + hr = flg->PassValue(eyePosNode, D3D_RETURN_PARAMETER_INDEX, texGenNode, 0); + hr = flg->CallFunction("", s_Linker.m_Module, texFuncName.c_str(), &texNodes[i]); + hr = flg->PassValue(texGenNode, D3D_RETURN_PARAMETER_INDEX, texNodes[i], 0); + } + else if (uvSource == kTexSourceCubeNormal) + { + NodePtr texGenNode; + hr = flg->CallFunction("", s_Linker.m_Module, "Float3to4", &texGenNode); + hr = flg->PassValue(eyeNormalNode, D3D_RETURN_PARAMETER_INDEX, texGenNode, 0); + hr = flg->CallFunction("", s_Linker.m_Module, texFuncName.c_str(), &texNodes[i]); + hr = flg->PassValue(texGenNode, D3D_RETURN_PARAMETER_INDEX, texNodes[i], 0); + } + else if (uvSource == kTexSourceCubeReflect) + { + NodePtr texGenNode; + hr = flg->CallFunction("", s_Linker.m_Module, "Float3to4", &texGenNode); + hr = flg->PassValue(eyeReflNode, D3D_RETURN_PARAMETER_INDEX, texGenNode, 0); + hr = flg->CallFunction("", s_Linker.m_Module, texFuncName.c_str(), &texNodes[i]); + hr = flg->PassValue(texGenNode, D3D_RETURN_PARAMETER_INDEX, texNodes[i], 0); + } + else + { + AssertString("Unknown texgen mode"); + } + texSources >>= 4; + } + + // fog if we have a spare varying + if (state.fogMode != kFogDisabled && outFogReg != -1) + { + Assert(eyePositionRequired); + + params.AddVectorParam (k11VertexFog*16, 4, kShaderVecFFFogParams); + + static const char* kFogFunction[] = + { + "", // kFogDisabled + "FogLinear", // kFogLinear + "FogExp", // kFogExp + "FogExp2" // kFogExp2 + }; + + hr = flg->CallFunction("", s_Linker.m_Module, kFogFunction[state.fogMode], &fogNode); + hr = flg->PassValue(eyePosNode, D3D_RETURN_PARAMETER_INDEX, fogNode, 0); + } + + // Vertex transformation + matrices.mat[kShaderInstanceMatMVP].gpuIndex = k11VertexMVP*16; + matrices.mat[kShaderInstanceMatMVP].rows = 4; + matrices.mat[kShaderInstanceMatMVP].cols = 4; + matrices.mat[kShaderInstanceMatMVP].cbID = params.m_CBID; + NodePtr vertexNode; + hr = flg->CallFunction("", s_Linker.m_Module, "TransformVertex", &vertexNode); + hr = flg->PassValue(inputNode, inPosReg, vertexNode, 0); + + + NodePtr outputNode; + Assert(outputRegCounter <= kMaxSignatureParams); + hr = flg->SetOutputSignature(outputSig, outputRegCounter, &outputNode); + + hr = flg->PassValue(vertexNode, D3D_RETURN_PARAMETER_INDEX, outputNode, outPosReg); + hr = flg->PassValue(saturatedColorNode, D3D_RETURN_PARAMETER_INDEX, outputNode, outColor0Reg); + if (saturatedSpecNode) + hr = flg->PassValue(saturatedSpecNode, D3D_RETURN_PARAMETER_INDEX, outputNode, outColor1Reg); + for (int i = 0; i < state.texUnitCount; i++) + { + if (texNodes[i]) + hr = flg->PassValue(texNodes[i], D3D_RETURN_PARAMETER_INDEX, outputNode, outUVReg[i]); + } + if (state.fogMode != kFogDisabled && outFogReg != -1) + { + hr = flg->PassValue(fogNode, D3D_RETURN_PARAMETER_INDEX, outputNode, outFogReg); + } + + #if 0 + // Print generated hlsl for debugging + BlobPtr hlslOutput; + hr = flg->GenerateHlsl(0, &hlslOutput); + if (SUCCEEDED(hr)) + { + printf_console("DX11 debug linked VS:\n%s\n", hlslOutput->GetBufferPointer()); + } + #endif + + + ModuleInstancePtr flgModule; + BlobPtr flgErrors; + hr = flg->CreateModuleInstance(&flgModule, &flgErrors); + if (FAILED(hr)) + { + const char* errorMsg = (const char*)flgErrors->GetBufferPointer(); + printf_console("DX11: Failed to create FF VS module: %s\n", errorMsg); + } + + LinkerPtr linker; + hr = s_Linker.createLinkerFunc(&linker); + hr = linker->UseLibrary (s_Linker.m_ModuleInstanceVS); + + + #if UNITY_WINRT + const char* target = "vs_4_0_level_9_1"; + #else + const char* target = "vs_4_0"; + #endif + + BlobPtr linkedCode; + BlobPtr linkedErrors; + hr = linker->Link(flgModule, "main", target, 0, &linkedCode, &linkedErrors); + if (FAILED(hr)) + { + const char* errorMsg = (const char*)linkedErrors->GetBufferPointer(); + printf_console("\nDX11: Failed to link FF VS: %s\n", errorMsg); + } + + if (!linkedCode) + { + outSize = 0; + return NULL; + } + outSize = linkedCode->GetBufferSize(); + void* finalCode = malloc(outSize); + memcpy (finalCode, linkedCode->GetBufferPointer(), outSize); + return finalCode; +} + + + +// --- FRAGMENT program ---------------------------------------------------------------------------- + + +enum CombinerWriteMask { kCombWriteRGBA, kCombWriteRGB, kCombWriteA }; +static const char* k11LinkCombOpNames[combiner::kCombinerOpCount] = { + "CombReplace", "CombModulate", "CombAdd", "CombAddSigned", "CombSubtract", "CombLerp", "CombDot3", "CombDot3rgba", "CombMulAdd", "CombMulSub", "CombMulAddSigned" +}; +static int k11LinkCompOpArgs[combiner::kCombinerOpCount] = { + 1, 2, 2, 2, 2, 3, 2, 2, 3, 3, 3 +}; + +static bool EmitCombinerMath11Link ( + int stage, + UInt32 combiner, + CombinerWriteMask writeMaskMode, + int texUnitCount, + FLGPtr& flg, + NodePtr& inputNode, NodePtr& prevNode, NodePtr& texNode, + NodePtr& outNewNode) +{ + Assert (texUnitCount < 10 && stage < 10); + + HRESULT hr = S_OK; + + combiner::Source sources[3]; + combiner::Operand operands[3]; + combiner::Operation op; + int scale; + combiner::DecodeTextureCombinerDescriptor (combiner, op, sources, operands, scale, true); + + // dot3 and dot3rgba write into RGBA; alpha combiner is always ignored + if (op == combiner::kOpDot3RGB || op == combiner::kOpDot3RGBA) + { + if (writeMaskMode == kCombWriteA) + { + outNewNode.Release(); + return false; + } + writeMaskMode = kCombWriteRGBA; + } + + bool usedConstant = false; + NodePtr reg[3]; + int regIndex[3] = {D3D_RETURN_PARAMETER_INDEX, D3D_RETURN_PARAMETER_INDEX, D3D_RETURN_PARAMETER_INDEX}; + for (int r = 0; r < 3; ++r) + { + combiner::Source source = sources[r]; + if (stage == 0 && source == combiner::kSrcPrevious) + source = combiner::kSrcPrimaryColor; // first stage, "previous" the same as "primary" + switch (source) + { + case combiner::kSrcPrimaryColor: + reg[r] = inputNode; + regIndex[r] = 0; + break; + case combiner::kSrcPrevious: + reg[r] = prevNode; + break; + case combiner::kSrcTexture: + reg[r] = texNode; + break; + case combiner::kSrcConstant: + usedConstant |= true; + { + std::string funcName = "LoadConstantColor"; + funcName += ('0'+stage); + hr = flg->CallFunction("", s_Linker.m_Module, funcName.c_str(), ®[r]); + } + break; + default: + AssertString("unknown source"); //reg[r] = "foo"; + } + } + + const char* regSwizzle[3]; + for (int r = 0; r < 3; ++r) + { + regSwizzle[r] = "rgba"; + // 1-x: into tmpN and use that + if (operands[r] == combiner::kOperOneMinusSrcColor || operands[r] == combiner::kOperOneMinusSrcAlpha) + { + NodePtr tmpNode; + hr = flg->CallFunction("", s_Linker.m_Module, "OneMinus4", &tmpNode); + hr = flg->PassValue(reg[r], regIndex[r], tmpNode, 0); + reg[r] = tmpNode; + regIndex[r] = D3D_RETURN_PARAMETER_INDEX; + } + // replicate alpha swizzle? + if (operands[r] == combiner::kOperSrcAlpha || operands[r] == combiner::kOperOneMinusSrcAlpha) + { + regSwizzle[r] = "aaaa"; + } + } + + // combiner op + NodePtr opNode; + hr = flg->CallFunction("", s_Linker.m_Module, k11LinkCombOpNames[op], &opNode); + for (int i = 0; i < k11LinkCompOpArgs[op]; ++i) + hr = flg->PassValueWithSwizzle(reg[i], regIndex[i], regSwizzle[i], opNode, i, "rgba"); + + // scale + if (scale > 1) + { + DebugAssert (scale == 2 || scale == 4); + NodePtr scaleNode; + hr = flg->CallFunction("", s_Linker.m_Module, scale == 2 ? "Scale2" : "Scale4", &scaleNode); + hr = flg->PassValue(opNode, D3D_RETURN_PARAMETER_INDEX, scaleNode, 0); + opNode = scaleNode; + } + + outNewNode = opNode; + return usedConstant; +} + + +void* BuildFragmentShaderD3D11_Link (const FixedFunctionStateD3D11& state, FixedFunctionProgramD3D11::ValueParameters& params, size_t& outSize) +{ + ShaderLab::FastPropertyName cbName; cbName.SetName(kD3D11PixelCB); + GetD3D11ConstantBuffers(GetRealGfxDevice()).SetCBInfo (cbName.index, k11PixelSize*16); + params.m_CBID = cbName.index; params.m_CBSize = k11PixelSize*16; + + HRESULT hr = S_OK; + const bool hasLinker = HasD3D11Linker(); + Assert(hasLinker); + + FLGPtr flg; + s_Linker.createFunctionLinkingGraphFunc (0, &flg); + + LinkerPtr linker; + hr = s_Linker.createLinkerFunc(&linker); + + // ---- Figure out input signature ---------------------------------------- + + D3D11_PARAMETER_DESC inputSig[kMaxSignatureParams]; + int inputRegCounter = 0; + int inColorReg = 0, inSpecReg = 0, inFogReg = 0; + int inUVReg[kMaxSupportedTextureCoords] = {0}; + static const char* kUVNames[kMaxSupportedTextureCoords] = {"uv0","uv1","uv2","uv3","uv4","uv5","uv6","uv7"}; + static const char* kUVSemantics[kMaxSupportedTextureCoords] = {"TEXCOORD0","TEXCOORD1","TEXCOORD2","TEXCOORD3","TEXCOORD4","TEXCOORD5","TEXCOORD6","TEXCOORD7"}; + + inputSig[inColorReg = inputRegCounter++] = CreateParamDesc("icolor", "COLOR0", 4); + if (state.lightingEnabled && state.specularEnabled) + inputSig[inSpecReg = inputRegCounter++] = CreateParamDesc("ispec", "COLOR1", 3); + for (int i = 0; i < state.texUnitCount; i++) + inputSig[inUVReg[i] = inputRegCounter++] = CreateParamDesc(kUVNames[i], kUVSemantics[i], 4); + if (state.fogMode != kFogDisabled && inputRegCounter < 8) + inputSig[inFogReg = inputRegCounter++] = CreateParamDesc("ifog", "FOG0", 1); + + NodePtr inputNode; + Assert(inputRegCounter <= kMaxSignatureParams); + hr = flg->SetInputSignature(inputSig, inputRegCounter, &inputNode); + + + // ---- Figure out output signature --------------------------------------- + + D3D11_PARAMETER_DESC outputSig[kMaxSignatureParams]; + int outputRegCounter = 0; + int outColorReg = 0; + + outputSig[outColorReg = outputRegCounter++] = CreateParamDesc("ocolor", "SV_Target", 4); + + + // ---- Build code -------------------------------------------------------- + + NodePtr colorNode; + + if (state.texUnitCount == 0) + { + // No combiners is special case: output primary color + flg->CallFunction("", s_Linker.m_Module, "LoadVertexColor", &colorNode); + flg->PassValue(inputNode, inColorReg, colorNode, 0); + } + else + { + for (int i = 0; i < state.texUnitCount; i++) + { + std::string funcName = "LoadTex"; + funcName += ('0'+i); + + // type: 0 - 2d, 1 - 2d proj, 2 - 3d, 3 - cube + int type = 0; + if (state.texUnit3D & (1<<i)) + type = 2; + else if (state.texUnitCube & (1<<i)) + type = 3; + else if (state.texUnitProjected & (1<<i)) + type = 1; + + // Sampling modules are layed out by InternalShader/CompileShaderLib/CompileShaderLib.cpp + int samplingModule = 8 * type + i; + + hr = linker->UseLibrary(s_Linker.m_SamplingModuleInstances[samplingModule]); + AssertIf(FAILED(hr)); + + NodePtr texNode; + hr = flg->CallFunction("", s_Linker.m_SamplingModules[samplingModule], funcName.c_str(), &texNode); + AssertIf(FAILED(hr)); + hr = flg->PassValue(inputNode, inUVReg[i], texNode, 0); + AssertIf(FAILED(hr)); + + // emit color & alpha combiners + NodePtr newColorNode; + UInt32 colorComb = state.texUnitColorCombiner[i]; + UInt32 alphaComb = state.texUnitAlphaCombiner[i]; + bool usedConstant = false; + if (colorComb == alphaComb) + { + usedConstant |= EmitCombinerMath11Link (i, colorComb, kCombWriteRGBA, state.texUnitCount, flg, inputNode, colorNode, texNode, newColorNode); + } + else + { + usedConstant |= EmitCombinerMath11Link (i, colorComb, kCombWriteRGB, state.texUnitCount, flg, inputNode, colorNode, texNode, newColorNode); + NodePtr newAlphaNode; + usedConstant |= EmitCombinerMath11Link (i, alphaComb, kCombWriteA, state.texUnitCount, flg, inputNode, colorNode, texNode, newAlphaNode); + if (newAlphaNode) + { + NodePtr combinedNode; + flg->CallFunction("", s_Linker.m_Module, "CombineAlpha", &combinedNode); + flg->PassValue(newColorNode, D3D_RETURN_PARAMETER_INDEX, combinedNode, 0); + flg->PassValue(newAlphaNode, D3D_RETURN_PARAMETER_INDEX, combinedNode, 1); + newColorNode = combinedNode; + } + } + + if (usedConstant) + params.AddVectorParam ((k11PixelColors+i)*16, 4, BuiltinShaderVectorParam(kShaderVecFFTextureEnvColor0+i)); + + colorNode = newColorNode; + } + } + + if (state.alphaTest != kFuncDisabled && state.alphaTest != kFuncAlways) + { + params.AddVectorParam (k11PixelAlphaRef*16, 1, kShaderVecFFAlphaTestRef); + + static const char* kCmpFunc[] = + { + "", // kFuncDisabled + "AlphaTestNever", // kFuncNever + "AlphaTestLess", // kFuncLess + "AlphaTestEqual", // kFuncEqual + "AlphaTestLEqual", // kFuncLEqual + "AlphaTestGreater", // kFuncGreater + "AlphaTestNotEqual", // kFuncNotEqual + "AlphaTestGEqual", // kFuncGEqual + "", // kFuncAlways + }; + + NodePtr alphaTestNode; + flg->CallFunction("", s_Linker.m_Module, kCmpFunc[state.alphaTest], &alphaTestNode); + flg->PassValue(colorNode, D3D_RETURN_PARAMETER_INDEX, alphaTestNode, 0); + colorNode = alphaTestNode; + } + + // add specular + if (state.lightingEnabled && state.specularEnabled) + { + NodePtr specNode; + flg->CallFunction("", s_Linker.m_Module, "AddSpec", &specNode); + flg->PassValue(colorNode, D3D_RETURN_PARAMETER_INDEX, specNode, 0); + flg->PassValue(inputNode, inSpecReg, specNode, 1); + colorNode = specNode; + } + + // fog + if (state.fogMode != kFogDisabled && inputRegCounter < 8) + { + + params.AddVectorParam (k11PixelFog*16, 4, kShaderVecFFFogColor); + + NodePtr fogNode; + flg->CallFunction("", s_Linker.m_Module, "ApplyFog", &fogNode); + flg->PassValue(colorNode, D3D_RETURN_PARAMETER_INDEX, fogNode, 0); + flg->PassValue(inputNode, inFogReg, fogNode, 1); + colorNode = fogNode; + } + + // ---- final steps + + NodePtr outputNode; + Assert(outputRegCounter <= kMaxSignatureParams); + hr = flg->SetOutputSignature(outputSig, outputRegCounter, &outputNode); + + hr = flg->PassValue(colorNode, D3D_RETURN_PARAMETER_INDEX, outputNode, outColorReg); + + #if 0 + // Print generated hlsl for debugging + BlobPtr hlslOutput; + hr = flg->GenerateHlsl(0, &hlslOutput); + if (SUCCEEDED(hr)) + { + printf_console("DX11 debug linked PS:\n%s\n", hlslOutput->GetBufferPointer()); + } + #endif + + ModuleInstancePtr flgModule; + BlobPtr flgErrors; + hr = flg->CreateModuleInstance(&flgModule, &flgErrors); + if (FAILED(hr)) + { + const char* errorMsg = (const char*)flgErrors->GetBufferPointer(); + printf_console("DX11: Failed to create FF PS module: %s\n", errorMsg); + } + + hr = linker->UseLibrary (s_Linker.m_ModuleInstancePS); + + #if UNITY_WINRT + const char* target = "ps_4_0_level_9_1"; + #else + const char* target = "ps_4_0"; + #endif + + BlobPtr linkedCode; + BlobPtr linkedErrors; + hr = linker->Link(flgModule, "main", target, 0, &linkedCode, &linkedErrors); + if (FAILED(hr)) + { + const char* errorMsg = (const char*)linkedErrors->GetBufferPointer(); + printf_console("\nDX11: Failed to link FF PS: %s\n", errorMsg); + } + + if (!linkedCode) + { + outSize = 0; + return NULL; + } + outSize = linkedCode->GetBufferSize(); + void* finalCode = malloc(outSize); + memcpy (finalCode, linkedCode->GetBufferPointer(), outSize); + return finalCode; +} + +#endif diff --git a/Runtime/GfxDevice/d3d11/ShaderPatchingD3D11.cpp b/Runtime/GfxDevice/d3d11/ShaderPatchingD3D11.cpp new file mode 100644 index 0000000..01d9f69 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/ShaderPatchingD3D11.cpp @@ -0,0 +1,702 @@ +#include "UnityPrefix.h" +#include "ShaderPatchingD3D11.h" +#include "D3D11ByteCode.h" +#include "External/DirectX/builds/dx9include/d3d9.h" + + +#define DEBUG_D3D11_SHADER_PATCHING 0 + + +// Vertex & pixel shaders might have different set of interpolated registers, so hard to adaptively +// pick register that would always fit. So instead always put fog into this register; and in case of +// shaders already using this one, we'll just fail and there will be no fog. +// SM4 has 16 output registers, let's use second-to-last. +const int kFogInterpRegister = 14; + + +// ------------------------------------------------------------------- + +#if DEBUG_D3D11_SHADER_PATCHING +struct D3D10BlobHack +{ + virtual HRESULT WINAPI QueryInterface(const int& iid, void** ppv) = 0; + virtual ULONG WINAPI AddRef() = 0; + virtual ULONG WINAPI Release() = 0; + virtual void* WINAPI GetBufferPointer() = 0; + virtual SIZE_T WINAPI GetBufferSize() = 0; +}; + +typedef HRESULT (WINAPI *D3DDisassembleFunc)(const void* pSrcData, SIZE_T SrcDataSize, UINT Flags, const char* szComments, D3D10BlobHack** ppDisassembly); + +static void DisassembleShader(const char* name, const void* data, size_t size) +{ + static D3DDisassembleFunc func = NULL; + if (!func) + { + HMODULE dll; +#if !UNITY_METRO + dll = LoadLibraryA("d3dcompiler_43.dll"); +#else + dll = LoadPackagedLibrary(L"d3dcompiler_46.dll", 0); // _46.dll is ARM +#endif + if (!dll) + { + printf_console("--- Failed to load d3dcompiler dll - error code: %d", GetLastError()); + return; + } + func = (D3DDisassembleFunc)GetProcAddress(dll,"D3DDisassemble"); + if (!func) + return; + } + D3D10BlobHack* blob = NULL; + HRESULT hr = func(data, size, 0, NULL, &blob); + if (FAILED(hr)) + { + printf_console("Failed to disasm shader!\n"); + } + if (blob) + { + std::string str((const char*)blob->GetBufferPointer(), blob->GetBufferSize()); + printf_console("==== %s:\n%s\n", name, str.c_str()); + blob->Release(); + } +} +#endif // #if DEBUG_D3D11_SHADER_PATCHING + + + +// ------------------------------------------------------------------- + + + +static DXBCChunkSig* AddFogToSignatureChunk (const DXBCChunkSig* in) +{ + // check for max number of registers used + UInt32 maxRegNum = 0; + for (int i = 0; i < in->count; ++i) + maxRegNum = std::max(maxRegNum, in->elements[i].register_num); + if (maxRegNum >= kFogInterpRegister) + return NULL; + + //@TODO: check for FOG already being used? + const char* kFogName = "FOG"; + + // size = header + existing size + one more DXBCSignatureElement + name + unsigned size = sizeof(DXBCChunkHeader) + in->size + sizeof(DXBCSignatureElement); + const unsigned nameOffset = size; + size += strlen(kFogName)+1; + size = (size + 3) & ~3; // align to next dword + + UInt8* buf = (UInt8*)malloc(size); + DXBCChunkSig* chunk = (DXBCChunkSig*)buf; + memset (chunk, 0xAB, size); + chunk->fourcc = in->fourcc; + chunk->size = size - 8; + chunk->count = in->count + 1; + chunk->unk8 = in->unk8; + // copy existing signature elements + memcpy (chunk->elements, in->elements, sizeof(chunk->elements[0]) * in->count); + // move name offsets + for (int i = 0; i < in->count; ++i) + chunk->elements[i].name_offset += sizeof(DXBCSignatureElement); + + // add our signature element + DXBCSignatureElement& el = chunk->elements[in->count]; + el.name_offset = nameOffset - 8; + el.semantic_index = 0; + el.system_value_type = 0; + el.component_type = 3; // float + el.register_num = kFogInterpRegister; + el.mask = 1; + el.read_write_mask = (in->fourcc == kFOURCC_ISGN) ? 1 : (~1 & 0xF); + el.stream = 0; + el.unused = 0; + + // copy old names + const unsigned oldNamesOffset = sizeof(DXBCChunkHeader) + 8 + sizeof(DXBCSignatureElement) * in->count; + const unsigned newNamesOffset = oldNamesOffset + sizeof(DXBCSignatureElement); + memcpy (buf + newNamesOffset, ((const char*)in) + oldNamesOffset, nameOffset - newNamesOffset); + + // add our name + memcpy (buf + nameOffset, kFogName, strlen(kFogName)+1); + + return chunk; +} + + +static bool IsDclOpcode (SM4Opcode op) +{ + return + op >= kSM4Op_DCL_RESOURCE && op <= kSM4Op_DCL_GLOBAL_FLAGS || + op >= kSM4Op_DCL_STREAM && op <= kSM4Op_DCL_RESOURCE_STRUCTURED || + op == kSM4Op_DCL_GS_INSTANCE_COUNT; +} + + +static int FindOutputRegister(const dynamic_array<UInt32>& tokens, bool vertex) +{ + SM4TokInstruction instr; + instr.dword = 0; + for (size_t idx = 0; idx < tokens.size(); idx += instr.length) + { + instr.dword = tokens[idx]; + if (vertex && instr.opcode == kSM4Op_DCL_OUTPUT_SIV && instr.length == 4) + { + UInt32 siv = tokens[idx+3]; + if (siv == 1) // D3D10_NAME_POSITION + return tokens[idx+2]; + } + if (!vertex && instr.opcode == kSM4Op_DCL_OUTPUT && instr.length == 3) + { + //@TODO: what happens when shader writes to both color & depth, in various orderings? + return tokens[idx+2]; + } + } + return -1; +} + + +static size_t FindAfterLastDclPos(const dynamic_array<UInt32>& tokens) +{ + SM4TokInstruction instr; + instr.dword = 0; + size_t afterLastDclPos = 0; + for (size_t idx = 0; idx < tokens.size(); idx += instr.length) + { + instr.dword = tokens[idx]; + if (IsDclOpcode((SM4Opcode)instr.opcode)) + afterLastDclPos = idx + instr.length; + else + break; + } + return afterLastDclPos; +} + + +static int AddTempRegisters(dynamic_array<UInt32>& tokens, int tempsToAdd) +{ + size_t afterLastDclPos = FindAfterLastDclPos(tokens); + + SM4TokInstruction instr; + instr.dword = 0; + for (size_t idx = 0; idx < afterLastDclPos; idx += instr.length) + { + instr.dword = tokens[idx]; + if (instr.opcode == kSM4Op_DCL_TEMPS && instr.length == 2) + { + int tempsCount = tokens[idx+1]; + tokens[idx+1] += tempsToAdd; + return tempsCount; + } + } + + // no temps used, insert dcl_temps after all other declaration statements + SM4TokInstruction tok; + tok.dword = 0; + tok.opcode = kSM4Op_DCL_TEMPS; + tok.length = 2; + tokens.insert(tokens.begin()+(afterLastDclPos++), tok.dword); + tokens.insert(tokens.begin()+(afterLastDclPos++), tempsToAdd); + + return 0; +} + + +static void AddFogRegister(dynamic_array<UInt32>& tokens, bool output) +{ + size_t afterLastDclPos = FindAfterLastDclPos(tokens); + + // add dcl statement for fog register after all other declarations + SM4TokInstruction dcl; + dcl.dword = 0; + dcl.opcode = output ? kSM4Op_DCL_OUTPUT : kSM4Op_DCL_INPUT_PS; + if (dcl.opcode == kSM4Op_DCL_INPUT_PS) + dcl.dcl_input_ps.interpolation = kSM4Interp_LINEAR; + dcl.length = 3; + SM4TokOperand op; + op.dword = 0; + op.comps_enum = kSM4OperComp4; + op.mode = SM4_OPERAND_MODE_MASK; + op.sel = 1; + op.file = output ? kSM4File_OUTPUT : kSM4File_INPUT; + op.num_indices = 1; + op.index0_repr = SM4_OPERAND_INDEX_REPR_IMM32; + + tokens.insert(tokens.begin()+(afterLastDclPos++), dcl.dword); + tokens.insert(tokens.begin()+(afterLastDclPos++), op.dword); + tokens.insert(tokens.begin()+(afterLastDclPos++), kFogInterpRegister); +} + + +static bool AddConstantBufferRegister(dynamic_array<UInt32>& tokens) +{ + size_t afterLastDclPos = FindAfterLastDclPos(tokens); + + // are we already using the needed CB bind point? + SM4TokInstruction instr; + instr.dword = 0; + for (size_t idx = 0; idx < afterLastDclPos; idx += instr.length) + { + instr.dword = tokens[idx]; + if (instr.opcode == kSM4Op_DCL_CONSTANT_BUFFER && instr.length == 4) + if (tokens[idx+2] == k11FogConstantBufferBind) + return false; + } + + // add dcl statement for constant buffer after all other declarations + SM4TokInstruction dcl; + dcl.dword = 0; + dcl.opcode = kSM4Op_DCL_CONSTANT_BUFFER; + dcl.length = 4; + SM4TokOperand op; + op.dword = 0; + op.comps_enum = kSM4OperComp4; + op.file = kSM4File_CONSTANT_BUFFER; + op.num_indices = 2; + + tokens.insert(tokens.begin()+(afterLastDclPos++), dcl.dword); + tokens.insert(tokens.begin()+(afterLastDclPos++), op.dword); + tokens.insert(tokens.begin()+(afterLastDclPos++), k11FogConstantBufferBind); + tokens.insert(tokens.begin()+(afterLastDclPos++), k11FogSize); + + return true; +} + + + +static bool SupportedIndexRepr(SM4OperIndexRepr repr) +{ + return repr == SM4_OPERAND_INDEX_REPR_IMM32 || repr == SM4_OPERAND_INDEX_REPR_REG_IMM32; +} + +static void RemapRegisterToTemp(dynamic_array<UInt32>& tokens, SM4RegFile type, int num, int tempNum) +{ + SM4TokInstruction instr; + instr.dword = 0; + for (size_t idx = 0; idx < tokens.size(); idx += instr.length) + { + instr.dword = tokens[idx]; + if (IsDclOpcode((SM4Opcode)instr.opcode) || instr.opcode == kSM4Op_CUSTOMDATA) + continue; + + size_t idxEnd = idx + instr.length; + + // skip over extended tokens + size_t jj = idx; + SM4TokInstructionEx exttok; + exttok.dword = instr.dword; + while (exttok.extended) + exttok.dword = tokens[++jj]; + Assert(jj < idxEnd); + + // go over operands + while (jj+1 < idxEnd) + { + SM4TokOperand optok; + optok.dword = tokens[++jj]; + size_t opIdx = jj; + if (optok.extended) + ++jj; + + // only remap simple register references: needed file, one simple index + if (optok.file == type && optok.num_indices == 1) + { + if (optok.index0_repr == SM4_OPERAND_INDEX_REPR_IMM32 || optok.index0_repr == SM4_OPERAND_INDEX_REPR_REG_IMM32) + { + if (tokens[jj+1] == num) + { + optok.file = kSM4File_TEMP; + tokens[opIdx] = optok.dword; + tokens[jj+1] = tempNum; + } + } + } + + // skip over data for this operand + if (optok.num_indices >= 1) { + if (!SupportedIndexRepr((SM4OperIndexRepr)optok.index0_repr)) + break; + ++jj; + } + if (optok.num_indices >= 2) { + if (!SupportedIndexRepr((SM4OperIndexRepr)optok.index1_repr)) + break; + ++jj; + } + if (optok.num_indices >= 3) { + if (!SupportedIndexRepr((SM4OperIndexRepr)optok.index2_repr)) + break; + ++jj; + } + if (optok.file == kSM4File_IMMEDIATE32) + ++jj; + if (optok.file == kSM4File_IMMEDIATE64) + jj += 2; + } + } +} + + +static void RemoveRetFromEnd (dynamic_array<UInt32>& tokens) +{ + if (tokens.empty()) + return; + + SM4TokInstruction instr; + instr.dword = tokens.back(); + if (instr.opcode == kSM4Op_RET && instr.length == 1) + tokens.pop_back(); +} + + +static DXBCChunkCode* AddFogToVertexCodeChunk (const DXBCChunkCode* in) +{ + const UInt32* inTokens = (const UInt32*)&in->version; + + dynamic_array<UInt32> newTokens; + newTokens.insert(newTokens.end(), inTokens + 2, inTokens + in->length); // don't add version & length words + + int posRegister = FindOutputRegister (newTokens, true); + if (posRegister < 0) + { + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Fog patch failed: output register not found\n"); + #endif + return NULL; + } + AddFogRegister (newTokens, true); + int tmpRegister = AddTempRegisters (newTokens, 1); + RemapRegisterToTemp (newTokens, kSM4File_OUTPUT, posRegister, tmpRegister); + RemoveRetFromEnd (newTokens); + + DXBCCodeBuilder* codeBuilder = dxb_create_code(newTokens); + DXBCBuilderStream bld(codeBuilder); + bld.op(kSM4Op_MOV).reg('o',posRegister,0xF).swz('r',tmpRegister,kSM4SwzNone); // pos.xyzw = tmp.xyzw + bld.op(kSM4Op_MOV).reg('o',kFogInterpRegister,0x1).swz('r',tmpRegister,kSM4SwzRepZ); // fog.x = tmp.z + bld.op(kSM4Op_RET); + dxb_destroy_code(codeBuilder); + + const unsigned chunkSize = sizeof(DXBCChunkCode) + newTokens.size()*sizeof(newTokens[0]); + UInt8* buf = (UInt8*)malloc(chunkSize); + DXBCChunkCode* chunk = (DXBCChunkCode*)buf; + chunk->fourcc = in->fourcc; + chunk->size = chunkSize - sizeof(DXBCChunkHeader); + chunk->version = inTokens[0]; + chunk->length = newTokens.size() + 2; + memcpy (buf + sizeof(DXBCChunkCode), newTokens.data(), newTokens.size()*sizeof(newTokens[0])); + + return chunk; +} + + +static DXBCChunkCode* AddFogToPixelCodeChunk (const DXBCChunkCode* in, FogMode fogMode) +{ + const UInt32* inTokens = (const UInt32*)&in->version; + + dynamic_array<UInt32> newTokens; + newTokens.insert(newTokens.end(), inTokens + 2, inTokens + in->length); // don't add version & length words + + int colRegister = FindOutputRegister (newTokens, false); + if (colRegister < 0) + { + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Fog patch failed: output register not found\n"); + #endif + return NULL; + } + AddFogRegister (newTokens, false); + if (!AddConstantBufferRegister (newTokens)) + { + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Fog patch failed: can't add constant buffer\n"); + #endif + return NULL; + } + + int tmpReg = AddTempRegisters (newTokens, 2); + const int tmp2 = tmpReg+1; + const UInt32 fogParamsReg = (k11FogConstantBufferBind << 16) | k11FogParams; + const UInt32 fogColorReg = (k11FogConstantBufferBind << 16) | k11FogColor; + + RemapRegisterToTemp (newTokens, kSM4File_OUTPUT, colRegister, tmpReg); + RemoveRetFromEnd (newTokens); + + // add fog handling code + DXBCCodeBuilder* codeBuilder = dxb_create_code(newTokens); + DXBCBuilderStream bld(codeBuilder); + + if (fogMode == kFogExp2) + { + // fog = exp(-(density*z)^2) + bld.op(kSM4Op_MUL).reg('r',tmp2,1).swz('c',fogParamsReg,kSM4SwzRepX).swz('v',kFogInterpRegister,kSM4SwzRepX); // tmp = (density/sqrt(ln(2))) * fog + bld.op(kSM4Op_MUL).reg('r',tmp2,1).swz('r',tmp2,kSM4SwzRepX).swz('r',tmp2,kSM4SwzRepX); // tmp = tmp * tmp + bld.op_sat(kSM4Op_EXP,tmp2).reg('r',tmp2,1).swz('r',tmp2,kSM4SwzRepX,true); // tmp = saturate (exp2 (-tmp)) + } + else if (fogMode == kFogExp) + { + // fog = exp(-density*z) + bld.op(kSM4Op_MUL).reg('r',tmp2,1).swz('c',fogParamsReg,kSM4SwzRepX).swz('v',kFogInterpRegister,kSM4SwzRepX); // tmp = (density/sqrt(ln(2))) * fog + bld.op_sat(kSM4Op_EXP,tmp2).reg('r',tmp2,1).swz('r',tmp2,kSM4SwzRepX,true); // tmp = saturate (exp2 (-tmp)) + } + else if (fogMode == kFogLinear) + { + // fog = (end-z)/(end-start) + // -> tmp = (-1/(end-start)) * fog + (end/(end-start)) + bld.op_sat(kSM4Op_MAD,tmp2).reg('r',tmp2,1).swz('v',kFogInterpRegister,kSM4SwzRepX).swz('c',fogParamsReg,kSM4SwzRepZ).swz('c',fogParamsReg,kSM4SwzRepW); + } + else + { + AssertString("unknown fog mode"); + } + + // color.rgb = lerp (fogColor.rgb, color.rgb, fogVar) = + // (color.rgb-fogColor.rgb) * fogVar + fogColor.rgb + bld.op(kSM4Op_ADD).reg('r',tmpReg,7).swz('r',tmpReg,kSM4SwzXYZX).swz('c',fogColorReg,kSM4SwzXYZX, true); + bld.op(kSM4Op_MAD).reg('r',tmpReg,7).swz('r',tmpReg,kSM4SwzXYZX).swz('r',tmp2,kSM4SwzRepX).swz('c',fogColorReg,kSM4SwzXYZX); + + // move into final output + bld.op(kSM4Op_MOV).reg('o',colRegister,0xF).swz('r',tmpReg,kSM4SwzNone); // col.xyzw = tmp.xyzw + bld.op(kSM4Op_RET); + dxb_destroy_code(codeBuilder); + + const unsigned chunkSize = sizeof(DXBCChunkCode) + newTokens.size()*sizeof(newTokens[0]); + UInt8* buf = (UInt8*)malloc(chunkSize); + DXBCChunkCode* chunk = (DXBCChunkCode*)buf; + chunk->fourcc = in->fourcc; + chunk->size = chunkSize - sizeof(DXBCChunkHeader); + chunk->version = inTokens[0]; + chunk->length = newTokens.size() + 2; + memcpy (buf + sizeof(DXBCChunkCode), newTokens.data(), newTokens.size()*sizeof(newTokens[0])); + + return chunk; +} + + +// ------------------------------------------------------------------- + + +static bool FindShaderChunks (const DXBCContainer* dxbc, int* inputIdx, int* outputIdx, int* codeIdx) +{ + *inputIdx = -1; + *outputIdx = -1; + *codeIdx = -1; + for (int i = 0; i < dxbc->chunks.size(); ++i) + { + DXBCChunkHeader* c = dxbc->chunks[i]; + if (c->fourcc == kFOURCC_ISGN) + *inputIdx = i; + else if (c->fourcc == kFOURCC_OSGN) + *outputIdx = i; + else if (c->fourcc == kFOURCC_SHDR || c->fourcc == kFOURCC_SHEX) + *codeIdx = i; + } + if (*inputIdx < 0 || *outputIdx < 0 || *codeIdx < 0) + return false; + return true; +} + + +// ------------------------------------------------------------------- + + + +bool PatchVertexOrDomainShaderFogD3D11 (dynamic_array<UInt8>& byteCode) +{ + std::auto_ptr<DXBCContainer> dxbc (dxbc_parse (byteCode.data(), byteCode.size())); + if (dxbc.get() == NULL) + return false; + + #if DEBUG_D3D11_SHADER_PATCHING + DisassembleShader ("VS before patching", byteCode.data(), byteCode.size()); + #endif + + int inputIdx, outputIdx, codeIdx; + if (!FindShaderChunks (dxbc.get(), &inputIdx, &outputIdx, &codeIdx)) + { + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Fog patch failed: shader chunks not found?\n"); + #endif + return false; + } + const DXBCChunkSig* inputChunk = (DXBCChunkSig*)dxbc->chunks[inputIdx]; + const DXBCChunkSig* outputChunk = (DXBCChunkSig*)dxbc->chunks[outputIdx]; + const DXBCChunkCode* codeChunk = (DXBCChunkCode*)dxbc->chunks[codeIdx]; + + DXBCChunkSig* newOutputChunk = AddFogToSignatureChunk (outputChunk); + if (!newOutputChunk) + { + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Fog patch failed: can't add fog output signature\n"); + #endif + return false; + } + + DXBCChunkCode* newCodeChunk = AddFogToVertexCodeChunk (codeChunk); + if (!newCodeChunk) + { + free (newOutputChunk); + return false; + } + + dxbc->chunks[outputIdx] = newOutputChunk; + dxbc->chunks[codeIdx] = newCodeChunk; + dynamic_array<UInt8> newByteCode = byteCode; + dxbc_create(dxbc->chunks.data(), dxbc->chunks.size(), newByteCode); + byteCode = newByteCode; + + #if DEBUG_D3D11_SHADER_PATCHING + DisassembleShader ("VS after patching", byteCode.data(), byteCode.size()); + #endif + + free (newOutputChunk); + free (newCodeChunk); + + return true; +} + + +// ------------------------------------------------------------------- + + +bool PatchPixelShaderFogD3D11 (dynamic_array<UInt8>& byteCode, FogMode fog) +{ + std::auto_ptr<DXBCContainer> dxbc (dxbc_parse (byteCode.data(), byteCode.size())); + if (dxbc.get() == NULL) + return false; + + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Patching fog mode %d\n", fog); + DisassembleShader ("PS before patching", byteCode.data(), byteCode.size()); + #endif + + int inputIdx, outputIdx, codeIdx; + if (!FindShaderChunks (dxbc.get(), &inputIdx, &outputIdx, &codeIdx)) + { + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Fog patch failed: shader chunks not found?\n"); + #endif + return false; + } + const DXBCChunkSig* inputChunk = (DXBCChunkSig*)dxbc->chunks[inputIdx]; + const DXBCChunkSig* outputChunk = (DXBCChunkSig*)dxbc->chunks[outputIdx]; + const DXBCChunkCode* codeChunk = (DXBCChunkCode*)dxbc->chunks[codeIdx]; + + DXBCChunkSig* newInputChunk = AddFogToSignatureChunk (inputChunk); + if (!newInputChunk) + { + #if DEBUG_D3D11_SHADER_PATCHING + printf_console("Fog patch failed: can't add fog input signature\n"); + #endif + return false; + } + + DXBCChunkCode* newCodeChunk = AddFogToPixelCodeChunk (codeChunk, fog); + if (!newCodeChunk) + { + free (newInputChunk); + return false; + } + + dxbc->chunks[inputIdx] = newInputChunk; + dxbc->chunks[codeIdx] = newCodeChunk; + + dynamic_array<UInt8> newByteCode = byteCode; + dxbc_create(dxbc->chunks.data(), dxbc->chunks.size(), newByteCode); + byteCode = newByteCode; + + #if DEBUG_D3D11_SHADER_PATCHING + DisassembleShader ("PS after patching", byteCode.data(), byteCode.size()); + #endif + + free (newInputChunk); + free (newCodeChunk); + + return true; +} + + + +bool PatchRemovePartialPrecisionD3D11 (dynamic_array<UInt8>& byteCode) +{ + DXBCChunkSM20* codeChunk = static_cast<DXBCChunkSM20*>(dxbc_find_chunk(byteCode.data(), byteCode.size(), kFOURCC_SM20)); + if (!codeChunk) + return false; + + // Reference for the bytecode format: "Direct3D Shader Codes" on MSDN, + // http://msdn.microsoft.com/en-us/library/windows/hardware/ff552891(v=vs.85).aspx + + #if DEBUG_D3D11_SHADER_PATCHING + dynamic_array<UInt8> origBC = byteCode; + #endif + + const UInt32* codeEnd = (const UInt32*)(((const UInt8*)codeChunk) + sizeof(DXBCChunkHeader) + codeChunk->size); + + // Go past chunk header into chunk content + UInt32* codePtr = (UInt32*)(codeChunk+1); + // Table, ints: version, shader size, code offset + if (codePtr+2 >= codeEnd) + return false; + const UInt32 codeOffset = codePtr[2]; + + // Get to actual byte code start. + // Code offset in the table is from end of DXBCChunkHeader + codePtr = (UInt32*)(((UInt8*)codeChunk) + sizeof(DXBCChunkHeader) + codeOffset); + codePtr++; // skip version token + + // Go over all instructions + bool didChanges = false; + while (codePtr < codeEnd) + { + SM2TokInstruction* insn = (SM2TokInstruction*)codePtr; + const int length = insn->length; + const SM2Opcode op = (SM2Opcode)insn->opcode; + if (op == kSM2Op_DCL) + { + // DCL instructions have special format: destination token is the 2nd token + if (length == 2) + { + SM2TokDst* dst = (SM2TokDst*)(codePtr+2); + if (dst->res_mod & (D3DSPDM_PARTIALPRECISION>>D3DSP_DSTMOD_SHIFT)) + { + dst->res_mod &= ~(D3DSPDM_PARTIALPRECISION>>D3DSP_DSTMOD_SHIFT); + didChanges = true; + } + } + } + else if (op == kSM2Op_DEF || op == kSM2Op_DEFI || op == kSM2Op_DEFB) + { + // DEF* instructions have special format, don't have to do anything + } + else if (op == kSM2Op_CALLNZ || op == D3DSIO_LOOP || op == kSM2Op_IFC || op == kSM2Op_BREAKP || op == kSM2Op_BREAKC) + { + // these instructions don't have destination token + } + else if (length > 1) // must be a more than 2 argument instruction to have a destination token + { + SM2TokDst* dst = (SM2TokDst*)(codePtr+1); + if (dst->res_mod & (D3DSPDM_PARTIALPRECISION>>D3DSP_DSTMOD_SHIFT)) + { + dst->res_mod &= ~(D3DSPDM_PARTIALPRECISION>>D3DSP_DSTMOD_SHIFT); + didChanges = true; + } + } + codePtr += length + 1; + } + + // Update shader checksum if we did changes + if (didChanges && byteCode.size() > 20) + { + void D3DHash (const unsigned char* data, unsigned size, unsigned char res[16]); + UInt8 hsh[16]; + D3DHash (&byteCode[20], byteCode.size()-20, &byteCode[4]); + + #if DEBUG_D3D11_SHADER_PATCHING + DisassembleShader ("Shader before partial precision remove", origBC.data(), origBC.size()); + DisassembleShader ("Shader after partial precision remove", byteCode.data(), byteCode.size()); + #endif + } + + + return true; +} + diff --git a/Runtime/GfxDevice/d3d11/ShaderPatchingD3D11.h b/Runtime/GfxDevice/d3d11/ShaderPatchingD3D11.h new file mode 100644 index 0000000..51b2854 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/ShaderPatchingD3D11.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Utilities/dynamic_array.h" + +enum { + k11FogColor = 0, + k11FogParams = 1, + k11FogSize = 2 +}; + +enum { + // DX11 has 14 constant buffers, and for safety reasons + // let's use 3rd to last one, 11. If that is already + // in use by shader, there will be no fog. + k11FogConstantBufferBind = 11, +}; + +bool PatchVertexOrDomainShaderFogD3D11 (dynamic_array<UInt8>& byteCode); +bool PatchPixelShaderFogD3D11 (dynamic_array<UInt8>& byteCode, FogMode fog); + +bool PatchRemovePartialPrecisionD3D11 (dynamic_array<UInt8>& byteCode); + +bool PatchRemovePartialPrecisionD3D11 (dynamic_array<UInt8>& byteCode); diff --git a/Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.cpp b/Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.cpp new file mode 100644 index 0000000..b1f3bd6 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.cpp @@ -0,0 +1,416 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/d3d11/GfxDeviceD3D11.h" +#include "Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.h" +#include "Runtime/GfxDevice/d3d11/D3D11Context.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/GfxDevice/d3d11/InternalShaders/builtin.h" +#include "Runtime/GfxDevice/d3d11/D3D11VBO.h" +#include "Runtime/Threads/ThreadedStreamBuffer.h" +#include "Runtime/GfxDevice/threaded/ThreadedDeviceStates.h" +#include "Runtime/GfxDevice/threaded/ThreadedVBO.h" + +struct ShaderPair +{ + ID3D11GeometryShader* m_GeometryShader; + ID3D11VertexShader* m_VertexShader; + ID3D11InputLayout* m_InputLayout; +}; + +typedef UInt32 InputSpec; // shaderChannelsMap + (bonesPerVertex << 16) + (maxBonesBits << 19) + +typedef std::map< InputSpec, ShaderPair> StreamOutShaderMap; + +struct SkinningGlobalsD3D11 +{ + SkinningGlobalsD3D11() + : m_BoundSP(0) + , m_OldGS(0) + , m_OldPS(0) + , m_OldVS(0) + , m_OldTopo(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED) + , m_DSState(0) + , m_OldCB(0) + { + } + + StreamOutShaderMap m_ShaderMap; + ShaderPair* m_BoundSP; + ID3D11GeometryShader* m_OldGS; + ID3D11PixelShader* m_OldPS; + ID3D11VertexShader* m_OldVS; + D3D11_PRIMITIVE_TOPOLOGY m_OldTopo; + ID3D11DepthStencilState* m_DSState; + ID3D11Buffer* m_OldCB; +}; +static SkinningGlobalsD3D11 s_SkinningGlobals; + +enum MemExShaderChannel +{ + kMEXC_Position = VERTEX_FORMAT1(Vertex), + kMEXC_Normal = VERTEX_FORMAT1(Normal), + kMEXC_Tangent = VERTEX_FORMAT1(Tangent), +}; + +void StreamOutSkinningInfo::CleanUp() +{ + StreamOutShaderMap::iterator it; + for (it = s_SkinningGlobals.m_ShaderMap.begin(); it != s_SkinningGlobals.m_ShaderMap.end(); ++it) + { + if (it->second.m_GeometryShader) + { + ULONG refCount = it->second.m_GeometryShader->Release(); + AssertIf(refCount != 0); + } + if (it->second.m_VertexShader) + { + ULONG refCount = it->second.m_VertexShader->Release(); + AssertIf(refCount != 0); + } + } + s_SkinningGlobals.m_ShaderMap.clear(); + + s_SkinningGlobals.m_BoundSP = NULL; + SAFE_RELEASE(s_SkinningGlobals.m_OldVS); + SAFE_RELEASE(s_SkinningGlobals.m_OldGS); + SAFE_RELEASE(s_SkinningGlobals.m_OldPS); + SAFE_RELEASE(s_SkinningGlobals.m_OldCB); + s_SkinningGlobals.m_OldTopo = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; + + SAFE_RELEASE(s_SkinningGlobals.m_DSState); +} + +static UInt32 roundUpToNextPowerOf2(UInt32 in) +{ + // Round up to nearest power of 2 + // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 + in--; + in |= in >> 1; + in |= in >> 2; + in |= in >> 4; + in |= in >> 8; + in |= in >> 16; + in++; + return in; +} +// Get the bones bit index based on bone count. Assumes bonecount is power of 2 +static int getBonesBits(UInt32 boneCount) +{ + // Calculate ln2 + // http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn + + static const int MultiplyDeBruijnBitPosition2[32] = + { + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, + 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 + }; + UInt32 res = MultiplyDeBruijnBitPosition2[(UInt32)(boneCount * 0x077CB531U) >> 27]; + + if(res < 5) // Minimum size is 32 (= 0) + return 0; + + return res-5; // Adjust so that 32 = 0, 64 = 1 etc. +} + + +// maxBonesBits == Max bone count: 0 = 32, 1 = 64, etc until 5 = 1024 + +static const BYTE* GetMemExShaderCode(UInt32 shaderChannelsMap, int bonesPerVertex, UInt32 maxBonesBits, UInt32& bytecodeSize) +{ + int channelIdx = 0; + switch(shaderChannelsMap) + { + case kMEXC_Position: channelIdx = 0; break; + case kMEXC_Position|kMEXC_Normal: channelIdx = 1; break; + case kMEXC_Position|kMEXC_Normal|kMEXC_Tangent: channelIdx = 2; break; + case kMEXC_Position|kMEXC_Tangent: channelIdx = 3; break; + default: + Assert(0 && "Unsupported vertex format for GPU skinning."); + bytecodeSize = 0; + return 0; + }; + + if(maxBonesBits > 5) + maxBonesBits = 5; // TODO: Alert of too many bones per vertex + + // Adjust bonespervertex to dense array (1, 2, 4 => 0, 1, 2) + if(bonesPerVertex == 4) + bonesPerVertex--; + bonesPerVertex--; + + bytecodeSize = g_StreamOutShaderSizes[channelIdx][maxBonesBits][bonesPerVertex]; + return g_StreamOutShaders[channelIdx][maxBonesBits][bonesPerVertex]; +} + +static ShaderPair* GetMemExShader(UInt32 shaderChannelsMap, UInt32 bonesPerVertex, UInt32 maxBonesBits) +{ + // Already have vertex shader for this format? + InputSpec is = shaderChannelsMap + (bonesPerVertex << 16) + (maxBonesBits << 19); + + StreamOutShaderMap::iterator it = s_SkinningGlobals.m_ShaderMap.find(is); + if (it != s_SkinningGlobals.m_ShaderMap.end()) + return &it->second; + + UInt32 codeSize = 0; + const BYTE* code = GetMemExShaderCode(shaderChannelsMap, bonesPerVertex, maxBonesBits, codeSize); + if (!code) + return NULL; + + D3D11_SO_DECLARATION_ENTRY entries[16] = {0}; + D3D11_SO_DECLARATION_ENTRY* entry = entries; + + + entry->SemanticName = "POSITION"; + entry->SemanticIndex = 0; + entry->StartComponent = 0; + entry->ComponentCount = 3; + entry->OutputSlot = 0; + entry++; + + UINT soStride = sizeof(float) * 3; + UInt32 semanticIndex = 0; + + if(shaderChannelsMap & kMEXC_Normal) + { + entry->SemanticName = "TEXCOORD"; + entry->SemanticIndex = semanticIndex++; + entry->StartComponent = 0; + entry->ComponentCount = 3; + entry->OutputSlot = 0; + entry++; + + soStride += 3 * sizeof(float); + } + + if(shaderChannelsMap & kMEXC_Tangent) + { + entry->SemanticName = "TEXCOORD"; + entry->SemanticIndex = semanticIndex++; + entry->StartComponent = 0; + entry->ComponentCount = 4; + entry->OutputSlot = 0; + entry++; + + soStride += 4 * sizeof(float); + } + + ShaderPair sp; + GetD3D11Device()->CreateVertexShader( + code, + codeSize, + 0, &sp.m_VertexShader); + + const DX11FeatureLevel fl = gGraphicsCaps.d3d11.featureLevel; + + GetD3D11Device()->CreateGeometryShaderWithStreamOutput( + code, + codeSize, + entries, + (entry-entries), + &soStride, + 1, + (fl >= kDX11Level11_0) ? D3D11_SO_NO_RASTERIZED_STREAM : 0, + 0, + &sp.m_GeometryShader); + + sp.m_InputLayout = GetD3D11GfxDevice().GetVertexDecls().GetVertexDecl(shaderChannelsMap, (void*)code, codeSize, true, bonesPerVertex); + + s_SkinningGlobals.m_ShaderMap.insert(std::make_pair(is, sp)); + + return &s_SkinningGlobals.m_ShaderMap.find( is )->second; +} + +// Note: we might not support all formats all the time. +static bool DoesVertexFormatQualifyForMemExport(UInt32 shaderChannelsMap) +{ + // 1. Channel filter + UInt32 unsupported = ~(kMEXC_Position | kMEXC_Normal | kMEXC_Tangent); // TODO: support more channels + //UInt32 unsupported = ~(kMEXC_Position | kMEXC_Normal | kMEXC_Color | kMEXC_UV0 | kMEXC_UV1 | kMEXC_Tangent); + bool qualify = ((shaderChannelsMap & unsupported) == 0); + // 3. Must have position + qualify &= (shaderChannelsMap & kMEXC_Position) != 0; + + return qualify; + +} + +void StreamOutSkinningInfo::SkinMesh(bool last) +{ +// Assert(DoesVertexFormatQualifyForMemExport(info.channelMap)); + if (!DoesVertexFormatQualifyForMemExport(GetChannelMap())) + return; + + // Get the vertex shader + //... + ShaderPair* sp = GetMemExShader(GetChannelMap(), GetBonesPerVertex(), getBonesBits(m_BoneCount)); + + UINT offsets[] = {0}; + D3D11VBO* vbo = (D3D11VBO*)GetDestVBO(); + vbo->BindToStreamOutput(); + + ID3D11DeviceContext* ctx = GetD3D11Context(); + + if (s_SkinningGlobals.m_BoundSP == 0) + { + ctx->VSGetShader( &s_SkinningGlobals.m_OldVS, 0, 0 ); + ctx->GSGetShader( &s_SkinningGlobals.m_OldGS, 0, 0 ); + ctx->PSGetShader( &s_SkinningGlobals.m_OldPS, 0, 0 ); + ctx->IAGetPrimitiveTopology(&s_SkinningGlobals.m_OldTopo); + ctx->VSGetConstantBuffers(0, 1, &s_SkinningGlobals.m_OldCB); + } + + if (s_SkinningGlobals.m_BoundSP != sp) + { + ctx->VSSetShader( sp->m_VertexShader, 0, 0 ); + ctx->GSSetShader( sp->m_GeometryShader, 0, 0 ); + ctx->PSSetShader( 0, 0, 0 ); + s_SkinningGlobals.m_BoundSP = sp; + } + ID3D11Buffer* const cbs[] = { m_SourceBones }; + ctx->VSSetConstantBuffers(0, 1, cbs); + + UInt32 skinStride = 4; // For 1 bone, just the index + if(GetBonesPerVertex() == 2) + skinStride *= 4; // 2 indices, 2 weights + else if(GetBonesPerVertex() == 4) + skinStride *= 8; + + ID3D11Buffer* const vsStreams[] = { m_SourceVBO, m_SourceSkin }; + const UINT streamStrides[]={ GetStride(), skinStride }; + const UINT streamOffsets[] = { 0,0 }; + + ctx->IASetVertexBuffers(0, 2, vsStreams, streamStrides, streamOffsets); + + // Call our own wrapper for DX11 input layout that does redundant layout change + // tracking. + extern void SetInputLayoutD3D11 (ID3D11DeviceContext* ctx, ID3D11InputLayout* layout); + SetInputLayoutD3D11(ctx, sp->m_InputLayout); + + if (s_SkinningGlobals.m_DSState == 0) + { + D3D11_DEPTH_STENCIL_DESC dsstatedesc = CD3D11_DEPTH_STENCIL_DESC(CD3D11_DEFAULT()); + dsstatedesc.DepthEnable = FALSE; + dsstatedesc.StencilEnable = FALSE; + GetD3D11Device()->CreateDepthStencilState(&dsstatedesc, &s_SkinningGlobals.m_DSState); + } + + ID3D11DepthStencilState* bdsstate = 0; + UINT bref; + ctx->OMGetDepthStencilState(&bdsstate, &bref); + ctx->OMSetDepthStencilState(s_SkinningGlobals.m_DSState, 0); + + ctx->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST ); + ctx->Draw(GetVertexCount(), 0); + + ctx->OMSetDepthStencilState(bdsstate, bref); + SAFE_RELEASE(bdsstate); + + if ( last ) + { + ctx->VSSetShader( s_SkinningGlobals.m_OldVS, 0, 0 ); + ctx->GSSetShader( s_SkinningGlobals.m_OldGS, 0, 0 ); + ctx->PSSetShader( s_SkinningGlobals.m_OldPS, 0, 0 ); + ctx->IASetPrimitiveTopology(s_SkinningGlobals.m_OldTopo); + ctx->VSSetConstantBuffers( 0, 1, &s_SkinningGlobals.m_OldCB ); + SAFE_RELEASE(s_SkinningGlobals.m_OldVS); + SAFE_RELEASE(s_SkinningGlobals.m_OldGS); + SAFE_RELEASE(s_SkinningGlobals.m_OldPS); + SAFE_RELEASE(s_SkinningGlobals.m_OldCB); + s_SkinningGlobals.m_BoundSP = 0; + } + vbo->UnbindFromStreamOutput(); + //TODO +} + +// ---------------------------------------------------------------------------- +static ID3D11Buffer* UpdateStaticVBO(ID3D11Buffer* vbo, const size_t size, const void* data, bool dirty) +{ + D3D11_BUFFER_DESC desc = CD3D11_BUFFER_DESC(size, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); + + if (!vbo) + { + GetD3D11Device()->CreateBuffer(&desc, 0, &vbo); + dirty = true; + } + else + { + D3D11_BUFFER_DESC curDesc; + vbo->GetDesc(&curDesc); + if (curDesc.ByteWidth != size) + { + vbo->Release(); + GetD3D11Device()->CreateBuffer(&desc, 0, &vbo); + dirty = true; + } + } + + if (dirty) + { + D3D11_MAPPED_SUBRESOURCE map; + GetD3D11Context()->Map(vbo, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); + memcpy(map.pData, data, size); + GetD3D11Context()->Unmap(vbo, 0); + } + + return vbo; +} + +StreamOutSkinningInfo::~StreamOutSkinningInfo() +{ + if(m_SourceSkin) + m_SourceSkin->Release(); + if(m_SourceVBO) + m_SourceVBO->Release(); + if(m_SourceBones) + m_SourceBones->Release(); +} + +void StreamOutSkinningInfo::UpdateSourceData(const void *vertData, const BoneInfluence *skinData, bool dirty) +{ + // If only one bone, it's just one int per vertex + UINT32 skinSize = GetVertexCount() * sizeof(UInt32); + if(GetBonesPerVertex() == 2) + skinSize *= 4; // 2 weights, 2 indices + else if(GetBonesPerVertex() == 4) + skinSize *= 8; // 4 weights, 4 indices + + m_SourceVBO = UpdateStaticVBO(m_SourceVBO, GetVertexCount() * GetStride(), vertData, dirty); + m_SourceSkin = UpdateStaticVBO(m_SourceSkin, skinSize, skinData, dirty); +} + + +void StreamOutSkinningInfo::UpdateSourceBones(const int boneCount, const Matrix4x4f* cachedPose) +{ + Assert(boneCount > 0); + + UInt32 uBoneCount = std::min(1024, boneCount); + uBoneCount = std::max(32, boneCount); // Clamp to 32 - 1024, as that's what our shaders expect. + + if (m_BoneCount < roundUpToNextPowerOf2(uBoneCount) && m_SourceBones) + { + // Bone count changed, resize the bone constant buffer + m_SourceBones->Release(); + m_SourceBones = NULL; + } + m_BoneCount = roundUpToNextPowerOf2(uBoneCount); + + if (!m_SourceBones) + { + const UInt32 bufSize = m_BoneCount * 48; // Must match the max bone count in internalshaders.hlsl + D3D11_BUFFER_DESC desc = CD3D11_BUFFER_DESC(bufSize, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); + GetD3D11Device()->CreateBuffer(&desc, 0, &m_SourceBones); + } + + D3D11_MAPPED_SUBRESOURCE map; + GetD3D11Context()->Map(m_SourceBones, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); + UInt8* dest = (UInt8*)map.pData; + + for (int i = 0; i < uBoneCount; ++i) + { + Matrix4x4f mat = cachedPose[i]; + mat.Transpose(); + memcpy(dest + i * 48, &mat, 48); + } + + GetD3D11Context()->Unmap(m_SourceBones, 0); +} + diff --git a/Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.h b/Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.h new file mode 100644 index 0000000..7d95232 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/StreamOutSkinnedMesh.h @@ -0,0 +1,42 @@ +#ifndef __STREAMOUTSKINNEDMESH_H__ +#define __STREAMOUTSKINNEDMESH_H__ + +#include "External/DirectX/builds/dx11include/d3d11.h" +#include "Runtime/GfxDevice/GPUSkinningInfo.h" +class VBO; +class Matrix4x4f; +class ThreadedStreamBuffer; +class GfxDeviceD3D11; + +// MemExport mesh skinning data. +class StreamOutSkinningInfo : public GPUSkinningInfo +{ + friend class GfxDeviceD3D11; +private: + ID3D11Buffer* m_SourceVBO; + ID3D11Buffer* m_SourceSkin; + ID3D11Buffer* m_SourceBones; + + //! Stores the bone count from the previous call to UpdateSourceBones. Used to select the most suitable shader version. + int m_BoneCount; + + // Private constructor and destructor , called from GfxDeviceD3D11 + StreamOutSkinningInfo() : GPUSkinningInfo(), m_SourceVBO(NULL), m_SourceSkin(NULL), m_SourceBones(NULL) {} + virtual ~StreamOutSkinningInfo(); + + + // Actual implementation methods, called from GfxDeviceD3D11 + + void UpdateSourceData(const void *vertData, const BoneInfluence *skinData, bool dirty); + void UpdateSourceBones(const int boneCount, const Matrix4x4f* cachedPose); + void SkinMesh(bool last); + +public: + + //! Clean up created shaders + static void CleanUp(); + +}; + + +#endif diff --git a/Runtime/GfxDevice/d3d11/TexturesD3D11.cpp b/Runtime/GfxDevice/d3d11/TexturesD3D11.cpp new file mode 100644 index 0000000..12f61b0 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/TexturesD3D11.cpp @@ -0,0 +1,1067 @@ +#include "UnityPrefix.h" +#include "TexturesD3D11.h" +#include "D3D11Context.h" +#include "D3D11Utils.h" +#include "Runtime/Allocator/FixedSizeAllocator.h" +#include "Runtime/Graphics/TextureFormat.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/GfxDevice/TextureUploadUtils.h" +#include "Runtime/GfxDevice/TextureIdMap.h" +#include "Runtime/Utilities/BitUtility.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Graphics/Texture2D.h" +#include "External/ProphecySDK/include/prcore/Surface.hpp" +#include "Runtime/Utilities/InitializeAndCleanup.h" + + +//#define ENABLE_OLD_TEXTURE_UPLOAD UNITY_WINRT +#define ENABLE_OLD_TEXTURE_UPLOAD 0 + +typedef FixedSizeAllocator<sizeof(TexturesD3D11::D3D11Texture)> TextureAllocator; +static TextureAllocator* _TextureAlloc = NULL; + +namespace TextureD3D11Alloc +{ + void StaticInitialize() + { + _TextureAlloc = UNITY_NEW_AS_ROOT(TextureAllocator(kMemGfxDevice),kMemGfxDevice, "TextureStructs", ""); + } + + void StaticDestroy() + { + UNITY_DELETE(_TextureAlloc, kMemGfxDevice); + } +} + +static RegisterRuntimeInitializeAndCleanup s_TextureAllocManagerCallbacks(TextureD3D11Alloc::StaticInitialize, TextureD3D11Alloc::StaticDestroy); + +static inline intptr_t AllocD3DTexture(ID3D11Resource* tex, ID3D11ShaderResourceView* srv, ID3D11UnorderedAccessView* uav, bool shadowMap) +{ + return (intptr_t)(new (_TextureAlloc->alloc()) TexturesD3D11::D3D11Texture(tex, srv, uav, shadowMap)); +} + +static inline TexturesD3D11::D3D11Texture* QueryD3DTexture(TextureID textureID) +{ + return (TexturesD3D11::D3D11Texture*)TextureIdMap::QueryNativeTexture(textureID); +} + + +static void SwizzleToRGBA (const UInt8* src, UInt8* dst, int width, int height, int dstPitch, TextureFormat format) +{ + if (format == kTexFormatAlphaLum16) + { + // Handle AlphaLum16 case. ProphecySDK does not support 16 bit/channel formats, + // so we blit manually. + UInt32 rowBytes = GetRowBytesFromWidthAndFormat(width,kTexFormatAlphaLum16); + const UInt8* srcRowData = src; + UInt8* destRowData = dst; + for( int r = 0; r < height; ++r ) + { + for( int c = 0; c < width; ++c ) + { + DWORD val = srcRowData[c*2+1]; + ((DWORD*)destRowData)[c] = 0xFF000000 | (val<<16) | (val<<8) | (val); + } + srcRowData += rowBytes; + destRowData += dstPitch; + } + } + else + { + prcore::Surface srcSurface (width, height, GetRowBytesFromWidthAndFormat(width,format), GetProphecyPixelFormat(format), (void*)src); + prcore::Surface dstSurface (width, height, dstPitch, prcore::PixelFormat(32,0x000000ff,0x0000ff00,0x00ff0000,0xff000000), dst); + dstSurface.BlitImage (srcSurface, prcore::Surface::BLIT_COPY); + } +} + + +struct FormatDesc11 { + TextureFormat unityformat; + DXGI_FORMAT d3dformat; + DXGI_FORMAT sRGBD3dformat; +}; + +const static FormatDesc11 kTextureFormatTable[kTexFormatPCCount+1] = +{ + { kTexFormatPCCount, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, + { kTexFormatAlpha8, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM }, // Alpha8 + { kTexFormatARGB4444, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // ARGB4444 + { kTexFormatRGB24, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGB24 + { kTexFormatRGBA32, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA32 + { kTexFormatARGB32, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // ARGB32 + { kTexFormatARGBFloat, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ARGBFloat + { kTexFormatRGB565, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGB565 + { kTexFormatBGR24, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // BGR24 + { kTexFormatAlphaLum16, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16_UNORM }, // AlphaLum16 + { kTexFormatDXT1, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB }, // DXT1 + { kTexFormatDXT3, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM_SRGB }, // DXT3 + { kTexFormatDXT5, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM_SRGB }, // DXT5 + { kTexFormatRGBA4444, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA4444 +}; + + +const static FormatDesc11 kTextureFormatA8Workaround = + { kTexFormatAlpha8, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM }; +const static FormatDesc11 kTextureFormatR16Workaround = + { kTexFormatAlphaLum16, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM }; +const static FormatDesc11 kTextureFormatBGRA32Workaround = + { kTexFormatBGRA32, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM }; + + +static const FormatDesc11& GetUploadFormat (TextureFormat inFormat) +{ + // 9.1 doesn't support A8 at all; other 9.x levels only support without mipmaps. + // To simplify things we just always expand to R8G8B8A8 on 9.x. + if (gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0 && inFormat == kTexFormatAlpha8) + return kTextureFormatA8Workaround; + + // 9.1 doesn't support R16 for AlphaLum16, so expand + if (gGraphicsCaps.d3d11.featureLevel <= kDX11Level9_1 && inFormat == kTexFormatAlphaLum16) + return kTextureFormatR16Workaround; + + // kTexFormatBGRA32 is one of those "esoteric" formats that is widely used for webcam textures + if (inFormat == kTexFormatBGRA32) + return kTextureFormatBGRA32Workaround; + + return kTextureFormatTable[inFormat]; +} + +TexturesD3D11::TexturesD3D11() +{ + InvalidateSamplers(); +} + +TexturesD3D11::~TexturesD3D11() +{ + #if !UNITY_EDITOR + Assert(m_ComputeBuffers.empty()); + Assert(m_StagingTextures.empty()); + #endif +} + +void TexturesD3D11::TextureFromShaderResourceView(ID3D11ShaderResourceView* resourceView, ID3D11Texture2D** texture) const +{ + ID3D11Resource* resource = NULL; + resourceView->GetResource(&resource); + Assert(resource && "ID3D11Resource is NULL"); + resource->Release(); // GetResource() calls AddRef() + D3D11_RESOURCE_DIMENSION rType; + resource->GetType(&rType); + Assert(rType == D3D11_RESOURCE_DIMENSION_TEXTURE2D && "ID3D11Resource is not Texture2D"); + resource->QueryInterface(texture); + Assert(texture && "Texture is NULL"); + (*texture)->Release(); // QueryInterface() calls AddRef() +} + +intptr_t TexturesD3D11::RegisterNativeTexture(ID3D11ShaderResourceView* resourceView) const +{ + ID3D11Texture2D* texture = NULL; + TextureFromShaderResourceView(resourceView, &texture); + return AllocD3DTexture(texture, resourceView, 0, false); +} + +void TexturesD3D11::UpdateNativeTexture(TextureID textureID, ID3D11ShaderResourceView* resourceView) +{ + ID3D11Texture2D* texture = NULL; + TextureFromShaderResourceView(resourceView, &texture); + D3D11Texture* target = QueryD3DTexture(textureID); + if(target) + { + target->m_Texture = texture; + target->m_SRV = resourceView; + } + else + AddTexture(textureID, texture, resourceView, 0, false); +} + +void TexturesD3D11::AddTexture (TextureID textureID, ID3D11Resource* texture, ID3D11ShaderResourceView* srv, ID3D11UnorderedAccessView* uav, bool shadowMap) +{ + TextureIdMap::UpdateTexture(textureID, AllocD3DTexture(texture,srv,uav,shadowMap)); +} + +void TexturesD3D11::RemoveTexture( TextureID textureID ) +{ + D3D11Texture* target = QueryD3DTexture(textureID); + if(target) + { + target->~D3D11Texture(); + _TextureAlloc->free(target); + } + TextureIdMap::RemoveTexture(textureID); +} + +TexturesD3D11::D3D11Texture* TexturesD3D11::GetTexture (TextureID textureID) +{ + return QueryD3DTexture(textureID); +} + +void TexturesD3D11::AddComputeBuffer (ComputeBufferID id, const ComputeBuffer11& buf) +{ + m_ComputeBuffers.insert (std::make_pair(id, buf)); +} + +void TexturesD3D11::RemoveComputeBuffer (ComputeBufferID id) +{ + m_ComputeBuffers.erase (id); +} + + +ComputeBuffer11* TexturesD3D11::GetComputeBuffer (ComputeBufferID id) +{ + ComputeBufferMap::iterator it = m_ComputeBuffers.find(id); + return it==m_ComputeBuffers.end() ? NULL : &it->second; +} + + +void TexturesD3D11::Upload2DData (const UInt8* dataPtr, TextureFormat dataFormat, int width, int height, bool decompressData, ID3D11Resource* dst, DXGI_FORMAT dstFormat, bool bgra, int dstSubResource) +{ + DX11_LOG_ENTER_FUNCTION("TexturesD3D11::Upload2DData (0x%08x, %d, %d, %d, %s, 0x%08x, %d, %d)", + dataPtr, dataFormat, width, height, GetDX11BoolString(decompressData), dst, dstFormat, dstSubResource); + + if (bgra) + { + if (dstFormat == DXGI_FORMAT_R8G8B8A8_UNORM) + dstFormat = DXGI_FORMAT_B8G8R8A8_UNORM; + else if (dstFormat == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) + dstFormat = DXGI_FORMAT_B8G8R8A8_UNORM_SRGB; + } + + HRESULT hr; + + bool isDXT = false; + int texWidth = width; + int texHeight = height; + int texMips = 1; + if (!decompressData && IsCompressedDXTTextureFormat(dataFormat)) + { + isDXT = true; + while (texWidth < 4 || texHeight < 4) + { + texWidth *= 2; + texHeight *= 2; + ++texMips; + } + } + + // find or create a staging texture of needed size & format + UInt64 stagingKey = (UInt64(width) << kStagingWidthShift) | (UInt64(height) << kStagingHeightShift) | (UInt64(dstFormat) << kStagingFormatShift); + StagingTextureMap::iterator it = m_StagingTextures.find (stagingKey); + if (it == m_StagingTextures.end()) + { + D3D11_TEXTURE2D_DESC desc; + desc.Width = texWidth; + desc.Height = texHeight; + desc.MipLevels = texMips; + desc.ArraySize = 1; + desc.Format = dstFormat; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.Usage = D3D11_USAGE_STAGING; + desc.BindFlags = 0; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = 0; + + ID3D11Device* dev = GetD3D11Device(); + ID3D11Texture2D* texture = NULL; + hr = dev->CreateTexture2D (&desc, NULL, &texture); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to create staging 2D texture w=%i h=%i d3dfmt=%i [%x]\n", width, height, dstFormat, hr); + return; + } + SetDebugNameD3D11 (texture, Format("Staging-Texture2D-%dx%d-fmt%d", width, height, dstFormat)); + + it = m_StagingTextures.insert (std::make_pair(stagingKey, texture)).first; + } + + // copy/convert source data into the staging texture + const int stagingSubresource = texMips-1; + ID3D11DeviceContext* ctx = GetD3D11Context(); + D3D11_MAPPED_SUBRESOURCE mapped; + hr = ctx->Map(it->second, stagingSubresource, D3D11_MAP_WRITE, 0, &mapped); + if (FAILED(hr)) + { + printf_console ("d3d11: failed to map staging 2D texture w=%i h=%i d3dfmt=%i [%x]\n", width, height, dstFormat, hr); + return; + } + + ///@TODO: more format conversions? + if (decompressData) + { + //int tmpWidth = std::max(width,4); + int tmpHeight = std::max(height,4); + DecompressNativeTextureFormatWithMipLevel (dataFormat, width, height, 0 /*TODO*/, (const UInt32*)dataPtr, mapped.RowPitch/4, tmpHeight, (UInt32*)mapped.pData); + //PerformUploadConversions (width, height, rgba, tempBufferPitch, usageMode, colorSpace, GetProphecyPixelFormat(kTexFormatRGBA32)); //@TODO? + } + else if (dstFormat == DXGI_FORMAT_R8G8B8A8_UNORM || dstFormat == DXGI_FORMAT_B8G8R8A8_UNORM) + { + SwizzleToRGBA (dataPtr, (UInt8*)mapped.pData, width, height, mapped.RowPitch, dataFormat); + } + else + { + size_t dataSize = CalculateImageSize(width,height,dataFormat); + const int minSize = isDXT ? 4 : 1; + int mipWidth = std::max(texWidth >> stagingSubresource, minSize); + int mipHeight = std::max(texHeight >> stagingSubresource, minSize); + size_t mappedSize = mapped.RowPitch * mipHeight; + // pitch for compressed formats is for full row of blocks + if (isDXT) + { + mappedSize /= 4; + mipHeight /= 4; + } + UInt8* mappedData = (UInt8*)mapped.pData; + if (dataSize == mappedSize) + { + memcpy(mappedData, dataPtr, dataSize); + } + else + { + // For compressed formats, height was already divided by block height, so this works out to operate + // on full row blocks + const size_t dataRowPitch = dataSize / mipHeight; + for (int y = 0; y < mipHeight; ++y) + { + memcpy(mappedData, dataPtr, dataRowPitch); + mappedData += mapped.RowPitch; + dataPtr += dataRowPitch; + } + } + } + ctx->Unmap(it->second, stagingSubresource); + + + // copy from staging into destination + ctx->CopySubresourceRegion (dst, dstSubResource, 0, 0, 0, it->second, stagingSubresource, NULL); + // Sometime CopySubresourceRegion hangs, that's why we have a message here + DX11_LOG_OUTPUT("TexturesD3D11::Upload2DData done"); +} + + +void TexturesD3D11::UploadTexture2D( + TextureID tid, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + AssertIf( srcData == NULL ); + AssertIf( (!IsPowerOfTwo(width) || !IsPowerOfTwo(height)) && !IsNPOTTextureAllowed(mipCount > 1) ); + + if( dimension != kTexDim2D ) + { + ErrorString( "Incorrect texture dimension!" ); + return; + } + + // Nothing to do here. Early out instead of failing, empty textures are serialized by dynamic fonts. + if( width == 0 || height == 0 ) + return; + + // Figure out whether we'll upload compressed or decompress on the fly + bool uploadIsCompressed, decompressOnTheFly; + HandleFormatDecompression (format, &usageMode, colorSpace, &uploadIsCompressed, &decompressOnTheFly); + if (decompressOnTheFly) + uploadIsCompressed = false; + + // find the texture + D3D11Texture* target = QueryD3DTexture(tid); + + // For compressed textures, stop applying masterTextureLimit if texture size drops below 4 + if( uploadIsCompressed ) + { + while( masterTextureLimit > 0 && ((width >> masterTextureLimit) < 4 || (height >> masterTextureLimit) < 4) ) + { + --masterTextureLimit; + } + } + + // skip several levels in data based on masterTextureLimit + int maxLevel = mipCount - 1; + int baseLevel = std::min( masterTextureLimit, maxLevel ); + int level; + for( level = 0; level < baseLevel; ++level ) + { + srcData += CalculateImageSize (width, height, format); + AssertIf( width == 1 && height == 1 && level != maxLevel ); + width = std::max( width / 2, 1 ); + height = std::max( height / 2, 1 ); + } + + const FormatDesc11& uploadFormat = GetUploadFormat(decompressOnTheFly ? kTexFormatRGBA32 : format); + DXGI_FORMAT d3dFormat = (colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB) ? uploadFormat.sRGBD3dformat : uploadFormat.d3dformat; + const bool needBGRA = (uploadFlags & GfxDevice::kUploadTextureOSDrawingCompatible); + + // While texture is too large for hardware limits, skip mip levels. + int texWidth = width, texHeight = height; + prcore::Surface::BlitMode blitMode = prcore::Surface::BLIT_COPY; + while( texWidth > gGraphicsCaps.maxTextureSize || texHeight > gGraphicsCaps.maxTextureSize ) + { + if( baseLevel < maxLevel ) + { + srcData += CalculateImageSize (texWidth, texHeight, format); + width = std::max( width / 2, 1 ); + height = std::max( height / 2, 1 ); + ++baseLevel; + } + texWidth = std::max( texWidth / 2, 1 ); + texHeight = std::max( texHeight / 2, 1 ); + blitMode = prcore::Surface::BLIT_SCALE; + if( texWidth <= 4 && texHeight <= 4 ) + break; + } + + ID3D11Device* dev = GetD3D11Device(); + + // create texture if it does not exist already + ID3D11Texture2D* texture = NULL; + if(!target) + { + D3D11_TEXTURE2D_DESC desc; + desc.Width = texWidth; + desc.Height = texHeight; + desc.MipLevels = mipCount - baseLevel; + desc.ArraySize = 1; + desc.Format = d3dFormat; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + + // GDI-compatible textures require certain restrictions + if (needBGRA) + { + desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE; + desc.BindFlags |= D3D11_BIND_RENDER_TARGET; + // BGRA format + if (desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM) + desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + else if (desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) + desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM_SRGB; + else { + AssertString("invalid d3d11 texture format for OS compatible texture"); + } + } + HRESULT hr = dev->CreateTexture2D (&desc, NULL, &texture); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texture, CalculateImageSize(texWidth, texHeight,format)*(mipCount>1?1.33:1),tid.m_ID); + if( FAILED(hr) ) + printf_console( "d3d11: failed to create 2D texture id=%i w=%i h=%i mips=%i d3dfmt=%i [%x]\n", tid, texWidth, texHeight, mipCount-baseLevel, d3dFormat, hr ); + SetDebugNameD3D11 (texture, Format("Texture2D-%d-%dx%d", tid.m_ID, texWidth, texHeight)); + + // Create the shader resource view + D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; + viewDesc.Format = desc.Format; + viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + viewDesc.Texture2D.MostDetailedMip = 0; + viewDesc.Texture2D.MipLevels = mipCount - baseLevel; + + ID3D11ShaderResourceView* srView = NULL; + hr = dev->CreateShaderResourceView (texture, &viewDesc, &srView); + if (FAILED(hr)) + printf_console ("d3d11: failed to create 2D texture view id=%i [%x]\n", tid, hr); + + SetDebugNameD3D11 (srView, Format("Texture2D-SRV-%d-%dx%d", tid.m_ID, texWidth, texHeight)); + TextureIdMap::UpdateTexture(tid, AllocD3DTexture(texture, srView, NULL, false)); + } + else + { + texture = (ID3D11Texture2D*)target->m_Texture; + } + if( !texture ) + { + AssertString( "failed to create 2D texture" ); + return; + } + + prcore::PixelFormat pf; + + ID3D11DeviceContext* ctx = GetD3D11Context(); + + UInt8* rgba = NULL; + if (uploadFormat.d3dformat == DXGI_FORMAT_R8G8B8A8_UNORM) + { + int tmpWidth = std::max(width,4); + int tmpHeight = std::max(height,4); + rgba = new UInt8[tmpWidth*tmpHeight*4]; + } + + // Upload the mip levels + for( level = baseLevel; level <= maxLevel; ++level ) + { +#if !ENABLE_OLD_TEXTURE_UPLOAD + if(decompressOnTheFly && IsCompressedFlashATFTextureFormat(format)){ + //Workaround for flash decompression, where we do not know the miplevel sizes. + Image tempImage (width, height, kTexFormatRGBA32); + DecompressNativeTextureFormatWithMipLevel(format, width, height, level, (UInt32*)srcData, width, height, (UInt32*)tempImage.GetImageData()); + Upload2DData (tempImage.GetImageData(), kTexFormatRGBA32, width, height, false, texture, uploadFormat.d3dformat, needBGRA, level-baseLevel); + }else{ + Upload2DData (srcData, format, width, height, decompressOnTheFly, texture, uploadFormat.d3dformat, needBGRA, level-baseLevel); + } +#else + if (!uploadIsCompressed) + { + int srcPitch = 0; + const UInt8* finalData = srcData; + + if (decompressOnTheFly) + { + int tmpWidth = std::max(width,4); + int tmpHeight = std::max(height,4); + DecompressNativeTextureFormatWithMipLevel (format, width, height, level, (UInt32*)srcData, tmpWidth,tmpHeight, (UInt32*)rgba); + //PerformUploadConversions (width, height, rgba, tempBufferPitch, usageMode, colorSpace, GetProphecyPixelFormat(kTexFormatRGBA32)); //@TODO? + srcPitch = width * 4; + finalData = rgba; + } + else if (uploadFormat.d3dformat == DXGI_FORMAT_R8G8B8A8_UNORM) + { + srcPitch = width * 4; + SwizzleToRGBA (srcData, rgba, width, height, srcPitch, format); + finalData = rgba; + } + else + { + srcPitch = GetRowBytesFromWidthAndFormat(width,format); + } + + ///@TODO: more format conversions? + ctx->UpdateSubresource (texture, level-baseLevel, NULL, finalData, srcPitch, 0); + } + else + { + int dxtWidth = std::max(width,4); + int srcPitch = (format==kTexFormatDXT1) ? dxtWidth*2 : dxtWidth*4; + if (width == texWidth && height == texHeight) + { + ctx->UpdateSubresource (texture, level-baseLevel, NULL, srcData, srcPitch, 0); + } + else + { + // TODO: fill with garbage? + } + } +#endif + // Go to next level + srcData += CalculateImageSize (width, height, format); + AssertIf( width == 1 && height == 1 && level != maxLevel ); + width = std::max( width / 2, 1 ); + height = std::max( height / 2, 1 ); + texWidth = std::max( texWidth / 2, 1 ); + texHeight = std::max( texHeight / 2, 1 ); + } + + delete[] rgba; +} + + +void TexturesD3D11::UploadTextureSubData2D( + TextureID tid, UInt8* srcData, int mipLevel, + int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + ID3D11DeviceContext* ctx = GetD3D11Context(); + if (!ctx) + return; + + Assert(srcData != NULL); + Assert(!IsAnyCompressedTextureFormat(format)); + + D3D11Texture* target = QueryD3DTexture(tid); + if (!target) + { + AssertString("Texture not found"); + return; + } + + const FormatDesc11& uploadFormat = GetUploadFormat(format); + ID3D11Resource* texture = (ID3D11Resource*)target->m_Texture; + Assert(texture); + + D3D11_BOX destRegion; + destRegion.left = x; + destRegion.right = x + width; + destRegion.top = y; + destRegion.bottom = y + height; + destRegion.front = 0; + destRegion.back = 1; + + ///@TODO: other format conversions? + bool releaseUploadData = false; + UInt8* uploadData = srcData; + int srcPitch = GetRowBytesFromWidthAndFormat(width,format); + if (uploadFormat.d3dformat == DXGI_FORMAT_R8G8B8A8_UNORM) + { + uploadData = new UInt8[width*height*4]; + SwizzleToRGBA (srcData, uploadData, width, height, width*4, format); + releaseUploadData = true; + srcPitch = width*4; + } + ctx->UpdateSubresource (texture, mipLevel, &destRegion, uploadData, srcPitch, 0); + if (releaseUploadData) + delete[] uploadData; +} + + +void TexturesD3D11::UploadTextureCube( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + ID3D11Device* dev = GetD3D11Device(); + if (!dev) + return; + + if (gGraphicsCaps.buggyMipmappedCubemaps) + mipCount = 1; + + // find the texture + D3D11Texture* target = QueryD3DTexture(tid); + + // create texture if it does not exist already + const FormatDesc11& uploadFormat = GetUploadFormat( format ); + bool sRGBUpload = (colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB); + +#if ENABLE_OLD_TEXTURE_UPLOAD + // Due to confirmed Microsoft DirectX Runtime bug we can't supply cubemap subresources via UpdateSubresource() function + // Prepare subresource data for CreateTexture2D() instead + + const int maxLevel = mipCount - 1; + + size_t uploadBufferSize = 0; + TextureFormat formatForSizeCalc = (uploadFormat.d3dformat == DXGI_FORMAT_R8G8B8A8_UNORM) ? kTexFormatARGB32 : format; + int mipSizeForCalc = size; + for (int level = 0; level <= maxLevel; ++level) + { + uploadBufferSize += CalculateImageSize (mipSizeForCalc, mipSizeForCalc, formatForSizeCalc); + mipSizeForCalc = std::max(mipSizeForCalc / 2, 1); + } + uploadBufferSize *= 6; + + UInt8* rawData = new UInt8[uploadBufferSize]; + UInt8* rawDataPtr = rawData; + D3D11_SUBRESOURCE_DATA subresourceData[6*20]; //2^20 should be enough + { + bool uploadIsCompressed = IsCompressedDXTTextureFormat(format); + + ID3D11DeviceContext* ctx = GetD3D11Context(); + + for (int face=0;face<6;face++) + { + int mipSize = size; + UInt8* data = srcData + face * faceDataSize; + + // Upload the mip levels + for (int level = 0; level <= maxLevel; ++level) + { + const UInt32 nLevelSize = CalculateImageSize( mipSize, mipSize, format ); + UInt32 levelRawSize = nLevelSize; + + ///@TODO: handle format conversions + int pitch = GetRowBytesFromWidthAndFormat(mipSize,format); + if (uploadFormat.d3dformat == DXGI_FORMAT_R8G8B8A8_UNORM) + { + pitch = mipSize * 4; + SwizzleToRGBA (data, rawDataPtr, mipSize, mipSize, pitch, format); + levelRawSize = mipSize*mipSize*4; + } + else + { + memcpy (rawDataPtr, data, nLevelSize); + } + + subresourceData[face*mipCount + level].pSysMem = rawDataPtr; + subresourceData[face*mipCount + level].SysMemPitch = pitch; + subresourceData[face*mipCount + level].SysMemSlicePitch = 0; + + // Go to next level + data += nLevelSize; + rawDataPtr += levelRawSize; + AssertIf( mipSize == 1 && level != maxLevel ); + mipSize = std::max( mipSize / 2, 1 ); + } + } + } +#endif + + ID3D11Texture2D* texture = NULL; + if (!target) + { + D3D11_TEXTURE2D_DESC desc; + desc.Width = size; + desc.Height = size; + desc.MipLevels = mipCount; + desc.ArraySize = 6; + desc.Format = sRGBUpload ? uploadFormat.sRGBD3dformat : uploadFormat.d3dformat; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE; +#if ENABLE_OLD_TEXTURE_UPLOAD + HRESULT hr = dev->CreateTexture2D (&desc, subresourceData, &texture); +#else + HRESULT hr = dev->CreateTexture2D (&desc, NULL, &texture); +#endif + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texture, 6 * CalculateImageSize(size, size, format)*(mipCount>1?1.33:1),tid.m_ID); + if (FAILED(hr)) + printf_console ("d3d11: failed to create Cube texture id=%i s=%i mips=%i d3dfmt=%i [%x]\n", tid, size, mipCount, sRGBUpload ? uploadFormat.sRGBD3dformat : uploadFormat.d3dformat, hr); + SetDebugNameD3D11 (texture, Format("TextureCube-%d-%dx%d", tid.m_ID, size)); + + // Create the shader resource view + D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; + viewDesc.Format = desc.Format; + viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + viewDesc.Texture2D.MostDetailedMip = 0; + viewDesc.Texture2D.MipLevels = mipCount; + + ID3D11ShaderResourceView* srView = NULL; + hr = dev->CreateShaderResourceView (texture, &viewDesc, &srView); + if (FAILED(hr)) + printf_console ("d3d11: failed to create Cube texture view id=%i [%x]\n", tid, hr); + + SetDebugNameD3D11 (srView, Format("TextureCube-SRV-%d-%d", tid.m_ID, size)); + + TextureIdMap::UpdateTexture(tid, AllocD3DTexture(texture, srView, NULL, false)); + } + else + { + texture = (ID3D11Texture2D*)target->m_Texture; + } +#if ENABLE_OLD_TEXTURE_UPLOAD + delete[] rawData; +#endif + + if (!texture) + { + AssertString( "failed to create cubemap" ); + return; + } +#if !ENABLE_OLD_TEXTURE_UPLOAD + // Upload data + // Note: DX11 Runtime on 9.x levels has a bug where setting cubemap data via UpdateSubresource doesn't work (only first + // subresource is ever updated). We use staging resources for upload here, but keep in mind if at some point you want + // to switch away from them. + const int maxLevel = mipCount - 1; + for (int face=0;face<6;face++) + { + int mipSize = size; + UInt8* data = srcData + face * faceDataSize; + + // Upload the mip levels + for (int level = 0; level <= maxLevel; ++level) + { + Upload2DData (data, format, mipSize, mipSize, false, texture, uploadFormat.d3dformat, false, D3D11CalcSubresource(level,face,mipCount)); + + data += CalculateImageSize(mipSize, mipSize, format); + Assert(mipSize != 1 || level == maxLevel); + mipSize = std::max(mipSize/2, 1); + } + } +#endif +} + +void TexturesD3D11::UploadTexture3D( + TextureID tid, UInt8* srcData, int width, int height, int depth, + TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + ID3D11Device* dev = GetD3D11Device(); + if (!dev) + return; + + if (gGraphicsCaps.buggyMipmapped3DTextures) + mipCount = 1; + + // find the texture + D3D11Texture* target = QueryD3DTexture(tid); + + // create texture if it does not exist already + const FormatDesc11& uploadFormat = GetUploadFormat(format); + + ID3D11Texture3D* texture = NULL; + if (!target) + { + D3D11_TEXTURE3D_DESC desc; + desc.Width = width; + desc.Height = height; + desc.Depth = depth; + desc.MipLevels = mipCount; + desc.Format = uploadFormat.d3dformat; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; + HRESULT hr = dev->CreateTexture3D (&desc, NULL, &texture); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texture, depth * CalculateImageSize(width, height, format)*(mipCount>1?1.33:1),tid.m_ID); + if (FAILED(hr)) + printf_console ("d3d11: failed to create 3D texture id=%i s=%ix%ix%i mips=%i d3dfmt=%i [%x]\n", tid, width, height, depth, mipCount, uploadFormat.d3dformat, hr); + SetDebugNameD3D11 (texture, Format("Texture3D-%d-%dx%dx%d", tid.m_ID, width, height, depth)); + + // Create the shader resource view + D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc; + viewDesc.Format = desc.Format; + viewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; + viewDesc.Texture3D.MostDetailedMip = 0; + viewDesc.Texture3D.MipLevels = mipCount; + + ID3D11ShaderResourceView* srView = NULL; + hr = dev->CreateShaderResourceView (texture, &viewDesc, &srView); + if (FAILED(hr)) + printf_console ("d3d11: failed to create 3D texture view id=%i [%x]\n", tid, hr); + + SetDebugNameD3D11 (srView, Format("Texture3D-SRV-%d-%dx%dx%d", tid.m_ID, width, height, depth)); + + TextureIdMap::UpdateTexture(tid, AllocD3DTexture(texture, srView, NULL, false)); + } + else + { + texture = (ID3D11Texture3D*)target->m_Texture; + } + if (!texture) + { + AssertString("failed to create 3D texture"); + return; + } + + // Upload data + bool uploadIsCompressed = IsCompressedDXTTextureFormat(format); + + ID3D11DeviceContext* ctx = GetD3D11Context(); + + int maxLevel = mipCount - 1; + + UInt8* rgba = NULL; + if (uploadFormat.d3dformat == DXGI_FORMAT_R8G8B8A8_UNORM) + rgba = new UInt8[width*height*depth*4]; + + for (int level = 0; level <= maxLevel; ++level) + { + ///@TODO: handle format conversions + const UInt8* finalData = srcData; + int pitch = GetRowBytesFromWidthAndFormat(width,format); + if (uploadFormat.d3dformat == DXGI_FORMAT_R8G8B8A8_UNORM) + { + const UInt8* srcSlice = srcData; + UInt8* dstSlice = rgba; + for (int d = 0; d < depth; ++d) + { + SwizzleToRGBA (srcSlice, dstSlice, width, height, width*4, format); + srcSlice += pitch * height; + dstSlice += 4 * width * height; + } + finalData = rgba; + pitch = width * 4; + } + + ctx->UpdateSubresource (texture, level, NULL, finalData, pitch, pitch * height); + + // Go to next level + srcData += CalculateImageSize(width, height, format) * height; + width = std::max(width / 2, 1); + height = std::max(height / 2, 1); + depth = std::max(depth / 2, 1); + } + delete[] rgba; +} + +static D3D11_TEXTURE_ADDRESS_MODE s_D3DWrapModes[kTexWrapCount] = { + D3D11_TEXTURE_ADDRESS_WRAP, + D3D11_TEXTURE_ADDRESS_CLAMP, +}; +static D3D11_FILTER s_D3DFilters[kTexFilterCount] = { + D3D11_FILTER_MIN_MAG_MIP_POINT, + D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, + D3D11_FILTER_MIN_MAG_MIP_LINEAR, +}; +static D3D11_FILTER s_D3DFiltersShadow[kTexFilterCount] = { + D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, + D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, + D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, +}; + +ID3D11SamplerState* TexturesD3D11::GetSampler(BuiltinSamplerState sampler) +{ + D3D11Sampler state; + switch (sampler) { + case kSamplerPointClamp: + state.filter = kTexFilterNearest; + state.wrap = kTexWrapClamp; + break; + case kSamplerLinearClamp: + state.filter = kTexFilterBilinear; + state.wrap = kTexWrapClamp; + break; + case kSamplerPointRepeat: + state.filter = kTexFilterNearest; + state.wrap = kTexWrapRepeat; + break; + case kSamplerLinearRepeat: + state.filter = kTexFilterBilinear; + state.wrap = kTexWrapRepeat; + break; + default: AssertString("unknown builtin sampler type"); + } + return GetSampler (state); +} + + +ID3D11SamplerState* TexturesD3D11::GetSampler(const D3D11Sampler& texSampler) +{ + SamplerMap::iterator sit = m_Samplers.find(texSampler); + if (sit != m_Samplers.end()) + return sit->second; + + ID3D11Device* dev = GetD3D11Device(); + ID3D11SamplerState* sampler = NULL; + + D3D11_SAMPLER_DESC desc; + if (texSampler.flags & kSamplerShadowMap) + desc.Filter = s_D3DFiltersShadow[texSampler.filter]; + else if (texSampler.anisoLevel > 1 && gGraphicsCaps.d3d11.featureLevel >= kDX11Level10_0) + desc.Filter = D3D11_FILTER_ANISOTROPIC; + else + desc.Filter = s_D3DFilters[texSampler.filter]; + desc.AddressU = desc.AddressV = desc.AddressW = s_D3DWrapModes[texSampler.wrap]; + desc.MipLODBias = texSampler.bias; + desc.MaxAnisotropy = texSampler.anisoLevel; + desc.ComparisonFunc = (gGraphicsCaps.d3d11.featureLevel < kDX11Level10_0) ? D3D11_COMPARISON_LESS_EQUAL : D3D11_COMPARISON_LESS; + desc.BorderColor[0] = desc.BorderColor[1] = desc.BorderColor[2] = desc.BorderColor[3] = 0.0f; + desc.MinLOD = -FLT_MAX; + desc.MaxLOD = FLT_MAX; + HRESULT hr = dev->CreateSamplerState (&desc, &sampler); + SetDebugNameD3D11 (sampler, Format("SamplerState-%d-%d", texSampler.filter, texSampler.wrap)); + + sit = m_Samplers.insert (std::make_pair(texSampler,sampler)).first; + return sit->second; +} + + +bool TexturesD3D11::SetTexture (ShaderType shaderType, int unit, int sampler, TextureID textureID, float bias) +{ + D3D11Texture* target = QueryD3DTexture(textureID); + if (!target) + return false; + + D3D11Texture& tex = *target; + // Do not bind texture if it's currently being used as a render target + if (g_D3D11CurrColorRT && g_D3D11CurrColorRT->m_Texture == tex.m_Texture && !tex.m_UAV) + return false; + + if (bias != std::numeric_limits<float>::infinity()) + tex.m_Sampler.bias = bias; + + // set sampler state + ID3D11SamplerState* smp = GetSampler(tex.m_Sampler); + + ID3D11DeviceContext* ctx = GetD3D11Context(); + switch (shaderType) { + case kShaderVertex: + ctx->VSSetShaderResources (unit, 1, &tex.m_SRV); + if (sampler >= 0 && m_ActiveD3DSamplers[kShaderVertex][sampler] != smp) + { + ctx->VSSetSamplers (sampler, 1, &smp); + m_ActiveD3DSamplers[kShaderVertex][sampler] = smp; + } + break; + case kShaderFragment: + ctx->PSSetShaderResources (unit, 1, &tex.m_SRV); + if (sampler >= 0 && m_ActiveD3DSamplers[kShaderFragment][sampler] != smp) + { + ctx->PSSetSamplers (sampler, 1, &smp); + m_ActiveD3DSamplers[kShaderFragment][sampler] = smp; + } + break; + case kShaderGeometry: + ctx->GSSetShaderResources (unit, 1, &tex.m_SRV); + if (sampler >= 0 && m_ActiveD3DSamplers[kShaderGeometry][sampler] != smp) + { + ctx->GSSetSamplers (sampler, 1, &smp); + m_ActiveD3DSamplers[kShaderGeometry][sampler] = smp; + } + break; + case kShaderHull: + ctx->HSSetShaderResources (unit, 1, &tex.m_SRV); + if (sampler >= 0 && m_ActiveD3DSamplers[kShaderHull][sampler] != smp) + { + ctx->HSSetSamplers (sampler, 1, &smp); + m_ActiveD3DSamplers[kShaderHull][sampler] = smp; + } + break; + case kShaderDomain: + ctx->DSSetShaderResources (unit, 1, &tex.m_SRV); + if (sampler >= 0 && m_ActiveD3DSamplers[kShaderDomain][sampler] != smp) + { + ctx->DSSetSamplers (sampler, 1, &smp); + m_ActiveD3DSamplers[kShaderDomain][sampler] = smp; + } + break; + default: AssertString ("unknown shader type"); + } + + return true; +} + +void TexturesD3D11::InvalidateSamplers() +{ + memset (m_ActiveD3DSamplers, 0, sizeof(m_ActiveD3DSamplers)); +} + + +void TexturesD3D11::SetTextureParams( TextureID textureID, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + D3D11Texture* target = QueryD3DTexture(textureID); + if (!target) + return; + + D3D11Sampler& s = target->m_Sampler; + s.filter = filter; + s.wrap = wrap; + s.anisoLevel = anisoLevel; + if (hasMipMap) + s.flags |= kSamplerHasMipMap; + else + s.flags &= ~kSamplerHasMipMap; +} + + +void TexturesD3D11::DeleteTexture( TextureID textureID ) +{ + D3D11Texture* target = QueryD3DTexture(textureID); + if( !target ) + return; + + // texture can be null if texture creation failed. At least don't make it crash here + if (target->m_Texture) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(target->m_Texture); + ULONG refCount = target->m_Texture->Release(); + DebugAssert(!refCount); + } + if (target->m_UAV) + { + ULONG refCount = target->m_UAV->Release(); + DebugAssert(!refCount); + } + if (target->m_SRV) + { + ULONG refCount = target->m_SRV->Release(); + DebugAssert(!refCount); + } + target->~D3D11Texture(); + _TextureAlloc->free(target); + TextureIdMap::RemoveTexture(textureID); +} + +void TexturesD3D11::ClearTextureResources() +{ + for (SamplerMap::iterator it = m_Samplers.begin(); it != m_Samplers.end(); ++it) + { + if (it->second) + it->second->Release(); + } + m_Samplers.clear(); + + for (StagingTextureMap::iterator it = m_StagingTextures.begin(), itEnd = m_StagingTextures.end(); it != itEnd; ++it) + { + if (it->second) + it->second->Release(); + } + m_StagingTextures.clear(); +} + diff --git a/Runtime/GfxDevice/d3d11/TexturesD3D11.h b/Runtime/GfxDevice/d3d11/TexturesD3D11.h new file mode 100644 index 0000000..d5971f9 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/TexturesD3D11.h @@ -0,0 +1,201 @@ +#pragma once + +#include "D3D11Includes.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Graphics/RenderSurface.h" +#include "Runtime/Threads/AtomicOps.h" +#include "Runtime/Utilities/NonCopyable.h" +#include "Runtime/Utilities/dynamic_array.h" +#include <map> + +class ImageReference; + +struct ComputeBuffer11 +{ + ID3D11Buffer* buffer; + ID3D11ShaderResourceView* srv; + ID3D11UnorderedAccessView* uav; +}; + + +class TexturesD3D11 +{ +public: + enum { kSamplerHasMipMap = (1<<0), kSamplerShadowMap = (1<<1) }; + struct D3D11Sampler { + D3D11Sampler() { + memset (this, 0, sizeof(*this)); + } + float bias; + UInt8 filter; // TextureFilterMode + UInt8 wrap; // TextureWrapMode + UInt8 anisoLevel; + UInt8 flags; + }; + struct D3D11Texture { + D3D11Texture() : m_Texture(NULL), m_SRV(NULL), m_UAV(NULL) { } + explicit D3D11Texture (ID3D11Resource* tex, ID3D11ShaderResourceView* srv, ID3D11UnorderedAccessView* uav, bool shadowMap) + : m_Texture(tex), m_SRV(srv), m_UAV(uav) { if (shadowMap) m_Sampler.flags |= kSamplerShadowMap; } + ID3D11Resource* m_Texture; + ID3D11ShaderResourceView* m_SRV; + ID3D11UnorderedAccessView* m_UAV; + D3D11Sampler m_Sampler; + }; + +public: + TexturesD3D11(); + ~TexturesD3D11(); + + void ClearTextureResources(); + + bool SetTexture (ShaderType shaderType, int unit, int sampler, TextureID textureID, float bias); + void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + + void DeleteTexture( TextureID textureID ); + + void UploadTexture2D( + TextureID tid, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + + void UploadTextureSubData2D( + TextureID tid, UInt8* srcData, int mipLevel, + int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + + void UploadTextureCube( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + + void UploadTexture3D( + TextureID tid, UInt8* srcData, int width, int height, int depth, + TextureFormat format, int mipCount, UInt32 uploadFlags ); + + void AddTexture (TextureID textureID, ID3D11Resource* texture, ID3D11ShaderResourceView* srv, ID3D11UnorderedAccessView* uav, bool shadowMap); + void RemoveTexture( TextureID textureID ); + D3D11Texture* GetTexture(TextureID textureID); + ID3D11SamplerState* GetSampler(const D3D11Sampler& texSampler); + ID3D11SamplerState* GetSampler(BuiltinSamplerState sampler); + + void AddComputeBuffer (ComputeBufferID id, const ComputeBuffer11& buf); + void RemoveComputeBuffer (ComputeBufferID id); + ComputeBuffer11* GetComputeBuffer (ComputeBufferID id); + + void InvalidateSamplers(); + void InvalidateSampler (ShaderType shader, int samplerUnit) { m_ActiveD3DSamplers[shader][samplerUnit] = NULL; } + + intptr_t RegisterNativeTexture(ID3D11ShaderResourceView* resourceView) const; + void UpdateNativeTexture(TextureID textureID, ID3D11ShaderResourceView* resourceView); + +private: + void Upload2DData (const UInt8* dataPtr, TextureFormat dataFormat, int width, int height, bool decompressData, ID3D11Resource* dst, DXGI_FORMAT dstFormat, bool bgra, int dstSubResource); + +private: + typedef std::map< D3D11Sampler, ID3D11SamplerState*, memcmp_less<D3D11Sampler> > SamplerMap; + SamplerMap m_Samplers; + + ID3D11SamplerState* m_ActiveD3DSamplers[kShaderTypeCount][kMaxSupportedTextureUnits]; + + // staging texture key: width, height, dxgi format + enum { + kStagingWidthShift = 0ULL, + kStagingHeightShift = 20ULL, + kStagingFormatShift = 40ULL, + }; + typedef std::map<UInt64, ID3D11Resource*> StagingTextureMap; + StagingTextureMap m_StagingTextures; + + typedef std::map<ComputeBufferID, ComputeBuffer11> ComputeBufferMap; + ComputeBufferMap m_ComputeBuffers; + + void TextureFromShaderResourceView(ID3D11ShaderResourceView* resourceView, ID3D11Texture2D** texture) const; +}; + + +struct RenderSurfaceD3D11 : RenderSurfaceBase, NonCopyable +{ + RenderSurfaceD3D11() + : m_Texture(NULL) + , m_SRView(NULL) + , m_SRViewForMips(NULL) + , m_UAView(NULL) + , depth(0) + , dim(kTexDim2D) + { + RenderSurfaceBase_Init(*this); + } + ID3D11Resource* m_Texture; + ID3D11ShaderResourceView* m_SRView; + ID3D11ShaderResourceView* m_SRViewForMips; // always without sRGB + ID3D11UnorderedAccessView* m_UAView; + int depth; + TextureDimension dim; +protected: + void Reset() + { + SAFE_RELEASE(m_Texture); + SAFE_RELEASE(m_SRView); + SAFE_RELEASE(m_SRViewForMips); + SAFE_RELEASE(m_UAView); + RenderSurfaceBase_Init(*this); + depth = 0; + dim = kTexDim2D; + } +}; + +struct RenderColorSurfaceD3D11 : public RenderSurfaceD3D11 +{ + RenderColorSurfaceD3D11() + : format(kRTFormatARGB32) + { + colorSurface = true; + } + + static UInt32 GetRTVKey(int face, int mipLevel, bool secondary) { + return (face) | (secondary ? 8 : 0) | (mipLevel << 4); + } + ID3D11RenderTargetView* GetRTV(int face, int mipLevel, bool secondary) { + UInt32 key = GetRTVKey(face, mipLevel, secondary); + for (int i = 0, n = m_RTVs.size(); i != n; ++i) + if (m_RTVs[i].first == key) + return m_RTVs[i].second; + return NULL; + } + void SetRTV(int face, int mipLevel, bool secondary, ID3D11RenderTargetView* rtv) { + DebugAssert(GetRTV(face, mipLevel, secondary) == NULL); + UInt32 key = GetRTVKey(face, mipLevel, secondary); + m_RTVs.push_back (std::make_pair(key, rtv)); + } + + void Reset() + { + RenderSurfaceD3D11::Reset(); + colorSurface = true; + for (int i = 0, n = m_RTVs.size(); i != n; ++i) + { + SAFE_RELEASE(m_RTVs[i].second); + } + m_RTVs.resize_uninitialized(0); + } + + typedef std::pair<UInt32, ID3D11RenderTargetView*> RTVPair; + dynamic_array<RTVPair> m_RTVs; + RenderTextureFormat format; +}; + +struct RenderDepthSurfaceD3D11 : public RenderSurfaceD3D11 +{ + RenderDepthSurfaceD3D11() + : m_DSView(NULL) + , depthFormat(kDepthFormatNone) + { + colorSurface = false; + } + ID3D11DepthStencilView* m_DSView; + DepthBufferFormat depthFormat; + void Reset() + { + RenderSurfaceD3D11::Reset(); + colorSurface = false; + SAFE_RELEASE(m_DSView); + depthFormat = kDepthFormatNone; + } +}; diff --git a/Runtime/GfxDevice/d3d11/TimerQueryD3D11.cpp b/Runtime/GfxDevice/d3d11/TimerQueryD3D11.cpp new file mode 100644 index 0000000..31afc52 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/TimerQueryD3D11.cpp @@ -0,0 +1,209 @@ +#include "UnityPrefix.h" +#if ENABLE_PROFILER +#include "GfxDeviceD3D11.h" +#include "D3D11Context.h" +#include "TimerQueryD3D11.h" + + +TimerQueryD3D11::TimerQueryD3D11() + : m_Query(NULL), m_Time(0), m_Active(false) +{ + D3D11_QUERY_DESC QueryDesc; + QueryDesc.Query = D3D11_QUERY_TIMESTAMP; + QueryDesc.MiscFlags = 0; + GetD3D11Device()->CreateQuery(&QueryDesc, &m_Query); + m_TimeMultiplier = 0.0f; +} + +TimerQueryD3D11::~TimerQueryD3D11() +{ + SAFE_RELEASE(m_Query); +} + +void TimerQueryD3D11::Measure() +{ + // Flush previous result + GetElapsed(kWaitRenderThread); + + if (m_Query) + { + g_TimerQueriesD3D11.AddActiveTimerQuery(this); + GetD3D11Context()->End(m_Query); + m_Active = true; + m_Time = kInvalidProfileTime; + } + else + m_Time = 0; + m_TimeMultiplier = 0.0f; +} + +ProfileTimeFormat TimerQueryD3D11::GetElapsed(UInt32 flags) +{ + while (m_Active) + { + bool wait = (flags & kWaitRenderThread) != 0; + if (!g_TimerQueriesD3D11.PollNextTimerQuery(wait)) + break; + } + return m_Time; +} + +bool TimerQueryD3D11::PollResult(UInt64& prevTime, bool wait) +{ + for (;;) + { + UINT64 time; + UINT flags = wait ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH; + HRESULT hr = GetD3D11Context()->GetData(m_Query, &time, sizeof(time), flags); + if (hr == S_OK) + { + UInt64 elapsed = prevTime ? (time - prevTime) : 0; + m_Time = ProfileTimeFormat(elapsed * m_TimeMultiplier); + prevTime = time; + return true; + } + // Stop polling on unknown result (e.g D3DERR_DEVICELOST) + if (hr != S_FALSE) + { + m_Time = 0; + prevTime = 0; + return true; + } + if (!wait) + break; + } + return false; +} + +TimerQueriesD3D11::TimerQueriesD3D11() +{ + m_LastQueryTime = 0; + m_DisjointQuery = NULL; + memset(m_StartTimeQueries, 0, sizeof(m_StartTimeQueries)); + m_StartTimeQueryIndex = 0; +} + +void TimerQueriesD3D11::ReleaseAllQueries() +{ + SAFE_RELEASE(m_DisjointQuery); + for (int i = 0; i < kStartTimeQueryCount; i++) + { + delete m_StartTimeQueries[i]; + m_StartTimeQueries[i] = NULL; + } + m_InactiveTimerQueries.append(m_ActiveTimerQueries); + m_InactiveTimerQueries.append(m_PolledTimerQueries); + TimerQueryList& queries = m_InactiveTimerQueries; + for (TimerQueryList::iterator it = queries.begin(); it != queries.end(); ++it) + { + TimerQueryD3D11& query = *it; + query.m_Active = false; + query.m_Time = 0; + SAFE_RELEASE(query.m_Query); + } +} + +void TimerQueriesD3D11::RecreateAllQueries() +{ + Assert(m_ActiveTimerQueries.empty()); + Assert(m_PolledTimerQueries.empty()); + TimerQueryList& queries = m_InactiveTimerQueries; + for (TimerQueryList::iterator it = queries.begin(); it != queries.end(); ++it) + { + TimerQueryD3D11& query = *it; + + D3D11_QUERY_DESC QueryDesc; + QueryDesc.Query = D3D11_QUERY_TIMESTAMP; + QueryDesc.MiscFlags = 0; + GetD3D11Device()->CreateQuery(&QueryDesc, &query.m_Query); + } +} + +void TimerQueriesD3D11::BeginTimerQueries() +{ + // Poll queries from previous frames + PollTimerQueries(); + + if (m_DisjointQuery == NULL) + { + D3D11_QUERY_DESC QueryDesc; + QueryDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT; + QueryDesc.MiscFlags = 0; + GetD3D11Device()->CreateQuery(&QueryDesc, &m_DisjointQuery); + } + GetD3D11Context()->Begin(m_DisjointQuery); + + int& index = m_StartTimeQueryIndex; + if (m_StartTimeQueries[index] == NULL) + { + m_StartTimeQueries[index] = new TimerQueryD3D11; + } + m_StartTimeQueries[index]->Measure(); + index = (index + 1) % kStartTimeQueryCount; +} + +void TimerQueriesD3D11::EndTimerQueries() +{ + if(m_DisjointQuery == NULL) + return; + + GetD3D11Context()->End(m_DisjointQuery); + + HRESULT hr; + D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjointQueryResult; + do + { + hr = GetD3D11Context()->GetData(m_DisjointQuery, &disjointQueryResult, sizeof(disjointQueryResult), 0); + } while (hr == S_FALSE); + if (hr == S_OK && !disjointQueryResult.Disjoint) + { + float timeMult = float(1000000000.0 / (double)disjointQueryResult.Frequency); + TimerQueryList::iterator query, queryEnd = m_ActiveTimerQueries.end(); + for (query = m_ActiveTimerQueries.begin(); query != queryEnd; ++query) + query->SetTimeMultiplier(timeMult); + } + // Move queries from active to polled list + m_PolledTimerQueries.append(m_ActiveTimerQueries); +} + +TimerQueryD3D11* TimerQueriesD3D11::CreateTimerQuery() +{ + TimerQueryD3D11* query = new TimerQueryD3D11; + m_InactiveTimerQueries.push_back(*query); + return query; +} + +void TimerQueriesD3D11::AddActiveTimerQuery(TimerQueryD3D11* query) +{ + query->RemoveFromList(); + m_ActiveTimerQueries.push_back(*query); +} + +void TimerQueriesD3D11::PollTimerQueries() +{ + for (;;) + { + if (!PollNextTimerQuery(false)) + break; + } +} + +bool TimerQueriesD3D11::PollNextTimerQuery(bool wait) +{ + if (m_PolledTimerQueries.empty()) + return false; + + TimerQueryD3D11& query = m_PolledTimerQueries.front(); + if (query.PollResult(m_LastQueryTime, wait)) + { + query.m_Active = false; + query.RemoveFromList(); + m_InactiveTimerQueries.push_back(query); + return true; + } + return false; +} + +TimerQueriesD3D11 g_TimerQueriesD3D11; + +#endif diff --git a/Runtime/GfxDevice/d3d11/TimerQueryD3D11.h b/Runtime/GfxDevice/d3d11/TimerQueryD3D11.h new file mode 100644 index 0000000..3f46a5c --- /dev/null +++ b/Runtime/GfxDevice/d3d11/TimerQueryD3D11.h @@ -0,0 +1,67 @@ +#ifndef TIMERQUERYD3D11_H +#define TIMERQUERYD3D11_H + +#if ENABLE_PROFILER + +#include "Runtime/GfxDevice/GfxTimerQuery.h" + +class TimerQueriesD3D11; + +class TimerQueryD3D11 : public GfxTimerQuery +{ +public: + ~TimerQueryD3D11(); + + virtual void Measure(); + virtual ProfileTimeFormat GetElapsed(UInt32 flags); + + bool PollResult(UInt64& prevTime, bool wait); + void SetTimeMultiplier(float tm) { m_TimeMultiplier = tm; } + +private: + friend TimerQueriesD3D11; + TimerQueryD3D11(); + + ID3D11Query* m_Query; + ProfileTimeFormat m_Time; + float m_TimeMultiplier; + bool m_Active; +}; + +class TimerQueriesD3D11 +{ +public: + TimerQueriesD3D11(); + + void ReleaseAllQueries(); + void RecreateAllQueries(); + + void BeginTimerQueries(); + void EndTimerQueries(); + + TimerQueryD3D11* CreateTimerQuery(); + + void AddActiveTimerQuery(TimerQueryD3D11* query); + void PollTimerQueries(); + bool PollNextTimerQuery(bool wait); + +private: + enum + { + kStartTimeQueryCount = 3 + }; + + UInt64 m_LastQueryTime; + ID3D11Query* m_DisjointQuery; + TimerQueryD3D11* m_StartTimeQueries[kStartTimeQueryCount]; + int m_StartTimeQueryIndex; + typedef List<TimerQueryD3D11> TimerQueryList; + TimerQueryList m_InactiveTimerQueries; + TimerQueryList m_ActiveTimerQueries; + TimerQueryList m_PolledTimerQueries; +}; + +extern TimerQueriesD3D11 g_TimerQueriesD3D11; + +#endif +#endif diff --git a/Runtime/GfxDevice/d3d11/VertexDeclarationsD3D11.cpp b/Runtime/GfxDevice/d3d11/VertexDeclarationsD3D11.cpp new file mode 100644 index 0000000..e98779b --- /dev/null +++ b/Runtime/GfxDevice/d3d11/VertexDeclarationsD3D11.cpp @@ -0,0 +1,282 @@ +#include "UnityPrefix.h" +#include "VertexDeclarationsD3D11.h" +#include "D3D11Context.h" +#include "D3D11ByteCode.h" +#include "D3D11Utils.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Shaders/VBO.h" + + +extern ID3D11InputLayout* g_ActiveInputLayoutD3D11; + + +bool VertexDeclarationsD3D11::KeyType::operator < (const KeyType& rhs) const +{ + if (inputSig != rhs.inputSig) + return inputSig < rhs.inputSig; + if (extraBits != rhs.extraBits) + return extraBits < rhs.extraBits; + return memcmp(channels, rhs.channels, sizeof(channels)) < 0; +} + + + +VertexDeclarationsD3D11::VertexDeclarationsD3D11() +{ +} + +VertexDeclarationsD3D11::~VertexDeclarationsD3D11() +{ + Clear(); +} + +static D3D11_INPUT_ELEMENT_DESC kChannelVertexElems[kShaderChannelCount] = { + // semantic name, semantic index, format, input slot, aligned byte offset, input slot class, instance data step rate + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TANGENT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, +}; +static const int kDefaultChannelSizes[kShaderChannelCount] = { + 12, // position + 12, // normal + 4, // color + 8, // uv + 8, // uv2 + 16, // tangent +}; + +static const int kChannelSkinningCount = 2; +static D3D11_INPUT_ELEMENT_DESC kChannelSkinning4[kChannelSkinningCount] = { + // Stream 1 + { "BLENDWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "BLENDINDICES", 0, DXGI_FORMAT_R32G32B32A32_SINT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 }, +}; + +static D3D11_INPUT_ELEMENT_DESC kChannelSkinning2[kChannelSkinningCount] = { + // Stream 1 + { "BLENDWEIGHT", 0, DXGI_FORMAT_R32G32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "BLENDINDICES", 0, DXGI_FORMAT_R32G32_SINT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, +}; + +static D3D11_INPUT_ELEMENT_DESC kChannelSkinning1[kChannelSkinningCount] = { + // Stream 1 + { "BONEINDEX", 0, DXGI_FORMAT_R32_SINT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, +}; + +static const D3D11_INPUT_ELEMENT_DESC kImmChannelVertexElems[] = { + // semantic name, semantic index, format, input slot, aligned byte offset, input slot class, instance data step rate + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32_FLOAT, 0, 40, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 2, DXGI_FORMAT_R32G32B32_FLOAT, 0, 52, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 3, DXGI_FORMAT_R32G32B32_FLOAT, 0, 64, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 4, DXGI_FORMAT_R32G32B32_FLOAT, 0, 76, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 5, DXGI_FORMAT_R32G32B32_FLOAT, 0, 88, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 6, DXGI_FORMAT_R32G32B32_FLOAT, 0,100, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 7, DXGI_FORMAT_R32G32B32_FLOAT, 0,112, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + // feed position as tangent0 data, just in case we use shaders that pretend to want tangents + { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, +}; + +static FORCE_INLINE DXGI_FORMAT GetD3D11VertexDeclType(const ChannelInfo& info) +{ + switch (info.format) + { + case kChannelFormatFloat: + { + switch (info.dimension) + { + case 1: return DXGI_FORMAT_R32_FLOAT; + case 2: return DXGI_FORMAT_R32G32_FLOAT; + case 3: return DXGI_FORMAT_R32G32B32_FLOAT; + case 4: return DXGI_FORMAT_R32G32B32A32_FLOAT; + } + break; + } + case kChannelFormatFloat16: + { + switch (info.dimension) + { + case 2: return DXGI_FORMAT_R16G16_FLOAT; + case 4: return DXGI_FORMAT_R16G16B16A16_FLOAT; + } + break; + } + case kChannelFormatColor: + { + return DXGI_FORMAT_R8G8B8A8_UNORM; + } + } + Assert("No matching D3D11 vertex decl type!"); + return DXGI_FORMAT_UNKNOWN; +} + +ID3D11InputLayout* VertexDeclarationsD3D11::GetVertexDecl( UInt32 shaderChannelsMap, void* vertexShaderCode, unsigned vertexShaderLength, bool memExportSkin, unsigned int bonesPerVertex) +{ + ChannelInfoArray channels; + int offset = 0; + for (int i = 0; i < kShaderChannelCount; i++) + { + ChannelInfo& info = channels[i]; + if (shaderChannelsMap & (1 << i)) + { + info.stream = 0; + info.offset = offset; + info.format = VBO::GetDefaultChannelFormat( i ); + info.dimension = VBO::GetDefaultChannelDimension( i ); + offset += VBO::GetDefaultChannelByteSize( i ); + } + else + info.Reset(); + } + return GetVertexDecl( channels, GetShaderInputSignature(vertexShaderCode, vertexShaderLength), memExportSkin, bonesPerVertex ); +} + + +ID3D11InputLayout* VertexDeclarationsD3D11::GetVertexDecl (const ChannelInfoArray& channels, const InputSignatureD3D11* inputSig, bool streamOutSkin, unsigned int bonesPerVertex) +{ + if (!inputSig) + { + AssertString("DX11 shader input signature is null"); + return NULL; + } + + KeyType key; + memcpy(key.channels, channels, sizeof(key.channels)); + key.extraBits = streamOutSkin ? bonesPerVertex : 0; // Set bones-per-vertex count for memExportSkin + key.inputSig = inputSig; + + // already have vertex declaration for this format/shader? + VertexDeclMap::iterator it = m_VertexDeclMap.find (key); + if( it != m_VertexDeclMap.end() ) + return it->second; + + // don't have this declaration yet - create one + D3D11_INPUT_ELEMENT_DESC elements[kShaderChannelCount + kChannelSkinningCount]; + int elIndex = 0; + for( int chan = 0; chan < kShaderChannelCount; chan++ ) + { + DebugAssert(elIndex < kShaderChannelCount); + if (!channels[chan].IsValid() ) + { + ///@TODO: for now, hack in all shader channels to pretend to be there + elements[elIndex] = kChannelVertexElems[chan]; + elements[elIndex].AlignedByteOffset = 0; + ++elIndex; + continue; + } + elements[elIndex] = kChannelVertexElems[chan]; + elements[elIndex].InputSlot = channels[chan].stream; + elements[elIndex].AlignedByteOffset = channels[chan].offset; + elements[elIndex].Format = GetD3D11VertexDeclType(channels[chan]); + ++elIndex; + } + + if (streamOutSkin) // Append extra elements required for streamout + { + switch(bonesPerVertex) + { + default: + case 1: + elements[elIndex] = kChannelSkinning1[0]; + ++elIndex; + break; + case 2: + for (int i = 0; i < kChannelSkinningCount; ++i) + { + elements[elIndex] = kChannelSkinning2[i]; + ++elIndex; + } + break; + case 4: + for (int i = 0; i < kChannelSkinningCount; ++i) + { + elements[elIndex] = kChannelSkinning4[i]; + ++elIndex; + } + break; + } + } + + ID3D11InputLayout* decl = NULL; + HRESULT hr = GetD3D11Device()->CreateInputLayout (elements, elIndex, inputSig->blob.data(), inputSig->blob.size(), &decl ); + if( FAILED(hr) ) { + AssertString ("Failed to create vertex declaration\n"); + // TODO: error! + } + SetDebugNameD3D11 (decl, Format("InputLayout-%d", elIndex)); + m_VertexDeclMap.insert( std::make_pair( key, decl ) ); + + return decl; +} + +ID3D11InputLayout* VertexDeclarationsD3D11::GetImmVertexDecl (const InputSignatureD3D11* inputSig) +{ + if (!inputSig) + { + AssertString("DX11 shader input signature is null"); + return NULL; + } + + // already have vertex declaration for this shader? + ImmVertexDeclMap::iterator it = m_ImmVertexDeclMap.find (inputSig); + if (it != m_ImmVertexDeclMap.end()) + return it->second; + + // don't have this declaration yet - create one + ID3D11InputLayout* decl = NULL; + HRESULT hr = GetD3D11Device()->CreateInputLayout (kImmChannelVertexElems,ARRAY_SIZE(kImmChannelVertexElems), inputSig->blob.data(), inputSig->blob.size(), &decl); + if (FAILED(hr)) + { + AssertString ("Failed to create vertex declaration for GL.Begin\n"); + // TODO: error! + } + SetDebugNameD3D11 (decl, "InputLayoutImmediate"); + m_ImmVertexDeclMap.insert(std::make_pair(inputSig, decl)); + + return decl; +} + +void VertexDeclarationsD3D11::Clear() +{ + g_ActiveInputLayoutD3D11 = NULL; + + for (VertexDeclMap::iterator it = m_VertexDeclMap.begin(); it != m_VertexDeclMap.end(); ++it) + { + if (it->second) { + ULONG refCount = it->second->Release(); + AssertIf( refCount != 0 ); + } + } + m_VertexDeclMap.clear(); + + for (ImmVertexDeclMap::iterator it = m_ImmVertexDeclMap.begin(); it != m_ImmVertexDeclMap.end(); ++it) + { + if (it->second) { + ULONG refCount = it->second->Release(); + AssertIf( refCount != 0 ); + } + } + m_ImmVertexDeclMap.clear(); +} + + +const InputSignatureD3D11* VertexDeclarationsD3D11::GetShaderInputSignature (void* code, unsigned length) +{ + DXBCChunkHeader* isigChunk = dxbc_find_chunk (code, length, kFOURCC_ISGN); + DebugAssert (isigChunk); + if (!isigChunk) + return NULL; + + InputSignatureD3D11 isig; + dxbc_create (&isigChunk, 1, isig.blob); + + InputSignatures::iterator it = m_InputSignatures.insert(isig).first; + return &(*it); +} diff --git a/Runtime/GfxDevice/d3d11/VertexDeclarationsD3D11.h b/Runtime/GfxDevice/d3d11/VertexDeclarationsD3D11.h new file mode 100644 index 0000000..cd7e981 --- /dev/null +++ b/Runtime/GfxDevice/d3d11/VertexDeclarationsD3D11.h @@ -0,0 +1,51 @@ +#pragma once + +#include "D3D11Includes.h" +#include "Runtime/Filters/Mesh/VertexData.h" +#include "Runtime/Utilities/dynamic_array.h" +#include <map> + +struct InputSignatureD3D11 +{ + dynamic_array<UInt8> blob; + bool operator < (const InputSignatureD3D11& o) const + { + size_t sizeA = blob.size(); + size_t sizeB = o.blob.size(); + if (sizeA != sizeB) + return sizeA < sizeB; + int res = memcmp (blob.data(), o.blob.data(), sizeA); + return res < 0; + } +}; + +class VertexDeclarationsD3D11 +{ +public: + VertexDeclarationsD3D11(); + ~VertexDeclarationsD3D11(); + + ID3D11InputLayout* GetVertexDecl( UInt32 shaderChannelsMap, void* vertexShaderCode, unsigned vertexShaderLength, bool streamOutSkin = false, unsigned int bonesPerVertex = 4 ); + ID3D11InputLayout* GetVertexDecl (const ChannelInfoArray& channels, const InputSignatureD3D11* inputSig, bool streamOutSkin = false, unsigned int bonesPerVertex = 4); + ID3D11InputLayout* GetImmVertexDecl (const InputSignatureD3D11* inputSig); + void Clear(); + + const InputSignatureD3D11* GetShaderInputSignature (void* code, unsigned length); + +private: + typedef std::set<InputSignatureD3D11> InputSignatures; + InputSignatures m_InputSignatures; + + struct KeyType + { + bool operator < (const KeyType& rhs) const; + ChannelInfoArray channels; + const InputSignatureD3D11* inputSig; + UInt32 extraBits; + }; + typedef UNITY_MAP(kMemVertexData, KeyType, ID3D11InputLayout*) VertexDeclMap; + VertexDeclMap m_VertexDeclMap; + + typedef UNITY_MAP(kMemVertexData, const InputSignatureD3D11*, ID3D11InputLayout*) ImmVertexDeclMap; + ImmVertexDeclMap m_ImmVertexDeclMap; +}; diff --git a/Runtime/GfxDevice/null/GfxDeviceNull.cpp b/Runtime/GfxDevice/null/GfxDeviceNull.cpp new file mode 100644 index 0000000..4981f54 --- /dev/null +++ b/Runtime/GfxDevice/null/GfxDeviceNull.cpp @@ -0,0 +1,251 @@ +#include "UnityPrefix.h" +#include "GfxDeviceNull.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Graphics/RenderSurface.h" +#include "GfxNullVBO.h" +#include "Runtime/GfxDevice/GfxDeviceWindow.h" +#include "External/shaderlab/Library/program.h" + + +static DeviceBlendState g_NullBlendState; +static DeviceDepthState g_NullDepthState; +static DeviceStencilState g_NullStencilState; +static DeviceRasterState g_NullRasterState; + +static float g_NullWorldMatrix[16]; +static float g_NullViewMatrix[16]; +static float g_NullProjectionMatrix[16]; + +static RenderSurfaceBase _ColorDefaultSurface; +static RenderSurfaceBase _DepthDefaultSurface; + + +void GraphicsCaps::InitNull(void) +{ + rendererString = "Null Device"; + vendorString = "Unity Technologies"; + driverVersionString = "1.0"; + fixedVersionString = "NULL 1.0 [1.0]"; + driverLibraryString = "(null)"; + videoMemoryMB = 64.0f; + rendererID = 0; + vendorID = 0; + + printf_console( "NullGfxDevice:\n" ); + printf_console( " Version: %s\n", fixedVersionString.c_str() ); + printf_console( " Renderer: %s\n", rendererString.c_str() ); + printf_console( " Vendor: %s\n", vendorString.c_str() ); + + shaderCaps = kShaderLevel2; + + maxLights = 8; + hasAnisoFilter = false; + maxAnisoLevel = 0; + hasMipLevelBias = false; + + hasMultiSample = false; + + hasBlendSquare = false; + hasSeparateAlphaBlend = false; + + hasS3TCCompression = false; + + hasAutoMipMapGeneration = false; + + maxTexImageUnits = 2; + maxTexCoords = 2; + + + maxTexUnits = 2; + + maxTextureSize = 1024; + maxCubeMapSize = 0; + maxRenderTextureSize = 0; + + for (int i = 0; i < kRTFormatCount; ++i) + { + supportsRenderTextureFormat[i] = false; + } + + has3DTexture = false; + npotRT = npot = kNPOTNone; + + hasRenderToTexture = false; + hasRenderToCubemap = false; + hasRenderTargetStencil = false; + hasTwoSidedStencil = false; + hasHighPrecisionTextureCombiners = false; + hasNativeDepthTexture = false; + hasStencilInDepthTexture = false; + hasNativeShadowMap = false; + + needsToSwizzleVertexColors = false; +} + + +GfxDevice* CreateNullGfxDevice() +{ + ::gGraphicsCaps.InitNull(); + + return UNITY_NEW_AS_ROOT(GfxDeviceNull(), kMemGfxDevice, "NullGfxDevice",""); +} + +GfxDeviceNull::GfxDeviceNull(void) +: dynamicVBO(NULL) +{ + InvalidateState(); + ResetFrameStats(); + + m_Renderer = kGfxRendererNull; + m_UsesOpenGLTextureCoords = false; + m_UsesHalfTexelOffset = false; + m_MaxBufferedFrames = -1; // no limiting + + RenderSurfaceBase_InitColor(_ColorDefaultSurface); + _ColorDefaultSurface.backBuffer = true; + SetBackBufferColorSurface(&_ColorDefaultSurface); + + RenderSurfaceBase_InitDepth(_DepthDefaultSurface); + _DepthDefaultSurface.backBuffer = true; + SetBackBufferDepthSurface(&_DepthDefaultSurface); +} + +GfxDeviceNull::~GfxDeviceNull(void) +{ + delete this->dynamicVBO; +} + +void GfxDeviceNull::GetMatrix( float outMatrix[16] ) const +{ + for( int i = 0; i < 16; ++i ) + outMatrix[i] = 0.0f; +} + + +void GfxDeviceNull::GetViewport( int* port ) const +{ + AssertIf(!port); + port[0] = 0; + port[1] = 0; + port[2] = 1; + port[3] = 1; +} + + +void GfxDeviceNull::GetScissorRect( int scissor[4] ) const +{ + AssertIf(!scissor); + scissor[0] = 0; + scissor[1] = 0; + scissor[2] = 1; + scissor[3] = 1; +} + +TextureCombinersHandle GfxDeviceNull::CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) +{ + return TextureCombinersHandle(this); // just have to pass non-NULL to the handle +} + +void GfxDeviceNull::DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ) +{ + textureCombiners.Reset(); +} + +void GfxDeviceNull::DestroySubProgram( ShaderLab::SubProgram* subprogram ) +{ + delete subprogram; +} + +VBO* GfxDeviceNull::CreateVBO() +{ + VBO* vbo = new GfxNullVBO(); + OnCreateVBO(vbo); + return vbo; +} + +void GfxDeviceNull::DeleteVBO( VBO* vbo ) +{ + AssertIf(!vbo); + OnDeleteVBO(vbo); + delete vbo; +} + +DynamicVBO& GfxDeviceNull::GetDynamicVBO() +{ + if (NULL == this->dynamicVBO) + { + this->dynamicVBO = new GfxDynamicNullVBO(); + } + + return *this->dynamicVBO; +} + + + +bool GfxDeviceNull::CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ) +{ + return true; +} + + +bool GfxDeviceNull::ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) +{ + return true; +} + +DeviceBlendState* GfxDeviceNull::CreateBlendState(const GfxBlendState& state) +{ + return & g_NullBlendState; +} + +DeviceDepthState* GfxDeviceNull::CreateDepthState(const GfxDepthState& state) +{ + return & g_NullDepthState; +} + +DeviceStencilState* GfxDeviceNull::CreateStencilState(const GfxStencilState& state) +{ + return & g_NullStencilState; +} + +DeviceRasterState* GfxDeviceNull::CreateRasterState(const GfxRasterState& state) +{ + return & g_NullRasterState; +} + +const float* GfxDeviceNull::GetWorldMatrix() const +{ + return g_NullWorldMatrix; +} + +const float* GfxDeviceNull::GetViewMatrix() const +{ + return g_NullViewMatrix; +} + +const float* GfxDeviceNull::GetProjectionMatrix() const +{ + return g_NullProjectionMatrix; +} + + + +RenderSurfaceHandle GfxDeviceNull::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) +{ + return RenderSurfaceHandle(&_ColorDefaultSurface); +} +RenderSurfaceHandle GfxDeviceNull::CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) +{ + return RenderSurfaceHandle(&_DepthDefaultSurface); +} + +// -------- editor only functions + +#if UNITY_EDITOR + +GfxDeviceWindow* GfxDeviceNull::CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) +{ + return new GfxDeviceWindow(window,width, height, depthFormat, antiAlias); +} + +#endif diff --git a/Runtime/GfxDevice/null/GfxDeviceNull.h b/Runtime/GfxDevice/null/GfxDeviceNull.h new file mode 100644 index 0000000..d96d016 --- /dev/null +++ b/Runtime/GfxDevice/null/GfxDeviceNull.h @@ -0,0 +1,158 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDevice.h" + + + +class GfxDeviceNull : public GfxDevice +{ +public: + GfxDeviceNull(); + GFX_API ~GfxDeviceNull(); + + GFX_API void InvalidateState() { } + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState() { } + #endif + + GFX_API void Clear (UInt32 clearFlags, const float color[4], float depth, int stencil) { } + GFX_API void SetUserBackfaceMode( bool enable ) { } + GFX_API void SetWireframe(bool wire) { } + GFX_API bool GetWireframe() const { return false; } + GFX_API void SetInvertProjectionMatrix( bool enable ) { } + GFX_API bool GetInvertProjectionMatrix() const { return false; } + + GFX_API void SetWorldMatrix( const float matrix[16] ) {}; + GFX_API void SetViewMatrix( const float matrix[16] ) {}; + GFX_API void SetProjectionMatrix (const Matrix4x4f& matrix) { } + GFX_API void GetMatrix( float outMatrix[16] ) const; + + GFX_API const float* GetWorldMatrix() const; + GFX_API const float* GetViewMatrix() const; + GFX_API const float* GetProjectionMatrix() const; + GFX_API const float* GetDeviceProjectionMatrix() const { return GetProjectionMatrix(); } + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ) { } + GFX_API void SetAlpha( BlendMode src, BlendMode dst, CompareFunction mode, float value, bool alphaToMask ) { } + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) {} + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) { } + GFX_API void SetColor( const float color[4] ) { } + GFX_API void SetViewport( int x, int y, int width, int height ) { } + GFX_API void GetViewport( int* port ) const; + + GFX_API void SetScissorRect( int x, int y, int width, int height ) { } + GFX_API void DisableScissor() { } + GFX_API bool IsScissorEnabled() const { return false; } + GFX_API void GetScissorRect( int values[4] ) const; + GFX_API void DiscardContents (RenderSurfaceHandle& rs) {} + + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& texturesCombiners ); + GFX_API void SetTextureCombiners( TextureCombinersHandle texturesCombiners, const ShaderLab::PropertySheet* props ) { } + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) { } + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) { } + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]) { } + GFX_API void SetTextureName ( TextureID texture, const char* name ) { } + + GFX_API void SetShadersMainThread( ShaderLab::SubProgram* programs[kShaderTypeCount], const ShaderLab::PropertySheet* props ) { } + GFX_API bool IsShaderActive( ShaderType type ) const { return false; } + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ); + + GFX_API void DisableLights( int startLight ) { } + GFX_API void SetLight( int light, const GfxVertexLight& data) { } + GFX_API void SetAmbient( const float ambient[4] ) { } + + GFX_API void EnableFog (const GfxFogParams& fog) { } + GFX_API void DisableFog() { } + + GFX_API GPUSkinningInfo *CreateGPUSkinningInfo() { return NULL; } + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info) { AssertBreak(false); } + GFX_API void SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ) { AssertBreak(false); } + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) { AssertBreak(false); } + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) { AssertBreak(false); } + + GFX_API VBO* CreateVBO(); + GFX_API void DeleteVBO( VBO* vbo ); + GFX_API DynamicVBO& GetDynamicVBO(); + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags); + GFX_API RenderSurfaceHandle CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags); + GFX_API void DestroyRenderSurface (RenderSurfaceHandle& rs) {} + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face = kCubeFaceUnknown) {} + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) { } + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface (int index) { return RenderSurfaceHandle(); } + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface () { return RenderSurfaceHandle(); } + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags) { } + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) { } + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) { } + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) { } + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) { } + GFX_API void DeleteTexture( TextureID texture ) { } + + GFX_API PresentMode GetPresentMode() { return kPresentBeforeUpdate; } + + GFX_API void BeginFrame() { m_InsideFrame = true; } + GFX_API void EndFrame() { m_InsideFrame = false; } + GFX_API void PresentFrame() { } + GFX_API bool IsValidState() { return true; } + + GFX_API void FinishRendering() { } + + // Immediate mode rendering + GFX_API void ImmediateVertex( float x, float y, float z ) { } + GFX_API void ImmediateNormal( float x, float y, float z ) { } + GFX_API void ImmediateColor( float r, float g, float b, float a ) { } + GFX_API void ImmediateTexCoordAll( float x, float y, float z ) { } + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ) { } + GFX_API void ImmediateBegin( GfxPrimitiveType type ) { } + GFX_API void ImmediateEnd() { } + + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ); + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); + GFX_API void GrabIntoRenderTexture( RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ) { } + + GFX_API void BeforeDrawCall( bool immediateMode ) { } + + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef) {} + GFX_API void SetRasterState(const DeviceRasterState* state) {} + GFX_API void SetDepthState(const DeviceDepthState* state) {} + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef) {}; + GFX_API void SetSRGBWrite (const bool) {}; + GFX_API bool GetSRGBWrite () {return false;}; + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state); + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state); + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state); + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state); + + GFX_API bool IsPositionRequiredForTexGen (int texStageIndex) const { return false; } + GFX_API bool IsNormalRequiredForTexGen (int texStageIndex) const { return false; } + GFX_API bool IsPositionRequiredForTexGen() const { return false; } + GFX_API bool IsNormalRequiredForTexGen() const { return false; } + + GFX_API int GetCurrentTargetWidth() const { return 0; } + GFX_API int GetCurrentTargetHeight() const { return 0; } + GFX_API void SetCurrentTargetSize(int width, int height) { } + + #if ENABLE_PROFILER + GFX_API GfxTimerQuery* CreateTimerQuery() { return NULL; } + GFX_API void DeleteTimerQuery(GfxTimerQuery* query) {} + GFX_API void BeginTimerQueries() {} + GFX_API void EndTimerQueries() {} + #endif + #if UNITY_EDITOR + GFX_API void SetAntiAliasFlag( bool aa ) { } + GFX_API void DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ) { } + GFX_API int GetCurrentTargetAA() const { return 0; } + GFX_API GfxDeviceWindow* CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) ; + #endif + #if GFX_USES_VIEWPORT_OFFSET + GFX_API void SetViewportOffset( float x, float y ){ } + GFX_API void GetViewportOffset( float &x, float &y ) const{ x = y = 0; } + #endif + +private: + DynamicVBO *dynamicVBO; +}; diff --git a/Runtime/GfxDevice/null/GfxNullVBO.cpp b/Runtime/GfxDevice/null/GfxNullVBO.cpp new file mode 100644 index 0000000..b624160 --- /dev/null +++ b/Runtime/GfxDevice/null/GfxNullVBO.cpp @@ -0,0 +1,107 @@ +#include "UnityPrefix.h" +#include "Runtime/Shaders/VBO.h" +#include "GfxNullVBO.h" +#include "Runtime/GfxDevice/GfxDevice.h" + + + +void GfxNullVBO::UpdateVertexData( const VertexBufferData& buffer ) +{ + BufferAccessibleVertexData(buffer); + } + +void GfxNullVBO::UpdateIndexData (const IndexBufferData& buffer) +{ +} + +void GfxNullVBO::DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ) +{ +} +#if GFX_ENABLE_DRAW_CALL_BATCHING + void GfxNullVBO::DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ) + { + } +#endif + + +bool GfxDynamicNullVBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ) +{ + AssertIf(this->m_LendedChunk); + AssertIf((maxVertices >= 65536) || (maxIndices >= (65536 * 3))); + bool indexed = IsIndexed(renderMode); + DebugAssertIf(indexed && (outIB == NULL)); + DebugAssertIf(!indexed && ((maxIndices != 0) || (outIB != NULL))); + + this->m_LendedChunk = true; + this->m_LastChunkShaderChannelMask = shaderChannelMask; + this->m_LastRenderMode = renderMode; + + if (maxVertices == 0) + { + maxVertices = 8; + } + + this->m_LastChunkStride = 0; + + for (int i = 0; i < kShaderChannelCount; ++i) + { + if (shaderChannelMask & (1 << i)) + { + this->m_LastChunkStride += GfxNullVBO::GetDefaultChannelByteSize(i); + } + } + + // + + DebugAssertIf(NULL == outVB); + + UInt32 vbCapacity = (maxVertices * this->m_LastChunkStride); + + if (vbCapacity > this->vertexBufferSize) + { + delete[] this->vertexBuffer; + this->vertexBuffer = new UInt8[vbCapacity]; + this->vertexBufferSize = vbCapacity; + } + + *outVB = this->vertexBuffer; + + // + + if (maxIndices && indexed) + { + UInt32 ibCapacity = maxIndices * kVBOIndexSize; + + if (ibCapacity > this->indexBufferSize) + { + delete[] this->indexBuffer; + this->indexBuffer = new UInt8[ibCapacity]; + this->indexBufferSize = ibCapacity; + } + + *outIB = this->indexBuffer; + } + + // + + return true; +} + +void GfxDynamicNullVBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ) +{ + AssertIf(!m_LendedChunk); + this->m_LendedChunk = false; + + this->m_LastChunkVertices = actualVertices; + this->m_LastChunkIndices = actualIndices; + + if (!actualVertices || (IsIndexed(m_LastRenderMode) && !actualIndices)) + { + this->m_LastChunkShaderChannelMask = 0; + } +} + +void GfxDynamicNullVBO::DrawChunk (const ChannelAssigns& channels) +{ +} diff --git a/Runtime/GfxDevice/null/GfxNullVBO.h b/Runtime/GfxDevice/null/GfxNullVBO.h new file mode 100644 index 0000000..ce4d0fa --- /dev/null +++ b/Runtime/GfxDevice/null/GfxNullVBO.h @@ -0,0 +1,55 @@ +#pragma once + +#include "Runtime/Shaders/BufferedVBO.h" + + +class GfxNullVBO : public BufferedVBO +{ +public: + inline GfxNullVBO(void) {} + virtual ~GfxNullVBO(void) {} + + virtual void UpdateVertexData( const VertexBufferData& buffer ); + virtual void UpdateIndexData (const IndexBufferData& buffer); + virtual void DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ); + #if GFX_ENABLE_DRAW_CALL_BATCHING + virtual void DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ); + #endif + + virtual bool IsVertexBufferLost() const { return false; } + + virtual int GetRuntimeMemorySize() const { return 0; } +}; + + + +class GfxDynamicNullVBO : + public DynamicVBO +{ +private: + UInt8 *vertexBuffer; + UInt32 vertexBufferSize; + UInt8 *indexBuffer; + UInt32 indexBufferSize; + +public: + inline GfxDynamicNullVBO(void) : + vertexBuffer(NULL), + vertexBufferSize(0), + indexBuffer(NULL), + indexBufferSize(0) + { + } + + virtual ~GfxDynamicNullVBO(void) + { + delete[] this->vertexBuffer; + delete[] this->indexBuffer; + } + + virtual bool GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ); + virtual void ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ); + virtual void DrawChunk (const ChannelAssigns& channels); + +};
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengl/ARBVBO.cpp b/Runtime/GfxDevice/opengl/ARBVBO.cpp new file mode 100644 index 0000000..f90415b --- /dev/null +++ b/Runtime/GfxDevice/opengl/ARBVBO.cpp @@ -0,0 +1,611 @@ +#include "UnityPrefix.h" +#include "ARBVBO.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "GLAssert.h" +#include "ChannelsGL.h" +#include "UnityGL.h" +#include "Runtime/GfxDevice/GfxDevice.h" + +#include "Runtime/Misc/Allocator.h" + + +extern GLenum kTopologyGL[kPrimitiveTypeCount]; + + +// ----------------------------------------------------------------------------- + +// 0 = no stats, 1 = overview stats, 2 = detailed stats +#define DEBUG_GL_VBO 0 + +#if DEBUG_GL_VBO == 2 +#define LOGVBO(x) printf_console( "vbo: " x "\n" ) +#else +#define LOGVBO(x) +#endif + + + +#if DEBUG_GL_VBO +static int gActiveVBOs = 0; +static int gActiveVBs = 0; +static int gActiveIBs = 0; +static int gUpdatedVBs = 0; +static int gUpdatedIBs = 0; +#endif + + +// In VBOs, the pointers are just offsets. Just fill start +// of VBO with this number of bytes so that the real offsets are never null. +const int kDummyVBStartBytes = 32; + + +// Cache the current vertex/index buffers. Don't ever call +// glBindBuffer from anywhere, always use these calls! +// Also make sure to call UnbindVertexBuffersGL() whenever you're starting +// immediate mode rendering or drawing from plain arrays. + +static int s_VBOCurrentVB = 0; +static int s_VBOCurrentIB = 0; + +void BindARBVertexBuffer( int id ) +{ + if( s_VBOCurrentVB != id ) + { + OGL_CALL(glBindBufferARB( GL_ARRAY_BUFFER_ARB, id )); + s_VBOCurrentVB = id; + } + + #if GFX_DEVICE_VERIFY_ENABLE + #ifndef DUMMY_OPENGL_CALLS + int glbuffer; + glGetIntegerv( GL_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != id ) + { + ErrorString( Format( "VBO vertex buffer binding differs from cache (%i != %i)\n", glbuffer, id ) ); + } + #endif + #endif +} + +void BindARBIndexBuffer( int id ) +{ + if( s_VBOCurrentIB != id ) + { + OGL_CALL(glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, id )); + s_VBOCurrentIB = id; + } + + #if GFX_DEVICE_VERIFY_ENABLE + #ifndef DUMMY_OPENGL_CALLS + int glbuffer; + glGetIntegerv( GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != id ) + { + ErrorString( Format( "VBO index buffer binding differs from cache (%i != %i)\n", glbuffer, id ) ); + } + #endif + #endif +} + +void UnbindVertexBuffersGL() +{ + OGL_CALL(glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 )); + OGL_CALL(glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 )); + s_VBOCurrentVB = 0; + s_VBOCurrentIB = 0; +} + + +// ----------------------------------------------------------------------------- + +ARBVBO::ARBVBO() +: m_VertexCount(0) +, m_VertexBindID(0) +, m_IndexBindID(0) +, m_VBSize(0) +, m_IBSize(0) +{ +} + +ARBVBO::~ARBVBO () +{ + if( m_VertexBindID ) + { + if (m_VertexBindID == s_VBOCurrentVB) + s_VBOCurrentVB = 0; + + glDeleteBuffersARB( 1, (GLuint*)&m_VertexBindID ); + } + + if( m_IndexBindID ) + { + if (m_IndexBindID == s_VBOCurrentIB) + s_VBOCurrentIB = 0; + + glDeleteBuffersARB( 1, (GLuint*)&m_IndexBindID ); + } +} + +void ARBVBO::VerifyVertexBuffer() +{ + #if GFX_DEVICE_VERIFY_ENABLE && !defined(DUMMY_OPENGL_CALLS) + int glbuffer; + glGetIntegerv( GL_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != s_VBOCurrentVB ) + { + ErrorString( Format( "VBO vertex buffer binding differs from cache (%i != %i)\n", glbuffer, s_VBOCurrentVB ) ); + } + glGetIntegerv( GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != s_VBOCurrentIB ) + { + ErrorString( Format( "VBO vertex buffer binding differs from cache (%i != %i)\n", glbuffer, s_VBOCurrentIB ) ); + } + #endif +} + + +void ARBVBO::UpdateIndexBufferData (const IndexBufferData& sourceData) +{ + if( !sourceData.indices ) + { + return; + } + + LOGVBO( "Update IB" ); + UInt8* buffer = (UInt8*)glMapBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB ); + if( !buffer ) + { + LOGVBO( "Error mapping IB!" ); + return; // TBD: error! + } + + // Setup index buffer + memcpy (buffer, sourceData.indices, sourceData.count * kVBOIndexSize); + + glUnmapBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB ); + + #if GFX_DEVICE_VERIFY_ENABLE && !defined(DUMMY_OPENGL_CALLS) + int glbuffer; + glGetIntegerv( GL_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != s_VBOCurrentVB ) + { + ErrorString( Format( "VBO vertex buffer binding differs from cache (%i != %i)\n", glbuffer, s_VBOCurrentVB ) ); + } + glGetIntegerv( GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != s_VBOCurrentIB ) + { + ErrorString( Format( "VBO vertex buffer binding differs from cache (%i != %i)\n", glbuffer, s_VBOCurrentIB ) ); + } + #endif +} + +bool ARBVBO::MapVertexStream( VertexStreamData& outData, unsigned stream ) +{ + Assert(stream == 0); + DebugAssertIf( m_VertexBindID == 0 ); + AssertIf( m_IsStreamMapped[stream] ); + m_IsStreamMapped[stream] = true; + const StreamInfo& info = m_Streams[stream]; + int streamSize = m_VertexCount * info.stride; + + LOGVBO( "Map VB" ); + BindARBVertexBuffer( m_VertexBindID ); + + // Check if there are other streams in buffer + bool mapRange = false; + for (int s = 0; s < kMaxVertexStreams && !mapRange; s++) + if (s != stream && m_Streams[s].channelMask) + mapRange = true; + + bool isDynamic = (m_StreamModes[stream] != kStreamModeDynamic); + + UInt8* buffer = NULL; + if (!UNITY_OSX && gGraphicsCaps.gl.hasArbMapBufferRange) + { + GLbitfield access = GL_MAP_WRITE_BIT; + if (isDynamic) + { + // With streams we invalidate the range but preserve the rest of the buffer + access |= mapRange ? GL_MAP_INVALIDATE_RANGE_BIT : GL_MAP_INVALIDATE_BUFFER_BIT; + } + buffer = (UInt8*)glMapBufferRange( GL_ARRAY_BUFFER_ARB, info.offset, streamSize, access ); + } + else + { + // Wipe vertex buffer if we rewrite the whole thing + if (isDynamic && !mapRange) + glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_VBSize, NULL, GL_DYNAMIC_DRAW_ARB ); + + #if UNITY_OSX + // Enable explicit flushing of modified data + if (gGraphicsCaps.gl.hasAppleFlushBufferRange) + glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); + #endif + + buffer = (UInt8*)glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB ); + + // We got the start of the buffer so apply offset + if (buffer) + buffer += info.offset; + } + + if( !buffer ) + { + LOGVBO( "Error mapping VB!" ); + return false; + } + + outData.buffer = buffer; + outData.channelMask = info.channelMask; + outData.stride = info.stride; + outData.vertexCount = m_VertexCount; + + #if GFX_DEVICE_VERIFY_ENABLE && !defined(DUMMY_OPENGL_CALLS) + int glbuffer; + glGetIntegerv( GL_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != s_VBOCurrentVB ) + { + ErrorString( Format( "VBO vertex buffer binding differs from cache (%i != %i)\n", glbuffer, s_VBOCurrentVB ) ); + } + glGetIntegerv( GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, &glbuffer ); + if( glbuffer != s_VBOCurrentIB ) + { + ErrorString( Format( "VBO vertex buffer binding differs from cache (%i != %i)\n", glbuffer, s_VBOCurrentIB ) ); + } + #endif + + GetRealGfxDevice().GetFrameStats().AddUploadVBO( streamSize ); + + return true; +} + +void ARBVBO::UnmapVertexStream( unsigned stream ) +{ + AssertIf( !m_IsStreamMapped[stream] ); + m_IsStreamMapped[stream] = false; + + // Important: bind the needed buffer. Mostly because of multithreaded skinning, the code does not necessarily + // follow the pattern of bind,map,unmap, bind,map,unmap. + BindARBVertexBuffer( m_VertexBindID ); + + #if UNITY_OSX + // We disabled implicit flushing on unmap, explicitly flush the range we wrote to + const StreamInfo& info = m_Streams[stream]; + int streamSize = m_VertexCount * info.stride; + if (gGraphicsCaps.gl.hasAppleFlushBufferRange) + glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER, info.offset, streamSize); + #endif + + glUnmapBufferARB( GL_ARRAY_BUFFER_ARB ); +} + + +void ARBVBO::DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ) +{ + // just return if no indices + if (m_IBSize == 0) + return; + + BindARBIndexBuffer( m_IndexBindID ); + + // With an index buffer bound OpenGL interprets pointer as an offset + DrawInternal(channels, reinterpret_cast<const void*>(firstIndexByte), indexCount, topology, vertexCount); +} + +void ARBVBO::DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ) +{ + BindARBIndexBuffer( 0 ); + + DrawInternal(channels, indices, indexCount, topology, drawVertexCount); +} + +void ARBVBO::DrawInternal( const ChannelAssigns& channels, const void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 drawVertexCount ) +{ + // setup VBO + DebugAssertIf( IsAnyStreamMapped() ); + DebugAssertIf( m_VertexBindID == 0 || m_IndexBindID == 0 ); + + BindARBVertexBuffer( m_VertexBindID ); + + ClearActiveChannelsGL(); + UInt32 targetMap = channels.GetTargetMap(); + for( int i = 0; i < kVertexCompCount; ++i ) + { + if( !( targetMap & (1<<i) ) ) + continue; + ShaderChannel src = channels.GetSourceForTarget( (VertexComponent)i ); + if( !m_Channels[src].IsValid() ) + continue; + + SetChannelDataGL( m_Channels[src], m_Streams, (VertexComponent)i ); + } + GfxDevice& device = GetRealGfxDevice(); + ActivateChannelsGL(); + device.BeforeDrawCall( false ); + + // draw + UInt16* indices16 = (UInt16*)indices; + static UInt32 maxIndices = 63000/6*6; + // must render in multiples of 3 (triangles) and 2 (tri strips) + UInt32 offset = 0; + while( offset < indexCount ) + { + int drawIndices = std::min( indexCount - offset, maxIndices ); + OGL_CALL(glDrawElements(kTopologyGL[topology], drawIndices, GL_UNSIGNED_SHORT, &indices16[offset] )); + offset += drawIndices; + if (offset < indexCount) + { + if (topology == kPrimitiveTriangleStripDeprecated) + offset -= 2; // primitives overlap by 2 indices + else if (topology == kPrimitiveLineStrip) + offset -= 1; // primitives overlap by 2 indices + } + } + + device.GetFrameStats().AddDrawCall (GetPrimitiveCount(indexCount, topology, true), drawVertexCount); +} + + + +void ARBVBO::UpdateVertexData( const VertexBufferData& buffer ) +{ + std::copy(buffer.channels, buffer.channels + kShaderChannelCount, m_Channels); + std::copy(buffer.streams, buffer.streams + kMaxVertexStreams, m_Streams); + + int bufferMode = GL_STATIC_DRAW_ARB; + // Use dynamic if uploading the second time + // Or when forced to dynamic + if (GetVertexStreamMode(0) == kStreamModeNoAccess && m_VertexBindID) + bufferMode = GL_DYNAMIC_DRAW_ARB; + else if (GetVertexStreamMode(0) == kStreamModeDynamic) + bufferMode = GL_DYNAMIC_DRAW_ARB; + + if( !m_VertexBindID ) + glGenBuffersARB( 1, (GLuint*)&m_VertexBindID ); + + BindARBVertexBuffer( m_VertexBindID ); + glBufferDataARB( GL_ARRAY_BUFFER_ARB, buffer.bufferSize, buffer.buffer, bufferMode ); + GetRealGfxDevice().GetFrameStats().AddUploadVBO( buffer.bufferSize ); + m_VBSize = buffer.bufferSize; + m_VertexCount = buffer.vertexCount; + + VerifyVertexBuffer(); + + DebugAssertIf(m_VertexBindID == 0); +} + +void ARBVBO::UpdateIndexData (const IndexBufferData& buffer) +{ + int buffersize = CalculateIndexBufferSize(buffer); + m_IBSize = buffersize; + + if (m_IBSize == 0) + { + Assert (buffer.count == 0); + return; + } + + if( !m_IndexBindID ) + { + // initially, generate buffer, set its size and static usage + glGenBuffersARB( 1, (GLuint*)&m_IndexBindID ); + BindARBIndexBuffer( m_IndexBindID ); + glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_IBSize, NULL, GL_STATIC_DRAW_ARB ); + GetRealGfxDevice().GetFrameStats().AddUploadIB( m_IBSize ); + } + else + { + // discard old and rebuild whole buffer + #if DEBUG_GL_VBO + ++gUpdatedIBs; + #endif + BindARBIndexBuffer( m_IndexBindID ); + glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_IBSize, NULL, GL_DYNAMIC_DRAW_ARB ); // discard old and mark new as dynamic + GetRealGfxDevice().GetFrameStats().AddUploadIB( m_IBSize ); + } + + UpdateIndexBufferData(buffer); + DebugAssertIf(m_IndexBindID == 0); +} + + +// ----------------------------------------------------------------------------- + +#if 0 // see comment in header file + +DynamicARBVBO::DynamicARBVBO( UInt32 vbSize ) +: DynamicVBO() +, m_VBSize(vbSize) +, m_VBUsedBytes(0) +, m_VertexBindID(0) +, m_VBChunkSize(0) +, m_IBChunk(NULL) +, m_IBChunkSize(0) +{ +} + +DynamicARBVBO::~DynamicARBVBO () +{ + if( m_VertexBindID ) + glDeleteBuffersARB( 1, (GLuint*)&m_VertexBindID ); + delete[] m_IBChunk; +} + +void DynamicARBVBO::DrawChunk (const ChannelAssigns& channels) +{ + // just return if nothing to render + if( !m_LastChunkShaderChannelMask ) + return; + + AssertIf( !m_LastChunkShaderChannelMask || !m_LastChunkStride ); + AssertIf( m_LendedChunk ); + + // setup VBO + DebugAssertIf( m_VertexBindID == 0 ); + + BindARBIndexBuffer( 0 ); + BindARBVertexBuffer( m_VertexBindID ); + + ClearActiveChannelsGL(); + UInt32 targetMap = channels.GetTargetMap(); + for( int i = 0; i < kVertexCompCount; ++i ) + { + if( !( targetMap & (1<<i) ) ) + continue; + ShaderChannel src = channels.GetSourceForTarget( (VertexComponent)i ); + if( !( m_LastChunkShaderChannelMask & (1<<src) ) ) + continue; + + SetChannelDataGL( src, (VertexComponent)i, reinterpret_cast<const void*>(m_BufferChannelOffsets[src]), m_LastChunkStride ); + } + GfxDevice& device = GetRealGfxDevice(); + ActivateChannelsGL(); + device.BeforeDrawCall( false ); + + // draw + GfxDeviceStats& stats = device.GetFrameStats(); + int primCount = 0; + if( m_LastRenderMode == kDrawTriangleStrip ) + { + OGL_CALL(glDrawArrays( GL_TRIANGLE_STRIP, 0, m_LastChunkVertices )); + primCount = m_LastChunkVertices-2; + } + else if (m_LastRenderMode == kDrawQuads) + { + OGL_CALL(glDrawArrays( GL_QUADS, 0, m_LastChunkVertices )); + primCount = m_LastChunkVertices/2; + } + else + { + DebugAssertIf( !m_IBChunk ); + OGL_CALL(glDrawElements( GL_TRIANGLES, m_LastChunkIndices, GL_UNSIGNED_SHORT, m_IBChunk )); + primCount = (m_LastRenderMode == kDrawIndexedTriangleStrip) ? m_LastChunkIndices-2 : m_LastChunkIndices/3; + } + stats.AddDrawCall (primCount, m_LastChunkVertices); + + GLAssert(); +} + +bool DynamicARBVBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ) +{ + AssertIf( m_LendedChunk ); + AssertIf( maxVertices >= 65536 || maxIndices >= 65536*3 ); + DebugAssertIf( renderMode == kDrawIndexedTriangles && outIB == NULL ); + DebugAssertIf( renderMode != kDrawIndexedTriangles && (maxIndices != 0 || outIB != NULL) ); + + m_LendedChunk = true; + m_LastChunkShaderChannelMask = shaderChannelMask; + m_LastRenderMode = renderMode; + if( maxVertices == 0 ) + maxVertices = 8; + + m_LastChunkStride = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( shaderChannelMask & (1<<i) ) + m_LastChunkStride += VBO::GetChannelByteSize(i); + } + + DebugAssertIf( !outVB ); + UInt32 vbCapacity = maxVertices * m_LastChunkStride; + + bool resizeVB = false; + if( !m_VertexBindID ) { + // generate buffer + glGenBuffersARB( 1, (GLuint*)&m_VertexBindID ); + resizeVB = true; + m_VBUsedBytes = 0; + } + + // check if requested chunk is larger than current buffer + if( vbCapacity > m_VBSize ) { + m_VBSize = vbCapacity * 2; // allocate more up front + resizeVB = true; + m_VBUsedBytes = 0; + } + + // if we'll be past the end of buffer, restart from beginning and discard the old one + if( m_VBUsedBytes + vbCapacity > m_VBSize ) { + resizeVB = true; + } + + // initialize or resize or discard the buffer + BindARBVertexBuffer( m_VertexBindID ); + if( resizeVB ) { + glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_VBSize + kDummyVBStartBytes, NULL, GL_DYNAMIC_DRAW_ARB ); + #if UNITY_OSX + if (gGraphicsCaps.gl.hasAppleFlushBufferRange) { + glBufferParameteriAPPLE(GL_ARRAY_BUFFER, GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); + } + #endif + m_VBUsedBytes = 0; + } + + // map the buffer + UInt8* buffer = (UInt8*)glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB ); + if( !buffer ) { + LOGVBO( "Error mapping VB!" ); + *outVB = NULL; + m_LendedChunk = false; + return false; + } + + *outVB = buffer + kDummyVBStartBytes + m_VBUsedBytes; + + if( maxIndices && renderMode == kDrawIndexedTriangles ) + { + UInt32 ibCapacity = maxIndices * kVBOIndexSize; + if( ibCapacity > m_IBChunkSize ) + { + delete[] m_IBChunk; + m_IBChunk = new UInt8[ ibCapacity ]; + m_IBChunkSize = ibCapacity; + } + *outIB = m_IBChunk; + } + return true; +} + +void DynamicARBVBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ) +{ + AssertIf( !m_LendedChunk ); + AssertIf( actualIndices % 3 != 0 ); + m_LendedChunk = false; + + m_LastChunkVertices = actualVertices; + m_LastChunkIndices = actualIndices; + + AssertIf (!m_VertexBindID); + BindARBVertexBuffer( m_VertexBindID ); + + UInt32 actualVBSize = actualVertices * m_LastChunkStride; + #if UNITY_OSX + if (gGraphicsCaps.gl.hasAppleFlushBufferRange) { + glFlushMappedBufferRangeAPPLE(GL_ARRAY_BUFFER_ARB, kDummyVBStartBytes + m_VBUsedBytes, actualVBSize); + } + #endif + + glUnmapBufferARB( GL_ARRAY_BUFFER_ARB ); + + if( !actualVertices || (m_LastRenderMode == kDrawIndexedTriangles && !actualIndices) ) { + m_LastChunkShaderChannelMask = 0; + return; + } + + // -------- Vertex buffer + + size_t channelOffset = kDummyVBStartBytes + m_VBUsedBytes; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( m_LastChunkShaderChannelMask & (1<<i) ) { + m_BufferChannelOffsets[i] = channelOffset; + channelOffset += VBO::GetChannelByteSize(i); + } + } + m_VBUsedBytes += actualVBSize; + + GLAssert(); +} + +#endif diff --git a/Runtime/GfxDevice/opengl/ARBVBO.h b/Runtime/GfxDevice/opengl/ARBVBO.h new file mode 100644 index 0000000..f9513f4 --- /dev/null +++ b/Runtime/GfxDevice/opengl/ARBVBO.h @@ -0,0 +1,75 @@ +#pragma once + +#include "Runtime/Shaders/VBO.h" + +void BindARBVertexBuffer( int id ); +void BindARBIndexBuffer( int id ); + +// Implements VBO through ARB_vertex_buffer_object. +class ARBVBO : public VBO { +public: + ARBVBO(); + virtual ~ARBVBO(); + + virtual void UpdateVertexData( const VertexBufferData& buffer ); + virtual void UpdateIndexData (const IndexBufferData& buffer); + virtual void DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount); + virtual void DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ); + virtual int GetRuntimeMemorySize() const { return m_VBSize + m_IBSize; } + + virtual bool MapVertexStream( VertexStreamData& outData, unsigned stream ); + virtual void UnmapVertexStream( unsigned stream ); + virtual bool IsVertexBufferLost() const { return false; } + + +private: + void DrawInternal( const ChannelAssigns& channels, const void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 drawVertexCount ); + void VerifyVertexBuffer(); + void UpdateIndexBufferData (const IndexBufferData& sourceData); + +private: + ChannelInfoArray m_Channels; + int m_VertexCount; + int m_VertexBindID; + int m_IndexBindID; + int m_VBSize; + int m_IBSize; +}; + + +#if 0 + +// Ok, dynamic VBOs with updating just the chunks with BufferSubData seem to be slower (by 30% - 50%) +// than just rendering from memory arrays. This is on MacBook Pro RX1600 (10.4.9), MBP GeForce8600 (10.5.7) +// and PC GeForce 6800 (93.xx). Using APPLE_flush_buffer_range does not help with performance. +// So we just don't use them for now! + +// This is dynamic vertex buffer, with index buffer just fed from memory. +// The reason is that BufferSubData on index buffers is really buggy on some drivers +// (e.g. Mac OS X 10.4.8/10.4.9 on X1600). +class DynamicARBVBO : public DynamicVBO { +public: + DynamicARBVBO( UInt32 vbSize ); + virtual ~DynamicARBVBO(); + + virtual bool GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ); + virtual void ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ); + virtual void DrawChunk (const ChannelAssigns& channels); + +private: + size_t m_BufferChannelOffsets[kShaderChannelCount]; + + UInt32 m_VBSize; + UInt32 m_VBUsedBytes; + + int m_VertexBindID; + UInt32 m_VBChunkSize; + UInt8* m_IBChunk; + UInt32 m_IBChunkSize; +}; + +#endif + diff --git a/Runtime/GfxDevice/opengl/ArbGpuProgamGL.cpp b/Runtime/GfxDevice/opengl/ArbGpuProgamGL.cpp new file mode 100644 index 0000000..18a5e10 --- /dev/null +++ b/Runtime/GfxDevice/opengl/ArbGpuProgamGL.cpp @@ -0,0 +1,458 @@ +#include "UnityPrefix.h" +#include "ArbGpuProgamGL.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Math/Vector4.h" +#include "UnityGL.h" +#include "GLAssert.h" +#include "External/shaderlab/Library/texenv.h" +#include "Runtime/Utilities/Word.h" + +unsigned int GetGLShaderImplTarget( ShaderImplType implType ); // GfxDeviceGL.cpp +void InvalidateActiveShaderStateGL( ShaderType type ); // GfxDeviceGL.cpp + + +/* +For ARB fragment programs on OS X, Intel, ATI cards, cache some first parameter values and +use Env paramters instead of Local ones. +Otherwise OS X 10.4.10 will insist on recompiling some shaders behind the scenes, or +some other funky stuff - which will make shadows be extremely slow: + + From: Aras Pranckevicius <aras@otee.dk> + To: Michel Castejon <mcast@apple.com> + Date: Jul 3, 2007 11:35 AM + <...> + On my MacBookPro/X1600 it gives 14 FPS with the glProgramLocalParameter4fv call, and 77 FPS + without the call. That call is the only difference between the two cases - when drawing the + objects receiving the shadow, the call sets the [1] local parameter (and the parameter is not + actually used anywhere). The call does not actually change the value, i.e. it always sets it to + {0.3, 0.7, 0.05, -4}. + + So, issuing this glProgramLocalParameter4fv that does not change the value of a local parameter + that is not actually used, makes each glDrawElements take about 1.3 milliseconds (from GL profiler + trace). If this call is not made, then each glDrawElements takes about 0.025 milliseconds (after + the first draw with the shader one which is longer). I can't really tell what's happening from + the Shark profile, as the difference is somewhere in the driver where I have no symbols. + <...> + +BUT do not do this on PPC Macs, Windows or other cards on Intel Macs. On PPC Macs using Env paramters +will make shadows completely randomly disappear. Oh the joy! +*/ + +const int kFPParamCacheSize = 32; // don't make this larger than 32 (won't fit into s_FPParamCacheValid mask) +UInt32 s_FPParamCacheValid = 0; +Vector4f s_FPParamCache[kFPParamCacheSize]; + +void InvalidateFPParamCacheGL() +{ + s_FPParamCacheValid = 0; +} + + +ArbGpuProgram::ArbGpuProgram( const std::string& source, ShaderType type, ShaderImplType implType ) +{ + for (int i = 0; i < kFogModeCount; ++i) + m_FogFailed[i] = false; + m_ImplType = implType; + if( !Create(source,type) ) + m_NotSupported = true; +} + +ArbGpuProgram::~ArbGpuProgram () +{ + for (int i = 0; i < kFogModeCount; ++i) + { + if (m_Programs[i] != 0) + { + glDeleteProgramsARB (1, &m_Programs[i]); + } + } +} + + +static std::string PreprocessARBShader( const std::string& source, ShaderImplType implType ) +{ + std::string processed; + processed = source; + + // Remove ARB precision hint if it's broken on this GPU + if( gGraphicsCaps.gl.buggyArbPrecisionHint ) + { + std::string::size_type pos; + while ((pos = processed.find ("OPTION ARB_precision_hint_fastest")) != std::string::npos) + { + std::string::size_type end = processed.find ("\n", pos); + if (end != std::string::npos) + processed.erase (pos, end - pos); + } + } + + // In fragment programs on hardware where we have to use&cache Env params instead of Local + // ones, do replacement in the shader. + if( implType == kShaderImplFragment && gGraphicsCaps.gl.cacheFPParamsWithEnvs ) + { + std::string kProgramLocal( "program.local" ); + std::string kProgramEnv( "program.env" ); + size_t pos = processed.find( kProgramLocal ); + while( pos != std::string::npos ) + { + processed.erase( pos, kProgramLocal.size() ); + processed.insert( pos, kProgramEnv ); + pos = processed.find( kProgramLocal, pos ); + } + } + + return processed; +} + + +bool ArbGpuProgram::Create( const std::string& source, ShaderType type ) +{ + // We specially prefix ARB shaders that are compiled for SM3.0-like limits. If a shader is + // prefixed this way, we can quickly skip loading & compiling it by just checking graphics caps. + // Saves from weird driver bugs, does not spam the log and is faster. + bool isShaderModel3 = false; + if( !strncmp (source.c_str(), "3.0-!!", 6) ) + { + if( gGraphicsCaps.shaderCaps < kShaderLevel3 ) + return false; + isShaderModel3 = true; + } + + m_GpuProgramLevel = isShaderModel3 ? kGpuProgramSM3 : kGpuProgramSM2; + + GLAssert(); // Clear any GL errors + + GLenum target = GetGLShaderImplTarget( m_ImplType ); + glGenProgramsARB (1, &m_Programs[0]); + glBindProgramARB (target, m_Programs[0]); + InvalidateActiveShaderStateGL( type ); + std::string processed = PreprocessARBShader( source, m_ImplType ); + + glProgramStringARB( target, GL_PROGRAM_FORMAT_ASCII_ARB, processed.size() - (isShaderModel3?4:0), processed.c_str() + (isShaderModel3?4:0) ); + + // Check for errors + GLint errorPos; + glGetIntegerv( GL_PROGRAM_ERROR_POSITION_ARB, &errorPos ); + if( errorPos != -1 ) + { + printf_console( "ARB shader compile error: %s for %s\n", glGetString (GL_PROGRAM_ERROR_STRING_ARB), processed.c_str() ); + int errorCounter = 0; + while( errorCounter < 10 && glGetError () != GL_NO_ERROR ) // prevent infinite loops for bad drivers + { + ++errorCounter; + } + + glDeleteProgramsARB (1, &m_Programs[0]); + m_Programs[0] = 0; + return false; + } + + m_SourceForFog = processed.c_str() + (isShaderModel3?4:0); + + return true; +} + +void ArbGpuProgram::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + GLenum target = GetGLShaderImplTarget( m_ImplType ); + + if( m_ImplType == kShaderImplFragment && gGraphicsCaps.gl.cacheFPParamsWithEnvs ) + { + // If we are fragment program and have to cache parameters, do that + // Apply vector and matrix parameters with cache + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for( GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i ) + { + if (i->m_RowCount == 1 && i->m_ArraySize == 1) + { + const Vector4f& val = *reinterpret_cast<const Vector4f*>(buffer); + int idx = i->m_Index; + UInt32 mask = 1 << idx; + if( idx >= kFPParamCacheSize ) + { + OGL_CALL(glProgramEnvParameter4fvARB( target, idx, val.GetPtr() )); + } + else + { + if( !(s_FPParamCacheValid & mask) || s_FPParamCache[idx] != val ) + { + OGL_CALL(glProgramEnvParameter4fvARB( target, idx, val.GetPtr() )); + s_FPParamCache[idx] = val; + } + s_FPParamCacheValid |= mask; + #if GFX_DEVICE_VERIFY_ENABLE + Vector4f testVal; + OGL_CALL(glGetProgramEnvParameterfvARB( target, idx, testVal.GetPtr() )); + if( s_FPParamCache[idx] != testVal ) + ErrorString( Format("FP local cache mismatch at index %i", idx) ); + #endif + } + buffer += sizeof(Vector4f); + } + else + { + // Apply matrix parameters, with cache + DebugAssert(i->m_RowCount == 4); + int size = *reinterpret_cast<const int*> (buffer); buffer += sizeof(int); + DebugAssert (size == 16); + const Matrix4x4f* val = reinterpret_cast<const Matrix4x4f*>(buffer); + const float *ptr = val->GetPtr(); + int idx = i->m_Index; + s_FPParamCacheValid &= ~(15 << idx); // mark 4 consecutive parameters as invalid in the cache + OGL_CALL(glProgramEnvParameter4fARB( target, idx+0, ptr[0], ptr[4], ptr[8], ptr[12] )); + OGL_CALL(glProgramEnvParameter4fARB( target, idx+1, ptr[1], ptr[5], ptr[9], ptr[13] )); + OGL_CALL(glProgramEnvParameter4fARB( target, idx+2, ptr[2], ptr[6], ptr[10], ptr[14] )); + OGL_CALL(glProgramEnvParameter4fARB( target, idx+3, ptr[3], ptr[7], ptr[11], ptr[15] )); + buffer += size * sizeof(float); + } + } + } + else + { + // Otherwise we are not FP or we don't have to cache - do the usual code path + + // Apply vector and matrix parameters + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for( GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i ) + { + if( i->m_RowCount == 1 ) + { + const Vector4f& val = *reinterpret_cast<const Vector4f*>(buffer); + OGL_CALL(glProgramLocalParameter4fvARB( target, i->m_Index, val.GetPtr() )); + buffer += sizeof(Vector4f); + } + else + { + DebugAssert(i->m_RowCount == 4); + int size = *reinterpret_cast<const int*> (buffer); buffer += sizeof(int); + DebugAssert (size == 16); + const Matrix4x4f* val = reinterpret_cast<const Matrix4x4f*>(buffer); + const float *ptr = val->GetPtr(); + OGL_CALL(glProgramLocalParameter4fARB( target, i->m_Index+0, ptr[0], ptr[4], ptr[8], ptr[12] )); + OGL_CALL(glProgramLocalParameter4fARB( target, i->m_Index+1, ptr[1], ptr[5], ptr[9], ptr[13] )); + OGL_CALL(glProgramLocalParameter4fARB( target, i->m_Index+2, ptr[2], ptr[6], ptr[10], ptr[14] )); + OGL_CALL(glProgramLocalParameter4fARB( target, i->m_Index+3, ptr[3], ptr[7], ptr[11], ptr[15] )); + buffer += size * sizeof(float); + } + } + } + + // Apply textures for fragment programs + if (m_ImplType == kShaderImplFragment) + { + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + const GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for( GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i ) + { + const GpuProgramParameters::TextureParameter& t = *i; + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + ApplyTexEnvData (t.m_Index, t.m_SamplerIndex, *texdata); + buffer += sizeof(*texdata); + } + } +} + + + +// -------------------------------------------------------------------------- +// ARB patching for fog + +#define DEBUG_FOG_PATCHING 0 + +static inline bool IsNewline( char c ) { return c == '\n' || c == '\r'; } + +bool PatchVertexShaderFogARB (std::string& src) +{ + #if DEBUG_FOG_PATCHING + printf_console ("ARB fog patching: original vertex shader:\n%s\n", src.c_str()); + #endif + + if (src.find("result.fogcoord") != std::string::npos) + return false; // already has hardcoded fog mode + + // find write to result.position, and do the same for result.fogcoord + size_t posWrite = src.find ("result.position.z"); + bool writesFullPos = false; + if (posWrite == std::string::npos) + { + posWrite = src.find ("result.position"); + if (posWrite == std::string::npos) + { + DebugAssert (!"couldn't find write to result.position"); + return false; + } + writesFullPos = true; + } + + // get whole line + size_t n = src.size(); + size_t posWriteStart = posWrite, posWriteEnd = posWrite; + while (posWriteStart > 0 && !IsNewline(src[posWriteStart])) --posWriteStart; + ++posWriteStart; + while (posWriteEnd < n && !IsNewline(src[posWriteEnd])) ++posWriteEnd; + + std::string instr = src.substr (posWriteStart, posWriteEnd-posWriteStart); + if (writesFullPos) + { + replace_string (instr, "result.position", "result.fogcoord", 0); + instr.resize(instr.size()-1); + instr += ".z;"; + } + else + { + replace_string (instr, "result.position.z", "result.fogcoord", 0); + } + instr += '\n'; + + // insert fog code just after write to position + src.insert (posWriteEnd+1, instr); + + #if DEBUG_FOG_PATCHING + printf_console ("ARB fog patching: after patching:\n%s\n", src.c_str()); + #endif + return true; +} + +bool PatchPixelShaderFogARB (std::string& src, FogMode fog) +{ + #if DEBUG_FOG_PATCHING + printf_console ("ARB fog patching: original pixel shader:\n%s\n", src.c_str()); + #endif + + if (src.find("OPTION ARB_fog_") != std::string::npos) + return false; // already has hardcoded fog mode + + // skip until next line after !!ARBfp1.0 + size_t pos = src.find("!!ARBfp1.0"); + if (pos == std::string::npos) + return false; // something is wrong + pos += 10; // skip !!ARBfp1.0 + + size_t n = src.size(); + while (pos < n && !IsNewline(src[pos])) ++pos; // skip until newline + while (pos < n && IsNewline(src[pos])) ++pos; // skip newlines + if (pos >= n) + return false; + + // insert fog option + static const char* kFogOptions[kFogModeCount] = {"", "OPTION ARB_fog_linear;\n", "OPTION ARB_fog_exp;\n", "OPTION ARB_fog_exp2;\n"}; + src.insert (pos, kFogOptions[fog]); + + #if DEBUG_FOG_PATCHING + printf_console ("ARB fog patching: after patching, fog mode %d:\n%s\n", fog, src.c_str()); + #endif + return true; +} + +GLShaderID ArbGpuProgram::GetGLProgram (FogMode fog) +{ + int index = 0; + if (fog > kFogDisabled && !m_SourceForFog.empty() && !m_FogFailed[fog]) + { + index = fog; + Assert (index >= 0 && index < kFogModeCount); + + // create patched fog program if needed + if (!m_Programs[index]) + { + std::string src = m_SourceForFog; + if (m_ImplType == kShaderImplFragment && PatchPixelShaderFogARB (src, fog)) + { + // create program + glGenProgramsARB (1, &m_Programs[index]); + glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, m_Programs[index]); + InvalidateActiveShaderStateGL (kShaderFragment); + glProgramStringARB (GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, src.size(), src.c_str()); + GLint errorPos; + glGetIntegerv( GL_PROGRAM_ERROR_POSITION_ARB, &errorPos ); + if (errorPos != -1) + { + glDeleteProgramsARB (1, &m_Programs[index]); + m_Programs[index] = 0; + m_FogFailed[index] = true; + index = 0; + } + } + else if (m_ImplType == kShaderImplVertex && PatchVertexShaderFogARB (src)) + { + // create program + glGenProgramsARB (1, &m_Programs[index]); + glBindProgramARB (GL_VERTEX_PROGRAM_ARB, m_Programs[index]); + InvalidateActiveShaderStateGL (kShaderVertex); + glProgramStringARB (GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, src.size(), src.c_str()); + GLint errorPos; + glGetIntegerv( GL_PROGRAM_ERROR_POSITION_ARB, &errorPos ); + if (errorPos != -1) + { + glDeleteProgramsARB (1, &m_Programs[index]); + m_Programs[index] = 0; + m_FogFailed[index] = true; + index = 0; + } + } + else + { + m_FogFailed[index] = true; + index = 0; + } + } + } + return m_Programs[index]; +} + +// -------------------------------------------------------------------------- + +#if ENABLE_UNIT_TESTS + +#include "External/UnitTest++/src/UnitTest++.h" + +SUITE (ShaderPatchingARBTests) +{ + TEST(PatchVSZWrite) + { + std::string s; + s = "!!ARBvp1.0\n" + "DP4 result.position.z, vertex.position, c[0];\n" + "END"; + CHECK (PatchVertexShaderFogARB(s)); + CHECK_EQUAL( + "!!ARBvp1.0\n" + "DP4 result.position.z, vertex.position, c[0];\n" + "DP4 result.fogcoord, vertex.position, c[0];\n" + "END", s); + } + TEST(PatchVSFullWrite) + { + std::string s; + s = "!!ARBvp1.0\n" + "MOV result.position, vertex.position;\n" + "END"; + CHECK (PatchVertexShaderFogARB(s)); + CHECK_EQUAL( + "!!ARBvp1.0\n" + "MOV result.position, vertex.position;\n" + "MOV result.fogcoord, vertex.position.z;\n" + "END", s); + } + TEST(PatchVSWriteNotAtEnd) + { + std::string s; + s = "!!ARBvp1.0\n" + "MOV result.position, R0;\n" + "MOV R0, R1;\n" + "END"; + CHECK (PatchVertexShaderFogARB(s)); + CHECK_EQUAL( + "!!ARBvp1.0\n" + "MOV result.position, R0;\n" + "MOV result.fogcoord, R0.z;\n" + "MOV R0, R1;\n" + "END", s); + } + +} // SUITE + +#endif // ENABLE_UNIT_TESTS diff --git a/Runtime/GfxDevice/opengl/ArbGpuProgamGL.h b/Runtime/GfxDevice/opengl/ArbGpuProgamGL.h new file mode 100644 index 0000000..404c3e7 --- /dev/null +++ b/Runtime/GfxDevice/opengl/ArbGpuProgamGL.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Runtime/GfxDevice/GpuProgram.h" + +class ArbGpuProgram : public GpuProgramGL { +public: + ArbGpuProgram( const std::string& source, ShaderType type, ShaderImplType implType ); + virtual ~ArbGpuProgram(); + + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); + + GLShaderID GetGLProgram(FogMode fog); + +private: + bool Create( const std::string& source, ShaderType type ); + +private: + bool m_FogFailed[kFogModeCount]; +}; diff --git a/Runtime/GfxDevice/opengl/ChannelsGL.cpp b/Runtime/GfxDevice/opengl/ChannelsGL.cpp new file mode 100644 index 0000000..3b4f275 --- /dev/null +++ b/Runtime/GfxDevice/opengl/ChannelsGL.cpp @@ -0,0 +1,252 @@ +#include "UnityPrefix.h" +#include "ChannelsGL.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "UnityGL.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "GLAssert.h" + +// dimensionality of the different channels (element count) +static const int kDefaultChannelSizes[kShaderChannelCount] = { + 3, // pos + 3, // normal + 4, // color + 2, // uv + 2, // uv2 + 4, // tangent +}; + +static const GLenum kDefaultChannelTypes[kShaderChannelCount] = { + GL_FLOAT, // pos + GL_FLOAT, // normal + GL_UNSIGNED_BYTE, // color + GL_FLOAT, // UV0 + GL_FLOAT, // UV1 + GL_FLOAT, // tangent +}; + + +static void SetVertexComponentData( VertexComponent comp, int size, unsigned int type, int stride, const void *pointer ) +{ + // We allow pointer to be used as an offset + //DebugAssertIf( !pointer ); + + switch (comp) { + case kVertexCompColor: + OGL_CALL(glColorPointer (size, type, stride, pointer)); + break; + case kVertexCompVertex: + OGL_CALL(glVertexPointer (size, type, stride, pointer)); + break; + case kVertexCompNormal: + DebugAssert( size >= 3 ); + OGL_CALL(glNormalPointer (type, stride, pointer)); + break; + case kVertexCompTexCoord0: + case kVertexCompTexCoord1: + case kVertexCompTexCoord2: + case kVertexCompTexCoord3: + case kVertexCompTexCoord4: + case kVertexCompTexCoord5: + case kVertexCompTexCoord6: + case kVertexCompTexCoord7: + if (gGraphicsCaps.maxTexCoords > 1) { + OGL_CALL(glClientActiveTextureARB( GL_TEXTURE0_ARB + comp - kVertexCompTexCoord0 )); + } + OGL_CALL(glTexCoordPointer (size, type, stride, pointer)); + break; + case kVertexCompTexCoord: + printf_console( "Warning: unspecified texcoord bound\n" ); + break; + case kVertexCompAttrib0: case kVertexCompAttrib1: case kVertexCompAttrib2: case kVertexCompAttrib3: + case kVertexCompAttrib4: case kVertexCompAttrib5: case kVertexCompAttrib6: case kVertexCompAttrib7: + case kVertexCompAttrib8: case kVertexCompAttrib9: case kVertexCompAttrib10: case kVertexCompAttrib11: + case kVertexCompAttrib12: case kVertexCompAttrib13: case kVertexCompAttrib14: case kVertexCompAttrib15: + OGL_CALL(glVertexAttribPointerARB( comp - kVertexCompAttrib0, size, type, true, stride, pointer )); + break; + } +} + +static signed char s_EnabledVertexComps[kVertexCompCount]; // 0/1 or -1 if unknown +static unsigned int s_EnabledTargetsMask; // Bitfield of which targets are currently valid + +void ClearActiveChannelsGL() +{ + s_EnabledTargetsMask = 0; +} + +static UInt32 GetGLType(const ChannelInfo& source) +{ + switch (source.format) + { + case kChannelFormatFloat: return GL_FLOAT; + case kChannelFormatFloat16: return GL_HALF_FLOAT_ARB; + case kChannelFormatColor: return GL_UNSIGNED_BYTE; + case kChannelFormatByte: return GL_BYTE; + } + ErrorString("Unknown channel format!"); + return 0; +} + +static int GetGLDimension(const ChannelInfo& source) +{ + return (source.format == kChannelFormatColor) ? 4 : source.dimension; +} + +void SetChannelDataGL( const ChannelInfo& source, const StreamInfoArray streams, VertexComponent target, const UInt8* buffer ) +{ + AssertIf( target == kVertexCompNone || target == kVertexCompTexCoord ); + int stride = source.CalcStride( streams ); + int offset = source.CalcOffset( streams ); + SetVertexComponentData( target, GetGLDimension(source), GetGLType(source), stride, buffer + offset ); + s_EnabledTargetsMask |= (1 << target); +} + +void SetChannelDataGL( ShaderChannel source, VertexComponent target, const void *pointer, int stride ) +{ + AssertIf( source == kShaderChannelNone ); + if( !pointer ) + return; + + DebugAssertIf( target == kVertexCompNone || target == kVertexCompTexCoord ); + SetVertexComponentData( target, kDefaultChannelSizes[source], kDefaultChannelTypes[source], stride, pointer ); + s_EnabledTargetsMask |= (1 << target); +} + +#if UNITY_EDITOR +// only used by GizmoUtil in the editor +void SetChannelDataGL( ShaderChannel source, const ChannelAssigns& channels, const void *pointer, int stride ) +{ + AssertIf( source == kShaderChannelNone ); + if( !pointer ) + return; + + for( int i = 0; i < kVertexCompCount; ++i ) + { + if( channels.GetSourceForTarget( (VertexComponent)i ) == source ) + { + AssertIf( i == kVertexCompNone || i == kVertexCompTexCoord ); + SetVertexComponentData( (VertexComponent)i, kDefaultChannelSizes[source], kDefaultChannelTypes[source], stride, pointer ); + s_EnabledTargetsMask |= (1 << i); + } + } +} + +#endif + + +void ActivateChannelsGL() +{ + unsigned int compMask = s_EnabledTargetsMask; + int i; + + // fetch now to prevent aliasing + GLint vaCount = gGraphicsCaps.gl.vertexAttribCount; + //GLint texUnitCount = gGraphicsCaps.maxTexUnits; + GLint texCoordCount = gGraphicsCaps.maxTexCoords; + + static GLenum gltargets[] = { 0, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_NORMAL_ARRAY }; + + // There's a dark corner of GL spec that says that generic and conventional vertex + // attributes (and arrays) may be aliased (most decent drivers don't alias them). + // http://oss.sgi.com/projects/ogl-sample/registry/NV/vertex_program.txt + // + // So we first disable all vertex components that we don't use; then enable all + // that we do use. This should work both in aliased and non-aliased implementations. + // + // On some systems (XP, Catalyst 5.7, R9600) this makes a difference! + // Without it e.g. a single GUIText is not visible. + + // -------------------------------- + // First disable components we don't use + + for( i = kVertexCompVertex; i <= kVertexCompNormal; ++i ) + { + if( !(compMask & (1<<i)) ) + { + if( s_EnabledVertexComps[i] != 0 ) + { + OGL_CALL(glDisableClientState( gltargets[i] )); + s_EnabledVertexComps[i] = 0; + } + } + } + + for( i = 0; i < texCoordCount; ++i ) + { + int compIndex = kVertexCompTexCoord0 + i; + if( !(compMask & (1 << compIndex)) ) + { + if( s_EnabledVertexComps[compIndex] != 0 ) + { + if( texCoordCount > 1 ) + OGL_CALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + i)); + OGL_CALL(glDisableClientState (GL_TEXTURE_COORD_ARRAY)); + s_EnabledVertexComps[compIndex] = 0; + } + } + } + + for( i = 0; i < vaCount; ++i ) + { + int compIndex = kVertexCompAttrib0 + i; + if( !(compMask & (1 << compIndex)) ) + { + if( s_EnabledVertexComps[compIndex] != 0 ) + { + OGL_CALL(glDisableVertexAttribArrayARB (i)); + s_EnabledVertexComps[compIndex] = 0; + } + } + } + + // -------------------------------- + // Then enable components we use + + for( i = kVertexCompVertex; i <= kVertexCompNormal; ++i ) + { + if( compMask & (1<<i) ) + { + if( s_EnabledVertexComps[i] != 1 ) + { + OGL_CALL(glEnableClientState( gltargets[i] )); + s_EnabledVertexComps[i] = 1; + } + } + } + + for( i = 0; i < texCoordCount; ++i ) + { + int compIndex = kVertexCompTexCoord0 + i; + if( compMask & (1 << compIndex) ) + { + if( s_EnabledVertexComps[compIndex] != 1 ) + { + if( texCoordCount > 1 ) + OGL_CALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + i)); + OGL_CALL(glEnableClientState (GL_TEXTURE_COORD_ARRAY)); + s_EnabledVertexComps[compIndex] = 1; + } + } + } + + for( i = 0; i < vaCount; ++i ) + { + int compIndex = kVertexCompAttrib0 + i; + if( compMask & (1 << compIndex) ) + { + if( s_EnabledVertexComps[compIndex] != 1 ) + { + OGL_CALL(glEnableVertexAttribArrayARB( i )); + s_EnabledVertexComps[compIndex] = 1; + } + } + } + + GLAssert(); +} + +void InvalidateChannelStateGL() +{ + for( int i = 0; i < kVertexCompCount; ++i ) + s_EnabledVertexComps[i] = -1; +} diff --git a/Runtime/GfxDevice/opengl/ChannelsGL.h b/Runtime/GfxDevice/opengl/ChannelsGL.h new file mode 100644 index 0000000..43e7cad --- /dev/null +++ b/Runtime/GfxDevice/opengl/ChannelsGL.h @@ -0,0 +1,17 @@ +#ifndef __CHANNELS_GL_H__ +#define __CHANNELS_GL_H__ + +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/Filters/Mesh/VertexData.h" + +void ClearActiveChannelsGL(); +void SetChannelDataGL( const ChannelInfo& source, const StreamInfoArray streams, VertexComponent target, const UInt8* buffer = NULL ); +void SetChannelDataGL( ShaderChannel source, VertexComponent target, const void *pointer, int stride ); +#if UNITY_EDITOR +void SetChannelDataGL( ShaderChannel source, const ChannelAssigns& channels, const void *pointer, int stride ); +#endif +void ActivateChannelsGL(); +void InvalidateChannelStateGL(); + +#endif diff --git a/Runtime/GfxDevice/opengl/CombinerGL.cpp b/Runtime/GfxDevice/opengl/CombinerGL.cpp new file mode 100644 index 0000000..4ed2ab9 --- /dev/null +++ b/Runtime/GfxDevice/opengl/CombinerGL.cpp @@ -0,0 +1,201 @@ +#include "UnityPrefix.h" +#include "CombinerGL.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "UnityGL.h" +#include "GLAssert.h" +#include "External/shaderlab/Library/pass.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +static const unsigned int kCombinerFuncTable[] = { + GL_REPLACE, GL_MODULATE, GL_ADD, GL_ADD_SIGNED_ARB, GL_SUBTRACT_ARB, GL_INTERPOLATE_ARB, GL_DOT3_RGB_ARB, GL_DOT3_RGBA_ARB +}; +static const unsigned int kCombinerBlendFuncTableATI[4] = { + GL_INTERPOLATE_ARB, GL_MODULATE_ADD_ATI, GL_MODULATE_SIGNED_ADD_ATI, GL_MODULATE_SUBTRACT_ATI +}; +static const unsigned int kCombinerBlendFuncTableNV[4] = { + GL_INTERPOLATE_ARB, GL_ADD, GL_ADD_SIGNED_EXT, 0 +}; +static const unsigned int kCombinerSourceTable[4] = { + GL_PREVIOUS_ARB, GL_TEXTURE, GL_CONSTANT_ARB, GL_PRIMARY_COLOR_ARB +}; +static const unsigned int kCombinerOperandTable[4] = { + GL_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA +}; + + +bool TextureCombinersGL::IsCombineModeSupported( unsigned int combiner ) +{ + int cf = COMBINER_GET_FUNC(combiner); + if( cf & combiner::kBlendFuncMask ) + { + int blendF = COMBINER_GET_BLEND_FUNC_INDEX(cf); + if( blendF != 0 ) // anything other than GL_INTERPOLATE_ARB requires extension + { + if( gGraphicsCaps.gl.hasTextureEnvCombine3ATI ) + return true; + if( gGraphicsCaps.gl.hasTextureEnvCombine3NV && blendF != 3 ) // NV fallback can't do a*b-c + return true; + return false; + } + } + + return true; +} + +void ApplyCombinerGL( unsigned int& currentCombColor, unsigned int& currentCombAlpha, unsigned int combcolor, unsigned int combalpha ) +{ + // only change combiner color setup if different from the cached version. + if( currentCombColor != combcolor ) + { + // Handle RGB + int s0 = (combcolor >> combiner::kSrcZeroShift) & 0xFF; + int cf = COMBINER_GET_FUNC(combcolor); + int s1 = (combcolor) & 0xFF; + + GLint source0 = kCombinerSourceTable[s0 & combiner::kSourceMask]; + GLint oper0 = kCombinerOperandTable[s0 >> combiner::kOperandShift]; + GLint source1 = kCombinerSourceTable[s1 & combiner::kSourceMask]; + GLint oper1 = kCombinerOperandTable[s1 >> combiner::kOperandShift]; + + OGL_CALL(glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB)); + if( !(cf & combiner::kBlendFuncMask) ) + { + OGL_CALL(glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, kCombinerFuncTable[cf])); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, source0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, oper0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, source1 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, oper1 )); + } + else + { + int blendF = COMBINER_GET_BLEND_FUNC_INDEX(cf); + int src2 = cf & combiner::kSourceMask; + int oper2 = ((cf & combiner::kOperandTwo) >> combiner::kOperandShift) | 1; + if( blendF == 0 || gGraphicsCaps.gl.hasTextureEnvCombine3ATI ) + { + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, source0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, oper0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, source1 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, oper1 )); + + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, kCombinerBlendFuncTableATI[blendF] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, kCombinerSourceTable[src2] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, kCombinerOperandTable[oper2] )); + } + else + { + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV )); + + // TNT combiners use a different argument order than ARB/ATI combiners... + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, source0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, oper0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, source1 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, oper1 )); + + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, kCombinerBlendFuncTableNV[blendF] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, kCombinerSourceTable[src2] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, kCombinerOperandTable[oper2] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE3_RGB_NV, GL_ZERO )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND3_RGB_NV, GL_ONE_MINUS_SRC_COLOR )); + } + } + OGL_CALL(glTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (combcolor >> combiner::kScaleShift) )); + + currentCombColor = combcolor; + } + + // only change combiner alpha setup if different from the cached version. + if( currentCombAlpha != combalpha ) + { + // Handle alpha + int s0 = (combalpha >> combiner::kSrcZeroShift) & 0xFF; + int cf = COMBINER_GET_FUNC(combalpha); + int s1 = (combalpha) & 0xFF; + if ((cf & 7) == 6) // dot3 combiner doesn't touch alpha, so use just source0 + cf = 0; + + GLint source0 = kCombinerSourceTable[s0 & combiner::kSourceMask]; + GLint oper0 = kCombinerOperandTable[(s0 >> combiner::kOperandShift)|1]; + GLint source1 = kCombinerSourceTable[s1 & combiner::kSourceMask]; + GLint oper1 = kCombinerOperandTable[(s1 >> combiner::kOperandShift)|1]; + + if (!(cf & combiner::kBlendFuncMask)) + { + OGL_CALL(glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, kCombinerFuncTable[cf])); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, source0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, oper0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, source1 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, oper1 )); + } + else + { + int blendF = COMBINER_GET_BLEND_FUNC_INDEX(cf); + int src2 = cf & combiner::kSourceMask; + int oper2 = ((cf & combiner::kOperandTwo) >> combiner::kOperandShift) | 1; + if( blendF == 0 || gGraphicsCaps.gl.hasTextureEnvCombine3ATI ) + { + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, source0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, oper0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, source1 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, oper1 )); + + OGL_CALL(glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, kCombinerBlendFuncTableATI[blendF])); + OGL_CALL(glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, kCombinerSourceTable[src2])); + OGL_CALL(glTexEnvi (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, kCombinerOperandTable[oper2])); + } + else + { + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV )); + + // TNT combiners use a different argument order than ARB/ATI combiners... + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, source0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, oper0 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_ARB, source1 )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_ARB, oper1 )); + + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, kCombinerBlendFuncTableNV[blendF] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, kCombinerSourceTable[src2] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, kCombinerOperandTable[oper2] )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE3_ALPHA_NV, GL_ZERO )); + OGL_CALL(glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND3_ALPHA_NV, GL_ONE_MINUS_SRC_ALPHA )); + } + } + OGL_CALL(glTexEnvf( GL_TEXTURE_ENV, GL_ALPHA_SCALE, (combalpha >> combiner::kScaleShift))); + + currentCombAlpha = combalpha; + } + GLAssert(); +} + + +TextureCombinersGL* TextureCombinersGL::Create( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props ) +{ + // check if supported + if( count > gGraphicsCaps.maxTexUnits ) + return NULL; + + // TODO: move this to client thread for threaded rendering + for( int i = 0; i < count; ++i ) + if( !IsCombineModeSupported( texEnvs[i].m_CombColor ) ) + return NULL; + + // For threaded rendering this check is done on the client side (and we get NULL here) + if( props ) { + for( int i = 0; i < count; ++i ) { + TextureDimension texDim; + TexGenMode texGen; + GetTexEnvInfoFromName( texEnvs[i].m_TextureName, texDim, texGen, props ); + if( !ShaderLab::IsTexEnvSupported( texEnvs[i].m_TextureName, texDim, texGen ) ) + return NULL; + } + } + + // create + TextureCombinersGL* combiners = new TextureCombinersGL(); + combiners->count = count; + combiners->texEnvs = texEnvs; + return combiners; +} + diff --git a/Runtime/GfxDevice/opengl/CombinerGL.h b/Runtime/GfxDevice/opengl/CombinerGL.h new file mode 100644 index 0000000..fcc1307 --- /dev/null +++ b/Runtime/GfxDevice/opengl/CombinerGL.h @@ -0,0 +1,18 @@ +#pragma once + +namespace ShaderLab { + struct TextureBinding; + class PropertySheet; +} + + +struct TextureCombinersGL +{ + static bool IsCombineModeSupported( unsigned int combiner ); + static TextureCombinersGL* Create( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props ); + + int count; + const ShaderLab::TextureBinding* texEnvs; +}; + +void ApplyCombinerGL( unsigned int& currentCombColor, unsigned int& currentCombAlpha, unsigned int combcolor, unsigned int combalpha ); diff --git a/Runtime/GfxDevice/opengl/GLAssert.cpp b/Runtime/GfxDevice/opengl/GLAssert.cpp new file mode 100644 index 0000000..4f3501d --- /dev/null +++ b/Runtime/GfxDevice/opengl/GLAssert.cpp @@ -0,0 +1,42 @@ +#include "UnityPrefix.h" +#include "GLAssert.h" +#include "UnityGL.h" + +#if UNITY_WIN || UNITY_LINUX +#include <GL/glu.h> +#else +#include <OpenGL/glu.h> +#endif + +using namespace std; + +void CheckOpenGLError (const char *prefix, const char* file, long line) +{ + const int kMaxErrors = 10; + int counter = 0; + + GLenum glerr; + while( (glerr = glGetError ()) != GL_NO_ERROR ) + { + if (prefix) + { + string errorString = prefix; + errorString += ": "; + const char* gluMsg = reinterpret_cast<const char*>(gluErrorString (glerr)); + errorString += gluMsg ? gluMsg : Format("unknown error 0x%x", glerr); + DebugStringToFile (errorString.c_str(), 0, file, line, kAssert); + } + else + { + const char* gluMsg = reinterpret_cast<const char*>(gluErrorString (glerr)); + string errorString = gluMsg ? gluMsg : Format("unknown error 0x%x", glerr); + DebugStringToFile (errorString.c_str(), 0, file, line, kAssert); + } + ++counter; + if( counter > kMaxErrors ) + { + printf_console( "GL: error count exceeds %i, stop reporting errors\n", kMaxErrors ); + return; + } + } +} diff --git a/Runtime/GfxDevice/opengl/GLAssert.h b/Runtime/GfxDevice/opengl/GLAssert.h new file mode 100644 index 0000000..7693012 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GLAssert.h @@ -0,0 +1,25 @@ +#ifndef GLASSERT_H +#define GLASSERT_H + +#include "Runtime/Utilities/LogAssert.h" + +void CheckOpenGLError (const char *prefix, const char* file, long line); + +#if !UNITY_RELEASE + #ifndef GLAssert + /// Asserts for checking the OpenGL error state + #define GLAssert() { CheckOpenGLError (NULL, __FILE__, __LINE__); } + #endif + #define GLAssertString(x) { CheckOpenGLError (x, __FILE__, __LINE__); } + #define GL_CHK(x) do { {x;} GLAssert(); } while(0) +#else + + #ifndef GLAssert + #define GLAssert() + #endif + #define GLAssertString(x) + #define GL_CHK(x) x + +#endif + +#endif diff --git a/Runtime/GfxDevice/opengl/GLContext.cpp b/Runtime/GfxDevice/opengl/GLContext.cpp new file mode 100644 index 0000000..047bc26 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GLContext.cpp @@ -0,0 +1,506 @@ +#include "UnityPrefix.h" +#include "GLContext.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/GfxDeviceSetup.h" +#include <set> +#include "UnityGL.h" +#include "Runtime/Misc/SystemInfo.h" +#include "Runtime/Threads/Thread.h" +#if UNITY_WIN +#include "PlatformDependent/Win/WinUtils.h" +#endif +#if UNITY_OSX +#if SUPPORT_AGL +#include <AGL/agl.h> +#endif +#include <OpenGL/OpenGL.h> +#include "Runtime/Graphics/ScreenManager.h" +#elif UNITY_LINUX +#include <X11/X.h> +#include <X11/Xlib.h> +#include <GL/glx.h> +#endif + + +// define to 1 to print lots of context info +#define DEBUG_GL_CONTEXT 0 + +#if UNITY_OSX +void CleanupMasterContextOSX (GraphicsContextGL* context); // GLContextOSX.cpp +#endif + + +static GraphicsContextHandle gMainGraphicsContext; +static GraphicsContextHandle gMasterGraphicsContext; +static GraphicsContexts gContexts; + + +GraphicsContexts& GetGLContexts() +{ + return gContexts; +} + +GraphicsContextHandle GetMainGraphicsContext() +{ + return gMainGraphicsContext; +} + +void SetMainGraphicsContext( GraphicsContextHandle context ) +{ + Assert(context.IsValid()); + gMainGraphicsContext = context; +} + +GraphicsContextHandle GetMasterGraphicsContext() +{ + #if UNITY_WIN + Assert(gMasterGraphicsContext.IsValid()); + #elif UNITY_OSX || UNITY_LINUX + if( !gMasterGraphicsContext.IsValid() ) + MakeMasterGLContext(); + #else + #error "Unknown platform" + #endif + + return gMasterGraphicsContext; +} + +bool IsMasterGraphicsContextValid() +{ + return gMasterGraphicsContext.IsValid(); +} + +void PresentContextGL( GraphicsContextHandle contextHandle ) +{ + AutoGfxDeviceAcquireThreadOwnership autoOwn; + if( !contextHandle.IsValid() ) + return; + + GraphicsContextGL* context = OBJECT_FROM_HANDLE(contextHandle,GraphicsContextGL); + +#if UNITY_WIN + BOOL ok = ::SwapBuffers( context->hdc ); + if( !ok ) { + DWORD err = GetLastError(); + } +#elif UNITY_LINUX + if (gGraphicsCaps.gl.hasArbSync) + { + if (context->presentSync) + { + OGL_CALL(glClientWaitSync(static_cast<GLsync> (context->presentSync), 0, GL_TIMEOUT_IGNORED)); + OGL_CALL(glDeleteSync(static_cast<GLsync> (context->presentSync))); + } + context->presentSync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + } + + #if !WEBPLUG && !UNITY_EDITOR + GLint curFBO; + glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &curFBO); + GetScreenManager().PreBlit(); + #endif + + glXSwapBuffers(reinterpret_cast<Display*> (context->display), context->window); + + #if !WEBPLUG && !UNITY_EDITOR + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, curFBO); + #endif +#elif UNITY_OSX + if (gGraphicsCaps.gl.hasAppleFence) + { + if (!context->appleFenceValid) + { + OGL_CALL(glGenFencesAPPLE(1, &context->appleFence)); + context->appleFenceValid = true; + } + else + OGL_CALL(glFinishFenceAPPLE(context->appleFence)); + + OGL_CALL(glSetFenceAPPLE(context->appleFence)); + } + + + #if WEBPLUG + // No need to swap in this case. + if ( GetScreenManager().IsUsingCoreAnimation() && !GetScreenManager().IsFullScreen() ) + return; + #endif + + #if !WEBPLUG && !UNITY_EDITOR + GLint curFBO; + glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &curFBO); + GetScreenManager().PreBlit(); + #endif + + CGLFlushDrawable( context->cgl ); + #if !WEBPLUG && !UNITY_EDITOR + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, curFBO); + #endif +#else + #error "Unknown platform" +#endif +} + +#if UNITY_OSX +void CleanupPresentSync (GraphicsContextGL* context) +{ + if (context == NULL) + return; + + if (context->presentSync) + { + glDeleteSync(static_cast<GLsync> (context->presentSync)); + context->presentSync = NULL; + } + + if (context->appleFenceValid) + { + glDeleteFencesAPPLE(1, &context->appleFence); + context->appleFenceValid = false; + context->appleFence = 0; + } +} +#endif + +#if UNITY_LINUX +void CleanupPresentSync (GraphicsContextGL* context) +{ + if (context && context->presentSync) + { + glDeleteSync(static_cast<GLsync> (context->presentSync)); + context->presentSync = NULL; + } +} +#endif + +void DestroyContextGL( GraphicsContextHandle& contextHandle ) +{ + AutoGfxDeviceAcquireThreadOwnership autoOwn; + ErrorIf( GetMasterGraphicsContext () == contextHandle ); + if ( !contextHandle.IsValid() ) + return; + + // prevent stale pointer to main context + if( contextHandle == GetMainGraphicsContext() ) + { + SetMainGraphicsContext( GetMasterGraphicsContext() ); + } + + GraphicsContextGL* context = OBJECT_FROM_HANDLE(contextHandle, GraphicsContextGL); + + gContexts.erase( *context ); + + #if UNITY_WIN + + #if DEBUG_GL_CONTEXT + printf_console( "CTX: destroy context %p\n", (DWORD)context->hglrc ); + #endif + + if (IsGfxDevice()) + { + HGLRC curGL = wglGetCurrentContext (); + HDC curDC = wglGetCurrentDC (); + wglMakeCurrent (context->hdc, context->hglrc); + GetRealGfxDevice().UnbindObjects(); + wglMakeCurrent (curDC, curGL); + } + + wglDeleteContext( context->hglrc ); + ReleaseDC( context->hwnd, context->hdc ); + + #elif UNITY_OSX + + CleanupPresentSync(context); + + #if DEBUG_GL_CONTEXT + printf_console( "CTX: destroy context %p\n", context->cgl ); + #endif + + if (IsGfxDevice()) + { + CGLContextObj currentCtx = CGLGetCurrentContext(); + CGLSetCurrentContext(context->cgl); + GetRealGfxDevice().UnbindObjects(); + CGLSetCurrentContext (currentCtx); + } + +#if SUPPORT_AGL + if (context->agl) + { + if( aglDestroyContext(context->agl)==GL_FALSE ) + printf_console( "aglDestroyContext failed!\n" ); + } + else +#endif + { + CGLError err = CGLDestroyContext(context->cgl); + if ( err ) + printf_console( "CGLDestroyContext failed: %s!\n", CGLErrorString(err) ); + } + #elif UNITY_LINUX + + CleanupPresentSync(context); + + #if DEBUG_GL_CONTEXT + printf_console( "CTX: destroy context %p\n", context->context); + #endif + + Display *display = reinterpret_cast<Display*> (context->display); + GLXContext glxcontext = reinterpret_cast <GLXContext> (context->context); + if (IsGfxDevice()) + { + GLXContext curGL = glXGetCurrentContext(); + GLXDrawable curDrawable = glXGetCurrentDrawable (); + glXMakeCurrent(display, context->window, glxcontext); + GetRealGfxDevice().UnbindObjects(); + glXMakeCurrent(display, curDrawable, curGL); + } + + glXDestroyContext(display, glxcontext); + + #else + #error "Unknown platform" + #endif + + delete context; + contextHandle.Reset(); +} + +void DestroyMainContextGL() +{ + AutoGfxDeviceAcquireThreadOwnership autoOwn; + GraphicsContextHandle ctx = GetMainGraphicsContext(); + if( ctx == GetMasterGraphicsContext() ) + return; + + if( ctx.IsValid() ) + { + glFinish(); + ActivateGraphicsContext( GetMasterGraphicsContext() ); + DestroyContextGL( ctx ); + } + SetMainGraphicsContext( GetMasterGraphicsContext() ); +} + + +void CleanupMasterContext() +{ + AutoGfxDeviceAcquireThreadOwnership autoOwn; + Assert(gMasterGraphicsContext.IsValid()); + GraphicsContextGL* context = OBJECT_FROM_HANDLE(gMasterGraphicsContext,GraphicsContextGL); + gContexts.erase( *context ); + + #if UNITY_WIN + + #if DEBUG_GL_CONTEXT + printf_console( "GLDebug context: cleanup master context %x %s\n", (DWORD)context->hglrc, GetMasterContextClassName().c_str() ); + #endif + wglMakeCurrent(NULL, NULL); + + wglDeleteContext( context->hglrc ); + #if DEBUG_GL_CONTEXT + printf_console( "GLDebug context: deleted glrc %x\n", context->hglrc ); + #endif + ReleaseDC( context->hwnd, context->hdc ); + #if DEBUG_GL_CONTEXT + printf_console( "GLDebug context: released dc %x for window %x\n", context->hdc, context->hwnd ); + #endif + DestroyWindow( context->hwnd ); + #if DEBUG_GL_CONTEXT + printf_console( "GLDebug context: destroyed window %x\n", context->hwnd ); + #endif + winutils::UnregisterWindowClass( GetMasterContextClassName().c_str() ); + + #elif UNITY_OSX + + CleanupMasterContextOSX (context); + + #elif UNITY_LINUX + Display *display = reinterpret_cast <Display*> (context->display); + glFlush (); + glXMakeCurrent(display, None, NULL); + glXDestroyContext(display, reinterpret_cast<GLXContext> (context->context)); + + #else + #error "Unknown platform" + #endif + + delete context; + gMasterGraphicsContext.Reset(); + + #if !UNITY_EDITOR // editor does not do cleanup + Assert(gContexts.empty()); + #endif +} + + +bool ActivateGraphicsContextGL( const GraphicsContextGL& context, int flags ) +{ + Assert(IsRealGfxDeviceThreadOwner()); + bool result = true; + + // In Web Player, do not unbind GL objects here: + // At least on Chrome/OSX, when switching to fullscreen (sometimes) calls + // into the plugin with an already destroyed + // GL context set as active and so we crash if we use that. + // Instead, unbind happens elsewhere for that case. + // + // However, have to unbind in the editor. Mostly when switching + // graphics emulation, multiple contexts for each view can get old + // stale state and picking would get wrong, case 408464. + #if !WEBPLUG + if( !(flags & kGLContextSkipUnbindObjects) && IsGfxDevice() ) + GetRealGfxDevice().UnbindObjects(); + #endif + + #if UNITY_WIN + Assert(context.hglrc); + + if( !wglMakeCurrent(context.hdc, context.hglrc) ) + { + printf_console( "GLContext: failed to activate %x: %s\n", context.hglrc, WIN_LAST_ERROR_TEXT ); + result = false; + } + + #elif UNITY_OSX + + Assert(context.cgl != NULL); + #if DEBUG_GL_CONTEXT + char const* master = gMasterGraphicsContext.object ? (&context == gMasterGraphicsContext.object ? " (MASTER)" : "") : " (MASTER NULL)"; + printf_console( "CTX: activate %p%s\n", context.cgl, master ); + #endif + // In general the previous context needs to be flushed whenever switching to a new one. + // This is even more important in case of multithreaded GL, where not flushing can + // result in random crashes. + // + // However, don't flush if explicitly told not to. We don't flush when activating context + // at start of web player loop, just after creating web player window, and so on (i.e. whenever + // context activation happens because we initialize something). Skipping flush gets rid of + // "first frame shows garbage or previous game" in most cases. + if( !(flags & kGLContextSkipFlush) && CGLGetCurrentContext() != NULL) + glFlush(); + + CGLError err = CGLSetCurrentContext(context.cgl); + if( err ) + printf_console( "GLContext: CGLSetCurrentContext() failed: %s\n", CGLErrorString(err) ); + + #elif UNITY_LINUX + Assert (context.window); + + if( !(flags & kGLContextSkipFlush) && glXGetCurrentContext() != NULL) + glFlush(); + + glXMakeCurrent(reinterpret_cast<Display*> (context.display), context.window, reinterpret_cast<GLXContext> (context.context)); + + #else + #error "Unknown platform" + #endif + + if( !(flags & kGLContextSkipUnbindObjects) && IsGfxDevice() ) + { + // Must unbind objects otherwise stuff falls apart in other places, like read pixels stop + // to work when OpenGL ES 1.1 is being emulated in the editor. + GetRealGfxDevice().UnbindObjects(); + } + if( !(flags & kGLContextSkipInvalidateState) && IsGfxDevice() ) + { + // In some cases we cannot invalidate, e.g. when destroying render textures (case 490767). + GetRealGfxDevice().InvalidateState(); + } + return result; +} + + +bool ActivateGraphicsContext (GraphicsContextHandle ctx, bool currentThreadOnly, int flags) +{ + bool isMainThread = Thread::CurrentThreadIsMainThread(); + if (isMainThread && IsGfxDevice()) + { + GetGfxDevice().AcquireThreadOwnership(); + } +#if ENABLE_PROFILER + bool activeTimerQueries = false; + if (IsGfxDevice()) + { + activeTimerQueries = GetRealGfxDevice().TimerQueriesIsActive(); + if (activeTimerQueries) + GetRealGfxDevice().EndTimerQueries(); + } +#endif + Assert(isMainThread || IsRealGfxDeviceThreadOwner()); + Assert (gMasterGraphicsContext.IsValid()); + GraphicsContextGL* context = OBJECT_FROM_HANDLE(ctx,GraphicsContextGL); + bool res = ActivateGraphicsContextGL( *context, flags ); +#if ENABLE_PROFILER + if (activeTimerQueries) + GetRealGfxDevice().BeginTimerQueries(); +#endif + if (isMainThread && IsGfxDevice()) + { + GetGfxDevice().ReleaseThreadOwnership(); + } + if (!currentThreadOnly && IsGfxDevice() && isMainThread) + { + GetGfxDevice().SetActiveContext (context); + } + return res; +} + +bool ActivateMasterContextGL() +{ + GraphicsContextHandle ctx = GetMasterGraphicsContext(); + ErrorIf( !ctx.IsValid() ); + return ActivateGraphicsContext (ctx); +} + +bool ActivateMainContextGL () +{ + GraphicsContextHandle ctx = GetMainGraphicsContext(); + if( ctx.IsValid() )return ActivateGraphicsContext (ctx); + return false; +} + +void AssignMasterGraphicsContextGL( GraphicsContextGL* ctx ) +{ + Assert(!gMasterGraphicsContext.IsValid()); + gMasterGraphicsContext.object = ctx; +} + + + +#if UNITY_OSX + +GraphicsContextGL GetCurrentGraphicsContext () +{ + GraphicsContextGL ctx; + ctx.cgl = CGLGetCurrentContext(); +#if SUPPORT_AGL + ctx.agl = aglGetCurrentContext(); +#endif + return ctx; +} + +#elif UNITY_WIN + +GraphicsContextGL GetCurrentGraphicsContext () +{ + GraphicsContextGL ctx; + ctx.hdc = wglGetCurrentDC(); + ctx.hglrc = wglGetCurrentContext(); + return ctx; +} + +#elif UNITY_LINUX + +GraphicsContextGL GetCurrentGraphicsContext () +{ + GraphicsContextGL ctx; + ctx.context = glXGetCurrentContext(); + ctx.window = (Window)glXGetCurrentDrawable(); + ctx.display = GetDisplay(); + return ctx; +} + +#else +#error "Unknown platform" +#endif diff --git a/Runtime/GfxDevice/opengl/GLContext.h b/Runtime/GfxDevice/opengl/GLContext.h new file mode 100644 index 0000000..42e628a --- /dev/null +++ b/Runtime/GfxDevice/opengl/GLContext.h @@ -0,0 +1,195 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +#if UNITY_WIN + struct GraphicsContextGL + { + HDC hdc; + HGLRC hglrc; + HWND hwnd; + + GraphicsContextGL() : hdc(NULL), hwnd(NULL), hglrc(NULL) + { + } + ~GraphicsContextGL() + { + hdc = NULL;hwnd = NULL; hglrc = NULL; + } + + bool IsValid()const { return hglrc != NULL; } + friend bool operator == (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.hglrc == rhs.hglrc; } + friend bool operator < (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.hglrc < rhs.hglrc; } + friend bool operator != (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.hglrc != rhs.hglrc; } + }; +#elif UNITY_OSX + #define SUPPORT_AGL (!UNITY_64) + struct __AGLContextRec; + typedef struct __AGLContextRec *AGLContext; + + struct _CGLContextObject; + typedef struct _CGLContextObject *CGLContext; + + struct _CGLPixelFormatObject; + typedef struct _CGLPixelFormatObject *CGLPixelFormatObj; + + // 10.5 SDK defines all CGL functions to use GLint, whereas 10.4 is long. Make this work in both. + #ifndef MAC_OS_X_VERSION_MAX_ALLOWED + #error Fail + #elif MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 + #define CGLint long + #else + #define CGLint int + #endif + + struct GraphicsContextGL + { + CGLContext cgl; + #if SUPPORT_AGL + AGLContext agl; + #endif + + void* presentSync; + uint appleFence; + bool appleFenceValid; + + GraphicsContextGL() { + cgl = NULL; + #if SUPPORT_AGL + agl = NULL; + #endif + presentSync = 0; + appleFence = 0; + appleFenceValid = false; + } + + friend bool operator == (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.cgl == rhs.cgl; } + friend bool operator < (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.cgl < rhs.cgl; } + friend bool operator != (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.cgl != rhs.cgl; } + }; + + #define CGL_FROM_HANDLE(context) (*OBJECT_FROM_HANDLE(context,GraphicsContextGL)).cgl +#if SUPPORT_AGL + #define AGL_FROM_HANDLE(context) (*OBJECT_FROM_HANDLE(context,GraphicsContextGL)).agl +#endif +#elif UNITY_LINUX + #include "UnityGL.h" + #include "PlatformDependent/Linux/X11Quarantine.h" + + struct GraphicsContextGL + { + NativeDisplayPtr display; + NativeWindow window; + void *context; + void *presentSync; + + GraphicsContextGL() : window(0), context(NULL), presentSync(NULL) + { + } + ~GraphicsContextGL() + { + window = 0; + context = NULL; + } + + bool IsValid()const { return window != 0; } + friend bool operator == (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.context == rhs.context; } + friend bool operator < (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.context < rhs.context; } + friend bool operator != (const GraphicsContextGL& lhs, const GraphicsContextGL& rhs) { return lhs.context != rhs.context; } + }; + #define GLX_FROM_HANDLE(context) (*OBJECT_FROM_HANDLE(context,GraphicsContextGL)).context +#else + #error "Unknown platform" +#endif + +// Returns the master context +// Mac: if necessary creates it +// Windows: explicitly create master context earlier, with CreateMasterGraphicsContext() +GraphicsContextHandle GetMasterGraphicsContext(); +bool IsMasterGraphicsContextValid(); + +void SetMainGraphicsContext( GraphicsContextHandle ctx ); +GraphicsContextHandle GetMainGraphicsContext (); + +void DestroyContextGL( GraphicsContextHandle& context ); +void DestroyMainContextGL(); + +// Makes the context active. And sets up some default state. +bool ActivateGraphicsContext (GraphicsContextHandle ctx, bool currentThreadOnly = false, int flags = 0); +bool ActivateMasterContextGL (); +bool ActivateMainContextGL (); +bool ActivateGraphicsContextGL ( const GraphicsContextGL& ctx, int flags ); +void AssignMasterGraphicsContextGL ( GraphicsContextGL* ctx ); +GraphicsContextGL GetCurrentGraphicsContext (); + +void PresentContextGL ( GraphicsContextHandle ctx ); + +#if UNITY_WIN + void SetMasterContextClassName ( const std::wstring& windowClassName ); + const std::wstring& GetMasterContextClassName (); + + GraphicsContextHandle SetupGraphicsContextFromWindow ( HWND window, int width, int height, int inFSAA, int& outFSAA ); +#endif + + + + +typedef std::set<GraphicsContextGL> GraphicsContexts; +GraphicsContexts& GetGLContexts(); + +enum { + kGLContextSkipInvalidateState = 1 << 0, + kGLContextSkipUnbindObjects = 1 << 1, + kGLContextSkipFlush = 2 << 2, +}; + + +#if UNITY_OSX + void CleanupMasterContext(); + + GraphicsContextHandle MakeNewContext( int width, int height, int fullscreen, bool doubleBuffer, bool pbuffer, DepthBufferFormat depthFormat, int* inoutAA, bool agl); + GraphicsContextHandle MakeOffScreenContext (int width, int height, int depthBits, int stencilBits); + GraphicsContextGL MakeNewContextGL( int width, int height, int fullscreen, bool doubleBuffer, bool pbuffer, bool depthTexture, DepthBufferFormat depthFormat, int* inoutAA, bool agl); + GraphicsContextGL MakeOffScreenContextGL (int width, int height, int depthBits, int stencilBits); + void GeneratePixelAttributes (int bits, int depthBits, int stencilBits, const void* cglPixelFormatAttributes, bool doubleBuffer,bool fullscreen, int supersample, bool pbuffer); + void SetupDefaultContextState( GraphicsContextGL &context, bool setMultiThreaded, int fsaa ); + + void CleanupPresentSync (GraphicsContextGL* context); + + void SetSyncToVBL (GraphicsContextHandle context, int syncCount); + + void SetDisplayID( CGDirectDisplayID display ); + + void MakeMasterGLContext(); + + #if UNITY_EDITOR + void GLFinishAllGraphicsContexts (); + void SetContextDrawable( GraphicsContextHandle context, CGrafPtr port, const float* frame ); + void UpdateContextDrawable( GraphicsContextHandle context, const float* frame ); + #endif +#elif UNITY_LINUX + void CleanupMasterContext(); + void CleanupPresentSync (GraphicsContextGL* context); + + GraphicsContextHandle MakeNewContext( int width, int height, int fullscreen, bool doubleBuffer, bool pbuffer, DepthBufferFormat depthFormat, int antiAlias); + GraphicsContextHandle MakeOffScreenContext (int width, int height, int depthBits, int stencilBits); + GraphicsContextGL MakeNewContextGL (NativeDisplayPtr display, NativeWindow window, int width, int height, int fullscreen, bool doubleBuffer, bool pbuffer, bool depthTexture, DepthBufferFormat depthFormat, int antiAlias); + GraphicsContextGL MakeOffScreenContextGL (int width, int height, int depthBits, int stencilBits); + void SetupDefaultContextState( GraphicsContextGL &context, bool setMultiThreaded, int fsaa ); + + void SetSyncToVBL (GraphicsContextHandle context, int syncCount); + void SetDisplay(NativeDisplayPtr display); + NativeDisplayPtr GetDisplay(); + + void MakeMasterGLContext(); + void MakeMasterGLContext(NativeDisplayPtr display, NativeWindow window); + GraphicsContextGL* MakeGLContextForWindow(NativeDisplayPtr display, NativeWindow window, bool shareWithMaster=true); + VisualInfoPtr CreateVisualInfo (NativeDisplayPtr display, int antialiasingLevel=0); + + #if UNITY_EDITOR + void GLFinishAllGraphicsContexts (); + void UpdateContextDrawable( GraphicsContextHandle context, const float* frame ); + GraphicsContextHandle SetupGraphicsContextFromWindow (NativeWindow window, int width, int height, int inFSAA, int& outFSAA); + #endif +#endif diff --git a/Runtime/GfxDevice/opengl/GLExtensionDefs.h b/Runtime/GfxDevice/opengl/GLExtensionDefs.h new file mode 100644 index 0000000..ba5f055 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GLExtensionDefs.h @@ -0,0 +1,247 @@ +// This file is automatically generated with Runtime/GfxDevice/opengl/GenerateGLExtensionDef.pl. +// It is generated from GLExtensionDefs.txt + + +//Tex coords +DEF (PFNGLACTIVETEXTUREPROC, glActiveTextureARB); +#define glActiveTextureARB UNITYGL_glActiveTextureARB +DEF (PFNGLCLIENTACTIVETEXTUREPROC, glClientActiveTextureARB); +#define glClientActiveTextureARB UNITYGL_glClientActiveTextureARB +DEF (PFNGLMULTITEXCOORD3FPROC, glMultiTexCoord3fARB); +#define glMultiTexCoord3fARB UNITYGL_glMultiTexCoord3fARB +DEF (PFNGLMULTITEXCOORD4FPROC, glMultiTexCoord4fARB); +#define glMultiTexCoord4fARB UNITYGL_glMultiTexCoord4fARB +DEF (PFNGLMULTITEXCOORD3FVPROC, glMultiTexCoord3fvARB); +#define glMultiTexCoord3fvARB UNITYGL_glMultiTexCoord3fvARB +DEF (PFNGLMULTITEXCOORD4FVPROC, glMultiTexCoord4fvARB); +#define glMultiTexCoord4fvARB UNITYGL_glMultiTexCoord4fvARB + +//Blending +DEF (PFNGLBLENDCOLORPROC, glBlendColor); +#define glBlendColor UNITYGL_glBlendColor +DEF (PFNGLBLENDFUNCSEPARATEEXTPROC, glBlendFuncSeparateEXT); +#define glBlendFuncSeparateEXT UNITYGL_glBlendFuncSeparateEXT +DEF (PFNGLBLENDEQUATIONPROC, glBlendEquation); +#define glBlendEquation UNITYGL_glBlendEquation +DEF (PFNGLBLENDEQUATIONSEPARATEEXTPROC, glBlendEquationSeparateEXT); +#define glBlendEquationSeparateEXT UNITYGL_glBlendEquationSeparateEXT + +// ARB_VP, ARB FP +DEF (PFNGLDELETEPROGRAMSARBPROC, glDeleteProgramsARB); +#define glDeleteProgramsARB UNITYGL_glDeleteProgramsARB +DEF (PFNGLGENPROGRAMSARBPROC, glGenProgramsARB); +#define glGenProgramsARB UNITYGL_glGenProgramsARB +DEF (PFNGLBINDPROGRAMARBPROC, glBindProgramARB); +#define glBindProgramARB UNITYGL_glBindProgramARB +DEF (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC, glProgramLocalParameter4fvARB); +#define glProgramLocalParameter4fvARB UNITYGL_glProgramLocalParameter4fvARB +DEF (PFNGLPROGRAMENVPARAMETER4FVARBPROC, glProgramEnvParameter4fvARB); +#define glProgramEnvParameter4fvARB UNITYGL_glProgramEnvParameter4fvARB +DEF (PFNGLPROGRAMLOCALPARAMETER4FARBPROC, glProgramLocalParameter4fARB); +#define glProgramLocalParameter4fARB UNITYGL_glProgramLocalParameter4fARB +DEF (PFNGLPROGRAMENVPARAMETER4FARBPROC, glProgramEnvParameter4fARB); +#define glProgramEnvParameter4fARB UNITYGL_glProgramEnvParameter4fARB +DEF (PFNGLPROGRAMSTRINGARBPROC, glProgramStringARB); +#define glProgramStringARB UNITYGL_glProgramStringARB +DEF (PFNGLGETPROGRAMENVPARAMETERFVARBPROC, glGetProgramEnvParameterfvARB); +#define glGetProgramEnvParameterfvARB UNITYGL_glGetProgramEnvParameterfvARB + +// Textures +DEF (PFNGLCOMPRESSEDTEXIMAGE2DARBPROC, glCompressedTexImage2DARB); +#define glCompressedTexImage2DARB UNITYGL_glCompressedTexImage2DARB +DEF (PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC, glCompressedTexSubImage2DARB); +#define glCompressedTexSubImage2DARB UNITYGL_glCompressedTexSubImage2DARB +DEF (PFNGLTEXIMAGE3DPROC, glTexImage3D); +#define glTexImage3D UNITYGL_glTexImage3D + +#if UNITY_OSX +// Apple fences +DEF (PFNGLGENFENCESAPPLEPROC, glGenFencesAPPLE); +#define glGenFencesAPPLE UNITYGL_glGenFencesAPPLE +DEF (PFNGLDELETEFENCESAPPLEPROC, glDeleteFencesAPPLE); +#define glDeleteFencesAPPLE UNITYGL_glDeleteFencesAPPLE +DEF (PFNGLSETFENCEAPPLEPROC, glSetFenceAPPLE); +#define glSetFenceAPPLE UNITYGL_glSetFenceAPPLE +DEF (PFNGLISFENCEAPPLEPROC, glIsFenceAPPLE); +#define glIsFenceAPPLE UNITYGL_glIsFenceAPPLE +DEF (PFNGLTESTFENCEAPPLEPROC, glTestFenceAPPLE); +#define glTestFenceAPPLE UNITYGL_glTestFenceAPPLE +DEF (PFNGLFINISHFENCEAPPLEPROC, glFinishFenceAPPLE); +#define glFinishFenceAPPLE UNITYGL_glFinishFenceAPPLE +DEF (PFNGLFINISHOBJECTAPPLEPROC, glFinishObjectAPPLE); +#define glFinishObjectAPPLE UNITYGL_glFinishObjectAPPLE +DEF (PFNGLTESTOBJECTAPPLEPROC, glTestObjectAPPLE); +#define glTestObjectAPPLE UNITYGL_glTestObjectAPPLE + +// APPLE_flush_buffer_range +DEF (PFNGLBUFFERPARAMETERIAPPLEPROC, glBufferParameteriAPPLE); +#define glBufferParameteriAPPLE UNITYGL_glBufferParameteriAPPLE +DEF (PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC, glFlushMappedBufferRangeAPPLE); +#define glFlushMappedBufferRangeAPPLE UNITYGL_glFlushMappedBufferRangeAPPLE +#endif + +// ARB_vertex_buffer_object +DEF (PFNGLGENBUFFERSARBPROC, glGenBuffersARB); +#define glGenBuffersARB UNITYGL_glGenBuffersARB +DEF (PFNGLDELETEBUFFERSARBPROC, glDeleteBuffersARB); +#define glDeleteBuffersARB UNITYGL_glDeleteBuffersARB +DEF (PFNGLBUFFERDATAARBPROC, glBufferDataARB); +#define glBufferDataARB UNITYGL_glBufferDataARB +DEF (PFNGLBINDBUFFERARBPROC, glBindBufferARB); +#define glBindBufferARB UNITYGL_glBindBufferARB +DEF (PFNGLMAPBUFFERARBPROC, glMapBufferARB); +#define glMapBufferARB UNITYGL_glMapBufferARB +DEF (PFNGLUNMAPBUFFERARBPROC, glUnmapBufferARB); +#define glUnmapBufferARB UNITYGL_glUnmapBufferARB +DEF (PFNGLBUFFERSUBDATAARBPROC, glBufferSubDataARB); +#define glBufferSubDataARB UNITYGL_glBufferSubDataARB + +// ARB_map_buffer_range +DEF (PFNGLMAPBUFFERRANGEPROC, glMapBufferRange); +#define glMapBufferRange UNITYGL_glMapBufferRange + +// ARB_vertex_program +DEF (PFNGLGETPROGRAMIVARBPROC, glGetProgramivARB); +#define glGetProgramivARB UNITYGL_glGetProgramivARB +DEF (PFNGLVERTEXATTRIBPOINTERARBPROC, glVertexAttribPointerARB); +#define glVertexAttribPointerARB UNITYGL_glVertexAttribPointerARB +DEF (PFNGLENABLEVERTEXATTRIBARRAYARBPROC, glEnableVertexAttribArrayARB); +#define glEnableVertexAttribArrayARB UNITYGL_glEnableVertexAttribArrayARB +DEF (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC, glDisableVertexAttribArrayARB); +#define glDisableVertexAttribArrayARB UNITYGL_glDisableVertexAttribArrayARB + +// ARB_occlusion query +DEF (PFNGLGENQUERIESARBPROC, glGenQueriesARB); +#define glGenQueriesARB UNITYGL_glGenQueriesARB +DEF (PFNGLBEGINQUERYARBPROC, glBeginQueryARB); +#define glBeginQueryARB UNITYGL_glBeginQueryARB +DEF (PFNGLENDQUERYARBPROC, glEndQueryARB); +#define glEndQueryARB UNITYGL_glEndQueryARB +DEF (PFNGLGETQUERYOBJECTIVARBPROC, glGetQueryObjectivARB); +#define glGetQueryObjectivARB UNITYGL_glGetQueryObjectivARB +DEF (PFNGLGETQUERYOBJECTUIVARBPROC, glGetQueryObjectuivARB); +#define glGetQueryObjectuivARB UNITYGL_glGetQueryObjectuivARB +DEF (PFNGLDELETEQUERIESARBPROC, glDeleteQueriesARB); +#define glDeleteQueriesARB UNITYGL_glDeleteQueriesARB + +// EXT_timer query +DEF (PFNGLGETQUERYOBJECTI64VEXTPROC, glGetQueryObjecti64vEXT); +#define glGetQueryObjecti64vEXT UNITYGL_glGetQueryObjecti64vEXT +DEF (PFNGLGETQUERYOBJECTUI64VEXTPROC, glGetQueryObjectui64vEXT); +#define glGetQueryObjectui64vEXT UNITYGL_glGetQueryObjectui64vEXT + +// ARB_sync +DEF (PFNGLFENCESYNCPROC, glFenceSync); +#define glFenceSync UNITYGL_glFenceSync +DEF (PFNGLDELETESYNCPROC, glDeleteSync); +#define glDeleteSync UNITYGL_glDeleteSync +DEF (PFNGLCLIENTWAITSYNCPROC, glClientWaitSync); +#define glClientWaitSync UNITYGL_glClientWaitSync + +// GLSL +DEF (PFNGLCREATEPROGRAMOBJECTARBPROC, glCreateProgramObjectARB); +#define glCreateProgramObjectARB UNITYGL_glCreateProgramObjectARB +DEF (PFNGLCREATESHADEROBJECTARBPROC, glCreateShaderObjectARB); +#define glCreateShaderObjectARB UNITYGL_glCreateShaderObjectARB +DEF (PFNGLSHADERSOURCEARBPROC, glShaderSourceARB); +#define glShaderSourceARB UNITYGL_glShaderSourceARB +DEF (PFNGLCOMPILESHADERARBPROC, glCompileShaderARB); +#define glCompileShaderARB UNITYGL_glCompileShaderARB +DEF (PFNGLATTACHOBJECTARBPROC, glAttachObjectARB); +#define glAttachObjectARB UNITYGL_glAttachObjectARB +DEF (PFNGLLINKPROGRAMARBPROC, glLinkProgramARB); +#define glLinkProgramARB UNITYGL_glLinkProgramARB +DEF (PFNGLUSEPROGRAMOBJECTARBPROC, glUseProgramObjectARB); +#define glUseProgramObjectARB UNITYGL_glUseProgramObjectARB +DEF (PFNGLDELETEOBJECTARBPROC, glDeleteObjectARB); +#define glDeleteObjectARB UNITYGL_glDeleteObjectARB +DEF (PFNGLGETHANDLEARBPROC, glGetHandleARB); +#define glGetHandleARB UNITYGL_glGetHandleARB +DEF (PFNGLGETINFOLOGARBPROC, glGetInfoLogARB); +#define glGetInfoLogARB UNITYGL_glGetInfoLogARB +DEF (PFNGLGETACTIVEATTRIBARBPROC, glGetActiveAttribARB); +#define glGetActiveAttribARB UNITYGL_glGetActiveAttribARB +DEF (PFNGLGETACTIVEUNIFORMARBPROC, glGetActiveUniformARB); +#define glGetActiveUniformARB UNITYGL_glGetActiveUniformARB +DEF (PFNGLGETUNIFORMLOCATIONARBPROC, glGetUniformLocationARB); +#define glGetUniformLocationARB UNITYGL_glGetUniformLocationARB +DEF (PFNGLGETATTRIBLOCATIONARBPROC, glGetAttribLocationARB); +#define glGetAttribLocationARB UNITYGL_glGetAttribLocationARB +DEF (PFNGLGETOBJECTPARAMETERIVARBPROC, glGetObjectParameterivARB); +#define glGetObjectParameterivARB UNITYGL_glGetObjectParameterivARB +DEF (PFNGLUNIFORM1FVARBPROC, glUniform1fvARB); +#define glUniform1fvARB UNITYGL_glUniform1fvARB +DEF (PFNGLUNIFORM2FVARBPROC, glUniform2fvARB); +#define glUniform2fvARB UNITYGL_glUniform2fvARB +DEF (PFNGLUNIFORM3FVARBPROC, glUniform3fvARB); +#define glUniform3fvARB UNITYGL_glUniform3fvARB +DEF (PFNGLUNIFORM4FVARBPROC, glUniform4fvARB); +#define glUniform4fvARB UNITYGL_glUniform4fvARB +DEF (PFNGLUNIFORMMATRIX4FVARBPROC, glUniformMatrix4fvARB); +#define glUniformMatrix4fvARB UNITYGL_glUniformMatrix4fvARB +DEF (PFNGLUNIFORM1IVARBPROC, glUniform1ivARB); +#define glUniform1ivARB UNITYGL_glUniform1ivARB +DEF (PFNGLUNIFORM2IVARBPROC, glUniform2ivARB); +#define glUniform2ivARB UNITYGL_glUniform2ivARB +DEF (PFNGLUNIFORM3IVARBPROC, glUniform3ivARB); +#define glUniform3ivARB UNITYGL_glUniform3ivARB +DEF (PFNGLUNIFORM4IVARBPROC, glUniform4ivARB); +#define glUniform4ivARB UNITYGL_glUniform4ivARB + +#if UNITY_WIN +// Windows P-buffers +DEF (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB); +#define wglChoosePixelFormatARB UNITYGL_wglChoosePixelFormatARB +DEF (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB); +#define wglGetPixelFormatAttribivARB UNITYGL_wglGetPixelFormatAttribivARB +DEF (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB); +#define wglGetExtensionsStringARB UNITYGL_wglGetExtensionsStringARB +DEF (PFNWGLGETEXTENSIONSSTRINGEXTPROC, wglGetExtensionsStringEXT); +#define wglGetExtensionsStringEXT UNITYGL_wglGetExtensionsStringEXT + +// Windows VSync +DEF (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT); +#define wglSwapIntervalEXT UNITYGL_wglSwapIntervalEXT +#endif + +// GL_EXT_framebuffer_object +DEF (PFNGLGENFRAMEBUFFERSEXTPROC, glGenFramebuffersEXT); +#define glGenFramebuffersEXT UNITYGL_glGenFramebuffersEXT +DEF (PFNGLBINDFRAMEBUFFEREXTPROC, glBindFramebufferEXT); +#define glBindFramebufferEXT UNITYGL_glBindFramebufferEXT +DEF (PFNGLGENRENDERBUFFERSEXTPROC, glGenRenderbuffersEXT); +#define glGenRenderbuffersEXT UNITYGL_glGenRenderbuffersEXT +DEF (PFNGLBINDRENDERBUFFEREXTPROC, glBindRenderbufferEXT); +#define glBindRenderbufferEXT UNITYGL_glBindRenderbufferEXT +DEF (PFNGLRENDERBUFFERSTORAGEEXTPROC, glRenderbufferStorageEXT); +#define glRenderbufferStorageEXT UNITYGL_glRenderbufferStorageEXT +DEF (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC, glFramebufferRenderbufferEXT); +#define glFramebufferRenderbufferEXT UNITYGL_glFramebufferRenderbufferEXT +DEF (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC, glFramebufferTexture2DEXT); +#define glFramebufferTexture2DEXT UNITYGL_glFramebufferTexture2DEXT +DEF (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC, glCheckFramebufferStatusEXT); +#define glCheckFramebufferStatusEXT UNITYGL_glCheckFramebufferStatusEXT +DEF (PFNGLDELETEFRAMEBUFFERSEXTPROC, glDeleteFramebuffersEXT); +#define glDeleteFramebuffersEXT UNITYGL_glDeleteFramebuffersEXT +DEF (PFNGLDELETERENDERBUFFERSEXTPROC, glDeleteRenderbuffersEXT); +#define glDeleteRenderbuffersEXT UNITYGL_glDeleteRenderbuffersEXT +DEF (PFNGLGENERATEMIPMAPEXTPROC, glGenerateMipmapEXT); +#define glGenerateMipmapEXT UNITYGL_glGenerateMipmapEXT + +// GL_ARB_draw_buffers +DEF (PFNGLDRAWBUFFERSARBPROC, glDrawBuffersARB); +#define glDrawBuffersARB UNITYGL_glDrawBuffersARB + +// GL_EXT_framebuffer_blit +DEF (PFNGLBLITFRAMEBUFFEREXTPROC, glBlitFramebufferEXT); +#define glBlitFramebufferEXT UNITYGL_glBlitFramebufferEXT + +// GL_EXT_framebuffer_multisample +DEF (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC, glRenderbufferStorageMultisampleEXT); +#define glRenderbufferStorageMultisampleEXT UNITYGL_glRenderbufferStorageMultisampleEXT + +// Separate stencil in GL2.0 +DEF (PFNGLSTENCILFUNCSEPARATEPROC, glStencilFuncSeparate); +#define glStencilFuncSeparate UNITYGL_glStencilFuncSeparate +DEF (PFNGLSTENCILOPSEPARATEPROC, glStencilOpSeparate); +#define glStencilOpSeparate UNITYGL_glStencilOpSeparate diff --git a/Runtime/GfxDevice/opengl/GLExtensionDefs.txt b/Runtime/GfxDevice/opengl/GLExtensionDefs.txt new file mode 100644 index 0000000..6cc3d6d --- /dev/null +++ b/Runtime/GfxDevice/opengl/GLExtensionDefs.txt @@ -0,0 +1,145 @@ + + +//Tex coords +glActiveTextureARB->glActiveTexture +glClientActiveTextureARB->glClientActiveTexture +glMultiTexCoord3fARB->glMultiTexCoord3f +glMultiTexCoord4fARB->glMultiTexCoord4f +glMultiTexCoord3fvARB->glMultiTexCoord3fv +glMultiTexCoord4fvARB->glMultiTexCoord4fv + +//Blending +glBlendColor +glBlendFuncSeparateEXT +glBlendEquation +glBlendEquationSeparateEXT + +// ARB_VP, ARB FP +glDeleteProgramsARB +glGenProgramsARB +glBindProgramARB +glProgramLocalParameter4fvARB +glProgramEnvParameter4fvARB +glProgramLocalParameter4fARB +glProgramEnvParameter4fARB +glProgramStringARB +glGetProgramEnvParameterfvARB + +// Textures +glCompressedTexImage2DARB +glCompressedTexSubImage2DARB +glTexImage3D + +#if UNITY_OSX +// Apple fences +glGenFencesAPPLE +glDeleteFencesAPPLE +glSetFenceAPPLE +glIsFenceAPPLE +glTestFenceAPPLE +glFinishFenceAPPLE +glFinishObjectAPPLE +glTestObjectAPPLE + +// APPLE_flush_buffer_range +glBufferParameteriAPPLE +glFlushMappedBufferRangeAPPLE +#endif + +// ARB_vertex_buffer_object +glGenBuffersARB +glDeleteBuffersARB +glBufferDataARB +glBindBufferARB +glMapBufferARB +glUnmapBufferARB +glBufferSubDataARB + +// ARB_map_buffer_range +glMapBufferRange + +// ARB_vertex_program +glGetProgramivARB +glVertexAttribPointerARB +glEnableVertexAttribArrayARB +glDisableVertexAttribArrayARB + +// ARB_occlusion query +glGenQueriesARB +glBeginQueryARB +glEndQueryARB +glGetQueryObjectivARB +glGetQueryObjectuivARB +glDeleteQueriesARB + +// EXT_timer query +glGetQueryObjecti64vEXT +glGetQueryObjectui64vEXT + +// ARB_sync +glFenceSync +glDeleteSync +glClientWaitSync + +// GLSL +glCreateProgramObjectARB +glCreateShaderObjectARB +glShaderSourceARB +glCompileShaderARB +glAttachObjectARB +glLinkProgramARB +glUseProgramObjectARB +glDeleteObjectARB +glGetHandleARB +glGetInfoLogARB +glGetActiveAttribARB +glGetActiveUniformARB +glGetUniformLocationARB +glGetAttribLocationARB +glGetObjectParameterivARB +glUniform1fvARB +glUniform2fvARB +glUniform3fvARB +glUniform4fvARB +glUniformMatrix4fvARB +glUniform1ivARB +glUniform2ivARB +glUniform3ivARB +glUniform4ivARB + +#if UNITY_WIN +// Windows P-buffers +wglChoosePixelFormatARB +wglGetPixelFormatAttribivARB +wglGetExtensionsStringARB +wglGetExtensionsStringEXT + +// Windows VSync +wglSwapIntervalEXT +#endif + +// GL_EXT_framebuffer_object +glGenFramebuffersEXT +glBindFramebufferEXT +glGenRenderbuffersEXT +glBindRenderbufferEXT +glRenderbufferStorageEXT +glFramebufferRenderbufferEXT +glFramebufferTexture2DEXT +glCheckFramebufferStatusEXT +glDeleteFramebuffersEXT +glDeleteRenderbuffersEXT +glGenerateMipmapEXT + +// GL_ARB_draw_buffers +glDrawBuffersARB + +// GL_EXT_framebuffer_blit +glBlitFramebufferEXT + +// GL_EXT_framebuffer_multisample +glRenderbufferStorageMultisampleEXT + +// Separate stencil in GL2.0 +glStencilFuncSeparate +glStencilOpSeparate diff --git a/Runtime/GfxDevice/opengl/GLWindow.h b/Runtime/GfxDevice/opengl/GLWindow.h new file mode 100644 index 0000000..53f79b9 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GLWindow.h @@ -0,0 +1,29 @@ +#ifndef GLWINDOW_H +#define GLWINDOW_H + +#include "UnityGL.h" +#include "Runtime/GfxDevice/GfxDeviceWindow.h" +#include "GLContext.h" + +class GLWindow : public GfxDeviceWindow +{ +private: + GraphicsContextHandle m_GLContext; + int cc; +public: + GLWindow (NativeWindow window, int width, int height, DepthBufferFormat depthFormat, int antiAlias); + ~GLWindow(); + + bool Reshape( int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + + bool BeginRendering(); + bool EndRendering( bool presentContent ); + +public: + static GLWindow* Current(); + + +}; + + +#endif diff --git a/Runtime/GfxDevice/opengl/GenerateGLExtensionDef.pl b/Runtime/GfxDevice/opengl/GenerateGLExtensionDef.pl new file mode 100644 index 0000000..81310df --- /dev/null +++ b/Runtime/GfxDevice/opengl/GenerateGLExtensionDef.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +open FH, "GLExtensionDefs.txt" or die $_; + +my$ output = "// This file is automatically generated with Runtime/GfxDevice/opengl/GenerateGLExtensionDef.pl.\n// It is generated from GLExtensionDefs.txt\n"; + +LINE: +while (<FH>) +{ + my $line = $_; + chomp ($line); + + if ($line =~ /^\s*\/\/\s*(.*)/) + { + $output = $output . "$line\n"; + } + elsif ($line =~ /^\s*\#\s*(.*)/) + { + $output = $output . "$line\n"; + } + elsif ($line =~ /^\s* s*(.*)/) + { + $output = $output . "$line\n"; + } + elsif ($line =~ /^\s*$/) + { + $output = $output . "$line\n"; + } + else + { + my$ name = $line; + my$ pfn = uc ($line); + if ($line =~ /^(.+)->(.+)/) + { + $name = $1; + $pfn = uc ($2); + } + my $upperLine = uc ($line); + $output = $output . "DEF (PFN" . $pfn . "PROC, $name);\n"; + $output = $output . "#define $name UNITYGL_$name\n"; + } +} + +open OUT, "> GLExtensionDefs.h"; +print OUT $output;
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengl/GfxDeviceGL.cpp b/Runtime/GfxDevice/opengl/GfxDeviceGL.cpp new file mode 100644 index 0000000..dfc2926 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GfxDeviceGL.cpp @@ -0,0 +1,3079 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Shaders/MaterialProperties.h" +#include "UnityGL.h" +#include "GLContext.h" +#include "TexturesGL.h" +#include "TimerQueryGL.h" +#include "ARBVBO.h" +#include "NullVBO.h" +#include "CombinerGL.h" +#include "External/shaderlab/Library/program.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "ChannelsGL.h" +#include "Runtime/Threads/AtomicOps.h" +#include "Runtime/Allocator/LinearAllocator.h" +#include "GpuProgramsGL.h" +#include "ArbGpuProgamGL.h" +#include "TextureIdMapGL.h" +#include "Runtime/Graphics/GraphicsHelper.h" +#include "Runtime/GfxDevice/GpuProgramParamsApply.h" +#if UNITY_EDITOR && UNITY_WIN +#include "GLWindow.h" +#endif +#include "Runtime/Misc/Plugins.h" + + +void InvalidateChannelStateGL(); // ChannelsGL.cpp +void InvalidateFPParamCacheGL(); // GpuProgramsGL.cpp +bool IsActiveRenderTargetWithColorGL(); // RenderTextureGL.cpp + +namespace ShaderLab { + TexEnv* GetTexEnvForBinding( const TextureBinding& binding, const PropertySheet* props ); // pass.cpp +} + +static const unsigned int kBlendModeGL[] = { + GL_ZERO, GL_ONE, GL_DST_COLOR, GL_SRC_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR, + GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA_SATURATE, GL_ONE_MINUS_SRC_ALPHA, +}; + +static const unsigned int kBlendFuncGL[] = { + GL_FUNC_ADD, GL_FUNC_SUBTRACT, + GL_FUNC_REVERSE_SUBTRACT, GL_MIN, GL_MAX, +}; + +static const unsigned int kCmpFuncGL[] = { + GL_NEVER, GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS +}; + +static const unsigned int kStencilOpGL[] = { + GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, + GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP +}; + +static const GLenum kColorMatModeGL[kColorMatTypeCount] = { 0, GL_EMISSION, GL_AMBIENT_AND_DIFFUSE }; + +static const unsigned long kTexDimTableGL[kTexDimCount] = {0, GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP_ARB, 0}; + +static GLenum kWrapModeGL[kTexWrapCount] = { GL_REPEAT, GL_CLAMP_TO_EDGE }; + +static const GLint kMinFilterGL[kTexFilterCount] = { GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR }; + +static const unsigned int kFogModeGL[kFogModeCount] = { GL_LINEAR, GL_LINEAR, GL_EXP, GL_EXP2 }; + +GLenum kTopologyGL[kPrimitiveTypeCount] = { GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_QUADS, GL_LINES, GL_LINE_STRIP, GL_POINTS }; + + +GfxThreadableDevice* CreateGLGfxDevice(); +const unsigned long* GetGLTextureDimensionTable(); +unsigned int GetGLShaderImplTarget( ShaderImplType implType ); +void InvalidateActiveShaderStateGL( ShaderType type ); + +#if SUPPORT_REPRODUCE_LOG_GFX_TRACE +#include "Runtime/Misc/ReproductionLog.h" +#define GFX_LOG(pattern) LogToScreenshotLog(__FUNCTION__+(" "+Format pattern)) +#else +#define GFX_LOG(pattern) +#endif + + +static inline void ActivateTextureUnitGL (int unit) +{ + // When using the fixed-function texture, the correct assert is: + //Assert(unit >= 0 && unit < gGraphicsCaps.maxTexUnits); + + Assert(unit >= 0 && unit < gGraphicsCaps.maxTexImageUnits); + + GFX_LOG(("%d", unit)); + if (gGraphicsCaps.maxTexImageUnits > 1) + OGL_CALL(glActiveTextureARB(GL_TEXTURE0_ARB + unit)); +} + + +// -------------------------------------------------------------------------- + +struct DeviceBlendStateGL : public DeviceBlendState +{ + UInt32 alphaFunc; +}; + + +struct DeviceDepthStateGL : public DeviceDepthState +{ + UInt32 depthFunc; +}; + +struct DeviceStencilStateGL : public DeviceStencilState +{ + GLenum stencilFuncFront; + GLenum stencilFailOpFront; + GLenum depthFailOpFront; + GLenum depthPassOpFront; + GLenum stencilFuncBack; + GLenum stencilFailOpBack; + GLenum depthFailOpBack; + GLenum depthPassOpBack; +}; + + + +typedef std::map< GfxBlendState, DeviceBlendStateGL, memcmp_less<GfxBlendState> > CachedBlendStates; +typedef std::map< GfxDepthState, DeviceDepthStateGL, memcmp_less<GfxDepthState> > CachedDepthStates; +typedef std::map< GfxStencilState, DeviceStencilStateGL, memcmp_less<GfxStencilState> > CachedStencilStates; +typedef std::map< GfxRasterState, DeviceRasterState, memcmp_less<GfxRasterState> > CachedRasterStates; + + +// -------------------------------------------------------------------------- + + +struct TextureUnitStateGL +{ + GLuint texID; + TextureDimension texDim; + unsigned int combColor, combAlpha; + Vector4f color; + TexGenMode texGen; + float bias; + + void Invalidate(); + void Verify( int unit ); +}; + +void TextureUnitStateGL::Invalidate() +{ + texID = -1; + texDim = kTexDimUnknown; + combColor = combAlpha = 0xFFFFFFFF; + color.Set( -1, -1, -1, -1 ); + texGen = kTexGenUnknown; + bias = 1.0e6f; +} + +// -------------------------------------------------------------------------- + + +struct VertexLightStateGL +{ + int enabled; // 0/1 or -1 if unknown + float attenQuad; + float spotAngle; + + void Invalidate(); + void Verify( int unit ); +}; + +void VertexLightStateGL::Invalidate() +{ + enabled = -1; + attenQuad = -1.0f; + spotAngle = -1000.0f; // -1.0f is used to flag non-spot lights, so it would be a valid value +} + +// -------------------------------------------------------------------------- + + +struct DeviceStateGL +{ + GLuint m_SharedFBO; + GLuint m_HelperFBO; + int m_TextureIDGenerator; + + int depthFunc; + int depthWrite; // 0/1 or -1 + + int blending; + int srcBlend, destBlend, srcBlendAlpha, destBlendAlpha; // GL modes + int blendOp, blendOpAlpha; // GL modes + CompareFunction alphaFunc; + float alphaValue; + int alphaToMask; + + CullMode culling; + bool appBackfaceMode, userBackfaceMode; + bool wireframe; + NormalizationMode normalization; + int scissor; + + + int lighting; + Vector4f matDiffuse, matAmbient, matSpecular, matEmissive; + Vector4f ambient; + float matShininess; + ColorMaterialMode colorMaterial; + + float offsetFactor, offsetUnits; + + GpuProgram* activeGpuProgram[kShaderTypeCount]; + const GpuProgramParameters* activeGpuProgramParams[kShaderTypeCount]; + ShaderImplType shaderEnabledImpl[kShaderTypeCount]; + int shaderEnabledID[kShaderTypeCount]; + + int separateSpecular; + + int colorWriteMask; // ColorWriteMask combinations + + TextureUnitStateGL textures[kMaxSupportedTextureUnits]; + VertexLightStateGL vertexLights[kMaxSupportedVertexLights]; + + DynamicVBO* m_DynamicVBO; + + int viewport[4]; + int scissorRect[4]; + + GfxPrimitiveType m_ImmediateMode; + dynamic_array<UInt8> m_ImmediateVertices; + + #if GFX_USES_VIEWPORT_OFFSET + float viewportOffsetX, viewportOffsetY; + #endif + + CachedBlendStates m_CachedBlendStates; + CachedDepthStates m_CachedDepthStates; + CachedStencilStates m_CachedStencilStates; + CachedRasterStates m_CachedRasterStates; + + DeviceBlendStateGL* m_CurrBlendState; + DeviceDepthStateGL* m_CurrDepthState; + const DeviceStencilStateGL* m_CurrStencilState; + int m_StencilRef; + DeviceRasterState* m_CurrRasterState; + Matrix4x4f m_WorldMatrix; + + void Invalidate(BuiltinShaderParamValues& builtins); + void Verify(); +}; + +static void ApplyBackfaceMode( const DeviceStateGL& state ); + + +void DeviceStateGL::Invalidate (BuiltinShaderParamValues& builtins) +{ + int i; + + depthFunc = kFuncUnknown; + depthWrite = -1; + + blending = -1; // unknown + srcBlend = destBlend = srcBlendAlpha = destBlendAlpha = -1; // won't match any GL mode + blendOp = blendOpAlpha = -1; // won't match any GL mode + alphaFunc = kFuncUnknown; + alphaValue = -1.0f; + alphaToMask = -1; // unknown + + culling = kCullUnknown; + normalization = kNormalizationUnknown; + scissor = -1; + + lighting = -1; + matDiffuse.Set( -1, -1, -1, -1 ); + matAmbient.Set( -1, -1, -1, -1 ); + matSpecular.Set( -1, -1, -1, -1 ); + matEmissive.Set( -1, -1, -1, -1 ); + ambient.Set( -1, -1, -1, -1 ); + matShininess = -1.0f; + colorMaterial = kColorMatUnknown; + + offsetFactor = offsetUnits = -1000.0f; + for( i = 0; i < kShaderTypeCount; ++i ) + { + activeGpuProgram[i] = NULL; + activeGpuProgramParams[i] = NULL; + shaderEnabledImpl[i] = kShaderImplUndefined; + shaderEnabledID[i] = -1; + } + + separateSpecular = -1; + + colorWriteMask = -1; // TBD ? + + m_StencilRef = -1; + + for( i = 0; i < kMaxSupportedTextureUnits; ++i ) + textures[i].Invalidate(); + for( i = 0; i < kMaxSupportedVertexLights; ++i ) + vertexLights[i].Invalidate(); + InvalidateChannelStateGL(); + InvalidateFPParamCacheGL(); + + // make sure we aren't using any programs + if( gGraphicsCaps.gl.hasGLSL ) + glUseProgramObjectARB( 0 ); + glDisable( GL_VERTEX_PROGRAM_ARB ); + glDisable( GL_FRAGMENT_PROGRAM_ARB ); + + // misc. state + glHint (GL_FOG_HINT, GL_NICEST); + glLightModelf (GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0F); + + // Setup GL_EYE_PLANE for R coordinate to reasonable value. This has to be done initially, + // and NOT when some arbitrary matrix is already set up. So it's important + // to load identity matrix here and only then setup GL_EYE_PLANE value. + glLoadIdentity(); + m_WorldMatrix.SetIdentity(); + builtins.GetWritableMatrixParam(kShaderMatView).SetIdentity(); + builtins.GetWritableMatrixParam(kShaderMatProj).SetIdentity(); + builtins.GetWritableMatrixParam(kShaderMatViewProj).SetIdentity(); + const float zplane[4] = {0.0f,0.0f,1.0f,0.0f}; + for( i = 0; i < gGraphicsCaps.maxTexUnits; ++i ) + { + ActivateTextureUnitGL (i); + glTexGenfv (GL_R, GL_EYE_PLANE, zplane); + } + + // make sure backface mode is in synch + ApplyBackfaceMode( *this ); + + // make sure no vertex buffers are bound + UnbindVertexBuffersGL(); + + m_ImmediateMode = kPrimitiveTriangles; + m_ImmediateVertices.clear(); + + #if GFX_DEVICE_VERIFY_ENABLE + Verify(); + #endif +} + +#include "GfxDeviceGL.h" + +// GLContext.cpp +#if UNITY_WIN +bool CreateMasterGraphicsContext(); +#endif +void CleanupMasterContext(); + + +GfxThreadableDevice* CreateGLGfxDevice() +{ + #if UNITY_WIN + SetMasterContextClassName(L"WindowGLClassName"); + if( !CreateMasterGraphicsContext() ) + return NULL; + #endif + GraphicsContextHandle context = GetMasterGraphicsContext(); + if( !context.IsValid() ) + return NULL; + + SetMainGraphicsContext( context ); + ActivateGraphicsContext (context, true); + + InitGLExtensions(); + gGraphicsCaps.InitGL(); + GLAssert(); + + return UNITY_NEW_AS_ROOT(GFX_GL_IMPL(), kMemGfxDevice, "GLGfxDevice", ""); +} + + +GFX_GL_IMPL::GFX_GL_IMPL() +{ + #if !GFX_DEVICE_VIRTUAL + impl = new GfxDeviceImpl(); + #endif + STATE.m_SharedFBO = 0; + STATE.m_HelperFBO = 0; + STATE.m_TextureIDGenerator = 0; + STATE.appBackfaceMode = false; + STATE.userBackfaceMode = false; + STATE.m_DynamicVBO = NULL; + STATE.wireframe = false; + #if GFX_USES_VIEWPORT_OFFSET + STATE.viewportOffsetX = 0; + STATE.viewportOffsetY = 0; + #endif + + OnCreate(); + InvalidateState(); + + m_Renderer = kGfxRendererOpenGL; + m_UsesOpenGLTextureCoords = true; + m_UsesHalfTexelOffset = false; + // Should be safe to assume we can get 24 bits for the framebuffer on desktop. + m_FramebufferDepthFormat = kDepthFormat24; + m_IsThreadable = true; + + STATE.m_CurrBlendState = NULL; + STATE.m_CurrDepthState = NULL; + STATE.m_CurrStencilState = NULL; + STATE.m_CurrRasterState = NULL; + + STATE.m_WorldMatrix.SetIdentity(); + + m_MaxBufferedFrames = -1; // no limiting + + STATE.viewport[0] = STATE.viewport[1] = STATE.viewport[2] = STATE.viewport[3] = 0; + STATE.scissorRect[0] = STATE.scissorRect[1] = STATE.scissorRect[2] = STATE.scissorRect[3] = 0; + + extern RenderSurfaceBase* CreateBackBufferColorSurfaceGL(); + SetBackBufferColorSurface(CreateBackBufferColorSurfaceGL()); + + extern RenderSurfaceBase* CreateBackBufferDepthSurfaceGL(); + SetBackBufferDepthSurface(CreateBackBufferDepthSurfaceGL()); +} + +GFX_GL_IMPL::~GFX_GL_IMPL() +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_WORKER + PluginsSetGraphicsDevice (NULL, kGfxRendererOpenGL, kGfxDeviceEventShutdown); +#endif + if (STATE.m_SharedFBO) + glDeleteFramebuffersEXT (1, &STATE.m_SharedFBO); + if (STATE.m_HelperFBO) + glDeleteFramebuffersEXT (1, &STATE.m_HelperFBO); + delete STATE.m_DynamicVBO; + + #if !GFX_DEVICE_VIRTUAL + delete impl; + #endif + + #if UNITY_WIN + CleanupMasterContext(); + #endif + CleanupGLExtensions(); +} + +void GFX_GL_IMPL::OnDeviceCreated (bool callingFromRenderThread) +{ + // needs to activate graphics context on both main & render threads + ActivateGraphicsContext (GetMainGraphicsContext(), true); +} + +void GFX_GL_IMPL::InvalidateState() +{ + m_FogParams.Invalidate(); + STATE.Invalidate(m_BuiltinParamValues); + + // Disable fog initially. At least on Mac/Intel, initial state seems to be off + // for fixed function (correct), but on for fragment/vertex programs (incorrect). + glFogf( GL_FOG_DENSITY, 0.0f ); + glDisable( GL_FOG ); + m_FogParams.mode = kFogDisabled; + m_FogParams.density = 0.0f; +} + + +const int kFPParamCacheSize = 32; // don't make this larger than 32 (won't fit into s_FPParamCacheValid mask) +extern UInt32 s_FPParamCacheValid; +extern Vector4f s_FPParamCache[kFPParamCacheSize]; + + +#define SET_LOCAL_MATRIX_PARAM( type, index, ptr ) \ + OGL_CALL(glProgramLocalParameter4fARB( type, index+0, ptr[0], ptr[4], ptr[8], ptr[12] )); \ + OGL_CALL(glProgramLocalParameter4fARB( type, index+1, ptr[1], ptr[5], ptr[9], ptr[13] )); \ + OGL_CALL(glProgramLocalParameter4fARB( type, index+2, ptr[2], ptr[6], ptr[10], ptr[14] )); \ + OGL_CALL(glProgramLocalParameter4fARB( type, index+3, ptr[3], ptr[7], ptr[11], ptr[15] )); \ + + +#define SET_ENV_MATRIX_PARAM( type, index, ptr ) \ + OGL_CALL(glProgramEnvParameter4fARB( type, index+0, ptr[0], ptr[4], ptr[8], ptr[12] )); \ + OGL_CALL(glProgramEnvParameter4fARB( type, index+1, ptr[1], ptr[5], ptr[9], ptr[13] )); \ + OGL_CALL(glProgramEnvParameter4fARB( type, index+2, ptr[2], ptr[6], ptr[10], ptr[14] )); \ + OGL_CALL(glProgramEnvParameter4fARB( type, index+3, ptr[3], ptr[7], ptr[11], ptr[15] )); \ + + +static void GLSetShaderMatrixConstant (ShaderImplType type, int index, int rows, int cols, const float* ptr) +{ + if (type == kShaderImplVertex) + { + SET_LOCAL_MATRIX_PARAM(GL_VERTEX_PROGRAM_ARB, index, ptr); + } + else if (type == kShaderImplFragment) + { + if (gGraphicsCaps.gl.cacheFPParamsWithEnvs) + { + // don't care here about cache + UInt32 mask0 = index+0 < kFPParamCacheSize ? 1 << (index+0) : 0; + UInt32 mask1 = index+1 < kFPParamCacheSize ? 1 << (index+1) : 0; + UInt32 mask2 = index+2 < kFPParamCacheSize ? 1 << (index+2) : 0; + UInt32 mask3 = index+3 < kFPParamCacheSize ? 1 << (index+3) : 0; + + s_FPParamCacheValid &= ~mask0; + s_FPParamCacheValid &= ~mask1; + s_FPParamCacheValid &= ~mask2; + s_FPParamCacheValid &= ~mask3; + + SET_ENV_MATRIX_PARAM(GL_FRAGMENT_PROGRAM_ARB, index, ptr); + } + else + { + SET_LOCAL_MATRIX_PARAM(GL_FRAGMENT_PROGRAM_ARB, index, ptr); + } + } + else if (type == kShaderImplBoth) + { + Assert(rows == 4 && cols == 4); + OGL_CALL(glUniformMatrix4fvARB(index, 1, false, ptr)); + } + else + { + AssertString("unknown shader type"); + } +} + + +#undef SET_ENV_MATRIX_PARAM +#undef SET_LOCAL_MATRIX_PARAM + +static void GLSetShaderVectorConstant (ShaderImplType shaderType, ShaderParamType type, int index, int dim, const Vector4f& val) +{ + if (shaderType == kShaderImplVertex) + { + OGL_CALL(glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, index, val.GetPtr())); + } + else if (shaderType == kShaderImplFragment) + { + if (gGraphicsCaps.gl.cacheFPParamsWithEnvs) + { + UInt32 mask = 1 << index; + if (index >= kFPParamCacheSize) + { + OGL_CALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, index, val.GetPtr())); + } + else + { + if( !(s_FPParamCacheValid & mask) || s_FPParamCache[index] != val ) + { + OGL_CALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, index, val.GetPtr())); + s_FPParamCache[index] = val; + } + s_FPParamCacheValid |= mask; + } + } + else + OGL_CALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, index, val.GetPtr())); + } + else if (shaderType == kShaderImplBoth) + { + if (type == kShaderParamFloat) + { + switch (dim) { + case 1: OGL_CALL(glUniform1fvARB(index, 1, val.GetPtr())); break; + case 2: OGL_CALL(glUniform2fvARB(index, 1, val.GetPtr())); break; + case 3: OGL_CALL(glUniform3fvARB(index, 1, val.GetPtr())); break; + case 4: OGL_CALL(glUniform4fvARB(index, 1, val.GetPtr())); break; + default: AssertString ("unknown uniform dimension"); break; + } + } + else + { + // In theory Uniform*f can also be used to load bool uniforms, in practice + // some drivers don't like that. So load both integers and bools via *i functions. + int ival[4] = {val.x, val.y, val.z, val.w}; + switch (dim) { + case 1: OGL_CALL(glUniform1ivARB(index, 1, ival)); break; + case 2: OGL_CALL(glUniform2ivARB(index, 1, ival)); break; + case 3: OGL_CALL(glUniform3ivARB(index, 1, ival)); break; + case 4: OGL_CALL(glUniform4ivARB(index, 1, ival)); break; + default: AssertString ("unknown uniform dimension"); break; + } + } + } + else + { + AssertString("unknown shader type"); + } +} + + +struct SetValuesFunctorGL +{ + SetValuesFunctorGL(GfxDevice& device, const ShaderImplType* shaderEnabledImpl) : m_Device(device), m_ShaderEnabledImpl(shaderEnabledImpl) { } + GfxDevice& m_Device; + const ShaderImplType* m_ShaderEnabledImpl; + void SetVectorVal (ShaderType shaderType, ShaderParamType type, int index, const float* ptr, int cols, const GpuProgramParameters& params, int cbIndex) + { + GLSetShaderVectorConstant (m_ShaderEnabledImpl[shaderType], type, index, cols, *(const Vector4f*)ptr); + } + void SetMatrixVal (ShaderType shaderType, int index, const Matrix4x4f* ptr, int rows, const GpuProgramParameters& params, int cbIndex) + { + GLSetShaderMatrixConstant (m_ShaderEnabledImpl[shaderType], index, rows, 4, (const float*)ptr); + } + void SetTextureVal (ShaderType shaderType, int index, int samplerIndex, TextureDimension dim, TextureID texID) + { + UInt32 texIndex = UInt32(index) >> 24; + m_Device.SetTexture (shaderType, texIndex, samplerIndex, texID, dim, std::numeric_limits<float>::infinity()); + } +}; + + +void GFX_GL_IMPL::BeforeDrawCall( bool immediateMode ) +{ + GFX_LOG(("%d",immediateMode)); + + // Special Matrix parameters (defined by Unity as built-ins + // but not present in GL default state) + const BuiltinShaderParamIndices& paramsVS = *m_BuiltinParamIndices[kShaderVertex]; + const BuiltinShaderParamIndices& paramsFS = *m_BuiltinParamIndices[kShaderFragment]; + + // M matrix + if (paramsVS.mat[kShaderInstanceMatM].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = paramsVS.mat[kShaderInstanceMatM]; + const Matrix4x4f& mat = STATE.m_WorldMatrix; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLSetShaderMatrixConstant (STATE.shaderEnabledImpl[kShaderVertex], matParam.gpuIndex, matParam.rows, matParam.cols, mat.GetPtr()); + } + if (paramsFS.mat[kShaderInstanceMatM].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = paramsFS.mat[kShaderInstanceMatM]; + const Matrix4x4f& mat = STATE.m_WorldMatrix; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLSetShaderMatrixConstant (STATE.shaderEnabledImpl[kShaderFragment], matParam.gpuIndex, matParam.rows, matParam.cols, mat.GetPtr()); + } + // Inverse M matrix + if (paramsVS.mat[kShaderInstanceMatInvM].gpuIndex >= 0 || paramsFS.mat[kShaderInstanceMatInvM].gpuIndex >= 0) + { + Matrix4x4f mat = STATE.m_WorldMatrix; + if (STATE.normalization == kNormalizationScale) + { + // Kill scale in the world matrix before inverse + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + mat.Get (0, 0) *= invScale; + mat.Get (1, 0) *= invScale; + mat.Get (2, 0) *= invScale; + mat.Get (0, 1) *= invScale; + mat.Get (1, 1) *= invScale; + mat.Get (2, 1) *= invScale; + mat.Get (0, 2) *= invScale; + mat.Get (1, 2) *= invScale; + mat.Get (2, 2) *= invScale; + } + Matrix4x4f inverseMat; + Matrix4x4f::Invert_General3D (mat, inverseMat); + if (paramsVS.mat[kShaderInstanceMatInvM].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = paramsVS.mat[kShaderInstanceMatInvM]; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLSetShaderMatrixConstant (STATE.shaderEnabledImpl[kShaderVertex], matParam.gpuIndex, matParam.rows, matParam.cols, inverseMat.GetPtr()); + } + if (paramsFS.mat[kShaderInstanceMatInvM].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = paramsFS.mat[kShaderInstanceMatInvM]; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLSetShaderMatrixConstant (STATE.shaderEnabledImpl[kShaderFragment], matParam.gpuIndex, matParam.rows, matParam.cols, inverseMat.GetPtr()); + } + } + + // Set instance vector parameters + for (int i = 0; i < kShaderInstanceVecCount; ++i) + { + const BuiltinShaderParamIndices::VectorParamData& parVS = paramsVS.vec[i]; + if (parVS.gpuIndex >= 0) + GLSetShaderVectorConstant (STATE.shaderEnabledImpl[kShaderVertex], kShaderParamFloat, parVS.gpuIndex, parVS.dim, m_BuiltinParamValues.GetInstanceVectorParam((ShaderBuiltinInstanceVectorParam)i)); + const BuiltinShaderParamIndices::VectorParamData& parFS = paramsFS.vec[i]; + if (parFS.gpuIndex >= 0) + GLSetShaderVectorConstant (STATE.shaderEnabledImpl[kShaderFragment], kShaderParamFloat, parFS.gpuIndex, parFS.dim, m_BuiltinParamValues.GetInstanceVectorParam((ShaderBuiltinInstanceVectorParam)i)); + } + + SetValuesFunctorGL setValuesFunc(*this, STATE.shaderEnabledImpl); + ApplyMaterialPropertyBlockValues(m_MaterialProperties, STATE.activeGpuProgram, STATE.activeGpuProgramParams, setValuesFunc); +} + + +DeviceBlendState* GFX_GL_IMPL::CreateBlendState(const GfxBlendState& state) +{ + + std::pair<CachedBlendStates::iterator, bool> result = STATE.m_CachedBlendStates.insert(std::make_pair(state, DeviceBlendStateGL())); + if (!result.second) + return &result.first->second; + + DeviceBlendStateGL& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(GfxBlendState)); + DebugAssertIf(kFuncUnknown==state.alphaTest); + glstate.alphaFunc = kCmpFuncGL[state.alphaTest]; + + return &result.first->second; +} + + +DeviceDepthState* GFX_GL_IMPL::CreateDepthState(const GfxDepthState& state) +{ + std::pair<CachedDepthStates::iterator, bool> result = STATE.m_CachedDepthStates.insert(std::make_pair(state, DeviceDepthStateGL())); + if (!result.second) + return &result.first->second; + + DeviceDepthStateGL& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(GfxDepthState)); + glstate.depthFunc = kCmpFuncGL[state.depthFunc]; + return &result.first->second; +} + +DeviceStencilState* GFX_GL_IMPL::CreateStencilState(const GfxStencilState& state) +{ + std::pair<CachedStencilStates::iterator, bool> result = STATE.m_CachedStencilStates.insert(std::make_pair(state, DeviceStencilStateGL())); + if (!result.second) + return &result.first->second; + + DeviceStencilStateGL& st = result.first->second; + memcpy (&st.sourceState, &state, sizeof(state)); + st.stencilFuncFront = kCmpFuncGL[state.stencilFuncFront]; + st.stencilFailOpFront = kStencilOpGL[state.stencilFailOpFront]; + st.depthFailOpFront = kStencilOpGL[state.stencilZFailOpFront]; + st.depthPassOpFront = kStencilOpGL[state.stencilPassOpFront]; + st.stencilFuncBack = kCmpFuncGL[state.stencilFuncBack]; + st.stencilFailOpBack = kStencilOpGL[state.stencilFailOpBack]; + st.depthFailOpBack = kStencilOpGL[state.stencilZFailOpBack]; + st.depthPassOpBack = kStencilOpGL[state.stencilPassOpBack]; + return &result.first->second; +} + + +DeviceRasterState* GFX_GL_IMPL::CreateRasterState(const GfxRasterState& state) +{ + std::pair<CachedRasterStates::iterator, bool> result = STATE.m_CachedRasterStates.insert(std::make_pair(state, DeviceRasterState())); + if (!result.second) + return &result.first->second; + + DeviceRasterState& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(DeviceRasterState)); + + return &result.first->second; +} + +void GFX_GL_IMPL::SetBlendState(const DeviceBlendState* state, float alphaRef) +{ + DeviceBlendStateGL* devstate = (DeviceBlendStateGL*)state; + + if (STATE.m_CurrBlendState == devstate && alphaRef == STATE.alphaValue) + return; + + STATE.m_CurrBlendState = devstate; + if (!STATE.m_CurrBlendState) + return; + + int mask = devstate->sourceState.renderTargetWriteMask; + if (!IsActiveRenderTargetWithColorGL()) + mask = 0; + if( mask != STATE.colorWriteMask ) { + OGL_CALL(glColorMask( (mask & kColorWriteR) != 0, (mask & kColorWriteG) != 0, (mask & kColorWriteB) != 0, (mask & kColorWriteA) != 0 )); + STATE.colorWriteMask = mask; + } + + const GfxBlendState& desc = state->sourceState; + const CompareFunction mode = state->sourceState.alphaTest; + const GLenum glsrc = kBlendModeGL[desc.srcBlend]; + const GLenum gldst = kBlendModeGL[desc.dstBlend]; + const GLenum glsrca = kBlendModeGL[desc.srcBlendAlpha]; + const GLenum gldsta = kBlendModeGL[desc.dstBlendAlpha]; + const GLenum glfunc = kBlendFuncGL[desc.blendOp]; + const GLenum glfunca = kBlendFuncGL[desc.blendOpAlpha]; + const bool blendDisabled = (glsrc == GL_ONE && gldst == GL_ZERO && glsrca == GL_ONE && gldsta == GL_ZERO); + + GFX_LOG(("%d, %d, %d, %f", desc.srcBlend, desc.dstBlend, mode, alphaRef)); + + // alpha blending states + + if( blendDisabled ) + { + if( STATE.blending != 0 ) + { + OGL_CALL(glDisable (GL_BLEND)); + STATE.blending = 0; + } + } + else + { + if( glsrc != STATE.srcBlend || gldst != STATE.destBlend || glsrca != STATE.srcBlendAlpha || gldsta != STATE.destBlendAlpha ) + { + if (gGraphicsCaps.hasSeparateAlphaBlend) + OGL_CALL(glBlendFuncSeparateEXT (glsrc, gldst, glsrca, gldsta)); + else + OGL_CALL(glBlendFunc( glsrc, gldst )); + STATE.srcBlend = glsrc; + STATE.destBlend = gldst; + STATE.srcBlendAlpha = glsrca; + STATE.destBlendAlpha = gldsta; + } + if (glfunc != STATE.blendOp || glfunca != STATE.blendOpAlpha) + { + bool supports = true; + if( (glfunc == GL_FUNC_SUBTRACT || glfunc == GL_FUNC_REVERSE_SUBTRACT) && !gGraphicsCaps.hasBlendSub ) + supports = false; + if( (glfunca == GL_FUNC_SUBTRACT || glfunca == GL_FUNC_REVERSE_SUBTRACT) && !gGraphicsCaps.hasBlendSub ) + supports = false; + if( (glfunc == GL_MIN || glfunc == GL_MAX) && !gGraphicsCaps.hasBlendMinMax ) + supports = false; + if( (glfunca == GL_MIN || glfunca == GL_MAX) && !gGraphicsCaps.hasBlendMinMax ) + supports = false; + + if(supports) + { + if (gGraphicsCaps.hasSeparateAlphaBlend) + OGL_CALL(glBlendEquationSeparateEXT (glfunc, glfunca)); + else + OGL_CALL(glBlendEquation (glfunc)); + STATE.blendOp = glfunc; + STATE.blendOpAlpha = glfunca; + } + } + if( STATE.blending != 1 ) + { + OGL_CALL(glEnable( GL_BLEND )); + STATE.blending = 1; + } + } + + // alpha testing states +#if UNITY_EDITOR // gles2.0 doesn't have FF alpha testing(only discard/clip on shader side), so disable on editor while emulating + bool skipAlphaTestFF = (gGraphicsCaps.IsEmulatingGLES20() && IsShaderActive(kShaderFragment)); + // possible that vertex shader will be used with FF "frag shader" (like Transparent/vertexlit.shader), + // which will change alphatesting. So later on when real frag shaders come, we need to force disable alpha + // testing or enjoy nasty artefacts (like active alpha testing messing up the whole scene). + if ( skipAlphaTestFF && STATE.alphaFunc!=kFuncDisabled ) + { + OGL_CALL(glDisable (GL_ALPHA_TEST)); + STATE.alphaFunc = kFuncDisabled; + } + + if ( !skipAlphaTestFF ) + { +#endif + if( mode != STATE.alphaFunc || alphaRef != STATE.alphaValue ) + { + if( mode != kFuncDisabled ) + { + OGL_CALL(glAlphaFunc( kCmpFuncGL[mode], alphaRef )); + OGL_CALL(glEnable( GL_ALPHA_TEST )); + } + else + { + OGL_CALL(glDisable (GL_ALPHA_TEST)); + } + + STATE.alphaFunc = mode; + STATE.alphaValue = alphaRef; + } +#if UNITY_EDITOR + } +#endif + +#if 0 + int atomask = alphaToMask ? 1 : 0; + if( atomask != STATE.alphaToMask && gGraphicsCaps.hasMultiSample ) + { + if( atomask ) + OGL_CALL(glEnable( GL_SAMPLE_ALPHA_TO_COVERAGE )); + else + OGL_CALL(glDisable( GL_SAMPLE_ALPHA_TO_COVERAGE )); + STATE.alphaToMask = atomask; + } +#endif +} + + +void GFX_GL_IMPL::SetRasterState(const DeviceRasterState* state) +{ + DeviceRasterState* devstate = (DeviceRasterState*)state; + if(!devstate) + { + STATE.m_CurrRasterState = NULL; + return; + } + + STATE.m_CurrRasterState = devstate; + + CullMode cull = devstate->sourceState.cullMode; + if( cull != STATE.culling ) + { + switch (cull) { + case kCullOff: + OGL_CALL(glDisable (GL_CULL_FACE)); + break; + case kCullFront: + OGL_CALL(glCullFace (GL_FRONT)); + OGL_CALL(glEnable (GL_CULL_FACE)); + break; + case kCullBack: + OGL_CALL(glCullFace (GL_BACK)); + OGL_CALL(glEnable (GL_CULL_FACE)); + break; + } + STATE.culling = cull; + } + + float zFactor = devstate->sourceState.slopeScaledDepthBias; + float zUnits = devstate->sourceState.depthBias; + if( zFactor != STATE.offsetFactor || zUnits != STATE.offsetUnits ) + { + OGL_CALL(glPolygonOffset( zFactor, zUnits )); + if( zFactor || zUnits ) + OGL_CALL(glEnable (GL_POLYGON_OFFSET_FILL)); + else + OGL_CALL(glDisable (GL_POLYGON_OFFSET_FILL)); + + STATE.offsetFactor = zFactor; + STATE.offsetUnits = zUnits; + } +} + + +void GFX_GL_IMPL::SetDepthState(const DeviceDepthState* state) +{ + DeviceDepthStateGL* devstate = (DeviceDepthStateGL*)state; + if (STATE.m_CurrDepthState == devstate) + return; + + STATE.m_CurrDepthState = devstate; + + if (!STATE.m_CurrDepthState) + return; + + const CompareFunction testFunc = devstate->sourceState.depthFunc; + if( testFunc != STATE.depthFunc ) + { + if( testFunc != kFuncDisabled ) { + OGL_CALL(glDepthFunc (kCmpFuncGL[testFunc])); + OGL_CALL(glEnable (GL_DEPTH_TEST)); + } else { + OGL_CALL(glDisable (GL_DEPTH_TEST)); + } + + STATE.depthFunc = testFunc; + } + + const int writeMode = devstate->sourceState.depthWrite ? GL_TRUE : GL_FALSE; + if( writeMode != STATE.depthWrite ) + { + OGL_CALL(glDepthMask (writeMode)); + STATE.depthWrite = writeMode; + } +} + +void GFX_GL_IMPL::SetStencilState (const DeviceStencilState* state, int stencilRef) +{ + if (STATE.m_CurrStencilState == state && STATE.m_StencilRef == stencilRef) + return; + const DeviceStencilStateGL* st = static_cast<const DeviceStencilStateGL*>(state); + STATE.m_CurrStencilState = st; + if (!st) + return; + + if (st->sourceState.stencilEnable) + glEnable (GL_STENCIL_TEST); + else + glDisable (GL_STENCIL_TEST); + if (gGraphicsCaps.hasTwoSidedStencil) + { + glStencilFuncSeparate (GL_FRONT, st->stencilFuncFront, stencilRef, st->sourceState.readMask); + glStencilOpSeparate (GL_FRONT, st->stencilFailOpFront, st->depthFailOpFront, st->depthPassOpFront); + glStencilFuncSeparate (GL_BACK, st->stencilFuncBack, stencilRef, st->sourceState.readMask); + glStencilOpSeparate (GL_BACK, st->stencilFailOpBack, st->depthFailOpBack, st->depthPassOpBack); + } + else + { + glStencilFunc (st->stencilFuncFront, stencilRef, st->sourceState.readMask); + glStencilOp (st->stencilFailOpFront, st->depthFailOpFront, st->depthPassOpFront); + } + glStencilMask (st->sourceState.writeMask); + + STATE.m_StencilRef = stencilRef; +} + + +void GFX_GL_IMPL::SetSRGBWrite (bool enable) +{ + if (!gGraphicsCaps.hasSRGBReadWrite) + return; + + if (enable) + OGL_CALL(glEnable(GL_FRAMEBUFFER_SRGB_EXT)); + else + OGL_CALL(glDisable(GL_FRAMEBUFFER_SRGB_EXT)); +} + +bool GFX_GL_IMPL::GetSRGBWrite () +{ + return gGraphicsCaps.hasSRGBReadWrite ? + glIsEnabled(GL_FRAMEBUFFER_SRGB_EXT): + false; +} + +void GFX_GL_IMPL::Clear (UInt32 clearFlags, const float color[4], float depth, int stencil) +{ + GFX_LOG(("%d, {%f, %f, %f, %f}, %f, %d", clearFlags, color[0], color[1], color[2], color[3], depth, stencil)); + + if (!IsActiveRenderTargetWithColorGL()) + clearFlags &= ~kGfxClearColor; + + // In OpenGL, clears are affected by color write mask and depth writing parameters. + // So make sure to set them! + GLbitfield flags = 0; + if (clearFlags & kGfxClearColor) + { + if (STATE.colorWriteMask != 15) + { + OGL_CALL(glColorMask( true, true, true, true )); + STATE.colorWriteMask = 15; + STATE.m_CurrBlendState = NULL; + } + flags |= GL_COLOR_BUFFER_BIT; + glClearColor (color[0], color[1], color[2], color[3]); + } + if (clearFlags & kGfxClearDepth) + { + OGL_CALL(glDepthMask (GL_TRUE)); + STATE.depthWrite = GL_TRUE; + STATE.m_CurrDepthState = NULL; + flags |= GL_DEPTH_BUFFER_BIT; + glClearDepth (depth); + } + if (clearFlags & kGfxClearStencil) + { + //@TODO: need to set stencil writes on? + flags |= GL_STENCIL_BUFFER_BIT; + glClearStencil (stencil); + } + glClear (flags); +} + + +static void ApplyBackfaceMode( const DeviceStateGL& state ) +{ + const bool bFlip = (state.appBackfaceMode != state.userBackfaceMode); + + if( bFlip ) + OGL_CALL(glFrontFace( GL_CCW )); + else + OGL_CALL(glFrontFace( GL_CW )); + + if(state.culling == kCullUnknown || state.culling == kCullOff) + return; + + DeviceRasterState* devstate = state.m_CurrRasterState; + if(!devstate) + return; + + GfxDevice &device = GetRealGfxDevice(); + device.SetRasterState(0); + device.SetRasterState(devstate); +} + + +void GFX_GL_IMPL::SetUserBackfaceMode( bool enable ) +{ + GFX_LOG(("%d", enable)); + if( STATE.userBackfaceMode == enable ) + return; + STATE.userBackfaceMode = enable; + ApplyBackfaceMode( STATE ); +} + + +void GFX_GL_IMPL::SetWireframe( bool wire ) +{ + if( wire ) + { + OGL_CALL(glEnable (GL_POLYGON_OFFSET_LINE)); + OGL_CALL(glPolygonMode (GL_FRONT_AND_BACK, GL_LINE)); + STATE.wireframe = true; + } + else + { + OGL_CALL(glDisable (GL_POLYGON_OFFSET_LINE)); + OGL_CALL(glPolygonMode (GL_FRONT_AND_BACK, GL_FILL)); + STATE.wireframe = false; + } +} + +bool GFX_GL_IMPL::GetWireframe() const +{ + return STATE.wireframe; +} + + + +void GFX_GL_IMPL::SetInvertProjectionMatrix (bool enable) +{ + Assert (!enable); // projection should never be flipped upside down on OpenGL +} + +bool GFX_GL_IMPL::GetInvertProjectionMatrix() const +{ + return false; +} + +#if GFX_USES_VIEWPORT_OFFSET +void GFX_GL_IMPL::SetViewportOffset( float x, float y ) +{ + GFX_LOG(("%f, %f", x, y)); + STATE.viewportOffsetX = x; + STATE.viewportOffsetY = y; +} + +void GFX_GL_IMPL::GetViewportOffset( float &x, float &y ) const +{ + x = STATE.viewportOffsetX; + y = STATE.viewportOffsetY; +} +#endif + +void GFX_GL_IMPL::SetProjectionMatrix (const Matrix4x4f& matrix) +{ + GFX_LOG(("{%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f}", + matrix[0], matrix[1], matrix[2], matrix[3], + matrix[4], matrix[5], matrix[6], matrix[7], + matrix[8], matrix[9], matrix[10], matrix[11], + matrix[12], matrix[13], matrix[14], matrix[15])); + + Matrix4x4f& projMat = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj); + CopyMatrix (matrix.GetPtr(), projMat.GetPtr()); + OGL_CALL(glMatrixMode( GL_PROJECTION )); + OGL_CALL(glLoadMatrixf (matrix.GetPtr())); + OGL_CALL(glMatrixMode( GL_MODELVIEW )); +} + +void GFX_GL_IMPL::SetWorldMatrix( const float matrix[16] ) +{ + GFX_LOG(("{%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f}", + matrix[0], matrix[1], matrix[2], matrix[3], + matrix[4], matrix[5], matrix[6], matrix[7], + matrix[8], matrix[9], matrix[10], matrix[11], + matrix[12], matrix[13], matrix[14], matrix[15])); + + CopyMatrix(matrix, STATE.m_WorldMatrix.GetPtr()); + + OGL_CALL(glLoadMatrixf(m_BuiltinParamValues.GetMatrixParam(kShaderMatView).GetPtr())); + OGL_CALL(glMultMatrixf(matrix)); +} + +void GFX_GL_IMPL::SetViewMatrix( const float matrix[16] ) +{ + glMatrixMode(GL_MODELVIEW); + glLoadMatrixf(matrix); + + const Matrix4x4f& projMat = m_BuiltinParamValues.GetMatrixParam(kShaderMatProj); + Matrix4x4f& viewMat = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatView); + Matrix4x4f& viewProjMat = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatViewProj); + CopyMatrix (matrix, viewMat.GetPtr()); + MultiplyMatrices4x4 (&projMat, &viewMat, &viewProjMat); + STATE.m_WorldMatrix.SetIdentity(); +} + + +void GFX_GL_IMPL::GetMatrix( float outMatrix[16] ) const +{ + OGL_CALL(glGetFloatv( GL_MODELVIEW_MATRIX, outMatrix )); +} + + +const float* GFX_GL_IMPL::GetWorldMatrix() const +{ + return STATE.m_WorldMatrix.GetPtr(); +} + +const float* GFX_GL_IMPL::GetViewMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatView).GetPtr(); +} + +const float* GFX_GL_IMPL::GetProjectionMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatProj).GetPtr(); +} + +const float* GFX_GL_IMPL::GetDeviceProjectionMatrix() const +{ + return GetProjectionMatrix(); +} + + + +void GFX_GL_IMPL::SetNormalizationBackface( NormalizationMode mode, bool backface ) +{ + GFX_LOG(("%d, %d", mode, backface)); + + if( mode != STATE.normalization ) + { + if( mode == kNormalizationDisabled ) + { + OGL_CALL(glDisable (GL_NORMALIZE)); + OGL_CALL(glDisable (GL_RESCALE_NORMAL)); + } + else if( mode == kNormalizationScale ) + { + OGL_CALL(glDisable (GL_NORMALIZE)); + OGL_CALL(glEnable (GL_RESCALE_NORMAL)); + } + else + { + OGL_CALL(glEnable (GL_NORMALIZE)); + OGL_CALL(glDisable (GL_RESCALE_NORMAL)); + } + + STATE.normalization = mode; + } + if( STATE.appBackfaceMode != backface ) + { + STATE.appBackfaceMode = backface; + ApplyBackfaceMode( STATE ); + } +} + +void GFX_GL_IMPL::SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) +{ + GFX_LOG(("%d, %d, %d", on, separateSpecular, colorMaterial)); + + int lighting = on ? 1 : 0; + if( lighting != STATE.lighting ) + { + if( lighting ) + OGL_CALL(glEnable( GL_LIGHTING )); + else + OGL_CALL(glDisable( GL_LIGHTING )); + STATE.lighting = lighting; + } + + int sepSpec = separateSpecular ? 1 : 0; + + if (STATE.separateSpecular != sepSpec) + { + // Never set separate specular and color sum to different values. + // Otherwise SIS 76x on OpenGL will hang up the machine. + // And we probably never need them to be different anyway :) + if( separateSpecular ) + { + OGL_CALL(glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR )); + OGL_CALL(glEnable( GL_COLOR_SUM_EXT )); + } + else + { + OGL_CALL(glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR )); + OGL_CALL(glDisable( GL_COLOR_SUM_EXT )); + } + STATE.separateSpecular = sepSpec; + } + + if( colorMaterial != STATE.colorMaterial ) + { + if( colorMaterial != kColorMatDisabled ) + { + OGL_CALL(glColorMaterial( GL_FRONT_AND_BACK, kColorMatModeGL[colorMaterial] )); + OGL_CALL(glEnable( GL_COLOR_MATERIAL )); + } + else + { + OGL_CALL(glDisable( GL_COLOR_MATERIAL )); + + // looks like by disabling ColorMaterial OpenGL driver will reset material props + // therefore we invalidate materials cache + STATE.matAmbient.Set(-1, -1, -1, -1); + STATE.matDiffuse.Set(-1, -1, -1, -1); + STATE.matSpecular.Set(-1, -1, -1, -1); + STATE.matEmissive.Set(-1, -1, -1, -1); + } + + STATE.colorMaterial = colorMaterial; + } +} + +void GFX_GL_IMPL::SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) +{ + GFX_LOG(("{%f, %f, %f, %f}, {%f, %f, %f, %f}, {%f, %f, %f, %f}, {%f, %f, %f, %f}, %f", + ambient[0], ambient[1], ambient[2], ambient[3], + diffuse[0], diffuse[1], diffuse[2], diffuse[3], + specular[0], specular[1], specular[2], specular[3], + emissive[0], emissive[1], emissive[2], emissive[3], + shininess)); + if (STATE.matAmbient != ambient) { + OGL_CALL(glMaterialfv (GL_FRONT, GL_AMBIENT, ambient)); + STATE.matAmbient.Set (ambient); + } + + if (STATE.matDiffuse != diffuse) { + OGL_CALL(glMaterialfv (GL_FRONT, GL_DIFFUSE, diffuse)); + STATE.matDiffuse.Set (diffuse); + } + + if (STATE.matSpecular != specular) { + OGL_CALL(glMaterialfv (GL_FRONT, GL_SPECULAR, specular)); + STATE.matSpecular.Set (specular); + } + + if (STATE.matEmissive != emissive) { + OGL_CALL(glMaterialfv (GL_FRONT, GL_EMISSION, emissive)); + STATE.matEmissive.Set (emissive); + } + + if( STATE.matShininess != shininess ) { + float glshine = std::max<float>( std::min<float>(shininess,1.0f), 0.0f) * 128.0f; + OGL_CALL(glMaterialf (GL_FRONT, GL_SHININESS, glshine)); + STATE.matShininess = shininess; + } + + // From shaderstate, the material is set after the ColorMaterial. + // So here if color material is used, setup invalid values to material + // cache; otherwise they would get out of sync. + + switch( STATE.colorMaterial ) { + case kColorMatEmission: STATE.matEmissive.Set(-1, -1, -1, -1); break; + case kColorMatAmbientAndDiffuse: + STATE.matAmbient.Set(-1, -1, -1, -1); + STATE.matDiffuse.Set(-1, -1, -1, -1); + break; + } +} + + +void GFX_GL_IMPL::SetColor( const float color[4] ) +{ + GFX_LOG(("{%f, %f, %f, %f}", color[0], color[1], color[2], color[3])); + OGL_CALL(glColor4fv( color )); +} + + +void GFX_GL_IMPL::SetViewport( int x, int y, int width, int height ) +{ + GFX_LOG(("{%d, %d, %d, %d}", x, y, width, height)); + STATE.viewport[0] = x; + STATE.viewport[1] = y; + STATE.viewport[2] = width; + STATE.viewport[3] = height; + OGL_CALL(glViewport( x, y, width, height )); +} + +void GFX_GL_IMPL::GetViewport( int* port ) const +{ + port[0] = STATE.viewport[0]; + port[1] = STATE.viewport[1]; + port[2] = STATE.viewport[2]; + port[3] = STATE.viewport[3]; +} + +void GFX_GL_IMPL::SetScissorRect( int x, int y, int width, int height ) +{ + GFX_LOG(("{%d, %d, %d, %d}", x, y, width, height)); + if (STATE.scissor != 1) + { + OGL_CALL(glEnable( GL_SCISSOR_TEST )); + STATE.scissor = 1; + } + + STATE.scissorRect[0] = x; + STATE.scissorRect[1] = y; + STATE.scissorRect[2] = width; + STATE.scissorRect[3] = height; + OGL_CALL(glScissor( x, y, width, height )); + +} + +void GFX_GL_IMPL::DisableScissor() +{ + GFX_LOG(("")); + if (STATE.scissor != 0) + { + OGL_CALL(glDisable( GL_SCISSOR_TEST )); + STATE.scissor = 0; + } +} + +bool GFX_GL_IMPL::IsScissorEnabled() const +{ + return STATE.scissor == 1; +} + +void GFX_GL_IMPL::GetScissorRect( int scissor[4] ) const +{ + scissor[0] = STATE.scissorRect[0]; + scissor[1] = STATE.scissorRect[1]; + scissor[2] = STATE.scissorRect[2]; + scissor[3] = STATE.scissorRect[3]; +} + +bool GFX_GL_IMPL::IsCombineModeSupported( unsigned int combiner ) +{ + return TextureCombinersGL::IsCombineModeSupported( combiner ); +} + +TextureCombinersHandle GFX_GL_IMPL::CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) +{ + GFX_LOG(("%d, %d, %d", count, hasVertexColorOrLighting, usesAddSpecular)); + TextureCombinersGL* implGL = TextureCombinersGL::Create( count, texEnvs, props ); + return TextureCombinersHandle( implGL ); +} + +void GFX_GL_IMPL::DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ) +{ + GFX_LOG(("")); + TextureCombinersGL* implGL = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersGL); + delete implGL; + textureCombiners.Reset(); +} + +static void ClearTextureUnitGL (DeviceStateGL& state, int unit) +{ + GFX_LOG(("%d", unit)); + DebugAssert (unit >= 0 && unit < gGraphicsCaps.maxTexUnits); + + TextureUnitStateGL& currTex = state.textures[unit]; + if (currTex.texDim == kTexDimNone) + return; + + if (state.shaderEnabledImpl[kShaderFragment] == kShaderImplUndefined) + { + ActivateTextureUnitGL (unit); + + if( currTex.texDim != kTexDimUnknown ) + { + OGL_CALL(glDisable( kTexDimTableGL[currTex.texDim] )); + } + else + { + OGL_CALL(glDisable( GL_TEXTURE_2D )); + OGL_CALL(glDisable( GL_TEXTURE_1D )); + OGL_CALL(glDisable( GL_TEXTURE_CUBE_MAP_ARB )); + if( gGraphicsCaps.has3DTexture ) + OGL_CALL(glDisable( GL_TEXTURE_3D )); + } + currTex.texDim = kTexDimNone; + } + else + { + currTex.texDim = kTexDimUnknown; + } +} + + +void GFX_GL_IMPL::SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ) +{ + TextureCombinersGL* implGL = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersGL); + AssertIf( !implGL ); + AssertIf (IsShaderActive( kShaderFragment )); + + int i = 0; + for( ; i < gGraphicsCaps.maxTexUnits && i < implGL->count; ++i ) + { + const ShaderLab::TextureBinding& binding = implGL->texEnvs[i]; + + // set the texture + ApplyTexEnvData (i, i, texEnvData[i]); + // apply the combiner + Vector4f texcolorVal = texColors[i]; + TextureUnitStateGL& unitState = STATE.textures[i]; + + // TODO: on Joe's machine this is sometimes failing (FPS tutorial, rotate scene view). + // So we just don't check, which disables the cache. + //if (current.texColor != texcolorVal) { + unitState.color = texcolorVal; + OGL_CALL(glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, texcolorVal.GetPtr() )); + //} + + // setup combine modes + ApplyCombinerGL( unitState.combColor, unitState.combAlpha, binding.m_CombColor, binding.m_CombAlpha ); + } + + // clear unused textures + for (; i < gGraphicsCaps.maxTexUnits; ++i) + ClearTextureUnitGL (STATE, i); + + // Get us back to TU 0, so we know where we stand + ActivateTextureUnitGL (0); +} + +void GFX_GL_IMPL::SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ) +{ + TextureCombinersGL* implGL = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersGL); + AssertIf( !implGL ); + + int count = std::min(implGL->count, gGraphicsCaps.maxTexUnits); + + // Fill in arrays + TexEnvData* texEnvData; + ALLOC_TEMP (texEnvData, TexEnvData, count); + for( int i = 0; i < count; ++i ) + { + ShaderLab::TexEnv *te = ShaderLab::GetTexEnvForBinding( implGL->texEnvs[i], props ); + Assert( te != NULL ); + te->PrepareData (implGL->texEnvs[i].m_TextureName.index, implGL->texEnvs[i].m_MatrixName, props, &texEnvData[i]); + } + + Vector4f* texColors; + ALLOC_TEMP (texColors, Vector4f, count); + for( int i = 0; i < count; ++i ) + { + const ShaderLab::TextureBinding& binding = implGL->texEnvs[i]; + texColors[i] = binding.GetTexColor().Get (props); + } + GFX_GL_IMPL::SetTextureCombinersThreadable(textureCombiners, texEnvData, texColors); +} + +const unsigned long* GetGLTextureDimensionTable() { return kTexDimTableGL; } + +void GFX_GL_IMPL::SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) +{ + GFX_LOG(("%d, %d, %d", unit, texture.m_ID, dim)); + DebugAssertIf( dim < kTexDim2D || dim > kTexDimCUBE ); + + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(texture); + if(targetTex == 0) + return; + + TextureUnitStateGL& currTex = STATE.textures[unit]; + + DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexImageUnits ); + ActivateTextureUnitGL (unit); + + int dimGLTarget = kTexDimTableGL[dim]; + + + if (!IsShaderActive(kShaderFragment)) + { + switch( currTex.texDim ) { + case kTexDimUnknown: + // We don't know which target is enabled, so disable all but the one we + // want to set, and enable only that one + if( dim != kTexDimDeprecated1D ) OGL_CALL(glDisable( GL_TEXTURE_1D )); + if( dim != kTexDim2D ) OGL_CALL(glDisable( GL_TEXTURE_2D )); + if( dim != kTexDimCUBE ) OGL_CALL(glDisable( GL_TEXTURE_CUBE_MAP_ARB )); + if( dim != kTexDim3D && gGraphicsCaps.has3DTexture ) OGL_CALL(glDisable( GL_TEXTURE_3D )); + OGL_CALL(glEnable( dimGLTarget )); + break; + case kTexDimNone: + // Texture unit was disabled. So simply enable our target. + OGL_CALL(glEnable( dimGLTarget )); + break; + default: + // Disable current and enable ours if they're different. + if( currTex.texDim != dim ) { + OGL_CALL(glDisable( kTexDimTableGL[currTex.texDim] )); + OGL_CALL(glEnable( dimGLTarget )); + } + break; + } + currTex.texDim = dim; + } + else + { + currTex.texDim = kTexDimUnknown; + } + + if( targetTex != currTex.texID ) + { + OGL_CALL(glBindTexture(dimGLTarget, targetTex)); + currTex.texID = targetTex; + } + m_Stats.AddUsedTexture(texture); + if (gGraphicsCaps.hasMipLevelBias && bias != currTex.bias && bias != std::numeric_limits<float>::infinity()) + { + OGL_CALL(glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, bias )); + currTex.bias = bias; + } +} + + +void GFX_GL_IMPL::SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]) +{ + GFX_LOG(("%d, %d, %d, %d, {%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f}", + unit, dim, texGen, identity, + matrix[0], matrix[1], matrix[2], matrix[3], + matrix[4], matrix[5], matrix[6], matrix[7], + matrix[8], matrix[9], matrix[10], matrix[11], + matrix[12], matrix[13], matrix[14], matrix[15] + )); + + Assert (unit >= 0 && unit < kMaxSupportedTextureCoords); + + // This assumes the current texture unit is already set!!! + TextureUnitStateGL& unitState = STATE.textures[unit]; + + // -------- texture matrix + + if (unit < gGraphicsCaps.maxTexUnits) + { + OGL_CALL(glMatrixMode( GL_TEXTURE )); + OGL_CALL(glLoadMatrixf( matrix )); + OGL_CALL(glMatrixMode( GL_MODELVIEW )); + } + + // -------- texture coordinate generation + + if( IsShaderActive(kShaderVertex) ) + { + // Ok, in theory we could just return here, as texgen is completely ignored + // with vertex shaders. However, on Mac OS X 10.4.10, Radeon X1600 and GeForce 8600M, + // there seems to be a bug. Repro case: shader that uses a single cubemap texture and + // CubeReflect texgen, and use glow on the camera = glow is wrong. + // + // On Windows / GeForce 7600 on OpenGL (93.71) the behaviour is correct. But I feel safer + // just using the workaround everywhere... + // + // So: with vertex shaders, force texgen to be disabled. The redundant change check below + // will catch most of the cases cheaply anyway. + texGen = kTexGenDisabled; + } + + if( texGen == unitState.texGen ) + return; + + switch( texGen ) + { + case kTexGenDisabled: + OGL_CALL(glDisable (GL_TEXTURE_GEN_S)); + OGL_CALL(glDisable (GL_TEXTURE_GEN_T)); + OGL_CALL(glDisable (GL_TEXTURE_GEN_R)); + break; + case kTexGenSphereMap: + OGL_CALL(glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP)); + OGL_CALL(glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_S)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_T)); + OGL_CALL(glDisable(GL_TEXTURE_GEN_R)); + break; + case kTexGenObject: { + float zplane[4] = {0,0,1,0}; + OGL_CALL(glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)); + OGL_CALL(glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)); + OGL_CALL(glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR)); + OGL_CALL(glTexGenfv (GL_R, GL_OBJECT_PLANE, zplane)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_S)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_T)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_R)); + break; + } + case kTexGenEyeLinear: { + OGL_CALL(glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)); + OGL_CALL(glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)); + OGL_CALL(glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_S)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_T)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_R)); + break; + } + case kTexGenCubeReflect: + OGL_CALL(glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB)); + OGL_CALL(glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB)); + OGL_CALL(glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_S)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_T)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_R)); + break; + case kTexGenCubeNormal: + OGL_CALL(glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB)); + OGL_CALL(glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB)); + OGL_CALL(glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_S)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_T)); + OGL_CALL(glEnable(GL_TEXTURE_GEN_R)); + break; + } + + unitState.texGen = texGen; +} + +void GFX_GL_IMPL::SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + GFX_LOG(("%d, %d, %d, %d, %d, %d, %d", texture.m_ID, texDim, filter, wrap, anisoLevel, hasMipMap, colorSpace)); + + TextureIdMapGL_QueryOrCreate(texture); + + GLuint target = GetGLTextureDimensionTable()[texDim]; + SetTexture (kShaderFragment, 0, 0, texture, texDim, std::numeric_limits<float>::infinity()); + + // Anisotropic texturing... + if( gGraphicsCaps.hasAnisoFilter && target != GL_TEXTURE_3D ) + { + anisoLevel = std::min( anisoLevel, gGraphicsCaps.maxAnisoLevel ); + OGL_CALL(glTexParameteri( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoLevel )); + } + + OGL_CALL(glTexParameteri( target, GL_TEXTURE_WRAP_S, kWrapModeGL[wrap] )); + OGL_CALL(glTexParameteri( target, GL_TEXTURE_WRAP_T, kWrapModeGL[wrap] )); + if( target == GL_TEXTURE_3D || target == GL_TEXTURE_CUBE_MAP_ARB ) + OGL_CALL(glTexParameteri( target, GL_TEXTURE_WRAP_R, kWrapModeGL[wrap] )); + + if( !hasMipMap && filter == kTexFilterTrilinear ) + filter = kTexFilterBilinear; + + OGL_CALL(glTexParameteri( target, GL_TEXTURE_MAG_FILTER, filter != kTexFilterNearest ? GL_LINEAR : GL_NEAREST )); + if( hasMipMap ) + OGL_CALL(glTexParameteri( target, GL_TEXTURE_MIN_FILTER, kMinFilterGL[filter] )); + else + OGL_CALL(glTexParameteri (target, GL_TEXTURE_MIN_FILTER, filter != kTexFilterNearest ? GL_LINEAR : GL_NEAREST)); +} + + + + +// Dark corner of OpenGL: +// (this is at least on OS X 10.4.9, MacBook Pro) +// Before switching to new context, unbind any textures/shaders/whatever in the previous one! +// +// Otherwise is some _rare_ cases the textures will leak VRAM. Cases like this: +// 1) create a depth render texture (this creates actual GL texture; as copy is required) +// 2) create another render texture, render into it using the depth texture +// 3) release both depth RT and this other RT +// 4) the memory used by GL texture from step 1 is leaked! +// +// It seems like OS X is refcounting resources between contexts, yet when +// a context is destroyed the refcounts are not released. Or something like that. +// +// The texture leak also happens if shader programs are not unbound (hard to correlate why, but...)! +void GFX_GL_IMPL::UnbindObjects() +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + + // unbind textures + int texUnits = gGraphicsCaps.maxTexUnits; + for( int i = 0; i < texUnits; ++i ) + ClearTextureUnitGL (GetGLDeviceState(device), i); + // unbind shaders + ShaderLab::SubProgram* programs[kShaderTypeCount] = {0}; + GraphicsHelper::SetShaders (*this, programs, NULL); + // unbind VBOs + UnbindVertexBuffersGL(); +} + + + +unsigned int GetGLShaderImplTarget( ShaderImplType implType ) +{ + switch( implType ) + { + case kShaderImplVertex: return GL_VERTEX_PROGRAM_ARB; + case kShaderImplFragment: return GL_FRAGMENT_PROGRAM_ARB; + } + DebugAssertIf( true ); + return 0; +} + +void InvalidateActiveShaderStateGL( ShaderType type ) +{ + GfxDevice& device = GetRealGfxDevice(); + AssertIf( device.GetRenderer() != kGfxRendererOpenGL ); + GFX_GL_IMPL& deviceGL = static_cast<GFX_GL_IMPL&>( device ); + + DeviceStateGL& state = GetGLDeviceState(deviceGL); + state.activeGpuProgram[type] = NULL; + state.activeGpuProgramParams[type] = NULL; + state.shaderEnabledImpl[type] = kShaderImplUndefined; + state.shaderEnabledID[type] = -1; +} + + +static void InternalSetShader( DeviceStateGL& state, GfxDeviceStats& stats, FogMode fog, ShaderType type, GpuProgram* program, const GpuProgramParameters* params ) +{ + if( program ) + { + GpuProgramGL& shaderGL = static_cast<GpuProgramGL&>(*program); + ShaderImplType implType = shaderGL.GetImplType(); + GLShaderID id = 0; + if (implType == kShaderImplBoth) { + id = static_cast<GlslGpuProgram&>(shaderGL).GetGLProgram(fog, const_cast<GpuProgramParameters&>(*params)); + } else { + id = static_cast<ArbGpuProgram&>(shaderGL).GetGLProgram(fog); + } + // set the shader + DebugAssert (id > 0); + + ShaderImplType oldType = state.shaderEnabledImpl[type]; + if( oldType != implType ) + { + // impl type is different, disable old one and enable new one + if( oldType == kShaderImplBoth ) + OGL_CALL(glUseProgramObjectARB( 0 )); + else if( oldType != kShaderImplUndefined ) + OGL_CALL(glDisable( GetGLShaderImplTarget(oldType) )); + else { + // we don't know which one is currently enabled, so disable everything we have! + if (type == kShaderVertex) + OGL_CALL(glDisable(GL_VERTEX_PROGRAM_ARB)); + if (type == kShaderFragment) + OGL_CALL(glDisable(GL_FRAGMENT_PROGRAM_ARB)); + } + + if( implType == kShaderImplBoth ) + { + Assert (type == kShaderVertex); + OGL_CALL(glUseProgramObjectARB( id )); + } + else + { + GLenum gltarget = GetGLShaderImplTarget( implType ); + OGL_CALL(glEnable( gltarget )); + OGL_CALL(glBindProgramARB( gltarget, id )); + } + + state.shaderEnabledImpl[type] = implType; + state.shaderEnabledID[type] = id; + } + else + { + // impl type is the same, just use new shader (if different) + + if( state.shaderEnabledID[type] != id ) + { + if( implType == kShaderImplBoth ) + { + OGL_CALL(glUseProgramObjectARB( id )); + } + else + { + OGL_CALL(glBindProgramARB( GetGLShaderImplTarget(implType), id )); + } + state.shaderEnabledID[type] = id; + } + } + } + else + { + // clear the shader + if( state.shaderEnabledID[type] == 0 ) + { + // shader disabled, do nothing + DebugAssertIf( state.shaderEnabledImpl[type] != kShaderImplUndefined ); + } + else if( state.shaderEnabledID[type] == -1 ) + { + // shader state unknown, disable everything + DebugAssertIf( state.shaderEnabledImpl[type] != kShaderImplUndefined ); + if( gGraphicsCaps.gl.hasGLSL ) + OGL_CALL(glUseProgramObjectARB( 0 )); + if( type == kShaderVertex ) + { + OGL_CALL(glDisable( GL_VERTEX_PROGRAM_ARB )); + } + else if( type == kShaderFragment ) + { + OGL_CALL(glDisable( GL_FRAGMENT_PROGRAM_ARB )); + } + else + { + AssertIf( true ); + } + state.shaderEnabledID[type] = 0; + } + else + { + // some shader enabled, disable just that one + ShaderImplType oldType = state.shaderEnabledImpl[type]; + DebugAssertIf( oldType == kShaderImplUndefined ); + if( oldType == kShaderImplBoth ) + { + OGL_CALL(glUseProgramObjectARB( 0 )); + } + else + OGL_CALL(glDisable( GetGLShaderImplTarget(oldType) )); + state.shaderEnabledImpl[type] = kShaderImplUndefined; + state.shaderEnabledID[type] = 0; + } + } + + // Note: set activeGpuProgram after doing everything above. Above code might be + // creating shader combinations for Fog on demand, which can reset activeGpuProgram to NULL. + state.activeGpuProgram[type] = program; + state.activeGpuProgramParams[type] = params; +} + +void GFX_GL_IMPL::SetShadersThreadable(GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]) +{ + GpuProgram* vertexProgram = programs[kShaderVertex]; + GpuProgram* fragmentProgram = programs[kShaderFragment]; + + GFX_LOG(("%d, %d", + (vertexProgram? vertexProgram->GetImplType() : kShaderImplUndefined), + (fragmentProgram? fragmentProgram->GetImplType() : kShaderImplUndefined))); + + // GLSL is only supported like this: + // vertex shader actually is both vertex & fragment linked program + // fragment shader is unused + + FogMode fogMode = m_FogParams.mode; + if (vertexProgram && vertexProgram->GetImplType() == kShaderImplBoth) + { + Assert (fragmentProgram == 0 || fragmentProgram->GetImplType() == kShaderImplBoth); + + InternalSetShader( STATE, m_Stats, m_FogParams.mode, kShaderVertex, vertexProgram, params[kShaderVertex] ); + } + else + { + Assert ((fragmentProgram ? fragmentProgram->GetImplType() != kShaderImplBoth : true)); + + InternalSetShader( STATE, m_Stats, fogMode, kShaderVertex, vertexProgram, params[kShaderVertex] ); + InternalSetShader( STATE, m_Stats, fogMode, kShaderFragment, fragmentProgram, params[kShaderFragment] ); + } + + for (int pt = 0; pt < kShaderTypeCount; ++pt) + { + if (programs[pt]) + { + programs[pt]->ApplyGpuProgram (*params[pt], paramsBuffer[pt]); + m_BuiltinParamIndices[pt] = ¶ms[pt]->GetBuiltinParams(); + } + else + { + m_BuiltinParamIndices[pt] = &m_NullParamIndices; + } + } +} + + +void GFX_GL_IMPL::CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ) +{ + GpuProgramGL& shaderGL = static_cast<GpuProgramGL&>(program->GetGpuProgram()); + ShaderImplType implType = shaderGL.GetImplType(); + if (implType == kShaderImplBoth) { + static_cast<GlslGpuProgram&>(shaderGL).GetGLProgram(fogMode, program->GetParams(fogMode)); + } else { + static_cast<ArbGpuProgram&>(shaderGL).GetGLProgram(fogMode); + } +} + +bool GFX_GL_IMPL::IsShaderActive( ShaderType type ) const +{ + return STATE.shaderEnabledImpl[type] != kShaderImplUndefined; +} + +void GFX_GL_IMPL::DestroySubProgram( ShaderLab::SubProgram* subprogram ) +{ + GpuProgram& program = subprogram->GetGpuProgram(); + GpuProgramGL& shaderGL = static_cast<GpuProgramGL&>(program); + ShaderType lastType = kShaderFragment; + if (shaderGL.GetImplType() == kShaderImplBoth) + lastType = kShaderVertex; + + for (int i = 0; i < kFogModeCount; ++i) + { + GLShaderID id = shaderGL.GetGLProgramIfCreated(FogMode(i)); + for (int j = kShaderVertex; j <= lastType; ++j) + { + if (id && STATE.shaderEnabledID[j] == id) + { + STATE.activeGpuProgram[j] = NULL; + STATE.activeGpuProgramParams[j] = NULL; + STATE.shaderEnabledID[j] = -1; + STATE.shaderEnabledImpl[j] = kShaderImplUndefined; + } + } + } + delete subprogram; +} + +void GFX_GL_IMPL::DisableLights( int startLight ) +{ + GFX_LOG(("%d", startLight)); + + DebugAssertIf( startLight < 0 || startLight > kMaxSupportedVertexLights ); + const Vector4f black(0.0F, 0.0F, 0.0F, 0.0F); + + const int maxLights = gGraphicsCaps.maxLights; + for (int i = startLight; i < maxLights; ++i) + { + if( STATE.vertexLights[i].enabled != 0 ) + { + OGL_CALL(glLightfv (GL_LIGHT0 + i, GL_DIFFUSE, black.GetPtr())); + OGL_CALL(glDisable( GL_LIGHT0 + i )); + + STATE.vertexLights[i].enabled = 0; + } + } + + for (int i = startLight; i < gGraphicsCaps.maxLights; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + i), black); + } +} + +void GFX_GL_IMPL::SetLight( int light, const GfxVertexLight& data) +{ + GFX_LOG(("%d, [{%f, %f, %f, %f}, {%f, %f, %f, %f}, {%f, %f, %f, %f}, %f, %f, %f, %d]", + light, + data.position.x, data.position.y, data.position.z, data.position.w, + data.spotDirection.x, data.spotDirection.y, data.spotDirection.z, data.spotDirection.w, + data.color.x, data.color.y, data.color.z, data.color.w, + data.range, data.quadAtten, data.spotAngle, data.type)); + + DebugAssert(light >= 0 && light < kMaxSupportedVertexLights); + + VertexLightStateGL& state = STATE.vertexLights[light]; + + if (state.enabled != 1) + { + OGL_CALL(glEnable( GL_LIGHT0 + light )); + state.enabled = 1; + } + + float dir[4]; + + // position + if( data.position.w == 0.0f ) + { + // negate directional light for OpenGL + dir[0] = -data.position.x; + dir[1] = -data.position.y; + dir[2] = -data.position.z; + dir[3] = 0.0f; + OGL_CALL(glLightfv( GL_LIGHT0 + light, GL_POSITION, dir )); + } + else + { + OGL_CALL(glLightfv( GL_LIGHT0 + light, GL_POSITION, data.position.GetPtr() )); + } + + // spot direction + if( data.spotAngle != -1.0f ) + OGL_CALL(glLightfv( GL_LIGHT0 + light, GL_SPOT_DIRECTION, data.spotDirection.GetPtr() )); + + // colors + OGL_CALL(glLightfv( GL_LIGHT0 + light, GL_DIFFUSE, data.color.GetPtr() )); + OGL_CALL(glLightfv( GL_LIGHT0 + light, GL_SPECULAR, data.color.GetPtr() )); + static float zeroColor[4] = { 0, 0, 0, 0 }; + OGL_CALL(glLightfv( GL_LIGHT0 + light, GL_AMBIENT, zeroColor )); + + // attenuation + if( state.attenQuad != data.quadAtten ) { + OGL_CALL(glLightf( GL_LIGHT0 + light, GL_CONSTANT_ATTENUATION, 1.0f )); + OGL_CALL(glLightf( GL_LIGHT0 + light, GL_QUADRATIC_ATTENUATION, data.quadAtten )); + state.attenQuad = data.quadAtten; + } + + // angles + if( state.spotAngle != data.spotAngle ) + { + if( data.spotAngle == -1.0f ) + { + // non-spot light + OGL_CALL(glLightf( GL_LIGHT0 + light, GL_SPOT_CUTOFF, 180.0f )); + } + else + { + // spot light + OGL_CALL(glLightf( GL_LIGHT0 + light, GL_SPOT_CUTOFF, data.spotAngle * 0.5f )); + OGL_CALL(glLightf( GL_LIGHT0 + light, GL_SPOT_EXPONENT, 18.0f - data.spotAngle * 0.1f )); + } + state.spotAngle = data.spotAngle; + } + + SetupVertexLightParams (light, data); +} + + +void GFX_GL_IMPL::SetAmbient( const float ambient[4] ) +{ + GFX_LOG(("{%f, %f, %f, %f}", ambient[0], ambient[1], ambient[2], ambient[3])); + if( STATE.ambient != ambient ) + { + OGL_CALL(glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient )); + STATE.ambient.Set( ambient ); + } +} + +void GFX_GL_IMPL::EnableFog (const GfxFogParams& fog) +{ + GFX_LOG(("%d, %f, %f, %f, {%f, %f, %f, %f}", fog.mode, fog.start, fog.end, fog.density, fog.color.x, fog.color.y, fog.color.z, fog.color.w)); + + DebugAssertIf( fog.mode <= kFogDisabled ); + if( m_FogParams.mode != fog.mode ) + { + OGL_CALL(glFogi( GL_FOG_MODE, kFogModeGL[fog.mode] )); + OGL_CALL(glEnable( GL_FOG )); + m_FogParams.mode = fog.mode; + } + if( m_FogParams.start != fog.start ) + { + OGL_CALL(glFogf( GL_FOG_START, fog.start )); + m_FogParams.start = fog.start; + } + if( m_FogParams.end != fog.end ) + { + OGL_CALL(glFogf( GL_FOG_END, fog.end )); + m_FogParams.end = fog.end; + } + if( m_FogParams.density != fog.density ) + { + OGL_CALL(glFogf( GL_FOG_DENSITY, fog.density )); + m_FogParams.density = fog.density; + } + if( m_FogParams.color != fog.color ) + { + OGL_CALL(glFogfv( GL_FOG_COLOR, fog.color.GetPtr() )); + m_FogParams.color = fog.color; + } +} + +void GFX_GL_IMPL::DisableFog() +{ + GFX_LOG(("")); + + if( m_FogParams.mode != kFogDisabled ) + { + OGL_CALL(glFogf( GL_FOG_DENSITY, 0.0f )); + OGL_CALL(glDisable( GL_FOG )); + + m_FogParams.mode = kFogDisabled; + m_FogParams.density = 0.0f; + } +} + + +VBO* GFX_GL_IMPL::CreateVBO() +{ + VBO* vbo = new ARBVBO(); + OnCreateVBO(vbo); + return vbo; +} + +void GFX_GL_IMPL::DeleteVBO( VBO* vbo ) +{ + OnDeleteVBO(vbo); + delete vbo; +} + +DynamicVBO& GFX_GL_IMPL::GetDynamicVBO() +{ + if( STATE.m_DynamicVBO == NULL ) + { + // DynamicARBVBO is slower! Just don't use it for now. + // STATE.m_DynamicVBO = new DynamicARBVBO( 1024 * 1024 ); // initial size: 1MiB VB + STATE.m_DynamicVBO = new DynamicNullVBO(); + } + return *STATE.m_DynamicVBO; +} + + + +// ---------- render textures + + +// defined in RenderTextureGL +RenderSurfaceHandle CreateRenderColorSurfaceGL (TextureID textureID, int width, int height, int samples, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, GLuint globalSharedFBO); +RenderSurfaceHandle CreateRenderDepthSurfaceGL (TextureID textureID, int width, int height, int samples, UInt32 createFlags, DepthBufferFormat depthFormat, GLuint globalSharedFBO); +void DestroyRenderSurfaceGL (RenderSurfaceHandle& rsHandle); +bool SetRenderTargetGL (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, GLuint globalSharedFBO); +RenderSurfaceHandle GetActiveRenderColorSurfaceGL(int index); +RenderSurfaceHandle GetActiveRenderDepthSurfaceGL(); +void ResolveDepthIntoTextureGL (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle, GLuint globalSharedFBO, GLuint helperFBO); +void GrabIntoRenderTextureGL (RenderSurfaceHandle rs, int x, int y, int width, int height, GLuint globalSharedFBO); + + +static GLuint GetFBO (GLuint* fbo) +{ + if (!(*fbo) && gGraphicsCaps.hasRenderToTexture) + { + glGenFramebuffersEXT (1, fbo); + } + return *fbo; +} + +static GLuint GetSharedFBO (DeviceStateGL& state) +{ + return GetFBO (&state.m_SharedFBO); +} + +static GLuint GetHelperFBO (DeviceStateGL& state) +{ + return GetFBO (&state.m_HelperFBO); +} + +RenderSurfaceHandle GFX_GL_IMPL::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) +{ + GFX_LOG(("%d, %d, %d, %d, %d", textureID.m_ID, width, height, createFlags, format)); + GLuint fbo = GetSharedFBO(STATE); + RenderSurfaceHandle rs = CreateRenderColorSurfaceGL (textureID, width, height, samples, dim, createFlags, format, fbo); + #if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); + #endif + return rs; +} +RenderSurfaceHandle GFX_GL_IMPL::CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) +{ + GFX_LOG(("%d, %d, %d, %d", textureID.m_ID, width, height, depthFormat)); + GLuint fbo = GetSharedFBO(STATE); + RenderSurfaceHandle rs = CreateRenderDepthSurfaceGL (textureID, width, height, samples, createFlags, depthFormat, fbo); + #if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); + #endif + return rs; +} +void GFX_GL_IMPL::DestroyRenderSurface (RenderSurfaceHandle& rs) +{ + GFX_LOG(("")); + + // Early out if render surface is not created (don't do flush in that case) + if( !rs.IsValid() ) + return; + + DestroyRenderSurfaceGL (rs); + + #if UNITY_WIN + // Invalidating state causes problems with Windows OpenGL editor (case 490767). + int flags = kGLContextSkipInvalidateState; + #else + // Not invalidating state makes the cached state not match the actual state on OS X (case 494066). + int flags = 0; + #endif + + GraphicsContextHandle ctx = GetMainGraphicsContext(); + if( ctx.IsValid() ) + ActivateGraphicsContext (ctx, false, flags); + + #if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); + #endif +} +void GFX_GL_IMPL::SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face) +{ + GFX_LOG(("%d", face)); + #if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); + #endif + SetRenderTargetGL (count, colorHandles, depthHandle, mipLevel, face, GetSharedFBO(STATE)); + // changing render target might mean different color clear flags; so reset current state + STATE.m_CurrBlendState = NULL; + #if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); + #endif +} +void GFX_GL_IMPL::ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle) +{ + GFX_LOG(("")); + ::ResolveDepthIntoTextureGL (colorHandle, depthHandle, GetSharedFBO(STATE), GetHelperFBO(STATE)); +} +void GFX_GL_IMPL::ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) +{ + void ResolveColorSurfaceGL (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle, GLuint globalSharedFBO, GLuint helperFBO); + + ResolveColorSurfaceGL (srcHandle, dstHandle, GetSharedFBO(STATE), GetHelperFBO(STATE)); +} +RenderSurfaceHandle GFX_GL_IMPL::GetActiveRenderColorSurface(int index) +{ + return GetActiveRenderColorSurfaceGL(index); +} +RenderSurfaceHandle GFX_GL_IMPL::GetActiveRenderDepthSurface() +{ + return GetActiveRenderDepthSurfaceGL(); +} +void GFX_GL_IMPL::SetSurfaceFlags (RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags) +{ +} + +// ---------- uploading textures + +void GFX_GL_IMPL::UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + GFX_LOG(("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d", texture.m_ID, dimension, width, height, format, mipCount, uploadFlags, skipMipLevels, usageMode, colorSpace)); + ::UploadTexture2DGL( texture, dimension, srcData, width, height, format, mipCount, uploadFlags, skipMipLevels, usageMode, colorSpace ); +} + +void GFX_GL_IMPL::UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + GFX_LOG(("%d, %d, %d, %d, %d, %d, %d, %d", texture.m_ID, mipLevel, x, y, width, height, format, colorSpace)); + ::UploadTextureSubData2DGL( texture, srcData, mipLevel, x, y, width, height, format, colorSpace ); +} + +void GFX_GL_IMPL::UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + GFX_LOG(("%d, %d, %d, %d, %d, %d, %d", texture.m_ID, faceDataSize, size, format, mipCount, uploadFlags, colorSpace)); + ::UploadTextureCubeGL( texture, srcData, faceDataSize, size, format, mipCount, uploadFlags, colorSpace ); +} + +void GFX_GL_IMPL::UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + GFX_LOG(("%d, %d, %d, %d, %d, %d, %d", texture.m_ID, width, height, depth, format, mipCount, uploadFlags )); + ::UploadTexture3DGL( texture, srcData, width, height, depth, format, mipCount, uploadFlags ); +} + +void GFX_GL_IMPL::DeleteTexture( TextureID texture ) +{ + GFX_LOG(("%d", texture.m_ID)); + GLuint texname = (GLuint)TextureIdMap::QueryNativeTexture(texture); + if(texname == 0) + return; + + REGISTER_EXTERNAL_GFX_DEALLOCATION(texture.m_ID); + glDeleteTextures( 1, &texname ); + + // invalidate texture unit states that used this texture + for( int i = 0; i < kMaxSupportedTextureUnits; ++i ) + { + TextureUnitStateGL& currTex = STATE.textures[i]; + if( currTex.texID == texname ) + currTex.Invalidate(); + } + + TextureIdMap::RemoveTexture(texture); +} + + +// ---------- context + +GfxDevice::PresentMode GFX_GL_IMPL::GetPresentMode() +{ + return kPresentBeforeUpdate; +} +void GFX_GL_IMPL::BeginFrame() +{ + GFX_LOG(("")); + m_InsideFrame = true; +} +void GFX_GL_IMPL::EndFrame() +{ + GFX_LOG(("")); + m_InsideFrame = false; +} +bool GFX_GL_IMPL::IsValidState() +{ + #if UNITY_LINUX + // The Linux webplayer sometimes appears to lose sync with the GL cache. + // This is a quick, best-guess test for that which allows us to recover gracefully. + float temp; + glGetFloatv (GL_FRONT_FACE, &temp); + return CompareApproximately(temp,(STATE.appBackfaceMode != STATE.userBackfaceMode)?GL_CCW:GL_CW,0.0001f); + #endif + return true; +} + +void GFX_GL_IMPL::PresentFrame() +{ + GFX_LOG(("")); + PresentContextGL( GetMainGraphicsContext() ); + #if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); + #endif +} + +void GFX_GL_IMPL::FinishRendering() +{ + GFX_LOG(("")); + OGL_CALL(glFinish()); +} + + +// ---------- immediate mode rendering + +template <class T> +void WriteToArray(const T& data, dynamic_array<UInt8>& dest) +{ + int offset = dest.size(); + dest.resize_uninitialized(offset + sizeof(T), true); + *reinterpret_cast<T*>(&dest[offset]) = data; +} + + +void GFX_GL_IMPL::ImmediateVertex( float x, float y, float z ) +{ + GFX_LOG(("%f, %f, %f", x, y ,z)); + WriteToArray(UInt32(kImmediateVertex), STATE.m_ImmediateVertices); + WriteToArray(Vector3f(x, y, z), STATE.m_ImmediateVertices); +} + +void GFX_GL_IMPL::ImmediateNormal( float x, float y, float z ) +{ + GFX_LOG(("%f, %f, %f", x, y ,z)); + WriteToArray(UInt32(kImmediateNormal), STATE.m_ImmediateVertices); + WriteToArray(Vector3f(x, y, z), STATE.m_ImmediateVertices); +} + +void GFX_GL_IMPL::ImmediateColor( float r, float g, float b, float a ) +{ + GFX_LOG(("%f, %f, %f, %f", r, g, b, a)); + WriteToArray(UInt32(kImmediateColor), STATE.m_ImmediateVertices); + WriteToArray(ColorRGBAf(r, g, b, a), STATE.m_ImmediateVertices); +} + +void GFX_GL_IMPL::ImmediateTexCoordAll( float x, float y, float z ) +{ + GFX_LOG(("%f, %f, %f", x, y ,z)); + WriteToArray(UInt32(kImmediateTexCoordAll), STATE.m_ImmediateVertices); + WriteToArray(Vector3f(x, y, z), STATE.m_ImmediateVertices); +} + +void GFX_GL_IMPL::ImmediateTexCoord( int unit, float x, float y, float z ) +{ + GFX_LOG(("%d, %f, %f, %f", unit, x, y ,z)); + WriteToArray(UInt32(kImmediateTexCoord), STATE.m_ImmediateVertices); + WriteToArray(UInt32(unit), STATE.m_ImmediateVertices); + WriteToArray(Vector3f(x, y, z), STATE.m_ImmediateVertices); +} + +void GFX_GL_IMPL::ImmediateBegin( GfxPrimitiveType type ) +{ + GFX_LOG(("%d", type)); + STATE.m_ImmediateMode = type; + STATE.m_ImmediateVertices.clear(); +} + +void GFX_GL_IMPL::ImmediateEnd() +{ + GFX_LOG(("")); + + int size = STATE.m_ImmediateVertices.size(); + if (size == 0) + return; + + // when beginning immediate mode, turn off any vertex array components that might be + // activated + UnbindVertexBuffersGL(); + ClearActiveChannelsGL(); + ActivateChannelsGL(); + BeforeDrawCall( true ); + glBegin (kTopologyGL[STATE.m_ImmediateMode]); + + const UInt8* src = STATE.m_ImmediateVertices.data(); + const UInt8* end = src + size; + int vertexCount = 0; + while (src < end) + { + UInt32 type = *reinterpret_cast<const UInt32*>(src); + src += sizeof(UInt32); + switch (type) + { + case kImmediateVertex: + { + const Vector3f& v = *reinterpret_cast<const Vector3f*>(src); + src += sizeof(Vector3f); + glVertex3f( v.x, v.y, v.z ); + ++vertexCount; + break; + } + case kImmediateNormal: + { + const Vector3f& v = *reinterpret_cast<const Vector3f*>(src); + src += sizeof(Vector3f); + glNormal3f( v.x, v.y, v.z ); + break; + } + case kImmediateColor: + { + const ColorRGBAf& col = *reinterpret_cast<const ColorRGBAf*>(src); + src += sizeof(ColorRGBAf); + glColor4f( col.r, col.g, col.b, col.a ); + break; + } + case kImmediateTexCoordAll: + { + const Vector3f& v = *reinterpret_cast<const Vector3f*>(src); + src += sizeof(Vector3f); + for( int i = gGraphicsCaps.maxTexCoords; i--; ) + { + if( STATE.textures[i].texGen <= kTexGenDisabled ) + glMultiTexCoord3fARB( GL_TEXTURE0_ARB + i, v.x, v.y, v.z ); + } + break; + } + case kImmediateTexCoord: + { + UInt32 unit = *reinterpret_cast<const UInt32*>(src); + src += sizeof(UInt32); + const Vector3f& v = *reinterpret_cast<const Vector3f*>(src); + src += sizeof(Vector3f); + glMultiTexCoord3fARB( GL_TEXTURE0_ARB + unit, v.x, v.y, v.z ); + break; + } + default: + ErrorString("Unknown immediate type!"); + break; + } + } + + glEnd(); + // NOTE: all immediate mode calls CAN'T call glGetError - this will result in an error! + // So all of Immediate* calls do not use OGL_CALL macro; instead we're just checking + // for errors after glEnd. + GLAssert(); + + STATE.m_ImmediateVertices.clear(); + + // stats + switch( STATE.m_ImmediateMode ) { + case kPrimitiveTriangles: + m_Stats.AddDrawCall( vertexCount / 3, vertexCount ); + break; + case kPrimitiveTriangleStripDeprecated: + m_Stats.AddDrawCall( vertexCount - 2, vertexCount ); + break; + case kPrimitiveQuads: + m_Stats.AddDrawCall( vertexCount / 4 * 2, vertexCount ); + break; + case kPrimitiveLines: + m_Stats.AddDrawCall( vertexCount / 2, vertexCount ); + break; + } +} + +extern GLint gDefaultFBOGL; + + +void GLReadPixelsWrapper (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) +{ + // When running in Safari 64-bit, we cannot just perform a normal glReadPixels. + // This is because we are rendering into an FBO which is allocated by the Safari process. + // Apparently there are some memory access restrictions, I have not been able to read from that fbo. + // Also, reading from FBOs with FSAA is not possible. + // We work around this by allocating an FBO of our own, blitting into that, and reading from there. + + GLuint fbo; + GLuint fboTexture; + GLint oldTexture; + bool useWorkaround = (gDefaultFBOGL != 0); + + if (useWorkaround) + { + GLint curFBO; + glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &curFBO); + if (curFBO != gDefaultFBOGL) + useWorkaround = false; + } + if (useWorkaround) + { + if( !gGraphicsCaps.gl.hasFrameBufferBlit ) + { + ErrorString ("Cannot read from image without framebuffer blit extension!"); + return; + } + + glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTexture); + + // Create FBO + glGenTextures(1, &fboTexture); + glBindTexture(GL_TEXTURE_2D, fboTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glGenFramebuffersEXT(1, &fbo); + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo ); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fboTexture, 0); + GLAssert(); + + // Blit into it + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, gDefaultFBOGL); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo); + glBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + GLAssert(); + } + + glReadPixels( x, y, width, height, format, type, pixels ); + + if (useWorkaround) + { + // Restore old state + glBindTexture(GL_TEXTURE_2D, oldTexture); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, gDefaultFBOGL); + + // Destroy FBO + glDeleteFramebuffersEXT( 1, &fbo ); + glDeleteTextures(1, &fboTexture); + GLAssert(); + } +} + +bool GFX_GL_IMPL::CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ) +{ + GFX_LOG(("%d, %d, %d, %d", left, bottom, width, height)); + GLReadPixelsWrapper ( left, bottom, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba32 ); + return true; +} + +bool GFX_GL_IMPL::ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) +{ + GFX_LOG(("%d, %d, %d, %d, %d, %d", left, bottom, width, height, destX, destY)); + return ReadbackTextureGL( image, left, bottom, width, height, destX, destY ); +} + +void GFX_GL_IMPL::GrabIntoRenderTexture (RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ) +{ + GFX_LOG(("%d, %d, %d, %d", x, y, width, height)); + ::GrabIntoRenderTextureGL (rs, x, y, width, height, GetHelperFBO (STATE)); +} + +RenderTextureFormat GFX_GL_IMPL::GetDefaultRTFormat() const { return kRTFormatARGB32; } +RenderTextureFormat GFX_GL_IMPL::GetDefaultHDRRTFormat() const { return kRTFormatARGBHalf; } + +void* GFX_GL_IMPL::GetNativeTexturePointer(TextureID id) +{ + return (void*)TextureIdMap::QueryNativeTexture(id); +} + + +void GFX_GL_IMPL::SetActiveContext (void* ctx) +{ + GraphicsContextGL* glctx = reinterpret_cast<GraphicsContextGL*> (ctx); + ActivateGraphicsContextGL (*glctx, kGLContextSkipInvalidateState | kGLContextSkipUnbindObjects | kGLContextSkipFlush); +} + + +#if ENABLE_PROFILER + +GfxTimerQuery* GFX_GL_IMPL::CreateTimerQuery() +{ + TimerQueryGL* query = new TimerQueryGL; + return query; +} + +void GFX_GL_IMPL::DeleteTimerQuery(GfxTimerQuery* query) +{ + delete query; +} + +void GFX_GL_IMPL::BeginTimerQueries() +{ + if( !gGraphicsCaps.hasTimerQuery ) + return; + + g_TimerQueriesGL.BeginTimerQueries(); +} + +void GFX_GL_IMPL::EndTimerQueries() +{ + if (!gGraphicsCaps.hasTimerQuery ) + return; + + g_TimerQueriesGL.EndTimerQueries(); +} + +bool GFX_GL_IMPL::TimerQueriesIsActive() +{ + if (!gGraphicsCaps.hasTimerQuery ) + return false; + + return g_TimerQueriesGL.IsActive(); +} + +#endif // ENABLE_PROFILER + +// -------- editor-only functions + +#if UNITY_EDITOR + +void GFX_GL_IMPL::SetAntiAliasFlag( bool aa ) +{ + if( aa ) + { + OGL_CALL(glHint (GL_LINE_SMOOTH_HINT, GL_NICEST)); + OGL_CALL(glEnable (GL_LINE_SMOOTH)); + } + else + { + OGL_CALL(glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST)); + OGL_CALL(glDisable (GL_LINE_SMOOTH)); + } +} + + +void GFX_GL_IMPL::DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ) +{ + if( vertexCount == 0 ) + return; + + AssertIf( !data || vertexCount < 0 || vertexChannels == 0 ); + + UnbindVertexBuffersGL(); + ClearActiveChannelsGL(); + int offset = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) + { + if( !( vertexChannels & (1<<i) ) ) + continue; + VertexComponent destComponent = kSuitableVertexComponentForChannel[i]; + SetChannelDataGL( (ShaderChannel)i, destComponent, (const UInt8*)data + offset, stride ); + offset += VBO::GetDefaultChannelByteSize(i); + } + ActivateChannelsGL(); + BeforeDrawCall(false); + + OGL_CALL(glDrawArrays(kTopologyGL[type], 0, vertexCount)); + + // stats + switch (type) { + case kPrimitiveTriangles: + m_Stats.AddDrawCall( vertexCount / 3, vertexCount ); + break; + case kPrimitiveQuads: + m_Stats.AddDrawCall( vertexCount / 4 * 2, vertexCount ); + break; + case kPrimitiveLines: + m_Stats.AddDrawCall( vertexCount / 2, vertexCount ); + break; + case kPrimitiveLineStrip: + m_Stats.AddDrawCall( vertexCount-1, vertexCount ); + break; + } +} + +int GFX_GL_IMPL::GetCurrentTargetAA() const +{ + int fsaa = 0; + if( gGraphicsCaps.hasMultiSample ) + glGetIntegerv( GL_SAMPLES_ARB, &fsaa ); + return fsaa; +} + +#if UNITY_WIN + GfxDeviceWindow* GFX_GL_IMPL::CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) + { + return new GLWindow(window, width, height, depthFormat, antiAlias); + } +#endif + + +#endif // UNITY_EDITOR + + + +// -------------------------------------------------------------------------- +// -------- verification of state + + + +#if GFX_DEVICE_VERIFY_ENABLE + + +void VerifyGLState(GLenum gl, float val, const char *str); +#define VERIFY(s,t) VerifyGLState (s, t, #s " (" #t ")") +void VerifyGLStateI(GLenum gl, int val, const char *str); +#define VERIFYI(s,t) VerifyGLStateI (s, t, #s " (" #t ")") +void VerifyGLState4(GLenum gl, const float *val, const char *str); +#define VERIFY4(s,t) VerifyGLState4 (s, t, #s " (" #t ")") + +void VerifyEnabled(GLenum gl, bool val, const char *str); +#define VERIFYENAB(s,t) VerifyEnabled ( s, t, #s " (" #t ")") + +void VerifyMaterial (GLenum gl, const float *val, const char *str); +#define VERIFYMAT(s,t) VerifyMaterial ( s, t, #s " (" #t ")") + +void VerifyTexParam (int target, GLenum gl, float val, const char *str); +#define VERIFYTP(s,t) VerifyTexParam (target, s, t, #s " (" #t ")") + +void VerifyTexEnv (GLenum target, GLenum gl, int val, const char *str); +#define VERIFYTE(g,s,t) VerifyTexEnv (g, s, t, #s " (" #t ")") + +void VerifyTexEnv4 (GLenum target, GLenum gl, const float *val, const char *str); +#define VERIFYTE4(g,s,t) VerifyTexEnv4(g, s, t, #s " (" #t ")") + +void VerifyTexGen (GLenum coord, GLenum gl, int val, const char *str); +#define VERIFYTG(c,s,t) VerifyTexGen (c, s, t, #s " (" #t ")") + + +static void VERIFY_PRINT( const char* format, ... ) +{ + va_list va; + va_start (va, format); + ErrorString( VFormat( format, va ) ); + va_end (va); +} + +const float kVerifyDelta = 0.0001f; + +void VerifyGLState(GLenum gl, float val, const char *str) +{ + float temp; + glGetFloatv (gl, &temp); + if( !CompareApproximately(temp,val,kVerifyDelta) ) { + VERIFY_PRINT ("%s differs from cache (%f != %f)\n", str, val, temp); + } +} + +void VerifyGLStateI(GLenum gl, int val, const char *str) +{ + int temp; + glGetIntegerv (gl, &temp); + if (temp != val) { + VERIFY_PRINT ("%s differs from cache (0x%x != 0x%x)\n", str, val, temp); + } +} + +void VerifyGLState4 (GLenum gl, const float *val, const char *str) +{ + GLfloat temp[4]; + glGetFloatv (gl, temp); + if( !CompareApproximately(temp[0],val[0],kVerifyDelta) || + !CompareApproximately(temp[1],val[1],kVerifyDelta) || + !CompareApproximately(temp[2],val[2],kVerifyDelta) || + !CompareApproximately(temp[3],val[3],kVerifyDelta) ) + { + VERIFY_PRINT ("%s differs from cache (%f,%f,%f,%f) != (%f,%f,%f,%f)\n", str, val[0],val[1],val[2],val[3], temp[0],temp[1],temp[2],temp[3]); + } +} + +void VerifyEnabled(GLenum gl, bool val, const char *str) +{ + bool temp = glIsEnabled (gl) ? true : false; + if (temp != val) { + VERIFY_PRINT ("%s differs from cache (%d != %d)\n", str, val, temp); + } +} + +void VerifyMaterial (GLenum gl, const float *val, const char *str) +{ + GLfloat temp[4]; + glGetMaterialfv (GL_FRONT, gl, temp); + if( !CompareApproximately(temp[0],val[0],kVerifyDelta) || + !CompareApproximately(temp[1],val[1],kVerifyDelta) || + !CompareApproximately(temp[2],val[2],kVerifyDelta) || + !CompareApproximately(temp[3],val[3],kVerifyDelta) ) + { + VERIFY_PRINT ("%s differs from cache (%f,%f,%f,%f) != (%f,%f,%f,%f)\n",str, val[0],val[1],val[2],val[3], temp[0],temp[1],temp[2],temp[3]); + } +} + +void VerifyTexParam (int target, GLenum gl, float val, const char *str) +{ + float temp; + glGetTexParameterfv (target, gl, &temp); + if( !CompareApproximately(temp,val,kVerifyDelta) ) { + VERIFY_PRINT ("%s differs from cache (%f != %f)\n", str, val, temp); + } +} + +void VerifyTexEnv (GLenum target, GLenum gl, int val, const char *str) +{ + GLint temp; + glGetTexEnviv (target, gl, &temp); + if (temp != val) { + VERIFY_PRINT ("%s differs from cache (%d != %d)\n", str, (int)val, (int)temp); + } +} + +void VerifyTexEnv4( GLenum target, GLenum gl, const float *val, const char *str ) +{ + GLfloat temp[4]; + glGetTexEnvfv(target, gl, temp); + float val0 = clamp01(val[0]); + float val1 = clamp01(val[1]); + float val2 = clamp01(val[2]); + float val3 = clamp01(val[3]); + if( !CompareApproximately(temp[0],val0,kVerifyDelta) || + !CompareApproximately(temp[1],val1,kVerifyDelta) || + !CompareApproximately(temp[2],val2,kVerifyDelta) || + !CompareApproximately(temp[3],val3,kVerifyDelta) ) + { + VERIFY_PRINT ("%s differs from cache (%f,%f,%f,%f) != (%f,%f,%f,%f)\n", str, val0,val1,val2,val3, temp[0],temp[1],temp[2],temp[3]); + } +} + + +void VerifyTexGen(GLenum coord, GLenum gl, int val, const char *str) +{ + GLint temp; + glGetTexGeniv (coord, gl, &temp); + if (temp != val) { + VERIFY_PRINT ("TexGen %s differs from cache (%d != %d)\n", str, val, (int)temp); + } +} + + +void GFX_GL_IMPL::VerifyState() +{ + STATE.Verify(); + + if( m_FogParams.mode != kFogUnknown ) + { + VERIFYENAB( GL_FOG, m_FogParams.mode != 0 ); + //VERIFY( GL_FOG_MODE, GetFogMode()[m_FogParams.mode] ); // TBD + if( m_FogParams.mode != kFogDisabled ) + { + VERIFY( GL_FOG_START, m_FogParams.start ); + VERIFY( GL_FOG_END, m_FogParams.end ); + VERIFY( GL_FOG_DENSITY, m_FogParams.density ); + float clampedFogColor[4]; + clampedFogColor[0] = clamp01(m_FogParams.color.x); + clampedFogColor[1] = clamp01(m_FogParams.color.y); + clampedFogColor[2] = clamp01(m_FogParams.color.z); + clampedFogColor[3] = clamp01(m_FogParams.color.w); + + VERIFY4( GL_FOG_COLOR, clampedFogColor ); + } + } +} + + +void DeviceStateGL::Verify() +{ + GLAssert(); + if( depthFunc != kFuncUnknown ) { + VERIFYENAB( GL_DEPTH_TEST, depthFunc != kFuncDisabled ); + if( depthFunc != kFuncDisabled ) { + VERIFY( GL_DEPTH_FUNC, kCmpFuncGL[depthFunc] ); + } + } + if( depthWrite != -1 ) { + GLboolean temp; + glGetBooleanv( GL_DEPTH_WRITEMASK, &temp ); + if( temp != depthWrite ) + printf_console( "DepthWrite mismatch (%d != %d)\n", (int)temp, (int)depthWrite ); + } + if( blending != -1 ) { + VERIFYENAB( GL_BLEND, blending != 0 ); + if( blending ) { + VERIFYI( GL_BLEND_SRC, srcBlend ); + VERIFYI( GL_BLEND_DST, destBlend ); + VERIFYI( GL_BLEND_EQUATION_RGB, blendOp ); + if( gGraphicsCaps.hasSeparateAlphaBlend ) { + VERIFYI( GL_BLEND_SRC_ALPHA, srcBlendAlpha ); + VERIFYI( GL_BLEND_DST_ALPHA, destBlendAlpha ); + VERIFYI( GL_BLEND_EQUATION_ALPHA, blendOpAlpha ); + } + + } + } + + if( alphaFunc != kFuncUnknown ) { + VERIFYENAB( GL_ALPHA_TEST, alphaFunc != kFuncDisabled ); + if( alphaFunc != kFuncDisabled ) { + VERIFY( GL_ALPHA_TEST_FUNC, kCmpFuncGL[alphaFunc] ); + if( alphaValue != -1 ) + VERIFY( GL_ALPHA_TEST_REF, alphaValue ); + } + } + + if( culling != kCullUnknown ) { + VERIFYENAB( GL_CULL_FACE, culling != kCullOff ); + switch (culling) { + case kCullOff: break; + case kCullFront: VERIFY (GL_CULL_FACE_MODE, GL_FRONT); break; + case kCullBack: VERIFY (GL_CULL_FACE_MODE, GL_BACK); break; + default: printf_console( "Invalid face cull mode: %d\n", (int)culling ); break; + } + } + VERIFY( GL_FRONT_FACE, (appBackfaceMode != userBackfaceMode) ? GL_CCW : GL_CW ); + + if( scissor != -1 ) { + VERIFYENAB( GL_SCISSOR_TEST, scissor != 0 ); + } + + if( lighting != -1 ) { + VERIFYENAB( GL_LIGHTING, lighting != 0 ); + if( lighting && colorMaterial == kColorMatDisabled ) { + if( matAmbient.x != -1.0f ) + VERIFYMAT( GL_AMBIENT, matAmbient.GetPtr() ); + if( matDiffuse.x != -1.0f ) + VERIFYMAT( GL_DIFFUSE, matDiffuse.GetPtr() ); + if( matSpecular.x != -1.0f ) + VERIFYMAT( GL_SPECULAR, matSpecular.GetPtr() ); + if( matEmissive.x != -1.0f ) + VERIFYMAT( GL_EMISSION, matEmissive.GetPtr() ); + if( matShininess != -1.0f ) + { + GLfloat temp; + glGetMaterialfv( GL_FRONT, GL_SHININESS, &temp ); + if( !CompareApproximately(temp, matShininess * 128.0f, kVerifyDelta) ) + printf_console( "Shininess mismatch: %f != %f\n", (float)temp, (float)matShininess ); + } + } + } + + // verify bound/enabled programs + for( int type = kShaderVertex; type < kShaderTypeCount; ++type ) + { + ShaderImplType currType = shaderEnabledImpl[type]; + if( currType == kShaderImplBoth ) + { + GLhandleARB gl = glGetHandleARB( GL_PROGRAM_OBJECT_ARB ); + if( gl != shaderEnabledID[type] ) + { + VERIFY_PRINT( "GLSL program differs from cache (%d != %d)\n", gl, shaderEnabledID[type] ); + } + } + else if( currType == kShaderImplUndefined ) + { + AssertIf( shaderEnabledID[type] != -1 && shaderEnabledID[type] != 0 ); + if( shaderEnabledID[type] == 0 ) + { + if( type == kShaderVertex ) + { + VERIFYENAB( GL_VERTEX_PROGRAM_ARB, false ); + } + else + { + VERIFYENAB( GL_FRAGMENT_PROGRAM_ARB, false ); + } + } + } + else + { + GLenum gltarget = GetGLShaderImplTarget( currType ); + VERIFYENAB( gltarget, true ); + int gl; + glGetProgramivARB( gltarget, GL_PROGRAM_BINDING_ARB, &gl ); + if( gl != shaderEnabledID[type] ) + { + VERIFY_PRINT( "Program #%i differs from cache (%d != %d)\n", type, gl, shaderEnabledID[type] ); + } + } + } + + // Verify all texture units + for( int i = 0; i < gGraphicsCaps.maxTexUnits; ++i ) { + textures[i].Verify(i); + } +} + +static const unsigned long kTextureBindingTable[6] = {0, GL_TEXTURE_BINDING_1D, GL_TEXTURE_BINDING_2D, GL_TEXTURE_BINDING_3D, GL_TEXTURE_BINDING_CUBE_MAP_ARB}; + +void TextureUnitStateGL::Verify( int texUnit ) +{ + if( gGraphicsCaps.maxTexUnits <= 1 ) // do not crash on no-multi-texture machines + return; + + if( texDim == kTexDimUnknown ) + return; + + glActiveTextureARB(GL_TEXTURE0_ARB + texUnit); + + VERIFYI(GL_TEXTURE_2D, texDim == kTexDim2D); + VERIFYI(GL_TEXTURE_CUBE_MAP_ARB, texDim == kTexDimCUBE); + if( gGraphicsCaps.has3DTexture ) { + VERIFYI(GL_TEXTURE_3D, texDim == kTexDim3D); + } + + if( color.x != -1 && color.y != -1 && color.z != -1 && color.w != -1 ) + VERIFYTE4( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color.GetPtr() ); + + if( texDim != kTexDimNone && texID != -1 ) + VERIFYI( kTextureBindingTable[texDim], texID ); + + if( texGen != kTexGenUnknown ) + { + switch( texGen ) + { + case kTexGenDisabled: + VERIFYENAB( GL_TEXTURE_GEN_S, false ); + VERIFYENAB( GL_TEXTURE_GEN_T, false ); + VERIFYENAB( GL_TEXTURE_GEN_R, false ); + break; + case kTexGenSphereMap: + VERIFYTG(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + VERIFYTG(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + VERIFYENAB( GL_TEXTURE_GEN_S, true ); + VERIFYENAB( GL_TEXTURE_GEN_T, true ); + VERIFYENAB( GL_TEXTURE_GEN_R, false ); + break; + case kTexGenObject: { + VERIFYTG(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + VERIFYTG(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + VERIFYTG(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + VERIFYENAB( GL_TEXTURE_GEN_S, true ); + VERIFYENAB( GL_TEXTURE_GEN_T, true ); + VERIFYENAB( GL_TEXTURE_GEN_R, true ); + break; + } + case kTexGenEyeLinear: { + VERIFYTG(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + VERIFYTG(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + VERIFYTG(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + VERIFYENAB( GL_TEXTURE_GEN_S, true ); + VERIFYENAB( GL_TEXTURE_GEN_T, true ); + VERIFYENAB( GL_TEXTURE_GEN_R, true ); + break; + } + case kTexGenCubeReflect: + VERIFYTG(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); + VERIFYTG(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); + VERIFYTG(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); + VERIFYENAB( GL_TEXTURE_GEN_S, true ); + VERIFYENAB( GL_TEXTURE_GEN_T, true ); + VERIFYENAB( GL_TEXTURE_GEN_R, true ); + break; + case kTexGenCubeNormal: + VERIFYTG(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); + VERIFYTG(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); + VERIFYTG(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB); + VERIFYENAB( GL_TEXTURE_GEN_S, true ); + VERIFYENAB( GL_TEXTURE_GEN_T, true ); + VERIFYENAB( GL_TEXTURE_GEN_R, true ); + break; + } + } +} + + +#endif // GFX_DEVICE_VERIFY_ENABLE diff --git a/Runtime/GfxDevice/opengl/GfxDeviceGL.h b/Runtime/GfxDevice/opengl/GfxDeviceGL.h new file mode 100644 index 0000000..59831a2 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GfxDeviceGL.h @@ -0,0 +1,191 @@ +#pragma once + +#if GFX_DEVICE_VIRTUAL + +class GFX_GL_IMPL : public GfxThreadableDevice { +public: + GFX_GL_IMPL(); + GFX_API ~GFX_GL_IMPL(); + GFX_API void OnDeviceCreated (bool callingFromRenderThread); + + GFX_API void InvalidateState(); + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState(); + #endif + + GFX_API void Clear (UInt32 clearFlags, const float color[4], float depth, int stencil); + GFX_API void SetUserBackfaceMode( bool enable ); + GFX_API void SetWireframe(bool wire); + GFX_API bool GetWireframe() const; + + GFX_API void SetInvertProjectionMatrix( bool enable ); + GFX_API bool GetInvertProjectionMatrix() const; + #if GFX_USES_VIEWPORT_OFFSET + GFX_API void SetViewportOffset( float x, float y ); + GFX_API void GetViewportOffset( float &x, float &y ) const; + #endif + + GFX_API void SetWorldMatrix( const float matrix[16] ); + GFX_API void SetViewMatrix( const float matrix[16] ); + + GFX_API void SetProjectionMatrix (const Matrix4x4f& matrix); + GFX_API void GetMatrix( float outMatrix[16] ) const; + + GFX_API const float* GetWorldMatrix() const ; + GFX_API const float* GetViewMatrix() const; + GFX_API const float* GetProjectionMatrix() const; + GFX_API const float* GetDeviceProjectionMatrix() const; + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ); + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ); + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ); + GFX_API void SetColor( const float color[4] ); + GFX_API void SetViewport( int x, int y, int width, int height ); + GFX_API void GetViewport( int* values ) const; + + GFX_API void SetScissorRect( int x, int y, int width, int height ); + GFX_API void DisableScissor(); + GFX_API bool IsScissorEnabled() const; + GFX_API void GetScissorRect( int values[4] ) const; + GFX_API void DiscardContents (RenderSurfaceHandle& rs) {} + + GFX_API GPUSkinningInfo *CreateGPUSkinningInfo() { return NULL; } + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info) { AssertBreak(false); } + GFX_API void SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ) { AssertBreak(false); } + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) { AssertBreak(false); } + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) { AssertBreak(false); } + + GFX_API bool IsCombineModeSupported( unsigned int combiner ); + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ); + GFX_API void SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ); + GFX_API void SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ); + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias); + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]); + GFX_API void SetTextureName ( TextureID texture, const char* name ) { } + + GFX_API void SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]); + GFX_API void CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ); + GFX_API bool IsShaderActive( ShaderType type ) const; + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ); + + GFX_API void DisableLights( int startLight ); + GFX_API void SetLight( int light, const GfxVertexLight& data); + GFX_API void SetAmbient( const float ambient[4] ); + + GFX_API void EnableFog (const GfxFogParams& fog); + GFX_API void DisableFog(); + + GFX_API VBO* CreateVBO(); + GFX_API void DeleteVBO( VBO* vbo ); + GFX_API DynamicVBO& GetDynamicVBO(); + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags); + GFX_API RenderSurfaceHandle CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags); + GFX_API void DestroyRenderSurface (RenderSurfaceHandle& rs); + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face = kCubeFaceUnknown); + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle); + GFX_API void ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle); + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface (int index); + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface (); + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags); + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace); + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ); + GFX_API void DeleteTexture( TextureID texture ); + + GFX_API PresentMode GetPresentMode(); + + GFX_API void BeginFrame(); + GFX_API void EndFrame(); + GFX_API void PresentFrame(); + GFX_API bool IsValidState(); + + GFX_API void FinishRendering(); + + // Immediate mode rendering + GFX_API void ImmediateVertex( float x, float y, float z ); + GFX_API void ImmediateNormal( float x, float y, float z ); + GFX_API void ImmediateColor( float r, float g, float b, float a ); + GFX_API void ImmediateTexCoordAll( float x, float y, float z ); + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ); + GFX_API void ImmediateBegin( GfxPrimitiveType type ); + GFX_API void ImmediateEnd(); + + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ); + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); + GFX_API void GrabIntoRenderTexture( RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ); + + GFX_API void BeforeDrawCall( bool immediateMode ); + + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef); + GFX_API void SetRasterState(const DeviceRasterState* state); + GFX_API void SetDepthState(const DeviceDepthState* state); + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef); + GFX_API void SetSRGBWrite (const bool); + GFX_API bool GetSRGBWrite (); + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state); + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state); + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state); + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state); + + GFX_API RenderTextureFormat GetDefaultRTFormat() const; + GFX_API RenderTextureFormat GetDefaultHDRRTFormat() const; + + GFX_API bool IsPositionRequiredForTexGen (int texStageIndex) const { return false; } + GFX_API bool IsNormalRequiredForTexGen (int texStageIndex) const { return false; } + GFX_API bool IsPositionRequiredForTexGen() const { return false; } + GFX_API bool IsNormalRequiredForTexGen() const { return false; } + + GFX_API void SetActiveContext (void* ctx); + GFX_API void UnbindObjects (); + + GFX_API void* GetNativeTexturePointer(TextureID id); + + #if ENABLE_PROFILER + GFX_API GfxTimerQuery* CreateTimerQuery(); + GFX_API void DeleteTimerQuery(GfxTimerQuery* query); + GFX_API void BeginTimerQueries(); + GFX_API void EndTimerQueries(); + GFX_API bool TimerQueriesIsActive(); + #endif + + #if UNITY_EDITOR + GFX_API void SetAntiAliasFlag( bool aa ); + GFX_API void DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ); + GFX_API int GetCurrentTargetAA() const; + + #if UNITY_WIN + GFX_API GfxDeviceWindow* CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + #endif + + #endif + + DeviceStateGL& GetState() { return m_State; } + +private: + DeviceStateGL m_State; +}; + +#define STATE this->m_State +#define GetGLDeviceState(device) device.GetState() + +#else + +struct GfxDeviceImpl { +#if UNITY_WII + DeviceStateWii state; +#else + DeviceStateGL state; +#endif +}; + +#define STATE impl->state +#define GetGLDeviceState(device) device.GetImpl()->state + +#endif diff --git a/Runtime/GfxDevice/opengl/GpuProgramsGL.cpp b/Runtime/GfxDevice/opengl/GpuProgramsGL.cpp new file mode 100644 index 0000000..430f342 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GpuProgramsGL.cpp @@ -0,0 +1,562 @@ +#include "UnityPrefix.h" +#include "GpuProgramsGL.h" +#include "External/shaderlab/Library/ShaderLabErrors.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Math/Vector4.h" +#include "UnityGL.h" +#include "GLAssert.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/program.h" +#include "Runtime/Utilities/GLSLUtilities.h" + + +#define DEBUG_GLSL_BINDINGS 0 + + +unsigned int GetGLShaderImplTarget( ShaderImplType implType ); // GfxDeviceGL.cpp +void InvalidateActiveShaderStateGL( ShaderType type ); // GfxDeviceGL.cpp + +void InvalidateFPParamCacheGL(); + + +// -------------------------------------------------------------------------- +// GLSL + +// AttributeConversionTable +const static int kAttribLookupTableSize = 12; +const static char* s_GLSLAttributes[kAttribLookupTableSize] = { + "gl_Vertex", "gl_Color", "gl_Normal", + "gl__unused__", // unused + "gl_MultiTexCoord0", "gl_MultiTexCoord1", "gl_MultiTexCoord2", "gl_MultiTexCoord3", + "gl_MultiTexCoord4", "gl_MultiTexCoord5", "gl_MultiTexCoord6", "gl_MultiTexCoord7" +}; +const static char* s_UnityAttributes[kAttribLookupTableSize] = { + "Vertex", "Color", "Normal", + "", // unused + "TexCoord", "TexCoord1", "TexCoord2", "TexCoord3", // TODO: all the rest texcoord channels! + "TexCoord4", "TexCoord5", "TexCoord6", "TexCoord7" +}; + +GlslGpuProgram::GlslGpuProgram( const std::string& source, CreateGpuProgramOutput& output ) +{ + m_ImplType = kShaderImplBoth; + output.SetPerFogModeParamsEnabled(true); + m_GpuProgramLevel = kGpuProgramSM2; + for (int i = 0; i < kFogModeCount; ++i) + { + m_GLSLVertexShader[i] = 0; + m_GLSLFragmentShader[i] = 0; + m_FogFailed[i] = false; + } + // Fragment shaders come out as dummy GLSL text. Just ignore them; the real shader was part of + // the vertex shader text anyway. + if (source.empty()) + return; + if (Create (source, output.CreateShaderErrors())) + { + GpuProgramParameters& params = output.CreateParams(); + FillParams (m_Programs[kFogDisabled], params, NULL); + FillChannels (output.CreateChannelAssigns()); +// GpuProgramParameters& params = parent.GetParams (kFogDisabled); +// FillParams (m_Programs[kFogDisabled], params, outNames); +// FillChannels (parent.GetChannels()); + if (params.GetTextureParams().size() > gGraphicsCaps.maxTexImageUnits) + m_NotSupported = true; + } + else + { + m_NotSupported = true; + } +} + +GlslGpuProgram::~GlslGpuProgram () +{ + Assert (m_ImplType == kShaderImplBoth); + + for (int i = 0; i < kFogModeCount; ++i) + { + if (m_GLSLVertexShader[i]) glDeleteObjectARB (m_GLSLVertexShader[i]); + if (m_GLSLFragmentShader[i]) glDeleteObjectARB (m_GLSLFragmentShader[i]); + if (m_Programs[i]) glDeleteObjectARB (m_Programs[i]); + } +} + + + + +static bool ParseGLSLErrors (GLuint handle , GLSLErrorType errorType, ShaderErrors& outErrors) +{ + bool hadErrors = false; + + int status; + char log[4096]; + GLsizei infoLogLength = 0; + switch(errorType) + { + case kErrorCompileVertexShader: + case kErrorCompileFragShader: + glGetObjectParameterivARB(handle, GL_OBJECT_COMPILE_STATUS_ARB, &status); + hadErrors = status == 0; + glGetInfoLogARB(handle, sizeof(log), &infoLogLength, log); + break; + case kErrorLinkProgram: + glGetObjectParameterivARB(handle, GL_OBJECT_LINK_STATUS_ARB, &status); + hadErrors = status == 0; + glGetInfoLogARB(handle, sizeof(log), &infoLogLength, log); + break; + default: + FatalErrorMsg("Unknown error type"); + break; + } + + if(!hadErrors)return false; + + OutputGLSLShaderError(log, errorType, outErrors); + + return hadErrors; +} + + +static void AddSizedVectorParam (GpuProgramParameters& params, ShaderParamType type, int vectorSize, int uniformNumber, int arraySize, const char* name, char* indexName, PropertyNamesSet* outNames) +{ + if (arraySize <= 1) + { + params.AddVectorParam (uniformNumber, type, vectorSize, name, -1, outNames); + } + else + { + for (int j = 0; j < arraySize; ++j) { + if (j < 10) { + indexName[0] = '0' + j; + indexName[1] = 0; + } else { + indexName[0] = '0' + j/10; + indexName[1] = '0' + j%10; + indexName[2] = 0; + } + params.AddVectorParam (uniformNumber+j, type, vectorSize, name, -1, outNames); + } + } +} + +static void AddSizedMatrixParam (GpuProgramParameters& params, int rows, int cols, int uniformNumber, int arraySize, const char* name, char* indexName, PropertyNamesSet* outNames) +{ + if (arraySize <= 1) + { + params.AddMatrixParam (uniformNumber, name, rows, cols, -1, outNames); + } + else + { + for (int j = 0; j < arraySize; ++j) { + if (j < 10) { + indexName[0] = '0' + j; + indexName[1] = 0; + } else { + indexName[0] = '0' + j/10; + indexName[1] = '0' + j%10; + indexName[2] = 0; + } + params.AddMatrixParam (uniformNumber+j, name, rows, cols, -1, outNames); + } + } +} + +static GLShaderID CompileVertexShader (const std::string& source, ShaderErrors& outErrors) +{ + const char* text = source.c_str(); + GLShaderID vertexId = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); + glShaderSourceARB (vertexId, 1, &text, NULL); + glCompileShaderARB (vertexId); + + if (ParseGLSLErrors( vertexId, kErrorCompileVertexShader, outErrors)) + { + glDeleteObjectARB(vertexId); + return 0; + } + + return vertexId; +} + +static GLShaderID CompileFragmentShader (const std::string& source, ShaderErrors& outErrors) +{ + const char* text = source.c_str(); + GLShaderID fragId = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB ); + glShaderSourceARB (fragId, 1, &text, NULL); + glCompileShaderARB (fragId); + + if (ParseGLSLErrors( fragId, kErrorCompileFragShader, outErrors)) + { + glDeleteObjectARB(fragId); + return 0; + } + + return fragId; +} + + + +bool GlslGpuProgram::Create (const std::string &shaderString, ShaderErrors& outErrors) +{ + if( !gGraphicsCaps.gl.hasGLSL ) + return false; + + GLAssert(); // Clear any GL errors + + m_Programs[0] = glCreateProgramObjectARB(); + + m_ImplType = kShaderImplBoth; + m_GpuProgramLevel = kGpuProgramSM2; + + std::string vertexShaderSource; + std::string fragmentShaderSource; + + + vertexShaderSource = "#define VERTEX\n" + shaderString; + fragmentShaderSource = "#define FRAGMENT\n" + shaderString; + + if( (m_GLSLVertexShader[0] = CompileVertexShader(vertexShaderSource, outErrors)) == 0 ) + { + return false; + } + + if( (m_GLSLFragmentShader[0] = CompileFragmentShader(fragmentShaderSource, outErrors)) == 0 ) + { + return false; + } + + glAttachObjectARB(m_Programs[0], m_GLSLVertexShader[0]); + glAttachObjectARB(m_Programs[0], m_GLSLFragmentShader[0]); + glLinkProgramARB(m_Programs[0]); + + if (ParseGLSLErrors (m_Programs[0], kErrorLinkProgram, outErrors)) + { + return false; + } + + m_SourceForFog = shaderString; + + GLAssert(); + return true; +} + + +void GlslGpuProgram::FillChannels (ChannelAssigns& channels) +{ + if (!m_Programs[0]) + return; + + // Figure out the attributes (vertex inputs) + const int kBufSize = 1024; + char name[kBufSize]; + + GLAssert(); + + GLenum type; + int arraySize=0, nameLength=0, activeCount=0; + glGetObjectParameterivARB(m_Programs[0], GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &activeCount); + + for(int i = 0; i < activeCount; i++) + { + glGetActiveAttribARB(m_Programs[0], i, kBufSize, &nameLength, &arraySize, &type, name); + int attribNumber = 0; + std::string stringName( name ); + // Find number for gl_ attribs in conversion table + if (!strncmp (name, "gl_", 3)) { + for(int j = 0; j < kAttribLookupTableSize; j++) + { + if(!strncmp(s_GLSLAttributes[j], stringName.c_str(), strlen(s_GLSLAttributes[j]))) + { + attribNumber = j+1; + stringName = s_UnityAttributes[j]; + break; + } + } + if( attribNumber == 0 ) + ErrorString( "Unrecognized vertex attribute: " + stringName ); // TODO: SL error + } + else + { + // Check in names for non gl_ attribs. if not gl_ name get number: + attribNumber = glGetAttribLocationARB(m_Programs[0], name) + kVertexCompAttrib0; + } + + ShaderChannel shaderChannel = GetShaderChannelFromName(stringName); + if( shaderChannel != kShaderChannelNone ) + { + channels.Bind (shaderChannel, (VertexComponent)attribNumber); + } + } + + GLAssert(); +} + +void GlslGpuProgram::FillParams (GLShaderID programID, GpuProgramParameters& params, PropertyNamesSet* outNames) +{ + if (!programID) + return; + + // Figure out the attributes (vertex inputs) + const int kBufSize = 1024; + char name[kBufSize]; + + GLAssert(); + + GLenum type; + int arraySize=0, nameLength=0, activeCount=0; + + // Figure out the uniforms + glGetObjectParameterivARB (programID, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); + for(int i=0; i < activeCount; i++) + { + glGetActiveUniformARB (programID, i, kBufSize, &nameLength, &arraySize, &type, name); + if (!strncmp (name, "gl_", 3)) + continue; + + if (!strcmp (name, "_unity_FogParams") || !strcmp(name, "_unity_FogColor")) + continue; + + int uniformNumber = glGetUniformLocationARB (programID, name); + char* indexName = name; + + bool isElemZero = false; + bool isArray = IsShaderParameterArray(name, nameLength, arraySize, &isElemZero); + if (isArray) + { + // for array parameters, transform name a bit: Foo[0] becomes Foo0 + if (arraySize >= 100) { + ErrorString( "GLSL: array sizes larger than 99 not supported" ); // TODO: SL error + arraySize = 99; + } + if (isElemZero) + { + indexName = name+nameLength-3; + indexName[0] = '0'; + indexName[1] = 0; + } + else + { + indexName = name+nameLength; + } + } + + if (type == GL_FLOAT) + AddSizedVectorParam (params, kShaderParamFloat, 1, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_FLOAT_VEC2_ARB) + AddSizedVectorParam (params, kShaderParamFloat, 2, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_FLOAT_VEC3_ARB) + AddSizedVectorParam (params, kShaderParamFloat, 3, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_FLOAT_VEC4_ARB) + AddSizedVectorParam (params, kShaderParamFloat, 4, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_INT) + AddSizedVectorParam (params, kShaderParamInt, 1, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_INT_VEC2_ARB) + AddSizedVectorParam (params, kShaderParamInt, 2, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_INT_VEC3_ARB) + AddSizedVectorParam (params, kShaderParamInt, 3, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_INT_VEC4_ARB) + AddSizedVectorParam (params, kShaderParamInt, 4, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_BOOL) + AddSizedVectorParam (params, kShaderParamBool, 1, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_BOOL_VEC2_ARB) + AddSizedVectorParam (params, kShaderParamBool, 2, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_BOOL_VEC3_ARB) + AddSizedVectorParam (params, kShaderParamBool, 3, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_BOOL_VEC4_ARB) + AddSizedVectorParam (params, kShaderParamBool, 4, uniformNumber, arraySize, name, indexName, outNames); + else if (type == GL_FLOAT_MAT4_ARB) + AddSizedMatrixParam (params, 4, 4, uniformNumber, arraySize, name, indexName, outNames); + // For all the textures, we could just statically bind the uniform to the sequential texture index, + // and save all the glUniform1i calls later. However one gfx test on Linux is failing with the change, + // and I can't figure out why. So instead I'll pack the uniform number & the index :( + else if (type == GL_SAMPLER_2D_ARB || type == GL_SAMPLER_2D_RECT_ARB || type == GL_SAMPLER_2D_SHADOW_ARB) + { + const UInt32 texIndex = params.GetTextureParams().size(); + const UInt32 packedIndex = (texIndex << 24) | (uniformNumber & 0xFFFFFF); + params.AddTextureParam (packedIndex, -1, name, kTexDim2D, outNames); + } + else if (type == GL_SAMPLER_CUBE_ARB) + { + const UInt32 texIndex = params.GetTextureParams().size(); + const UInt32 packedIndex = (texIndex << 24) | (uniformNumber & 0xFFFFFF); + params.AddTextureParam (packedIndex, -1, name, kTexDimCUBE, outNames); + } + else if (type == GL_SAMPLER_3D_ARB) + { + const UInt32 texIndex = params.GetTextureParams().size(); + const UInt32 packedIndex = (texIndex << 24) | (uniformNumber & 0xFFFFFF); + params.AddTextureParam (packedIndex, -1, name, kTexDim3D, outNames); + } + else { + AssertString( "Unrecognized GLSL uniform type" ); + } + } + + GLAssert(); +} + + +void GlslGpuProgram::ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) +{ + #if DEBUG_GLSL_BINDINGS + printf_console("GLSL: apply program id=%i\n", m_ShaderID); + #endif + + // Fog parameters if needed + const GfxFogParams& fog = GetRealGfxDevice().GetFogParams(); + if (fog.mode > kFogDisabled && m_Programs[fog.mode]) + { + OGL_CALL(glUniform4fvARB (m_FogColorIndex[fog.mode], 1, fog.color.GetPtr())); + float params[4]; + params[0] = fog.density * 1.2011224087f ; // density / sqrt(ln(2)) + params[1] = fog.density * 1.4426950408f; // density / ln(2) + if (fog.mode == kFogLinear) + { + float diff = fog.end - fog.start; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + params[2] = -invDiff; + params[3] = fog.end * invDiff; + } + else + { + params[2] = 0.0f; + params[3] = 0.0f; + } + OGL_CALL(glUniform4fvARB (m_FogParamsIndex[fog.mode], 1, params)); + } + + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for( GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i ) + { + if(i->m_RowCount == 1 && i->m_ArraySize == 1) + { + // Apply float/vector parameters + const Vector4f& val = *reinterpret_cast<const Vector4f*>(buffer); + if (i->m_Type == kShaderParamFloat) + { + if (i->m_ColCount == 1) + OGL_CALL(glUniform1fvARB (i->m_Index, 1, val.GetPtr())); + else if(i->m_ColCount == 2) + OGL_CALL(glUniform2fvARB (i->m_Index, 1, val.GetPtr())); + else if(i->m_ColCount == 3) + OGL_CALL(glUniform3fvARB (i->m_Index, 1, val.GetPtr())); + else if(i->m_ColCount == 4) + OGL_CALL(glUniform4fvARB (i->m_Index, 1, val.GetPtr())); + } + else + { + // In theory Uniform*f can also be used to load bool uniforms, in practice + // some drivers don't like that. So load both integers and bools via *i functions. + int ival[4] = {val.x, val.y, val.z, val.w}; + if (i->m_ColCount == 1) + OGL_CALL(glUniform1ivARB (i->m_Index, 1, ival)); + else if(i->m_ColCount == 2) + OGL_CALL(glUniform2ivARB (i->m_Index, 1, ival)); + else if(i->m_ColCount == 3) + OGL_CALL(glUniform3ivARB (i->m_Index, 1, ival)); + else if(i->m_ColCount == 4) + OGL_CALL(glUniform4ivARB (i->m_Index, 1, ival)); + } + #if DEBUG_GLSL_BINDINGS + printf_console(" vector %i dim=%i\n", i->m_Index, i->m_Dim ); + #endif + buffer += sizeof(Vector4f); + } + else + { + // Apply matrix parameters + DebugAssert(i->m_RowCount == 4); + int size = *reinterpret_cast<const int*> (buffer); buffer += sizeof(int); + DebugAssert (size == 16); + const Matrix4x4f* mat = reinterpret_cast<const Matrix4x4f*>(buffer); + const float *ptr = mat->GetPtr (); + OGL_CALL(glUniformMatrix4fvARB (i->m_Index, 1, false, ptr)); + #if DEBUG_GLSL_BINDINGS + printf_console(" matrix %i (%s)\n", i->m_Index, i->m_Name.GetName() ); + #endif + buffer += size * sizeof(float); + } + } + + // Apply textures + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for( GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i ) + { + const GpuProgramParameters::TextureParameter& t = *i; + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + int texIndex = int(UInt32(t.m_Index) >> 24); + Assert(texIndex < gGraphicsCaps.maxTexImageUnits); + UInt32 uniformIndex = t.m_Index & 0xFFFFFF; + OGL_CALL(glUniform1ivARB( uniformIndex, 1, &texIndex )); + #if DEBUG_GLSL_BINDINGS + printf_console(" sampler %i to unit %i (%s)\n", uniformIndex, texIndex, t.m_Name.GetName() ); + #endif + ApplyTexEnvData (texIndex, texIndex, *texdata); + buffer += sizeof(*texdata); + } + + GLAssert(); +} + + +GLShaderID GlslGpuProgram::GetGLProgram (FogMode fog, GpuProgramParameters& outParams) +{ + int index = 0; + if (fog > kFogDisabled && !m_SourceForFog.empty() && !m_FogFailed[fog]) + { + index = fog; + Assert (index >= 0 && index < kFogModeCount); + + // create patched fog program if needed + if (!m_Programs[index]) + { + std::string src = m_SourceForFog; + if (PatchShaderFogGLSL (src, fog)) + { + // create program, fragment shader, link + m_Programs[index] = glCreateProgramObjectARB(); + ShaderErrors errors; + if( + (m_GLSLVertexShader[index] = CompileVertexShader("#define VERTEX\n" + src, errors)) != 0 && + (m_GLSLFragmentShader[index] = CompileFragmentShader("#define FRAGMENT\n" + src, errors)) != 0 ) + { + glAttachObjectARB(m_Programs[index], m_GLSLVertexShader[index]); + glAttachObjectARB(m_Programs[index], m_GLSLFragmentShader[index]); + glLinkProgramARB(m_Programs[index]); + if (!ParseGLSLErrors (m_Programs[index], kErrorLinkProgram, errors)) + { + FillParams (m_Programs[index], outParams, NULL); + m_FogParamsIndex[index] = glGetUniformLocationARB(m_Programs[index], "_unity_FogParams"); + m_FogColorIndex[index] = glGetUniformLocationARB(m_Programs[index], "_unity_FogColor"); + } + else + { + glDeleteObjectARB(m_GLSLVertexShader[index]); m_GLSLVertexShader[index] = 0; + glDeleteObjectARB(m_GLSLFragmentShader[index]); m_GLSLFragmentShader[index] = 0; + glDeleteObjectARB(m_Programs[index]); m_Programs[index] = 0; + m_FogFailed[index] = true; + index = 0; + } + } + else + { + glDeleteObjectARB(m_GLSLVertexShader[index]); m_GLSLVertexShader[index] = 0; + glDeleteObjectARB(m_GLSLFragmentShader[index]); m_GLSLFragmentShader[index] = 0; + glDeleteObjectARB(m_Programs[index]); m_Programs[index] = 0; + m_FogFailed[index] = true; + index = 0; + } + } + else + { + m_FogFailed[index] = true; + index = 0; + } + } + } + return m_Programs[index]; +} diff --git a/Runtime/GfxDevice/opengl/GpuProgramsGL.h b/Runtime/GfxDevice/opengl/GpuProgramsGL.h new file mode 100644 index 0000000..f9649dd --- /dev/null +++ b/Runtime/GfxDevice/opengl/GpuProgramsGL.h @@ -0,0 +1,28 @@ +#pragma once + +#include "Runtime/GfxDevice/GpuProgram.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" + +class ShaderErrors; + +class GlslGpuProgram : public GpuProgramGL { +public: + GlslGpuProgram( const std::string& source, CreateGpuProgramOutput& output ); + virtual ~GlslGpuProgram(); + + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer); + + GLShaderID GetGLProgram (FogMode fog, GpuProgramParameters& outParams); + +private: + bool Create( const std::string& source, ShaderErrors& outErrors ); + static void FillParams (GLShaderID programID, GpuProgramParameters& params, PropertyNamesSet* outNames); + void FillChannels (ChannelAssigns& channels); + +private: + GLShaderID m_GLSLVertexShader[kFogModeCount]; + GLShaderID m_GLSLFragmentShader[kFogModeCount]; + int m_FogColorIndex[kFogModeCount]; + int m_FogParamsIndex[kFogModeCount]; + bool m_FogFailed[kFogModeCount]; +}; diff --git a/Runtime/GfxDevice/opengl/GraphicsCapsGL.cpp b/Runtime/GfxDevice/opengl/GraphicsCapsGL.cpp new file mode 100644 index 0000000..407b3c3 --- /dev/null +++ b/Runtime/GfxDevice/opengl/GraphicsCapsGL.cpp @@ -0,0 +1,1176 @@ +#include "UnityPrefix.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "UnityGL.h" +#include <string> +#include "Runtime/Utilities/Word.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Utilities/Utility.h" +#include "Runtime/Shaders/ShaderKeywords.h" +#include "GLContext.h" + +#define GL_RT_COMMON_GL 1 +#include "Runtime/GfxDevice/GLRTCommon.h" +#undef GL_RT_COMMON_GL + + +#if UNITY_OSX +#include <OpenGL/OpenGL.h> +#include "GLContext.h" +#endif + +#if UNITY_LINUX +#include <dirent.h> +#include <GL/glx.h> +#endif + +using namespace std; + + +bool QueryExtensionGL (const char* ext) +{ + static const char* extensions = NULL; + if (!extensions) + extensions = (const char*)glGetString(GL_EXTENSIONS); + return FindGLExtension (extensions, ext); +} + +#if UNITY_LINUX +static bool QueryExtensionGLX (const char* ext) +{ + static const char* glxExtensions = NULL; + if (!glxExtensions) { + Display *display = reinterpret_cast<Display*> (GetScreenManager ().GetDisplay ()); + glxExtensions = glXQueryExtensionsString (display, 0); + printf_console ("GLX Extensions: %s\n", glxExtensions); + } + return FindGLExtension (glxExtensions, ext); +} +#endif + + +#if UNITY_WIN + +#include "PlatformDependent/Win/wglext.h" +#include "PlatformDependent/Win/WinDriverUtils.h" + +static bool WglQueryExtension( const char* extension ) +{ + static bool gotExtensions = false; + static const char* extensions = NULL; + + if( !gotExtensions ) + { + gotExtensions = true; + + if (wglGetExtensionsStringARB) + extensions = wglGetExtensionsStringARB( wglGetCurrentDC() ); + else if (wglGetExtensionsStringEXT) + extensions = wglGetExtensionsStringEXT(); + + // always print WGL extensions + if( extensions ) + printf_console( " WGL extensions: %s\n", extensions ); + else + printf_console( " WGL extensions: none!\n" ); + } + + if( extensions == NULL || extensions[0] == '\0' ) + return false; + + int extLen = strlen( extension ); + const char* start; + const char* where, *terminator; + start = extensions; + for(;;) { + where = strstr(start, extension); + if(!where) break; + terminator = where + extLen; + if( where == start || *(where - 1) == ' ' ) { + if(*terminator == ' ' || *terminator == '\0') + return true; + } + start = terminator; + } + + return false; +} + +#endif + + +// Checks if all given formats are supported. Terminate the array with -1. +static bool CheckCompressedFormatsSupport( const GLint* formats ) +{ + if( !QueryExtensionGL( "GL_EXT_texture_compression_s3tc" ) ) + return false; + + GLint numSupportedFormats = 0; + glGetIntegerv( GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, &numSupportedFormats ); + GLint* supportedFormats = new GLint[numSupportedFormats+1]; + glGetIntegerv( GL_COMPRESSED_TEXTURE_FORMATS_ARB, supportedFormats ); + GLint* supportedFormatsEnd = supportedFormats + numSupportedFormats; + + bool result = true; + + // for each given format, try to find it in the supported formats list + while( *formats != -1 ) + { + if( std::find( supportedFormats, supportedFormatsEnd, *formats ) == supportedFormatsEnd ) + { + result = false; + break; + } + ++formats; + } + + delete[] supportedFormats; + + return result; +} + +static bool IsRendererAppleFX5200( const std::string& renderer ) +{ + return + (renderer.find("NVIDIA NV34MAP OpenGL Engine") != string::npos) || + (renderer.find("NVIDIA GeForce FX 5200") != string::npos); +} + + +#if UNITY_WIN +static void GetVideoCardIDsWin (int& outVendorID, int& outDeviceID) +{ + outVendorID = 0; + outDeviceID = 0; + + DISPLAY_DEVICEA dev; + dev.cb = sizeof(dev); + int i = 0; + while (EnumDisplayDevicesA(NULL, i, &dev, 0)) + { + if (dev.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) + { + const char* sVendorID = strstr (dev.DeviceID, "VEN_"); + if (sVendorID) + sscanf(sVendorID, "VEN_%x", &outVendorID); + const char *sDeviceID = strstr (dev.DeviceID, "DEV_"); + if (sDeviceID) + sscanf(sDeviceID, "DEV_%x", &outDeviceID); + return; + } + ++i; + } +} +#endif + +#if UNITY_OSX +static UInt32 GetOSXVersion() +{ + UInt32 response = 0; + + Gestalt(gestaltSystemVersion, (MacSInt32*) &response); + return response; +} + +static CFTypeRef SearchPortForProperty(io_registry_entry_t dspPort, CFStringRef propertyName) +{ + return IORegistryEntrySearchCFProperty(dspPort, + kIOServicePlane, + propertyName, + kCFAllocatorDefault, + kIORegistryIterateRecursively | kIORegistryIterateParents); +} + +static UInt32 IntValueOfCFData(CFDataRef d) +{ + UInt32 value = 0; + if (d) { + const UInt32 *vp = reinterpret_cast<const UInt32*>(CFDataGetBytePtr(d)); + if (vp != NULL) + value = *vp; + } + return value; +} + +static void GetVideoCardIDsOSX (int& outVendorID, int& outDeviceID) +{ + CFStringRef strVendorID = CFStringCreateWithCString (NULL, "vendor-id", kCFStringEncodingASCII); + CFStringRef strDeviceID = CFStringCreateWithCString (NULL, "device-id", kCFStringEncodingASCII); + + CGDirectDisplayID displayID = kCGDirectMainDisplay; + io_registry_entry_t dspPort = CGDisplayIOServicePort (displayID); + CFTypeRef vendorIDRef = SearchPortForProperty (dspPort, strVendorID); + CFTypeRef deviceIDRef = SearchPortForProperty (dspPort, strDeviceID); + + CFRelease (strDeviceID); + CFRelease (strVendorID); + + outVendorID = IntValueOfCFData ((CFDataRef)vendorIDRef); + outDeviceID = IntValueOfCFData ((CFDataRef)deviceIDRef); + + if (vendorIDRef) CFRelease (vendorIDRef); + if (deviceIDRef) CFRelease (deviceIDRef); +} + +static float GetVideoMemoryMBOSX() +{ + float vramMB = 0.0f; + + // Adapted from "Custom Cocoa OpenGL" sample. + // We used code from VideoHardwareInfo sample before, but that reports wrong VRAM + // amount in some cases (e.g. Intel GMA 950 reports 256MB, but it has 64MB; GeForce 9600 reports + // 256MB, but it has 512MB). + + const int kMaxDisplays = 8; + CGDirectDisplayID displays[kMaxDisplays]; + CGDisplayCount displayCount; + CGGetActiveDisplayList( kMaxDisplays, displays, &displayCount ); + CGOpenGLDisplayMask openGLDisplayMask = CGDisplayIDToOpenGLDisplayMask(displays[0]); + + CGLRendererInfoObj info; + CGLint numRenderers = 0; + CGLError err = CGLQueryRendererInfo( openGLDisplayMask, &info, &numRenderers ); + if( 0 == err ) { + CGLDescribeRenderer( info, 0, kCGLRPRendererCount, &numRenderers ); + for( int j = 0; j < numRenderers; ++j ) + { + CGLint rv = 0; + // find accelerated renderer (assume only one) + CGLDescribeRenderer( info, j, kCGLRPAccelerated, &rv ); + if( true == rv ) + { + CGLint vram = 0; + CGLDescribeRenderer( info, j, kCGLRPVideoMemory, &vram ); + vramMB = double(vram)/1024.0/1024.0; + break; + } + } + CGLDestroyRendererInfo (info); + } + + // safe guards + if( vramMB == 0.0f ) // if some device reports zero (integrated cards?), treat as 64MB + vramMB = 64.0f; + return vramMB; +} +#endif + +#if UNITY_LINUX +typedef struct { + unsigned int vendor; + unsigned int device; + unsigned long vramSize; +} card_info_t; + +static void GetPrimaryGraphicsCardInfo(card_info_t *info) +{ + struct dirent *pDir; + + // Open the /sys/devices directory and iterate over for PCI busses + // It appears that most modern graphics cards will be mapped as a PCI device. + // That includes integrated chipsets and AGP cards as well. AGP cards get connected + // through an AGP to PCI bus link + const char *dirPath = "/sys/devices/"; + const char *PCI_BASE_CLASS_DISPLAY = "0x03"; + + DIR *devicesDir = opendir(dirPath); + while ((pDir=readdir(devicesDir)) != NULL) + { + if(strncmp(pDir->d_name, "pci", 3) == 0) + { + char busID[PATH_MAX]; + memcpy(busID, pDir->d_name+3, strlen(pDir->d_name)); + + // Now iterate over each directory for this bus + struct dirent *pPCIDir; + char domainPath[PATH_MAX]; + strcpy(domainPath, dirPath); + strcat(domainPath, pDir->d_name); + DIR *pciDeviceDir = opendir(domainPath); + while ((pPCIDir=readdir(pciDeviceDir)) != NULL) + { + if(strstr(pPCIDir->d_name, busID) != NULL) + { + char filePath[PATH_MAX]; + char line[512]; + char pciSubDevPath[PATH_MAX]; + char domain[PATH_MAX]; + struct dirent *pSubDevDir; + + // Get a copy of the PCI domain + memcpy(domain, pPCIDir->d_name, 4); + + // Ok, now open and read the first line of the class file. + // We're only concerned with display class devices + sprintf(filePath, "%s/%s", domainPath, pPCIDir->d_name); + + FILE *classFile = fopen(filePath, "r"); + fgets(line, sizeof(line), classFile); + fclose(classFile); + + // Now iterate over each directory for this device + + sprintf(pciSubDevPath, "%s/%s", domainPath, pPCIDir->d_name); + DIR *pciSubDeviceDir = opendir(pciSubDevPath); + while ((pSubDevDir=readdir(pciSubDeviceDir)) != NULL) + { + char devPath[PATH_MAX]; + + // Ok, now open and read the first line of the class file. + // We're only concerned with display class devices + sprintf(filePath, "%s/%s", pciSubDevPath, pSubDevDir->d_name); + strcpy(devPath, filePath); + strcat(filePath, "/class"); + + FILE *classFile = fopen(filePath, "r"); + if(classFile) + { + fgets(line, sizeof(line), classFile); + fclose(classFile); + + if(strstr(line, PCI_BASE_CLASS_DISPLAY) != NULL) + { + // Device ID is in the device file + strcpy(filePath, devPath); + strcat(filePath, "/device"); + FILE *f = fopen(filePath, "r"); + if(f) + { + fgets(line, sizeof(line), f); + fclose(f); + info->device = strtol(line, NULL, 16); + } + + // Vendor ID is in the vendor file + strcpy(filePath, devPath); + strcat(filePath, "/vendor"); + f = fopen(filePath, "r"); + if(f) + { + fgets(line, sizeof(line), f); + fclose(f); + info->vendor = strtol(line, NULL, 16); + } + + // Now for the tricky part. VRAM size. + // Each line in the resource file represents the memory range of a PCI resource + // Start address, end address and flags. Separated by spaces. VRAM is most often + // the only prefetchable resource so we can identify it by checking for that flag. + strcpy(filePath, devPath); + strcat(filePath, "/resource"); + f = fopen(filePath, "r"); + if(f) + { + // Loop through each resource + while(fgets(line, sizeof(line), f)) + { + unsigned long low, high, flags; + char *next = line; + low = strtoull(next, &next, 16); + high = strtoull(next, &next, 16); + flags = strtoull(next, &next, 16); + // Check for the prefetchable flag + if((flags & 0x08)) + { + info->vramSize += (high-low)+1; + } + } + fclose(f); + } + } + } + } + } + } + closedir(pciDeviceDir); + } + } + closedir(devicesDir); +} + +static card_info_t gCardInfo; +static void InitCardInfoLinux(){ + gCardInfo.device = 0; + gCardInfo.vendor = 0; + gCardInfo.vramSize = 0; + GetPrimaryGraphicsCardInfo(&gCardInfo); + + if(gCardInfo.vramSize < (64*1024*1024)){ + // Default to 64MB + gCardInfo.vramSize = 64*1024*1024; + } +} + +static void GetVideoCardIDsLinux (int& outVendorID, int& outDeviceID) +{ + outVendorID = gCardInfo.vendor; + outDeviceID = gCardInfo.device; +} + +static float GetVideoMemoryMBLinux() +{ + // Nvidia + if (QueryExtensionGL ("GL_NVX_gpu_memory_info")) { + GLint vram = 0; + glGetIntegerv (GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &vram); + printf_console ("GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX: %ld\n", vram); + GLAssert (); + return vram / 1024.0f; + } + // ATI + if (QueryExtensionGL ("GL_ATI_meminfo")) { + GLint vram[4] = {0,0,0,0}; + glGetIntegerv (VBO_FREE_MEMORY_ATI, vram); + printf_console ("VBO_FREE_MEMORY_ATI: %ld\n", vram[0]); + glGetIntegerv (RENDERBUFFER_FREE_MEMORY_ATI, vram); + printf_console ("RENDERBUFFER_FREE_MEMORY_ATI: %ld\n", vram[0]); + glGetIntegerv (TEXTURE_FREE_MEMORY_ATI, vram); + printf_console ("TEXTURE_FREE_MEMORY_ATI: %ld\n", vram[0]); + GLAssert (); + return vram[0] / 1024.0f; + } + + // Fallback to pci aperture size + return gCardInfo.vramSize / 1048576.0f; +} +#endif + + +void GraphicsCaps::InitGL() +{ + // Figure out major & minor version numbers. + // Some drivers do not report this according to the spec, and sometimes mix in some letters and whatnot (e.g. "1.08a" - SIS, I'm looking at you). + // So try to parse one full number, a period and one digit, and stop parsing on anything that we can' t recognize. + const char *versionStr = (const char *)glGetString (GL_VERSION); + driverVersionString = versionStr; + int major = 0, minor = 0; + bool gotMajor = false; + while( versionStr && *versionStr ) { + char c = *versionStr; + if( isdigit(c) ) + { + if( !gotMajor ) + { + major = major * 10 + (c-'0'); + } + else + { + minor = c-'0'; + break; // only take first digit of minor version + } + } + else if( c == '.' ) + { + gotMajor = true; + } + else + { + // unknown symbol, stop parsing + break; + } + ++versionStr; + } + + // Important: only take first digit of minor version. + // Some cards have version like 1.12. + int version = major * 10 + minor % 10; + + rendererString = (const char*)glGetString( GL_RENDERER ); + vendorString = (const char*)glGetString( GL_VENDOR ); + + // some drivers are absolutely horrible! + AdjustBuggyVersionGL( version, major, minor ); + + gl.glVersion = version; + + char buffer[200]; + snprintf( buffer, 200, "OpenGL %d.%d [%s]", major, minor, driverVersionString.c_str() ); + fixedVersionString = buffer; + + #if UNITY_WIN + GetVideoCardIDsWin (vendorID, rendererID); + #elif UNITY_OSX + GetVideoCardIDsOSX (vendorID, rendererID); + #elif UNITY_LINUX + InitCardInfoLinux(); + GetVideoCardIDsLinux(vendorID, rendererID); + #else + #error "Unknown platform" + #endif + + #if UNITY_OSX + videoMemoryMB = GetVideoMemoryMBOSX(); + #elif UNITY_LINUX + videoMemoryMB = GetVideoMemoryMBLinux(); + #endif + + driverLibraryString = "n/a"; + + // On windows, we always output GL info. There is so much variety that + // it always helps! + printf_console( "OpenGL:\n" ); + printf_console( " Version: %s\n", fixedVersionString.c_str() ); + printf_console( " Renderer: %s\n", rendererString.c_str() ); + printf_console( " Vendor: %s\n", vendorString.c_str() ); + #if UNITY_WIN + windriverutils::VersionInfo driverVersion; + std::string driverName; + if( windriverutils::GetDisplayDriverInfoRegistry( NULL, &driverName, driverVersion ) ) + { + driverLibraryString = Format("%s %i.%i.%i.%i", + driverName.c_str(), + driverVersion.hipart >> 16, driverVersion.hipart & 0xFFFF, + driverVersion.lopart >> 16, driverVersion.lopart & 0xFFFF ); + printf_console( " Driver: %s\n", driverLibraryString.c_str() ); + } + const char* vramMethod = ""; + int vramMB = windriverutils::GetVideoMemorySizeMB (MonitorFromWindow(GetDesktopWindow(),MONITOR_DEFAULTTOPRIMARY), &vramMethod); + videoMemoryMB = vramMB; + printf_console( " VRAM: %i MB (via %s)\n", (int)videoMemoryMB, vramMethod ); + #else + driverLibraryString = driverVersionString; + printf_console( " VRAM: %i MB\n", (int)videoMemoryMB ); + #endif + + printf_console( " Extensions: %s\n", glGetString(GL_EXTENSIONS) ); + +#if UNITY_OSX + maxVSyncInterval = 4; +#elif UNITY_LINUX + if (QueryExtensionGLX ("GLX_SGI_swap_control")) + maxVSyncInterval = 4; + printf_console ("Setting maxVSyncInterval to %d\n", maxVSyncInterval); +#else +// TODO: What should max vsync interval be? +#endif + has16BitFloatVertex = QueryExtensionGL( "GL_ARB_half_float_vertex" ); + needsToSwizzleVertexColors = false; + + glGetIntegerv( GL_MAX_LIGHTS, &maxLights ); + maxLights = clamp<int>( maxLights, 0, 8 ); + + glGetIntegerv( GL_MAX_TEXTURE_SIZE, &maxTextureSize ); + glGetIntegerv( GL_MAX_CUBE_MAP_TEXTURE_SIZE, &maxCubeMapSize ); + maxRenderTextureSize = maxTextureSize; + + hasBlendSquare = QueryExtensionGL( "GL_NV_blend_square" ); + hasSeparateAlphaBlend = QueryExtensionGL ("GL_EXT_blend_func_separate"); + + // Treat blendOps supported only if we have a full set (minmax & subtract; separate + // blend equation if have separate alpha func) + hasBlendSub = QueryExtensionGL("GL_EXT_blend_subtract"); + hasBlendMinMax = QueryExtensionGL("GL_EXT_blend_minmax"); + if (hasSeparateAlphaBlend) + { + hasBlendSub &= QueryExtensionGL("GL_EXT_blend_equation_separate"); + hasBlendMinMax &= QueryExtensionGL("GL_EXT_blend_equation_separate"); + } + + // GLSL Vertex/Fragment shaders + gl.hasGLSL = QueryExtensionGL("GL_ARB_shader_objects") && QueryExtensionGL("GL_ARB_vertex_shader") && QueryExtensionGL("GL_ARB_fragment_shader"); + + + gl.nativeVPInstructions = gl.vertexAttribCount = 0; + // Instruction count + glGetProgramivARB (GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl.nativeVPInstructions); + // Vertex atrribute count + glGetProgramivARB (GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ATTRIBS_ARB, &gl.vertexAttribCount); + if( gl.vertexAttribCount > 16 ) + gl.vertexAttribCount = 16; + + gl.nativeFPInstructions = gl.nativeFPTemporaries = gl.nativeFPALUInstructions = gl.nativeFPTexInstructions = 0; + // FP capabilities + glGetProgramivARB (GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl.nativeFPInstructions); + glGetProgramivARB (GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl.nativeFPTemporaries); + glGetProgramivARB (GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, &gl.nativeFPALUInstructions); + glGetProgramivARB (GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, &gl.nativeFPTexInstructions); + + gl.hasTextureEnvCombine3ATI = QueryExtensionGL( "GL_ATI_texture_env_combine3" ); + gl.hasTextureEnvCombine3NV = QueryExtensionGL( "GL_NV_texture_env_combine4" ); + + maxTexUnits = maxTexImageUnits = maxTexCoords = 1; + glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, (GLint *)&maxTexUnits); + glGetIntegerv (GL_MAX_TEXTURE_IMAGE_UNITS_ARB, (GLint *)&maxTexImageUnits); + glGetIntegerv( GL_MAX_TEXTURE_COORDS_ARB, (GLint *)&maxTexCoords ); + + // Clamp max counts. Some recent GPUs (e.g. Radeon 5xxx on Windows) + // report 16 texture coordinates, which wreak havoc in the channel bindings + // (those assume 8 coords maximum, and more than that starts overwriting + // generic attribute bindings) + maxTexCoords = std::min<int> (maxTexCoords, kMaxSupportedTextureCoords); + maxTexImageUnits = std::min<int> (maxTexImageUnits, kMaxSupportedTextureUnits); + maxTexUnits = std::max<int>( std::min<int>( maxTexUnits, kMaxSupportedTextureUnits ), 1 ); + + hasAnisoFilter = QueryExtensionGL( "GL_EXT_texture_filter_anisotropic" ); + if( hasAnisoFilter ) + glGetIntegerv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint *)&maxAnisoLevel ); + else + maxAnisoLevel = 1; + hasMipLevelBias = version >= 14 || QueryExtensionGL( "GL_EXT_texture_lod_bias" ); + + static GLint requiredCompressedFormats[] = { GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, -1 }; + hasS3TCCompression = CheckCompressedFormatsSupport( requiredCompressedFormats ); + + // Set bits defined by GL version + gl.hasArbMapBufferRange = QueryExtensionGL ("GL_ARB_map_buffer_range"); + + // ARB_sync seems to be flaky on OS X 10.7 + // Discovered as part of case 441958, when switching fullscreen mode. + // it will fall back to GL_APPLE_fence which seems to work reliably + gl.hasArbSync = UNITY_LINUX && QueryExtensionGL ("GL_ARB_sync"); + + #if UNITY_OSX + gl.hasAppleFence = QueryExtensionGL ("GL_APPLE_fence"); + gl.hasAppleFlushBufferRange = QueryExtensionGL ("GL_APPLE_flush_buffer_range"); + #endif + + has3DTexture = QueryExtensionGL ("GL_EXT_texture3D") || version >= 12; + + npot = QueryExtensionGL ("GL_ARB_texture_non_power_of_two") ? kNPOTFull : kNPOTNone; + // On OS X, pre-DX10 ATI cards can't really fully handle it. +#if UNITY_OSX + if (npot == kNPOTFull && gl.nativeFPInstructions < 4096) { + npot = kNPOTRestricted; + } +#endif + npotRT = npot; + + hasTimerQuery = QueryExtensionGL ("GL_EXT_timer_query"); + + // has multi sampling? + #if UNITY_WIN + hasMultiSample = QueryExtensionGL( "GL_ARB_multisample" ) && WglQueryExtension( "WGL_ARB_multisample" ); + gl.hasWglARBPixelFormat = WglQueryExtension( "WGL_ARB_pixel_format" ) && wglGetPixelFormatAttribivARB && wglChoosePixelFormatARB; + if( !gl.hasWglARBPixelFormat ) + { + hasMultiSample = false; + printf_console( "GL: disabling multisample because WGL_ARB_pixel_format not fully supported\n" ); + } + #else + hasMultiSample = QueryExtensionGL ("GL_ARB_multisample"); + #endif + + hasMultiSample &= QueryExtensionGL ("GL_EXT_framebuffer_multisample"); + gl.maxSamples = 1; + if (hasMultiSample) + glGetIntegerv(GL_MAX_SAMPLES_EXT, &gl.maxSamples); + + // has WGL swap control? + #if UNITY_WIN + gl.hasWglSwapControl = WglQueryExtension( "WGL_EXT_swap_control" ); + #endif + + hasSRGBReadWrite = QueryExtensionGL("GL_EXT_texture_sRGB"); + hasSRGBReadWrite = hasSRGBReadWrite && QueryExtensionGL("GL_EXT_framebuffer_sRGB"); + + // Has render textures? We only support FBOs, not p-buffers. + hasRenderToTexture = QueryExtensionGL("GL_EXT_framebuffer_object"); + hasRenderToCubemap = hasRenderToTexture; + hasRenderTargetStencil = QueryExtensionGL("GL_EXT_packed_depth_stencil"); + if (QueryExtensionGL("GL_ARB_draw_buffers")) + { + glGetIntegerv (GL_MAX_DRAW_BUFFERS_ARB, &maxMRTs); + maxMRTs = clamp<int> (maxMRTs, 1, kMaxSupportedRenderTargets); + } + else + { + maxMRTs = 1; + } + hasStencil = true; + hasTwoSidedStencil = (version >= 20); + hasNativeDepthTexture = true; + hasStencilInDepthTexture = true; + + + #pragma message ("Properly implement supported formats!") + for (int q = 0; q < kTexFormatPCCount; ++q) + supportsTextureFormat[q] = true; + + + supportsRenderTextureFormat[kRTFormatARGB32] = hasRenderToTexture; + supportsRenderTextureFormat[kRTFormatDepth] = QueryExtensionGL ("GL_ARB_depth_texture"); + supportsRenderTextureFormat[kRTFormatA2R10G10B10] = false; + supportsRenderTextureFormat[kRTFormatARGB64] = false; + + if( hasRenderToTexture ) + { + FBColorFormatCheckerGL checker; + + supportsRenderTextureFormat[kRTFormatRGB565] = checker.CheckFormatSupported(GL_RGB5, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); + supportsRenderTextureFormat[kRTFormatARGB4444] = checker.CheckFormatSupported(GL_RGBA4, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4); + supportsRenderTextureFormat[kRTFormatARGB1555] = checker.CheckFormatSupported(GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_5_5_5_1); + } + + { + const bool supportFloatTex = QueryExtensionGL("GL_ARB_texture_float"); + const bool supportsHalfRT = supportFloatTex && QueryExtensionGL("GL_ARB_half_float_pixel"); + const bool supportsFloatRT = supportFloatTex && (QueryExtensionGL("GL_ARB_color_buffer_float") || QueryExtensionGL("GL_APPLE_float_pixels")); + const bool supportsIntRT = QueryExtensionGL("GL_EXT_texture_integer"); + const bool supportsRG = QueryExtensionGL("GL_ARB_texture_rg"); + + supportsRenderTextureFormat[kRTFormatARGBHalf] = hasRenderToTexture && supportsHalfRT; + supportsRenderTextureFormat[kRTFormatARGBFloat] = hasRenderToTexture && supportsFloatRT; + supportsRenderTextureFormat[kRTFormatR8] = hasRenderToTexture && supportsRG; + supportsRenderTextureFormat[kRTFormatRHalf] = hasRenderToTexture && supportsHalfRT && supportsRG; + supportsRenderTextureFormat[kRTFormatRFloat] = hasRenderToTexture && supportsFloatRT && supportsRG; + supportsRenderTextureFormat[kRTFormatRGHalf] = hasRenderToTexture && supportsHalfRT && supportsRG; + supportsRenderTextureFormat[kRTFormatRGFloat] = hasRenderToTexture && supportsFloatRT && supportsRG; + } + + supportsRenderTextureFormat[kRTFormatDefault] = hasRenderToTexture; + + hasNativeShadowMap = supportsRenderTextureFormat[kRTFormatDepth] && QueryExtensionGL("GL_ARB_fragment_program_shadow"); + // GL_ARB_fragment_program_shadow does not work on OS X (at least on 10.4.8-10.4.10) + // Seems to work on 10.6.7 & 10.7.x (nvidia), so for safety just disable it on < 10.6.7. + #if UNITY_OSX + if (GetOSXVersion() < 0x01067) + hasNativeShadowMap = false; + #endif + gl.originalHasNativeShadowMaps = hasNativeShadowMap; + supportsRenderTextureFormat[kRTFormatShadowMap] = hasNativeShadowMap; + + // Framebuffer blit + gl.hasFrameBufferBlit = QueryExtensionGL( "GL_EXT_framebuffer_blit" ); + + hasAutoMipMapGeneration = version >= 14 || QueryExtensionGL("GL_SGIS_generate_mipmap"); + + //// *** Unity bug workarounds following: + + // Driver bugs/workarounds following + DetectDriverBugsGL( version ); + + // in the very end, figure out shader capabilities level (after all workarounds are applied) + if (gl.nativeFPInstructions < 1024 || gl.nativeFPTexInstructions < 512 || gl.nativeFPALUInstructions < 512 || gl.nativeFPTemporaries < 32) + { + // under 1024 instructions (512 tex + 512 alu) or under 32 temps: 2.x shaders + shaderCaps = kShaderLevel2; + } + else + { + // has everything we care about! + shaderCaps = kShaderLevel3; + } +} + +static bool DisableGraphicsWorkarounds() +{ + // Disable workarounds if we have env set + if( getenv ("UNITY_DISABLE_GRAPHICS_DRIVER_WORKAROUNDS") && StrICmp (getenv ("UNITY_DISABLE_GRAPHICS_DRIVER_WORKAROUNDS"), "yes") == 0 ) + { + printf_console( "GL: disabling graphics workarounds\n" ); + return true; + } + return false; +} + +void GraphicsCaps::AdjustBuggyVersionGL( int& version, int& major, int& minor ) const +{ + if( DisableGraphicsWorkarounds() ) + return; + + // SiS stuff + if( (vendorString.find("SiS") == 0) ) + { + // Compatible VGA / MMX: reports as 2.06a.00, seems like 1.1 + if( (rendererString.find("Compatible VGA") != string::npos) && version >= 20 ) + { + printf_console("GL: Wrong GL version reported, treating as GL 1.1\n"); + version = 11; + major = 1; + minor = 1; + return; + } + // 630/730 / MMX: reports as 2.03 to 2.08, seems like 1.1 + if( (rendererString.find("630/730") != string::npos) && version >= 20 ) + { + printf_console("GL: Wrong GL version reported, treating as GL 1.1\n"); + version = 11; + major = 1; + minor = 1; + return; + } + } +} + +#if UNITY_WIN +#include "PlatformDependent/Win/WinUtils.h" +#endif + +void GraphicsCaps::DetectDriverBugsGL( int version ) +{ + gl.buggyArbPrecisionHint = false; + gl.force24DepthForFBO = false; + gl.cacheFPParamsWithEnvs = false; + gl.forceColorBufferWithDepthFBO = false; + gl.buggyPackedDepthStencil = false; + gl.mustWriteToDepthBufferBeforeClear = false; + + const bool isNvidia = (vendorString.find("NVIDIA") != string::npos) || (vendorString.find("Nvidia") != string::npos); + const bool isRadeon = (rendererString.find("RADEON") != string::npos) || (rendererString.find("Radeon") != string::npos); + +#if UNITY_WIN || UNITY_LINUX + // vendorString on Intel Gfx / Linux contains Tungsten graphics instead of Intel so we check the rendererString too... + bool isIntel = (vendorString.find ("INTEL") != string::npos) || (vendorString.find ("Intel") != string::npos) || (rendererString.find("Intel") != string::npos); +#endif + + + // Driver version numbers +#if UNITY_WIN || UNITY_LINUX + int majorVersion = 0, minorVersion = 0; + bool parsedDriverVersion = false; +#endif +#if UNITY_WIN + int buildVersion = 0; +#endif +#if UNITY_LINUX + int seriesVersion = 0; + bool parsedSeriesVersion = false; +#endif + +#if UNITY_WIN + int driverFields = sscanf( driverVersionString.c_str(), "%i.%i.%i", &majorVersion, &minorVersion, &buildVersion ); + parsedDriverVersion = (driverFields == 3); +#endif +#if UNITY_LINUX + if (isNvidia) + { + int temp1, temp2, temp3 = 0; + int driverFields = sscanf (driverVersionString.c_str(), "%i.%i.%i NVIDIA %i.%i", &temp1, &temp2, &temp3, &majorVersion, &minorVersion); + parsedDriverVersion = (driverFields == 5); + } + if (isRadeon) + { + char temp[BUFSIZ]; + int seriesFields = sscanf (rendererString.c_str(), "%s Radeon HD %i %*", temp, &seriesVersion); + parsedSeriesVersion = (seriesFields == 2); + } +#endif + + if( DisableGraphicsWorkarounds() ) + return; + + + // Timer queries are broken on OS X + older NVIDIA cards. Before 10.8 they just return bogus data; + // starting with 10.8 they actually lock up. It seems that everything before GeForce 6xx is affected + // (8800, 9400, 9600, GT120, 320, GT330). But GT650 is not affected and has GPU profiler working properly. + // From https://developer.apple.com/graphicsimaging/opengl/capabilities/ looks like earlier GPUs have ~60 + // varying floats, and 6xx has ~120, so let's detect on that. + #if UNITY_OSX + if (isNvidia && gl.hasGLSL) + { + // Case 562054: + // It looks that timer queries are broken on OS X + Nvidia cards again. + // For now, just disable timer queries on all Nvidia cars + OS X. + + //GLint maxVarying = 0; + //glGetIntegerv (GL_MAX_VARYING_FLOATS, &maxVarying); + //if (maxVarying < 100) + hasTimerQuery = false; + } + #endif // #if UNITY_OSX + + + // DynamicVBO with tangents is buggy. From comment by rej in dynamic batching code: + // "For some (yet) unkown reason DynamicNullVBO under OpenGL fail rendering geometry with Tangents + // we have to avoid batching for geometry with Tangents as long as DynamicNullVBO is going to be used" + // No one remembers the OS/GPU details by now (was around Unity 3.0 release), and looks like it's not a problem + // around Unity 4.0 release. So we'll assume that some recent OS X fixed the underlying issue. Let's say + // starting with 10.6.8 the problem does not exist... +#if UNITY_OSX + if (GetOSXVersion() < 0x01068) + buggyDynamicVBOWithTangents = true; +#endif + +#if UNITY_LINUX + if (isNvidia && parsedDriverVersion && (majorVersion <= 195)) + { + printf_console ("GL: enabling buggyPackedDepthStencil due to driver bug\n"); + gl.buggyPackedDepthStencil = true; + buggyTextureBothColorAndDepth = true; + } +#endif + +#if UNITY_OSX || UNITY_LINUX + bool isGMA950 = (rendererString == "Intel GMA 950 OpenGL Engine"); + bool isGMA3100 = (rendererString == "Intel GMA X3100 OpenGL Engine"); +#endif + + +#if UNITY_OSX + bool hasLeakingFBOWhenUsingMipMaps = rendererString == "NVIDIA GeForce 8600M GT OpenGL Engine"; + if (hasLeakingFBOWhenUsingMipMaps) + { + printf_console( "GL: disabling mip map calculation on Render Textures due to memory leak on NVIDIA GeForce 8600 graphics drivers.\n"); + hasAutoMipMapGeneration = false; + } +#endif + + +#if UNITY_OSX + // On OS X, trying to create depth texture/buffer in 16 bits fails on pre-10.6. + if (GetOSXVersion() < 0x01062) + { + gl.force24DepthForFBO = true; + } +#endif + + // Macs with Radeon HD cards (2400-4850) have bugs when using depthstencil texture + // as both depth buffer for testing and reading as a texture. Happens at least on 10.5.8 to 10.6.4. + // Same happens on Radeon X1600 as well, so we just do the workaround for all Radeons. + // + // Also, 10.6.4 graphics driver update broke regular sampling of depth stencil textures. Some words from + // Apple's Matt Collins: + // "What I suspect is happening is that ATI doesn't handle sampling from depth + // textures correctly if Hi-Z/Z-compression is on AND that texture has no mipmapping. I want to see + // if we can force the driver to alloc mipmaps for you. Typically we check a couple things to + // determine whether to allocate: whether the app has requested mipmaps, whether one the sampling mode is + // a mipmap filter, if mipmaps have been manually specified, or if MAX_LEVELS has been changed from + // the default value." + // Setting TEXTURE_MAX_LEVELS to zero before creating the texture fixes this particular problem; but sampling + // of the texture while using it for depth testing is still broken. +#if UNITY_OSX + if (hasRenderTargetStencil && isRadeon) + { + printf_console( "GL: buggy packed depth stencil; Deferred rendering will use slower rendering path\n" ); + gl.buggyPackedDepthStencil = true; + buggyTextureBothColorAndDepth = true; + } +#endif + + // Disable 16-bit float vertex channels on Radeon cards as the driver hits a super slow path + // when using three 16-bit components of a normal and 16-bits of padding to keep it aligned. + if (isRadeon) + has16BitFloatVertex = false; + +#if UNITY_OSX && WEBPLUG + if (GetOSXVersion() >= 0x01072 && isNvidia) + gl.mustWriteToDepthBufferBeforeClear = true; +#endif + +#if UNITY_OSX + // Macs with GeForce 7300 cards have broken packed depth stencil implementation. Happens at least + // up to OS X 10.6.3. We can tell pre-DX10 cards by looking at max. texture size; it is always less + // than 8192 on Macs. + const bool isGeForcePreDX10 = isNvidia && (maxTextureSize < 8192); + if (hasRenderTargetStencil && isGeForcePreDX10) + { + printf_console( "GL: disabling deferred lighting (buggy packed depth stencil on pre-DX10 GeForce cards)\n" ); + hasRenderTargetStencil = false; + buggyTextureBothColorAndDepth = true; + gl.force24DepthForFBO = true; // looks like that still can't handle 16 bit FBO depth (OS X 10.6.3) + } + + // Also, GeForce 7300 seems to bail out on anti-aliasing switches. OS X 10.5.8; anti-aliasing switching + // graphics tests produce "NVDA(OpenGL): Channel exception! status = 0xffff info32 = 0x6 = Fifo: Parse Error". + if (isGeForcePreDX10 && GetOSXVersion() < 0x01062) + { + printf_console( "GL: disabling anti-aliasing (buggy drivers on OS X 10.5 on pre-DX10 GeForce cards)\n" ); + hasMultiSample = false; + } + +# if WEBPLUG + if (isNvidia && GetOSXVersion () < 0x01090) + { + // NVIDIA drivers crash on OS X earlier than 10.9.0 when multisampling is enabled (case 521161): + // - when right-clicking the Unity content in Firefox + // - when exiting fullscreen in Chrome and Safari + printf_console( "GL: disabling anti-aliasing (buggy drivers on OS X pre-10.9.0 on NVIDIA cards give kernel panics)\n" ); + hasMultiSample = false; + } +# endif +#endif + +#if UNITY_OSX + // OS X with GMA X3100: lots of problems! (on OS X earlier than 10.5.3) + if( isGMA3100 && GetOSXVersion() < 0x01053 ) + { + // Crashes if depth component FBO is used without color attachment. + if( hasRenderToTexture ) + gl.forceColorBufferWithDepthFBO = true; + + // Depth textures just contain garbage + printf_console( "GL: disabling shadows (buggy on GMA X3100 pre-10.5.3)\n" ); + supportsRenderTextureFormat[kRTFormatDepth] = false; + // Cubemap pbuffers/FBOs contain garbage + printf_console( "GL: disabling render to cubemap (buggy on GMA X3100 pre-10.5.3)\n" ); + hasRenderToCubemap = false; + } + + // OS X 10.5.3 and 10.5.4 with non-updated drivers on Radeon X1xxx cards: shadows and render textures broken! + // Do not disable them though, sometimes they work... just show error message. + if( rendererString.find("ATI Radeon X1") != string::npos && GetOSXVersion() >= 0x01053 ) + { + // Driver 2.0 ATI-1.5.28 is broken (10.5.3, looks like 10.5.4 has the same driver). + // Pre-release driver 2.0 ATI-1.5.30 is good. + int driverBuild = 0; + sscanf( driverVersionString.c_str(), "2.0 ATI-1.5.%i", &driverBuild ); + if( driverBuild >= 28 && driverBuild < 30 ) { + ErrorString( "GL: broken Radeon X1xxx driver, shadows and render textures might behave funny. Wait for Apple to fix it..." ); + } + } +#endif + +#if UNITY_WIN || UNITY_OSX || UNITY_LINUX + // When creating the FBO and not attaching any color buffer, the FBO will return 'FBO fail: INCOMPLETE_DIMENSIONS'. + gl.forceColorBufferWithDepthFBO = true; +#endif + +#if UNITY_OSX + bool isGeForceGT650M = (rendererString == "NVIDIA GeForce GT 650M OpenGL Engine"); + if (isGeForceGT650M) + { + // MBP Retina June 2012 with OS X 10.8.2 freezes when at least one dimension of the texture is 8192 + maxTextureSize = 4096; + } +#endif + +#if UNITY_OSX + // Some NVIDIA cards have a broken ARB precision hint. We postprocess all fragment + // programs to not use it. + // It is definitely broken on a GeForce 5200 mobility on tiger 10.4.1 + gl.buggyArbPrecisionHint |= IsRendererAppleFX5200(rendererString); +#endif + +#if UNITY_OSX + if( isGMA950 ) + { + printf_console("GL: Disabling soft shadows because of GMA950 driver bugs\n"); + disableSoftShadows = true; + + // OS X: occasional crashes in auto FBO mipmap generation, OS X 10.5 & 10.6, case 372004 + printf_console( "GL: disabling mip map calculation on Render Textures due to GMA950 driver bugs\n"); + hasAutoMipMapGeneration = false; + + // Something wrong with FBOs on GMA 950, try disabling depth+stencil & color+depth FBOs. + hasRenderTargetStencil = false; + buggyTextureBothColorAndDepth = true; + } +#endif + +#if UNITY_OSX && UNITY_LITTLE_ENDIAN + // On Intel Macs with ATI cards, use Env parameters for fragment programs instead of Local + // ones, and cache the redundant changes. + // Do not do this on any other cards, as that will make shadows randomly disappear on PPC Macs. + gl.cacheFPParamsWithEnvs |= vendorString.find("ATI Technologies") != string::npos; +#endif + + +#if UNITY_WIN + if( isIntel ) + { + // Intel 965 seems to be randomly broken with shadows, and sometimes with render + // textures. Sometimes they hang with them (e.g. in terrain unit test). Just disable. + if( rendererString.find("965/963") != string::npos || rendererString.find("Broadwater") != string::npos ) + { + if( hasRenderToTexture ) + { + printf_console( "GL: Disabling render to texture on Intel card (buggy)\n" ); + hasRenderToTexture = false; + hasRenderToCubemap = false; + hasAutoMipMapGeneration = false; + for (int i = 0; i < kRTFormatCount; ++i) + supportsRenderTextureFormat[i] = false; + maxMRTs = 1; + } + } + } +#endif + +#if UNITY_LINUX + // Hardware shadow maps on spot light shadows seem to be weird, + // at least on gfx test agent (GeForce GTX 260 OpenGL 3.3 [3.3.0 NVIDIA 295.40]) + buggySpotNativeShadowMap = true; +#endif + +#if UNITY_WIN || UNITY_LINUX + if( isIntel ) + { + // Intel 9xx have lots of problems with shadows. Just disable them. + printf_console( "GL: disabling shadows on Intel 9xx (buggy)\n" ); + supportsRenderTextureFormat[kRTFormatDepth] = false; + hasRenderToCubemap = false; + hasAutoMipMapGeneration = false; + } +#endif + +#if UNITY_LINUX + if (isIntel) + { + printf_console ("GL: disabling framebuffer blit, antialiasing, SRGB on Intel\n"); + gl.hasFrameBufferBlit = false; + hasMultiSample = false; + hasSRGBReadWrite = false; + + } +#endif + + // S3 UniChrome does not have 3D textures, even if they say it's OpenGL 1.2. + // To be safe just disable them on all S3 cards that don't explicitly expose it. + if( (vendorString.find("S3 ") == 0) && !QueryExtensionGL("GL_EXT_texture3D") ) + { + printf_console( "GL: Disabling 3D textures because the card does not actually have them\n" ); + has3DTexture = false; + } + + + // Many Radeon drivers on windows are quite bad +#if UNITY_WIN + if( (isRadeon || (rendererString.find("FIREGL") != string::npos) || (rendererString.find("FireGL") != string::npos)) && (vendorString.find("ATI ") != string::npos) ) + { + // FireGL with version 2.0.5284 crashes when destroying render textures. The driver is + // from about year 2005. Disable RTs. + if( parsedDriverVersion && version <= 20 && buildVersion <= 5284 && rendererString.find("FireGL") != string::npos ) + { + hasRenderToTexture = hasRenderToCubemap = false; + for (int i = 0; i < kRTFormatCount; ++i) + supportsRenderTextureFormat[i] = false; + maxMRTs = 1; + printf_console( "GL: disabling render textures due to FireGL driver bugs\n" ); + } + + /* The issue description from Emil Persson <epersson@ati.com>: + + The problem is that the shaders are using constructs like this: + PARAM c[4] = { program.local[0..2], { 2 } }; + Older drivers didn't handle mixed declaration well. Are you using Cg to + compile the shaders? They switched to using mixed declarations quite a + while ago, which exposed the bug. If you revert to an older version of + the compiler (I think it was 1.3 that caused the problem, so try 1.2) + that should dodge the problem for 5.3. + <...> + It's not the range, but the mix of params and immediate values that + causes the problem. Both work fine separately, but if you put both in + the same array it's going to break. So what you can do is split it into + two arrays, one for program.local and one for immediate values. + PARAM c[4] = { program.local[0..2], { 2 } }; + becomes + PARAM c[3] = { program.local[0..2] }; + PARAM d[1] = { { 2 } }; + Then you'll have to replace all occurrences of c[3] with d[0] in the + shader. + */ + + // Even with latest drivers today (7.4, May 2007) render-to-cubemap + // does not quite work (faces inverted/flipped/etc.). Disable! + printf_console( "GL: disabling render-to-cubemap due to Radeon driver bugs\n" ); + hasRenderToCubemap = false; + + // Mip-mapped render textures seem to crash randomly, at least + // on MBP/Vista (GL version 2.0.6347). E.g. the mipmapped RT unit test scene crashes. + // Does work correctly on XP. + // + // The same also crashes on iMac Radeon HD 2600, Windows XP (GL version 2.0.6641). So we detect Vista + // or Radeon HD and disable. + if( winutils::GetWindowsVersion() >= winutils::kWindowsVista || rendererString.find("Radeon HD") != string::npos ) + { + printf_console( "GL: disabling mipmapped render textures due to Radeon driver bugs\n" ); + hasAutoMipMapGeneration = false; + } + } +#endif + + // Sanitize VRAM amount + if( videoMemoryMB < 32 ) { + printf_console("GL: VRAM amount suspiciously low (less than 32MB for fragment program card)\n"); + videoMemoryMB = 32; + } +} diff --git a/Runtime/GfxDevice/opengl/NullVBO.cpp b/Runtime/GfxDevice/opengl/NullVBO.cpp new file mode 100644 index 0000000..acc802f --- /dev/null +++ b/Runtime/GfxDevice/opengl/NullVBO.cpp @@ -0,0 +1,168 @@ +#include "UnityPrefix.h" +#include "NullVBO.h" +#include "UnityGL.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "ChannelsGL.h" + + +extern GLenum kTopologyGL[kPrimitiveTypeCount]; + + + +DynamicNullVBO::DynamicNullVBO() +: DynamicVBO() +, m_VBChunk(NULL) +, m_VBChunkSize(0) +, m_IBChunk(NULL) +, m_IBChunkSize(0) +{ +} + +DynamicNullVBO::~DynamicNullVBO () +{ + delete[] m_VBChunk; + delete[] m_IBChunk; +} + +void DynamicNullVBO::DrawChunk (const ChannelAssigns& channels) +{ + // just return if nothing to render + if( !m_LastChunkShaderChannelMask ) + return; + + Assert(m_LastChunkShaderChannelMask && m_LastChunkStride); + Assert(!m_LendedChunk); + + // setup VBO + UnbindVertexBuffersGL(); + ClearActiveChannelsGL(); + UInt32 targetMap = channels.GetTargetMap(); + for( int i = 0; i < kVertexCompCount; ++i ) + { + if( !( targetMap & (1<<i) ) ) + continue; + ShaderChannel src = channels.GetSourceForTarget( (VertexComponent)i ); + if( !( m_LastChunkShaderChannelMask & (1<<src) ) ) + continue; + + SetChannelDataGL( src, (VertexComponent)i, (UInt8*)m_BufferChannel[src], m_LastChunkStride ); + } + GfxDevice& device = GetRealGfxDevice(); + ActivateChannelsGL(); + device.BeforeDrawCall( false ); + + // draw + int primCount = 0; + if( m_LastRenderMode == kDrawTriangleStrip ) + { + Assert(m_LastChunkIndices == 0); + OGL_CALL(glDrawArrays( GL_TRIANGLE_STRIP, 0, m_LastChunkVertices )); + primCount = m_LastChunkVertices-2; + } + else if (m_LastRenderMode == kDrawQuads) + { + Assert(m_LastChunkIndices == 0); + OGL_CALL(glDrawArrays( GL_QUADS, 0, m_LastChunkVertices )); + primCount = m_LastChunkVertices/2; + } + else if (m_LastRenderMode == kDrawIndexedTriangleStrip) + { + DebugAssert(m_LastChunkIndices > 0); + OGL_CALL(glDrawElements( GL_TRIANGLE_STRIP, m_LastChunkIndices, GL_UNSIGNED_SHORT, m_IBChunk )); + primCount = m_LastChunkIndices-2; + } + else if (m_LastRenderMode == kDrawIndexedLines) + { + DebugAssert(m_LastChunkIndices > 0); + OGL_CALL(glDrawElements( GL_LINES, m_LastChunkIndices, GL_UNSIGNED_SHORT, m_IBChunk )); + primCount = m_LastChunkIndices/2; + } + else if (m_LastRenderMode == kDrawIndexedPoints) + { + DebugAssert(m_LastChunkIndices > 0); + OGL_CALL(glDrawElements( GL_POINTS, m_LastChunkIndices, GL_UNSIGNED_SHORT, m_IBChunk )); + primCount = m_LastChunkIndices; + } + else + { + DebugAssert(m_LastChunkIndices > 0); + OGL_CALL(glDrawElements( GL_TRIANGLES, m_LastChunkIndices, GL_UNSIGNED_SHORT, m_IBChunk )); + primCount = m_LastChunkIndices/3; + } + device.GetFrameStats().AddDrawCall (primCount, m_LastChunkVertices); +} + +bool DynamicNullVBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ) +{ + Assert( !m_LendedChunk ); + Assert( maxVertices < 65536 && maxIndices < 65536*3 ); + DebugAssert( outVB != NULL && maxVertices > 0 ); + DebugAssert( + (renderMode == kDrawIndexedQuads && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedPoints && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedLines && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangles && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangleStrip && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawTriangleStrip && (outIB == NULL && maxIndices == 0)) || + (renderMode == kDrawQuads && (outIB == NULL && maxIndices == 0))); + + m_LendedChunk = true; + m_LastChunkShaderChannelMask = shaderChannelMask; + m_LastRenderMode = renderMode; + if( maxVertices == 0 ) + maxVertices = 8; + + m_LastChunkStride = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( shaderChannelMask & (1<<i) ) + m_LastChunkStride += VBO::GetDefaultChannelByteSize(i); + } + + UInt32 vbCapacity = maxVertices * m_LastChunkStride; + if( vbCapacity > m_VBChunkSize ) + { + delete[] m_VBChunk; + m_VBChunk = new UInt8[ vbCapacity ]; + m_VBChunkSize = vbCapacity; + } + *outVB = m_VBChunk; + + const bool indexed = (renderMode != kDrawQuads) && (renderMode != kDrawTriangleStrip); + if( maxIndices && indexed) + { + UInt32 ibCapacity = maxIndices * kVBOIndexSize; + if( ibCapacity > m_IBChunkSize ) + { + delete[] m_IBChunk; + m_IBChunk = new UInt8[ ibCapacity ]; + m_IBChunkSize = ibCapacity; + } + *outIB = m_IBChunk; + } + + return true; +} + +void DynamicNullVBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ) +{ + Assert( m_LendedChunk ); + Assert( m_LastRenderMode == kDrawIndexedTriangleStrip || m_LastRenderMode == kDrawIndexedQuads || m_LastRenderMode == kDrawIndexedPoints || m_LastRenderMode == kDrawIndexedLines || actualIndices % 3 == 0 ); + m_LendedChunk = false; + + m_LastChunkVertices = actualVertices; + m_LastChunkIndices = actualIndices; + + const bool indexed = (m_LastRenderMode != kDrawQuads) && (m_LastRenderMode != kDrawTriangleStrip); + if( !actualVertices || (indexed && !actualIndices) ) { + m_LastChunkShaderChannelMask = 0; + return; + } + + UInt8* channelOffset = (UInt8*)m_VBChunk; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( m_LastChunkShaderChannelMask & (1<<i) ) { + m_BufferChannel[i] = channelOffset; + channelOffset += VBO::GetDefaultChannelByteSize(i); + } + } +} diff --git a/Runtime/GfxDevice/opengl/NullVBO.h b/Runtime/GfxDevice/opengl/NullVBO.h new file mode 100644 index 0000000..a916f5a --- /dev/null +++ b/Runtime/GfxDevice/opengl/NullVBO.h @@ -0,0 +1,27 @@ +#ifndef NULL_VBO_H +#define NULL_VBO_H + +#include "Runtime/Shaders/BufferedVBO.h" +#include "Configuration/UnityConfigure.h" + + +class DynamicNullVBO : public DynamicVBO { +public: + DynamicNullVBO(); + virtual ~DynamicNullVBO(); + + virtual bool GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ); + virtual void ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ); + virtual void DrawChunk (const ChannelAssigns& channels); + +private: + void* m_BufferChannel[kShaderChannelCount]; + + UInt8* m_VBChunk; + UInt32 m_VBChunkSize; + UInt8* m_IBChunk; + UInt32 m_IBChunkSize; +}; + + +#endif diff --git a/Runtime/GfxDevice/opengl/RenderTextureGL.cpp b/Runtime/GfxDevice/opengl/RenderTextureGL.cpp new file mode 100644 index 0000000..c20c3e5 --- /dev/null +++ b/Runtime/GfxDevice/opengl/RenderTextureGL.cpp @@ -0,0 +1,751 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "UnityGL.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "GLAssert.h" +#include "GLContext.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Graphics/RenderSurface.h" +#include "TexturesGL.h" +#include "TextureIdMapGL.h" + +#if UNITY_OSX +#include <OpenGL/OpenGL.h> +#elif UNITY_WIN +#include <windows.h> +#include "PlatformDependent/Win/wglext.h" +#elif UNITY_LINUX +#include <GL/glext.h> +#else +#error "Unknown platform" +#endif + +#define GL_RT_COMMON_GL 1 +#include "Runtime/GfxDevice/GLRTCommon.h" +#undef GL_RT_COMMON_GL + + +extern GLint gDefaultFBOGL = 0; + +// define to 1 to print lots of activity info +#define DEBUG_RENDER_TEXTURES 0 + + +struct RenderColorSurfaceGL : public RenderSurfaceBase +{ + GLuint m_ColorBuffer; + RenderTextureFormat format; + TextureDimension dim; +}; + +struct RenderDepthSurfaceGL : public RenderSurfaceBase +{ + GLuint m_DepthBuffer; + DepthBufferFormat depthFormat; +}; + +const unsigned long* GetGLTextureDimensionTable(); // GfxDeviceGL.cpp + + +static RenderColorSurfaceGL* s_ActiveColorTargets[kMaxSupportedRenderTargets]; +static int s_ActiveColorTargetCount = 0; +static int s_AttachedColorTargetCount = 0; +static RenderDepthSurfaceGL* s_ActiveDepthTarget = NULL; +static int s_ActiveMip = 0; +static CubemapFace s_ActiveFace = kCubeFaceUnknown; + +static const char* GetFBOStatusError( GLenum status ) +{ + Assert(status != GL_FRAMEBUFFER_COMPLETE_EXT); // should not be called when everything is ok... + switch( status ) + { + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: return "INCOMPLETE_ATTACHMENT"; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: return "INCOMPLETE_MISSING_ATTACHMENT"; + case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT: return "INCOMPLETE_DUPLICATE_ATTACHMENT"; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: return "INCOMPLETE_DIMENSIONS"; + case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: return "INCOMPLETE_FORMATS"; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: return "INCOMPLETE_DRAW_BUFFER"; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: return "INCOMPLETE_READ_BUFFER"; + case GL_FRAMEBUFFER_UNSUPPORTED_EXT: return "UNSUPPORTED"; + default: return "unknown error"; + } +} + +static void DetachPreviousColorTargets (int startIndex, int endIndex) +{ + // Detach color buffers from the attachments that were not touched this time + for (int i = startIndex; i < endIndex; ++i) + { + GLenum colorAttach = GL_COLOR_ATTACHMENT0_EXT + i; + + // Even though we were attaching a 2D texture, a cubemap face or a render buffer, + // we can detach either of them like a 2D texture. + glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, colorAttach, GL_TEXTURE_2D, 0, 0); + } +} + +bool SetRenderTargetGL (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, GLuint globalSharedFBO) +{ + RenderColorSurfaceGL* rcolorZero = reinterpret_cast<RenderColorSurfaceGL*>(colorHandles[0].object); + RenderDepthSurfaceGL* rdepth = reinterpret_cast<RenderDepthSurfaceGL*>( depthHandle.object ); + + #if DEBUG_RENDER_TEXTURES + printf_console( "RT: SetRenderTargetGL color=%i depth=%i mip=%i face=%i\n", + rcolorZero ? rcolorZero->textureID.m_ID : 0, + rdepth ? rdepth->textureID.m_ID : 0, + mipLevel, face ); + #endif + + // Exit if nothing to do + if (count == s_ActiveColorTargetCount && s_ActiveDepthTarget == rdepth && s_ActiveMip == mipLevel && s_ActiveFace == face) + { + bool colorsSame = true; + for (int i = 0; i < count; ++i) + { + if (s_ActiveColorTargets[i] != reinterpret_cast<RenderColorSurfaceGL*>(colorHandles[i].object)) + colorsSame = false; + } + if (colorsSame) + return false; + } + + Assert (gGraphicsCaps.hasRenderToTexture); + GetRealGfxDevice().GetFrameStats().AddRenderTextureChange(); // stats + + // cant mix default fbo and user fbo + Assert(colorHandles[0].IsValid() && depthHandle.IsValid()); + Assert(colorHandles[0].object->backBuffer == depthHandle.object->backBuffer); + + + if (!rcolorZero->backBuffer) + { + // color surfaces + glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, globalSharedFBO); + GLenum drawBuffers[kMaxSupportedRenderTargets]; + bool readBufferNone = false; + for (int i = 0; i < count; ++i) + { + GLenum colorAttach = GL_COLOR_ATTACHMENT0_EXT + i; + RenderColorSurfaceGL* rcolor = reinterpret_cast<RenderColorSurfaceGL*>(colorHandles[i].object); + Assert (rcolor->colorSurface); + if (rcolor->textureID.m_ID) + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: color buffer texture %i\n", rcolor->textureID.m_ID ); + #endif + drawBuffers[i] = colorAttach; + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(rcolor->textureID); + if (rcolor->dim == kTexDimCUBE) + { + glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, colorAttach, GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + clamp<int>(face,0,5), targetTex, mipLevel ); + } + else + { + glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, colorAttach, GL_TEXTURE_2D, targetTex, mipLevel ); + } + } + else + { + if (rcolor->m_ColorBuffer) + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: color buffer plain %i\n", rcolor->m_ColorBuffer ); + #endif + glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, colorAttach, GL_RENDERBUFFER_EXT, rcolor->m_ColorBuffer); + drawBuffers[i] = colorAttach; + } + else + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: color buffer none\n" ); + #endif + glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, colorAttach, GL_TEXTURE_2D, 0); + drawBuffers[i] = GL_NONE; + if (i == 0) + readBufferNone = true; + } + } + } + + DetachPreviousColorTargets (count, s_AttachedColorTargetCount); + s_AttachedColorTargetCount = count; + + if (count <= 1 || gGraphicsCaps.maxMRTs <= 1) + glDrawBuffer (drawBuffers[0]); + else + glDrawBuffersARB (count, drawBuffers); + glReadBuffer (readBufferNone ? GL_NONE : GL_COLOR_ATTACHMENT0_EXT); + + // depth surface + Assert (!rdepth->colorSurface); + bool bindDepthTexture = true; + if (gGraphicsCaps.gl.buggyPackedDepthStencil) + { + if (rcolorZero && rcolorZero->textureID.m_ID && rdepth->depthFormat == kDepthFormat24) + { + bindDepthTexture = false; + } + } + + if (rdepth->textureID.m_ID && bindDepthTexture) + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: depth buffer texture %i\n", rdepth->textureID.m_ID ); + #endif + + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(rdepth->textureID); + + glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, targetTex, 0); + if (gGraphicsCaps.hasRenderTargetStencil && rdepth->depthFormat == kDepthFormat24 && !gGraphicsCaps.gl.buggyPackedDepthStencil) + glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, targetTex, 0); + else + glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0); + } + else + { + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: depth buffer plain %i\n", rdepth->m_DepthBuffer ); + #endif + glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rdepth->m_DepthBuffer); + if (gGraphicsCaps.hasRenderTargetStencil && rdepth->depthFormat == kDepthFormat24) + glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rdepth->m_DepthBuffer); + else + glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0); + } + + #if GFX_DEVICE_VERIFY_ENABLE + GLenum status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) + { + std::string msg = Format("OpenGL failed to activate FBO: %s (color tex %i buf %i fmt %i) (depth tex %i buf %i fmt %i)", + GetFBOStatusError(status), + rcolorZero->textureID.m_ID, + rcolorZero->m_ColorBuffer, + rcolorZero->format, + rdepth->textureID.m_ID, + rdepth->m_DepthBuffer, + rdepth->depthFormat + ); + AssertString (msg); + } + #endif + } + else + { + Assert (rcolorZero->backBuffer && rdepth->backBuffer); // OpenGL can't mix FBO and native window at once + #if DEBUG_RENDER_TEXTURES + printf_console( " RT: backbuffer\n" ); + #endif + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, gDefaultFBOGL ); + } + + // If we previously had a mip-mapped render texture, generate mip levels + // for it now. Just using GL_GENERATE_MIPMAP does not work on OS X, and the explicit + // should probably be faster. + if (s_ActiveColorTargets[0] && + (s_ActiveColorTargets[0]->flags & kSurfaceCreateMipmap) && + (s_ActiveColorTargets[0]->flags & kSurfaceCreateAutoGenMips)) + { + const int textureTarget = GetGLTextureDimensionTable()[s_ActiveColorTargets[0]->dim]; + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, s_ActiveColorTargets[0]->textureID, s_ActiveColorTargets[0]->dim, std::numeric_limits<float>::infinity()); + glGenerateMipmapEXT(textureTarget); + } + + for (int i = 0; i < count; ++i) + s_ActiveColorTargets[i] = reinterpret_cast<RenderColorSurfaceGL*>(colorHandles[i].object); + s_ActiveColorTargetCount = count; + s_ActiveDepthTarget = rdepth; + s_ActiveMip = mipLevel; + s_ActiveFace = face; + return true; +} + +RenderSurfaceHandle GetActiveRenderColorSurfaceGL(int index) +{ + return RenderSurfaceHandle(s_ActiveColorTargets[index]); +} +RenderSurfaceHandle GetActiveRenderDepthSurfaceGL() +{ + return RenderSurfaceHandle(s_ActiveDepthTarget); +} + +bool IsActiveRenderTargetWithColorGL() +{ + return !s_ActiveColorTargets[0] || s_ActiveColorTargets[0]->backBuffer || !IsDepthRTFormat (s_ActiveColorTargets[0]->format); +} + +static int GetBytesFromGLFormat( GLenum fmt ) +{ + switch(fmt) { + case 0: return 0; + case GL_RGBA4: return 2; + case GL_RGB5: return 2; + case GL_RGBA8: return 4; + case GL_DEPTH_COMPONENT16: return 2; + case GL_DEPTH_COMPONENT24: return 4; // all hardware uses 4 bytes for 24 bit depth + case GL_DEPTH_COMPONENT32: return 4; + case GL_DEPTH24_STENCIL8_EXT: return 4; + default: + AssertString("unknown GL format"); + return 0; + } +} + +static void CreateFBORenderColorSurfaceGL (RenderColorSurfaceGL& rs) +{ + int textureTarget = GetGLTextureDimensionTable()[rs.dim]; + + if( !IsDepthRTFormat(rs.format) ) + { + GLenum internalFormat = (rs.flags & kSurfaceCreateSRGB) ? RTColorInternalFormatSRGBGL(rs.format) : RTColorInternalFormatGL(rs.format); + GLenum textureFormat = RTColorTextureFormatGL(rs.format); + GLenum textureType = RTColorTextureTypeGL(rs.format); + + // Create texture to render for color + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, rs.textureID, rs.dim, std::numeric_limits<float>::infinity()); + if (rs.dim == kTexDimCUBE) + { + // cubemap: initialize all faces + for( int f = 0; f < 6; ++f ) + { + glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + f, 0, internalFormat, rs.width, rs.height, 0, textureFormat, textureType, NULL ); + } + if (rs.flags & kSurfaceCreateMipmap) + { + // establish mip map chain if needed + glGenerateMipmapEXT (textureTarget); + } + } + else if (!rs.textureID.m_ID) + { + // MSAA render buffer + glGenRenderbuffersEXT( 1, &rs.m_ColorBuffer ); + glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rs.m_ColorBuffer ); + for (int samples = std::min(rs.samples, gGraphicsCaps.gl.maxSamples); samples >= 1; samples--) + { + if (samples > 1) + { + glRenderbufferStorageMultisampleEXT( GL_RENDERBUFFER_EXT, samples, internalFormat, rs.width, rs.height ); + if (glGetError() == GL_NO_ERROR) + break; + } + else + { + glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, internalFormat, rs.width, rs.height ); + GLAssert(); + } + } + } + else + { + // regular texture: initialize + glTexImage2D( textureTarget, 0, internalFormat, rs.width, rs.height, 0, textureFormat, textureType, NULL ); + if (rs.flags & kSurfaceCreateMipmap) + { + // establish mip map chain if needed + glGenerateMipmapEXT (textureTarget); + } + } + } + else + { + // Depth render texture + // We're prefer to just have no color buffer, but some GL implementations don't like that + // (PPC NVIDIA drivers on OS X). So if we have that, we try color buffers starting from + // low-memory formats. + if (gGraphicsCaps.gl.forceColorBufferWithDepthFBO) + { + glGenRenderbuffersEXT( 1, &rs.m_ColorBuffer ); + glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rs.m_ColorBuffer ); + glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_RGBA8, rs.width, rs.height ); + } + } +} + + +static void CreateFBORenderDepthSurfaceGL (RenderDepthSurfaceGL& rs) +{ + int textureTarget = GetGLTextureDimensionTable()[kTexDim2D]; + + GLenum depthFormat; + GLenum genericFormat; + GLenum typeFormat; + if (rs.depthFormat == kDepthFormat16) + { + depthFormat = GL_DEPTH_COMPONENT16; + genericFormat = GL_DEPTH_COMPONENT; + typeFormat = GL_UNSIGNED_BYTE; + } + else if (gGraphicsCaps.hasRenderTargetStencil && rs.depthFormat == kDepthFormat24) + { + depthFormat = GL_DEPTH24_STENCIL8_EXT; + genericFormat = GL_DEPTH_STENCIL_EXT; + typeFormat = GL_UNSIGNED_INT_24_8_EXT; + } + else + { + depthFormat = GL_DEPTH_COMPONENT24; + genericFormat = GL_DEPTH_COMPONENT; + typeFormat = GL_UNSIGNED_BYTE; + } + if (depthFormat == GL_DEPTH_COMPONENT16 && gGraphicsCaps.gl.force24DepthForFBO) + depthFormat = GL_DEPTH_COMPONENT24; + if (!rs.textureID.m_ID) + { + // create just depth surface + if( rs.depthFormat != kDepthFormatNone ) + { + glGenRenderbuffersEXT( 1, &rs.m_DepthBuffer ); + glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rs.m_DepthBuffer ); + for (int samples = std::min(rs.samples, gGraphicsCaps.gl.maxSamples); samples >= 1; samples--) + { + if (samples > 1) + { + glRenderbufferStorageMultisampleEXT( GL_RENDERBUFFER_EXT, samples, depthFormat, rs.width, rs.height ); + if (glGetError() == GL_NO_ERROR) + break; + } + else + { + glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, depthFormat, rs.width, rs.height ); + GLAssert(); + } + } + } + } + else + { + // create depth texture + + // If packed depth stencil is buggy as a texture, create just the depth texture. We still need packed depth + // stencil for the non-texture case, so do not do this above in the format selection. + if (gGraphicsCaps.gl.buggyPackedDepthStencil && genericFormat == GL_DEPTH_STENCIL_EXT) + { + depthFormat = GL_DEPTH_COMPONENT24; + genericFormat = GL_DEPTH_COMPONENT; + typeFormat = GL_UNSIGNED_BYTE; + } + + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, rs.textureID, kTexDim2D, std::numeric_limits<float>::infinity()); + glTexImage2D( textureTarget, 0, depthFormat, rs.width, rs.height, 0, genericFormat, typeFormat, NULL ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + if (rs.flags & kSurfaceCreateShadowmap) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); + } + } +} + + +RenderSurfaceHandle CreateRenderColorSurfaceGL (TextureID textureID, int width, int height, int samples, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, GLuint globalSharedFBO) +{ + RenderSurfaceHandle rsHandle; + + Assert(GetMainGraphicsContext().IsValid()); + + if( !gGraphicsCaps.hasRenderToTexture ) + return rsHandle; + if( !gGraphicsCaps.supportsRenderTextureFormat[format] ) + return rsHandle; + + RenderColorSurfaceGL* rs = new RenderColorSurfaceGL(); + RenderSurfaceBase_InitColor(*rs); + rs->width = width; + rs->height = height; + rs->samples = samples; + rs->format = format; + rs->textureID = textureID; + rs->dim = dim; + rs->flags = createFlags; + rs->m_ColorBuffer = 0; + + if(textureID.m_ID) + TextureIdMapGL_QueryOrCreate(textureID); + + #if DEBUG_RENDER_TEXTURES + printf_console ("RT: create color id=%i, %ix%i, flags=%i, fmt=%i\n", textureID.m_ID, width, height, createFlags, format); + #endif + + CreateFBORenderColorSurfaceGL (*rs); + + rsHandle.object = rs; + return rsHandle; +} + + +RenderSurfaceHandle CreateRenderDepthSurfaceGL (TextureID textureID, int width, int height, int samples, UInt32 createFlags, DepthBufferFormat depthFormat, GLuint globalSharedFBO) +{ + RenderSurfaceHandle rsHandle; + + Assert(GetMainGraphicsContext().IsValid()); + + if( !gGraphicsCaps.hasRenderToTexture ) + return rsHandle; + + RenderDepthSurfaceGL* rs = new RenderDepthSurfaceGL; + RenderSurfaceBase_InitDepth(*rs); + rs->width = width; + rs->height = height; + rs->samples = samples; + rs->depthFormat = depthFormat; + rs->textureID = textureID; + rs->flags = createFlags; + + rs->m_DepthBuffer = 0; + + #if DEBUG_RENDER_TEXTURES + printf_console ("RT: create depth id=%i, %ix%i, d=%i flags=%i\n", textureID.m_ID, width, height, depthFormat, createFlags); + #endif + + if(textureID.m_ID) + TextureIdMapGL_QueryOrCreate(textureID); + + CreateFBORenderDepthSurfaceGL (*rs); + + rsHandle.object = rs; + return rsHandle; +} + + +static void InternalDestroyRenderSurfaceGL (RenderSurfaceBase* rs) +{ + Assert(rs); + + #if DEBUG_RENDER_TEXTURES + printf_console( "RT: destroy id=%i, %ix%i\n", rs->textureID.m_ID, rs->width, rs->height ); + #endif + + if (rs->textureID.m_ID) + GetRealGfxDevice().DeleteTexture( rs->textureID ); + GLAssert (); + + RenderSurfaceHandle defaultColor = GetRealGfxDevice().GetBackBufferColorSurface(); + RenderSurfaceHandle defaultDepth = GetRealGfxDevice().GetBackBufferDepthSurface(); + + + if (s_ActiveDepthTarget == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + SetRenderTargetGL (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, gDefaultFBOGL); + } + for (int i = 0; i < s_ActiveColorTargetCount; ++i) + { + if (s_ActiveColorTargets[i] == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + SetRenderTargetGL (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, gDefaultFBOGL); + } + } + if (rs->colorSurface) + { + RenderColorSurfaceGL* rsc = static_cast<RenderColorSurfaceGL*>(rs); + if( rsc->m_ColorBuffer ) + glDeleteRenderbuffersEXT( 1, &rsc->m_ColorBuffer ); + } + else + { + RenderDepthSurfaceGL* rsd = static_cast<RenderDepthSurfaceGL*>(rs); + if( rsd->m_DepthBuffer ) + glDeleteRenderbuffersEXT( 1, &rsd->m_DepthBuffer ); + } +} + +static void AssertFBOIsCurrentFBO (GLuint currentFBO) +{ +#if !UNITY_RELEASE + // verify that globalSharedFBO is currently bound, + // don't query OpenGL in release mode though + GLint realCurrentFBO; + glGetIntegerv (GL_FRAMEBUFFER_BINDING_EXT, &realCurrentFBO); + DebugAssert (realCurrentFBO == currentFBO); +#endif +} + +void ResolveColorSurfaceGL (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle, GLuint globalSharedFBO, GLuint helperFBO) +{ + Assert (srcHandle.IsValid()); + Assert (dstHandle.IsValid()); + RenderColorSurfaceGL* src = reinterpret_cast<RenderColorSurfaceGL*>(srcHandle.object); + RenderColorSurfaceGL* dst = reinterpret_cast<RenderColorSurfaceGL*>(dstHandle.object); + if (!src->colorSurface || !dst->colorSurface) + { + WarningString("RenderTexture: Resolving non-color surfaces."); + return; + } + + GLuint targetTex = (GLuint)TextureIdMapGL_QueryOrCreate(dst->textureID); + if (!src->m_ColorBuffer || !targetTex) + { + WarningString("RenderTexture: Resolving NULL buffers."); + return; + } + + DebugAssert(gGraphicsCaps.gl.hasFrameBufferBlit); + AssertFBOIsCurrentFBO(globalSharedFBO); + GLuint currentFBO = globalSharedFBO; + + // attach source render buffer + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, currentFBO ); + glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, src->m_ColorBuffer ); + + // attach destination texture + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, helperFBO ); + glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, targetTex, 0 ); + + // perform blit + glBindFramebufferEXT( GL_READ_FRAMEBUFFER_EXT, currentFBO ); + glBindFramebufferEXT( GL_DRAW_FRAMEBUFFER_EXT, helperFBO ); + + // set read & draw buffers to be from FBO color attachemnts + glReadBuffer (GL_COLOR_ATTACHMENT0_EXT); + glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT); + + glBlitFramebufferEXT( 0, 0, src->width, src->height, 0, 0, dst->width, dst->height, GL_COLOR_BUFFER_BIT, GL_NEAREST ); + GLAssert(); + + // clean up helperFBO + glFramebufferTexture2DEXT( GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0 ); + + // restore the previously bound FBO + glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, currentFBO); +} + +void DestroyRenderSurfaceGL (RenderSurfaceHandle& rsHandle) +{ + if(rsHandle.object->backBuffer) + return; + + RenderSurfaceBase* rs = rsHandle.object; + InternalDestroyRenderSurfaceGL (rs); + delete rs; + rsHandle.object = NULL; +} + +void ResolveDepthIntoTextureGL (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle, GLuint globalSharedFBO, GLuint helperFBO) +{ + RenderDepthSurfaceGL* rdepth = reinterpret_cast<RenderDepthSurfaceGL*>(depthHandle.object); + + // use the full size of the depth buffer, sub-rects are not needed and might not work on some hardware + GLint x = 0; + GLint y = 0; + GLint width = rdepth->width; + GLint height = rdepth->height; + + if (gGraphicsCaps.gl.hasFrameBufferBlit) + { + AssertFBOIsCurrentFBO (globalSharedFBO); + GLuint currentFBO = globalSharedFBO; + + // bind helper FBO + glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, helperFBO); + + // attach the color buffer if needed (see gGraphicsCaps.gl.forceColorBufferWithDepthFBO) + RenderColorSurfaceGL* rcolor = reinterpret_cast<RenderColorSurfaceGL*>(colorHandle.object); + const bool attachColorBuffer = (!rcolor->textureID.m_ID && rcolor->m_ColorBuffer); + + if (attachColorBuffer) + glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rcolor->m_ColorBuffer); + + // attach the depth buffer + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(rdepth->textureID); + glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, targetTex, 0); + glDrawBuffer (GL_NONE); + glReadBuffer (GL_NONE); + + // check the FBO + GLenum framebufferStatus = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); + AssertMsg (framebufferStatus == GL_FRAMEBUFFER_COMPLETE_EXT, GetFBOStatusError (framebufferStatus)); + + // blit + glBindFramebufferEXT (GL_READ_FRAMEBUFFER_EXT, currentFBO); + glBindFramebufferEXT (GL_DRAW_FRAMEBUFFER_EXT, helperFBO); + glBlitFramebufferEXT (x, y, x + width, y + height, x, y, x + width, y + height, GL_DEPTH_BUFFER_BIT, GL_NEAREST); + + // clean up helperFBO + glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0); + if (attachColorBuffer) + glFramebufferRenderbufferEXT (GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, 0); + + // restore the previously bound FBO + glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, currentFBO); + } + else + { + GetRealGfxDevice ().SetTexture (kShaderFragment, 0, 0, rdepth->textureID, kTexDim2D, std::numeric_limits<float>::infinity ()); + glCopyTexSubImage2D (GL_TEXTURE_2D, 0, x, y, x, y, width, height); + } + GLAssert(); +} + +void GrabIntoRenderTextureGL (RenderSurfaceHandle rsHandle, int x, int y, int width, int height, GLuint helperFBO) +{ + if( !rsHandle.IsValid() ) + return; + + RenderColorSurfaceGL* rs = reinterpret_cast<RenderColorSurfaceGL*>( rsHandle.object ); + + // If we are not using the back buffer, we cannot copy using glTexSubImage2D + // when we have a proxy FBO with FSAA. This also affects Safari with + // the CoreAnimation drawing model. + // So, instead we blit from the proxy FBO to a helper FBO with our output texture attached. + // (Related issue in GLReadPixelsWrapper()) + GLint curFBO; + glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &curFBO); + if (gDefaultFBOGL != 0 && gDefaultFBOGL == curFBO && gGraphicsCaps.gl.hasFrameBufferBlit) + { + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(rs->textureID); + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, helperFBO); + glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, targetTex, 0 ); + + glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, gDefaultFBOGL); + glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, helperFBO); + + // Ensure that color0 is always set here, + // because we attach to color0 when setting up the FBO for scaled fullscreen mode + glReadBuffer (GL_COLOR_ATTACHMENT0_EXT); + glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT); + + glBlitFramebufferEXT(x, y, x+width, y+height, x, y, x+width, y+height, GL_COLOR_BUFFER_BIT, GL_NEAREST); + + // clean up helperFBO + glFramebufferTexture2DEXT (GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0 ); + + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, curFBO ); + } + else + { + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, rs->textureID, kTexDim2D, std::numeric_limits<float>::infinity()); + glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, x, y, width, height); + } + GLAssert (); +} + + +RenderSurfaceBase* CreateBackBufferColorSurfaceGL() +{ + RenderColorSurfaceGL* rs = new RenderColorSurfaceGL(); + ::memset(rs, 0x00, sizeof(RenderColorSurfaceGL)); + RenderSurfaceBase_InitColor(*rs); + rs->backBuffer = true; + + return rs; +} +RenderSurfaceBase* CreateBackBufferDepthSurfaceGL() +{ + RenderDepthSurfaceGL* rs = new RenderDepthSurfaceGL(); + ::memset(rs, 0x00, sizeof(RenderDepthSurfaceGL)); + RenderSurfaceBase_InitDepth(*rs); + rs->backBuffer = true; + + return rs; +} + diff --git a/Runtime/GfxDevice/opengl/TextureIdMapGL.h b/Runtime/GfxDevice/opengl/TextureIdMapGL.h new file mode 100644 index 0000000..3781901 --- /dev/null +++ b/Runtime/GfxDevice/opengl/TextureIdMapGL.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/TextureIdMap.h" + +inline GLuint TextureIdMapGL_QueryOrCreate(TextureID texid) +{ + GLuint ret = (GLuint)TextureIdMap::QueryNativeTexture(texid); + if(ret == 0) + { + glGenTextures(1, &ret); + TextureIdMap::UpdateTexture(texid, ret); + } + + return ret; +} diff --git a/Runtime/GfxDevice/opengl/TexturesGL.cpp b/Runtime/GfxDevice/opengl/TexturesGL.cpp new file mode 100644 index 0000000..8d79219 --- /dev/null +++ b/Runtime/GfxDevice/opengl/TexturesGL.cpp @@ -0,0 +1,494 @@ +#include "UnityPrefix.h" +#include "TexturesGL.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Utilities/BitUtility.h" +#include "Runtime/Graphics/S3Decompression.h" +#include "UnityGL.h" +#include "GLAssert.h" +#include "TextureIdMapGL.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/VramLimits.h" +#include "Runtime/GfxDevice/TextureUploadUtils.h" + + +// define to 1 to print lots of texture creation/destroy info +#define DEBUG_GL_TEXTURE 0 + +static inline bool SupportsS3Compression () { return gGraphicsCaps.hasS3TCCompression; } + +const static int kTextureFormatTable[kTexFormatPCCount*4] = +{ + // internal format, internal format sRGB, input format, datatype + 0, 0, 0, 0, + GL_ALPHA, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, // Alpha8 + GL_RGBA, GL_RGBA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, // ARGB4444 + GL_RGB, GL_SRGB8_EXT, GL_RGB, GL_UNSIGNED_BYTE, // RGB24 + GL_RGBA, GL_SRGB8_ALPHA8_EXT, GL_RGBA, GL_UNSIGNED_BYTE, // RGBA32 +#if UNITY_BIG_ENDIAN + GL_RGBA, GL_SRGB8_ALPHA8_EXT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, // ARGB32 +#else + GL_RGBA, GL_SRGB8_ALPHA8_EXT, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, // ARGB32 +#endif + 0, 0, 0, 0, // ARGBFloat + GL_RGB, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, // RGB565 ///////@TODO: What to do with 16 bit textures????? + GL_RGB, GL_SRGB8_EXT, GL_BGR, GL_UNSIGNED_BYTE, // BGR24 + GL_ALPHA16, GL_ALPHA16, GL_ALPHA, GL_UNSIGNED_SHORT, // AlphaLum16 + GL_COMPRESSED_RGB_S3TC_DXT1_EXT,GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, -1, -1, // DXT1 + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, -1, -1,// DXT3 + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, -1, -1,// DXT5 + GL_RGBA, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, // RGBA4444 +}; + + +static void GetUncompressedTextureFormat (int inFormat, bool sRGB, int* internalFormat, int* inputFormat, int* dataType) +{ + DebugAssertIf( IsAnyCompressedTextureFormat(inFormat) ); + *internalFormat = kTextureFormatTable[inFormat*4+(sRGB ? 1 : 0)]; + *inputFormat = kTextureFormatTable[inFormat*4+2]; + *dataType = kTextureFormatTable[inFormat*4+3]; +} + +static void GetCompressedTextureFormat (int inFormat, bool sRGB, int width, int height, int* internalFormat, int* size) +{ + *internalFormat = kTextureFormatTable[inFormat*4+(sRGB ? 1 : 0)]; + switch (inFormat) + { + case kTexFormatDXT1: + case kTexFormatATC_RGB4: + *size = ((width + 3) / 4) * ((height + 3) / 4) * 8; + break; + case kTexFormatDXT3: + case kTexFormatDXT5: + case kTexFormatATC_RGBA8: + *size = ((width + 3) / 4) * ((height + 3) / 4) * 16; + break; + case kTexFormatETC_RGB4: + *size = 8 * ((width+3)>>2) * ((height+3)>>2); // 8 bytes per 4x4 block + break; + default: + Assert(false && "Texture is not compressed"); + } +} + +#if THREADED_LOADING_DEBUG +float totalTextureUploadTime = 0.0F; +double GetTimeSinceStartup(); +#endif + + + + +void UploadTexture2DGL( + TextureID tid, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureUsageMode usageMode, TextureColorSpace colorSpace) +{ +#if THREADED_LOADING_DEBUG + double begin = GetTimeSinceStartup(); +#endif + + AssertIf( srcData == NULL ); + AssertIf( (!IsPowerOfTwo(width) || !IsPowerOfTwo(height)) && !IsNPOTTextureAllowed(mipCount > 1) ); + if( dimension != kTexDim2D ) + { + ErrorString( "Incorrect texture dimension!" ); + return; + } + + bool uploadIsCompressed, decompressOnTheFly; + HandleFormatDecompression (format, &usageMode, colorSpace, &uploadIsCompressed, &decompressOnTheFly); + + TextureFormat uploadFormat; + if( decompressOnTheFly ) + { + uploadFormat = kTexFormatRGBA32; + uploadIsCompressed = false; + } + else + { + uploadFormat = format; + + if (usageMode == kTexUsageLightmapDoubleLDR || usageMode == kTexUsageNormalmapPlain) + { + // make sure we have a format with alpha + uploadFormat = kTexFormatRGBA32; + } + + uploadIsCompressed = IsAnyCompressedTextureFormat( format ); + } + + int baseLevel, maxLevel, texWidth, texHeight; + size_t textureSize; + SkipLevelsForMasterTextureLimit (masterTextureLimit, format, uploadFormat, mipCount, uploadIsCompressed, &srcData, &width, &height, &baseLevel, &maxLevel, &texWidth, &texHeight, &textureSize); + + if (!glIsTexture(tid.m_ID)) + uploadFlags |= GfxDevice::kUploadTextureDontUseSubImage; + +#if DEBUG_GL_TEXTURE + printf_console( "GLDebug texture: upload %i (%ix%i). Unity format: %d\n", tid, texWidth, texHeight ,format ); +#endif + GLAssert (); + REGISTER_EXTERNAL_GFX_DEALLOCATION(tid.m_ID); + + TextureIdMapGL_QueryOrCreate(tid); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, tid, dimension, std::numeric_limits<float>::infinity()); + + glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + // glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE); + + UInt8* decompressBuffer = NULL; + UInt8* tempBuffer = NULL; + UInt8* scaleBuffer = NULL; + + int bufferPitch; + + int internalFormat = 0, datatype = 0, inputFormat = 0, size = 0; + int uploadedSize = 0; + for( int level = baseLevel; level <= maxLevel; ++level ) + { + UInt8* feedSourceData; + const int uploadLevel = level-baseLevel; + + if( decompressOnTheFly ) + { + ConvertCompressedTextureUpload (width, height, format, srcData, decompressBuffer, bufferPitch, usageMode, colorSpace, level); + feedSourceData = decompressBuffer; + } + // Allocate temporary memory and swizzle texture + else if (uploadFormat != format || usageMode != kTexUsageNone) + { + InitImageBuffer (width, height, decompressBuffer, uploadFormat); + bufferPitch = GetRowBytesFromWidthAndFormat(width, uploadFormat); + feedSourceData = decompressBuffer; + + prcore::Surface srcSurface (width, height, GetRowBytesFromWidthAndFormat (width, format), GetProphecyPixelFormat(format), srcData); + prcore::Surface dstSurface (width, height, GetRowBytesFromWidthAndFormat (width, uploadFormat), GetProphecyPixelFormat(uploadFormat), feedSourceData); + + if (!ConvertUncompressedTextureUpload(srcSurface, dstSurface, prcore::Surface::BLIT_COPY, uploadFormat, usageMode, colorSpace, width, height, feedSourceData, bufferPitch, GetProphecyPixelFormat(uploadFormat), tempBuffer, bufferPitch)) + { + dstSurface.BlitImage( srcSurface, prcore::Surface::BLIT_COPY ); + } + } + // Just feed the data + else + { + feedSourceData = srcData; + } + + // Don't use SubImage when uploading smaller than 4*4 compressed texture + if( uploadIsCompressed && (texWidth < 4 || texHeight < 4) ) + uploadFlags |= GfxDevice::kUploadTextureDontUseSubImage; + + // Now, if we're uploading non-mipmapped texture that is too large, the actual + // data has to be downscaled. + UInt8* feedRealData = feedSourceData; + if( !uploadIsCompressed && (width != texWidth || height != texHeight) ) { + if( !scaleBuffer ) + scaleBuffer = new UInt8[CalculateImageSize( texWidth, texHeight, uploadFormat )]; + feedRealData = scaleBuffer; + prcore::Surface srcSurface( width, height, GetRowBytesFromWidthAndFormat(width,uploadFormat), GetProphecyPixelFormat(uploadFormat), feedSourceData ); + prcore::Surface dstSurface( texWidth, texHeight, GetRowBytesFromWidthAndFormat(texWidth,uploadFormat), GetProphecyPixelFormat(uploadFormat), feedRealData ); + dstSurface.BlitImage( srcSurface, prcore::Surface::BLIT_SCALE ); + } + + // Complete texture image + if (uploadFlags & GfxDevice::kUploadTextureDontUseSubImage) + { + if (uploadIsCompressed) + { + GetCompressedTextureFormat (uploadFormat, colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB, texWidth, texHeight, &internalFormat, &size); +#if DEBUG_GL_TEXTURE + printf_console( "GLDebug texture: glCompressedTexImage2DARB: level=%i ifmt=%i width=%i height=%i size=%i data=%x\n", uploadLevel, internalFormat, texWidth, texHeight, size, (UInt32)feedRealData ); +#endif + glCompressedTexImage2DARB (GL_TEXTURE_2D, uploadLevel, internalFormat, texWidth, texHeight, 0, size, feedRealData); + } + else + { + GetUncompressedTextureFormat (uploadFormat, colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB, &internalFormat, &inputFormat, &datatype); +#if DEBUG_GL_TEXTURE + printf_console( "GLDebug texture: glTexImage2D: level=%i ifmt=%i width=%i height=%i fmt=%i type=%i data=%x\n", uploadLevel, internalFormat, texWidth, texHeight, inputFormat,datatype, (UInt32)feedRealData ); +#endif + glTexImage2D (GL_TEXTURE_2D, uploadLevel, internalFormat, texWidth, texHeight, 0, inputFormat, datatype, feedRealData); + } + } + // Upload texture with subimage + else + { + if (uploadIsCompressed) + { + GetCompressedTextureFormat (uploadFormat, colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB, texWidth, texHeight, &internalFormat, &size); +#if DEBUG_GL_TEXTURE + printf_console( "GLDebug texture: glCompressedTexSubImage2DARB: level=%i width=%i height=%i fmt=%i size=%i data=%x\n", uploadLevel, texWidth, texHeight, internalFormat, size, (UInt32)feedRealData ); +#endif + glCompressedTexSubImage2DARB (GL_TEXTURE_2D, uploadLevel, 0, 0, texWidth, texHeight, internalFormat, size, feedRealData); + } + else + { + GetUncompressedTextureFormat (uploadFormat, colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB, &internalFormat, &inputFormat, &datatype); +#if DEBUG_GL_TEXTURE + printf_console( "GLDebug texture: glTexSubImage2D: level=%i width=%i height=%i fmt=%i type=%i data=%x\n", uploadLevel, texWidth, texHeight, inputFormat,datatype, (UInt32)feedRealData ); +#endif + glTexSubImage2D (GL_TEXTURE_2D, uploadLevel, 0, 0, texWidth, texHeight, inputFormat, datatype, feedRealData); + } + } + uploadedSize += CalculateImageSize( texWidth, texHeight, uploadFormat ); + // Go to next mip level + AssertIf( width == 1 && height == 1 && level != maxLevel ); + AdvanceToNextMipLevel (format, srcData, width, height, texWidth, texHeight); + } + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(tid.m_ID,uploadedSize,tid.m_ID); + AssertIf( baseLevel > maxLevel ); + + GLAssert (); + + delete[] decompressBuffer; + delete[] tempBuffer; + delete[] scaleBuffer; + + // glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE); + +#if THREADED_LOADING_DEBUG + totalTextureUploadTime += GetTimeSinceStartup() - begin; + printf_console("Total Texture upload time %f\n", totalTextureUploadTime); +#endif +} + + +void UploadTextureSubData2DGL( + TextureID tid, UInt8* srcData, + int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + AssertIf( IsAnyCompressedTextureFormat( format ) ); + + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(tid); + + Assert(targetTex != 0); + if(targetTex == 0) + return; + + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, tid, kTexDim2D, std::numeric_limits<float>::infinity()); + + TextureFormat uploadFormat = format; + + UInt8* decompressBuffer = NULL; + + UInt8* feedData = srcData; + // Allocate temporary memory and swizzle texture + if( uploadFormat != format ) + { + int decompressedSize = CalculateImageSize (width, height, uploadFormat); + if (decompressBuffer == NULL) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + + ImageReference src (width, height, GetRowBytesFromWidthAndFormat (width, format), format, srcData); + ImageReference dst (width, height, GetRowBytesFromWidthAndFormat (width, uploadFormat), uploadFormat, feedData); + dst.BlitImage( src ); + } + + glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + int internalFormat, datatype, inputFormat; + GetUncompressedTextureFormat (uploadFormat, colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB, &internalFormat, &inputFormat, &datatype); + glTexSubImage2D( GL_TEXTURE_2D, mipLevel, x, y, width, height, inputFormat, datatype, feedData ); + + GLAssert (); + + if( decompressBuffer ) + delete[] decompressBuffer; +} + + +void UploadTextureCubeGL( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + if (!glIsTexture(tid.m_ID)) + uploadFlags |= GfxDevice::kUploadTextureDontUseSubImage; + REGISTER_EXTERNAL_GFX_DEALLOCATION(tid.m_ID); + + TextureIdMapGL_QueryOrCreate(tid); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, tid, kTexDimCUBE, std::numeric_limits<float>::infinity()); + + glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + // We have a compressed format but the hardware doesnt support it. + // - setup format to be uncompressed + // - dont use client storage (we are using temporary memory to store the texture) + TextureFormat uploadFormat; + bool uploadIsCompressed; + const bool decompressOnTheFly = IsAnyCompressedTextureFormat(format) && !gGraphicsCaps.hasS3TCCompression; + if( decompressOnTheFly ) + { + uploadFormat = kTexFormatRGBA32; + uploadIsCompressed = false; + } + else + { + uploadFormat = format; + uploadIsCompressed = IsAnyCompressedTextureFormat( format ); + } + + UInt8* decompressBuffer = NULL; + + const GLenum faces[6] = + { + GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, + GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, + GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, + GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB + }; + + int maxLevel = mipCount - 1; + int uploadSize = 0; + for (int face=0;face<6;face++) + { + int mipSize = size; + UInt8* data = srcData + face * faceDataSize; + int internalFormat = 0, datatype = 0, inputFormat = 0, size = 0; + + for( int level=0;level<=maxLevel;level++ ) + { + UInt8* feedData; + + // Allocate temporary memory and decompress texture + if( decompressOnTheFly ) + { + int dstSize = std::max( mipSize, 4 ); + int decompressedSize = CalculateImageSize( dstSize, dstSize, uploadFormat ); + if( decompressBuffer == NULL ) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + + DecompressNativeTextureFormat( format, mipSize, mipSize, (UInt32*)data, dstSize, dstSize, (UInt32*)feedData ); + } + // Allocate temporary memory and swizzle texture + else if( uploadFormat != format ) + { + int decompressedSize = CalculateImageSize (mipSize, mipSize, uploadFormat); + if (decompressBuffer == NULL) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + + ImageReference src (mipSize, mipSize, GetRowBytesFromWidthAndFormat (mipSize, format), format, data); + ImageReference dst (mipSize, mipSize, GetRowBytesFromWidthAndFormat (mipSize, uploadFormat), uploadFormat, feedData); + dst.BlitImage( src ); + } + // Just feed the data + else + { + feedData = data; + } + + // Upload + if( uploadIsCompressed ) + { + GetCompressedTextureFormat( uploadFormat, colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB, mipSize, mipSize, &internalFormat, &size ); + glCompressedTexImage2DARB (faces[face], level, internalFormat, mipSize, mipSize, 0, size, feedData); + } + else + { + GetUncompressedTextureFormat( uploadFormat, colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB, &internalFormat, &inputFormat, &datatype ); + glTexImage2D (faces[face], level, internalFormat, mipSize, mipSize, 0, inputFormat, datatype, feedData); + } + + GLAssert (); + int levelSize = CalculateImageSize( mipSize, mipSize, format ); + uploadSize += levelSize; + data += levelSize; + AssertIf( mipSize == 1 && level != maxLevel ); + + mipSize = std::max( mipSize / 2, 1 ); + } + } + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(tid.m_ID,uploadSize,tid.m_ID); + if( decompressBuffer ) + delete[] decompressBuffer; +} + + +void UploadTexture3DGL( + TextureID tid, UInt8* srcData, int width, int height, int depth, + TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + if (!gGraphicsCaps.has3DTexture) + return; + + if (!glIsTexture(tid.m_ID)) + uploadFlags |= GfxDevice::kUploadTextureDontUseSubImage; + +#if DEBUG_GL_TEXTURE + printf_console( "GLDebug texture 3D: upload %i (%ix%ix%i)\n", tid, width, height, depth ); +#endif + REGISTER_EXTERNAL_GFX_DEALLOCATION(tid.m_ID); + + TextureIdMapGL_QueryOrCreate(tid); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, tid, kTexDim3D, std::numeric_limits<float>::infinity()); + + glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + int internalFormat, datatype, inputFormat; + int maxLevel = mipCount - 1; + int bpp = GetBytesFromTextureFormat(format); + int uploadSize = 0; + + for (int level=0;level<=maxLevel;level++) + { + GetUncompressedTextureFormat (format, false, &internalFormat, &inputFormat, &datatype); +#if DEBUG_GL_TEXTURE + printf_console( "GLDebug texture 3D: glTexImage3D: level=%i ifmt=%i width=%i height=%i depth=%i fmt=%i type=%i data=%x\n", level, internalFormat, width, height, depth, inputFormat,datatype, (UInt32)srcData ); +#endif + glTexImage3D (GL_TEXTURE_3D, level, internalFormat, width, height, depth, 0, inputFormat, datatype, srcData); + GLAssert (); + uploadSize += width*height*depth*bpp; + + // Go to next level + srcData += CalculateImageSize(width, height, format) * depth; + width = std::max(width / 2, 1); + height = std::max(height / 2, 1); + depth = std::max(depth / 2, 1); + } + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(tid.m_ID,uploadSize,tid.m_ID); +} + + +void GLReadPixelsWrapper (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); + +bool ReadbackTextureGL( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) +{ + int internalFormat, datatype, inputFormat; + GetUncompressedTextureFormat( image.GetFormat(), false, &internalFormat, &inputFormat, &datatype ); + + // The whole image we're reading into can be larger than the rect we read. + // So setup the alignment. + glPixelStorei( GL_PACK_ROW_LENGTH, image.GetRowBytes() / GetBytesFromTextureFormat(image.GetFormat()) ); + glPixelStorei( GL_PACK_ALIGNMENT, 1 ); + + switch( image.GetFormat() ) { + case kTexFormatARGB32: + GLReadPixelsWrapper(left,bottom,width,height,inputFormat,datatype,image.GetRowPtr(destY) + destX * 4); + break; + case kTexFormatRGB24: + GLReadPixelsWrapper(left,bottom,width,height,inputFormat,datatype,image.GetRowPtr(destY) + destX * 3); + break; + case kTexFormatAlpha8: + GLReadPixelsWrapper(left,bottom,width,height,inputFormat,datatype,image.GetRowPtr(destY) + destX); + break; + default: + AssertString ("Not Supported"); + glPixelStorei( GL_PACK_ROW_LENGTH, 0 ); + return false; + } + + glPixelStorei( GL_PACK_ROW_LENGTH, 0 ); + + return true; +} diff --git a/Runtime/GfxDevice/opengl/TexturesGL.h b/Runtime/GfxDevice/opengl/TexturesGL.h new file mode 100644 index 0000000..746c342 --- /dev/null +++ b/Runtime/GfxDevice/opengl/TexturesGL.h @@ -0,0 +1,25 @@ +#pragma once + +#include "Runtime/Graphics/TextureFormat.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Configuration/UnityConfigure.h" + +class ImageReference; + +void UploadTexture2DGL( + TextureID tid, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + +void UploadTextureSubData2DGL( + TextureID tid, UInt8* srcData, + int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + +void UploadTextureCubeGL( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + +void UploadTexture3DGL( + TextureID tid, UInt8* srcData, int width, int height, int depth, + TextureFormat format, int mipCount, UInt32 uploadFlags ); + +bool ReadbackTextureGL( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); diff --git a/Runtime/GfxDevice/opengl/TimerQueryGL.cpp b/Runtime/GfxDevice/opengl/TimerQueryGL.cpp new file mode 100644 index 0000000..8f218d8 --- /dev/null +++ b/Runtime/GfxDevice/opengl/TimerQueryGL.cpp @@ -0,0 +1,162 @@ +#include "UnityPrefix.h" +#if ENABLE_PROFILER +#include "UnityGL.h" +#include "TimerQueryGL.h" +#include "Runtime/Shaders/GraphicsCaps.h" + +TimerQueryGL::TimerQueryGL() +{ + m_Query = g_TimerQueriesGL.AllocateQuery(); +} + +TimerQueryGL::~TimerQueryGL() +{ + g_TimerQueriesGL.ReleaseQuery(m_Query); +} + +void TimerQueryGL::Measure() +{ + // Finish previous timer query + OGL_CALL(glEndQueryARB(GL_TIME_ELAPSED_EXT)); + + MeasureBegin(); +} + +void TimerQueryGL::MeasureBegin() +{ + // Flush previous result + GetElapsed(kWaitRenderThread); + + OGL_CALL(glBeginQueryARB(GL_TIME_ELAPSED_EXT, m_Query)); + + g_TimerQueriesGL.AddActiveTimerQuery(this); + m_Time = kInvalidProfileTime; +} + +ProfileTimeFormat TimerQueryGL::GetElapsed(UInt32 flags) +{ + bool wait = (flags & kWaitRenderThread) != 0; + // We need to return a valid time if waiting + if (wait && m_Time == kInvalidProfileTime) + m_Time = 0; + while (IsInList()) + { + if (!g_TimerQueriesGL.PollNextTimerQuery(wait)) + break; + } + return m_Time; +} + +bool TimerQueryGL::PollResult(UInt64& prevTime, bool wait) +{ + for (;;) + { + // Currently we always wait on result + //GLint available = 0; + //OGL_CALL(glGetQueryObjectivARB(m_Query, GL_QUERY_RESULT_AVAILABLE, &available)); + //if (available) + { + GLuint64EXT time; + OGL_CALL(glGetQueryObjectui64vEXT(m_Query, GL_QUERY_RESULT, &time)); + // Some Nvidia cards return invalid results, sanity check! + if (time > GLuint64EXT(0xffffffff)) + gGraphicsCaps.buggyTimerQuery = true; + // We actually want previous query's time elapsed + // Save current returned result for next query + m_Time = prevTime; + prevTime = time; + return true; + } + if (!wait) + break; + } + return false; +} + +TimerQueriesGL::TimerQueriesGL() +{ + memset(m_FreeQueries, 0, sizeof(m_FreeQueries)); + m_NumFreeQueries = 0; + m_LastQueryTime = 0; + memset(m_StartTimeQueries, 0, sizeof(m_StartTimeQueries)); + m_StartTimeQueryIndex = 0; + m_Active = false; +} + +GLuint TimerQueriesGL::AllocateQuery() +{ + if (m_NumFreeQueries == 0) + { + OGL_CALL(glGenQueriesARB(kMaxFreeQueries, m_FreeQueries)); + m_NumFreeQueries = kMaxFreeQueries; + } + return m_FreeQueries[--m_NumFreeQueries]; +} + +void TimerQueriesGL::ReleaseQuery(GLuint query) +{ + if (m_NumFreeQueries == kMaxFreeQueries) + { + OGL_CALL(glDeleteQueriesARB(kMaxFreeQueries, m_FreeQueries)); + m_NumFreeQueries = 0; + } + m_FreeQueries[m_NumFreeQueries++] = query; +} + +void TimerQueriesGL::AddActiveTimerQuery(TimerQueryGL* query) +{ + m_ActiveTimerQueries.push_back(*query); +} + +void TimerQueriesGL::BeginTimerQueries() +{ + Assert(!m_Active); + int& index = m_StartTimeQueryIndex; + if(m_StartTimeQueries[index] == NULL) + { + m_StartTimeQueries[index] = new TimerQueryGL; + } + m_StartTimeQueries[index]->MeasureBegin(); + index = (index + 1) % kStartTimeQueryCount; + m_Active = true; +} + +void TimerQueriesGL::EndTimerQueries() +{ + Assert(m_Active); + OGL_CALL(glEndQueryARB(GL_TIME_ELAPSED_EXT)); + OGL_CALL(glFlush()); + + // Move queries from active to polled list + m_PolledTimerQueries.append(m_ActiveTimerQueries); + + g_TimerQueriesGL.PollTimerQueries(true); + m_Active = false; +} + +void TimerQueriesGL::PollTimerQueries(bool wait) +{ + for (;;) + { + if (!PollNextTimerQuery(wait)) + break; + } +} + +bool TimerQueriesGL::PollNextTimerQuery(bool wait) +{ + if (m_PolledTimerQueries.empty()) + return false; + + TimerQueryGL& query = m_PolledTimerQueries.front(); + if (query.PollResult(m_LastQueryTime, wait)) + { + m_PolledTimerQueries.pop_front(); + return true; + } + return false; +} + +TimerQueriesGL g_TimerQueriesGL; + +#endif diff --git a/Runtime/GfxDevice/opengl/TimerQueryGL.h b/Runtime/GfxDevice/opengl/TimerQueryGL.h new file mode 100644 index 0000000..eb95f56 --- /dev/null +++ b/Runtime/GfxDevice/opengl/TimerQueryGL.h @@ -0,0 +1,63 @@ +#ifndef TIMERQUERYGL_H +#define TIMERQUERYGL_H + +#if ENABLE_PROFILER + +#include "Runtime/GfxDevice/GfxTimerQuery.h" + +class TimerQueryGL : public GfxTimerQuery +{ +public: + TimerQueryGL(); + ~TimerQueryGL(); + + virtual void Measure(); + void MeasureBegin(); + virtual ProfileTimeFormat GetElapsed(UInt32 flags); + + bool PollResult(UInt64& prevTime, bool wait); + +private: + GLuint m_Query; + ProfileTimeFormat m_Time; +}; + +class TimerQueriesGL +{ +public: + TimerQueriesGL(); + + GLuint AllocateQuery(); + void ReleaseQuery(GLuint query); + + void BeginTimerQueries(); + void EndTimerQueries(); + + bool IsActive() const { return m_Active; } + + void AddActiveTimerQuery(TimerQueryGL* query); + void PollTimerQueries(bool wait); + bool PollNextTimerQuery(bool wait); + +private: + enum + { + kStartTimeQueryCount = 3, + kMaxFreeQueries = 128 + }; + + GLuint m_FreeQueries[kMaxFreeQueries]; + int m_NumFreeQueries; + UInt64 m_LastQueryTime; + TimerQueryGL* m_StartTimeQueries[kStartTimeQueryCount]; + int m_StartTimeQueryIndex; + typedef List<TimerQueryGL> TimerQueryList; + TimerQueryList m_ActiveTimerQueries; + TimerQueryList m_PolledTimerQueries; + bool m_Active; +}; + +extern TimerQueriesGL g_TimerQueriesGL; + +#endif +#endif diff --git a/Runtime/GfxDevice/opengl/UnityGL.h b/Runtime/GfxDevice/opengl/UnityGL.h new file mode 100644 index 0000000..e7f4bb2 --- /dev/null +++ b/Runtime/GfxDevice/opengl/UnityGL.h @@ -0,0 +1,176 @@ +#ifndef UNITYGL_H +#define UNITYGL_H + +#ifdef GLES_INCLUDES_H +# error "Don't include UnityGL.h and GLESIncludes.h at the same time!" +#endif + +#if UNITY_OSX + #include "unity_gl.h" + #undef GL_VERSION_1_2 + #include "unity_glext.h" +#elif UNITY_WIN + #undef NOMINMAX + #define NOMINMAX 1 + #include <windows.h> + #include "unity_gl.h" + #undef GL_VERSION_1_2 + #include "unity_glext.h" + #include "PlatformDependent/Win/wglext.h" +#elif UNITY_WII + #include <revolution.h> +#elif UNITY_ANDROID + #include <GLES/gl.h> +#elif UNITY_LINUX + #include "unity_gl.h" + #undef GL_VERSION_1_2 + #include "unity_glext.h" +#else +#error "Unknown platform" +#endif + +#if UNITY_WII + +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef signed char GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef unsigned char GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef float GLfloat; +typedef float GLclampf; +typedef double GLdouble; +typedef double GLclampd; +typedef void GLvoid; + +void glBegin (GLenum mode); +void glEnd (void); + +void glVertex2f (GLfloat x, GLfloat y); +void glVertex3f (GLfloat x, GLfloat y, GLfloat z); +void glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w ); +void glVertex3fv (const GLfloat *v); +void glColor4fv (const GLfloat *v); +void glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +void glTexCoord1f (GLfloat s); +void glTexCoord2f (GLfloat s, GLfloat t); +void glTexCoord3f (GLfloat s, GLfloat t, GLfloat r); +void glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q); +void glTexCoord1fv (const GLfloat *v); +void glTexCoord2fv (const GLfloat *v); +void glTexCoord3fv (const GLfloat *v); +void glTexCoord4fv (const GLfloat *v); +//void glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); +void glNormal3fv (const GLfloat *v); +void glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); + +void glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +void glDisableClientState (GLenum array); +void glClientActiveTextureARB (GLenum); +void glPolygonMode (GLenum face, GLenum mode); +void glActiveTextureARB (GLenum); +void glMultiTexCoord3fvARB (GLenum, const GLfloat *); +void glMultiTexCoord3fARB (GLenum, GLfloat, GLfloat, GLfloat); +void glMultiTexCoord4fARB (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +void glMultiTexCoord4fvARB (GLenum, const GLfloat *); +void glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +void glDrawArrays (GLenum mode, GLint first, GLsizei count); +void glDisableVertexAttribArrayARB (GLuint); +void glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); + +void glBindTexture (GLenum target, GLuint texture); +void glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); +void glTexParameteri (GLenum target, GLenum pname, GLint param); +void glTranslatef (GLfloat x, GLfloat y, GLfloat z); +void glScalef (GLfloat x, GLfloat y, GLfloat z); + +void glMatrixMode (GLenum mode); +void glMultMatrixf (const GLfloat *m); +void glPushMatrix (void); +void glPopMatrix (void); +void glLoadIdentity (void); + +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_FLOAT 0x1406 + +#define GL_ZERO 0 +#define GL_ONE 1 +//#define GL_SRC_COLOR 0x0300 +//#define GL_ONE_MINUS_SRC_COLOR 0x0301 +//#define GL_SRC_ALPHA 0x0302 +//#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +//#define GL_DST_ALPHA 0x0304 +//#define GL_ONE_MINUS_DST_ALPHA 0x0305 + +#define GL_FRONT_AND_BACK 0x0408 + +#define GL_LINES 0x0001 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_QUADS 0x0007 + +#define GL_TEXTURE_2D 0x0DE1 + +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A + +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +#define GL_CLAMP_TO_BORDER_ARB 0x812D + +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 + +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +#define GL_COLOR_ARRAY 0x8076 +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_TEXTURE_COORD_ARRAY 0x8078 + +#define GL_TEXTURE0_ARB 0x84C0 + +#elif UNITY_ANDROID +#else + +#if GFX_SUPPORTS_OPENGL +#define DEF(a,b) extern a UNITYGL_##b +#include "GLExtensionDefs.h" +#undef DEF +#endif + +#endif + +#if GFX_SUPPORTS_OPENGL +void InitGLExtensions(); +void CleanupGLExtensions(); +void UnbindVertexBuffersGL(); // defined in GfxDeviceGL.cpp +#include "GLAssert.h" +#endif + + +//#define DUMMY_OPENGL_CALLS + + +#ifndef DUMMY_OPENGL_CALLS +#define OGL_CALL(x) do { x; GLAssert(); } while(0) +#else +void DummyOpenGLFunction(); +#define OGL_CALL(x) DummyOpenGLFunction() +#endif + + + +#endif diff --git a/Runtime/GfxDevice/opengl/unity_gl.h b/Runtime/GfxDevice/opengl/unity_gl.h new file mode 100644 index 0000000..2097ef3 --- /dev/null +++ b/Runtime/GfxDevice/opengl/unity_gl.h @@ -0,0 +1,1914 @@ +#ifndef __gl_h_ +#define __gl_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** The contents of this file are subject to the GLX Public License Version 1.0 +** (the "License"). You may not use this file except in compliance with the +** License. You may obtain a copy of the License at Silicon Graphics, Inc., +** attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA 94043 +** or at http://www.sgi.com/software/opensource/glx/license.html. +** +** Software distributed under the License is distributed on an "AS IS" +** basis. ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY +** IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR +** PURPOSE OR OF NON- INFRINGEMENT. See the License for the specific +** language governing rights and limitations under the License. +** +** The Original Software is GLX version 1.2 source code, released February, +** 1999. The developer of the Original Software is Silicon Graphics, Inc. +** Those portions of the Subject Software created by Silicon Graphics, Inc. +** are Copyright (c) 1991-9 Silicon Graphics, Inc. All Rights Reserved. +*/ + +#ifndef _WIN32 +#define WINGDIAPI +#define APIENTRY +#endif + +typedef unsigned int GLenum; +typedef unsigned char GLboolean; +typedef unsigned int GLbitfield; +typedef signed char GLbyte; +typedef short GLshort; +typedef int GLint; +typedef int GLsizei; +typedef unsigned char GLubyte; +typedef unsigned short GLushort; +typedef unsigned int GLuint; +typedef float GLfloat; +typedef float GLclampf; +typedef double GLdouble; +typedef double GLclampd; +typedef void GLvoid; + +/*************************************************************/ + +/* Version */ +#define GL_VERSION_1_1 1 +#define GL_VERSION_1_2 1 + +/* Extensions */ +#define GL_ARB_imaging 1 +#define GL_ARB_multitexture 1 + +/* AccumOp */ +#define GL_ACCUM 0x0100 +#define GL_LOAD 0x0101 +#define GL_RETURN 0x0102 +#define GL_MULT 0x0103 +#define GL_ADD 0x0104 + +/* AlphaFunction */ +#define GL_NEVER 0x0200 +#define GL_LESS 0x0201 +#define GL_EQUAL 0x0202 +#define GL_LEQUAL 0x0203 +#define GL_GREATER 0x0204 +#define GL_NOTEQUAL 0x0205 +#define GL_GEQUAL 0x0206 +#define GL_ALWAYS 0x0207 + +/* AttribMask */ +#define GL_CURRENT_BIT 0x00000001 +#define GL_POINT_BIT 0x00000002 +#define GL_LINE_BIT 0x00000004 +#define GL_POLYGON_BIT 0x00000008 +#define GL_POLYGON_STIPPLE_BIT 0x00000010 +#define GL_PIXEL_MODE_BIT 0x00000020 +#define GL_LIGHTING_BIT 0x00000040 +#define GL_FOG_BIT 0x00000080 +#define GL_DEPTH_BUFFER_BIT 0x00000100 +#define GL_ACCUM_BUFFER_BIT 0x00000200 +#define GL_STENCIL_BUFFER_BIT 0x00000400 +#define GL_VIEWPORT_BIT 0x00000800 +#define GL_TRANSFORM_BIT 0x00001000 +#define GL_ENABLE_BIT 0x00002000 +#define GL_COLOR_BUFFER_BIT 0x00004000 +#define GL_HINT_BIT 0x00008000 +#define GL_EVAL_BIT 0x00010000 +#define GL_LIST_BIT 0x00020000 +#define GL_TEXTURE_BIT 0x00040000 +#define GL_SCISSOR_BIT 0x00080000 +#define GL_ALL_ATTRIB_BITS 0x000fffff + +/* BeginMode */ +#define GL_POINTS 0x0000 +#define GL_LINES 0x0001 +#define GL_LINE_LOOP 0x0002 +#define GL_LINE_STRIP 0x0003 +#define GL_TRIANGLES 0x0004 +#define GL_TRIANGLE_STRIP 0x0005 +#define GL_TRIANGLE_FAN 0x0006 +#define GL_QUADS 0x0007 +#define GL_QUAD_STRIP 0x0008 +#define GL_POLYGON 0x0009 + +/* BlendEquationMode */ +/* GL_LOGIC_OP */ +/* GL_FUNC_ADD */ +/* GL_MIN */ +/* GL_MAX */ +/* GL_FUNC_SUBTRACT */ +/* GL_FUNC_REVERSE_SUBTRACT */ + +/* BlendingFactorDest */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 +/* GL_CONSTANT_COLOR */ +/* GL_ONE_MINUS_CONSTANT_COLOR */ +/* GL_CONSTANT_ALPHA */ +/* GL_ONE_MINUS_CONSTANT_ALPHA */ + +/* BlendingFactorSrc */ +/* GL_ZERO */ +/* GL_ONE */ +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 +/* GL_SRC_ALPHA */ +/* GL_ONE_MINUS_SRC_ALPHA */ +/* GL_DST_ALPHA */ +/* GL_ONE_MINUS_DST_ALPHA */ +/* GL_CONSTANT_COLOR */ +/* GL_ONE_MINUS_CONSTANT_COLOR */ +/* GL_CONSTANT_ALPHA */ +/* GL_ONE_MINUS_CONSTANT_ALPHA */ + +/* Boolean */ +#define GL_TRUE 1 +#define GL_FALSE 0 + +/* ClearBufferMask */ +/* GL_COLOR_BUFFER_BIT */ +/* GL_ACCUM_BUFFER_BIT */ +/* GL_STENCIL_BUFFER_BIT */ +/* GL_DEPTH_BUFFER_BIT */ + +/* ClientArrayType */ +/* GL_VERTEX_ARRAY */ +/* GL_NORMAL_ARRAY */ +/* GL_COLOR_ARRAY */ +/* GL_INDEX_ARRAY */ +/* GL_TEXTURE_COORD_ARRAY */ +/* GL_EDGE_FLAG_ARRAY */ + +/* ClipPlaneName */ +#define GL_CLIP_PLANE0 0x3000 +#define GL_CLIP_PLANE1 0x3001 +#define GL_CLIP_PLANE2 0x3002 +#define GL_CLIP_PLANE3 0x3003 +#define GL_CLIP_PLANE4 0x3004 +#define GL_CLIP_PLANE5 0x3005 + +/* ColorMaterialFace */ +/* GL_FRONT */ +/* GL_BACK */ +/* GL_FRONT_AND_BACK */ + +/* ColorMaterialParameter */ +/* GL_AMBIENT */ +/* GL_DIFFUSE */ +/* GL_SPECULAR */ +/* GL_EMISSION */ +/* GL_AMBIENT_AND_DIFFUSE */ + +/* ColorPointerType */ +/* GL_BYTE */ +/* GL_UNSIGNED_BYTE */ +/* GL_SHORT */ +/* GL_UNSIGNED_SHORT */ +/* GL_INT */ +/* GL_UNSIGNED_INT */ +/* GL_FLOAT */ +/* GL_DOUBLE */ + +/* ColorTableParameterPName */ +/* GL_COLOR_TABLE_SCALE */ +/* GL_COLOR_TABLE_BIAS */ + +/* ColorTableTarget */ +/* GL_COLOR_TABLE */ +/* GL_POST_CONVOLUTION_COLOR_TABLE */ +/* GL_POST_COLOR_MATRIX_COLOR_TABLE */ +/* GL_PROXY_COLOR_TABLE */ +/* GL_PROXY_POST_CONVOLUTION_COLOR_TABLE */ +/* GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE */ + +/* ConvolutionBorderMode */ +/* GL_REDUCE */ +/* GL_IGNORE_BORDER */ +/* GL_CONSTANT_BORDER */ + +/* ConvolutionParameter */ +/* GL_CONVOLUTION_BORDER_MODE */ +/* GL_CONVOLUTION_FILTER_SCALE */ +/* GL_CONVOLUTION_FILTER_BIAS */ + +/* ConvolutionTarget */ +/* GL_CONVOLUTION_1D */ +/* GL_CONVOLUTION_2D */ + +/* CullFaceMode */ +/* GL_FRONT */ +/* GL_BACK */ +/* GL_FRONT_AND_BACK */ + +/* DataType */ +#define GL_BYTE 0x1400 +#define GL_UNSIGNED_BYTE 0x1401 +#define GL_SHORT 0x1402 +#define GL_UNSIGNED_SHORT 0x1403 +#define GL_INT 0x1404 +#define GL_UNSIGNED_INT 0x1405 +#define GL_FLOAT 0x1406 +#define GL_2_BYTES 0x1407 +#define GL_3_BYTES 0x1408 +#define GL_4_BYTES 0x1409 +#define GL_DOUBLE 0x140A + +/* DepthFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* DrawBufferMode */ +#define GL_NONE 0 +#define GL_FRONT_LEFT 0x0400 +#define GL_FRONT_RIGHT 0x0401 +#define GL_BACK_LEFT 0x0402 +#define GL_BACK_RIGHT 0x0403 +#define GL_FRONT 0x0404 +#define GL_BACK 0x0405 +#define GL_LEFT 0x0406 +#define GL_RIGHT 0x0407 +#define GL_FRONT_AND_BACK 0x0408 +#define GL_AUX0 0x0409 +#define GL_AUX1 0x040A +#define GL_AUX2 0x040B +#define GL_AUX3 0x040C + +/* Enable */ +/* GL_FOG */ +/* GL_LIGHTING */ +/* GL_TEXTURE_1D */ +/* GL_TEXTURE_2D */ +/* GL_LINE_STIPPLE */ +/* GL_POLYGON_STIPPLE */ +/* GL_CULL_FACE */ +/* GL_ALPHA_TEST */ +/* GL_BLEND */ +/* GL_INDEX_LOGIC_OP */ +/* GL_COLOR_LOGIC_OP */ +/* GL_DITHER */ +/* GL_STENCIL_TEST */ +/* GL_DEPTH_TEST */ +/* GL_CLIP_PLANE0 */ +/* GL_CLIP_PLANE1 */ +/* GL_CLIP_PLANE2 */ +/* GL_CLIP_PLANE3 */ +/* GL_CLIP_PLANE4 */ +/* GL_CLIP_PLANE5 */ +/* GL_LIGHT0 */ +/* GL_LIGHT1 */ +/* GL_LIGHT2 */ +/* GL_LIGHT3 */ +/* GL_LIGHT4 */ +/* GL_LIGHT5 */ +/* GL_LIGHT6 */ +/* GL_LIGHT7 */ +/* GL_TEXTURE_GEN_S */ +/* GL_TEXTURE_GEN_T */ +/* GL_TEXTURE_GEN_R */ +/* GL_TEXTURE_GEN_Q */ +/* GL_MAP1_VERTEX_3 */ +/* GL_MAP1_VERTEX_4 */ +/* GL_MAP1_COLOR_4 */ +/* GL_MAP1_INDEX */ +/* GL_MAP1_NORMAL */ +/* GL_MAP1_TEXTURE_COORD_1 */ +/* GL_MAP1_TEXTURE_COORD_2 */ +/* GL_MAP1_TEXTURE_COORD_3 */ +/* GL_MAP1_TEXTURE_COORD_4 */ +/* GL_MAP2_VERTEX_3 */ +/* GL_MAP2_VERTEX_4 */ +/* GL_MAP2_COLOR_4 */ +/* GL_MAP2_INDEX */ +/* GL_MAP2_NORMAL */ +/* GL_MAP2_TEXTURE_COORD_1 */ +/* GL_MAP2_TEXTURE_COORD_2 */ +/* GL_MAP2_TEXTURE_COORD_3 */ +/* GL_MAP2_TEXTURE_COORD_4 */ +/* GL_POINT_SMOOTH */ +/* GL_LINE_SMOOTH */ +/* GL_POLYGON_SMOOTH */ +/* GL_SCISSOR_TEST */ +/* GL_COLOR_MATERIAL */ +/* GL_NORMALIZE */ +/* GL_AUTO_NORMAL */ +/* GL_VERTEX_ARRAY */ +/* GL_NORMAL_ARRAY */ +/* GL_COLOR_ARRAY */ +/* GL_INDEX_ARRAY */ +/* GL_TEXTURE_COORD_ARRAY */ +/* GL_EDGE_FLAG_ARRAY */ +/* GL_POLYGON_OFFSET_POINT */ +/* GL_POLYGON_OFFSET_LINE */ +/* GL_POLYGON_OFFSET_FILL */ +/* GL_COLOR_TABLE */ +/* GL_POST_CONVOLUTION_COLOR_TABLE */ +/* GL_POST_COLOR_MATRIX_COLOR_TABLE */ +/* GL_CONVOLUTION_1D */ +/* GL_CONVOLUTION_2D */ +/* GL_SEPARABLE_2D */ +/* GL_HISTOGRAM */ +/* GL_MINMAX */ +/* GL_RESCALE_NORMAL */ +/* GL_TEXTURE_3D */ + +/* ErrorCode */ +#define GL_NO_ERROR 0 +#define GL_INVALID_ENUM 0x0500 +#define GL_INVALID_VALUE 0x0501 +#define GL_INVALID_OPERATION 0x0502 +#define GL_STACK_OVERFLOW 0x0503 +#define GL_STACK_UNDERFLOW 0x0504 +#define GL_OUT_OF_MEMORY 0x0505 +/* GL_TABLE_TOO_LARGE */ + +/* FeedBackMode */ +#define GL_2D 0x0600 +#define GL_3D 0x0601 +#define GL_3D_COLOR 0x0602 +#define GL_3D_COLOR_TEXTURE 0x0603 +#define GL_4D_COLOR_TEXTURE 0x0604 + +/* FeedBackToken */ +#define GL_PASS_THROUGH_TOKEN 0x0700 +#define GL_POINT_TOKEN 0x0701 +#define GL_LINE_TOKEN 0x0702 +#define GL_POLYGON_TOKEN 0x0703 +#define GL_BITMAP_TOKEN 0x0704 +#define GL_DRAW_PIXEL_TOKEN 0x0705 +#define GL_COPY_PIXEL_TOKEN 0x0706 +#define GL_LINE_RESET_TOKEN 0x0707 + +/* FogMode */ +/* GL_LINEAR */ +#define GL_EXP 0x0800 +#define GL_EXP2 0x0801 + +/* FogParameter */ +/* GL_FOG_COLOR */ +/* GL_FOG_DENSITY */ +/* GL_FOG_END */ +/* GL_FOG_INDEX */ +/* GL_FOG_MODE */ +/* GL_FOG_START */ + +/* FrontFaceDirection */ +#define GL_CW 0x0900 +#define GL_CCW 0x0901 + +/* GetColorTableParameterPName */ +/* GL_COLOR_TABLE_SCALE */ +/* GL_COLOR_TABLE_BIAS */ +/* GL_COLOR_TABLE_FORMAT */ +/* GL_COLOR_TABLE_WIDTH */ +/* GL_COLOR_TABLE_RED_SIZE */ +/* GL_COLOR_TABLE_GREEN_SIZE */ +/* GL_COLOR_TABLE_BLUE_SIZE */ +/* GL_COLOR_TABLE_ALPHA_SIZE */ +/* GL_COLOR_TABLE_LUMINANCE_SIZE */ +/* GL_COLOR_TABLE_INTENSITY_SIZE */ + +/* GetConvolutionParameterPName */ +/* GL_CONVOLUTION_BORDER_COLOR */ +/* GL_CONVOLUTION_BORDER_MODE */ +/* GL_CONVOLUTION_FILTER_SCALE */ +/* GL_CONVOLUTION_FILTER_BIAS */ +/* GL_CONVOLUTION_FORMAT */ +/* GL_CONVOLUTION_WIDTH */ +/* GL_CONVOLUTION_HEIGHT */ +/* GL_MAX_CONVOLUTION_WIDTH */ +/* GL_MAX_CONVOLUTION_HEIGHT */ + +/* GetHistogramParameterPName */ +/* GL_HISTOGRAM_WIDTH */ +/* GL_HISTOGRAM_FORMAT */ +/* GL_HISTOGRAM_RED_SIZE */ +/* GL_HISTOGRAM_GREEN_SIZE */ +/* GL_HISTOGRAM_BLUE_SIZE */ +/* GL_HISTOGRAM_ALPHA_SIZE */ +/* GL_HISTOGRAM_LUMINANCE_SIZE */ +/* GL_HISTOGRAM_SINK */ + +/* GetMapTarget */ +#define GL_COEFF 0x0A00 +#define GL_ORDER 0x0A01 +#define GL_DOMAIN 0x0A02 + +/* GetMinmaxParameterPName */ +/* GL_MINMAX_FORMAT */ +/* GL_MINMAX_SINK */ + +/* GetPixelMap */ +/* GL_PIXEL_MAP_I_TO_I */ +/* GL_PIXEL_MAP_S_TO_S */ +/* GL_PIXEL_MAP_I_TO_R */ +/* GL_PIXEL_MAP_I_TO_G */ +/* GL_PIXEL_MAP_I_TO_B */ +/* GL_PIXEL_MAP_I_TO_A */ +/* GL_PIXEL_MAP_R_TO_R */ +/* GL_PIXEL_MAP_G_TO_G */ +/* GL_PIXEL_MAP_B_TO_B */ +/* GL_PIXEL_MAP_A_TO_A */ + +/* GetPointerTarget */ +/* GL_VERTEX_ARRAY_POINTER */ +/* GL_NORMAL_ARRAY_POINTER */ +/* GL_COLOR_ARRAY_POINTER */ +/* GL_INDEX_ARRAY_POINTER */ +/* GL_TEXTURE_COORD_ARRAY_POINTER */ +/* GL_EDGE_FLAG_ARRAY_POINTER */ + +/* GetTarget */ +#define GL_CURRENT_COLOR 0x0B00 +#define GL_CURRENT_INDEX 0x0B01 +#define GL_CURRENT_NORMAL 0x0B02 +#define GL_CURRENT_TEXTURE_COORDS 0x0B03 +#define GL_CURRENT_RASTER_COLOR 0x0B04 +#define GL_CURRENT_RASTER_INDEX 0x0B05 +#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06 +#define GL_CURRENT_RASTER_POSITION 0x0B07 +#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08 +#define GL_CURRENT_RASTER_DISTANCE 0x0B09 +#define GL_POINT_SMOOTH 0x0B10 +#define GL_POINT_SIZE 0x0B11 +#define GL_POINT_SIZE_RANGE 0x0B12 +#define GL_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_LINE_SMOOTH 0x0B20 +#define GL_LINE_WIDTH 0x0B21 +#define GL_LINE_WIDTH_RANGE 0x0B22 +#define GL_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_LINE_STIPPLE 0x0B24 +#define GL_LINE_STIPPLE_PATTERN 0x0B25 +#define GL_LINE_STIPPLE_REPEAT 0x0B26 +/* GL_SMOOTH_POINT_SIZE_RANGE */ +/* GL_SMOOTH_POINT_SIZE_GRANULARITY */ +/* GL_SMOOTH_LINE_WIDTH_RANGE */ +/* GL_SMOOTH_LINE_WIDTH_GRANULARITY */ +/* GL_ALIASED_POINT_SIZE_RANGE */ +/* GL_ALIASED_LINE_WIDTH_RANGE */ +#define GL_LIST_MODE 0x0B30 +#define GL_MAX_LIST_NESTING 0x0B31 +#define GL_LIST_BASE 0x0B32 +#define GL_LIST_INDEX 0x0B33 +#define GL_POLYGON_MODE 0x0B40 +#define GL_POLYGON_SMOOTH 0x0B41 +#define GL_POLYGON_STIPPLE 0x0B42 +#define GL_EDGE_FLAG 0x0B43 +#define GL_CULL_FACE 0x0B44 +#define GL_CULL_FACE_MODE 0x0B45 +#define GL_FRONT_FACE 0x0B46 +#define GL_LIGHTING 0x0B50 +#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51 +#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52 +#define GL_LIGHT_MODEL_AMBIENT 0x0B53 +#define GL_SHADE_MODEL 0x0B54 +#define GL_COLOR_MATERIAL_FACE 0x0B55 +#define GL_COLOR_MATERIAL_PARAMETER 0x0B56 +#define GL_COLOR_MATERIAL 0x0B57 +#define GL_FOG 0x0B60 +#define GL_FOG_INDEX 0x0B61 +#define GL_FOG_DENSITY 0x0B62 +#define GL_FOG_START 0x0B63 +#define GL_FOG_END 0x0B64 +#define GL_FOG_MODE 0x0B65 +#define GL_FOG_COLOR 0x0B66 +#define GL_DEPTH_RANGE 0x0B70 +#define GL_DEPTH_TEST 0x0B71 +#define GL_DEPTH_WRITEMASK 0x0B72 +#define GL_DEPTH_CLEAR_VALUE 0x0B73 +#define GL_DEPTH_FUNC 0x0B74 +#define GL_ACCUM_CLEAR_VALUE 0x0B80 +#define GL_STENCIL_TEST 0x0B90 +#define GL_STENCIL_CLEAR_VALUE 0x0B91 +#define GL_STENCIL_FUNC 0x0B92 +#define GL_STENCIL_VALUE_MASK 0x0B93 +#define GL_STENCIL_FAIL 0x0B94 +#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95 +#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96 +#define GL_STENCIL_REF 0x0B97 +#define GL_STENCIL_WRITEMASK 0x0B98 +#define GL_MATRIX_MODE 0x0BA0 +#define GL_NORMALIZE 0x0BA1 +#define GL_VIEWPORT 0x0BA2 +#define GL_MODELVIEW_STACK_DEPTH 0x0BA3 +#define GL_PROJECTION_STACK_DEPTH 0x0BA4 +#define GL_TEXTURE_STACK_DEPTH 0x0BA5 +#define GL_MODELVIEW_MATRIX 0x0BA6 +#define GL_PROJECTION_MATRIX 0x0BA7 +#define GL_TEXTURE_MATRIX 0x0BA8 +#define GL_ATTRIB_STACK_DEPTH 0x0BB0 +#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1 +#define GL_ALPHA_TEST 0x0BC0 +#define GL_ALPHA_TEST_FUNC 0x0BC1 +#define GL_ALPHA_TEST_REF 0x0BC2 +#define GL_DITHER 0x0BD0 +#define GL_BLEND_DST 0x0BE0 +#define GL_BLEND_SRC 0x0BE1 +#define GL_BLEND 0x0BE2 +#define GL_LOGIC_OP_MODE 0x0BF0 +#define GL_INDEX_LOGIC_OP 0x0BF1 +#define GL_COLOR_LOGIC_OP 0x0BF2 +#define GL_AUX_BUFFERS 0x0C00 +#define GL_DRAW_BUFFER 0x0C01 +#define GL_READ_BUFFER 0x0C02 +#define GL_SCISSOR_BOX 0x0C10 +#define GL_SCISSOR_TEST 0x0C11 +#define GL_INDEX_CLEAR_VALUE 0x0C20 +#define GL_INDEX_WRITEMASK 0x0C21 +#define GL_COLOR_CLEAR_VALUE 0x0C22 +#define GL_COLOR_WRITEMASK 0x0C23 +#define GL_INDEX_MODE 0x0C30 +#define GL_RGBA_MODE 0x0C31 +#define GL_DOUBLEBUFFER 0x0C32 +#define GL_STEREO 0x0C33 +#define GL_RENDER_MODE 0x0C40 +#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50 +#define GL_POINT_SMOOTH_HINT 0x0C51 +#define GL_LINE_SMOOTH_HINT 0x0C52 +#define GL_POLYGON_SMOOTH_HINT 0x0C53 +#define GL_FOG_HINT 0x0C54 +#define GL_TEXTURE_GEN_S 0x0C60 +#define GL_TEXTURE_GEN_T 0x0C61 +#define GL_TEXTURE_GEN_R 0x0C62 +#define GL_TEXTURE_GEN_Q 0x0C63 +#define GL_PIXEL_MAP_I_TO_I 0x0C70 +#define GL_PIXEL_MAP_S_TO_S 0x0C71 +#define GL_PIXEL_MAP_I_TO_R 0x0C72 +#define GL_PIXEL_MAP_I_TO_G 0x0C73 +#define GL_PIXEL_MAP_I_TO_B 0x0C74 +#define GL_PIXEL_MAP_I_TO_A 0x0C75 +#define GL_PIXEL_MAP_R_TO_R 0x0C76 +#define GL_PIXEL_MAP_G_TO_G 0x0C77 +#define GL_PIXEL_MAP_B_TO_B 0x0C78 +#define GL_PIXEL_MAP_A_TO_A 0x0C79 +#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0 +#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1 +#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2 +#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3 +#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4 +#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5 +#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6 +#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7 +#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8 +#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9 +#define GL_UNPACK_SWAP_BYTES 0x0CF0 +#define GL_UNPACK_LSB_FIRST 0x0CF1 +#define GL_UNPACK_ROW_LENGTH 0x0CF2 +#define GL_UNPACK_SKIP_ROWS 0x0CF3 +#define GL_UNPACK_SKIP_PIXELS 0x0CF4 +#define GL_UNPACK_ALIGNMENT 0x0CF5 +#define GL_PACK_SWAP_BYTES 0x0D00 +#define GL_PACK_LSB_FIRST 0x0D01 +#define GL_PACK_ROW_LENGTH 0x0D02 +#define GL_PACK_SKIP_ROWS 0x0D03 +#define GL_PACK_SKIP_PIXELS 0x0D04 +#define GL_PACK_ALIGNMENT 0x0D05 +#define GL_MAP_COLOR 0x0D10 +#define GL_MAP_STENCIL 0x0D11 +#define GL_INDEX_SHIFT 0x0D12 +#define GL_INDEX_OFFSET 0x0D13 +#define GL_RED_SCALE 0x0D14 +#define GL_RED_BIAS 0x0D15 +#define GL_ZOOM_X 0x0D16 +#define GL_ZOOM_Y 0x0D17 +#define GL_GREEN_SCALE 0x0D18 +#define GL_GREEN_BIAS 0x0D19 +#define GL_BLUE_SCALE 0x0D1A +#define GL_BLUE_BIAS 0x0D1B +#define GL_ALPHA_SCALE 0x0D1C +#define GL_ALPHA_BIAS 0x0D1D +#define GL_DEPTH_SCALE 0x0D1E +#define GL_DEPTH_BIAS 0x0D1F +#define GL_MAX_EVAL_ORDER 0x0D30 +#define GL_MAX_LIGHTS 0x0D31 +#define GL_MAX_CLIP_PLANES 0x0D32 +#define GL_MAX_TEXTURE_SIZE 0x0D33 +#define GL_MAX_PIXEL_MAP_TABLE 0x0D34 +#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35 +#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36 +#define GL_MAX_NAME_STACK_DEPTH 0x0D37 +#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38 +#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39 +#define GL_MAX_VIEWPORT_DIMS 0x0D3A +#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B +#define GL_SUBPIXEL_BITS 0x0D50 +#define GL_INDEX_BITS 0x0D51 +#define GL_RED_BITS 0x0D52 +#define GL_GREEN_BITS 0x0D53 +#define GL_BLUE_BITS 0x0D54 +#define GL_ALPHA_BITS 0x0D55 +#define GL_DEPTH_BITS 0x0D56 +#define GL_STENCIL_BITS 0x0D57 +#define GL_ACCUM_RED_BITS 0x0D58 +#define GL_ACCUM_GREEN_BITS 0x0D59 +#define GL_ACCUM_BLUE_BITS 0x0D5A +#define GL_ACCUM_ALPHA_BITS 0x0D5B +#define GL_NAME_STACK_DEPTH 0x0D70 +#define GL_AUTO_NORMAL 0x0D80 +#define GL_MAP1_COLOR_4 0x0D90 +#define GL_MAP1_INDEX 0x0D91 +#define GL_MAP1_NORMAL 0x0D92 +#define GL_MAP1_TEXTURE_COORD_1 0x0D93 +#define GL_MAP1_TEXTURE_COORD_2 0x0D94 +#define GL_MAP1_TEXTURE_COORD_3 0x0D95 +#define GL_MAP1_TEXTURE_COORD_4 0x0D96 +#define GL_MAP1_VERTEX_3 0x0D97 +#define GL_MAP1_VERTEX_4 0x0D98 +#define GL_MAP2_COLOR_4 0x0DB0 +#define GL_MAP2_INDEX 0x0DB1 +#define GL_MAP2_NORMAL 0x0DB2 +#define GL_MAP2_TEXTURE_COORD_1 0x0DB3 +#define GL_MAP2_TEXTURE_COORD_2 0x0DB4 +#define GL_MAP2_TEXTURE_COORD_3 0x0DB5 +#define GL_MAP2_TEXTURE_COORD_4 0x0DB6 +#define GL_MAP2_VERTEX_3 0x0DB7 +#define GL_MAP2_VERTEX_4 0x0DB8 +#define GL_MAP1_GRID_DOMAIN 0x0DD0 +#define GL_MAP1_GRID_SEGMENTS 0x0DD1 +#define GL_MAP2_GRID_DOMAIN 0x0DD2 +#define GL_MAP2_GRID_SEGMENTS 0x0DD3 +#define GL_TEXTURE_1D 0x0DE0 +#define GL_TEXTURE_2D 0x0DE1 +#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0 +#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1 +#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2 +#define GL_SELECTION_BUFFER_POINTER 0x0DF3 +#define GL_SELECTION_BUFFER_SIZE 0x0DF4 +/* GL_TEXTURE_BINDING_1D */ +/* GL_TEXTURE_BINDING_2D */ +/* GL_TEXTURE_BINDING_3D */ +/* GL_VERTEX_ARRAY */ +/* GL_NORMAL_ARRAY */ +/* GL_COLOR_ARRAY */ +/* GL_INDEX_ARRAY */ +/* GL_TEXTURE_COORD_ARRAY */ +/* GL_EDGE_FLAG_ARRAY */ +/* GL_VERTEX_ARRAY_SIZE */ +/* GL_VERTEX_ARRAY_TYPE */ +/* GL_VERTEX_ARRAY_STRIDE */ +/* GL_NORMAL_ARRAY_TYPE */ +/* GL_NORMAL_ARRAY_STRIDE */ +/* GL_COLOR_ARRAY_SIZE */ +/* GL_COLOR_ARRAY_TYPE */ +/* GL_COLOR_ARRAY_STRIDE */ +/* GL_INDEX_ARRAY_TYPE */ +/* GL_INDEX_ARRAY_STRIDE */ +/* GL_TEXTURE_COORD_ARRAY_SIZE */ +/* GL_TEXTURE_COORD_ARRAY_TYPE */ +/* GL_TEXTURE_COORD_ARRAY_STRIDE */ +/* GL_EDGE_FLAG_ARRAY_STRIDE */ +/* GL_POLYGON_OFFSET_FACTOR */ +/* GL_POLYGON_OFFSET_UNITS */ +/* GL_COLOR_TABLE */ +/* GL_POST_CONVOLUTION_COLOR_TABLE */ +/* GL_POST_COLOR_MATRIX_COLOR_TABLE */ +/* GL_CONVOLUTION_1D */ +/* GL_CONVOLUTION_2D */ +/* GL_SEPARABLE_2D */ +/* GL_POST_CONVOLUTION_RED_SCALE */ +/* GL_POST_CONVOLUTION_GREEN_SCALE */ +/* GL_POST_CONVOLUTION_BLUE_SCALE */ +/* GL_POST_CONVOLUTION_ALPHA_SCALE */ +/* GL_POST_CONVOLUTION_RED_BIAS */ +/* GL_POST_CONVOLUTION_GREEN_BIAS */ +/* GL_POST_CONVOLUTION_BLUE_BIAS */ +/* GL_POST_CONVOLUTION_ALPHA_BIAS */ +/* GL_COLOR_MATRIX */ +/* GL_COLOR_MATRIX_STACK_DEPTH */ +/* GL_MAX_COLOR_MATRIX_STACK_DEPTH */ +/* GL_POST_COLOR_MATRIX_RED_SCALE */ +/* GL_POST_COLOR_MATRIX_GREEN_SCALE */ +/* GL_POST_COLOR_MATRIX_BLUE_SCALE */ +/* GL_POST_COLOR_MATRIX_ALPHA_SCALE */ +/* GL_POST_COLOR_MATRIX_RED_BIAS */ +/* GL_POST_COLOR_MATRIX_GREEN_BIAS */ +/* GL_POST_COLOR_MATRIX_BLUE_BIAS */ +/* GL_POST_COLOR_MATRIX_ALPHA_BIAS */ +/* GL_HISTOGRAM */ +/* GL_MINMAX */ +/* GL_MAX_ELEMENTS_VERTICES */ +/* GL_MAX_ELEMENTS_INDICES */ +/* GL_RESCALE_NORMAL */ +/* GL_LIGHT_MODEL_COLOR_CONTROL */ +/* GL_PACK_SKIP_IMAGES */ +/* GL_PACK_IMAGE_HEIGHT */ +/* GL_UNPACK_SKIP_IMAGES */ +/* GL_UNPACK_IMAGE_HEIGHT */ +/* GL_TEXTURE_3D */ +/* GL_MAX_3D_TEXTURE_SIZE */ +/* GL_BLEND_COLOR */ +/* GL_BLEND_EQUATION */ +/* GL_ACTIVE_TEXTURE_ARB */ +/* GL_CLIENT_ACTIVE_TEXTURE_ARB */ +/* GL_MAX_TEXTURE_UNITS_ARB */ + +/* GetTextureParameter */ +/* GL_TEXTURE_MAG_FILTER */ +/* GL_TEXTURE_MIN_FILTER */ +/* GL_TEXTURE_WRAP_S */ +/* GL_TEXTURE_WRAP_T */ +#define GL_TEXTURE_WIDTH 0x1000 +#define GL_TEXTURE_HEIGHT 0x1001 +#define GL_TEXTURE_INTERNAL_FORMAT 0x1003 +#define GL_TEXTURE_BORDER_COLOR 0x1004 +#define GL_TEXTURE_BORDER 0x1005 +/* GL_TEXTURE_RED_SIZE */ +/* GL_TEXTURE_GREEN_SIZE */ +/* GL_TEXTURE_BLUE_SIZE */ +/* GL_TEXTURE_ALPHA_SIZE */ +/* GL_TEXTURE_LUMINANCE_SIZE */ +/* GL_TEXTURE_INTENSITY_SIZE */ +/* GL_TEXTURE_PRIORITY */ +/* GL_TEXTURE_RESIDENT */ +/* GL_TEXTURE_DEPTH */ +/* GL_TEXTURE_WRAP_R */ +/* GL_TEXTURE_MIN_LOD */ +/* GL_TEXTURE_MAX_LOD */ +/* GL_TEXTURE_BASE_LEVEL */ +/* GL_TEXTURE_MAX_LEVEL */ + +/* HintMode */ +#define GL_DONT_CARE 0x1100 +#define GL_FASTEST 0x1101 +#define GL_NICEST 0x1102 + +/* HintTarget */ +/* GL_PERSPECTIVE_CORRECTION_HINT */ +/* GL_POINT_SMOOTH_HINT */ +/* GL_LINE_SMOOTH_HINT */ +/* GL_POLYGON_SMOOTH_HINT */ +/* GL_FOG_HINT */ + +/* HistogramTarget */ +/* GL_HISTOGRAM */ +/* GL_PROXY_HISTOGRAM */ + +/* IndexPointerType */ +/* GL_SHORT */ +/* GL_INT */ +/* GL_FLOAT */ +/* GL_DOUBLE */ + +/* LightModelColorControl */ +/* GL_SINGLE_COLOR */ +/* GL_SEPARATE_SPECULAR_COLOR */ + +/* LightModelParameter */ +/* GL_LIGHT_MODEL_AMBIENT */ +/* GL_LIGHT_MODEL_LOCAL_VIEWER */ +/* GL_LIGHT_MODEL_TWO_SIDE */ +/* GL_LIGHT_MODEL_COLOR_CONTROL */ + +/* LightName */ +#define GL_LIGHT0 0x4000 +#define GL_LIGHT1 0x4001 +#define GL_LIGHT2 0x4002 +#define GL_LIGHT3 0x4003 +#define GL_LIGHT4 0x4004 +#define GL_LIGHT5 0x4005 +#define GL_LIGHT6 0x4006 +#define GL_LIGHT7 0x4007 + +/* LightParameter */ +#define GL_AMBIENT 0x1200 +#define GL_DIFFUSE 0x1201 +#define GL_SPECULAR 0x1202 +#define GL_POSITION 0x1203 +#define GL_SPOT_DIRECTION 0x1204 +#define GL_SPOT_EXPONENT 0x1205 +#define GL_SPOT_CUTOFF 0x1206 +#define GL_CONSTANT_ATTENUATION 0x1207 +#define GL_LINEAR_ATTENUATION 0x1208 +#define GL_QUADRATIC_ATTENUATION 0x1209 + +/* InterleavedArrays */ +/* GL_V2F */ +/* GL_V3F */ +/* GL_C4UB_V2F */ +/* GL_C4UB_V3F */ +/* GL_C3F_V3F */ +/* GL_N3F_V3F */ +/* GL_C4F_N3F_V3F */ +/* GL_T2F_V3F */ +/* GL_T4F_V4F */ +/* GL_T2F_C4UB_V3F */ +/* GL_T2F_C3F_V3F */ +/* GL_T2F_N3F_V3F */ +/* GL_T2F_C4F_N3F_V3F */ +/* GL_T4F_C4F_N3F_V4F */ + +/* ListMode */ +#define GL_COMPILE 0x1300 +#define GL_COMPILE_AND_EXECUTE 0x1301 + +/* ListNameType */ +/* GL_BYTE */ +/* GL_UNSIGNED_BYTE */ +/* GL_SHORT */ +/* GL_UNSIGNED_SHORT */ +/* GL_INT */ +/* GL_UNSIGNED_INT */ +/* GL_FLOAT */ +/* GL_2_BYTES */ +/* GL_3_BYTES */ +/* GL_4_BYTES */ + +/* LogicOp */ +#define GL_CLEAR 0x1500 +#define GL_AND 0x1501 +#define GL_AND_REVERSE 0x1502 +#define GL_COPY 0x1503 +#define GL_AND_INVERTED 0x1504 +#define GL_NOOP 0x1505 +#define GL_XOR 0x1506 +#define GL_OR 0x1507 +#define GL_NOR 0x1508 +#define GL_EQUIV 0x1509 +#define GL_INVERT 0x150A +#define GL_OR_REVERSE 0x150B +#define GL_COPY_INVERTED 0x150C +#define GL_OR_INVERTED 0x150D +#define GL_NAND 0x150E +#define GL_SET 0x150F + +/* MapTarget */ +/* GL_MAP1_COLOR_4 */ +/* GL_MAP1_INDEX */ +/* GL_MAP1_NORMAL */ +/* GL_MAP1_TEXTURE_COORD_1 */ +/* GL_MAP1_TEXTURE_COORD_2 */ +/* GL_MAP1_TEXTURE_COORD_3 */ +/* GL_MAP1_TEXTURE_COORD_4 */ +/* GL_MAP1_VERTEX_3 */ +/* GL_MAP1_VERTEX_4 */ +/* GL_MAP2_COLOR_4 */ +/* GL_MAP2_INDEX */ +/* GL_MAP2_NORMAL */ +/* GL_MAP2_TEXTURE_COORD_1 */ +/* GL_MAP2_TEXTURE_COORD_2 */ +/* GL_MAP2_TEXTURE_COORD_3 */ +/* GL_MAP2_TEXTURE_COORD_4 */ +/* GL_MAP2_VERTEX_3 */ +/* GL_MAP2_VERTEX_4 */ + +/* MaterialFace */ +/* GL_FRONT */ +/* GL_BACK */ +/* GL_FRONT_AND_BACK */ + +/* MaterialParameter */ +#define GL_EMISSION 0x1600 +#define GL_SHININESS 0x1601 +#define GL_AMBIENT_AND_DIFFUSE 0x1602 +#define GL_COLOR_INDEXES 0x1603 +/* GL_AMBIENT */ +/* GL_DIFFUSE */ +/* GL_SPECULAR */ + +/* MatrixMode */ +#define GL_MODELVIEW 0x1700 +#define GL_PROJECTION 0x1701 +#define GL_TEXTURE 0x1702 + +/* MeshMode1 */ +/* GL_POINT */ +/* GL_LINE */ + +/* MeshMode2 */ +/* GL_POINT */ +/* GL_LINE */ +/* GL_FILL */ + +/* MinmaxTarget */ +/* GL_MINMAX */ + +/* NormalPointerType */ +/* GL_BYTE */ +/* GL_SHORT */ +/* GL_INT */ +/* GL_FLOAT */ +/* GL_DOUBLE */ + +/* PixelCopyType */ +#define GL_COLOR 0x1800 +#define GL_DEPTH 0x1801 +#define GL_STENCIL 0x1802 + +/* PixelFormat */ +#define GL_COLOR_INDEX 0x1900 +#define GL_STENCIL_INDEX 0x1901 +#define GL_DEPTH_COMPONENT 0x1902 +#define GL_RED 0x1903 +#define GL_GREEN 0x1904 +#define GL_BLUE 0x1905 +#define GL_ALPHA 0x1906 +#define GL_RGB 0x1907 +#define GL_RGBA 0x1908 +#define GL_LUMINANCE 0x1909 +#define GL_LUMINANCE_ALPHA 0x190A +/* GL_ABGR */ + +/* PixelInternalFormat */ +/* GL_ALPHA4 */ +/* GL_ALPHA8 */ +/* GL_ALPHA12 */ +/* GL_ALPHA16 */ +/* GL_LUMINANCE4 */ +/* GL_LUMINANCE8 */ +/* GL_LUMINANCE12 */ +/* GL_LUMINANCE16 */ +/* GL_LUMINANCE4_ALPHA4 */ +/* GL_LUMINANCE6_ALPHA2 */ +/* GL_LUMINANCE8_ALPHA8 */ +/* GL_LUMINANCE12_ALPHA4 */ +/* GL_LUMINANCE12_ALPHA12 */ +/* GL_LUMINANCE16_ALPHA16 */ +/* GL_INTENSITY */ +/* GL_INTENSITY4 */ +/* GL_INTENSITY8 */ +/* GL_INTENSITY12 */ +/* GL_INTENSITY16 */ +/* GL_R3_G3_B2 */ +/* GL_RGB4 */ +/* GL_RGB5 */ +/* GL_RGB8 */ +/* GL_RGB10 */ +/* GL_RGB12 */ +/* GL_RGB16 */ +/* GL_RGBA2 */ +/* GL_RGBA4 */ +/* GL_RGB5_A1 */ +/* GL_RGBA8 */ +/* GL_RGB10_A2 */ +/* GL_RGBA12 */ +/* GL_RGBA16 */ + +/* PixelMap */ +/* GL_PIXEL_MAP_I_TO_I */ +/* GL_PIXEL_MAP_S_TO_S */ +/* GL_PIXEL_MAP_I_TO_R */ +/* GL_PIXEL_MAP_I_TO_G */ +/* GL_PIXEL_MAP_I_TO_B */ +/* GL_PIXEL_MAP_I_TO_A */ +/* GL_PIXEL_MAP_R_TO_R */ +/* GL_PIXEL_MAP_G_TO_G */ +/* GL_PIXEL_MAP_B_TO_B */ +/* GL_PIXEL_MAP_A_TO_A */ + +/* PixelStore */ +/* GL_UNPACK_SWAP_BYTES */ +/* GL_UNPACK_LSB_FIRST */ +/* GL_UNPACK_ROW_LENGTH */ +/* GL_UNPACK_SKIP_ROWS */ +/* GL_UNPACK_SKIP_PIXELS */ +/* GL_UNPACK_ALIGNMENT */ +/* GL_PACK_SWAP_BYTES */ +/* GL_PACK_LSB_FIRST */ +/* GL_PACK_ROW_LENGTH */ +/* GL_PACK_SKIP_ROWS */ +/* GL_PACK_SKIP_PIXELS */ +/* GL_PACK_ALIGNMENT */ +/* GL_PACK_SKIP_IMAGES */ +/* GL_PACK_IMAGE_HEIGHT */ +/* GL_UNPACK_SKIP_IMAGES */ +/* GL_UNPACK_IMAGE_HEIGHT */ + +/* PixelTransfer */ +/* GL_MAP_COLOR */ +/* GL_MAP_STENCIL */ +/* GL_INDEX_SHIFT */ +/* GL_INDEX_OFFSET */ +/* GL_RED_SCALE */ +/* GL_RED_BIAS */ +/* GL_GREEN_SCALE */ +/* GL_GREEN_BIAS */ +/* GL_BLUE_SCALE */ +/* GL_BLUE_BIAS */ +/* GL_ALPHA_SCALE */ +/* GL_ALPHA_BIAS */ +/* GL_DEPTH_SCALE */ +/* GL_DEPTH_BIAS */ +/* GL_POST_CONVOLUTION_RED_SCALE */ +/* GL_POST_CONVOLUTION_GREEN_SCALE */ +/* GL_POST_CONVOLUTION_BLUE_SCALE */ +/* GL_POST_CONVOLUTION_ALPHA_SCALE */ +/* GL_POST_CONVOLUTION_RED_BIAS */ +/* GL_POST_CONVOLUTION_GREEN_BIAS */ +/* GL_POST_CONVOLUTION_BLUE_BIAS */ +/* GL_POST_CONVOLUTION_ALPHA_BIAS */ +/* GL_POST_COLOR_MATRIX_RED_SCALE */ +/* GL_POST_COLOR_MATRIX_GREEN_SCALE */ +/* GL_POST_COLOR_MATRIX_BLUE_SCALE */ +/* GL_POST_COLOR_MATRIX_ALPHA_SCALE */ +/* GL_POST_COLOR_MATRIX_RED_BIAS */ +/* GL_POST_COLOR_MATRIX_GREEN_BIAS */ +/* GL_POST_COLOR_MATRIX_BLUE_BIAS */ +/* GL_POST_COLOR_MATRIX_ALPHA_BIAS */ + +/* PixelType */ +#define GL_BITMAP 0x1A00 +/* GL_BYTE */ +/* GL_UNSIGNED_BYTE */ +/* GL_SHORT */ +/* GL_UNSIGNED_SHORT */ +/* GL_INT */ +/* GL_UNSIGNED_INT */ +/* GL_FLOAT */ +/* GL_BGR */ +/* GL_BGRA */ +/* GL_UNSIGNED_BYTE_3_3_2 */ +/* GL_UNSIGNED_SHORT_4_4_4_4 */ +/* GL_UNSIGNED_SHORT_5_5_5_1 */ +/* GL_UNSIGNED_INT_8_8_8_8 */ +/* GL_UNSIGNED_INT_10_10_10_2 */ +/* GL_UNSIGNED_SHORT_5_6_5 */ +/* GL_UNSIGNED_BYTE_2_3_3_REV */ +/* GL_UNSIGNED_SHORT_5_6_5_REV */ +/* GL_UNSIGNED_SHORT_4_4_4_4_REV */ +/* GL_UNSIGNED_SHORT_1_5_5_5_REV */ +/* GL_UNSIGNED_INT_8_8_8_8_REV */ +/* GL_UNSIGNED_INT_2_10_10_10_REV */ + +/* PolygonMode */ +#define GL_POINT 0x1B00 +#define GL_LINE 0x1B01 +#define GL_FILL 0x1B02 + +/* ReadBufferMode */ +/* GL_FRONT_LEFT */ +/* GL_FRONT_RIGHT */ +/* GL_BACK_LEFT */ +/* GL_BACK_RIGHT */ +/* GL_FRONT */ +/* GL_BACK */ +/* GL_LEFT */ +/* GL_RIGHT */ +/* GL_AUX0 */ +/* GL_AUX1 */ +/* GL_AUX2 */ +/* GL_AUX3 */ + +/* RenderingMode */ +#define GL_RENDER 0x1C00 +#define GL_FEEDBACK 0x1C01 +#define GL_SELECT 0x1C02 + +/* SeparableTarget */ +/* GL_SEPARABLE_2D */ + +/* ShadingModel */ +#define GL_FLAT 0x1D00 +#define GL_SMOOTH 0x1D01 + +/* StencilFunction */ +/* GL_NEVER */ +/* GL_LESS */ +/* GL_EQUAL */ +/* GL_LEQUAL */ +/* GL_GREATER */ +/* GL_NOTEQUAL */ +/* GL_GEQUAL */ +/* GL_ALWAYS */ + +/* StencilOp */ +/* GL_ZERO */ +#define GL_KEEP 0x1E00 +#define GL_REPLACE 0x1E01 +#define GL_INCR 0x1E02 +#define GL_DECR 0x1E03 +/* GL_INVERT */ + +/* StringName */ +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 +#define GL_VERSION 0x1F02 +#define GL_EXTENSIONS 0x1F03 + +/* TextureCoordName */ +#define GL_S 0x2000 +#define GL_T 0x2001 +#define GL_R 0x2002 +#define GL_Q 0x2003 + +/* TexCoordPointerType */ +/* GL_SHORT */ +/* GL_INT */ +/* GL_FLOAT */ +/* GL_DOUBLE */ + +/* TextureEnvMode */ +#define GL_MODULATE 0x2100 +#define GL_DECAL 0x2101 +/* GL_BLEND */ +/* GL_REPLACE */ + +/* TextureEnvParameter */ +#define GL_TEXTURE_ENV_MODE 0x2200 +#define GL_TEXTURE_ENV_COLOR 0x2201 + +/* TextureEnvTarget */ +#define GL_TEXTURE_ENV 0x2300 + +/* TextureGenMode */ +#define GL_EYE_LINEAR 0x2400 +#define GL_OBJECT_LINEAR 0x2401 +#define GL_SPHERE_MAP 0x2402 + +/* TextureGenParameter */ +#define GL_TEXTURE_GEN_MODE 0x2500 +#define GL_OBJECT_PLANE 0x2501 +#define GL_EYE_PLANE 0x2502 + +/* TextureMagFilter */ +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +/* TextureMinFilter */ +/* GL_NEAREST */ +/* GL_LINEAR */ +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 + +/* TextureParameterName */ +#define GL_TEXTURE_MAG_FILTER 0x2800 +#define GL_TEXTURE_MIN_FILTER 0x2801 +#define GL_TEXTURE_WRAP_S 0x2802 +#define GL_TEXTURE_WRAP_T 0x2803 +/* GL_TEXTURE_BORDER_COLOR */ +/* GL_TEXTURE_PRIORITY */ +/* GL_TEXTURE_WRAP_R */ +/* GL_TEXTURE_MIN_LOD */ +/* GL_TEXTURE_MAX_LOD */ +/* GL_TEXTURE_BASE_LEVEL */ +/* GL_TEXTURE_MAX_LEVEL */ + +/* TextureTarget */ +/* GL_TEXTURE_1D */ +/* GL_TEXTURE_2D */ +/* GL_PROXY_TEXTURE_1D */ +/* GL_PROXY_TEXTURE_2D */ +/* GL_TEXTURE_3D */ +/* GL_PROXY_TEXTURE_3D */ + +/* TextureUnit */ +/* GL_TEXTURE0_ARB */ +/* GL_TEXTURE1_ARB */ +/* GL_TEXTURE2_ARB */ +/* GL_TEXTURE3_ARB */ +/* GL_TEXTURE4_ARB */ +/* GL_TEXTURE5_ARB */ +/* GL_TEXTURE6_ARB */ +/* GL_TEXTURE7_ARB */ +/* GL_TEXTURE8_ARB */ +/* GL_TEXTURE9_ARB */ +/* GL_TEXTURE10_ARB */ +/* GL_TEXTURE11_ARB */ +/* GL_TEXTURE12_ARB */ +/* GL_TEXTURE13_ARB */ +/* GL_TEXTURE14_ARB */ +/* GL_TEXTURE15_ARB */ +/* GL_TEXTURE16_ARB */ +/* GL_TEXTURE17_ARB */ +/* GL_TEXTURE18_ARB */ +/* GL_TEXTURE19_ARB */ +/* GL_TEXTURE20_ARB */ +/* GL_TEXTURE21_ARB */ +/* GL_TEXTURE22_ARB */ +/* GL_TEXTURE23_ARB */ +/* GL_TEXTURE24_ARB */ +/* GL_TEXTURE25_ARB */ +/* GL_TEXTURE26_ARB */ +/* GL_TEXTURE27_ARB */ +/* GL_TEXTURE28_ARB */ +/* GL_TEXTURE29_ARB */ +/* GL_TEXTURE30_ARB */ +/* GL_TEXTURE31_ARB */ + +/* TextureWrapMode */ +#define GL_CLAMP 0x2900 +#define GL_REPEAT 0x2901 +/* GL_CLAMP_TO_EDGE */ + +/* VertexPointerType */ +/* GL_SHORT */ +/* GL_INT */ +/* GL_FLOAT */ +/* GL_DOUBLE */ + +/* ClientAttribMask */ +#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001 +#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002 +#define GL_CLIENT_ALL_ATTRIB_BITS 0xffffffff + +/* polygon_offset */ +#define GL_POLYGON_OFFSET_FACTOR 0x8038 +#define GL_POLYGON_OFFSET_UNITS 0x2A00 +#define GL_POLYGON_OFFSET_POINT 0x2A01 +#define GL_POLYGON_OFFSET_LINE 0x2A02 +#define GL_POLYGON_OFFSET_FILL 0x8037 + +/* texture */ +#define GL_ALPHA4 0x803B +#define GL_ALPHA8 0x803C +#define GL_ALPHA12 0x803D +#define GL_ALPHA16 0x803E +#define GL_LUMINANCE4 0x803F +#define GL_LUMINANCE8 0x8040 +#define GL_LUMINANCE12 0x8041 +#define GL_LUMINANCE16 0x8042 +#define GL_LUMINANCE4_ALPHA4 0x8043 +#define GL_LUMINANCE6_ALPHA2 0x8044 +#define GL_LUMINANCE8_ALPHA8 0x8045 +#define GL_LUMINANCE12_ALPHA4 0x8046 +#define GL_LUMINANCE12_ALPHA12 0x8047 +#define GL_LUMINANCE16_ALPHA16 0x8048 +#define GL_INTENSITY 0x8049 +#define GL_INTENSITY4 0x804A +#define GL_INTENSITY8 0x804B +#define GL_INTENSITY12 0x804C +#define GL_INTENSITY16 0x804D +#define GL_R3_G3_B2 0x2A10 +#define GL_RGB4 0x804F +#define GL_RGB5 0x8050 +#define GL_RGB8 0x8051 +#define GL_RGB10 0x8052 +#define GL_RGB12 0x8053 +#define GL_RGB16 0x8054 +#define GL_RGBA2 0x8055 +#define GL_RGBA4 0x8056 +#define GL_RGB5_A1 0x8057 +#define GL_RGBA8 0x8058 +#define GL_RGB10_A2 0x8059 +#define GL_RGBA12 0x805A +#define GL_RGBA16 0x805B +#define GL_TEXTURE_RED_SIZE 0x805C +#define GL_TEXTURE_GREEN_SIZE 0x805D +#define GL_TEXTURE_BLUE_SIZE 0x805E +#define GL_TEXTURE_ALPHA_SIZE 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE 0x8061 +#define GL_PROXY_TEXTURE_1D 0x8063 +#define GL_PROXY_TEXTURE_2D 0x8064 + +/* texture_object */ +#define GL_TEXTURE_PRIORITY 0x8066 +#define GL_TEXTURE_RESIDENT 0x8067 +#define GL_TEXTURE_BINDING_1D 0x8068 +#define GL_TEXTURE_BINDING_2D 0x8069 +#define GL_TEXTURE_BINDING_3D 0x806A + +/* vertex_array */ +#define GL_VERTEX_ARRAY 0x8074 +#define GL_NORMAL_ARRAY 0x8075 +#define GL_COLOR_ARRAY 0x8076 +#define GL_INDEX_ARRAY 0x8077 +#define GL_TEXTURE_COORD_ARRAY 0x8078 +#define GL_EDGE_FLAG_ARRAY 0x8079 +#define GL_VERTEX_ARRAY_SIZE 0x807A +#define GL_VERTEX_ARRAY_TYPE 0x807B +#define GL_VERTEX_ARRAY_STRIDE 0x807C +#define GL_NORMAL_ARRAY_TYPE 0x807E +#define GL_NORMAL_ARRAY_STRIDE 0x807F +#define GL_COLOR_ARRAY_SIZE 0x8081 +#define GL_COLOR_ARRAY_TYPE 0x8082 +#define GL_COLOR_ARRAY_STRIDE 0x8083 +#define GL_INDEX_ARRAY_TYPE 0x8085 +#define GL_INDEX_ARRAY_STRIDE 0x8086 +#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A +#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C +#define GL_VERTEX_ARRAY_POINTER 0x808E +#define GL_NORMAL_ARRAY_POINTER 0x808F +#define GL_COLOR_ARRAY_POINTER 0x8090 +#define GL_INDEX_ARRAY_POINTER 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093 +#define GL_V2F 0x2A20 +#define GL_V3F 0x2A21 +#define GL_C4UB_V2F 0x2A22 +#define GL_C4UB_V3F 0x2A23 +#define GL_C3F_V3F 0x2A24 +#define GL_N3F_V3F 0x2A25 +#define GL_C4F_N3F_V3F 0x2A26 +#define GL_T2F_V3F 0x2A27 +#define GL_T4F_V4F 0x2A28 +#define GL_T2F_C4UB_V3F 0x2A29 +#define GL_T2F_C3F_V3F 0x2A2A +#define GL_T2F_N3F_V3F 0x2A2B +#define GL_T2F_C4F_N3F_V3F 0x2A2C +#define GL_T4F_C4F_N3F_V4F 0x2A2D + +/* bgra */ +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 + +/* blend_color */ +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 + +/* blend_minmax */ +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 + +/* blend_subtract */ +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B + +/* color_matrix */ +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB + +/* color_table */ +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF + +/* convolution */ +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 + +/* draw_range_elements */ +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 + +/* histogram */ +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 + +/* packed_pixels */ +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 + +/* rescale_normal */ +#define GL_RESCALE_NORMAL 0x803A + +/* separate_specular_color */ +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA + +/* texture3D */ +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 + +/* texture_edge_clamp */ +#define GL_CLAMP_TO_EDGE 0x812F + +/* texture_lod */ +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D + +/* GetTarget1_2 */ +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E + +/* multitexture */ +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 + +/* Extensions */ +#define GL_EXT_abgr 1 +#define GL_EXT_blend_color 1 +#define GL_EXT_blend_minmax 1 +#define GL_EXT_blend_subtract 1 +#define GL_EXT_texture_env_combine 1 +#define GL_EXT_texture_env_add 1 + +/* EXT_abgr */ +#define GL_ABGR_EXT 0x8000 + +/* EXT_blend_color */ +#define GL_CONSTANT_COLOR_EXT 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 +#define GL_CONSTANT_ALPHA_EXT 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 +#define GL_BLEND_COLOR_EXT 0x8005 + +/* EXT_blend_minmax */ +#define GL_FUNC_ADD_EXT 0x8006 +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#define GL_BLEND_EQUATION_EXT 0x8009 + +/* EXT_blend_subtract */ +#define GL_FUNC_SUBTRACT_EXT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B + +/* EXT_texture_env_combine */ +#define GL_COMBINE_EXT 0x8570 +#define GL_COMBINE_RGB_EXT 0x8571 +#define GL_COMBINE_ALPHA_EXT 0x8572 +#define GL_RGB_SCALE_EXT 0x8573 +#define GL_ADD_SIGNED_EXT 0x8574 +#define GL_INTERPOLATE_EXT 0x8575 +#define GL_CONSTANT_EXT 0x8576 +#define GL_PRIMARY_COLOR_EXT 0x8577 +#define GL_PREVIOUS_EXT 0x8578 +#define GL_SOURCE0_RGB_EXT 0x8580 +#define GL_SOURCE1_RGB_EXT 0x8581 +#define GL_SOURCE2_RGB_EXT 0x8582 +#define GL_SOURCE0_ALPHA_EXT 0x8588 +#define GL_SOURCE1_ALPHA_EXT 0x8589 +#define GL_SOURCE2_ALPHA_EXT 0x858A +#define GL_OPERAND0_RGB_EXT 0x8590 +#define GL_OPERAND1_RGB_EXT 0x8591 +#define GL_OPERAND2_RGB_EXT 0x8592 +#define GL_OPERAND0_ALPHA_EXT 0x8598 +#define GL_OPERAND1_ALPHA_EXT 0x8599 +#define GL_OPERAND2_ALPHA_EXT 0x859A + +/* For compatibility with OpenGL v1.0 */ +#define GL_LOGIC_OP GL_INDEX_LOGIC_OP +#define GL_TEXTURE_COMPONENTS GL_TEXTURE_INTERNAL_FORMAT + +/*************************************************************/ + +WINGDIAPI void APIENTRY glAccum (GLenum op, GLfloat value); +WINGDIAPI void APIENTRY glAlphaFunc (GLenum func, GLclampf ref); +WINGDIAPI GLboolean APIENTRY glAreTexturesResident (GLsizei n, const GLuint *textures, GLboolean *residences); +WINGDIAPI void APIENTRY glArrayElement (GLint i); +WINGDIAPI void APIENTRY glBegin (GLenum mode); +WINGDIAPI void APIENTRY glBindTexture (GLenum target, GLuint texture); +WINGDIAPI void APIENTRY glBitmap (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap); +WINGDIAPI void APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +WINGDIAPI void APIENTRY glCallList (GLuint list); +WINGDIAPI void APIENTRY glCallLists (GLsizei n, GLenum type, const GLvoid *lists); +WINGDIAPI void APIENTRY glClear (GLbitfield mask); +WINGDIAPI void APIENTRY glClearAccum (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +WINGDIAPI void APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +WINGDIAPI void APIENTRY glClearDepth (GLclampd depth); +WINGDIAPI void APIENTRY glClearIndex (GLfloat c); +WINGDIAPI void APIENTRY glClearStencil (GLint s); +WINGDIAPI void APIENTRY glClipPlane (GLenum plane, const GLdouble *equation); +WINGDIAPI void APIENTRY glColor3b (GLbyte red, GLbyte green, GLbyte blue); +WINGDIAPI void APIENTRY glColor3bv (const GLbyte *v); +WINGDIAPI void APIENTRY glColor3d (GLdouble red, GLdouble green, GLdouble blue); +WINGDIAPI void APIENTRY glColor3dv (const GLdouble *v); +WINGDIAPI void APIENTRY glColor3f (GLfloat red, GLfloat green, GLfloat blue); +WINGDIAPI void APIENTRY glColor3fv (const GLfloat *v); +WINGDIAPI void APIENTRY glColor3i (GLint red, GLint green, GLint blue); +WINGDIAPI void APIENTRY glColor3iv (const GLint *v); +WINGDIAPI void APIENTRY glColor3s (GLshort red, GLshort green, GLshort blue); +WINGDIAPI void APIENTRY glColor3sv (const GLshort *v); +WINGDIAPI void APIENTRY glColor3ub (GLubyte red, GLubyte green, GLubyte blue); +WINGDIAPI void APIENTRY glColor3ubv (const GLubyte *v); +WINGDIAPI void APIENTRY glColor3ui (GLuint red, GLuint green, GLuint blue); +WINGDIAPI void APIENTRY glColor3uiv (const GLuint *v); +WINGDIAPI void APIENTRY glColor3us (GLushort red, GLushort green, GLushort blue); +WINGDIAPI void APIENTRY glColor3usv (const GLushort *v); +WINGDIAPI void APIENTRY glColor4b (GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha); +WINGDIAPI void APIENTRY glColor4bv (const GLbyte *v); +WINGDIAPI void APIENTRY glColor4d (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha); +WINGDIAPI void APIENTRY glColor4dv (const GLdouble *v); +WINGDIAPI void APIENTRY glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +WINGDIAPI void APIENTRY glColor4fv (const GLfloat *v); +WINGDIAPI void APIENTRY glColor4i (GLint red, GLint green, GLint blue, GLint alpha); +WINGDIAPI void APIENTRY glColor4iv (const GLint *v); +WINGDIAPI void APIENTRY glColor4s (GLshort red, GLshort green, GLshort blue, GLshort alpha); +WINGDIAPI void APIENTRY glColor4sv (const GLshort *v); +WINGDIAPI void APIENTRY glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +WINGDIAPI void APIENTRY glColor4ubv (const GLubyte *v); +WINGDIAPI void APIENTRY glColor4ui (GLuint red, GLuint green, GLuint blue, GLuint alpha); +WINGDIAPI void APIENTRY glColor4uiv (const GLuint *v); +WINGDIAPI void APIENTRY glColor4us (GLushort red, GLushort green, GLushort blue, GLushort alpha); +WINGDIAPI void APIENTRY glColor4usv (const GLushort *v); +WINGDIAPI void APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +WINGDIAPI void APIENTRY glColorMaterial (GLenum face, GLenum mode); +WINGDIAPI void APIENTRY glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glCopyPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type); +WINGDIAPI void APIENTRY glCopyTexImage1D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +WINGDIAPI void APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +WINGDIAPI void APIENTRY glCopyTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +WINGDIAPI void APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +WINGDIAPI void APIENTRY glCullFace (GLenum mode); +WINGDIAPI void APIENTRY glDeleteLists (GLuint list, GLsizei range); +WINGDIAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); +WINGDIAPI void APIENTRY glDepthFunc (GLenum func); +WINGDIAPI void APIENTRY glDepthMask (GLboolean flag); +WINGDIAPI void APIENTRY glDepthRange (GLclampd zNear, GLclampd zFar); +WINGDIAPI void APIENTRY glDisable (GLenum cap); +WINGDIAPI void APIENTRY glDisableClientState (GLenum array); +WINGDIAPI void APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +WINGDIAPI void APIENTRY glDrawBuffer (GLenum mode); +WINGDIAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); +WINGDIAPI void APIENTRY glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glEdgeFlag (GLboolean flag); +WINGDIAPI void APIENTRY glEdgeFlagPointer (GLsizei stride, const GLboolean *pointer); +WINGDIAPI void APIENTRY glEdgeFlagv (const GLboolean *flag); +WINGDIAPI void APIENTRY glEnable (GLenum cap); +WINGDIAPI void APIENTRY glEnableClientState (GLenum array); +WINGDIAPI void APIENTRY glEnd (void); +WINGDIAPI void APIENTRY glEndList (void); +WINGDIAPI void APIENTRY glEvalCoord1d (GLdouble u); +WINGDIAPI void APIENTRY glEvalCoord1dv (const GLdouble *u); +WINGDIAPI void APIENTRY glEvalCoord1f (GLfloat u); +WINGDIAPI void APIENTRY glEvalCoord1fv (const GLfloat *u); +WINGDIAPI void APIENTRY glEvalCoord2d (GLdouble u, GLdouble v); +WINGDIAPI void APIENTRY glEvalCoord2dv (const GLdouble *u); +WINGDIAPI void APIENTRY glEvalCoord2f (GLfloat u, GLfloat v); +WINGDIAPI void APIENTRY glEvalCoord2fv (const GLfloat *u); +WINGDIAPI void APIENTRY glEvalMesh1 (GLenum mode, GLint i1, GLint i2); +WINGDIAPI void APIENTRY glEvalMesh2 (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2); +WINGDIAPI void APIENTRY glEvalPoint1 (GLint i); +WINGDIAPI void APIENTRY glEvalPoint2 (GLint i, GLint j); +WINGDIAPI void APIENTRY glFeedbackBuffer (GLsizei size, GLenum type, GLfloat *buffer); +WINGDIAPI void APIENTRY glFinish (void); +WINGDIAPI void APIENTRY glFlush (void); +WINGDIAPI void APIENTRY glFogf (GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glFogfv (GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glFogi (GLenum pname, GLint param); +WINGDIAPI void APIENTRY glFogiv (GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glFrontFace (GLenum mode); +WINGDIAPI void APIENTRY glFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +WINGDIAPI GLuint APIENTRY glGenLists (GLsizei range); +WINGDIAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures); +WINGDIAPI void APIENTRY glGetBooleanv (GLenum pname, GLboolean *params); +WINGDIAPI void APIENTRY glGetClipPlane (GLenum plane, GLdouble *equation); +WINGDIAPI void APIENTRY glGetDoublev (GLenum pname, GLdouble *params); +WINGDIAPI GLenum APIENTRY glGetError (void); +WINGDIAPI void APIENTRY glGetFloatv (GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetLightfv (GLenum light, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetLightiv (GLenum light, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetMapdv (GLenum target, GLenum query, GLdouble *v); +WINGDIAPI void APIENTRY glGetMapfv (GLenum target, GLenum query, GLfloat *v); +WINGDIAPI void APIENTRY glGetMapiv (GLenum target, GLenum query, GLint *v); +WINGDIAPI void APIENTRY glGetMaterialfv (GLenum face, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetMaterialiv (GLenum face, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetPixelMapfv (GLenum map, GLfloat *values); +WINGDIAPI void APIENTRY glGetPixelMapuiv (GLenum map, GLuint *values); +WINGDIAPI void APIENTRY glGetPixelMapusv (GLenum map, GLushort *values); +WINGDIAPI void APIENTRY glGetPointerv (GLenum pname, GLvoid* *params); +WINGDIAPI void APIENTRY glGetPolygonStipple (GLubyte *mask); +WINGDIAPI const GLubyte * APIENTRY glGetString (GLenum name); +WINGDIAPI void APIENTRY glGetTexEnvfv (GLenum target, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexEnviv (GLenum target, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetTexGendv (GLenum coord, GLenum pname, GLdouble *params); +WINGDIAPI void APIENTRY glGetTexGenfv (GLenum coord, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexGeniv (GLenum coord, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetTexImage (GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels); +WINGDIAPI void APIENTRY glGetTexLevelParameterfv (GLenum target, GLint level, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexLevelParameteriv (GLenum target, GLint level, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params); +WINGDIAPI void APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params); +WINGDIAPI void APIENTRY glHint (GLenum target, GLenum mode); +WINGDIAPI void APIENTRY glIndexMask (GLuint mask); +WINGDIAPI void APIENTRY glIndexPointer (GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glIndexd (GLdouble c); +WINGDIAPI void APIENTRY glIndexdv (const GLdouble *c); +WINGDIAPI void APIENTRY glIndexf (GLfloat c); +WINGDIAPI void APIENTRY glIndexfv (const GLfloat *c); +WINGDIAPI void APIENTRY glIndexi (GLint c); +WINGDIAPI void APIENTRY glIndexiv (const GLint *c); +WINGDIAPI void APIENTRY glIndexs (GLshort c); +WINGDIAPI void APIENTRY glIndexsv (const GLshort *c); +WINGDIAPI void APIENTRY glIndexub (GLubyte c); +WINGDIAPI void APIENTRY glIndexubv (const GLubyte *c); +WINGDIAPI void APIENTRY glInitNames (void); +WINGDIAPI void APIENTRY glInterleavedArrays (GLenum format, GLsizei stride, const GLvoid *pointer); +WINGDIAPI GLboolean APIENTRY glIsEnabled (GLenum cap); +WINGDIAPI GLboolean APIENTRY glIsList (GLuint list); +WINGDIAPI GLboolean APIENTRY glIsTexture (GLuint texture); +WINGDIAPI void APIENTRY glLightModelf (GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glLightModelfv (GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glLightModeli (GLenum pname, GLint param); +WINGDIAPI void APIENTRY glLightModeliv (GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glLightf (GLenum light, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glLightfv (GLenum light, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glLighti (GLenum light, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glLightiv (GLenum light, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glLineStipple (GLint factor, GLushort pattern); +WINGDIAPI void APIENTRY glLineWidth (GLfloat width); +WINGDIAPI void APIENTRY glListBase (GLuint base); +WINGDIAPI void APIENTRY glLoadIdentity (void); +WINGDIAPI void APIENTRY glLoadMatrixd (const GLdouble *m); +WINGDIAPI void APIENTRY glLoadMatrixf (const GLfloat *m); +WINGDIAPI void APIENTRY glLoadName (GLuint name); +WINGDIAPI void APIENTRY glLogicOp (GLenum opcode); +WINGDIAPI void APIENTRY glMap1d (GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points); +WINGDIAPI void APIENTRY glMap1f (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points); +WINGDIAPI void APIENTRY glMap2d (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points); +WINGDIAPI void APIENTRY glMap2f (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points); +WINGDIAPI void APIENTRY glMapGrid1d (GLint un, GLdouble u1, GLdouble u2); +WINGDIAPI void APIENTRY glMapGrid1f (GLint un, GLfloat u1, GLfloat u2); +WINGDIAPI void APIENTRY glMapGrid2d (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2); +WINGDIAPI void APIENTRY glMapGrid2f (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2); +WINGDIAPI void APIENTRY glMaterialf (GLenum face, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glMaterialfv (GLenum face, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glMateriali (GLenum face, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glMaterialiv (GLenum face, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glMatrixMode (GLenum mode); +WINGDIAPI void APIENTRY glMultMatrixd (const GLdouble *m); +WINGDIAPI void APIENTRY glMultMatrixf (const GLfloat *m); +WINGDIAPI void APIENTRY glNewList (GLuint list, GLenum mode); +WINGDIAPI void APIENTRY glNormal3b (GLbyte nx, GLbyte ny, GLbyte nz); +WINGDIAPI void APIENTRY glNormal3bv (const GLbyte *v); +WINGDIAPI void APIENTRY glNormal3d (GLdouble nx, GLdouble ny, GLdouble nz); +WINGDIAPI void APIENTRY glNormal3dv (const GLdouble *v); +WINGDIAPI void APIENTRY glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz); +WINGDIAPI void APIENTRY glNormal3fv (const GLfloat *v); +WINGDIAPI void APIENTRY glNormal3i (GLint nx, GLint ny, GLint nz); +WINGDIAPI void APIENTRY glNormal3iv (const GLint *v); +WINGDIAPI void APIENTRY glNormal3s (GLshort nx, GLshort ny, GLshort nz); +WINGDIAPI void APIENTRY glNormal3sv (const GLshort *v); +WINGDIAPI void APIENTRY glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar); +WINGDIAPI void APIENTRY glPassThrough (GLfloat token); +WINGDIAPI void APIENTRY glPixelMapfv (GLenum map, GLint mapsize, const GLfloat *values); +WINGDIAPI void APIENTRY glPixelMapuiv (GLenum map, GLint mapsize, const GLuint *values); +WINGDIAPI void APIENTRY glPixelMapusv (GLenum map, GLint mapsize, const GLushort *values); +WINGDIAPI void APIENTRY glPixelStoref (GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glPixelStorei (GLenum pname, GLint param); +WINGDIAPI void APIENTRY glPixelTransferf (GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glPixelTransferi (GLenum pname, GLint param); +WINGDIAPI void APIENTRY glPixelZoom (GLfloat xfactor, GLfloat yfactor); +WINGDIAPI void APIENTRY glPointSize (GLfloat size); +WINGDIAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode); +WINGDIAPI void APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); +WINGDIAPI void APIENTRY glPolygonStipple (const GLubyte *mask); +WINGDIAPI void APIENTRY glPopAttrib (void); +WINGDIAPI void APIENTRY glPopClientAttrib (void); +WINGDIAPI void APIENTRY glPopMatrix (void); +WINGDIAPI void APIENTRY glPopName (void); +WINGDIAPI void APIENTRY glPrioritizeTextures (GLsizei n, const GLuint *textures, const GLclampf *priorities); +WINGDIAPI void APIENTRY glPushAttrib (GLbitfield mask); +WINGDIAPI void APIENTRY glPushClientAttrib (GLbitfield mask); +WINGDIAPI void APIENTRY glPushMatrix (void); +WINGDIAPI void APIENTRY glPushName (GLuint name); +WINGDIAPI void APIENTRY glRasterPos2d (GLdouble x, GLdouble y); +WINGDIAPI void APIENTRY glRasterPos2dv (const GLdouble *v); +WINGDIAPI void APIENTRY glRasterPos2f (GLfloat x, GLfloat y); +WINGDIAPI void APIENTRY glRasterPos2fv (const GLfloat *v); +WINGDIAPI void APIENTRY glRasterPos2i (GLint x, GLint y); +WINGDIAPI void APIENTRY glRasterPos2iv (const GLint *v); +WINGDIAPI void APIENTRY glRasterPos2s (GLshort x, GLshort y); +WINGDIAPI void APIENTRY glRasterPos2sv (const GLshort *v); +WINGDIAPI void APIENTRY glRasterPos3d (GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glRasterPos3dv (const GLdouble *v); +WINGDIAPI void APIENTRY glRasterPos3f (GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glRasterPos3fv (const GLfloat *v); +WINGDIAPI void APIENTRY glRasterPos3i (GLint x, GLint y, GLint z); +WINGDIAPI void APIENTRY glRasterPos3iv (const GLint *v); +WINGDIAPI void APIENTRY glRasterPos3s (GLshort x, GLshort y, GLshort z); +WINGDIAPI void APIENTRY glRasterPos3sv (const GLshort *v); +WINGDIAPI void APIENTRY glRasterPos4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +WINGDIAPI void APIENTRY glRasterPos4dv (const GLdouble *v); +WINGDIAPI void APIENTRY glRasterPos4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +WINGDIAPI void APIENTRY glRasterPos4fv (const GLfloat *v); +WINGDIAPI void APIENTRY glRasterPos4i (GLint x, GLint y, GLint z, GLint w); +WINGDIAPI void APIENTRY glRasterPos4iv (const GLint *v); +WINGDIAPI void APIENTRY glRasterPos4s (GLshort x, GLshort y, GLshort z, GLshort w); +WINGDIAPI void APIENTRY glRasterPos4sv (const GLshort *v); +WINGDIAPI void APIENTRY glReadBuffer (GLenum mode); +WINGDIAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); +WINGDIAPI void APIENTRY glRectd (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2); +WINGDIAPI void APIENTRY glRectdv (const GLdouble *v1, const GLdouble *v2); +WINGDIAPI void APIENTRY glRectf (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2); +WINGDIAPI void APIENTRY glRectfv (const GLfloat *v1, const GLfloat *v2); +WINGDIAPI void APIENTRY glRecti (GLint x1, GLint y1, GLint x2, GLint y2); +WINGDIAPI void APIENTRY glRectiv (const GLint *v1, const GLint *v2); +WINGDIAPI void APIENTRY glRects (GLshort x1, GLshort y1, GLshort x2, GLshort y2); +WINGDIAPI void APIENTRY glRectsv (const GLshort *v1, const GLshort *v2); +WINGDIAPI GLint APIENTRY glRenderMode (GLenum mode); +WINGDIAPI void APIENTRY glRotated (GLdouble angle, GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glScaled (GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glScalef (GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height); +WINGDIAPI void APIENTRY glSelectBuffer (GLsizei size, GLuint *buffer); +WINGDIAPI void APIENTRY glShadeModel (GLenum mode); +WINGDIAPI void APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +WINGDIAPI void APIENTRY glStencilMask (GLuint mask); +WINGDIAPI void APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); +WINGDIAPI void APIENTRY glTexCoord1d (GLdouble s); +WINGDIAPI void APIENTRY glTexCoord1dv (const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord1f (GLfloat s); +WINGDIAPI void APIENTRY glTexCoord1fv (const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord1i (GLint s); +WINGDIAPI void APIENTRY glTexCoord1iv (const GLint *v); +WINGDIAPI void APIENTRY glTexCoord1s (GLshort s); +WINGDIAPI void APIENTRY glTexCoord1sv (const GLshort *v); +WINGDIAPI void APIENTRY glTexCoord2d (GLdouble s, GLdouble t); +WINGDIAPI void APIENTRY glTexCoord2dv (const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord2f (GLfloat s, GLfloat t); +WINGDIAPI void APIENTRY glTexCoord2fv (const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord2i (GLint s, GLint t); +WINGDIAPI void APIENTRY glTexCoord2iv (const GLint *v); +WINGDIAPI void APIENTRY glTexCoord2s (GLshort s, GLshort t); +WINGDIAPI void APIENTRY glTexCoord2sv (const GLshort *v); +WINGDIAPI void APIENTRY glTexCoord3d (GLdouble s, GLdouble t, GLdouble r); +WINGDIAPI void APIENTRY glTexCoord3dv (const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord3f (GLfloat s, GLfloat t, GLfloat r); +WINGDIAPI void APIENTRY glTexCoord3fv (const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord3i (GLint s, GLint t, GLint r); +WINGDIAPI void APIENTRY glTexCoord3iv (const GLint *v); +WINGDIAPI void APIENTRY glTexCoord3s (GLshort s, GLshort t, GLshort r); +WINGDIAPI void APIENTRY glTexCoord3sv (const GLshort *v); +WINGDIAPI void APIENTRY glTexCoord4d (GLdouble s, GLdouble t, GLdouble r, GLdouble q); +WINGDIAPI void APIENTRY glTexCoord4dv (const GLdouble *v); +WINGDIAPI void APIENTRY glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q); +WINGDIAPI void APIENTRY glTexCoord4fv (const GLfloat *v); +WINGDIAPI void APIENTRY glTexCoord4i (GLint s, GLint t, GLint r, GLint q); +WINGDIAPI void APIENTRY glTexCoord4iv (const GLint *v); +WINGDIAPI void APIENTRY glTexCoord4s (GLshort s, GLshort t, GLshort r, GLshort q); +WINGDIAPI void APIENTRY glTexCoord4sv (const GLshort *v); +WINGDIAPI void APIENTRY glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glTexEnvf (GLenum target, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glTexEnvfv (GLenum target, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glTexEnvi (GLenum target, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glTexEnviv (GLenum target, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glTexGend (GLenum coord, GLenum pname, GLdouble param); +WINGDIAPI void APIENTRY glTexGendv (GLenum coord, GLenum pname, const GLdouble *params); +WINGDIAPI void APIENTRY glTexGenf (GLenum coord, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glTexGenfv (GLenum coord, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glTexGeni (GLenum coord, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glTexGeniv (GLenum coord, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glTexImage1D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param); +WINGDIAPI void APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params); +WINGDIAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); +WINGDIAPI void APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params); +WINGDIAPI void APIENTRY glTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +WINGDIAPI void APIENTRY glTranslated (GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glTranslatef (GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glVertex2d (GLdouble x, GLdouble y); +WINGDIAPI void APIENTRY glVertex2dv (const GLdouble *v); +WINGDIAPI void APIENTRY glVertex2f (GLfloat x, GLfloat y); +WINGDIAPI void APIENTRY glVertex2fv (const GLfloat *v); +WINGDIAPI void APIENTRY glVertex2i (GLint x, GLint y); +WINGDIAPI void APIENTRY glVertex2iv (const GLint *v); +WINGDIAPI void APIENTRY glVertex2s (GLshort x, GLshort y); +WINGDIAPI void APIENTRY glVertex2sv (const GLshort *v); +WINGDIAPI void APIENTRY glVertex3d (GLdouble x, GLdouble y, GLdouble z); +WINGDIAPI void APIENTRY glVertex3dv (const GLdouble *v); +WINGDIAPI void APIENTRY glVertex3f (GLfloat x, GLfloat y, GLfloat z); +WINGDIAPI void APIENTRY glVertex3fv (const GLfloat *v); +WINGDIAPI void APIENTRY glVertex3i (GLint x, GLint y, GLint z); +WINGDIAPI void APIENTRY glVertex3iv (const GLint *v); +WINGDIAPI void APIENTRY glVertex3s (GLshort x, GLshort y, GLshort z); +WINGDIAPI void APIENTRY glVertex3sv (const GLshort *v); +WINGDIAPI void APIENTRY glVertex4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +WINGDIAPI void APIENTRY glVertex4dv (const GLdouble *v); +WINGDIAPI void APIENTRY glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +WINGDIAPI void APIENTRY glVertex4fv (const GLfloat *v); +WINGDIAPI void APIENTRY glVertex4i (GLint x, GLint y, GLint z, GLint w); +WINGDIAPI void APIENTRY glVertex4iv (const GLint *v); +WINGDIAPI void APIENTRY glVertex4s (GLshort x, GLshort y, GLshort z, GLshort w); +WINGDIAPI void APIENTRY glVertex4sv (const GLshort *v); +WINGDIAPI void APIENTRY glVertexPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +WINGDIAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +#ifdef __cplusplus +} +#endif + +#endif /* __gl_h_ */ diff --git a/Runtime/GfxDevice/opengl/unity_glext.h b/Runtime/GfxDevice/opengl/unity_glext.h new file mode 100644 index 0000000..b048ad8 --- /dev/null +++ b/Runtime/GfxDevice/opengl/unity_glext.h @@ -0,0 +1,6704 @@ +#ifndef __glext_h_ +#define __glext_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2004 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: This software was created using the +** OpenGL(R) version 1.2.1 Sample Implementation published by SGI, but has +** not been independently verified as being compliant with the OpenGL(R) +** version 1.2.1 Specification. +*/ + +#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) +#define WIN32_LEAN_AND_MEAN 1 +#include <windows.h> +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif +#ifndef GLAPI +#define GLAPI extern +#endif + +/*************************************************************/ + +/* Header file version number, required by OpenGL ABI for Linux */ +/* glext.h last updated 2005/06/20 */ +/* Current version at http://oss.sgi.com/projects/ogl-sample/registry/ */ +#define GL_GLEXT_VERSION 29 + +#ifndef GL_VERSION_1_2 +#define GL_UNSIGNED_BYTE_3_3_2 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2 0x8036 +#define GL_RESCALE_NORMAL 0x803A +#define GL_TEXTURE_BINDING_3D 0x806A +#define GL_PACK_SKIP_IMAGES 0x806B +#define GL_PACK_IMAGE_HEIGHT 0x806C +#define GL_UNPACK_SKIP_IMAGES 0x806D +#define GL_UNPACK_IMAGE_HEIGHT 0x806E +#define GL_TEXTURE_3D 0x806F +#define GL_PROXY_TEXTURE_3D 0x8070 +#define GL_TEXTURE_DEPTH 0x8071 +#define GL_TEXTURE_WRAP_R 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE 0x8073 +#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362 +#define GL_UNSIGNED_SHORT_5_6_5 0x8363 +#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364 +#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365 +#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366 +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#define GL_BGR 0x80E0 +#define GL_BGRA 0x80E1 +#define GL_MAX_ELEMENTS_VERTICES 0x80E8 +#define GL_MAX_ELEMENTS_INDICES 0x80E9 +#define GL_CLAMP_TO_EDGE 0x812F +#define GL_TEXTURE_MIN_LOD 0x813A +#define GL_TEXTURE_MAX_LOD 0x813B +#define GL_TEXTURE_BASE_LEVEL 0x813C +#define GL_TEXTURE_MAX_LEVEL 0x813D +#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8 +#define GL_SINGLE_COLOR 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR 0x81FA +#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12 +#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13 +#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22 +#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23 +#define GL_ALIASED_POINT_SIZE_RANGE 0x846D +#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E +#endif + +#ifndef GL_ARB_imaging +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 +#define GL_BLEND_COLOR 0x8005 +#define GL_FUNC_ADD 0x8006 +#define GL_MIN 0x8007 +#define GL_MAX 0x8008 +#define GL_BLEND_EQUATION 0x8009 +#define GL_FUNC_SUBTRACT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT 0x800B +#define GL_CONVOLUTION_1D 0x8010 +#define GL_CONVOLUTION_2D 0x8011 +#define GL_SEPARABLE_2D 0x8012 +#define GL_CONVOLUTION_BORDER_MODE 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS 0x8015 +#define GL_REDUCE 0x8016 +#define GL_CONVOLUTION_FORMAT 0x8017 +#define GL_CONVOLUTION_WIDTH 0x8018 +#define GL_CONVOLUTION_HEIGHT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023 +#define GL_HISTOGRAM 0x8024 +#define GL_PROXY_HISTOGRAM 0x8025 +#define GL_HISTOGRAM_WIDTH 0x8026 +#define GL_HISTOGRAM_FORMAT 0x8027 +#define GL_HISTOGRAM_RED_SIZE 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C +#define GL_HISTOGRAM_SINK 0x802D +#define GL_MINMAX 0x802E +#define GL_MINMAX_FORMAT 0x802F +#define GL_MINMAX_SINK 0x8030 +#define GL_TABLE_TOO_LARGE 0x8031 +#define GL_COLOR_MATRIX 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB +#define GL_COLOR_TABLE 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2 +#define GL_PROXY_COLOR_TABLE 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5 +#define GL_COLOR_TABLE_SCALE 0x80D6 +#define GL_COLOR_TABLE_BIAS 0x80D7 +#define GL_COLOR_TABLE_FORMAT 0x80D8 +#define GL_COLOR_TABLE_WIDTH 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF +#define GL_CONSTANT_BORDER 0x8151 +#define GL_REPLICATE_BORDER 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR 0x8154 +#endif + +#ifndef GL_VERSION_1_3 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_TEXTURE3 0x84C3 +#define GL_TEXTURE4 0x84C4 +#define GL_TEXTURE5 0x84C5 +#define GL_TEXTURE6 0x84C6 +#define GL_TEXTURE7 0x84C7 +#define GL_TEXTURE8 0x84C8 +#define GL_TEXTURE9 0x84C9 +#define GL_TEXTURE10 0x84CA +#define GL_TEXTURE11 0x84CB +#define GL_TEXTURE12 0x84CC +#define GL_TEXTURE13 0x84CD +#define GL_TEXTURE14 0x84CE +#define GL_TEXTURE15 0x84CF +#define GL_TEXTURE16 0x84D0 +#define GL_TEXTURE17 0x84D1 +#define GL_TEXTURE18 0x84D2 +#define GL_TEXTURE19 0x84D3 +#define GL_TEXTURE20 0x84D4 +#define GL_TEXTURE21 0x84D5 +#define GL_TEXTURE22 0x84D6 +#define GL_TEXTURE23 0x84D7 +#define GL_TEXTURE24 0x84D8 +#define GL_TEXTURE25 0x84D9 +#define GL_TEXTURE26 0x84DA +#define GL_TEXTURE27 0x84DB +#define GL_TEXTURE28 0x84DC +#define GL_TEXTURE29 0x84DD +#define GL_TEXTURE30 0x84DE +#define GL_TEXTURE31 0x84DF +#define GL_ACTIVE_TEXTURE 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1 +#define GL_MAX_TEXTURE_UNITS 0x84E2 +#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6 +#define GL_MULTISAMPLE 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE 0x809F +#define GL_SAMPLE_COVERAGE 0x80A0 +#define GL_SAMPLE_BUFFERS 0x80A8 +#define GL_SAMPLES 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT 0x80AB +#define GL_MULTISAMPLE_BIT 0x20000000 +#define GL_NORMAL_MAP 0x8511 +#define GL_REFLECTION_MAP 0x8512 +#define GL_TEXTURE_CUBE_MAP 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C +#define GL_COMPRESSED_ALPHA 0x84E9 +#define GL_COMPRESSED_LUMINANCE 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB +#define GL_COMPRESSED_INTENSITY 0x84EC +#define GL_COMPRESSED_RGB 0x84ED +#define GL_COMPRESSED_RGBA 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0 +#define GL_TEXTURE_COMPRESSED 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3 +#define GL_CLAMP_TO_BORDER 0x812D +#define GL_COMBINE 0x8570 +#define GL_COMBINE_RGB 0x8571 +#define GL_COMBINE_ALPHA 0x8572 +#define GL_SOURCE0_RGB 0x8580 +#define GL_SOURCE1_RGB 0x8581 +#define GL_SOURCE2_RGB 0x8582 +#define GL_SOURCE0_ALPHA 0x8588 +#define GL_SOURCE1_ALPHA 0x8589 +#define GL_SOURCE2_ALPHA 0x858A +#define GL_OPERAND0_RGB 0x8590 +#define GL_OPERAND1_RGB 0x8591 +#define GL_OPERAND2_RGB 0x8592 +#define GL_OPERAND0_ALPHA 0x8598 +#define GL_OPERAND1_ALPHA 0x8599 +#define GL_OPERAND2_ALPHA 0x859A +#define GL_RGB_SCALE 0x8573 +#define GL_ADD_SIGNED 0x8574 +#define GL_INTERPOLATE 0x8575 +#define GL_SUBTRACT 0x84E7 +#define GL_CONSTANT 0x8576 +#define GL_PRIMARY_COLOR 0x8577 +#define GL_PREVIOUS 0x8578 +#define GL_DOT3_RGB 0x86AE +#define GL_DOT3_RGBA 0x86AF +#endif + +#ifndef GL_VERSION_1_4 +#define GL_BLEND_DST_RGB 0x80C8 +#define GL_BLEND_SRC_RGB 0x80C9 +#define GL_BLEND_DST_ALPHA 0x80CA +#define GL_BLEND_SRC_ALPHA 0x80CB +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_GENERATE_MIPMAP 0x8191 +#define GL_GENERATE_MIPMAP_HINT 0x8192 +#define GL_DEPTH_COMPONENT16 0x81A5 +#define GL_DEPTH_COMPONENT24 0x81A6 +#define GL_DEPTH_COMPONENT32 0x81A7 +#define GL_MIRRORED_REPEAT 0x8370 +#define GL_FOG_COORDINATE_SOURCE 0x8450 +#define GL_FOG_COORDINATE 0x8451 +#define GL_FRAGMENT_DEPTH 0x8452 +#define GL_CURRENT_FOG_COORDINATE 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456 +#define GL_FOG_COORDINATE_ARRAY 0x8457 +#define GL_COLOR_SUM 0x8458 +#define GL_CURRENT_SECONDARY_COLOR 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D +#define GL_SECONDARY_COLOR_ARRAY 0x845E +#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD +#define GL_TEXTURE_FILTER_CONTROL 0x8500 +#define GL_TEXTURE_LOD_BIAS 0x8501 +#define GL_INCR_WRAP 0x8507 +#define GL_DECR_WRAP 0x8508 +#define GL_TEXTURE_DEPTH_SIZE 0x884A +#define GL_DEPTH_TEXTURE_MODE 0x884B +#define GL_TEXTURE_COMPARE_MODE 0x884C +#define GL_TEXTURE_COMPARE_FUNC 0x884D +#define GL_COMPARE_R_TO_TEXTURE 0x884E +#endif + +#ifndef GL_VERSION_1_5 +#define GL_BUFFER_SIZE 0x8764 +#define GL_BUFFER_USAGE 0x8765 +#define GL_QUERY_COUNTER_BITS 0x8864 +#define GL_CURRENT_QUERY 0x8865 +#define GL_QUERY_RESULT 0x8866 +#define GL_QUERY_RESULT_AVAILABLE 0x8867 +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F +#define GL_READ_ONLY 0x88B8 +#define GL_WRITE_ONLY 0x88B9 +#define GL_READ_WRITE 0x88BA +#define GL_BUFFER_ACCESS 0x88BB +#define GL_BUFFER_MAPPED 0x88BC +#define GL_BUFFER_MAP_POINTER 0x88BD +#define GL_STREAM_DRAW 0x88E0 +#define GL_STREAM_READ 0x88E1 +#define GL_STREAM_COPY 0x88E2 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STATIC_READ 0x88E5 +#define GL_STATIC_COPY 0x88E6 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_DYNAMIC_READ 0x88E9 +#define GL_DYNAMIC_COPY 0x88EA +#define GL_SAMPLES_PASSED 0x8914 +#define GL_FOG_COORD_SRC GL_FOG_COORDINATE_SOURCE +#define GL_FOG_COORD GL_FOG_COORDINATE +#define GL_CURRENT_FOG_COORD GL_CURRENT_FOG_COORDINATE +#define GL_FOG_COORD_ARRAY_TYPE GL_FOG_COORDINATE_ARRAY_TYPE +#define GL_FOG_COORD_ARRAY_STRIDE GL_FOG_COORDINATE_ARRAY_STRIDE +#define GL_FOG_COORD_ARRAY_POINTER GL_FOG_COORDINATE_ARRAY_POINTER +#define GL_FOG_COORD_ARRAY GL_FOG_COORDINATE_ARRAY +#define GL_FOG_COORD_ARRAY_BUFFER_BINDING GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING +#define GL_SRC0_RGB GL_SOURCE0_RGB +#define GL_SRC1_RGB GL_SOURCE1_RGB +#define GL_SRC2_RGB GL_SOURCE2_RGB +#define GL_SRC0_ALPHA GL_SOURCE0_ALPHA +#define GL_SRC1_ALPHA GL_SOURCE1_ALPHA +#define GL_SRC2_ALPHA GL_SOURCE2_ALPHA +#endif + +#ifndef GL_VERSION_2_0 +#define GL_BLEND_EQUATION_RGB GL_BLEND_EQUATION +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB 0x8626 +#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 +#define GL_STENCIL_BACK_FUNC 0x8800 +#define GL_STENCIL_BACK_FAIL 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803 +#define GL_MAX_DRAW_BUFFERS 0x8824 +#define GL_DRAW_BUFFER0 0x8825 +#define GL_DRAW_BUFFER1 0x8826 +#define GL_DRAW_BUFFER2 0x8827 +#define GL_DRAW_BUFFER3 0x8828 +#define GL_DRAW_BUFFER4 0x8829 +#define GL_DRAW_BUFFER5 0x882A +#define GL_DRAW_BUFFER6 0x882B +#define GL_DRAW_BUFFER7 0x882C +#define GL_DRAW_BUFFER8 0x882D +#define GL_DRAW_BUFFER9 0x882E +#define GL_DRAW_BUFFER10 0x882F +#define GL_DRAW_BUFFER11 0x8830 +#define GL_DRAW_BUFFER12 0x8831 +#define GL_DRAW_BUFFER13 0x8832 +#define GL_DRAW_BUFFER14 0x8833 +#define GL_DRAW_BUFFER15 0x8834 +#define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_POINT_SPRITE 0x8861 +#define GL_COORD_REPLACE 0x8862 +#define GL_MAX_VERTEX_ATTRIBS 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A +#define GL_MAX_TEXTURE_COORDS 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A +#define GL_MAX_VARYING_FLOATS 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D +#define GL_SHADER_TYPE 0x8B4F +#define GL_FLOAT_VEC2 0x8B50 +#define GL_FLOAT_VEC3 0x8B51 +#define GL_FLOAT_VEC4 0x8B52 +#define GL_INT_VEC2 0x8B53 +#define GL_INT_VEC3 0x8B54 +#define GL_INT_VEC4 0x8B55 +#define GL_BOOL 0x8B56 +#define GL_BOOL_VEC2 0x8B57 +#define GL_BOOL_VEC3 0x8B58 +#define GL_BOOL_VEC4 0x8B59 +#define GL_FLOAT_MAT2 0x8B5A +#define GL_FLOAT_MAT3 0x8B5B +#define GL_FLOAT_MAT4 0x8B5C +#define GL_SAMPLER_1D 0x8B5D +#define GL_SAMPLER_2D 0x8B5E +#define GL_SAMPLER_3D 0x8B5F +#define GL_SAMPLER_CUBE 0x8B60 +#define GL_SAMPLER_1D_SHADOW 0x8B61 +#define GL_SAMPLER_2D_SHADOW 0x8B62 +#define GL_DELETE_STATUS 0x8B80 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 +#define GL_VALIDATE_STATUS 0x8B83 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_ATTACHED_SHADERS 0x8B85 +#define GL_ACTIVE_UNIFORMS 0x8B86 +#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87 +#define GL_SHADER_SOURCE_LENGTH 0x8B88 +#define GL_ACTIVE_ATTRIBUTES 0x8B89 +#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B +#define GL_SHADING_LANGUAGE_VERSION 0x8B8C +#define GL_CURRENT_PROGRAM 0x8B8D +#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0 +#define GL_LOWER_LEFT 0x8CA1 +#define GL_UPPER_LEFT 0x8CA2 +#define GL_STENCIL_BACK_REF 0x8CA3 +#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4 +#define GL_STENCIL_BACK_WRITEMASK 0x8CA5 +#endif + +#ifndef GL_ARB_multitexture +#define GL_TEXTURE0_ARB 0x84C0 +#define GL_TEXTURE1_ARB 0x84C1 +#define GL_TEXTURE2_ARB 0x84C2 +#define GL_TEXTURE3_ARB 0x84C3 +#define GL_TEXTURE4_ARB 0x84C4 +#define GL_TEXTURE5_ARB 0x84C5 +#define GL_TEXTURE6_ARB 0x84C6 +#define GL_TEXTURE7_ARB 0x84C7 +#define GL_TEXTURE8_ARB 0x84C8 +#define GL_TEXTURE9_ARB 0x84C9 +#define GL_TEXTURE10_ARB 0x84CA +#define GL_TEXTURE11_ARB 0x84CB +#define GL_TEXTURE12_ARB 0x84CC +#define GL_TEXTURE13_ARB 0x84CD +#define GL_TEXTURE14_ARB 0x84CE +#define GL_TEXTURE15_ARB 0x84CF +#define GL_TEXTURE16_ARB 0x84D0 +#define GL_TEXTURE17_ARB 0x84D1 +#define GL_TEXTURE18_ARB 0x84D2 +#define GL_TEXTURE19_ARB 0x84D3 +#define GL_TEXTURE20_ARB 0x84D4 +#define GL_TEXTURE21_ARB 0x84D5 +#define GL_TEXTURE22_ARB 0x84D6 +#define GL_TEXTURE23_ARB 0x84D7 +#define GL_TEXTURE24_ARB 0x84D8 +#define GL_TEXTURE25_ARB 0x84D9 +#define GL_TEXTURE26_ARB 0x84DA +#define GL_TEXTURE27_ARB 0x84DB +#define GL_TEXTURE28_ARB 0x84DC +#define GL_TEXTURE29_ARB 0x84DD +#define GL_TEXTURE30_ARB 0x84DE +#define GL_TEXTURE31_ARB 0x84DF +#define GL_ACTIVE_TEXTURE_ARB 0x84E0 +#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1 +#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3 +#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4 +#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5 +#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6 +#endif + +#ifndef GL_ARB_multisample +#define GL_MULTISAMPLE_ARB 0x809D +#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F +#define GL_SAMPLE_COVERAGE_ARB 0x80A0 +#define GL_SAMPLE_BUFFERS_ARB 0x80A8 +#define GL_SAMPLES_ARB 0x80A9 +#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA +#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB +#define GL_MULTISAMPLE_BIT_ARB 0x20000000 +#endif + +#ifndef GL_ARB_texture_env_add +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_NORMAL_MAP_ARB 0x8511 +#define GL_REFLECTION_MAP_ARB 0x8512 +#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C +#endif + +#ifndef GL_ARB_texture_compression +#define GL_COMPRESSED_ALPHA_ARB 0x84E9 +#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA +#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB +#define GL_COMPRESSED_INTENSITY_ARB 0x84EC +#define GL_COMPRESSED_RGB_ARB 0x84ED +#define GL_COMPRESSED_RGBA_ARB 0x84EE +#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF +#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0 +#define GL_TEXTURE_COMPRESSED_ARB 0x86A1 +#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2 +#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3 +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_CLAMP_TO_BORDER_ARB 0x812D +#endif + +#ifndef GL_ARB_point_parameters +#define GL_POINT_SIZE_MIN_ARB 0x8126 +#define GL_POINT_SIZE_MAX_ARB 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128 +#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129 +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_MAX_VERTEX_UNITS_ARB 0x86A4 +#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5 +#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6 +#define GL_VERTEX_BLEND_ARB 0x86A7 +#define GL_CURRENT_WEIGHT_ARB 0x86A8 +#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9 +#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA +#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB +#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC +#define GL_WEIGHT_ARRAY_ARB 0x86AD +#define GL_MODELVIEW0_ARB 0x1700 +#define GL_MODELVIEW1_ARB 0x850A +#define GL_MODELVIEW2_ARB 0x8722 +#define GL_MODELVIEW3_ARB 0x8723 +#define GL_MODELVIEW4_ARB 0x8724 +#define GL_MODELVIEW5_ARB 0x8725 +#define GL_MODELVIEW6_ARB 0x8726 +#define GL_MODELVIEW7_ARB 0x8727 +#define GL_MODELVIEW8_ARB 0x8728 +#define GL_MODELVIEW9_ARB 0x8729 +#define GL_MODELVIEW10_ARB 0x872A +#define GL_MODELVIEW11_ARB 0x872B +#define GL_MODELVIEW12_ARB 0x872C +#define GL_MODELVIEW13_ARB 0x872D +#define GL_MODELVIEW14_ARB 0x872E +#define GL_MODELVIEW15_ARB 0x872F +#define GL_MODELVIEW16_ARB 0x8730 +#define GL_MODELVIEW17_ARB 0x8731 +#define GL_MODELVIEW18_ARB 0x8732 +#define GL_MODELVIEW19_ARB 0x8733 +#define GL_MODELVIEW20_ARB 0x8734 +#define GL_MODELVIEW21_ARB 0x8735 +#define GL_MODELVIEW22_ARB 0x8736 +#define GL_MODELVIEW23_ARB 0x8737 +#define GL_MODELVIEW24_ARB 0x8738 +#define GL_MODELVIEW25_ARB 0x8739 +#define GL_MODELVIEW26_ARB 0x873A +#define GL_MODELVIEW27_ARB 0x873B +#define GL_MODELVIEW28_ARB 0x873C +#define GL_MODELVIEW29_ARB 0x873D +#define GL_MODELVIEW30_ARB 0x873E +#define GL_MODELVIEW31_ARB 0x873F +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_MATRIX_PALETTE_ARB 0x8840 +#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841 +#define GL_MAX_PALETTE_MATRICES_ARB 0x8842 +#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843 +#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844 +#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845 +#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846 +#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847 +#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848 +#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849 +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_COMBINE_ARB 0x8570 +#define GL_COMBINE_RGB_ARB 0x8571 +#define GL_COMBINE_ALPHA_ARB 0x8572 +#define GL_SOURCE0_RGB_ARB 0x8580 +#define GL_SOURCE1_RGB_ARB 0x8581 +#define GL_SOURCE2_RGB_ARB 0x8582 +#define GL_SOURCE0_ALPHA_ARB 0x8588 +#define GL_SOURCE1_ALPHA_ARB 0x8589 +#define GL_SOURCE2_ALPHA_ARB 0x858A +#define GL_OPERAND0_RGB_ARB 0x8590 +#define GL_OPERAND1_RGB_ARB 0x8591 +#define GL_OPERAND2_RGB_ARB 0x8592 +#define GL_OPERAND0_ALPHA_ARB 0x8598 +#define GL_OPERAND1_ALPHA_ARB 0x8599 +#define GL_OPERAND2_ALPHA_ARB 0x859A +#define GL_RGB_SCALE_ARB 0x8573 +#define GL_ADD_SIGNED_ARB 0x8574 +#define GL_INTERPOLATE_ARB 0x8575 +#define GL_SUBTRACT_ARB 0x84E7 +#define GL_CONSTANT_ARB 0x8576 +#define GL_PRIMARY_COLOR_ARB 0x8577 +#define GL_PREVIOUS_ARB 0x8578 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_DOT3_RGB_ARB 0x86AE +#define GL_DOT3_RGBA_ARB 0x86AF +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_ARB 0x8370 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_DEPTH_COMPONENT16_ARB 0x81A5 +#define GL_DEPTH_COMPONENT24_ARB 0x81A6 +#define GL_DEPTH_COMPONENT32_ARB 0x81A7 +#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A +#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B +#endif + +#ifndef GL_ARB_shadow +#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C +#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D +#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF +#endif + +#ifndef GL_ARB_window_pos +#endif + +#ifndef GL_ARB_vertex_program +#define GL_COLOR_SUM_ARB 0x8458 +#define GL_VERTEX_PROGRAM_ARB 0x8620 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625 +#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626 +#define GL_PROGRAM_LENGTH_ARB 0x8627 +#define GL_PROGRAM_STRING_ARB 0x8628 +#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E +#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F +#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640 +#define GL_CURRENT_MATRIX_ARB 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645 +#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B +#define GL_PROGRAM_BINDING_ARB 0x8677 +#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A +#define GL_PROGRAM_ERROR_STRING_ARB 0x8874 +#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 +#define GL_PROGRAM_FORMAT_ARB 0x8876 +#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0 +#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1 +#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2 +#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3 +#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4 +#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5 +#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6 +#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7 +#define GL_PROGRAM_PARAMETERS_ARB 0x88A8 +#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9 +#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA +#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB +#define GL_PROGRAM_ATTRIBS_ARB 0x88AC +#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD +#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE +#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF +#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0 +#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1 +#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2 +#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3 +#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4 +#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5 +#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6 +#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7 +#define GL_MATRIX0_ARB 0x88C0 +#define GL_MATRIX1_ARB 0x88C1 +#define GL_MATRIX2_ARB 0x88C2 +#define GL_MATRIX3_ARB 0x88C3 +#define GL_MATRIX4_ARB 0x88C4 +#define GL_MATRIX5_ARB 0x88C5 +#define GL_MATRIX6_ARB 0x88C6 +#define GL_MATRIX7_ARB 0x88C7 +#define GL_MATRIX8_ARB 0x88C8 +#define GL_MATRIX9_ARB 0x88C9 +#define GL_MATRIX10_ARB 0x88CA +#define GL_MATRIX11_ARB 0x88CB +#define GL_MATRIX12_ARB 0x88CC +#define GL_MATRIX13_ARB 0x88CD +#define GL_MATRIX14_ARB 0x88CE +#define GL_MATRIX15_ARB 0x88CF +#define GL_MATRIX16_ARB 0x88D0 +#define GL_MATRIX17_ARB 0x88D1 +#define GL_MATRIX18_ARB 0x88D2 +#define GL_MATRIX19_ARB 0x88D3 +#define GL_MATRIX20_ARB 0x88D4 +#define GL_MATRIX21_ARB 0x88D5 +#define GL_MATRIX22_ARB 0x88D6 +#define GL_MATRIX23_ARB 0x88D7 +#define GL_MATRIX24_ARB 0x88D8 +#define GL_MATRIX25_ARB 0x88D9 +#define GL_MATRIX26_ARB 0x88DA +#define GL_MATRIX27_ARB 0x88DB +#define GL_MATRIX28_ARB 0x88DC +#define GL_MATRIX29_ARB 0x88DD +#define GL_MATRIX30_ARB 0x88DE +#define GL_MATRIX31_ARB 0x88DF +#endif + +#ifndef GL_ARB_fragment_program +#define GL_FRAGMENT_PROGRAM_ARB 0x8804 +#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805 +#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806 +#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807 +#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808 +#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809 +#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A +#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B +#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C +#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D +#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E +#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F +#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810 +#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_BUFFER_SIZE_ARB 0x8764 +#define GL_BUFFER_USAGE_ARB 0x8765 +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893 +#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895 +#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896 +#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897 +#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898 +#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899 +#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A +#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B +#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C +#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D +#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E +#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F +#define GL_READ_ONLY_ARB 0x88B8 +#define GL_WRITE_ONLY_ARB 0x88B9 +#define GL_READ_WRITE_ARB 0x88BA +#define GL_BUFFER_ACCESS_ARB 0x88BB +#define GL_BUFFER_MAPPED_ARB 0x88BC +#define GL_BUFFER_MAP_POINTER_ARB 0x88BD +#define GL_STREAM_DRAW_ARB 0x88E0 +#define GL_STREAM_READ_ARB 0x88E1 +#define GL_STREAM_COPY_ARB 0x88E2 +#define GL_STATIC_DRAW_ARB 0x88E4 +#define GL_STATIC_READ_ARB 0x88E5 +#define GL_STATIC_COPY_ARB 0x88E6 +#define GL_DYNAMIC_DRAW_ARB 0x88E8 +#define GL_DYNAMIC_READ_ARB 0x88E9 +#define GL_DYNAMIC_COPY_ARB 0x88EA +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_MAP_READ_BIT 0x0001 +#define GL_MAP_WRITE_BIT 0x0002 +#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 +#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 +#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 +#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_QUERY_COUNTER_BITS_ARB 0x8864 +#define GL_CURRENT_QUERY_ARB 0x8865 +#define GL_QUERY_RESULT_ARB 0x8866 +#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 +#define GL_SAMPLES_PASSED_ARB 0x8914 +#endif + +#ifndef GL_EXT_timer_query +#define GL_TIME_ELAPSED_EXT 0x88BF +#endif + +#ifndef GL_ARB_sync +#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 +#define GL_OBJECT_TYPE 0x9112 +#define GL_SYNC_CONDITION 0x9113 +#define GL_SYNC_STATUS 0x9114 +#define GL_SYNC_FLAGS 0x9115 +#define GL_SYNC_FENCE 0x9116 +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#define GL_UNSIGNALED 0x9118 +#define GL_SIGNALED 0x9119 +#define GL_ALREADY_SIGNALED 0x911A +#define GL_TIMEOUT_EXPIRED 0x911B +#define GL_CONDITION_SATISFIED 0x911C +#define GL_WAIT_FAILED 0x911D +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull +#endif + +#ifndef GL_ARB_shader_objects +#define GL_PROGRAM_OBJECT_ARB 0x8B40 +#define GL_SHADER_OBJECT_ARB 0x8B48 +#define GL_OBJECT_TYPE_ARB 0x8B4E +#define GL_OBJECT_SUBTYPE_ARB 0x8B4F +#define GL_FLOAT_VEC2_ARB 0x8B50 +#define GL_FLOAT_VEC3_ARB 0x8B51 +#define GL_FLOAT_VEC4_ARB 0x8B52 +#define GL_INT_VEC2_ARB 0x8B53 +#define GL_INT_VEC3_ARB 0x8B54 +#define GL_INT_VEC4_ARB 0x8B55 +#define GL_BOOL_ARB 0x8B56 +#define GL_BOOL_VEC2_ARB 0x8B57 +#define GL_BOOL_VEC3_ARB 0x8B58 +#define GL_BOOL_VEC4_ARB 0x8B59 +#define GL_FLOAT_MAT2_ARB 0x8B5A +#define GL_FLOAT_MAT3_ARB 0x8B5B +#define GL_FLOAT_MAT4_ARB 0x8B5C +#define GL_SAMPLER_1D_ARB 0x8B5D +#define GL_SAMPLER_2D_ARB 0x8B5E +#define GL_SAMPLER_3D_ARB 0x8B5F +#define GL_SAMPLER_CUBE_ARB 0x8B60 +#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61 +#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62 +#define GL_SAMPLER_2D_RECT_ARB 0x8B63 +#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64 +#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80 +#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81 +#define GL_OBJECT_LINK_STATUS_ARB 0x8B82 +#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83 +#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84 +#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85 +#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86 +#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87 +#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88 +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_VERTEX_SHADER_ARB 0x8B31 +#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A +#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B +#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C +#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D +#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89 +#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49 +#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ARB 0x8824 +#define GL_DRAW_BUFFER0_ARB 0x8825 +#define GL_DRAW_BUFFER1_ARB 0x8826 +#define GL_DRAW_BUFFER2_ARB 0x8827 +#define GL_DRAW_BUFFER3_ARB 0x8828 +#define GL_DRAW_BUFFER4_ARB 0x8829 +#define GL_DRAW_BUFFER5_ARB 0x882A +#define GL_DRAW_BUFFER6_ARB 0x882B +#define GL_DRAW_BUFFER7_ARB 0x882C +#define GL_DRAW_BUFFER8_ARB 0x882D +#define GL_DRAW_BUFFER9_ARB 0x882E +#define GL_DRAW_BUFFER10_ARB 0x882F +#define GL_DRAW_BUFFER11_ARB 0x8830 +#define GL_DRAW_BUFFER12_ARB 0x8831 +#define GL_DRAW_BUFFER13_ARB 0x8832 +#define GL_DRAW_BUFFER14_ARB 0x8833 +#define GL_DRAW_BUFFER15_ARB 0x8834 +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_TEXTURE_RECTANGLE_ARB 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_RGBA_FLOAT_MODE_ARB 0x8820 +#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A +#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B +#define GL_CLAMP_READ_COLOR_ARB 0x891C +#define GL_FIXED_ONLY_ARB 0x891D +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_HALF_FLOAT_ARB 0x140B +#endif + +#ifndef GL_ARB_texture_float +#define GL_TEXTURE_RED_TYPE_ARB 0x8C10 +#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11 +#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12 +#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13 +#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14 +#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15 +#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16 +#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17 +#define GL_RGBA32F_ARB 0x8814 +#define GL_RGB32F_ARB 0x8815 +#define GL_ALPHA32F_ARB 0x8816 +#define GL_INTENSITY32F_ARB 0x8817 +#define GL_LUMINANCE32F_ARB 0x8818 +#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 +#define GL_RGBA16F_ARB 0x881A +#define GL_RGB16F_ARB 0x881B +#define GL_ALPHA16F_ARB 0x881C +#define GL_INTENSITY16F_ARB 0x881D +#define GL_LUMINANCE16F_ARB 0x881E +#define GL_LUMINANCE_ALPHA16F_ARB 0x881F +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF +#endif + +#ifndef GL_EXT_abgr +#define GL_ABGR_EXT 0x8000 +#endif + +#ifndef GL_EXT_blend_color +#define GL_CONSTANT_COLOR_EXT 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002 +#define GL_CONSTANT_ALPHA_EXT 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004 +#define GL_BLEND_COLOR_EXT 0x8005 +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_POLYGON_OFFSET_EXT 0x8037 +#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038 +#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039 +#endif + +#ifndef GL_EXT_texture +#define GL_ALPHA4_EXT 0x803B +#define GL_ALPHA8_EXT 0x803C +#define GL_ALPHA12_EXT 0x803D +#define GL_ALPHA16_EXT 0x803E +#define GL_LUMINANCE4_EXT 0x803F +#define GL_LUMINANCE8_EXT 0x8040 +#define GL_LUMINANCE12_EXT 0x8041 +#define GL_LUMINANCE16_EXT 0x8042 +#define GL_LUMINANCE4_ALPHA4_EXT 0x8043 +#define GL_LUMINANCE6_ALPHA2_EXT 0x8044 +#define GL_LUMINANCE8_ALPHA8_EXT 0x8045 +#define GL_LUMINANCE12_ALPHA4_EXT 0x8046 +#define GL_LUMINANCE12_ALPHA12_EXT 0x8047 +#define GL_LUMINANCE16_ALPHA16_EXT 0x8048 +#define GL_INTENSITY_EXT 0x8049 +#define GL_INTENSITY4_EXT 0x804A +#define GL_INTENSITY8_EXT 0x804B +#define GL_INTENSITY12_EXT 0x804C +#define GL_INTENSITY16_EXT 0x804D +#define GL_RGB2_EXT 0x804E +#define GL_RGB4_EXT 0x804F +#define GL_RGB5_EXT 0x8050 +#define GL_RGB8_EXT 0x8051 +#define GL_RGB10_EXT 0x8052 +#define GL_RGB12_EXT 0x8053 +#define GL_RGB16_EXT 0x8054 +#define GL_RGBA2_EXT 0x8055 +#define GL_RGBA4_EXT 0x8056 +#define GL_RGB5_A1_EXT 0x8057 +#define GL_RGBA8_EXT 0x8058 +#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGBA12_EXT 0x805A +#define GL_RGBA16_EXT 0x805B +#define GL_TEXTURE_RED_SIZE_EXT 0x805C +#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D +#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E +#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F +#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060 +#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061 +#define GL_REPLACE_EXT 0x8062 +#define GL_PROXY_TEXTURE_1D_EXT 0x8063 +#define GL_PROXY_TEXTURE_2D_EXT 0x8064 +#define GL_TEXTURE_TOO_LARGE_EXT 0x8065 +#endif + +#ifndef GL_EXT_texture3D +#define GL_PACK_SKIP_IMAGES_EXT 0x806B +#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C +#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D +#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E +#define GL_TEXTURE_3D_EXT 0x806F +#define GL_PROXY_TEXTURE_3D_EXT 0x8070 +#define GL_TEXTURE_DEPTH_EXT 0x8071 +#define GL_TEXTURE_WRAP_R_EXT 0x8072 +#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_FILTER4_SGIS 0x8146 +#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147 +#endif + +#ifndef GL_EXT_subtexture +#endif + +#ifndef GL_EXT_copy_texture +#endif + +#ifndef GL_EXT_histogram +#define GL_HISTOGRAM_EXT 0x8024 +#define GL_PROXY_HISTOGRAM_EXT 0x8025 +#define GL_HISTOGRAM_WIDTH_EXT 0x8026 +#define GL_HISTOGRAM_FORMAT_EXT 0x8027 +#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028 +#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029 +#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A +#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B +#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C +#define GL_HISTOGRAM_SINK_EXT 0x802D +#define GL_MINMAX_EXT 0x802E +#define GL_MINMAX_FORMAT_EXT 0x802F +#define GL_MINMAX_SINK_EXT 0x8030 +#define GL_TABLE_TOO_LARGE_EXT 0x8031 +#endif + +#ifndef GL_EXT_convolution +#define GL_CONVOLUTION_1D_EXT 0x8010 +#define GL_CONVOLUTION_2D_EXT 0x8011 +#define GL_SEPARABLE_2D_EXT 0x8012 +#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013 +#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014 +#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015 +#define GL_REDUCE_EXT 0x8016 +#define GL_CONVOLUTION_FORMAT_EXT 0x8017 +#define GL_CONVOLUTION_WIDTH_EXT 0x8018 +#define GL_CONVOLUTION_HEIGHT_EXT 0x8019 +#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A +#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B +#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C +#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D +#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E +#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F +#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020 +#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021 +#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022 +#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023 +#endif + +#ifndef GL_SGI_color_matrix +#define GL_COLOR_MATRIX_SGI 0x80B1 +#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2 +#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3 +#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4 +#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5 +#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6 +#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7 +#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8 +#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9 +#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA +#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB +#endif + +#ifndef GL_SGI_color_table +#define GL_COLOR_TABLE_SGI 0x80D0 +#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1 +#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2 +#define GL_PROXY_COLOR_TABLE_SGI 0x80D3 +#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4 +#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5 +#define GL_COLOR_TABLE_SCALE_SGI 0x80D6 +#define GL_COLOR_TABLE_BIAS_SGI 0x80D7 +#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8 +#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9 +#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA +#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB +#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC +#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD +#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE +#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_PIXEL_TEXTURE_SGIS 0x8353 +#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354 +#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355 +#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356 +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_PIXEL_TEX_GEN_SGIX 0x8139 +#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B +#endif + +#ifndef GL_SGIS_texture4D +#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130 +#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131 +#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132 +#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133 +#define GL_TEXTURE_4D_SGIS 0x8134 +#define GL_PROXY_TEXTURE_4D_SGIS 0x8135 +#define GL_TEXTURE_4DSIZE_SGIS 0x8136 +#define GL_TEXTURE_WRAP_Q_SGIS 0x8137 +#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138 +#define GL_TEXTURE_4D_BINDING_SGIS 0x814F +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC +#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD +#endif + +#ifndef GL_EXT_cmyka +#define GL_CMYK_EXT 0x800C +#define GL_CMYKA_EXT 0x800D +#define GL_PACK_CMYK_HINT_EXT 0x800E +#define GL_UNPACK_CMYK_HINT_EXT 0x800F +#endif + +#ifndef GL_EXT_texture_object +#define GL_TEXTURE_PRIORITY_EXT 0x8066 +#define GL_TEXTURE_RESIDENT_EXT 0x8067 +#define GL_TEXTURE_1D_BINDING_EXT 0x8068 +#define GL_TEXTURE_2D_BINDING_EXT 0x8069 +#define GL_TEXTURE_3D_BINDING_EXT 0x806A +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095 +#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096 +#define GL_LINEAR_DETAIL_SGIS 0x8097 +#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098 +#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099 +#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A +#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B +#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_LINEAR_SHARPEN_SGIS 0x80AD +#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE +#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF +#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0 +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032 +#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033 +#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034 +#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035 +#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_TEXTURE_MIN_LOD_SGIS 0x813A +#define GL_TEXTURE_MAX_LOD_SGIS 0x813B +#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C +#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D +#endif + +#ifndef GL_SGIS_multisample +#define GL_MULTISAMPLE_SGIS 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F +#define GL_SAMPLE_MASK_SGIS 0x80A0 +#define GL_1PASS_SGIS 0x80A1 +#define GL_2PASS_0_SGIS 0x80A2 +#define GL_2PASS_1_SGIS 0x80A3 +#define GL_4PASS_0_SGIS 0x80A4 +#define GL_4PASS_1_SGIS 0x80A5 +#define GL_4PASS_2_SGIS 0x80A6 +#define GL_4PASS_3_SGIS 0x80A7 +#define GL_SAMPLE_BUFFERS_SGIS 0x80A8 +#define GL_SAMPLES_SGIS 0x80A9 +#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA +#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB +#define GL_SAMPLE_PATTERN_SGIS 0x80AC +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_RESCALE_NORMAL_EXT 0x803A +#endif + +#ifndef GL_EXT_vertex_array +#define GL_VERTEX_ARRAY_EXT 0x8074 +#define GL_NORMAL_ARRAY_EXT 0x8075 +#define GL_COLOR_ARRAY_EXT 0x8076 +#define GL_INDEX_ARRAY_EXT 0x8077 +#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078 +#define GL_EDGE_FLAG_ARRAY_EXT 0x8079 +#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A +#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B +#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C +#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D +#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E +#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F +#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080 +#define GL_COLOR_ARRAY_SIZE_EXT 0x8081 +#define GL_COLOR_ARRAY_TYPE_EXT 0x8082 +#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083 +#define GL_COLOR_ARRAY_COUNT_EXT 0x8084 +#define GL_INDEX_ARRAY_TYPE_EXT 0x8085 +#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086 +#define GL_INDEX_ARRAY_COUNT_EXT 0x8087 +#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088 +#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089 +#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A +#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B +#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C +#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D +#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E +#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F +#define GL_COLOR_ARRAY_POINTER_EXT 0x8090 +#define GL_INDEX_ARRAY_POINTER_EXT 0x8091 +#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092 +#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093 +#endif + +#ifndef GL_EXT_misc_attribute +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_GENERATE_MIPMAP_SGIS 0x8191 +#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170 +#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171 +#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172 +#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173 +#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174 +#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175 +#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176 +#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177 +#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178 +#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D +#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E +#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F +#endif + +#ifndef GL_SGIX_shadow +#define GL_TEXTURE_COMPARE_SGIX 0x819A +#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B +#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C +#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_CLAMP_TO_EDGE_SGIS 0x812F +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_CLAMP_TO_BORDER_SGIS 0x812D +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_FUNC_ADD_EXT 0x8006 +#define GL_MIN_EXT 0x8007 +#define GL_MAX_EXT 0x8008 +#define GL_BLEND_EQUATION_EXT 0x8009 +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_FUNC_SUBTRACT_EXT 0x800A +#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B +#endif + +#ifndef GL_EXT_blend_logic_op +#endif + +#ifndef GL_SGIX_interlace +#define GL_INTERLACE_SGIX 0x8094 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E +#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F +#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140 +#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141 +#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142 +#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143 +#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144 +#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145 +#endif + +#ifndef GL_SGIS_texture_select +#define GL_DUAL_ALPHA4_SGIS 0x8110 +#define GL_DUAL_ALPHA8_SGIS 0x8111 +#define GL_DUAL_ALPHA12_SGIS 0x8112 +#define GL_DUAL_ALPHA16_SGIS 0x8113 +#define GL_DUAL_LUMINANCE4_SGIS 0x8114 +#define GL_DUAL_LUMINANCE8_SGIS 0x8115 +#define GL_DUAL_LUMINANCE12_SGIS 0x8116 +#define GL_DUAL_LUMINANCE16_SGIS 0x8117 +#define GL_DUAL_INTENSITY4_SGIS 0x8118 +#define GL_DUAL_INTENSITY8_SGIS 0x8119 +#define GL_DUAL_INTENSITY12_SGIS 0x811A +#define GL_DUAL_INTENSITY16_SGIS 0x811B +#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C +#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D +#define GL_QUAD_ALPHA4_SGIS 0x811E +#define GL_QUAD_ALPHA8_SGIS 0x811F +#define GL_QUAD_LUMINANCE4_SGIS 0x8120 +#define GL_QUAD_LUMINANCE8_SGIS 0x8121 +#define GL_QUAD_INTENSITY4_SGIS 0x8122 +#define GL_QUAD_INTENSITY8_SGIS 0x8123 +#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124 +#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SPRITE_SGIX 0x8148 +#define GL_SPRITE_MODE_SGIX 0x8149 +#define GL_SPRITE_AXIS_SGIX 0x814A +#define GL_SPRITE_TRANSLATION_SGIX 0x814B +#define GL_SPRITE_AXIAL_SGIX 0x814C +#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D +#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E +#endif + +#ifndef GL_EXT_point_parameters +#define GL_POINT_SIZE_MIN_EXT 0x8126 +#define GL_POINT_SIZE_MAX_EXT 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128 +#define GL_DISTANCE_ATTENUATION_EXT 0x8129 +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_POINT_SIZE_MIN_SGIS 0x8126 +#define GL_POINT_SIZE_MAX_SGIS 0x8127 +#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128 +#define GL_DISTANCE_ATTENUATION_SGIS 0x8129 +#endif + +#ifndef GL_SGIX_instruments +#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180 +#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181 +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179 +#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A +#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B +#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C +#endif + +#ifndef GL_SGIX_framezoom +#define GL_FRAMEZOOM_SGIX 0x818B +#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C +#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#endif + +#ifndef GL_FfdMaskSGIX +#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001 +#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002 +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194 +#define GL_TEXTURE_DEFORMATION_SGIX 0x8195 +#define GL_DEFORMATIONS_MASK_SGIX 0x8196 +#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197 +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_REFERENCE_PLANE_SGIX 0x817D +#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E +#endif + +#ifndef GL_SGIX_flush_raster +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_DEPTH_COMPONENT16_SGIX 0x81A5 +#define GL_DEPTH_COMPONENT24_SGIX 0x81A6 +#define GL_DEPTH_COMPONENT32_SGIX 0x81A7 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_FOG_FUNC_SGIS 0x812A +#define GL_FOG_FUNC_POINTS_SGIS 0x812B +#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_FOG_OFFSET_SGIX 0x8198 +#define GL_FOG_OFFSET_VALUE_SGIX 0x8199 +#endif + +#ifndef GL_HP_image_transform +#define GL_IMAGE_SCALE_X_HP 0x8155 +#define GL_IMAGE_SCALE_Y_HP 0x8156 +#define GL_IMAGE_TRANSLATE_X_HP 0x8157 +#define GL_IMAGE_TRANSLATE_Y_HP 0x8158 +#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159 +#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A +#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B +#define GL_IMAGE_MAG_FILTER_HP 0x815C +#define GL_IMAGE_MIN_FILTER_HP 0x815D +#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E +#define GL_CUBIC_HP 0x815F +#define GL_AVERAGE_HP 0x8160 +#define GL_IMAGE_TRANSFORM_2D_HP 0x8161 +#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162 +#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163 +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_IGNORE_BORDER_HP 0x8150 +#define GL_CONSTANT_BORDER_HP 0x8151 +#define GL_REPLICATE_BORDER_HP 0x8153 +#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154 +#endif + +#ifndef GL_INGR_palette_buffer +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE +#endif + +#ifndef GL_EXT_color_subtable +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_VERTEX_DATA_HINT_PGI 0x1A22A +#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B +#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C +#define GL_MAX_VERTEX_HINT_PGI 0x1A22D +#define GL_COLOR3_BIT_PGI 0x00010000 +#define GL_COLOR4_BIT_PGI 0x00020000 +#define GL_EDGEFLAG_BIT_PGI 0x00040000 +#define GL_INDEX_BIT_PGI 0x00080000 +#define GL_MAT_AMBIENT_BIT_PGI 0x00100000 +#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000 +#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000 +#define GL_MAT_EMISSION_BIT_PGI 0x00800000 +#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000 +#define GL_MAT_SHININESS_BIT_PGI 0x02000000 +#define GL_MAT_SPECULAR_BIT_PGI 0x04000000 +#define GL_NORMAL_BIT_PGI 0x08000000 +#define GL_TEXCOORD1_BIT_PGI 0x10000000 +#define GL_TEXCOORD2_BIT_PGI 0x20000000 +#define GL_TEXCOORD3_BIT_PGI 0x40000000 +#define GL_TEXCOORD4_BIT_PGI 0x80000000 +#define GL_VERTEX23_BIT_PGI 0x00000004 +#define GL_VERTEX4_BIT_PGI 0x00000008 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8 +#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD +#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE +#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202 +#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203 +#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204 +#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C +#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D +#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E +#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F +#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210 +#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211 +#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216 +#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217 +#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218 +#define GL_FULL_STIPPLE_HINT_PGI 0x1A219 +#define GL_CLIP_NEAR_HINT_PGI 0x1A220 +#define GL_CLIP_FAR_HINT_PGI 0x1A221 +#define GL_WIDE_LINE_HINT_PGI 0x1A222 +#define GL_BACK_NORMALS_HINT_PGI 0x1A223 +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_COLOR_INDEX1_EXT 0x80E2 +#define GL_COLOR_INDEX2_EXT 0x80E3 +#define GL_COLOR_INDEX4_EXT 0x80E4 +#define GL_COLOR_INDEX8_EXT 0x80E5 +#define GL_COLOR_INDEX12_EXT 0x80E6 +#define GL_COLOR_INDEX16_EXT 0x80E7 +#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_LIST_PRIORITY_SGIX 0x8182 +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_IR_INSTRUMENT1_SGIX 0x817F +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E +#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F +#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SHADOW_AMBIENT_SGIX 0x80BF +#endif + +#ifndef GL_EXT_index_texture +#endif + +#ifndef GL_EXT_index_material +#define GL_INDEX_MATERIAL_EXT 0x81B8 +#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9 +#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA +#endif + +#ifndef GL_EXT_index_func +#define GL_INDEX_TEST_EXT 0x81B5 +#define GL_INDEX_TEST_FUNC_EXT 0x81B6 +#define GL_INDEX_TEST_REF_EXT 0x81B7 +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_IUI_V2F_EXT 0x81AD +#define GL_IUI_V3F_EXT 0x81AE +#define GL_IUI_N3F_V2F_EXT 0x81AF +#define GL_IUI_N3F_V3F_EXT 0x81B0 +#define GL_T2F_IUI_V2F_EXT 0x81B1 +#define GL_T2F_IUI_V3F_EXT 0x81B2 +#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3 +#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8 +#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9 +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_CULL_VERTEX_EXT 0x81AA +#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB +#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_YCRCB_422_SGIX 0x81BB +#define GL_YCRCB_444_SGIX 0x81BC +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_FRAGMENT_LIGHTING_SGIX 0x8400 +#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401 +#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402 +#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403 +#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404 +#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405 +#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406 +#define GL_LIGHT_ENV_MODE_SGIX 0x8407 +#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408 +#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409 +#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A +#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B +#define GL_FRAGMENT_LIGHT0_SGIX 0x840C +#define GL_FRAGMENT_LIGHT1_SGIX 0x840D +#define GL_FRAGMENT_LIGHT2_SGIX 0x840E +#define GL_FRAGMENT_LIGHT3_SGIX 0x840F +#define GL_FRAGMENT_LIGHT4_SGIX 0x8410 +#define GL_FRAGMENT_LIGHT5_SGIX 0x8411 +#define GL_FRAGMENT_LIGHT6_SGIX 0x8412 +#define GL_FRAGMENT_LIGHT7_SGIX 0x8413 +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167 +#define GL_TEXTURE_POST_SPECULAR_HP 0x8168 +#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8 +#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9 +#endif + +#ifndef GL_WIN_phong_shading +#define GL_PHONG_WIN 0x80EA +#define GL_PHONG_HINT_WIN 0x80EB +#endif + +#ifndef GL_WIN_specular_fog +#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC +#endif + +#ifndef GL_EXT_light_texture +#define GL_FRAGMENT_MATERIAL_EXT 0x8349 +#define GL_FRAGMENT_NORMAL_EXT 0x834A +#define GL_FRAGMENT_COLOR_EXT 0x834C +#define GL_ATTENUATION_EXT 0x834D +#define GL_SHADOW_ATTENUATION_EXT 0x834E +#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F +#define GL_TEXTURE_LIGHT_EXT 0x8350 +#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351 +#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352 +/* reuse GL_FRAGMENT_DEPTH_EXT */ +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_ALPHA_MIN_SGIX 0x8320 +#define GL_ALPHA_MAX_SGIX 0x8321 +#endif + +#ifndef GL_SGIX_impact_pixel_texture +#define GL_PIXEL_TEX_GEN_Q_CEILING_SGIX 0x8184 +#define GL_PIXEL_TEX_GEN_Q_ROUND_SGIX 0x8185 +#define GL_PIXEL_TEX_GEN_Q_FLOOR_SGIX 0x8186 +#define GL_PIXEL_TEX_GEN_ALPHA_REPLACE_SGIX 0x8187 +#define GL_PIXEL_TEX_GEN_ALPHA_NO_REPLACE_SGIX 0x8188 +#define GL_PIXEL_TEX_GEN_ALPHA_LS_SGIX 0x8189 +#define GL_PIXEL_TEX_GEN_ALPHA_MS_SGIX 0x818A +#endif + +#ifndef GL_EXT_bgra +#define GL_BGR_EXT 0x80E0 +#define GL_BGRA_EXT 0x80E1 +#endif + +#ifndef GL_SGIX_async +#define GL_ASYNC_MARKER_SGIX 0x8329 +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C +#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D +#define GL_ASYNC_READ_PIXELS_SGIX 0x835E +#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F +#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360 +#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_ASYNC_HISTOGRAM_SGIX 0x832C +#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D +#endif + +#ifndef GL_INTEL_texture_scissor +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_PARALLEL_ARRAYS_INTEL 0x83F4 +#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5 +#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6 +#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7 +#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8 +#endif + +#ifndef GL_HP_occlusion_test +#define GL_OCCLUSION_TEST_HP 0x8165 +#define GL_OCCLUSION_TEST_RESULT_HP 0x8166 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330 +#define GL_PIXEL_MAG_FILTER_EXT 0x8331 +#define GL_PIXEL_MIN_FILTER_EXT 0x8332 +#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333 +#define GL_CUBIC_EXT 0x8334 +#define GL_AVERAGE_EXT 0x8335 +#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336 +#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337 +#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338 +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8 +#define GL_SINGLE_COLOR_EXT 0x81F9 +#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA +#endif + +#ifndef GL_EXT_secondary_color +#define GL_COLOR_SUM_EXT 0x8458 +#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459 +#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A +#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B +#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C +#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D +#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_PERTURB_EXT 0x85AE +#define GL_TEXTURE_NORMAL_EXT 0x85AF +#endif + +#ifndef GL_EXT_multi_draw_arrays +#endif + +#ifndef GL_EXT_fog_coord +#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450 +#define GL_FOG_COORDINATE_EXT 0x8451 +#define GL_FRAGMENT_DEPTH_EXT 0x8452 +#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453 +#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454 +#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455 +#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456 +#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457 +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_SCREEN_COORDINATES_REND 0x8490 +#define GL_INVERTED_SCREEN_W_REND 0x8491 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_TANGENT_ARRAY_EXT 0x8439 +#define GL_BINORMAL_ARRAY_EXT 0x843A +#define GL_CURRENT_TANGENT_EXT 0x843B +#define GL_CURRENT_BINORMAL_EXT 0x843C +#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E +#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F +#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440 +#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441 +#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442 +#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443 +#define GL_MAP1_TANGENT_EXT 0x8444 +#define GL_MAP2_TANGENT_EXT 0x8445 +#define GL_MAP1_BINORMAL_EXT 0x8446 +#define GL_MAP2_BINORMAL_EXT 0x8447 +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_COMBINE_EXT 0x8570 +#define GL_COMBINE_RGB_EXT 0x8571 +#define GL_COMBINE_ALPHA_EXT 0x8572 +#define GL_RGB_SCALE_EXT 0x8573 +#define GL_ADD_SIGNED_EXT 0x8574 +#define GL_INTERPOLATE_EXT 0x8575 +#define GL_CONSTANT_EXT 0x8576 +#define GL_PRIMARY_COLOR_EXT 0x8577 +#define GL_PREVIOUS_EXT 0x8578 +#define GL_SOURCE0_RGB_EXT 0x8580 +#define GL_SOURCE1_RGB_EXT 0x8581 +#define GL_SOURCE2_RGB_EXT 0x8582 +#define GL_SOURCE0_ALPHA_EXT 0x8588 +#define GL_SOURCE1_ALPHA_EXT 0x8589 +#define GL_SOURCE2_ALPHA_EXT 0x858A +#define GL_OPERAND0_RGB_EXT 0x8590 +#define GL_OPERAND1_RGB_EXT 0x8591 +#define GL_OPERAND2_RGB_EXT 0x8592 +#define GL_OPERAND0_ALPHA_EXT 0x8598 +#define GL_OPERAND1_ALPHA_EXT 0x8599 +#define GL_OPERAND2_ALPHA_EXT 0x859A +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_TRANSFORM_HINT_APPLE 0x85B1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_FOG_SCALE_SGIX 0x81FC +#define GL_FOG_SCALE_VALUE_SGIX 0x81FD +#endif + +#ifndef GL_SUNX_constant_data +#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5 +#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6 +#endif + +#ifndef GL_SUN_global_alpha +#define GL_GLOBAL_ALPHA_SUN 0x81D9 +#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA +#endif + +#ifndef GL_SUN_triangle_list +#define GL_RESTART_SUN 0x0001 +#define GL_REPLACE_MIDDLE_SUN 0x0002 +#define GL_REPLACE_OLDEST_SUN 0x0003 +#define GL_TRIANGLE_LIST_SUN 0x81D7 +#define GL_REPLACEMENT_CODE_SUN 0x81D8 +#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0 +#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1 +#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2 +#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3 +#define GL_R1UI_V3F_SUN 0x85C4 +#define GL_R1UI_C4UB_V3F_SUN 0x85C5 +#define GL_R1UI_C3F_V3F_SUN 0x85C6 +#define GL_R1UI_N3F_V3F_SUN 0x85C7 +#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8 +#define GL_R1UI_T2F_V3F_SUN 0x85C9 +#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA +#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB +#endif + +#ifndef GL_SUN_vertex +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_BLEND_DST_RGB_EXT 0x80C8 +#define GL_BLEND_SRC_RGB_EXT 0x80C9 +#define GL_BLEND_DST_ALPHA_EXT 0x80CA +#define GL_BLEND_SRC_ALPHA_EXT 0x80CB +#endif + +#ifndef GL_INGR_color_clamp +#define GL_RED_MIN_CLAMP_INGR 0x8560 +#define GL_GREEN_MIN_CLAMP_INGR 0x8561 +#define GL_BLUE_MIN_CLAMP_INGR 0x8562 +#define GL_ALPHA_MIN_CLAMP_INGR 0x8563 +#define GL_RED_MAX_CLAMP_INGR 0x8564 +#define GL_GREEN_MAX_CLAMP_INGR 0x8565 +#define GL_BLUE_MAX_CLAMP_INGR 0x8566 +#define GL_ALPHA_MAX_CLAMP_INGR 0x8567 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INTERLACE_READ_INGR 0x8568 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_INCR_WRAP_EXT 0x8507 +#define GL_DECR_WRAP_EXT 0x8508 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_422_EXT 0x80CC +#define GL_422_REV_EXT 0x80CD +#define GL_422_AVERAGE_EXT 0x80CE +#define GL_422_REV_AVERAGE_EXT 0x80CF +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NORMAL_MAP_NV 0x8511 +#define GL_REFLECTION_MAP_NV 0x8512 +#endif + +#ifndef GL_EXT_texture_cube_map +#define GL_NORMAL_MAP_EXT 0x8511 +#define GL_REFLECTION_MAP_EXT 0x8512 +#define GL_TEXTURE_CUBE_MAP_EXT 0x8513 +#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518 +#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519 +#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A +#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B +#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_WRAP_BORDER_SUN 0x81D4 +#endif + +#ifndef GL_EXT_texture_env_add +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD +#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500 +#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_MODELVIEW0_STACK_DEPTH_EXT GL_MODELVIEW_STACK_DEPTH +#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502 +#define GL_MODELVIEW0_MATRIX_EXT GL_MODELVIEW_MATRIX +#define GL_MODELVIEW1_MATRIX_EXT 0x8506 +#define GL_VERTEX_WEIGHTING_EXT 0x8509 +#define GL_MODELVIEW0_EXT GL_MODELVIEW +#define GL_MODELVIEW1_EXT 0x850A +#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B +#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C +#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D +#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E +#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F +#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510 +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_MAX_SHININESS_NV 0x8504 +#define GL_MAX_SPOT_EXPONENT_NV 0x8505 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_NV 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E +#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F +#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520 +#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521 +#endif + +#ifndef GL_NV_register_combiners +#define GL_REGISTER_COMBINERS_NV 0x8522 +#define GL_VARIABLE_A_NV 0x8523 +#define GL_VARIABLE_B_NV 0x8524 +#define GL_VARIABLE_C_NV 0x8525 +#define GL_VARIABLE_D_NV 0x8526 +#define GL_VARIABLE_E_NV 0x8527 +#define GL_VARIABLE_F_NV 0x8528 +#define GL_VARIABLE_G_NV 0x8529 +#define GL_CONSTANT_COLOR0_NV 0x852A +#define GL_CONSTANT_COLOR1_NV 0x852B +#define GL_PRIMARY_COLOR_NV 0x852C +#define GL_SECONDARY_COLOR_NV 0x852D +#define GL_SPARE0_NV 0x852E +#define GL_SPARE1_NV 0x852F +#define GL_DISCARD_NV 0x8530 +#define GL_E_TIMES_F_NV 0x8531 +#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532 +#define GL_UNSIGNED_IDENTITY_NV 0x8536 +#define GL_UNSIGNED_INVERT_NV 0x8537 +#define GL_EXPAND_NORMAL_NV 0x8538 +#define GL_EXPAND_NEGATE_NV 0x8539 +#define GL_HALF_BIAS_NORMAL_NV 0x853A +#define GL_HALF_BIAS_NEGATE_NV 0x853B +#define GL_SIGNED_IDENTITY_NV 0x853C +#define GL_SIGNED_NEGATE_NV 0x853D +#define GL_SCALE_BY_TWO_NV 0x853E +#define GL_SCALE_BY_FOUR_NV 0x853F +#define GL_SCALE_BY_ONE_HALF_NV 0x8540 +#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541 +#define GL_COMBINER_INPUT_NV 0x8542 +#define GL_COMBINER_MAPPING_NV 0x8543 +#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544 +#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545 +#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546 +#define GL_COMBINER_MUX_SUM_NV 0x8547 +#define GL_COMBINER_SCALE_NV 0x8548 +#define GL_COMBINER_BIAS_NV 0x8549 +#define GL_COMBINER_AB_OUTPUT_NV 0x854A +#define GL_COMBINER_CD_OUTPUT_NV 0x854B +#define GL_COMBINER_SUM_OUTPUT_NV 0x854C +#define GL_MAX_GENERAL_COMBINERS_NV 0x854D +#define GL_NUM_GENERAL_COMBINERS_NV 0x854E +#define GL_COLOR_SUM_CLAMP_NV 0x854F +#define GL_COMBINER0_NV 0x8550 +#define GL_COMBINER1_NV 0x8551 +#define GL_COMBINER2_NV 0x8552 +#define GL_COMBINER3_NV 0x8553 +#define GL_COMBINER4_NV 0x8554 +#define GL_COMBINER5_NV 0x8555 +#define GL_COMBINER6_NV 0x8556 +#define GL_COMBINER7_NV 0x8557 +/* reuse GL_TEXTURE0_ARB */ +/* reuse GL_TEXTURE1_ARB */ +/* reuse GL_ZERO */ +/* reuse GL_NONE */ +/* reuse GL_FOG */ +#endif + +#ifndef GL_NV_fog_distance +#define GL_FOG_DISTANCE_MODE_NV 0x855A +#define GL_EYE_RADIAL_NV 0x855B +#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C +/* reuse GL_EYE_PLANE */ +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_EMBOSS_LIGHT_NV 0x855D +#define GL_EMBOSS_CONSTANT_NV 0x855E +#define GL_EMBOSS_MAP_NV 0x855F +#endif + +#ifndef GL_NV_blend_square +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_COMBINE4_NV 0x8503 +#define GL_SOURCE3_RGB_NV 0x8583 +#define GL_SOURCE3_ALPHA_NV 0x858B +#define GL_OPERAND3_RGB_NV 0x8593 +#define GL_OPERAND3_ALPHA_NV 0x859B +#endif + +#ifndef GL_MESA_resize_buffers +#endif + +#ifndef GL_MESA_window_pos +#endif + +#ifndef GL_EXT_texture_compression_s3tc +#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_CULL_VERTEX_IBM 103050 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_VERTEX_ARRAY_LIST_IBM 103070 +#define GL_NORMAL_ARRAY_LIST_IBM 103071 +#define GL_COLOR_ARRAY_LIST_IBM 103072 +#define GL_INDEX_ARRAY_LIST_IBM 103073 +#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074 +#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075 +#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076 +#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077 +#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080 +#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081 +#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082 +#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083 +#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084 +#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085 +#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086 +#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087 +#endif + +#ifndef GL_SGIX_subsample +#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0 +#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1 +#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2 +#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3 +#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_YCRCB_SGIX 0x8318 +#define GL_YCRCBA_SGIX 0x8319 +#endif + +#ifndef GL_SGI_depth_pass_instrument +#define GL_DEPTH_PASS_INSTRUMENT_SGIX 0x8310 +#define GL_DEPTH_PASS_INSTRUMENT_COUNTERS_SGIX 0x8311 +#define GL_DEPTH_PASS_INSTRUMENT_MAX_SGIX 0x8312 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0 +#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_MULTISAMPLE_3DFX 0x86B2 +#define GL_SAMPLE_BUFFERS_3DFX 0x86B3 +#define GL_SAMPLES_3DFX 0x86B4 +#define GL_MULTISAMPLE_BIT_3DFX 0x20000000 +#endif + +#ifndef GL_3DFX_tbuffer +#endif + +#ifndef GL_EXT_multisample +#define GL_MULTISAMPLE_EXT 0x809D +#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E +#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F +#define GL_SAMPLE_MASK_EXT 0x80A0 +#define GL_1PASS_EXT 0x80A1 +#define GL_2PASS_0_EXT 0x80A2 +#define GL_2PASS_1_EXT 0x80A3 +#define GL_4PASS_0_EXT 0x80A4 +#define GL_4PASS_1_EXT 0x80A5 +#define GL_4PASS_2_EXT 0x80A6 +#define GL_4PASS_3_EXT 0x80A7 +#define GL_SAMPLE_BUFFERS_EXT 0x80A8 +#define GL_SAMPLES_EXT 0x80A9 +#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA +#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB +#define GL_SAMPLE_PATTERN_EXT 0x80AC +#define GL_MULTISAMPLE_BIT_EXT 0x20000000 +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_VERTEX_PRECLIP_SGIX 0x83EE +#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_CONVOLUTION_HINT_SGIX 0x8316 +#endif + +#ifndef GL_SGIX_resample +#define GL_PACK_RESAMPLE_SGIX 0x842C +#define GL_UNPACK_RESAMPLE_SGIX 0x842D +#define GL_RESAMPLE_REPLICATE_SGIX 0x842E +#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F +#define GL_RESAMPLE_DECIMATE_SGIX 0x8430 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0 +#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1 +#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2 +#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3 +#define GL_EYE_POINT_SGIS 0x81F4 +#define GL_OBJECT_POINT_SGIS 0x81F5 +#define GL_EYE_LINE_SGIS 0x81F6 +#define GL_OBJECT_LINE_SGIS 0x81F7 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_DOT3_RGB_EXT 0x8740 +#define GL_DOT3_RGBA_EXT 0x8741 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_MIRROR_CLAMP_ATI 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743 +#endif + +#ifndef GL_NV_fence +#define GL_ALL_COMPLETED_NV 0x84F2 +#define GL_FENCE_STATUS_NV 0x84F3 +#define GL_FENCE_CONDITION_NV 0x84F4 +#endif + +#ifndef GL_IBM_texture_mirrored_repeat +#define GL_MIRRORED_REPEAT_IBM 0x8370 +#endif + +#ifndef GL_NV_evaluators +#define GL_EVAL_2D_NV 0x86C0 +#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1 +#define GL_MAP_TESSELLATION_NV 0x86C2 +#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3 +#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4 +#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5 +#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6 +#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7 +#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8 +#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9 +#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA +#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB +#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC +#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD +#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE +#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF +#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0 +#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1 +#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2 +#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3 +#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4 +#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5 +#define GL_MAX_MAP_TESSELLATION_NV 0x86D6 +#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7 +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_DEPTH_STENCIL_NV 0x84F9 +#define GL_UNSIGNED_INT_24_8_NV 0x84FA +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_PER_STAGE_CONSTANTS_NV 0x8535 +#endif + +#ifndef GL_NV_texture_compression_vtc +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_TEXTURE_RECTANGLE_NV 0x84F5 +#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 +#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 +#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 +#endif + +#ifndef GL_NV_texture_shader +#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C +#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D +#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E +#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9 +#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA +#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB +#define GL_DSDT_MAG_INTENSITY_NV 0x86DC +#define GL_SHADER_CONSISTENT_NV 0x86DD +#define GL_TEXTURE_SHADER_NV 0x86DE +#define GL_SHADER_OPERATION_NV 0x86DF +#define GL_CULL_MODES_NV 0x86E0 +#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1 +#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2 +#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3 +#define GL_OFFSET_TEXTURE_2D_MATRIX_NV GL_OFFSET_TEXTURE_MATRIX_NV +#define GL_OFFSET_TEXTURE_2D_SCALE_NV GL_OFFSET_TEXTURE_SCALE_NV +#define GL_OFFSET_TEXTURE_2D_BIAS_NV GL_OFFSET_TEXTURE_BIAS_NV +#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4 +#define GL_CONST_EYE_NV 0x86E5 +#define GL_PASS_THROUGH_NV 0x86E6 +#define GL_CULL_FRAGMENT_NV 0x86E7 +#define GL_OFFSET_TEXTURE_2D_NV 0x86E8 +#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9 +#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA +#define GL_DOT_PRODUCT_NV 0x86EC +#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED +#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE +#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0 +#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1 +#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2 +#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3 +#define GL_HILO_NV 0x86F4 +#define GL_DSDT_NV 0x86F5 +#define GL_DSDT_MAG_NV 0x86F6 +#define GL_DSDT_MAG_VIB_NV 0x86F7 +#define GL_HILO16_NV 0x86F8 +#define GL_SIGNED_HILO_NV 0x86F9 +#define GL_SIGNED_HILO16_NV 0x86FA +#define GL_SIGNED_RGBA_NV 0x86FB +#define GL_SIGNED_RGBA8_NV 0x86FC +#define GL_SIGNED_RGB_NV 0x86FE +#define GL_SIGNED_RGB8_NV 0x86FF +#define GL_SIGNED_LUMINANCE_NV 0x8701 +#define GL_SIGNED_LUMINANCE8_NV 0x8702 +#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703 +#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704 +#define GL_SIGNED_ALPHA_NV 0x8705 +#define GL_SIGNED_ALPHA8_NV 0x8706 +#define GL_SIGNED_INTENSITY_NV 0x8707 +#define GL_SIGNED_INTENSITY8_NV 0x8708 +#define GL_DSDT8_NV 0x8709 +#define GL_DSDT8_MAG8_NV 0x870A +#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B +#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C +#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D +#define GL_HI_SCALE_NV 0x870E +#define GL_LO_SCALE_NV 0x870F +#define GL_DS_SCALE_NV 0x8710 +#define GL_DT_SCALE_NV 0x8711 +#define GL_MAGNITUDE_SCALE_NV 0x8712 +#define GL_VIBRANCE_SCALE_NV 0x8713 +#define GL_HI_BIAS_NV 0x8714 +#define GL_LO_BIAS_NV 0x8715 +#define GL_DS_BIAS_NV 0x8716 +#define GL_DT_BIAS_NV 0x8717 +#define GL_MAGNITUDE_BIAS_NV 0x8718 +#define GL_VIBRANCE_BIAS_NV 0x8719 +#define GL_TEXTURE_BORDER_VALUES_NV 0x871A +#define GL_TEXTURE_HI_SIZE_NV 0x871B +#define GL_TEXTURE_LO_SIZE_NV 0x871C +#define GL_TEXTURE_DS_SIZE_NV 0x871D +#define GL_TEXTURE_DT_SIZE_NV 0x871E +#define GL_TEXTURE_MAG_SIZE_NV 0x871F +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533 +#endif + +#ifndef GL_NV_vertex_program +#define GL_VERTEX_PROGRAM_NV 0x8620 +#define GL_VERTEX_STATE_PROGRAM_NV 0x8621 +#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623 +#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624 +#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625 +#define GL_CURRENT_ATTRIB_NV 0x8626 +#define GL_PROGRAM_LENGTH_NV 0x8627 +#define GL_PROGRAM_STRING_NV 0x8628 +#define GL_MODELVIEW_PROJECTION_NV 0x8629 +#define GL_IDENTITY_NV 0x862A +#define GL_INVERSE_NV 0x862B +#define GL_TRANSPOSE_NV 0x862C +#define GL_INVERSE_TRANSPOSE_NV 0x862D +#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E +#define GL_MAX_TRACK_MATRICES_NV 0x862F +#define GL_MATRIX0_NV 0x8630 +#define GL_MATRIX1_NV 0x8631 +#define GL_MATRIX2_NV 0x8632 +#define GL_MATRIX3_NV 0x8633 +#define GL_MATRIX4_NV 0x8634 +#define GL_MATRIX5_NV 0x8635 +#define GL_MATRIX6_NV 0x8636 +#define GL_MATRIX7_NV 0x8637 +#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640 +#define GL_CURRENT_MATRIX_NV 0x8641 +#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642 +#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643 +#define GL_PROGRAM_PARAMETER_NV 0x8644 +#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645 +#define GL_PROGRAM_TARGET_NV 0x8646 +#define GL_PROGRAM_RESIDENT_NV 0x8647 +#define GL_TRACK_MATRIX_NV 0x8648 +#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649 +#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A +#define GL_PROGRAM_ERROR_POSITION_NV 0x864B +#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650 +#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651 +#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652 +#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653 +#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654 +#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655 +#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656 +#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657 +#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658 +#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659 +#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A +#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B +#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C +#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D +#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E +#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F +#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660 +#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661 +#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662 +#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663 +#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664 +#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665 +#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666 +#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667 +#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668 +#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669 +#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A +#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B +#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C +#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D +#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E +#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F +#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670 +#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671 +#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672 +#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673 +#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674 +#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675 +#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676 +#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677 +#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678 +#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679 +#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A +#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B +#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C +#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D +#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E +#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369 +#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A +#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SCALEBIAS_HINT_SGIX 0x8322 +#endif + +#ifndef GL_OML_interlace +#define GL_INTERLACE_OML 0x8980 +#define GL_INTERLACE_READ_OML 0x8981 +#endif + +#ifndef GL_OML_subsample +#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982 +#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983 +#endif + +#ifndef GL_OML_resample +#define GL_PACK_RESAMPLE_OML 0x8984 +#define GL_UNPACK_RESAMPLE_OML 0x8985 +#define GL_RESAMPLE_REPLICATE_OML 0x8986 +#define GL_RESAMPLE_ZERO_FILL_OML 0x8987 +#define GL_RESAMPLE_AVERAGE_OML 0x8988 +#define GL_RESAMPLE_DECIMATE_OML 0x8989 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E +#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_BUMP_ROT_MATRIX_ATI 0x8775 +#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776 +#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777 +#define GL_BUMP_TEX_UNITS_ATI 0x8778 +#define GL_DUDV_ATI 0x8779 +#define GL_DU8DV8_ATI 0x877A +#define GL_BUMP_ENVMAP_ATI 0x877B +#define GL_BUMP_TARGET_ATI 0x877C +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_FRAGMENT_SHADER_ATI 0x8920 +#define GL_REG_0_ATI 0x8921 +#define GL_REG_1_ATI 0x8922 +#define GL_REG_2_ATI 0x8923 +#define GL_REG_3_ATI 0x8924 +#define GL_REG_4_ATI 0x8925 +#define GL_REG_5_ATI 0x8926 +#define GL_REG_6_ATI 0x8927 +#define GL_REG_7_ATI 0x8928 +#define GL_REG_8_ATI 0x8929 +#define GL_REG_9_ATI 0x892A +#define GL_REG_10_ATI 0x892B +#define GL_REG_11_ATI 0x892C +#define GL_REG_12_ATI 0x892D +#define GL_REG_13_ATI 0x892E +#define GL_REG_14_ATI 0x892F +#define GL_REG_15_ATI 0x8930 +#define GL_REG_16_ATI 0x8931 +#define GL_REG_17_ATI 0x8932 +#define GL_REG_18_ATI 0x8933 +#define GL_REG_19_ATI 0x8934 +#define GL_REG_20_ATI 0x8935 +#define GL_REG_21_ATI 0x8936 +#define GL_REG_22_ATI 0x8937 +#define GL_REG_23_ATI 0x8938 +#define GL_REG_24_ATI 0x8939 +#define GL_REG_25_ATI 0x893A +#define GL_REG_26_ATI 0x893B +#define GL_REG_27_ATI 0x893C +#define GL_REG_28_ATI 0x893D +#define GL_REG_29_ATI 0x893E +#define GL_REG_30_ATI 0x893F +#define GL_REG_31_ATI 0x8940 +#define GL_CON_0_ATI 0x8941 +#define GL_CON_1_ATI 0x8942 +#define GL_CON_2_ATI 0x8943 +#define GL_CON_3_ATI 0x8944 +#define GL_CON_4_ATI 0x8945 +#define GL_CON_5_ATI 0x8946 +#define GL_CON_6_ATI 0x8947 +#define GL_CON_7_ATI 0x8948 +#define GL_CON_8_ATI 0x8949 +#define GL_CON_9_ATI 0x894A +#define GL_CON_10_ATI 0x894B +#define GL_CON_11_ATI 0x894C +#define GL_CON_12_ATI 0x894D +#define GL_CON_13_ATI 0x894E +#define GL_CON_14_ATI 0x894F +#define GL_CON_15_ATI 0x8950 +#define GL_CON_16_ATI 0x8951 +#define GL_CON_17_ATI 0x8952 +#define GL_CON_18_ATI 0x8953 +#define GL_CON_19_ATI 0x8954 +#define GL_CON_20_ATI 0x8955 +#define GL_CON_21_ATI 0x8956 +#define GL_CON_22_ATI 0x8957 +#define GL_CON_23_ATI 0x8958 +#define GL_CON_24_ATI 0x8959 +#define GL_CON_25_ATI 0x895A +#define GL_CON_26_ATI 0x895B +#define GL_CON_27_ATI 0x895C +#define GL_CON_28_ATI 0x895D +#define GL_CON_29_ATI 0x895E +#define GL_CON_30_ATI 0x895F +#define GL_CON_31_ATI 0x8960 +#define GL_MOV_ATI 0x8961 +#define GL_ADD_ATI 0x8963 +#define GL_MUL_ATI 0x8964 +#define GL_SUB_ATI 0x8965 +#define GL_DOT3_ATI 0x8966 +#define GL_DOT4_ATI 0x8967 +#define GL_MAD_ATI 0x8968 +#define GL_LERP_ATI 0x8969 +#define GL_CND_ATI 0x896A +#define GL_CND0_ATI 0x896B +#define GL_DOT2_ADD_ATI 0x896C +#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D +#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E +#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F +#define GL_NUM_PASSES_ATI 0x8970 +#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971 +#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972 +#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973 +#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974 +#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975 +#define GL_SWIZZLE_STR_ATI 0x8976 +#define GL_SWIZZLE_STQ_ATI 0x8977 +#define GL_SWIZZLE_STR_DR_ATI 0x8978 +#define GL_SWIZZLE_STQ_DQ_ATI 0x8979 +#define GL_SWIZZLE_STRQ_ATI 0x897A +#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B +#define GL_RED_BIT_ATI 0x00000001 +#define GL_GREEN_BIT_ATI 0x00000002 +#define GL_BLUE_BIT_ATI 0x00000004 +#define GL_2X_BIT_ATI 0x00000001 +#define GL_4X_BIT_ATI 0x00000002 +#define GL_8X_BIT_ATI 0x00000004 +#define GL_HALF_BIT_ATI 0x00000008 +#define GL_QUARTER_BIT_ATI 0x00000010 +#define GL_EIGHTH_BIT_ATI 0x00000020 +#define GL_SATURATE_BIT_ATI 0x00000040 +#define GL_COMP_BIT_ATI 0x00000002 +#define GL_NEGATE_BIT_ATI 0x00000004 +#define GL_BIAS_BIT_ATI 0x00000008 +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_PN_TRIANGLES_ATI 0x87F0 +#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1 +#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2 +#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3 +#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4 +#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5 +#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6 +#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7 +#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8 +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_STATIC_ATI 0x8760 +#define GL_DYNAMIC_ATI 0x8761 +#define GL_PRESERVE_ATI 0x8762 +#define GL_DISCARD_ATI 0x8763 +#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764 +#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765 +#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766 +#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767 +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_VERTEX_SHADER_EXT 0x8780 +#define GL_VERTEX_SHADER_BINDING_EXT 0x8781 +#define GL_OP_INDEX_EXT 0x8782 +#define GL_OP_NEGATE_EXT 0x8783 +#define GL_OP_DOT3_EXT 0x8784 +#define GL_OP_DOT4_EXT 0x8785 +#define GL_OP_MUL_EXT 0x8786 +#define GL_OP_ADD_EXT 0x8787 +#define GL_OP_MADD_EXT 0x8788 +#define GL_OP_FRAC_EXT 0x8789 +#define GL_OP_MAX_EXT 0x878A +#define GL_OP_MIN_EXT 0x878B +#define GL_OP_SET_GE_EXT 0x878C +#define GL_OP_SET_LT_EXT 0x878D +#define GL_OP_CLAMP_EXT 0x878E +#define GL_OP_FLOOR_EXT 0x878F +#define GL_OP_ROUND_EXT 0x8790 +#define GL_OP_EXP_BASE_2_EXT 0x8791 +#define GL_OP_LOG_BASE_2_EXT 0x8792 +#define GL_OP_POWER_EXT 0x8793 +#define GL_OP_RECIP_EXT 0x8794 +#define GL_OP_RECIP_SQRT_EXT 0x8795 +#define GL_OP_SUB_EXT 0x8796 +#define GL_OP_CROSS_PRODUCT_EXT 0x8797 +#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798 +#define GL_OP_MOV_EXT 0x8799 +#define GL_OUTPUT_VERTEX_EXT 0x879A +#define GL_OUTPUT_COLOR0_EXT 0x879B +#define GL_OUTPUT_COLOR1_EXT 0x879C +#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D +#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E +#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F +#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0 +#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1 +#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2 +#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3 +#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4 +#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5 +#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6 +#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7 +#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8 +#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9 +#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA +#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB +#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC +#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD +#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE +#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF +#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0 +#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1 +#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2 +#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3 +#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4 +#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5 +#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6 +#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7 +#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8 +#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9 +#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA +#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB +#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC +#define GL_OUTPUT_FOG_EXT 0x87BD +#define GL_SCALAR_EXT 0x87BE +#define GL_VECTOR_EXT 0x87BF +#define GL_MATRIX_EXT 0x87C0 +#define GL_VARIANT_EXT 0x87C1 +#define GL_INVARIANT_EXT 0x87C2 +#define GL_LOCAL_CONSTANT_EXT 0x87C3 +#define GL_LOCAL_EXT 0x87C4 +#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5 +#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6 +#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7 +#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8 +#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9 +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD +#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE +#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF +#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0 +#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1 +#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2 +#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3 +#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4 +#define GL_X_EXT 0x87D5 +#define GL_Y_EXT 0x87D6 +#define GL_Z_EXT 0x87D7 +#define GL_W_EXT 0x87D8 +#define GL_NEGATIVE_X_EXT 0x87D9 +#define GL_NEGATIVE_Y_EXT 0x87DA +#define GL_NEGATIVE_Z_EXT 0x87DB +#define GL_NEGATIVE_W_EXT 0x87DC +#define GL_ZERO_EXT 0x87DD +#define GL_ONE_EXT 0x87DE +#define GL_NEGATIVE_ONE_EXT 0x87DF +#define GL_NORMALIZED_RANGE_EXT 0x87E0 +#define GL_FULL_RANGE_EXT 0x87E1 +#define GL_CURRENT_VERTEX_EXT 0x87E2 +#define GL_MVP_MATRIX_EXT 0x87E3 +#define GL_VARIANT_VALUE_EXT 0x87E4 +#define GL_VARIANT_DATATYPE_EXT 0x87E5 +#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6 +#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7 +#define GL_VARIANT_ARRAY_EXT 0x87E8 +#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9 +#define GL_INVARIANT_VALUE_EXT 0x87EA +#define GL_INVARIANT_DATATYPE_EXT 0x87EB +#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC +#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_MAX_VERTEX_STREAMS_ATI 0x876B +#define GL_VERTEX_STREAM0_ATI 0x876C +#define GL_VERTEX_STREAM1_ATI 0x876D +#define GL_VERTEX_STREAM2_ATI 0x876E +#define GL_VERTEX_STREAM3_ATI 0x876F +#define GL_VERTEX_STREAM4_ATI 0x8770 +#define GL_VERTEX_STREAM5_ATI 0x8771 +#define GL_VERTEX_STREAM6_ATI 0x8772 +#define GL_VERTEX_STREAM7_ATI 0x8773 +#define GL_VERTEX_SOURCE_ATI 0x8774 +#endif + +#ifndef GL_ATI_element_array +#define GL_ELEMENT_ARRAY_ATI 0x8768 +#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769 +#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A +#endif + +#ifndef GL_SUN_mesh_array +#define GL_QUAD_MESH_SUN 0x8614 +#define GL_TRIANGLE_MESH_SUN 0x8615 +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SLICE_ACCUM_SUN 0x85CC +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_DEPTH_CLAMP_NV 0x864F +#endif + +#ifndef GL_NV_occlusion_query +#define GL_PIXEL_COUNTER_BITS_NV 0x8864 +#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865 +#define GL_PIXEL_COUNT_NV 0x8866 +#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867 +#endif + +#ifndef GL_NV_point_sprite +#define GL_POINT_SPRITE_NV 0x8861 +#define GL_COORD_REPLACE_NV 0x8862 +#define GL_POINT_SPRITE_R_MODE_NV 0x8863 +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850 +#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852 +#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853 +#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854 +#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856 +#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857 +#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858 +#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859 +#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A +#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B +#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C +#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D +#define GL_HILO8_NV 0x885E +#define GL_SIGNED_HILO8_NV 0x885F +#define GL_FORCE_BLUE_TO_ONE_NV 0x8860 +#endif + +#ifndef GL_NV_vertex_program1_1 +#endif + +#ifndef GL_EXT_shadow_funcs +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 +#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2 +#endif + +/* The values of those in the official file and the extension spec are different. However, the values +in the headers on OS X are those. So we prefer OS X version. */ +#ifndef GL_APPLE_element_array +#define GL_ELEMENT_ARRAY_APPLE 0x8A0C +#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8A0D +#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x8A0E +#endif + +#ifndef GL_APPLE_fence +#define GL_DRAW_PIXELS_APPLE 0x8A0A +#define GL_FENCE_APPLE 0x8A0B +#endif + +#ifndef GL_APPLE_vertex_array_object +#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5 +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D +#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E +#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F +#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521 +#define GL_STORAGE_CACHED_APPLE 0x85BE +#define GL_STORAGE_SHARED_APPLE 0x85BF +#endif + +#ifndef GL_APPLE_flush_buffer_range +#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13 +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_YCBCR_422_APPLE 0x85B9 +#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB +#endif + +#ifndef GL_S3_s3tc +#define GL_RGB_S3TC 0x83A0 +#define GL_RGB4_S3TC 0x83A1 +#define GL_RGBA_S3TC 0x83A2 +#define GL_RGBA4_S3TC 0x83A3 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_MAX_DRAW_BUFFERS_ATI 0x8824 +#define GL_DRAW_BUFFER0_ATI 0x8825 +#define GL_DRAW_BUFFER1_ATI 0x8826 +#define GL_DRAW_BUFFER2_ATI 0x8827 +#define GL_DRAW_BUFFER3_ATI 0x8828 +#define GL_DRAW_BUFFER4_ATI 0x8829 +#define GL_DRAW_BUFFER5_ATI 0x882A +#define GL_DRAW_BUFFER6_ATI 0x882B +#define GL_DRAW_BUFFER7_ATI 0x882C +#define GL_DRAW_BUFFER8_ATI 0x882D +#define GL_DRAW_BUFFER9_ATI 0x882E +#define GL_DRAW_BUFFER10_ATI 0x882F +#define GL_DRAW_BUFFER11_ATI 0x8830 +#define GL_DRAW_BUFFER12_ATI 0x8831 +#define GL_DRAW_BUFFER13_ATI 0x8832 +#define GL_DRAW_BUFFER14_ATI 0x8833 +#define GL_DRAW_BUFFER15_ATI 0x8834 +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_TYPE_RGBA_FLOAT_ATI 0x8820 +#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835 +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_MODULATE_ADD_ATI 0x8744 +#define GL_MODULATE_SIGNED_ADD_ATI 0x8745 +#define GL_MODULATE_SUBTRACT_ATI 0x8746 +#endif + +#ifndef GL_ATI_texture_float +#define GL_RGBA_FLOAT32_ATI 0x8814 +#define GL_RGB_FLOAT32_ATI 0x8815 +#define GL_ALPHA_FLOAT32_ATI 0x8816 +#define GL_INTENSITY_FLOAT32_ATI 0x8817 +#define GL_LUMINANCE_FLOAT32_ATI 0x8818 +#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819 +#define GL_RGBA_FLOAT16_ATI 0x881A +#define GL_RGB_FLOAT16_ATI 0x881B +#define GL_ALPHA_FLOAT16_ATI 0x881C +#define GL_INTENSITY_FLOAT16_ATI 0x881D +#define GL_LUMINANCE_FLOAT16_ATI 0x881E +#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F +#endif + +#ifndef GL_NV_float_buffer +#define GL_FLOAT_R_NV 0x8880 +#define GL_FLOAT_RG_NV 0x8881 +#define GL_FLOAT_RGB_NV 0x8882 +#define GL_FLOAT_RGBA_NV 0x8883 +#define GL_FLOAT_R16_NV 0x8884 +#define GL_FLOAT_R32_NV 0x8885 +#define GL_FLOAT_RG16_NV 0x8886 +#define GL_FLOAT_RG32_NV 0x8887 +#define GL_FLOAT_RGB16_NV 0x8888 +#define GL_FLOAT_RGB32_NV 0x8889 +#define GL_FLOAT_RGBA16_NV 0x888A +#define GL_FLOAT_RGBA32_NV 0x888B +#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C +#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D +#define GL_FLOAT_RGBA_MODE_NV 0x888E +#endif + +#ifndef GL_NV_fragment_program +#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868 +#define GL_FRAGMENT_PROGRAM_NV 0x8870 +#define GL_MAX_TEXTURE_COORDS_NV 0x8871 +#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872 +#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873 +#define GL_PROGRAM_ERROR_STRING_NV 0x8874 +#endif + +#ifndef GL_NV_half_float +#define GL_HALF_FLOAT_NV 0x140B +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878 +#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879 +#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A +#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B +#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C +#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D +#endif + +#ifndef GL_NV_primitive_restart +#define GL_PRIMITIVE_RESTART_NV 0x8558 +#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559 +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F +#endif + +#ifndef GL_NV_vertex_program2 +#endif + +#ifndef GL_ATI_map_object_buffer +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_STENCIL_BACK_FUNC_ATI 0x8800 +#define GL_STENCIL_BACK_FAIL_ATI 0x8801 +#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802 +#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803 +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#endif + +#ifndef GL_OES_read_format +#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A +#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890 +#define GL_DEPTH_BOUNDS_EXT 0x8891 +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_MIRROR_CLAMP_EXT 0x8742 +#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743 +#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_BLEND_EQUATION_RGB_EXT GL_BLEND_EQUATION +#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D +#endif + +#ifndef GL_MESA_pack_invert +#define GL_PACK_INVERT_MESA 0x8758 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA +#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB +#define GL_YCBCR_MESA 0x8757 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB +#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC +#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED +#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF +#endif + +#ifndef GL_NV_fragment_program_option +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4 +#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5 +#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6 +#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7 +#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8 +#endif + +#ifndef GL_NV_vertex_program2_option +/* reuse GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV */ +/* reuse GL_MAX_PROGRAM_CALL_DEPTH_NV */ +#endif + +#ifndef GL_NV_vertex_program3 +/* reuse GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB */ +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 +#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8 +#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0 +#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3 +#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4 +#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5 +#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6 +#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7 +#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 0x8CD8 +#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9 +#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA +#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB +#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC +#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD +#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF +#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0 +#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1 +#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2 +#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3 +#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4 +#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5 +#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6 +#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7 +#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8 +#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9 +#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA +#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB +#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC +#define GL_COLOR_ATTACHMENT13_EXT 0x8CED +#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE +#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF +#define GL_DEPTH_ATTACHMENT_EXT 0x8D00 +#define GL_STENCIL_ATTACHMENT_EXT 0x8D20 +#define GL_FRAMEBUFFER_EXT 0x8D40 +#define GL_RENDERBUFFER_EXT 0x8D41 +#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42 +#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43 +#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44 +#define GL_STENCIL_INDEX1_EXT 0x8D46 +#define GL_STENCIL_INDEX4_EXT 0x8D47 +#define GL_STENCIL_INDEX8_EXT 0x8D48 +#define GL_STENCIL_INDEX16_EXT 0x8D49 +#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50 +#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51 +#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52 +#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53 +#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54 +#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55 +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_READ_FRAMEBUFFER_EXT 0x8CA8 +#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9 +#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6 +#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA +#endif + +#ifndef GL_EXT_packed_depth_stencil +#define GL_DEPTH_STENCIL_EXT 0x84F9 +#define GL_UNSIGNED_INT_24_8_EXT 0x84FA +#define GL_DEPTH24_STENCIL8_EXT 0x88F0 +#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1 +#endif + +#ifndef GL_EXT_texture_sRGB +#define GL_SRGB_EXT 0x8C40 +#define GL_SRGB8_EXT 0x8C41 +#define GL_SRGB_ALPHA_EXT 0x8C42 +#define GL_SRGB8_ALPHA8_EXT 0x8C43 +#define GL_SLUMINANCE_ALPHA_EXT 0x8C44 +#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45 +#define GL_SLUMINANCE_EXT 0x8C46 +#define GL_SLUMINANCE8_EXT 0x8C47 +#define GL_COMPRESSED_SRGB_EXT 0x8C48 +#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49 +#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A +#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B +#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E +#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F +#endif + +#ifndef GL_EXT_framebuffer_sRGB +#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 +#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA +#endif + + +/*************************************************************/ + +#include <stddef.h> +#ifndef GL_VERSION_2_0 +/* GL type for program/shader text */ +typedef char GLchar; /* native character */ +#endif + +#ifndef GL_VERSION_1_5 +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptr; +typedef ptrdiff_t GLsizeiptr; +#endif + +#ifndef GL_ARB_vertex_buffer_object +/* GL types for handling large vertex buffer objects */ +typedef ptrdiff_t GLintptrARB; +typedef ptrdiff_t GLsizeiptrARB; +#endif + +#ifndef GL_ARB_shader_objects +/* GL types for handling shader object handles and program/shader text */ +typedef char GLcharARB; /* native character */ +typedef unsigned int GLhandleARB; /* shader object handle */ +#endif + +/* GL types for "half" precision (s10e5) float data in host memory */ +#ifndef GL_ARB_half_float_pixel +typedef unsigned short GLhalfARB; +#endif + +#ifndef GL_NV_half_float +typedef unsigned short GLhalfNV; +#endif + +#ifndef GLEXT_64_TYPES_DEFINED +/* This code block is duplicated in glxext.h, so must be protected */ +#define GLEXT_64_TYPES_DEFINED +/* Define int32_t, int64_t, and uint64_t types for UST/MSC */ +/* (as used in the GL_EXT_timer_query extension). */ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#include <inttypes.h> +#elif defined(__sun__) || defined(__digital__) +#include <inttypes.h> +#if defined(__STDC__) +#if defined(__arch64__) || defined(_LP64) +typedef long int int64_t; +typedef unsigned long int uint64_t; +#else +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#endif /* __arch64__ */ +#endif /* __STDC__ */ +#elif defined( __VMS ) || defined(__sgi) +#include <inttypes.h> +#elif defined(__SCO__) || defined(__USLC__) +#include <stdint.h> +#elif defined(__UNIXOS2__) || defined(__SOL64__) +typedef long int int32_t; +typedef long long int int64_t; +typedef unsigned long long int uint64_t; +#elif defined(_WIN32) && defined(__GNUC__) +#include <stdint.h> +#elif defined(_WIN32) +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +/* Fallback if nothing above works */ +#include <inttypes.h> +#endif +#endif + +#ifndef GL_EXT_timer_query +typedef int64_t GLint64EXT; +typedef uint64_t GLuint64EXT; +#endif + +#if !(defined GL_ARB_sync || defined GL_VERSION_3_0) +typedef int64_t GLint64; +typedef uint64_t GLuint64; +typedef struct __GLsync *GLsync; +#endif + +#ifndef GL_VERSION_1_2 +#define GL_VERSION_1_2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColor (GLclampf, GLclampf, GLclampf, GLclampf); +GLAPI void APIENTRY glBlendEquation (GLenum); +GLAPI void APIENTRY glDrawRangeElements (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTable (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTableParameterfv (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glColorTableParameteriv (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyColorTable (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glGetColorTable (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetColorTableParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glColorSubTable (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyColorSubTable (GLenum, GLsizei, GLint, GLint, GLsizei); +GLAPI void APIENTRY glConvolutionFilter1D (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionParameterf (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glConvolutionParameterfv (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glConvolutionParameteri (GLenum, GLenum, GLint); +GLAPI void APIENTRY glConvolutionParameteriv (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetConvolutionFilter (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetSeparableFilter (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); +GLAPI void APIENTRY glSeparableFilter2D (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); +GLAPI void APIENTRY glGetHistogram (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetHistogramParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetHistogramParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMinmax (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glHistogram (GLenum, GLsizei, GLenum, GLboolean); +GLAPI void APIENTRY glMinmax (GLenum, GLenum, GLboolean); +GLAPI void APIENTRY glResetHistogram (GLenum); +GLAPI void APIENTRY glResetMinmax (GLenum); +GLAPI void APIENTRY glTexImage3D (GLenum, GLint, GLint, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target); +typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_VERSION_1_3 +#define GL_VERSION_1_3 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTexture (GLenum); +GLAPI void APIENTRY glClientActiveTexture (GLenum); +GLAPI void APIENTRY glMultiTexCoord1d (GLenum, GLdouble); +GLAPI void APIENTRY glMultiTexCoord1dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord1f (GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexCoord1fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord1i (GLenum, GLint); +GLAPI void APIENTRY glMultiTexCoord1iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord1s (GLenum, GLshort); +GLAPI void APIENTRY glMultiTexCoord1sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord2d (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord2dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord2f (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord2fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord2i (GLenum, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord2iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord2s (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord2sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord3d (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord3dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord3f (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord3fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord3i (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord3iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord3s (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord3sv (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord4d (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord4dv (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord4f (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord4fv (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord4i (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord4iv (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord4s (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord4sv (GLenum, const GLshort *); +GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *); +GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *); +GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *); +GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *); +GLAPI void APIENTRY glSampleCoverage (GLclampf, GLboolean); +GLAPI void APIENTRY glCompressedTexImage3D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage2D (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage1D (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedTexImage (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_VERSION_1_4 +#define GL_VERSION_1_4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparate (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glFogCoordf (GLfloat); +GLAPI void APIENTRY glFogCoordfv (const GLfloat *); +GLAPI void APIENTRY glFogCoordd (GLdouble); +GLAPI void APIENTRY glFogCoorddv (const GLdouble *); +GLAPI void APIENTRY glFogCoordPointer (GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glMultiDrawArrays (GLenum, GLint *, GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawElements (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +GLAPI void APIENTRY glPointParameterf (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfv (GLenum, const GLfloat *); +GLAPI void APIENTRY glPointParameteri (GLenum, GLint); +GLAPI void APIENTRY glPointParameteriv (GLenum, const GLint *); +GLAPI void APIENTRY glSecondaryColor3b (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *); +GLAPI void APIENTRY glSecondaryColor3d (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *); +GLAPI void APIENTRY glSecondaryColor3f (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *); +GLAPI void APIENTRY glSecondaryColor3i (GLint, GLint, GLint); +GLAPI void APIENTRY glSecondaryColor3iv (const GLint *); +GLAPI void APIENTRY glSecondaryColor3s (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *); +GLAPI void APIENTRY glSecondaryColor3ub (GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *); +GLAPI void APIENTRY glSecondaryColor3ui (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *); +GLAPI void APIENTRY glSecondaryColor3us (GLushort, GLushort, GLushort); +GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *); +GLAPI void APIENTRY glSecondaryColorPointer (GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glWindowPos2d (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dv (const GLdouble *); +GLAPI void APIENTRY glWindowPos2f (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fv (const GLfloat *); +GLAPI void APIENTRY glWindowPos2i (GLint, GLint); +GLAPI void APIENTRY glWindowPos2iv (const GLint *); +GLAPI void APIENTRY glWindowPos2s (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2sv (const GLshort *); +GLAPI void APIENTRY glWindowPos3d (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dv (const GLdouble *); +GLAPI void APIENTRY glWindowPos3f (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fv (const GLfloat *); +GLAPI void APIENTRY glWindowPos3i (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3iv (const GLint *); +GLAPI void APIENTRY glWindowPos3s (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3sv (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v); +#endif + +#ifndef GL_VERSION_1_5 +#define GL_VERSION_1_5 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueries (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteQueries (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsQuery (GLuint); +GLAPI void APIENTRY glBeginQuery (GLenum, GLuint); +GLAPI void APIENTRY glEndQuery (GLenum); +GLAPI void APIENTRY glGetQueryiv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectuiv (GLuint, GLenum, GLuint *); +GLAPI void APIENTRY glBindBuffer (GLenum, GLuint); +GLAPI void APIENTRY glDeleteBuffers (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenBuffers (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsBuffer (GLuint); +GLAPI void APIENTRY glBufferData (GLenum, GLsizeiptr, const GLvoid *, GLenum); +GLAPI void APIENTRY glBufferSubData (GLenum, GLintptr, GLsizeiptr, const GLvoid *); +GLAPI void APIENTRY glGetBufferSubData (GLenum, GLintptr, GLsizeiptr, GLvoid *); +GLAPI GLvoid* APIENTRY glMapBuffer (GLenum, GLenum); +GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum); +GLAPI void APIENTRY glGetBufferParameteriv (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetBufferPointerv (GLenum, GLenum, GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params); +typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_VERSION_2_0 +#define GL_VERSION_2_0 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparate (GLenum, GLenum); +GLAPI void APIENTRY glDrawBuffers (GLsizei, const GLenum *); +GLAPI void APIENTRY glStencilOpSeparate (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glStencilFuncSeparate (GLenum, GLenum, GLint, GLuint); +GLAPI void APIENTRY glStencilMaskSeparate (GLenum, GLuint); +GLAPI void APIENTRY glAttachShader (GLuint, GLuint); +GLAPI void APIENTRY glBindAttribLocation (GLuint, GLuint, const GLchar *); +GLAPI void APIENTRY glCompileShader (GLuint); +GLAPI GLuint APIENTRY glCreateProgram (void); +GLAPI GLuint APIENTRY glCreateShader (GLenum); +GLAPI void APIENTRY glDeleteProgram (GLuint); +GLAPI void APIENTRY glDeleteShader (GLuint); +GLAPI void APIENTRY glDetachShader (GLuint, GLuint); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint); +GLAPI void APIENTRY glEnableVertexAttribArray (GLuint); +GLAPI void APIENTRY glGetActiveAttrib (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); +GLAPI void APIENTRY glGetActiveUniform (GLuint, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLchar *); +GLAPI void APIENTRY glGetAttachedShaders (GLuint, GLsizei, GLsizei *, GLuint *); +GLAPI GLint APIENTRY glGetAttribLocation (GLuint, const GLchar *); +GLAPI void APIENTRY glGetProgramiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetShaderiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetShaderInfoLog (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI void APIENTRY glGetShaderSource (GLuint, GLsizei, GLsizei *, GLchar *); +GLAPI GLint APIENTRY glGetUniformLocation (GLuint, const GLchar *); +GLAPI void APIENTRY glGetUniformfv (GLuint, GLint, GLfloat *); +GLAPI void APIENTRY glGetUniformiv (GLuint, GLint, GLint *); +GLAPI void APIENTRY glGetVertexAttribdv (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfv (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgram (GLuint); +GLAPI GLboolean APIENTRY glIsShader (GLuint); +GLAPI void APIENTRY glLinkProgram (GLuint); +GLAPI void APIENTRY glShaderSource (GLuint, GLsizei, const GLchar* *, const GLint *); +GLAPI void APIENTRY glUseProgram (GLuint); +GLAPI void APIENTRY glUniform1f (GLint, GLfloat); +GLAPI void APIENTRY glUniform2f (GLint, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform3f (GLint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform4f (GLint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform1i (GLint, GLint); +GLAPI void APIENTRY glUniform2i (GLint, GLint, GLint); +GLAPI void APIENTRY glUniform3i (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform4i (GLint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform1fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform2fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform3fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform4fv (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform1iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform2iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform3iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform4iv (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniformMatrix2fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4fv (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glValidateProgram (GLuint); +GLAPI void APIENTRY glVertexAttrib1d (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1f (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1s (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2d (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2f (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2s (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3d (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3f (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3s (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4Niv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4Nub (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttrib4bv (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4d (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dv (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4f (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fv (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4iv (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4s (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4sv (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubv (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4uiv (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4usv (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttribPointer (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha); +typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs); +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask); +typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name); +typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader); +typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void); +typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); +typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); +typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program); +typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader); +typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* *string, const GLint *length); +typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_ARB_multitexture +#define GL_ARB_multitexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveTextureARB (GLenum); +GLAPI void APIENTRY glClientActiveTextureARB (GLenum); +GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum, GLdouble); +GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum, GLfloat); +GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum, GLint); +GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum, GLshort); +GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum, const GLshort *); +GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum, const GLdouble *); +GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum, const GLfloat *); +GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum, const GLint *); +GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum, const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v); +#endif + +#ifndef GL_ARB_transpose_matrix +#define GL_ARB_transpose_matrix 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *); +GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *); +GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *); +GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m); +typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m); +#endif + +#ifndef GL_ARB_multisample +#define GL_ARB_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleCoverageARB (GLclampf, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLclampf value, GLboolean invert); +#endif + +#ifndef GL_ARB_texture_env_add +#define GL_ARB_texture_env_add 1 +#endif + +#ifndef GL_ARB_texture_cube_map +#define GL_ARB_texture_cube_map 1 +#endif + +#ifndef GL_ARB_texture_compression +#define GL_ARB_texture_compression 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum, GLint, GLint, GLsizei, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum, GLint, GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, GLvoid *img); +#endif + +#ifndef GL_ARB_texture_border_clamp +#define GL_ARB_texture_border_clamp 1 +#endif + +#ifndef GL_ARB_point_parameters +#define GL_ARB_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfARB (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvARB (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_ARB_vertex_blend +#define GL_ARB_vertex_blend 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWeightbvARB (GLint, const GLbyte *); +GLAPI void APIENTRY glWeightsvARB (GLint, const GLshort *); +GLAPI void APIENTRY glWeightivARB (GLint, const GLint *); +GLAPI void APIENTRY glWeightfvARB (GLint, const GLfloat *); +GLAPI void APIENTRY glWeightdvARB (GLint, const GLdouble *); +GLAPI void APIENTRY glWeightubvARB (GLint, const GLubyte *); +GLAPI void APIENTRY glWeightusvARB (GLint, const GLushort *); +GLAPI void APIENTRY glWeightuivARB (GLint, const GLuint *); +GLAPI void APIENTRY glWeightPointerARB (GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexBlendARB (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights); +typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights); +typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights); +typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights); +typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights); +typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights); +typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights); +typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count); +#endif + +#ifndef GL_ARB_matrix_palette +#define GL_ARB_matrix_palette 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint); +GLAPI void APIENTRY glMatrixIndexubvARB (GLint, const GLubyte *); +GLAPI void APIENTRY glMatrixIndexusvARB (GLint, const GLushort *); +GLAPI void APIENTRY glMatrixIndexuivARB (GLint, const GLuint *); +GLAPI void APIENTRY glMatrixIndexPointerARB (GLint, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index); +typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices); +typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_ARB_texture_env_combine +#define GL_ARB_texture_env_combine 1 +#endif + +#ifndef GL_ARB_texture_env_crossbar +#define GL_ARB_texture_env_crossbar 1 +#endif + +#ifndef GL_ARB_texture_env_dot3 +#define GL_ARB_texture_env_dot3 1 +#endif + +#ifndef GL_ARB_texture_mirrored_repeat +#define GL_ARB_texture_mirrored_repeat 1 +#endif + +#ifndef GL_ARB_depth_texture +#define GL_ARB_depth_texture 1 +#endif + +#ifndef GL_ARB_shadow +#define GL_ARB_shadow 1 +#endif + +#ifndef GL_ARB_shadow_ambient +#define GL_ARB_shadow_ambient 1 +#endif + +#ifndef GL_ARB_window_pos +#define GL_ARB_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dARB (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *); +GLAPI void APIENTRY glWindowPos2fARB (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *); +GLAPI void APIENTRY glWindowPos2iARB (GLint, GLint); +GLAPI void APIENTRY glWindowPos2ivARB (const GLint *); +GLAPI void APIENTRY glWindowPos2sARB (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2svARB (const GLshort *); +GLAPI void APIENTRY glWindowPos3dARB (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *); +GLAPI void APIENTRY glWindowPos3fARB (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *); +GLAPI void APIENTRY glWindowPos3iARB (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3ivARB (const GLint *); +GLAPI void APIENTRY glWindowPos3sARB (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3svARB (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v); +#endif + +#ifndef GL_ARB_vertex_program +#define GL_ARB_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttrib1dARB (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1fARB (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1sARB (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2dARB (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2fARB (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2sARB (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3dARB (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3fARB (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3sARB (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint, const GLbyte *); +GLAPI void APIENTRY glVertexAttrib4dARB (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4fARB (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint, const GLint *); +GLAPI void APIENTRY glVertexAttrib4sARB (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4svARB (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint, const GLuint *); +GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint, const GLushort *); +GLAPI void APIENTRY glVertexAttribPointerARB (GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *); +GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint); +GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint); +GLAPI void APIENTRY glProgramStringARB (GLenum, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glBindProgramARB (GLenum, GLuint); +GLAPI void APIENTRY glDeleteProgramsARB (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenProgramsARB (GLsizei, GLuint *); +GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum, GLuint, GLdouble *); +GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum, GLuint, GLfloat *); +GLAPI void APIENTRY glGetProgramivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramStringARB (GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribivARB (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgramARB (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); +typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const GLvoid *string); +typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, GLvoid *string); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program); +#endif + +#ifndef GL_ARB_fragment_program +#define GL_ARB_fragment_program 1 +/* All ARB_fragment_program entry points are shared with ARB_vertex_program. */ +#endif + +#ifndef GL_ARB_vertex_buffer_object +#define GL_ARB_vertex_buffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindBufferARB (GLenum, GLuint); +GLAPI void APIENTRY glDeleteBuffersARB (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenBuffersARB (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsBufferARB (GLuint); +GLAPI void APIENTRY glBufferDataARB (GLenum, GLsizeiptrARB, const GLvoid *, GLenum); +GLAPI void APIENTRY glBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, const GLvoid *); +GLAPI void APIENTRY glGetBufferSubDataARB (GLenum, GLintptrARB, GLsizeiptrARB, GLvoid *); +GLAPI GLvoid* APIENTRY glMapBufferARB (GLenum, GLenum); +GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum); +GLAPI void APIENTRY glGetBufferParameterivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetBufferPointervARB (GLenum, GLenum, GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); +typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); +typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); +typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data); +typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data); +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access); +typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, GLvoid* *params); +#endif + +#ifndef GL_ARB_map_buffer_range +#define GL_ARB_map_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length); +#endif + +#ifndef GL_ARB_occlusion_query +#define GL_ARB_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenQueriesARB (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteQueriesARB (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsQueryARB (GLuint); +GLAPI void APIENTRY glBeginQueryARB (GLenum, GLuint); +GLAPI void APIENTRY glEndQueryARB (GLenum); +GLAPI void APIENTRY glGetQueryivARB (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectivARB (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target); +typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_EXT_timer_query +#define GL_EXT_timer_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64EXT *params); +GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64EXT *params); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64EXT *params); +typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64EXT *params); +#endif + +#ifndef GL_ARB_sync +#define GL_ARB_sync 1 +#ifdef GL3_PROTOTYPES +GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags); +GLAPI GLboolean APIENTRY glIsSync (GLsync sync); +GLAPI void APIENTRY glDeleteSync (GLsync sync); +GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout); +GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *params); +GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif /* GL3_PROTOTYPES */ +typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags); +typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync); +typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync); +typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout); +typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *params); +typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values); +#endif + +#ifndef GL_ARB_shader_objects +#define GL_ARB_shader_objects 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB); +GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum); +GLAPI void APIENTRY glDetachObjectARB (GLhandleARB, GLhandleARB); +GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum); +GLAPI void APIENTRY glShaderSourceARB (GLhandleARB, GLsizei, const GLcharARB* *, const GLint *); +GLAPI void APIENTRY glCompileShaderARB (GLhandleARB); +GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void); +GLAPI void APIENTRY glAttachObjectARB (GLhandleARB, GLhandleARB); +GLAPI void APIENTRY glLinkProgramARB (GLhandleARB); +GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB); +GLAPI void APIENTRY glValidateProgramARB (GLhandleARB); +GLAPI void APIENTRY glUniform1fARB (GLint, GLfloat); +GLAPI void APIENTRY glUniform2fARB (GLint, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform3fARB (GLint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform4fARB (GLint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glUniform1iARB (GLint, GLint); +GLAPI void APIENTRY glUniform2iARB (GLint, GLint, GLint); +GLAPI void APIENTRY glUniform3iARB (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform4iARB (GLint, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glUniform1fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform2fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform3fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform4fvARB (GLint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glUniform1ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform2ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform3ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniform4ivARB (GLint, GLsizei, const GLint *); +GLAPI void APIENTRY glUniformMatrix2fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix3fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glUniformMatrix4fvARB (GLint, GLsizei, GLboolean, const GLfloat *); +GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB, GLenum, GLfloat *); +GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB, GLenum, GLint *); +GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); +GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB, GLsizei, GLsizei *, GLhandleARB *); +GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB, const GLcharARB *); +GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); +GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB, GLint, GLfloat *); +GLAPI void APIENTRY glGetUniformivARB (GLhandleARB, GLint, GLint *); +GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB, GLsizei, GLsizei *, GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); +typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); +typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); +typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); +typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); +typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); +typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj); +typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0); +typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1); +typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2); +typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); +typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1); +typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2); +typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3); +typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog); +typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj); +typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params); +typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params); +typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); +#endif + +#ifndef GL_ARB_vertex_shader +#define GL_ARB_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB, GLuint, const GLcharARB *); +GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB, GLuint, GLsizei, GLsizei *, GLint *, GLenum *, GLcharARB *); +GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB, const GLcharARB *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name); +typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name); +typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); +#endif + +#ifndef GL_ARB_fragment_shader +#define GL_ARB_fragment_shader 1 +#endif + +#ifndef GL_ARB_shading_language_100 +#define GL_ARB_shading_language_100 1 +#endif + +#ifndef GL_ARB_texture_non_power_of_two +#define GL_ARB_texture_non_power_of_two 1 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_ARB_point_sprite 1 +#endif + +#ifndef GL_ARB_fragment_program_shadow +#define GL_ARB_fragment_program_shadow 1 +#endif + +#ifndef GL_ARB_draw_buffers +#define GL_ARB_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersARB (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ARB_texture_rectangle +#define GL_ARB_texture_rectangle 1 +#endif + +#ifndef GL_ARB_color_buffer_float +#define GL_ARB_color_buffer_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glClampColorARB (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp); +#endif + +#ifndef GL_ARB_half_float_pixel +#define GL_ARB_half_float_pixel 1 +#endif + +#ifndef GL_ARB_texture_float +#define GL_ARB_texture_float 1 +#endif + +#ifndef GL_ARB_pixel_buffer_object +#define GL_ARB_pixel_buffer_object 1 +#endif + +#ifndef GL_EXT_abgr +#define GL_EXT_abgr 1 +#endif + +#ifndef GL_EXT_blend_color +#define GL_EXT_blend_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendColorEXT (GLclampf, GLclampf, GLclampf, GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); +#endif + +#ifndef GL_EXT_polygon_offset +#define GL_EXT_polygon_offset 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias); +#endif + +#ifndef GL_EXT_texture +#define GL_EXT_texture 1 +#endif + +#ifndef GL_EXT_texture3D +#define GL_EXT_texture3D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage3DEXT (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGIS_texture_filter4 +#define GL_SGIS_texture_filter4 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum, GLenum, GLsizei, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights); +typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights); +#endif + +#ifndef GL_EXT_subtexture +#define GL_EXT_subtexture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexSubImage1DEXT (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_EXT_copy_texture +#define GL_EXT_copy_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint); +GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint); +GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); +#endif + +#ifndef GL_EXT_histogram +#define GL_EXT_histogram 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetHistogramEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMinmaxEXT (GLenum, GLboolean, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glHistogramEXT (GLenum, GLsizei, GLenum, GLboolean); +GLAPI void APIENTRY glMinmaxEXT (GLenum, GLenum, GLboolean); +GLAPI void APIENTRY glResetHistogramEXT (GLenum); +GLAPI void APIENTRY glResetMinmaxEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink); +typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target); +#endif + +#ifndef GL_EXT_convolution +#define GL_EXT_convolution 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum, GLenum, GLint); +GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum, GLenum, GLint, GLint, GLsizei, GLsizei); +GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum, GLenum, GLenum, GLvoid *, GLvoid *, GLvoid *); +GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum, GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *image); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params); +typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *image); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *row, GLvoid *column, GLvoid *span); +typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *row, const GLvoid *column); +#endif + +#ifndef GL_EXT_color_matrix +#define GL_EXT_color_matrix 1 +#endif + +#ifndef GL_SGI_color_table +#define GL_SGI_color_table 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableSGI (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glColorTableParameterivSGI (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glCopyColorTableSGI (GLenum, GLenum, GLint, GLint, GLsizei); +GLAPI void APIENTRY glGetColorTableSGI (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); +typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params); +#endif + +#ifndef GL_SGIX_pixel_texture +#define GL_SGIX_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenSGIX (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode); +#endif + +#ifndef GL_SGIS_pixel_texture +#define GL_SGIS_pixel_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum, GLint); +GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum, const GLint *); +GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum, GLfloat); +GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum, const GLfloat *); +GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum, GLint *); +GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIS_texture4D +#define GL_SGIS_texture4D 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexImage4DSGIS (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const GLvoid *pixels); +#endif + +#ifndef GL_SGI_texture_color_table +#define GL_SGI_texture_color_table 1 +#endif + +#ifndef GL_EXT_cmyka +#define GL_EXT_cmyka 1 +#endif + +#ifndef GL_EXT_texture_object +#define GL_EXT_texture_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei, const GLuint *, GLboolean *); +GLAPI void APIENTRY glBindTextureEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenTexturesEXT (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint); +GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei, const GLuint *, const GLclampf *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture); +typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures); +typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures); +typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture); +typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities); +#endif + +#ifndef GL_SGIS_detail_texture +#define GL_SGIS_detail_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum, GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_SGIS_sharpen_texture +#define GL_SGIS_sharpen_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum, GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points); +#endif + +#ifndef GL_EXT_packed_pixels +#define GL_EXT_packed_pixels 1 +#endif + +#ifndef GL_SGIS_texture_lod +#define GL_SGIS_texture_lod 1 +#endif + +#ifndef GL_SGIS_multisample +#define GL_SGIS_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskSGIS (GLclampf, GLboolean); +GLAPI void APIENTRY glSamplePatternSGIS (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern); +#endif + +#ifndef GL_EXT_rescale_normal +#define GL_EXT_rescale_normal 1 +#endif + +#ifndef GL_EXT_vertex_array +#define GL_EXT_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glArrayElementEXT (GLint); +GLAPI void APIENTRY glColorPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glDrawArraysEXT (GLenum, GLint, GLsizei); +GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei, GLsizei, const GLboolean *); +GLAPI void APIENTRY glGetPointervEXT (GLenum, GLvoid* *); +GLAPI void APIENTRY glIndexPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glNormalPointerEXT (GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glTexCoordPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexPointerEXT (GLint, GLenum, GLsizei, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i); +typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer); +typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, GLvoid* *params); +typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_misc_attribute +#define GL_EXT_misc_attribute 1 +#endif + +#ifndef GL_SGIS_generate_mipmap +#define GL_SGIS_generate_mipmap 1 +#endif + +#ifndef GL_SGIX_clipmap +#define GL_SGIX_clipmap 1 +#endif + +#ifndef GL_SGIX_shadow +#define GL_SGIX_shadow 1 +#endif + +#ifndef GL_SGIS_texture_edge_clamp +#define GL_SGIS_texture_edge_clamp 1 +#endif + +#ifndef GL_SGIS_texture_border_clamp +#define GL_SGIS_texture_border_clamp 1 +#endif + +#ifndef GL_EXT_blend_minmax +#define GL_EXT_blend_minmax 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_blend_subtract +#define GL_EXT_blend_subtract 1 +#endif + +#ifndef GL_EXT_blend_logic_op +#define GL_EXT_blend_logic_op 1 +#endif + +#ifndef GL_SGIX_interlace +#define GL_SGIX_interlace 1 +#endif + +#ifndef GL_SGIX_pixel_tiles +#define GL_SGIX_pixel_tiles 1 +#endif + +#ifndef GL_SGIX_texture_select +#define GL_SGIX_texture_select 1 +#endif + +#ifndef GL_SGIX_sprite +#define GL_SGIX_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum, GLfloat); +GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum, const GLfloat *); +GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum, GLint); +GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_texture_multi_buffer +#define GL_SGIX_texture_multi_buffer 1 +#endif + +#ifndef GL_EXT_point_parameters +#define GL_EXT_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfEXT (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvEXT (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIS_point_parameters +#define GL_SGIS_point_parameters 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameterfSGIS (GLenum, GLfloat); +GLAPI void APIENTRY glPointParameterfvSGIS (GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_SGIX_instruments +#define GL_SGIX_instruments 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLint APIENTRY glGetInstrumentsSGIX (void); +GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei, GLint *); +GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *); +GLAPI void APIENTRY glReadInstrumentsSGIX (GLint); +GLAPI void APIENTRY glStartInstrumentsSGIX (void); +GLAPI void APIENTRY glStopInstrumentsSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer); +typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p); +typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker); +typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void); +typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker); +#endif + +#ifndef GL_SGIX_texture_scale_bias +#define GL_SGIX_texture_scale_bias 1 +#endif + +#ifndef GL_SGIX_framezoom +#define GL_SGIX_framezoom 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFrameZoomSGIX (GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor); +#endif + +#ifndef GL_SGIX_tag_sample_buffer +#define GL_SGIX_tag_sample_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTagSampleBufferSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_polynomial_ffd +#define GL_SGIX_polynomial_ffd 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, const GLdouble *); +GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, const GLfloat *); +GLAPI void APIENTRY glDeformSGIX (GLbitfield); +GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points); +typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points); +typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask); +typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask); +#endif + +#ifndef GL_SGIX_reference_plane +#define GL_SGIX_reference_plane 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation); +#endif + +#ifndef GL_SGIX_flush_raster +#define GL_SGIX_flush_raster 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushRasterSGIX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void); +#endif + +#ifndef GL_SGIX_depth_texture +#define GL_SGIX_depth_texture 1 +#endif + +#ifndef GL_SGIS_fog_function +#define GL_SGIS_fog_function 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogFuncSGIS (GLsizei, const GLfloat *); +GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points); +typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points); +#endif + +#ifndef GL_SGIX_fog_offset +#define GL_SGIX_fog_offset 1 +#endif + +#ifndef GL_HP_image_transform +#define GL_HP_image_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glImageTransformParameteriHP (GLenum, GLenum, GLint); +GLAPI void APIENTRY glImageTransformParameterfHP (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glImageTransformParameterivHP (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_HP_convolution_border_modes +#define GL_HP_convolution_border_modes 1 +#endif + +#ifndef GL_SGIX_texture_add_env +#define GL_SGIX_texture_add_env 1 +#endif + +#ifndef GL_EXT_color_subtable +#define GL_EXT_color_subtable 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorSubTableEXT (GLenum, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum, GLsizei, GLint, GLint, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const GLvoid *data); +typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); +#endif + +#ifndef GL_PGI_vertex_hints +#define GL_PGI_vertex_hints 1 +#endif + +#ifndef GL_PGI_misc_hints +#define GL_PGI_misc_hints 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glHintPGI (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode); +#endif + +#ifndef GL_EXT_paletted_texture +#define GL_EXT_paletted_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorTableEXT (GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid *); +GLAPI void APIENTRY glGetColorTableEXT (GLenum, GLenum, GLenum, GLvoid *); +GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const GLvoid *table); +typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, GLvoid *data); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_EXT_clip_volume_hint +#define GL_EXT_clip_volume_hint 1 +#endif + +#ifndef GL_SGIX_list_priority +#define GL_SGIX_list_priority 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetListParameterivSGIX (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glListParameterfSGIX (GLuint, GLenum, GLfloat); +GLAPI void APIENTRY glListParameterfvSGIX (GLuint, GLenum, const GLfloat *); +GLAPI void APIENTRY glListParameteriSGIX (GLuint, GLenum, GLint); +GLAPI void APIENTRY glListParameterivSGIX (GLuint, GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params); +#endif + +#ifndef GL_SGIX_ir_instrument1 +#define GL_SGIX_ir_instrument1 1 +#endif + +#ifndef GL_SGIX_calligraphic_fragment +#define GL_SGIX_calligraphic_fragment 1 +#endif + +#ifndef GL_SGIX_texture_lod_bias +#define GL_SGIX_texture_lod_bias 1 +#endif + +#ifndef GL_SGIX_shadow_ambient +#define GL_SGIX_shadow_ambient 1 +#endif + +#ifndef GL_EXT_index_texture +#define GL_EXT_index_texture 1 +#endif + +#ifndef GL_EXT_index_material +#define GL_EXT_index_material 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_EXT_index_func +#define GL_EXT_index_func 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIndexFuncEXT (GLenum, GLclampf); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref); +#endif + +#ifndef GL_EXT_index_array_formats +#define GL_EXT_index_array_formats 1 +#endif + +#ifndef GL_EXT_compiled_vertex_array +#define GL_EXT_compiled_vertex_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glLockArraysEXT (GLint, GLsizei); +GLAPI void APIENTRY glUnlockArraysEXT (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void); +#endif + +#ifndef GL_EXT_cull_vertex +#define GL_EXT_cull_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCullParameterdvEXT (GLenum, GLdouble *); +GLAPI void APIENTRY glCullParameterfvEXT (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params); +#endif + +#ifndef GL_SGIX_ycrcb +#define GL_SGIX_ycrcb 1 +#endif + +#ifndef GL_SGIX_fragment_lighting +#define GL_SGIX_fragment_lighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum, GLenum); +GLAPI void APIENTRY glFragmentLightfSGIX (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentLightiSGIX (GLenum, GLenum, GLint); +GLAPI void APIENTRY glFragmentLightivSGIX (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum, GLfloat); +GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum, GLint); +GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum, const GLint *); +GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum, GLenum, GLint); +GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glLightEnviSGIX (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_IBM_rasterpos_clip +#define GL_IBM_rasterpos_clip 1 +#endif + +#ifndef GL_HP_texture_lighting +#define GL_HP_texture_lighting 1 +#endif + +#ifndef GL_EXT_draw_range_elements +#define GL_EXT_draw_range_elements 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum, GLuint, GLuint, GLsizei, GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices); +#endif + +#ifndef GL_WIN_phong_shading +#define GL_WIN_phong_shading 1 +#endif + +#ifndef GL_WIN_specular_fog +#define GL_WIN_specular_fog 1 +#endif + +#ifndef GL_EXT_light_texture +#define GL_EXT_light_texture 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glApplyTextureEXT (GLenum); +GLAPI void APIENTRY glTextureLightEXT (GLenum); +GLAPI void APIENTRY glTextureMaterialEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode); +typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname); +typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode); +#endif + +#ifndef GL_SGIX_blend_alpha_minmax +#define GL_SGIX_blend_alpha_minmax 1 +#endif + +#ifndef GL_EXT_bgra +#define GL_EXT_bgra 1 +#endif + +#ifndef GL_SGIX_async +#define GL_SGIX_async 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint); +GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *); +GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *); +GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei); +GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint, GLsizei); +GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker); +typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp); +typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp); +typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range); +typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range); +typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker); +#endif + +#ifndef GL_SGIX_async_pixel +#define GL_SGIX_async_pixel 1 +#endif + +#ifndef GL_SGIX_async_histogram +#define GL_SGIX_async_histogram 1 +#endif + +#ifndef GL_INTEL_parallel_arrays +#define GL_INTEL_parallel_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexPointervINTEL (GLint, GLenum, const GLvoid* *); +GLAPI void APIENTRY glNormalPointervINTEL (GLenum, const GLvoid* *); +GLAPI void APIENTRY glColorPointervINTEL (GLint, GLenum, const GLvoid* *); +GLAPI void APIENTRY glTexCoordPointervINTEL (GLint, GLenum, const GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const GLvoid* *pointer); +#endif + +#ifndef GL_HP_occlusion_test +#define GL_HP_occlusion_test 1 +#endif + +#ifndef GL_EXT_pixel_transform +#define GL_EXT_pixel_transform 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum, GLenum, GLint); +GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum, GLenum, GLfloat); +GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum, GLenum, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params); +#endif + +#ifndef GL_EXT_pixel_transform_color_table +#define GL_EXT_pixel_transform_color_table 1 +#endif + +#ifndef GL_EXT_shared_texture_palette +#define GL_EXT_shared_texture_palette 1 +#endif + +#ifndef GL_EXT_separate_specular_color +#define GL_EXT_separate_specular_color 1 +#endif + +#ifndef GL_EXT_secondary_color +#define GL_EXT_secondary_color 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *); +GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *); +GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *); +GLAPI void APIENTRY glSecondaryColor3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *); +GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *); +GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *); +GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *); +GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort, GLushort, GLushort); +GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *); +GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_perturb_normal +#define GL_EXT_texture_perturb_normal 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureNormalEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode); +#endif + +#ifndef GL_EXT_multi_draw_arrays +#define GL_EXT_multi_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); +#endif + +#ifndef GL_EXT_fog_coord +#define GL_EXT_fog_coord 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFogCoordfEXT (GLfloat); +GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *); +GLAPI void APIENTRY glFogCoorddEXT (GLdouble); +GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *); +GLAPI void APIENTRY glFogCoordPointerEXT (GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord); +typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord); +typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord); +typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_REND_screen_coordinates +#define GL_REND_screen_coordinates 1 +#endif + +#ifndef GL_EXT_coordinate_frame +#define GL_EXT_coordinate_frame 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTangent3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *); +GLAPI void APIENTRY glTangent3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *); +GLAPI void APIENTRY glTangent3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *); +GLAPI void APIENTRY glTangent3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glTangent3ivEXT (const GLint *); +GLAPI void APIENTRY glTangent3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glTangent3svEXT (const GLshort *); +GLAPI void APIENTRY glBinormal3bEXT (GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *); +GLAPI void APIENTRY glBinormal3dEXT (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *); +GLAPI void APIENTRY glBinormal3fEXT (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *); +GLAPI void APIENTRY glBinormal3iEXT (GLint, GLint, GLint); +GLAPI void APIENTRY glBinormal3ivEXT (const GLint *); +GLAPI void APIENTRY glBinormal3sEXT (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glBinormal3svEXT (const GLshort *); +GLAPI void APIENTRY glTangentPointerEXT (GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glBinormalPointerEXT (GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz); +typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz); +typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz); +typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz); +typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz); +typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz); +typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v); +typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz); +typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz); +typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz); +typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz); +typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_EXT_texture_env_combine +#define GL_EXT_texture_env_combine 1 +#endif + +#ifndef GL_APPLE_specular_vector +#define GL_APPLE_specular_vector 1 +#endif + +#ifndef GL_APPLE_transform_hint +#define GL_APPLE_transform_hint 1 +#endif + +#ifndef GL_SGIX_fog_scale +#define GL_SGIX_fog_scale 1 +#endif + +#ifndef GL_SUNX_constant_data +#define GL_SUNX_constant_data 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFinishTextureSUNX (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void); +#endif + +#ifndef GL_SUN_global_alpha +#define GL_SUN_global_alpha 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte); +GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort); +GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint); +GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat); +GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble); +GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte); +GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort); +GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor); +typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor); +#endif + +#ifndef GL_SUN_triangle_list +#define GL_SUN_triangle_list 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint); +GLAPI void APIENTRY glReplacementCodeusSUN (GLushort); +GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte); +GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *); +GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *); +GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *); +GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum, GLsizei, const GLvoid* *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const GLvoid* *pointer); +#endif + +#ifndef GL_SUN_vertex +#define GL_SUN_vertex 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat, GLfloat, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint, GLubyte, GLubyte, GLubyte, GLubyte, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *, const GLfloat *, const GLfloat *, const GLfloat *, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v); +#endif + +#ifndef GL_EXT_blend_func_separate +#define GL_EXT_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum, GLenum, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_blend_func_separate +#define GL_INGR_blend_func_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum, GLenum, GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha); +#endif + +#ifndef GL_INGR_color_clamp +#define GL_INGR_color_clamp 1 +#endif + +#ifndef GL_INGR_interlace_read +#define GL_INGR_interlace_read 1 +#endif + +#ifndef GL_EXT_stencil_wrap +#define GL_EXT_stencil_wrap 1 +#endif + +#ifndef GL_EXT_422_pixels +#define GL_EXT_422_pixels 1 +#endif + +#ifndef GL_NV_texgen_reflection +#define GL_NV_texgen_reflection 1 +#endif + +#ifndef GL_SUN_convolution_border_modes +#define GL_SUN_convolution_border_modes 1 +#endif + +#ifndef GL_EXT_texture_env_add +#define GL_EXT_texture_env_add 1 +#endif + +#ifndef GL_EXT_texture_lod_bias +#define GL_EXT_texture_lod_bias 1 +#endif + +#ifndef GL_EXT_texture_filter_anisotropic +#define GL_EXT_texture_filter_anisotropic 1 +#endif + +#ifndef GL_EXT_vertex_weighting +#define GL_EXT_vertex_weighting 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexWeightfEXT (GLfloat); +GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *); +GLAPI void APIENTRY glVertexWeightPointerEXT (GLsizei, GLenum, GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLsizei size, GLenum type, GLsizei stride, const GLvoid *pointer); +#endif + +#ifndef GL_NV_light_max_exponent +#define GL_NV_light_max_exponent 1 +#endif + +#ifndef GL_NV_vertex_array_range +#define GL_NV_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glFlushVertexArrayRangeNV (void); +GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void); +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const GLvoid *pointer); +#endif + +#ifndef GL_NV_register_combiners +#define GL_NV_register_combiners 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerParameterfvNV (GLenum, const GLfloat *); +GLAPI void APIENTRY glCombinerParameterfNV (GLenum, GLfloat); +GLAPI void APIENTRY glCombinerParameterivNV (GLenum, const GLint *); +GLAPI void APIENTRY glCombinerParameteriNV (GLenum, GLint); +GLAPI void APIENTRY glCombinerInputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glCombinerOutputNV (GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum, GLboolean, GLboolean, GLboolean); +GLAPI void APIENTRY glFinalCombinerInputNV (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum, GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum, GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum, GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum); +typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params); +#endif + +#ifndef GL_NV_fog_distance +#define GL_NV_fog_distance 1 +#endif + +#ifndef GL_NV_texgen_emboss +#define GL_NV_texgen_emboss 1 +#endif + +#ifndef GL_NV_blend_square +#define GL_NV_blend_square 1 +#endif + +#ifndef GL_NV_texture_env_combine4 +#define GL_NV_texture_env_combine4 1 +#endif + +#ifndef GL_MESA_resize_buffers +#define GL_MESA_resize_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glResizeBuffersMESA (void); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void); +#endif + +#ifndef GL_MESA_window_pos +#define GL_MESA_window_pos 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glWindowPos2dMESA (GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos2fMESA (GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos2iMESA (GLint, GLint); +GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos2sMESA (GLshort, GLshort); +GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *); +GLAPI void APIENTRY glWindowPos3dMESA (GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos3fMESA (GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos3iMESA (GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos3sMESA (GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *); +GLAPI void APIENTRY glWindowPos4dMESA (GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *); +GLAPI void APIENTRY glWindowPos4fMESA (GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *); +GLAPI void APIENTRY glWindowPos4iMESA (GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *); +GLAPI void APIENTRY glWindowPos4sMESA (GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y); +typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v); +typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v); +#endif + +#ifndef GL_IBM_cull_vertex +#define GL_IBM_cull_vertex 1 +#endif + +#ifndef GL_IBM_multimode_draw_arrays +#define GL_IBM_multimode_draw_arrays 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *, const GLint *, const GLsizei *, GLsizei, GLint); +GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *, const GLsizei *, GLenum, const GLvoid* const *, GLsizei, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride); +typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei primcount, GLint modestride); +#endif + +#ifndef GL_IBM_vertex_array_lists +#define GL_IBM_vertex_array_lists 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint, const GLboolean* *, GLint); +GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glIndexPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glNormalPointerListIBM (GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glTexCoordPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +GLAPI void APIENTRY glVertexPointerListIBM (GLint, GLenum, GLint, const GLvoid* *, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const GLvoid* *pointer, GLint ptrstride); +#endif + +#ifndef GL_SGIX_subsample +#define GL_SGIX_subsample 1 +#endif + +#ifndef GL_SGIX_ycrcba +#define GL_SGIX_ycrcba 1 +#endif + +#ifndef GL_SGIX_ycrcb_subsample +#define GL_SGIX_ycrcb_subsample 1 +#endif + +#ifndef GL_SGIX_depth_pass_instrument +#define GL_SGIX_depth_pass_instrument 1 +#endif + +#ifndef GL_3DFX_texture_compression_FXT1 +#define GL_3DFX_texture_compression_FXT1 1 +#endif + +#ifndef GL_3DFX_multisample +#define GL_3DFX_multisample 1 +#endif + +#ifndef GL_3DFX_tbuffer +#define GL_3DFX_tbuffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTbufferMask3DFX (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask); +#endif + +#ifndef GL_EXT_multisample +#define GL_EXT_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glSampleMaskEXT (GLclampf, GLboolean); +GLAPI void APIENTRY glSamplePatternEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert); +typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern); +#endif + +#ifndef GL_SGIX_vertex_preclip +#define GL_SGIX_vertex_preclip 1 +#endif + +#ifndef GL_SGIX_convolution_accuracy +#define GL_SGIX_convolution_accuracy 1 +#endif + +#ifndef GL_SGIX_resample +#define GL_SGIX_resample 1 +#endif + +#ifndef GL_SGIS_point_line_texgen +#define GL_SGIS_point_line_texgen 1 +#endif + +#ifndef GL_SGIS_texture_color_mask +#define GL_SGIS_texture_color_mask 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean, GLboolean, GLboolean, GLboolean); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +#endif + +#ifndef GL_SGIX_igloo_interface +#define GL_SGIX_igloo_interface 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const GLvoid *params); +#endif + +#ifndef GL_EXT_texture_env_dot3 +#define GL_EXT_texture_env_dot3 1 +#endif + +#ifndef GL_ATI_texture_mirror_once +#define GL_ATI_texture_mirror_once 1 +#endif + +#ifndef GL_NV_fence +#define GL_NV_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDeleteFencesNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenFencesNV (GLsizei, GLuint *); +GLAPI GLboolean APIENTRY glIsFenceNV (GLuint); +GLAPI GLboolean APIENTRY glTestFenceNV (GLuint); +GLAPI void APIENTRY glGetFenceivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glFinishFenceNV (GLuint); +GLAPI void APIENTRY glSetFenceNV (GLuint, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences); +typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition); +#endif + +#ifndef GL_NV_evaluators +#define GL_NV_evaluators 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLint, GLint, GLboolean, const GLvoid *); +GLAPI void APIENTRY glMapParameterivNV (GLenum, GLenum, const GLint *); +GLAPI void APIENTRY glMapParameterfvNV (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetMapControlPointsNV (GLenum, GLuint, GLenum, GLsizei, GLsizei, GLboolean, GLvoid *); +GLAPI void APIENTRY glGetMapParameterivNV (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGetMapParameterfvNV (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum, GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glEvalMapsNV (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const GLvoid *points); +typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params); +typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, GLvoid *points); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode); +#endif + +#ifndef GL_NV_packed_depth_stencil +#define GL_NV_packed_depth_stencil 1 +#endif + +#ifndef GL_NV_register_combiners2 +#define GL_NV_register_combiners2 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum, GLenum, const GLfloat *); +GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params); +typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params); +#endif + +#ifndef GL_NV_texture_compression_vtc +#define GL_NV_texture_compression_vtc 1 +#endif + +#ifndef GL_NV_texture_rectangle +#define GL_NV_texture_rectangle 1 +#endif + +#ifndef GL_NV_texture_shader +#define GL_NV_texture_shader 1 +#endif + +#ifndef GL_NV_texture_shader2 +#define GL_NV_texture_shader2 1 +#endif + +#ifndef GL_NV_vertex_array_range2 +#define GL_NV_vertex_array_range2 1 +#endif + +#ifndef GL_NV_vertex_program +#define GL_NV_vertex_program 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei, const GLuint *, GLboolean *); +GLAPI void APIENTRY glBindProgramNV (GLenum, GLuint); +GLAPI void APIENTRY glDeleteProgramsNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glExecuteProgramNV (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glGenProgramsNV (GLsizei, GLuint *); +GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum, GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum, GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetProgramivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetProgramStringNV (GLuint, GLenum, GLubyte *); +GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum, GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint, GLenum, GLdouble *); +GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint, GLenum, GLvoid* *); +GLAPI GLboolean APIENTRY glIsProgramNV (GLuint); +GLAPI void APIENTRY glLoadProgramNV (GLenum, GLuint, GLsizei, const GLubyte *); +GLAPI void APIENTRY glProgramParameter4dNV (GLenum, GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramParameter4dvNV (GLenum, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramParameter4fNV (GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramParameter4fvNV (GLenum, GLuint, const GLfloat *); +GLAPI void APIENTRY glProgramParameters4dvNV (GLenum, GLuint, GLuint, const GLdouble *); +GLAPI void APIENTRY glProgramParameters4fvNV (GLenum, GLuint, GLuint, const GLfloat *); +GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei, const GLuint *); +GLAPI void APIENTRY glTrackMatrixNV (GLenum, GLuint, GLenum, GLenum); +GLAPI void APIENTRY glVertexAttribPointerNV (GLuint, GLint, GLenum, GLsizei, const GLvoid *); +GLAPI void APIENTRY glVertexAttrib1dNV (GLuint, GLdouble); +GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib1fNV (GLuint, GLfloat); +GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib1sNV (GLuint, GLshort); +GLAPI void APIENTRY glVertexAttrib1svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib2dNV (GLuint, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib2fNV (GLuint, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib2sNV (GLuint, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib2svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib3dNV (GLuint, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib3fNV (GLuint, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib3sNV (GLuint, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib3svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4dNV (GLuint, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint, const GLdouble *); +GLAPI void APIENTRY glVertexAttrib4fNV (GLuint, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint, const GLfloat *); +GLAPI void APIENTRY glVertexAttrib4sNV (GLuint, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexAttrib4svNV (GLuint, const GLshort *); +GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint, GLubyte, GLubyte, GLubyte, GLubyte); +GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint, const GLubyte *); +GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs1svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs2svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs3svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint, GLsizei, const GLdouble *); +GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint, GLsizei, const GLfloat *); +GLAPI void APIENTRY glVertexAttribs4svNV (GLuint, GLsizei, const GLshort *); +GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint, GLsizei, const GLubyte *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences); +typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id); +typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params); +typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program); +typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, GLvoid* *pointer); +typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLuint count, const GLdouble *v); +typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLuint count, const GLfloat *v); +typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs); +typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform); +typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v); +#endif + +#ifndef GL_SGIX_texture_coordinate_clamp +#define GL_SGIX_texture_coordinate_clamp 1 +#endif + +#ifndef GL_SGIX_scalebias_hint +#define GL_SGIX_scalebias_hint 1 +#endif + +#ifndef GL_OML_interlace +#define GL_OML_interlace 1 +#endif + +#ifndef GL_OML_subsample +#define GL_OML_subsample 1 +#endif + +#ifndef GL_OML_resample +#define GL_OML_resample 1 +#endif + +#ifndef GL_NV_copy_depth_to_color +#define GL_NV_copy_depth_to_color 1 +#endif + +#ifndef GL_ATI_envmap_bumpmap +#define GL_ATI_envmap_bumpmap 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glTexBumpParameterivATI (GLenum, const GLint *); +GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum, GLint *); +GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param); +typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param); +typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param); +#endif + +#ifndef GL_ATI_fragment_shader +#define GL_ATI_fragment_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint); +GLAPI void APIENTRY glBindFragmentShaderATI (GLuint); +GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint); +GLAPI void APIENTRY glBeginFragmentShaderATI (void); +GLAPI void APIENTRY glEndFragmentShaderATI (void); +GLAPI void APIENTRY glPassTexCoordATI (GLuint, GLuint, GLenum); +GLAPI void APIENTRY glSampleMapATI (GLuint, GLuint, GLenum); +GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint, const GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range); +typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void); +typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle); +typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod); +typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod); +typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value); +#endif + +#ifndef GL_ATI_pn_triangles +#define GL_ATI_pn_triangles 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPNTrianglesiATI (GLenum, GLint); +GLAPI void APIENTRY glPNTrianglesfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_vertex_array_object +#define GL_ATI_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei, const GLvoid *, GLenum); +GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint); +GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint, GLuint, GLsizei, const GLvoid *, GLenum); +GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetObjectBufferivATI (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glFreeObjectBufferATI (GLuint); +GLAPI void APIENTRY glArrayObjectATI (GLenum, GLint, GLenum, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum, GLenum, GLfloat *); +GLAPI void APIENTRY glGetArrayObjectivATI (GLenum, GLenum, GLint *); +GLAPI void APIENTRY glVariantArrayObjectATI (GLuint, GLenum, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const GLvoid *pointer, GLenum usage); +typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const GLvoid *pointer, GLenum preserve); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params); +#endif + +#ifndef GL_EXT_vertex_shader +#define GL_EXT_vertex_shader 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBeginVertexShaderEXT (void); +GLAPI void APIENTRY glEndVertexShaderEXT (void); +GLAPI void APIENTRY glBindVertexShaderEXT (GLuint); +GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint); +GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint); +GLAPI void APIENTRY glShaderOp1EXT (GLenum, GLuint, GLuint); +GLAPI void APIENTRY glShaderOp2EXT (GLenum, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glShaderOp3EXT (GLenum, GLuint, GLuint, GLuint, GLuint); +GLAPI void APIENTRY glSwizzleEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glWriteMaskEXT (GLuint, GLuint, GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glInsertComponentEXT (GLuint, GLuint, GLuint); +GLAPI void APIENTRY glExtractComponentEXT (GLuint, GLuint, GLuint); +GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glSetInvariantEXT (GLuint, GLenum, const GLvoid *); +GLAPI void APIENTRY glSetLocalConstantEXT (GLuint, GLenum, const GLvoid *); +GLAPI void APIENTRY glVariantbvEXT (GLuint, const GLbyte *); +GLAPI void APIENTRY glVariantsvEXT (GLuint, const GLshort *); +GLAPI void APIENTRY glVariantivEXT (GLuint, const GLint *); +GLAPI void APIENTRY glVariantfvEXT (GLuint, const GLfloat *); +GLAPI void APIENTRY glVariantdvEXT (GLuint, const GLdouble *); +GLAPI void APIENTRY glVariantubvEXT (GLuint, const GLubyte *); +GLAPI void APIENTRY glVariantusvEXT (GLuint, const GLushort *); +GLAPI void APIENTRY glVariantuivEXT (GLuint, const GLuint *); +GLAPI void APIENTRY glVariantPointerEXT (GLuint, GLenum, GLuint, const GLvoid *); +GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint); +GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint); +GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum, GLenum, GLenum); +GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum, GLenum); +GLAPI GLuint APIENTRY glBindParameterEXT (GLenum); +GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint, GLenum); +GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVariantPointervEXT (GLuint, GLenum, GLvoid* *); +GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint, GLenum, GLboolean *); +GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint, GLenum, GLfloat *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void); +typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range); +typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1); +typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2); +typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3); +typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW); +typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num); +typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components); +typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const GLvoid *addr); +typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr); +typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr); +typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr); +typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr); +typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr); +typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr); +typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr); +typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr); +typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const GLvoid *addr); +typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id); +typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value); +typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value); +typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap); +typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, GLvoid* *data); +typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data); +typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data); +#endif + +#ifndef GL_ATI_vertex_streams +#define GL_ATI_vertex_streams 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexStream1sATI (GLenum, GLshort); +GLAPI void APIENTRY glVertexStream1svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream1iATI (GLenum, GLint); +GLAPI void APIENTRY glVertexStream1ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream1fATI (GLenum, GLfloat); +GLAPI void APIENTRY glVertexStream1fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream1dATI (GLenum, GLdouble); +GLAPI void APIENTRY glVertexStream1dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream2sATI (GLenum, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream2svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream2iATI (GLenum, GLint, GLint); +GLAPI void APIENTRY glVertexStream2ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream2fATI (GLenum, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream2fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream2dATI (GLenum, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream2dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream3sATI (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream3svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream3iATI (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexStream3ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream3fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream3dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glVertexStream4sATI (GLenum, GLshort, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glVertexStream4svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glVertexStream4iATI (GLenum, GLint, GLint, GLint, GLint); +GLAPI void APIENTRY glVertexStream4ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glVertexStream4fATI (GLenum, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glVertexStream4fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glVertexStream4dATI (GLenum, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glVertexStream4dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glNormalStream3bATI (GLenum, GLbyte, GLbyte, GLbyte); +GLAPI void APIENTRY glNormalStream3bvATI (GLenum, const GLbyte *); +GLAPI void APIENTRY glNormalStream3sATI (GLenum, GLshort, GLshort, GLshort); +GLAPI void APIENTRY glNormalStream3svATI (GLenum, const GLshort *); +GLAPI void APIENTRY glNormalStream3iATI (GLenum, GLint, GLint, GLint); +GLAPI void APIENTRY glNormalStream3ivATI (GLenum, const GLint *); +GLAPI void APIENTRY glNormalStream3fATI (GLenum, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glNormalStream3fvATI (GLenum, const GLfloat *); +GLAPI void APIENTRY glNormalStream3dATI (GLenum, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glNormalStream3dvATI (GLenum, const GLdouble *); +GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum); +GLAPI void APIENTRY glVertexBlendEnviATI (GLenum, GLint); +GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum, GLfloat); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x); +typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y); +typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z); +typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz); +typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords); +typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param); +#endif + +#ifndef GL_ATI_element_array +#define GL_ATI_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerATI (GLenum, const GLvoid *); +GLAPI void APIENTRY glDrawElementArrayATI (GLenum, GLsizei); +GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum, GLuint, GLuint, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count); +#endif + +#ifndef GL_SUN_mesh_array +#define GL_SUN_mesh_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum, GLint, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width); +#endif + +#ifndef GL_SUN_slice_accum +#define GL_SUN_slice_accum 1 +#endif + +#ifndef GL_NV_multisample_filter_hint +#define GL_NV_multisample_filter_hint 1 +#endif + +#ifndef GL_NV_depth_clamp +#define GL_NV_depth_clamp 1 +#endif + +#ifndef GL_NV_occlusion_query +#define GL_NV_occlusion_query 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint); +GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint); +GLAPI void APIENTRY glEndOcclusionQueryNV (void); +GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint, GLenum, GLint *); +GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint, GLenum, GLuint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids); +typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids); +typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id); +typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params); +#endif + +#ifndef GL_NV_point_sprite +#define GL_NV_point_sprite 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPointParameteriNV (GLenum, GLint); +GLAPI void APIENTRY glPointParameterivNV (GLenum, const GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params); +#endif + +#ifndef GL_NV_texture_shader3 +#define GL_NV_texture_shader3 1 +#endif + +#ifndef GL_NV_vertex_program1_1 +#define GL_NV_vertex_program1_1 1 +#endif + +#ifndef GL_EXT_shadow_funcs +#define GL_EXT_shadow_funcs 1 +#endif + +#ifndef GL_EXT_stencil_two_side +#define GL_EXT_stencil_two_side 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face); +#endif + +#ifndef GL_ATI_text_fragment_shader +#define GL_ATI_text_fragment_shader 1 +#endif + +#ifndef GL_APPLE_client_storage +#define GL_APPLE_client_storage 1 +#endif + +#ifndef GL_APPLE_element_array +#define GL_APPLE_element_array 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glElementPointerAPPLE (GLenum, const GLvoid *); +GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum, GLint, GLsizei); +GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, GLint, GLsizei); +GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum, const GLint *, const GLsizei *, GLsizei); +GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum, GLuint, GLuint, const GLint *, const GLsizei *, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const GLvoid *pointer); +typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count); +typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); +typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount); +#endif + +#ifndef GL_APPLE_fence +#define GL_APPLE_fence 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glGenFencesAPPLE (GLsizei, GLuint *); +GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei, const GLuint *); +GLAPI void APIENTRY glSetFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint); +GLAPI void APIENTRY glFinishFenceAPPLE (GLuint); +GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum, GLuint); +GLAPI void APIENTRY glFinishObjectAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences); +typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences); +typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence); +typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence); +typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name); +typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name); +#endif + + +#ifndef GL_APPLE_flush_buffer_range +#define GL_APPLE_flush_buffer_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void glBufferParameteriAPPLE(GLenum target, GLenum pname, GLint param); +GLAPI void glFlushMappedBufferRangeAPPLE(GLenum target, GLintptr offset, GLsizeiptr size); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param); +typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size); +#endif + + +#ifndef GL_APPLE_vertex_array_object +#define GL_APPLE_vertex_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint); +GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei, const GLuint *); +GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array); +typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays); +typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); +#endif + +#ifndef GL_APPLE_vertex_array_range +#define GL_APPLE_vertex_array_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei, GLvoid *); +GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei, GLvoid *); +GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum, GLint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param); +#endif + +#ifndef GL_APPLE_ycbcr_422 +#define GL_APPLE_ycbcr_422 1 +#endif + +#ifndef GL_S3_s3tc +#define GL_S3_s3tc 1 +#endif + +#ifndef GL_ATI_draw_buffers +#define GL_ATI_draw_buffers 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDrawBuffersATI (GLsizei, const GLenum *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs); +#endif + +#ifndef GL_ATI_pixel_format_float +#define GL_ATI_pixel_format_float 1 +/* This is really a WGL extension, but defines some associated GL enums. + * ATI does not export "GL_ATI_pixel_format_float" in the GL_EXTENSIONS string. + */ +#endif + +#ifndef GL_ATI_texture_env_combine3 +#define GL_ATI_texture_env_combine3 1 +#endif + +#ifndef GL_ATI_texture_float +#define GL_ATI_texture_float 1 +#endif + +#ifndef GL_NV_float_buffer +#define GL_NV_float_buffer 1 +#endif + +#ifndef GL_NV_fragment_program +#define GL_NV_fragment_program 1 +/* Some NV_fragment_program entry points are shared with ARB_vertex_program. */ +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint, GLsizei, const GLubyte *, GLfloat, GLfloat, GLfloat, GLfloat); +GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint, GLsizei, const GLubyte *, GLdouble, GLdouble, GLdouble, GLdouble); +GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint, GLsizei, const GLubyte *, const GLfloat *); +GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint, GLsizei, const GLubyte *, const GLdouble *); +GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint, GLsizei, const GLubyte *, GLfloat *); +GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint, GLsizei, const GLubyte *, GLdouble *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v); +typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params); +typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params); +#endif + +#ifndef GL_NV_half_float +#define GL_NV_half_float 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertex2hNV (GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertex3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertex4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glNormal3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glColor4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV); +GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum, const GLhalfNV *); +GLAPI void APIENTRY glFogCoordhNV (GLhalfNV); +GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *); +GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV); +GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib1hNV (GLuint, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib2hNV (GLuint, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib3hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttrib4hNV (GLuint, GLhalfNV, GLhalfNV, GLhalfNV, GLhalfNV); +GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint, GLsizei, const GLhalfNV *); +GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint, GLsizei, const GLhalfNV *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz); +typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha); +typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s); +typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s); +typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t); +typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r); +typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q); +typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog); +typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue); +typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight); +typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x); +typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y); +typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z); +typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w); +typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v); +#endif + +#ifndef GL_NV_pixel_data_range +#define GL_NV_pixel_data_range 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPixelDataRangeNV (GLenum, GLsizei, GLvoid *); +GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, GLvoid *pointer); +typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target); +#endif + +#ifndef GL_NV_primitive_restart +#define GL_NV_primitive_restart 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glPrimitiveRestartNV (void); +GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void); +typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index); +#endif + +#ifndef GL_NV_texture_expand_normal +#define GL_NV_texture_expand_normal 1 +#endif + +#ifndef GL_NV_vertex_program2 +#define GL_NV_vertex_program2 1 +#endif + +#ifndef GL_ATI_map_object_buffer +#define GL_ATI_map_object_buffer 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLvoid* APIENTRY glMapObjectBufferATI (GLuint); +GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLvoid* (APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer); +typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer); +#endif + +#ifndef GL_ATI_separate_stencil +#define GL_ATI_separate_stencil 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStencilOpSeparateATI (GLenum, GLenum, GLenum, GLenum); +GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum, GLenum, GLint, GLuint); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass); +typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask); +#endif + +#ifndef GL_ATI_vertex_attrib_array_object +#define GL_ATI_vertex_attrib_array_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint, GLint, GLenum, GLboolean, GLsizei, GLuint, GLuint); +GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint, GLenum, GLfloat *); +GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint, GLenum, GLint *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params); +#endif + +#ifndef GL_OES_read_format +#define GL_OES_read_format 1 +#endif + +#ifndef GL_EXT_depth_bounds_test +#define GL_EXT_depth_bounds_test 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glDepthBoundsEXT (GLclampd, GLclampd); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax); +#endif + +#ifndef GL_EXT_texture_mirror_clamp +#define GL_EXT_texture_mirror_clamp 1 +#endif + +#ifndef GL_EXT_blend_equation_separate +#define GL_EXT_blend_equation_separate 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha); +#endif + +#ifndef GL_MESA_pack_invert +#define GL_MESA_pack_invert 1 +#endif + +#ifndef GL_MESA_ycbcr_texture +#define GL_MESA_ycbcr_texture 1 +#endif + +#ifndef GL_EXT_pixel_buffer_object +#define GL_EXT_pixel_buffer_object 1 +#endif + +#ifndef GL_NV_fragment_program_option +#define GL_NV_fragment_program_option 1 +#endif + +#ifndef GL_NV_fragment_program2 +#define GL_NV_fragment_program2 1 +#endif + +#ifndef GL_NV_vertex_program2_option +#define GL_NV_vertex_program2_option 1 +#endif + +#ifndef GL_NV_vertex_program3 +#define GL_NV_vertex_program3 1 +#endif + +#ifndef GL_EXT_framebuffer_object +#define GL_EXT_framebuffer_object 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint); +GLAPI void APIENTRY glBindRenderbufferEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei, GLuint *); +GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum, GLenum, GLsizei, GLsizei); +GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum, GLenum, GLint *); +GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint); +GLAPI void APIENTRY glBindFramebufferEXT (GLenum, GLuint); +GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei, const GLuint *); +GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei, GLuint *); +GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum); +GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum, GLenum, GLenum, GLuint, GLint); +GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum, GLenum, GLenum, GLuint, GLint, GLint); +GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum, GLenum, GLenum, GLuint); +GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum, GLenum, GLenum, GLint *); +GLAPI void APIENTRY glGenerateMipmapEXT (GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer); +typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params); +typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer); +typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer); +typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers); +typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers); +typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); +typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset); +typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target); +#endif + +#ifndef GL_GREMEDY_string_marker +#define GL_GREMEDY_string_marker 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei, const GLvoid *); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const GLvoid *string); +#endif + +#ifndef GL_EXT_framebuffer_blit +#define GL_EXT_framebuffer_blit 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glBlitFramebufferEXT (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLint, GLbitfield, GLenum); +#endif + +// http://developer.download.nvidia.com/opengl/specs/GL_NVX_gpu_memory_info.txt +#ifndef GL_NVX_gpu_memory_info +#define GL_NVX_gpu_memory_info 1 +#define GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047 +#define GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048 +#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049 +#define GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A +#define GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B +#endif + +#ifndef GL_ATI_meminfo +#define GL_ATI_meminfo 1 +#define VBO_FREE_MEMORY_ATI 0x87FB +#define TEXTURE_FREE_MEMORY_ATI 0x87FC +#define RENDERBUFFER_FREE_MEMORY_ATI 0x87FD +#endif + +#ifndef GL_EXT_framebuffer_multisample +#define GL_EXT_framebuffer_multisample 1 +#ifdef GL_GLEXT_PROTOTYPES +GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +#endif /* GL_GLEXT_PROTOTYPES */ +typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum, GLsizei, GLenum, GLsizei, GLsizei); +#endif + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Runtime/GfxDevice/opengles/ExtensionsGLES.cpp b/Runtime/GfxDevice/opengles/ExtensionsGLES.cpp new file mode 100644 index 0000000..a948883 --- /dev/null +++ b/Runtime/GfxDevice/opengles/ExtensionsGLES.cpp @@ -0,0 +1,30 @@ +#include "UnityPrefix.h" + +#include "ExtensionsGLES.h" +#include "IncludesGLES.h" + +#if GFX_SUPPORTS_OPENGLESXX + +#if UNITY_IPHONE + #include <dlfcn.h> +#endif + +void* GetGLExtProcAddress(const char* name) +{ +#if GFX_SUPPORTS_EGL && !UNITY_WIN + return (void*) eglGetProcAddress(name); +#elif UNITY_IPHONE + + // on ios we link to framework, so symbols are already resolved + static void* selfHandle = 0; + if(!selfHandle) + selfHandle = dlopen(0, RTLD_LOCAL | RTLD_LAZY); + + return selfHandle ? dlsym(selfHandle, name) : 0; +#else + return 0; + +#endif +} + +#endif
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengles/ExtensionsGLES.h b/Runtime/GfxDevice/opengles/ExtensionsGLES.h new file mode 100644 index 0000000..51de6ad --- /dev/null +++ b/Runtime/GfxDevice/opengles/ExtensionsGLES.h @@ -0,0 +1,9 @@ +#pragma once + +#include "IncludesGLES.h" + +#if GFX_SUPPORTS_OPENGLESXX + +void* GetGLExtProcAddress(const char* name); + +#endif
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengles/IncludesGLES.h b/Runtime/GfxDevice/opengles/IncludesGLES.h new file mode 100644 index 0000000..300199d --- /dev/null +++ b/Runtime/GfxDevice/opengles/IncludesGLES.h @@ -0,0 +1,71 @@ +#pragma once + +#ifdef UNITYGL_H +# error "Don't Mix with UnityGL!!!" +#endif + +#define GFX_SUPPORTS_OPENGLESXX (GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30) + +#if GFX_SUPPORTS_OPENGLESXX + +#define GFX_SUPPORTS_EGL (UNITY_WIN || UNITY_LINUX || UNITY_ANDROID || UNITY_TIZEN || UNITY_BB10) + +#if UNITY_ANDROID || UNITY_WEBGL +# define GL_GLEXT_PROTOTYPES +#endif + +#if GFX_SUPPORTS_OPENGLES30 +# if UNITY_WIN +# include "PlatformDependent/WinPlayer/unityes_egl.h" +# include "PlatformDependent/WinPlayer/unityes_gl2.h" + // \todo [pyry] Remove gl2ext include since most of the extensions are now in core +# include "PlatformDependent/WinPlayer/unityes_gl2ext.h" +# include "PlatformDependent/WinPlayer/unityes_gl3.h" +# define INCLUDE_GLES_2X 1 +# define INCLUDE_GLES_3X 1 +# define DEF(ret,name,args) extern ret (WINAPI *name) args +# include "PlatformDependent/WinPlayer/GLESFunctionDefs.h" +# elif UNITY_ANDROID +# include <EGL/egl.h> +# include "PlatformDependent/AndroidPlayer/unityes_gl3.h" + // \todo [pyry] Remove gl2ext include since most of the extensions are now in core +# include <GLES2/gl2ext.h> +# include "Runtime/GfxDevice/opengles20/UnityGLES20Ext.h" +# else +# error "Unknown platform" +# endif +# +# include "Runtime/GfxDevice/opengles30//UnityGLES30Ext.h" + +#elif GFX_SUPPORTS_OPENGLES20 +# if UNITY_WIN +# include "PlatformDependent/WinPlayer/unityes_egl.h" +# include "PlatformDependent/WinPlayer/unityes_gl2.h" +# include "PlatformDependent/WinPlayer/unityes_gl2ext.h" +# define INCLUDE_GLES_2X 1 +# define DEF(ret,name,args) extern ret (WINAPI *name) args +# include "PlatformDependent/WinPlayer/GLESFunctionDefs.h" +# elif UNITY_IPHONE +# include <OpenGLES/ES2/gl.h> +# include <OpenGLES/ES2/glext.h> +# elif UNITY_LINUX || UNITY_ANDROID || UNITY_BB10 +# include <EGL/egl.h> +# include <GLES2/gl2.h> +# include <GLES2/gl2ext.h> +# elif UNITY_PEPPER || UNITY_WEBGL +# include <GLES2/gl2.h> +# include <GLES2/gl2ext.h> +# elif UNITY_TIZEN +# include <FGraphics.h> +# include <FGraphicsOpengl2.h> +using namespace Tizen::Graphics; +using namespace Tizen::Graphics::Opengl; +# else +# error "Unknown platform" +# endif +# +# include "Runtime/GfxDevice/opengles20/UnityGLES20Ext.h" +# +#endif + +#endif // GFX_SUPPORTS_OPENGLESXX
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengles20/AssertGLES20.cpp b/Runtime/GfxDevice/opengles20/AssertGLES20.cpp new file mode 100644 index 0000000..1b77623 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/AssertGLES20.cpp @@ -0,0 +1,58 @@ +#include "UnityPrefix.h" +#include "AssertGLES20.h" +#include "IncludesGLES20.h" + +#if GFX_SUPPORTS_OPENGLES20 + +using namespace std; + +static const char* GetErrorString(GLenum glerr) +{ + // Error descriptions taken from OpenGLES 1.1 specification (page 13) + switch(glerr) + { + case GL_NO_ERROR: + return "GL_NO_ERROR: No error occured"; + case GL_INVALID_ENUM: + return "GL_INVALID_ENUM: enum argument out of range"; + case GL_INVALID_VALUE: + return "GL_INVALID_VALUE: Numeric argument out of range"; + case GL_INVALID_OPERATION: + return "GL_INVALID_OPERATION: Operation illegal in current state"; + case GL_OUT_OF_MEMORY: + return "GL_OUT_OF_MEMORY: Not enough memory left to execute command"; + case 0x0506: // INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506 + return "GL_INVALID_FRAMEBUFFER_OPERATION_EXT"; + default: +#if UNITY_WEBGL + printf_console("AssertGles20::GetErrorString invoked for unknown error %d",glerr); +#endif + return "Unknown error"; + } +} + +void CheckOpenGLES2Error (const char *prefix, const char* file, long line) +{ + const int kMaxErrors = 10; + int counter = 0; + + GLenum glerr; + while( (glerr = glGetError ()) != GL_NO_ERROR ) + { + string errorString(GetErrorString(glerr)); + + if (prefix) + errorString = string(prefix) + ": " + errorString; + + DebugStringToFile (errorString.c_str(), 0, file, line, kAssert); + + ++counter; + if( counter > kMaxErrors ) + { + printf_console( "GLES: error count exceeds %i, stop reporting errors\n", kMaxErrors ); + return; + } + } +} + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/AssertGLES20.h b/Runtime/GfxDevice/opengles20/AssertGLES20.h new file mode 100644 index 0000000..4a9809c --- /dev/null +++ b/Runtime/GfxDevice/opengles20/AssertGLES20.h @@ -0,0 +1,29 @@ +#ifndef GLES_ASSERTGLES20_H +#define GLES_ASSERTGLES20_H + +#include "Runtime/Utilities/LogAssert.h" + +void CheckOpenGLES2Error (const char *prefix, const char* file, long line); + +#if !UNITY_RELEASE + #ifndef GLESAssert + /// Asserts for checking the OpenGL error state + #define GLESAssert() { CheckOpenGLES2Error (NULL, __FILE__, __LINE__); } + #endif + #define GLESAssertString(x) { CheckOpenGLES2Error (x, __FILE__, __LINE__); } + #define GLES_CHK(x) do { {x;} GLESAssert(); } while(0) +#else + + #ifndef GLESAssert + #define GLESAssert() + #endif + #define GLESAssertString(x) + #define GLES_CHK(x) x +#endif + + +//#define GLES_CHK(x) do {} while(0) +//#define GLES_CHK(x) +//#define GLES_CHK(x) do { printf_console("GLES: %s %d\n", __FILE__, __LINE__); } while(0) + +#endif diff --git a/Runtime/GfxDevice/opengles20/CombinerGLES20.cpp b/Runtime/GfxDevice/opengles20/CombinerGLES20.cpp new file mode 100644 index 0000000..eaff5fb --- /dev/null +++ b/Runtime/GfxDevice/opengles20/CombinerGLES20.cpp @@ -0,0 +1,21 @@ +#include "UnityPrefix.h" +#include "CombinerGLES20.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "VBOGLES20.h" + +#if GFX_SUPPORTS_OPENGLES20 + +TextureCombinersGLES2* TextureCombinersGLES2::Create (int count, const ShaderLab::TextureBinding* texEnvs) +{ + // check if we have enough vertex attributes to emulate this combiner + if (count + GL_TEXTURE_ARRAY0 >= gGraphicsCaps.gles20.maxAttributes) + return NULL; + + // create struct that holds texture combiner info object + TextureCombinersGLES2* combiners = new TextureCombinersGLES2(); + combiners->count = count; + combiners->texEnvs = texEnvs; + return combiners; +} + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/CombinerGLES20.h b/Runtime/GfxDevice/opengles20/CombinerGLES20.h new file mode 100644 index 0000000..6c144c5 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/CombinerGLES20.h @@ -0,0 +1,10 @@ +#pragma once + +namespace ShaderLab { struct TextureBinding; } + +struct TextureCombinersGLES2 +{ + static TextureCombinersGLES2* Create (int count, const ShaderLab::TextureBinding* texEnvs); + int count; + const ShaderLab::TextureBinding* texEnvs; +}; diff --git a/Runtime/GfxDevice/opengles20/ContextGLES20.cpp b/Runtime/GfxDevice/opengles20/ContextGLES20.cpp new file mode 100644 index 0000000..1eaa8fd --- /dev/null +++ b/Runtime/GfxDevice/opengles20/ContextGLES20.cpp @@ -0,0 +1,237 @@ +#include "UnityPrefix.h" +#include "ContextGLES20.h" +#include "IncludesGLES20.h" +#include "AssertGLES20.h" +#include "Runtime/Graphics/ScreenManager.h" + +#if GFX_SUPPORTS_OPENGLES20 + +#if UNITY_WIN + + +struct EGLESData +{ + void* dsp; + void* cfg; + void* cxt; + void* surf; + EGLESData():dsp(NULL),cfg(NULL),cxt(NULL),surf(NULL){} +}; + + +static EGLESData sOpenGLESData; + +bool InitializeGLES20 () +{ + HWND hwnd = GetScreenManager().GetWindow(); + if (hwnd) + { + CreateContextGLES20 (hwnd); + return true; + } + ErrorString ("gles20: Can't initialize because HWND not set up"); + return false; +} +void ShutdownGLES20 () +{ + DestroyContextGLES20(); +} +bool IsContextGLES20Created() +{ + return sOpenGLESData.surf != NULL && + sOpenGLESData.cxt != NULL && + sOpenGLESData.cfg != NULL && + sOpenGLESData.dsp != NULL; +} + +bool CreateContextGLES20(HWND hWnd) +{ + //Just in case + DestroyContextGLES20(); + + EGLint numConfigs; + EGLint majorVersion; + EGLint minorVersion; + +#if UNITY_WIN + + /// Build up the attribute list + const EGLint configAttribs[] = + { + EGL_LEVEL, 0, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NATIVE_RENDERABLE, EGL_FALSE, + EGL_DEPTH_SIZE, 16, + EGL_NONE + }; + + // Get Display + sOpenGLESData.dsp = eglGetDisplay( hWnd?GetDC(hWnd):EGL_DEFAULT_DISPLAY ); + if ( sOpenGLESData.dsp == EGL_NO_DISPLAY ) + { + printf_console("GLES20: eglGetDisplay failed\n" ); + return false; + } + //Hack : eglInitialize invokes WM_ACTIVATE message, and gAppActive is already true, so Unity will try to call some functions which requires some initialization, + // and this is not done yet + extern bool gAlreadyClosing; + bool last = gAlreadyClosing; + gAlreadyClosing = true; + // Initialize EGL + if ( ! eglInitialize( sOpenGLESData.dsp, &majorVersion, &minorVersion) ) + { + printf_console("GLES20: eglInitialize failed\n"); + return false; + } + + + // Choose config + if ( !eglChooseConfig(sOpenGLESData.dsp, configAttribs, &sOpenGLESData.cfg, 1, &numConfigs) ) + { + printf_console("GLES20: eglChooseConfig failed\n"); + return false; + } + + + // Create a surface + sOpenGLESData.surf = eglCreateWindowSurface( sOpenGLESData.dsp, sOpenGLESData.cfg, NativeWindowType( hWnd ), NULL ); + if ( sOpenGLESData.surf == EGL_NO_SURFACE ) + { + printf_console("GLES20: eglCreateWindowSurface failed\n"); + return false; + } + + // Create a GL context + EGLint ctxAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; + sOpenGLESData.cxt = eglCreateContext( sOpenGLESData.dsp, sOpenGLESData.cfg, EGL_NO_CONTEXT, ctxAttribList ); + if ( sOpenGLESData.cxt == EGL_NO_CONTEXT ) + { + printf_console("GLES20: eglCreateContext failed\n"); + return false; + } + + // Make the context current + if ( ! eglMakeCurrent( sOpenGLESData.dsp, sOpenGLESData.surf, sOpenGLESData.surf, sOpenGLESData.cxt ) ) + { + printf_console("GLES20: eglMakeCurrent failed\n"); + return false; + } + + gAlreadyClosing = last; +#endif + + GLESAssert(); + + return true; +} + + +void DestroyContextGLES20() +{ + if(sOpenGLESData.dsp) + { + eglMakeCurrent(sOpenGLESData.dsp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) ; + eglDestroyContext( sOpenGLESData.dsp, sOpenGLESData.cxt ); + eglDestroySurface( sOpenGLESData.dsp, sOpenGLESData.surf ); + eglTerminate( sOpenGLESData.dsp); + } + sOpenGLESData.surf = NULL; + sOpenGLESData.cxt = NULL; + sOpenGLESData.cfg = NULL; + sOpenGLESData.dsp = NULL; +} +void PresentContextGLES20() +{ + eglSwapBuffers( sOpenGLESData.dsp, sOpenGLESData.surf ); +} + +#elif UNITY_LINUX + +static EGLDisplay gEGLDisplay = EGL_NO_DISPLAY; +static EGLConfig gEGLConfig; +static EGLSurface gEGLSurface = EGL_NO_SURFACE; +static EGLContext gEGLContext = EGL_NO_CONTEXT; + +void SetEGLDisplay(EGLDisplay display) +{ + gEGLDisplay = display; +} + +void SetEGLConfig(const EGLConfig &config) +{ + gEGLConfig = config; +} + +bool InitializeGLES20 () +{ + Window window = 0; + window = GetScreenManager().GetWindow(); + + if(window) + { + CreateContextGLES20(window); + return true; + } + + return false; +} + +void ShutdownGLES20 () +{ + DestroyContextGLES20(); +} + +bool IsContextGLES20Created() +{ + return gEGLSurface != EGL_NO_SURFACE && gEGLContext != EGL_NO_CONTEXT; +} + +bool CreateContextGLES20(Window window) +{ + DestroyContextGLES20(); + + gEGLSurface = eglCreateWindowSurface(gEGLDisplay, gEGLConfig, window, NULL); + if(gEGLSurface == EGL_NO_SURFACE) + { + printf_console("eglCreateWindowSurface failed\n"); + return false; + } + + // Create a context + printf_console("Creating context\n"); + EGLint ctxAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; + gEGLContext = eglCreateContext(gEGLDisplay, gEGLConfig, EGL_NO_CONTEXT, ctxAttribList ); + if ( gEGLContext == EGL_NO_CONTEXT ) + { + printf_console( "eglCreateContext failed\n" ); + return false; + } + + if(!eglMakeCurrent(gEGLDisplay, gEGLSurface, gEGLSurface, gEGLContext)) + { + printf_console("eglMakeCurrent failed\n"); + } + + return true; +} + +void DestroyContextGLES20() +{ + if(IsContextGLES20Created()) + { + eglMakeCurrent(gEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(gEGLDisplay, gEGLContext); + eglDestroySurface(gEGLDisplay, gEGLSurface); + } + + gEGLSurface = EGL_NO_SURFACE; + gEGLContext = EGL_NO_CONTEXT; +} + +void PresentContextGLES() +{ + eglSwapBuffers(gEGLDisplay, gEGLSurface); +} +#endif // UNITY_WIN +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/ContextGLES20.h b/Runtime/GfxDevice/opengles20/ContextGLES20.h new file mode 100644 index 0000000..4fab18b --- /dev/null +++ b/Runtime/GfxDevice/opengles20/ContextGLES20.h @@ -0,0 +1,43 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +#if UNITY_LINUX +#include <X11/Xlib.h> +#include <GLES2/gl2.h> +#endif + +#if UNITY_BB10 +#include <GLES2/gl2.h> +#include <screen/screen.h> +#endif + +#if UNITY_WIN || UNITY_LINUX || UNITY_BB10 || UNITY_TIZEN || UNITY_ANDROID +bool InitializeGLES20 (); +void ShutdownGLES20 (); +bool IsContextGLES20Created(); +#if UNITY_WIN +bool CreateContextGLES20(HWND hWnd); +#elif UNITY_LINUX +bool CreateContextGLES20(Window window); +#elif UNITY_BB10 +bool CreateContextGLES20(screen_window_t window); +void ResizeContextGLES20(screen_window_t window, int width, int height); +void AdjustVsync(int val); +#elif UNITY_TIZEN +bool CreateContextGLES20(); +void ResizeContextGLES20(int width, int height); +#endif +#if !UNITY_ANDROID +void DestroyContextGLES20(); +#endif +#endif +void PresentContextGLES(); +void PresentContextGLES20(); + +#if UNITY_ANDROID +void ReleaseGLES20Context(); + +void AcquireGLES20Context(); +#endif diff --git a/Runtime/GfxDevice/opengles20/DebugGLES20.cpp b/Runtime/GfxDevice/opengles20/DebugGLES20.cpp new file mode 100644 index 0000000..d087e07 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/DebugGLES20.cpp @@ -0,0 +1,38 @@ +#include "UnityPrefix.h" +#include "IncludesGLES20.h" +#include "DebugGLES20.h" +#include "AssertGLES20.h" + + +void DumpVertexArrayStateGLES20() +{ +#if GFX_SUPPORTS_OPENGLES20 + GLint maxVertexAttribs = 0; + GLES_CHK(glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs)); + + GLint vbo = 0; + GLint ibo = 0; + GLES_CHK(glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vbo)); + GLES_CHK(glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &ibo)); + + printf_console("---> VertexArray State: vbo:%d ibo:%d\n", vbo, ibo); + + for (int q = 0; q < maxVertexAttribs; ++q) + { + int enabled, size, stride, normalized, type, vbo; + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_SIZE, &size)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &stride)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &normalized)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_TYPE, &type)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &vbo)); + + GLvoid* ptr; + GLES_CHK(glGetVertexAttribPointerv(q, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); + + printf_console(" attr[%d] --- %s type:%d size:%d stride:%d norm:%d vbo:%d, %p\n", + q, enabled? "On ": "Off", + type, size, stride, normalized, vbo, ptr); + } +#endif +} diff --git a/Runtime/GfxDevice/opengles20/DebugGLES20.h b/Runtime/GfxDevice/opengles20/DebugGLES20.h new file mode 100644 index 0000000..b8c0004 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/DebugGLES20.h @@ -0,0 +1,139 @@ +#ifndef DEBUGGLES20_H +#define DEBUGGLES20_H + +#include "Runtime/Utilities/LogAssert.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Math/Matrix4x4.h" + + +void DumpVertexArrayStateGLES20(); + +#if !UNITY_RELEASE + #define DBG_LOG_GLES20_ACTIVE 0 + #define DBG_TEXTURE_VERBOSE_GLES20_ACTIVE 0 + #define DBG_SHADER_VERBOSE_GLES20_ACTIVE 0 + #define DBG_GLSL_BINDINGS_GLES20_ACTIVE 0 +#else + #define DBG_LOG_GLES20_ACTIVE 0 + #define DBG_TEXTURE_VERBOSE_GLES20_ACTIVE 0 + #define DBG_SHADER_VERBOSE_GLES20_ACTIVE 0 + #define DBG_GLSL_BINDINGS_GLES20_ACTIVE 0 +#endif + +#if DBG_LOG_GLES20_ACTIVE + #define DBG_LOG_GLES20(...) {printf_console(__VA_ARGS__);printf_console("\n");} + + inline std::string GetMatrixString(const Matrix4x4f& mtx) + { + return Format("%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f", + mtx[0], mtx[1], mtx[2], mtx[3], + mtx[4], mtx[5], mtx[6], mtx[7], + mtx[8], mtx[9], mtx[10],mtx[11], + mtx[12],mtx[13],mtx[14],mtx[15]); + } + + inline const char* GetBoolString(bool type) + { + return type?"True":"False"; + } + + inline const char * GetBlendModeString(BlendMode type) + { + switch(type) + { + case kBlendZero:return "kBlendZero"; + case kBlendOne:return "kBlendOne"; + case kBlendDstColor:return "kBlendDstColor"; + case kBlendSrcColor:return "kBlendSrcColor"; + case kBlendOneMinusDstColor:return "kBlendOneMinusDstColor"; + case kBlendSrcAlpha:return "kBlendSrcAlpha"; + case kBlendOneMinusSrcColor:return "kBlendOneMinusSrcColor"; + case kBlendDstAlpha:return "kBlendDstAlpha"; + case kBlendOneMinusDstAlpha:return "kBlendOneMinusDstAlpha"; + case kBlendSrcAlphaSaturate:return "kBlendSrcAlphaSaturate"; + case kBlendOneMinusSrcAlpha:return "kBlendOneMinusSrcAlpha"; + default:return "GetBlendModeString<Undefined>"; + } + } + inline const char * GetCullModeString(CullMode type) + { + switch(type) + { + case kCullUnknown:return "kCullUnknown"; + case kCullOff:return "kCullOff:return"; + case kCullFront:return "kCullFront"; + case kCullBack:return "kCullBack";; + default:return "GetCullMode<undefined>"; + } + } + + inline const char * GetCompareFunctionString(CompareFunction type) + { + switch(type) + { + case kFuncUnknown:return "kFuncUnknown"; + case kFuncDisabled:return "kFuncDisabled"; + case kFuncNever:return "kFuncNever"; + case kFuncLess:return "kFuncLess"; + case kFuncEqual:return "kFuncEqual"; + case kFuncLEqual:return "kFuncLEqual"; + case kFuncGreater:return "kFuncGreater"; + case kFuncNotEqual:return "kFuncNotEqual"; + case kFuncGEqual:return "kFuncGEqual"; + case kFuncAlways:return "kFuncAlways"; + default:return "GetCompareFunctionString<Undefined>"; + } + } + + inline const char * GetShaderTypeString(ShaderType type) + { + switch(type) + { + case kShaderNone:return "kShaderNone"; + case kShaderVertex:return "kShaderVertex"; + case kShaderFragment:return "kShaderFragment"; + default:return "GetShaderTypeString<undefined>"; + } + } + + inline const char * GetShaderImplTypeString(ShaderImplType type) + { + switch(type) + { + case kShaderImplUndefined: return "kShaderImplUndefined"; + case kShaderImplVertex: return "kShaderImplVertex"; + case kShaderImplFragment: return "kShaderImplFragment"; + case kShaderImplBoth: return "kShaderImplBoth"; + default:return "GetShaderImplTypeString<Undefined>"; + } + } + +#else + #define DBG_LOG_GLES20(...) +#endif + +#if DBG_TEXTURE_VERBOSE_GLES20_ACTIVE +#define DBG_TEXTURE_VERBOSE_GLES20(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#else +#define DBG_TEXTURE_VERBOSE_GLES20(...) +#endif + +#if DBG_SHADER_VERBOSE_GLES20_ACTIVE + #define DBG_SHADER_VERBOSE_GLES20(...) {printf_console(__VA_ARGS__);printf_console("\n");} + #define DBG_SHADER_VERBOSE_GLES20_DUMP_SHADER(prefix, text) { printf_console("%s\n", prefix);DebugTextLineByLine(text);printf_console("\n---\n");} +#else + #define DBG_SHADER_VERBOSE_GLES20(...) + #define DBG_SHADER_VERBOSE_GLES20_DUMP_SHADER(prefix, text) +#endif + +#if DBG_GLSL_BINDINGS_GLES20_ACTIVE + #define DBG_GLSL_BINDINGS_GLES20(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#else + #define DBG_GLSL_BINDINGS_GLES20(...) +#endif + + +#endif diff --git a/Runtime/GfxDevice/opengles20/FixedFunctionStateGLES20.cpp b/Runtime/GfxDevice/opengles20/FixedFunctionStateGLES20.cpp new file mode 100644 index 0000000..4df51e1 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/FixedFunctionStateGLES20.cpp @@ -0,0 +1,73 @@ +#include "UnityPrefix.h" +#include "FixedFunctionStateGLES20.h" +#include <sstream> + + +FixedFunctionStateGLES20::FixedFunctionStateGLES20 () +: texUnitCount(0), + lightType(0), + texUnitMatrix(0), + lightingEnabled(false), + specularEnabled(true), + onlyDirectionalLights(false), + lightCount(0), + useUniformInsteadOfVertexColor(false), + useVertexColorAsAmbientAndDiffuse(false), + useVertexColorAsEmission(false), + fogMode(kFogDisabled), + addSpecularAfterTexturing(false), + alphaTest(kFuncDisabled), + setupPointSize(false) +{ + for (int q = 0; q < kMaxSupportedTextureUnitsGLES; ++q) + { + texUnitCube[q] = false; + texUnitGen[q] = kTexGenDisabled; + texUnitColorCombiner[q] = ~0UL; + texUnitAlphaCombiner[q] = ~0UL; + } +} + +static std::string CombinerToString (unsigned int combinerDesc) +{ + std::ostringstream s; + s << combinerDesc; + return s.str().c_str(); +} + + +std::string FixedFunctionStateGLES20::ToString () const +{ + std::ostringstream s; + + s << "FixedFunctionStateGLES20::ToString():\n"; + s << " lightingEnabled = " << lightingEnabled << "\n"; + s << " specularEnabled = " << specularEnabled << "\n"; + s << " lights = " << lightCount << "\n"; + for (int i = 0; i < lightCount; ++i) + s << " light" << i << " : " << GetLightType(i) << "\n"; + + s << " useUniformInsteadOfVertexColor = " << useUniformInsteadOfVertexColor << "\n"; + s << " useVertexColorAsAmbientAndDiffuse = " << useVertexColorAsAmbientAndDiffuse << "\n"; + s << " useVertexColorAsEmission = " << useVertexColorAsEmission << "\n"; + + s << " fogMode = " << fogMode << "\n"; + + for (int i = 0; i < texUnitCount; ++i) + { + s << " texture " << i << "\n"; + + s << " CUBE = " << ((texUnitCube[i])? "true": "false") << "\n"; + s << " rgb combiner = " << CombinerToString(texUnitColorCombiner[i]) << "\n"; + s << " alpba combiner = " << CombinerToString(texUnitAlphaCombiner[i]) << "\n"; + s << " texGen = " << texUnitGen[i] << "\n"; + s << " need matrix: " << (NeedTexUnitMatrix(i)?"true":"false") << "\n"; + s << " need perspective divide: " << (IsTexUnitProjected(i)?"true":"false") << "\n"; + } + + s << " addSpecularafterTexturing = " << addSpecularAfterTexturing << "\n"; + s << " alphaTest = " << alphaTest << "\n"; + s << " setupPointSize = " << setupPointSize << "\n"; + + return s.str().c_str(); +} diff --git a/Runtime/GfxDevice/opengles20/FixedFunctionStateGLES20.h b/Runtime/GfxDevice/opengles20/FixedFunctionStateGLES20.h new file mode 100644 index 0000000..9fe723e --- /dev/null +++ b/Runtime/GfxDevice/opengles20/FixedFunctionStateGLES20.h @@ -0,0 +1,66 @@ +#ifndef FIXEDFUNCTIONSTATE_GLES20_H +#define FIXEDFUNCTIONSTATE_GLES20_H + +#include "IncludesGLES20.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include <string> + +// we can use one var to determine both shift and mask, but let help out the compiler ;-) +#define FFPSTATE_SET_MASK(target, idx, val, shift_mul, mask) \ +do{ \ + target &= ~(mask << ((idx)*shift_mul)); \ + target |= (val << ((idx)*shift_mul)); \ +}while(0) \ + + + +class FixedFunctionStateGLES20 +{ +public: + FixedFunctionStateGLES20(); + + UInt32 texUnitColorCombiner[kMaxSupportedTextureUnitsGLES]; + UInt32 texUnitAlphaCombiner[kMaxSupportedTextureUnitsGLES]; + bool texUnitCube[kMaxSupportedTextureUnitsGLES]; + int texUnitGen[kMaxSupportedTextureUnitsGLES]; + int texUnitCount; + + // we will use 4bits per light - this way we can handle up to 8 lights (though kMaxEmulatedVertexLights = 4) + UInt32 lightType; + // we will use 2 bits per tex unit - one for perspective divide, the other one for if we need matrix mul at all + // this way we can store 16 texunit info (though kMaxSupportedTextureUnitsGLES = 8) + UInt32 texUnitMatrix; + + int lightCount : 8; + FogMode fogMode : 8; + CompareFunction alphaTest : 8; + + bool lightingEnabled; + bool specularEnabled; + bool onlyDirectionalLights; + bool setupPointSize; + + bool useUniformInsteadOfVertexColor; + bool useVertexColorAsAmbientAndDiffuse; + bool useVertexColorAsEmission; + bool addSpecularAfterTexturing; + + unsigned GetLightType(int i) const { return (lightType >> (i*4)) & 0xF; } + void SetLightType(int i, unsigned type) { FFPSTATE_SET_MASK(lightType, i, type, 4, 0xF); } + + bool NeedTexUnitMatrix(int i) const { return ((texUnitMatrix >> (i*2)) & 0x1) != 0; } + bool IsTexUnitProjected(int i) const { return ((texUnitMatrix >> (i*2)) & 0x2) != 0; } + + void SetTexUnitMatrixParam(int i, bool hasMatrix, bool isProjected) + { + int mask = (hasMatrix ? 1 : 0) | (isProjected ? 2 : 0); + FFPSTATE_SET_MASK(texUnitMatrix, i, mask, 2, 0x3); + } + + std::string ToString () const; +}; + + +#undef FFPSTATE_SET_MASK + +#endif /* FIXEDFUNCTIONSTATE_GLES20_H */ diff --git a/Runtime/GfxDevice/opengles20/GfxDeviceGLES20.cpp b/Runtime/GfxDevice/opengles20/GfxDeviceGLES20.cpp new file mode 100644 index 0000000..cf59ce6 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GfxDeviceGLES20.cpp @@ -0,0 +1,2815 @@ +#include "UnityPrefix.h" +#if GFX_SUPPORTS_OPENGLES20 +#include "Runtime/Graphics/ScreenManager.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Shaders/MaterialProperties.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/Misc/Allocator.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/Math/Quaternion.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/properties.h" +#include "External/shaderlab/Library/program.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Threads/AtomicOps.h" +#include "Runtime/GfxDevice/TransformState.h" +#include "Runtime/GfxDevice/GpuProgramParamsApply.h" +#include "IncludesGLES20.h" +#include "AssertGLES20.h" +#include "ContextGLES20.h" +#include "VBOGLES20.h" +#include "TexturesGLES20.h" +#include "CombinerGLES20.h" +#include "GpuProgramsGLES20.h" +#include "FixedFunctionStateGLES20.h" +#include "ShaderGeneratorGLES20.h" +#include "RenderTextureGLES20.h" +#include "DebugGLES20.h" +#include "TimerQueryGLES20.h" +#include "TextureIdMapGLES20.h" +#include "UnityGLES20Ext.h" + +#if UNITY_IPHONE + #include "PlatformDependent/iPhonePlayer/iPhoneSettings.h" +#elif UNITY_ANDROID + #include "PlatformDependent/AndroidPlayer/ContextGLES.h" + #include "PlatformDependent/AndroidPlayer/EntryPoint.h" + #include "PlatformDependent/AndroidPlayer/AndroidSystemInfo.h" +#endif + +#include "Runtime/GfxDevice/GLDataBufferCommon.h" + +#if NV_STATE_FILTERING + +void filteredInitGLES20(); +void filteredBindBufferGLES20(GLenum target, GLuint buffer, bool isImmediate); +void filteredVertexAttribPointerGLES20(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); +void filteredDeleteBuffersGLES20(GLsizei n, const GLuint *buffers); + +#ifdef glBindBuffer +#undef glBindBuffer +#endif +#define glBindBuffer(a, b) filteredBindBufferGLES20(a, b, true) +#ifndef glDeleteBuffers +#define glDeleteBuffers filteredDeleteBuffersGLES20 +#endif +#ifndef glVertexAttribPointer +#define glVertexAttribPointer filteredVertexAttribPointerGLES20 +#endif + +#endif + +// let's play safe here: +// ios/glesemu works just fine +// and shadows demands more careful eps choice - do it later +#define WORKAROUND_POLYGON_OFFSET UNITY_ANDROID + +// forward declarations + +bool IsActiveRenderTargetWithColorGLES2(); // RenderTextureGL.cpp +namespace ShaderLab { + TexEnv* GetTexEnvForBinding( const TextureBinding& binding, const PropertySheet* props ); // pass.cpp +} + +// local forward declarations +struct DeviceStateGLES20; +static void ApplyBackfaceMode( const DeviceStateGLES20& state ); +static GLuint GetSharedFBO (DeviceStateGLES20& state); + +extern GLint gDefaultFBO; + +// NOTE: GLES2.0 supports only 4 lights for now +enum { kMaxSupportedVertexLightsByGLES20 = 4 }; + +// Constant tables +static const unsigned int kBlendModeES2[] = { + GL_ZERO, GL_ONE, GL_DST_COLOR, GL_SRC_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR, + GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA_SATURATE, GL_ONE_MINUS_SRC_ALPHA, +}; + +static const unsigned int kBlendFuncES2[] = { + GL_FUNC_ADD, GL_FUNC_SUBTRACT, + GL_FUNC_REVERSE_SUBTRACT, GL_MIN_EXT, GL_MAX_EXT, +}; + +static const unsigned int kCmpFuncES2[] = { + GL_NEVER, GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS +}; + +static const unsigned int kStencilOpES2[] = { + GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, + GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP +}; + +static const GLenum kWrapModeES2[kTexWrapCount] = { + GL_REPEAT, + GL_CLAMP_TO_EDGE, +}; + +static const GLint kMinFilterES2[kTexFilterCount] = { GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR }; + +// -------------------------------------------------------------------------- + +struct DeviceDepthStateGLES20 : public DeviceDepthState +{ + UInt32 depthFunc; +}; + +struct DeviceStencilStateGLES20 : public DeviceStencilState +{ + GLenum stencilFuncFront; + GLenum stencilFailOpFront; + GLenum depthFailOpFront; + GLenum depthPassOpFront; + GLenum stencilFuncBack; + GLenum stencilFailOpBack; + GLenum depthFailOpBack; + GLenum depthPassOpBack; +}; + + +typedef std::map< GfxBlendState, DeviceBlendState, memcmp_less<GfxBlendState> > CachedBlendStates; +typedef std::map< GfxDepthState, DeviceDepthStateGLES20, memcmp_less<GfxDepthState> > CachedDepthStates; +typedef std::map< GfxStencilState, DeviceStencilStateGLES20, memcmp_less<GfxStencilState> > CachedStencilStates; +typedef std::map< GfxRasterState, DeviceRasterState, memcmp_less<GfxRasterState> > CachedRasterStates; + +// -------------------------------------------------------------------------- +struct TextureUnitStateGLES2 +{ + GLuint texID; + TextureDimension texDim; + unsigned int combColor, combAlpha; + Vector4f color; + TexGenMode texGen; + Matrix4x4f textureMatrix; + float bias; + + // right let waste space here instead of device-level int + bool identityMatrix; + bool isProjected; + bool posForTexGen; + bool nrmForTexGen; + + void Invalidate(); + + static bool PositionRequiredForTexGen(TexGenMode mode) + { + return (mode == kTexGenObject || mode == kTexGenEyeLinear); + } + + static bool NormalRequiredForTexGen(TexGenMode mode) + { + return (mode == kTexGenSphereMap || mode == kTexGenCubeReflect || mode == kTexGenCubeNormal); + } + + void SetTexGen( TexGenMode mode ) + { + posForTexGen = PositionRequiredForTexGen(mode); + nrmForTexGen = NormalRequiredForTexGen(mode); + + texGen = mode; + } +}; + +void TextureUnitStateGLES2::Invalidate() +{ + texID = -1; + texDim = kTexDimNone; + combColor = combAlpha = 0xFFFFFFFF; + color.Set( -1, -1, -1, -1 ); + texGen = kTexGenUnknown; + posForTexGen = 0; + nrmForTexGen = 0; + textureMatrix.SetIdentity(); + identityMatrix = true; + isProjected = false; + bias = 1.0e6f; +} + + +// -------------------------------------------------------------------------- +// TODO: optimize this. Right now we just send off whole 8 float3 UVs with each +// immediate mode vertex. We could at least detect the number of them used from +// ImmediateTexCoord calls. +struct ImmediateVertexGLES20 { + Vector3f vertex; + Vector3f normal; + UInt32 color; + Vector3f texCoords[8]; +}; + +struct ImmediateModeGLES20 { + std::vector<ImmediateVertexGLES20> m_Vertices; + ImmediateVertexGLES20 m_Current; + GfxPrimitiveType m_Mode; + UInt16* m_QuadsIB; + + int m_IndexBufferQuadsID; + + ImmediateModeGLES20(); + ~ImmediateModeGLES20(); + void Invalidate(); +}; + +// -------------------------------------------------------------------------- +struct DeviceStateGLES20 +{ + GLuint m_SharedFBO; + GLuint m_HelperFBO; + int m_TextureIDGenerator; + + int depthFunc; + int depthWrite; // 0/1 or -1 + + int blending; + int srcBlend, destBlend, srcBlendAlpha, destBlendAlpha; // Blend modes + int blendOp, blendOpAlpha; + CompareFunction alphaTest; + float alphaValue; + + CullMode culling; + bool appBackfaceMode, userBackfaceMode; + NormalizationMode + normalization; + int scissor; + + bool lighting; + bool separateSpecular; + SimpleVec4 matDiffuse, matAmbient, matSpecular, matEmissive; + SimpleVec4 ambient; + float matShininess; + ColorMaterialMode + colorMaterial; + + float offsetFactor, offsetUnits; + + int colorWriteMask; // ColorWriteMask combinations + SimpleVec4 color; + + TextureUnitStateGLES2 + textures[kMaxSupportedTextureUnitsGLES]; + int textureCount; + int activeTextureUnit; + + // pure optimization: texGen is very special case and is used sparingly + UInt32 positionTexGen; + UInt32 normalTexGen; + + int vertexLightCount; + LightType vertexLightTypes[kMaxSupportedVertexLights]; + + TransformState transformState; + + DynamicVBO* m_DynamicVBO; + bool vboContainsColor; + + int viewport[4]; + int scissorRect[4]; + + // should be set before BeforeDrawCall call + GfxPrimitiveType drawCallTopology; + + + GpuProgram* activeProgram; + const GpuProgramParameters* activeProgramParams; + dynamic_array<UInt8> activeProgramParamsBuffer; + UInt32 activeProgramID; + + + CachedBlendStates m_CachedBlendStates; + CachedDepthStates m_CachedDepthStates; + CachedStencilStates m_CachedStencilStates; + CachedRasterStates m_CachedRasterStates; + + const DeviceBlendState* m_CurrBlendState; + const DeviceDepthStateGLES20* m_CurrDepthState; + const DeviceStencilStateGLES20* m_CurrStencilState; + int m_StencilRef; + const DeviceRasterState* m_CurrRasterState; + + ImmediateModeGLES20 m_Imm; + +public: + DeviceStateGLES20(); + void Invalidate(); + void ComputeFixedFunctionState(FixedFunctionStateGLES20& state, const GfxFogParams& fog) const; + + inline void ApplyTexGen( UInt32 unit ); + inline void DropTexGen( UInt32 unit ); +}; + +DeviceStateGLES20::DeviceStateGLES20() +: m_DynamicVBO(0) +{ + m_TextureIDGenerator = 0; +} + +void DeviceStateGLES20::Invalidate() +{ + DBG_LOG_GLES20("Invalidate"); + int i; + + depthFunc = -1; //unknown + depthWrite = -1; + + blending = -1; // unknown + srcBlend = destBlend = srcBlendAlpha = destBlendAlpha = -1; // won't match any GL mode + blendOp = blendOpAlpha = -1; + alphaTest = kFuncUnknown; + alphaValue = -1.0f; + + culling = kCullUnknown; + normalization = kNormalizationUnknown; + scissor = -1; + + lighting = false; + separateSpecular = false; + + matDiffuse.set( -1, -1, -1, -1 ); + matAmbient.set( -1, -1, -1, -1 ); + matSpecular.set( -1, -1, -1, -1 ); + matEmissive.set( -1, -1, -1, -1 ); + ambient.set( -1, -1, -1, -1 ); + matShininess = -1.0f; + colorMaterial = kColorMatUnknown; + + offsetFactor = offsetUnits = -1000.0f; + + colorWriteMask = -1; // TBD ? + m_StencilRef = -1; + + color.set( -1, -1, -1, -1 ); + + activeTextureUnit = -1; + for( i = 0; i < kMaxSupportedTextureUnitsGLES; ++i ) + textures[i].Invalidate(); + textureCount = 0; + + positionTexGen = 0; + normalTexGen = 0; + + vertexLightCount = 0; + for ( i = 0; i < kMaxSupportedVertexLights; ++i) + vertexLightTypes[i] = kLightDirectional; + + // make sure backface mode is in sync + appBackfaceMode = false; + userBackfaceMode = false; + ApplyBackfaceMode( *this ); + + vboContainsColor = true; + + viewport[0] = 0; + viewport[1] = 0; + viewport[2] = 0; + viewport[3] = 0; + + scissorRect[0] = 0; + scissorRect[1] = 0; + scissorRect[2] = 0; + scissorRect[3] = 0; + + activeProgram = 0; + activeProgramParams = 0; + activeProgramParamsBuffer.resize_uninitialized(0); + activeProgramID = -1; + + m_Imm.Invalidate(); + + InvalidateVertexInputCacheGLES20(); + + GLESAssert(); +} + +void DeviceStateGLES20::ComputeFixedFunctionState(FixedFunctionStateGLES20& state, const GfxFogParams& fog) const +{ + if (lighting) + { + int numLights = vertexLightCount; + bool onlyDir = true; + for(int i = 0 ; i < numLights ; ++i) + { + onlyDir = onlyDir && (vertexLightTypes[i] == kLightDirectional); + state.SetLightType(i,vertexLightTypes[i]); + } + + state.lightingEnabled = true; + state.lightCount = numLights; + state.onlyDirectionalLights = onlyDir; + state.specularEnabled = separateSpecular; + + switch (colorMaterial) + { + case kColorMatDisabled: + break; + + case kColorMatAmbientAndDiffuse: + state.useVertexColorAsAmbientAndDiffuse = true; + break; + + case kColorMatEmission: + state.useVertexColorAsEmission = true; + break; + + default: + ErrorString("Unsupported color material mode"); + break; + } + } + else + { + state.lightingEnabled = false; + state.lightCount = 0; + } + + state.useUniformInsteadOfVertexColor = !vboContainsColor; + state.texUnitCount = textureCount; + + for (int i = 0; i < textureCount; i++) + { + Assert(textures[i].texDim != kTexDimUnknown); + Assert(textures[i].texDim != kTexDimNone); + Assert(textures[i].texDim != kTexDimAny); + Assert(textures[i].texDim != kTexDim3D); // OpenGLES2.0 does NOT supports 3D textures + state.texUnitCube[i] = (textures[i].texDim == kTexDimCUBE); + state.texUnitColorCombiner[i] = textures[i].combColor, + state.texUnitAlphaCombiner[i] = textures[i].combAlpha; + state.texUnitGen[i] = textures[i].texGen; + + bool needMatrix = !textures[i].identityMatrix || textures[i].texGen > kTexGenDisabled; + state.SetTexUnitMatrixParam(i, needMatrix, textures[i].isProjected); + } + + state.fogMode = fog.mode; + switch (fog.mode) + { + case kFogUnknown: + case kFogDisabled: + state.fogMode = kFogDisabled; + default: + break; + } + + if(gGraphicsCaps.gles20.hasAlphaTestQCOM) + { + // we dont want to generate special shader if we have alpha-test done gl style + state.alphaTest = kFuncDisabled; + } + else + { + state.alphaTest = alphaTest; + switch (alphaTest) + { + case kFuncNever: /* \todo Disable drawing. */ + case kFuncUnknown: + case kFuncDisabled: + case kFuncAlways: + state.alphaTest = kFuncDisabled; + default: + break; + } + } + + state.setupPointSize = drawCallTopology == kPrimitivePoints; +} + +inline void DeviceStateGLES20::ApplyTexGen( UInt32 unit ) +{ + const TextureUnitStateGLES2& state = textures[unit]; + + positionTexGen = state.posForTexGen ? positionTexGen | (1<<unit) + : positionTexGen & ~(1<<unit); + + normalTexGen = state.nrmForTexGen ? normalTexGen | (1<<unit) + : normalTexGen & ~(1<<unit); +} + +inline void DeviceStateGLES20::DropTexGen( UInt32 unit ) +{ + positionTexGen &= ~(1<<unit); + normalTexGen &= ~(1<<unit); +} + + +#include "GfxDeviceGLES20.h" +#include "Runtime/GfxDevice/GLESCommon.h" + +void GfxDeviceGLES20_MarkWorldViewProjDirty() +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + GetGLES20DeviceState(device).transformState.dirtyFlags |= TransformState::kWorldViewProjDirty; +} + +void GfxDeviceGLES20_DisableDepthTest() +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + GetGLES20DeviceState(device).depthFunc = GL_NEVER; + GLES_CHK(glDisable(GL_DEPTH_TEST)); +} + +void GfxDeviceGLES20_SetDrawCallTopology(GfxPrimitiveType topology) +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + GetGLES20DeviceState(device).drawCallTopology = topology; +} + + +#define GL_RT_COMMON_GLES2 1 +#include "Runtime/GfxDevice/GLRTCommon.h" +#undef GL_RT_COMMON_GLES2 + +void GraphicsCaps::InitGLES20() +{ + GLES_InitCommonCaps(this); + gGlesExtFunc.InitExtFunc(); + + shaderCaps = kShaderLevel3; + + maxLights = kMaxSupportedVertexLightsByGLES20; // vertex light count + hasAnisoFilter = QueryExtension("GL_EXT_texture_filter_anisotropic"); // has anisotropic filtering? + if (hasAnisoFilter) + { + #if UNITY_PEPPER + // Google's implementation incorrectly reports a maxAnisoLevel of 1. + // Until they fix this, just set it here. + maxAnisoLevel = 16; + #else + GLES_CHK(glGetIntegerv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint *)&maxAnisoLevel )); + #endif + } + else + maxAnisoLevel = 1; + + + maxTexImageUnits = 8; + GLES_CHK(glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTexImageUnits)); + maxTexImageUnits = std::max<int>(std::min<int>( maxTexImageUnits, kMaxSupportedTextureUnitsGLES ), 1); + + maxTexUnits = maxTexImageUnits; + maxTexCoords = maxTexImageUnits; + + GLES_CHK(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize)); + GLES_CHK(glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &maxCubeMapSize)); + GLES_CHK(glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderTextureSize)); + + hasMipLevelBias = QueryExtension("GL_EXT_texture_lod_bias"); // can apply bias for mips? + hasMipMaxLevel = QueryExtension("GL_APPLE_texture_max_level"); + + gles20.hasAppleMSAA = QueryExtension("GL_APPLE_framebuffer_multisample"); + gles20.hasImgMSAA = QueryExtension("GL_IMG_multisampled_render_to_texture") && gGlesExtFunc.glRenderbufferStorageMultisampleIMG && gGlesExtFunc.glFramebufferTexture2DMultisampleIMG; + + hasMultiSampleAutoResolve = gles20.hasImgMSAA; + hasMultiSample = gles20.hasAppleMSAA || gles20.hasImgMSAA; + + + hasBlendSquare = true; + hasSeparateAlphaBlend = true; + hasBlendSub = true; + hasBlendMinMax = QueryExtension("GL_EXT_blend_minmax"); + + hasS3TCCompression = false; + + hasAutoMipMapGeneration = true; + + has3DTexture = false; + + npot = kNPOTRestricted; + if( QueryExtension("GL_OES_texture_npot") || QueryExtension("GL_ARB_texture_non_power_of_two") ) + npot = kNPOTFull; + + npotRT = npot; + + hasRenderToTexture = true; // We have render-to-texture functionality. + hasShadowCollectorPass = false; + + hasHighPrecisionTextureCombiners = false; + + hasRenderToCubemap = true; + + supportsTextureFormat[kTexFormatBGRA32] = QueryExtension("GL_APPLE_texture_format_BGRA8888") || QueryExtension("GL_EXT_texture_format_BGRA8888"); + supportsTextureFormat[kTexFormatAlphaLum16] = false; + supportsTextureFormat[kTexFormatARGB32] = false; // OpenGL ES has no support for INT_8_8_8_8 format, so don't bother with Unity reversed formats at all + supportsTextureFormat[kTexFormatBGR24] = false; // OpenGL ES has no support for INT_8_8_8_8 format, so don't bother with Unity reversed formats at all + supportsTextureFormat[kTexFormatDXT1] = QueryExtension("GL_EXT_texture_compression_s3tc") || QueryExtension("GL_EXT_texture_compression_dxt1"); + supportsTextureFormat[kTexFormatDXT3] = QueryExtension("GL_EXT_texture_compression_s3tc") || QueryExtension("GL_CHROMIUM_texture_compression_dxt3"); + supportsTextureFormat[kTexFormatDXT5] = QueryExtension("GL_EXT_texture_compression_s3tc") || QueryExtension("GL_CHROMIUM_texture_compression_dxt5"); + supportsTextureFormat[kTexFormatPVRTC_RGB2] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatPVRTC_RGBA2] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatPVRTC_RGB4] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatPVRTC_RGBA4] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatETC_RGB4] = QueryExtension("GL_OES_compressed_ETC1_RGB8_texture"); + supportsTextureFormat[kTexFormatATC_RGB4] = QueryExtension("GL_AMD_compressed_ATC_texture") || QueryExtension("GL_ATI_texture_compression_atitc"); + supportsTextureFormat[kTexFormatATC_RGBA8] = QueryExtension("GL_AMD_compressed_ATC_texture") || QueryExtension("GL_ATI_texture_compression_atitc"); + + supportsRenderTextureFormat[kRTFormatARGB32] = true; + + { + const bool supportsHalfRB = QueryExtension("GL_EXT_color_buffer_half_float"); + // if we dont have OES_texture_half_float we cant have half texture (only RB) + const bool supportsHalfRT = supportsHalfRB && QueryExtension("GL_OES_texture_half_float"); + const bool supportsRG = QueryExtension("GL_EXT_texture_rg"); + + supportsRenderTextureFormat[kRTFormatARGBHalf] = supportsHalfRT; + supportsRenderTextureFormat[kRTFormatR8] = supportsRG; + supportsRenderTextureFormat[kRTFormatRHalf] = supportsHalfRT && supportsRG; + supportsRenderTextureFormat[kRTFormatRGHalf] = supportsHalfRT && supportsRG; + } + + { + FBColorFormatCheckerGLES2 checker; + + supportsRenderTextureFormat[kRTFormatRGB565] = checker.CheckFormatSupported(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); + supportsRenderTextureFormat[kRTFormatARGB4444] = checker.CheckFormatSupported(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); + supportsRenderTextureFormat[kRTFormatARGB1555] = checker.CheckFormatSupported(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); + + // for float formats there is no ext to check rif they are renderable, so do manually + if(QueryExtension("OES_texture_float")) + { + supportsRenderTextureFormat[kRTFormatARGBHalf] = checker.CheckFormatSupported(GL_RGBA, GL_RGBA, GL_FLOAT); + if(QueryExtension("GL_EXT_texture_rg")) + { + // TODO: move all this unity gles ext header + supportsRenderTextureFormat[kRTFormatRFloat] = checker.CheckFormatSupported(0x1903, 0x1903, GL_FLOAT); + supportsRenderTextureFormat[kRTFormatRGFloat] = checker.CheckFormatSupported(0x8227, 0x8227, GL_FLOAT); + } + } + } + + const bool isPvrGpu = (rendererString.find("PowerVR") != string::npos); + const bool isMaliGpu = (rendererString.find("Mali") != string::npos); + const bool isAdrenoGpu = (rendererString.find("Adreno") != string::npos); + const bool isTegraGpu = (rendererString.find("Tegra") != string::npos); + + // Only support stencil when we have packed depth stencil, for simplicity + hasStencil = hasTwoSidedStencil = hasRenderTargetStencil = QueryExtension("GL_OES_packed_depth_stencil"); + +#if UNITY_BB10 + if(isAdrenoGpu) + hasRenderTargetStencil = false; +#endif + + // Adreno 2xx seems to not like a texture attached to color & depth & stencil at once; + // Adreno 3xx seems to be fine. Most 3xx devices have GL_OES_depth_texture_cube_map extension + // present, and 2xx do not. So detect based on that. + const bool isAdreno2xx = isAdrenoGpu && !QueryExtension("GL_OES_depth_texture_cube_map"); + if (isAdreno2xx) + hasRenderTargetStencil = false; + + hasNativeDepthTexture = QueryExtension("GL_OES_depth_texture") || QueryExtension ("GL_GOOGLE_depth_texture"); +#if UNITY_ANDROID + if(android::systeminfo::ApiLevel() < android::apiHoneycomb || (android::systeminfo::ApiLevel() < android::apiIceCreamSandwich && isPvrGpu)) + hasNativeDepthTexture = false; +#endif + + hasStencilInDepthTexture = hasRenderTargetStencil && hasNativeDepthTexture; + gles20.has24DepthForFBO = QueryExtension("GL_OES_depth24"); + + hasNativeShadowMap = QueryExtension("GL_EXT_shadow_samplers"); + + supportsRenderTextureFormat[kRTFormatA2R10G10B10] = false; + supportsRenderTextureFormat[kRTFormatARGB64] = false; + supportsRenderTextureFormat[kRTFormatDepth] = hasNativeDepthTexture; + supportsRenderTextureFormat[kRTFormatShadowMap] = hasNativeShadowMap; + + + has16BitFloatVertex = QueryExtension("GL_OES_vertex_half_float"); + needsToSwizzleVertexColors = false; + + // ---- driver bug/workaround flags + +#if UNITY_LINUX + if(isTegraGpu) + { + supportsRenderTextureFormat[kRTFormatDepth] = hasNativeDepthTexture = true; + hasRenderTargetStencil = true; + hasStencilInDepthTexture = true; + hasTwoSidedStencil = true; + } +#endif + + hasSRGBReadWrite = QueryExtension("GL_EXT_sRGB"); + // TODO: we should check srgb+compressed on gpu-case basis, but for now it is tegra only anyway ;-) + hasSRGBReadWrite = hasSRGBReadWrite && QueryExtension("GL_NV_sRGB_formats"); + + disableSoftShadows = true; + + hasShadowCollectorPass = false; + + // ---- gles20 specifics + + gles20.hasGLSL = true; + gles20.maxAttributes = 16; + gles20.hasNLZ = QueryExtension("GL_NV_depth_nonlinear"); + gles20.hasAlphaTestQCOM = QueryExtension("GL_QCOM_alpha_test") && gGlesExtFunc.glAlphaFuncQCOM; + + gles20.hasMapbuffer = QueryExtension("GL_OES_mapbuffer") && gGlesExtFunc.glMapBufferOES && gGlesExtFunc.glUnmapBufferOES; + gles20.hasMapbufferRange= QueryExtension("GL_EXT_map_buffer_range") && gGlesExtFunc.glMapBufferRangeEXT && gGlesExtFunc.glUnmapBufferOES; + +#if UNITY_PEPPER + // it was cut out in ifdef before, so lets play safe and assume we dont have map + gles20.hasMapbuffer = gles20.hasMapbufferRange = false; +#endif + + gles20.hasBinaryShaders = (UNITY_ANDROID || UNITY_BLACKBERRY || UNITY_TIZEN) && QueryExtension("GL_OES_get_program_binary") && GlslGpuProgramGLES20::InitBinaryShadersSupport(); + + gles20.hasNVMRT = QueryExtension("GL_NV_draw_buffers") && QueryExtension("GL_NV_fbo_color_attachments") && gGlesExtFunc.glDrawBuffersNV; + if(gles20.hasNVMRT) + { + GLES_CHK(glGetIntegerv(GL_MAX_DRAW_BUFFERS_NV, &maxMRTs)); + maxMRTs = clamp<int> (maxMRTs, 1, kMaxSupportedRenderTargets); + } + +#if UNITY_IPHONE + if( iphone::GetDeviceGeneration() == iphone::kiPhoneGenerationiPad2Gen && iphone::isIOSVersionOrNewerButBefore("4.3", "5.0") ) + gles20.buggyColorMaskBlendMSAA = true; +#endif + +#if UNITY_ANDROID || UNITY_BB10 + // Adreno (Qualcomm chipsets) have a driver bug (Android2.2) + // which fails to patch vfetch instructions under certain circumstances + gles20.buggyVFetchPatching = isAdrenoGpu; +#endif + + // Mali-400 MP? They promised to fix drivers (they know about the issue) + gles20.buggyDisableVAttrKeepsActive = isMaliGpu; + +#if UNITY_ANDROID + // samsung galaxy on mali + ics update ruined shader compiler + // most osam part: on some shaders tex sample in vprog result in crash close to kernel (no callstack in logcat) + gles20.buggyVprogTextures = isMaliGpu && (android::systeminfo::ApiLevel() >= android::apiIceCreamSandwich); +#endif + + // on android pvr if we enable dynamic geom drawing from memory sometimes we hit crash in the driver + // it seems that some internal caching goes crazy - solved by actually drawing watermark + // This is also needed on BB10 devices (both pvr and adreno) to fix video display issues + gles20.needToRenderWatermarkDueToDrawFromMemoryBuggy = (UNITY_ANDROID && isPvrGpu) || UNITY_BB10; + + // PowerVR GPUs have slow discard + gles20.slowAlphaTest = isPvrGpu; + + // on adreno devices drivers don't like if+discard combo + // so set slowAlphaTest here too, to remove trivial clip + gles20.slowAlphaTest |= isAdrenoGpu; + + // orphaning path is terribly slower universally + // apart from some corner cases on ios where it is not faster anyway + gles20.hasVBOOrphaning = false; + + gles20.hasDebugMarkers = QueryExtension("GL_EXT_debug_marker") && gGlesExtFunc.glPushGroupMarkerEXT && gGlesExtFunc.glPopGroupMarkerEXT; + gles20.hasDiscardFramebuffer = QueryExtension("GL_EXT_discard_framebuffer") && gGlesExtFunc.glDiscardFramebufferEXT; + gles20.hasHalfLinearFilter = QueryExtension("GL_OES_texture_half_float_linear"); + + + gles20.slowDynamicVBO = isPvrGpu || isAdrenoGpu || isMaliGpu; + gles20.forceStaticBatchFromMem = isMaliGpu; +#if UNITY_IPHONE + gles20.forceStaticBatchFromMem = true; +#endif + gles20.needFlushAfterTextureUpload = isAdrenoGpu; + + gles20.needFlushAfterTextureUpload = isAdrenoGpu; + + hasTiledGPU = isPvrGpu || isAdrenoGpu || isMaliGpu; + + // on Tegra (for now all drivers) there is a bug that sometimes results in samplers not being reported + // the only known workaround is to force highp default precision + gles20.forceHighpFSPrec = isTegraGpu; + + // on Adreno (Nexus4 at least) there is a bug that sometimes results in program link crash + // the only known workaround is to force highp default precision + gles20.forceHighpFSPrec = isAdrenoGpu; + + + GLES_CHK(glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &gles20.maxAttributes)); + GLES_CHK(glGetIntegerv(GL_MAX_VARYING_VECTORS, &gles20.maxVaryings)); + + if(gles20.hasAppleMSAA) + GLES_CHK(glGetIntegerv(GL_MAX_SAMPLES_APPLE, &gles20.maxSamples)); + if(gles20.hasImgMSAA) + GLES_CHK(glGetIntegerv(GL_MAX_SAMPLES_IMG, &gles20.maxSamples)); + +#if ENABLE_PROFILER + g_TimerQueriesGLES.Init(); +#endif +#if NV_STATE_FILTERING + filteredInitGLES20(); +#endif +} + +//chai: extern º¯Êý +GfxDevice* CreateGLES20GfxDevice() +{ +#if UNITY_WIN || UNITY_LINUX || UNITY_BB10 || UNITY_TIZEN || UNITY_ANDROID + InitializeGLES20(); +#endif + gGraphicsCaps.InitGLES20(); +#if UNITY_EDITOR + return NULL; +#else + return UNITY_NEW_AS_ROOT(GFX_GL_IMPL(), kMemGfxDevice, "GLES20GfxDevice",""); +#endif +} + +GFX_GL_IMPL::GFX_GL_IMPL() +{ + ;;printf_console("Creating OpenGLES2.0 graphics device\n"); + #if !GFX_DEVICE_VIRTUAL + impl = new GfxDeviceImpl(); + #endif + + // ??? ReJ: (Q for Tomas) WHY InvalidateState was commented out here? InvalidateState is necessary to enable correct back-face culling + OnCreate(); + InvalidateState(); +#if UNITY_PEPPER || UNITY_WEBGL + m_Renderer = kGfxRendererOpenGLES20Desktop; +#else + m_Renderer = kGfxRendererOpenGLES20Mobile; +#endif + m_IsThreadable = true; + + m_UsesOpenGLTextureCoords = true; + m_UsesHalfTexelOffset = false; + + STATE.m_CurrBlendState = NULL; + STATE.m_CurrDepthState = NULL; + STATE.m_CurrStencilState = NULL; + STATE.m_CurrRasterState = NULL; + STATE.m_SharedFBO = STATE.m_HelperFBO = 0; + + InitBackBufferGLES2(&m_BackBufferColor.object, &m_BackBufferDepth.object); +} + +GFX_GL_IMPL::~GFX_GL_IMPL() +{ + delete STATE.m_DynamicVBO; + + #if !GFX_DEVICE_VIRTUAL + delete impl; + #endif +#if UNITY_WIN || UNITY_ANDROID + ShutdownGLES20(); +#endif +} + + +static void ActivateTextureUnitGLES2 (DeviceStateGLES20& state, int unit) +{ + if (state.activeTextureUnit == unit) + return; + GLES_CHK(glActiveTexture(GL_TEXTURE0 + unit)); + state.activeTextureUnit = unit; +} + + +void GFX_GL_IMPL::InvalidateState() +{ + DBG_LOG_GLES20("InvalidateState"); + m_FogParams.Invalidate(); + STATE.transformState.Invalidate(m_BuiltinParamValues); + STATE.Invalidate(); + +#if NV_STATE_FILTERING + StateFiltering_InvalidateVBOCacheGLES20(); +#endif + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatEmission, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatAmbient, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatDiffuse, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatSpecular, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatShininess, Vector4f(1,1,1,1)); + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogColor, Vector4f(0,0,0,0)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogParams, Vector4f(0,0,0,0)); + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFAlphaTestRef, Vector4f(0,0,0,0)); + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFColor, Vector4f(1,1,1,1)); + for (int i = 0; i < kMaxSupportedTextureUnitsGLES; i++) + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecFFTextureEnvColor0+i), Vector4f(0,0,0,0)); +} + + + +DeviceBlendState* GFX_GL_IMPL::CreateBlendState(const GfxBlendState& state) +{ + std::pair<CachedBlendStates::iterator, bool> result = STATE.m_CachedBlendStates.insert(std::make_pair(state, DeviceBlendState())); + if (!result.second) + return &result.first->second; + + DeviceBlendState& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(glstate.sourceState)); + DebugAssertIf(kFuncUnknown==state.alphaTest); + + return &result.first->second; +} + + +DeviceDepthState* GFX_GL_IMPL::CreateDepthState(const GfxDepthState& state) +{ + std::pair<CachedDepthStates::iterator, bool> result = STATE.m_CachedDepthStates.insert(std::make_pair(state, DeviceDepthStateGLES20())); + if (!result.second) + return &result.first->second; + + DeviceDepthStateGLES20& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(glstate.sourceState)); + glstate.depthFunc = kCmpFuncES2[state.depthFunc]; + return &result.first->second; +} + +DeviceStencilState* GFX_GL_IMPL::CreateStencilState(const GfxStencilState& state) +{ + std::pair<CachedStencilStates::iterator, bool> result = STATE.m_CachedStencilStates.insert(std::make_pair(state, DeviceStencilStateGLES20())); + if (!result.second) + return &result.first->second; + + DeviceStencilStateGLES20& st = result.first->second; + memcpy (&st.sourceState, &state, sizeof(st.sourceState)); + st.stencilFuncFront = kCmpFuncES2[state.stencilFuncFront]; + st.stencilFailOpFront = kStencilOpES2[state.stencilFailOpFront]; + st.depthFailOpFront = kStencilOpES2[state.stencilZFailOpFront]; + st.depthPassOpFront = kStencilOpES2[state.stencilPassOpFront]; + st.stencilFuncBack = kCmpFuncES2[state.stencilFuncBack]; + st.stencilFailOpBack = kStencilOpES2[state.stencilFailOpBack]; + st.depthFailOpBack = kStencilOpES2[state.stencilZFailOpBack]; + st.depthPassOpBack = kStencilOpES2[state.stencilPassOpBack]; + return &result.first->second; +} + +DeviceRasterState* GFX_GL_IMPL::CreateRasterState(const GfxRasterState& state) +{ + std::pair<CachedRasterStates::iterator, bool> result = STATE.m_CachedRasterStates.insert(std::make_pair(state, DeviceRasterState())); + if (!result.second) + return &result.first->second; + + DeviceRasterState& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(glstate.sourceState)); + + return &result.first->second; +} + +void GFX_GL_IMPL::SetBlendState(const DeviceBlendState* state, float alphaRef) +{ + DeviceBlendState* devstate = (DeviceBlendState*)state; + + if (STATE.m_CurrBlendState == devstate && alphaRef == STATE.alphaValue) + return; + + STATE.m_CurrBlendState = devstate; + if (!STATE.m_CurrBlendState) + return; + + const GfxBlendState& desc = state->sourceState; + const GLenum glsrc = kBlendModeES2[desc.srcBlend]; + const GLenum gldst = kBlendModeES2[desc.dstBlend]; + const GLenum glsrca = kBlendModeES2[desc.srcBlendAlpha]; + const GLenum gldsta = kBlendModeES2[desc.dstBlendAlpha]; + const GLenum glfunc = kBlendFuncES2[desc.blendOp]; + const GLenum glfunca = kBlendFuncES2[desc.blendOpAlpha]; + const bool blendDisabled = (glsrc == GL_ONE && gldst == GL_ZERO && glsrca == GL_ONE && gldsta == GL_ZERO); + + int mask = devstate->sourceState.renderTargetWriteMask; + + if (!IsActiveRenderTargetWithColorGLES2()) + mask = 0; + +#if UNITY_IPHONE + if( (mask && mask != 15) && gGraphicsCaps.gles20.buggyColorMaskBlendMSAA && !blendDisabled && IsActiveMSAARenderTargetGLES2() ) + mask = 15; +#endif + + if( mask != STATE.colorWriteMask ) + { + GLES_CHK(glColorMask( (mask & kColorWriteR) != 0, (mask & kColorWriteG) != 0, (mask & kColorWriteB) != 0, (mask & kColorWriteA) != 0 )); + STATE.colorWriteMask = mask; + } + + if( blendDisabled ) + { + if( STATE.blending != 0 ) + { + GLES_CHK(glDisable (GL_BLEND)); + STATE.blending = 0; + } + } + else + { + if( glsrc != STATE.srcBlend || gldst != STATE.destBlend || glsrca != STATE.srcBlendAlpha || gldsta != STATE.destBlendAlpha ) + { + GLES_CHK(glBlendFuncSeparate(glsrc, gldst, glsrca, gldsta)); + STATE.srcBlend = glsrc; + STATE.destBlend = gldst; + STATE.srcBlendAlpha = glsrca; + STATE.destBlendAlpha = gldsta; + } + if (glfunc != STATE.blendOp || glfunca != STATE.blendOpAlpha) + { + bool supports = true; + if( (glfunc == GL_MIN_EXT || glfunc == GL_MAX_EXT) && !gGraphicsCaps.hasBlendMinMax ) + supports = false; + if( (glfunca == GL_MIN_EXT || glfunca == GL_MAX_EXT) && !gGraphicsCaps.hasBlendMinMax ) + supports = false; + + if(supports) + { + GLES_CHK(glBlendEquationSeparate(glfunc, glfunca)); + STATE.blendOp = glfunc; + STATE.blendOpAlpha = glfunca; + } + } + if( STATE.blending != 1 ) + { + GLES_CHK(glEnable( GL_BLEND )); + STATE.blending = 1; + } + } + // fragment shader is expected to implement per fragment culling + CompareFunction alphaTest = devstate->sourceState.alphaTest; + + if (gGraphicsCaps.gles20.slowAlphaTest) + { + // Alpha testing is slow on some GPUs + // skip trivial cases such as (alpha > 0) + if (alphaTest == kFuncGreater && alphaRef <= 0.01) + alphaTest = kFuncDisabled; + } + + if( gGraphicsCaps.gles20.hasAlphaTestQCOM && (alphaTest != STATE.alphaTest || alphaRef != STATE.alphaValue) ) + { + if( alphaTest != kFuncDisabled ) + { + GLES_CHK(gGlesExtFunc.glAlphaFuncQCOM(kCmpFuncES2[alphaTest], alphaRef)); + GLES_CHK(glEnable(GL_ALPHA_TEST_QCOM)); + } + else + { + GLES_CHK(glDisable(GL_ALPHA_TEST_QCOM)); + } + } + + STATE.alphaTest = alphaTest; + STATE.alphaValue = alphaRef; +} + + +void GFX_GL_IMPL::SetRasterState(const DeviceRasterState* state) +{ + DeviceRasterState* devstate = (DeviceRasterState*)state; + if(!devstate) + { + STATE.m_CurrRasterState = NULL; + return; + } + + STATE.m_CurrRasterState = devstate; + + CullMode cull = devstate->sourceState.cullMode; + if( cull != STATE.culling ) + { + switch (cull) { + case kCullOff: + GLES_CHK(glDisable (GL_CULL_FACE)); + break; + case kCullFront: + GLES_CHK(glCullFace (GL_FRONT)); + GLES_CHK(glEnable (GL_CULL_FACE)); + break; + case kCullBack: + GLES_CHK(glCullFace (GL_BACK)); + GLES_CHK(glEnable (GL_CULL_FACE)); + break; + default: + break; + } + STATE.culling = cull; + } + + float zFactor = devstate->sourceState.slopeScaledDepthBias; + float zUnits = devstate->sourceState.depthBias; + if( zFactor != STATE.offsetFactor || zUnits != STATE.offsetUnits ) + { + +#if WORKAROUND_POLYGON_OFFSET + // on some androids polygon offset work the other way (positive push to viewer) + // so we tweak projection matrix to do offset + // also use available depth precision better (on Adreno for example fix bugs with z-fighting) + // Game Programming Gems Vol1 + // Eric Lengyel's "Tweaking a Vertex's Projected Depth Value" + // we use simplified formula: just smallest possible eps directly (multiplied by zUnits) + // we calculate eps for 16bit depth (good enough for larger depth) + // in projection matrix [2,2] = (f+n)/(n-f) + // so eps would be BitsMult * -1/proj[2,2] + + static const float _BitsMult = -1.0f / (float)0xFFFF; // FFFF = 2^16-1, minus sign incorporated here + + float* matrixElem = &m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj).Get(2,2); + + const float eps = _BitsMult / *matrixElem; + *matrixElem *= (1.0f + zUnits*eps); +#else + GLES_CHK(glPolygonOffset( zFactor, zUnits )); + if( zFactor || zUnits ) + GLES_CHK(glEnable (GL_POLYGON_OFFSET_FILL)); + else + GLES_CHK(glDisable (GL_POLYGON_OFFSET_FILL)); +#endif + STATE.offsetFactor = zFactor; + STATE.offsetUnits = zUnits; + } +} + + +void GFX_GL_IMPL::SetDepthState(const DeviceDepthState* state) +{ + DeviceDepthStateGLES20* devstate = (DeviceDepthStateGLES20*)state; + if (STATE.m_CurrDepthState == devstate) + return; + + STATE.m_CurrDepthState = devstate; + + if (!STATE.m_CurrDepthState) + return; + + const int depthFunc = devstate->depthFunc; + if( depthFunc != STATE.depthFunc ) + { + if( depthFunc != GL_NEVER ) { + GLES_CHK(glDepthFunc (depthFunc)); + GLES_CHK(glEnable (GL_DEPTH_TEST)); + } else { + GLES_CHK(glDisable (GL_DEPTH_TEST)); + } + + STATE.depthFunc = depthFunc; + } + + const int writeMode = devstate->sourceState.depthWrite ? GL_TRUE : GL_FALSE; + if( writeMode != STATE.depthWrite ) + { + GLES_CHK(glDepthMask (writeMode)); + STATE.depthWrite = writeMode; + } +} + +void GFX_GL_IMPL::SetStencilState (const DeviceStencilState* state, int stencilRef) +{ + if (STATE.m_CurrStencilState == state && STATE.m_StencilRef == stencilRef) + return; + const DeviceStencilStateGLES20* st = static_cast<const DeviceStencilStateGLES20*>(state); + STATE.m_CurrStencilState = st; + if (!st) + return; + + if (st->sourceState.stencilEnable) + GLES_CHK(glEnable (GL_STENCIL_TEST)); + else + GLES_CHK(glDisable (GL_STENCIL_TEST)); + if (gGraphicsCaps.hasTwoSidedStencil) + { + GLES_CHK(glStencilFuncSeparate (GL_FRONT, st->stencilFuncFront, stencilRef, st->sourceState.readMask)); + GLES_CHK(glStencilOpSeparate (GL_FRONT, st->stencilFailOpFront, st->depthFailOpFront, st->depthPassOpFront)); + GLES_CHK(glStencilFuncSeparate (GL_BACK, st->stencilFuncBack, stencilRef, st->sourceState.readMask)); + GLES_CHK(glStencilOpSeparate (GL_BACK, st->stencilFailOpBack, st->depthFailOpBack, st->depthPassOpBack)); + } + else + { + GLES_CHK(glStencilFunc (st->stencilFuncFront, stencilRef, st->sourceState.readMask)); + GLES_CHK(glStencilOp (st->stencilFailOpFront, st->depthFailOpFront, st->depthPassOpFront)); + } + GLES_CHK(glStencilMask (st->sourceState.writeMask)); + + STATE.m_StencilRef = stencilRef; +} + +void GFX_GL_IMPL::SetSRGBWrite (bool enable) +{ +} + +bool GFX_GL_IMPL::GetSRGBWrite () +{ + return false; +} + +void GFX_GL_IMPL::Clear (UInt32 clearFlags, const float color[4], float depth, int stencil) +{ + DBG_LOG_GLES20("Clear(%d, (%.2f, %.2f, %.2f, %.2f), %.2f, %d", clearFlags, color[0], color[1], color[2], color[3], depth, stencil); + + EnsureDefaultFBInitedGLES2(); + + if (!IsActiveRenderTargetWithColorGLES2()) + clearFlags &= ~kGfxClearColor; + + float clearColorAlpha = color[3]; + + // In OpenGL, clears are affected by color write mask and depth writing parameters. + // So make sure to set them! + GLbitfield flags = 0; + if (clearFlags & kGfxClearColor) + { + if (STATE.colorWriteMask != 15) + { + GLES_CHK(glColorMask( true, true, true, true )); + STATE.colorWriteMask = 15; + STATE.m_CurrBlendState = NULL; + } + flags |= GL_COLOR_BUFFER_BIT; + GLES_CHK(glClearColor( color[0], color[1], color[2], clearColorAlpha )); + } + if (clearFlags & kGfxClearDepth) + { + GLES_CHK(glDepthMask (GL_TRUE)); + STATE.depthWrite = GL_TRUE; + STATE.m_CurrDepthState = NULL; + flags |= GL_DEPTH_BUFFER_BIT; + GLES_CHK(glClearDepthf( depth )); + } + if (clearFlags & kGfxClearStencil) + { + //@TODO: need to set stencil writes on? + flags |= GL_STENCIL_BUFFER_BIT; + GLES_CHK(glClearStencil (stencil)); + } + GLES_CHK(glClear(flags)); +} + +static void ApplyBackfaceMode( const DeviceStateGLES20& state ) +{ + DBG_LOG_GLES20("ApplyBackfaceMode"); + if (state.appBackfaceMode != state.userBackfaceMode) + GLES_CHK(glFrontFace( GL_CCW )); + else + GLES_CHK(glFrontFace( GL_CW )); +} + + +void GFX_GL_IMPL::SetUserBackfaceMode( bool enable ) +{ + DBG_LOG_GLES20("SetUserBackfaceMode(%s)", GetBoolString(enable)); + if( STATE.userBackfaceMode == enable ) + return; + + STATE.userBackfaceMode = enable; + ApplyBackfaceMode( STATE ); +} + +void GFX_GL_IMPL::SetInvertProjectionMatrix( bool enable ) +{ + Assert (!enable); // projection should never be flipped upside down on OpenGL +} + +bool GFX_GL_IMPL::GetInvertProjectionMatrix() const +{ + return false; +} + +void GFX_GL_IMPL::SetProjectionMatrix (const Matrix4x4f& matrix) +{ + DBG_LOG_GLES20("SetProjectionMatrix(...)"); + + CopyMatrix(matrix.GetPtr(), STATE.transformState.projectionMatrixOriginal.GetPtr()); + CopyMatrix (matrix.GetPtr(), m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj).GetPtr()); + STATE.transformState.dirtyFlags |= TransformState::kProjDirty; +} + + +void GFX_GL_IMPL::SetWorldMatrix( const float matrix[16] ) +{ + CopyMatrix( matrix, STATE.transformState.worldMatrix.GetPtr() ); + STATE.transformState.dirtyFlags |= TransformState::kWorldDirty; +} + +void GFX_GL_IMPL::SetViewMatrix( const float matrix[16] ) +{ + STATE.transformState.SetViewMatrix (matrix, m_BuiltinParamValues); +} + + +void GFX_GL_IMPL::GetMatrix( float outMatrix[16] ) const +{ + STATE.transformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + CopyMatrix (STATE.transformState.worldViewMatrix.GetPtr(), outMatrix); +} + +const float* GFX_GL_IMPL::GetWorldMatrix() const +{ + return STATE.transformState.worldMatrix.GetPtr(); +} + +const float* GFX_GL_IMPL::GetViewMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatView).GetPtr(); +} + +const float* GFX_GL_IMPL::GetProjectionMatrix() const +{ + return STATE.transformState.projectionMatrixOriginal.GetPtr(); +} + +const float* GFX_GL_IMPL::GetDeviceProjectionMatrix() const +{ + return GetProjectionMatrix(); +} + +void GFX_GL_IMPL::SetNormalizationBackface( NormalizationMode mode, bool backface ) +{ + DBG_LOG_GLES20("SetNormalizationBackface(%d %s)", mode, backface?"back":"front"); + STATE.normalization = mode; + if( STATE.appBackfaceMode != backface ) + { + STATE.appBackfaceMode = backface; + ApplyBackfaceMode( STATE ); + } +} + +void GFX_GL_IMPL::SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) +{ + DBG_LOG_GLES20("SetFFLighting(%s, %s, %d)", on?"True":"False", separateSpecular?"True":"False", colorMaterial); + STATE.lighting = on; + STATE.separateSpecular = separateSpecular; + STATE.colorMaterial = colorMaterial; +} + +void GFX_GL_IMPL::SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) +{ + DBG_LOG_GLES20("SetMaterial()"); + STATE.matAmbient.set (ambient[0], ambient[1], ambient[2], 1.0F); + STATE.matDiffuse.set (diffuse); + STATE.matSpecular.set (specular[0], specular[1], specular[2], 1.0F); + STATE.matEmissive.set (emissive[0], emissive[1], emissive[2], 1.0F); + float glshine = std::max<float>(std::min<float>(shininess,1.0f), 0.0f) * 128.0f; + STATE.matShininess = glshine; +} + + +void GFX_GL_IMPL::SetColor( const float color[4] ) +{ + DBG_LOG_GLES20("SetColor()"); + STATE.color.set( color ); + // Emulate OpenGL's behaviour + ImmediateColor( color[0], color[1], color[2], color[3] ); +} + +void GFX_GL_IMPL::SetViewport( int x, int y, int width, int height ) +{ + DBG_LOG_GLES20("SetViewport(%d, %d, %d, %d)", x, y, width, height); + STATE.viewport[0] = x; + STATE.viewport[1] = y; + STATE.viewport[2] = width; + STATE.viewport[3] = height; + GLES_CHK(glViewport( x, y, width, height )); +} + +void GFX_GL_IMPL::GetViewport( int* port ) const +{ + DBG_LOG_GLES20("GetViewport()"); + port[0] = STATE.viewport[0]; + port[1] = STATE.viewport[1]; + port[2] = STATE.viewport[2]; + port[3] = STATE.viewport[3]; +} + + + +void GFX_GL_IMPL::SetScissorRect( int x, int y, int width, int height ) +{ + DBG_LOG_GLES20("SetScissorRect(%d, %d, %d, %d)", x, y, width, height); + if (STATE.scissor != 1) + { + GLES_CHK(glEnable( GL_SCISSOR_TEST )); + STATE.scissor = 1; + } + + + STATE.scissorRect[0] = x; + STATE.scissorRect[1] = y; + STATE.scissorRect[2] = width; + STATE.scissorRect[3] = height; + GLES_CHK(glScissor( x, y, width, height )); + +} + +bool GFX_GL_IMPL::IsCombineModeSupported( unsigned int combiner ) +{ + return true; +} + +void GFX_GL_IMPL::DisableScissor() +{ + DBG_LOG_GLES20("DisableScissor()"); + if (STATE.scissor != 0) + { + GLES_CHK(glDisable( GL_SCISSOR_TEST )); + STATE.scissor = 0; + } +} + +bool GFX_GL_IMPL::IsScissorEnabled() const +{ + DBG_LOG_GLES20("IsScissorEnabled():returns %s", STATE.scissor == 1?"True":"False"); + return STATE.scissor == 1; +} + +void GFX_GL_IMPL::GetScissorRect( int scissor[4] ) const +{ + DBG_LOG_GLES20("GetScissorRect()"); + scissor[0] = STATE.scissorRect[0]; + scissor[1] = STATE.scissorRect[1]; + scissor[2] = STATE.scissorRect[2]; + scissor[3] = STATE.scissorRect[3]; +} + +TextureCombinersHandle GFX_GL_IMPL::CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) +{ + DBG_LOG_GLES20("CreateTextureCombiners()"); + TextureCombinersGLES2* implGLES = TextureCombinersGLES2::Create (count, texEnvs); + return TextureCombinersHandle (implGLES); +} + + +void GFX_GL_IMPL::SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ) +{ + DBG_LOG_GLES20("SetTextureCombiners()"); + TextureCombinersGLES2* implGLES = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersGLES2); + Assert (implGLES); + + const int count = std::min(gGraphicsCaps.maxTexUnits, implGLES->count); + STATE.textureCount = count; + for (int i = 0; i < count; ++i) + { + const ShaderLab::TextureBinding& binding = implGLES->texEnvs[i]; + + // set the texture + ApplyTexEnvData (i, i, texEnvData[i]); + + // setup texture unit state + TextureUnitStateGLES2& texUnitState = STATE.textures[i]; + texUnitState.color = texColors[i]; + texUnitState.combColor = binding.m_CombColor; + texUnitState.combAlpha = binding.m_CombAlpha; + } + // we can just create mask and "and" with it + // but consider me lazy + for( int i = count ; i < gGraphicsCaps.maxTexUnits ; ++i) + STATE.DropTexGen(i); + + STATE.activeProgram = 0; + + // Get us back to TU 0, so we know where we stand + ActivateTextureUnitGLES2 (STATE, 0); +} + +void GFX_GL_IMPL::DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ) +{ + DBG_LOG_GLES20("DeleteTextureCombiners()"); + TextureCombinersGLES2* implGLES = OBJECT_FROM_HANDLE(textureCombiners, TextureCombinersGLES2); + delete implGLES; + textureCombiners.Reset(); +} + +void GFX_GL_IMPL::SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ) +{ + DBG_LOG_GLES20("SetTextureCombiners()"); + TextureCombinersGLES2* implGLES = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersGLES2); + Assert (implGLES); + + const int count = std::min(gGraphicsCaps.maxTexUnits, implGLES->count); + // Fill in arrays + TexEnvData* texEnvData; + ALLOC_TEMP (texEnvData, TexEnvData, count); + for( int i = 0; i < count; ++i ) + { + ShaderLab::TexEnv *te = ShaderLab::GetTexEnvForBinding( implGLES->texEnvs[i], props ); + Assert( te != NULL ); + te->PrepareData (implGLES->texEnvs[i].m_TextureName.index, implGLES->texEnvs[i].m_MatrixName, props, &texEnvData[i]); + } + + Vector4f* texColors; + ALLOC_TEMP (texColors, Vector4f, implGLES->count); + for( int i = 0; i < implGLES->count; ++i ) + { + const ShaderLab::TextureBinding& binding = implGLES->texEnvs[i]; + texColors[i] = binding.GetTexColor().Get (props); + } + GFX_GL_IMPL::SetTextureCombinersThreadable(textureCombiners, texEnvData, texColors); +} + +void GFX_GL_IMPL::SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) +{ + DBG_LOG_GLES20("SetTexture(%d %d)", unit, texture.m_ID); + DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits ); + + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(texture); + if(targetTex == 0) + return; + + TextureUnitStateGLES2& currTex = STATE.textures[unit]; + if (STATE.textureCount > unit && targetTex == currTex.texID) + { + return; + } + ActivateTextureUnitGLES2 (STATE, unit); + + switch (dim) + { + case kTexDim2D: GLES_CHK(glBindTexture(GL_TEXTURE_2D, targetTex)); break; + case kTexDimCUBE: GLES_CHK(glBindTexture(GL_TEXTURE_CUBE_MAP, targetTex)); break; + default: break; + } + + if (STATE.textureCount <= unit) + STATE.textureCount = unit+1; + currTex.texID = targetTex; + currTex.texDim = dim; + if (currTex.texGen == kTexGenUnknown) + currTex.texGen = kTexGenDisabled; + + STATE.ApplyTexGen(unit); + + GLESAssert(); + + #if defined(GL_EXT_texture_lod_bias) && !UNITY_LINUX + if (gGraphicsCaps.hasMipLevelBias && unitState.bias != bias && bias != std::numeric_limits<float>::infinity()) + { + GL_CHK(glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, bias )); + unitState.bias = bias; + } + #endif +} + +void GFX_GL_IMPL::SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]) +{ + DBG_LOG_GLES20("SetTextureTransform()"); + DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits ); + TextureUnitStateGLES2& unitState = STATE.textures[unit]; + + unitState.SetTexGen(texGen); + unitState.textureMatrix = *(Matrix4x4f const*)matrix; + + // Since we will set texture matrix even if TexGen is disabled (since matrix can contain scale/offset information) + // we set textureMatrix to identity to be on a safe side + if (identity) + unitState.textureMatrix.SetIdentity(); + unitState.identityMatrix = identity; + + unitState.isProjected = false; + if (!identity && dim==kTexDim2D) + unitState.isProjected = (matrix[3] != 0.0f || matrix[7] != 0.0f || matrix[11] != 0.0f || matrix[15] != 1.0f); + + STATE.ApplyTexGen(unit); +} + +static const unsigned long kGLES20TextureDimensionTable[kTexDimCount] = {0, -1/*GL_TEXTURE_1D*/, GL_TEXTURE_2D, -1/*GL_TEXTURE_3D*/, GL_TEXTURE_CUBE_MAP, 0}; + +void GFX_GL_IMPL::SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + DBG_LOG_GLES20("SetTextureParams()"); + + TextureIdMapGLES20_QueryOrCreate(texture); + + GLuint target = kGLES20TextureDimensionTable[texDim]; + SetTexture (kShaderFragment, 0, 0, texture, texDim, std::numeric_limits<float>::infinity()); + + // Anisotropic texturing... + if( gGraphicsCaps.hasAnisoFilter ) + { + anisoLevel = std::min( anisoLevel, gGraphicsCaps.maxAnisoLevel ); + GLES_CHK(glTexParameteri( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoLevel )); + } + + GLenum wrapMode = kWrapModeES2[wrap]; + GLES_CHK(glTexParameteri( target, GL_TEXTURE_WRAP_S, wrapMode )); + GLES_CHK(glTexParameteri( target, GL_TEXTURE_WRAP_T, wrapMode )); + + if( !hasMipMap && filter == kTexFilterTrilinear ) + filter = kTexFilterBilinear; + + GLES_CHK(glTexParameteri( target, GL_TEXTURE_MAG_FILTER, filter != kTexFilterNearest ? GL_LINEAR : GL_NEAREST )); + if( hasMipMap ) + GLES_CHK(glTexParameteri( target, GL_TEXTURE_MIN_FILTER, kMinFilterES2[filter] )); + else + GLES_CHK(glTexParameteri (target, GL_TEXTURE_MIN_FILTER, filter != kTexFilterNearest ? GL_LINEAR : GL_NEAREST)); + + GLESAssert(); +} + +void GFX_GL_IMPL::SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]) +{ + DBG_LOG_GLES20("SetShadersThreadable()"); + GpuProgram* vertexProgram = programs[kShaderVertex]; + GpuProgram* fragmentProgram = programs[kShaderFragment]; + + DBG_LOG_GLES20("SetShaders(%s, %s)", + GetShaderImplTypeString(vertexProgram? vertexProgram->GetImplType():kShaderImplUndefined), + GetShaderImplTypeString(fragmentProgram? fragmentProgram->GetImplType():kShaderImplUndefined)); + + // GLSL is only supported like this: + // vertex shader actually is both vertex & fragment linked program + // fragment shader is unused + if (vertexProgram && vertexProgram->GetImplType() == kShaderImplBoth) + { + Assert(fragmentProgram == 0 || fragmentProgram->GetImplType() == kShaderImplBoth); + STATE.activeProgram = vertexProgram; + STATE.activeProgramParams = params[kShaderVertex]; + DebugAssert(STATE.activeProgramParams->IsReady()); + int bufferSize = STATE.activeProgramParams->GetValuesSize(); + STATE.activeProgramParamsBuffer.resize_uninitialized(bufferSize); + memcpy(STATE.activeProgramParamsBuffer.data(), paramsBuffer[kShaderVertex], bufferSize); + } + else + { + Assert(vertexProgram == 0); + STATE.activeProgram = 0; + STATE.activeProgramParams = 0; + STATE.activeProgramParamsBuffer.resize_uninitialized(0); + } +} + +void GFX_GL_IMPL::CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ) +{ + GlslGpuProgramGLES20& programGLES = static_cast<GlslGpuProgramGLES20&>(program->GetGpuProgram()); + programGLES.GetGLProgram(fogMode, program->GetParams(fogMode), program->GetChannels()); +} + +bool GFX_GL_IMPL::IsShaderActive( ShaderType type ) const +{ + //DBG_LOG_GLES20("IsShaderActive(%s): returns %s", GetShaderTypeString(type), STATE.shaderEnabledImpl[type] != kShaderImplUndefined?"True":"False"); + //return STATE.shaderEnabledImpl[type] != kShaderImplUndefined; + DBG_LOG_GLES20("IsShaderActive(%s):", GetShaderTypeString(type)); + return (STATE.activeProgram != 0); +} + +void GFX_GL_IMPL::DestroySubProgram( ShaderLab::SubProgram* subprogram ) +{ + //@TODO + //if (STATE.activeProgram == program) + //{ + // STATE.activeProgram = NULL; + // STATE.activeProgramProps = NULL; + //} + delete subprogram; +} + + + +void GFX_GL_IMPL::DisableLights( int startLight ) +{ + DBG_LOG_GLES20("DisableLights(%d)", startLight); + startLight = std::min (startLight, gGraphicsCaps.maxLights); + STATE.vertexLightCount = startLight; + for (int i = startLight; i < kMaxSupportedVertexLightsByGLES20; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Position + i), Vector4f(0.0f, 0.0f, 1.0f, 0.0f)); + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + i), Vector4f(0.0f, 0.0f, 0.0f, 0.0f)); + } +} + + +void GFX_GL_IMPL::SetLight( int light, const GfxVertexLight& data) +{ + DBG_LOG_GLES20("SetLight(%d), [{%f, %f, %f, %f}, {%f, %f, %f, %f}, {%f, %f, %f, %f}, %f, %f, %f, %d]", + light, + data.position[0], data.position[1], data.position[2], data.position[3], + data.spotDirection[0], data.spotDirection[1], data.spotDirection[2], data.spotDirection[3], + data.color[0], data.color[1], data.color[2], data.color[3], + data.range, data.quadAtten, data.spotAngle, data.type); + Assert( light >= 0 && light < kMaxSupportedVertexLights ); + + if (light >= kMaxSupportedVertexLightsByGLES20) + return; + + STATE.vertexLightTypes[light] = data.type; + + SetupVertexLightParams (light, data); +} + +void GFX_GL_IMPL::SetAmbient( const float ambient[4] ) +{ + DBG_LOG_GLES20("SetAmbient()"); + STATE.ambient.set (ambient[0], ambient[1], ambient[2], ambient[3]); + m_BuiltinParamValues.SetVectorParam(kShaderVecLightModelAmbient, Vector4f(ambient)); +} + +void GFX_GL_IMPL::EnableFog (const GfxFogParams& fog) +{ + DBG_LOG_GLES20("EnableFog()"); + DebugAssertIf( fog.mode <= kFogDisabled ); + m_FogParams = fog; +} + +void GFX_GL_IMPL::DisableFog() +{ + DBG_LOG_GLES20("DisableFog()"); + + if( m_FogParams.mode != kFogDisabled ) + { + m_FogParams.mode = kFogDisabled; + m_FogParams.density = 0.0f; + } +} + +VBO* GFX_GL_IMPL::CreateVBO() +{ + VBO* vbo = new GLES2VBO(); + OnCreateVBO(vbo); + return vbo; +} + +void GFX_GL_IMPL::DeleteVBO( VBO* vbo ) +{ + OnDeleteVBO(vbo); + delete vbo; +} + +DynamicVBO& GFX_GL_IMPL::GetDynamicVBO() +{ + if( !STATE.m_DynamicVBO ) { + STATE.m_DynamicVBO = new DynamicGLES2VBO(); + } + return *STATE.m_DynamicVBO; +} + +// ---------- render textures + +static GLuint GetFBO(GLuint* fbo) +{ + if (!(*fbo) && gGraphicsCaps.hasRenderToTexture) + glGenFramebuffers(1, fbo); + + return *fbo; +} +static GLuint GetSharedFBO (DeviceStateGLES20& state) { return GetFBO (&state.m_SharedFBO); } +static GLuint GetHelperFBO (DeviceStateGLES20& state) { return GetFBO (&state.m_HelperFBO); } + +RenderSurfaceHandle GFX_GL_IMPL::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) +{ + RenderSurfaceHandle rs = CreateRenderColorSurfaceGLES2 (textureID, 0, width, height, dim, createFlags, format, samples); +#if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); +#endif + return rs; +} +RenderSurfaceHandle GFX_GL_IMPL::CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) +{ + RenderSurfaceHandle rs = CreateRenderDepthSurfaceGLES2 (textureID, 0, width, height, createFlags, depthFormat, samples); +#if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); +#endif + return rs; +} +void GFX_GL_IMPL::DestroyRenderSurface (RenderSurfaceHandle& rs) +{ + // Early out if render surface is not created (don't do invalidate/flush in that case) + if( !rs.IsValid() ) + return; + + DestroyRenderSurfaceGLES2 (rs); + + InvalidateState(); +#if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); +#endif +} +void GFX_GL_IMPL::SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face) +{ +#if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); +#endif + if (SetRenderTargetGLES2 (count, colorHandles, depthHandle, mipLevel, face, GetSharedFBO(STATE))) + { + // changing render target might mean different color clear flags; so reset current state + STATE.m_CurrBlendState = NULL; + } +#if GFX_DEVICE_VERIFY_ENABLE + VerifyState(); +#endif +} + +void GFX_GL_IMPL::ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) +{ + ResolveColorSurfaceGLES2(srcHandle, dstHandle, GetSharedFBO(STATE), GetHelperFBO(STATE)); +} + +RenderSurfaceHandle GFX_GL_IMPL::GetActiveRenderColorSurface(int index) +{ + Assert (index == 0); + return GetActiveRenderColorSurfaceGLES2(); +} +RenderSurfaceHandle GFX_GL_IMPL::GetActiveRenderDepthSurface() +{ + return GetActiveRenderDepthSurfaceGLES2(); +} +void GFX_GL_IMPL::SetSurfaceFlags (RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags) +{ +} +void GFX_GL_IMPL::DiscardContents (RenderSurfaceHandle& rs) +{ + DiscardContentsGLES2(rs); +} + + +// ---------- uploading textures + +void GFX_GL_IMPL::UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + ::UploadTexture2DGLES2( texture, dimension, srcData, width, height, format, mipCount, uploadFlags, skipMipLevels, colorSpace ); +} + +void GFX_GL_IMPL::UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + ::UploadTextureSubData2DGLES2( texture, srcData, mipLevel, x, y, width, height, format, colorSpace ); +} + +void GFX_GL_IMPL::UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + ::UploadTextureCubeGLES2( texture, srcData, faceDataSize, size, format, mipCount, uploadFlags, colorSpace ); +} + +void GFX_GL_IMPL::UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + ErrorString("3D textures are not supported by OpenGLES!"); +} + +void GFX_GL_IMPL::DeleteTexture(TextureID texture) +{ + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(texture); + if(targetTex == 0) + return; + + REGISTER_EXTERNAL_GFX_DEALLOCATION(texture.m_ID); + GLES_CHK(glDeleteTextures(1, &targetTex)); + + // invalidate texture unit states that used this texture + for( int i = 0; i < gGraphicsCaps.maxTexUnits; ++i ) + { + TextureUnitStateGLES2& currTex = STATE.textures[i]; + if( currTex.texID == targetTex ) + currTex.Invalidate(); + } + + TextureIdMap::RemoveTexture(texture); +} + +// ---------- context + +GfxDevice::PresentMode GFX_GL_IMPL::GetPresentMode() +{ + return UNITY_IPHONE ? kPresentAfterDraw : kPresentBeforeUpdate; +} +void GFX_GL_IMPL::BeginFrame() +{ + DBG_LOG_GLES20("BeginFrame()"); + m_InsideFrame = true; + + if(gGraphicsCaps.hasTiledGPU) + { + SetBackBufferGLES2(); + + extern void ClearCurrentFBImpl(bool clearColor, bool clearDepth); + ClearCurrentFBImpl(true,true); + } +} +void GFX_GL_IMPL::EndFrame() +{ + // on ios we do it in trampoline + // also we handle BackBuffer MSAA and Render Resolution ourselves, so discard is a bit more complicated +#if !UNITY_IPHONE + if(gGraphicsCaps.gles20.hasDiscardFramebuffer) + { + SetBackBufferGLES2(); + + extern void DiscardCurrentFBImpl(bool discardColor, bool discardDepth, GLenum target); + DiscardCurrentFBImpl(false, true, GL_FRAMEBUFFER); + } +#endif + + + DBG_LOG_GLES20("EndFrame()"); + m_InsideFrame = false; +} + +bool GFX_GL_IMPL::IsValidState() +{ +#if UNITY_ANDROID + return ContextGLES::IsValid(); +#else + return true; +#endif +} + +bool GFX_GL_IMPL::HandleInvalidState() +{ +#if UNITY_ANDROID + bool needReload; + if (!ContextGLES::HandleInvalidState(&needReload)) + return false; + if (needReload) + ReloadResources(); + return true; +#else + return true; +#endif +} + +void GFX_GL_IMPL::PresentFrame() +{ + DBG_LOG_GLES20("===================================="); + DBG_LOG_GLES20("===================================="); + DBG_LOG_GLES20("PresentFrame"); + DBG_LOG_GLES20("===================================="); + DBG_LOG_GLES20("===================================="); + +#if UNITY_WIN + PresentContextGLES20(); +#else + PresentContextGLES(); +#endif +} + +void GFX_GL_IMPL::FinishRendering() +{ + GLES_CHK(glFinish()); +} + + +// ---------- immediate mode rendering + +// we break very large immediate mode submissions into multiple batches internally +const int kMaxImmediateVerticesPerDraw = 2048; + + +ImmediateModeGLES20::ImmediateModeGLES20() +: m_Mode(kPrimitiveTriangles) +, m_QuadsIB(0) +, m_IndexBufferQuadsID(0) +{ + m_QuadsIB = (UInt16*)UNITY_MALLOC(kMemGeometry, kMaxImmediateVerticesPerDraw*6*sizeof(UInt16)); + UInt32 baseIndex = 0; + UInt16* ibPtr = m_QuadsIB; + for( int i = 0; i < kMaxImmediateVerticesPerDraw; ++i ) + { + ibPtr[0] = baseIndex + 1; + ibPtr[1] = baseIndex + 2; + ibPtr[2] = baseIndex; + ibPtr[3] = baseIndex + 2; + ibPtr[4] = baseIndex + 3; + ibPtr[5] = baseIndex; + baseIndex += 4; + ibPtr += 6; + } +} + +ImmediateModeGLES20::~ImmediateModeGLES20() +{ + Invalidate(); + UNITY_FREE(kMemGeometry,m_QuadsIB); +} + +void ImmediateModeGLES20::Invalidate() +{ + if( m_IndexBufferQuadsID ) + { + glDeregisterBufferData(1, (GLuint*)&m_IndexBufferQuadsID); + GLES_CHK(glDeleteBuffers(1, (GLuint*)&m_IndexBufferQuadsID)); + m_IndexBufferQuadsID = 0; + } + m_Vertices.clear(); + memset( &m_Current, 0, sizeof(m_Current) ); +} + +void GFX_GL_IMPL::ImmediateVertex( float x, float y, float z ) +{ + // If the current batch is becoming too large, internally end it and begin it again. + size_t currentSize = STATE.m_Imm.m_Vertices.size(); + if( currentSize >= kMaxImmediateVerticesPerDraw - 4 ) + { + GfxPrimitiveType mode = STATE.m_Imm.m_Mode; + // For triangles, break batch when multiple of 3's is reached. + if( mode == kPrimitiveTriangles && currentSize % 3 == 0 ) + { + ImmediateEnd(); + ImmediateBegin( mode ); + } + // For other primitives, break on multiple of 4's. + // NOTE: This won't quite work for triangle strips, but we'll just pretend + // that will never happen. + else if( mode != kPrimitiveTriangles && currentSize % 4 == 0 ) + { + ImmediateEnd(); + ImmediateBegin( mode ); + } + } + Vector3f& vert = STATE.m_Imm.m_Current.vertex; + vert.x = x; + vert.y = y; + vert.z = z; + STATE.m_Imm.m_Vertices.push_back( STATE.m_Imm.m_Current ); +} + +void GFX_GL_IMPL::ImmediateNormal( float x, float y, float z ) +{ + STATE.m_Imm.m_Current.normal.x = x; + STATE.m_Imm.m_Current.normal.y = y; + STATE.m_Imm.m_Current.normal.z = z; +} + +void GFX_GL_IMPL::ImmediateColor( float r, float g, float b, float a ) +{ + r = clamp01(r); + g = clamp01(g); + b = clamp01(b); + a = clamp01(a); + + STATE.m_Imm.m_Current.color = + ((UInt32)(a * 255.0f) << 24) | + ((UInt32)(b * 255.0f) << 16) | + ((UInt32)(g * 255.0f) << 8) | + ((UInt32)(r * 255.0f)); +} + +void GFX_GL_IMPL::ImmediateTexCoordAll( float x, float y, float z ) +{ + for( int i = 0; i < gGraphicsCaps.maxTexCoords; ++i ) + { + Vector3f& uv = STATE.m_Imm.m_Current.texCoords[i]; + uv.x = x; + uv.y = y; + uv.z = z; + } +} + +void GFX_GL_IMPL::ImmediateTexCoord( int unit, float x, float y, float z ) +{ + if( unit < 0 || unit >= 8 ) + { + ErrorString( "Invalid unit for texcoord" ); + return; + } + Vector3f& uv = STATE.m_Imm.m_Current.texCoords[unit]; + uv.x = x; + uv.y = y; + uv.z = z; +} + +void GFX_GL_IMPL::ImmediateBegin( GfxPrimitiveType type ) +{ + STATE.m_Imm.m_Mode = type; + STATE.m_Imm.m_Vertices.clear(); +} + +void GFX_GL_IMPL::ImmediateEnd() +{ + int vertexCount = STATE.m_Imm.m_Vertices.size(); + if( vertexCount == 0 ) + return; + + InvalidateVertexInputCacheGLES20(); + + const size_t stride = sizeof(ImmediateVertexGLES20); + const ImmediateVertexGLES20* vertices = &STATE.m_Imm.m_Vertices[0]; + + void* dstVertices = LockSharedBufferGLES20 (GL_ARRAY_BUFFER, stride * vertexCount); + DebugAssert (dstVertices); + memcpy (dstVertices, vertices, stride * vertexCount); + + if(STATE.m_Imm.m_Mode == kPrimitiveQuads && !STATE.m_Imm.m_IndexBufferQuadsID) + { + GLES_CHK(glGenBuffers( 1, (GLuint*)&STATE.m_Imm.m_IndexBufferQuadsID)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, STATE.m_Imm.m_IndexBufferQuadsID)); + GLES_CHK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, kMaxImmediateVerticesPerDraw * 6, STATE.m_Imm.m_QuadsIB, GL_STATIC_DRAW)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } + + const GLuint vbo = UnlockSharedBufferGLES20 (); + const GLuint ibo = (STATE.m_Imm.m_Mode == kPrimitiveQuads)? STATE.m_Imm.m_IndexBufferQuadsID: 0; + + //;;printf_console("ImmediateEnd> vbo: %d ibo: %d\n", vbo, ibo); + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, vbo)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); + + size_t offset = 0; + if(gGraphicsCaps.gles20.slowDynamicVBO) + offset = (size_t)static_cast<DynamicGLES2VBO&> (GetRealGfxDevice ().GetDynamicVBO ()).GetVertexMemory(stride * vertexCount); + + GLES_CHK(glEnableVertexAttribArray(GL_VERTEX_ARRAY)); + //;;printf_console("ImmediateEnd> vertex %d\n", offset); + GLES_CHK(glVertexAttribPointer(GL_VERTEX_ARRAY, 3, GL_FLOAT, false, stride, (void*)offset)); offset += sizeof(Vector3f); + GLES_CHK(glEnableVertexAttribArray(GL_NORMAL_ARRAY)); + //;;printf_console("ImmediateEnd> normal %d\n", offset); + GLES_CHK(glVertexAttribPointer(GL_NORMAL_ARRAY, 3, GL_FLOAT, false, stride, (void*)offset)); offset += sizeof(Vector3f); + GLES_CHK(glEnableVertexAttribArray(GL_COLOR_ARRAY)); + //;;printf_console("ImmediateEnd> color %d\n", offset); + GLES_CHK(glVertexAttribPointer(GL_COLOR_ARRAY, 4, GL_UNSIGNED_BYTE, true, stride, (void*)offset)); offset += sizeof(UInt32); + for (size_t q = 0; q < gGraphicsCaps.maxTexUnits; ++q) + { + if (GL_TEXTURE_ARRAY0 + q < gGraphicsCaps.gles20.maxAttributes) + { + GLES_CHK(glEnableVertexAttribArray(GL_TEXTURE_ARRAY0 + q)); + //;;printf_console("ImmediateEnd> tex%d %d\n", q, offset); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY0 + q, 3, GL_FLOAT, false, stride, (void*)offset)); offset += sizeof(Vector3f); + } + else + { + #pragma message ("ToDo") + } + } + + if(!gGraphicsCaps.gles20.slowDynamicVBO) + { + DebugAssert (offset <= stride); + } + + BeforeDrawCall (true); + + //;;printf_console("ImmediateEnd> dip %d %d\n", STATE.m_Imm.m_Mode, vertexCount); + switch (STATE.m_Imm.m_Mode) + { + case kPrimitiveTriangles: + GLES_CHK(glDrawArrays(GL_TRIANGLES, 0, vertexCount)); + m_Stats.AddDrawCall( vertexCount / 3, vertexCount ); + break; + case kPrimitiveTriangleStripDeprecated: + GLES_CHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, vertexCount)); + m_Stats.AddDrawCall( vertexCount - 2, vertexCount ); + break; + case kPrimitiveQuads: + GLES_CHK(glDrawElements(GL_TRIANGLES, (vertexCount/2)*3, GL_UNSIGNED_SHORT, 0)); + m_Stats.AddDrawCall( vertexCount / 2, vertexCount ); + break; + case kPrimitiveLines: + GLES_CHK(glDrawArrays(GL_LINES, 0, vertexCount)); + m_Stats.AddDrawCall( vertexCount / 2, vertexCount ); + break; + default: + AssertString("ImmediateEnd: unknown draw mode"); + } + + // reset VBO bindings + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + InvalidateVertexInputCacheGLES20(); + + // clear vertices + STATE.m_Imm.m_Vertices.clear(); +} + +// ---------- readback path + +bool GFX_GL_IMPL::CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ) +{ + GLES_CHK(glReadPixels( left, bottom, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba32 )); + return true; +} + +bool GFX_GL_IMPL::ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) +{ + return ReadbackTextureGLES2(image, left, bottom, width, height, destX, destY, GetSharedFBO(STATE), GetHelperFBO(STATE)); +} +void GFX_GL_IMPL::GrabIntoRenderTexture( RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ) +{ + ::GrabIntoRenderTextureGLES2(rs, rd, x, y, width, height, GetSharedFBO(STATE), GetHelperFBO(STATE)); +} + + +#if ENABLE_PROFILER + + +void GFX_GL_IMPL::BeginProfileEvent(const char* name) +{ + if(gGraphicsCaps.gles20.hasDebugMarkers) + gGlesExtFunc.glPushGroupMarkerEXT(0, name); +} + +void GFX_GL_IMPL::EndProfileEvent() +{ + if(gGraphicsCaps.gles20.hasDebugMarkers) + gGlesExtFunc.glPopGroupMarkerEXT(); +} + +GfxTimerQuery* GFX_GL_IMPL::CreateTimerQuery() +{ + if( gGraphicsCaps.hasTimerQuery ) + return new TimerQueryGLES; + return NULL; +} + +void GFX_GL_IMPL::DeleteTimerQuery(GfxTimerQuery* query) +{ + delete query; +} + +void GFX_GL_IMPL::BeginTimerQueries() +{ + if( !gGraphicsCaps.hasTimerQuery ) + return; + + g_TimerQueriesGLES.BeginTimerQueries(); +} + +void GFX_GL_IMPL::EndTimerQueries() +{ + if( !gGraphicsCaps.hasTimerQuery ) + return; + + g_TimerQueriesGLES.EndTimerQueries(); +} +#endif // ENABLE_PROFILER + +typedef std::map<FixedFunctionStateGLES20, FixedFunctionProgramGLES20*, FullStateCompareGLES20> FFProgramCacheT; +typedef std::map<FixedFunctionStateGLES20, GLShaderID, VertexStateCompareGLES20> FFVertexProgramCacheT; +typedef std::map<FixedFunctionStateGLES20, GLShaderID, FragmentStateCompareGLES20> FFFragmentProgramCacheT; + +static FFProgramCacheT g_FixedFunctionProgramCache; +static FFVertexProgramCacheT g_FFVertexProgramCache; +static FFFragmentProgramCacheT g_FFFragmentProgramCache; + +void ClearFixedFunctionPrograms() +{ + for (FFVertexProgramCacheT::iterator it = g_FFVertexProgramCache.begin(); it != g_FFVertexProgramCache.end(); ++it) + { + GLES_CHK(glDeleteShader(it->second)); + } + g_FFVertexProgramCache.clear(); + for (FFFragmentProgramCacheT::iterator it = g_FFFragmentProgramCache.begin(); it != g_FFFragmentProgramCache.end(); ++it) + { + GLES_CHK(glDeleteShader(it->second)); + } + g_FFFragmentProgramCache.clear(); + + for(FFProgramCacheT::iterator i = g_FixedFunctionProgramCache.begin(); i != g_FixedFunctionProgramCache.end(); ++i) + { + delete i->second; + } + g_FixedFunctionProgramCache.clear(); + +} + +static const FixedFunctionProgramGLES20* GetFixedFunctionProgram(const FixedFunctionStateGLES20& state) +{ + FFProgramCacheT::const_iterator cachedProgIt = g_FixedFunctionProgramCache.find(state); + if (cachedProgIt != g_FixedFunctionProgramCache.end()) + return cachedProgIt->second; + + // Cache miss, create fixed function program + // NOTE: don't worry too much about performance of vertex/fragment maps + // shader building/compilation is crazy expensive anyway + FFVertexProgramCacheT::const_iterator vertexProgIt = g_FFVertexProgramCache.find(state); + FFFragmentProgramCacheT::const_iterator fragmentProgIt = g_FFFragmentProgramCache.find(state); + + GLShaderID vertexShader = (vertexProgIt != g_FFVertexProgramCache.end())? vertexProgIt->second: 0; + GLShaderID fragmentShader = (fragmentProgIt != g_FFFragmentProgramCache.end())? fragmentProgIt->second: 0; + + if (vertexShader == 0) + { + vertexShader = glCreateShader(GL_VERTEX_SHADER); + std::string src = BuildVertexShaderSourceGLES20(state); + const char* cStr = src.c_str(); + + DBG_SHADER_VERBOSE_GLES20("Compiling generated vertex shader"); + CompileGlslShader(vertexShader, kErrorCompileVertexShader, cStr); + GLESAssert(); + + g_FFVertexProgramCache[state] = vertexShader; + } + + if (fragmentShader == 0) + { + fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + std::string src = BuildFragmentShaderSourceGLES20(state); + const char* cStr = src.c_str(); + + DBG_SHADER_VERBOSE_GLES20("Compiling generated fragment shader"); + CompileGlslShader(fragmentShader, kErrorCompileFragShader, cStr); + GLESAssert(); + + g_FFFragmentProgramCache[state] = fragmentShader; + } + + DBG_SHADER_VERBOSE_GLES20("Creating and linking GLES program"); + FixedFunctionProgramGLES20* ffProg = new FixedFunctionProgramGLES20(vertexShader, fragmentShader); + g_FixedFunctionProgramCache[state] = ffProg; + + return ffProg; +} + +static bool ComputeTextureTransformMatrix(TextureUnitStateGLES2 const& tex, Matrix4x4f const& worldViewMatrix, Matrix4x4f const& worldMatrix, + Matrix4x4f& outMatrix) +{ + switch (tex.texGen) + { + case kTexGenDisabled: + // NOTE: although tex-gen can be disabled + // textureMatrix can contain UV scale/offset + // so we will set it + case kTexGenObject: + if (tex.identityMatrix) + { + outMatrix.SetIdentity(); + return false; + } + CopyMatrix(tex.textureMatrix.GetPtr(), outMatrix.GetPtr()); + break; + case kTexGenSphereMap: + { + float invScale = 1.0f / Magnitude (worldViewMatrix.GetAxisX()); + + Matrix4x4f scaleOffsetMatrix; + scaleOffsetMatrix.SetScale(Vector3f(0.5*invScale, 0.5*invScale, 0.0)); + scaleOffsetMatrix.SetPosition(Vector3f(0.5, 0.5, 0.0)); + + Matrix4x4f worldViewMatrixRotation = worldViewMatrix; + worldViewMatrixRotation.SetPosition(Vector3f::zero); + Matrix4x4f combo; + MultiplyMatrices4x4(&scaleOffsetMatrix, &worldViewMatrixRotation, &combo); + MultiplyMatrices4x4(&tex.textureMatrix, &combo, &outMatrix); + break; + } + case kTexGenEyeLinear: + MultiplyMatrices4x4(&tex.textureMatrix, &worldViewMatrix, &outMatrix); + break; + case kTexGenCubeNormal: + case kTexGenCubeReflect: + { + float invScale = 1.0f / Magnitude (worldMatrix.GetAxisX()); + CopyMatrix(worldViewMatrix.GetPtr(), outMatrix.GetPtr()); + outMatrix.Scale(Vector3f(invScale, invScale, invScale)); + outMatrix.SetPosition(Vector3f::zero); + break; + } + default: + ErrorString( Format("Unknown TexGen mode %d", tex.texGen) ); + } + return true; +} + +void VBOContainsColorGLES20(bool flag) +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + GetGLES20DeviceState(device).vboContainsColor = flag; +} + +//chai: glUseProgram +void GLSLUseProgramGLES20(UInt32 programID) +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + if (GetGLES20DeviceState(device).activeProgramID == programID) + { +#if UNITY_ANDROID || UNITY_BB10 || UNITY_TIZEN + if (gGraphicsCaps.gles20.buggyVFetchPatching) + { + // NOTE: Qualcomm driver (Android2.2) fails to re-patch vfetch instructions + // if shader stays the same, but vertex layout has been changed + // as a temporary workaround just reset the shader + GLES_CHK(glUseProgram (0)); // driver caches shaderid, so set to 0 first + GLES_CHK(glUseProgram (programID)); + return; + } +#endif + return; + } + +#if NV_STATE_FILTERING + GetGLES20DeviceState(device).transformState.dirtyFlags |= TransformState::kWorldViewProjDirty; +#endif + + GLES_CHK(glUseProgram (programID)); + GetGLES20DeviceState(device).activeProgramID = programID; +} + + +struct SetValuesFunctorES2 +{ + SetValuesFunctorES2(GfxDevice& device, UniformCacheGLES20* targetCache) : m_Device(device), m_TargetCache(targetCache) { } + GfxDevice& m_Device; + UniformCacheGLES20* m_TargetCache; + void SetVectorVal (ShaderParamType type, int index, const float* ptr, int cols) + { + switch(cols) { + case 1: CachedUniform1(m_TargetCache, type, index, ptr); break; + case 2: CachedUniform2(m_TargetCache, type, index, ptr); break; + case 3: CachedUniform3(m_TargetCache, type, index, ptr); break; + case 4: CachedUniform4(m_TargetCache, type, index, ptr); break; + } + } + void SetMatrixVal (int index, const Matrix4x4f* ptr, int rows) + { + DebugAssert(rows == 4); + GLES_CHK(glUniformMatrix4fv (index, 1, GL_FALSE, ptr->GetPtr())); + } + void SetTextureVal (ShaderType shaderType, int index, int samplerIndex, TextureDimension dim, TextureID texID) + { + m_Device.SetTexture (shaderType, index, samplerIndex, texID, dim, std::numeric_limits<float>::infinity()); + } +}; + + +//chai: ÉèÖÃshader uniforms +void GFX_GL_IMPL::BeforeDrawCall(bool immediateMode) +{ + DBG_LOG_GLES20("BeforeDrawCall(%s)", GetBoolString(immediateMode)); + + ShaderLab::PropertySheet *props = ShaderLab::g_GlobalProperties; + Assert(props); + + // WorldView Matrix +#if NV_STATE_FILTERING + // UpdateWorldViewMatrix will reset the dirty flags, however we want to forward any modified matrices + // to the shader, so we "reset" the dirty state after UpdateWorldViewMatrix has been called + UInt32 savedDirty = STATE.transformState.dirtyFlags; + STATE.transformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + STATE.transformState.dirtyFlags = savedDirty; +#else + STATE.transformState.UpdateWorldViewMatrix (m_BuiltinParamValues); +#endif + + // Materials + if (STATE.lighting) + { + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatEmission, Vector4f(STATE.matEmissive.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatAmbient, Vector4f(STATE.matAmbient.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatDiffuse, Vector4f(STATE.matDiffuse.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatSpecular, Vector4f(STATE.matSpecular.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatShininess, Vector4f(STATE.matShininess, STATE.matShininess, STATE.matShininess, STATE.matShininess)); + } + + // Fog + if (m_FogParams.mode > kFogDisabled) + { + float diff = m_FogParams.mode == kFogLinear ? m_FogParams.end - m_FogParams.start : 0.0f; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogColor, m_FogParams.color); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogParams, Vector4f(m_FogParams.density * 1.2011224087f, + m_FogParams.density * 1.4426950408f, + m_FogParams.mode == kFogLinear ? -invDiff : 0.0f, + m_FogParams.mode == kFogLinear ? m_FogParams.end * invDiff : 0.0f + )); + } + // Alpha-test + m_BuiltinParamValues.SetVectorParam(kShaderVecFFAlphaTestRef, Vector4f(STATE.alphaValue, STATE.alphaValue, STATE.alphaValue, STATE.alphaValue)); + + UniformCacheGLES20* targetCache = 0; + if (STATE.activeProgram) + { + //chai: glUseProgram + // + // Apply GPU program + //ת»»ÀàÐÍ + GlslGpuProgramGLES20& program = static_cast<GlslGpuProgramGLES20&>(*STATE.activeProgram); + int fogIndex = program.ApplyGpuProgramES20 (*STATE.activeProgramParams, STATE.activeProgramParamsBuffer.data()); + m_BuiltinParamIndices[kShaderVertex] = &STATE.activeProgramParams->GetBuiltinParams(); + + targetCache = &program.m_UniformCache[fogIndex]; + } + else + { + //chai:Ä£Äâ¹Ì¶¨¹ÜÏß + // Emulate Fixed Function pipe + m_BuiltinParamValues.SetVectorParam(kShaderVecFFColor, Vector4f(STATE.color.GetPtr())); + for (int i = 0; i < STATE.textureCount; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecFFTextureEnvColor0+i), STATE.textures[i].color); + } + + // generate program from fixed function state + DBG_LOG_GLES20(" using fixed-function"); + FixedFunctionStateGLES20 ffstate; + STATE.ComputeFixedFunctionState(ffstate, m_FogParams); + const FixedFunctionProgramGLES20* program = GetFixedFunctionProgram(ffstate); + program->ApplyFFGpuProgram(m_BuiltinParamValues); + m_BuiltinParamIndices[kShaderVertex] = &program->GetBuiltinParams(); + + targetCache = &program->m_UniformCache; + } + + //chai: ÉèÖÃUnityÄÚÖÃuniforms + + // Set Unity built-in parameters + { + Assert(m_BuiltinParamIndices[kShaderVertex]); + const BuiltinShaderParamIndices& params = *m_BuiltinParamIndices[kShaderVertex]; + + // MVP matrix + if (params.mat[kShaderInstanceMatMVP].gpuIndex >= 0 +#if NV_STATE_FILTERING + && (STATE.transformState.dirtyFlags & TransformState::kWorldViewProjDirty) +#endif + ) + { + Matrix4x4f wvp; + MultiplyMatrices4x4(&m_BuiltinParamValues.GetMatrixParam(kShaderMatProj), &STATE.transformState.worldViewMatrix, &wvp); + + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatMVP]; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, wvp.GetPtr())); + } + // MV matrix + if (params.mat[kShaderInstanceMatMV].gpuIndex >= 0 +#if NV_STATE_FILTERING + && (STATE.transformState.dirtyFlags & TransformState::kWorldViewDirty) +#endif + ) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatMV]; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, STATE.transformState.worldViewMatrix.GetPtr())); + } + // Transpose of MV matrix + if (params.mat[kShaderInstanceMatTransMV].gpuIndex >= 0 +#if NV_STATE_FILTERING + && (STATE.transformState.dirtyFlags & TransformState::kWorldViewDirty) +#endif + ) + { + Matrix4x4f tWV; + TransposeMatrix4x4(&STATE.transformState.worldViewMatrix, &tWV); + + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatTransMV]; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, tWV.GetPtr())); + } + // Inverse transpose of MV matrix + if (params.mat[kShaderInstanceMatInvTransMV].gpuIndex >= 0 +#if NV_STATE_FILTERING + && (STATE.transformState.dirtyFlags & TransformState::kWorldViewDirty) +#endif + ) + { + // Inverse transpose of modelview should be scaled by uniform + // normal scale (this will match state.matrix.invtrans.modelview + // and gl_NormalMatrix in OpenGL) + Matrix4x4f mat = STATE.transformState.worldViewMatrix; + if (STATE.normalization == kNormalizationScale) + { + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + mat.Get (0, 0) *= invScale; + mat.Get (1, 0) *= invScale; + mat.Get (2, 0) *= invScale; + mat.Get (0, 1) *= invScale; + mat.Get (1, 1) *= invScale; + mat.Get (2, 1) *= invScale; + mat.Get (0, 2) *= invScale; + mat.Get (1, 2) *= invScale; + mat.Get (2, 2) *= invScale; + } + Matrix4x4f invWV, tInvWV; + Matrix4x4f::Invert_General3D (mat, invWV); + TransposeMatrix4x4(&invWV, &tInvWV); + + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatInvTransMV]; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, tInvWV.GetPtr())); + } + // M matrix + if (params.mat[kShaderInstanceMatM].gpuIndex >= 0 +#if NV_STATE_FILTERING + && (STATE.transformState.dirtyFlags & TransformState::kWorldDirty) +#endif + ) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatM]; + const Matrix4x4f& mat = STATE.transformState.worldMatrix; + Assert(matParam.rows == 4 && matParam.cols == 4); + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, mat.GetPtr())); + } + // Inverse M matrix + if (params.mat[kShaderInstanceMatInvM].gpuIndex >= 0 +#if NV_STATE_FILTERING + && (STATE.transformState.dirtyFlags & TransformState::kWorldDirty) +#endif + ) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatInvM]; + Matrix4x4f mat = STATE.transformState.worldMatrix; + if (STATE.normalization == kNormalizationScale) + { + // Kill scale in the world matrix before inverse + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + mat.Get (0, 0) *= invScale; + mat.Get (1, 0) *= invScale; + mat.Get (2, 0) *= invScale; + mat.Get (0, 1) *= invScale; + mat.Get (1, 1) *= invScale; + mat.Get (2, 1) *= invScale; + mat.Get (0, 2) *= invScale; + mat.Get (1, 2) *= invScale; + mat.Get (2, 2) *= invScale; + } + Matrix4x4f inverseMat; + Matrix4x4f::Invert_General3D (mat, inverseMat); + Assert(matParam.rows == 4 && matParam.cols == 4); + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, inverseMat.GetPtr())); + } + + // Normal matrix + if (params.mat[kShaderInstanceMatNormalMatrix].gpuIndex >= 0 +#if NV_STATE_FILTERING + && (STATE.transformState.dirtyFlags & TransformState::kWorldViewDirty) +#endif + ) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatNormalMatrix]; + + // @TBD: remove normalization in fixed function emulation after Normal matrix multiply. + Matrix4x4f rotWV; + rotWV = STATE.transformState.worldViewMatrix; + rotWV.SetPosition(Vector3f::zero); // reset translation + + if (STATE.normalization == kNormalizationScale) // reset scale + { + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + rotWV.Get (0, 0) *= invScale; + rotWV.Get (1, 0) *= invScale; + rotWV.Get (2, 0) *= invScale; + rotWV.Get (0, 1) *= invScale; + rotWV.Get (1, 1) *= invScale; + rotWV.Get (2, 1) *= invScale; + rotWV.Get (0, 2) *= invScale; + rotWV.Get (1, 2) *= invScale; + rotWV.Get (2, 2) *= invScale; + } + Matrix3x3f rotWV33 = Matrix3x3f(rotWV); + + GLES_CHK(glUniformMatrix3fv (matParam.gpuIndex, 1, GL_FALSE, rotWV33.GetPtr())); + } + + + //chai: ÉèÖÃÏòÁ¿uniforms + // Set instance vector parameters + for (int i = 0; i < kShaderInstanceVecCount; ++i) + { + int gpuIndexVS = params.vec[i].gpuIndex; + if (gpuIndexVS >= 0) + { + const float* val = m_BuiltinParamValues.GetInstanceVectorParam((ShaderBuiltinInstanceVectorParam)i).GetPtr(); + switch (params.vec[i].dim) { + case 1: CachedUniform1(targetCache, kShaderParamFloat, gpuIndexVS, val); break; + case 2: CachedUniform2(targetCache, kShaderParamFloat, gpuIndexVS, val); break; + case 3: CachedUniform3(targetCache, kShaderParamFloat, gpuIndexVS, val); break; + case 4: CachedUniform4(targetCache, kShaderParamFloat, gpuIndexVS, val); break; + } + GLESAssert(); + } + } + + // Texture Matrices + Matrix4x4f texM; + for (int i = 0; i < kMaxSupportedTextureUnitsGLES; ++i) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatTexture0 + i]; + if (matParam.gpuIndex >= 0) + { + if (i < STATE.textureCount) + ComputeTextureTransformMatrix(STATE.textures[i], STATE.transformState.worldViewMatrix, STATE.transformState.worldMatrix, texM); + else + texM.SetIdentity(); + + Assert(matParam.rows == 4 && matParam.cols == 4); + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, texM.GetPtr())); + } + } +#if NV_STATE_FILTERING + STATE.transformState.dirtyFlags = 0; +#endif + } + + // Set per-drawcall properties + SetValuesFunctorES2 setValuesFunc(*this, targetCache); + ApplyMaterialPropertyBlockValuesES(m_MaterialProperties, STATE.activeProgram, STATE.activeProgramParams, setValuesFunc); +} + +bool GFX_GL_IMPL::IsPositionRequiredForTexGen(int unit) const +{ + if (unit >= STATE.textureCount) + return false; + if (STATE.activeProgram) + return false; + + //DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits); + const TextureUnitStateGLES2& unitState = STATE.textures[unit]; + return TextureUnitStateGLES2::PositionRequiredForTexGen(unitState.texGen); +} + +bool GFX_GL_IMPL::IsNormalRequiredForTexGen(int unit) const +{ + if (unit >= STATE.textureCount) + return false; + if (STATE.activeProgram) + return false; + + //DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits ); + const TextureUnitStateGLES2& unitState = STATE.textures[unit]; + return TextureUnitStateGLES2::NormalRequiredForTexGen(unitState.texGen); +} + + +bool GFX_GL_IMPL::IsPositionRequiredForTexGen() const +{ + return ( STATE.positionTexGen != 0 && !STATE.activeProgram ); +} + +bool GFX_GL_IMPL::IsNormalRequiredForTexGen() const +{ + return ( STATE.normalTexGen != 0 && !STATE.activeProgram ); +} + +RenderTextureFormat GFX_GL_IMPL::GetDefaultRTFormat() const +{ +#if UNITY_PEPPER + // desktop platfrom = noone cares + return kRTFormatARGB32; +#else + + RenderTextureFormat defaultFormat = GetCurrentFBColorFormatGLES20(); + return gGraphicsCaps.supportsRenderTextureFormat[defaultFormat] ? defaultFormat : kRTFormatARGB32; + +#endif +} + +RenderTextureFormat GFX_GL_IMPL::GetDefaultHDRRTFormat() const +{ +#if UNITY_PEPPER + // desktop platfrom = noone cares + return kRTFormatARGB32; +#else + + if(gGraphicsCaps.supportsRenderTextureFormat[kRTFormatARGBHalf]) + return kRTFormatARGBHalf; + + RenderTextureFormat defaultFormat = GetCurrentFBColorFormatGLES20(); + return gGraphicsCaps.supportsRenderTextureFormat[defaultFormat] ? defaultFormat : kRTFormatARGB32; + +#endif +} + + +void* GFX_GL_IMPL::GetNativeTexturePointer(TextureID id) +{ + return (void*)TextureIdMap::QueryNativeTexture(id); +} + + + +void GFX_GL_IMPL::ReloadResources() +{ + MarkAllVBOsLost(); + GetDynamicVBO().Recreate(); + + GfxDevice::CommonReloadResources(kReleaseRenderTextures | kReloadShaders | kReloadTextures); + ClearFixedFunctionPrograms(); + + extern void ClearFBMapping(); + ClearFBMapping(); + STATE.m_SharedFBO = STATE.m_HelperFBO = 0; + + InvalidateState(); +} + +void GFX_GL_IMPL::InitFramebufferDepthFormat() +{ + m_FramebufferDepthFormat = QueryFBDepthFormatGLES2(); +} + +// Acquire thread ownership on the calling thread. Worker releases ownership. +void GFX_GL_IMPL::AcquireThreadOwnership() +{ +#if UNITY_ANDROID + AcquireGLES20Context(); +#endif +} + +// Release thread ownership on the calling thread. Worker acquires ownership. +void GFX_GL_IMPL::ReleaseThreadOwnership() +{ +#if UNITY_ANDROID + ReleaseGLES20Context(); +#endif +} + +// and now the real magic +void GfxDeviceGLES20_InitFramebufferDepthFormat() +{ + ((GFX_GL_IMPL&)GetRealGfxDevice()).InitFramebufferDepthFormat(); +} + +// ---------- verify state +#if GFX_DEVICE_VERIFY_ENABLE +void GFX_GL_IMPL::VerifyState() +{ +} + +#endif // GFX_DEVICE_VERIFY_ENABLE + +#if NV_STATE_FILTERING + #ifdef glDeleteBuffers + #undef glDeleteBuffers + #endif + #ifdef glBindBuffer + #undef glBindBuffer + #endif + #ifdef glVertexAttribPointer + #undef glVertexAttribPointer + #endif +#endif + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/GfxDeviceGLES20.h b/Runtime/GfxDevice/opengles20/GfxDeviceGLES20.h new file mode 100644 index 0000000..265477e --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GfxDeviceGLES20.h @@ -0,0 +1,190 @@ +#pragma once + +#if GFX_DEVICE_VIRTUAL + +#ifdef GFX_GL_IMPL +#undef GFX_GL_IMPL +#endif +#define GFX_GL_IMPL GfxDeviceGLES20 + +class GFX_GL_IMPL : public GfxThreadableDevice { +public: + GFX_GL_IMPL(); + GFX_API ~GFX_GL_IMPL(); + + GFX_API void InvalidateState(); + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState(); + #endif + + GFX_API void Clear (UInt32 clearFlags, const float color[4], float depth, int stencil); + GFX_API void SetUserBackfaceMode( bool enable ); + GFX_API void SetWireframe(bool wire) { } // not possible in GLES + GFX_API bool GetWireframe() const { return false; } // not possible in GLES + GFX_API void SetInvertProjectionMatrix( bool enable ); + GFX_API bool GetInvertProjectionMatrix() const; + + GFX_API void SetWorldMatrix( const float matrix[16] ); + GFX_API void SetViewMatrix( const float matrix[16] ); + + GFX_API void SetProjectionMatrix (const Matrix4x4f& matrix); + GFX_API void GetMatrix( float outMatrix[16] ) const; + + GFX_API GPUSkinningInfo *CreateGPUSkinningInfo() { return NULL; } + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info) { AssertBreak(false); } + GFX_API void SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ) { AssertBreak(false); } + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) { AssertBreak(false); } + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) { AssertBreak(false); } + + GFX_API const float* GetWorldMatrix() const ; + GFX_API const float* GetViewMatrix() const; + GFX_API const float* GetProjectionMatrix() const; + GFX_API const float* GetDeviceProjectionMatrix() const; + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ); + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ); + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ); + GFX_API void SetColor( const float color[4] ); + GFX_API void SetViewport( int x, int y, int width, int height ); + GFX_API void GetViewport( int* values ) const; + + GFX_API void SetScissorRect( int x, int y, int width, int height ); + GFX_API void DisableScissor(); + GFX_API bool IsScissorEnabled() const; + GFX_API void GetScissorRect( int values[4] ) const; + GFX_API void SetSRGBWrite (const bool); + GFX_API bool GetSRGBWrite (); + + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ); + GFX_API void SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ); + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias); + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]); + GFX_API void SetTextureName ( TextureID texture, const char* name ) { } + + GFX_API void SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]); + GFX_API void CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ); + + GFX_API bool IsCombineModeSupported( unsigned int combiner ); + GFX_API void SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ); + + GFX_API bool IsShaderActive( ShaderType type ) const; + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ); + + GFX_API void DisableLights( int startLight ); + GFX_API void SetLight( int light, const GfxVertexLight& data); + GFX_API void SetAmbient( const float ambient[4] ); + + GFX_API void EnableFog (const GfxFogParams& fog); + GFX_API void DisableFog(); + + GFX_API VBO* CreateVBO(); + GFX_API void DeleteVBO( VBO* vbo ); + GFX_API DynamicVBO& GetDynamicVBO(); + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags); + GFX_API RenderSurfaceHandle CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags); + GFX_API void DestroyRenderSurface (RenderSurfaceHandle& rs); + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face = kCubeFaceUnknown); + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle); + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface (int index); + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface (); + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags); + GFX_API void DiscardContents (RenderSurfaceHandle& rs); + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ); + GFX_API void DeleteTexture( TextureID texture ); + + GFX_API PresentMode GetPresentMode(); + + GFX_API void BeginFrame(); + GFX_API void EndFrame(); + GFX_API void PresentFrame(); + + GFX_API bool IsValidState(); + GFX_API bool HandleInvalidState(); + + GFX_API void FinishRendering(); + + // Immediate mode rendering + GFX_API void ImmediateVertex( float x, float y, float z ); + GFX_API void ImmediateNormal( float x, float y, float z ); + GFX_API void ImmediateColor( float r, float g, float b, float a ); + GFX_API void ImmediateTexCoordAll( float x, float y, float z ); + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ); + GFX_API void ImmediateBegin( GfxPrimitiveType type ); + GFX_API void ImmediateEnd(); + + GFX_API void AcquireThreadOwnership(); + GFX_API void ReleaseThreadOwnership(); + + protected: + + + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ); + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); + GFX_API void GrabIntoRenderTexture( RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ); + + GFX_API void BeforeDrawCall( bool immediateMode); + + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef); + GFX_API void SetRasterState(const DeviceRasterState* state); + GFX_API void SetDepthState(const DeviceDepthState* state); + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef); + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state); + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state); + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state); + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state); + +#if ENABLE_PROFILER + GFX_API void BeginProfileEvent (const char* name); + GFX_API void EndProfileEvent (); + + GFX_API GfxTimerQuery* CreateTimerQuery(); + GFX_API void DeleteTimerQuery(GfxTimerQuery* query); + GFX_API void BeginTimerQueries(); + GFX_API void EndTimerQueries(); +#endif + +public: + // OpenGLES specific + GFX_API void ReloadResources(); + GFX_API bool IsPositionRequiredForTexGen(int texStageIndex) const; + GFX_API bool IsNormalRequiredForTexGen(int texStageIndex) const; + + GFX_API bool IsPositionRequiredForTexGen() const; + GFX_API bool IsNormalRequiredForTexGen() const; + + GFX_API RenderTextureFormat GetDefaultRTFormat() const; + GFX_API RenderTextureFormat GetDefaultHDRRTFormat() const; + + GFX_API void* GetNativeTexturePointer(TextureID id); + + DeviceStateGLES20& GetState() { return state; } + + void InitFramebufferDepthFormat(); + +private: + DeviceStateGLES20 state; +}; + +#define STATE this->state +#define GetGLES20DeviceState(device) device.GetState() + +#else // GFX_DEVICE_VIRTUAL + + +struct GfxDeviceImpl { + DeviceStateGLES20 state; +}; + +#define STATE impl->state +#define GetGLES20DeviceState(device) device.GetImpl()->state + +#endif // GFX_DEVICE_VIRTUAL diff --git a/Runtime/GfxDevice/opengles20/GpuProgramsGLES20.cpp b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20.cpp new file mode 100644 index 0000000..e28fbde --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20.cpp @@ -0,0 +1,1120 @@ +#include "UnityPrefix.h" +#if GFX_SUPPORTS_OPENGLES20 +#include "GpuProgramsGLES20.h" +#include "Runtime/Utilities/LogAssert.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Utilities/File.h" +#include "Runtime/File/ApplicationSpecificPersistentDataPath.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "External/shaderlab/Library/ShaderLabErrors.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/program.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/Math/Matrix3x3.h" +#include "Runtime/Math/Vector4.h" + + +#include "IncludesGLES20.h" +#include "AssertGLES20.h" +#include "GpuPropertiesGLES20.h" +#include "Runtime/Utilities/GLSLUtilities.h" +#include "VBOGLES20.h" +#include "DebugGLES20.h" +#include "UnityGLES20Ext.h" + +#if UNITY_ANDROID + #include "PlatformDependent/AndroidPlayer/EntryPoint.h" + #include "PlatformDependent/AndroidPlayer/AndroidSystemInfo.h" +#endif + +#if UNITY_BLACKBERRY + #include "ctype.h" +#endif + + +#include <stdio.h> + +#define DEBUG_GLSL_BINDINGS 0 +#define DEBUG_SHADER_CACHE 0 + + +// from shader_yacc.hpp +extern std::string g_LastParsedShaderName; + +void GLSLUseProgramGLES20 (UInt32 programID); // defined in GfxDeviceGLES20.cpp + +bool CompileGLSLVertexShader (const std::string& source, ChannelAssigns& channels, GLShaderID programID, GLShaderID parentProgramID, GLShaderID* outShaderID); +bool CompileGLSLFragmentShader (const std::string& source, GLShaderID* outShaderID); +bool BindVProgAttrbutes(const std::string& source, ChannelAssigns& channels, GLShaderID programID); +bool RebindVProgAttrbutes(GLShaderID programID, GLShaderID parentProgramID); + + +static void GetCachedBinaryName(const std::string& vprog, const std::string& fshader, char filename[33]); + + +// -------------------------------------------------------------------------- +// GLSL + +// AttributeConversionTable +const static UInt32 kAttribLookupTableSize = 12; + +const static char* s_GLSLESAttributes[kAttribLookupTableSize] = { + "_glesVertex", "_glesColor", "_glesNormal", + "_gles_unused__", // unused + "_glesMultiTexCoord0", "_glesMultiTexCoord1", "_glesMultiTexCoord2", "_glesMultiTexCoord3", + "_glesMultiTexCoord4", "_glesMultiTexCoord5", "_glesMultiTexCoord6", "_glesMultiTexCoord7" +}; +const static char* s_UnityAttributes[kAttribLookupTableSize] = { + "Vertex", "Color", "Normal", + "", // unused + "TexCoord", "TexCoord1", "TexCoord2", "TexCoord3", + "TexCoord4", "TexCoord5", "TexCoord6", "TexCoord7" +}; + + +const VertexComponent s_UnityVertexComponents[kAttribLookupTableSize] = { + kVertexCompVertex, + kVertexCompColor, + kVertexCompNormal, + kVertexCompTexCoord, + kVertexCompTexCoord0, kVertexCompTexCoord1, kVertexCompTexCoord2, kVertexCompTexCoord3, + kVertexCompTexCoord4, kVertexCompTexCoord5, kVertexCompTexCoord6, kVertexCompTexCoord7 +}; + +const GLuint s_GLESVertexComponents[kAttribLookupTableSize] = { + GL_VERTEX_ARRAY, + GL_COLOR_ARRAY, + GL_NORMAL_ARRAY, + ~0 /*kVertexCompTexCoord*/, + GL_TEXTURE_ARRAY0, GL_TEXTURE_ARRAY1, GL_TEXTURE_ARRAY2, GL_TEXTURE_ARRAY3, + GL_TEXTURE_ARRAY4, GL_TEXTURE_ARRAY5, GL_TEXTURE_ARRAY6, GL_TEXTURE_ARRAY7 +}; + +GlslGpuProgramGLES20::GlslGpuProgramGLES20 (const std::string& source, CreateGpuProgramOutput& output) +{ + output.SetPerFogModeParamsEnabled(true); + m_ImplType = kShaderImplBoth; + for (int i = 0; i < kFogModeCount; ++i) + { + m_GLSLVertexShader[i] = 0; + m_GLSLFragmentShader[i] = 0; + m_FogColorIndex[i] = -1; + m_FogParamsIndex[i] = -1; + m_FogFailed[i] = false; + } + + // Fragment shaders come out as dummy GLSL text. Just ignore them; the real shader was part of + // the vertex shader text anyway. + if (source.empty()) + return; + + if (Create (source, output.CreateChannelAssigns())) + { + GpuProgramParameters& params = output.CreateParams(); + FillParams (m_Programs[kFogDisabled], params, output.GetOutNames()); + if (params.GetTextureParams().size() > gGraphicsCaps.maxTexImageUnits) + m_NotSupported = true; + + m_UniformCache[kFogDisabled].Create(¶ms, -1, -1); + } + else + { + m_NotSupported = true; + } +} + +GlslGpuProgramGLES20::~GlslGpuProgramGLES20 () +{ + Assert (m_ImplType == kShaderImplBoth); + for (int i = 0; i < kFogModeCount; ++i) + { + if (m_GLSLVertexShader[i]) { GLES_CHK(glDeleteShader(m_GLSLVertexShader[i])); } + if (m_GLSLFragmentShader[i]) { GLES_CHK(glDeleteShader(m_GLSLFragmentShader[i])); } + if (m_Programs[i]) { GLES_CHK(glDeleteProgram(m_Programs[i])); } + m_UniformCache[i].Destroy(); + } +} + +static bool ParseGlslErrors (GLuint type, GLSLErrorType errorType, const char* source = 0) +{ + bool hadErrors = false; + char compileInfoLog[4096]; + GLsizei infoLogLength = 0; + switch(errorType) + { + case kErrorCompileVertexShader: + case kErrorCompileFragShader: + glGetShaderInfoLog(type, 4096, &infoLogLength, compileInfoLog); + break; + case kErrorLinkProgram: + glGetProgramInfoLog(type, 4096, &infoLogLength, compileInfoLog); + break; + default: + FatalErrorMsg("Unknown error type"); + break; + } + + if(infoLogLength) + { + hadErrors = true; + if(source) + { + ErrorStringMsg("-------- failed compiling %s:\n", errorType==kErrorCompileVertexShader?"vertex program":"fragment shader"); + DebugTextLineByLine(source); + } + + ErrorStringMsg("-------- GLSL error: %s\n\n", compileInfoLog); + } + + return hadErrors; +} + +static std::string ExtractDefineBock(const std::string& defineName, const std::string& str, std::string* remainderStr) +{ + const std::string beginsWith = "#ifdef " + defineName; + const std::string endsWith = "#endif"; + + size_t b; + if ((b = str.find(beginsWith))==std::string::npos) + return ""; + + b += beginsWith.size(); + + size_t e = b; + size_t n = 1; + do + { + size_t nextEnd = str.find(endsWith, e); + size_t nextIf = str.find("#if", e); + + if (nextEnd == std::string::npos) + return ""; + + if (nextIf != std::string::npos && nextIf < nextEnd) + { + ++n; + e = nextIf + 1; + } + else + { + --n; + e = nextEnd + 1; + } + } + while (n > 0); + + std::string retVal = str.substr(b, e-b-1); + if (remainderStr) + { + *remainderStr = str.substr(0, b - beginsWith.size()); + if (e + endsWith.size() < str.length()) *remainderStr += str.substr(e + endsWith.size()); + } + + return retVal; +} + +static void FindProgramStart(const char* source, std::string* header, std::string* prog) +{ + const char* line_start = source; + while(*line_start) + { + while(isspace(*line_start)) + ++line_start; + if(*line_start == '#') + { + while(*line_start != '\n' && *line_start != '\r') + ++line_start; + } + else + { + header->assign(source, line_start - source); + prog->assign(line_start); + break; + } + } +} + +bool CompileGlslShader(GLShaderID shader, GLSLErrorType type, const char* source) +{ + GLES_CHK(glShaderSource(shader, 1, &source, NULL)); + GLES_CHK(glCompileShader(shader)); + + int compiled = 10; + GLES_CHK(glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled)); + + if (compiled==0) + { + ParseGlslErrors(shader, type, source); + return false; + } + + return true; +} + +bool GlslGpuProgramGLES20::Create (const std::string &shaderString, ChannelAssigns& channels) +{ + if( !gGraphicsCaps.gles20.hasGLSL ) + return false; + + GLESAssert(); // Clear any GL errors + + GLES_CHK(m_Programs[0] = glCreateProgram()); + + m_ImplType = kShaderImplBoth; + + // NOTE: pre-pending shader with VERTEX/FRAGMENT defines doesn't work with ES/GLSL compilers for some reason + // therefore we extract VERTEX/FRAGMENT sections from the shaderString + + std::string remainder = shaderString; + std::string vertexShaderSource = ExtractDefineBock("VERTEX", shaderString, &remainder); + std::string fragmentShaderSource = ExtractDefineBock("FRAGMENT", remainder, &remainder); + + vertexShaderSource = remainder + vertexShaderSource; + fragmentShaderSource = remainder + fragmentShaderSource; + + if(!CompileProgram(0, vertexShaderSource, fragmentShaderSource, channels)) + { + ParseGlslErrors(m_Programs[0], kErrorLinkProgram); + + // TODO: cleanup + return false; + } + + m_VertexShaderSourceForFog = vertexShaderSource; + m_SourceForFog = fragmentShaderSource; + + return true; +} + +std::string GlslGpuProgramGLES20::_CachePath; + +bool GlslGpuProgramGLES20::InitBinaryShadersSupport() +{ +#if UNITY_ANDROID + // the implementation is broken on pre-HC on pvr at least, but we'd rather play safe with this dino stuff + if(android::systeminfo::ApiLevel() < android::apiHoneycomb) + return false; + + // Huawei is osam in general + if(gGraphicsCaps.rendererString.find("Immersion") != std::string::npos) + return false; +#endif + + if(QueryExtension("GL_OES_get_program_binary") && gGlesExtFunc.glGetProgramBinaryOES && gGlesExtFunc.glProgramBinaryOES) + { + int binFormatCount = 0; + GLES_CHK(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS_OES, &binFormatCount)); + + if(binFormatCount > 0) + { + _CachePath = GetTemporaryCachePathApplicationSpecific() + "/UnityShaderCache/"; + if(!IsDirectoryCreated(_CachePath)) + CreateDirectory(_CachePath); + + return true; + } + } + + return false; +} + +void Internal_ClearShaderCache() +{ + std::string shaderCache = GetTemporaryCachePathApplicationSpecific() + "/UnityShaderCache/"; + DeleteFileOrDirectory(shaderCache); + CreateDirectory(shaderCache); +} + +bool GlslGpuProgramGLES20::CompileProgram(unsigned index, const std::string& vprog, const std::string& fshader, ChannelAssigns& channels) +{ + std::string binaryPath; + if(gGraphicsCaps.gles20.hasBinaryShaders) + { + char filename[33] = {0}; + GetCachedBinaryName(vprog, fshader, filename); + + binaryPath = _CachePath + filename; + #if DEBUG_SHADER_CACHE + ::printf_console("Starting compilation \"%s\" variation with md5:%s\n", g_LastParsedShaderName.c_str(), filename); + #endif + } + + // first 4 bytes are for binary format + char* binaryData = 0; + char* binaryProgram = 0; + unsigned binaryLength = 0; + + bool loadedBinary = false; + if(gGraphicsCaps.gles20.hasBinaryShaders) + { + FILE* binaryFile = ::fopen(binaryPath.c_str(), "rb"); + if(binaryFile) + { + ::fseek(binaryFile, 0, SEEK_END); + unsigned datasz = (unsigned)::ftell(binaryFile); + ::fseek(binaryFile, 0, SEEK_SET); + + binaryData = (char*)::malloc(datasz); + binaryProgram = binaryData + sizeof(GLenum); + binaryLength = datasz - sizeof(GLenum); + ::fread(binaryData, datasz, 1, binaryFile); + ::fclose(binaryFile); + + loadedBinary = true; + #if DEBUG_SHADER_CACHE + ::printf_console("Loaded from cache"); + #endif + } + } + + if(loadedBinary) + { + loadedBinary = false; + + bool attrBound = index==0 ? BindVProgAttrbutes(vprog, channels, m_Programs[0]) + : RebindVProgAttrbutes(m_Programs[index], m_Programs[0]); + if(attrBound) + { + GLES_CHK(gGlesExtFunc.glProgramBinaryOES(m_Programs[index], *((GLenum*)binaryData), binaryProgram, binaryLength)); + + int linked = 0; + GLES_CHK(glGetProgramiv(m_Programs[index], GL_LINK_STATUS, &linked)); + loadedBinary = linked != 0; + } + + if(!loadedBinary) + { + #if DEBUG_SHADER_CACHE + ::printf_console("Bad cached version\n"); + #endif + + ::free(binaryData); + binaryProgram = binaryData = 0; + } + } + + // fallback to compiling shaders at runtime + if(!loadedBinary) + { + DBG_SHADER_VERBOSE_GLES20("Compiling shader: %s\n", g_LastParsedShaderName.c_str()); + #if DEBUG_SHADER_CACHE + ::printf_console("Actually compiling"); + #endif + + if(!CompileGLSLVertexShader(vprog, channels, m_Programs[index], m_Programs[0], &m_GLSLVertexShader[index])) + return false; + if(!CompileGLSLFragmentShader(fshader, &m_GLSLFragmentShader[index])) + return false; + + GLES_CHK(glAttachShader(m_Programs[index], m_GLSLVertexShader[index])); + GLES_CHK(glAttachShader(m_Programs[index], m_GLSLFragmentShader[index])); + GLES_CHK(glLinkProgram(m_Programs[index])); + + int linked = 0; + GLES_CHK(glGetProgramiv(m_Programs[index], GL_LINK_STATUS, &linked)); + if(linked == 0) + return false; + + if(gGraphicsCaps.gles20.hasBinaryShaders) + { + Assert(binaryData == 0 && binaryProgram == 0); + + GLES_CHK(glGetProgramiv(m_Programs[index], GL_PROGRAM_BINARY_LENGTH_OES, (GLint*)&binaryLength)); + binaryData = (char*)::malloc(binaryLength + sizeof(GLenum)); + binaryProgram = binaryData + sizeof(GLenum); + GLES_CHK(gGlesExtFunc.glGetProgramBinaryOES(m_Programs[index], binaryLength, 0, (GLenum*)binaryData, binaryProgram)); + + FILE* binaryFile = ::fopen(binaryPath.c_str(), "wb"); + if(binaryFile) + { + ::fwrite(binaryData, binaryLength + sizeof(GLenum), 1, binaryFile); + ::fclose(binaryFile); + + #if DEBUG_SHADER_CACHE + ::printf_console("Saved to cache\n"); + #endif + } + } + } + + if(binaryData) + ::free(binaryData); + + return true; +} + + + +static void PrintNumber (char* s, int i, bool brackets) +{ + DebugAssert (i >= 0 && i < 100); + if (brackets) + *s++ = '['; + + if (i < 10) { + *s++ = '0' + i; + } else { + *s++ = '0' + i/10; + *s++ = '0' + i%10; + } + + if (brackets) + *s++ = ']'; + *s++ = 0; +} + +static void AddSizedVectorParam (GpuProgramParameters& params, ShaderParamType type, GLuint program, int vectorSize, int uniformNumber, int arraySize, const char* unityName, char* glName, int glNameIndexOffset, PropertyNamesSet* outNames) +{ + if (arraySize <= 1) + { + params.AddVectorParam (uniformNumber, type, vectorSize, unityName, -1, outNames); + } + else + { + for (int j = 0; j < arraySize; ++j) + { + PrintNumber (glName+glNameIndexOffset, j, true); + uniformNumber = glGetUniformLocation (program, glName); + PrintNumber (glName+glNameIndexOffset, j, false); + params.AddVectorParam (uniformNumber, type, vectorSize, glName, -1, outNames); + } + } +} + +static void AddSizedMatrixParam (GpuProgramParameters& params, GLuint program, int rows, int cols, int uniformNumber, int arraySize, const char* unityName, char* glName, int glNameIndexOffset, PropertyNamesSet* outNames) +{ + if (arraySize <= 1) + { + params.AddMatrixParam (uniformNumber, unityName, rows, cols, -1, outNames); + } + else + { + for (int j = 0; j < arraySize; ++j) + { + PrintNumber (glName+glNameIndexOffset, j, true); + uniformNumber = glGetUniformLocation (program, glName); + PrintNumber (glName+glNameIndexOffset, j, false); + params.AddMatrixParam (uniformNumber, glName, rows, cols, -1, outNames); + } + } +} + + +void GlslGpuProgramGLES20::FillParams (unsigned int programID, GpuProgramParameters& params, PropertyNamesSet* outNames) +{ + if (!programID) + return; + + int activeUniforms; + + char name[1024]; + GLenum type; + int arraySize = 0, + nameLength = 0, + bufSize = sizeof(name); + + DBG_LOG_GLES20("GLSL: apply params to program id=%i\n", programID); + GLSLUseProgramGLES20 (programID); + + // Figure out the uniforms + GLES_CHK(glGetProgramiv (programID, GL_ACTIVE_UNIFORMS, &activeUniforms)); + for(int i=0; i < activeUniforms; i++) + { + //chai: »ñµÃUniform±äÁ¿Ãû + GLES_CHK(glGetActiveUniform (programID, i, bufSize, &nameLength, &arraySize, &type, name)); + + if (!strcmp (name, "_unity_FogParams") || !strcmp(name, "_unity_FogColor")) + continue; + + // some Unity builtin properties are mapped to GLSL structure fields + // hijack them here + const char* glslName = GetGLSLESPropertyNameRemap(name); + const char* unityName = glslName ? glslName : name; + + if (!strncmp (name, "gl_", 3)) // skip "gl_" names + continue; + + int uniformNumber = glGetUniformLocation (programID, name); + Assert(uniformNumber != -1); + + char* glName = name; + int glNameIndexOffset = 0; + + bool isElemZero = false; + bool isArray = IsShaderParameterArray(name, nameLength, arraySize, &isElemZero); + if (isArray) + { + // for array parameters, transform name a bit: Foo[0] becomes Foo0 + if (arraySize >= 100) { + ErrorString( "GLSL: array sizes larger than 99 not supported" ); // TODO: SL error + arraySize = 99; + } + // TODO: wrong? what if we use only array[1] for example + if (isElemZero) + { + glNameIndexOffset = nameLength-3; + glName[glNameIndexOffset] = '0'; + glName[glNameIndexOffset+1] = 0; + } + else + { + glNameIndexOffset = nameLength; + } + } + + if (type == GL_FLOAT) + AddSizedVectorParam (params, kShaderParamFloat, programID, 1, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_FLOAT_VEC2) + AddSizedVectorParam (params, kShaderParamFloat, programID, 2, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_FLOAT_VEC3) + AddSizedVectorParam (params, kShaderParamFloat, programID, 3, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_FLOAT_VEC4) + AddSizedVectorParam (params, kShaderParamFloat, programID, 4, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_INT) + AddSizedVectorParam (params, kShaderParamInt, programID, 1, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_INT_VEC2) + AddSizedVectorParam (params, kShaderParamInt, programID, 2, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_INT_VEC3) + AddSizedVectorParam (params, kShaderParamInt, programID, 3, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_INT_VEC4) + AddSizedVectorParam (params, kShaderParamInt, programID, 4, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_BOOL) + AddSizedVectorParam (params, kShaderParamBool, programID, 1, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_BOOL_VEC2) + AddSizedVectorParam (params, kShaderParamBool, programID, 2, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_BOOL_VEC3) + AddSizedVectorParam (params, kShaderParamBool, programID, 3, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_BOOL_VEC4) + AddSizedVectorParam (params, kShaderParamBool, programID, 4, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_FLOAT_MAT4) + AddSizedMatrixParam (params, programID, 4, 4, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + else if (type == GL_FLOAT_MAT3) + AddSizedMatrixParam (params, programID, 3, 3, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + + else if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_SHADOW_EXT) { + const int texIndex = params.GetTextureParams().size(); // statically bind this uniform to sequential texture index + GLES_CHK(glUniform1i (uniformNumber, texIndex)); + params.AddTextureParam (texIndex, -1, unityName, kTexDim2D, outNames); + } + else if (type == GL_SAMPLER_CUBE) { + const int texIndex = params.GetTextureParams().size(); // statically bind this uniform to sequential texture index + GLES_CHK(glUniform1i (uniformNumber, texIndex)); + params.AddTextureParam (texIndex, -1, unityName, kTexDimCUBE, outNames); + } + /* + else if(type == GL_SAMPLER_3D) { + GLES_CHK(glUniform1i (uniformNumber, params.GetTextureParams().size())); + params.AddTextureParam( name, kTexDim3D, uniformNumber ); + } + else if(type == GL_SAMPLER_2D_SHADOW) { + GLES_CHK(glUniform1i (uniformNumber, params.GetTextureParams().size())); + params.AddTextureParam( name, kTexDim2D, uniformNumber ); + } + + */ + else { + AssertString( "Unrecognized GLSL uniform type" ); + } + } + + GLESAssert(); +} + +bool RebindVProgAttrbutes(GLShaderID programID, GLShaderID parentProgramID) +{ + int attribCount = 0; + GLES_CHK(glGetProgramiv(parentProgramID, GL_ACTIVE_ATTRIBUTES, &attribCount)); + + const int kBufSize = 256; + char name[kBufSize]; + for(int i = 0 ; i < attribCount ; ++i) + { + int nameLength = 0, arraySize = 0; + GLenum type; + GLES_CHK(glGetActiveAttrib (parentProgramID, i, kBufSize, &nameLength, &arraySize, &type, name)); + int location = glGetAttribLocation (parentProgramID, name); + if (location != -1) + GLES_CHK(glBindAttribLocation(programID, location, name)); + } + + return true; +} + +bool BindVProgAttrbutes(const std::string& source, ChannelAssigns& channels, GLShaderID programID) +{ + // Add necessary attribute tags + for (UInt32 j = 0; j < kAttribLookupTableSize; j++) + { + if (source.find(s_GLSLESAttributes[j]) != std::string::npos) + { + if (s_GLESVertexComponents[j] >= gGraphicsCaps.gles20.maxAttributes) + { + ErrorString("Shader uses too many vertex attributes for this platform"); + return false; + } + GLES_CHK(glBindAttribLocation(programID, s_GLESVertexComponents[j], s_GLSLESAttributes[j])); + ShaderChannel shaderChannel = GetShaderChannelFromName(s_UnityAttributes[j]); + if( shaderChannel != kShaderChannelNone ) + channels.Bind (shaderChannel, s_UnityVertexComponents[j]); + } + } + + // UGLY HACK: + // somewhere deep inside shader generation we just put attribute TANGENT + // without ever using it after + // look for TANGENT twice to be sure we use it + size_t firstTangentUsage = source.find("TANGENT"); + if( firstTangentUsage != std::string::npos && source.find("TANGENT", firstTangentUsage+1) != std::string::npos ) + { + // Find first free slot for tangents and use it. + // Unity normally supports 2 UV slots (0&1), so start looking from + // kVertexTexCoord2 + for (int i = kVertexCompTexCoord2; i < kVertexCompTexCoord7; i++) + { + if (channels.GetSourceForTarget((VertexComponent)i) == kShaderChannelNone) + { + channels.Bind (kShaderChannelTangent, (VertexComponent)i); + GLES_CHK(glBindAttribLocation(programID, GL_TEXTURE_ARRAY0 + i - kVertexCompTexCoord0, "_glesTANGENT")); + break; + } + } + } + + return true; +} + + +bool CompileGLSLVertexShader (const std::string& source, ChannelAssigns& channels, GLShaderID programID, GLShaderID parentProgramID, GLShaderID* outShaderID) +{ + GLES_CHK(*outShaderID = glCreateShader(GL_VERTEX_SHADER)); + + if(parentProgramID == programID) + BindVProgAttrbutes(source, channels, programID); + else + RebindVProgAttrbutes(programID, parentProgramID); + + +#if UNITY_ANDROID + if(gGraphicsCaps.gles20.buggyVprogTextures) + { + if( source.find("texture2D") != std::string::npos || source.find("tex2D") != std::string::npos ) + { + ErrorString("GLES20: Running on platform with buggy vprog textures.\n"); + ErrorString("GLES20: Compiling this shader may result in crash.\n"); + ErrorString("GLES20: Shader in question:\n"); + DebugTextLineByLine(source.c_str()); + ErrorString("\n---------------\n"); + } + } +#endif + + const char* text = source.c_str(); + DBG_SHADER_VERBOSE_GLES20_DUMP_SHADER("Compiling VERTEX program:", text); + + return CompileGlslShader(*outShaderID, kErrorCompileVertexShader, text); +} + + +bool CompileGLSLFragmentShader (const std::string& source, GLShaderID* outShaderID) +{ + *outShaderID = glCreateShader(GL_FRAGMENT_SHADER); + + ///@TODO: find any existing precision statement + + std::string modSourceHeader, modSourceProg; + FindProgramStart(source.c_str(), &modSourceHeader, &modSourceProg); + + std::string prec_modifier = gGraphicsCaps.gles20.forceHighpFSPrec ? "precision highp float;\n" : "precision mediump float;\n"; + + std::string modSource = modSourceHeader + prec_modifier + modSourceProg; + + const char* text = modSource.c_str(); + DBG_SHADER_VERBOSE_GLES20_DUMP_SHADER("Compiling FRAGMENT program:", text); + + return CompileGlslShader(*outShaderID, kErrorCompileFragShader, text); +} + +int GlslGpuProgramGLES20::GetGLProgram (FogMode fog, GpuProgramParameters& outParams, ChannelAssigns &channels) +{ + int index = 0; + if (fog > kFogDisabled && !m_FogFailed[fog] && !m_SourceForFog.empty()) + { + index = fog; + Assert (index >= 0 && index < kFogModeCount); + + // create patched fog program if needed + if(!m_Programs[index]) + { + std::string srcVS = m_VertexShaderSourceForFog; + std::string srcPS = m_SourceForFog; + + if(PatchShaderFogGLES (srcVS, srcPS, fog, CanUseOptimizedFogCodeGLES(srcVS))) + { + // create program, shaders, link + GLES_CHK(m_Programs[index] = glCreateProgram()); + ShaderErrors errors; + if(CompileProgram(index, srcVS, srcPS, channels)) + { + FillParams (m_Programs[index], outParams, NULL); + m_FogParamsIndex[index] = glGetUniformLocation(m_Programs[index], "_unity_FogParams"); + m_FogColorIndex[index] = glGetUniformLocation(m_Programs[index], "_unity_FogColor"); + + m_UniformCache[index].Create(&outParams, m_FogParamsIndex[index], m_FogColorIndex[index]); + } + else + { + if(m_GLSLVertexShader[index]) + glDeleteShader(m_GLSLVertexShader[index]); + + if(m_GLSLFragmentShader[index]) + glDeleteShader(m_GLSLFragmentShader[index]); + + m_GLSLVertexShader[index] = 0; + m_GLSLFragmentShader[index] = 0; + + glDeleteProgram(m_Programs[index]); + m_Programs[index] = 0; + + m_FogFailed[index] = true; + index = 0; + } + } + else + { + m_FogFailed[index] = true; + index = 0; + } + } + } + return index; +} + +// chai: ÔÚBeforDrawCallµ÷Óà +int GlslGpuProgramGLES20::ApplyGpuProgramES20 (const GpuProgramParameters& params, const UInt8 *buffer) +{ + DBG_LOG_GLES20("GlslGpuProgramGLES20::ApplyGpuProgramES20()"); + + // m_Programs[0] == 0, is when Unity tries to build a dummy shader with empty source for fragment shaders, do nothing in this case + if (m_Programs[0] == 0) + return 0; + + GfxDevice& device = GetRealGfxDevice(); + + const GfxFogParams& fog = device.GetFogParams(); + const int index = (int)fog.mode; + + DBG_LOG_GLES20("GLSL: apply program id=%i\n", m_Programs[index]); + + //chai£º glUseProgram + GLSLUseProgramGLES20 (m_Programs[index]); + + // Apply value parameters + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for( GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i ) + { + if (i->m_RowCount == 1 && i->m_ArraySize == 1) + { + UniformCacheGLES20* cache = m_UniformCache+index; + const float * val = reinterpret_cast<const float*>(buffer); + + switch (i->m_ColCount) + { + case 1: CachedUniform1(cache, i->m_Type, i->m_Index, val); break; + case 2: CachedUniform2(cache, i->m_Type, i->m_Index, val); break; + case 3: CachedUniform3(cache, i->m_Type, i->m_Index, val); break; + case 4: CachedUniform4(cache, i->m_Type, i->m_Index, val); break; + default: break; + } + + #if DEBUG_GLSL_BINDINGS + ;;printf_console(" vector %i dim=%i\n", i->m_Index, i->m_Dim ); + #endif + buffer += 4*sizeof(float); + } + else + { + // Apply matrix parameters + DebugAssert (i->m_ArraySize == 1); + int size = *reinterpret_cast<const int*>(buffer); buffer += sizeof(int); + Assert (size == 16); + const Matrix4x4f* mat = reinterpret_cast<const Matrix4x4f*>(buffer); + if (i->m_RowCount == 3 && i->m_ColCount == 3) + { + Matrix3x3f m33 = Matrix3x3f(*mat); + GLES_CHK(glUniformMatrix3fv (i->m_Index, 1, GL_FALSE, m33.GetPtr())); + } + else + { + const float *ptr = mat->GetPtr (); + GLES_CHK(glUniformMatrix4fv (i->m_Index, 1, GL_FALSE, ptr)); + } + #if DEBUG_GLSL_BINDINGS + ;;printf_console(" matrix %i (%s)\n", i->m_Index, i->m_Name.GetName() ); + #endif + buffer += size * sizeof(float); + } + } + + // Apply textures + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for( GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i ) + { + const GpuProgramParameters::TextureParameter& t = *i; + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + #if DEBUG_GLSL_BINDINGS + ;;printf_console(" sampler %i (%s) id=%i dim=%i\n", t.m_Index, t.m_Name.GetName(), tex->GetActualTextureID().m_ID, tex->GetTexDim() ); + #endif + ApplyTexEnvData (t.m_Index, t.m_Index, *texdata); + buffer += sizeof(TexEnvData); + } + + // Fog parameters if needed + if (index > 0) + { + if (m_FogColorIndex[fog.mode] >= 0) + CachedUniform4(m_UniformCache+index, kShaderParamFloat, m_FogColorIndex[fog.mode], fog.color.GetPtr()); + + Vector4f params( + fog.density * 1.2011224087f,// density / sqrt(ln(2)) + fog.density * 1.4426950408f, // density / ln(2) + 0.0f, + 0.0f + ); + + if (fog.mode == kFogLinear) + { + float diff = fog.end - fog.start; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + params[2] = -invDiff; + params[3] = fog.end * invDiff; + } + + if (m_FogParamsIndex[fog.mode] >= 0) + CachedUniform4(m_UniformCache+index, kShaderParamFloat, m_FogParamsIndex[fog.mode], params.GetPtr()); + } + + GLESAssert(); + + return index; +} + + +// -------------------------------------------------------------------------- + + +FixedFunctionProgramGLES20::FixedFunctionProgramGLES20(GLShaderID vertexShader, GLShaderID fragmentShader) +: m_GLSLProgram(0) +, m_GLSLVertexShader(vertexShader) +, m_GLSLFragmentShader(fragmentShader) +{ + m_GLSLProgram = Create(m_GLSLVertexShader, m_GLSLFragmentShader); +} + +FixedFunctionProgramGLES20::~FixedFunctionProgramGLES20 () +{ + // NOTE: do not delete vertex/fragment shaders; they can be shared between multiple programs + // and are deleted in ClearFixedFunctionPrograms + if (m_GLSLProgram != 0 ) // only delete valid programs + GLES_CHK(glDeleteProgram(m_GLSLProgram)); + + m_UniformCache.Destroy(); +} + +GLShaderID FixedFunctionProgramGLES20::Create(GLShaderID vertexShader, GLShaderID fragmentShader) +{ + if( !gGraphicsCaps.gles20.hasGLSL ) + return false; + + GLESAssert(); // Clear any GL errors + + GLuint program; + GLES_CHK(program = glCreateProgram()); + + for (int i = 0; i < kAttribLookupTableSize; i++) + { + if(s_GLESVertexComponents[i] < gGraphicsCaps.gles20.maxAttributes) + GLES_CHK(glBindAttribLocation(program, s_GLESVertexComponents[i], s_GLSLESAttributes[i])); + } + + GLES_CHK(glAttachShader(program, m_GLSLVertexShader)); + GLES_CHK(glAttachShader(program, m_GLSLFragmentShader)); + + //We must link only after binding the attributes + GLES_CHK(glLinkProgram(program)); + + int linked = 0; + GLES_CHK(glGetProgramiv(program, GL_LINK_STATUS, &linked)); + if (linked == 0) + { + ParseGlslErrors(program, kErrorLinkProgram); + GLES_CHK(glDeleteProgram(program)); + return 0; + } + + // Figure out the uniforms + int activeUniforms; + + char name[1024]; + GLenum type; + int size = 0, + length = 0, + bufSize = sizeof(name); + + // Fetch texture stage samplers. Bind GLSL uniform to the OpenGL texture unit + // just once, cause it never changes after that for this program; and could cause + // internal shader recompiles when changing them. + DBG_LOG_GLES20("GLSL: apply fixed-function program id=%i\n", program); + GLSLUseProgramGLES20 (program); + + for (int i = 0; i < kMaxSupportedTextureUnitsGLES; i++) + { + std::string samplerName = Format("u_sampler%d", i); + GLint uniformNumber = glGetUniformLocation(program, samplerName.c_str()); + + if (uniformNumber != -1) + { + GLES_CHK(glUniform1i (uniformNumber, i)); + DBG_GLSL_BINDINGS_GLES20(" FFsampler: %s nr=%d", samplerName.c_str(), uniformNumber); + } + } + + // fetch generic params + GLES_CHK(glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &activeUniforms)); + for(int i=0; i < activeUniforms; i++) + { + GLES_CHK(glGetActiveUniform(program, i, bufSize, &length, &size, &type, name)); + int uniformNumber = glGetUniformLocation(program, name); + + const char* glslName = GetGLSLESPropertyNameRemap(name); + const char* unityName = glslName ? glslName : name; + + if(type == GL_FLOAT) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 1, unityName, -1, NULL); + } + else if(type == GL_FLOAT_VEC2) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 2, unityName, -1, NULL); + } + else if(type == GL_FLOAT_VEC3) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 3, unityName, -1, NULL); + } + else if(type == GL_FLOAT_VEC4) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 4, unityName, -1, NULL); + } + else if(type == GL_FLOAT_MAT4) { + m_Params.AddMatrixParam(uniformNumber, unityName, 4, 4, -1, NULL); + } + else if(type == GL_FLOAT_MAT3) { + m_Params.AddMatrixParam(uniformNumber, unityName, 3, 3, -1, NULL); + } + else if(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE) { + } + else { + AssertString( "Unrecognized GLSL uniform type" ); + } + DBG_GLSL_BINDINGS_GLES20(" FFuniform: %s nr=%d type=%d", unityName, uniformNumber, type); + } + + m_UniformCache.Create(&m_Params, -1,-1); + + GLESAssert(); + return program; +} + +void FixedFunctionProgramGLES20::ApplyFFGpuProgram(const BuiltinShaderParamValues& values) const +{ + DBG_LOG_GLES20("FixedFunctionProgramGLES20::ApplyFFGpuProgram()"); + + DBG_LOG_GLES20("GLSL: apply fixed-function program id=%i\n", m_GLSLProgram); + GLSLUseProgramGLES20 (m_GLSLProgram); + + // Apply float/vector parameters + const GpuProgramParameters::ValueParameterArray& valueParams = m_Params.GetValueParams(); + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for( GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i ) + { + if(i->m_RowCount == 1 && i->m_ArraySize == 1) + { + UniformCacheGLES20* cache = &m_UniformCache; + const float * val = values.GetVectorParam((BuiltinShaderVectorParam)i->m_Name.BuiltinIndex()).GetPtr(); + switch (i->m_ColCount) + { + case 1: CachedUniform1(cache, kShaderParamFloat, i->m_Index, val); break; + case 2: CachedUniform2(cache, kShaderParamFloat, i->m_Index, val); break; + case 3: CachedUniform3(cache, kShaderParamFloat, i->m_Index, val); break; + case 4: CachedUniform4(cache, kShaderParamFloat, i->m_Index, val); break; + default: break; + } + } + else + { + // Apply matrix parameters + DebugAssert (i->m_ArraySize == 1); + const Matrix4x4f& mat = values.GetMatrixParam((BuiltinShaderMatrixParam)i->m_Name.BuiltinIndex()); + if (i->m_RowCount == 3 && i->m_ColCount == 3) + { + Matrix3x3f m33 = Matrix3x3f(mat); + GLES_CHK(glUniformMatrix3fv (i->m_Index, 1, GL_FALSE, m33.GetPtr())); + } + else + { + const float *ptr = mat.GetPtr (); + GLES_CHK(glUniformMatrix4fv (i->m_Index, 1, GL_FALSE, ptr)); + } + DBG_GLSL_BINDINGS_GLES20(" FFmatrix %i (%s)", i->m_Index, i->m_Name.GetName() ); + } + } + + GLESAssert(); +} + + +#if UNITY_ANDROID || UNITY_BLACKBERRY || UNITY_TIZEN +//----------------------------------------------------------------------------- +// md5 internals are extracted from External/MurmurHash/md5.cpp + struct + md5_context + { + unsigned long total[2]; + unsigned long state[4]; + unsigned char buffer[64]; + unsigned char ipad[64]; + unsigned char opad[64]; + }; + + extern void md5_starts(md5_context* ctx); + extern void md5_update(md5_context* ctx, unsigned char* input, int ilen); + extern void md5_finish(md5_context* ctx, unsigned char output[16]); +#endif + + +static void GetCachedBinaryName(const std::string& vprog, const std::string& fshader, char filename[33]) +{ +// we have caching only on android, so no need to worry (at least for now) about md5 +#if UNITY_ANDROID || UNITY_BLACKBERRY || UNITY_TIZEN + + unsigned char hash[16] = {0}; + + md5_context ctx; + md5_starts(&ctx); + md5_update(&ctx, (unsigned char*)vprog.c_str(), vprog.length()); + md5_update(&ctx, (unsigned char*)fshader.c_str(), fshader.length()); + md5_finish(&ctx, hash); + + BytesToHexString(hash, 16, filename); + +#else + + (void)vprog; + (void)fshader; + ::memset(filename, '1', 33); + +#endif +} + + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/GpuProgramsGLES20.h b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20.h new file mode 100644 index 0000000..a9a14d2 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20.h @@ -0,0 +1,78 @@ +#ifndef GPUPROGRAMSGLES20_H +#define GPUPROGRAMSGLES20_H + + +#if !GFX_SUPPORTS_OPENGLES20 +#error "Should not include GpuProgramsGLES20 on this platform" +#endif + + +#include "Runtime/GfxDevice/GpuProgram.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/Utilities/GLSLUtilities.h" +#include "IncludesGLES20.h" +#include "GpuProgramsGLES20_UniformCache.h" + +class GlslGpuProgramGLES20 : public GpuProgramGL +{ +public: + GlslGpuProgramGLES20 (const std::string& source, CreateGpuProgramOutput& output); + ~GlslGpuProgramGLES20(); + + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) { Assert(!"Should not be used"); } + + // Returns the permutation index used + int ApplyGpuProgramES20 (const GpuProgramParameters& params, const UInt8 *buffer); + int GetGLProgram (FogMode fog, GpuProgramParameters& outParams, ChannelAssigns& channels); + + static bool InitBinaryShadersSupport(); + + + UniformCacheGLES20 m_UniformCache[kFogModeCount]; + +private: + static void FillParams (unsigned int programID, GpuProgramParameters& params, PropertyNamesSet* outNames); + + bool Create (const std::string& source, ChannelAssigns& channels); + + bool CompileProgram(unsigned index, const std::string& vprog, const std::string& fshader, ChannelAssigns& channels); + +private: + std::string m_VertexShaderSourceForFog; + GLShaderID m_GLSLVertexShader[kFogModeCount]; + GLShaderID m_GLSLFragmentShader[kFogModeCount]; + int m_FogColorIndex[kFogModeCount]; + int m_FogParamsIndex[kFogModeCount]; + bool m_FogFailed[kFogModeCount]; + + static std::string _CachePath; + static glGetProgramBinaryOESFunc _glGetProgramBinaryOES; + static glProgramBinaryOESFunc _glProgramBinaryOES; +}; + + +class FixedFunctionProgramGLES20 +{ +public: + FixedFunctionProgramGLES20(GLShaderID vertexShader, GLShaderID fragmentShader); + ~FixedFunctionProgramGLES20(); + + void ApplyFFGpuProgram(const BuiltinShaderParamValues& values) const; + const BuiltinShaderParamIndices& GetBuiltinParams() const { return m_Params.GetBuiltinParams(); } + + mutable UniformCacheGLES20 m_UniformCache; + +protected: + GLShaderID Create(GLShaderID vertexShader, GLShaderID fragmentShader); + +private: + GLShaderID m_GLSLProgram; + GLShaderID m_GLSLVertexShader, m_GLSLFragmentShader; + + GpuProgramParameters m_Params; +}; + +bool CompileGlslShader(GLShaderID shader, GLSLErrorType type, const char* source); + +#endif diff --git a/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.cpp b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.cpp new file mode 100644 index 0000000..db725d2 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.cpp @@ -0,0 +1,72 @@ +#include "UnityPrefix.h" +#if !GFX_SUPPORTS_OPENGLES20 +#error "Should not include GpuProgramsGLES20 on this platform" +#endif + +#include "GpuProgramsGLES20_UniformCache.h" + +#include "Runtime/Allocator/MemoryMacros.h" +#include "Runtime/GfxDevice/GpuProgram.h" +#include "IncludesGLES20.h" +#include "AssertGLES20.h" + + +void UniformCacheGLES20::Create(const GpuProgramParameters* params, int fogParamsIndex, int fogColorIndex) +{ + int lastUsedUniform = -1; + + // we will track only float/vector uniforms + GpuProgramParameters::ValueParameterArray::const_iterator paramI = params->GetValueParams().begin(); + GpuProgramParameters::ValueParameterArray::const_iterator paramEnd = params->GetValueParams().end(); + while(paramI != paramEnd) + { + if(paramI->m_RowCount == 1 && paramI->m_ArraySize == 1 && paramI->m_Index > lastUsedUniform) + lastUsedUniform = paramI->m_Index; + + ++paramI; + } + + const BuiltinShaderParamIndices& builtinParam = params->GetBuiltinParams(); + for(unsigned i = 0 ; i < kShaderInstanceVecCount ; ++i) + { + if(builtinParam.vec[i].gpuIndex > lastUsedUniform) + lastUsedUniform = builtinParam.vec[i].gpuIndex; + } + + if(fogParamsIndex > lastUsedUniform) lastUsedUniform = fogParamsIndex; + if(fogColorIndex > lastUsedUniform) lastUsedUniform = fogColorIndex; + + count = lastUsedUniform + 1; + uniform = (float*)UNITY_MALLOC_ALIGNED(kMemShader, count*4 * sizeof(float), 16); + memset(uniform, 0xff /* NaN */, count*4 * sizeof(float)); +} + +void UniformCacheGLES20::Destroy() +{ + count = 0; + + UNITY_FREE(kMemShader, uniform); + uniform = 0; +} + + +// In theory Uniform*f can also be used to load bool uniforms, in practice +// some drivers don't like that (e.g. PVR GLES2.0 Emu wants bools to be loaded +// via Uniform*i). So load both integers and bools via *i functions. +#define CACHED_UNIFORM_IMPL(Count) \ +void CachedUniform##Count(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val) \ +{ \ + if (cache->UpdateUniform(index, val, Count)) { \ + if (type == kShaderParamFloat) \ + GLES_CHK(glUniform##Count##fv(index, 1, val)); \ + else { \ + int ival[4] = {val[0],val[1],val[2],val[3]}; \ + GLES_CHK(glUniform##Count##iv(index, 1, ival)); \ + } \ + } \ +} \ + +CACHED_UNIFORM_IMPL(1); +CACHED_UNIFORM_IMPL(2); +CACHED_UNIFORM_IMPL(3); +CACHED_UNIFORM_IMPL(4); diff --git a/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h new file mode 100644 index 0000000..6f01fc4 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GpuProgramsGLES20_UniformCache.h @@ -0,0 +1,51 @@ +#pragma once + +#if !GFX_SUPPORTS_OPENGLES20 +#error "Should not include GpuProgramsGLES20 on this platform" +#endif + +#include "Runtime/Utilities/LogAssert.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include <string.h> + +class GpuProgramParameters; + +struct +UniformCacheGLES20 +{ + // for gles we must set values per-uniform (not per-registers like in dx) + // so there is no real need for dirty tracking. + // TODO: do unified impl with dirty tracking if/when we do "everything is an array" in gles + float* uniform; + unsigned count; + + UniformCacheGLES20() : uniform(0), count(0) {} + + // we will pre-alloc memory. Fog params are handled differently (not added to gpu params). + // TODO: make it more general, int* perhaps, or some struct + void Create(const GpuProgramParameters* params, int fogParamsIndex, int fogColorIndex); + void Destroy(); + + // returns true if you need to update for real + bool UpdateUniform(int index, const float* val, unsigned floatCount); +}; + +void CachedUniform1(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val); +void CachedUniform2(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val); +void CachedUniform3(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val); +void CachedUniform4(UniformCacheGLES20* cache, ShaderParamType type, int index, const float* val); + + +inline bool UniformCacheGLES20::UpdateUniform(int index, const float* val, unsigned floatCount) +{ + Assert(index < count); + const unsigned mem_sz = floatCount*sizeof(float); + + float* target = uniform + 4*index; + if(::memcmp(target, val, mem_sz)) + { + ::memcpy(target, val, mem_sz); + return true; + } + return false; +} diff --git a/Runtime/GfxDevice/opengles20/GpuPropertiesGLES20.cpp b/Runtime/GfxDevice/opengles20/GpuPropertiesGLES20.cpp new file mode 100644 index 0000000..0d808a1 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GpuPropertiesGLES20.cpp @@ -0,0 +1,70 @@ +#include "UnityPrefix.h" +#include "GpuPropertiesGLES20.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/GfxDevice/BuiltinShaderParams.h" +#include "Runtime/GfxDevice/BuiltinShaderParamsNames.h" + +#if GFX_SUPPORTS_OPENGLES20 + +struct GLSLESProperty +{ + GLSLESProperty(const char* _glName, const char* _glesName) : glName(_glName), unityName(_glesName) { } + const char* glName; + const char* unityName; +}; + +#define DEF_MAT_INTERNAL(name, builtin) GLSLESProperty(name, GetShaderInstanceMatrixParamName(builtin)) +#define DEF_MAT_BUILTIN(name, builtin) GLSLESProperty(name, GetBuiltinMatrixParamName(builtin)) +#define BIND_VEC_BUILTIN(name, builtin) GLSLESProperty(name, GetBuiltinVectorParamName(builtin)) + + +static const GLSLESProperty kglslesProperties[] = +{ + DEF_MAT_BUILTIN("gl_ProjectionMatrix", kShaderMatProj), + DEF_MAT_INTERNAL("gl_NormalMatrix", kShaderInstanceMatNormalMatrix), + DEF_MAT_INTERNAL("gl_ModelViewProjectionMatrix", kShaderInstanceMatMVP), + DEF_MAT_INTERNAL("gl_ModelViewMatrixTranspose", kShaderInstanceMatTransMV), + DEF_MAT_INTERNAL("gl_ModelViewMatrixInverseTranspose", kShaderInstanceMatInvTransMV), + DEF_MAT_INTERNAL("gl_ModelViewMatrix", kShaderInstanceMatMV), + + DEF_MAT_INTERNAL("gl_TextureMatrix0", kShaderInstanceMatTexture0), + DEF_MAT_INTERNAL("gl_TextureMatrix1", kShaderInstanceMatTexture1), + DEF_MAT_INTERNAL("gl_TextureMatrix2", kShaderInstanceMatTexture2), + DEF_MAT_INTERNAL("gl_TextureMatrix3", kShaderInstanceMatTexture3), + DEF_MAT_INTERNAL("gl_TextureMatrix4", kShaderInstanceMatTexture4), + DEF_MAT_INTERNAL("gl_TextureMatrix5", kShaderInstanceMatTexture5), + DEF_MAT_INTERNAL("gl_TextureMatrix6", kShaderInstanceMatTexture6), + DEF_MAT_INTERNAL("gl_TextureMatrix7", kShaderInstanceMatTexture7), + + BIND_VEC_BUILTIN("_glesLightSource[0].diffuse", kShaderVecLight0Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[1].diffuse", kShaderVecLight1Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[2].diffuse", kShaderVecLight2Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[3].diffuse", kShaderVecLight3Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[0].position", kShaderVecLight0Position), + BIND_VEC_BUILTIN("_glesLightSource[1].position", kShaderVecLight1Position), + BIND_VEC_BUILTIN("_glesLightSource[2].position", kShaderVecLight2Position), + BIND_VEC_BUILTIN("_glesLightSource[3].position", kShaderVecLight3Position), + BIND_VEC_BUILTIN("_glesLightSource[0].spotDirection", kShaderVecLight0SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[1].spotDirection", kShaderVecLight1SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[2].spotDirection", kShaderVecLight2SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[3].spotDirection", kShaderVecLight3SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[0].atten", kShaderVecLight0Atten), + BIND_VEC_BUILTIN("_glesLightSource[1].atten", kShaderVecLight1Atten), + BIND_VEC_BUILTIN("_glesLightSource[2].atten", kShaderVecLight2Atten), + BIND_VEC_BUILTIN("_glesLightSource[3].atten", kShaderVecLight3Atten), + BIND_VEC_BUILTIN("_glesLightModel.ambient", kShaderVecLightModelAmbient), +}; + + +const char* GetGLSLESPropertyNameRemap (const char* name) +{ + for (int i = 0; i < ARRAY_SIZE(kglslesProperties); i++) + { + const GLSLESProperty& prop = kglslesProperties[i]; + if (strcmp(name, prop.glName) == 0) + return prop.unityName; + } + return NULL; +} + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/GpuPropertiesGLES20.h b/Runtime/GfxDevice/opengles20/GpuPropertiesGLES20.h new file mode 100644 index 0000000..9caae9a --- /dev/null +++ b/Runtime/GfxDevice/opengles20/GpuPropertiesGLES20.h @@ -0,0 +1,3 @@ +#pragma once + +const char* GetGLSLESPropertyNameRemap (const char* name); diff --git a/Runtime/GfxDevice/opengles20/IncludesGLES20.h b/Runtime/GfxDevice/opengles20/IncludesGLES20.h new file mode 100644 index 0000000..260bea5 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/IncludesGLES20.h @@ -0,0 +1 @@ +#include "Runtime/GfxDevice/opengles/IncludesGLES.h"
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengles20/RenderTextureGLES20.cpp b/Runtime/GfxDevice/opengles20/RenderTextureGLES20.cpp new file mode 100644 index 0000000..d397c6e --- /dev/null +++ b/Runtime/GfxDevice/opengles20/RenderTextureGLES20.cpp @@ -0,0 +1,958 @@ +#include "UnityPrefix.h" +#include "RenderTextureGLES20.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Utilities/BitUtility.h" +#include "Runtime/Graphics/RenderSurface.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Graphics/ScreenManager.h" +#include "IncludesGLES20.h" +#include "AssertGLES20.h" +#include "DebugGLES20.h" +#include "TextureIdMapGLES20.h" +#include "UnityGLES20Ext.h" + +// seems like code is the best place to leave TODO: +// GetCurrentFBImpl - it is called in random places - should just put somehwere (begin frame?) +// discard logic - both color/depth have flags, but only color is used, also - mrt case + + + +#if UNITY_ANDROID + #include "PlatformDependent/AndroidPlayer/EntryPoint.h" +#endif + +#if 1 + #define DBG_LOG_RT_GLES20(...) {} +#else + #define DBG_LOG_RT_GLES20(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#endif + + +#if GFX_SUPPORTS_OPENGLES20 + +#define GL_RT_COMMON_GLES2 1 +#include "Runtime/GfxDevice/GLRTCommon.h" +#undef GL_RT_COMMON_GLES2 + +#if UNITY_IPHONE + extern "C" bool UnityDefaultFBOHasMSAA(); + extern "C" void* UnityDefaultFBOColorBuffer(); +#endif + + +struct RenderColorSurfaceGLES2 : public RenderSurfaceBase +{ + GLuint m_ColorBuffer; + RenderTextureFormat format; + TextureDimension dim; +}; + +struct RenderDepthSurfaceGLES2 : public RenderSurfaceBase +{ + GLuint m_DepthBuffer; + DepthBufferFormat depthFormat; + bool depthWithStencil; +}; + +extern GLint gDefaultFBO; +static bool gDefaultFboInited = false; + +static const unsigned long kOpenGLESTextureDimensionTable[kTexDimCount] = {0, 0, GL_TEXTURE_2D, 0, GL_TEXTURE_CUBE_MAP, 0}; + +static RenderColorSurfaceGLES2* s_ActiveColorTarget[kMaxSupportedRenderTargets] = {0}; +static int s_ActiveColorTargetCount = 0; +static int s_ActiveMip = 0; +static CubemapFace s_ActiveFace = kCubeFaceUnknown; +static RenderDepthSurfaceGLES2* s_ActiveDepthTarget = 0; + +static RenderColorSurfaceGLES2 s_BackBufferColor; +static RenderDepthSurfaceGLES2 s_BackBufferDepth; + + +// at least on ios when changing ext of attachments there is huge perf penalty +// so do fbo per rt-ext + +typedef std::pair<unsigned, unsigned> FBKey; +typedef std::map<FBKey, GLuint> FBMap; + +static FBMap _FBMap; +static GLuint GetFBFromAttachments(RenderColorSurfaceGLES2* color, RenderDepthSurfaceGLES2* depth) +{ + // while it may seems bad that we freely mix rb/texture - we do the distinction per-gpu/per-platform mostly + // so it is actually ok + unsigned ckey = color->textureID.m_ID ? color->textureID.m_ID : color->m_ColorBuffer; + unsigned dkey = depth->textureID.m_ID ? depth->textureID.m_ID : depth->m_DepthBuffer; + FBKey key = std::make_pair(ckey, dkey); + + + FBMap::iterator fbi = _FBMap.find(key); + if(fbi == _FBMap.end()) + { + GLuint fb=0; + GLES_CHK(glGenFramebuffers(1, &fb)); + + fbi = _FBMap.insert(std::make_pair(key, fb)).first; + } + + Assert(fbi != _FBMap.end()); + return fbi->second; +} + +// this should be called on context loss +// TODO: need we care about the case of actually deleting FBOs +void ClearFBMapping() +{ + _FBMap.clear(); +} + +// this is not the best way, but unless we have proper rt->fbo mapping let's live with that +// the reason is to avoid leaks when we destroy rb/tex that is still attached to some FBO +static void OnFBOAttachmentDelete(RenderSurfaceBase* rs) +{ + unsigned key = rs->textureID.m_ID; + if(key == 0) + key = rs->colorSurface ? ((RenderColorSurfaceGLES2*)rs)->m_ColorBuffer : ((RenderDepthSurfaceGLES2*)rs)->m_DepthBuffer; + + int curFB = GetCurrentFBGLES2(); + + for(FBMap::iterator i = _FBMap.begin() ; i != _FBMap.end() ; ) + { + if(i->first.first == key || i->first.second == key) + { + // make sure we also drop attachments before killing FBO (some drivers may leak otherwise) + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, i->second)); + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0)); + GLES_CHK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0)); + GLES_CHK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0)); + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, curFB)); + + GLES_CHK(glDeleteFramebuffers(1, &i->second)); + FBMap::iterator rem = i; + ++i; + _FBMap.erase(rem); + } + else + { + ++i; + } + } +} + +static const char* GetFBOStatusError( GLenum status ) +{ + Assert( status != GL_FRAMEBUFFER_COMPLETE ); // should not be called when everything is ok... + switch( status ) + { + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "INCOMPLETE_ATTACHMENT"; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "INCOMPLETE_MISSING_ATTACHMENT"; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: return "INCOMPLETE_DIMENSIONS"; + case GL_FRAMEBUFFER_UNSUPPORTED: return "UNSUPPORTED"; + default: return "unknown error"; + } +} +static const char* GetFBOAttachementType(GLint type) +{ + switch (type) + { + case GL_RENDERBUFFER: return "GL_RENDERBUFFER"; + case GL_TEXTURE: return "GL_TEXTURE"; + default: return "GL_NONE"; + } +} + +static int GetCurrentFBImpl() +{ + GLint curFB; + GLES_CHK(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curFB)); + + return (int)curFB; +} + +int GetCurrentFBGLES2() +{ + return GetCurrentFBImpl(); +} + +void EnsureDefaultFBInitedGLES2() +{ + if(!gDefaultFboInited) + { + gDefaultFBO = GetCurrentFBImpl(); + // this will be called from correct thread, so no need to sync or whatever + extern void GfxDeviceGLES20_InitFramebufferDepthFormat(); + GfxDeviceGLES20_InitFramebufferDepthFormat(); + + gDefaultFboInited = true; + } +} + +void DiscardCurrentFBImpl(bool discardColor, bool discardDepth, GLenum target=GL_FRAMEBUFFER) +{ + if(gGraphicsCaps.gles20.hasDiscardFramebuffer) + { + // TODO: mrt case? + GLenum discardUserAttach[] = {GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; + GLenum discardSystemAttach[] = {GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT}; + + const GLenum* discardTarget = discardUserAttach; + if(s_ActiveColorTarget[0]->backBuffer && GetCurrentFBGLES2() == 0) + discardTarget = discardSystemAttach; + + + if(!discardColor) discardTarget += 1; + + unsigned discardCount = 0; + if(discardColor) discardCount += 1; + if(discardDepth) discardCount += 2; + + if(discardCount) + GLES_CHK(gGlesExtFunc.glDiscardFramebufferEXT(GL_FRAMEBUFFER, discardCount, discardTarget)); + } +} + +void ClearCurrentFBImpl(bool clearColor, bool clearDepth) +{ + if(gGraphicsCaps.hasTiledGPU) + { + UInt32 clearFlags = (clearColor ? kGfxClearColor : 0) | (clearDepth ? kGfxClearDepthStencil : 0); + float clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f}; + + GetRealGfxDevice().Clear(clearFlags, clearColor, 1.0f, 0); + } +} + +enum +{ + discardDiscardFB = 0, + discardClearFB = 1 +}; + +static void DiscardContentsImpl(int discardPhase) +{ + // TODO: mrt? + if(s_ActiveColorTarget[0] || s_ActiveDepthTarget) + { + bool* colorVar = discardPhase == discardDiscardFB ? &s_ActiveColorTarget[0]->shouldDiscard : &s_ActiveColorTarget[0]->shouldClear; + bool* depthVar = discardPhase == discardDiscardFB ? &s_ActiveDepthTarget->shouldDiscard : &s_ActiveDepthTarget->shouldClear; + + bool color = *colorVar, depth = *depthVar; + + *colorVar = *depthVar = false; + + if(color || depth) + { + if(discardPhase == discardDiscardFB) DiscardCurrentFBImpl(color, depth); + else ClearCurrentFBImpl(color, depth); + } + } +} + + +void DiscardContentsGLES2(RenderSurfaceHandle rs) +{ + // TODO: handle bb + if(rs.IsValid()) + { + RenderColorSurfaceGLES2* rsgles = reinterpret_cast<RenderColorSurfaceGLES2*>(rs.object); + // discard only makes sense for current active rt + rsgles->shouldDiscard = gGraphicsCaps.gles20.hasDiscardFramebuffer && rsgles == s_ActiveColorTarget[0]; + rsgles->shouldClear = gGraphicsCaps.hasTiledGPU; + } +} + +bool SetRenderTargetGLES2 (int count, RenderSurfaceHandle* colorHandle, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, GLuint globalSharedFBO) +{ + RenderColorSurfaceGLES2* rcolor0 = reinterpret_cast<RenderColorSurfaceGLES2*>( colorHandle[0].object ); + RenderDepthSurfaceGLES2* rdepth = reinterpret_cast<RenderDepthSurfaceGLES2*>( depthHandle.object ); + + // Exit if nothing to do + if( s_ActiveColorTargetCount == count && s_ActiveDepthTarget == rdepth && s_ActiveFace == face && s_ActiveMip == mipLevel ) + { + bool colorSame = true; + for(int i = 0 ; i < count && colorSame ; ++i) + { + if(s_ActiveColorTarget[i] != reinterpret_cast<RenderColorSurfaceGLES2*>(colorHandle[i].object)) + colorSame = false; + } + if (colorSame) + return false; + } + + EnsureDefaultFBInitedGLES2(); + DiscardContentsImpl(discardDiscardFB); + + AssertIf (!gGraphicsCaps.hasRenderToTexture); + GetRealGfxDevice().GetFrameStats().AddRenderTextureChange(); // stats + + + Assert(colorHandle[0].IsValid() && depthHandle.IsValid()); + Assert(colorHandle[0].object->backBuffer == depthHandle.object->backBuffer); + + + GLenum colorAttachStart = GL_COLOR_ATTACHMENT0; + if(gGraphicsCaps.gles20.hasNVMRT) + colorAttachStart = GL_COLOR_ATTACHMENT0_NV; + + Assert(gGraphicsCaps.gles20.hasNVMRT || count==1); + + if(!rcolor0->backBuffer) + { + GLuint fb = GetFBFromAttachments(rcolor0, rdepth); + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, fb)); + + GLenum drawBuffers[kMaxSupportedRenderTargets] = {0}; + for(int i = 0 ; i < count ; ++i) + { + // when we start to support EXT variant - add check here + GLenum colorAttach = colorAttachStart + i; + RenderColorSurfaceGLES2* rcolor = reinterpret_cast<RenderColorSurfaceGLES2*>(colorHandle[i].object); + Assert(rcolor->colorSurface); + + GLuint targetColorTex = (GLuint)TextureIdMap::QueryNativeTexture(rcolor->textureID); + + drawBuffers[i] = colorAttach; + if(!IsDepthRTFormat(rcolor->format) && targetColorTex) + { + if (rcolor->dim == kTexDimCUBE) + { + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttach, GL_TEXTURE_CUBE_MAP_POSITIVE_X + clamp<int>(face,0,5), targetColorTex, mipLevel)); + } + else + { + if(rcolor->samples > 1 && gGraphicsCaps.gles20.hasImgMSAA) + GLES_CHK(gGlesExtFunc.glFramebufferTexture2DMultisampleIMG(GL_FRAMEBUFFER, colorAttach, GL_TEXTURE_2D, targetColorTex, mipLevel, rcolor->samples)); + else + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, colorAttach, GL_TEXTURE_2D, targetColorTex, mipLevel)); + } + } + else + { + GLES_CHK(glFramebufferRenderbuffer (GL_FRAMEBUFFER, colorAttach, GL_RENDERBUFFER, rcolor->m_ColorBuffer)); + if(rcolor->m_ColorBuffer == 0) + drawBuffers[i] = GL_NONE; + } + } + + if(gGraphicsCaps.gles20.hasNVMRT) + gGlesExtFunc.glDrawBuffersNV(count, drawBuffers); + + GLuint targetDepthTex = (GLuint)TextureIdMap::QueryNativeTexture(rdepth->textureID); + bool needAttachStencil = gGraphicsCaps.hasStencil && rdepth->depthWithStencil; + + // depth surface + AssertIf (rdepth->colorSurface); + if (targetDepthTex +#if UNITY_PEPPER +// Workaround for http://code.google.com/p/angleproject/issues/detail?id=211 + || rdepth->m_DepthBuffer == 0 +#endif + ) + { + DBG_LOG_RT_GLES20("glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, %d, 0);", rdepth->textureID.m_ID); + GLES_CHK(glFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, targetDepthTex, 0)); + // A driver might not support attaching depth & stencil as textures here. + if (!gGraphicsCaps.hasRenderTargetStencil) + needAttachStencil = false; + if (needAttachStencil) + GLES_CHK(glFramebufferTexture2D (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, targetDepthTex, 0)); + else + GLES_CHK(glFramebufferTexture2D (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0)); + } + else + { + DBG_LOG_RT_GLES20("glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, %d, 0);", rdepth->m_DepthBuffer); + GLES_CHK(glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rdepth->m_DepthBuffer)); + if(needAttachStencil) + GLES_CHK(glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rdepth->m_DepthBuffer)); + else + GLES_CHK(glFramebufferRenderbuffer (GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0)); + } + + GLenum status = glCheckFramebufferStatus (GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + { + int colorParam, depthParam, stencilParam; + int colorValue, depthValue, stencilValue; + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &colorParam); + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &depthParam); + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &stencilParam); + + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &colorValue); + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &depthValue); + glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &stencilValue); + + AssertString (Format( + "FBO fail: %s\nDetailed description:\n" + "GL_COLOR_ATTACHMENT0 Type:%s Value:%d\n" + "GL_DEPTH_ATTACHMENT Type:%s Value:%d\n" + "GL_STENCIL_ATTACHEMENT Type:%s Value:%d\n", + GetFBOStatusError(status), + GetFBOAttachementType(colorParam), colorValue, + GetFBOAttachementType(depthParam), depthValue, + GetFBOAttachementType(stencilParam), stencilValue)); + } + Assert(status == GL_FRAMEBUFFER_COMPLETE); + } + else + { + Assert(rcolor0->backBuffer && rdepth->backBuffer); // OpenGL can't mix FBO and native window at once + GLES_CHK(glBindFramebuffer( GL_FRAMEBUFFER, gDefaultFBO )); + } + + // If we previously had a mip-mapped render texture, generate mip levels for it now. + if (s_ActiveColorTarget[0] && + (s_ActiveColorTarget[0]->flags & kSurfaceCreateMipmap) && + (s_ActiveColorTarget[0]->flags & kSurfaceCreateAutoGenMips)) + { + const int textureTarget = kOpenGLESTextureDimensionTable[s_ActiveColorTarget[0]->dim]; + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, s_ActiveColorTarget[0]->textureID, s_ActiveColorTarget[0]->dim, std::numeric_limits<float>::infinity()); + GLES_CHK(glGenerateMipmap(textureTarget)); + } + + s_ActiveColorTargetCount = count; + for(int i = 0 ; i < count ; ++i) + s_ActiveColorTarget[i] = reinterpret_cast<RenderColorSurfaceGLES2*>(colorHandle[i].object); + + s_ActiveDepthTarget = rdepth; + s_ActiveFace = face; + s_ActiveMip = mipLevel; + + DiscardContentsImpl(discardClearFB); + + return true; +} + +// TODO: take index into account here too +RenderSurfaceHandle GetActiveRenderColorSurfaceGLES2() +{ + return RenderSurfaceHandle(s_ActiveColorTarget[0]); +} +RenderSurfaceHandle GetActiveRenderDepthSurfaceGLES2() +{ + return RenderSurfaceHandle(s_ActiveDepthTarget); +} + +bool IsActiveRenderTargetWithColorGLES2() +{ + return !s_ActiveColorTarget[0] || s_ActiveColorTarget[0]->backBuffer || !IsDepthRTFormat (s_ActiveColorTarget[0]->format); +} + + +static void CreateFBORenderColorSurfaceGLES (RenderColorSurfaceGLES2& rs) +{ + int textureTarget = kOpenGLESTextureDimensionTable[rs.dim]; + + if( !IsDepthRTFormat(rs.format) ) + { + GLenum internalFormat = (rs.flags & kSurfaceCreateSRGB) ? RTColorInternalFormatSRGBGLES2(rs.format) : RTColorInternalFormatGLES2(rs.format); + GLenum textureFormat = (rs.flags & kSurfaceCreateSRGB) ? RTColorTextureFormatSRGBGLES2(rs.format) : RTColorTextureFormatGLES2(rs.format); + GLenum textureType = RTColorTextureTypeGLES2(rs.format); + + // Create texture to render for color + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, rs.textureID, rs.dim, std::numeric_limits<float>::infinity()); + + if (rs.dim == kTexDimCUBE) + { + // cubemap: initialize all faces + for( int f = 0; f < 6; ++f ) + { + glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, 0, internalFormat, rs.width, rs.height, 0, textureFormat, textureType, NULL ); + } + DBG_LOG_RT_GLES20("Creating FBO Color Surface (GL_TEXTURE_CUBE_MAP) [%d] - Width(%d) x Height(%d)", rs.textureID.m_ID, rs.width, rs.height); + if (rs.flags & kSurfaceCreateMipmap) { // establish mip map chain if needed + GLES_CHK(glGenerateMipmap( textureTarget )); + } + } + // not the best way around, but oh well + else if(!rs.textureID.m_ID) + { + internalFormat = RBColorInternalFormatGLES2(rs.format); + GLES_CHK(glGenRenderbuffers(1, &rs.m_ColorBuffer)); + GLES_CHK(glBindRenderbuffer(GL_RENDERBUFFER, rs.m_ColorBuffer)); + if(rs.samples > 1 && gGraphicsCaps.gles20.hasAppleMSAA) + GLES_CHK(gGlesExtFunc.glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, rs.samples, internalFormat, rs.width, rs.height)); + else + GLES_CHK(glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, rs.width, rs.height)); + } + else + { + // regular texture: initialize + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); + GLES_CHK(glTexImage2D( textureTarget, 0, internalFormat, rs.width, rs.height, 0, textureFormat, textureType, NULL )); + + DBG_LOG_RT_GLES20("Creating FBO Color Surface (GL_TEXTURE_2D) [%d] - Width(%d) x Height(%d)", rs.textureID.m_ID, rs.width, rs.height); + if (rs.flags & kSurfaceCreateMipmap) { // establish mip map chain if needed + GLES_CHK(glGenerateMipmap( textureTarget )); + } + } + } + else + { + // Note : For GLES2.0Emu and NaCl we must create RenderBuffer even if no color + #if UNITY_WIN || UNITY_NACL + glGenRenderbuffers( 1, &rs.m_ColorBuffer ); + glBindRenderbuffer( GL_RENDERBUFFER, rs.m_ColorBuffer ); + glRenderbufferStorage( GL_RENDERBUFFER, GL_RGBA4, rs.width, rs.height ); + DBG_LOG_RT_GLES20("Creating dummy color buffer (GL_RENDERBUFFER) [%d] - Width(%d) x Height(%d)", rs.m_ColorBuffer, rs.width, rs.height); + #endif + } +} + + +static void CreateFBORenderDepthSurfaceGLES (RenderDepthSurfaceGLES2& rs) +{ + int textureTarget = kOpenGLESTextureDimensionTable[kTexDim2D]; + + GLenum depthFormat; + GLenum genericFormat; + GLenum typeFormat; + + // TODO 24bit depth should be revisited + if (rs.depthFormat == kDepthFormat24 && gGraphicsCaps.hasStencil) + { + rs.depthWithStencil = true; + depthFormat = GL_DEPTH24_STENCIL8_OES; + genericFormat = GL_DEPTH_STENCIL_OES; + typeFormat = GL_UNSIGNED_INT_24_8_OES; + } + else if (rs.depthFormat == kDepthFormat24 && gGraphicsCaps.gles20.has24DepthForFBO) + { + depthFormat = GL_DEPTH_COMPONENT24_OES; + genericFormat = GL_DEPTH_COMPONENT; + typeFormat = GL_UNSIGNED_BYTE; + } + else if (gGraphicsCaps.gles20.hasNLZ) + { + depthFormat = 0x8E2C; // GL_DEPTH_COMPONENT16_NONLINEAR_NV + genericFormat = GL_DEPTH_COMPONENT; + typeFormat = GL_UNSIGNED_SHORT; + } + else + { + depthFormat = GL_DEPTH_COMPONENT16; + genericFormat = GL_DEPTH_COMPONENT; + typeFormat = GL_UNSIGNED_SHORT; + } + + GLuint targetDepthTex = (GLuint)TextureIdMap::QueryNativeTexture(rs.textureID); + if (!targetDepthTex) + { + // Note : For GLES2.0Emu we must create RenderBuffer even if depth format is none +#if !UNITY_WIN + if( rs.depthFormat != kDepthFormatNone ) +#endif + { + GLES_CHK(glGenRenderbuffers( 1, &rs.m_DepthBuffer )); + GLES_CHK(glBindRenderbuffer( GL_RENDERBUFFER, rs.m_DepthBuffer )); + + if(rs.samples > 1) + { + if(gGraphicsCaps.gles20.hasAppleMSAA) + GLES_CHK(gGlesExtFunc.glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, rs.samples, depthFormat, rs.width, rs.height)); + else if(gGraphicsCaps.gles20.hasImgMSAA) + GLES_CHK(gGlesExtFunc.glRenderbufferStorageMultisampleIMG(GL_RENDERBUFFER, rs.samples, depthFormat, rs.width, rs.height)); + } + else + { + GLES_CHK(glRenderbufferStorage( GL_RENDERBUFFER, depthFormat, rs.width, rs.height )); + } + + DBG_LOG_RT_GLES20("Creating FBO Depth Surface (GL_RENDERBUFFER) [%d] - Width(%d) x Height(%d)", rs.m_DepthBuffer, rs.width, rs.height); + } + } + else + { + // create depth texture + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, rs.textureID, kTexDim2D, std::numeric_limits<float>::infinity()); + GLES_CHK(glTexImage2D( textureTarget, 0, genericFormat, rs.width, rs.height, 0, genericFormat, typeFormat, NULL )); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + if (rs.flags & kSurfaceCreateShadowmap) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_EXT, GL_COMPARE_REF_TO_TEXTURE_EXT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_EXT, GL_LEQUAL); + } + + DBG_LOG_RT_GLES20("Creating FBO Depth Surface (GL_TEXTURE_2D) [%d] - Width(%d) x Height(%d)", rs.textureID.m_ID, rs.width, rs.height); + } +} + +static RenderColorSurfaceGLES2* CreateRenderColorSurfaceGLES2Impl(void* rs, TextureID textureID, unsigned rbID, int width, int height, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, int samples) +{ + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(textureID); + Assert(rbID == 0 || targetTex == 0); + + if( !gGraphicsCaps.hasRenderToTexture || !gGraphicsCaps.supportsRenderTextureFormat[format] ) + return 0; + + RenderColorSurfaceGLES2* ret = rs ? (RenderColorSurfaceGLES2*)rs : new RenderColorSurfaceGLES2; + RenderSurfaceBase_InitColor(*ret); + ret->width = width; + ret->height = height; + ret->format = format; + ret->dim = dim; + ret->flags = createFlags; + ret->samples = samples > gGraphicsCaps.gles20.maxSamples ? gGraphicsCaps.gles20.maxSamples : samples; + + ret->textureID = textureID; + ret->m_ColorBuffer = rbID; + + if(textureID.m_ID && !rbID) + TextureIdMapGLES20_QueryOrCreate(textureID); + + return ret; +} + +RenderSurfaceHandle CreateRenderColorSurfaceGLES2 (TextureID textureID, unsigned rbID, int width, int height, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, int samples) +{ + RenderColorSurfaceGLES2* rs = CreateRenderColorSurfaceGLES2Impl(0, textureID, rbID, width, height, dim, createFlags, format, samples); + if(rs) + CreateFBORenderColorSurfaceGLES(*rs); + + return RenderSurfaceHandle(rs); +} + +static RenderDepthSurfaceGLES2* CreateRenderDepthSurfaceGLES2Impl(void* rs, TextureID textureID, unsigned rbID, int width, int height, UInt32 createFlags, DepthBufferFormat depthFormat, int samples) +{ + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(textureID); + Assert(rbID == 0 || targetTex == 0); + + if( !gGraphicsCaps.hasRenderToTexture ) + return 0; + + RenderDepthSurfaceGLES2* ret = rs ? (RenderDepthSurfaceGLES2*)rs : new RenderDepthSurfaceGLES2; + RenderSurfaceBase_InitDepth(*ret); + ret->depthWithStencil = false; + ret->width = width; + ret->height = height; + ret->depthFormat = depthFormat; + ret->flags = createFlags; + ret->samples = samples > gGraphicsCaps.gles20.maxSamples ? gGraphicsCaps.gles20.maxSamples : samples; + + ret->textureID = textureID; + ret->m_DepthBuffer = rbID; + + if(textureID.m_ID && !rbID) + TextureIdMapGLES20_QueryOrCreate(textureID); + + return ret; +} + + +RenderSurfaceHandle CreateRenderDepthSurfaceGLES2 (TextureID textureID, unsigned rbID, int width, int height, UInt32 createFlags, DepthBufferFormat depthFormat, int samples) +{ + RenderDepthSurfaceGLES2* rs = CreateRenderDepthSurfaceGLES2Impl(0, textureID, rbID, width, height, createFlags, depthFormat, samples); + if(rs) + CreateFBORenderDepthSurfaceGLES(*rs); + + return RenderSurfaceHandle(rs); +} + + +static void InternalDestroyRenderSurfaceGLES (RenderSurfaceBase* rs) +{ + AssertIf( !rs ); + + if (rs->textureID.m_ID) + { + GetRealGfxDevice().DeleteTexture( rs->textureID ); + DBG_LOG_RT_GLES20("Destroying GL_TEXTURE_2D/GL_CUBE_MAP %d", rs->textureID.m_ID); + } + GLESAssert (); + + + RenderSurfaceHandle defaultColor = GetRealGfxDevice().GetBackBufferColorSurface(); + RenderSurfaceHandle defaultDepth = GetRealGfxDevice().GetBackBufferDepthSurface(); + + + for (int i = 0 ; i < s_ActiveColorTargetCount ; ++i) + { + if (s_ActiveColorTarget[i] == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + SetRenderTargetGLES2 (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, gDefaultFBO); + } + } + if (s_ActiveDepthTarget == rs) + { + ErrorString( "RenderTexture warning: Destroying active render texture. Switching to main context." ); + SetRenderTargetGLES2 (1, &defaultColor, defaultDepth, 0, kCubeFaceUnknown, gDefaultFBO); + } + + OnFBOAttachmentDelete(rs); + + if (rs->colorSurface) + { + RenderColorSurfaceGLES2* rsc = static_cast<RenderColorSurfaceGLES2*>(rs); + if( rsc->m_ColorBuffer ) + { + GLES_CHK(glDeleteRenderbuffers( 1, &rsc->m_ColorBuffer )); + DBG_LOG_RT_GLES20("Destroying GL_RENDER_BUFFER %d", rsc->m_ColorBuffer); + } + } + else + { + RenderDepthSurfaceGLES2* rsd = static_cast<RenderDepthSurfaceGLES2*>(rs); + if( rsd->m_DepthBuffer ) + { + GLES_CHK(glDeleteRenderbuffers( 1, &rsd->m_DepthBuffer )); + DBG_LOG_RT_GLES20("Destroying GL_RENDER_BUFFER %d", rsd->m_DepthBuffer); + } + } +} + + +void DestroyRenderSurfaceGLES2 (RenderSurfaceHandle& rsHandle) +{ + if(rsHandle.object->backBuffer) + return; + + RenderSurfaceBase* rs = rsHandle.object; + InternalDestroyRenderSurfaceGLES (rs); + delete rs; + rsHandle.object = NULL; +} + +void ResolveMSAA(GLuint dstTex, GLuint srcRB, GLuint globalSharedFBO, GLuint helperFBO) +{ + if(gGraphicsCaps.gles20.hasAppleMSAA) + { + GLint oldFBO; + GLES_CHK(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO)); + + GLES_CHK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, globalSharedFBO)); + GLES_CHK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER_APPLE, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dstTex, 0)); + GLES_CHK(glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_APPLE, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0)); + GLES_CHK(glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_APPLE, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0)); + ClearCurrentFBImpl(true, false); + + GLES_CHK(glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, helperFBO)); + GLES_CHK(glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER_APPLE, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, srcRB)); + GLES_CHK(gGlesExtFunc.glResolveMultisampleFramebufferAPPLE()); + + DiscardCurrentFBImpl(true, false, GL_READ_FRAMEBUFFER_APPLE); + GLES_CHK(glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER_APPLE, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0)); + + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, oldFBO)); + } +} + +RenderSurfaceBase* ResolveMSAASetupFBO(void* screenRS, int format, GLuint globalSharedFBO, GLuint helperFBO) +{ + RenderSurfaceHandle ret; + + RenderColorSurfaceGLES2* screen = (RenderColorSurfaceGLES2*)screenRS; + if(gGraphicsCaps.gles20.hasAppleMSAA) + { + TextureID texid = GetRealGfxDevice().CreateTextureID(); + ret = CreateRenderColorSurfaceGLES2(texid, 0, screen->width, screen->height, kTexDim2D, 0, (RenderTextureFormat)format, 1); + + GLuint gltex = (GLuint)TextureIdMap::QueryNativeTexture(texid); + ResolveMSAA(gltex, screen->m_ColorBuffer, globalSharedFBO, helperFBO); + + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, globalSharedFBO)); + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gltex, 0)); + } + + return ret.object; +} + +void ResolveMSAASetupFBO_Cleanup(RenderSurfaceBase* rs) +{ + RenderSurfaceHandle handle(rs); + + if(handle.IsValid()) + DestroyRenderSurfaceGLES2(handle); +} + + +void ResolveColorSurfaceGLES2(RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle, GLuint globalSharedFBO, GLuint helperFBO) +{ + // TODO: unify all the places we do resolve + + Assert (srcHandle.IsValid()); + Assert (dstHandle.IsValid()); + RenderColorSurfaceGLES2* src = reinterpret_cast<RenderColorSurfaceGLES2*>(srcHandle.object); + RenderColorSurfaceGLES2* dst = reinterpret_cast<RenderColorSurfaceGLES2*>(dstHandle.object); + if (!src->colorSurface || !dst->colorSurface) + { + WarningString("RenderTexture: Resolving non-color surfaces."); + return; + } + + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(dst->textureID); + if (!src->m_ColorBuffer || !targetTex) + { + WarningString("RenderTexture: Resolving NULL buffers."); + return; + } + + ResolveMSAA(targetTex, src->m_ColorBuffer, globalSharedFBO, helperFBO); +} + +void GrabIntoRenderTextureGLES2 (RenderSurfaceHandle rsHandle, RenderSurfaceHandle rdHandle, int x, int y, int width, int height, GLuint globalSharedFBO, GLuint helperFBO) +{ + if(!rsHandle.IsValid() || rsHandle.object->backBuffer) + return; + + RenderColorSurfaceGLES2* rs = reinterpret_cast<RenderColorSurfaceGLES2*>(rsHandle.object); + +#if UNITY_IPHONE + GLint oldFBO = 0; + RenderSurfaceBase* resolveRS = 0; + + if(IsActiveMSAARenderTargetGLES2() && gGraphicsCaps.gles20.hasAppleMSAA) + { + RenderColorSurfaceGLES2* screen = (RenderColorSurfaceGLES2*)UnityDefaultFBOColorBuffer(); + + bool fullScreenResolve = (x==0 && y==0 && width == screen->width && height == screen->height); + if(fullScreenResolve) + { + GLuint texColor = (GLuint)TextureIdMap::QueryNativeTexture(rs->textureID); + ResolveMSAA(texColor, screen->m_ColorBuffer, globalSharedFBO, helperFBO); + + return; + } + else + { + // intentional fall-through - we setup resolved FBO + GLES_CHK(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO)); + resolveRS = ResolveMSAASetupFBO(screen, rs->format, globalSharedFBO, helperFBO); + } + } +#endif + + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, rs->textureID, kTexDim2D, std::numeric_limits<float>::infinity()); + GLES_CHK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + + bool needsReadPixelsFallback = false; +#if UNITY_WIN + // GLES 2.0 Emulator seems to have a bug, in that it can only do glCopyTexSubImage2D for power of two textures. + needsReadPixelsFallback = !IsPowerOfTwo(rs->width) || !IsPowerOfTwo(rs->height); +#endif +#if UNITY_ANDROID + // on pre-honeycomb devices AND in case of EGL_ANDROID_framebuffer_target + // we may end up with alphabits=0 explicitely, which, on some devices, cases FB to be considered RGB + { + GLint rbits=0, gbits=0, bbits=0, abits=0; + CHECK(glGetIntegerv(GL_RED_BITS, &rbits)); + CHECK(glGetIntegerv(GL_GREEN_BITS, &gbits)); + CHECK(glGetIntegerv(GL_BLUE_BITS, &bbits)); + CHECK(glGetIntegerv(GL_ALPHA_BITS, &abits)); + + if(rbits==8 && gbits==8 && bbits==8 && abits==0) + needsReadPixelsFallback = true; + } +#endif + + if (needsReadPixelsFallback) + { + UInt8* data = NULL; + switch (rs->format) + { + case kRTFormatARGB32: + data = new UInt8[width*height*4]; + GLES_CHK(glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data)); + GLES_CHK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data)); + break; + + default: + ErrorStringMsg ("Unsupported render texture format :%d", rs->format); + break; + } + delete [] data; + } + else + { + GLES_CHK(glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, x, y, width, height)); + } + +#if UNITY_IPHONE + if(resolveRS) + { + ResolveMSAASetupFBO_Cleanup(resolveRS); + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, oldFBO)); + } +#endif +} + +RenderTextureFormat GetCurrentFBColorFormatGLES20() +{ + if( s_ActiveColorTarget[0] ) + return s_ActiveColorTarget[0]->format; + + return QueryFBColorFormatGLES2(); +} + +void InitBackBufferGLES2(RenderSurfaceBase** outColor, RenderSurfaceBase** outDepth) +{ + RenderSurfaceBase_InitColor(s_BackBufferColor); + s_BackBufferColor.backBuffer = true; + + RenderSurfaceBase_InitDepth(s_BackBufferDepth); + s_BackBufferDepth.backBuffer = true; + + *outColor = s_ActiveColorTarget[0] = &s_BackBufferColor; + *outDepth = s_ActiveDepthTarget = &s_BackBufferDepth; +} + +void SetBackBufferGLES2() +{ + s_ActiveColorTarget[0] = &s_BackBufferColor; + s_ActiveColorTargetCount= 0; + s_ActiveMip = 0; + s_ActiveFace = kCubeFaceUnknown; + + s_ActiveDepthTarget = &s_BackBufferDepth; + + EnsureDefaultFBInitedGLES2(); + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, gDefaultFBO)); +} + + +#if UNITY_IPHONE +bool IsActiveMSAARenderTargetGLES2() +{ + return s_ActiveColorTarget[0] && !s_ActiveColorTarget[0]->backBuffer ? s_ActiveColorTarget[0]->samples > 1 : UnityDefaultFBOHasMSAA(); +} + +void* UnityCreateUpdateExternalColorSurfaceGLES2(void* surf, unsigned texid, unsigned rbid, int width, int height, bool is32bit) +{ + TextureID tex = surf ? ((RenderSurfaceBase*)surf)->textureID : GetUncheckedGfxDevice().CreateTextureID(); + TextureIdMap::UpdateTexture(tex, texid); + + // TODO for android we will probably need to properly distinct 24/32 + RenderTextureFormat format = is32bit ? kRTFormatARGB32 : kRTFormatRGB565; + return CreateRenderColorSurfaceGLES2Impl(surf, tex, rbid, width, height, kTexDim2D, 0, format, 1); +} +void* UnityCreateUpdateExternalDepthSurfaceGLES2(void* surf, unsigned texid, unsigned rbid, int width, int height, bool is24bit) +{ + TextureID tex = surf ? ((RenderSurfaceBase*)surf)->textureID : GetUncheckedGfxDevice().CreateTextureID(); + TextureIdMap::UpdateTexture(tex, texid); + + DepthBufferFormat format = is24bit ? kDepthFormat24 : kDepthFormat16; + return CreateRenderDepthSurfaceGLES2Impl(surf, tex, rbid, width, height, 0, format, 1); +} + +void UnityDestroyExternalColorSurfaceGLES2(void* surf) +{ + delete (RenderColorSurfaceGLES2*)surf; +} +void UnityDestroyExternalDepthSurfaceGLES2(void* surf) +{ + delete (RenderDepthSurfaceGLES2*)surf; +} +#endif + + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/RenderTextureGLES20.h b/Runtime/GfxDevice/opengles20/RenderTextureGLES20.h new file mode 100644 index 0000000..b80a5a6 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/RenderTextureGLES20.h @@ -0,0 +1,40 @@ +#ifndef UNITY_RENDER_TEXTURES_GLES20_H_ +#define UNITY_RENDER_TEXTURES_GLES20_H_ + +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/GfxDeviceConfigure.h" +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "IncludesGLES20.h" + +RenderSurfaceHandle CreateRenderColorSurfaceGLES2 (TextureID textureID, unsigned rbID, int width, int height, TextureDimension dim, UInt32 createFlags, RenderTextureFormat format, int samples); +RenderSurfaceHandle CreateRenderDepthSurfaceGLES2 (TextureID textureID, unsigned rbID, int width, int height, UInt32 createFlags, DepthBufferFormat depthFormat, int samples); +void DestroyRenderSurfaceGLES2 (RenderSurfaceHandle& rsHandle); +bool SetRenderTargetGLES2 (int count, RenderSurfaceHandle* colorHandle, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, unsigned int globalSharedFBO); +RenderSurfaceHandle GetActiveRenderColorSurfaceGLES2 (); +RenderSurfaceHandle GetActiveRenderDepthSurfaceGLES2 (); +void GrabIntoRenderTextureGLES2 (RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height, GLuint globalSharedFBO, GLuint helperFBO); +void ResolveColorSurfaceGLES2(RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle, GLuint globalSharedFBO, GLuint helperFBO); +void DiscardContentsGLES2(RenderSurfaceHandle rs); + +int GetCurrentFBGLES2(); +void EnsureDefaultFBInitedGLES2(); + +RenderTextureFormat GetCurrentFBColorFormatGLES20(); + +void InitBackBufferGLES2(RenderSurfaceBase** color, RenderSurfaceBase** depth); +void SetBackBufferGLES2(); + +#if UNITY_IPHONE +void* UnityCreateExternalColorSurfaceGLES2(unsigned texid, unsigned rbid, int width, int height, bool is32bit); +void* UnityCreateExternalDepthSurfaceGLES2(unsigned texid, unsigned rbid, int width, int height, bool is24bit); +void UnityDestroyExternalColorSurfaceGLES2(void* surf); +void UnityDestroyExternalDepthSurfaceGLES2(void* surf); +#endif + +#if UNITY_IPHONE +bool IsActiveMSAARenderTargetGLES2(); +#endif + + +#endif diff --git a/Runtime/GfxDevice/opengles20/ShaderGeneratorGLES20.cpp b/Runtime/GfxDevice/opengles20/ShaderGeneratorGLES20.cpp new file mode 100644 index 0000000..c9f4e78 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/ShaderGeneratorGLES20.cpp @@ -0,0 +1,749 @@ +#include "UnityPrefix.h" +#include "FixedFunctionStateGLES20.h" +#include "ShaderGeneratorGLES20.h" +#include "IncludesGLES20.h" +#include "DebugGLES20.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/BuiltinShaderParams.h" +#include "Runtime/GfxDevice/BuiltinShaderParamsNames.h" +#include "Runtime/Utilities/BitUtility.h" + +#include <sstream> +#include <assert.h> + + +#define CMP_STATE(member) { \ + if (a.member < b.member) \ + return true; \ + else if (b.member < a.member) \ + return false; \ +} + +// builtins support only 4 lights +const int kMaxEmulatedVertexLights = 4;//kMaxSupportedVertexLights; + +bool FullStateCompareGLES20::operator() (FixedFunctionStateGLES20 const& a, const FixedFunctionStateGLES20& b) const +{ + CMP_STATE(lightingEnabled) + CMP_STATE(specularEnabled) + CMP_STATE(lightCount) + CMP_STATE(onlyDirectionalLights) + CMP_STATE(lightType) + CMP_STATE(texUnitMatrix) + CMP_STATE(useUniformInsteadOfVertexColor) + CMP_STATE(useVertexColorAsAmbientAndDiffuse) + CMP_STATE(useVertexColorAsEmission) + + CMP_STATE(fogMode) + + CMP_STATE(texUnitCount); + for (int i = 0; i < a.texUnitCount; i++) + { + CMP_STATE(texUnitCube[i]) + CMP_STATE(texUnitGen[i]) + CMP_STATE(texUnitColorCombiner[i]) + CMP_STATE(texUnitAlphaCombiner[i]) + } + + CMP_STATE(addSpecularAfterTexturing) + CMP_STATE(alphaTest) + CMP_STATE(setupPointSize) + + return false; /* All equal, not lesser. */ +} + +bool VertexStateCompareGLES20::operator() (FixedFunctionStateGLES20 const& a, FixedFunctionStateGLES20 const& b) const +{ + CMP_STATE(lightingEnabled) + CMP_STATE(specularEnabled) + CMP_STATE(lightCount) + CMP_STATE(onlyDirectionalLights) + CMP_STATE(lightType) + CMP_STATE(texUnitMatrix) + CMP_STATE(useUniformInsteadOfVertexColor) + CMP_STATE(useVertexColorAsAmbientAndDiffuse) + CMP_STATE(useVertexColorAsEmission) + + CMP_STATE(fogMode) + CMP_STATE(setupPointSize) + + CMP_STATE(texUnitCount); + for (int i = 0; i < a.texUnitCount; i++) + { + CMP_STATE(texUnitCube[i]) + CMP_STATE(texUnitGen[i]) + } + return false; /* All equal, not lesser. */ +} + +bool FragmentStateCompareGLES20::operator() (FixedFunctionStateGLES20 const& a, FixedFunctionStateGLES20 const& b) const +{ + CMP_STATE(fogMode) + CMP_STATE(texUnitCount) + + for (int i = 0; i < a.texUnitCount; i++) + { + CMP_STATE(texUnitCube[i]) + CMP_STATE(texUnitGen[i]) + CMP_STATE(texUnitColorCombiner[i]) + CMP_STATE(texUnitAlphaCombiner[i]) + } + + CMP_STATE(addSpecularAfterTexturing) + CMP_STATE(alphaTest) + + return false; /* All equal, not lesser. */ +} + + +// --- VERTEX program ---------------------------------------------------------------------------- + +std::string BuildVertexShaderSourceGLES20 (const FixedFunctionStateGLES20& state) +{ + DBG_SHADER_VERBOSE_GLES20("ShaderGeneratorGLES20::BuildVertexShaderSource()\n"); + DBG_SHADER_VERBOSE_GLES20(" state: %s\n", state.ToString().c_str()); + + bool eyePositionRequired = (state.lightingEnabled && state.lightCount > 0 && !state.onlyDirectionalLights); + for (int i = 0; i < state.texUnitCount; i++) + if (state.texUnitGen[i]==kTexGenCubeReflect) + eyePositionRequired = true; + + std::ostringstream src; + + /* Standard uniforms. */ + src << "uniform highp mat4 " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMVP) << ";\n"; + if (eyePositionRequired) + { + src << "uniform highp mat4 " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMV) << ";\n"; + } + + /* Default attributes. */ + src << "attribute highp vec4 _glesVertex;\n"; + src << "attribute mediump vec3 _glesNormal;\n"; + if (state.useUniformInsteadOfVertexColor) + src << "uniform lowp vec4 _glesFFColor;\n"; + else + src << "attribute lowp vec4 _glesColor;\n"; + + /* Default varyings. */ + src << "varying lowp vec4 v_color;\n"; + + if (state.fogMode > kFogDisabled) + { + src << "uniform highp vec4 _glesFogParams;\n"; + src << "uniform lowp vec4 _glesFogColor;\n"; + src << "varying lowp vec4 _glesFogColorPreMul;\n"; + src << "varying lowp vec4 _glesFogVar;\n"; + } + + /* Texture coordinates and transformation matrices. */ + for (int i = 0; i < state.texUnitCount; i++) + { + src << "attribute " << (state.NeedTexUnitMatrix(i)?"highp":"mediump") << " vec4 _glesMultiTexCoord" << i << ";\n"; + if (!state.texUnitCube[i]) + { + if (state.texUnitGen[i] == kTexGenObject) + src << "varying highp vec4 v_texGenObjCoord" << i << ";\n"; + else + src << "varying mediump vec2 v_texCoord" << i << ";\n"; + } + else + { + src << "varying highp vec3 v_texCoord" << i << ";\n"; + } + + if(state.NeedTexUnitMatrix(i)) + src << "uniform highp mat4 " << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << ";\n"; + } + + /* Handle color -> material mapping. */ + const char* ambientColor = state.useVertexColorAsAmbientAndDiffuse ? "vertexColor" : "_glesFrontMaterial.ambient"; + const char* diffuseColor = state.useVertexColorAsAmbientAndDiffuse ? "vertexColor" : "_glesFrontMaterial.diffuse"; + const char* emissionColor = state.useVertexColorAsEmission ? "vertexColor" : "_glesFrontMaterial.emission"; + + /* Light params. */ + if (state.lightingEnabled) + { + src << "struct LightModelParameters {\n"; + src << " vec4 ambient;\n"; + src << "};\n"; + + src << "struct MaterialParameters {\n"; + src << " vec4 emission;\n"; + src << " vec4 ambient;\n"; + src << " vec4 diffuse;\n"; + src << " vec4 specular;\n"; + src << " float shininess;\n"; + src << "};\n"; + + src << "uniform LightModelParameters _glesLightModel;\n"; + src << "uniform MaterialParameters _glesFrontMaterial;\n"; + + if (state.lightCount > 0) + { + src << "struct LightSourceParameters {\n"; + src << " vec4 diffuse;\n"; + src << " vec4 position;\n"; + src << " vec3 spotDirection;\n"; + src << " vec4 atten;\n"; + src << "};\n"; + + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLightModelAmbient) << ";\n"; + for (int q = 0; q < kMaxEmulatedVertexLights; ++q) + { + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0Diffuse + q) << ";\n"; + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0Position + q) << ";\n"; + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0SpotDirection + q) << ";\n"; + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0Atten + q) << ";\n"; + } + + src << "uniform mat3 _glesNormalMatrix;\n"; + + /* Compute functions. */ + src << "\nvec3 direction (vec4 from, vec4 to)\n"; + src << "{\n"; + src << " return (to.xyz * from.w - from.xyz * to.w);\n"; + src << "}\n"; + + src << "\nvec3 computeLighting(LightSourceParameters light, vec3 dirToLight, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " float NdotL = max(dot(eyeNormal, dirToLight), 0.0);\n"; + // \note in Unity, light ambient is always zero + src << " vec3 color = NdotL * " << diffuseColor << ".rgb * light.diffuse.rgb;\n"; + if (state.specularEnabled) + { + src << " if (NdotL > 0.0)\n"; + src << " {\n"; + src << " vec3 h = normalize(dirToLight + vec3(0.0, 0.0, 1.0));\n"; + src << " float HdotN = max(dot(eyeNormal, h), 0.0);\n"; + // \note in Unity, light specular color is always the same as diffuse color + src << " color += pow(HdotN, _glesFrontMaterial.shininess) * _glesFrontMaterial.specular.rgb * light.diffuse.rgb;\n"; + src << " }\n"; + } + src << " return color;\n"; + src << "}\n"; + + src << "\nvec3 computeDirLight(LightSourceParameters light, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " vec3 dirToLight = light.position.xyz;\n"; + // \note D3D backend uses min(val, 1.0). We use clamp(), because Img's wrapper is buggy! + src << " return clamp(computeLighting(light, dirToLight, eyeNormal, vertexColor), 0.0, 1.0);\n"; + src << "}\n"; + + src << "\nvec3 computePointLight(LightSourceParameters light, vec4 eyePosition, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " vec3 dirToLight = direction(eyePosition, light.position);\n"; + src << " float distSqr = dot(dirToLight, dirToLight);\n"; + // \note in Unity, const attenuation=1.0, linear=0.0 + src << " float att = 1.0 / (1.0 + light.atten.z * distSqr);\n"; + src << " dirToLight *= inversesqrt(distSqr);\n"; + // \note D3D backend uses min(val, 1.0). We use clamp(), because Img's wrapper is buggy! + src << " return clamp(att * computeLighting(light, dirToLight, eyeNormal, vertexColor), 0.0, 1.0);\n"; + src << "}\n"; + + src << "\nvec3 computeSpotLight(LightSourceParameters light, vec4 eyePosition, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " vec3 dirToLight = direction(eyePosition, light.position);\n"; + src << " float distSqr = dot(dirToLight, dirToLight);\n"; + // \note in Unity, const atten=1.0, linear=0.0 + src << " float att = 1.0 / (1.0 + light.atten.z * distSqr);\n"; + src << " dirToLight *= inversesqrt(distSqr);\n"; + src << " float rho = max(dot(dirToLight, light.spotDirection), 0.0);\n"; + src << " float spotAtt = (rho - light.atten.x) * light.atten.y;\n"; + src << " spotAtt = clamp(spotAtt, 0.0, 1.0);\n"; + // \note D3D backend uses min(val, 1.0). We use clamp(), because Img's wrapper is buggy! + src << " return clamp(att * spotAtt * computeLighting(light, dirToLight, eyeNormal, vertexColor), 0.0, 1.0);\n"; + //src << " return computeLighting(light, dirToLight, eyeNormal, vertexColor);\n"; // DEBUG DEBUG + + src << "}\n"; + } + } + + + + /* Main body. */ + src << "\nvoid main()\n"; + src << "{\n"; + + /* Vertex transformation. */ + src << " gl_Position = " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMVP) << " * _glesVertex;\n"; + if(state.setupPointSize) + src << " gl_PointSize = 1.0;\n"; + + /* Unpack vertex color if necessary. */ + if (state.useUniformInsteadOfVertexColor) + src << " vec4 vertexColor = _glesFFColor;\n"; + else + src << " vec4 vertexColor = _glesColor;\n"; + + if (eyePositionRequired) + src << " highp vec4 eyePosition = " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMV) << " * _glesVertex;\n"; + + /* Pass and transform texture coordinates. */ + for (int i = 0; i < state.texUnitCount; i++) + { + if (!state.texUnitCube[i]) + { + if (state.texUnitGen[i] == kTexGenObject) + { + Assert(state.NeedTexUnitMatrix(i)); + src << " v_texGenObjCoord" << i << " = "; + src << "(" << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << " * _glesMultiTexCoord" << i << ").xyzw;\n"; + } + else + { + if(state.NeedTexUnitMatrix(i)) + { + src << " vec4 tmpTexCoord" << i << " = (" << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << " * _glesMultiTexCoord" << i << ").xyzw;\n"; + if(state.IsTexUnitProjected(i)) + src << " v_texCoord" << i << " = tmpTexCoord" << i << ".xy / tmpTexCoord" << i << ".w;\n"; + else + src << " v_texCoord" << i << " = tmpTexCoord" << i << ".xy;\n"; + } + else + { + src << " v_texCoord" << i << " = _glesMultiTexCoord" << i << ".xy;\n"; + } + } + } + else + { + src << " v_texCoord" << i << " = "; + src << "vec3(" << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << " * _glesMultiTexCoord" << i << ");\n"; + if (state.texUnitGen[i] == kTexGenCubeReflect) + { + Assert(eyePositionRequired); + src << "{\n"; + src << " vec3 n = v_texCoord"<< i <<".xyz;\n"; + src << " v_texCoord"<< i <<" = reflect(eyePosition.xyz * eyePosition.w, n);\n"; + src << "}\n"; + } + } + } + + switch (state.fogMode) + { + case kFogLinear: + src << " _glesFogVar = vec4(clamp (_glesFogParams.z * gl_Position.z + _glesFogParams.w, 0.0, 1.0)); _glesFogVar.a = 1.0;\n"; + src << " _glesFogColorPreMul = _glesFogColor * (vec4(1.0)-_glesFogVar);\n"; + break; + case kFogExp: + src << " float _patchFog = _glesFogParams.y * gl_Position.z;\n"; + src << " _glesFogVar = vec4(clamp (exp2(-_patchFog), 0.0, 1.0)); _glesFogVar.a = 1.0;\n"; + src << " _glesFogColorPreMul = _glesFogColor * (vec4(1.0)-_glesFogVar);\n"; + break; + case kFogExp2: + src << " float _patchFog = _glesFogParams.x * gl_Position.z;\n"; + src << " _patchFog = _patchFog * _patchFog;\n"; + src << " _glesFogVar = vec4(clamp (exp2(-_patchFog), 0.0, 1.0)); _glesFogVar.a = 1.0;\n"; + src << " _glesFogColorPreMul = _glesFogColor * (vec4(1.0)-_glesFogVar);\n"; + break; + default: + break; + } + + /* Vertex color computation. */ + if (state.lightingEnabled) + { + src << " vec3 color = " << emissionColor << ".rgb + " << ambientColor << ".rgb * _glesLightModel.ambient.rgb;\n"; +// src << " color = vec3(0.0);\n"; // DEBUG DEBUG + + if (state.lightCount > 0) + { + src << " vec3 eyeNormal = normalize(_glesNormalMatrix * _glesNormal);\n"; + for (int i = 0; i < state.lightCount && i < kMaxEmulatedVertexLights; i++) + { + src << " LightSourceParameters light" << i << ";\n"; + src << " light" << i << ".diffuse = " << GetBuiltinVectorParamName(kShaderVecLight0Diffuse + i) << ";\n"; + src << " light" << i << ".position = " << GetBuiltinVectorParamName(kShaderVecLight0Position + i) << ";\n"; + src << " light" << i << ".spotDirection = " << GetBuiltinVectorParamName(kShaderVecLight0SpotDirection + i) << ".xyz;\n"; + src << " light" << i << ".atten = " << GetBuiltinVectorParamName(kShaderVecLight0Atten + i) << ";\n"; + + if(state.GetLightType(i) == kLightDirectional) + src << " color += computeDirLight(light" << i << ", eyeNormal, vertexColor);\n"; + else if(state.GetLightType(i) == kLightSpot) + src << " color += computeSpotLight(light" << i << ", eyePosition, eyeNormal, vertexColor);\n"; + else + src << " color += computePointLight(light" << i << ", eyePosition, eyeNormal, vertexColor);\n"; + + Assert(eyePositionRequired || state.GetLightType(i) == kLightDirectional); + } + } + + src << " float alpha = " << diffuseColor << ".a;\n"; + src << " v_color = vec4(color, alpha);\n"; + } + else + { + src << " v_color = vertexColor;\n"; + } + + src << "}\n"; + + DBG_SHADER_VERBOSE_GLES20("Generated VERTEX program:\n%s\n---\n", src.str().c_str()); + + return src.str().c_str(); +} + +// --- FRAGMENT program ---------------------------------------------------------------------------- + + +static void AddTexOperandSrc ( + std::ostringstream& src, + int unitNdx, + combiner::Channels channels, + combiner::Operand operand, + combiner::Source source) +{ + src << "("; + + if (operand == combiner::kOperOneMinusSrcAlpha || + operand == combiner::kOperOneMinusSrcColor) + { + src << "vec4(1.0) - "; + } + + switch (source) + { + case combiner::kSrcPrimaryColor: + src << "v_color"; + break; + + case combiner::kSrcPrevious: + src << "prev"; + break; + + case combiner::kSrcTexture: + src << "texture"; + break; + + case combiner::kSrcConstant: + src << "_glesTextureEnvColor" << unitNdx; + break; + + default: + printf_console("Error: Unsupported combiner source %d\n", source); + src << "vec4(1.0)"; /* Dummy value. */ + } + + src << ")"; + + switch (operand) + { + case combiner::kOperSrcColor: + case combiner::kOperOneMinusSrcColor: + if (channels == combiner::kRGBA) + src << ".rgba"; + else if (channels == combiner::kRGB) + src << ".rgb"; + else if (channels == combiner::kAlpha) + src << ".a"; + break; + + case combiner::kOperSrcAlpha: + case combiner::kOperOneMinusSrcAlpha: + if (channels == combiner::kRGBA) + src << ".aaaa"; + else if (channels == combiner::kRGB) + src << ".aaa"; + else if (channels == combiner::kAlpha) + src << ".a"; + break; + } +} + +static void AddTextureCombinerBody (std::ostringstream& src, int unitNdx, UInt32 combinerDesc, combiner::Channels channels) +{ + Assert(combiner::kRGBA == 0); + Assert(combiner::kRGB == 1); + Assert(combiner::kAlpha == 2); + + const std::string channelTypes[] = { "vec4", "vec3", "float" }; + const std::string channelMask[] = { "", ".rgb", ".a" }; + + + combiner::Source sources[3]; + combiner::Operand operands[3]; + combiner::Operation op; + int scale; + + combiner::DecodeTextureCombinerDescriptor(combinerDesc, + op, sources, operands, scale, false); + + if ((op == combiner::kOpDot3RGBA || op == combiner::kOpDot3RGB)) + { + if (channels == combiner::kAlpha) + return; + channels = combiner::kRGBA; + } + + src << " color" << channelMask[channels] << " = "; + + switch (op) + { + case combiner::kOpReplace: + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + break; + + case combiner::kOpModulate: + { + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " * "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + break; + } + + case combiner::kOpAdd: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " + "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + + case combiner::kOpSubtract: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " - "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + + case combiner::kOpAddSigned: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " + "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << " - " << channelTypes[channels] << "(0.5)"; + src << ")"; + break; + } + + case combiner::kOpLerp: + { + // NOTE: arguments of Unity LERP combiner are reversed for some reason + src << "mix("; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ", "; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << ", "; + AddTexOperandSrc(src, unitNdx, combiner::kAlpha, operands[2], sources[2]); + src << ")"; + break; + } + + case combiner::kOpDot3RGB: + { + if (channels == combiner::kRGBA) + { + src << channelTypes[channels] << "(vec3(4.0 * dot("; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[0], sources[0]); + src << " - vec3(0.5), "; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[1], sources[1]); + src << " - vec3(0.5))), "; + AddTexOperandSrc(src, unitNdx, combiner::kAlpha, operands[0], sources[0]); + src << ")"; + // Note: I am really not sure what goes into alpha channel when dot3_rgb is performed, it's definetly not the from dot + // My best guess, that original alpha value is kept + + } + else + { + src << channelTypes[channels] << "(4.0* dot("; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[0], sources[0]); + src << " - vec3(0.5), "; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[1], sources[1]); + src << " - vec3(0.5)))"; + } + break; + } + + case combiner::kOpDot3RGBA: + { + src << channelTypes[channels] << "(4.0 * dot("; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[0], sources[0]); + src << " - vec3(0.5), "; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[1], sources[1]); + src << " - vec3(0.5)))"; + break; + } + case combiner::kOpMulAdd: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " * "; + AddTexOperandSrc(src, unitNdx, channels, operands[2], sources[2]); + src << " + "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + case combiner::kOpMulSub: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " * "; + AddTexOperandSrc(src, unitNdx, channels, operands[2], sources[2]); + src << " - "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + default: + ErrorString(Format("Error: Unsupported combiner operation %d\n", op).c_str()); + + /* Dummy value. */ + src << channelTypes[channels] << "(1.0)"; + break; + } + + if (scale != 1) + src << " * float(" << scale << ".0)"; + src << ";\n"; +} + +static void AddTextureCombinerSrc (std::ostringstream& src, int unitNdx, bool isCube, UInt32 colorCombiner, UInt32 alphaCombiner) +{ + src << " {\n /* Combiner " << unitNdx << " */\n"; + + /* Perform lookup. */ + src << " lowp vec4 texture = " << (isCube ? "textureCube" : "texture2D") << "(u_sampler" << unitNdx << ", v_texCoord" << unitNdx << ");\n"; + + src << " lowp vec4 prev = " << ((unitNdx > 0)? "color": "v_color") << ";\n"; + + /* Combine. */ + if (colorCombiner == alphaCombiner) + { + // In case of color and alpha combiner being the same + // we calc all 4 channels in a single operation + // as some GLSL compilers (iPhone) will silently fail on following: + // color.rgb = arg0.rgb (op) arg1.rgb + // color.a = arg0.a (op) arg1.a + // instead we spit: + // color = arg0 (op) arg1 + // plus it is more readable + AddTextureCombinerBody(src, unitNdx, colorCombiner, combiner::kRGBA); + } + else + { + AddTextureCombinerBody(src, unitNdx, colorCombiner, combiner::kRGB); + AddTextureCombinerBody(src, unitNdx, alphaCombiner, combiner::kAlpha); + } + + src << " }\n"; +} + + +std::string BuildFragmentShaderSourceGLES20 (const FixedFunctionStateGLES20& state) +{ + DBG_SHADER_VERBOSE_GLES20("ShaderGeneratorGLES20::BuildFragmentShaderSource()\n"); + DBG_SHADER_VERBOSE_GLES20(" state: %s\n", state.ToString().c_str()); + + std::ostringstream src; + + bool alphaTestEnabled = state.alphaTest != kFuncDisabled && + state.alphaTest != kFuncAlways; + + /* Default varyings. */ + src << "varying lowp vec4 v_color;\n"; + + /* Uniforms. */ + if (alphaTestEnabled) + src << "uniform lowp float _glesAlphaTestReference;\n"; + + if (state.fogMode > kFogDisabled) + { + src << "varying lowp vec4 _glesFogColorPreMul;\n"; + src << "varying lowp vec4 _glesFogVar;\n"; + } + + /* Texture units. */ + for (int i = 0; i < state.texUnitCount; i++) + { + if (!state.texUnitCube[i]) + { + if (state.texUnitGen[i] == kTexGenObject) + src << "varying highp vec4 v_texGenObjCoord" << i << ";\n"; + else + src << "varying mediump vec2 v_texCoord" << i << ";\n"; + + src << "uniform sampler2D u_sampler" << i << ";\n"; + } + else + { + src << "varying highp vec3 v_texCoord" << i << ";\n"; + src << "uniform samplerCube u_sampler" << i << ";\n"; + } + + src << "uniform lowp vec4 _glesTextureEnvColor" << i << ";\n"; + } + + + /* Main body. */ + src << "\nvoid main()\n"; + src << "{\n"; + + /* Initialize color. */ + src << " lowp vec4 color = v_color;\n"; + + /* Generate correct texCoords if we have texGenObject */ + for (int i = 0; i < state.texUnitCount; i++) + { + if (!state.texUnitCube[i] && state.texUnitGen[i] == kTexGenObject) + src << " highp vec2 v_texCoord" << i << " = v_texGenObjCoord" << i << ".xy / v_texGenObjCoord" << i << ".w;\n"; + } + + /* Texturing. */ + for (int i = 0; i < state.texUnitCount; i++) + AddTextureCombinerSrc(src, i, state.texUnitCube[i], state.texUnitColorCombiner[i], state.texUnitAlphaCombiner[i]); + + if (state.fogMode > kFogDisabled) + src << " gl_FragColor = color * _glesFogVar + _glesFogColorPreMul;\n"; + else + src << " gl_FragColor = color;\n"; + + /* Alpha test. */ + if (alphaTestEnabled) + { + Assert(gGraphicsCaps.gles20.hasAlphaTestQCOM == false); + + if (state.alphaTest == kFuncNever) + { + // ToDo: Do we just discard everything, or skip drawing itself at vbo level? + src << " discard;\n"; + } + else + { + // Reverse logic because we're using here 'discard' + static const char* s_cmpOps[] = + { + "", // kFuncDisabled + "", // kFuncNever + ">=", // kFuncLess + "!=", // kFuncEqual + ">", // kFuncLEqual + "<=", // kFuncGreater + "==", // kFuncNotEqual + "<", // kFuncGEqual + "", // kFuncAlways + }; + + src << " if (color.a " << s_cmpOps[state.alphaTest] << "_glesAlphaTestReference)\n"; + src << " discard;\n"; + } + } +// src << " gl_FragColor = vec4(v_color.xyz, 1.0);\n"; // DEBUG DEBUG +// src << " gl_FragColor = 0.5 * texture2D(u_sampler0, v_texCoord0);\n"; // DEBUG DEBUG +// src << " gl_FragColor = vec4(_glesTextureEnvColor0.rgb, 1.0);\n"; // DEBUG DEBUG + src << "}\n"; + + DBG_SHADER_VERBOSE_GLES20("Generated FRAGMENT program:\n%s\n---\n", src.str().c_str()); + + return src.str().c_str(); +} diff --git a/Runtime/GfxDevice/opengles20/ShaderGeneratorGLES20.h b/Runtime/GfxDevice/opengles20/ShaderGeneratorGLES20.h new file mode 100644 index 0000000..26669a1 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/ShaderGeneratorGLES20.h @@ -0,0 +1,24 @@ +#ifndef SHADERGENERATOR_GLES20_H +#define SHADERGENERATOR_GLES20_H + +#include <string> + +class FixedFunctionStateGLES20; + +std::string BuildVertexShaderSourceGLES20 (const FixedFunctionStateGLES20& state); +std::string BuildFragmentShaderSourceGLES20 (const FixedFunctionStateGLES20& state); + +struct FullStateCompareGLES20 +{ + bool operator() (FixedFunctionStateGLES20 const& a, FixedFunctionStateGLES20 const& b) const; +}; +struct VertexStateCompareGLES20 +{ + bool operator() (FixedFunctionStateGLES20 const& a, FixedFunctionStateGLES20 const& b) const; +}; +struct FragmentStateCompareGLES20 +{ + bool operator() (FixedFunctionStateGLES20 const& a, FixedFunctionStateGLES20 const& b) const; +}; + +#endif /* SHADERGENERATOR_GLES20_H */ diff --git a/Runtime/GfxDevice/opengles20/TextureIdMapGLES20.h b/Runtime/GfxDevice/opengles20/TextureIdMapGLES20.h new file mode 100644 index 0000000..eb0c6dd --- /dev/null +++ b/Runtime/GfxDevice/opengles20/TextureIdMapGLES20.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/TextureIdMap.h" +#include "IncludesGLES20.h" + +inline GLuint TextureIdMapGLES20_QueryOrCreate(TextureID texid) +{ + GLuint ret = (GLuint)TextureIdMap::QueryNativeTexture(texid); + if(ret == 0) + { + GLES_CHK(glGenTextures(1, &ret)); + TextureIdMap::UpdateTexture(texid, ret); + } + + return ret; +} diff --git a/Runtime/GfxDevice/opengles20/TexturesGLES20.cpp b/Runtime/GfxDevice/opengles20/TexturesGLES20.cpp new file mode 100644 index 0000000..b300e85 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/TexturesGLES20.cpp @@ -0,0 +1,633 @@ +#include "UnityPrefix.h" +#include "TexturesGLES20.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/TextureUploadUtils.h" +#include "Runtime/Graphics/S3Decompression.h" +#include "Runtime/Graphics/Texture2D.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Utilities/BitUtility.h" +#include "IncludesGLES20.h" +#include "AssertGLES20.h" +#include "DebugGLES20.h" +#include "TextureIdMapGLES20.h" + + +#if GFX_SUPPORTS_OPENGLES20 + +// these are used to fill in table without using too much width +#define GL_ETC1 GL_ETC1_RGB8_OES +#define GL_DXT1 GL_COMPRESSED_RGB_S3TC_DXT1_EXT +#define GL_DXT3 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT +#define GL_DXT5 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT +#define GL_SRGBDXT1 GL_COMPRESSED_SRGB_S3TC_DXT1_NV +#define GL_SRGBDXT3 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV +#define GL_SRGBDXT5 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV +#define GL_PVR1RGB2 GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG +#define GL_PVR1RGBA2 GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG +#define GL_PVR1RGB4 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG +#define GL_PVR1RGBA4 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG +#define GL_ATC4 GL_ATC_RGB_AMD +#define GL_ATC8 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD + +#define RESERVED_FORMAT -1,-1,-1,0, + +const static int kTextureFormatTable[kTexFormatTotalCount*4] = +{ + // for GLES format == internal format, so we keep only one + // format, srgb format, datatype, alternative format + 0, 0, 0, 0, + GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, 0, // Alpha8 + GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 0, // ARGB4444 + GL_RGB, GL_SRGB_EXT, GL_UNSIGNED_BYTE, 0, // RGB24 + GL_RGBA, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, 0, // RGBA32 + -1, -1, -1, kTexFormatRGBA32, // ARGB32 + GL_RGBA, GL_SRGB_ALPHA_EXT, GL_HALF_FLOAT_OES, kTexFormatRGBA32, // ARGBFloat + GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0, // RGB565 + -1, -1, -1, kTexFormatRGB24, // BGR24 + -1, -1, -1, kTexFormatAlpha8, // AlphaLum16 + GL_DXT1, GL_SRGBDXT1, -1, 0, // DXT1 + GL_DXT3, GL_SRGBDXT3, -1, 0, // DXT3 + GL_DXT5, GL_SRGBDXT5, -1, 0, // DXT5 + GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 0, // RGBA4444 + + RESERVED_FORMAT /*14*/ RESERVED_FORMAT /*15*/ RESERVED_FORMAT /*16*/ RESERVED_FORMAT /*17*/ + RESERVED_FORMAT /*18*/ RESERVED_FORMAT /*19*/ RESERVED_FORMAT /*20*/ RESERVED_FORMAT /*21*/ + RESERVED_FORMAT /*22*/ RESERVED_FORMAT /*23*/ RESERVED_FORMAT /*24*/ RESERVED_FORMAT /*25*/ + RESERVED_FORMAT /*26*/ RESERVED_FORMAT /*27*/ RESERVED_FORMAT /*28*/ RESERVED_FORMAT /*29*/ + + GL_PVR1RGB2, -1, -1, 0, // PVRTC_RGB2 + GL_PVR1RGBA2, -1, -1, 0, // PVRTC_RGBA2 + GL_PVR1RGB4, -1, -1, 0, // PVRTC_RGB4 + GL_PVR1RGBA4, -1, -1, 0, // PVRTC_RGBA4 + GL_ETC1, -1, -1, 0, // ETC_RGB4 + GL_ATC4, -1, -1, 0, // ATC_RGB4 + GL_ATC8, -1, -1, 0, // ATC_RGBA8 + GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE, 0, // BGRA32 +}; + +#undef GL_ETC1 +#undef GL_DXT1 +#undef GL_DXT3 +#undef GL_DXT5 +#undef GL_PVR1RGB2 +#undef GL_PVR1RGBA2 +#undef GL_PVR1RGB4 +#undef GL_PVR1RGBA4 +#undef GL_ATC4 +#undef GL_ATC8 +#undef RESERVED_FORMAT + + +static int IsSupportedTextureFormat(TextureFormat inFormat) +{ + return (kTextureFormatTable[inFormat*4+0] > 0) && gGraphicsCaps.supportsTextureFormat[inFormat]; +} + +static int RemapToAlternativeFormat (TextureFormat inFormat) +{ + int altFormat = kTextureFormatTable[inFormat*4+3]; + return altFormat > 0 ? altFormat : kTexFormatRGBA32; +} + +static void GetUncompressedTextureFormat (int inFormat, bool srgb, int* format, int* dataType) +{ + DebugAssertIf( IsAnyCompressedTextureFormat(inFormat) ); + *format = kTextureFormatTable[inFormat*4 + (srgb?1:0)]; + *dataType = kTextureFormatTable[inFormat*4 + 2]; +} + +static void GetCompressedTextureFormat (int inFormat, bool srgb, int width, int height, int* internalFormat, int* size) +{ + // srgb support will be enabled only if compressed srgb is supported + // also we will ever use only supported formats + *internalFormat = kTextureFormatTable[inFormat*4 + (srgb?1:0)]; + Assert(*internalFormat != -1); + + switch(inFormat) + { + case kTexFormatPVRTC_RGB4: + case kTexFormatPVRTC_RGBA4: + *size = (std::max(width, 8) * std::max(height, 8) * 4 + 7) / 8; + break; + case kTexFormatPVRTC_RGB2: + case kTexFormatPVRTC_RGBA2: + *size = (std::max(width, 16) * std::max(height, 8) * 2 + 7) / 8; + break; + case kTexFormatDXT1: + case kTexFormatATC_RGB4: + *size = ((width + 3) / 4) * ((height + 3) / 4) * 8; + break; + case kTexFormatDXT5: + case kTexFormatATC_RGBA8: + *size = ((width + 3) / 4) * ((height + 3) / 4) * 16; + break; + case kTexFormatETC_RGB4: + *size = 8 * ((width+3)>>2) * ((height+3)>>2); // 8 bytes per 4x4 block + break; + default: + Assert(false && "Texture is not compressed"); + } +} + +static TextureFormat GetUploadFormat(TextureFormat format, bool& uploadIsCompressed, bool& decompressOnTheFly) +{ + TextureFormat uploadFormat = format; + uploadIsCompressed = IsAnyCompressedTextureFormat(format); + decompressOnTheFly = false; + if (!IsSupportedTextureFormat(format)) + { + if( uploadIsCompressed ) + { + uploadIsCompressed = false; + decompressOnTheFly = true; + } + + uploadFormat = RemapToAlternativeFormat(format); + } + + if( decompressOnTheFly ) + { + if (IsCompressedPVRTCTextureFormat(format)) + { + printf_console ("WARNING: PVRTC texture format is not supported, decompressing texture\n"); + } + else if (IsCompressedDXTTextureFormat(format)) + { + printf_console ("WARNING: DXT texture format is not supported, decompressing texture\n"); + } + else if (IsCompressedETCTextureFormat(format)) + { + printf_console ("WARNING: ETC texture format is not supported, decompressing texture\n"); + } + else if (IsCompressedATCTextureFormat(format)) + { + printf_console ("WARNING: ATC texture format is not supported, decompressing texture\n"); + } + } + + return uploadFormat; +} + +#if UNITY_PEPPER +// Unity generates textures as ARGB4444, but GLES only supports RGBA4444. +// On mobile GLES, we swizzle textures at build time, but on NaCl, we use the same data format as used +// in the normal web player, so we cannot do that here. So we swizzle at runtime. +// TODO for 4.0: See if there is any good reason to use ARGB4444 at all, or if we should switch to RGBA4444 completely! +UInt8 *SwizzleRGBA4444 (UInt8 *srcData, UInt8 **decompressBuffer, int width, int height) +{ + if( *decompressBuffer == NULL ) + *decompressBuffer = new UInt8[width * height * 2]; + + UInt8 *feedData = *decompressBuffer; + for (int q = 0; q < width * height; ++q) + { + // RGBA4444 <- ARGB4444 + UInt32 argb = *(UInt16*)(srcData + q * 2); + UInt16 rgba = (argb << 4) | (0x0F & (argb >> 12)); + + feedData[q * 2 + 0] = (UInt8)rgba; + feedData[q * 2 + 1] = (UInt8)(rgba >> 8); + } + return feedData; +} +#endif + +void UploadTexture2DGLES2( + TextureID tid, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureColorSpace colorSpace ) +{ + Assert( srcData != NULL ); + AssertIf( (!IsPowerOfTwo(width) || !IsPowerOfTwo(height)) && !IsNPOTTextureAllowed(mipCount > 1) ); + if( dimension != kTexDim2D ) + { + ErrorStringMsg( "Incorrect texture dimension! (dimension = %d)", dimension ); + return; + } + + bool uploadIsCompressed, decompressOnTheFly; + TextureFormat uploadFormat = GetUploadFormat(format, uploadIsCompressed, decompressOnTheFly); + + DBG_TEXTURE_VERBOSE_GLES20("Texture2D #%i (%ix%i) unityFmt: %d, uploadFmt: %d, compressed: %d, decompressOnCpu: %d", + tid.m_ID, width, height, format, uploadFormat, (int)uploadIsCompressed, (int)decompressOnTheFly); + REGISTER_EXTERNAL_GFX_DEALLOCATION(tid.m_ID); + + TextureIdMapGLES20_QueryOrCreate(tid); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, tid, dimension, std::numeric_limits<float>::infinity()); + GLES_CHK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + + int maxLevel = mipCount - 1; + int baseLevel = std::min( masterTextureLimit, maxLevel ); + +#if UNITY_IPHONE && GL_APPLE_texture_max_level + if( gGraphicsCaps.hasMipMaxLevel ) + { + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL_APPLE, maxLevel)); + } +#endif + + // xenon, for real? + bool isSRGB = (colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB); + + UInt8* decompressBuffer = NULL; + int glesFormat, datatype; + int uploadedSize = 0; + int skippedMipCount = 0; + for( int level = 0; level <= maxLevel; ++level ) + { + UInt8* feedData; + int uploadLevel = level - baseLevel - skippedMipCount; + + // Should this level be skipped because of master texture limit? + if( level < baseLevel ) + { + feedData = NULL; + } + // Should this level be skipped because it is too large for hardware limits? + else if (width > gGraphicsCaps.maxTextureSize || height > gGraphicsCaps.maxTextureSize) + { + skippedMipCount++; + DBG_TEXTURE_VERBOSE_GLES20("Texture2D #%i mip level %i (%ix%i) is too big, skipping!", tid.m_ID, level, width, height); + feedData = NULL; + } + // Allocate temporary memory and decompress texture + else if( decompressOnTheFly ) + { + Assert(uploadFormat == kTexFormatRGBA32); + + int dstWidth = std::max( width, 4 ); + int dstHeight = std::max( height, 4 ); + int decompressedSize = CalculateImageSize( dstWidth, dstHeight, uploadFormat ); + if( decompressBuffer == NULL ) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + DecompressNativeTextureFormat ( format, width, height, (UInt32*)srcData, dstWidth, dstHeight, (UInt32*)feedData ); + + if (UNITY_IPHONE && (format == kTexFormatDXT3 || format == kTexFormatDXT5)) + { + printf_console ("swapping DXT channels\n"); + + for (int q = 0; q < width * height; ++q) + { + std::swap(feedData[q * 4 + 0], feedData[q * 4 + 3]); + std::swap(feedData[q * 4 + 1], feedData[q * 4 + 2]); + } + } + } + // Allocate temporary memory and swizzle texture + else if (uploadFormat != format) + { + int decompressedSize = CalculateImageSize (width, height, uploadFormat); + if (decompressBuffer == NULL) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + + ImageReference src (width, height, GetRowBytesFromWidthAndFormat (width, format), format, srcData); + ImageReference dst (width, height, GetRowBytesFromWidthAndFormat (width, uploadFormat), uploadFormat, feedData); + dst.BlitImage( src ); + } +#if UNITY_PEPPER + else if (uploadFormat == kTexFormatARGB4444) + { + feedData = SwizzleRGBA4444 (srcData, &decompressBuffer, width, height); + } +#endif + else + { + // Just feed the data + feedData = srcData; + } + + // If this level should be skipped, just do nothing + if( feedData == NULL ) + { + } + else + { + if (uploadIsCompressed) + { + int size; + GetCompressedTextureFormat (uploadFormat, isSRGB, width, height, &glesFormat, &size); + if( glesFormat <= 0 ) + { + ErrorString(Format("Format not supported: %u!", (unsigned)uploadFormat)); + return; + } + + DBG_TEXTURE_VERBOSE_GLES20("GLESDebug texture: glCompressedTexImage2D: level=%i fmt=%i width=%i height=%i type=%i data=%x", + uploadLevel, glesFormat, width, height, datatype, (UInt32)feedData); + GLES_CHK(glCompressedTexImage2D (GL_TEXTURE_2D, uploadLevel, glesFormat, width, height, 0, size, feedData)); + } + else + { + GetUncompressedTextureFormat (uploadFormat, isSRGB, &glesFormat, &datatype); + if( glesFormat <= 0 ) + { + ErrorString(Format("Format not supported: %u!", (unsigned)uploadFormat)); + return; + } + + int internalFormat = glesFormat; + #if UNITY_IPHONE + //APPLE_texture_format_BGRA8888 dictates internal format for GL_BGRA_EXT to be GL_RGBA + if(glesFormat == GL_BGRA_EXT) + internalFormat = GL_RGBA; + #endif + + DBG_TEXTURE_VERBOSE_GLES20("GLESDebug texture: glTexImage2D: level=%i fmt=%i width=%i height=%i type=%i data=%x", + uploadLevel, glesFormat, width, height, datatype, (UInt32)feedData); + GLES_CHK(glTexImage2D (GL_TEXTURE_2D, uploadLevel, internalFormat, width, height, 0, glesFormat, datatype, feedData)); + } + } + if( gGraphicsCaps.gles20.needFlushAfterTextureUpload ) + GLES_CHK(glFlush()); + + // Go to next mip level + int levelSize = CalculateImageSize (width, height, format);; + uploadedSize += levelSize; + srcData += levelSize; + AssertIf( width == 1 && height == 1 && level != maxLevel ); + width = std::max( width / 2, 1 ); + height = std::max( height / 2, 1 ); + } + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(tid.m_ID, uploadedSize, tid.m_ID); + + AssertIf( baseLevel > maxLevel ); + + if( decompressBuffer ) + delete[] decompressBuffer; +} + +void UploadTextureSubData2DGLES2( TextureID glname, UInt8* srcData, + int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + Assert( !IsAnyCompressedTextureFormat( format ) ); + + bool uploadIsCompressed, decompressOnTheFly; + TextureFormat uploadFormat = GetUploadFormat(format, uploadIsCompressed, decompressOnTheFly); + Assert( !uploadIsCompressed ); + Assert( !decompressOnTheFly ); + + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(glname); + + Assert(targetTex != 0); + if(targetTex == 0) + return; + + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, glname, kTexDim2D, std::numeric_limits<float>::infinity()); + GLES_CHK(glActiveTexture(GL_TEXTURE0)); + GLES_CHK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + + UInt8* decompressBuffer = NULL; + UInt8* feedData = srcData; + + // Allocate temporary memory and swizzle texture + if( uploadFormat != format ) + { + int decompressedSize = CalculateImageSize (width, height, uploadFormat); + if (decompressBuffer == NULL) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + + ImageReference src (width, height, GetRowBytesFromWidthAndFormat (width, format), format, srcData); + ImageReference dst (width, height, GetRowBytesFromWidthAndFormat (width, uploadFormat), uploadFormat, feedData); + dst.BlitImage( src ); + } +#if UNITY_PEPPER + else if (uploadFormat == kTexFormatARGB4444) + { + feedData = SwizzleRGBA4444 (srcData, &decompressBuffer, width, height); + } +#endif + + // xenon, for real? + bool isSRGB = (colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB); + + int glesFormat, datatype; + GetUncompressedTextureFormat (uploadFormat, isSRGB, &glesFormat, &datatype); + + GLES_CHK(glTexSubImage2D( GL_TEXTURE_2D, mipLevel, x, y, width, height, glesFormat, datatype, feedData )); + + if( gGraphicsCaps.gles20.needFlushAfterTextureUpload ) + GLES_CHK(glFlush()); + + if( decompressBuffer ) + delete[] decompressBuffer; +} + +void UploadTextureCubeGLES2( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + bool uploadIsCompressed, decompressOnTheFly; + TextureFormat uploadFormat = GetUploadFormat(format, uploadIsCompressed, decompressOnTheFly); + DBG_TEXTURE_VERBOSE_GLES20("TextureCUBE #%i (%ix%ix6) unityFmt: %d, uploadFmt: %d, compressed: %d, decompressOnCpu: %d", + tid.m_ID, size, size, format, uploadFormat, (int)uploadIsCompressed, (int)decompressOnTheFly); + REGISTER_EXTERNAL_GFX_DEALLOCATION(tid.m_ID); + + TextureIdMapGLES20_QueryOrCreate(tid); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, tid, kTexDimCUBE, std::numeric_limits<float>::infinity()); + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + // xenon, for real? + bool isSRGB = (colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB); + + UInt8* decompressBuffer = NULL; + + const GLenum faces[6] = + { + GL_TEXTURE_CUBE_MAP_POSITIVE_X, + GL_TEXTURE_CUBE_MAP_NEGATIVE_X, + GL_TEXTURE_CUBE_MAP_POSITIVE_Y, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + }; + int uploadedSize = 0; + int maxLevel = mipCount - 1; + for (int face=0;face<6;face++) + { + int mipSize = size; + UInt8* data = srcData + face * faceDataSize; + int glesFormat, datatype, size; + + for( int level=0;level<=maxLevel;level++ ) + { + UInt8* feedData; + + // Allocate temporary memory and decompress texture + if( decompressOnTheFly ) + { + int dstSize = std::max( mipSize, 4 ); + int decompressedSize = CalculateImageSize( dstSize, dstSize, uploadFormat ); + if( decompressBuffer == NULL ) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + DecompressNativeTextureFormat( format, mipSize, mipSize, (UInt32*)data, dstSize, dstSize, (UInt32*)feedData ); + //SetUnpackClientStorage (false); + } + // Allocate temporary memory and swizzle texture + else if( uploadFormat != format ) + { + int decompressedSize = CalculateImageSize (mipSize, mipSize, uploadFormat); + if (decompressBuffer == NULL) + decompressBuffer = new UInt8[decompressedSize]; + feedData = decompressBuffer; + + ImageReference src (mipSize, mipSize, GetRowBytesFromWidthAndFormat (mipSize, format), format, data); + ImageReference dst (mipSize, mipSize, GetRowBytesFromWidthAndFormat (mipSize, uploadFormat), uploadFormat, feedData); + dst.BlitImage( src ); + } +#if UNITY_PEPPER + else if (uploadFormat == kTexFormatARGB4444) + { + feedData = SwizzleRGBA4444 (srcData, &decompressBuffer, mipSize, mipSize); + } +#endif + // Just feed the data + else + { + feedData = data; + } + + // Upload + if( uploadIsCompressed ) + { + GetCompressedTextureFormat( uploadFormat, isSRGB, mipSize, mipSize, &glesFormat, &size ); + GLES_CHK(glCompressedTexImage2D (faces[face], level, glesFormat, mipSize, mipSize, 0, size, feedData)); + } + else + { + GetUncompressedTextureFormat( uploadFormat, isSRGB, &glesFormat, &datatype ); + + int internalFormat = glesFormat; + #if UNITY_IPHONE + //APPLE_texture_format_BGRA8888 dictates internal format for GL_BGRA_EXT to be GL_RGBA + if(glesFormat == GL_BGRA_EXT) + internalFormat = GL_RGBA; + #endif + + GLES_CHK(glTexImage2D (faces[face], level, internalFormat, mipSize, mipSize, 0, glesFormat, datatype, feedData)); + } + + if( gGraphicsCaps.gles20.needFlushAfterTextureUpload ) + GLES_CHK(glFlush()); + + //GLAssert (); + int levelSize = CalculateImageSize( mipSize, mipSize, format ); + uploadedSize += levelSize; + data += levelSize; + AssertIf( mipSize == 1 && level != maxLevel ); + + mipSize = std::max( mipSize / 2, 1 ); + } + } + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(tid.m_ID, uploadedSize, tid.m_ID); + + if( decompressBuffer ) + delete[] decompressBuffer; +} + +#if UNITY_IPHONE + extern bool IsActiveMSAARenderTargetGLES2(); + extern RenderSurfaceBase* ResolveMSAASetupFBO(void*, int, GLuint, GLuint); + extern void ResolveMSAASetupFBO_Cleanup(RenderSurfaceBase*); + + extern "C" void* UnityDefaultFBOColorBuffer(); +#endif + +bool ReadbackTextureGLES2(ImageReference& image, int left, int bottom, int width, int height, int destX, int destY, GLuint globalSharedFBO, GLuint helperFBO) +{ + bool result = true; + +#if UNITY_IPHONE + RenderSurfaceBase* resolveRS = 0; + GLint oldFBO = 0; + if(IsActiveMSAARenderTargetGLES2() && gGraphicsCaps.gles20.hasAppleMSAA) + { + GLES_CHK(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO)); + resolveRS = ResolveMSAASetupFBO(UnityDefaultFBOColorBuffer(), 0, globalSharedFBO, helperFBO); + } +#endif + + int glesFormat, datatype; + + + // The whole image we're reading into can be larger than the rect we read, so setup the alignment. + GLES_CHK(glPixelStorei( GL_PACK_ALIGNMENT, 1 )); + + void* dstImagePtr[kTexFormatPCCount] = + { + 0, // + image.GetRowPtr(destY) + destX, // kTexFormatAlpha8 + 0, // kTexFormatARGB4444 + image.GetRowPtr(destY) + destX * 3, // kTexFormatRGB24 + image.GetRowPtr(destY) + destX * 4, // kTexFormatRGBA32 + image.GetRowPtr(destY) + destX * 4, // kTexFormatARGB32 + 0, // kTexFormatARGBFloat + image.GetRowPtr(destY) + destX * 2, // kTexFormatRGB565 + 0, // kTexFormatBGR24 + + 0, // kTexFormatAlphaLum16 + 0, // kTexFormatDXT1 + 0, // kTexFormatDXT3 + 0, // kTexFormatDXT5 + 0 // kTexFormatRGBA4444 + }; + + GetUncompressedTextureFormat( image.GetFormat(), false, &glesFormat, &datatype ); + void* dstPtr = dstImagePtr[image.GetFormat()]; + switch( image.GetFormat() ) + { + case kTexFormatRGB565: + case kTexFormatRGBA32: + case kTexFormatARGB32: + case kTexFormatRGB24: + case kTexFormatAlpha8: + { + int readFormat, readType; + GLES_CHK(glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &readFormat)); + GLES_CHK(glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &readType)); + + // Check if reading format/type matches our image's format/type, and width (as glReadPixels knows nothing about dst pitch) + if (glesFormat == readFormat && datatype == readType && width == image.GetWidth()) + { + GLES_CHK(glReadPixels(left, bottom, width, height, glesFormat, datatype, dstPtr)); + } + else + { + // Read as GL_RGBA/GL_UNSIGNED_BYTE, because it's always valid in OpenGL ES, and convert it to specified image format + int readFormat = kTexFormatRGBA32; + int readFormatSize = CalculateImageSize (width, height, readFormat); + + GetUncompressedTextureFormat( readFormat, false, &glesFormat, &datatype ); + + UInt8* data = new UInt8[readFormatSize]; + GLES_CHK(glReadPixels(left, bottom, width, height, glesFormat, datatype, data)); + + ImageReference src (width, height, GetRowBytesFromWidthAndFormat (width, readFormat), readFormat, data); + ImageReference dst (width, height, image.GetRowBytes(), image.GetFormat(), dstPtr); + dst.BlitImage( src ); + + delete[]data; + } + } + break; + default: + AssertString ("Not Supported"); + result = false; + } + +#if UNITY_IPHONE + if(resolveRS) + { + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, oldFBO)); + ResolveMSAASetupFBO_Cleanup(resolveRS); + } +#endif + + return result; +} + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/TexturesGLES20.h b/Runtime/GfxDevice/opengles20/TexturesGLES20.h new file mode 100644 index 0000000..ded70e9 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/TexturesGLES20.h @@ -0,0 +1,21 @@ +#ifndef UNITY_TEXTURES_GLES_H_ +#define UNITY_TEXTURES_GLES_H_ + +#include "Configuration/UnityConfigure.h" +#include "Runtime/Graphics/TextureFormat.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +class ImageReference; + +void UploadTexture2DGLES2( + TextureID glname, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureColorSpace colorSpace ); +void UploadTextureSubData2DGLES2( + TextureID glname, UInt8* srcData, + int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); +void UploadTextureCubeGLES2( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); +bool ReadbackTextureGLES2(ImageReference& image, int left, int bottom, int width, int height, int destX, int destY, unsigned int globalSharedFBO, unsigned int helperFBO); + +#endif // UNITY_TEXTURES_GLES_H_ diff --git a/Runtime/GfxDevice/opengles20/TimerQueryGLES20.cpp b/Runtime/GfxDevice/opengles20/TimerQueryGLES20.cpp new file mode 100644 index 0000000..1a5887e --- /dev/null +++ b/Runtime/GfxDevice/opengles20/TimerQueryGLES20.cpp @@ -0,0 +1,109 @@ +#include "UnityPrefix.h" +#if ENABLE_PROFILER && GFX_SUPPORTS_OPENGLES20 +#include "TimerQueryGLES20.h" +#include "AssertGLES20.h" +#include "UnityGLES20Ext.h" +#include "Runtime/Shaders/GraphicsCaps.h" + +bool TimerQueriesGLES::Init() +{ + bool hasHWSupport = false; + if( QueryExtension("GL_NV_timer_query") ) + { + hasHWSupport = gGlesExtFunc.glGetQueryObjectuivEXT && gGlesExtFunc.glGenQueriesEXT; + + #if UNITY_ANDROID + hasHWSupport = hasHWSupport && gGlesExtFunc.glQueryCounterNV && gGlesExtFunc.glGetQueryObjectui64vNV; + #endif + } + + gGraphicsCaps.hasTimerQuery = hasHWSupport; + if(hasHWSupport) + GLES_CHK(gGlesExtFunc.glGenQueriesEXT(kQueriesCount, timestamp_gl)); + + nextIndex = 0; + return true; +} + +void TimerQueriesGLES::BeginTimerQueries() +{ + GLES_CHK(glFlush()); + SetTimestamp(); +} + +void TimerQueriesGLES::EndTimerQueries() +{ + GLES_CHK(glFlush()); +} + +unsigned TimerQueriesGLES::SetTimestamp() +{ +#if UNITY_ANDROID + GLES_CHK(gGlesExtFunc.glQueryCounterNV(timestamp_gl[nextIndex], GL_TIMESTAMP_NV)); +#endif + unsigned ret = nextIndex; + + ++nextIndex; + if(nextIndex == kQueriesCount) + nextIndex = 0; + + return ret; +} + +UInt64 TimerQueriesGLES::GetElapsedTime(unsigned idx, bool wait) +{ +#if UNITY_ANDROID + GLuint available = 0; + GLES_CHK(gGlesExtFunc.glGetQueryObjectuivEXT(timestamp_gl[idx], GL_QUERY_RESULT_AVAILABLE_EXT, &available)); + // sometimes timestamp might be not ready (we still dont know why) + // the only workaround would be to add glFlush into SetTimestamp + // but then some timings will be a bit off + if(wait) + { + for(unsigned i = 0 ; i < 100 && !available ; ++i) + { + GLES_CHK(gGlesExtFunc.glGetQueryObjectuivEXT(timestamp_gl[idx], GL_QUERY_RESULT_AVAILABLE_EXT, &available)); + } + } + + if(available) + { + unsigned prev_idx = idx > 0 ? idx-1 : kQueriesCount-1; + + EGLuint64NV time1, time2; + GLES_CHK(gGlesExtFunc.glGetQueryObjectui64vNV(timestamp_gl[prev_idx], GL_QUERY_RESULT_EXT, &time1)); + GLES_CHK(gGlesExtFunc.glGetQueryObjectui64vNV(timestamp_gl[idx], GL_QUERY_RESULT_EXT, &time2)); + + return time2-time1; + } +#endif + + return kInvalidProfileTime; + +} + + +TimerQueryGLES::TimerQueryGLES() + : m_Index(0), + m_Time(kInvalidProfileTime) +{ +} + +void TimerQueryGLES::Measure() +{ + m_Index = g_TimerQueriesGLES.SetTimestamp(); + m_Time = kInvalidProfileTime; +} + +ProfileTimeFormat TimerQueryGLES::GetElapsed(UInt32 flags) +{ + if(m_Time == kInvalidProfileTime) + m_Time = g_TimerQueriesGLES.GetElapsedTime(m_Index, (flags & kWaitRenderThread) != 0); + + return m_Time; +} + +TimerQueriesGLES g_TimerQueriesGLES; + + +#endif diff --git a/Runtime/GfxDevice/opengles20/TimerQueryGLES20.h b/Runtime/GfxDevice/opengles20/TimerQueryGLES20.h new file mode 100644 index 0000000..67137eb --- /dev/null +++ b/Runtime/GfxDevice/opengles20/TimerQueryGLES20.h @@ -0,0 +1,47 @@ +#ifndef TIMERQUERYGLES_H +#define TIMERQUERYGLES_H + +#if ENABLE_PROFILER && GFX_SUPPORTS_OPENGLES20 + +#include "IncludesGLES20.h" +#include "Runtime/GfxDevice/GfxTimerQuery.h" + +struct TimerQueriesGLES +{ + enum + { + kQueriesCount = 128, + }; + + GLuint timestamp_gl[kQueriesCount]; + unsigned nextIndex; + + bool Init(); + + void BeginTimerQueries(); + void EndTimerQueries(); + + unsigned SetTimestamp(); + UInt64 GetElapsedTime(unsigned idx, bool wait); +}; +extern TimerQueriesGLES g_TimerQueriesGLES; + + +class TimerQueryGLES + : public GfxTimerQuery +{ +public: + + TimerQueryGLES(); + + virtual void Measure(); + virtual ProfileTimeFormat GetElapsed(UInt32 flags); + +private: + + unsigned m_Index; + ProfileTimeFormat m_Time; +}; + +#endif +#endif diff --git a/Runtime/GfxDevice/opengles20/UnityGLES20Ext.cpp b/Runtime/GfxDevice/opengles20/UnityGLES20Ext.cpp new file mode 100644 index 0000000..5ba6532 --- /dev/null +++ b/Runtime/GfxDevice/opengles20/UnityGLES20Ext.cpp @@ -0,0 +1,40 @@ +#include "UnityPrefix.h" +#include "IncludesGLES20.h" +#include "UnityGLES20Ext.h" +#include "Runtime/GfxDevice/opengles/ExtensionsGLES.h" + +void GlesExtFunc::InitExtFunc() +{ + glPushGroupMarkerEXT = (glPushGroupMarkerEXTFunc)GetGLExtProcAddress("glPushGroupMarkerEXT"); + glPopGroupMarkerEXT = (glPopGroupMarkerEXTFunc)GetGLExtProcAddress("glPopGroupMarkerEXT"); + glDiscardFramebufferEXT = (glDiscardFramebufferEXTFunc)GetGLExtProcAddress("glDiscardFramebufferEXT"); + glGenQueriesEXT = (glGenQueriesEXTFunc)GetGLExtProcAddress("glGenQueriesEXT"); + glDeleteQueriesEXT = (glDeleteQueriesEXTFunc)GetGLExtProcAddress("glDeleteQueriesEXT"); + glGetQueryObjectuivEXT = (glGetQueryObjectuivEXTFunc)GetGLExtProcAddress("glGetQueryObjectuivEXT"); + + glGetProgramBinaryOES = (glGetProgramBinaryOESFunc)GetGLExtProcAddress("glGetProgramBinaryOES"); + glProgramBinaryOES = (glProgramBinaryOESFunc)GetGLExtProcAddress("glProgramBinaryOES"); + + glMapBufferOES = (glMapBufferOESFunc)GetGLExtProcAddress("glMapBufferOES"); + glUnmapBufferOES = (glUnmapBufferOESFunc)GetGLExtProcAddress("glUnmapBufferOES"); + + glMapBufferRangeEXT = (glMapBufferRangeEXTFunc)GetGLExtProcAddress("glMapBufferRangeEXT"); + glFlushMappedBufferRangeEXT = (glFlushMappedBufferRangeEXTFunc)GetGLExtProcAddress("glFlushMappedBufferRangeEXT"); + + glRenderbufferStorageMultisampleAPPLE = (glRenderbufferStorageMultisampleAPPLEFunc)GetGLExtProcAddress("glRenderbufferStorageMultisampleAPPLE"); + glResolveMultisampleFramebufferAPPLE = (glResolveMultisampleFramebufferAPPLEFunc)GetGLExtProcAddress("glResolveMultisampleFramebufferAPPLE"); + + glRenderbufferStorageMultisampleIMG = (glRenderbufferStorageMultisampleIMGFunc)GetGLExtProcAddress("glRenderbufferStorageMultisampleIMG"); + glFramebufferTexture2DMultisampleIMG = (glFramebufferTexture2DMultisampleIMGFunc)GetGLExtProcAddress("glFramebufferTexture2DMultisampleIMG"); + + glRenderbufferStorageMultisampleEXT = (glRenderbufferStorageMultisampleEXTFunc)GetGLExtProcAddress("glRenderbufferStorageMultisampleEXT"); + glFramebufferTexture2DMultisampleEXT = (glFramebufferTexture2DMultisampleEXTFunc)GetGLExtProcAddress("glFramebufferTexture2DMultisampleEXT"); + + glDrawBuffersNV = (glDrawBuffersNVFunc)GetGLExtProcAddress("glDrawBuffersNV"); + glQueryCounterNV = (glQueryCounterNVFunc)GetGLExtProcAddress("glQueryCounterNV"); + glGetQueryObjectui64vNV = (glGetQueryObjectui64vNVFunc)GetGLExtProcAddress("glGetQueryObjectui64vNV"); + + glAlphaFuncQCOM = (glAlphaFuncQCOMFunc)GetGLExtProcAddress("glAlphaFuncQCOM"); +} + +GlesExtFunc gGlesExtFunc; diff --git a/Runtime/GfxDevice/opengles20/UnityGLES20Ext.h b/Runtime/GfxDevice/opengles20/UnityGLES20Ext.h new file mode 100644 index 0000000..4ab0e1d --- /dev/null +++ b/Runtime/GfxDevice/opengles20/UnityGLES20Ext.h @@ -0,0 +1,342 @@ +#pragma once +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/opengles/ExtensionsGLES.h" + +// The reason to have this file is that we use plenty of gles extensions, +// and not all of them are handled in (all) sdk we build with. +// Still we do guard all the usages with runtime ifs, so there is no need to intro addidtional preprocessor magic + + +// ---------------------------------------------------------------------------- +// Texture Formats +// + +#ifndef GL_BGRA_EXT + #define GL_BGRA_EXT 0x80E1 +#endif +#ifndef GL_ETC1_RGB8_OES + #define GL_ETC1_RGB8_OES 0x8D64 +#endif +#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT + #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#endif +#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#endif +#ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#endif +#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif +#ifndef GL_COMPRESSED_SRGB_S3TC_DXT1_NV + #define GL_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C +#endif +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV + #define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D +#endif +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV + #define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E +#endif +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV + #define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F +#endif +#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG + #define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#endif +#ifndef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG + #define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#endif +#ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG + #define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#endif +#ifndef GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG + #define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif +#ifndef GL_ATC_RGB_AMD + #define GL_ATC_RGB_AMD 0x8C92 +#endif +#ifndef GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD + #define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +#ifndef GL_HALF_FLOAT_OES + #define GL_HALF_FLOAT_OES 0x8D61 +#endif +#ifndef GL_SRGB_EXT + #define GL_SRGB_EXT 0x8C40 +#endif +#ifndef GL_SRGB_ALPHA_EXT + #define GL_SRGB_ALPHA_EXT 0x8C42 +#endif + + +// ---------------------------------------------------------------------------- +// GL_EXT_blend_minmax +// + +#ifndef GL_MIN_EXT + #define GL_MIN_EXT 0x8007 +#endif + +#ifndef GL_MAX_EXT + #define GL_MAX_EXT 0x8008 +#endif + +// ---------------------------------------------------------------------------- +// GL_EXT_debug_marker +// + +typedef void (*glPushGroupMarkerEXTFunc)(int len, const char* name); +typedef void (*glPopGroupMarkerEXTFunc)(); + + +// ---------------------------------------------------------------------------- +// GL_EXT_discard_framebuffer +// + +#ifndef GL_COLOR_EXT + #define GL_COLOR_EXT 0x1800 +#endif +#ifndef GL_DEPTH_EXT + #define GL_DEPTH_EXT 0x1801 +#endif +#ifndef GL_STENCIL_EXT + #define GL_STENCIL_EXT 0x1802 +#endif + +typedef void (*glDiscardFramebufferEXTFunc)(GLenum target, GLsizei numAttachments, const GLenum *attachments); + + +// ---------------------------------------------------------------------------- +// GL_EXT_occlusion_query_boolean +// Note: while we dont use occlusion queries, all queries ext are based on that one +// + +#ifndef GL_QUERY_RESULT_EXT + #define GL_QUERY_RESULT_EXT 0x8866 +#endif +#ifndef GL_QUERY_RESULT_AVAILABLE_EXT + #define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867 +#endif + +typedef void (*glGenQueriesEXTFunc)(GLuint n, GLuint *ids); +typedef void (*glDeleteQueriesEXTFunc)(GLuint n, const GLuint *ids); +typedef void (*glBeginQueryEXTFunc)(GLuint target, GLuint id); +typedef void (*glEndQueryEXTFunc)(GLuint target); +typedef void (*glGetQueryObjectuivEXTFunc)(GLuint id, GLuint pname, GLuint *params); + + +// ---------------------------------------------------------------------------- +// GL_EXT_shadow_samplers +// + +#ifndef GL_TEXTURE_COMPARE_MODE_EXT + #define GL_TEXTURE_COMPARE_MODE_EXT 0x884C +#endif +#ifndef GL_TEXTURE_COMPARE_FUNC_EXT + #define GL_TEXTURE_COMPARE_FUNC_EXT 0x884D +#endif +#ifndef GL_COMPARE_REF_TO_TEXTURE_EXT + #define GL_COMPARE_REF_TO_TEXTURE_EXT 0x884E +#endif +#ifndef GL_SAMPLER_2D_SHADOW_EXT + #define GL_SAMPLER_2D_SHADOW_EXT 0x8B62 +#endif + + +// ---------------------------------------------------------------------------- +// GL_EXT_texture_rg +// + +#ifndef GL_RED_EXT + #define GL_RED_EXT 0x1903 +#endif +#ifndef GL_RG_EXT + #define GL_RG_EXT 0x8227 +#endif + + +// ---------------------------------------------------------------------------- +// GL_OES_get_program_binary +// + +#ifndef GL_PROGRAM_BINARY_LENGTH_OES + #define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 +#endif + +#ifndef GL_NUM_PROGRAM_BINARY_FORMATS_OES + #define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE +#endif + +typedef void (*glGetProgramBinaryOESFunc)(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary); +typedef void (*glProgramBinaryOESFunc)(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); + + +// ---------------------------------------------------------------------------- +// GL_OES_mapbuffer +// + +#ifndef GL_WRITE_ONLY_OES + #define GL_WRITE_ONLY_OES 0x88B9 +#endif + +typedef void* (*glMapBufferOESFunc)(GLenum target, GLenum access); +typedef GLboolean (*glUnmapBufferOESFunc)(GLenum target); + + +// ---------------------------------------------------------------------------- +// GL_EXT_map_buffer_range +// + +#ifndef GL_MAP_READ_BIT_EXT + #define GL_MAP_READ_BIT_EXT 0x0001 +#endif +#ifndef GL_MAP_WRITE_BIT_EXT + #define GL_MAP_WRITE_BIT_EXT 0x0002 +#endif +#ifndef GL_MAP_INVALIDATE_RANGE_BIT_EXT + #define GL_MAP_INVALIDATE_RANGE_BIT_EXT 0x0004 +#endif +#ifndef GL_MAP_INVALIDATE_BUFFER_BIT_EXT + #define GL_MAP_INVALIDATE_BUFFER_BIT_EXT 0x0008 +#endif +#ifndef GL_MAP_FLUSH_EXPLICIT_BIT_EXT + #define GL_MAP_FLUSH_EXPLICIT_BIT_EXT 0x0010 +#endif +#ifndef GL_MAP_UNSYNCHRONIZED_BIT_EXT + #define GL_MAP_UNSYNCHRONIZED_BIT_EXT 0x0020 +#endif + +typedef void* (*glMapBufferRangeEXTFunc)(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); +typedef void (*glFlushMappedBufferRangeEXTFunc)(GLenum target, GLintptr offset, GLsizeiptr length); + + + +// ---------------------------------------------------------------------------- +// GL_APPLE_framebuffer_multisample +// + +#ifndef GL_MAX_SAMPLES_APPLE + #define GL_MAX_SAMPLES_APPLE 0x8D57 +#endif +#ifndef GL_READ_FRAMEBUFFER_APPLE + #define GL_READ_FRAMEBUFFER_APPLE 0x8CA8 +#endif +#ifndef GL_DRAW_FRAMEBUFFER_APPLE + #define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9 +#endif + + +typedef void (*glRenderbufferStorageMultisampleAPPLEFunc)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (*glResolveMultisampleFramebufferAPPLEFunc)(void); + + +// ---------------------------------------------------------------------------- +// GL_IMG_multisampled_render_to_texture +// + +#ifndef GL_MAX_SAMPLES_IMG + #define GL_MAX_SAMPLES_IMG 0x9135 +#endif + +typedef void (*glRenderbufferStorageMultisampleIMGFunc)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (*glFramebufferTexture2DMultisampleIMGFunc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); + + +// ---------------------------------------------------------------------------- +// GL_EXT_multisampled_render_to_texture +// + +#ifndef GL_MAX_SAMPLES_EXT +#define GL_MAX_SAMPLES_EXT 0x8D57 +#endif + +typedef void (*glRenderbufferStorageMultisampleEXTFunc)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (*glFramebufferTexture2DMultisampleEXTFunc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); + + +// ---------------------------------------------------------------------------- +// GL_NV_draw_buffers +// + +#ifndef GL_MAX_DRAW_BUFFERS_NV + #define GL_MAX_DRAW_BUFFERS_NV 0x8824 +#endif +#ifndef GL_COLOR_ATTACHMENT0_NV + #define GL_COLOR_ATTACHMENT0_NV 0x8CE0 +#endif + +typedef void (*glDrawBuffersNVFunc)(int len, const GLenum* bufs); + + +// ---------------------------------------------------------------------------- +// GL_NV_timer_query +// + +#ifndef GL_TIME_ELAPSED_NV + #define GL_TIME_ELAPSED_NV 0x88BF +#endif +#ifndef GL_TIMESTAMP_NV + #define GL_TIMESTAMP_NV 0x8E28 +#endif + +typedef unsigned long long int EGLuint64NV; + +typedef void (*glQueryCounterNVFunc)(GLuint target, GLuint id); +typedef void (*glGetQueryObjectui64vNVFunc)(GLuint id, GLuint pname, EGLuint64NV *params); + + +// ---------------------------------------------------------------------------- +// GL_QCOM_alpha_test +// + +#ifndef GL_ALPHA_TEST_QCOM + #define GL_ALPHA_TEST_QCOM 0x0BC0 +#endif + +typedef void (*glAlphaFuncQCOMFunc)(GLenum func, GLfloat ref); + + +// ---------------------------------------------------------------------------- +// common place to get function pointers +// + +struct +GlesExtFunc +{ + glPushGroupMarkerEXTFunc glPushGroupMarkerEXT; + glPopGroupMarkerEXTFunc glPopGroupMarkerEXT; + glDiscardFramebufferEXTFunc glDiscardFramebufferEXT; + glGenQueriesEXTFunc glGenQueriesEXT; + glDeleteQueriesEXTFunc glDeleteQueriesEXT; + glGetQueryObjectuivEXTFunc glGetQueryObjectuivEXT; + + glGetProgramBinaryOESFunc glGetProgramBinaryOES; + glProgramBinaryOESFunc glProgramBinaryOES; + + glMapBufferOESFunc glMapBufferOES; + glUnmapBufferOESFunc glUnmapBufferOES; + + glMapBufferRangeEXTFunc glMapBufferRangeEXT; + glFlushMappedBufferRangeEXTFunc glFlushMappedBufferRangeEXT; + + + glRenderbufferStorageMultisampleAPPLEFunc glRenderbufferStorageMultisampleAPPLE; + glResolveMultisampleFramebufferAPPLEFunc glResolveMultisampleFramebufferAPPLE; + + glRenderbufferStorageMultisampleIMGFunc glRenderbufferStorageMultisampleIMG; + glFramebufferTexture2DMultisampleIMGFunc glFramebufferTexture2DMultisampleIMG; + + glRenderbufferStorageMultisampleEXTFunc glRenderbufferStorageMultisampleEXT; + glFramebufferTexture2DMultisampleEXTFunc glFramebufferTexture2DMultisampleEXT; + + glDrawBuffersNVFunc glDrawBuffersNV; + glQueryCounterNVFunc glQueryCounterNV; + glGetQueryObjectui64vNVFunc glGetQueryObjectui64vNV; + + glAlphaFuncQCOMFunc glAlphaFuncQCOM; + + void InitExtFunc(); +}; +extern GlesExtFunc gGlesExtFunc; diff --git a/Runtime/GfxDevice/opengles20/VBOGLES20.cpp b/Runtime/GfxDevice/opengles20/VBOGLES20.cpp new file mode 100644 index 0000000..01b715b --- /dev/null +++ b/Runtime/GfxDevice/opengles20/VBOGLES20.cpp @@ -0,0 +1,1559 @@ +#include "UnityPrefix.h" + +//chai +//#define GFX_SUPPORTS_OPENGLES20 1 + +#if GFX_SUPPORTS_OPENGLES20 +#include "VBOGLES20.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Misc/Allocator.h" +#include "Runtime/Filters/Renderer.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/Utilities/Prefetch.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/GfxDevice/BatchRendering.h" +#include "IncludesGLES20.h" +#include "AssertGLES20.h" +#include "GpuProgramsGLES20.h" +#include "DebugGLES20.h" +#include "Runtime/Profiler/TimeHelper.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/GfxDevice/GLESChannels.h" +#include "Runtime/GfxDevice/GLDataBufferCommon.h" +#include "Runtime/Profiler/MemoryProfiler.h" + + +static const GLenum kTopologyGLES2[kPrimitiveTypeCount] = { + GL_TRIANGLES, + GL_TRIANGLE_STRIP, + GL_TRIANGLES, + GL_LINES, + GL_LINE_STRIP, + GL_POINTS, +}; + +template <typename T> +inline T Align (T v, size_t alignment) +{ + return (v + (alignment-1)) & ~(alignment-1); +} + +extern void VBOContainsColorGLES20 (bool flag); +extern void GfxDeviceGLES20_SetDrawCallTopology(GfxPrimitiveType topology); + +#define DISABLE_GLES_CALLS 0 +#define DISABLE_DRAW_CALLS_ONLY 0 + + +static UInt32 sCurrentTargetMap = 0; +void InvalidateVertexInputCacheGLES20() +{ + GLES_CHK(glDisableVertexAttribArray(GL_VERTEX_ARRAY)); + GLES_CHK(glDisableVertexAttribArray(GL_NORMAL_ARRAY)); + GLES_CHK(glDisableVertexAttribArray(GL_COLOR_ARRAY)); + for (size_t q = 0; q < gGraphicsCaps.maxTexImageUnits; ++q) + { + if (GL_TEXTURE_ARRAY0 + q < gGraphicsCaps.gles20.maxAttributes) + { + GLES_CHK(glDisableVertexAttribArray(GL_TEXTURE_ARRAY0 + q)); + } + } + sCurrentTargetMap = 0; +} + +static UInt32 MaskUnavailableChannels(UInt32 targetMap, UInt32 unavailableChannels) +{ + if (unavailableChannels == 0) + return targetMap; + + #define MASK_UNAVAILABLE_CHANNEL(schnl, vchnl) if (unavailableChannels & schnl) targetMap &= ~vchnl; + + MASK_UNAVAILABLE_CHANNEL(VERTEX_FORMAT1(Vertex), kVtxChnVertex); + MASK_UNAVAILABLE_CHANNEL(VERTEX_FORMAT1(Color), kVtxChnColor); + MASK_UNAVAILABLE_CHANNEL(VERTEX_FORMAT1(Normal), kVtxChnNormal); + MASK_UNAVAILABLE_CHANNEL(VERTEX_FORMAT1(TexCoord0), kVtxChnTexCoord0); + MASK_UNAVAILABLE_CHANNEL(VERTEX_FORMAT1(TexCoord1), kVtxChnTexCoord1); + MASK_UNAVAILABLE_CHANNEL(VERTEX_FORMAT1(Tangent), kVtxChnTexCoord2); + + #undef MASK_UNAVAILABLE_CHANNEL + + return targetMap; +} + +#if NV_STATE_FILTERING +typedef struct +{ + GLint size; + GLenum type; + GLboolean normalized; + GLsizei stride; + GLuint buffer; + const GLvoid* pointer; +} FilteredVertexAttribPointer; +static GLuint boundBuffers[2]; +static FilteredVertexAttribPointer* currPointers = 0; +static GLint max_attribs; + +void filteredInitGLES20() +{ + static bool firstCall = true; + if (!firstCall) + return; + firstCall = false; + + memset(boundBuffers, 0, 2*sizeof(GLuint)); + + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_attribs); + currPointers = new FilteredVertexAttribPointer[max_attribs]; // this memory is considered 'static' and is never freed. + memset(currPointers, 0x00, max_attribs * sizeof(FilteredVertexAttribPointer)); +} + +void filteredBindBufferGLES20(GLenum target, GLuint buffer, bool isImmediate) +{ + int index = 0; + if (target == GL_ELEMENT_ARRAY_BUFFER) + index = 1; + + if ( (target != GL_ELEMENT_ARRAY_BUFFER && target != GL_ARRAY_BUFFER) || + (boundBuffers[index] != buffer)) + { + boundBuffers[index] = buffer; + glBindBuffer(target, buffer); + + if (buffer && !isImmediate) + { + // TODO: This is to flush the matrix to the shader, but why is it needed? + // Isn't the matrix set when switching buffer elsewhere? + void GfxDeviceGLES20_MarkWorldViewProjDirty(); + GfxDeviceGLES20_MarkWorldViewProjDirty(); + } + } +} + +void filteredVertexAttribPointerGLES20(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) +{ + bool doCall = false; + if (index < 0 || index >= max_attribs) + { + doCall = true; + } + else + { + FilteredVertexAttribPointer &p = currPointers[index]; + if (p.buffer != boundBuffers[0] || p.size != size || p.type != type || p.normalized != normalized || p.stride != stride || p.pointer != pointer) + { + doCall = true; + p.buffer = boundBuffers[0]; + p.size = size; + p.type = type; + p.normalized = normalized; + p.stride = stride; + p.pointer = pointer; + } + } + if (doCall) + { + glVertexAttribPointer(index, size, type, normalized, stride, pointer); + } +} + +void filteredDeleteBuffersGLES20(GLsizei n, const GLuint *buffers) +{ + if (buffers && n) + { + for (int i = 0; i < n; i++) + { + for (int j = 0; j < max_attribs; j++) + { + if (currPointers[j].buffer == buffers[i]) + { + memset(&currPointers[j], 0, sizeof(FilteredVertexAttribPointer)); + } + } + } + } + glDeleteBuffers(n, buffers); +} + +#ifndef glBindBuffer +#define glBindBuffer filteredBindBufferGLES20 +#endif +#ifndef glDeleteBuffers +#define glDeleteBuffers filteredDeleteBuffersGLES20 +#endif +#ifndef glVertexAttribPointer +#define glVertexAttribPointer filteredVertexAttribPointerGLES20 +#endif + +void StateFiltering_InvalidateVBOCacheGLES20() +{ + memset(boundBuffers, 0, 2*sizeof(GLuint)); + if(currPointers) + memset(currPointers, 0x00, max_attribs * sizeof(FilteredVertexAttribPointer)); +} + + +#endif + + +#define SETUP_VERTEX_CHANNEL(vchnl, vcomp, glArray, norm, channelSize, channelType, stride, ptr) \ + if (targetMap & vchnl) \ + { \ + if (channelsToEnable & vchnl) { \ + GLES_CHK(glEnableVertexAttribArray(glArray)); \ + } \ + const ShaderChannel src = channels.GetSourceForTarget( vcomp ); \ + GLES_CHK(glVertexAttribPointer(glArray, channelSize, channelType, norm, stride, ptr));\ + } else if (channelsToDisable & vchnl) { \ + GLES_CHK(glDisableVertexAttribArray(glArray)); \ + } \ + +#define SETUP_TEXCOORD_CHANNEL(vchnl, vcomp, glTex, setFunc) \ + if (targetMap & vchnl) \ + { \ + if (channelsToEnable & vchnl) { \ + GLES_CHK(glEnableVertexAttribArray(GL_TEXTURE_COORD_ARRAY)); \ + } \ + const ShaderChannel src = channels.GetSourceForTarget( vcomp ); \ + setFunc; \ + } else if (channelsToDisable & vchnl) { \ + GLES_CHK(glEnableVertexAttribArray(GL_TEXTURE_COORD_ARRAY)); \ + } + +// TODO: normalize normals??? +#define LINK_TEXCOORD_CHANNEL(glTex) \ + GLES_CHK(glEnableVertexAttribArray(glTex)); \ + GLES_CHK(glVertexAttribPointer(glTex, channelSizes[src], channelTypes[src], false, \ + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src]))); + + +#if UNITY_ANDROID || UNITY_TIZEN +static void WorkaroundMaliBug(const UInt32 strides[kShaderChannelCount], void* dataChannel[kShaderChannelCount]) +{ + // on Mali (first devices) there is bug in driver + // that results in attributes from interleaved streams + // remain active, even though they are disabled + // as a workaround, find any non null ptr in dataChannel and set it + + void* readPtr = 0; + UInt32 stride = 0; + for( unsigned i = 0 ; i < kShaderChannelCount && !readPtr ; ++i) + { + readPtr = dataChannel[i]; + stride = strides[i]; + } + + GLES_CHK(glVertexAttribPointer(GL_VERTEX_ARRAY, 3, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_COLOR_ARRAY, 4, GL_UNSIGNED_BYTE, true, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_NORMAL_ARRAY, 3, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY0, 2, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY1, 2, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY2, 2, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY3, 2, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY4, 2, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY5, 2, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY6, 2, GL_FLOAT, false, stride, readPtr)); + GLES_CHK(glVertexAttribPointer(GL_TEXTURE_ARRAY7, 2, GL_FLOAT, false, stride, readPtr)); + + InvalidateVertexInputCacheGLES20(); +} +#endif + +//Èç¹ûÊDz»ÓÃVBOµÄģʽ£¬Ö±½ÓÉÏ´«¶¥µãÊý¾Ý +static void SetupVertexInput(const ChannelAssigns& channels, void* dataChannel[kShaderChannelCount], const UInt32 strides[kShaderChannelCount], const int channelSizes[kShaderChannelCount], const GLenum channelTypes[kShaderChannelCount], UInt32 unavailableChannels = 0) +{ +#if DISABLE_GLES_CALLS + return; +#endif + GfxDevice& device = GetRealGfxDevice(); + +#if UNITY_ANDROID || UNITY_TIZEN + if( gGraphicsCaps.gles20.buggyDisableVAttrKeepsActive ) + WorkaroundMaliBug(strides, dataChannel); +#endif + + UInt32 targetMap = MaskUnavailableChannels(channels.GetTargetMap(), unavailableChannels); + + const UInt32 channelsDiff = sCurrentTargetMap ^ targetMap; + const UInt32 channelsToEnable = channelsDiff & targetMap; + const UInt32 channelsToDisable = channelsDiff & (~targetMap); + + SETUP_VERTEX_CHANNEL(kVtxChnVertex, kVertexCompVertex, GL_VERTEX_ARRAY, false, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + + SETUP_VERTEX_CHANNEL(kVtxChnColor, kVertexCompColor, GL_COLOR_ARRAY, true, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + + SETUP_VERTEX_CHANNEL(kVtxChnNormal, kVertexCompNormal, GL_NORMAL_ARRAY, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + + + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord0, kVertexCompTexCoord0, GL_TEXTURE_ARRAY0, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord1, kVertexCompTexCoord1, GL_TEXTURE_ARRAY1, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord2, kVertexCompTexCoord2, GL_TEXTURE_ARRAY2, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord3, kVertexCompTexCoord3, GL_TEXTURE_ARRAY3, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord4, kVertexCompTexCoord4, GL_TEXTURE_ARRAY4, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord5, kVertexCompTexCoord5, GL_TEXTURE_ARRAY5, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord6, kVertexCompTexCoord6, GL_TEXTURE_ARRAY6, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + SETUP_VERTEX_CHANNEL(kVtxChnTexCoord7, kVertexCompTexCoord7, GL_TEXTURE_ARRAY7, channelTypes[src] == GL_BYTE, + channelSizes[src], channelTypes[src], + strides[src], reinterpret_cast<GLvoid const*>(dataChannel[src])); + + sCurrentTargetMap = targetMap; + + // setup fixed function texGens + const UInt32 sourceMap = channels.GetSourceMap(); + { + const ShaderChannel src = kShaderChannelVertex; + if( device.IsPositionRequiredForTexGen() && (sourceMap & (1 << src)) ) + { + for (int texUnit = 0; texUnit < gGraphicsCaps.maxTexImageUnits; ++texUnit) + { + if( device.IsPositionRequiredForTexGen(texUnit) ) + { + // pass position as tex-coord, if required by texgen operation + LINK_TEXCOORD_CHANNEL(GL_TEXTURE_ARRAY0 + texUnit); + Assert(texUnit < ARRAY_SIZE(sTexCoordChannels)); + sCurrentTargetMap |= sTexCoordChannels[texUnit]; + } + } + } + } + + { + const ShaderChannel src = kShaderChannelNormal; + if( device.IsNormalRequiredForTexGen() && (sourceMap & (1 << src)) ) + { + for (int texUnit = 0; texUnit < gGraphicsCaps.maxTexImageUnits; ++texUnit) + { + if( device.IsNormalRequiredForTexGen(texUnit) ) + { + // pass normal as tex-coord, if required by texgen operation + LINK_TEXCOORD_CHANNEL(GL_TEXTURE_ARRAY0 + texUnit); + Assert(texUnit < ARRAY_SIZE(sTexCoordChannels)); + sCurrentTargetMap |= sTexCoordChannels[texUnit]; + } + } + } + } +} + +/* +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +*/ + + +//chai: +// called by +// DrawVBO() +// DrawCustomIndexed() +void GLES2VBO::DrawInternal(int vertexBufferID, int indexBufferID, const ChannelAssigns& channels, void* indices, UInt32 indexCount, GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount) +{ + UInt32 unavailableChannels = GetUnavailableChannels(channels); + + // should never happen; a dummy all-white vertex color array is always created by Mesh code + AssertIf( unavailableChannels & (1<<kShaderChannelColor) ); + +#if DISABLE_GLES_CALLS + return; +#endif + + DBG_LOG_GLES20("---> GLES2VBO::DrawVBO indexCount:%d channels: %04X/%04X, unavailable: %04X", (int)indexCount, channels.GetTargetMap(), channels.GetSourceMap(), unavailableChannels, unavailableChannels); + + VBOContainsColorGLES20 (channels.GetSourceForTarget (kVertexCompColor) == kShaderChannelColor); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID)); + + // setup vertex state + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, vertexBufferID)); + void* channelData[kShaderChannelCount]; + UInt32 channelStrides[kShaderChannelCount]; + if (vertexBufferID != 0) + GetChannelOffsetsAndStrides(channelData, channelStrides); + else + GetChannelDataAndStrides(channelData, channelStrides); + + int channelSizes[kShaderChannelCount]; + GLenum channelTypes[kShaderChannelCount]; + SetupGLESChannelSizes(m_Channels, channelSizes); + SetupGLESChannelTypes(m_Channels, channelTypes); + SetupVertexInput(channels, channelData, channelStrides, channelSizes, channelTypes, unavailableChannels); + + GfxDeviceGLES20_SetDrawCallTopology(topology); + + //chai: ÔÚÕâÀïÉèÖÃʹÓõÄshader£¬²¢ÉèÖÃuniforms + //stack: + // GfxDevice::BeforeDrawCall + // GpuProgramsGLES20::ApplyGpuProgramES20 + GetRealGfxDevice().BeforeDrawCall(false); + +#if DBG_LOG_GLES20_ACTIVE + DumpVertexArrayStateGLES20(); +#endif + + // draw +#if !DISABLE_DRAW_CALLS_ONLY + ABSOLUTE_TIME drawDt = START_TIME; + GLenum gltopo = kTopologyGLES2[topology]; + GLES_CHK(glDrawElements(gltopo, indexCount, GL_UNSIGNED_SHORT, indices)); + drawDt = ELAPSED_TIME(drawDt); + + int primCount = GetPrimitiveCount(indexCount, topology, false); + GetRealGfxDevice().GetFrameStats().AddDrawCall (primCount, drawVertexCount, drawDt); +#endif +} + +void GLES2VBO::DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ) +{ + int indexBufferID = m_IndexBufferID; + void* indexBufferData = (UInt8*)(m_IndexBufferID ? 0 : m_IBData.indices) + firstIndexByte; + + // If we're drawing quads, convert them into triangles; into a temporary index buffer area + void* tempIndexBuffer = NULL; + if (topology == kPrimitiveQuads) + { + UInt32 ibCapacityNeeded = indexCount/4*6*2; + + // Get IB space from shared buffer or just allocate + void* ibPtr; + if (gGraphicsCaps.gles20.slowDynamicVBO) + { + ibPtr = UNITY_MALLOC(kMemDynamicGeometry, ibCapacityNeeded); + tempIndexBuffer = ibPtr; + } + else + { + ibPtr = LockSharedBufferGLES20 (GL_ELEMENT_ARRAY_BUFFER, ibCapacityNeeded); + } + DebugAssert (ibPtr); + + // Convert quads into triangles + FillIndexBufferForQuads ((UInt16*)ibPtr, ibCapacityNeeded, (const UInt16*)((UInt8*)m_ReadableIndices + firstIndexByte), indexCount/4); + + // Finish up with temporary space + if (gGraphicsCaps.gles20.slowDynamicVBO) + { + indexBufferID = 0; + indexBufferData = ibPtr; + } + else + { + indexBufferID = UnlockSharedBufferGLES20 (); + indexBufferData = NULL; + } + indexCount = indexCount/4*6; + } + + // Draw! + DrawInternal( m_UsesVBO ? m_VertexBufferID[m_CurrentBufferIndex] : 0, indexBufferID, channels, indexBufferData, indexCount, + topology, firstVertex, firstVertex+vertexCount, vertexCount); + + // Release any temporary buffer we might have allocated + if (tempIndexBuffer) + { + UNITY_FREE(kMemDynamicGeometry, tempIndexBuffer); + } +} + +void GLES2VBO::DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ) +{ + Assert (topology != kPrimitiveQuads); // only called by static batching; which only handles triangles + + int ibo = 0; + if(!gGraphicsCaps.gles20.forceStaticBatchFromMem) + { + // we expect static batches to be quite large ibos, and in that case drawing from memory is worst case scenario + // sure, unless running on some buggy piece of sh**t + const size_t ibCapacity = indexCount * kVBOIndexSize; + void* dstIndices = LockSharedBufferGLES20 (GL_ELEMENT_ARRAY_BUFFER, ibCapacity, true); + DebugAssert (dstIndices); + memcpy (dstIndices, indices, ibCapacity); + ibo = UnlockSharedBufferGLES20 (0, true); + indices = 0; + } + + DrawInternal( m_UsesVBO ? m_VertexBufferID[m_CurrentBufferIndex] : 0, ibo, channels, indices, indexCount, + topology, vertexRangeBegin, vertexRangeEnd, drawVertexCount); +} + +GLES2VBO::GLES2VBO() +: m_CurrentBufferIndex(0) +, m_IndexBufferID(0) +, m_IBSize(0) +, m_ReadableIndices(0) +, m_VBOUsage(GL_STATIC_DRAW) +, m_IBOUsage(GL_STATIC_DRAW) +, m_UsesVBO(false) +, m_UsesIBO(false) +{ + ::memset(m_VertexBufferID, 0x0, sizeof(m_VertexBufferID)); + ::memset(&m_IBData, 0, sizeof(m_IBData)); +} + +GLES2VBO::~GLES2VBO() +{ + Cleanup (); +} + +void GLES2VBO::Cleanup() +{ + int bufferCount = HasStreamWithMode(kStreamModeDynamic) ? DynamicVertexBufferCount : 1; + glDeregisterBufferData(bufferCount, (GLuint*)m_VertexBufferID); + GLES_CHK(glDeleteBuffers(bufferCount, (GLuint*)m_VertexBufferID)); + ::memset(m_VertexBufferID, 0x0, sizeof(m_VertexBufferID)); + + if (m_IndexBufferID) + { + glDeregisterBufferData(1, (GLuint*)&m_IndexBufferID); + GLES_CHK(glDeleteBuffers(1, (GLuint*)&m_IndexBufferID)); + m_IndexBufferID = 0; + } + + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); +} + +void GLES2VBO::Recreate() +{ + MarkBuffersLost(); + + if(m_VertexData.bufferSize > 0) + EnsureVerticesInited(true); + + if(m_IBSize > 0) + EnsureIndicesInited(); +} + +bool GLES2VBO::IsVertexBufferLost() const +{ + return (m_VertexBufferID[m_CurrentBufferIndex] == 0 && m_UsesVBO); +} + +bool GLES2VBO::IsIndexBufferLost() const +{ + return (m_IndexBufferID == 0 && m_UsesIBO); +} + +void GLES2VBO::MarkBuffersLost() +{ + ::memset(m_VertexBufferID, 0x0, sizeof(m_VertexBufferID)); + m_IndexBufferID = 0; + + // we also want to pretend we use vbo/ibo to hit "lost" path + // in case of vbo we also need to get rid of bufferedvbo copy + + if(!m_UsesVBO) + { + UnbufferVertexData(); + m_UsesVBO = true; + } + m_UsesIBO = true; +} + + +bool GLES2VBO::MapVertexStream(VertexStreamData& outData, unsigned stream) +{ + DebugAssert(!IsAnyStreamMapped()); + Assert(m_VertexData.bufferSize > 0); + + if(HasStreamWithMode(kStreamModeDynamic)) + m_CurrentBufferIndex = (m_CurrentBufferIndex + 1) % DynamicVertexBufferCount; + else + m_CurrentBufferIndex = 0; + + // TODO: make it possible to change m_UsesVBO at runtime + // for now once we use mapbuffer, the buffered data is lost so no going back + + if(m_UsesVBO && (gGraphicsCaps.gles20.hasMapbuffer || gGraphicsCaps.gles20.hasMapbufferRange)) + { + static const int _MapRangeFlags = GL_MAP_WRITE_BIT_EXT | GL_MAP_INVALIDATE_BUFFER_BIT_EXT; + + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, m_VertexBufferID[m_CurrentBufferIndex])); + + void* buf = 0; + if(gGraphicsCaps.gles20.hasMapbufferRange) + buf = gGlesExtFunc.glMapBufferRangeEXT(GL_ARRAY_BUFFER, 0, m_VertexData.bufferSize, _MapRangeFlags); + else + buf = gGlesExtFunc.glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES); + + GLESAssert(); + if(buf) + { + const StreamInfo& info = m_VertexData.streams[stream]; + outData.buffer = (UInt8*)buf + info.offset; + outData.channelMask = info.channelMask; + outData.stride = info.stride; + outData.vertexCount = m_VertexData.vertexCount; + + UnbufferVertexData(); + m_IsStreamMapped[stream] = true; + } + return buf != 0; + } + + return BufferedVBO::MapVertexStream(outData, stream); +} + +void GLES2VBO::UnmapVertexStream( unsigned stream ) +{ + Assert(m_IsStreamMapped[stream]); + Assert(m_VertexData.bufferSize > 0); + + m_IsStreamMapped[stream] = false; + if(m_UsesVBO) + { + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, m_VertexBufferID[m_CurrentBufferIndex])); + if(gGraphicsCaps.gles20.hasMapbuffer || gGraphicsCaps.gles20.hasMapbufferRange) + GLES_CHK(gGlesExtFunc.glUnmapBufferOES(GL_ARRAY_BUFFER)); + else + GLES_CHK(glBufferSubData(GL_ARRAY_BUFFER, 0, m_VertexData.bufferSize, m_VertexData.buffer)); + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); + } +} + +// the threshold is pretty arbitrary: +// from our tests on "slowDynamicVBO" gpus "small" buffers are faster drawn from mem, and "bigger" ones as buffers (like normal case) +// so we just pick something as small buffer threshold and be gone + +static const int _SmallBufferSizeThreshold = 1024; + +bool GLES2VBO::ShouldUseVBO() +{ + if(HasStreamWithMode(kStreamModeDynamic) && gGraphicsCaps.gles20.slowDynamicVBO) + return m_VertexData.bufferSize > _SmallBufferSizeThreshold; + + return true; +} + +bool GLES2VBO::ShouldUseIBO() +{ + if(AreIndicesDynamic() && gGraphicsCaps.gles20.slowDynamicVBO) + return m_IBData.count * kVBOIndexSize > _SmallBufferSizeThreshold; + + return true; +} + + +void GLES2VBO::EnsureVerticesInited(bool newBuffers) +{ + bool isDynamic = HasStreamWithMode(kStreamModeDynamic); + + int createStart = 0; + int createCount = 0; + if(m_VertexBufferID[0] == 0) + { + // initial create + createCount = isDynamic ? DynamicVertexBufferCount : 1; + newBuffers = true; + } + else if(m_VertexBufferID[1] == 0 && isDynamic) + { + // changed to dynamic + createStart = 1; + createCount = DynamicVertexBufferCount - 1; + newBuffers = true; + } + else if(m_VertexBufferID[1] != 0 && !isDynamic) + { + // changed to static + glDeregisterBufferData(DynamicVertexBufferCount-1, (GLuint*)&m_VertexBufferID[1]); + GLES_CHK(glDeleteBuffers(DynamicVertexBufferCount-1, (GLuint*)&m_VertexBufferID[1])); + ::memset(&m_VertexBufferID[1], 0x0, (DynamicVertexBufferCount-1)*sizeof(int)); + } + + m_VBOUsage = isDynamic ? GL_STREAM_DRAW : GL_STATIC_DRAW; + m_UsesVBO = ShouldUseVBO(); + if(m_UsesVBO) + { + if(newBuffers && createCount) + GLES_CHK(glGenBuffers(createCount, (GLuint*)&m_VertexBufferID[createStart])); + + // TODO: the only reason to fill whole VB is for multi-stream support + // TODO: somehow check if we can get away with less data copied + for(int i = 0, count = isDynamic ? DynamicVertexBufferCount : 1 ; i < count ; ++i) + { + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, m_VertexBufferID[i])); + if(newBuffers) + { + GLES_CHK(glBufferData(GL_ARRAY_BUFFER, m_VertexData.bufferSize, m_VertexData.buffer, m_VBOUsage)); + glRegisterBufferData(m_VertexBufferID[i], m_VertexData.bufferSize, this); + } + else + { + GLES_CHK(glBufferSubData(GL_ARRAY_BUFFER, 0, m_VertexData.bufferSize, m_VertexData.buffer)); + } + GetRealGfxDevice().GetFrameStats().AddUploadVBO(m_VertexData.bufferSize); + } + + // now the hacky stuff - we dont actually need extra mem copy as we will recreate VBO from mesh + // on the other hand we still need it if we want to map stream + // by coincidence ;-) we will map only when having dynamic streams, and kStreamModeWritePersist (for cloth) + if(!HasStreamWithMode(kStreamModeDynamic) && !HasStreamWithMode(kStreamModeWritePersist)) + UnbufferVertexData(); + } + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); + m_CurrentBufferIndex = 0; +} + +void GLES2VBO::EnsureIndicesInited() +{ + m_IBOUsage = AreIndicesDynamic() ? GL_STREAM_DRAW : GL_STATIC_DRAW; + m_UsesIBO = ShouldUseIBO(); + if(m_UsesIBO) + { + const size_t size = CalculateIndexBufferSize(m_IBData); + + if(!m_IndexBufferID) + GLES_CHK(glGenBuffers(1, (GLuint*)&m_IndexBufferID)); + + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBufferID)); + GLES_CHK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, m_IBData.indices, m_IBOUsage)); + glRegisterBufferData(m_IndexBufferID, size, this); + GetRealGfxDevice().GetFrameStats().AddUploadIB(size); + m_IBSize = size; + + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + } + else if(m_IndexBufferID) + { + glDeregisterBufferData(1, (GLuint*)&m_IndexBufferID); + GLES_CHK(glDeleteBuffers(1, (GLuint*)&m_IndexBufferID)); + m_IndexBufferID = 0; + } +} + +void GLES2VBO::UpdateVertexData( const VertexBufferData& srcBuffer ) +{ + int oldVBSize = m_VertexData.bufferSize; + + BufferedVBO::BufferAllVertexData(srcBuffer); + std::copy(srcBuffer.streams, srcBuffer.streams + kMaxVertexStreams, m_Streams); + std::copy(srcBuffer.channels, srcBuffer.channels + kShaderChannelCount, m_Channels); + + EnsureVerticesInited(oldVBSize < m_VertexData.bufferSize); +} + +void GLES2VBO::UpdateIndexData (const IndexBufferData& buffer) +{ + m_IBData.indices = buffer.indices; + m_IBData.count = buffer.count; + EnsureIndicesInited(); + + m_ReadableIndices = buffer.indices; +} + +UInt32 GLES2VBO::GetUnavailableChannels(const ChannelAssigns& channels) const +{ + // Figure out which channels we can't find in the streams + UInt32 unavailableChannels = channels.GetSourceMap(); + for (int stream = 0; stream < kMaxVertexStreams; stream++) + { + unavailableChannels &= ~m_Streams[stream].channelMask; + } + return unavailableChannels; +} + +int GLES2VBO::GetRuntimeMemorySize() const +{ +#if ENABLE_MEM_PROFILER + return GetMemoryProfiler()->GetRelatedMemorySize(this) + + GetMemoryProfiler()->GetRelatedIDMemorySize((UInt32)this); +#else + return 0; +#endif +} + +/* +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +*/ + +DynamicGLES2VBO::DynamicGLES2VBO() +: m_LastRenderMode (kDrawIndexedTriangles) +, m_VB (0) +, m_LargeVB (0) +, m_ActiveVB (0) +, m_IB (0) +, m_LargeIB (0) +, m_ActiveIB (0) +, m_QuadsIB (0) +, m_IndexBufferQuadsID (0) +, m_VtxSysMemStorage(0) +, m_VtxSysMemStorageSize(0) +, m_IdxSysMemStorage(0) +, m_IdxSysMemStorageSize(0) +{ + for( int i = 0; i < kShaderChannelCount; ++i ) + { + m_BufferChannel[i] = 0; + } + + //chai: https://stackoverflow.com/questions/15297773/opengl-es-ios-drawing-performance-a-lot-slower-with-vbos-than-without + const bool willUseMemory = gGraphicsCaps.gles20.slowDynamicVBO; + const bool willUseOnlyMemory = willUseMemory && gGraphicsCaps.gles20.forceStaticBatchFromMem; + + if(willUseMemory) + { + m_VtxSysMemStorageSize = 8096; + m_VtxSysMemStorage = (UInt8*)UNITY_MALLOC_ALIGNED(kMemDynamicGeometry, m_VtxSysMemStorageSize, 32); + m_IdxSysMemStorageSize = 4096; + m_IdxSysMemStorage = (UInt16*)UNITY_MALLOC_ALIGNED(kMemDynamicGeometry, m_IdxSysMemStorageSize, 32); + } + + if(!willUseOnlyMemory) + { + if(!gGraphicsCaps.gles20.hasVBOOrphaning) + { + // total preallocated memory ~2MB, but it can grow! + // we expect mostly small VBs + m_VB = UNITY_NEW(SharedBuffer,kMemDynamicGeometry) (GL_ARRAY_BUFFER, 8096, 32, false); + m_IB = UNITY_NEW(SharedBuffer,kMemDynamicGeometry) (GL_ELEMENT_ARRAY_BUFFER, 4096, 16, false); + m_LargeVB = UNITY_NEW(SharedBuffer,kMemDynamicGeometry) (GL_ARRAY_BUFFER, 32768, 32, false); + m_LargeIB = UNITY_NEW(SharedBuffer,kMemDynamicGeometry) (GL_ELEMENT_ARRAY_BUFFER, 16384, 32, false); + } + else + { + //chai: Ö§³ÖVBO orphaning£¬±ÜÃâimplicit synchronization + m_VB = UNITY_NEW(SharedBuffer,kMemDynamicGeometry) (GL_ARRAY_BUFFER, 32768); + m_IB = UNITY_NEW(SharedBuffer,kMemDynamicGeometry) (GL_ELEMENT_ARRAY_BUFFER, 8096); + } + } +} + +DynamicGLES2VBO::~DynamicGLES2VBO () +{ + UNITY_FREE(kMemDynamicGeometry, m_VtxSysMemStorage); + UNITY_FREE(kMemDynamicGeometry, m_IdxSysMemStorage); + + UNITY_DELETE (m_VB, kMemDynamicGeometry); + UNITY_DELETE (m_IB, kMemDynamicGeometry); + UNITY_DELETE (m_LargeVB, kMemDynamicGeometry); + UNITY_DELETE (m_LargeIB, kMemDynamicGeometry); + + if (m_IndexBufferQuadsID) + { + glDeregisterBufferData(1, (GLuint*)&m_IndexBufferQuadsID); + GLES_CHK(glDeleteBuffers(1, (GLuint*)&m_IndexBufferQuadsID)); + } + UNITY_FREE (kMemDynamicGeometry, m_QuadsIB); +} + +void DynamicGLES2VBO::Recreate() +{ + m_IndexBufferQuadsID = 0; + + if(m_VB) m_VB->Recreate(); + if(m_IB) m_IB->Recreate(); + if(m_LargeVB) m_LargeVB->Recreate(); + if(m_LargeIB) m_LargeIB->Recreate(); +} + +inline void DynamicGLES2VBO::InitializeQuadsIB() +{ + Assert(m_IndexBufferQuadsID == 0); + + if(!m_QuadsIB) + { + m_QuadsIB = (UInt16*)UNITY_MALLOC_ALIGNED(kMemDynamicGeometry, VBO::kMaxQuads * 6 * kVBOIndexSize, 32); + Assert (m_QuadsIB); + + UInt16* ib = m_QuadsIB; + UInt32 baseIndex = 0; + for( int i = 0; i < VBO::kMaxQuads; ++i ) + { + ib[0] = baseIndex + 1; + ib[1] = baseIndex + 2; + ib[2] = baseIndex; + ib[3] = baseIndex + 2; + ib[4] = baseIndex + 3; + ib[5] = baseIndex; + baseIndex += 4; + ib += 6; + } + } + + GLES_CHK(glGenBuffers( 1, (GLuint*)&m_IndexBufferQuadsID )); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBufferQuadsID)); + GLES_CHK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, VBO::kMaxQuads * 6 * kVBOIndexSize, m_QuadsIB, GL_STATIC_DRAW)); + glRegisterBufferData(m_IndexBufferQuadsID, VBO::kMaxQuads * 6 * kVBOIndexSize, this); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); +} + +// chai: »æÖƺ¯ÊýÖ®Ò» +void DynamicGLES2VBO::DrawChunk (const ChannelAssigns& channels) +{ +#if DISABLE_GLES_CALLS + return; +#endif + + // just return if nothing to render + if( !m_LastChunkShaderChannelMask ) + return; + + AssertIf ( !m_LastChunkShaderChannelMask || !m_LastChunkStride ); + Assert (!m_LendedChunk); + + UInt8* ibPointer = (UInt8*)m_IdxSysMemStorage; + + GLuint vbo = m_VtxSysMemStorage ? 0 : m_ActiveVB->GetDrawable (); + GLuint ibo = 0; + if (m_LastRenderMode == kDrawQuads) + { + if (!m_IndexBufferQuadsID) + InitializeQuadsIB(); + ibo = m_IndexBufferQuadsID; + ibPointer = 0; + } + else if (m_ActiveIB) + { + ibo = m_ActiveIB->GetDrawable (); + } + + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, vbo)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); + + switch(m_LastRenderMode) + { + case kDrawIndexedTriangles: + case kDrawIndexedQuads: + case kDrawQuads: + GfxDeviceGLES20_SetDrawCallTopology(kPrimitiveTriangles); break; + case kDrawTriangleStrip: + case kDrawIndexedTriangleStrip: + GfxDeviceGLES20_SetDrawCallTopology(kPrimitiveTriangleStripDeprecated); break; + case kDrawIndexedLines: + GfxDeviceGLES20_SetDrawCallTopology(kPrimitiveLines); break; + case kDrawIndexedPoints: + GfxDeviceGLES20_SetDrawCallTopology(kPrimitivePoints); break; + } + + + VBOContainsColorGLES20(m_LastChunkShaderChannelMask & (1<<kShaderChannelColor)); + + //chai: ÔÚÕâÀïÉèÖÃʹÓõÄshader£¬²¢ÉèÖÃuniforms + //stack: + // GfxDevice::BeforeDrawCall + // GpuProgramsGLES20::ApplyGpuProgramES20 + GetRealGfxDevice().BeforeDrawCall( false ); + + //------------------- + // chai: µ½ÕâÀï¶¥µãÊý¾Ý\uniforms¶¼ÉèÖúÃÁË + //------------------- + + // ûÓпªÆôµÄchannel + const UInt32 unavailableChannels = channels.GetSourceMap() & ~m_LastChunkShaderChannelMask; + UInt32 strides[kShaderChannelCount]; + std::fill(strides, strides + kShaderChannelCount, m_LastChunkStride); + SetupVertexInput(channels, m_BufferChannel, strides, kDefaultChannelSizes, kDefaultChannelTypes, unavailableChannels); + + DBG_LOG_GLES20("--->"); + DBG_LOG_GLES20("--->DrawChunk"); + DBG_LOG_GLES20("--->"); + // draw +#if !DISABLE_DRAW_CALLS_ONLY + ABSOLUTE_TIME drawStartTime = START_TIME; + int primCount = 0; // ͼԪÊýÁ¿ + switch (m_LastRenderMode) + { + case kDrawIndexedTriangles: + Assert (m_LastChunkIndices != 0); + GLES_CHK(glDrawElements(GL_TRIANGLES, m_LastChunkIndices, GL_UNSIGNED_SHORT, ibPointer)); + primCount = m_LastChunkIndices/3; + break; + case kDrawTriangleStrip: + Assert (m_LastChunkIndices == 0); + GLES_CHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, m_LastChunkVertices)); + primCount = m_LastChunkVertices-2; + break; + case kDrawQuads: + GLES_CHK(glDrawElements(GL_TRIANGLES, (m_LastChunkVertices/2)*3, GL_UNSIGNED_SHORT, ibPointer)); + primCount = m_LastChunkVertices/2; + break; + case kDrawIndexedTriangleStrip: + Assert (m_LastChunkIndices != 0); + GLES_CHK(glDrawElements(GL_TRIANGLE_STRIP, m_LastChunkIndices, GL_UNSIGNED_SHORT, ibPointer)); + primCount = m_LastChunkIndices-2; + break; + case kDrawIndexedLines: + Assert(m_LastChunkIndices != 0); + GLES_CHK(glDrawElements(GL_LINES, m_LastChunkIndices, GL_UNSIGNED_SHORT, ibPointer)); + primCount = m_LastChunkIndices/2; + break; + case kDrawIndexedPoints: + Assert(m_LastChunkIndices != 0); + GLES_CHK(glDrawElements(GL_POINTS, m_LastChunkIndices, GL_UNSIGNED_SHORT, ibPointer)); + primCount = m_LastChunkIndices; + break; + case kDrawIndexedQuads: + Assert(m_LastChunkIndices != 0); + GLES_CHK(glDrawElements(GL_TRIANGLES, m_LastChunkIndices, GL_UNSIGNED_SHORT, ibPointer)); + primCount = m_LastChunkIndices/3; + break; + } + GetRealGfxDevice().GetFrameStats().AddDrawCall (primCount, m_LastChunkVertices, ELAPSED_TIME(drawStartTime)); +#endif +} + +bool DynamicGLES2VBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, DynamicVBO::RenderMode renderMode, void** outVB, void** outIB ) +{ + Assert( !m_LendedChunk ); + Assert( maxVertices < 65536 && maxIndices < 65536*3 ); + Assert(!((renderMode == kDrawQuads) && (VBO::kMaxQuads*4 < maxVertices))); + DebugAssert( outVB != NULL && maxVertices > 0 ); + DebugAssert( + (renderMode == kDrawIndexedQuads && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedPoints && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedLines && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangles && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangleStrip && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawTriangleStrip && (outIB == NULL && maxIndices == 0)) || + (renderMode == kDrawQuads && (outIB == NULL && maxIndices == 0))); + + m_LendedChunk = true; + m_LastChunkShaderChannelMask = shaderChannelMask; //chai: ÉèÖÃÆôÓõÄchannel + m_LastRenderMode = renderMode; + + if( maxVertices == 0 ) + maxVertices = 8; + + m_LastChunkStride = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( shaderChannelMask & (1<<i) ) + m_LastChunkStride += VBO::GetDefaultChannelByteSize(i); + } + DebugAssert (outVB); + const size_t vbCapacity = Align (maxVertices * m_LastChunkStride, 1024); // if size would require growing buffer, make sure to grow in descreet steps + + if(m_VtxSysMemStorage) + { + //chai: ÔÚÄÚ´æÀï·ÖÅävbCapacity´óСµÄÇøÓò + *outVB = GetVertexMemory(vbCapacity); + m_ActiveVB = 0; + } + else + { + //chai: ÉèÖÃдÈëGPU + m_ActiveVB = GetSharedVB (vbCapacity); + *outVB = m_ActiveVB->Lock (vbCapacity); + if (!*outVB) + return false; + } + + const bool indexed = (renderMode != kDrawQuads) && (renderMode != kDrawTriangleStrip); + if (maxIndices && indexed) + { + DebugAssert (outIB); + const size_t ibCapacity = Align( maxIndices * 2, 1024); // if size would require growing buffer, make sure to grow in discrete steps + + if(m_IdxSysMemStorage) + { + *outIB = GetIndexMemory(ibCapacity); + m_ActiveIB = 0; + } + else + { + m_ActiveIB = GetSharedIB (ibCapacity); + *outIB = m_ActiveIB->Lock (ibCapacity); + if (!*outIB) + return false; + } + } + else + { + DebugAssert (!outIB); + m_ActiveIB = NULL; + } + + return true; +} + + +// chai: ½«bufferµÄÊý¾ÝÉÏ´«µ½GPU +void DynamicGLES2VBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ) +{ + Assert( m_LendedChunk ); + Assert( m_LastRenderMode == kDrawIndexedTriangleStrip || m_LastRenderMode == kDrawIndexedQuads || m_LastRenderMode == kDrawIndexedPoints || m_LastRenderMode == kDrawIndexedLines || actualIndices % 3 == 0 ); + m_LendedChunk = false; + + m_LastChunkVertices = actualVertices; + m_LastChunkIndices = actualIndices; + + // chai: Èç¹û¹¹Ô캯ÊýÀïûÓÐÉèÖÃm_VtxSysMemStorage£¬ÉÏ´«µ½GPU + // gles20.slowDynamicVBO = isPvrGpu || isAdrenoGpu || isMaliGpu; + // ÒÔÉϼ¸¿îGPUʹÓÃDynamic VBO»¹Ã»ÓдÓÄÚ´æÖ±½Ó¿½±´¿ì + if(!m_VtxSysMemStorage) + { + DebugAssert (m_ActiveVB); + m_ActiveVB->Unlock (actualVertices * m_LastChunkStride); + } + + if(!m_IdxSysMemStorage) + { + if (m_ActiveIB) + m_ActiveIB->Unlock (actualIndices * kVBOIndexSize); + } + + const bool indexed = (m_LastRenderMode != kDrawQuads) && (m_LastRenderMode != kDrawTriangleStrip); + if( !actualVertices || (indexed && !actualIndices) ) + { + m_LastChunkShaderChannelMask = 0; + return; + } + + UInt8* channelOffset = m_VtxSysMemStorage; + for( int i = 0; i < kShaderChannelCount; ++i ) + { + //chai: Èç¹û¿ªÆôÁËÕâ¸öchannel + if( m_LastChunkShaderChannelMask & (1<<i) ) + { + //chai: ¼Ç¼Õâ¸öchannelµÄÊý¾ÝÔÚm_VtxSysMemStorageÖÐµÄÆ«ÒƺóµÄÊ×µØÖ· + m_BufferChannel[i] = channelOffset; + channelOffset += VBO::GetDefaultChannelByteSize(i); + } + else + m_BufferChannel[i] = 0; + } +} + +//chai: µ÷Õûm_VtxSysMemStorage´óС +void* DynamicGLES2VBO::GetVertexMemory(size_t bytes) +{ + if(m_VtxSysMemStorageSize < bytes) + { + UNITY_FREE(kMemDynamicGeometry, m_VtxSysMemStorage); + + m_VtxSysMemStorageSize = bytes; + m_VtxSysMemStorage = (UInt8*)UNITY_MALLOC_ALIGNED(kMemDynamicGeometry, m_VtxSysMemStorageSize, 32); + } + return m_VtxSysMemStorage; +} + +void* DynamicGLES2VBO::GetIndexMemory(size_t bytes) +{ + if(m_IdxSysMemStorageSize < bytes) + { + UNITY_FREE(kMemDynamicGeometry, m_IdxSysMemStorage); + + m_IdxSysMemStorageSize = bytes; + m_IdxSysMemStorage = (UInt16*)UNITY_MALLOC_ALIGNED(kMemDynamicGeometry, m_IdxSysMemStorageSize, 32); + } + return m_IdxSysMemStorage; +} + +static SharedBuffer* ChooseBestBuffer (SharedBuffer* smallBuffer, SharedBuffer* largeBuffer, size_t bytes) +{ + if (!largeBuffer) + return smallBuffer; + + const size_t couldGrow = smallBuffer->GetAvailableBytes () * 2; + if (couldGrow >= bytes && couldGrow < largeBuffer->GetAvailableBytes () / 2) + return smallBuffer; + + return largeBuffer; +} + +SharedBuffer* DynamicGLES2VBO::GetSharedVB (size_t bytes) +{ + return ChooseBestBuffer (m_VB, m_LargeVB, bytes); +} + +SharedBuffer* DynamicGLES2VBO::GetSharedIB (size_t bytes) +{ + return ChooseBestBuffer (m_IB, m_LargeIB, bytes); +} + +/* +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~¨~ +*/ + +class SharedBuffer +{ +public: + SharedBuffer(int bufferType, size_t bytesPerBlock, size_t blocks = 1, bool driverSupportsBufferOrphaning = true); + ~SharedBuffer(); + void Recreate(); + + void* Lock(size_t bytes); + void Unlock(size_t actualBytes = 0); + + typedef int BufferId; + BufferId GetDrawable() const; + void MarkAsDrawn(BufferId bufferId) {} + + size_t GetAvailableBytes() const; + +private: + void* OrphanLock(size_t bytes); + void OrphanUnlock(size_t actualBytes); + + void* SimpleLock(size_t bytes); + void SimpleUnlock(size_t actualBytes); + +private: + int m_BufferType; // GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER + vector<BufferId> m_BufferIDs; + vector<size_t> m_BufferSizes; + bool m_DriverSupportsBufferOrphaning; + + size_t m_NextBufferIndex; + size_t m_ReadyBufferIndex; // chai: ready for drawing + + UInt8* m_TemporaryDataStorage; + size_t m_TemporaryDataStorageSize; + + size_t m_LockedBytes; +}; + +inline size_t AlignTemporaryDataStorageSize (size_t size) +{ + // NOTE: to simplify neon optimization - pad to 64 bit (neon register size) + size = Align (size, 8); + Assert (size % 8 == 0); + Assert (size > 0); + return size; +} + +SharedBuffer::SharedBuffer (int bufferType, size_t bytesPerBlock, size_t blocks, bool driverSupportsBufferOrphaning) +: m_BufferType (bufferType) +, m_DriverSupportsBufferOrphaning (driverSupportsBufferOrphaning) +, m_NextBufferIndex (0) +, m_ReadyBufferIndex (~0UL) +, m_TemporaryDataStorage (NULL) +, m_TemporaryDataStorageSize (0) +, m_LockedBytes (0) +{ + Assert (bufferType == GL_ARRAY_BUFFER || bufferType == GL_ELEMENT_ARRAY_BUFFER); + Assert (blocks > 0); + Assert (bytesPerBlock > 0); + bytesPerBlock = AlignTemporaryDataStorageSize (bytesPerBlock); + + if (m_DriverSupportsBufferOrphaning) + { + Assert (blocks == 1); + } + + if (!gGraphicsCaps.gles20.hasMapbuffer || !m_DriverSupportsBufferOrphaning) + { + m_TemporaryDataStorageSize = bytesPerBlock; + m_TemporaryDataStorage = (UInt8*)UNITY_MALLOC_ALIGNED (kMemDynamicGeometry, m_TemporaryDataStorageSize, 32); + Assert (m_TemporaryDataStorage); + memset (m_TemporaryDataStorage, 0x00, m_TemporaryDataStorageSize); + } + + m_BufferSizes.resize (blocks); + m_BufferIDs.resize (blocks); + + for (size_t q = 0; q < m_BufferSizes.size(); ++q) + m_BufferSizes[q] = bytesPerBlock; + + Recreate(); + + DebugAssert (m_BufferIDs.size() == m_BufferSizes.size ()); +} + +void SharedBuffer::Recreate() +{ + GLES_CHK (glGenBuffers (m_BufferIDs.size(), (GLuint*)&m_BufferIDs[0])); + + if (!m_DriverSupportsBufferOrphaning) + { + for (size_t q = 0; q < m_BufferIDs.size(); ++q) + { + GLES_CHK (glBindBuffer (m_BufferType, m_BufferIDs[q])); + GLES_CHK(glBufferData(m_BufferType, m_BufferSizes[q], m_TemporaryDataStorage, GL_STREAM_DRAW)); + glRegisterBufferData(m_BufferIDs[q], m_BufferSizes[q], this); + } + GLES_CHK (glBindBuffer (m_BufferType, 0)); + } +} + +SharedBuffer::~SharedBuffer () +{ + glDeregisterBufferData(m_BufferIDs.size (), (GLuint*)&m_BufferIDs[0]); + GLES_CHK(glDeleteBuffers(m_BufferIDs.size (), (GLuint*)&m_BufferIDs[0])); + UNITY_FREE (kMemDynamicGeometry, m_TemporaryDataStorage); +} + +void* SharedBuffer::Lock (size_t bytes) +{ + Assert (m_LockedBytes == 0); + + m_LockedBytes = bytes; + + if (m_TemporaryDataStorage && m_TemporaryDataStorageSize < bytes) + { + m_TemporaryDataStorageSize = AlignTemporaryDataStorageSize (bytes); + m_TemporaryDataStorage = (UInt8*)UNITY_REALLOC (kMemDynamicGeometry, m_TemporaryDataStorage, m_TemporaryDataStorageSize, 32); + Assert (m_TemporaryDataStorage); + } + + // chai: ²ßÂÔģʽ£¬Á½ÖÖ²ßÂÔ¡£ + if (m_DriverSupportsBufferOrphaning) + return OrphanLock (bytes); + else + return SimpleLock (bytes); +} + +void SharedBuffer::Unlock (size_t actualBytes) +{ + if (actualBytes == 0) + actualBytes = m_LockedBytes; + + Assert (actualBytes <= m_LockedBytes); + + if (m_DriverSupportsBufferOrphaning) + OrphanUnlock (actualBytes); + else + SimpleUnlock (actualBytes); + + DebugAssert (m_NextBufferIndex != ~0UL); + DebugAssert (m_ReadyBufferIndex != ~0UL); + + DebugAssert (m_NextBufferIndex < m_BufferIDs.size()); + DebugAssert (m_ReadyBufferIndex < m_BufferIDs.size()); + + m_LockedBytes = 0; +} + +void* SharedBuffer::OrphanLock (size_t bytes) +{ + DebugAssert (m_DriverSupportsBufferOrphaning); + DebugAssert (m_BufferIDs.size () == 1); + DebugAssert (m_NextBufferIndex == 0); + + UInt8* lockedBuffer = NULL; + + if (gGraphicsCaps.gles20.hasMapbuffer) + { + GLES_CHK (glBindBuffer (m_BufferType, m_BufferIDs[0])); + GLES_CHK (glBufferData (m_BufferType, bytes, 0, GL_STREAM_DRAW)); // orphan old buffer, driver will allocate new storage + //chai: µ÷ÓÃglBufferData(,,NULL,)ÄÜÈÃÇý¶¯ÖªµÀ½ÓÏÂÀ´¶Ô´ËbufferµÄbufferdata²Ù×÷²»ÐèҪ֮ǰµÄÊý¾Ý + // ¿ÉÒÔÖØÐ´´½¨Ò»¸öbuffer,ʹÁ½Õß¿ÉÒÔ²¢ÐÐ + lockedBuffer = reinterpret_cast<UInt8*> (gGlesExtFunc.glMapBufferOES(m_BufferType, GL_WRITE_ONLY_OES)); + GLESAssert(); + } + else + { + Assert (m_TemporaryDataStorage); + lockedBuffer = m_TemporaryDataStorage; + + GLES_CHK (glBindBuffer (m_BufferType, m_BufferIDs[0])); + GLES_CHK (glBufferData (m_BufferType, 0, 0, GL_STREAM_DRAW)); // orphan old buffer, driver will allocate new storage + } + + Assert (lockedBuffer); + return lockedBuffer; +} + +void SharedBuffer::OrphanUnlock (size_t actualBytes) +{ + Assert (m_NextBufferIndex == 0); + + GLES_CHK (glBindBuffer (m_BufferType, m_BufferIDs[0])); + + if (gGraphicsCaps.gles20.hasMapbuffer) + GLES_CHK(gGlesExtFunc.glUnmapBufferOES (m_BufferType)); + else + GLES_CHK(glBufferData (m_BufferType, actualBytes, m_TemporaryDataStorage, GL_STREAM_DRAW)); + + GLES_CHK (glBindBuffer (m_BufferType, 0)); + + m_NextBufferIndex = 0; + m_ReadyBufferIndex = 0; +} + +void* SharedBuffer::SimpleLock (size_t bytes) +{ + DebugAssert (!m_DriverSupportsBufferOrphaning); + DebugAssert (!m_BufferIDs.empty ()); + + Assert (m_TemporaryDataStorageSize >= bytes); + Assert (m_TemporaryDataStorage); + return m_TemporaryDataStorage; +} + +//chai: ÊÖ¶¯ÊµÏÖbuffer object orphaning +void SharedBuffer::SimpleUnlock (size_t actualBytes) +{ + DebugAssert (m_BufferIDs.size() == m_BufferSizes.size ()); + // NOTE: current implementation with naively pick next buffer + // it is possible that GPU haven't rendered it and CPU will stall + // however we expect that enough buffers are allocated and stall doesn't happen in practice + + m_ReadyBufferIndex = m_NextBufferIndex; + ++m_NextBufferIndex; + if (m_NextBufferIndex >= m_BufferIDs.size ()) + m_NextBufferIndex = 0; + DebugAssert (m_NextBufferIndex != m_ReadyBufferIndex); + + const size_t bufferIndex = m_ReadyBufferIndex; + DebugAssert (bufferIndex < m_BufferIDs.size()); + + Assert (m_TemporaryDataStorageSize >= actualBytes); + + GLES_CHK (glBindBuffer (m_BufferType, m_BufferIDs[bufferIndex])); + if (m_BufferSizes[bufferIndex] < actualBytes) + { + GLES_CHK (glBufferData (m_BufferType, actualBytes, m_TemporaryDataStorage, GL_STREAM_DRAW)); + m_BufferSizes[bufferIndex] = actualBytes; + } + else + { + GLES_CHK (glBufferSubData (m_BufferType, 0, actualBytes, m_TemporaryDataStorage)); + } + GLES_CHK (glBindBuffer (m_BufferType, 0)); +} + +size_t SharedBuffer::GetAvailableBytes () const +{ + return m_BufferSizes[m_NextBufferIndex]; +} + +SharedBuffer::BufferId SharedBuffer::GetDrawable () const +{ + DebugAssert (m_ReadyBufferIndex != ~0UL); + DebugAssert (m_ReadyBufferIndex < m_BufferIDs.size()); + if (m_ReadyBufferIndex >= m_BufferIDs.size ()) + return 0; + + return m_BufferIDs[m_ReadyBufferIndex]; +} + + +// WARNING: this is just a temp solution, as we really need to clean up all this mess + +static SharedBuffer* lockedSharedBuffer = NULL; +void* LockSharedBufferGLES20 (int bufferType, size_t bytes, bool forceBufferObject) +{ + Assert (bufferType == GL_ARRAY_BUFFER || bufferType == GL_ELEMENT_ARRAY_BUFFER); + DynamicGLES2VBO& dynamicVBO = static_cast<DynamicGLES2VBO&> (GetRealGfxDevice ().GetDynamicVBO ()); + + if(gGraphicsCaps.gles20.slowDynamicVBO && !forceBufferObject) + { + if (bufferType == GL_ARRAY_BUFFER) + return dynamicVBO.GetVertexMemory(bytes); + else if (bufferType == GL_ELEMENT_ARRAY_BUFFER) + return dynamicVBO.GetIndexMemory(bytes); + } + else + { + DebugAssert (lockedSharedBuffer == NULL); + if (bufferType == GL_ARRAY_BUFFER) + lockedSharedBuffer = dynamicVBO.GetSharedVB (bytes); + else if (bufferType == GL_ELEMENT_ARRAY_BUFFER) + lockedSharedBuffer = dynamicVBO.GetSharedIB (bytes); + + Assert (lockedSharedBuffer); + return lockedSharedBuffer->Lock (bytes); + } + + return 0; +} + +int UnlockSharedBufferGLES20 (size_t actualBytes, bool forceBufferObject) +{ + if(gGraphicsCaps.gles20.slowDynamicVBO && !forceBufferObject) + { + return 0; + } + else + { + Assert (lockedSharedBuffer); + lockedSharedBuffer->Unlock (actualBytes); + const int bufferId = lockedSharedBuffer->GetDrawable (); + lockedSharedBuffer = NULL; + return bufferId; + } +} + +#if NV_STATE_FILTERING + #ifdef glDeleteBuffers + #undef glDeleteBuffers + #endif + #ifdef glBindBuffer + #undef glBindBuffer + #endif + #ifdef glVertexAttribPointer + #undef glVertexAttribPointer + #endif +#endif + +#endif // GFX_SUPPORTS_OPENGLES20 diff --git a/Runtime/GfxDevice/opengles20/VBOGLES20.h b/Runtime/GfxDevice/opengles20/VBOGLES20.h new file mode 100644 index 0000000..62ce55d --- /dev/null +++ b/Runtime/GfxDevice/opengles20/VBOGLES20.h @@ -0,0 +1,147 @@ +#ifndef VBO_GLES20_H +#define VBO_GLES20_H + +#include "Runtime/Shaders/BufferedVBO.h" +#include "IncludesGLES20.h" +#include <map> + +class GLES2VBO : public BufferedVBO { +public: + GLES2VBO(); + virtual ~GLES2VBO (); + + virtual void UpdateVertexData( const VertexBufferData& buffer ); + virtual void UpdateIndexData (const IndexBufferData& buffer); + virtual void DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ); + virtual void DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ); + + virtual bool MapVertexStream( VertexStreamData& outData, unsigned stream ); + virtual void UnmapVertexStream( unsigned stream ); + + virtual void Cleanup(); + virtual void Recreate(); + virtual bool IsVertexBufferLost() const; + virtual bool IsIndexBufferLost() const; + virtual void MarkBuffersLost(); + + virtual bool IsUsingSourceVertices() const { return m_VertexBufferID[0] == 0; } + virtual bool IsUsingSourceIndices() const { return m_IndexBufferID == 0; } + + virtual int GetRuntimeMemorySize() const; + +private: + + void DrawInternal(int vertexBufferID, int indexBufferID, const ChannelAssigns& channels, void* indices, UInt32 indexCount, GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount); + + UInt32 GetUnavailableChannels(const ChannelAssigns& channels) const; + + ChannelInfoArray m_Channels; + IndexBufferData m_IBData; + enum { DynamicVertexBufferCount = 3 }; + int m_VertexBufferID[DynamicVertexBufferCount]; + int m_CurrentBufferIndex; + int m_IndexBufferID; + int m_IBSize; + void* m_ReadableIndices; + + int m_VBOUsage; + int m_IBOUsage; + + + bool m_UsesVBO; + bool m_UsesIBO; + + // for now these are only called on UpdateVertexData/UpdateIndexData + // so they are extracted only for convinience + bool ShouldUseVBO(); + bool ShouldUseIBO(); + + void EnsureVerticesInited(bool newBuffers); + void EnsureIndicesInited(); +}; + +class SharedBuffer; + +// Usage: +// 1) GetChunk +// if this returns false, don't use data pointers, bail out +// 2) fill with data +// 3) ReleaseChunk +// 4) DrawChunk (possibly multiple times) +// +// The key is that drawing must happen immediately after filling the chunk, because the next +// GetChunk might destroy the previous chunk's data. So never count on chunks being persistent. +class DynamicGLES2VBO : public DynamicVBO +{ +public: + DynamicGLES2VBO(); + ~DynamicGLES2VBO(); + + virtual bool GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ); + virtual void ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ); + virtual void DrawChunk (const ChannelAssigns& channels); + + virtual void Recreate(); + + SharedBuffer* GetSharedVB (size_t bytes); + SharedBuffer* GetSharedIB (size_t bytes); + + void* GetVertexMemory(size_t bytes); + void* GetIndexMemory(size_t bytes); + +private: + void InitializeQuadsIB(); + +private: + //chai: ¼Ç¼channelÔÚm_VtxSysMemStorageÖеĸ÷¸öchannelµÄÊ×µØÖ· + void* m_BufferChannel[kShaderChannelCount]; + RenderMode m_LastRenderMode; + + //chai: ¼Ç¼¿ªÆôµÄchannel + //UInt32 m_LastChunkShaderChannelMask; + + + SharedBuffer* m_VB; + SharedBuffer* m_LargeVB; + SharedBuffer* m_ActiveVB; + SharedBuffer* m_IB; + SharedBuffer* m_LargeIB; + SharedBuffer* m_ActiveIB; + + UInt16* m_QuadsIB; + int m_IndexBufferQuadsID; + + UInt8* m_VtxSysMemStorage; + unsigned m_VtxSysMemStorageSize; + + UInt16* m_IdxSysMemStorage; + unsigned m_IdxSysMemStorageSize; +}; + +void InvalidateVertexInputCacheGLES20(); +// WARNING: forceBufferObject is just a temp solution, as we really need to clean up all this mess +// we need it for bigger dynamic vbos +void* LockSharedBufferGLES20 (int bufferType, size_t bytes, bool forceBufferObject=false); +int UnlockSharedBufferGLES20 (size_t actualBytes = 0, bool forceBufferObject=false); + +#define GL_VERTEX_ARRAY 0 +#define GL_COLOR_ARRAY 1 +#define GL_NORMAL_ARRAY 2 +#define GL_TEXTURE_ARRAY0 3 +#define GL_TEXTURE_ARRAY1 GL_TEXTURE_ARRAY0 + 1 +#define GL_TEXTURE_ARRAY2 GL_TEXTURE_ARRAY0 + 2 +#define GL_TEXTURE_ARRAY3 GL_TEXTURE_ARRAY0 + 3 +#define GL_TEXTURE_ARRAY4 GL_TEXTURE_ARRAY0 + 4 +#define GL_TEXTURE_ARRAY5 GL_TEXTURE_ARRAY0 + 5 +#define GL_TEXTURE_ARRAY6 GL_TEXTURE_ARRAY0 + 6 +#define GL_TEXTURE_ARRAY7 GL_TEXTURE_ARRAY0 + 7 + +#if NV_STATE_FILTERING +void filteredBindBufferGLES20(GLenum target, GLuint buffer,bool isImmediate=false); +void filteredVertexAttribPointerGLES20(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer); +void StateFiltering_InvalidateVBOCacheGLES20(); +#endif + +#endif diff --git a/Runtime/GfxDevice/opengles20/_DebugStuffGLES20.cpp b/Runtime/GfxDevice/opengles20/_DebugStuffGLES20.cpp new file mode 100644 index 0000000..a72f01a --- /dev/null +++ b/Runtime/GfxDevice/opengles20/_DebugStuffGLES20.cpp @@ -0,0 +1,438 @@ +#include "UnityPrefix.h" +#include "AssertGLES20.h" +#include "IncludesGLES20.h" +#include "Runtime/Math/Matrix4x4.h" +#include "_DebugStuffGLES20.h" +#include "VBOGLES20.h" + +void PrintMatrix(const char* name, const Matrix4x4f& m) +{ + printf_console("Outputing:%s\n------------\n" + "mat4 mat = (%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f);\n\n",name, + m[0], m[1], m[2], m[3], + m[4], m[5], m[6], m[7], + m[8], m[9], m[10], m[11], + m[12], m[13], m[14], m[15]); +} +void _Debug::MiniLoopGLES20() +{ + + #define VERTEX_ARRAY 0 + float pfIdentity[] = + { + 1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f + }; + + // Fragment and vertex shaders code + char* pszFragShader = "\ + void main (void)\ + {\ + gl_FragColor = vec4(1.0, 1.0, 0.66 ,1.0);\ + }"; + char* pszVertShader = "\ + attribute highp vec3 myVertex;\ + uniform mediump mat4 myPMVMatrix;\ + void main(void)\ + {\ + gl_Position = myPMVMatrix * vec4(myVertex,1.0);\ + }"; + + + GLuint uiFragShader, uiVertShader; /* Used to hold the fragment and vertex shader handles */ + GLuint uiProgramObject; /* Used to hold the program handle (made out of the two previous shaders */ + + // Create the fragment shader object + uiFragShader = glCreateShader(GL_FRAGMENT_SHADER); + + // Load the source code into it + glShaderSource(uiFragShader, 1, (const char**)&pszFragShader, NULL); + + // Compile the source code + glCompileShader(uiFragShader); + + // Check if compilation succeeded + GLint bShaderCompiled; + bShaderCompiled = 0; + glGetShaderiv(uiFragShader, GL_COMPILE_STATUS, &bShaderCompiled); + + if (!bShaderCompiled) + { +#ifndef NO_GDI + // An error happened, first retrieve the length of the log message + int i32InfoLogLength, i32CharsWritten; + glGetShaderiv(uiFragShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength); + + // Allocate enough space for the message and retrieve it + char* pszInfoLog = new char[i32InfoLogLength]; + glGetShaderInfoLog(uiFragShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog); + + printf_console(pszInfoLog); + // Displays the error in a dialog box + delete[] pszInfoLog; +#endif + return; + } + + // Loads the vertex shader in the same way + uiVertShader = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(uiVertShader, 1, (const char**)&pszVertShader, NULL); + glCompileShader(uiVertShader); + glGetShaderiv(uiVertShader, GL_COMPILE_STATUS, &bShaderCompiled); + if (!bShaderCompiled) + { +#ifndef NO_GDI + int i32InfoLogLength, i32CharsWritten; + glGetShaderiv(uiVertShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength); + char* pszInfoLog = new char[i32InfoLogLength]; + glGetShaderInfoLog(uiVertShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog); + printf_console(pszInfoLog); + delete[] pszInfoLog; +#endif + return; + } + + // Create the shader program + uiProgramObject = glCreateProgram(); + // Bind the custom vertex attribute "myVertex" to location VERTEX_ARRAY + glBindAttribLocation(uiProgramObject, VERTEX_ARRAY, "myVertex"); + // Attach the fragment and vertex shaders to it + glAttachShader(uiProgramObject, uiFragShader); + glAttachShader(uiProgramObject, uiVertShader); + + + + // Link the program + glLinkProgram(uiProgramObject); + + // Check if linking succeeded in the same way we checked for compilation success + GLint bLinked; + glGetProgramiv(uiProgramObject, GL_LINK_STATUS, &bLinked); + if (!bLinked) + { +#ifndef NO_GDI + int i32InfoLogLength, i32CharsWritten; + glGetProgramiv(uiProgramObject, GL_INFO_LOG_LENGTH, &i32InfoLogLength); + char* pszInfoLog = new char[i32InfoLogLength]; + glGetProgramInfoLog(uiProgramObject, i32InfoLogLength, &i32CharsWritten, pszInfoLog); + printf_console(pszInfoLog); + delete[] pszInfoLog; +#endif + return; + } + + + // Actually use the created program + glUseProgram(uiProgramObject); + GLESAssert(); + + // Sets the clear color. + // The colours are passed per channel (red,green,blue,alpha) as float values from 0.0 to 1.0 + glClearColor(0.6f, 0.8f, 1.0f, 1.0f); + GLESAssert(); + + // We're going to draw a triangle to the screen so create a vertex buffer object for our triangle + GLuint ui32Vbo; // Vertex buffer object handle + + // Interleaved vertex data + GLfloat afVertices[] = { -0.1f,-0.4f,0.0f, // Position + 0.4f ,-0.4f,0.0f, + 0.0f ,0.4f ,0.0f}; + + // Generate the vertex buffer object (VBO) + glGenBuffers(1, &ui32Vbo); + GLESAssert(); + + // Bind the VBO so we can fill it with data + glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo); + GLESAssert(); + + // Set the buffer's data + unsigned int uiSize = 3 * (sizeof(GLfloat) * 3); // Calc afVertices size (3 vertices * stride (3 GLfloats per vertex)) + glBufferData(GL_ARRAY_BUFFER, uiSize, afVertices, GL_STATIC_DRAW); + GLESAssert(); + + glClearDepthf(1.0f); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glDisable(GL_CULL_FACE); + printf_console("Loop launched\n"); + while (1) + { + glClearColor(1.0f, 1.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + GLESAssert(); + + + /* + Bind the projection model view matrix (PMVMatrix) to + the associated uniform variable in the shader + */ + + // First gets the location of that variable in the shader using its name + int i32Location = glGetUniformLocation(uiProgramObject, "myPMVMatrix"); + + // Then passes the matrix to that variable + glUniformMatrix4fv( i32Location, 1, GL_FALSE, pfIdentity); + GLESAssert(); + + /* + Enable the custom vertex attribute at index VERTEX_ARRAY. + We previously binded that index to the variable in our shader "vec4 MyVertex;" + */ + glEnableVertexAttribArray(VERTEX_ARRAY); + GLESAssert(); + + // Sets the vertex data to this attribute index + glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0); + + /* + Draws a non-indexed triangle array from the pointers previously given. + This function allows the use of other primitive types : triangle strips, lines, ... + For indexed geometry, use the function glDrawElements() with an index list. + */ + glDrawArrays(GL_TRIANGLES, 0, 3); + GLESAssert(); + + void PresentContextGLES(); + PresentContextGLES(); + } +} +int _Debug::CreateDefaultShader (bool texturing) +{ + char* strVertexShader = NULL; + char* strFragmentShader = NULL; + if (texturing) + { + strVertexShader = + "attribute highp vec3 _glesVertex;\n" + "attribute highp vec4 _glesUV0;\n" + "uniform mediump mat4 _glesMVP;\n" + "varying mediump vec2 _glesVarUV0;\n" + "void main(void)\n" + "{\n" + " gl_Position = _glesMVP * vec4(_glesVertex,1.0);\n" + " _glesVarUV0 = _glesUV0.st;\n" + "}"; + + strFragmentShader = + "uniform sampler2D texDiffuse;\n" + "varying mediump vec2 _glesVarUV0;\n" + "void main (void)\n" + "{\n" + " gl_FragColor = texture2D(texDiffuse, _glesVarUV0);\n" + "}"; + } + else + { + strVertexShader = + "attribute highp vec3 _glesVertex;\n" + "uniform mediump mat4 _glesMVP;\n" + "void main(void)\n" + "{\n" + " gl_Position = _glesMVP * vec4(_glesVertex,1.0);\n" + "}"; + + + strFragmentShader = + "void main (void)\n" + "{\n" + " gl_FragColor = vec4(1.0, 1.0, 0.66 ,1.0);\n" + "}"; + + } + return CreateShader(strVertexShader, strFragmentShader); + +} +int _Debug::CreateShader(const char* vertexShader, const char* fragmenShader) +{ + GLuint vertShader, fragShader; + GLuint shader; + + GLint compiled, linked; + + //Vertex shader + GLES_CHK(vertShader = glCreateShader(GL_VERTEX_SHADER)); + GLES_CHK(glShaderSource(vertShader, 1, (const char**)&vertexShader, NULL)); + GLES_CHK(glCompileShader(vertShader)); + + compiled = 0; + GLES_CHK(glGetShaderiv(vertShader, GL_COMPILE_STATUS, &compiled)); + + if (!compiled) + { + int i32InfoLogLength, i32CharsWritten; + GLES_CHK(glGetShaderiv(vertShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength)); + char* pszInfoLog = new char[i32InfoLogLength]; + GLES_CHK(glGetShaderInfoLog(vertShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog)); + printf_console(pszInfoLog); + delete[] pszInfoLog; + return 0; + } + + //Fragment shader + GLES_CHK(fragShader = glCreateShader(GL_FRAGMENT_SHADER)); + GLES_CHK(glShaderSource(fragShader, 1, (const char**)&fragmenShader, NULL)); + GLES_CHK(glCompileShader(fragShader)); + + compiled = 0; + GLES_CHK(glGetShaderiv(fragShader, GL_COMPILE_STATUS, &compiled)); + + if (!compiled) + { + int i32InfoLogLength, i32CharsWritten; + GLES_CHK(glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &i32InfoLogLength)); + char* pszInfoLog = new char[i32InfoLogLength]; + GLES_CHK(glGetShaderInfoLog(fragShader, i32InfoLogLength, &i32CharsWritten, pszInfoLog)); + printf_console(pszInfoLog); + delete[] pszInfoLog; + return 0; + } + + // Final Step, attacha and link shaders + shader = glCreateProgram(); + (glBindAttribLocation(shader, GL_VERTEX_ARRAY, "_glesVertex")); + (glBindAttribLocation(shader, GL_TEXTURE_ARRAY0, "_glesUV0")); + + GLES_CHK(glAttachShader(shader, fragShader)); + GLES_CHK(glAttachShader(shader, vertShader)); + GLES_CHK(glLinkProgram(shader)); + + linked = 0; + GLES_CHK(glGetProgramiv(shader, GL_LINK_STATUS, &linked)); + if (!linked) + { + int i32InfoLogLength, i32CharsWritten; + GLES_CHK(glGetProgramiv(shader, GL_INFO_LOG_LENGTH, &i32InfoLogLength)); + char* pszInfoLog = new char[i32InfoLogLength]; + GLES_CHK(glGetProgramInfoLog(shader, i32InfoLogLength, &i32CharsWritten, pszInfoLog)); + printf_console(pszInfoLog); + delete[] pszInfoLog; + return 0; + } + return shader; +} + +int _Debug::CreateDefaultVBO (bool texCoords) +{ + float verts[] = + { + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f, + 0.5f, 0.5f, 0.0f, + -0.5f, -0.5f, 0.0f, + 0.5f, 0.5f, 0.0f, + -0.5f, 0.5f, 0.0f + }; + + float vertsUV[] = + { + -0.5f, -0.5f, 0.0f, + 0.0f, 0.0f, + 0.5f, -0.5f, 0.0f, + 1.0f, 0.0f, + 0.5f, 0.5f, 0.0f, + 1.0f, 1.0f, + -0.5f, -0.5f, 0.0f, + 0.0f, 0.0f, + 0.5f, 0.5f, 0.0f, + 1.0f, 1.0f, + -0.5f, 0.5f, 0.0f, + 0.0f, 1.0f, + }; + + if (texCoords) + { + return CreateVBO(vertsUV, 6, sizeof(float) * 5); + } + else + { + return CreateVBO(vertsUV, 6, sizeof(float) * 3); + } +} + + +int _Debug::CreateVBO(const float* data, int vertexCount, int vertexSize) +{ + GLuint vbo; + GLES_CHK(glGenBuffers(1, &vbo)); + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, vbo)); + GLES_CHK(glBufferData(GL_ARRAY_BUFFER, vertexSize * vertexCount, data, GL_STATIC_DRAW)); + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); + return vbo; +} + +void _Debug::SetUniformMatrix4x4f(int shaderID, const char* name, const Matrix4x4f& mat) +{ + int loc ; + GLES_CHK(loc = glGetUniformLocation(shaderID, name)); + + if (loc != -1)GLES_CHK(glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetPtr())); + else printf_console("Failed to find uniform %s\n", name); +} +void _Debug::SetUniformSample2D (int shaderID, const char* name, int texUnit) +{ + int loc ; + GLES_CHK(loc = glGetUniformLocation(shaderID, name)); + + if (loc != -1)GLES_CHK(glUniform1i(loc, texUnit)); + else printf_console("Failed to find uniform %s\n", name); +} +void _Debug::UseShader(int shaderID) +{ + GLES_CHK(glUseProgram(shaderID)); +} +void _Debug::DrawVBO(int vboID, int vertexCount, bool texCoords) +{ + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, vboID)); + if (texCoords) + { + glEnableVertexAttribArray(GL_VERTEX_ARRAY); + glVertexAttribPointer(GL_VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, 0); + glEnableVertexAttribArray(GL_TEXTURE_ARRAY0); + glVertexAttribPointer(GL_TEXTURE_ARRAY0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, (void*) (3 * sizeof(GLfloat))); + + GLES_CHK(glDrawArrays(GL_TRIANGLES, 0, vertexCount)); + + GLES_CHK(glDisableVertexAttribArray(GL_VERTEX_ARRAY)); + GLES_CHK(glDisableVertexAttribArray(GL_TEXTURE_ARRAY0)); + } + else + { + GLES_CHK(glEnableVertexAttribArray(GL_VERTEX_ARRAY)); + GLES_CHK(glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0)); + GLES_CHK(glDrawArrays(GL_TRIANGLES, 0, vertexCount)); + GLES_CHK(glDisableVertexAttribArray(GL_VERTEX_ARRAY)); + } + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); +} +void _Debug::DisplayTextureMiniLoop(int textureID) +{ + bool texCoords = true; + int vbo = CreateDefaultVBO(texCoords); + int shader = CreateDefaultShader(texCoords); + GLES_CHK(glDisable(GL_DEPTH_TEST)); + GLES_CHK(glDisable(GL_CULL_FACE)); + GLES_CHK(glDisable(GL_BLEND)); + GLES_CHK(glBindFramebuffer (GL_FRAMEBUFFER, 0)); + while (1) + { + GLES_CHK(glClearColor(1.0f, 1.0f, 0.0f, 1.0f)); + GLES_CHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); + GLES_CHK(glActiveTexture(GL_TEXTURE0)); + GLES_CHK(glBindTexture(GL_TEXTURE_2D, textureID)); + + UseShader(shader); + SetUniformMatrix4x4f(shader, "_glesMVP", Matrix4x4f::identity); + SetUniformSample2D(shader, "texDiffuse", 0); + DrawVBO(vbo, 6, texCoords); + + void PresentContextGLES(); + PresentContextGLES(); + } +}
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengles30/AssertGLES30.cpp b/Runtime/GfxDevice/opengles30/AssertGLES30.cpp new file mode 100644 index 0000000..9f20a92 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/AssertGLES30.cpp @@ -0,0 +1,58 @@ +#include "UnityPrefix.h" +#include "AssertGLES30.h" +#include "IncludesGLES30.h" + +#if GFX_SUPPORTS_OPENGLES30 + +using namespace std; + +static const char* GetErrorString(GLenum glerr) +{ + // Error descriptions taken from OpenGLES 1.1 specification (page 13) + switch(glerr) + { + case GL_NO_ERROR: + return "GL_NO_ERROR: No error occured"; + case GL_INVALID_ENUM: + return "GL_INVALID_ENUM: enum argument out of range"; + case GL_INVALID_VALUE: + return "GL_INVALID_VALUE: Numeric argument out of range"; + case GL_INVALID_OPERATION: + return "GL_INVALID_OPERATION: Operation illegal in current state"; + case GL_OUT_OF_MEMORY: + return "GL_OUT_OF_MEMORY: Not enough memory left to execute command"; + case GL_INVALID_FRAMEBUFFER_OPERATION: + return "GL_INVALID_FRAMEBUFFER_OPERATION: Framebuffer is not complete or incompatible with command"; + default: +#if UNTIY_WEBGL + printf_console("AssertGles20::GetErrorString invoked for unknown error %d",glerr); +#endif + return "Unknown error"; + } +} + +void CheckOpenGLES3Error (const char *prefix, const char* file, long line) +{ + const int kMaxErrors = 10; + int counter = 0; + + GLenum glerr; + while( (glerr = glGetError ()) != GL_NO_ERROR ) + { + string errorString(GetErrorString(glerr)); + + if (prefix) + errorString = string(prefix) + ": " + errorString; + + DebugStringToFile (errorString.c_str(), 0, file, line, kAssert); + + ++counter; + if( counter > kMaxErrors ) + { + printf_console( "GLES: error count exceeds %i, stop reporting errors\n", kMaxErrors ); + return; + } + } +} + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/AssertGLES30.h b/Runtime/GfxDevice/opengles30/AssertGLES30.h new file mode 100644 index 0000000..bb9c26d --- /dev/null +++ b/Runtime/GfxDevice/opengles30/AssertGLES30.h @@ -0,0 +1,40 @@ +#ifndef GLES_ASSERTGLES30_H +#define GLES_ASSERTGLES30_H + +#include "Runtime/Utilities/LogAssert.h" + +void CheckOpenGLES3Error (const char *prefix, const char* file, long line); + +#if !UNITY_RELEASE || UNITY_WEBGL + #ifndef GLESAssert + /// Asserts for checking the OpenGL error state + #define GLESAssert() { CheckOpenGLES3Error (NULL, __FILE__, __LINE__); } + #endif + #define GLESAssertString(x) { CheckOpenGLES3Error (x, __FILE__, __LINE__); } + + #define GLES30_PRINT_GL_TRACE 0 + #if GLES30_PRINT_GL_TRACE + #define GLESCHKSTRINGIFY(x) GLESCHKSTRINGIFY2(x) + #define GLESCHKSTRINGIFY2(x) #x + + #define GLES_CHK(x) do { {printf_console("GLES: %s %s %d\n", GLESCHKSTRINGIFY(x), __FILE__, __LINE__); x;} GLESAssert(); } while(0) + #else + #define GLES_CHK(x) do { {x;} GLESAssert(); } while(0) + #endif +#else + + #ifndef GLESAssert + #define GLESAssert() + #endif + #define GLESAssertString(x) + #define GLES_CHK(x) x + + +#endif + + +//#define GLES_CHK(x) do {} while(0) +//#define GLES_CHK(x) +//#define GLES_CHK(x) do { printf_console("GLES: %s %d\n", __FILE__, __LINE__); } while(0) + +#endif diff --git a/Runtime/GfxDevice/opengles30/CombinerGLES30.cpp b/Runtime/GfxDevice/opengles30/CombinerGLES30.cpp new file mode 100644 index 0000000..51f64c4 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/CombinerGLES30.cpp @@ -0,0 +1,21 @@ +#include "UnityPrefix.h" +#include "CombinerGLES30.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "VBOGLES30.h" + +#if GFX_SUPPORTS_OPENGLES30 + +TextureCombinersGLES3* TextureCombinersGLES3::Create (int count, const ShaderLab::TextureBinding* texEnvs) +{ + // check if we have enough vertex attributes to emulate this combiner + if (count + kGLES3AttribLocationTexCoord0 >= gGraphicsCaps.gles30.maxAttributes) + return NULL; + + // create struct that holds texture combiner info object + TextureCombinersGLES3* combiners = new TextureCombinersGLES3(); + combiners->count = count; + combiners->texEnvs = texEnvs; + return combiners; +} + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/CombinerGLES30.h b/Runtime/GfxDevice/opengles30/CombinerGLES30.h new file mode 100644 index 0000000..4073e99 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/CombinerGLES30.h @@ -0,0 +1,10 @@ +#pragma once + +namespace ShaderLab { struct TextureBinding; } + +struct TextureCombinersGLES3 +{ + static TextureCombinersGLES3* Create (int count, const ShaderLab::TextureBinding* texEnvs); + int count; + const ShaderLab::TextureBinding* texEnvs; +}; diff --git a/Runtime/GfxDevice/opengles30/ConstantBuffersGLES30.cpp b/Runtime/GfxDevice/opengles30/ConstantBuffersGLES30.cpp new file mode 100644 index 0000000..4a64c08 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/ConstantBuffersGLES30.cpp @@ -0,0 +1,338 @@ +#include "UnityPrefix.h" +#include "ConstantBuffersGLES30.h" +#include "AssertGLES30.h" + +// NEVER enable this for release! Turns off all CB caching and makes things +// very slow, for debugging. +#define DEBUG_DISABLE_CONSTANT_BUFFER_CACHES (0 && !UNITY_RELEASE) + +#define CONSTANT_BUFFER_ID_MASK 0xB0000000 +#define MAKE_CONSTANT_BUFFER_ID(id) (id|CONSTANT_BUFFER_ID_MASK) + + +#if DEBUG_GLES30_UNIFORM_BUFFER_STATS +#include "External/shaderlab/Library/FastPropertyName.h" +extern std::string g_LastParsedShaderName; +#endif + +ConstantBuffersGLES30::ConstantBuffersGLES30() +{ + memset (m_ActiveBuffers, 0, sizeof(m_ActiveBuffers)); +} + +void ConstantBuffersGLES30::Clear() +{ + memset (m_ActiveBuffers, 0, sizeof(m_ActiveBuffers)); + for (size_t i = 0; i < m_Buffers.size(); ++i) + { + ConstBuffer& cb = m_Buffers[i]; + delete[] cb.data; + if (cb.buffer) + { + REGISTER_EXTERNAL_GFX_DEALLOCATION(MAKE_CONSTANT_BUFFER_ID(cb.buffer)); + GLES_CHK(glDeleteBuffers(1, (GLuint*)&cb.buffer)); + } + #if DEBUG_GLES30_CONSTANT_BUFFER_STATS + delete[] cb.changeCounts; + delete[] cb.tryCounts; + #endif + } + m_Buffers.clear(); + m_BufferKeys.clear(); +} + +void ConstantBuffersGLES30::SetCBInfo(int id, int size) +{ + size_t n = m_Buffers.size(); + Assert (m_BufferKeys.size() == n); + UInt32 key = id | (size<<16); + for (size_t i = 0; i < n; ++i) + { + if (m_BufferKeys[i] == key) + return; + } + + // not found, create one + ConstBuffer cb; + cb.data = new UInt8[size]; + memset (cb.data, 0, size); + cb.dirty = true; + cb.bindIndex = -1; + #if DEBUG_GLES30_CONSTANT_BUFFER_STATS + cb.statsDirty = 0; + cb.stats = 0; + ShaderLab::FastPropertyName name; + name.index = id; + printf_console ("GLES30 Uniform Buffer Info: new %s size=%i shader=%s\n", name.GetName(), size, g_LastParsedShaderName.c_str()); + cb.changeCounts = new int[size/4]; + memset (cb.changeCounts, 0, size); + cb.tryCounts = new int[size/4]; + memset (cb.tryCounts, 0, size); + #endif + + GLES_CHK(glGenBuffers(1, (GLuint*)&cb.buffer)); + GLES_CHK(glBindBuffer(GL_UNIFORM_BUFFER, cb.buffer)); + GLES_CHK(glBufferData(GL_UNIFORM_BUFFER, size, NULL, GL_DYNAMIC_DRAW)); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(MAKE_CONSTANT_BUFFER_ID(cb.buffer),size,this); + + m_Buffers.push_back (cb); + m_BufferKeys.push_back (key); +} + +int ConstantBuffersGLES30::FindAndBindCB (int id, int bind, int size) +{ + UInt32 key = id | (size<<16); + int idx = 0; + for (ConstBufferKeys::const_iterator it = m_BufferKeys.begin(), itEnd = m_BufferKeys.end(); it != itEnd; ++it, ++idx) + { + if (*it == key) + { + ConstBuffer& cb = m_Buffers[idx]; + if (bind >= 0) + { + cb.bindIndex = bind; + } + return idx; + } + } + Assert (false); + return -1; +} + +void ConstantBuffersGLES30::ResetBinds() +{ + for (ConstBuffers::iterator it = m_Buffers.begin(), itEnd = m_Buffers.end(); it != itEnd; ++it) + { + it->bindIndex = -1; + } +} + +void ConstantBuffersGLES30::SetCBConstant (int idx, int offset, const void* data, int size) +{ + Assert (idx >= 0 && idx < m_Buffers.size()); + ConstBuffer& cb = m_Buffers[idx]; + Assert (offset >= 0 && offset+size <= (m_BufferKeys[idx]>>16) && size > 0); + + #if DEBUG_GLES30_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.tryCounts[i]; + #endif + + if (size == 4) + { + UInt32* dstData = (UInt32*)(cb.data+offset); + UInt32 srcData = *(UInt32*)data; + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || *dstData != srcData) + { + *dstData = srcData; + cb.dirty = true; + + #if DEBUG_GLES30_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.changeCounts[i]; + #endif + } + } + else + { + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || memcmp(cb.data+offset, data, size) != 0) + { + memcpy (cb.data+offset, data, size); + cb.dirty = true; + + #if DEBUG_GLES30_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.changeCounts[i]; + #endif + } + } +} + +void ConstantBuffersGLES30::UpdateBuffers () +{ + size_t n = m_Buffers.size(); + + #if !UNITY_RELEASE + // check if we have duplicate buffers bound to the same slot (should never happen!) + UInt32 bound = 0; + for (size_t i = 0; i < n; ++i) + { + ConstBuffer& cb = m_Buffers[i]; + int bind = cb.bindIndex; + if (bind >= 0 && bind < 32) + { + Assert (!(bound & (1<<bind))); + bound |= (1<<bind); + } + } + #endif + + + for (size_t i = 0; i < n; ++i) + { + ConstBuffer& cb = m_Buffers[i]; + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || cb.dirty) + { + GLES_CHK(glBindBuffer(GL_UNIFORM_BUFFER, cb.buffer)); + + UInt32 bufferSize = (m_BufferKeys[i]>>16); + GLES_CHK(glBufferData(GL_UNIFORM_BUFFER, bufferSize, cb.data, GL_DYNAMIC_DRAW)); + //void* data = glMapBufferRange(GL_UNIFORM_BUFFER, 0, bufferSize, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); + //GLESAssert(); + //if (data != NULL) + //{ + // ::memcpy(data, cb.data, bufferSize); + //} + //GLES_CHK(glUnmapBuffer(GL_UNIFORM_BUFFER)); + #if DEBUG_GLES30_CONSTANT_BUFFER_STATS + ++cb.statsDirty; + #endif + } + + // Bind + int bindIndex = cb.bindIndex; + if (bindIndex >= 0 && (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || m_ActiveBuffers[bindIndex] != cb.buffer)) + { + GLES_CHK(glBindBufferBase(GL_UNIFORM_BUFFER, bindIndex, cb.buffer)); + } + cb.dirty = false; + } +} + +#if 0 + +void ConstantBuffersD3D11::SetBuiltinCBConstant (int id, int offset, const void* data, int size) +{ + int idx = GetCBIndexByID (id); + ConstBuffer& cb = m_Buffers[idx]; + Assert (offset >= 0 && offset+size <= (m_BufferKeys[idx]>>16) && size > 0); + + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.tryCounts[i]; + #endif + + if (DEBUG_DISABLE_CONSTANT_BUFFER_CACHES || memcmp(cb.data+offset, data, size) != 0) + { + memcpy (cb.data+offset, data, size); + cb.dirty = true; + + #if DEBUG_D3D11_CONSTANT_BUFFER_STATS + for (int i = offset/4; i < offset/4+size/4; ++i) + ++cb.changeCounts[i]; + #endif + } +} + +#if DEBUG_D3D11_CONSTANT_BUFFER_STATS + +static void WriteTGAFile (const char* filename, int width, int height, const UInt8* bgr) +{ + FILE* f = fopen(filename, "wb"); + // header + putc(0,f); + putc(0,f); + putc(2,f); // uncompressed RGB + putc(0,f); putc(0,f); + putc(0,f); putc(0,f); + putc(0,f); + putc(0,f); putc(0,f); + putc(0,f); putc(0,f); + putc((width & 0x00FF),f); + putc((width & 0xFF00)>>8,f); + putc((height & 0x00FF),f); + putc((height & 0xFF00)>>8,f); + putc(24,f); // 24 bit + putc(0x20,f); // vertical flip + // data + fwrite (bgr, 3, width*height, f); + fclose (f); +} + +static void DensityToBGR (int density, UInt8* bgr) +{ + if (density < 1) + { + bgr[0] = bgr[1] = bgr[2] = 0; + return; + } + bgr[0] = clamp(40+density/4, 0, 255); + bgr[1] = clamp(40+density/4, 0, 255); + bgr[2] = clamp(40+density/4, 0, 255); +} + +static void PutBGRPixelBlock (UInt8* img, int imgWidth, int x, int y, const UInt8* bgr) +{ + for (int i = 0; i < 4; ++i) + { + UInt8* ptr = img + ((y+i)*imgWidth+x) * 3; + for (int j = 0; j < 4; ++j, ptr += 3) + { + ptr[0] = bgr[0]; + ptr[1] = bgr[1]; + ptr[2] = bgr[2]; + } + } +} + + +void ConstantBuffersD3D11::NewFrame() +{ + if (GetAsyncKeyState(VK_F7)) + { + printf_console ("DX11 Constant Buffer stats:\n"); + float traffic = 0.0f; + int uploads = 0; + int maxSize = 0; + for (size_t i = 0; i < m_BufferKeys.size(); ++i) + maxSize = std::max(int(m_BufferKeys[i]>>16), maxSize); + + int imgWidth = maxSize+1; + int imgHeight = m_Buffers.size()*3*4; + UInt8* imgData = new UInt8[imgWidth*imgHeight*3]; + memset (imgData, 0, imgWidth*imgHeight*3); + + for (size_t i = 0; i < m_Buffers.size(); ++i) + { + ConstBuffer& cb = m_Buffers[i]; + int cbId = (m_BufferKeys[i]&0xFFFF); + int cbSize = (m_BufferKeys[i]>>16); + ShaderLab::FastPropertyName name; + name.index = cbId; + traffic += (cbSize*cb.statsDirty)/1024.0f; + uploads += cb.statsDirty; + printf_console (" %s size:%i (%.1fkB in %i upl) vs:%i ps:%i\n", name.GetName(), cbSize, (cbSize*cb.statsDirty)/1024.0f, cb.statsDirty, cb.statsVS, cb.statsPS); + if (cb.statsDirty > 0) + { + for (int j = 0; j < cbSize/4; ++j) + { + UInt8 bgr[3]; + DensityToBGR (cb.tryCounts[j], bgr); + PutBGRPixelBlock (imgData, imgWidth, j*4, i*3*4, bgr); + DensityToBGR (cb.changeCounts[j], bgr); + PutBGRPixelBlock (imgData, imgWidth, j*4, i*3*4+4, bgr); + } + } + for (int j = 0; j < 8; ++j) + { + imgData[((i*3*4+j)*imgWidth + cbSize)*3 + 1] = 255; + } + } + WriteTGAFile ("cbStats.tga", imgWidth, imgHeight, imgData); + delete[] imgData; + printf_console (" =%i uploads, %.1fkB traffic\n\n", uploads, traffic); + } + + // reset stats + for (size_t i = 0; i < m_Buffers.size(); ++i) + { + ConstBuffer& cb = m_Buffers[i]; + int cbSize = (m_BufferKeys[i]>>16); + cb.statsDirty = cb.statsVS = cb.statsPS = 0; + memset (cb.changeCounts, 0, cbSize/4*4); + memset (cb.tryCounts, 0, cbSize/4*4); + } +} +#endif + +#endif
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengles30/ConstantBuffersGLES30.h b/Runtime/GfxDevice/opengles30/ConstantBuffersGLES30.h new file mode 100644 index 0000000..a22eba2 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/ConstantBuffersGLES30.h @@ -0,0 +1,72 @@ +#pragma once + +#include "IncludesGLES30.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + + +#define DEBUG_GLES30_CONSTANT_BUFFER_STATS 0 + +#if DEBUG_GLES30_CONSTANT_BUFFER_STATS +#include <map> +#endif + + +class ConstantBuffersGLES30 +{ +public: + ConstantBuffersGLES30(); + ~ConstantBuffersGLES30() { Clear(); } + + void Clear(); + + struct ConstBuffer { + int bindIndex; + bool dirty; + UInt8* data; + UInt32 buffer; + #if DEBUG_GLES30_CONSTANT_BUFFER_STATS + int statsDirty; + int stats + int* tryCounts; + int* changeCounts; + #endif + }; + + void SetCBInfo (int id, int size); + int FindAndBindCB (int id, int bind, int size); + void ResetBinds (); + + void SetBuiltinCBConstant (int id, int offset, const void* data, int size); + void SetCBConstant (int index, int offset, const void* data, int size); + + void UpdateBuffers(); + void NewFrame(); + +private: + inline int GetCBIndexByID (int id) const + { + UInt32 key = id; + int n = m_BufferKeys.size(); + for (int i = 0; i < n; ++i) + { + if ((m_BufferKeys[i]&0xFFFF) == key) + return i; + } + Assert (false); + return -1; + } + +private: + typedef std::vector<UInt32> ConstBufferKeys; + typedef std::vector<ConstBuffer> ConstBuffers; + ConstBufferKeys m_BufferKeys; + ConstBuffers m_Buffers; + + UInt32 m_ActiveBuffers[16]; +}; + + +#if !DEBUG_GLES30_CONSTANT_BUFFER_STATS +inline void ConstantBuffersGLES30::NewFrame() { } +#endif + diff --git a/Runtime/GfxDevice/opengles30/ContextGLES30.cpp b/Runtime/GfxDevice/opengles30/ContextGLES30.cpp new file mode 100644 index 0000000..812d81b --- /dev/null +++ b/Runtime/GfxDevice/opengles30/ContextGLES30.cpp @@ -0,0 +1,288 @@ +#include "UnityPrefix.h" +#include "ContextGLES30.h" +#include "IncludesGLES30.h" +#include "AssertGLES30.h" +#include "Runtime/Graphics/ScreenManager.h" +#include "Runtime/Misc/QualitySettings.h" + +#if GFX_SUPPORTS_OPENGLES30 + +#if UNITY_WIN + +#define EGL_OPENGL_ES3_BIT_KHR 0x00000040 + + +struct EGLESData +{ + void* dsp; + void* cfg; + void* cxt; + void* surf; + EGLESData():dsp(NULL),cfg(NULL),cxt(NULL),surf(NULL){} +}; + + +static EGLESData sOpenGLESData; + +bool InitializeGLES30 () +{ + HWND hwnd = GetScreenManager().GetWindow(); + if (hwnd) + { + CreateContextGLES30 (hwnd); + return true; + } + ErrorString ("gles20: Can't initialize because HWND not set up"); + return false; +} +void ShutdownGLES30 () +{ + DestroyContextGLES30(); +} +bool IsContextGLES30Created() +{ + return sOpenGLESData.surf != NULL && + sOpenGLESData.cxt != NULL && + sOpenGLESData.cfg != NULL && + sOpenGLESData.dsp != NULL; +} + +bool CreateContextGLES30(HWND hWnd) +{ + //Just in case + DestroyContextGLES30(); + + EGLint numConfigs; + EGLint majorVersion; + EGLint minorVersion; + +#if UNITY_WIN + + int sampleCount = GetQualitySettings().GetCurrent().antiAliasing; + + /// Build up the attribute list + const EGLint configAttribs[] = + { + EGL_LEVEL, 0, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, + EGL_NATIVE_RENDERABLE, EGL_FALSE, + EGL_DEPTH_SIZE, 16, + EGL_ALPHA_SIZE, 1, + EGL_STENCIL_SIZE, 1, + EGL_SAMPLES, sampleCount, + EGL_NONE + }; + + // Get Display + sOpenGLESData.dsp = eglGetDisplay( hWnd?GetDC(hWnd):EGL_DEFAULT_DISPLAY ); + if ( sOpenGLESData.dsp == EGL_NO_DISPLAY ) + { + printf_console("GLES30: eglGetDisplay failed\n" ); + return false; + } + //Hack : eglInitialize invokes WM_ACTIVATE message, and gAppActive is already true, so Unity will try to call some functions which requires some initialization, + // and this is not done yet + extern bool gAlreadyClosing; + bool last = gAlreadyClosing; + gAlreadyClosing = true; + // Initialize EGL + if ( ! eglInitialize( sOpenGLESData.dsp, &majorVersion, &minorVersion) ) + { + printf_console("GLES30: eglInitialize failed\n"); + return false; + } + + + // Choose config + if ( !eglChooseConfig(sOpenGLESData.dsp, configAttribs, &sOpenGLESData.cfg, 1, &numConfigs) ) + { + printf_console("GLES30: eglChooseConfig failed\n"); + return false; + } + + + // Create a surface + sOpenGLESData.surf = eglCreateWindowSurface( sOpenGLESData.dsp, sOpenGLESData.cfg, NativeWindowType( hWnd ), NULL ); + if ( sOpenGLESData.surf == EGL_NO_SURFACE ) + { + printf_console("GLES30: eglCreateWindowSurface failed\n"); + return false; + } + + // Create a GL context + EGLint ctxAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE}; + sOpenGLESData.cxt = eglCreateContext( sOpenGLESData.dsp, sOpenGLESData.cfg, EGL_NO_CONTEXT, ctxAttribList ); + if ( sOpenGLESData.cxt == EGL_NO_CONTEXT ) + { + printf_console("GLES30: eglCreateContext failed\n"); + return false; + } + + // Make the context current + if ( ! eglMakeCurrent( sOpenGLESData.dsp, sOpenGLESData.surf, sOpenGLESData.surf, sOpenGLESData.cxt ) ) + { + printf_console("GLES30: eglMakeCurrent failed\n"); + return false; + } + + gAlreadyClosing = last; +#endif + + GLESAssert(); + + return true; +} + + +void DestroyContextGLES30() +{ + if(sOpenGLESData.dsp) + { + eglMakeCurrent(sOpenGLESData.dsp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) ; + eglDestroyContext( sOpenGLESData.dsp, sOpenGLESData.cxt ); + eglDestroySurface( sOpenGLESData.dsp, sOpenGLESData.surf ); + eglTerminate( sOpenGLESData.dsp); + } + sOpenGLESData.surf = NULL; + sOpenGLESData.cxt = NULL; + sOpenGLESData.cfg = NULL; + sOpenGLESData.dsp = NULL; +} +void PresentContextGLES30() +{ + eglSwapBuffers( sOpenGLESData.dsp, sOpenGLESData.surf ); +} + +void AcquireGLES30Context() +{ + if(sOpenGLESData.dsp) + { + // Make the context current + if ( ! eglMakeCurrent( sOpenGLESData.dsp, sOpenGLESData.surf, sOpenGLESData.surf, sOpenGLESData.cxt ) ) + { + printf_console("GLES30: eglMakeCurrent failed\n"); + } + } +} + +void ReleaseGLES30Context() +{ + if(sOpenGLESData.dsp) + { + eglMakeCurrent(sOpenGLESData.dsp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) ; + } +} + + +#elif UNITY_LINUX + +static EGLDisplay gEGLDisplay = EGL_NO_DISPLAY; +static EGLConfig gEGLConfig; +static EGLSurface gEGLSurface = EGL_NO_SURFACE; +static EGLContext gEGLContext = EGL_NO_CONTEXT; + +void SetEGLDisplay(EGLDisplay display) +{ + gEGLDisplay = display; +} + +void SetEGLConfig(const EGLConfig &config) +{ + gEGLConfig = config; +} + +bool InitializeGLES30 () +{ + Window window = 0; + window = GetScreenManager().GetWindow(); + + if(window) + { + CreateContextGLES30(window); + return true; + } + + return false; +} + +void ShutdownGLES30 () +{ + DestroyContextGLES30(); +} + +bool IsContextGLES30Created() +{ + return gEGLSurface != EGL_NO_SURFACE && gEGLContext != EGL_NO_CONTEXT; +} + +bool CreateContextGLES30(Window window) +{ + DestroyContextGLES30(); + + gEGLSurface = eglCreateWindowSurface(gEGLDisplay, gEGLConfig, window, NULL); + if(gEGLSurface == EGL_NO_SURFACE) + { + printf_console("eglCreateWindowSurface failed\n"); + return false; + } + + // Create a context + printf_console("Creating context\n"); + EGLint ctxAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; + gEGLContext = eglCreateContext(gEGLDisplay, gEGLConfig, EGL_NO_CONTEXT, ctxAttribList ); + if ( gEGLContext == EGL_NO_CONTEXT ) + { + printf_console( "eglCreateContext failed\n" ); + return false; + } + + if(!eglMakeCurrent(gEGLDisplay, gEGLSurface, gEGLSurface, gEGLContext)) + { + printf_console("eglMakeCurrent failed\n"); + } + + return true; +} + +void DestroyContextGLES30() +{ + if(IsContextGLES30Created()) + { + eglMakeCurrent(gEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(gEGLDisplay, gEGLContext); + eglDestroySurface(gEGLDisplay, gEGLSurface); + } + + gEGLSurface = EGL_NO_SURFACE; + gEGLContext = EGL_NO_CONTEXT; +} + +void PresentContextGLES() +{ + eglSwapBuffers(gEGLDisplay, gEGLSurface); +} + +void AcquireGLES30Context() +{ + if(gEGLDisplay) + { + // Make the context current + if(!eglMakeCurrent(gEGLDisplay, gEGLSurface, gEGLSurface, gEGLContext)) + { + printf_console("GLES30: eglMakeCurrent failed\n"); + } + } +} + +void ReleaseGLES30Context() +{ + if(gEGLDisplay) + { + eglMakeCurrent(gEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + } +} + + +#endif // UNITY_WIN +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/ContextGLES30.h b/Runtime/GfxDevice/opengles30/ContextGLES30.h new file mode 100644 index 0000000..c509f57 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/ContextGLES30.h @@ -0,0 +1,37 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +#if UNITY_LINUX +#include <X11/Xlib.h> +#include <GLES3/gl2.h> +#endif + +#if UNITY_BB10 +#include <GLES3/gl2.h> +#include <screen/screen.h> +#endif + +#if UNITY_WIN || UNITY_LINUX || UNITY_BB10 || UNITY_ANDROID +bool InitializeGLES30 (); +void ShutdownGLES30 (); +bool IsContextGLES30Created(); +#if UNITY_WIN +bool CreateContextGLES30(HWND hWnd); +#elif UNITY_LINUX +bool CreateContextGLES30(Window window); +#elif UNITY_BB10 +bool CreateContextGLES30(screen_window_t window); +void ResizeContextGLES30(screen_window_t window, int width, int height); +#endif +void DestroyContextGLES30(); +#endif +void PresentContextGLES(); +void PresentContextGLES30(); + +void ReleaseGLES30Context(); + +void AcquireGLES30Context(); + + diff --git a/Runtime/GfxDevice/opengles30/DataBuffersGLES30.cpp b/Runtime/GfxDevice/opengles30/DataBuffersGLES30.cpp new file mode 100644 index 0000000..24484d7 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/DataBuffersGLES30.cpp @@ -0,0 +1,429 @@ +#include "UnityPrefix.h" +#include "DataBuffersGLES30.h" + +#if GFX_SUPPORTS_OPENGLES30 + +#include "AssertGLES30.h" +#include "IncludesGLES30.h" +#include "Runtime/GfxDevice/GLDataBufferCommon.h" + +#include <algorithm> + +#if 1 + #define DBG_LOG_BUF_GLES30(...) {} +#else + #define DBG_LOG_BUF_GLES30(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#endif + +static const float kBufferAllocateWeight = 10.0f; //! Default weight for buffer allocation from scratch. +static const float kBufferSizeWeightFactor = 1.f/8096.f; //!< Weight factor for size difference. +static const float kBufferUsageDiffWeight = 8.f; //!< Weight factor for usage difference. + +static const float kBufferDeleteSizeWeightFactor = 1.f/16384.f; //!< Deleting scale factor. +static const float kBufferDeleteMaxWeightFactor = 300.0f; //!< ... +static const float kBufferDeleteMinWeight = 30.0f; //!< Required weight for deleting buffer. + +static const UInt32 kBufferPruneFrequency = 10; //!< Unneeded buffers are pruned once per kBufferPruneFrequency frames. + +bool BufferUpdateCausesStallGLES30 (const DataBufferGLES30* buffer) +{ + // \note If needed, the min age should me made ES3 specific graphics capability. + return buffer->GetRenderAge() < kBufferUpdateMinAgeGLES30; +} + +//! Computes weight for sorting buffers +static float ComputeBufferWeight (const DataBufferGLES30* buffer, int desiredSize, UInt32 desiredUsage) +{ + const int bufferSize = buffer->GetSize(); + const UInt32 bufferUsage = buffer->GetUsage(); + + if (buffer->GetSize() == 0) + return kBufferAllocateWeight; + + const int sizeDiff = std::abs(bufferSize-desiredSize); + + return float(sizeDiff)*kBufferSizeWeightFactor + ((bufferUsage != desiredUsage) ? kBufferUsageDiffWeight : 0.f); +} + +//! Compute weight for eliminating old buffers. +static float ComputeBufferDeleteWeight (const DataBufferGLES30* buffer) +{ + // \todo [2013-05-13 pyry] Take into account current memory pressure and buffer size. + const UInt32 renderAge = buffer->GetRenderAge(); + return float(renderAge) - std::min(kBufferDeleteMaxWeightFactor, float(buffer->GetSize())*kBufferDeleteSizeWeightFactor); +} + +struct WeightedBufferGLES3 +{ + int sizeClass; + int bufferNdx; + float weight; + + WeightedBufferGLES3 (int sizeClass_, int bufferNdx_, float weight_) + : sizeClass (sizeClass_) + , bufferNdx (bufferNdx_) + , weight (weight_) + { + } +}; + +struct CompareWeightsLess +{ + inline bool operator() (const WeightedBufferGLES3& a, const WeightedBufferGLES3& b) const + { + return a.weight < b.weight; + } +}; + +struct CompareWeightsGreater +{ + inline bool operator() (const WeightedBufferGLES3& a, const WeightedBufferGLES3& b) const + { + return a.weight > b.weight; + } +}; + +// DataBufferGLES30 + +static const GLenum kBufferTarget = GL_COPY_WRITE_BUFFER; //!< Target used for buffer operations. + +DataBufferGLES30::DataBufferGLES30 (BufferManagerGLES30& bufferManager) + : m_manager (bufferManager) + , m_buffer (0) + , m_size (0) + , m_usage (0) + , m_lastRecreated (0) + , m_lastUpdated (0) + , m_lastRendered (0) +{ + GLES_CHK(glGenBuffers(1, (GLuint*)&m_buffer)); +} + +DataBufferGLES30::~DataBufferGLES30 (void) +{ + if (m_buffer) + glDeleteBuffers(1, (GLuint*)&m_buffer); +} + +void DataBufferGLES30::Disown (void) +{ + m_buffer = 0; +} + +void DataBufferGLES30::Release (void) +{ + m_manager.ReleaseBuffer(this); +} + +void DataBufferGLES30::RecreateStorage (int size, UInt32 usage) +{ + RecreateWithData(size, usage, 0); +} + +void DataBufferGLES30::RecreateWithData (int size, UInt32 usage, const void* data) +{ + glBindBuffer(kBufferTarget, m_buffer); + glBufferData(kBufferTarget, size, data, usage); + glBindBuffer(kBufferTarget, 0); + GLESAssert(); + + RecordRecreate(size, usage); +} + +void DataBufferGLES30::Upload (int offset, int size, const void* data) +{ + glBindBuffer(kBufferTarget, m_buffer); + glBufferSubData(kBufferTarget, offset, size, data); + glBindBuffer(kBufferTarget, 0); + GLESAssert(); + + RecordUpdate(); +} + +void* DataBufferGLES30::Map (int offset, int size, UInt32 mapBits) +{ + glBindBuffer(kBufferTarget, m_buffer); + void* ptr = glMapBufferRange(kBufferTarget, offset, size, mapBits); + glBindBuffer(kBufferTarget, 0); + GLESAssert(); + + return ptr; +} + +void DataBufferGLES30::FlushMappedRange (int offset, int size) +{ + glBindBuffer(kBufferTarget, m_buffer); + glFlushMappedBufferRange(kBufferTarget, offset, size); + glBindBuffer(kBufferTarget, 0); + GLESAssert(); +} + +void DataBufferGLES30::Unmap (void) +{ + glBindBuffer(kBufferTarget, m_buffer); + glUnmapBuffer(kBufferTarget); + glBindBuffer(kBufferTarget, 0); + GLESAssert(); +} + +void DataBufferGLES30::RecordRecreate (int size, UInt32 usage) +{ + if (BufferUpdateCausesStallGLES30(this)) + DBG_LOG_BUF_GLES30("DataBufferGLES30: Warning: buffer with render age %u was recreated!", GetRenderAge()); + + m_size = size; + m_usage = usage; + m_lastRecreated = m_manager.GetFrameIndex(); + + // Update GFX mem allocation stats + REGISTER_EXTERNAL_GFX_DEALLOCATION(MAKE_DATA_BUFFER_ID(m_buffer)); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(MAKE_DATA_BUFFER_ID(m_buffer), size, this); +} + +void DataBufferGLES30::RecordUpdate (void) +{ + if (BufferUpdateCausesStallGLES30(this)) + DBG_LOG_BUF_GLES30("DataBufferGLES30: Warning: buffer with render age %u was updated!", GetRenderAge()); + + m_lastUpdated = m_manager.GetFrameIndex(); +} + +void DataBufferGLES30::RecordRender (void) +{ + m_lastRendered = m_manager.GetFrameIndex(); +} + +// \note Overflow is perfectly ok here. + +UInt32 DataBufferGLES30::GetRecreateAge (void) const +{ + return m_manager.GetFrameIndex() - m_lastRecreated; +} + +UInt32 DataBufferGLES30::GetUpdateAge (void) const +{ + return m_manager.GetFrameIndex() - m_lastUpdated; +} + +UInt32 DataBufferGLES30::GetRenderAge (void) const +{ + return m_manager.GetFrameIndex() - m_lastRendered; +} + +// BufferManagerGLES30 + +BufferManagerGLES30::BufferManagerGLES30 (void) + : m_frameIndex(0) +{ +} + +BufferManagerGLES30::~BufferManagerGLES30 (void) +{ + Clear(); +} + +void BufferManagerGLES30::Clear (void) +{ + for (std::vector<DataBufferGLES30*>::iterator i = m_pendingBuffers.begin(); i != m_pendingBuffers.end(); i++) + delete *i; + m_pendingBuffers.clear(); + + for (int ndx = 0; ndx < kSizeClassCount; ndx++) + { + for (std::vector<DataBufferGLES30*>::iterator i = m_liveBuffers[ndx].begin(); i != m_liveBuffers[ndx].end(); i++) + delete *i; + m_liveBuffers[ndx].clear(); + } +} + +inline int BufferManagerGLES30::GetSizeClass (int size) +{ + for (int ndx = 0; ndx < kSizeClassCount; ndx++) + { + if (size < GetSizeClassLimit(ndx)) + return ndx; + } + Assert(false); + return 0; +} + +DataBufferGLES30* BufferManagerGLES30::AcquireBuffer (int size, UInt32 usage) +{ + const float maxWeight = kBufferAllocateWeight; + const int maxCandidates = 5; // Number of potential candidates to consider actually. + + const int sizeClass = GetSizeClass(size); // Try only that size class + int numCandidates = 0; // Number of potential candidates considered + int bestBufferNdx = -1; + float bestWeight = std::numeric_limits<float>::infinity(); + + for (int bufferNdx = 0; bufferNdx < (int)m_liveBuffers[sizeClass].size(); bufferNdx++) + { + DataBufferGLES30* buffer = m_liveBuffers[sizeClass][bufferNdx]; + const float weight = ComputeBufferWeight(buffer, size, usage); + + if (weight <= maxWeight && weight < bestWeight) + { + bestBufferNdx = bufferNdx; + bestWeight = weight; + + numCandidates += 1; + } + + if (numCandidates >= maxCandidates) + break; // Do not try other buffers, sorry. + } + + DBG_LOG_BUF_GLES30("BufferManagerGLES30::AcquireBuffer(%d, 0x%04x): tried %d candidates", size, usage, numCandidates); + + if (bestBufferNdx >= 0) + { + const int bufferNdx = bestBufferNdx; + DataBufferGLES30* selectedBuffer = m_liveBuffers[sizeClass][bufferNdx]; + + if (bufferNdx+1 != m_liveBuffers[sizeClass].size()) + std::swap(m_liveBuffers[sizeClass][bufferNdx], m_liveBuffers[sizeClass].back()); + m_liveBuffers[sizeClass].pop_back(); + + DBG_LOG_BUF_GLES30(" => selected buffer [%d]%d, weight = %f", sizeClass, bufferNdx, ComputeBufferWeight(selectedBuffer, size, usage)); + return selectedBuffer; + } + else + { + DBG_LOG_BUF_GLES30(" => creating new buffer"); + return new DataBufferGLES30(*this); + } +} + +void BufferManagerGLES30::ReleaseBuffer (DataBufferGLES30* buffer) +{ + if (!BufferUpdateCausesStallGLES30(buffer)) + InsertIntoLive(buffer); + else + m_pendingBuffers.push_back(buffer); +} + +void BufferManagerGLES30::AdvanceFrame (void) +{ + m_frameIndex += 1; // \note Overflow is ok. + + UpdateLiveSetFromPending(); + + // \todo [2013-05-13 pyry] Do we want to do pruning somewhere else as well? + if ((m_frameIndex % kBufferPruneFrequency) == 0) + PruneFreeBuffers(); +} + +void BufferManagerGLES30::UpdateLiveSetFromPending (void) +{ + int bufNdx = 0; + while (bufNdx < (int)m_pendingBuffers.size()) + { + if (!BufferUpdateCausesStallGLES30(m_pendingBuffers[bufNdx])) + { + DataBufferGLES30* newLiveBuffer = m_pendingBuffers[bufNdx]; + + if (bufNdx+1 != m_pendingBuffers.size()) + std::swap(m_pendingBuffers[bufNdx], m_pendingBuffers.back()); + m_pendingBuffers.pop_back(); + + InsertIntoLive(newLiveBuffer); + // \note bufNdx now contains a new buffer and it must be processed as well. Thus bufNdx is not incremented. + } + else + bufNdx += 1; + } +} + +void BufferManagerGLES30::InsertIntoLive (DataBufferGLES30* buffer) +{ + const int bufSize = buffer->GetSize(); + const int sizeClass = GetSizeClass(bufSize); + + m_liveBuffers[sizeClass].push_back(buffer); +} + +UInt32 BufferManagerGLES30::GetTotalFreeSize (void) +{ + UInt32 totalBytes = 0; + + for (std::vector<DataBufferGLES30*>::const_iterator bufIter = m_pendingBuffers.begin(); bufIter != m_pendingBuffers.end(); ++bufIter) + totalBytes += (*bufIter)->GetSize(); + + for (int ndx = 0; ndx < kSizeClassCount; ndx++) + { + for (std::vector<DataBufferGLES30*>::const_iterator bufIter = m_liveBuffers[ndx].begin(); bufIter != m_liveBuffers[ndx].end(); ++bufIter) + totalBytes += (*bufIter)->GetSize(); + } + + return totalBytes; +} + +void BufferManagerGLES30::PruneFreeBuffers (void) +{ + const UInt32 numBytesInFreeList = GetTotalFreeSize(); + DBG_LOG_BUF_GLES30("BufferManagerGLES30: %u B / %.2f MiB in free buffers", numBytesInFreeList, float(numBytesInFreeList) / float(1<<20)); + + // \todo [2013-05-13 pyry] Do this properly - take into account allocated memory size. + + UInt32 numBytesFreed = 0; + int numBuffersDeleted = 0; + + // \note pending buffers are ignored. They will end up in live soon anyway. + for (int sizeClass = 0; sizeClass < kSizeClassCount; sizeClass++) + { + int bufNdx = 0; + while (bufNdx < m_liveBuffers[sizeClass].size()) + { + DataBufferGLES30* buffer = m_liveBuffers[sizeClass][bufNdx]; + const float weight = ComputeBufferDeleteWeight(buffer); + + if (weight >= kBufferDeleteMinWeight) + { + if (bufNdx+1 != m_liveBuffers[sizeClass].size()) + std::swap(m_liveBuffers[sizeClass][bufNdx], m_liveBuffers[sizeClass].back()); + m_liveBuffers[sizeClass].pop_back(); + + numBytesFreed += buffer->GetSize(); + numBuffersDeleted += 1; + + delete buffer; + } + else + bufNdx += 1; + } + } + + DBG_LOG_BUF_GLES30(" => freed %d buffers, %u B / %.2f MiB", numBuffersDeleted, numBytesFreed, float(numBytesFreed) / float(1<<20)); +} + +void BufferManagerGLES30::InvalidateAll (void) +{ + for (std::vector<DataBufferGLES30*>::iterator iter = m_pendingBuffers.begin(); iter != m_pendingBuffers.end(); ++iter) + { + (*iter)->Disown(); + delete *iter; + } + m_pendingBuffers.clear(); + + for (int classNdx = 0; classNdx < kSizeClassCount; classNdx++) + { + for (std::vector<DataBufferGLES30*>::iterator iter = m_liveBuffers[classNdx].begin(); iter != m_liveBuffers[classNdx].end(); ++iter) + { + (*iter)->Disown(); + delete *iter; + } + m_liveBuffers[classNdx].clear(); + } +} + +BufferManagerGLES30* g_bufferManager = 0; + +BufferManagerGLES30* GetBufferManagerGLES30 (void) +{ + if (!g_bufferManager) + g_bufferManager = new BufferManagerGLES30(); + return g_bufferManager; +} + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/DataBuffersGLES30.h b/Runtime/GfxDevice/opengles30/DataBuffersGLES30.h new file mode 100644 index 0000000..524dc53 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/DataBuffersGLES30.h @@ -0,0 +1,137 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/GfxDeviceConfigure.h" + +#if GFX_SUPPORTS_OPENGLES30 + +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +class BufferManagerGLES30; + +enum +{ + kBufferUpdateMinAgeGLES30 = 2 //!< This many frames must be elapsed since last render before next buffer update. \todo [2013-05-31 pyry] From GfxDevice caps +}; + +class DataBufferGLES30 +{ +public: + DataBufferGLES30 (BufferManagerGLES30& bufferManager); + ~DataBufferGLES30 (void); + + void Release (void); //!< Release to BufferManager. + + UInt32 GetBuffer (void) const { return m_buffer; } + int GetSize (void) const { return m_size; } + UInt32 GetUsage (void) const { return m_usage; } + + void RecreateStorage (int size, UInt32 usage); + void RecreateWithData (int size, UInt32 usage, const void* data); + + void Upload (int offset, int size, const void* data); + + void* Map (int offset, int size, UInt32 mapBits); + void FlushMappedRange (int offset, int size); + void Unmap (void); + + void RecordRecreate (int size, UInt32 usage); //!< Updates storage parameters and recreate time. + void RecordUpdate (void); //!< Updates last update time if buffer was updated manually. + void RecordRender (void); //!< Updates last render time. + + UInt32 GetRecreateAge (void) const; + UInt32 GetUpdateAge (void) const; + UInt32 GetRenderAge (void) const; + + //! Disown and remove buffer handle. Used if destructor should not try to delete buffer.. + void Disown (void); + +private: + DataBufferGLES30 (const DataBufferGLES30& other); + DataBufferGLES30& operator= (const DataBufferGLES30& other); + + BufferManagerGLES30& m_manager; + UInt32 m_buffer; + int m_size; + UInt32 m_usage; + + // \note Always used to compute relative age and overflow is handled + // in computation. Thus frame index can safely overflow. + UInt32 m_lastRecreated; //!< Last recreated. + UInt32 m_lastUpdated; //!< Frame index when last updated. + UInt32 m_lastRendered; //!< Frame index when last rendered. +}; + +// BufferManager +// +// BufferManager is responsible for allocating and maintaining list of free buffer objects that +// could be recycled later on. Buffers are either allocated or recycled based on their properties. +// Most important property for proper use of buffers is to make sure they are not recycled +// too soon after using them for rendering. +// +// BufferManager is only responsible for managing currently free buffers. So user must either +// release or destroy buffer objects manually. User is also responsible of implementing sane +// usage patterns for buffers that it owns (for example not updating data right after buffer +// has been submitted for rendering). +// +// Buffers are associated to the BufferManager that was used to create them. Thus user must either +// destroy buffer, or release it back to same BufferManager. +// +// The best usage pattern for leveraging BufferManager is to always release buffers when there +// is no longer need to preserve the data in buffer object. That way BufferManager takes care +// of recycling buffer when it is appropriate. + +class BufferManagerGLES30 +{ +public: + BufferManagerGLES30 (void); + ~BufferManagerGLES30 (void); + + //! Acquire a new or recycled buffer. Returns either buffer object that can fit data, or empty buffer (GetSize() == 0). + DataBufferGLES30* AcquireBuffer (int size, UInt32 usage); + void ReleaseBuffer (DataBufferGLES30* buffer); + + void AdvanceFrame (void); //!< Advance frame index. Must be called at the end of frame. + UInt32 GetFrameIndex (void) const { return m_frameIndex; } + + //!< Invalidate all owned buffers. Used on context loss. + void InvalidateAll (void); + +private: + BufferManagerGLES30 (const BufferManagerGLES30& other); + BufferManagerGLES30& operator= (const BufferManagerGLES30& other); + + void Clear (void); + + void PruneFreeBuffers (void); + UInt32 GetTotalFreeSize (void); + + static inline int GetSizeClassLimit (int classNdx) { return classNdx+1 < kSizeClassCount ? (1<<(classNdx*kSizeClassStepLog2 + kSizeClassBaseLog2)) : INT_MAX; } + + void UpdateLiveSetFromPending(void); + void InsertIntoLive (DataBufferGLES30* buffer); + static int GetSizeClass (int bufSize); + + UInt32 m_frameIndex; //!< Frame index for computing buffer ages. + + enum + { + kSizeClassBaseLog2 = 10, + kSizeClassStepLog2 = 1, + kSizeClassCount = 7 + }; + + // Buffers that can not be selected are in pendingBuffers. Live buffers contain + // buffers organized by size into kSizeClassCount classes. + std::vector<DataBufferGLES30*> m_pendingBuffers; + std::vector<DataBufferGLES30*> m_liveBuffers[kSizeClassCount]; +}; + +// \todo [2013-05-10 pyry] Do not use singletons... +BufferManagerGLES30* GetBufferManagerGLES30 (void); + +//! Determine if buffer update will likely cause GPU stall. +bool BufferUpdateCausesStallGLES30 (const DataBufferGLES30* buffer); + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/DebugGLES30.cpp b/Runtime/GfxDevice/opengles30/DebugGLES30.cpp new file mode 100644 index 0000000..af5efad --- /dev/null +++ b/Runtime/GfxDevice/opengles30/DebugGLES30.cpp @@ -0,0 +1,38 @@ +#include "UnityPrefix.h" +#include "IncludesGLES30.h" +#include "DebugGLES30.h" +#include "AssertGLES30.h" + + +void DumpVertexArrayStateGLES30() +{ +#if GFX_SUPPORTS_OPENGLES30 + GLint maxVertexAttribs = 0; + GLES_CHK(glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs)); + + GLint vbo = 0; + GLint ibo = 0; + GLES_CHK(glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vbo)); + GLES_CHK(glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &ibo)); + + printf_console("---> VertexArray State: vbo:%d ibo:%d\n", vbo, ibo); + + for (int q = 0; q < maxVertexAttribs; ++q) + { + int enabled, size, stride, normalized, type, vbo; + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_SIZE, &size)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &stride)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &normalized)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_TYPE, &type)); + GLES_CHK(glGetVertexAttribiv(q, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &vbo)); + + GLvoid* ptr; + GLES_CHK(glGetVertexAttribPointerv(q, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); + + printf_console(" attr[%d] --- %s type:%d size:%d stride:%d norm:%d vbo:%d, %p\n", + q, enabled? "On ": "Off", + type, size, stride, normalized, vbo, ptr); + } +#endif +} diff --git a/Runtime/GfxDevice/opengles30/DebugGLES30.h b/Runtime/GfxDevice/opengles30/DebugGLES30.h new file mode 100644 index 0000000..0468cdf --- /dev/null +++ b/Runtime/GfxDevice/opengles30/DebugGLES30.h @@ -0,0 +1,139 @@ +#ifndef DEBUGGLES30_H +#define DEBUGGLES30_H + +#include "Runtime/Utilities/LogAssert.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Math/Matrix4x4.h" + + +void DumpVertexArrayStateGLES30(); + +#if !UNITY_RELEASE + #define DBG_LOG_GLES30_ACTIVE 0 + #define DBG_TEXTURE_VERBOSE_GLES30_ACTIVE 0 + #define DBG_SHADER_VERBOSE_GLES30_ACTIVE 0 + #define DBG_GLSL_BINDINGS_GLES30_ACTIVE 0 +#else + #define DBG_LOG_GLES30_ACTIVE UNITY_WEBGL + #define DBG_TEXTURE_VERBOSE_GLES30_ACTIVE UNITY_WEBGL + #define DBG_SHADER_VERBOSE_GLES30_ACTIVE 0 + #define DBG_GLSL_BINDINGS_GLES30_ACTIVE 0 +#endif + +#if DBG_LOG_GLES30_ACTIVE + #define DBG_LOG_GLES30(...) {printf_console(__VA_ARGS__);printf_console("\n");} + + inline std::string GetMatrixString(const Matrix4x4f& mtx) + { + return Format("%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f,\n" + "%.2f, %.2f, %.2f, %2f", + mtx[0], mtx[1], mtx[2], mtx[3], + mtx[4], mtx[5], mtx[6], mtx[7], + mtx[8], mtx[9], mtx[10],mtx[11], + mtx[12],mtx[13],mtx[14],mtx[15]); + } + + inline const char* GetBoolString(bool type) + { + return type?"True":"False"; + } + + inline const char * GetBlendModeString(BlendMode type) + { + switch(type) + { + case kBlendZero:return "kBlendZero"; + case kBlendOne:return "kBlendOne"; + case kBlendDstColor:return "kBlendDstColor"; + case kBlendSrcColor:return "kBlendSrcColor"; + case kBlendOneMinusDstColor:return "kBlendOneMinusDstColor"; + case kBlendSrcAlpha:return "kBlendSrcAlpha"; + case kBlendOneMinusSrcColor:return "kBlendOneMinusSrcColor"; + case kBlendDstAlpha:return "kBlendDstAlpha"; + case kBlendOneMinusDstAlpha:return "kBlendOneMinusDstAlpha"; + case kBlendSrcAlphaSaturate:return "kBlendSrcAlphaSaturate"; + case kBlendOneMinusSrcAlpha:return "kBlendOneMinusSrcAlpha"; + default:return "GetBlendModeString<Undefined>"; + } + } + inline const char * GetCullModeString(CullMode type) + { + switch(type) + { + case kCullUnknown:return "kCullUnknown"; + case kCullOff:return "kCullOff:return"; + case kCullFront:return "kCullFront"; + case kCullBack:return "kCullBack";; + default:return "GetCullMode<undefined>"; + } + } + + inline const char * GetCompareFunctionString(CompareFunction type) + { + switch(type) + { + case kFuncUnknown:return "kFuncUnknown"; + case kFuncDisabled:return "kFuncDisabled"; + case kFuncNever:return "kFuncNever"; + case kFuncLess:return "kFuncLess"; + case kFuncEqual:return "kFuncEqual"; + case kFuncLEqual:return "kFuncLEqual"; + case kFuncGreater:return "kFuncGreater"; + case kFuncNotEqual:return "kFuncNotEqual"; + case kFuncGEqual:return "kFuncGEqual"; + case kFuncAlways:return "kFuncAlways"; + default:return "GetCompareFunctionString<Undefined>"; + } + } + + inline const char * GetShaderTypeString(ShaderType type) + { + switch(type) + { + case kShaderNone:return "kShaderNone"; + case kShaderVertex:return "kShaderVertex"; + case kShaderFragment:return "kShaderFragment"; + default:return "GetShaderTypeString<undefined>"; + } + } + + inline const char * GetShaderImplTypeString(ShaderImplType type) + { + switch(type) + { + case kShaderImplUndefined: return "kShaderImplUndefined"; + case kShaderImplVertex: return "kShaderImplVertex"; + case kShaderImplFragment: return "kShaderImplFragment"; + case kShaderImplBoth: return "kShaderImplBoth"; + default:return "GetShaderImplTypeString<Undefined>"; + } + } + +#else + #define DBG_LOG_GLES30(...) +#endif + +#if DBG_TEXTURE_VERBOSE_GLES30_ACTIVE +#define DBG_TEXTURE_VERBOSE_GLES30(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#else +#define DBG_TEXTURE_VERBOSE_GLES30(...) +#endif + +#if DBG_SHADER_VERBOSE_GLES30_ACTIVE + #define DBG_SHADER_VERBOSE_GLES30(...) {printf_console(__VA_ARGS__);printf_console("\n");} + #define DBG_SHADER_VERBOSE_GLES30_DUMP_SHADER(prefix, text) { printf_console("%s\n", prefix);DebugTextLineByLine(text);printf_console("\n---\n");} +#else + #define DBG_SHADER_VERBOSE_GLES30(...) + #define DBG_SHADER_VERBOSE_GLES30_DUMP_SHADER(prefix, text) +#endif + +#if DBG_GLSL_BINDINGS_GLES30_ACTIVE + #define DBG_GLSL_BINDINGS_GLES30(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#else + #define DBG_GLSL_BINDINGS_GLES30(...) +#endif + + +#endif diff --git a/Runtime/GfxDevice/opengles30/FixedFunctionStateGLES30.cpp b/Runtime/GfxDevice/opengles30/FixedFunctionStateGLES30.cpp new file mode 100644 index 0000000..de052b9 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/FixedFunctionStateGLES30.cpp @@ -0,0 +1,71 @@ +#include "UnityPrefix.h" +#include "FixedFunctionStateGLES30.h" +#include <sstream> + + +FixedFunctionStateGLES30::FixedFunctionStateGLES30 () +: texUnitCount(0), + lightType(0), + texUnitMatrix(0), + lightingEnabled(false), + specularEnabled(true), + onlyDirectionalLights(false), + lightCount(0), + useUniformInsteadOfVertexColor(false), + useVertexColorAsAmbientAndDiffuse(false), + useVertexColorAsEmission(false), + fogMode(kFogDisabled), + addSpecularAfterTexturing(false), + alphaTest(kFuncDisabled) +{ + for (int q = 0; q < kMaxSupportedTextureUnitsGLES; ++q) + { + texUnitCube[q] = false; + texUnitGen[q] = kTexGenDisabled; + texUnitColorCombiner[q] = ~0UL; + texUnitAlphaCombiner[q] = ~0UL; + } +} + +static std::string CombinerToString (unsigned int combinerDesc) +{ + std::ostringstream s; + s << combinerDesc; + return s.str().c_str(); +} + + +std::string FixedFunctionStateGLES30::ToString () const +{ + std::ostringstream s; + + s << "FixedFunctionStateGLES30::ToString():\n"; + s << " lightingEnabled = " << lightingEnabled << "\n"; + s << " specularEnabled = " << specularEnabled << "\n"; + s << " lights = " << lightCount << "\n"; + for (int i = 0; i < lightCount; ++i) + s << " light" << i << " : " << GetLightType(i) << "\n"; + + s << " useUniformInsteadOfVertexColor = " << useUniformInsteadOfVertexColor << "\n"; + s << " useVertexColorAsAmbientAndDiffuse = " << useVertexColorAsAmbientAndDiffuse << "\n"; + s << " useVertexColorAsEmission = " << useVertexColorAsEmission << "\n"; + + s << " fogMode = " << fogMode << "\n"; + + for (int i = 0; i < texUnitCount; ++i) + { + s << " texture " << i << "\n"; + + s << " CUBE = " << ((texUnitCube[i])? "true": "false") << "\n"; + s << " rgb combiner = " << CombinerToString(texUnitColorCombiner[i]) << "\n"; + s << " alpba combiner = " << CombinerToString(texUnitAlphaCombiner[i]) << "\n"; + s << " texGen = " << texUnitGen[i] << "\n"; + s << " need matrix: " << (NeedTexUnitMatrix(i)?"true":"false") << "\n"; + s << " need perspective divide: " << (IsTexUnitProjected(i)?"true":"false") << "\n"; + } + + s << " addSpecularafterTexturing = " << addSpecularAfterTexturing << "\n"; + s << " alphaTest = " << alphaTest << "\n"; + + return s.str().c_str(); +} diff --git a/Runtime/GfxDevice/opengles30/FixedFunctionStateGLES30.h b/Runtime/GfxDevice/opengles30/FixedFunctionStateGLES30.h new file mode 100644 index 0000000..8de6be8 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/FixedFunctionStateGLES30.h @@ -0,0 +1,65 @@ +#ifndef FIXEDFUNCTIONSTATE_GLES30_H +#define FIXEDFUNCTIONSTATE_GLES30_H + +#include "IncludesGLES30.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include <string> + +// we can use one var to determine both shift and mask, but let help out the compiler ;-) +#define FFPSTATE_SET_MASK(target, idx, val, shift_mul, mask) \ +do{ \ + target &= ~(mask << ((idx)*shift_mul)); \ + target |= (val << ((idx)*shift_mul)); \ +}while(0) \ + + + +class FixedFunctionStateGLES30 +{ +public: + FixedFunctionStateGLES30(); + + UInt32 texUnitColorCombiner[kMaxSupportedTextureUnitsGLES]; + UInt32 texUnitAlphaCombiner[kMaxSupportedTextureUnitsGLES]; + bool texUnitCube[kMaxSupportedTextureUnitsGLES]; + int texUnitGen[kMaxSupportedTextureUnitsGLES]; + int texUnitCount; + + // we will use 4bits per light - this way we can handle up to 8 lights (though kMaxEmulatedVertexLights = 4) + UInt32 lightType; + // we will use 2 bits per tex unit - one for perspective divide, the other one for if we need matrix mul at all + // this way we can store 16 texunit info (though kMaxSupportedTextureUnitsGLES = 8) + UInt32 texUnitMatrix; + + + bool lightingEnabled; + bool specularEnabled; + bool onlyDirectionalLights; + int lightCount : 8; + FogMode fogMode : 8; + CompareFunction alphaTest : 8; + + bool useUniformInsteadOfVertexColor; + bool useVertexColorAsAmbientAndDiffuse; + bool useVertexColorAsEmission; + bool addSpecularAfterTexturing; + + unsigned GetLightType(int i) const { return (lightType >> (i*4)) & 0xF; } + void SetLightType(int i, unsigned type) { FFPSTATE_SET_MASK(lightType, i, type, 4, 0xF); } + + bool NeedTexUnitMatrix(int i) const { return ((texUnitMatrix >> (i*2)) & 0x1) != 0; } + bool IsTexUnitProjected(int i) const { return ((texUnitMatrix >> (i*2)) & 0x2) != 0; } + + void SetTexUnitMatrixParam(int i, bool hasMatrix, bool isProjected) + { + int mask = (hasMatrix ? 1 : 0) | (isProjected ? 2 : 0); + FFPSTATE_SET_MASK(texUnitMatrix, i, mask, 2, 0x3); + } + + std::string ToString () const; +}; + + +#undef FFPSTATE_SET_MASK + +#endif /* FIXEDFUNCTIONSTATE_GLES30_H */ diff --git a/Runtime/GfxDevice/opengles30/GfxDeviceGLES30.cpp b/Runtime/GfxDevice/opengles30/GfxDeviceGLES30.cpp new file mode 100644 index 0000000..240cb58 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GfxDeviceGLES30.cpp @@ -0,0 +1,3328 @@ +#include "UnityPrefix.h" +#if GFX_SUPPORTS_OPENGLES30 +#include "Runtime/Graphics/ScreenManager.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Shaders/MaterialProperties.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/Misc/Allocator.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/Math/Quaternion.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/properties.h" +#include "External/shaderlab/Library/program.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Threads/AtomicOps.h" +#include "Runtime/GfxDevice/TransformState.h" +#include "IncludesGLES30.h" +#include "AssertGLES30.h" +#include "ConstantBuffersGLES30.h" +#include "ContextGLES30.h" +#include "VBOGLES30.h" +#include "TexturesGLES30.h" +#include "CombinerGLES30.h" +#include "GpuProgramsGLES30.h" +#include "FixedFunctionStateGLES30.h" +#include "ShaderGeneratorGLES30.h" +#include "RenderTextureGLES30.h" +#include "DebugGLES30.h" +#include "TimerQueryGLES30.h" +#include "TextureIdMapGLES30.h" +#include "UtilsGLES30.h" +#include "Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.h" +#include "DataBuffersGLES30.h" +#include "Runtime/GfxDevice/opengles/ExtensionsGLES.h" + +#if UNITY_IPHONE + #include "PlatformDependent/iPhonePlayer/iPhoneSettings.h" +#elif UNITY_ANDROID + #include "PlatformDependent/AndroidPlayer/ContextGLES.h" + #include "PlatformDependent/AndroidPlayer/EntryPoint.h" + #include "PlatformDependent/AndroidPlayer/AndroidSystemInfo.h" +#endif + +#include "Runtime/GfxDevice/GLDataBufferCommon.h" + +#define UNITY_GLES3_ENTRYPOINTS_FROM_GETPROCADDR 0 + +#if UNITY_ANDROID +#undef UNITY_GLES3_ENTRYPOINTS_FROM_GETPROCADDR +#define UNITY_GLES3_ENTRYPOINTS_FROM_GETPROCADDR 1 +#endif + +#if UNITY_GLES3_ENTRYPOINTS_FROM_GETPROCADDR + +#define STRINGIFY(x) STRINGIFY2(x) +#define STRINGIFY2(x) #x + +#define DO_GLFUNC(retval, name, ...) typedef void (GL_APIENTRYP PFN##name) (__VA_ARGS__); \ + retval GL_APIENTRY name (__VA_ARGS__) \ +{ \ + static PFN##name addr = NULL; \ + if(!addr) \ + { \ + /*DBG_LOG_GLES30("Retrieving GLES3 proc address " STRINGIFY(name) );*/ \ + addr = (PFN##name) GetGLExtProcAddress(STRINGIFY(name)); \ + if(!addr) \ + { \ + Assert("Could not find GLES 3.0 entry point" STRINGIFY(name)); \ + return (retval)0; \ + } \ + DBG_LOG_GLES30("Success\n"); \ + } \ + __builtin_return(__builtin_apply((void (*)(...))addr, __builtin_apply_args(), 100)); \ + /*DBG_LOG_GLES30("Called " STRINGIFY(name) " successfully\n");*/ \ +} + +DO_GLFUNC(void, glBindBufferBase, GLenum target, GLuint index, GLuint buffer) +DO_GLFUNC(void, glBindBufferRange, GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr range) +DO_GLFUNC(void, glBlitFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) +DO_GLFUNC(void, glDeleteTransformFeedbacks, GLsizei n, const GLuint* ids) +DO_GLFUNC(void, glDrawBuffers, GLsizei n, const GLenum* bufs) +DO_GLFUNC(void, glGenQueries, GLsizei n, GLuint* ids) +DO_GLFUNC(void, glGetActiveUniformBlockiv, GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params) +DO_GLFUNC(void, glGetActiveUniformBlockName, GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) +DO_GLFUNC(void, glGetActiveUniformsiv, GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params) +DO_GLFUNC(void, glGetProgramBinary, GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary) +DO_GLFUNC(void, glGetQueryObjectuiv, GLuint id, GLenum pname, GLuint* params) +DO_GLFUNC(GLuint, glGetUniformBlockIndex, GLuint program, const GLchar *uniformBlockName) +DO_GLFUNC(void, glInvalidateFramebuffer, GLenum target, GLsizei numAttachments, const GLenum* attachments) +DO_GLFUNC(void *, glMapBufferRange, GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) +DO_GLFUNC(void, glProgramBinary, GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length) +DO_GLFUNC(void, glReadBuffer, GLenum buf) +DO_GLFUNC(void, glRenderbufferStorageMultisample, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) +DO_GLFUNC(void, glUniformBlockBinding, GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding) +DO_GLFUNC(GLboolean, glUnmapBuffer, GLenum target) +DO_GLFUNC(void, glGenTransformFeedbacks, GLsizei n, GLuint *ids) +DO_GLFUNC(void, glVertexAttribIPointer, GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) +DO_GLFUNC(void, glTransformFeedbackVaryings, GLuint program, GLsizei count, const char* const* varyings, GLenum bufferMode) +DO_GLFUNC(void, glBeginTransformFeedback, GLenum primitivemode) +DO_GLFUNC(void, glEndTransformFeedback) +DO_GLFUNC(void, glFlushMappedBufferRange, GLenum target, GLintptr offset, GLsizeiptr length) +DO_GLFUNC(void, glGenVertexArrays, GLsizei n, GLuint* arrays) +DO_GLFUNC(void, glDeleteVertexArrays, GLsizei n, const GLuint* arrays) +DO_GLFUNC(void, glBindVertexArray, GLuint array) + +#undef DO_GLFUNC +#undef STRINGIFY +#undef STRINGIFY2 + +#endif +static void ClearFixedFunctionPrograms(); + +// \todo [2013-04-16 pyry] UtilsGLES30 or similar for these? + +static int queryInt (UInt32 pname) +{ + int value = 0; + GLES_CHK(glGetIntegerv(pname, &value)); + return value; +} + +// let's play safe here: +// ios/glesemu works just fine +// and shadows demands more careful eps choice - do it later +#define WORKAROUND_POLYGON_OFFSET UNITY_ANDROID + +// forward declarations + +namespace ShaderLab { + TexEnv* GetTexEnvForBinding( const TextureBinding& binding, const PropertySheet* props ); // pass.cpp +} + +// local forward declarations +struct DeviceStateGLES30; +static void ApplyBackfaceMode( const DeviceStateGLES30& state ); + +static FramebufferObjectManagerGLES30& GetFBOManager (DeviceStateGLES30& deviceState); + +// NOTE: GLES3.0 supports only 4 lights for now +enum { kMaxSupportedVertexLightsByGLES30 = 4 }; + +// Constant tables +static const unsigned int kBlendModeES2[] = { + GL_ZERO, GL_ONE, GL_DST_COLOR, GL_SRC_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR, + GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA_SATURATE, GL_ONE_MINUS_SRC_ALPHA, +}; + +static const unsigned int kBlendFuncES2[] = { + GL_FUNC_ADD, GL_FUNC_SUBTRACT, + GL_FUNC_REVERSE_SUBTRACT, GL_MIN, GL_MAX, +}; + +static const unsigned int kCmpFuncES2[] = { + GL_NEVER, GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS +}; + +static const unsigned int kStencilOpES2[] = { + GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, + GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP +}; + +static const GLenum kWrapModeES2[kTexWrapCount] = { + GL_REPEAT, + GL_CLAMP_TO_EDGE, +}; + +static const GLenum kGLES30TextureDimensionTable[kTexDimCount] = {0, -1/*GL_TEXTURE_1D*/, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP, 0}; + +static const GLint kMinFilterES2[kTexFilterCount] = { GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR }; + +// -------------------------------------------------------------------------- + +struct DeviceDepthStateGLES30 : public DeviceDepthState +{ + UInt32 depthFunc; +}; + +struct DeviceStencilStateGLES30 : public DeviceStencilState +{ + GLenum stencilFuncFront; + GLenum stencilFailOpFront; + GLenum depthFailOpFront; + GLenum depthPassOpFront; + GLenum stencilFuncBack; + GLenum stencilFailOpBack; + GLenum depthFailOpBack; + GLenum depthPassOpBack; +}; + + +typedef std::map< GfxBlendState, DeviceBlendState, memcmp_less<GfxBlendState> > CachedBlendStates; +typedef std::map< GfxDepthState, DeviceDepthStateGLES30, memcmp_less<GfxDepthState> > CachedDepthStates; +typedef std::map< GfxStencilState, DeviceStencilStateGLES30, memcmp_less<GfxStencilState> > CachedStencilStates; +typedef std::map< GfxRasterState, DeviceRasterState, memcmp_less<GfxRasterState> > CachedRasterStates; + +// -------------------------------------------------------------------------- +struct TextureUnitStateGLES3 +{ + GLuint texID; + TextureDimension texDim; + unsigned int combColor, combAlpha; + Vector4f color; + TexGenMode texGen; + Matrix4x4f textureMatrix; + float bias; + + // right let waste space here instead of device-level int + bool identityMatrix; + bool isProjected; + bool posForTexGen; + bool nrmForTexGen; + + void Invalidate(); + + static bool PositionRequiredForTexGen(TexGenMode mode) + { + return (mode == kTexGenObject || mode == kTexGenEyeLinear); + } + + static bool NormalRequiredForTexGen(TexGenMode mode) + { + return (mode == kTexGenSphereMap || mode == kTexGenCubeReflect || mode == kTexGenCubeNormal); + } + + void SetTexGen( TexGenMode mode ) + { + posForTexGen = PositionRequiredForTexGen(mode); + nrmForTexGen = NormalRequiredForTexGen(mode); + + texGen = mode; + } +}; + +void TextureUnitStateGLES3::Invalidate() +{ + texID = -1; + texDim = kTexDimNone; + combColor = combAlpha = 0xFFFFFFFF; + color.Set( -1, -1, -1, -1 ); + texGen = kTexGenUnknown; + posForTexGen = 0; + nrmForTexGen = 0; + textureMatrix.SetIdentity(); + identityMatrix = true; + isProjected = false; + bias = 1.0e6f; +} + + +// -------------------------------------------------------------------------- +// TODO: optimize this. Right now we just send off whole 8 float3 UVs with each +// immediate mode vertex. We could at least detect the number of them used from +// ImmediateTexCoord calls. +struct ImmediateVertexGLES30 { + Vector3f vertex; + Vector3f normal; + UInt32 color; + Vector3f texCoords[8]; +}; + +struct ImmediateModeGLES30 { + std::vector<ImmediateVertexGLES30> m_Vertices; + ImmediateVertexGLES30 m_Current; + GfxPrimitiveType m_Mode; + + DataBufferGLES30* m_IndexBufferQuads; + + ImmediateModeGLES30(); + ~ImmediateModeGLES30(); + void Invalidate(); +}; + +// -------------------------------------------------------------------------- +struct DeviceStateGLES30 +{ + int m_TextureIDGenerator; + + int depthFunc; + int depthWrite; // 0/1 or -1 + + int blending; + int srcBlend, destBlend, srcBlendAlpha, destBlendAlpha; // Blend modes + int blendOp, blendOpAlpha; + CompareFunction alphaTest; + float alphaValue; + + CullMode culling; + bool appBackfaceMode, userBackfaceMode; + NormalizationMode + normalization; + int scissor; + + bool lighting; + bool separateSpecular; + SimpleVec4 matDiffuse, matAmbient, matSpecular, matEmissive; + SimpleVec4 ambient; + float matShininess; + ColorMaterialMode + colorMaterial; + + float offsetFactor, offsetUnits; + + int colorWriteMask; // ColorWriteMask combinations + SimpleVec4 color; + + TextureUnitStateGLES3 + textures[kMaxSupportedTextureUnitsGLES]; + int textureCount; + int activeTextureUnit; + + // pure optimization: texGen is very special case and is used sparingly + UInt32 positionTexGen; + UInt32 normalTexGen; + + int vertexLightCount; + LightType vertexLightTypes[kMaxSupportedVertexLights]; + + TransformState transformState; + + ConstantBuffersGLES30 + m_CBs; + + DynamicVBO* m_DynamicVBO; + bool vboContainsColor; + + int viewport[4]; + int scissorRect[4]; + + + GpuProgram* activeProgram; + const GpuProgramParameters* activeProgramParams; + dynamic_array<UInt8> activeProgramParamsBuffer; + UInt32 activeProgramID; + + + CachedBlendStates m_CachedBlendStates; + CachedDepthStates m_CachedDepthStates; + CachedStencilStates m_CachedStencilStates; + CachedRasterStates m_CachedRasterStates; + + const DeviceBlendState* m_CurrBlendState; + const DeviceDepthStateGLES30* m_CurrDepthState; + const DeviceStencilStateGLES30* m_CurrStencilState; + int m_StencilRef; + const DeviceRasterState* m_CurrRasterState; + + MaterialPropertyBlock m_MaterialProperties; + ImmediateModeGLES30 m_Imm; + + // Framebuffer objects. + FramebufferObjectManagerGLES30* m_fboManager; + FramebufferObjectGLES30* m_activeFbo; //!< Currently bound FBO. + FramebufferObjectGLES30* m_defaultFbo; //!< Default render target FBO or null if using default framebuffer (0). + +public: + DeviceStateGLES30(); + void Invalidate(); + void ComputeFixedFunctionState(FixedFunctionStateGLES30& state, const GfxFogParams& fog) const; + + inline void ApplyTexGen( UInt32 unit ); + inline void DropTexGen( UInt32 unit ); +}; + +DeviceStateGLES30::DeviceStateGLES30() +: m_DynamicVBO(0) +, m_fboManager(0) +, m_activeFbo (0) +, m_defaultFbo(0) +{ + m_TextureIDGenerator = 0; +} + +void DeviceStateGLES30::Invalidate() +{ + DBG_LOG_GLES30("Invalidate"); + int i; + + depthFunc = -1; //unknown + depthWrite = -1; + + blending = -1; // unknown + srcBlend = destBlend = -1; // won't match any GL mode + blendOp = blendOpAlpha = -1; + alphaTest = kFuncUnknown; + alphaValue = -1.0f; + + culling = kCullUnknown; + normalization = kNormalizationUnknown; + scissor = -1; + + lighting = false; + separateSpecular = false; + + matDiffuse.set( -1, -1, -1, -1 ); + matAmbient.set( -1, -1, -1, -1 ); + matSpecular.set( -1, -1, -1, -1 ); + matEmissive.set( -1, -1, -1, -1 ); + ambient.set( -1, -1, -1, -1 ); + matShininess = -1.0f; + colorMaterial = kColorMatUnknown; + + offsetFactor = offsetUnits = -1000.0f; + + colorWriteMask = -1; // TBD ? + m_StencilRef = -1; + + color.set( -1, -1, -1, -1 ); + + activeTextureUnit = -1; + for( i = 0; i < kMaxSupportedTextureUnitsGLES; ++i ) + textures[i].Invalidate(); + textureCount = 0; + + positionTexGen = 0; + normalTexGen = 0; + + vertexLightCount = 0; + for ( i = 0; i < kMaxSupportedVertexLights; ++i) + vertexLightTypes[i] = kLightDirectional; + + // make sure backface mode is in sync + appBackfaceMode = false; + userBackfaceMode = false; + ApplyBackfaceMode( *this ); + + vboContainsColor = true; + + viewport[0] = 0; + viewport[1] = 0; + viewport[2] = 0; + viewport[3] = 0; + + scissorRect[0] = 0; + scissorRect[1] = 0; + scissorRect[2] = 0; + scissorRect[3] = 0; + + activeProgram = 0; + activeProgramParams = 0; + activeProgramParamsBuffer.resize_uninitialized(0); + activeProgramID = -1; + + m_Imm.Invalidate(); + + m_activeFbo = 0; + + InvalidateVertexInputCacheGLES30(); + + GLESAssert(); +} + +void DeviceStateGLES30::ComputeFixedFunctionState(FixedFunctionStateGLES30& state, const GfxFogParams& fog) const +{ + if (lighting) + { + int numLights = vertexLightCount; + bool onlyDir = true; + for(int i = 0 ; i < numLights ; ++i) + { + onlyDir = onlyDir && (vertexLightTypes[i] == kLightDirectional); + state.SetLightType(i,vertexLightTypes[i]); + } + + state.lightingEnabled = true; + state.lightCount = numLights; + state.onlyDirectionalLights = onlyDir; + state.specularEnabled = separateSpecular; + + switch (colorMaterial) + { + case kColorMatDisabled: + break; + + case kColorMatAmbientAndDiffuse: + state.useVertexColorAsAmbientAndDiffuse = true; + break; + + case kColorMatEmission: + state.useVertexColorAsEmission = true; + break; + + default: + ErrorString("Unsupported color material mode"); + break; + } + } + else + { + state.lightingEnabled = false; + state.lightCount = 0; + } + + state.useUniformInsteadOfVertexColor = !vboContainsColor; + state.texUnitCount = textureCount; + + for (int i = 0; i < textureCount; i++) + { + Assert(textures[i].texDim != kTexDimUnknown); + Assert(textures[i].texDim != kTexDimNone); + Assert(textures[i].texDim != kTexDimAny); + Assert(textures[i].texDim != kTexDim3D); // OpenGLES3.0 does NOT supports 3D textures + state.texUnitCube[i] = (textures[i].texDim == kTexDimCUBE); + state.texUnitColorCombiner[i] = textures[i].combColor, + state.texUnitAlphaCombiner[i] = textures[i].combAlpha; + state.texUnitGen[i] = textures[i].texGen; + + bool needMatrix = !textures[i].identityMatrix || textures[i].texGen > kTexGenDisabled; + state.SetTexUnitMatrixParam(i, needMatrix, textures[i].isProjected); + } + + state.fogMode = fog.mode; + switch (fog.mode) + { + case kFogUnknown: + case kFogDisabled: + state.fogMode = kFogDisabled; + default: + break; + } + + if(gGraphicsCaps.gles30.hasAlphaTestQCOM) + { + // we dont want to generate special shader if we have alpha-test done gl style + state.alphaTest = kFuncDisabled; + } + else + { + state.alphaTest = alphaTest; + switch (alphaTest) + { + case kFuncNever: + /* \todo Disable drawing. */ + break; + case kFuncUnknown: + case kFuncDisabled: + case kFuncAlways: + state.alphaTest = kFuncDisabled; + default: + break; + } + } +} + +inline void DeviceStateGLES30::ApplyTexGen( UInt32 unit ) +{ + const TextureUnitStateGLES3& state = textures[unit]; + + positionTexGen = state.posForTexGen ? positionTexGen | (1<<unit) + : positionTexGen & ~(1<<unit); + + normalTexGen = state.nrmForTexGen ? normalTexGen | (1<<unit) + : normalTexGen & ~(1<<unit); +} + +inline void DeviceStateGLES30::DropTexGen( UInt32 unit ) +{ + positionTexGen &= ~(1<<unit); + normalTexGen &= ~(1<<unit); +} + + +#include "GfxDeviceGLES30.h" +#include "Runtime/GfxDevice/GLESCommon.h" + +void GfxDeviceGLES30_MarkWorldViewProjDirty() +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + GetGLES30DeviceState(device).transformState.dirtyFlags |= TransformState::kWorldViewProjDirty; +} + +void GfxDeviceGLES30_DisableDepthTest() +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + GetGLES30DeviceState(device).depthFunc = GL_NEVER; + GLES_CHK(glDisable(GL_DEPTH_TEST)); +} + +void GraphicsCaps::InitGLES30() +{ + // \todo [2013-04-16 pyry] Requires some serious cleanaup: + // - This functions shouldn't be member of GraphicsCaps (why it is?) + // - query extensions once, split to set and check from there + // - nicer wrapper for int caps queries + + GLES_InitCommonCaps(this); + gGles3ExtFunc.InitExtFunc(); + + shaderCaps = kShaderLevel3; + + maxLights = kMaxSupportedVertexLightsByGLES30; // vertex light count + hasAnisoFilter = QueryExtension("GL_EXT_texture_filter_anisotropic"); // has anisotropic filtering? + if (hasAnisoFilter) + GLES_CHK(glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, (GLint *)&maxAnisoLevel)); + else + maxAnisoLevel = 1; + + maxTexImageUnits = 8; + GLES_CHK(glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTexImageUnits)); + maxTexImageUnits = std::max<int>(std::min<int>( maxTexImageUnits, kMaxSupportedTextureUnitsGLES ), 1); + + maxTexUnits = maxTexImageUnits; + maxTexCoords = maxTexImageUnits; + maxMRTs = std::min<int>(FramebufferAttachmentsGLES30::kMaxColorAttachments, queryInt(GL_MAX_COLOR_ATTACHMENTS)); + + GLES_CHK(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize)); + GLES_CHK(glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &maxCubeMapSize)); + GLES_CHK(glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxRenderTextureSize)); + + hasMipLevelBias = true; + hasMipMaxLevel = true; + + hasMultiSampleAutoResolve = false; // ES3 requires explicit glBlitFramebuffer() to do resolve. This affects how RenderTexture behaves. + hasMultiSample = true; + + hasBlendSquare = true; + hasSeparateAlphaBlend = true; + hasBlendSub = true; + hasBlendMinMax = true; + + hasS3TCCompression = false; + + hasAutoMipMapGeneration = false; // \todo [2013-04-16 pyry] glGenMipmap() does exist + + has3DTexture = false; // \todo [2013-04-16 pyry] Expose 3D textures + + npot = kNPOTFull; + npotRT = npot; + + hasRenderToTexture = true; + hasShadowCollectorPass = false; + + hasHighPrecisionTextureCombiners = false; // \todo [2013-04-16 pyry] Yep. We can use highp (fp32) in FS. Should be enough. + + hasRenderToCubemap = true; + + // \note supportsTextureFormat[N < kTexFormatPCCount] = true + + supportsTextureFormat[kTexFormatBGRA32] = QueryExtension("GL_APPLE_texture_format_BGRA8888"); + supportsTextureFormat[kTexFormatDXT1] = QueryExtension("GL_EXT_texture_compression_s3tc") || QueryExtension("GL_EXT_texture_compression_dxt1"); + supportsTextureFormat[kTexFormatDXT3] = QueryExtension("GL_EXT_texture_compression_s3tc") || QueryExtension("GL_CHROMIUM_texture_compression_dxt3"); + supportsTextureFormat[kTexFormatDXT5] = QueryExtension("GL_EXT_texture_compression_s3tc") || QueryExtension("GL_CHROMIUM_texture_compression_dxt5"); + supportsTextureFormat[kTexFormatPVRTC_RGB2] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatPVRTC_RGBA2] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatPVRTC_RGB4] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatPVRTC_RGBA4] = QueryExtension("GL_IMG_texture_compression_pvrtc"); + supportsTextureFormat[kTexFormatATC_RGB4] = QueryExtension("GL_AMD_compressed_ATC_texture") || QueryExtension("GL_ATI_texture_compression_atitc"); + supportsTextureFormat[kTexFormatATC_RGBA8] = QueryExtension("GL_AMD_compressed_ATC_texture") || QueryExtension("GL_ATI_texture_compression_atitc"); + + supportsTextureFormat[kTexFormatETC_RGB4] = true; // \note Mapped to ETC2. + supportsTextureFormat[kTexFormatEAC_R] = true; + supportsTextureFormat[kTexFormatEAC_R_SIGNED] = true; + supportsTextureFormat[kTexFormatEAC_RG] = true; + supportsTextureFormat[kTexFormatEAC_RG_SIGNED] = true; + supportsTextureFormat[kTexFormatETC2_RGB] = true; + supportsTextureFormat[kTexFormatETC2_RGBA1] = true; + supportsTextureFormat[kTexFormatETC2_RGBA8] = true; + + const bool supportsASTC = QueryExtension("GL_KHR_texture_compression_astc_ldr"); + for(int loop = kTexFormatASTC_RGB_4x4; loop <= kTexFormatASTC_RGBA_12x12; loop++) + supportsTextureFormat[loop] = supportsASTC; + + // \todo [2013-04-16 pyry] Support means nothing until we can expose these to shaders as well. + // It requires changes to shader translator. + supportsRenderTextureFormat[kRTFormatARGB32] = true; + supportsRenderTextureFormat[kRTFormatDepth] = true; + supportsRenderTextureFormat[kRTFormatShadowMap] = true; + supportsRenderTextureFormat[kRTFormatRGB565] = true; + supportsRenderTextureFormat[kRTFormatARGB4444] = true; + supportsRenderTextureFormat[kRTFormatARGB1555] = true; + supportsRenderTextureFormat[kRTFormatDefault] = true; + supportsRenderTextureFormat[kRTFormatA2R10G10B10] = true; + supportsRenderTextureFormat[kRTFormatARGB64] = false; + supportsRenderTextureFormat[kRTFormatR8] = true; + supportsRenderTextureFormat[kRTFormatARGBInt] = true; + supportsRenderTextureFormat[kRTFormatRGInt] = true; + supportsRenderTextureFormat[kRTFormatRInt] = true; + + if (QueryExtension("GL_EXT_color_buffer_float")) + { + // Support for fp render targets was stripped from spec as last minute decision. Sigh.. + supportsRenderTextureFormat[kRTFormatARGBHalf] = true; + supportsRenderTextureFormat[kRTFormatRGHalf] = true; + supportsRenderTextureFormat[kRTFormatRHalf] = true; + + supportsRenderTextureFormat[kRTFormatARGBFloat] = true; + supportsRenderTextureFormat[kRTFormatRGFloat] = true; + supportsRenderTextureFormat[kRTFormatRFloat] = true; + + supportsRenderTextureFormat[kRTFormatDefaultHDR] = true; // ES3 backend uses R11F_G11F_B10F as default HDR format + } + + const bool isPvrGpu = (rendererString.find("PowerVR") != string::npos); + const bool isMaliGpu = (rendererString.find("Mali") != string::npos); + const bool isAdrenoGpu = (rendererString.find("Adreno") != string::npos); + const bool isTegraGpu = (rendererString.find("Tegra") != string::npos); + + hasNativeDepthTexture = true; + hasNativeShadowMap = true; + + hasRenderTargetStencil = true; + hasTwoSidedStencil = true; + hasStencilInDepthTexture = true; + hasStencil = true; + + has16BitFloatVertex = true; + needsToSwizzleVertexColors = false; + + hasSRGBReadWrite = false; // \todo [2013-06-05 pyry] Doesn't function properly + + disableSoftShadows = false; + buggyCameraRenderToCubemap = false; + + hasShadowCollectorPass = false; + + // Timer queries + gGraphicsCaps.hasTimerQuery = QueryExtension("GL_NV_timer_query"); + + // GLES3-specific variables. + gles30.maxAttributes = std::min<int>(kGLES3MaxVertexAttribs, queryInt(GL_MAX_VERTEX_ATTRIBS)); + gles30.maxVaryings = queryInt(GL_MAX_VARYING_VECTORS); + gles30.maxSamples = queryInt(GL_MAX_SAMPLES); + + hasTiledGPU = isPvrGpu || isAdrenoGpu || isMaliGpu; + + const bool isAdreno330 = (rendererString.find("Adreno (TM) 330") != string::npos); // MSM8974 dev device, with rather unstable drivers. + const bool isMali628 = (rendererString.find("Mali-T628") != string::npos); // ARM TG4 dev device, mapbuffer broken. + const bool isGLESEmu = (rendererString.find("Mali OpenGL ES Emulator") != string::npos); // ARM OpenGL ES 3.0 emulator, glGetProgramBinary broken + + gles30.useMapBuffer = true; + if(isAdrenoGpu || !isAdreno330) + gles30.useMapBuffer = false; // Buffer mapping is dead-slow on Adreno, but using BufferData() is broken on Adreno 330 + + if(isMali628) + gles30.useMapBuffer = false; // Mapbuffer broken on TG4 + + gles30.useProgramBinary = true; // Set true first, check actual support in Init call below. + gles30.useProgramBinary = GlslGpuProgramGLES30::InitBinaryShadersSupport(); + + + gles30.useTFSkinning = true; // TF skinning used to be broken on adreno, worked around now. + + + // \todo [2013-04-17 pyry] Extension queries. + + // \todo [2013-04-16 pyry] Figure out which gles20 flags make sense for ES3 as well. + + // \todo [2013-04-16 pyry] Why init timer queries here? +#if ENABLE_PROFILER + g_TimerQueriesGLES30.Init(); +#endif +} + +GfxDevice* CreateGLES30GfxDevice() +{ +#if UNITY_WIN || UNITY_LINUX || UNITY_BB10 || UNITY_ANDROID + InitializeGLES30(); +#endif + + gGraphicsCaps.InitGLES30(); + +#if UNITY_EDITOR + return NULL; +#else + return UNITY_NEW_AS_ROOT(GFX_GL_IMPL(), kMemGfxDevice, "GLES30GfxDevice",""); +#endif +} + +GFX_GL_IMPL::GFX_GL_IMPL() +{ + printf_console("Creating OpenGL ES 3.0 graphics device\n"); + #if !GFX_DEVICE_VIRTUAL + impl = new GfxDeviceImpl(); + #endif + + OnCreate(); + InvalidateState(); + m_Renderer = kGfxRendererOpenGLES30; + m_IsThreadable = true; + + m_UsesOpenGLTextureCoords = true; + m_UsesHalfTexelOffset = false; + + STATE.m_CurrBlendState = NULL; + STATE.m_CurrDepthState = NULL; + STATE.m_CurrStencilState = NULL; + STATE.m_CurrRasterState = NULL; + + extern RenderSurfaceBase* CreateBackBufferColorSurfaceGLES3(); + SetBackBufferColorSurface(CreateBackBufferColorSurfaceGLES3()); + + extern RenderSurfaceBase* CreateBackBufferDepthSurfaceGLES3(); + SetBackBufferDepthSurface(CreateBackBufferDepthSurfaceGLES3()); +} + +GFX_GL_IMPL::~GFX_GL_IMPL() +{ + TransformFeedbackSkinningInfo::CleanupTransformFeedbackShaders(); + ClearFixedFunctionPrograms(); + STATE.m_CBs.Clear(); + delete STATE.m_DynamicVBO; + delete STATE.m_fboManager; + + #if !GFX_DEVICE_VIRTUAL + delete impl; + #endif +#if UNITY_WIN || UNITY_ANDROID + ShutdownGLES30(); +#endif +} + +static void ActivateTextureUnitGLES3 (DeviceStateGLES30& state, int unit) +{ + if (state.activeTextureUnit == unit) + return; + GLES_CHK(glActiveTexture(GL_TEXTURE0 + unit)); + state.activeTextureUnit = unit; +} + +void GFX_GL_IMPL::InvalidateState() +{ + DBG_LOG_GLES30("InvalidateState"); + m_FogParams.Invalidate(); + STATE.transformState.Invalidate(m_BuiltinParamValues); + STATE.Invalidate(); + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatEmission, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatAmbient, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatDiffuse, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatSpecular, Vector4f(1,1,1,1)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatShininess, Vector4f(1,1,1,1)); + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogColor, Vector4f(0,0,0,0)); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogParams, Vector4f(0,0,0,0)); + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFAlphaTestRef, Vector4f(0,0,0,0)); + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFColor, Vector4f(1,1,1,1)); + for (int i = 0; i < kMaxSupportedTextureUnitsGLES; i++) + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecFFTextureEnvColor0+i), Vector4f(0,0,0,0)); +} + +DeviceBlendState* GFX_GL_IMPL::CreateBlendState(const GfxBlendState& state) +{ + std::pair<CachedBlendStates::iterator, bool> result = STATE.m_CachedBlendStates.insert(std::make_pair(state, DeviceBlendState())); + if (!result.second) + return &result.first->second; + + DeviceBlendState& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(glstate.sourceState)); + DebugAssertIf(kFuncUnknown==state.alphaTest); + + return &result.first->second; +} + +DeviceDepthState* GFX_GL_IMPL::CreateDepthState(const GfxDepthState& state) +{ + std::pair<CachedDepthStates::iterator, bool> result = STATE.m_CachedDepthStates.insert(std::make_pair(state, DeviceDepthStateGLES30())); + if (!result.second) + return &result.first->second; + + DeviceDepthStateGLES30& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(glstate.sourceState)); + glstate.depthFunc = kCmpFuncES2[state.depthFunc]; + return &result.first->second; +} + +DeviceStencilState* GFX_GL_IMPL::CreateStencilState(const GfxStencilState& state) +{ + std::pair<CachedStencilStates::iterator, bool> result = STATE.m_CachedStencilStates.insert(std::make_pair(state, DeviceStencilStateGLES30())); + if (!result.second) + return &result.first->second; + + DeviceStencilStateGLES30& st = result.first->second; + memcpy (&st.sourceState, &state, sizeof(st.sourceState)); + st.stencilFuncFront = kCmpFuncES2[state.stencilFuncFront]; + st.stencilFailOpFront = kStencilOpES2[state.stencilFailOpFront]; + st.depthFailOpFront = kStencilOpES2[state.stencilZFailOpFront]; + st.depthPassOpFront = kStencilOpES2[state.stencilPassOpFront]; + st.stencilFuncBack = kCmpFuncES2[state.stencilFuncBack]; + st.stencilFailOpBack = kStencilOpES2[state.stencilFailOpBack]; + st.depthFailOpBack = kStencilOpES2[state.stencilZFailOpBack]; + st.depthPassOpBack = kStencilOpES2[state.stencilPassOpBack]; + return &result.first->second; +} + +DeviceRasterState* GFX_GL_IMPL::CreateRasterState(const GfxRasterState& state) +{ + std::pair<CachedRasterStates::iterator, bool> result = STATE.m_CachedRasterStates.insert(std::make_pair(state, DeviceRasterState())); + if (!result.second) + return &result.first->second; + + DeviceRasterState& glstate = result.first->second; + memcpy(&glstate.sourceState, &state, sizeof(glstate.sourceState)); + + return &result.first->second; +} + +void GFX_GL_IMPL::SetBlendState(const DeviceBlendState* state, float alphaRef) +{ + DeviceBlendState* devstate = (DeviceBlendState*)state; + + if (STATE.m_CurrBlendState == devstate && alphaRef == STATE.alphaValue) + return; + + STATE.m_CurrBlendState = devstate; + if (!STATE.m_CurrBlendState) + return; + + const GfxBlendState& desc = state->sourceState; + const GLenum glsrc = kBlendModeES2[desc.srcBlend]; + const GLenum gldst = kBlendModeES2[desc.dstBlend]; + const GLenum glsrca = kBlendModeES2[desc.srcBlendAlpha]; + const GLenum gldsta = kBlendModeES2[desc.dstBlendAlpha]; + const GLenum glfunc = kBlendFuncES2[desc.blendOp]; + const GLenum glfunca = kBlendFuncES2[desc.blendOpAlpha]; + const bool blendDisabled = (glsrc == GL_ONE && gldst == GL_ZERO && glsrca == GL_ONE && gldsta == GL_ZERO); + + int mask = devstate->sourceState.renderTargetWriteMask; + if (STATE.m_activeFbo && STATE.m_activeFbo->GetNumColorAttachments() == 0) + mask = 0; + + if( mask != STATE.colorWriteMask ) + { + GLES_CHK(glColorMask( (mask & kColorWriteR) != 0, (mask & kColorWriteG) != 0, (mask & kColorWriteB) != 0, (mask & kColorWriteA) != 0 )); + STATE.colorWriteMask = mask; + } + + if( blendDisabled ) + { + if( STATE.blending != 0 ) + { + GLES_CHK(glDisable (GL_BLEND)); + STATE.blending = 0; + } + } + else + { + if( glsrc != STATE.srcBlend || gldst != STATE.destBlend || glsrca != STATE.srcBlendAlpha || gldsta != STATE.destBlendAlpha ) + { + GLES_CHK(glBlendFuncSeparate(glsrc, gldst, glsrca, gldsta)); + STATE.srcBlend = glsrc; + STATE.destBlend = gldst; + STATE.srcBlendAlpha = glsrca; + STATE.destBlendAlpha = gldsta; + } + if (glfunc != STATE.blendOp || glfunca != STATE.blendOpAlpha) + { + GLES_CHK(glBlendEquationSeparate(glfunc, glfunca)); + STATE.blendOp = glfunc; + STATE.blendOpAlpha = glfunca; + } + if( STATE.blending != 1 ) + { + GLES_CHK(glEnable( GL_BLEND )); + STATE.blending = 1; + } + } + // fragment shader is expected to implement per fragment culling + CompareFunction alphaTest = devstate->sourceState.alphaTest; + + // \todo [2013-04-16 pyry] Alpha testing should be moved to shaders + + if (gGraphicsCaps.gles30.hasAlphaTestQCOM && (alphaTest != STATE.alphaTest || alphaRef != STATE.alphaValue)) + { + if (alphaTest != kFuncDisabled) + { + GLES_CHK(gGles3ExtFunc.glAlphaFuncQCOM(kCmpFuncES2[alphaTest], alphaRef)); + GLES_CHK(glEnable(GL_ALPHA_TEST_QCOM)); + } + else + { + GLES_CHK(glDisable(GL_ALPHA_TEST_QCOM)); + } + } + + STATE.alphaTest = alphaTest; + STATE.alphaValue = alphaRef; +} + +void GFX_GL_IMPL::SetRasterState(const DeviceRasterState* state) +{ + DeviceRasterState* devstate = (DeviceRasterState*)state; + if(!devstate) + { + STATE.m_CurrRasterState = NULL; + return; + } + + STATE.m_CurrRasterState = devstate; + + CullMode cull = devstate->sourceState.cullMode; + if( cull != STATE.culling ) + { + switch (cull) { + case kCullOff: + GLES_CHK(glDisable (GL_CULL_FACE)); + break; + case kCullFront: + GLES_CHK(glCullFace (GL_FRONT)); + GLES_CHK(glEnable (GL_CULL_FACE)); + break; + case kCullBack: + GLES_CHK(glCullFace (GL_BACK)); + GLES_CHK(glEnable (GL_CULL_FACE)); + break; + default: + break; + } + STATE.culling = cull; + } + + float zFactor = devstate->sourceState.slopeScaledDepthBias; + float zUnits = devstate->sourceState.depthBias; + if( zFactor != STATE.offsetFactor || zUnits != STATE.offsetUnits ) + { + +#if WORKAROUND_POLYGON_OFFSET + // on some androids polygon offset work the other way (positive push to viewer) + // so we tweak projection matrix to do offset + // also use available depth precision better (on Adreno for example fix bugs with z-fighting) + // Game Programming Gems Vol1 + // Eric Lengyel's "Tweaking a Vertex's Projected Depth Value" + // we use simplified formula: just smallest possible eps directly (multiplied by zUnits) + // we calculate eps for 16bit depth (good enough for larger depth) + // in projection matrix [2,2] = (f+n)/(n-f) + // so eps would be BitsMult * -1/proj[2,2] + + static const float _BitsMult = -1.0f / (float)0xFFFF; // FFFF = 2^16-1, minus sign incorporated here + + float* matrixElem = &m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj).Get(2,2); + + const float eps = _BitsMult / *matrixElem; + *matrixElem *= (1.0f + zUnits*eps); +#else + GLES_CHK(glPolygonOffset( zFactor, zUnits )); + if( zFactor || zUnits ) + GLES_CHK(glEnable (GL_POLYGON_OFFSET_FILL)); + else + GLES_CHK(glDisable (GL_POLYGON_OFFSET_FILL)); +#endif + STATE.offsetFactor = zFactor; + STATE.offsetUnits = zUnits; + } +} + + +void GFX_GL_IMPL::SetDepthState(const DeviceDepthState* state) +{ + DeviceDepthStateGLES30* devstate = (DeviceDepthStateGLES30*)state; + if (STATE.m_CurrDepthState == devstate) + return; + + STATE.m_CurrDepthState = devstate; + + if (!STATE.m_CurrDepthState) + return; + + const int depthFunc = devstate->depthFunc; + if( depthFunc != STATE.depthFunc ) + { + if( depthFunc != GL_NEVER ) { + GLES_CHK(glDepthFunc (depthFunc)); + GLES_CHK(glEnable (GL_DEPTH_TEST)); + } else { + GLES_CHK(glDisable (GL_DEPTH_TEST)); + } + + STATE.depthFunc = depthFunc; + } + + const int writeMode = devstate->sourceState.depthWrite ? GL_TRUE : GL_FALSE; + if( writeMode != STATE.depthWrite ) + { + GLES_CHK(glDepthMask (writeMode)); + STATE.depthWrite = writeMode; + } +} + +void GFX_GL_IMPL::SetStencilState (const DeviceStencilState* state, int stencilRef) +{ + if (STATE.m_CurrStencilState == state && STATE.m_StencilRef == stencilRef) + return; + const DeviceStencilStateGLES30* st = static_cast<const DeviceStencilStateGLES30*>(state); + STATE.m_CurrStencilState = st; + if (!st) + return; + + if (st->sourceState.stencilEnable) + GLES_CHK(glEnable (GL_STENCIL_TEST)); + else + GLES_CHK(glDisable (GL_STENCIL_TEST)); + if (gGraphicsCaps.hasTwoSidedStencil) + { + GLES_CHK(glStencilFuncSeparate (GL_FRONT, st->stencilFuncFront, stencilRef, st->sourceState.readMask)); + GLES_CHK(glStencilOpSeparate (GL_FRONT, st->stencilFailOpFront, st->depthFailOpFront, st->depthPassOpFront)); + GLES_CHK(glStencilFuncSeparate (GL_BACK, st->stencilFuncBack, stencilRef, st->sourceState.readMask)); + GLES_CHK(glStencilOpSeparate (GL_BACK, st->stencilFailOpBack, st->depthFailOpBack, st->depthPassOpBack)); + } + else + { + GLES_CHK(glStencilFunc (st->stencilFuncFront, stencilRef, st->sourceState.readMask)); + GLES_CHK(glStencilOp (st->stencilFailOpFront, st->depthFailOpFront, st->depthPassOpFront)); + } + GLES_CHK(glStencilMask (st->sourceState.writeMask)); + + STATE.m_StencilRef = stencilRef; +} + +void GFX_GL_IMPL::SetSRGBWrite (bool enable) +{ + // \todo [2013-04-16 pyry] Implement sRGB support: + // - In ES3 sRGB bit is tied to format and there is no way to create views with different format + // - This is used rather liberally from Camera + // -> Use sRGB FBO for emulation, and defer necessary blits until it is known whether they are needed + Assert("Not implemented"); +} + +bool GFX_GL_IMPL::GetSRGBWrite () +{ + return false; +} + +void GFX_GL_IMPL::Clear (UInt32 clearFlags, const float color[4], float depth, int stencil) +{ + DBG_LOG_GLES30("Clear(%d, (%.2f, %.2f, %.2f, %.2f), %.2f, %d", clearFlags, color[0], color[1], color[2], color[3], depth, stencil); + + // \todo [2013-04-16 pyry] Integer render targets require use of glClearBuffer() + // \todo [2013-04-29 pyry] Here was a call that restored FBO binding to default one. Why? + + if (STATE.m_activeFbo && STATE.m_activeFbo->GetNumColorAttachments() == 0) + clearFlags &= ~kGfxClearColor; + + // In OpenGL, clears are affected by color write mask and depth writing parameters. + // So make sure to set them! + GLbitfield flags = 0; + if (clearFlags & kGfxClearColor) + { + if (STATE.colorWriteMask != 15) + { + GLES_CHK(glColorMask( true, true, true, true )); + STATE.colorWriteMask = 15; + STATE.m_CurrBlendState = NULL; + } + flags |= GL_COLOR_BUFFER_BIT; + GLES_CHK(glClearColor( color[0], color[1], color[2], color[3] )); + } + if (clearFlags & kGfxClearDepth) + { + GLES_CHK(glDepthMask (GL_TRUE)); + STATE.depthWrite = GL_TRUE; + STATE.m_CurrDepthState = NULL; + flags |= GL_DEPTH_BUFFER_BIT; + GLES_CHK(glClearDepthf( depth )); + } + if (clearFlags & kGfxClearStencil) + { + //@TODO: need to set stencil writes on? + flags |= GL_STENCIL_BUFFER_BIT; + GLES_CHK(glClearStencil (stencil)); + } + GLES_CHK(glClear(flags)); +} + +static void ApplyBackfaceMode( const DeviceStateGLES30& state ) +{ + DBG_LOG_GLES30("ApplyBackfaceMode"); + if (state.appBackfaceMode != state.userBackfaceMode) + GLES_CHK(glFrontFace( GL_CCW )); + else + GLES_CHK(glFrontFace( GL_CW )); +} + +void GFX_GL_IMPL::SetUserBackfaceMode( bool enable ) +{ + DBG_LOG_GLES30("SetUserBackfaceMode(%s)", GetBoolString(enable)); + if( STATE.userBackfaceMode == enable ) + return; + + STATE.userBackfaceMode = enable; + ApplyBackfaceMode( STATE ); +} + +void GFX_GL_IMPL::SetInvertProjectionMatrix( bool enable ) +{ + Assert (!enable); // projection should never be flipped upside down on OpenGL +} + +bool GFX_GL_IMPL::GetInvertProjectionMatrix() const +{ + return false; +} + +void GFX_GL_IMPL::SetProjectionMatrix (const Matrix4x4f& matrix) +{ + DBG_LOG_GLES30("SetProjectionMatrix(...)"); + + CopyMatrix(matrix.GetPtr(), STATE.transformState.projectionMatrixOriginal.GetPtr()); + CopyMatrix (matrix.GetPtr(), m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj).GetPtr()); + STATE.transformState.dirtyFlags |= TransformState::kProjDirty; +} + +void GFX_GL_IMPL::SetWorldMatrix( const float matrix[16] ) +{ + CopyMatrix( matrix, STATE.transformState.worldMatrix.GetPtr() ); + STATE.transformState.dirtyFlags |= TransformState::kWorldDirty; +} + +void GFX_GL_IMPL::SetViewMatrix( const float matrix[16] ) +{ + STATE.transformState.SetViewMatrix (matrix, m_BuiltinParamValues); +} + +void GFX_GL_IMPL::GetMatrix( float outMatrix[16] ) const +{ + STATE.transformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + CopyMatrix (STATE.transformState.worldViewMatrix.GetPtr(), outMatrix); +} + +const float* GFX_GL_IMPL::GetWorldMatrix() const +{ + return STATE.transformState.worldMatrix.GetPtr(); +} + +const float* GFX_GL_IMPL::GetViewMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatView).GetPtr(); +} + +const float* GFX_GL_IMPL::GetProjectionMatrix() const +{ + return STATE.transformState.projectionMatrixOriginal.GetPtr(); +} + +const float* GFX_GL_IMPL::GetDeviceProjectionMatrix() const +{ + return GetProjectionMatrix(); +} + +void GFX_GL_IMPL::SetNormalizationBackface( NormalizationMode mode, bool backface ) +{ + DBG_LOG_GLES30("SetNormalizationBackface(%d %s)", mode, backface?"back":"front"); + STATE.normalization = mode; + if( STATE.appBackfaceMode != backface ) + { + STATE.appBackfaceMode = backface; + ApplyBackfaceMode( STATE ); + } +} + +void GFX_GL_IMPL::SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) +{ + DBG_LOG_GLES30("SetFFLighting(%s, %s, %d)", on?"True":"False", separateSpecular?"True":"False", colorMaterial); + STATE.lighting = on; + STATE.separateSpecular = separateSpecular; + STATE.colorMaterial = colorMaterial; +} + +void GFX_GL_IMPL::SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) +{ + DBG_LOG_GLES30("SetMaterial()"); + STATE.matAmbient.set (ambient[0], ambient[1], ambient[2], 1.0F); + STATE.matDiffuse.set (diffuse); + STATE.matSpecular.set (specular[0], specular[1], specular[2], 1.0F); + STATE.matEmissive.set (emissive[0], emissive[1], emissive[2], 1.0F); + float glshine = std::max<float>(std::min<float>(shininess,1.0f), 0.0f) * 128.0f; + STATE.matShininess = glshine; +} + +void GFX_GL_IMPL::SetColor( const float color[4] ) +{ + DBG_LOG_GLES30("SetColor()"); + STATE.color.set( color ); + // Emulate OpenGL's behaviour + ImmediateColor( color[0], color[1], color[2], color[3] ); +} + +void GFX_GL_IMPL::SetViewport( int x, int y, int width, int height ) +{ + DBG_LOG_GLES30("SetViewport(%d, %d, %d, %d)", x, y, width, height); + STATE.viewport[0] = x; + STATE.viewport[1] = y; + STATE.viewport[2] = width; + STATE.viewport[3] = height; + GLES_CHK(glViewport( x, y, width, height )); +} + +void GFX_GL_IMPL::GetViewport( int* port ) const +{ + DBG_LOG_GLES30("GetViewport()"); + port[0] = STATE.viewport[0]; + port[1] = STATE.viewport[1]; + port[2] = STATE.viewport[2]; + port[3] = STATE.viewport[3]; +} + +void GFX_GL_IMPL::SetScissorRect( int x, int y, int width, int height ) +{ + DBG_LOG_GLES30("SetScissorRect(%d, %d, %d, %d)", x, y, width, height); + + if (STATE.scissor != 1) + { + GLES_CHK(glEnable( GL_SCISSOR_TEST )); + STATE.scissor = 1; + } + + STATE.scissorRect[0] = x; + STATE.scissorRect[1] = y; + STATE.scissorRect[2] = width; + STATE.scissorRect[3] = height; + GLES_CHK(glScissor( x, y, width, height )); + +} + +void GFX_GL_IMPL::DisableScissor() +{ + DBG_LOG_GLES30("DisableScissor()"); + if (STATE.scissor != 0) + { + GLES_CHK(glDisable( GL_SCISSOR_TEST )); + STATE.scissor = 0; + } +} + +bool GFX_GL_IMPL::IsScissorEnabled() const +{ + DBG_LOG_GLES30("IsScissorEnabled():returns %s", STATE.scissor == 1?"True":"False"); + return STATE.scissor == 1; +} + +void GFX_GL_IMPL::GetScissorRect( int scissor[4] ) const +{ + DBG_LOG_GLES30("GetScissorRect()"); + scissor[0] = STATE.scissorRect[0]; + scissor[1] = STATE.scissorRect[1]; + scissor[2] = STATE.scissorRect[2]; + scissor[3] = STATE.scissorRect[3]; +} +bool GFX_GL_IMPL::IsCombineModeSupported( unsigned int combiner ) +{ + return true; +} + +TextureCombinersHandle GFX_GL_IMPL::CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) +{ + DBG_LOG_GLES30("CreateTextureCombiners()"); + TextureCombinersGLES3* implGLES = TextureCombinersGLES3::Create (count, texEnvs); + return TextureCombinersHandle (implGLES); +} + +void GFX_GL_IMPL::DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ) +{ + DBG_LOG_GLES30("DeleteTextureCombiners()"); + TextureCombinersGLES3* implGLES = OBJECT_FROM_HANDLE(textureCombiners, TextureCombinersGLES3); + delete implGLES; + textureCombiners.Reset(); +} + +void GFX_GL_IMPL::SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ) +{ + DBG_LOG_GLES30("SetTextureCombiners()"); + TextureCombinersGLES3* implGLES = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersGLES3); + Assert (implGLES); + + const int count = std::min(gGraphicsCaps.maxTexUnits, implGLES->count); + // Fill in arrays + TexEnvData* texEnvData; + ALLOC_TEMP (texEnvData, TexEnvData, count); + for( int i = 0; i < count; ++i ) + { + ShaderLab::TexEnv *te = ShaderLab::GetTexEnvForBinding( implGLES->texEnvs[i], props ); + Assert( te != NULL ); + te->PrepareData (implGLES->texEnvs[i].m_TextureName.index, implGLES->texEnvs[i].m_MatrixName, props, &texEnvData[i]); + } + + Vector4f* texColors; + ALLOC_TEMP (texColors, Vector4f, implGLES->count); + for( int i = 0; i < implGLES->count; ++i ) + { + const ShaderLab::TextureBinding& binding = implGLES->texEnvs[i]; + texColors[i] = binding.GetTexColor().Get (props); + } + GFX_GL_IMPL::SetTextureCombinersThreadable(textureCombiners, texEnvData, texColors); + +} + + +void GFX_GL_IMPL::SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ) +{ + DBG_LOG_GLES30("SetTextureCombiners()"); + TextureCombinersGLES3* implGLES = OBJECT_FROM_HANDLE(textureCombiners,TextureCombinersGLES3); + Assert (implGLES); + + const int count = std::min(gGraphicsCaps.maxTexUnits, implGLES->count); + STATE.textureCount = count; + for (int i = 0; i < count; ++i) + { + const ShaderLab::TextureBinding& binding = implGLES->texEnvs[i]; + + // set the texture + ApplyTexEnvData (i, i, texEnvData[i]); + + // setup texture unit state + TextureUnitStateGLES3& texUnitState = STATE.textures[i]; + texUnitState.color = texColors[i]; + texUnitState.combColor = binding.m_CombColor; + texUnitState.combAlpha = binding.m_CombAlpha; + } + // we can just create mask and "and" with it + // but consider me lazy + for( int i = count ; i < gGraphicsCaps.maxTexUnits ; ++i) + STATE.DropTexGen(i); + + STATE.activeProgram = 0; + + // Get us back to TU 0, so we know where we stand + ActivateTextureUnitGLES3 (STATE, 0); + +} + +void GFX_GL_IMPL::SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) +{ + DBG_LOG_GLES30("SetTexture(%d %d)", unit, texture.m_ID); + DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits ); + + GLenum texType = kGLES30TextureDimensionTable[dim]; + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(texture); + + if (texType == (GLenum)-1) + { + Assert("Not supported"); + return; + } + + // \todo [2013-04-16 pyry] Shouldn't we clear state still? + if (targetTex == 0) + return; + + TextureUnitStateGLES3& currTex = STATE.textures[unit]; + if (STATE.textureCount > unit && targetTex == currTex.texID) + return; // Already bound. + + ActivateTextureUnitGLES3 (STATE, unit); + + GLES_CHK(glBindTexture(texType, targetTex)); + + if (STATE.textureCount <= unit) + STATE.textureCount = unit+1; + currTex.texID = targetTex; + currTex.texDim = dim; + if (currTex.texGen == kTexGenUnknown) + currTex.texGen = kTexGenDisabled; + + STATE.ApplyTexGen(unit); + + GLESAssert(); + + // \todo [2013-04-16 pyry] Lod bias is given from shader. + if (bias != std::numeric_limits<float>::infinity()) + currTex.bias = bias; +} + +void GFX_GL_IMPL::SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]) +{ + DBG_LOG_GLES30("SetTextureTransform()"); + DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits ); + TextureUnitStateGLES3& unitState = STATE.textures[unit]; + + unitState.SetTexGen(texGen); + unitState.textureMatrix = *(Matrix4x4f const*)matrix; + + // Since we will set texture matrix even if TexGen is disabled (since matrix can contain scale/offset information) + // we set textureMatrix to identity to be on a safe side + if (identity) + unitState.textureMatrix.SetIdentity(); + unitState.identityMatrix = identity; + + unitState.isProjected = false; + if (!identity && dim==kTexDim2D) + unitState.isProjected = (matrix[3] != 0.0f || matrix[7] != 0.0f || matrix[11] != 0.0f || matrix[15] != 1.0f); + + STATE.ApplyTexGen(unit); +} + +void GFX_GL_IMPL::SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + DBG_LOG_GLES30("SetTextureParams()"); + + TextureIdMapGLES30_QueryOrCreate(texture); + + GLuint target = kGLES30TextureDimensionTable[texDim]; + SetTexture (kShaderFragment, 0, 0, texture, texDim, std::numeric_limits<float>::infinity()); + + // Anisotropic texturing... + if( gGraphicsCaps.hasAnisoFilter ) + { + anisoLevel = std::min( anisoLevel, gGraphicsCaps.maxAnisoLevel ); + GLES_CHK(glTexParameteri( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisoLevel )); + } + + GLenum wrapMode = kWrapModeES2[wrap]; + GLES_CHK(glTexParameteri( target, GL_TEXTURE_WRAP_S, wrapMode )); + GLES_CHK(glTexParameteri( target, GL_TEXTURE_WRAP_T, wrapMode )); + + if( !hasMipMap && filter == kTexFilterTrilinear ) + filter = kTexFilterBilinear; + + GLES_CHK(glTexParameteri( target, GL_TEXTURE_MAG_FILTER, filter != kTexFilterNearest ? GL_LINEAR : GL_NEAREST )); + if( hasMipMap ) + GLES_CHK(glTexParameteri( target, GL_TEXTURE_MIN_FILTER, kMinFilterES2[filter] )); + else + GLES_CHK(glTexParameteri (target, GL_TEXTURE_MIN_FILTER, filter != kTexFilterNearest ? GL_LINEAR : GL_NEAREST)); + + GLESAssert(); +} + +void GFX_GL_IMPL::SetMaterialProperties( const MaterialPropertyBlock& block ) +{ + STATE.m_MaterialProperties = block; +} + +void GFX_GL_IMPL::SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]) +{ + GpuProgram* vertexProgram = programs[kShaderVertex]; + GpuProgram* fragmentProgram = programs[kShaderFragment]; + + DBG_LOG_GLES30("SetShaders(%s, %s)", + GetShaderImplTypeString(vertexProgram? vertexProgram->GetImplType():kShaderImplUndefined), + GetShaderImplTypeString(fragmentProgram? fragmentProgram->GetImplType():kShaderImplUndefined)); + + // GLSL is only supported like this: + // vertex shader actually is both vertex & fragment linked program + // fragment shader is unused + + if (vertexProgram && vertexProgram->GetImplType() == kShaderImplBoth) + { + Assert(fragmentProgram == 0 || fragmentProgram->GetImplType() == kShaderImplBoth); + STATE.activeProgram = vertexProgram; + STATE.activeProgramParams = params[kShaderVertex]; + DebugAssert(STATE.activeProgramParams->IsReady()); + int bufferSize = STATE.activeProgramParams->GetValuesSize(); + STATE.activeProgramParamsBuffer.resize_uninitialized(bufferSize); + memcpy(STATE.activeProgramParamsBuffer.data(), paramsBuffer[kShaderVertex], bufferSize); + } + else + { + Assert(vertexProgram == 0); + STATE.activeProgram = 0; + STATE.activeProgramParams = 0; + STATE.activeProgramParamsBuffer.resize_uninitialized(0); + } +} + +void GFX_GL_IMPL::CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ) +{ + GlslGpuProgramGLES30& programGLES = static_cast<GlslGpuProgramGLES30&>(program->GetGpuProgram()); + programGLES.GetGLProgram(fogMode, program->GetParams(fogMode), program->GetChannels()); +} + +bool GFX_GL_IMPL::IsShaderActive( ShaderType type ) const +{ + //DBG_LOG_GLES30("IsShaderActive(%s): returns %s", GetShaderTypeString(type), STATE.shaderEnabledImpl[type] != kShaderImplUndefined?"True":"False"); + //return STATE.shaderEnabledImpl[type] != kShaderImplUndefined; + DBG_LOG_GLES30("IsShaderActive(%s):", GetShaderTypeString(type)); + return (STATE.activeProgram != 0); +} + +void GFX_GL_IMPL::DestroySubProgram( ShaderLab::SubProgram* subprogram ) +{ + //@TODO + //if (STATE.activeProgram == program) + //{ + // STATE.activeProgram = NULL; + // STATE.activeProgramProps = NULL; + //} + delete subprogram; +} + +void GFX_GL_IMPL::SetConstantBufferInfo( int id, int size ) +{ + STATE.m_CBs.SetCBInfo(id, size); +} + +void GFX_GL_IMPL::DisableLights( int startLight ) +{ + DBG_LOG_GLES30("DisableLights(%d)", startLight); + startLight = std::min (startLight, gGraphicsCaps.maxLights); + STATE.vertexLightCount = startLight; + for (int i = startLight; i < kMaxSupportedVertexLightsByGLES30; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Position + i), Vector4f(0.0f, 0.0f, 1.0f, 0.0f)); + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + i), Vector4f(0.0f, 0.0f, 0.0f, 0.0f)); + } +} + +void GFX_GL_IMPL::SetLight( int light, const GfxVertexLight& data) +{ + DBG_LOG_GLES30("SetLight(%d), [{%f, %f, %f, %f}, {%f, %f, %f, %f}, {%f, %f, %f, %f}, %f, %f, %f, %d]", + light, + data.position[0], data.position[1], data.position[2], data.position[3], + data.spotDirection[0], data.spotDirection[1], data.spotDirection[2], data.spotDirection[3], + data.color[0], data.color[1], data.color[2], data.color[3], + data.range, data.quadAtten, data.spotAngle, data.type); + Assert( light >= 0 && light < kMaxSupportedVertexLights ); + + if (light >= kMaxSupportedVertexLightsByGLES30) + return; + + STATE.vertexLightTypes[light] = data.type; + + // Transform lighting into view space + const Matrix4x4f& viewMat = m_BuiltinParamValues.GetMatrixParam(kShaderMatView); + + // spot direction + Vector4f& spotDirection = m_BuiltinParamValues.GetWritableVectorParam(BuiltinShaderVectorParam(kShaderVecLight0SpotDirection + light)); + if( data.spotAngle > 0.0f ) + { + Vector3f d = viewMat.MultiplyVector3( (const Vector3f&)data.spotDirection ); + spotDirection.Set(-d.x, -d.y, -d.z, 0.0f); + } + else + { + spotDirection.Set(0.0f, 0.0f, 1.0f, 0.0f); + } + + Vector4f& position = m_BuiltinParamValues.GetWritableVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Position + light)); + if (data.type == kLightDirectional) + { + Vector3f p = viewMat.MultiplyVector3( (const Vector3f&)data.position ); + position.Set(-p.x, -p.y, -p.z, 0.0f); + } + else + { + Vector3f p = viewMat.MultiplyPoint3( (const Vector3f&)data.position ); + position.Set(p.x, p.y, p.z, 1.0f); + } + + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + light), data.color); + if (data.spotAngle > 0.0f) + { + // spot attenuation formula taken from D3D9 fixed-function emulation + // see: VertexPipeD3D9.cpp + const float cosTheta = cosf(Deg2Rad(data.spotAngle)*0.25f); + const float cosPhi = cosf(Deg2Rad(data.spotAngle)*0.5f); + const float cosDiff = cosTheta - cosPhi; + m_BuiltinParamValues.GetWritableVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Atten + light)).Set(cosPhi, (cosDiff != 0.0f) ? 1.0f / cosDiff : 1.0f, data.quadAtten, data.range*data.range); + } + else + { + // non-spot light + m_BuiltinParamValues.GetWritableVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Atten + light)).Set(-1.0f, 1.0f, data.quadAtten, data.range*data.range); + } +} + +void GFX_GL_IMPL::SetAmbient( const float ambient[4] ) +{ + DBG_LOG_GLES30("SetAmbient()"); + STATE.ambient.set (ambient[0], ambient[1], ambient[2], ambient[3]); + m_BuiltinParamValues.SetVectorParam(kShaderVecLightModelAmbient, Vector4f(ambient)); +} + +void GFX_GL_IMPL::EnableFog (const GfxFogParams& fog) +{ + DBG_LOG_GLES30("EnableFog()"); + DebugAssertIf( fog.mode <= kFogDisabled ); + m_FogParams = fog; +} + +void GFX_GL_IMPL::DisableFog() +{ + DBG_LOG_GLES30("DisableFog()"); + + if( m_FogParams.mode != kFogDisabled ) + { + m_FogParams.mode = kFogDisabled; + m_FogParams.density = 0.0f; + } +} + +VBO* GFX_GL_IMPL::CreateVBO() +{ + VBO* vbo = new GLES3VBO(); + OnCreateVBO(vbo); + return vbo; +} + +void GFX_GL_IMPL::DeleteVBO( VBO* vbo ) +{ + OnDeleteVBO(vbo); + delete vbo; +} + +DynamicVBO& GFX_GL_IMPL::GetDynamicVBO() +{ + if( !STATE.m_DynamicVBO ) { + STATE.m_DynamicVBO = new DynamicGLES3VBO(); + } + return *STATE.m_DynamicVBO; +} + +// ---------- render textures + +static FramebufferObjectManagerGLES30& GetFBOManager (DeviceStateGLES30& deviceState) +{ + if (!deviceState.m_fboManager) + deviceState.m_fboManager = new FramebufferObjectManagerGLES30(); + return *deviceState.m_fboManager; +} + +static RenderSurfaceGLES30* CreateRenderTexture (TextureDimension dim, TextureID texID, UInt32 internalFormat, int width, int height, int depth) +{ + if (dim == kTexDim2D) + { + Assert(depth == 1); + return new RenderTexture2DGLES30(texID, internalFormat, width, height); + } + else if (dim == kTexDimCUBE) + { + Assert(width == height && depth == 1); + return new RenderTextureCubeGLES30(texID, internalFormat, width, height); + } + else + { + Assert(!"Not supported"); + return 0; + } +} + +static RenderSurfaceGLES30* CreateShadowMapRenderTexture (TextureDimension dim, TextureID texID, UInt32 internalFormat, int width, int height, int depth) +{ + // \note Assumes that constructor binds texID! + if (dim == kTexDim2D) + { + Assert(depth == 1); + RenderTexture2DGLES30* tex = new RenderTexture2DGLES30(texID, internalFormat, width, height); + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE)); + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL)); + return tex; + } + else if (dim == kTexDimCUBE) + { + Assert(width == height && depth == 1); + RenderTextureCubeGLES30* tex = new RenderTextureCubeGLES30(texID, internalFormat, width, height); + GLES_CHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE)); + GLES_CHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL)); + return tex; + } + else + { + Assert(!"Not supported"); + return 0; + } +} + +static RenderSurfaceGLES30* CreateRenderBuffer (TextureDimension dim, UInt32 internalFormat, int width, int height, int depth, int numSamples) +{ + if (dim == kTexDim2D) + { + Assert(depth == 1); + return new RenderBufferGLES30(internalFormat, width, height, numSamples); + } + else if (dim == kTexDimCUBE) + { + Assert(width == height && depth == 1); + return new RenderBufferCubeGLES30(internalFormat, width, height, numSamples); + } + else + { + Assert(!"Not supported"); + return 0; + } +} + +RenderSurfaceHandle GFX_GL_IMPL::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) +{ + DBG_LOG_GLES30("CreateRenderColorSurface(id = %d, %dx%dx%d, samples = %d, dim = %d, fmt = %d, flags = 0x%04x)", textureID.m_ID, width, height, depth, samples, dim, format, createFlags); + + // \note Sample count 0 and 1 both map to non-multisampled textures. + + if (createFlags & kSurfaceCreateNeverUsed) + { + // Use dummy surface that is not backed by any real GL object. + return RenderSurfaceHandle(new DummyRenderSurfaceGLES30(width, height)); + } + else + { + const bool isSRGB = (createFlags & kSurfaceCreateSRGB) != 0; + const UInt32 internalFormat = isSRGB ? GL_SRGB8_ALPHA8 : GetColorFormatGLES30(format); + const bool useRBO = textureID.m_ID == 0 || samples > 1; + + Assert(internalFormat != GL_NONE); + Assert((createFlags & kSurfaceCreateShadowmap) == 0); + + if (useRBO) + { + // \todo [2013-06-04 pyry] There is no global graphics caps for max samples. + const int numSamplesToUse = std::min(gGraphicsCaps.gles30.maxSamples, std::max(samples,1)); + return RenderSurfaceHandle(CreateRenderBuffer(dim, internalFormat, width, height, depth, numSamplesToUse)); + } + else + return RenderSurfaceHandle(CreateRenderTexture(dim, textureID, internalFormat, width, height, depth)); + } + + return RenderSurfaceHandle(0); +} + +RenderSurfaceHandle GFX_GL_IMPL::CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) +{ + DBG_LOG_GLES30("CreateRenderDepthSurface(id = %d, %dx%d, samples = %d, dim = %d, fmt = %d, createFlags = 0x%04x)", textureID.m_ID, width, height, samples, dim, depthFormat, createFlags); + + // \note Sample count 0 and 1 both map to non-multisampled textures. + + if (depthFormat == kDepthFormatNone || (createFlags & kSurfaceCreateNeverUsed) != 0) + { + // Umm... Assuming that we don't want depth buffer at all, but still this is called? + return RenderSurfaceHandle(new DummyRenderSurfaceGLES30(width, height)); + } + else + { + const bool shadowMap = (createFlags & kSurfaceCreateShadowmap) != 0; + const bool useStencil = !shadowMap; + const UInt32 internalFormat = useStencil ? GetDepthStencilFormatGLES30(depthFormat) : GetDepthOnlyFormatGLES30(depthFormat); + const bool useRBO = textureID.m_ID == 0 || samples > 1; + + Assert(internalFormat != GL_NONE); + Assert(!shadowMap || !useRBO); + + if (useRBO) + { + // \todo [2013-06-04 pyry] There is no global graphics caps for max samples. + const int numSamplesToUse = std::min(gGraphicsCaps.gles30.maxSamples, std::max(samples,1)); + return RenderSurfaceHandle(CreateRenderBuffer(dim, internalFormat, width, height, 1, numSamplesToUse)); + } + else if (shadowMap) + return RenderSurfaceHandle(CreateShadowMapRenderTexture(dim, textureID, internalFormat, width, height, 1)); + else + return RenderSurfaceHandle(CreateRenderTexture(dim, textureID, internalFormat, width, height, 1)); + } + + return RenderSurfaceHandle(0); +} + +void GFX_GL_IMPL::DestroyRenderSurface (RenderSurfaceHandle& rs) +{ + DBG_LOG_GLES30("DestroyRenderSurface(%p)", rs.object); + + if (!rs.IsValid()) + return; + + RenderSurfaceGLES30* renderSurface = static_cast<RenderSurfaceGLES30*>(rs.object); + + // Default FBO should not be managed from outside. + Assert(!STATE.m_defaultFbo || !IsInFramebufferAttachmentsGLES30(*STATE.m_defaultFbo->GetAttachments(), renderSurface)); + + // If rs was attached to current FBO, unbind it. + if (STATE.m_activeFbo && IsInFramebufferAttachmentsGLES30(*STATE.m_activeFbo->GetAttachments(), renderSurface)) + { + if (STATE.m_defaultFbo) + BindFramebufferObjectGLES30(STATE.m_defaultFbo); + else + BindDefaultFramebufferGLES30(); + + STATE.m_activeFbo = STATE.m_defaultFbo; + } + + // Delete FBOs where renderSurface was attached. + STATE.m_fboManager->InvalidateSurface(renderSurface); + + delete renderSurface; + rs.object = 0; +} + +static bool IsAnyRSHandleValid (const RenderSurfaceHandle* handles, int numHandles) +{ + for (int ndx = 0; ndx < numHandles; ndx++) + { + if (handles[ndx].IsValid()) + return true; + } + return false; +} + +void GFX_GL_IMPL::SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face) +{ + bool hasColor = !colorHandles[0].object->backBuffer; + bool hasDepth = !depthHandle.object->backBuffer; + + DBG_LOG_GLES30("SetRenderTargets(count = %d, color = %s, depth = %s, mip = %d, face = %d)", count, (hasColor ? "yes" : "no"), (hasDepth ? "yes" : "no"), mipLevel, face); + + // \todo [2013-05-06 pyry] Enable SetRenderTargets() variant with flags and check if we should discard buffers. + // \todo [2013-05-02 pyry] It probably makes sense to do RT change deferred. + + Assert(count <= FramebufferAttachmentsGLES30::kMaxColorAttachments); + + Assert(colorHandles[0].IsValid() && depthHandle.IsValid()); + Assert(colorHandles[0].object->backBuffer == depthHandle.object->backBuffer); + + if(!hasColor && !hasDepth) + { + // Assuming default FB - right? + if (STATE.m_activeFbo != STATE.m_defaultFbo) + { + if (STATE.m_defaultFbo) + BindFramebufferObjectGLES30(STATE.m_defaultFbo); + else + BindDefaultFramebufferGLES30(); + + STATE.m_activeFbo = STATE.m_defaultFbo; + GetRealGfxDevice().GetFrameStats().AddRenderTextureChange(); + } + } + else + { + // Translate to FramebufferAttachments + FramebufferAttachmentsGLES30 attachments; + + attachments.numColorAttachments = count; + attachments.depthStencil = static_cast<RenderSurfaceGLES30*>(depthHandle.object); + attachments.cubemapFace = face; + + for (int ndx = 0; ndx < count; ndx++) + attachments.color[ndx] = static_cast<RenderSurfaceGLES30*>(colorHandles[ndx].object); + + // Create (or fetch from cache) FBO + FramebufferObjectGLES30* fbo = GetFBOManager(STATE).GetFramebufferObject(attachments); + + if (STATE.m_activeFbo != fbo) + { + BindFramebufferObjectGLES30(fbo); + STATE.m_activeFbo = fbo; + GetRealGfxDevice().GetFrameStats().AddRenderTextureChange(); + } + } +} + +void GFX_GL_IMPL::ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) +{ + DBG_LOG_GLES30("ResolveColorSurface(src = %p, dst = %p)", srcHandle.object, dstHandle.object); + + // Fetch temporary FBOs for resolve - use single color attachment. + FramebufferObjectGLES30* srcFbo = 0; + FramebufferObjectGLES30* dstFbo = 0; + + Assert(srcHandle.object && dstHandle.object); + + for (int ndx = 0; ndx < 2; ndx++) + { + FramebufferAttachmentsGLES30 attachments; + attachments.numColorAttachments = 1; + attachments.color[0] = static_cast<RenderSurfaceGLES30*>(ndx ? srcHandle.object : dstHandle.object); + + (ndx ? srcFbo : dstFbo) = GetFBOManager(STATE).GetFramebufferObject(attachments); + } + + Assert(srcFbo && dstFbo); + + int width = static_cast<RenderSurfaceGLES30*>(dstHandle.object)->GetWidth(); + int height = static_cast<RenderSurfaceGLES30*>(dstHandle.object)->GetHeight(); + + glBindFramebuffer(GL_READ_FRAMEBUFFER, srcFbo->GetFboID()); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dstFbo->GetFboID()); + GLES_CHK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + + // Restore old FBO binding + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, STATE.m_activeFbo ? STATE.m_activeFbo->GetFboID() : 0)); +} + +RenderSurfaceHandle GFX_GL_IMPL::GetActiveRenderColorSurface(int index) +{ + Assert(0 <= index && index <= FramebufferAttachmentsGLES30::kMaxColorAttachments); + + if (STATE.m_activeFbo) + return RenderSurfaceHandle(STATE.m_activeFbo->GetColorAttachment(index)); + else + return RenderSurfaceHandle(0); +} + +RenderSurfaceHandle GFX_GL_IMPL::GetActiveRenderDepthSurface() +{ + if (STATE.m_activeFbo) + return RenderSurfaceHandle(STATE.m_activeFbo->GetDepthStencilAttachment()); + else + return RenderSurfaceHandle(0); +} + +void GFX_GL_IMPL::SetSurfaceFlags (RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags) +{ + // \todo [2013-04-29 pyry] Implement handling for flags! +} + +void GFX_GL_IMPL::DiscardContents (RenderSurfaceHandle& rs) +{ + DBG_LOG_GLES30("DiscardContents(%p)", rs.object); + + if (!rs.IsValid()) + return; // \todo [2013-06-05 pyry] Bug in threaded device code causes DiscardContents() calls to invalid handles. + + FramebufferObjectGLES30* curFbo = STATE.m_activeFbo; + GLenum discardAttachments[FramebufferAttachmentsGLES30::kMaxColorAttachments+1]; + int attachNdx = 0; + + if (curFbo) + { + // Check if rs is attached to current fbo. + for (int colorNdx = 0; colorNdx < curFbo->GetNumColorAttachments(); colorNdx++) + { + if (rs.object == curFbo->GetColorAttachment(colorNdx)) + discardAttachments[attachNdx++] = GL_COLOR_ATTACHMENT0+colorNdx; + } + + if (rs.object == curFbo->GetDepthStencilAttachment()) + { + // \todo [2013-05-02 pyry] Should we check if FBO actually has stencil attachment enabled? + discardAttachments[attachNdx++] = GL_DEPTH_STENCIL_ATTACHMENT; + } + } + + Assert(attachNdx <= (int)(sizeof(discardAttachments)/sizeof(discardAttachments[0]))); + if (attachNdx > 0) + GLES_CHK(glInvalidateFramebuffer(GL_FRAMEBUFFER, attachNdx, &discardAttachments[attachNdx])); + + DBG_LOG_GLES30(" .. discarded in current FBO = %s", (attachNdx > 0) ? "true" : "false"); + + // If attachment was not discarded yet, do it later when it is bound. + if (attachNdx == 0) + { + RenderSurfaceGLES30* renderSurface = static_cast<RenderSurfaceGLES30*>(rs.object); + renderSurface->SetFlags(renderSurface->GetFlags() | RenderSurfaceGLES30::kDiscardOnBind); + } +} + +// ---------- uploading textures + +void GFX_GL_IMPL::UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + ::UploadTexture2DGLES3( texture, dimension, srcData, width, height, format, mipCount, uploadFlags, skipMipLevels, colorSpace ); +} + +void GFX_GL_IMPL::UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + ::UploadTextureSubData2DGLES3( texture, srcData, mipLevel, x, y, width, height, format, colorSpace ); +} + +void GFX_GL_IMPL::UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + ::UploadTextureCubeGLES3( texture, srcData, faceDataSize, size, format, mipCount, uploadFlags, colorSpace ); +} + +void GFX_GL_IMPL::UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + // \todo [2013-04-16 pyry] Add support. + ErrorString("3D textures are not supported by OpenGLES!"); +} + +void GFX_GL_IMPL::DeleteTexture(TextureID texture) +{ + GLuint targetTex = (GLuint)TextureIdMap::QueryNativeTexture(texture); + if(targetTex == 0) + return; + + REGISTER_EXTERNAL_GFX_DEALLOCATION(texture.m_ID); + GLES_CHK(glDeleteTextures(1, &targetTex)); + + // invalidate texture unit states that used this texture + for( int i = 0; i < gGraphicsCaps.maxTexUnits; ++i ) + { + TextureUnitStateGLES3& currTex = STATE.textures[i]; + if( currTex.texID == targetTex ) + currTex.Invalidate(); + } + + TextureIdMap::RemoveTexture(texture); +} + +// ---------- context + +GfxDevice::PresentMode GFX_GL_IMPL::GetPresentMode() +{ + return UNITY_IPHONE ? kPresentAfterDraw : kPresentBeforeUpdate; +} + +static void ResetFboBindingToDefault (DeviceStateGLES30& state) +{ + if (state.m_activeFbo != state.m_defaultFbo) + { + if (state.m_defaultFbo) + BindFramebufferObjectGLES30(state.m_defaultFbo); + else + BindDefaultFramebufferGLES30(); + state.m_activeFbo = state.m_defaultFbo; + } +} + +void GFX_GL_IMPL::BeginFrame() +{ + DBG_LOG_GLES30("BeginFrame()"); + m_InsideFrame = true; + + if (gGraphicsCaps.hasTiledGPU) + { + // \todo [2013-05-02 pyry] Should we reset FBO binding here? + ResetFboBindingToDefault(STATE); + if(STATE.scissor) + GLES_CHK(glDisable(GL_SCISSOR_TEST)); + GLES_CHK(glViewport(0, 0, 65536, 65536)); + GLES_CHK(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); + GLES_CHK(glClearStencil(0)); + GLES_CHK(glClearDepthf(1.0f)); + GLES_CHK(glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT)); + GLES_CHK(glViewport(STATE.viewport[0], STATE.viewport[1], STATE.viewport[2], STATE.viewport[3])); + if(STATE.scissor) + GLES_CHK(glEnable(GL_SCISSOR_TEST)); + + } +} +void GFX_GL_IMPL::EndFrame() +{ + // \todo [2013-05-02 pyry] Do we really want to reset FBO binding here? + ResetFboBindingToDefault(STATE); + if (STATE.m_activeFbo != 0) + { + // If rendering to FBO, discard contents. + static const GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_DEPTH_STENCIL_ATTACHMENT }; + GLES_CHK(glInvalidateFramebuffer(GL_FRAMEBUFFER, sizeof(attachments)/sizeof(attachments[0]), &attachments[0])); + } + else + { + // System "FBO", discard only depthstencil + static const GLenum attachments[] = { GL_DEPTH, GL_STENCIL }; + GLES_CHK(glInvalidateFramebuffer(GL_FRAMEBUFFER, sizeof(attachments)/sizeof(attachments[0]), &attachments[0])); + } + + GetBufferManagerGLES30()->AdvanceFrame(); + + DBG_LOG_GLES30("EndFrame()"); + m_InsideFrame = false; +} + +bool GFX_GL_IMPL::IsValidState() +{ +#if UNITY_ANDROID + return ContextGLES::IsValid(); +#else + return true; +#endif +} + +bool GFX_GL_IMPL::HandleInvalidState() +{ +#if UNITY_ANDROID + bool needReload; + if (!ContextGLES::HandleInvalidState(&needReload)) + return false; + if (needReload) + ReloadResources(); + return true; +#else + return true; +#endif +} + +void GFX_GL_IMPL::PresentFrame() +{ + DBG_LOG_GLES30("===================================="); + DBG_LOG_GLES30("===================================="); + DBG_LOG_GLES30("PresentFrame"); + DBG_LOG_GLES30("===================================="); + DBG_LOG_GLES30("===================================="); + +#if UNITY_WIN + PresentContextGLES30(); +#else + PresentContextGLES(); +#endif +} + +void GFX_GL_IMPL::FinishRendering() +{ + GLES_CHK(glFinish()); +} + +// ---------- immediate mode rendering + +// we break very large immediate mode submissions into multiple batches internally +const int kMaxImmediateVerticesPerDraw = 2048; + + +ImmediateModeGLES30::ImmediateModeGLES30() + : m_Mode (kPrimitiveTriangles) + , m_IndexBufferQuads(0) +{ +#if 0 + m_QuadsIB = (UInt16*)UNITY_MALLOC(kMemGeometry, kMaxImmediateVerticesPerDraw*6*sizeof(UInt16)); + UInt32 baseIndex = 0; + UInt16* ibPtr = m_QuadsIB; + for( int i = 0; i < kMaxImmediateVerticesPerDraw; ++i ) + { + ibPtr[0] = baseIndex + 1; + ibPtr[1] = baseIndex + 2; + ibPtr[2] = baseIndex; + ibPtr[3] = baseIndex + 2; + ibPtr[4] = baseIndex + 3; + ibPtr[5] = baseIndex; + baseIndex += 4; + ibPtr += 6; + } +#endif +} + +ImmediateModeGLES30::~ImmediateModeGLES30() +{ + Invalidate(); +} + +void ImmediateModeGLES30::Invalidate() +{ + if (m_IndexBufferQuads) + { + m_IndexBufferQuads->Release(); + m_IndexBufferQuads = 0; + } + + m_Vertices.clear(); + memset(&m_Current, 0, sizeof(m_Current)); +} + +void GFX_GL_IMPL::ImmediateVertex( float x, float y, float z ) +{ + // If the current batch is becoming too large, internally end it and begin it again. + size_t currentSize = STATE.m_Imm.m_Vertices.size(); + if( currentSize >= kMaxImmediateVerticesPerDraw - 4 ) + { + GfxPrimitiveType mode = STATE.m_Imm.m_Mode; + // For triangles, break batch when multiple of 3's is reached. + if( mode == kPrimitiveTriangles && currentSize % 3 == 0 ) + { + ImmediateEnd(); + ImmediateBegin( mode ); + } + // For other primitives, break on multiple of 4's. + // NOTE: This won't quite work for triangle strips, but we'll just pretend + // that will never happen. + else if( mode != kPrimitiveTriangles && currentSize % 4 == 0 ) + { + ImmediateEnd(); + ImmediateBegin( mode ); + } + } + Vector3f& vert = STATE.m_Imm.m_Current.vertex; + vert.x = x; + vert.y = y; + vert.z = z; + STATE.m_Imm.m_Vertices.push_back( STATE.m_Imm.m_Current ); +} + +void GFX_GL_IMPL::ImmediateNormal( float x, float y, float z ) +{ + STATE.m_Imm.m_Current.normal.x = x; + STATE.m_Imm.m_Current.normal.y = y; + STATE.m_Imm.m_Current.normal.z = z; +} + +void GFX_GL_IMPL::ImmediateColor( float r, float g, float b, float a ) +{ + r = clamp01(r); + g = clamp01(g); + b = clamp01(b); + a = clamp01(a); + + STATE.m_Imm.m_Current.color = + ((UInt32)(a * 255.0f) << 24) | + ((UInt32)(b * 255.0f) << 16) | + ((UInt32)(g * 255.0f) << 8) | + ((UInt32)(r * 255.0f)); +} + +void GFX_GL_IMPL::ImmediateTexCoordAll( float x, float y, float z ) +{ + for( int i = 0; i < gGraphicsCaps.maxTexCoords; ++i ) + { + Vector3f& uv = STATE.m_Imm.m_Current.texCoords[i]; + uv.x = x; + uv.y = y; + uv.z = z; + } +} + +void GFX_GL_IMPL::ImmediateTexCoord( int unit, float x, float y, float z ) +{ + if( unit < 0 || unit >= 8 ) + { + ErrorString( "Invalid unit for texcoord" ); + return; + } + Vector3f& uv = STATE.m_Imm.m_Current.texCoords[unit]; + uv.x = x; + uv.y = y; + uv.z = z; +} + +void GFX_GL_IMPL::ImmediateBegin( GfxPrimitiveType type ) +{ + STATE.m_Imm.m_Mode = type; + STATE.m_Imm.m_Vertices.clear(); +} + +void GFX_GL_IMPL::ImmediateEnd() +{ + if (STATE.m_Imm.m_Vertices.empty()) + return; + + const UInt32 minBufferThreshold = 2048; + + const int numVertices = STATE.m_Imm.m_Vertices.size(); + const UInt32 vertexBufStride = (UInt32)sizeof(ImmediateVertexGLES30); + const UInt32 vertexBufUsage = GL_STREAM_DRAW; + const UInt32 vertexBufSize = vertexBufStride*numVertices; + const bool useBuffer = vertexBufSize >= minBufferThreshold; + DataBufferGLES30* vertexBuffer = useBuffer ? GetBufferManagerGLES30()->AcquireBuffer(numVertices*vertexBufStride, vertexBufUsage) : 0; + VertexArrayInfoGLES30 vertexSetup; + + // \todo [2013-05-31 pyry] Recreate or update? + if (vertexBuffer) + vertexBuffer->RecreateWithData(vertexBufSize, vertexBufUsage, &STATE.m_Imm.m_Vertices[0]); + + if (STATE.m_Imm.m_Mode == kPrimitiveQuads && !STATE.m_Imm.m_IndexBufferQuads) + { + // \todo [2013-05-31 pyry] Move somewhere else. + const int quadCount = kMaxImmediateVerticesPerDraw/4; + const int quadIndexCount = quadCount * 6; + const int indexBufferSize = quadIndexCount * sizeof(UInt16); + const UInt32 indexBufferUsage = GL_STATIC_DRAW; + std::vector<UInt16> quadIndices (quadIndexCount); + + for (int quadNdx = 0; quadNdx < quadCount; ++quadNdx) + { + const UInt16 srcBaseNdx = quadNdx*4; + const int dstBaseNdx = quadNdx*6; + quadIndices[dstBaseNdx + 0] = srcBaseNdx + 1; + quadIndices[dstBaseNdx + 1] = srcBaseNdx + 2; + quadIndices[dstBaseNdx + 2] = srcBaseNdx; + quadIndices[dstBaseNdx + 3] = srcBaseNdx + 2; + quadIndices[dstBaseNdx + 4] = srcBaseNdx + 3; + quadIndices[dstBaseNdx + 5] = srcBaseNdx; + } + + STATE.m_Imm.m_IndexBufferQuads = GetBufferManagerGLES30()->AcquireBuffer(indexBufferSize, indexBufferUsage); + STATE.m_Imm.m_IndexBufferQuads->RecreateWithData(indexBufferSize, indexBufferUsage, &quadIndices[0]); + } + + // Fill in vertex setup info. + { + const UInt8* basePtr = vertexBuffer ? 0 : (const UInt8*)&STATE.m_Imm.m_Vertices[0]; + const UInt32 buffer = vertexBuffer ? vertexBuffer->GetBuffer() : 0; + + // \todo [2013-05-31 pyry] Do not send unused attributes! + vertexSetup.enabledArrays = (1<<kGLES3AttribLocationPosition) + | (1<<kGLES3AttribLocationColor) + | (1<<kGLES3AttribLocationNormal); + + // All are sourcing from same buffer + for (int i = 0; i < kGLES3MaxVertexAttribs; i++) + vertexSetup.buffers[i] = buffer; + + vertexSetup.arrays[kGLES3AttribLocationPosition] = VertexInputInfoGLES30(basePtr + 0, kChannelFormatFloat, 3, vertexBufStride); + vertexSetup.arrays[kGLES3AttribLocationNormal] = VertexInputInfoGLES30(basePtr + 3*sizeof(float), kChannelFormatFloat, 3, vertexBufStride); + vertexSetup.arrays[kGLES3AttribLocationColor] = VertexInputInfoGLES30(basePtr + 6*sizeof(float), kChannelFormatColor, 4, vertexBufStride); + UInt32 curOffset = 6*sizeof(float) + sizeof(UInt32); + + for (int texCoordNdx = 0; texCoordNdx < (kGLES3MaxVertexAttribs-kGLES3AttribLocationTexCoord0); texCoordNdx++) + { + const int attribLoc = kGLES3AttribLocationTexCoord0+texCoordNdx; + + if (attribLoc < gGraphicsCaps.gles30.maxAttributes) + { + vertexSetup.enabledArrays |= (1<<attribLoc); + vertexSetup.arrays[kGLES3AttribLocationTexCoord0+texCoordNdx] = + VertexInputInfoGLES30(basePtr + curOffset, kChannelFormatFloat, 3, vertexBufStride); + curOffset += 3*sizeof(float); + } + } + } + + // Setup state + BeforeDrawCall(true /* immediate */); + SetupDefaultVertexArrayStateGLES30(vertexSetup); + + switch (STATE.m_Imm.m_Mode) + { + case kPrimitiveTriangles: + GLES_CHK(glDrawArrays(GL_TRIANGLES, 0, numVertices)); + m_Stats.AddDrawCall(numVertices / 3, numVertices); + break; + + case kPrimitiveTriangleStripDeprecated: + GLES_CHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices)); + m_Stats.AddDrawCall(numVertices - 2, numVertices); + break; + + case kPrimitiveLines: + GLES_CHK(glDrawArrays(GL_LINES, 0, numVertices)); + m_Stats.AddDrawCall(numVertices / 2, numVertices); + break; + + case kPrimitiveQuads: + Assert(STATE.m_Imm.m_IndexBufferQuads); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, STATE.m_Imm.m_IndexBufferQuads->GetBuffer())); + GLES_CHK(glDrawElements(GL_TRIANGLES, (numVertices/4)*6, GL_UNSIGNED_SHORT, 0)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + m_Stats.AddDrawCall(numVertices / 2, numVertices); + break; + + default: + AssertString("ImmediateEnd: unknown draw mode"); + } + + if (vertexBuffer) + vertexBuffer->Release(); +} + +// ---------- readback path + +static int GetFirstValidColorAttachmentNdx (const FramebufferObjectGLES30* fbo) +{ + for (int colorNdx = 0; colorNdx < fbo->GetNumColorAttachments(); colorNdx++) + { + if (fbo->GetColorAttachment(colorNdx)) + return colorNdx; + } + + return -1; +} + +static bool IsRenderSurfaceFormatCompatibleWithRGBA8Read (UInt32 format) +{ + switch (format) + { + case GL_RGBA8: + case GL_RGB8: + case GL_RG8: + case GL_R8: + case GL_RGB565: + case GL_RGB10_A2: + case GL_RGBA4: + case GL_RGB5_A1: + case GL_SRGB8_ALPHA8: + case GL_SRGB8: + return true; + + default: + return false; + } +} + +static bool CanReadRGBA8FromFirstColorAttachment (const FramebufferObjectGLES30* fbo) +{ + int ndx = GetFirstValidColorAttachmentNdx(fbo); + if (ndx >= 0) + return IsRenderSurfaceFormatCompatibleWithRGBA8Read(fbo->GetColorAttachment(ndx)->GetFormat()); + else + return false; +} + +static void ReadPixelsFromDefaultFramebufferRGBA8 (int x, int y, int width, int height, UInt8* dstPtr) +{ + GLES_CHK(glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, dstPtr)); +} + +static void ReadPixelsFromActiveFramebufferObjectRGBA8 (DeviceStateGLES30& state, int x, int y, int width, int height, UInt8* dstPtr) +{ + Assert(state.m_activeFbo != 0); + Assert(CanReadRGBA8FromFirstColorAttachment(state.m_activeFbo)); + + FramebufferObjectGLES30* activeFbo = state.m_activeFbo; + const int colorNdx = GetFirstValidColorAttachmentNdx(state.m_activeFbo); + const RenderSurfaceGLES30* colorSurface = activeFbo->GetColorAttachment(colorNdx); + const bool requiresResolve = colorSurface->GetNumSamples() > 1; + + if (requiresResolve) + { + FramebufferObjectManagerGLES30& fboManager = GetFBOManager(state); + FramebufferObjectGLES30* resolveBuffer = GetResolveFramebufferObjectGLES30(&fboManager, colorSurface->GetFormat(), 0, + colorSurface->GetWidth(), colorSurface->GetHeight()); + + GLenum drawBuffer = GL_COLOR_ATTACHMENT0; + GLES_CHK(glDrawBuffers(1, &drawBuffer)); + GLES_CHK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolveBuffer->GetFboID())); + + // \note active FBO is already GL_READ_FRAMEBUFFER + GLES_CHK(glReadBuffer(GL_COLOR_ATTACHMENT0+colorNdx)); + + // Resolve blit. + GLES_CHK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + + // Read from resolve buffer. + GLES_CHK(glReadBuffer(GL_COLOR_ATTACHMENT0)); + GLES_CHK(glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, dstPtr)); + + // Restore binding. + BindFramebufferObjectGLES30(activeFbo); + } + else + { + GLES_CHK(glReadBuffer(GL_COLOR_ATTACHMENT0+colorNdx)); + GLES_CHK(glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, dstPtr)); + } +} + +void GFX_GL_IMPL::ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle) +{ + FramebufferAttachmentsGLES30 att; + att.numColorAttachments = 1; + att.color[0] = static_cast<RenderSurfaceGLES30 *>(colorHandle.object); + att.depthStencil = static_cast<RenderSurfaceGLES30 *>(depthHandle.object); + att.cubemapFace = kCubeFaceUnknown; + + FramebufferObjectGLES30 *helperFBO = GetFBOManager(STATE).GetFramebufferObject(att); + FramebufferObjectGLES30 *oldFBO = STATE.m_activeFbo; + + + // use the full size of the depth buffer, sub-rects are not needed and might not work on some hardware + GLint x = 0; + GLint y = 0; + GLint width = att.depthStencil->GetWidth(); + GLint height = att.depthStencil->GetHeight(); + + // bind helper FBO + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, helperFBO->GetFboID())); + + GLES_CHK(glReadBuffer (GL_NONE)); + + // blit + GLES_CHK(glBindFramebuffer (GL_READ_FRAMEBUFFER, oldFBO->GetFboID())); + GLES_CHK(glBindFramebuffer (GL_DRAW_FRAMEBUFFER, helperFBO->GetFboID())); + GLES_CHK(glBlitFramebuffer (x, y, x + width, y + height, x, y, x + width, y + height, GL_DEPTH_BUFFER_BIT, GL_NEAREST)); + + // restore the previously bound FBO + GLES_CHK(glBindFramebuffer (GL_FRAMEBUFFER, oldFBO->GetFboID())); + + +} + + +bool GFX_GL_IMPL::CaptureScreenshot (int left, int bottom, int width, int height, UInt8* rgba32) +{ + if (STATE.m_activeFbo) + { + if (CanReadRGBA8FromFirstColorAttachment(STATE.m_activeFbo)) + { + ReadPixelsFromActiveFramebufferObjectRGBA8(STATE, left, bottom, width, height, rgba32); + return true; + } + else + { + ErrorString("Active FBO is not compatible with screenshots"); + return false; + } + } + else + { + ReadPixelsFromDefaultFramebufferRGBA8(left, bottom, width, height, rgba32); + return true; + } +} + +bool GFX_GL_IMPL::ReadbackImage (ImageReference& image, int left, int bottom, int width, int height, int destX, int destY) +{ + const bool coordsOk = destX == 0; + const bool formatOk = image.GetFormat() == kTexFormatRGBA32; + const bool strideOk = image.GetRowBytes() == 4*width; + const bool directRead = coordsOk && formatOk && strideOk; + + if (directRead) + return CaptureScreenshot(left, bottom, width, height, image.GetRowPtr(destY)); + else + { + std::vector<UInt8> tmpBuf(width*height*4); + if (!CaptureScreenshot(left, bottom, width, height, &tmpBuf[0])) + return false; + + ImageReference blitSrc(width, height, 4*width, kTexFormatRGBA32, &tmpBuf[0]); + image.BlitImage(destX, destY, blitSrc); + + return true; + } +} + +void GFX_GL_IMPL::GrabIntoRenderTexture( RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ) +{ + if (!rs.IsValid()) + return; + + RenderSurfaceGLES30* dstColorSurface = static_cast<RenderSurfaceGLES30*>(rs.object); + RenderSurfaceGLES30* dstDepthSurface = static_cast<RenderSurfaceGLES30*>(rd.object); + + // Grabbing to MSAA targets is not supported. + if (dstColorSurface->GetNumSamples() > 1 || (dstDepthSurface && dstDepthSurface->GetNumSamples() > 1)) + { + ErrorString("GrabIntoRenderTexture(): Grabbing to MSAA RenderSurfaces is not supported"); + return; + } + + if (dstColorSurface->GetType() == RenderSurfaceGLES30::kTypeTexture2D && !dstDepthSurface && !STATE.m_activeFbo) + { + // Simple path: use glCopyTexSubImage() + RenderTexture2DGLES30* dstColorTex = static_cast<RenderTexture2DGLES30*>(dstColorSurface); + + GetRealGfxDevice().SetTexture(kShaderFragment, 0, 0, dstColorTex->GetTextureID(), kTexDim2D, std::numeric_limits<float>::infinity()); + GLES_CHK(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, x, y, width, height)); + } + else + { + // Temporary dst fbo. + FramebufferObjectManagerGLES30& fboManager = GetFBOManager(STATE); + FramebufferObjectGLES30* dstFbo = 0; + { + FramebufferAttachmentsGLES30 attachments; + attachments.numColorAttachments = 1; + attachments.color[0] = dstColorSurface; + attachments.depthStencil = dstDepthSurface; + + dstFbo = fboManager.GetFramebufferObject(attachments); + } + + bool copyColor = false; + bool copyDepth = false; + bool colorNeedsResolve = false; + bool depthNeedsResolve = false; + UInt32 srcColorFormat = 0; + UInt32 srcDepthFormat = 0; + GLenum srcColorAttachment = 0; + + if (STATE.m_activeFbo) + { + const int srcColorNdx = GetFirstValidColorAttachmentNdx(STATE.m_activeFbo); + const RenderSurfaceGLES30* srcColorSurface = srcColorNdx >= 0 ? STATE.m_activeFbo->GetColorAttachment(srcColorNdx) : 0; + const RenderSurfaceGLES30* srcDepthSurface = STATE.m_activeFbo->GetDepthStencilAttachment() ? STATE.m_activeFbo->GetDepthStencilAttachment() : 0; + + copyColor = srcColorSurface && dstColorSurface; + copyDepth = dstColorSurface && dstDepthSurface; + colorNeedsResolve = copyColor && srcColorSurface->GetNumSamples() > 1; + depthNeedsResolve = copyDepth && srcDepthSurface->GetNumSamples() > 1; + srcColorFormat = srcColorSurface ? srcColorSurface->GetFormat() : 0; + srcDepthFormat = srcDepthSurface ? srcDepthSurface->GetFormat() : 0; + srcColorAttachment = GL_COLOR_ATTACHMENT0 + srcColorNdx; + } + else + { + const bool isMSAA = queryInt(GL_SAMPLE_BUFFERS) > 0; + + srcColorFormat = GetDefaultFramebufferColorFormatGLES30(); + srcDepthFormat = GetDefaultFramebufferDepthFormatGLES30(); + copyColor = srcColorFormat != 0 && dstColorSurface; + copyDepth = srcDepthFormat != 0 && dstDepthSurface; + colorNeedsResolve = isMSAA; + depthNeedsResolve = isMSAA; + srcColorAttachment = GL_BACK; + } + + const bool colorFormatMatch = !copyColor || srcColorFormat == dstColorSurface->GetFormat(); + const bool depthFormatMatch = !copyDepth || srcDepthFormat == dstDepthSurface->GetFormat(); + const bool copyBoundsOk = x == 0 && y == 0; + const bool copyDirectly = (!colorNeedsResolve || (colorFormatMatch && copyBoundsOk)) && (!depthNeedsResolve || (depthFormatMatch && copyBoundsOk)); + const UInt32 blitBuffers = (copyColor?GL_COLOR_BUFFER_BIT:0)|(copyDepth?GL_DEPTH_BUFFER_BIT:0); + + // \note There are blits that are not supported altogether. For example blitting + // from unorm to integer format. Supporting them would require emulating the + // blit and even in such case the semantics are rather vague. So we just rely + // on GL giving an error if user attempts to do something strange. + + if (copyDirectly) + { + GLenum drawBuffer = GL_COLOR_ATTACHMENT0; + + GLES_CHK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dstFbo->GetFboID())); + GLES_CHK(glDrawBuffers(1, &drawBuffer)); + + // \note active FBO is already GL_READ_FRAMEBUFFER + GLES_CHK(glReadBuffer(srcColorAttachment)); + + GLES_CHK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, blitBuffers, GL_NEAREST)); + } + else + { + Assert(colorNeedsResolve || depthNeedsResolve); + + GLenum drawBuffer = GL_COLOR_ATTACHMENT0; + GLES_CHK(glDrawBuffers(1, &drawBuffer)); + + FramebufferObjectGLES30* resolveBuffer = GetResolveFramebufferObjectGLES30(&fboManager, + copyColor ? srcColorFormat : 0, + copyDepth ? srcDepthFormat : 0, + width, height); + + GLES_CHK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolveBuffer->GetFboID())); + + // \note active FBO is already GL_READ_FRAMEBUFFER + GLES_CHK(glReadBuffer(srcColorAttachment)); + + // Resolve blit. + GLES_CHK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, blitBuffers, GL_NEAREST)); + + // Blit from resolve buffer to destination. + GLES_CHK(glBindFramebuffer(GL_READ_FRAMEBUFFER, resolveBuffer->GetFboID())); + GLES_CHK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dstFbo->GetFboID())); + GLES_CHK(glReadBuffer(GL_COLOR_ATTACHMENT0)); + GLES_CHK(glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, blitBuffers, GL_NEAREST)); + } + + // Restore readbuffer state. + GLES_CHK(glReadBuffer(GL_BACK)); + + // Restore binding. + if (!STATE.m_activeFbo) + BindDefaultFramebufferGLES30(); + else + BindFramebufferObjectGLES30(STATE.m_activeFbo); + } +} + +#if ENABLE_PROFILER + +void GFX_GL_IMPL::BeginProfileEvent(const char* name) +{ + if(gGraphicsCaps.gles30.hasDebugMarkers) + gGles3ExtFunc.glPushGroupMarkerEXT(0, name); +} + +void GFX_GL_IMPL::EndProfileEvent() +{ + if(gGraphicsCaps.gles30.hasDebugMarkers) + gGles3ExtFunc.glPopGroupMarkerEXT(); +} + +GfxTimerQuery* GFX_GL_IMPL::CreateTimerQuery() +{ + if( gGraphicsCaps.hasTimerQuery ) + return new TimerQueryGLES30; + return NULL; +} + +void GFX_GL_IMPL::DeleteTimerQuery(GfxTimerQuery* query) +{ + delete query; +} + +void GFX_GL_IMPL::BeginTimerQueries() +{ + if( !gGraphicsCaps.hasTimerQuery ) + return; + + g_TimerQueriesGLES30.BeginTimerQueries(); +} + +void GFX_GL_IMPL::EndTimerQueries() +{ + if( !gGraphicsCaps.hasTimerQuery ) + return; + + g_TimerQueriesGLES30.EndTimerQueries(); +} + +#endif // ENABLE_PROFILER + +typedef std::map<FixedFunctionStateGLES30, FixedFunctionProgramGLES30*, FullStateCompareGLES30> FFProgramCacheT; +typedef std::map<FixedFunctionStateGLES30, GLShaderID, VertexStateCompareGLES30> FFVertexProgramCacheT; +typedef std::map<FixedFunctionStateGLES30, GLShaderID, FragmentStateCompareGLES30> FFFragmentProgramCacheT; + +static FFProgramCacheT g_FixedFunctionProgramCache; +static FFVertexProgramCacheT g_FFVertexProgramCache; +static FFFragmentProgramCacheT g_FFFragmentProgramCache; + +static void ClearFixedFunctionPrograms() +{ + for (FFVertexProgramCacheT::iterator it = g_FFVertexProgramCache.begin(); it != g_FFVertexProgramCache.end(); ++it) + { + GLES_CHK(glDeleteShader(it->second)); + } + g_FFVertexProgramCache.clear(); + for (FFFragmentProgramCacheT::iterator it = g_FFFragmentProgramCache.begin(); it != g_FFFragmentProgramCache.end(); ++it) + { + GLES_CHK(glDeleteShader(it->second)); + } + g_FFFragmentProgramCache.clear(); + + for(FFProgramCacheT::iterator i = g_FixedFunctionProgramCache.begin(); i != g_FixedFunctionProgramCache.end(); ++i) + { + delete i->second; + } + g_FixedFunctionProgramCache.clear(); + +} + +static const FixedFunctionProgramGLES30* GetFixedFunctionProgram(const FixedFunctionStateGLES30& state) +{ + FFProgramCacheT::const_iterator cachedProgIt = g_FixedFunctionProgramCache.find(state); + if (cachedProgIt != g_FixedFunctionProgramCache.end()) + return cachedProgIt->second; + + // Cache miss, create fixed function program + // NOTE: don't worry too much about performance of vertex/fragment maps + // shader building/compilation is crazy expensive anyway + FFVertexProgramCacheT::const_iterator vertexProgIt = g_FFVertexProgramCache.find(state); + FFFragmentProgramCacheT::const_iterator fragmentProgIt = g_FFFragmentProgramCache.find(state); + + GLShaderID vertexShader = (vertexProgIt != g_FFVertexProgramCache.end())? vertexProgIt->second: 0; + GLShaderID fragmentShader = (fragmentProgIt != g_FFFragmentProgramCache.end())? fragmentProgIt->second: 0; + + if (vertexShader == 0) + { + vertexShader = glCreateShader(GL_VERTEX_SHADER); + std::string src = BuildVertexShaderSourceGLES30(state); + const char* cStr = src.c_str(); + + DBG_SHADER_VERBOSE_GLES30("Compiling generated vertex shader"); + GlslGpuProgramGLES30::CompileGlslShader(vertexShader, cStr); + GLESAssert(); + + g_FFVertexProgramCache[state] = vertexShader; + } + + if (fragmentShader == 0) + { + fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + std::string src = BuildFragmentShaderSourceGLES30(state); + const char* cStr = src.c_str(); + + DBG_SHADER_VERBOSE_GLES30("Compiling generated fragment shader"); + GlslGpuProgramGLES30::CompileGlslShader(fragmentShader, cStr); + GLESAssert(); + + g_FFFragmentProgramCache[state] = fragmentShader; + } + + DBG_SHADER_VERBOSE_GLES30("Creating and linking GLES program"); + FixedFunctionProgramGLES30* ffProg = new FixedFunctionProgramGLES30(vertexShader, fragmentShader); + g_FixedFunctionProgramCache[state] = ffProg; + + return ffProg; +} + +static bool ComputeTextureTransformMatrix(TextureUnitStateGLES3 const& tex, Matrix4x4f const& worldViewMatrix, Matrix4x4f const& worldMatrix, + Matrix4x4f& outMatrix) +{ + switch (tex.texGen) + { + case kTexGenDisabled: + // NOTE: although tex-gen can be disabled + // textureMatrix can contain UV scale/offset + // so we will set it + case kTexGenObject: + if (tex.identityMatrix) + { + outMatrix.SetIdentity(); + return false; + } + CopyMatrix(tex.textureMatrix.GetPtr(), outMatrix.GetPtr()); + break; + case kTexGenSphereMap: + { + float invScale = 1.0f / Magnitude (worldViewMatrix.GetAxisX()); + + Matrix4x4f scaleOffsetMatrix; + scaleOffsetMatrix.SetScale(Vector3f(0.5*invScale, 0.5*invScale, 0.0)); + scaleOffsetMatrix.SetPosition(Vector3f(0.5, 0.5, 0.0)); + + Matrix4x4f worldViewMatrixRotation = worldViewMatrix; + worldViewMatrixRotation.SetPosition(Vector3f::zero); + Matrix4x4f combo; + MultiplyMatrices4x4(&scaleOffsetMatrix, &worldViewMatrixRotation, &combo); + MultiplyMatrices4x4(&tex.textureMatrix, &combo, &outMatrix); + break; + } + case kTexGenEyeLinear: + MultiplyMatrices4x4(&tex.textureMatrix, &worldViewMatrix, &outMatrix); + break; + case kTexGenCubeNormal: + case kTexGenCubeReflect: + { + float invScale = 1.0f / Magnitude (worldMatrix.GetAxisX()); + CopyMatrix(worldViewMatrix.GetPtr(), outMatrix.GetPtr()); + outMatrix.Scale(Vector3f(invScale, invScale, invScale)); + outMatrix.SetPosition(Vector3f::zero); + break; + } + default: + ErrorString( Format("Unknown TexGen mode %d", tex.texGen) ); + } + return true; +} + +void VBOContainsColorGLES30(bool flag) +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + GetGLES30DeviceState(device).vboContainsColor = flag; +} + +void GLSLUseProgramGLES30(UInt32 programID) +{ + GFX_GL_IMPL& device = static_cast<GFX_GL_IMPL&>(GetRealGfxDevice()); + if (GetGLES30DeviceState(device).activeProgramID == programID) + return; + + GLES_CHK(glUseProgram (programID)); + GetGLES30DeviceState(device).activeProgramID = programID; +} + +static void UploadUniformMatrix4(BuiltinShaderParamIndices::MatrixParamData& matParam, const GpuProgramParameters::ConstantBufferList* constantBuffers, const float* dataPtr, ConstantBuffersGLES30& cbs) +{ + Assert(matParam.cols == 4 && matParam.rows == 4); + if (matParam.cbID == -1) + { + GLES_CHK(glUniformMatrix4fv (matParam.gpuIndex, 1, GL_FALSE, dataPtr)); + } + else if (constantBuffers != NULL) + { + for (int i = 0; i < constantBuffers->size(); ++i) + { + if ((*constantBuffers)[i].m_Name.index == matParam.cbID) + { + const GpuProgramParameters::ConstantBuffer& cb = (*constantBuffers)[i]; + int idx = cbs.FindAndBindCB(cb.m_Name.index, cb.m_BindIndex, cb.m_Size); + cbs.SetCBConstant(idx, matParam.gpuIndex, dataPtr, sizeof(Matrix4x4f)); + break; + } + } + } +} + +static void UploadUniformMatrix3(BuiltinShaderParamIndices::MatrixParamData& matParam, const GpuProgramParameters::ConstantBufferList* constantBuffers, const float* dataPtr, ConstantBuffersGLES30& cbs) +{ + Assert(matParam.cols == 3 && matParam.rows == 3); + if (matParam.cbID == -1) + { + GLES_CHK(glUniformMatrix3fv (matParam.gpuIndex, 1, GL_FALSE, dataPtr)); + } + else if (constantBuffers != NULL) + { + for (int i = 0; i < constantBuffers->size(); ++i) + { + if ((*constantBuffers)[i].m_Name.index == matParam.cbID) + { + const GpuProgramParameters::ConstantBuffer& cb = (*constantBuffers)[i]; + int idx = cbs.FindAndBindCB(cb.m_Name.index, cb.m_BindIndex, cb.m_Size); + cbs.SetCBConstant(idx, matParam.gpuIndex, dataPtr, sizeof(Matrix3x3f)); + break; + } + } + } +} + +void GFX_GL_IMPL::BeforeDrawCall(bool immediateMode) +{ + DBG_LOG_GLES30("BeforeDrawCall(%s)", GetBoolString(immediateMode)); + + ShaderLab::PropertySheet *props = ShaderLab::g_GlobalProperties; + Assert(props); + + // WorldView Matrix + STATE.transformState.UpdateWorldViewMatrix (m_BuiltinParamValues); + + // Materials + if (STATE.lighting) + { + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatEmission, Vector4f(STATE.matEmissive.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatAmbient, Vector4f(STATE.matAmbient.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatDiffuse, Vector4f(STATE.matDiffuse.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatSpecular, Vector4f(STATE.matSpecular.GetPtr())); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFMatShininess, Vector4f(STATE.matShininess, STATE.matShininess, STATE.matShininess, STATE.matShininess)); + } + + // Fog + if (m_FogParams.mode > kFogDisabled) + { + float diff = m_FogParams.mode == kFogLinear ? m_FogParams.end - m_FogParams.start : 0.0f; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogColor, m_FogParams.color); + m_BuiltinParamValues.SetVectorParam(kShaderVecFFFogParams, Vector4f(m_FogParams.density * 1.2011224087f, + m_FogParams.density * 1.4426950408f, + m_FogParams.mode == kFogLinear ? -invDiff : 0.0f, + m_FogParams.mode == kFogLinear ? m_FogParams.end * invDiff : 0.0f + )); + } + + // Alpha-test + m_BuiltinParamValues.SetVectorParam(kShaderVecFFAlphaTestRef, Vector4f(STATE.alphaValue, STATE.alphaValue, STATE.alphaValue, STATE.alphaValue)); + + UniformCacheGLES30* targetCache = 0; + const GpuProgramParameters::ConstantBufferList* constantBuffers = NULL; + if (STATE.activeProgram) + { + // Apply GPU program + GlslGpuProgramGLES30& prog = static_cast<GlslGpuProgramGLES30&>(*STATE.activeProgram); + int fogIndex = prog.ApplyGpuProgramES30 (*STATE.activeProgramParams, STATE.activeProgramParamsBuffer.data()); + constantBuffers = &STATE.activeProgramParams->GetConstantBuffers(); + m_BuiltinParamIndices[kShaderVertex] = &STATE.activeProgramParams->GetBuiltinParams(); + + targetCache = &prog.m_UniformCache[fogIndex]; + } + else + { + // Emulate Fixed Function pipe + m_BuiltinParamValues.SetVectorParam(kShaderVecFFColor, Vector4f(STATE.color.GetPtr())); + for (int i = 0; i < STATE.textureCount; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecFFTextureEnvColor0+i), STATE.textures[i].color); + } + + // generate program from fixed function state + DBG_LOG_GLES30(" using fixed-function"); + FixedFunctionStateGLES30 ffstate; + STATE.ComputeFixedFunctionState(ffstate, m_FogParams); + const FixedFunctionProgramGLES30* program = GetFixedFunctionProgram(ffstate); + program->ApplyFFGpuProgram(m_BuiltinParamValues, STATE.m_CBs); + m_BuiltinParamIndices[kShaderVertex] = &program->GetBuiltinParams(); + constantBuffers = &program->GetConstantBuffers(); + + targetCache = &program->m_UniformCache; + } + + // Set Unity built-in parameters + { + Assert(m_BuiltinParamIndices[kShaderVertex]); + const BuiltinShaderParamIndices& params = *m_BuiltinParamIndices[kShaderVertex]; + + // MVP matrix + if (params.mat[kShaderInstanceMatMVP].gpuIndex >= 0) + { + Matrix4x4f wvp; + MultiplyMatrices4x4(&m_BuiltinParamValues.GetMatrixParam(kShaderMatProj), &STATE.transformState.worldViewMatrix, &wvp); + + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatMVP]; + Assert(matParam.rows == 4 && matParam.cols == 4); + UploadUniformMatrix4(matParam, constantBuffers, wvp.GetPtr(), STATE.m_CBs); + } + // MV matrix + if (params.mat[kShaderInstanceMatMV].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatMV]; + Assert(matParam.rows == 4 && matParam.cols == 4); + UploadUniformMatrix4(matParam, constantBuffers, STATE.transformState.worldViewMatrix.GetPtr(), STATE.m_CBs); + } + // Transpose of MV matrix + if (params.mat[kShaderInstanceMatTransMV].gpuIndex >= 0) + { + Matrix4x4f tWV; + TransposeMatrix4x4(&STATE.transformState.worldViewMatrix, &tWV); + + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatTransMV]; + Assert(matParam.rows == 4 && matParam.cols == 4); + UploadUniformMatrix4(matParam, constantBuffers, tWV.GetPtr(), STATE.m_CBs); + } + // Inverse transpose of MV matrix + if (params.mat[kShaderInstanceMatInvTransMV].gpuIndex >= 0) + { + // Inverse transpose of modelview should be scaled by uniform + // normal scale (this will match state.matrix.invtrans.modelview + // and gl_NormalMatrix in OpenGL) + Matrix4x4f mat = STATE.transformState.worldViewMatrix; + if (STATE.normalization == kNormalizationScale) + { + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + mat.Get (0, 0) *= invScale; + mat.Get (1, 0) *= invScale; + mat.Get (2, 0) *= invScale; + mat.Get (0, 1) *= invScale; + mat.Get (1, 1) *= invScale; + mat.Get (2, 1) *= invScale; + mat.Get (0, 2) *= invScale; + mat.Get (1, 2) *= invScale; + mat.Get (2, 2) *= invScale; + } + Matrix4x4f invWV, tInvWV; + Matrix4x4f::Invert_General3D (mat, invWV); + TransposeMatrix4x4(&invWV, &tInvWV); + + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatInvTransMV]; + Assert(matParam.rows == 4 && matParam.cols == 4); + UploadUniformMatrix4(matParam, constantBuffers, tInvWV.GetPtr(), STATE.m_CBs); + } + // M matrix + if (params.mat[kShaderInstanceMatM].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatM]; + const Matrix4x4f& mat = STATE.transformState.worldMatrix; + Assert(matParam.rows == 4 && matParam.cols == 4); + UploadUniformMatrix4(matParam, constantBuffers, mat.GetPtr(), STATE.m_CBs); + } + // Inverse M matrix + if (params.mat[kShaderInstanceMatInvM].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatInvM]; + Matrix4x4f mat = STATE.transformState.worldMatrix; + if (STATE.normalization == kNormalizationScale) + { + // Kill scale in the world matrix before inverse + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + mat.Get (0, 0) *= invScale; + mat.Get (1, 0) *= invScale; + mat.Get (2, 0) *= invScale; + mat.Get (0, 1) *= invScale; + mat.Get (1, 1) *= invScale; + mat.Get (2, 1) *= invScale; + mat.Get (0, 2) *= invScale; + mat.Get (1, 2) *= invScale; + mat.Get (2, 2) *= invScale; + } + Matrix4x4f inverseMat; + Matrix4x4f::Invert_General3D (mat, inverseMat); + Assert(matParam.rows == 4 && matParam.cols == 4); + UploadUniformMatrix4(matParam, constantBuffers, inverseMat.GetPtr(), STATE.m_CBs); + } + + // Normal matrix + if (params.mat[kShaderInstanceMatNormalMatrix].gpuIndex >= 0) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatNormalMatrix]; + + // @TBD: remove normalization in fixed function emulation after Normal matrix multiply. + Matrix4x4f rotWV; + rotWV = STATE.transformState.worldViewMatrix; + rotWV.SetPosition(Vector3f::zero); // reset translation + + if (STATE.normalization == kNormalizationScale) // reset scale + { + float invScale = m_BuiltinParamValues.GetInstanceVectorParam(kShaderInstanceVecScale).w; + rotWV.Get (0, 0) *= invScale; + rotWV.Get (1, 0) *= invScale; + rotWV.Get (2, 0) *= invScale; + rotWV.Get (0, 1) *= invScale; + rotWV.Get (1, 1) *= invScale; + rotWV.Get (2, 1) *= invScale; + rotWV.Get (0, 2) *= invScale; + rotWV.Get (1, 2) *= invScale; + rotWV.Get (2, 2) *= invScale; + } + Matrix3x3f rotWV33 = Matrix3x3f(rotWV); + UploadUniformMatrix3(matParam, constantBuffers, rotWV33.GetPtr(), STATE.m_CBs); + } + + // Set instance vector parameters + for (int i = 0; i < kShaderInstanceVecCount; ++i) + { + int gpuIndexVS = params.vec[i].gpuIndex; + if (gpuIndexVS >= 0) + { + const float* val = m_BuiltinParamValues.GetInstanceVectorParam((ShaderBuiltinInstanceVectorParam)i).GetPtr(); + switch (params.vec[i].dim) { + case 1: CachedUniform1(targetCache, gpuIndexVS, val); break; + case 2: CachedUniform2(targetCache, gpuIndexVS, val); break; + case 3: CachedUniform3(targetCache, gpuIndexVS, val); break; + case 4: CachedUniform4(targetCache, gpuIndexVS, val); break; + } + GLESAssert(); + } + } + + // Texture Matrices + Matrix4x4f texM; + for (int i = 0; i < kMaxSupportedTextureUnitsGLES; ++i) + { + BuiltinShaderParamIndices::MatrixParamData matParam = params.mat[kShaderInstanceMatTexture0 + i]; + if (matParam.gpuIndex >= 0) + { + if (i < STATE.textureCount) + ComputeTextureTransformMatrix(STATE.textures[i], STATE.transformState.worldViewMatrix, STATE.transformState.worldMatrix, texM); + else + texM.SetIdentity(); + + Assert(matParam.rows == 4 && matParam.cols == 4); + UploadUniformMatrix4(matParam, constantBuffers, texM.GetPtr(), STATE.m_CBs); + } + } + } + + // Set per-drawcall properties + GpuProgram* subprogram = STATE.activeProgram; + if (subprogram) + { + const MaterialPropertyBlock::Property* curProp = STATE.m_MaterialProperties.GetPropertiesBegin(); + const MaterialPropertyBlock::Property* propEnd = STATE.m_MaterialProperties.GetPropertiesEnd(); + const float* propBuffer = STATE.m_MaterialProperties.GetBufferBegin(); + while (curProp != propEnd) + { + FastPropertyName name; + name.index = curProp->nameIndex; + const GpuProgramParameters::ValueParameter* param = STATE.activeProgramParams->FindParam(name); + if (param && curProp->rows == param->m_RowCount) + { + if (curProp->rows == 1) + { + const float* src = &propBuffer[curProp->offset]; + switch (param->m_ColCount) { + case 1: CachedUniform1(targetCache, param->m_Index, src); break; + case 2: CachedUniform2(targetCache, param->m_Index, src); break; + case 3: CachedUniform3(targetCache, param->m_Index, src); break; + case 4: CachedUniform4(targetCache, param->m_Index, src); break; + } + GLESAssert(); + } + else if (curProp->rows == 4) + { + DebugAssert(curProp->cols == 4); + const Matrix4x4f* mat = (const Matrix4x4f*)&propBuffer[curProp->offset]; + GLES_CHK(glUniformMatrix4fv (param->m_Index, 1, GL_FALSE, mat->GetPtr())); + } + else + { + AssertString("Unknown property dimensions"); + } + } + ++curProp; + } + } + STATE.m_MaterialProperties.Clear(); + + STATE.m_CBs.UpdateBuffers (); +} + +bool GFX_GL_IMPL::IsPositionRequiredForTexGen(int unit) const +{ + if (unit >= STATE.textureCount) + return false; + if (STATE.activeProgram) + return false; + + //DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits); + const TextureUnitStateGLES3& unitState = STATE.textures[unit]; + return TextureUnitStateGLES3::PositionRequiredForTexGen(unitState.texGen); +} + +bool GFX_GL_IMPL::IsNormalRequiredForTexGen(int unit) const +{ + if (unit >= STATE.textureCount) + return false; + if (STATE.activeProgram) + return false; + + //DebugAssertIf( unit < 0 || unit >= gGraphicsCaps.maxTexUnits ); + const TextureUnitStateGLES3& unitState = STATE.textures[unit]; + return TextureUnitStateGLES3::NormalRequiredForTexGen(unitState.texGen); +} + +bool GFX_GL_IMPL::IsPositionRequiredForTexGen() const +{ + return ( STATE.positionTexGen != 0 && !STATE.activeProgram ); +} + +bool GFX_GL_IMPL::IsNormalRequiredForTexGen() const +{ + return ( STATE.normalTexGen != 0 && !STATE.activeProgram ); +} + +void* GFX_GL_IMPL::GetNativeTexturePointer(TextureID id) +{ + return (void*)TextureIdMap::QueryNativeTexture(id); +} + +void GFX_GL_IMPL::ReloadResources() +{ + // Buffers in BufferManager must be cleared before recreating VBOs. + GetBufferManagerGLES30()->InvalidateAll(); + + RecreateAllVBOs(); + GfxDevice::CommonReloadResources(kReleaseRenderTextures | kReloadShaders | kReloadTextures); + ClearFixedFunctionPrograms(); + + if (STATE.m_fboManager) + STATE.m_fboManager->InvalidateObjects(); + + InvalidateState(); +} + +// GPU skinning functionality +GPUSkinningInfo * GFX_GL_IMPL::CreateGPUSkinningInfo() +{ + if (gGraphicsCaps.gles30.useTFSkinning) + return new TransformFeedbackSkinningInfo(); + else + return 0; +} + +void GFX_GL_IMPL::DeleteGPUSkinningInfo(GPUSkinningInfo *info) +{ + delete reinterpret_cast<TransformFeedbackSkinningInfo *>(info); +} + +// All actual functionality is performed in TransformFeedbackSkinningInfo, just forward the calls +void GFX_GL_IMPL::SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ) +{ + reinterpret_cast<TransformFeedbackSkinningInfo *>(info)->SkinMesh(lastThisFrame); +} + +void GFX_GL_IMPL::UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) +{ + reinterpret_cast<TransformFeedbackSkinningInfo *>(info)->UpdateSourceData(vertData, skinData, dirty); +} + +void GFX_GL_IMPL::UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) +{ + reinterpret_cast<TransformFeedbackSkinningInfo *>(info)->UpdateSourceBones(boneCount, poses); +} + +// Acquire thread ownership on the calling thread. Worker releases ownership. +void GFX_GL_IMPL::AcquireThreadOwnership() +{ + AcquireGLES30Context(); +} + +// Release thread ownership on the calling thread. Worker acquires ownership. +void GFX_GL_IMPL::ReleaseThreadOwnership() +{ + ReleaseGLES30Context(); +} + + + +// ---------- verify state +#if GFX_DEVICE_VERIFY_ENABLE +void GFX_GL_IMPL::VerifyState() +{ +} + +#endif // GFX_DEVICE_VERIFY_ENABLE + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/GfxDeviceGLES30.h b/Runtime/GfxDevice/opengles30/GfxDeviceGLES30.h new file mode 100644 index 0000000..dfc716b --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GfxDeviceGLES30.h @@ -0,0 +1,191 @@ +#pragma once + +#if GFX_DEVICE_VIRTUAL + +#ifdef GFX_GL_IMPL +#undef GFX_GL_IMPL +#endif +#define GFX_GL_IMPL GfxDeviceGLES30 + +class GFX_GL_IMPL : public GfxThreadableDevice { +public: + GFX_GL_IMPL(); + GFX_API ~GFX_GL_IMPL(); + + GFX_API void InvalidateState(); + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState(); + #endif + + GFX_API void Clear (UInt32 clearFlags, const float color[4], float depth, int stencil); + GFX_API void SetUserBackfaceMode( bool enable ); + GFX_API void SetWireframe(bool wire) { } // not possible in GLES + GFX_API bool GetWireframe() const { return false; } // not possible in GLES + GFX_API void SetInvertProjectionMatrix( bool enable ); + GFX_API bool GetInvertProjectionMatrix() const; + + GFX_API void SetWorldMatrix( const float matrix[16] ); + GFX_API void SetViewMatrix( const float matrix[16] ); + + GFX_API void SetProjectionMatrix (const Matrix4x4f& matrix); + GFX_API void GetMatrix( float outMatrix[16] ) const; + + GFX_API const float* GetWorldMatrix() const ; + GFX_API const float* GetViewMatrix() const; + GFX_API const float* GetProjectionMatrix() const; + GFX_API const float* GetDeviceProjectionMatrix() const; + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ); + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ); + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ); + GFX_API void SetColor( const float color[4] ); + GFX_API void SetViewport( int x, int y, int width, int height ); + GFX_API void GetViewport( int* values ) const; + + GFX_API void SetScissorRect( int x, int y, int width, int height ); + GFX_API void DisableScissor(); + GFX_API bool IsScissorEnabled() const; + GFX_API void GetScissorRect( int values[4] ) const; + GFX_API void SetSRGBWrite (const bool); + GFX_API bool GetSRGBWrite (); + + GFX_API void ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle); + + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ); + GFX_API void SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ); + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias); + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]); + GFX_API void SetTextureName ( TextureID texture, const char* name ) { } + + GFX_API void SetMaterialProperties( const MaterialPropertyBlock& block ); + + GFX_API void SetShadersThreadable (GpuProgram* programs[kShaderTypeCount], const GpuProgramParameters* params[kShaderTypeCount], UInt8 const * const paramsBuffer[kShaderTypeCount]); + GFX_API void CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ); + + GFX_API bool IsCombineModeSupported( unsigned int combiner ); + GFX_API void SetTextureCombinersThreadable( TextureCombinersHandle textureCombiners, const TexEnvData* texEnvData, const Vector4f* texColors ); + + GFX_API bool IsShaderActive( ShaderType type ) const; + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ); + GFX_API void SetConstantBufferInfo( int id, int size ); + + GFX_API void DisableLights( int startLight ); + GFX_API void SetLight( int light, const GfxVertexLight& data); + GFX_API void SetAmbient( const float ambient[4] ); + + GFX_API void EnableFog (const GfxFogParams& fog); + GFX_API void DisableFog(); + + GFX_API VBO* CreateVBO(); + GFX_API void DeleteVBO( VBO* vbo ); + GFX_API DynamicVBO& GetDynamicVBO(); + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags); + GFX_API RenderSurfaceHandle CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags); + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face = kCubeFaceUnknown); + GFX_API void DestroyRenderSurface (RenderSurfaceHandle& rs); + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle); + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface (int index); + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface (); + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags); + GFX_API void DiscardContents (RenderSurfaceHandle& rs); + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ); + GFX_API void DeleteTexture( TextureID texture ); + + GFX_API PresentMode GetPresentMode(); + + GFX_API void BeginFrame(); + GFX_API void EndFrame(); + GFX_API void PresentFrame(); + + GFX_API bool IsValidState(); + GFX_API bool HandleInvalidState(); + + GFX_API void FinishRendering(); + + // Immediate mode rendering + GFX_API void ImmediateVertex( float x, float y, float z ); + GFX_API void ImmediateNormal( float x, float y, float z ); + GFX_API void ImmediateColor( float r, float g, float b, float a ); + GFX_API void ImmediateTexCoordAll( float x, float y, float z ); + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ); + GFX_API void ImmediateBegin( GfxPrimitiveType type ); + GFX_API void ImmediateEnd(); + + // Acquire thread ownership on the calling thread. Worker releases ownership. + GFX_API void AcquireThreadOwnership(); + // Release thread ownership on the calling thread. Worker acquires ownership. + GFX_API void ReleaseThreadOwnership(); + + protected: + + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ); + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); + GFX_API void GrabIntoRenderTexture( RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height ); + + GFX_API void BeforeDrawCall( bool immediateMode); + + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef); + GFX_API void SetRasterState(const DeviceRasterState* state); + GFX_API void SetDepthState(const DeviceDepthState* state); + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef); + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state); + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state); + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state); + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state); + + GFX_API GPUSkinningInfo *CreateGPUSkinningInfo(); + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info); + GFX_API void SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ); + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty); + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses); + +#if ENABLE_PROFILER + GFX_API void BeginProfileEvent (const char* name); + GFX_API void EndProfileEvent (); + + GFX_API GfxTimerQuery* CreateTimerQuery(); + GFX_API void DeleteTimerQuery(GfxTimerQuery* query); + GFX_API void BeginTimerQueries(); + GFX_API void EndTimerQueries(); +#endif + +public: + // OpenGLES specific + GFX_API void ReloadResources(); + GFX_API bool IsPositionRequiredForTexGen(int texStageIndex) const; + GFX_API bool IsNormalRequiredForTexGen(int texStageIndex) const; + + GFX_API bool IsPositionRequiredForTexGen() const; + GFX_API bool IsNormalRequiredForTexGen() const; + + GFX_API void* GetNativeTexturePointer(TextureID id); + + DeviceStateGLES30& GetState() { return state; } + +private: + DeviceStateGLES30 state; +}; + +#define STATE this->state +#define GetGLES30DeviceState(device) device.GetState() + +#else // GFX_DEVICE_VIRTUAL + + +struct GfxDeviceImpl { + DeviceStateGLES30 state; +}; + +#define STATE impl->state +#define GetGLES30DeviceState(device) device.GetImpl()->state + +#endif // GFX_DEVICE_VIRTUAL diff --git a/Runtime/GfxDevice/opengles30/GpuProgramsGLES30.cpp b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30.cpp new file mode 100644 index 0000000..42d468f --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30.cpp @@ -0,0 +1,1176 @@ +#include "UnityPrefix.h" +#if GFX_SUPPORTS_OPENGLES30 +#include "GpuProgramsGLES30.h" +#include "Runtime/Utilities/LogAssert.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Utilities/File.h" +#include "Runtime/File/ApplicationSpecificPersistentDataPath.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "External/shaderlab/Library/ShaderLabErrors.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/program.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/Math/Matrix3x3.h" +#include "Runtime/Math/Vector4.h" + + +#include "IncludesGLES30.h" +#include "AssertGLES30.h" +#include "GpuPropertiesGLES30.h" +#include "Runtime/Utilities/GLSLUtilities.h" +#include "VBOGLES30.h" +#include "ConstantBuffersGLES30.h" +#include "DebugGLES30.h" + +#if UNITY_ANDROID + #include "PlatformDependent/AndroidPlayer/EntryPoint.h" + #include "PlatformDependent/AndroidPlayer/AndroidSystemInfo.h" +#endif + +#if UNITY_BLACKBERRY + #include "ctype.h" +#endif + + +#include <stdio.h> + +#define DEBUG_GLSL_BINDINGS 0 +#define DEBUG_SHADER_CACHE 0 + + +// from shader_yacc.hpp +extern std::string g_LastParsedShaderName; + +void GLSLUseProgramGLES30 (UInt32 programID); // defined in GfxDeviceGLES30.cpp + +static bool CompileGLSLVertexShader (const std::string& source, ChannelAssigns& channels, GLShaderID programID, GLShaderID parentProgramID, GLShaderID* outShaderID); +static bool CompileGLSLFragmentShader (const std::string& source, GLShaderID* outShaderID); +static bool BindVProgAttrbutes(const std::string& source, ChannelAssigns& channels, GLShaderID programID); +static bool RebindVProgAttrbutes(GLShaderID programID, GLShaderID parentProgramID); + + +static void GetCachedBinaryName(const std::string& vprog, const std::string& fshader, char filename[33]); + + +// -------------------------------------------------------------------------- +// GLSL + +// AttributeConversionTable +const static UInt32 kAttribLookupTableSize = 12; + +const static char* s_GLSLESAttributes[kAttribLookupTableSize] = { + "_glesVertex", "_glesColor", "_glesNormal", + "_gles_unused__", // unused + "_glesMultiTexCoord0", "_glesMultiTexCoord1", "_glesMultiTexCoord2", "_glesMultiTexCoord3", + "_glesMultiTexCoord4", "_glesMultiTexCoord5", "_glesMultiTexCoord6", "_glesMultiTexCoord7" +}; +const static char* s_UnityAttributes[kAttribLookupTableSize] = { + "Vertex", "Color", "Normal", + "", // unused + "TexCoord", "TexCoord1", "TexCoord2", "TexCoord3", + "TexCoord4", "TexCoord5", "TexCoord6", "TexCoord7" +}; + + +const VertexComponent s_UnityVertexComponents[kAttribLookupTableSize] = { + kVertexCompVertex, + kVertexCompColor, + kVertexCompNormal, + kVertexCompTexCoord, + kVertexCompTexCoord0, kVertexCompTexCoord1, kVertexCompTexCoord2, kVertexCompTexCoord3, + kVertexCompTexCoord4, kVertexCompTexCoord5, kVertexCompTexCoord6, kVertexCompTexCoord7 +}; + +const int s_GLESVertexComponents[kAttribLookupTableSize] = { + kGLES3AttribLocationPosition, + kGLES3AttribLocationColor, + kGLES3AttribLocationNormal, + -1 /*kVertexCompTexCoord*/, + kGLES3AttribLocationTexCoord0, + kGLES3AttribLocationTexCoord1, + kGLES3AttribLocationTexCoord2, + kGLES3AttribLocationTexCoord3, + kGLES3AttribLocationTexCoord4, + kGLES3AttribLocationTexCoord5, + kGLES3AttribLocationTexCoord6, + kGLES3AttribLocationTexCoord7, +}; + +GlslGpuProgramGLES30::GlslGpuProgramGLES30 (const std::string& source, CreateGpuProgramOutput& output) +{ + output.SetPerFogModeParamsEnabled(true); + m_ImplType = kShaderImplBoth; + for (int i = 0; i < kFogModeCount; ++i) + { + m_GLSLVertexShader[i] = 0; + m_GLSLFragmentShader[i] = 0; + m_FogColorIndex[i] = -1; + m_FogParamsIndex[i] = -1; + m_FogFailed[i] = false; + } + + // Fragment shaders come out as dummy GLSL text. Just ignore them; the real shader was part of + // the vertex shader text anyway. + if (source.empty()) + return; + + if (Create (source, output.CreateChannelAssigns())) + { + GpuProgramParameters& params = output.CreateParams (); + FillParams (m_Programs[kFogDisabled], params, output.GetOutNames()); + if (params.GetTextureParams().size() > gGraphicsCaps.maxTexImageUnits) + m_NotSupported = true; + + m_UniformCache[kFogDisabled].Create(¶ms, -1, -1); + } + else + { + m_NotSupported = true; + } +} + +GlslGpuProgramGLES30::~GlslGpuProgramGLES30 () +{ + Assert (m_ImplType == kShaderImplBoth); + for (int i = 0; i < kFogModeCount; ++i) + { + if (m_GLSLVertexShader[i]) { GLES_CHK(glDeleteShader(m_GLSLVertexShader[i])); } + if (m_GLSLFragmentShader[i]) { GLES_CHK(glDeleteShader(m_GLSLFragmentShader[i])); } + if (m_Programs[i]) { GLES_CHK(glDeleteProgram(m_Programs[i])); } + m_UniformCache[i].Destroy(); + } +} + +static bool ParseGlslErrors (GLuint type , GLSLErrorType errorType, const char* source = 0) +{ + bool hadErrors = false; + char compileInfoLog[4096]; + GLsizei infoLogLength = 0; + switch(errorType) + { + case kErrorCompileVertexShader: + case kErrorCompileFragShader: + glGetShaderInfoLog(type, 4096, &infoLogLength, compileInfoLog ); + break; + case kErrorLinkProgram: + glGetProgramInfoLog(type, 4096, &infoLogLength, compileInfoLog ); + break; + default: + FatalErrorMsg("Unknown error type"); + break; + } + + // Make sure it is null-terminated + compileInfoLog[std::min<int>(infoLogLength, 4096)] = 0; + + if (strlen (compileInfoLog) > 0) + { + hadErrors = true; + if (source) + { + printf_console("-------- GLSL source: \n"); + DebugTextLineByLine(source); + } + + printf_console("-------- GLSL error:\n%s\n\n", compileInfoLog); + } + + return hadErrors; +} + +static std::string ExtractDefineBock(const std::string& defineName, const std::string& str, std::string* remainderStr) +{ + const std::string beginsWith = "#ifdef " + defineName; + const std::string endsWith = "#endif"; + + size_t b; + if ((b = str.find(beginsWith))==std::string::npos) + return ""; + + b += beginsWith.size(); + + size_t e = b; + size_t n = 1; + do + { + size_t nextEnd = str.find(endsWith, e); + size_t nextIf = str.find("#if", e); + + if (nextEnd == std::string::npos) + return ""; + + if (nextIf != std::string::npos && nextIf < nextEnd) + { + ++n; + e = nextIf + 1; + } + else + { + --n; + e = nextEnd + 1; + } + } + while (n > 0); + + std::string retVal = str.substr(b, e-b-1); + if (remainderStr) + { + *remainderStr = str.substr(0, b - beginsWith.size()); + if (e + endsWith.size() < str.length()) *remainderStr += str.substr(e + endsWith.size()); + } + + return retVal; +} + +static void FindProgramStart(const char* source, std::string* header, std::string* prog) +{ + const char* line_start = source; + while(*line_start) + { + while(isspace(*line_start)) + ++line_start; + if(*line_start == '#') + { + while(*line_start != '\n' && *line_start != '\r') + ++line_start; + } + else + { + header->assign(source, line_start - source); + prog->assign(line_start); + break; + } + } +} + +bool GlslGpuProgramGLES30::CompileGlslShader(GLShaderID shader, const char* source) +{ + GLES_CHK(glShaderSource(shader, 1, &source, NULL)); + GLES_CHK(glCompileShader(shader)); + + int compiled = 10; + GLES_CHK(glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled)); + + if (compiled==0) + { + ParseGlslErrors(shader, kErrorCompileFragShader, source); + return false; + } + + return true; +} + +bool GlslGpuProgramGLES30::Create (const std::string &shaderString, ChannelAssigns& channels) +{ + GLESAssert(); // Clear any GL errors + + GLES_CHK(m_Programs[0] = glCreateProgram()); + + m_ImplType = kShaderImplBoth; + + // NOTE: pre-pending shader with VERTEX/FRAGMENT defines doesn't work with ES/GLSL compilers for some reason + // therefore we extract VERTEX/FRAGMENT sections from the shaderString + + std::string remainder = shaderString; + std::string vertexShaderSource = ExtractDefineBock("VERTEX", shaderString, &remainder); + std::string fragmentShaderSource = ExtractDefineBock("FRAGMENT", remainder, &remainder); + + vertexShaderSource = remainder + vertexShaderSource; + fragmentShaderSource = remainder + fragmentShaderSource; + + if(!CompileProgram(0, vertexShaderSource, fragmentShaderSource, channels)) + { + ParseGlslErrors( m_Programs[0], kErrorLinkProgram ); + + int charsWritten=0; + + if(m_GLSLVertexShader[0]) + { + int vertShaderLength = 0; + GLES_CHK(glGetShaderiv(m_GLSLVertexShader[0], GL_SHADER_SOURCE_LENGTH, &vertShaderLength)); + char* modVertexShader = new char[vertShaderLength]; + GLES_CHK(glGetShaderSource(m_GLSLVertexShader[0], vertShaderLength, &charsWritten, modVertexShader)); + + #if UNITY_WIN + OutputDebugString(Format("Vertex Shader:\n%s\n", modVertexShader).c_str()); + #else + ::printf_console("Vertex Shader:\n"); + DebugTextLineByLine(modVertexShader); + #endif + + delete[] modVertexShader; + } + + if(m_GLSLFragmentShader[0]) + { + int fragShaderLength = 0; + GLES_CHK(glGetShaderiv(m_GLSLFragmentShader[0], GL_SHADER_SOURCE_LENGTH, &fragShaderLength)); + char* modFragmentShader = new char[fragShaderLength]; + GLES_CHK(glGetShaderSource(m_GLSLFragmentShader[0], fragShaderLength, &charsWritten, modFragmentShader)); + + #if UNITY_WIN + OutputDebugString(Format("Fragment Shader:\n%s\n", modFragmentShader).c_str()); + #else + ::printf_console("Vertex Shader:\n"); + DebugTextLineByLine(modFragmentShader); + #endif + + delete[] modFragmentShader; + } + + // TODO: cleanup + return false; + } + + m_VertexShaderSourceForFog = vertexShaderSource; + m_SourceForFog = fragmentShaderSource; + + return true; +} + +// \todo [2013-04-17 pyry] Uh... +std::string GlslGpuProgramGLES30::_CachePath; + +bool GlslGpuProgramGLES30::InitBinaryShadersSupport() +{ + if (gGraphicsCaps.gles30.useProgramBinary) + { + int binFormatCount = 0; + GLES_CHK(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS_OES, &binFormatCount)); + + if(binFormatCount > 0) + { + _CachePath = GetPersistentDataPathApplicationSpecific() + "/shader/"; + if(!IsDirectoryCreated(_CachePath)) + CreateDirectory(_CachePath); + + return true; + } + } + + return false; +} + +static void Internal_ClearShaderCache() +{ + std::string shaderCache = GetPersistentDataPathApplicationSpecific() + "/shader/"; + DeleteFileOrDirectory(shaderCache); + CreateDirectory(shaderCache); +} + +bool GlslGpuProgramGLES30::CompileProgram(unsigned index, const std::string& vprog, const std::string& fshader, ChannelAssigns& channels) +{ + std::string binaryPath; + + if (gGraphicsCaps.gles30.useProgramBinary) + { + char filename[33] = {0}; + GetCachedBinaryName(vprog, fshader, filename); + + binaryPath = _CachePath + filename; + #if DEBUG_SHADER_CACHE + ::printf_console("Starting compilation \"%s\" variation with md5:%s\n", g_LastParsedShaderName.c_str(), filename); + #endif + } + + // first 4 bytes are for binary format + char* binaryData = 0; + char* binaryProgram = 0; + unsigned binaryLength = 0; + + bool loadedBinary = false; + if (gGraphicsCaps.gles30.useProgramBinary) + { + FILE* binaryFile = ::fopen(binaryPath.c_str(), "rb"); + if(binaryFile) + { + ::fseek(binaryFile, 0, SEEK_END); + unsigned datasz = (unsigned)::ftell(binaryFile); + ::fseek(binaryFile, 0, SEEK_SET); + + binaryData = (char*)::malloc(datasz); + binaryProgram = binaryData + sizeof(GLenum); + binaryLength = datasz - sizeof(GLenum); + ::fread(binaryData, datasz, 1, binaryFile); + ::fclose(binaryFile); + + loadedBinary = true; + #if DEBUG_SHADER_CACHE + ::printf_console("Loaded from cache"); + #endif + } + } + + if(loadedBinary) + { + loadedBinary = false; + + bool attrBound = index==0 ? BindVProgAttrbutes(vprog, channels, m_Programs[0]) + : RebindVProgAttrbutes(m_Programs[index], m_Programs[0]); + if(attrBound) + { + GLES_CHK(glProgramBinary(m_Programs[index], *((GLenum*)binaryData), binaryProgram, binaryLength)); + + int linked = 0; + GLES_CHK(glGetProgramiv(m_Programs[index], GL_LINK_STATUS, &linked)); + loadedBinary = linked != 0; + } + + if(!loadedBinary) + { + #if DEBUG_SHADER_CACHE + ::printf_console("Bad cached version\n"); + #endif + + ::free(binaryData); + binaryProgram = binaryData = 0; + } + } + + // fallback to compiling shaders at runtime + if(!loadedBinary) + { + DBG_SHADER_VERBOSE_GLES30("Compiling shader: %s\n", g_LastParsedShaderName.c_str()); + #if DEBUG_SHADER_CACHE + ::printf_console("Actually compiling"); + #endif + + if(!CompileGLSLVertexShader(vprog, channels, m_Programs[index], m_Programs[0], &m_GLSLVertexShader[index])) + return false; + if(!CompileGLSLFragmentShader(fshader, &m_GLSLFragmentShader[index])) + return false; + + GLES_CHK(glAttachShader(m_Programs[index], m_GLSLVertexShader[index])); + GLES_CHK(glAttachShader(m_Programs[index], m_GLSLFragmentShader[index])); + GLES_CHK(glLinkProgram(m_Programs[index])); + + int linked = 0; + GLES_CHK(glGetProgramiv(m_Programs[index], GL_LINK_STATUS, &linked)); + if(linked == 0) + return false; + + if (gGraphicsCaps.gles30.useProgramBinary) + { + Assert(binaryData == 0 && binaryProgram == 0); + + GLES_CHK(glGetProgramiv(m_Programs[index], GL_PROGRAM_BINARY_LENGTH_OES, (GLint*)&binaryLength)); + binaryData = (char*)::malloc(binaryLength + sizeof(GLenum)); + binaryProgram = binaryData + sizeof(GLenum); + GLES_CHK(glGetProgramBinary(m_Programs[index], binaryLength, 0, (GLenum*)binaryData, binaryProgram)); + + FILE* binaryFile = ::fopen(binaryPath.c_str(), "wb"); + if(binaryFile) + { + ::fwrite(binaryData, binaryLength + sizeof(GLenum), 1, binaryFile); + ::fclose(binaryFile); + + #if DEBUG_SHADER_CACHE + ::printf_console("Saved to cache\n"); + #endif + } + } + } + + if(binaryData) + ::free(binaryData); + + return true; +} + + + +static void PrintNumber (char* s, int i, bool brackets) +{ + DebugAssert (i >= 0 && i < 100); + if (brackets) + *s++ = '['; + + if (i < 10) { + *s++ = '0' + i; + } else { + *s++ = '0' + i/10; + *s++ = '0' + i%10; + } + + if (brackets) + *s++ = ']'; + *s++ = 0; +} + +static void AddSizedVectorParam (GpuProgramParameters& params, ShaderParamType type, GLuint program, int vectorSize, int uniformNumber, int arraySize, const char* unityName, char* glName, int glNameIndexOffset, PropertyNamesSet* outNames) +{ + if (arraySize <= 1) + { + params.AddVectorParam (uniformNumber, type, vectorSize, unityName, -1, outNames); + } + else + { + for (int j = 0; j < arraySize; ++j) + { + PrintNumber (glName+glNameIndexOffset, j, true); + uniformNumber = glGetUniformLocation (program, glName); + PrintNumber (glName+glNameIndexOffset, j, false); + params.AddVectorParam (uniformNumber, type, vectorSize, glName, -1, outNames); + } + } +} + +static void AddSizedMatrixParam (GpuProgramParameters& params, GLuint program, int rows, int cols, int uniformNumber, int arraySize, const char* unityName, char* glName, int glNameIndexOffset, PropertyNamesSet* outNames) +{ + if (arraySize <= 1) + { + params.AddMatrixParam (uniformNumber, unityName, rows, cols, -1, outNames); + } + else + { + for (int j = 0; j < arraySize; ++j) + { + PrintNumber (glName+glNameIndexOffset, j, true); + uniformNumber = glGetUniformLocation (program, glName); + PrintNumber (glName+glNameIndexOffset, j, false); + params.AddMatrixParam (uniformNumber, glName, rows, cols, -1, outNames); + } + } +} + + +void GlslGpuProgramGLES30::FillParams (unsigned int programID, GpuProgramParameters& params, PropertyNamesSet* outNames) +{ + if (!programID) + return; + + int activeUniforms; + + char name[1024]; + GLenum type; + int arraySize = 0, + nameLength = 0, + bufSize = sizeof(name); + + DBG_LOG_GLES30("GLSL: apply params to program id=%i\n", programID); + GLSLUseProgramGLES30 (programID); + + // Figure out the uniforms + GLES_CHK(glGetProgramiv (programID, GL_ACTIVE_UNIFORMS, &activeUniforms)); + for(int i=0; i < activeUniforms; i++) + { + GLES_CHK(glGetActiveUniform (programID, i, bufSize, &nameLength, &arraySize, &type, name)); + + if (!strcmp (name, "_unity_FogParams") || !strcmp(name, "_unity_FogColor")) + continue; + + // some Unity builtin properties are mapped to GLSL structure fields + // hijack them here + const char* glslName = GetGLSLES3PropertyNameRemap(name); + const char* unityName = glslName ? glslName : name; + + if (!strncmp (name, "gl_", 3)) // skip "gl_" names + continue; + + int uniformNumber = glGetUniformLocation (programID, name); + Assert(uniformNumber != -1); + + char* glName = name; + int glNameIndexOffset = 0; + + bool isElemZero = false; + bool isArray = IsShaderParameterArray(name, nameLength, arraySize, &isElemZero); + if (isArray) + { + // for array parameters, transform name a bit: Foo[0] becomes Foo0 + if (arraySize >= 100) { + ErrorString( "GLSL: array sizes larger than 99 not supported" ); // TODO: SL error + arraySize = 99; + } + // TODO: wrong? what if we use only array[1] for example + if (isElemZero) + { + glNameIndexOffset = nameLength-3; + if(glNameIndexOffset < 0) + glNameIndexOffset = 0; + glName[glNameIndexOffset] = '0'; + glName[glNameIndexOffset+1] = 0; + } + else + { + glNameIndexOffset = nameLength; + } + } + + if(type == GL_FLOAT) { + AddSizedVectorParam (params, kShaderParamFloat, programID, 1, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + } + else if(type == GL_FLOAT_VEC2) { + AddSizedVectorParam (params, kShaderParamFloat, programID, 2, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + } + else if(type == GL_FLOAT_VEC3) { + AddSizedVectorParam (params, kShaderParamFloat, programID, 3, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + } + else if(type == GL_FLOAT_VEC4) { + AddSizedVectorParam (params, kShaderParamFloat, programID, 4, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + } + else if(type == GL_FLOAT_MAT4) { + AddSizedMatrixParam (params, programID, 4, 4, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + } + else if(type == GL_FLOAT_MAT3) { + AddSizedMatrixParam (params, programID, 3, 3, uniformNumber, arraySize, unityName, glName, glNameIndexOffset, outNames); + } + + else if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_SHADOW) { + GLES_CHK(glUniform1i (uniformNumber, params.GetTextureParams().size())); + params.AddTextureParam (uniformNumber, -1, unityName, kTexDim2D, outNames); + } + else if (type == GL_SAMPLER_CUBE || type == GL_SAMPLER_CUBE_SHADOW) { + GLES_CHK(glUniform1i (uniformNumber, params.GetTextureParams().size())); + params.AddTextureParam (uniformNumber, -1, unityName, kTexDimCUBE, outNames); + } + /* + else if(type == GL_SAMPLER_3D) { + GLES_CHK(glUniform1i (uniformNumber, params.GetTextureParams().size())); + params.AddTextureParam( name, kTexDim3D, uniformNumber ); + } + else if(type == GL_SAMPLER_2D_SHADOW) { + GLES_CHK(glUniform1i (uniformNumber, params.GetTextureParams().size())); + params.AddTextureParam( name, kTexDim2D, uniformNumber ); + } + + */ + else { + AssertString( "Unrecognized GLSL uniform type" ); + } + } + + GLESAssert(); +} + +static bool RebindVProgAttrbutes(GLShaderID programID, GLShaderID parentProgramID) +{ + int attribCount = 0; + GLES_CHK(glGetProgramiv(parentProgramID, GL_ACTIVE_ATTRIBUTES, &attribCount)); + + const int kBufSize = 256; + char name[kBufSize]; + for(int i = 0 ; i < attribCount ; ++i) + { + int nameLength = 0, arraySize = 0; + GLenum type; + GLES_CHK(glGetActiveAttrib (parentProgramID, i, kBufSize, &nameLength, &arraySize, &type, name)); + int location = glGetAttribLocation (parentProgramID, name); + if (location != -1) + GLES_CHK(glBindAttribLocation(programID, location, name)); + } + + return true; +} + +static bool BindVProgAttrbutes(const std::string& source, ChannelAssigns& channels, GLShaderID programID) +{ + // Add necessary attribute tags + for (UInt32 j = 0; j < kAttribLookupTableSize; j++) + { + if (source.find(s_GLSLESAttributes[j]) != std::string::npos) + { + if (s_GLESVertexComponents[j] >= gGraphicsCaps.gles30.maxAttributes) + { + ErrorString("Shader uses too many vertex attributes for this platform"); + return false; + } + GLES_CHK(glBindAttribLocation(programID, s_GLESVertexComponents[j], s_GLSLESAttributes[j])); + ShaderChannel shaderChannel = GetShaderChannelFromName(s_UnityAttributes[j]); + if( shaderChannel != kShaderChannelNone ) + channels.Bind (shaderChannel, s_UnityVertexComponents[j]); + } + } + + // UGLY HACK: + // somewhere deep inside shader generation we just put attribute TANGENT + // without ever using it after + // look for TANGENT twice to be sure we use it + size_t firstTangentUsage = source.find("TANGENT"); + if( firstTangentUsage != std::string::npos && source.find("TANGENT", firstTangentUsage+1) != std::string::npos ) + { + // Find first free slot for tangents and use it. + // Unity normally supports 2 UV slots (0&1), so start looking from + // kVertexTexCoord2 + for (int i = kVertexCompTexCoord2; i < kVertexCompTexCoord7; i++) + { + if (channels.GetSourceForTarget((VertexComponent)i) == kShaderChannelNone) + { + channels.Bind (kShaderChannelTangent, (VertexComponent)i); + GLES_CHK(glBindAttribLocation(programID, kGLES3AttribLocationTexCoord0 + i - kVertexCompTexCoord0, "_glesTANGENT")); + break; + } + } + } + + return true; +} + +static bool CompileGLSLVertexShader (const std::string& source, ChannelAssigns& channels, GLShaderID programID, GLShaderID parentProgramID, GLShaderID* outShaderID) +{ + GLES_CHK(*outShaderID = glCreateShader(GL_VERTEX_SHADER)); + + if(parentProgramID == programID) + BindVProgAttrbutes(source, channels, programID); + else + RebindVProgAttrbutes(programID, parentProgramID); + + const char* text = source.c_str(); + DBG_SHADER_VERBOSE_GLES30_DUMP_SHADER("Compiling VERTEX program:", text); + + if (GlslGpuProgramGLES30::CompileGlslShader(*outShaderID, text)) + return true; + + printf_console ("GLES30: failed to compile vertex shader:\n%s\n", text); + + // TODO: cleanup + return false; +} + +static bool CompileGLSLFragmentShader (const std::string& source, GLShaderID* outShaderID) +{ + *outShaderID = glCreateShader(GL_FRAGMENT_SHADER); + + ///@TODO: find any existing precision statement + + std::string modSourceHeader, modSourceProg; + FindProgramStart(source.c_str(), &modSourceHeader, &modSourceProg); + + // \todo [2013-04-17 pyry] Should we default to highp or mediump? + std::string modSource = modSourceHeader + + std::string("precision highp float;\n") + + modSourceProg; + + const char* text = modSource.c_str(); + DBG_SHADER_VERBOSE_GLES30_DUMP_SHADER("Compiling FRAGMENT program:", text); + + if (GlslGpuProgramGLES30::CompileGlslShader(*outShaderID, text)) + return true; + + printf_console ("GLES30: failed to compile fragment shader:\n%s\n", text); + + // TODO: cleanup + return false; +} + +int GlslGpuProgramGLES30::GetGLProgram (FogMode fog, GpuProgramParameters& outParams, ChannelAssigns &channels) +{ + int index = 0; + if (fog > kFogDisabled && !m_FogFailed[fog] && !m_SourceForFog.empty()) + { + index = fog; + Assert (index >= 0 && index < kFogModeCount); + + // create patched fog program if needed + if(!m_Programs[index]) + { + std::string srcVS = m_VertexShaderSourceForFog; + std::string srcPS = m_SourceForFog; + + if(PatchShaderFogGLES (srcVS, srcPS, fog, CanUseOptimizedFogCodeGLES(srcVS))) + { + // create program, shaders, link + GLES_CHK(m_Programs[index] = glCreateProgram()); + ShaderErrors errors; + if(CompileProgram(index, srcVS, srcPS, channels)) + { + FillParams (m_Programs[index], outParams, NULL); + m_FogParamsIndex[index] = glGetUniformLocation(m_Programs[index], "_unity_FogParams"); + m_FogColorIndex[index] = glGetUniformLocation(m_Programs[index], "_unity_FogColor"); + + m_UniformCache[index].Create(&outParams, m_FogParamsIndex[index], m_FogColorIndex[index]); + } + else + { + if(m_GLSLVertexShader[index]) + glDeleteShader(m_GLSLVertexShader[index]); + + if(m_GLSLFragmentShader[index]) + glDeleteShader(m_GLSLFragmentShader[index]); + + m_GLSLVertexShader[index] = 0; + m_GLSLFragmentShader[index] = 0; + + glDeleteProgram(m_Programs[index]); + m_Programs[index] = 0; + + m_FogFailed[index] = true; + index = 0; + } + } + else + { + m_FogFailed[index] = true; + index = 0; + } + } + } + return index; +} + +int GlslGpuProgramGLES30::ApplyGpuProgramES30 (const GpuProgramParameters& params, const UInt8 *buffer) +{ + DBG_LOG_GLES30("GlslGpuProgramGLES30::ApplyGpuProgramES30()"); + + // m_Programs[0] == 0, is when Unity tries to build a dummy shader with empty source for fragment shaders, do nothing in this case + if (m_Programs[0] == 0) + return 0; + + GfxDevice& device = GetRealGfxDevice(); + + const GfxFogParams& fog = device.GetFogParams(); + const int index = (int)fog.mode; + + DBG_LOG_GLES30("GLSL: apply program id=%i\n", m_Programs[index]); + GLSLUseProgramGLES30 (m_Programs[index]); + + // Apply value parameters + const GpuProgramParameters::ValueParameterArray& valueParams = params.GetValueParams(); + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for( GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i ) + { + if (i->m_RowCount == 1 && i->m_ArraySize == 1) + { + UniformCacheGLES30* cache = m_UniformCache+index; +// const float* val = i->m_ColCount == 1 ? &ShaderLab::shaderprops::GetFloat(props, i->m_Name) +// : ShaderLab::shaderprops::GetVector(props, i->m_Name).GetPtr(); + const float * val = reinterpret_cast<const float*>(buffer); + + switch (i->m_ColCount) + { + case 1: CachedUniform1(cache, i->m_Index, val); break; + case 2: CachedUniform2(cache, i->m_Index, val); break; + case 3: CachedUniform3(cache, i->m_Index, val); break; + case 4: CachedUniform4(cache, i->m_Index, val); break; + default: break; + } + + #if DEBUG_GLSL_BINDINGS + ;;printf_console(" vector %i dim=%i\n", i->m_Index, i->m_Dim ); + #endif + + buffer += 4*sizeof(float); + } + else + { + // Apply matrix parameters + DebugAssert (i->m_ArraySize == 1); + int size = *reinterpret_cast<const int*>(buffer); buffer += sizeof(int); + Assert (size == 16); + const Matrix4x4f* mat = reinterpret_cast<const Matrix4x4f*>(buffer); + if (i->m_RowCount == 3 && i->m_ColCount == 3) + { + Matrix3x3f m33 = Matrix3x3f(*mat); + GLES_CHK(glUniformMatrix3fv (i->m_Index, 1, GL_FALSE, m33.GetPtr())); + } + else + { + const float *ptr = mat->GetPtr (); + GLES_CHK(glUniformMatrix4fv (i->m_Index, 1, GL_FALSE, ptr)); + } + #if DEBUG_GLSL_BINDINGS + ;;printf_console(" matrix %i (%s)\n", i->m_Index, i->m_Name.GetName() ); + #endif + buffer += size * sizeof(float); + } + } + + // Apply textures + int j = 0; + const GpuProgramParameters::TextureParameterList& textureParams = params.GetTextureParams(); + GpuProgramParameters::TextureParameterList::const_iterator textureParamsEnd = textureParams.end(); + for( GpuProgramParameters::TextureParameterList::const_iterator i = textureParams.begin(); i != textureParamsEnd; ++i ) + { + const TexEnvData* texdata = reinterpret_cast<const TexEnvData*>(buffer); + #if DEBUG_GLSL_BINDINGS + ;;printf_console(" sampler %i to unit %i (%s) id=%i dim=%i\n", t.m_Index, j, t.m_Name.GetName(), tex->GetActualTextureID().m_ID, tex->GetTexDim() ); + #endif + ApplyTexEnvData (j, j, *texdata); + ++j; + buffer += sizeof(TexEnvData); + } + + // Fog parameters if needed + if (index > 0) + { + if (m_FogColorIndex[fog.mode] >= 0) + CachedUniform4(m_UniformCache+index, m_FogColorIndex[fog.mode], fog.color.GetPtr()); + + Vector4f params( + fog.density * 1.2011224087f,// density / sqrt(ln(2)) + fog.density * 1.4426950408f, // density / ln(2) + 0.0f, + 0.0f + ); + + if (fog.mode == kFogLinear) + { + float diff = fog.end - fog.start; + float invDiff = Abs(diff) > 0.0001f ? 1.0f/diff : 0.0f; + params[2] = -invDiff; + params[3] = fog.end * invDiff; + } + + if (m_FogParamsIndex[fog.mode] >= 0) + CachedUniform4(m_UniformCache+index, m_FogParamsIndex[fog.mode], params.GetPtr()); + } + + GLESAssert(); + + return index; +} + + +// -------------------------------------------------------------------------- + +const ShaderLab::FastPropertyName FixedFunctionProgramGLES30::kSLPropTransformBlock = ShaderLab::Property("_ffTransform"); +const ShaderLab::FastPropertyName FixedFunctionProgramGLES30::kSLPropUVTransformBlock = ShaderLab::Property("_ffUVTransform"); + + +FixedFunctionProgramGLES30::FixedFunctionProgramGLES30(GLShaderID vertexShader, GLShaderID fragmentShader) +: m_GLSLProgram(0) +, m_GLSLVertexShader(vertexShader) +, m_GLSLFragmentShader(fragmentShader) +{ + m_GLSLProgram = Create(m_GLSLVertexShader, m_GLSLFragmentShader); +} + +FixedFunctionProgramGLES30::~FixedFunctionProgramGLES30 () +{ + // NOTE: do not delete vertex/fragment shaders; they can be shared between multiple programs + // and are deleted in ClearFixedFunctionPrograms + if (m_GLSLProgram != 0 ) // only delete valid programs + GLES_CHK(glDeleteProgram(m_GLSLProgram)); + + m_UniformCache.Destroy(); +} + +GLShaderID FixedFunctionProgramGLES30::Create(GLShaderID vertexShader, GLShaderID fragmentShader) +{ + GLESAssert(); // Clear any GL errors + + GLuint program; + GLES_CHK(program = glCreateProgram()); + + for (int i = 0; i < kAttribLookupTableSize; i++) + { + if (s_GLESVertexComponents[i] < gGraphicsCaps.gles30.maxAttributes && s_GLESVertexComponents[i] >= 0) + GLES_CHK(glBindAttribLocation(program, s_GLESVertexComponents[i], s_GLSLESAttributes[i])); + } + + GLES_CHK(glAttachShader(program, m_GLSLVertexShader)); + GLES_CHK(glAttachShader(program, m_GLSLFragmentShader)); + + //We must link only after binding the attributes + GLES_CHK(glLinkProgram(program)); + + int linked = 0; + GLES_CHK(glGetProgramiv(program, GL_LINK_STATUS, &linked)); + if (linked == 0) + { + ParseGlslErrors(program, kErrorLinkProgram); + GLES_CHK(glDeleteProgram(program)); + return 0; + } + + // Figure out the uniforms + int activeUniforms; + int activeUniformBlocks; + + char name[1024]; + GLenum type; + int size = 0, + length = 0, + bufSize = sizeof(name); + + // Fetch texture stage samplers. Bind GLSL uniform to the OpenGL texture unit + // just once, cause it never changes after that for this program; and could cause + // internal shader recompiles when changing them. + DBG_LOG_GLES30("GLSL: apply fixed-function program id=%i\n", program); + GLSLUseProgramGLES30 (program); + + for (int i = 0; i < kMaxSupportedTextureUnitsGLES; i++) + { + std::string samplerName = Format("u_sampler%d", i); + GLint uniformNumber; + GLES_CHK(uniformNumber = glGetUniformLocation(program, samplerName.c_str())); + + if (uniformNumber != -1) + { + GLES_CHK(glUniform1i (uniformNumber, i)); + DBG_GLSL_BINDINGS_GLES30(" FFsampler: %s nr=%d", samplerName.c_str(), uniformNumber); + } + } + + // uniform blocks + GLES_CHK(glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &activeUniformBlocks)); + m_Params.GetConstantBuffers().clear(); + m_Params.GetConstantBuffers().reserve(activeUniformBlocks); + for (int i = 0; i < activeUniformBlocks; ++i) + { + GLES_CHK(glGetActiveUniformBlockName(program, i, bufSize, &length, name)); + GLES_CHK(glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_DATA_SIZE, &size)); + + GpuProgramParameters::ConstantBuffer cb; + cb.m_Name = ShaderLab::Property(name); + cb.m_Size = size; + cb.m_BindIndex = i; + + GLES_CHK(glUniformBlockBinding(program, i, i)); + + m_Params.GetConstantBuffers().push_back(cb); + GetRealGfxDevice().SetConstantBufferInfo(cb.m_Name.index, cb.m_Size); + } + + // fetch generic params + GLES_CHK(glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &activeUniforms)); + for(int i=0; i < activeUniforms; i++) + { + int uniformNumber; + int cbIndex = -1; + + GLES_CHK(glGetActiveUniform(program, i, bufSize, &length, &size, &type, name)); + GLES_CHK(uniformNumber = glGetUniformLocation(program, name)); + + const char* glslName = GetGLSLES3PropertyNameRemap(name); + const char* unityName = glslName ? glslName : name; + + if (uniformNumber == GL_INVALID_INDEX) + { + // in a uniform block + GLES_CHK(glGetActiveUniformsiv(program, 1, (GLuint*)&i, GL_UNIFORM_OFFSET, &uniformNumber)); + GLES_CHK(glGetActiveUniformsiv(program, 1, (GLuint*)&i, GL_UNIFORM_BLOCK_INDEX, &cbIndex)); + } + + if(type == GL_FLOAT) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 1, unityName, cbIndex, NULL); + } + else if(type == GL_FLOAT_VEC2) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 2, unityName, cbIndex, NULL); + } + else if(type == GL_FLOAT_VEC3) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 3, unityName, cbIndex, NULL); + } + else if(type == GL_FLOAT_VEC4) { + m_Params.AddVectorParam(uniformNumber, kShaderParamFloat, 4, unityName, cbIndex, NULL); + } + else if(type == GL_FLOAT_MAT4) { + m_Params.AddMatrixParam(uniformNumber, unityName, 4, 4, cbIndex, NULL); + } + else if(type == GL_FLOAT_MAT3) { + m_Params.AddMatrixParam(uniformNumber, unityName, 3, 3, cbIndex, NULL); + } + else if(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE) { + } + else { + AssertString( "Unrecognized GLSL uniform type" ); + } + DBG_GLSL_BINDINGS_GLES30(" FFuniform: %s nr=%d type=%d", unityName, uniformNumber, type); + } + + m_UniformCache.Create(&m_Params, -1,-1); + + GLESAssert(); + return program; +} + +void FixedFunctionProgramGLES30::ApplyFFGpuProgram(const BuiltinShaderParamValues& values, ConstantBuffersGLES30& cbs) const +{ + DBG_LOG_GLES30("FixedFunctionProgramGLES30::ApplyFFGpuProgram()"); + + DBG_LOG_GLES30("GLSL: apply fixed-function program id=%i\n", m_GLSLProgram); + GLSLUseProgramGLES30 (m_GLSLProgram); + + cbs.ResetBinds(); + + // Apply float/vector parameters + const GpuProgramParameters::ValueParameterArray& valueParams = m_Params.GetValueParams(); + GpuProgramParameters::ValueParameterArray::const_iterator valueParamsEnd = valueParams.end(); + for( GpuProgramParameters::ValueParameterArray::const_iterator i = valueParams.begin(); i != valueParamsEnd; ++i ) + { + if(i->m_RowCount == 1 && i->m_ArraySize == 1) + { + UniformCacheGLES30* cache = &m_UniformCache; + const float * val = values.GetVectorParam((BuiltinShaderVectorParam)i->m_Name.BuiltinIndex()).GetPtr(); + + switch (i->m_ColCount) + { + case 1: CachedUniform1(cache, i->m_Index, val); break; + case 2: CachedUniform2(cache, i->m_Index, val); break; + case 3: CachedUniform3(cache, i->m_Index, val); break; + case 4: CachedUniform4(cache, i->m_Index, val); break; + default: break; + } + } + else + { + // Apply matrix parameters + DebugAssert (i->m_ArraySize == 1); + int matSize; + const Matrix4x4f& mat = values.GetMatrixParam((BuiltinShaderMatrixParam)i->m_Name.BuiltinIndex()); + if (i->m_RowCount == 3 && i->m_ColCount == 3) + { + Matrix3x3f m33 = Matrix3x3f(mat); + GLES_CHK(glUniformMatrix3fv (i->m_Index, 1, GL_FALSE, m33.GetPtr())); + } + else + { + const float *ptr = mat.GetPtr (); + GLES_CHK(glUniformMatrix4fv (i->m_Index, 1, GL_FALSE, ptr)); + } + DBG_GLSL_BINDINGS_GLES30(" FFmatrix %i (%s)", i->m_Index, i->m_Name.GetName() ); + } + } + + GLESAssert(); +} + + +#if UNITY_ANDROID || UNITY_BLACKBERRY +//----------------------------------------------------------------------------- +// md5 internals are extracted from External/MurmurHash/md5.cpp + struct + md5_context + { + unsigned long total[2]; + unsigned long state[4]; + unsigned char buffer[64]; + unsigned char ipad[64]; + unsigned char opad[64]; + }; + + extern void md5_starts(md5_context* ctx); + extern void md5_update(md5_context* ctx, unsigned char* input, int ilen); + extern void md5_finish(md5_context* ctx, unsigned char output[16]); +#endif + + +static void GetCachedBinaryName(const std::string& vprog, const std::string& fshader, char filename[33]) +{ +// we have caching only on android, so no need to worry (at least for now) about md5 +#if UNITY_ANDROID || UNITY_BLACKBERRY + + unsigned char hash[16] = {0}; + + md5_context ctx; + md5_starts(&ctx); + md5_update(&ctx, (unsigned char*)vprog.c_str(), vprog.length()); + md5_update(&ctx, (unsigned char*)fshader.c_str(), fshader.length()); + md5_finish(&ctx, hash); + + BytesToHexString(hash, 16, filename); + +#else + + (void)vprog; + (void)fshader; + ::memset(filename, '1', 33); + +#endif +} + + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/GpuProgramsGLES30.h b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30.h new file mode 100644 index 0000000..73bd469 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30.h @@ -0,0 +1,88 @@ +#ifndef GPUPROGRAMSGLES30_H +#define GPUPROGRAMSGLES30_H + + +#if !GFX_SUPPORTS_OPENGLES30 && !GFX_SUPPORTS_OPENGLES +#error "Should not include GpuProgramsGLES30 on this platform" +#endif + + +#include "Runtime/GfxDevice/GpuProgram.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "IncludesGLES30.h" +#include "GpuProgramsGLES30_UniformCache.h" + +class ConstantBuffersGLES30; + +class GlslGpuProgramGLES30 : public GpuProgramGL +{ +public: + GlslGpuProgramGLES30 (const std::string& source, CreateGpuProgramOutput& output); + + ~GlslGpuProgramGLES30(); + + virtual void ApplyGpuProgram (const GpuProgramParameters& params, const UInt8* buffer) { Assert(!"Should not be used"); } + + // Returns the permutation index used + int ApplyGpuProgramES30 (const GpuProgramParameters& params, const UInt8 *buffer); + + static bool InitBinaryShadersSupport(); + + + UniformCacheGLES30 m_UniformCache[kFogModeCount]; + + static bool CompileGlslShader(GLShaderID shader, const char* source); + int GetGLProgram (FogMode fog, GpuProgramParameters& outParams, ChannelAssigns& channels); + +private: + + static void FillParams (unsigned int programID, GpuProgramParameters& params, PropertyNamesSet* outNames); + + bool Create (const std::string& source, ChannelAssigns& channels); + + bool CompileProgram(unsigned index, const std::string& vprog, const std::string& fshader, ChannelAssigns& channels); + +private: + std::string m_VertexShaderSourceForFog; + GLShaderID m_GLSLVertexShader[kFogModeCount]; + GLShaderID m_GLSLFragmentShader[kFogModeCount]; + int m_FogColorIndex[kFogModeCount]; + int m_FogParamsIndex[kFogModeCount]; + bool m_FogFailed[kFogModeCount]; + + static std::string _CachePath; + static glGetProgramBinaryOESFunc _glGetProgramBinaryOES; + static glProgramBinaryOESFunc _glProgramBinaryOES; +}; + + +class FixedFunctionProgramGLES30 +{ +public: + static const ShaderLab::FastPropertyName kSLPropTransformBlock; + static const ShaderLab::FastPropertyName kSLPropUVTransformBlock; + +public: + FixedFunctionProgramGLES30(GLShaderID vertexShader, GLShaderID fragmentShader); + ~FixedFunctionProgramGLES30(); + + void ApplyFFGpuProgram(const BuiltinShaderParamValues& values, ConstantBuffersGLES30& cbs) const; + + const BuiltinShaderParamIndices& GetBuiltinParams() const { return m_Params.GetBuiltinParams(); } + const GpuProgramParameters::ConstantBufferList& GetConstantBuffers() const { return m_Params.GetConstantBuffers(); } + + mutable UniformCacheGLES30 m_UniformCache; + +protected: + GLShaderID Create(GLShaderID vertexShader, GLShaderID fragmentShader); + +private: + GLShaderID m_GLSLProgram; + GLShaderID m_GLSLVertexShader, m_GLSLFragmentShader; + + GpuProgramParameters m_Params; +}; + + +#endif diff --git a/Runtime/GfxDevice/opengles30/GpuProgramsGLES30_UniformCache.cpp b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30_UniformCache.cpp new file mode 100644 index 0000000..235ff7a --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30_UniformCache.cpp @@ -0,0 +1,62 @@ +#include "UnityPrefix.h" +#if !GFX_SUPPORTS_OPENGLES30 +#error "Should not include GpuProgramsGLES30 on this platform" +#endif + +#include "GpuProgramsGLES30_UniformCache.h" + +#include "Runtime/Allocator/MemoryMacros.h" +#include "Runtime/GfxDevice/GpuProgram.h" +#include "IncludesGLES30.h" +#include "AssertGLES30.h" + + +void UniformCacheGLES30::Create(const GpuProgramParameters* params, int fogParamsIndex, int fogColorIndex) +{ + int lastUsedUniform = -1; + + // we will track only float/vector uniforms + GpuProgramParameters::ValueParameterArray::const_iterator paramI = params->GetValueParams().begin(); + GpuProgramParameters::ValueParameterArray::const_iterator paramEnd = params->GetValueParams().end(); + while(paramI != paramEnd) + { + if(paramI->m_RowCount == 1 && paramI->m_ArraySize == 1 && paramI->m_Index > lastUsedUniform) + lastUsedUniform = paramI->m_Index; + + ++paramI; + } + + const BuiltinShaderParamIndices& builtinParam = params->GetBuiltinParams(); + for(unsigned i = 0 ; i < kShaderInstanceVecCount ; ++i) + { + if(builtinParam.vec[i].gpuIndex > lastUsedUniform) + lastUsedUniform = builtinParam.vec[i].gpuIndex; + } + + if(fogParamsIndex > lastUsedUniform) lastUsedUniform = fogParamsIndex; + if(fogColorIndex > lastUsedUniform) lastUsedUniform = fogColorIndex; + + count = lastUsedUniform + 1; + uniform = (float*)UNITY_MALLOC_ALIGNED(kMemShader, count*4 * sizeof(float), 16); + memset(uniform, 0xff /* NaN */, count*4 * sizeof(float)); +} + +void UniformCacheGLES30::Destroy() +{ + count = 0; + + UNITY_FREE(kMemShader, uniform); + uniform = 0; +} + +#define CACHED_UNIFORM_IMPL(Count) \ +void CachedUniform##Count(UniformCacheGLES30* cache, int index, const float* val) \ +{ \ + if(cache->UpdateUniform(index, val, Count)) \ + GLES_CHK(glUniform##Count##fv(index, 1, val)); \ +} \ + +CACHED_UNIFORM_IMPL(1); +CACHED_UNIFORM_IMPL(2); +CACHED_UNIFORM_IMPL(3); +CACHED_UNIFORM_IMPL(4); diff --git a/Runtime/GfxDevice/opengles30/GpuProgramsGLES30_UniformCache.h b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30_UniformCache.h new file mode 100644 index 0000000..aa0e74b --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GpuProgramsGLES30_UniformCache.h @@ -0,0 +1,50 @@ +#pragma once + +#if !GFX_SUPPORTS_OPENGLES30 +#error "Should not include GpuProgramsGLES30 on this platform" +#endif + +#include "Runtime/Utilities/LogAssert.h" +#include <string.h> + +class GpuProgramParameters; + +struct +UniformCacheGLES30 +{ + // for gles we must set values per-uniform (not per-registers like in dx) + // so there is no real need for dirty tracking. + // TODO: do unified impl with dirty tracking if/when we do "everything is an array" in gles + float* uniform; + unsigned count; + + UniformCacheGLES30() : uniform(0), count(0) {} + + // we will pre-alloc memory. Fog params are handled differently (not added to gpu params). + // TODO: make it more general, int* perhaps, or some struct + void Create(const GpuProgramParameters* params, int fogParamsIndex, int fogColorIndex); + void Destroy(); + + // returns true if you need to update for real + bool UpdateUniform(int index, const float* val, unsigned floatCount); +}; + +void CachedUniform1(UniformCacheGLES30* cache, int index, const float* val); +void CachedUniform2(UniformCacheGLES30* cache, int index, const float* val); +void CachedUniform3(UniformCacheGLES30* cache, int index, const float* val); +void CachedUniform4(UniformCacheGLES30* cache, int index, const float* val); + + +inline bool UniformCacheGLES30::UpdateUniform(int index, const float* val, unsigned floatCount) +{ + Assert(index < count); + const unsigned mem_sz = floatCount*sizeof(float); + + float* target = uniform + 4*index; + if(::memcmp(target, val, mem_sz)) + { + ::memcpy(target, val, mem_sz); + return true; + } + return false; +} diff --git a/Runtime/GfxDevice/opengles30/GpuPropertiesGLES30.cpp b/Runtime/GfxDevice/opengles30/GpuPropertiesGLES30.cpp new file mode 100644 index 0000000..ab5c8a2 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GpuPropertiesGLES30.cpp @@ -0,0 +1,70 @@ +#include "UnityPrefix.h" +#include "GpuPropertiesGLES30.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/GfxDevice/BuiltinShaderParams.h" +#include "Runtime/GfxDevice/BuiltinShaderParamsNames.h" + +#if GFX_SUPPORTS_OPENGLES30 + +struct GLSLESProperty +{ + GLSLESProperty(const char* _glName, const char* _glesName) : glName(_glName), unityName(_glesName) { } + const char* glName; + const char* unityName; +}; + +#define DEF_MAT_INTERNAL(name, builtin) GLSLESProperty(name, GetShaderInstanceMatrixParamName(builtin)) +#define DEF_MAT_BUILTIN(name, builtin) GLSLESProperty(name, GetBuiltinMatrixParamName(builtin)) +#define BIND_VEC_BUILTIN(name, builtin) GLSLESProperty(name, GetBuiltinVectorParamName(builtin)) + + +static const GLSLESProperty kglslesProperties[] = +{ + DEF_MAT_BUILTIN("gl_ProjectionMatrix", kShaderMatProj), + DEF_MAT_INTERNAL("gl_NormalMatrix", kShaderInstanceMatNormalMatrix), + DEF_MAT_INTERNAL("gl_ModelViewProjectionMatrix", kShaderInstanceMatMVP), + DEF_MAT_INTERNAL("gl_ModelViewMatrixTranspose", kShaderInstanceMatTransMV), + DEF_MAT_INTERNAL("gl_ModelViewMatrixInverseTranspose", kShaderInstanceMatInvTransMV), + DEF_MAT_INTERNAL("gl_ModelViewMatrix", kShaderInstanceMatMV), + + DEF_MAT_INTERNAL("gl_TextureMatrix0", kShaderInstanceMatTexture0), + DEF_MAT_INTERNAL("gl_TextureMatrix1", kShaderInstanceMatTexture1), + DEF_MAT_INTERNAL("gl_TextureMatrix2", kShaderInstanceMatTexture2), + DEF_MAT_INTERNAL("gl_TextureMatrix3", kShaderInstanceMatTexture3), + DEF_MAT_INTERNAL("gl_TextureMatrix4", kShaderInstanceMatTexture4), + DEF_MAT_INTERNAL("gl_TextureMatrix5", kShaderInstanceMatTexture5), + DEF_MAT_INTERNAL("gl_TextureMatrix6", kShaderInstanceMatTexture6), + DEF_MAT_INTERNAL("gl_TextureMatrix7", kShaderInstanceMatTexture7), + + BIND_VEC_BUILTIN("_glesLightSource[0].diffuse", kShaderVecLight0Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[1].diffuse", kShaderVecLight1Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[2].diffuse", kShaderVecLight2Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[3].diffuse", kShaderVecLight3Diffuse), + BIND_VEC_BUILTIN("_glesLightSource[0].position", kShaderVecLight0Position), + BIND_VEC_BUILTIN("_glesLightSource[1].position", kShaderVecLight1Position), + BIND_VEC_BUILTIN("_glesLightSource[2].position", kShaderVecLight2Position), + BIND_VEC_BUILTIN("_glesLightSource[3].position", kShaderVecLight3Position), + BIND_VEC_BUILTIN("_glesLightSource[0].spotDirection", kShaderVecLight0SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[1].spotDirection", kShaderVecLight1SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[2].spotDirection", kShaderVecLight2SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[3].spotDirection", kShaderVecLight3SpotDirection), + BIND_VEC_BUILTIN("_glesLightSource[0].atten", kShaderVecLight0Atten), + BIND_VEC_BUILTIN("_glesLightSource[1].atten", kShaderVecLight1Atten), + BIND_VEC_BUILTIN("_glesLightSource[2].atten", kShaderVecLight2Atten), + BIND_VEC_BUILTIN("_glesLightSource[3].atten", kShaderVecLight3Atten), + BIND_VEC_BUILTIN("_glesLightModel.ambient", kShaderVecLightModelAmbient), +}; + + +const char* GetGLSLES3PropertyNameRemap (const char* name) +{ + for (int i = 0; i < ARRAY_SIZE(kglslesProperties); i++) + { + const GLSLESProperty& prop = kglslesProperties[i]; + if (strcmp(name, prop.glName) == 0) + return prop.unityName; + } + return NULL; +} + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/GpuPropertiesGLES30.h b/Runtime/GfxDevice/opengles30/GpuPropertiesGLES30.h new file mode 100644 index 0000000..86b980e --- /dev/null +++ b/Runtime/GfxDevice/opengles30/GpuPropertiesGLES30.h @@ -0,0 +1,3 @@ +#pragma once + +const char* GetGLSLES3PropertyNameRemap (const char* name); diff --git a/Runtime/GfxDevice/opengles30/IncludesGLES30.h b/Runtime/GfxDevice/opengles30/IncludesGLES30.h new file mode 100644 index 0000000..260bea5 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/IncludesGLES30.h @@ -0,0 +1 @@ +#include "Runtime/GfxDevice/opengles/IncludesGLES.h"
\ No newline at end of file diff --git a/Runtime/GfxDevice/opengles30/RenderTextureGLES30.cpp b/Runtime/GfxDevice/opengles30/RenderTextureGLES30.cpp new file mode 100644 index 0000000..7f5a92f --- /dev/null +++ b/Runtime/GfxDevice/opengles30/RenderTextureGLES30.cpp @@ -0,0 +1,551 @@ +#include "UnityPrefix.h" +#include "RenderTextureGLES30.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/Utilities/BitUtility.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Graphics/ScreenManager.h" +#include "IncludesGLES30.h" +#include "AssertGLES30.h" +#include "DebugGLES30.h" +#include "TextureIdMapGLES30.h" +#include "UtilsGLES30.h" + +#if UNITY_ANDROID + #include "PlatformDependent/AndroidPlayer/EntryPoint.h" +#endif + +#if 1 + #define DBG_LOG_RT_GLES30(...) {} +#else + #define DBG_LOG_RT_GLES30(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#endif + +#if GFX_SUPPORTS_OPENGLES30 + +namespace +{ + +static const UInt32 kCubeFacesES3[] = +{ + GL_TEXTURE_CUBE_MAP_POSITIVE_X, + GL_TEXTURE_CUBE_MAP_NEGATIVE_X, + GL_TEXTURE_CUBE_MAP_POSITIVE_Y, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, +}; + +inline bool IsDepthStencilFormat (UInt32 format) +{ + switch (format) + { + case GL_DEPTH24_STENCIL8: + case GL_DEPTH32F_STENCIL8: + return true; + + default: + return false; + } +} + +const char* GetFBOStatusName (UInt32 status) +{ + switch (status) + { + case GL_FRAMEBUFFER_COMPLETE: return "COMPLETE"; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "INCOMPLETE_ATTACHMENT"; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "INCOMPLETE_MISSING_ATTACHMENT"; + case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: return "INCOMPLETE_DIMENSIONS"; + case GL_FRAMEBUFFER_UNSUPPORTED: return "UNSUPPORTED"; + default: return "unknown error"; + } +} + +} // anonymous + +// RenderSurfaceGLES30 +RenderSurfaceGLES30::RenderSurfaceGLES30 (Type type, UInt32 format, int w, int h, int numSamples) + : m_type (type) + , m_format (format) + , m_flags (0) +{ + RenderSurfaceBase_Init(*this); + width = w; + height = h; + samples = numSamples; +} + +// RenderTexture2DGLES30 + +RenderTexture2DGLES30::RenderTexture2DGLES30 (TextureID texID, UInt32 format, int w, int h) + : RenderSurfaceGLES30 (kTypeTexture2D, format, w, h, 1) +{ + textureID = texID; + + TransferFormatGLES30 transferFmt = GetTransferFormatGLES30(format); + GLuint glTexID = TextureIdMapGLES30_QueryOrCreate(textureID); + + Assert(glTexID != 0); + + GetRealGfxDevice().SetTexture(kShaderFragment, 0, 0, textureID, kTexDim2D, std::numeric_limits<float>::infinity()); + GLES_CHK(glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, transferFmt.format, transferFmt.dataType, 0)); +} + +RenderTexture2DGLES30::~RenderTexture2DGLES30 (void) +{ + // \todo [2013-04-29 pyry] Set texture storage to null? +} + +void RenderTexture2DGLES30::AttachColor (int ndx, CubemapFace face) +{ + Assert(face == kCubeFaceUnknown); + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+ndx, GL_TEXTURE_2D, GetGLTextureID(), 0)); +} + +void RenderTexture2DGLES30::AttachDepthStencil (CubemapFace face) +{ + // \note Using GL_DEPTH_STENCIL_ATTACHMENT would eliminate one more call, but unfortunately + // that is broken at least on ARM GLES3 EMU. + Assert(face == kCubeFaceUnknown); + + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, GetGLTextureID(), 0)); + + if (IsDepthStencilFormat(m_format)) + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, GetGLTextureID(), 0)); +} + +// RenderTextureCubeGLES30 + +RenderTextureCubeGLES30::RenderTextureCubeGLES30 (TextureID texID, UInt32 format, int w, int h) + : RenderSurfaceGLES30 (kTypeTextureCube, format, w, h, 1) +{ + textureID = texID; + + TransferFormatGLES30 transferFmt = GetTransferFormatGLES30(format); + GLuint glTexID = TextureIdMapGLES30_QueryOrCreate(textureID); + + Assert(glTexID != 0); + + GetRealGfxDevice().SetTexture(kShaderFragment, 0, 0, textureID, kTexDimCUBE, std::numeric_limits<float>::infinity()); + + for (int ndx = 0; ndx < 6; ndx++) + GLES_CHK(glTexImage2D(kCubeFacesES3[ndx], 0, format, width, height, 0, transferFmt.format, transferFmt.dataType, 0)); +} + +RenderTextureCubeGLES30::~RenderTextureCubeGLES30 (void) +{ + // \todo [2013-04-29 pyry] Set texture storage to null? +} + +void RenderTextureCubeGLES30::AttachColor (int ndx, CubemapFace face) +{ + const int faceIndex = clamp<int>(face,0,5); // can be passed -1 when restoring from previous RT + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+ndx, kCubeFacesES3[faceIndex], GetGLTextureID(), 0)); +} + +void RenderTextureCubeGLES30::AttachDepthStencil (CubemapFace face) +{ + const int faceIndex = clamp<int>(face,0,5); // can be passed -1 when restoring from previous RT + + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, kCubeFacesES3[faceIndex], GetGLTextureID(), 0)); + + if (IsDepthStencilFormat(m_format)) + GLES_CHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, kCubeFacesES3[faceIndex], GetGLTextureID(), 0)); +} + +// RenderBufferGLES30 + +RenderBufferGLES30::RenderBufferGLES30 (UInt32 format, int w, int h, int numSamples) + : RenderSurfaceGLES30 (kTypeRenderBuffer, format, w, h, numSamples) + , m_bufferID (0) +{ + glGenRenderbuffers(1, (GLuint*)&m_bufferID); + glBindRenderbuffer(GL_RENDERBUFFER, m_bufferID); + + if (numSamples > 1) + GLES_CHK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, numSamples, format, width, height)); + else + GLES_CHK(glRenderbufferStorage(GL_RENDERBUFFER, format, width, height)); +} + +RenderBufferGLES30::~RenderBufferGLES30 (void) +{ + if (m_bufferID) + glDeleteRenderbuffers(1, (GLuint*)&m_bufferID); +} + +void RenderBufferGLES30::AttachColor (int ndx, CubemapFace face) +{ + Assert(face == kCubeFaceUnknown); + GLES_CHK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+ndx, GL_RENDERBUFFER, m_bufferID)); +} + +void RenderBufferGLES30::AttachDepthStencil (CubemapFace face) +{ + Assert(face == kCubeFaceUnknown); + + GLES_CHK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_bufferID)); + + if (IsDepthStencilFormat(m_format)) + GLES_CHK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_bufferID)); +} + +void RenderBufferGLES30::Disown (void) +{ + m_bufferID = 0; +} + +// RenderBufferCubeGLES30 + +RenderBufferCubeGLES30::RenderBufferCubeGLES30 (UInt32 format, int w, int h, int numSamples) + : RenderSurfaceGLES30 (kTypeRenderBufferCube, format, w, h, numSamples) +{ + memset(&m_buffers[0], 0, sizeof(m_buffers)); + + for (int i = 0; i < 6; i++) + m_buffers[i] = new RenderBufferGLES30(format, width, height, numSamples); +} + +RenderBufferCubeGLES30::~RenderBufferCubeGLES30 (void) +{ + for (int i = 0; i < 6; i++) + delete m_buffers[i]; +} + +void RenderBufferCubeGLES30::AttachColor (int ndx, CubemapFace face) +{ + const int faceIndex = clamp<int>(face,0,5); // can be passed -1 when restoring from previous RT + m_buffers[faceIndex]->AttachColor(ndx, kCubeFaceUnknown); +} + +void RenderBufferCubeGLES30::AttachDepthStencil (CubemapFace face) +{ + const int faceIndex = clamp<int>(face,0,5); // can be passed -1 when restoring from previous RT + m_buffers[faceIndex]->AttachDepthStencil(kCubeFaceUnknown); +} + +// FramebufferAttachmentsGLES30 + +FramebufferAttachmentsGLES30::FramebufferAttachmentsGLES30 (int numColorAttachments, RenderSurfaceGLES30* colorAttachments, RenderSurfaceGLES30* depthStencilAttachment, CubemapFace face) + : numColorAttachments (numColorAttachments) + , depthStencil (depthStencilAttachment) + , cubemapFace (face) +{ + for (int ndx = 0; ndx < numColorAttachments; ndx++) + color[ndx] = &colorAttachments[ndx]; + + for (int ndx = numColorAttachments; ndx < kMaxColorAttachments; ndx++) + color[ndx] = 0; +} + +FramebufferAttachmentsGLES30::FramebufferAttachmentsGLES30 (void) + : numColorAttachments (0) + , depthStencil (0) + , cubemapFace (kCubeFaceUnknown) +{ + memset(&color[0], 0, sizeof(color)); +} + +// FramebufferObjectGLES30 + +FramebufferObjectGLES30::FramebufferObjectGLES30 (const FramebufferAttachmentsGLES30& attachments) + : m_fboID (0) + , m_attachments (attachments) +{ + GLuint oldFbo = 0; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&oldFbo); + + glGenFramebuffers(1, (GLuint*)&m_fboID); + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, m_fboID)); + + for (int colorNdx = 0; colorNdx < attachments.numColorAttachments; colorNdx++) + { + if (m_attachments.color[colorNdx] && m_attachments.color[colorNdx]->GetType() != RenderSurfaceGLES30::kTypeDummy) + m_attachments.color[colorNdx]->AttachColor(colorNdx, m_attachments.cubemapFace); + } + + if (m_attachments.depthStencil) + m_attachments.depthStencil->AttachDepthStencil(m_attachments.cubemapFace); + + UInt32 status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) + { + const char* statusName = GetFBOStatusName(status); + ErrorStringMsg("Framebuffer is not complete: %s", statusName); + Assert(status == GL_FRAMEBUFFER_COMPLETE); + } + + // \todo [2013-04-30 pyry] We should really fail object construction if fbo is not complete. + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, oldFbo)); +} + +FramebufferObjectGLES30::~FramebufferObjectGLES30 (void) +{ + if (m_fboID) + glDeleteFramebuffers(1, (GLuint*)&m_fboID); +} + +void FramebufferObjectGLES30::Disown (void) +{ + m_fboID = 0; +} + +RenderSurfaceGLES30* FramebufferObjectGLES30::GetColorAttachment (int ndx) +{ + Assert(0 <= ndx && ndx <= FramebufferAttachmentsGLES30::kMaxColorAttachments); + return m_attachments.color[ndx]; +} + +const RenderSurfaceGLES30* FramebufferObjectGLES30::GetColorAttachment (int ndx) const +{ + Assert(0 <= ndx && ndx <= FramebufferAttachmentsGLES30::kMaxColorAttachments); + return m_attachments.color[ndx]; +} + +RenderSurfaceGLES30* FramebufferObjectGLES30::GetDepthStencilAttachment (void) +{ + return m_attachments.depthStencil; +} + +const RenderSurfaceGLES30* FramebufferObjectGLES30::GetDepthStencilAttachment (void) const +{ + return m_attachments.depthStencil; +} + +// FramebufferObjectManagerGLES30 + +bool CompareFramebufferAttachmentsGLES30::operator() (const FramebufferAttachmentsGLES30* a, const FramebufferAttachmentsGLES30* b) const +{ + if (a->numColorAttachments < b->numColorAttachments) return true; + else if (a->numColorAttachments > b->numColorAttachments) return false; + + if (a->depthStencil < b->depthStencil) return true; + else if (a->depthStencil > b->depthStencil) return false; + + if (a->cubemapFace < b->cubemapFace) return true; + else if (a->cubemapFace > b->cubemapFace) return false; + + for (int ndx = 0; ndx < a->numColorAttachments; ndx++) + { + if (a->color[ndx] < b->color[ndx]) return true; + else if (a->color[ndx] > b->color[ndx]) return false; + } + + return false; // Equal. +} + +bool CompareRenderBufferParamsGLES30::operator() (const RenderBufferParamsGLES30& a, const RenderBufferParamsGLES30& b) const +{ + if (a.format < b.format) return true; + else if (a.format > b.format) return false; + + if (a.width < b.width) return true; + else if (a.width > b.width) return false; + + if (a.height < b.height) return true; + else if (a.height > b.height) return false; + + return false; // Equal. +} + +FramebufferObjectManagerGLES30::FramebufferObjectManagerGLES30 (void) +{ +} + +FramebufferObjectManagerGLES30::~FramebufferObjectManagerGLES30 (void) +{ + Clear(); +} + +void FramebufferObjectManagerGLES30::InvalidateObjects (void) +{ + // Call disown on all FBOs first. + for (FramebufferObjectMapGLES30::iterator iter = m_fboMap.begin(); iter != m_fboMap.end(); ++iter) + iter->second->Disown(); + + for (RenderBufferMapGLES30::iterator iter = m_rbufMap.begin(); iter != m_rbufMap.end(); ++iter) + iter->second->Disown(); + + // Clear objects. + Clear(); +} + +void FramebufferObjectManagerGLES30::Clear (void) +{ + // \todo [pyry] This actually invalidates keys as well. Is that okay in clear()? + for (FramebufferObjectMapGLES30::iterator iter = m_fboMap.begin(); iter != m_fboMap.end(); ++iter) + delete iter->second; + m_fboMap.clear(); + + for (RenderBufferMapGLES30::iterator iter = m_rbufMap.begin(); iter != m_rbufMap.end(); ++iter) + delete iter->second; + m_rbufMap.clear(); +} + +void FramebufferObjectManagerGLES30::InvalidateSurface (const RenderSurfaceGLES30* surface) +{ + std::vector<FramebufferObjectGLES30*> deleteFbos; + + for (FramebufferObjectMapGLES30::iterator iter = m_fboMap.begin(); iter != m_fboMap.end(); ++iter) + { + if (IsInFramebufferAttachmentsGLES30(*iter->first, surface)) + deleteFbos.push_back(iter->second); + } + + for (std::vector<FramebufferObjectGLES30*>::iterator iter = deleteFbos.begin(); iter != deleteFbos.end(); ++iter) + { + m_fboMap.erase((*iter)->GetAttachments()); + delete *iter; + } +} + +FramebufferObjectGLES30* FramebufferObjectManagerGLES30::GetFramebufferObject (const FramebufferAttachmentsGLES30& attachments) +{ + // Try to fetch from cache. + { + FramebufferObjectMapGLES30::const_iterator fboPos = m_fboMap.find(&attachments); + if (fboPos != m_fboMap.end()) + return fboPos->second; + } + + DBG_LOG_RT_GLES30("FramebufferObjectManagerGLES30::GetFramebufferObject(): cache miss, creating FBO"); + + // Not found - create a new one and insert. + { + FramebufferObjectGLES30* fbo = new FramebufferObjectGLES30(attachments); + m_fboMap.insert(std::make_pair(fbo->GetAttachments(), fbo)); + return fbo; + } +} + +RenderBufferGLES30* FramebufferObjectManagerGLES30::GetRenderBuffer (UInt32 format, int width, int height) +{ + RenderBufferParamsGLES30 params(format, width, height); + + { + RenderBufferMapGLES30::const_iterator pos = m_rbufMap.find(params); + if (pos != m_rbufMap.end()) + return pos->second; + } + + DBG_LOG_RT_GLES30("FramebufferObjectManagerGLES30::GetRenderBuffer(): cache miss, creating RBO"); + + { + RenderBufferGLES30* buf = new RenderBufferGLES30(format, width, height, 1); + m_rbufMap.insert(std::make_pair(params, buf)); + return buf; + } +} + +// Utilities + +bool IsInFramebufferAttachmentsGLES30 (const FramebufferAttachmentsGLES30& attachments, const RenderSurfaceGLES30* renderSurface) +{ + for (int ndx = 0; ndx < attachments.numColorAttachments; ndx++) + { + if (attachments.color[ndx] == renderSurface) + return true; + } + + if (attachments.depthStencil == renderSurface) + return true; + + return false; +} + +void BindFramebufferObjectGLES30 (FramebufferObjectGLES30* fbo) +{ + Assert(fbo != 0); + + GLenum drawBuffers [FramebufferAttachmentsGLES30::kMaxColorAttachments]; + GLenum discardBuffers [FramebufferAttachmentsGLES30::kMaxColorAttachments+1]; + int drawBufferNdx = 0; + int discardBufferNdx = 0; + + for (int ndx = 0; ndx < fbo->GetNumColorAttachments(); ndx++) + { + RenderSurfaceGLES30* attachment = fbo->GetColorAttachment(ndx); + + if (attachment) + drawBuffers[drawBufferNdx++] = GL_COLOR_ATTACHMENT0+ndx; + + if (attachment && (attachment->GetFlags() & RenderSurfaceGLES30::kDiscardOnBind)) + { + if(fbo->GetFboID() == 0) + discardBuffers[discardBufferNdx++] = GL_COLOR; + else + discardBuffers[discardBufferNdx++] = GL_COLOR_ATTACHMENT0+ndx; + attachment->SetFlags(attachment->GetFlags() & ~RenderSurfaceGLES30::kDiscardOnBind); + } + } + + if (fbo->GetDepthStencilAttachment()) + { + RenderSurfaceGLES30* depthStencilAttachment = fbo->GetDepthStencilAttachment(); + if (depthStencilAttachment->GetFlags() & RenderSurfaceGLES30::kDiscardOnBind && depthStencilAttachment->GetType() != RenderSurfaceGLES30::kTypeDummy) + { + if(fbo->GetFboID() == 0) + { + discardBuffers[discardBufferNdx++] = GL_DEPTH; + discardBuffers[discardBufferNdx++] = GL_STENCIL; + } + else + { + discardBuffers[discardBufferNdx++] = GL_DEPTH_ATTACHMENT; + discardBuffers[discardBufferNdx++] = GL_STENCIL_ATTACHMENT; + } + + depthStencilAttachment->SetFlags(depthStencilAttachment->GetFlags() & ~RenderSurfaceGLES30::kDiscardOnBind); + } + } + + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, fbo->GetFboID())); + GLES_CHK(glDrawBuffers(drawBufferNdx, &drawBuffers[0])); + + if (discardBufferNdx > 0) + GLES_CHK(glInvalidateFramebuffer(GL_FRAMEBUFFER, discardBufferNdx, &discardBuffers[0])); +} + +void BindDefaultFramebufferGLES30 (void) +{ + GLuint defaultDrawBuffer = GL_BACK; + GLES_CHK(glBindFramebuffer(GL_FRAMEBUFFER, 0)); + GLES_CHK(glDrawBuffers(1, &defaultDrawBuffer)); +} + +FramebufferObjectGLES30* GetResolveFramebufferObjectGLES30 (FramebufferObjectManagerGLES30* fboManager, UInt32 colorFormat, UInt32 depthStencilFormat, int width, int height) +{ + RenderBufferGLES30* colorBuf = colorFormat != 0 ? fboManager->GetRenderBuffer(colorFormat, width, height) : 0; + RenderBufferGLES30* depthBuf = depthStencilFormat != 0 ? fboManager->GetRenderBuffer(depthStencilFormat, width, height) : 0; + FramebufferAttachmentsGLES30 attachments; + + attachments.color[0] = colorBuf; + attachments.depthStencil = depthBuf; + attachments.numColorAttachments = colorBuf ? 1 : 0; + + return fboManager->GetFramebufferObject(attachments); +} + +// back buffer +RenderSurfaceBase* CreateBackBufferColorSurfaceGLES3() +{ + DummyRenderSurfaceGLES30* rs = new DummyRenderSurfaceGLES30(0,0); + RenderSurfaceBase_InitColor(*rs); + rs->backBuffer = true; + + return rs; +} +RenderSurfaceBase* CreateBackBufferDepthSurfaceGLES3() +{ + DummyRenderSurfaceGLES30* rs = new DummyRenderSurfaceGLES30(0,0); + RenderSurfaceBase_InitDepth(*rs); + rs->backBuffer = true; + + return rs; +} + + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/RenderTextureGLES30.h b/Runtime/GfxDevice/opengles30/RenderTextureGLES30.h new file mode 100644 index 0000000..adc1898 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/RenderTextureGLES30.h @@ -0,0 +1,267 @@ +#pragma once + +#if GFX_SUPPORTS_OPENGLES30 + +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/GfxDeviceConfigure.h" +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/GfxDevice/TextureIdMap.h" +#include "Runtime/Graphics/RenderSurface.h" + +#include <map> + +//! Render surface base class (implementations in RenderTextureGLES30 or RenderBufferGLES30) +class RenderSurfaceGLES30 : public RenderSurfaceBase +{ +public: + enum Type + { + kTypeTexture2D = 0, + kTypeTextureCube, + kTypeRenderBuffer, + kTypeRenderBufferCube, //!< RenderSurface that contains one RenderBuffer for each cubemap face. Used for MSAA cubemap rendering. + kTypeDummy, //!< Dummy surface (no real storage), used when doing depth only. + }; + + enum Flags + { + kDiscardOnBind = (1<<0), //!< Discard this attachment when bound as render target next time. + }; + + virtual ~RenderSurfaceGLES30 (void) {} + + Type GetType (void) const { return m_type; } + UInt32 GetFormat (void) const { return m_format; } + int GetWidth (void) const { return width; } + int GetHeight (void) const { return height; } + int GetNumSamples (void) const { return samples; } + + UInt32 GetFlags (void) const { return m_flags; } + void SetFlags (UInt32 flags) { m_flags = flags; } + + virtual void AttachColor (int ndx, CubemapFace face) = 0; + virtual void AttachDepthStencil (CubemapFace face) = 0; + +protected: + RenderSurfaceGLES30 (Type type, UInt32 format, int width, int height, int numSamples); + + const Type m_type; //!< RenderSurface type + const UInt32 m_format; //!< Internal format + + UInt32 m_flags; //!< Flags. + +private: + RenderSurfaceGLES30 (const RenderSurfaceGLES30& other); // Not allowed! + RenderSurfaceGLES30& operator= (const RenderSurfaceGLES30& other); // Not allowed! +}; + +class DummyRenderSurfaceGLES30 : public RenderSurfaceGLES30 +{ +public: + DummyRenderSurfaceGLES30 (int width, int height) : RenderSurfaceGLES30(kTypeDummy, 0, width, height, 1) {} + ~DummyRenderSurfaceGLES30 (void) {} + + virtual void AttachColor (int ndx, CubemapFace face) {} + virtual void AttachDepthStencil (CubemapFace face) {} +}; + +class RenderTexture2DGLES30 : public RenderSurfaceGLES30 +{ +public: + RenderTexture2DGLES30 (TextureID textureID, UInt32 format, int width, int height); + ~RenderTexture2DGLES30 (void); + + virtual void AttachColor (int ndx, CubemapFace face); + virtual void AttachDepthStencil (CubemapFace face); + + TextureID GetTextureID (void) const { return textureID; } + UInt32 GetGLTextureID (void) const { return (UInt32)TextureIdMap::QueryNativeTexture(textureID); } +}; + +class RenderTextureCubeGLES30 : public RenderSurfaceGLES30 +{ +public: + RenderTextureCubeGLES30 (TextureID textureID, UInt32 format, int width, int height); + ~RenderTextureCubeGLES30 (void); + + virtual void AttachColor (int ndx, CubemapFace face); + virtual void AttachDepthStencil (CubemapFace face); + + TextureID GetTextureID (void) const { return textureID; } + UInt32 GetGLTextureID (void) const { return (UInt32)TextureIdMap::QueryNativeTexture(textureID); } +}; + +class RenderBufferGLES30 : public RenderSurfaceGLES30 +{ +public: + RenderBufferGLES30 (UInt32 format, int width, int height, int numSamples); + ~RenderBufferGLES30 (void); + + virtual void AttachColor (int ndx, CubemapFace face); + virtual void AttachDepthStencil (CubemapFace face); + + UInt32 GetBufferID (void) const { return m_bufferID; } + + //! RenderBuffer specific: remove current buffer handle and do not attempt to destroy it. + void Disown (void); + +private: + UInt32 m_bufferID; +}; + +class RenderBufferCubeGLES30 : public RenderSurfaceGLES30 +{ +public: + RenderBufferCubeGLES30 (UInt32 format, int width, int height, int numSamples); + ~RenderBufferCubeGLES30 (void); + + virtual void AttachColor (int ndx, CubemapFace face); + virtual void AttachDepthStencil (CubemapFace face); + + const RenderBufferGLES30& GetBuffer (CubemapFace face) const; + +private: + RenderBufferGLES30* m_buffers[6]; +}; + +//!< FBO attachment container - used as FBO map key and in FramebufferObject +class FramebufferAttachmentsGLES30 +{ +public: + enum + { + kMaxColorAttachments = 4 + }; + + FramebufferAttachmentsGLES30 (int numColorAttachments, RenderSurfaceGLES30* colorAttachments, RenderSurfaceGLES30* depthStencilAttachment, CubemapFace face); + FramebufferAttachmentsGLES30 (void); + + int numColorAttachments; //!< Number of valid attachments in color[] array. Rest are zero-filled. + RenderSurfaceGLES30* color[kMaxColorAttachments]; //!< Color attachments. + RenderSurfaceGLES30* depthStencil; //!< Depth or depth-stencil attachment, if such is used. + CubemapFace cubemapFace; //!< Applies to cubemap attachments only. +}; + +class FramebufferObjectGLES30 +{ +public: + FramebufferObjectGLES30 (const FramebufferAttachmentsGLES30& attachments); + ~FramebufferObjectGLES30 (void); + + UInt32 GetFboID (void) const { return m_fboID; } + + const FramebufferAttachmentsGLES30* GetAttachments (void) const { return &m_attachments; } + + int GetNumColorAttachments (void) const { return m_attachments.numColorAttachments; } + CubemapFace GetCubemapFace (void) const { return m_attachments.cubemapFace; } + + RenderSurfaceGLES30* GetColorAttachment (int ndx); + const RenderSurfaceGLES30* GetColorAttachment (int ndx) const; + + RenderSurfaceGLES30* GetDepthStencilAttachment (void); + const RenderSurfaceGLES30* GetDepthStencilAttachment (void) const; + + //! Disown and remove fbo handle. Used if destructor should not try to delete fbo for some reason (context lost for example). + void Disown (void); + +private: + UInt32 m_fboID; + FramebufferAttachmentsGLES30 m_attachments; +}; + +class RenderBufferParamsGLES30 +{ +public: + UInt32 format; + int width; + int height; + // \note No numSamples since these are currently used for allocating resolve buffers only. + // Sample count may be added if temporary buffers are required for something else. + + RenderBufferParamsGLES30 (UInt32 format_, int width_, int height_) + : format (format_) + , width (width_) + , height (height_) + { + } +}; + +// FramebufferObject map implementation. +// +// Pointers to actual key data is used, since they are cheaper to move around. When inserting, +// key pointer is acquired from FramebufferObject. When searching, it is up to user to provide +// valid pointer (usually from stack). +struct CompareFramebufferAttachmentsGLES30 +{ + bool operator() (const FramebufferAttachmentsGLES30* a, const FramebufferAttachmentsGLES30* b) const; +}; +typedef std::map<const FramebufferAttachmentsGLES30*, FramebufferObjectGLES30*, CompareFramebufferAttachmentsGLES30> FramebufferObjectMapGLES30; + +// RenderBuffer map implementation. +struct CompareRenderBufferParamsGLES30 +{ + bool operator() (const RenderBufferParamsGLES30& a, const RenderBufferParamsGLES30& b) const; +}; +typedef std::map<RenderBufferParamsGLES30, RenderBufferGLES30*, CompareRenderBufferParamsGLES30> RenderBufferMapGLES30; + +class FramebufferObjectManagerGLES30 +{ +public: + FramebufferObjectManagerGLES30 (void); + ~FramebufferObjectManagerGLES30 (void); + + //! Mark API objects invalid and clear cache (use on context loss) + void InvalidateObjects (void); + + //!< Destroy all internal and API objects (clear cache and free objects). + void Clear (void); + + //!< Destroy all FBOs where render surface is attached. + void InvalidateSurface (const RenderSurfaceGLES30* surface); + + //! Create (or fetch from cache) framebuffer object to hold given attachment set. + FramebufferObjectGLES30* GetFramebufferObject (const FramebufferAttachmentsGLES30& attachments); + + //! Create (or fetch from cache) temporary render buffer. + // + // Temporary render buffers are currently used as resolve buffers. + // Callee should not store returned buffer anywhere since it will be + // re-used. + RenderBufferGLES30* GetRenderBuffer (UInt32 format, int width, int height); + +private: + FramebufferObjectMapGLES30 m_fboMap; + RenderBufferMapGLES30 m_rbufMap; +}; + +//! Check if surface is in given FBO attachment list. +bool IsInFramebufferAttachmentsGLES30 (const FramebufferAttachmentsGLES30& attachments, const RenderSurfaceGLES30* renderSurface); + +//! Bind FBO and setup for drawing +// +// This call setups FBO as rendering target: +// 1) FBO is bound to current context +// 2) If any of attachments have actions deferred to next bind defined, they are executed +// + kDiscardOnBind: InvalidateFramebuffer() is called for those attachments +// 3) DrawBuffers is set up based on attachments +void BindFramebufferObjectGLES30 (FramebufferObjectGLES30* fbo); + +//! Bind default framebuffer (0) +// +// Changes FBO binding to 0 and sets GL_BACK as draw buffer. +void BindDefaultFramebufferGLES30 (void); + +//! Get resolve FBO. +// +// \param fboManager FBO manager +// \param colorFormat Color buffer format or 0 if not used. +// \param depthStencilFormat Depth / depth-stencil format or 0 if not used +// \param width +// \param height +// +// Creates FBO for doing resolve. Buffers are allocated using fboManager->GetRenderBuffer() +// and thus will be re-used by subsequent resolve FBOs if formats match. +FramebufferObjectGLES30* GetResolveFramebufferObjectGLES30 (FramebufferObjectManagerGLES30* fboManager, UInt32 colorFormat, UInt32 depthStencilFormat, int width, int height); + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/ShaderGeneratorGLES30.cpp b/Runtime/GfxDevice/opengles30/ShaderGeneratorGLES30.cpp new file mode 100644 index 0000000..afb9bdb --- /dev/null +++ b/Runtime/GfxDevice/opengles30/ShaderGeneratorGLES30.cpp @@ -0,0 +1,824 @@ +#include "UnityPrefix.h" +#include "FixedFunctionStateGLES30.h" +#include "GpuProgramsGLES30.h" +#include "ShaderGeneratorGLES30.h" +#include "IncludesGLES30.h" +#include "DebugGLES30.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/BuiltinShaderParams.h" +#include "Runtime/GfxDevice/BuiltinShaderParamsNames.h" +#include "Runtime/Utilities/BitUtility.h" + +#include <sstream> +#include <assert.h> + + +#define CMP_STATE(member) { \ + if (a.member < b.member) \ + return true; \ + else if (b.member < a.member) \ + return false; \ +} + +// builtins support only 4 lights +const int kMaxEmulatedVertexLights = 4;//kMaxSupportedVertexLights; + +bool FullStateCompareGLES30::operator() (FixedFunctionStateGLES30 const& a, const FixedFunctionStateGLES30& b) const +{ + CMP_STATE(lightingEnabled) + CMP_STATE(specularEnabled) + CMP_STATE(lightCount) + CMP_STATE(onlyDirectionalLights) + CMP_STATE(lightType) + CMP_STATE(texUnitMatrix) + CMP_STATE(useUniformInsteadOfVertexColor) + CMP_STATE(useVertexColorAsAmbientAndDiffuse) + CMP_STATE(useVertexColorAsEmission) + + CMP_STATE(fogMode) + + CMP_STATE(texUnitCount); + for (int i = 0; i < a.texUnitCount; i++) + { + CMP_STATE(texUnitCube[i]) + CMP_STATE(texUnitGen[i]) + CMP_STATE(texUnitColorCombiner[i]) + CMP_STATE(texUnitAlphaCombiner[i]) + } + + CMP_STATE(addSpecularAfterTexturing) + CMP_STATE(alphaTest) + + return false; /* All equal, not lesser. */ +} + +bool VertexStateCompareGLES30::operator() (FixedFunctionStateGLES30 const& a, FixedFunctionStateGLES30 const& b) const +{ + CMP_STATE(lightingEnabled) + CMP_STATE(specularEnabled) + CMP_STATE(lightCount) + CMP_STATE(onlyDirectionalLights) + CMP_STATE(lightType) + CMP_STATE(texUnitMatrix) + CMP_STATE(useUniformInsteadOfVertexColor) + CMP_STATE(useVertexColorAsAmbientAndDiffuse) + CMP_STATE(useVertexColorAsEmission) + + CMP_STATE(fogMode) + + CMP_STATE(texUnitCount); + for (int i = 0; i < a.texUnitCount; i++) + { + CMP_STATE(texUnitCube[i]) + CMP_STATE(texUnitGen[i]) + } + return false; /* All equal, not lesser. */ +} + +bool FragmentStateCompareGLES30::operator() (FixedFunctionStateGLES30 const& a, FixedFunctionStateGLES30 const& b) const +{ + CMP_STATE(fogMode) + CMP_STATE(texUnitCount) + + for (int i = 0; i < a.texUnitCount; i++) + { + CMP_STATE(texUnitCube[i]) + CMP_STATE(texUnitGen[i]) + CMP_STATE(texUnitColorCombiner[i]) + CMP_STATE(texUnitAlphaCombiner[i]) + } + + CMP_STATE(addSpecularAfterTexturing) + CMP_STATE(alphaTest) + + return false; /* All equal, not lesser. */ +} + + +// --- VERTEX program ---------------------------------------------------------------------------- + +std::string BuildVertexShaderSourceGLES30 (const FixedFunctionStateGLES30& state) +{ + DBG_SHADER_VERBOSE_GLES30("ShaderGeneratorGLES30::BuildVertexShaderSource()\n"); + DBG_SHADER_VERBOSE_GLES30(" state: %s\n", state.ToString().c_str()); + + bool eyePositionRequired = (state.lightingEnabled && state.lightCount > 0 && !state.onlyDirectionalLights); + for (int i = 0; i < state.texUnitCount; i++) + if (state.texUnitGen[i]==kTexGenCubeReflect) + eyePositionRequired = true; + + std::ostringstream src; + + src << "#version 300 es\n"; + + /* Standard uniforms. */ + src << "uniform " << FixedFunctionProgramGLES30::kSLPropTransformBlock.GetName() << " {\n"; + src << " highp mat4 " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMVP) << ";\n"; + if (eyePositionRequired) + { + src << " highp mat4 " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMV) << ";\n"; + } + src << "};\n"; + + /* Default attributes. */ + src << "in highp vec4 _glesVertex;\n"; + src << "in mediump vec3 _glesNormal;\n"; + if (state.useUniformInsteadOfVertexColor) + src << "uniform lowp vec4 _glesFFColor;\n"; + else + src << "in lowp vec4 _glesColor;\n"; + + /* Default varyings. */ + src << "out lowp vec4 v_color;\n"; + + if (state.fogMode > kFogDisabled) + { + src << "uniform highp vec4 _glesFogParams;\n"; + src << "uniform lowp vec4 _glesFogColor;\n"; + src << "out lowp vec4 _glesFogColorPreMul;\n"; + src << "out lowp vec4 _glesFogVar;\n"; + } + + /* Texture coordinates and transformation matrices. */ + bool needTexUnitMatrix = false; + for (int i = 0; i < state.texUnitCount; i++) + { + src << "in " << (state.NeedTexUnitMatrix(i)?"highp":"mediump") << " vec4 _glesMultiTexCoord" << i << ";\n"; + if (!state.texUnitCube[i]) + { + if (state.texUnitGen[i] == kTexGenObject) + src << "out highp vec4 v_texGenObjCoord" << i << ";\n"; + else + src << "out mediump vec2 v_texCoord" << i << ";\n"; + } + else + { + src << "out highp vec3 v_texCoord" << i << ";\n"; + } + + if (!needTexUnitMatrix && state.NeedTexUnitMatrix(i)) + { + needTexUnitMatrix = true; + } + } + + if (needTexUnitMatrix) + { + src << "uniform " << FixedFunctionProgramGLES30::kSLPropUVTransformBlock.GetName() << " {\n"; + for (int i = 0; i < state.texUnitCount; ++i) + { + if(state.NeedTexUnitMatrix(i)) + src << " highp mat4 " << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << ";\n"; + } + src << "};\n"; + } + + /* Handle color -> material mapping. */ + const char* ambientColor = state.useVertexColorAsAmbientAndDiffuse ? "vertexColor" : "_glesFrontMaterial.ambient"; + const char* diffuseColor = state.useVertexColorAsAmbientAndDiffuse ? "vertexColor" : "_glesFrontMaterial.diffuse"; + const char* emissionColor = state.useVertexColorAsEmission ? "vertexColor" : "_glesFrontMaterial.emission"; + + /* Light params. */ + if (state.lightingEnabled) + { + src << "struct LightModelParameters {\n"; + src << " vec4 ambient;\n"; + src << "};\n"; + + src << "struct MaterialParameters {\n"; + src << " vec4 emission;\n"; + src << " vec4 ambient;\n"; + src << " vec4 diffuse;\n"; + src << " vec4 specular;\n"; + src << " float shininess;\n"; + src << "};\n"; + + src << "uniform LightModelParameters _glesLightModel;\n"; + src << "uniform MaterialParameters _glesFrontMaterial;\n"; + + if (state.lightCount > 0) + { + src << "struct LightSourceParameters {\n"; + src << " vec4 diffuse;\n"; + src << " vec4 position;\n"; + src << " vec3 spotDirection;\n"; + src << " vec4 atten;\n"; + src << "};\n"; + + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLightModelAmbient) << ";\n"; + for (int q = 0; q < kMaxEmulatedVertexLights; ++q) + { + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0Diffuse + q) << ";\n"; + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0Position + q) << ";\n"; + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0SpotDirection + q) << ";\n"; + src << "uniform vec4 " << GetBuiltinVectorParamName(kShaderVecLight0Atten + q) << ";\n"; + } + + src << "uniform mat3 _glesNormalMatrix;\n"; + + /* Compute functions. */ + src << "\nvec3 direction (vec4 from, vec4 to)\n"; + src << "{\n"; + src << " return (to.xyz * from.w - from.xyz * to.w);\n"; + src << "}\n"; + + src << "\nvec3 computeLighting(LightSourceParameters light, vec3 dirToLight, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " float NdotL = max(dot(eyeNormal, dirToLight), 0.0);\n"; + // \note in Unity, light ambient is always zero + src << " vec3 color = NdotL * " << diffuseColor << ".rgb * light.diffuse.rgb;\n"; + if (state.specularEnabled) + { + src << " if (NdotL > 0.0)\n"; + src << " {\n"; + src << " vec3 h = normalize(dirToLight + vec3(0.0, 0.0, 1.0));\n"; + src << " float HdotN = max(dot(eyeNormal, h), 0.0);\n"; + // \note in Unity, light specular color is always the same as diffuse color + src << " color += pow(HdotN, _glesFrontMaterial.shininess) * _glesFrontMaterial.specular.rgb * light.diffuse.rgb;\n"; + src << " }\n"; + } + src << " return color;\n"; + src << "}\n"; + + src << "\nvec3 computeDirLight(LightSourceParameters light, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " vec3 dirToLight = light.position.xyz;\n"; + // \note D3D backend uses min(val, 1.0). We use clamp(), because Img's wrapper is buggy! + src << " return clamp(computeLighting(light, dirToLight, eyeNormal, vertexColor), 0.0, 1.0);\n"; + src << "}\n"; + + src << "\nvec3 computePointLight(LightSourceParameters light, vec4 eyePosition, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " vec3 dirToLight = direction(eyePosition, light.position);\n"; + src << " float distSqr = dot(dirToLight, dirToLight);\n"; + // \note in Unity, const attenuation=1.0, linear=0.0 + src << " float att = 1.0 / (1.0 + light.atten.z * distSqr);\n"; + src << " dirToLight *= inversesqrt(distSqr);\n"; + // \note D3D backend uses min(val, 1.0). We use clamp(), because Img's wrapper is buggy! + src << " return clamp(att * computeLighting(light, dirToLight, eyeNormal, vertexColor), 0.0, 1.0);\n"; + src << "}\n"; + + src << "\nvec3 computeSpotLight(LightSourceParameters light, vec4 eyePosition, vec3 eyeNormal, vec4 vertexColor)\n"; + src << "{\n"; + src << " vec3 dirToLight = direction(eyePosition, light.position);\n"; + src << " float distSqr = dot(dirToLight, dirToLight);\n"; + // \note in Unity, const atten=1.0, linear=0.0 + src << " float att = 1.0 / (1.0 + light.atten.z * distSqr);\n"; + src << " dirToLight *= inversesqrt(distSqr);\n"; + src << " float rho = max(dot(dirToLight, light.spotDirection), 0.0);\n"; + src << " float spotAtt = (rho - light.atten.x) * light.atten.y;\n"; + src << " spotAtt = clamp(spotAtt, 0.0, 1.0);\n"; + // \note D3D backend uses min(val, 1.0). We use clamp(), because Img's wrapper is buggy! + src << " return clamp(att * spotAtt * computeLighting(light, dirToLight, eyeNormal, vertexColor), 0.0, 1.0);\n"; + //src << " return computeLighting(light, dirToLight, eyeNormal, vertexColor);\n"; // DEBUG DEBUG + + src << "}\n"; + } + } + + + + /* Main body. */ + src << "\nvoid main()\n"; + src << "{\n"; + + /* Vertex transformation. */ + src << " gl_Position = " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMVP) << " * _glesVertex;\n"; + + /* Unpack vertex color if necessary. */ + if (state.useUniformInsteadOfVertexColor) + src << " vec4 vertexColor = _glesFFColor;\n"; + else + src << " vec4 vertexColor = _glesColor;\n"; + + if (eyePositionRequired) + src << " highp vec4 eyePosition = " << GetShaderInstanceMatrixParamName (kShaderInstanceMatMV) << " * _glesVertex;\n"; + + /* Pass and transform texture coordinates. */ + for (int i = 0; i < state.texUnitCount; i++) + { + if (!state.texUnitCube[i]) + { + if (state.texUnitGen[i] == kTexGenObject) + { + Assert(state.NeedTexUnitMatrix(i)); + src << " v_texGenObjCoord" << i << " = "; + src << "(" << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << " * _glesMultiTexCoord" << i << ").xyzw;\n"; + } + else + { + if(state.NeedTexUnitMatrix(i)) + { + src << " vec4 tmpTexCoord" << i << " = (" << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << " * _glesMultiTexCoord" << i << ").xyzw;\n"; + if(state.IsTexUnitProjected(i)) + src << " v_texCoord" << i << " = tmpTexCoord" << i << ".xy / tmpTexCoord" << i << ".w;\n"; + else + src << " v_texCoord" << i << " = tmpTexCoord" << i << ".xy;\n"; + } + else + { + src << " v_texCoord" << i << " = _glesMultiTexCoord" << i << ".xy;\n"; + } + } + } + else + { + src << " v_texCoord" << i << " = "; + src << "vec3(" << GetShaderInstanceMatrixParamName (kShaderInstanceMatTexture0 + i) << " * _glesMultiTexCoord" << i << ");\n"; + if (state.texUnitGen[i] == kTexGenCubeReflect) + { + Assert(eyePositionRequired); + src << "{\n"; + src << " vec3 n = v_texCoord"<< i <<".xyz;\n"; + src << " v_texCoord"<< i <<" = reflect(eyePosition.xyz * eyePosition.w, n);\n"; + src << "}\n"; + } + } + } + + switch (state.fogMode) + { + case kFogLinear: + src << " _glesFogVar = vec4(clamp (_glesFogParams.z * gl_Position.z + _glesFogParams.w, 0.0, 1.0)); _glesFogVar.a = 1.0;\n"; + src << " _glesFogColorPreMul = _glesFogColor * (vec4(1.0)-_glesFogVar);\n"; + break; + case kFogExp: + src << " float _patchFog = _glesFogParams.y * gl_Position.z;\n"; + src << " _glesFogVar = vec4(clamp (exp2(-_patchFog), 0.0, 1.0)); _glesFogVar.a = 1.0;\n"; + src << " _glesFogColorPreMul = _glesFogColor * (vec4(1.0)-_glesFogVar);\n"; + break; + case kFogExp2: + src << " float _patchFog = _glesFogParams.x * gl_Position.z;\n"; + src << " _patchFog = _patchFog * _patchFog;\n"; + src << " _glesFogVar = vec4(clamp (exp2(-_patchFog), 0.0, 1.0)); _glesFogVar.a = 1.0;\n"; + src << " _glesFogColorPreMul = _glesFogColor * (vec4(1.0)-_glesFogVar);\n"; + break; + default: + break; + } + + /* Vertex color computation. */ + if (state.lightingEnabled) + { + src << " vec3 color = " << emissionColor << ".rgb + " << ambientColor << ".rgb * _glesLightModel.ambient.rgb;\n"; +// src << " color = vec3(0.0);\n"; // DEBUG DEBUG + + if (state.lightCount > 0) + { + src << " vec3 eyeNormal = normalize(_glesNormalMatrix * _glesNormal);\n"; + for (int i = 0; i < state.lightCount && i < kMaxEmulatedVertexLights; i++) + { + src << " LightSourceParameters light" << i << ";\n"; + src << " light" << i << ".diffuse = " << GetBuiltinVectorParamName(kShaderVecLight0Diffuse + i) << ";\n"; + src << " light" << i << ".position = " << GetBuiltinVectorParamName(kShaderVecLight0Position + i) << ";\n"; + src << " light" << i << ".spotDirection = " << GetBuiltinVectorParamName(kShaderVecLight0SpotDirection + i) << ".xyz;\n"; + src << " light" << i << ".atten = " << GetBuiltinVectorParamName(kShaderVecLight0Atten + i) << ";\n"; + + if(state.GetLightType(i) == kLightDirectional) + src << " color += computeDirLight(light" << i << ", eyeNormal, vertexColor);\n"; + else if(state.GetLightType(i) == kLightSpot) + src << " color += computeSpotLight(light" << i << ", eyePosition, eyeNormal, vertexColor);\n"; + else + src << " color += computePointLight(light" << i << ", eyePosition, eyeNormal, vertexColor);\n"; + + Assert(eyePositionRequired || state.GetLightType(i) == kLightDirectional); + } + } + + src << " float alpha = " << diffuseColor << ".a;\n"; + src << " v_color = vec4(color, alpha);\n"; + } + else + { + src << " v_color = vertexColor;\n"; + } + + src << "}\n"; + + DBG_SHADER_VERBOSE_GLES30("Generated VERTEX program:\n%s\n---\n", src.str().c_str()); + + return src.str().c_str(); +} + +// --- FRAGMENT program ---------------------------------------------------------------------------- + + +static void DecodeTextureCombinerDescriptor (unsigned int combinerDesc, + combiner::Operation& operation, + combiner::Source sources[3], + combiner::Operand operands[3], + int& scale) +{ + int srcBits0 = (combinerDesc >> combiner::kSrcZeroShift) & 0xFF; + int srcBits1 = combinerDesc & 0xFF; + int cf = COMBINER_GET_FUNC(combinerDesc); + + sources[0] = static_cast<combiner::Source>(srcBits0 & combiner::kSourceMask); + operands[0] = static_cast<combiner::Operand>(srcBits0 >> combiner::kOperandShift); + sources[1] = static_cast<combiner::Source>(srcBits1 & combiner::kSourceMask); + operands[1] = static_cast<combiner::Operand>(srcBits1 >> combiner::kOperandShift); + scale = (combinerDesc >> combiner::kScaleShift); + + if (cf & combiner::kBlendFuncMask) + { + int blendF = COMBINER_GET_BLEND_FUNC_INDEX(cf); + int src2 = cf & combiner::kSourceMask; + int oper2 = ((cf & combiner::kOperandTwo) >> combiner::kOperandShift) | 1; + + switch( blendF ) + { + case 1: + // src0 * src2 alpha + src1 + sources[2] = static_cast<combiner::Source>(src2); + operands[2] = static_cast<combiner::Operand>(oper2); + operation = combiner::kOpMulAdd; + break; + case 3: + // src0 * src2 alpha - src1 + sources[2] = static_cast<combiner::Source>(src2); + operands[2] = static_cast<combiner::Operand>(oper2); + operation = combiner::kOpMulSub; + break; + // If not supported or lerp combiner, must go below + case 0: + // src0 lerp(src2 alpha) src1 + // handeled by default + case 2: + // src0 * src2 alpha +- src1 + // not supported! + default: + if (blendF != 0) ErrorString("Combiner function not supported by OpenGLES, defaulting to LERP!"); + sources[2] = static_cast<combiner::Source>(src2); + operands[2] = static_cast<combiner::Operand>(oper2); + operation = combiner::kOpLerp; + break; + } + + + } + else + operation = static_cast<combiner::Operation>(cf); +} + +static void AddTexOperandSrc ( + std::ostringstream& src, + int unitNdx, + combiner::Channels channels, + combiner::Operand operand, + combiner::Source source) +{ + src << "("; + + if (operand == combiner::kOperOneMinusSrcAlpha || + operand == combiner::kOperOneMinusSrcColor) + { + src << "vec4(1.0) - "; + } + + switch (source) + { + case combiner::kSrcPrimaryColor: + src << "v_color"; + break; + + case combiner::kSrcPrevious: + src << "prev"; + break; + + case combiner::kSrcTexture: + src << "texture"; + break; + + case combiner::kSrcConstant: + src << "_glesTextureEnvColor" << unitNdx; + break; + + default: + printf_console("Error: Unsupported combiner source %d\n", source); + src << "vec4(1.0)"; /* Dummy value. */ + } + + src << ")"; + + switch (operand) + { + case combiner::kOperSrcColor: + case combiner::kOperOneMinusSrcColor: + if (channels == combiner::kRGBA) + src << ".rgba"; + else if (channels == combiner::kRGB) + src << ".rgb"; + else if (channels == combiner::kAlpha) + src << ".a"; + break; + + case combiner::kOperSrcAlpha: + case combiner::kOperOneMinusSrcAlpha: + if (channels == combiner::kRGBA) + src << ".aaaa"; + else if (channels == combiner::kRGB) + src << ".aaa"; + else if (channels == combiner::kAlpha) + src << ".a"; + break; + } +} + +static void AddTextureCombinerBody (std::ostringstream& src, int unitNdx, UInt32 combinerDesc, combiner::Channels channels) +{ + Assert(combiner::kRGBA == 0); + Assert(combiner::kRGB == 1); + Assert(combiner::kAlpha == 2); + + const std::string channelTypes[] = { "vec4", "vec3", "float" }; + const std::string channelMask[] = { "", ".rgb", ".a" }; + + + combiner::Source sources[3]; + combiner::Operand operands[3]; + combiner::Operation op; + int scale; + + DecodeTextureCombinerDescriptor(combinerDesc, + op, sources, operands, scale); + + if ((op == combiner::kOpDot3RGBA || op == combiner::kOpDot3RGB)) + { + if (channels == combiner::kAlpha) + return; + channels = combiner::kRGBA; + } + + src << " color" << channelMask[channels] << " = "; + + switch (op) + { + case combiner::kOpReplace: + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + break; + + case combiner::kOpModulate: + { + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " * "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + break; + } + + case combiner::kOpAdd: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " + "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + + case combiner::kOpSubtract: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " - "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + + case combiner::kOpAddSigned: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " + "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << " - " << channelTypes[channels] << "(0.5)"; + src << ")"; + break; + } + + case combiner::kOpLerp: + { + // NOTE: arguments of Unity LERP combiner are reversed for some reason + src << "mix("; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ", "; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << ", "; + AddTexOperandSrc(src, unitNdx, combiner::kAlpha, operands[2], sources[2]); + src << ")"; + break; + } + + case combiner::kOpDot3RGB: + { + if (channels == combiner::kRGBA) + { + src << channelTypes[channels] << "(vec3(4.0 * dot("; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[0], sources[0]); + src << " - vec3(0.5), "; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[1], sources[1]); + src << " - vec3(0.5))), "; + AddTexOperandSrc(src, unitNdx, combiner::kAlpha, operands[0], sources[0]); + src << ")"; + // Note: I am really not sure what goes into alpha channel when dot3_rgb is performed, it's definetly not the from dot + // My best guess, that original alpha value is kept + + } + else + { + src << channelTypes[channels] << "(4.0* dot("; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[0], sources[0]); + src << " - vec3(0.5), "; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[1], sources[1]); + src << " - vec3(0.5)))"; + } + break; + } + + case combiner::kOpDot3RGBA: + { + src << channelTypes[channels] << "(4.0 * dot("; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[0], sources[0]); + src << " - vec3(0.5), "; + AddTexOperandSrc(src, unitNdx, combiner::kRGB, operands[1], sources[1]); + src << " - vec3(0.5)))"; + break; + } + case combiner::kOpMulAdd: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " * "; + AddTexOperandSrc(src, unitNdx, channels, operands[2], sources[2]); + src << " + "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + case combiner::kOpMulSub: + { + src << "("; + AddTexOperandSrc(src, unitNdx, channels, operands[0], sources[0]); + src << " * "; + AddTexOperandSrc(src, unitNdx, channels, operands[2], sources[2]); + src << " - "; + AddTexOperandSrc(src, unitNdx, channels, operands[1], sources[1]); + src << ")"; + break; + } + default: + ErrorString(Format("Error: Unsupported combiner operation %d\n", op).c_str()); + + /* Dummy value. */ + src << channelTypes[channels] << "(1.0)"; + break; + } + + if (scale != 1) + src << " * float(" << scale << ".0)"; + src << ";\n"; +} + +static void AddTextureCombinerSrc (std::ostringstream& src, int unitNdx, bool isCube, UInt32 colorCombiner, UInt32 alphaCombiner) +{ + src << " {\n /* Combiner " << unitNdx << " */\n"; + + /* Perform lookup. */ + src << " lowp vec4 texture = " << "texture(u_sampler" << unitNdx << ", v_texCoord" << unitNdx << ");\n"; + + src << " lowp vec4 prev = " << ((unitNdx > 0)? "color": "v_color") << ";\n"; + + /* Combine. */ + if (colorCombiner == alphaCombiner) + { + // In case of color and alpha combiner being the same + // we calc all 4 channels in a single operation + // as some GLSL compilers (iPhone) will silently fail on following: + // color.rgb = arg0.rgb (op) arg1.rgb + // color.a = arg0.a (op) arg1.a + // instead we spit: + // color = arg0 (op) arg1 + // plus it is more readable + AddTextureCombinerBody(src, unitNdx, colorCombiner, combiner::kRGBA); + } + else + { + AddTextureCombinerBody(src, unitNdx, colorCombiner, combiner::kRGB); + AddTextureCombinerBody(src, unitNdx, alphaCombiner, combiner::kAlpha); + } + + src << " }\n"; +} + + +std::string BuildFragmentShaderSourceGLES30 (const FixedFunctionStateGLES30& state) +{ + DBG_SHADER_VERBOSE_GLES30("ShaderGeneratorGLES30::BuildFragmentShaderSource()\n"); + DBG_SHADER_VERBOSE_GLES30(" state: %s\n", state.ToString().c_str()); + + std::ostringstream src; + + src << "#version 300 es\n"; + + bool alphaTestEnabled = state.alphaTest != kFuncDisabled && + state.alphaTest != kFuncAlways; + + /* Default varyings. */ + src << "in lowp vec4 v_color;\n"; + + /* Uniforms. */ + if (alphaTestEnabled) + src << "uniform lowp float _glesAlphaTestReference;\n"; + + if (state.fogMode > kFogDisabled) + { + src << "in lowp vec4 _glesFogColorPreMul;\n"; + src << "in lowp vec4 _glesFogVar;\n"; + } + + /* Texture units. */ + for (int i = 0; i < state.texUnitCount; i++) + { + if (!state.texUnitCube[i]) + { + if (state.texUnitGen[i] == kTexGenObject) + src << "in highp vec4 v_texGenObjCoord" << i << ";\n"; + else + src << "in mediump vec2 v_texCoord" << i << ";\n"; + + src << "uniform sampler2D u_sampler" << i << ";\n"; + } + else + { + src << "in highp vec3 v_texCoord" << i << ";\n"; + src << "uniform samplerCube u_sampler" << i << ";\n"; + } + + src << "uniform lowp vec4 _glesTextureEnvColor" << i << ";\n"; + } + + + /* Main body. */ + src << "out lowp vec4 _glesFragColor;\n"; + src << "\nvoid main()\n"; + src << "{\n"; + + /* Initialize color. */ + src << " lowp vec4 color = v_color;\n"; + + /* Generate correct texCoords if we have texGenObject */ + for (int i = 0; i < state.texUnitCount; i++) + { + if (!state.texUnitCube[i] && state.texUnitGen[i] == kTexGenObject) + src << " highp vec2 v_texCoord" << i << " = v_texGenObjCoord" << i << ".xy / v_texGenObjCoord" << i << ".w;\n"; + } + + /* Texturing. */ + for (int i = 0; i < state.texUnitCount; i++) + AddTextureCombinerSrc(src, i, state.texUnitCube[i], state.texUnitColorCombiner[i], state.texUnitAlphaCombiner[i]); + + if (state.fogMode > kFogDisabled) + src << " _glesFragColor = color * _glesFogVar + _glesFogColorPreMul;\n"; + else + src << " _glesFragColor = color;\n"; + + /* Alpha test. */ + if (alphaTestEnabled) + { + Assert(gGraphicsCaps.gles30.hasAlphaTestQCOM == false); + + if (state.alphaTest == kFuncNever) + { + // ToDo: Do we just discard everything, or skip drawing itself at vbo level? + src << " discard;\n"; + } + else + { + // Reverse logic because we're using here 'discard' + static const char* s_cmpOps[] = + { + "", // kFuncDisabled + "", // kFuncNever + ">=", // kFuncLess + "!=", // kFuncEqual + ">", // kFuncLEqual + "<=", // kFuncGreater + "==", // kFuncNotEqual + "<", // kFuncGEqual + "", // kFuncAlways + }; + + src << " if (color.a " << s_cmpOps[state.alphaTest] << "_glesAlphaTestReference)\n"; + src << " discard;\n"; + } + } +// src << " gl_FragColor = vec4(v_color.xyz, 1.0);\n"; // DEBUG DEBUG +// src << " gl_FragColor = 0.5 * texture2D(u_sampler0, v_texCoord0);\n"; // DEBUG DEBUG +// src << " gl_FragColor = vec4(_glesTextureEnvColor0.rgb, 1.0);\n"; // DEBUG DEBUG + src << "}\n"; + + DBG_SHADER_VERBOSE_GLES30("Generated FRAGMENT program:\n%s\n---\n", src.str().c_str()); + + return src.str().c_str(); +} diff --git a/Runtime/GfxDevice/opengles30/ShaderGeneratorGLES30.h b/Runtime/GfxDevice/opengles30/ShaderGeneratorGLES30.h new file mode 100644 index 0000000..57e0045 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/ShaderGeneratorGLES30.h @@ -0,0 +1,24 @@ +#ifndef SHADERGENERATOR_GLES30_H +#define SHADERGENERATOR_GLES30_H + +#include <string> + +class FixedFunctionStateGLES30; + +std::string BuildVertexShaderSourceGLES30 (const FixedFunctionStateGLES30& state); +std::string BuildFragmentShaderSourceGLES30 (const FixedFunctionStateGLES30& state); + +struct FullStateCompareGLES30 +{ + bool operator() (FixedFunctionStateGLES30 const& a, FixedFunctionStateGLES30 const& b) const; +}; +struct VertexStateCompareGLES30 +{ + bool operator() (FixedFunctionStateGLES30 const& a, FixedFunctionStateGLES30 const& b) const; +}; +struct FragmentStateCompareGLES30 +{ + bool operator() (FixedFunctionStateGLES30 const& a, FixedFunctionStateGLES30 const& b) const; +}; + +#endif /* SHADERGENERATOR_GLES30_H */ diff --git a/Runtime/GfxDevice/opengles30/TextureIdMapGLES30.h b/Runtime/GfxDevice/opengles30/TextureIdMapGLES30.h new file mode 100644 index 0000000..b0bcd2e --- /dev/null +++ b/Runtime/GfxDevice/opengles30/TextureIdMapGLES30.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/TextureIdMap.h" +#include "IncludesGLES30.h" + +inline GLuint TextureIdMapGLES30_QueryOrCreate(TextureID texid) +{ + GLuint ret = (GLuint)TextureIdMap::QueryNativeTexture(texid); + if(ret == 0) + { + GLES_CHK(glGenTextures(1, &ret)); + TextureIdMap::UpdateTexture(texid, ret); + } + + return ret; +} diff --git a/Runtime/GfxDevice/opengles30/TexturesGLES30.cpp b/Runtime/GfxDevice/opengles30/TexturesGLES30.cpp new file mode 100644 index 0000000..ba3885c --- /dev/null +++ b/Runtime/GfxDevice/opengles30/TexturesGLES30.cpp @@ -0,0 +1,535 @@ +#include "UnityPrefix.h" +#include "TexturesGLES30.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" +#include "Runtime/Graphics/Image.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/TextureUploadUtils.h" +#include "Runtime/Graphics/S3Decompression.h" +#include "Runtime/Graphics/Texture2D.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Utilities/BitUtility.h" +#include "IncludesGLES30.h" +#include "AssertGLES30.h" +#include "DebugGLES30.h" +#include "TextureIdMapGLES30.h" + +#include <vector> + +#if GFX_SUPPORTS_OPENGLES30 + +struct TextureFormatInfoGLES30 +{ + enum Type + { + kTypeReserved = 0, //!< Reserved format (should not be used). + kTypeUncompressed, //!< Uncompressed, natively supported format. + kTypeNonNative, //!< Uncompressed, but not supported format. Requires swizzle to nativeFormat. + kTypeCompressed //!< Compressed format. If not supported, always decompressed to kTexFormatRGBA32 + }; + + Type type; //!< Texture format type, as interpreted by ES3. + + UInt32 linearInternalFormat; //!< Internal format for linear color space + UInt32 sRGBInternalFormat; //!< Internal format for sRGB color space or 0 if not supported + + UInt32 transferFormat; //!< Transfer format, or 0 if compressed texture + UInt32 dataType; //!< Transfer data type, or 0 if compressed texture + + TextureFormat nativeFormat; //!< Data must be converted to this format first. +}; + +static const TextureFormatInfoGLES30 s_textureFormatInfos[] = +{ +#define _RES { TextureFormatInfoGLES30::kTypeReserved, 0, 0, 0, 0, 0 } +#define _NAT(NATIVE) { TextureFormatInfoGLES30::kTypeNonNative, 0, 0, 0, 0, NATIVE } +#define _UNC(LINEAR, TRANSFERFMT, DATATYPE) { TextureFormatInfoGLES30::kTypeUncompressed, LINEAR, 0, TRANSFERFMT, DATATYPE, 0 } +#define _SRG(LINEAR, SRGB, TRANSFERFMT, DATATYPE) { TextureFormatInfoGLES30::kTypeUncompressed, LINEAR, SRGB, TRANSFERFMT, DATATYPE, 0 } +#define _CMP(LINEAR, SRGB) { TextureFormatInfoGLES30::kTypeCompressed, LINEAR, SRGB, 0, 0, 0 } + + /* 0 */ _RES, + /* kTexFormatAlpha8 */ _UNC(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE), + /* kTexFormatARGB4444 */ _UNC(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), // \todo [2013-05-03 pyry] Should we swizzle this? + /* kTexFormatRGB24 */ _SRG(GL_RGB8, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE), + /* kTexFormatRGBA32 */ _SRG(GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE), + /* kTexFormatARGB32 */ _NAT(kTexFormatRGBA32), + /* kTexFormatARGBFloat */ _UNC(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT), + /* kTexFormatRGB565 */ _UNC(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5), + /* kTexFormatBGR24 */ _NAT(kTexFormatRGB24), + /* kTexFormatAlphaLum16 */ _UNC(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE), + /* kTexFormatDXT1 */ _CMP(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_S3TC_DXT1_NV), + /* kTexFormatDXT3 */ _CMP(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV), + /* kTexFormatDXT5 */ _CMP(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV), + /* kTexFormatRGBA4444 */ _UNC(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4), + /* kTexReserved1 */ _RES, + /* kTexReserved2 */ _RES, + /* kTexReserved3 */ _RES, + /* kTexReserved4 */ _RES, + /* kTexReserved5 */ _RES, + /* kTexReserved6 */ _RES, + /* reserved (wii) 0 */ _RES, + /* reserved (wii) 1 */ _RES, + /* reserved (wii) 2 */ _RES, + /* reserved (wii) 3 */ _RES, + /* reserved (wii) 4 */ _RES, + /* reserved (wii) 5 */ _RES, + /* reserved (wii) 6 */ _RES, + /* reserved (wii) 7 */ _RES, + /* kTexReserved11 */ _RES, + /* kTexReserved12 */ _RES, + /* kTexFormatPVRTC_RGB2 */ _CMP(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 0), + /* kTexFormatPVRTC_RGBA2 */ _CMP(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 0), + /* kTexFormatPVRTC_RGB4 */ _CMP(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 0), + /* kTexFormatPVRTC_RGBA4 */ _CMP(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 0), + /* kTexFormatETC_RGB4 */ _CMP(GL_COMPRESSED_RGB8_ETC2, 0), + /* kTexFormatATC_RGB4 */ _CMP(GL_ATC_RGB_AMD, 0), + /* kTexFormatATC_RGBA8 */ _CMP(GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, 0), + /* kTexFormatBGRA32 */ _NAT(kTexFormatRGBA32), // \todo [2013-05-03 pyry] Use BGRA extension if possible. + /* kTexFormatFlashATF_RGB_DXT1 */ _RES, + /* kTexFormatFlashATF_RGBA_JPG */ _RES, + /* kTexFormatFlashATF_RGB_JPG */ _RES, + /* kTexFormatEAC_R */ _CMP(GL_COMPRESSED_R11_EAC, 0), + /* kTexFormatEAC_R_SIGNED */ _CMP(GL_COMPRESSED_SIGNED_R11_EAC, 0), + /* kTexFormatEAC_RG */ _CMP(GL_COMPRESSED_RG11_EAC, 0), + /* kTexFormatEAC_RG_SIGNED */ _CMP(GL_COMPRESSED_SIGNED_RG11_EAC, 0), + /* kTexFormatETC2_RGB */ _CMP(GL_COMPRESSED_RGB8_ETC2, 0), + /* kTexFormatETC2_RGBA1 */ _CMP(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 0), + /* kTexFormatETC2_RGBA8 */ _CMP(GL_COMPRESSED_RGBA8_ETC2_EAC, 0), + /*kTexFormatASTC_RGB_4x4 */ _CMP(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 0), + /*kTexFormatASTC_RGB_5x5 */ _CMP(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 0), + /*kTexFormatASTC_RGB_6x6 */ _CMP(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 0), + /*kTexFormatASTC_RGB_8x8 */ _CMP(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 0), + /*kTexFormatASTC_RGB_10x10 */ _CMP(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 0), + /*kTexFormatASTC_RGB_12x12 */ _CMP(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 0), + + /*kTexFormatASTC_RGBA_4x4 */ _CMP(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 0), + /*kTexFormatASTC_RGBA_5x5 */ _CMP(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 0), + /*kTexFormatASTC_RGBA_6x6 */ _CMP(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 0), + /*kTexFormatASTC_RGBA_8x8 */ _CMP(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 0), + /*kTexFormatASTC_RGBA_10x10 */ _CMP(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 0), + /*kTexFormatASTC_RGBA_12x12 */ _CMP(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 0), + +#undef _CMP +#undef _SRG +#undef _NAT +#undef _UNC +#undef _RES +}; + +// Static assert for array size. +typedef char __gles3TexFormatTableSizeAssert[(int)(sizeof(s_textureFormatInfos) / sizeof(s_textureFormatInfos[0])) == kTexFormatTotalCount ? 1 : - 1]; + +static const TextureFormatInfoGLES30& GetTextureFormatInfoGLES30 (TextureFormat format) +{ + Assert(0 <= format && format < (int)(sizeof(s_textureFormatInfos)/sizeof(s_textureFormatInfos[0]))); + return s_textureFormatInfos[format]; +} + +static inline bool IsTextureFormatSupported (TextureFormat format) +{ + return gGraphicsCaps.supportsTextureFormat[format]; +} + +static const char* GetCompressedTextureFormatName (TextureFormat format) +{ + if (IsCompressedPVRTCTextureFormat(format)) + return "PVRTC"; + else if (IsCompressedDXTTextureFormat(format)) + return "DXT"; + else if (IsCompressedETCTextureFormat(format)) + return "ETC1"; + else if (IsCompressedATCTextureFormat(format)) + return "ATC"; + else if (IsCompressedETC2TextureFormat(format)) + return "ETC2"; + else if (IsCompressedEACTextureFormat(format)) + return "EAC"; + else + return "UNKNOWN"; +} + +static void GetDecompressBlockSize (TextureFormat format, int& width, int& height) +{ + // \todo [2013-05-06 pyry] Is there any format that doesn't use 4x4 blocks? + width = 4; + height = 4; +} + +static inline int GetDecompressBlockWidth (TextureFormat format) +{ + int w, h; + GetDecompressBlockSize(format, w, h); + return w; +} + +static inline int GetDecompressBlockHeight (TextureFormat format) +{ + int w, h; + GetDecompressBlockSize(format, w, h); + return h; +} + +static inline int AlignToBlockSize (int dim, int blockSize) +{ + if (dim % blockSize != 0) + return dim + blockSize - (dim % blockSize); + else + return dim; +} + +static int UploadPyramidCompressed (UInt32 target, + TextureFormat format, + bool sRGB, + int width, + int height, + int numLevels, + const UInt8* data) +{ + Assert(IsTextureFormatSupported(format)); + + const TextureFormatInfoGLES30& formatInfo = GetTextureFormatInfoGLES30(format); + const bool isSRGBUploadOk = formatInfo.sRGBInternalFormat != 0; + const UInt32 internalFormat = (sRGB && isSRGBUploadOk) ? formatInfo.sRGBInternalFormat : formatInfo.linearInternalFormat; + const UInt8* curDataPtr = data; + int totalUploadSize = 0; + + for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) + { + const int levelW = std::max<int>(width>>levelNdx, 1); + const int levelH = std::max<int>(height>>levelNdx, 1); + const int levelSize = CalculateImageSize(levelW, levelH, format); + const int uploadLevel = levelNdx; + + GLES_CHK(glCompressedTexImage2D(target, levelNdx, internalFormat, levelW, levelH, 0, levelSize, curDataPtr)); + + curDataPtr += levelSize; + totalUploadSize += levelSize; + } + + return totalUploadSize; +} + +static int UploadPyramidDecompress (UInt32 target, + TextureFormat format, + bool sRGB, + int width, + int height, + int numLevels, + const UInt8* data) +{ + const TextureFormatInfoGLES30& formatInfo = GetTextureFormatInfoGLES30(format); + const TextureFormat decompressFormat = kTexFormatRGBA32; + const TextureFormatInfoGLES30& uploadFormat = GetTextureFormatInfoGLES30(decompressFormat); + const bool isSRGBUploadOk = uploadFormat.sRGBInternalFormat != 0; + const UInt32 internalFormat = (sRGB && isSRGBUploadOk) ? uploadFormat.sRGBInternalFormat : uploadFormat.linearInternalFormat; + const UInt8* curDataPtr = data; + const int blockW = GetDecompressBlockWidth(format); + const int blockH = GetDecompressBlockHeight(format); + int totalUploadSize = 0; + std::vector<UInt8> decompressBuffer (CalculateImageSize(AlignToBlockSize(width, blockW), AlignToBlockSize(height, blockH), decompressFormat)); + + for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) + { + const int levelW = std::max<int>(width>>levelNdx, 1); + const int levelH = std::max<int>(height>>levelNdx, 1); + const int levelSize = CalculateImageSize(levelW, levelH, format); + const int decompressW = AlignToBlockSize(levelW, blockW); + const int decompressH = AlignToBlockSize(levelH, blockH); + const int decompressSize = CalculateImageSize(decompressW, decompressH, decompressFormat); + + Assert(decompressSize <= (int)decompressBuffer.size()); + if (!DecompressNativeTextureFormat(format, levelW, levelH, (UInt32*)curDataPtr, decompressW, decompressH, (UInt32*)&decompressBuffer[0])) + ErrorStringMsg("Decompressing level %d failed!", levelNdx); + + GLES_CHK(glTexImage2D(target, levelNdx, internalFormat, levelW, levelH, 0, uploadFormat.transferFormat, uploadFormat.dataType, &decompressBuffer[0])); + + curDataPtr += levelSize; + totalUploadSize += decompressSize; + } + + return totalUploadSize; +} + +static int UploadPyramidConvert (UInt32 target, + TextureFormat srcFormat, + TextureFormat dstFormat, + bool sRGB, + int width, + int height, + int numLevels, + const UInt8* data) +{ + const TextureFormatInfoGLES30& dstFormatInfo = GetTextureFormatInfoGLES30(dstFormat); + const bool isSRGBUploadOk = dstFormatInfo.sRGBInternalFormat != 0; + const UInt32 internalFormat = (sRGB && isSRGBUploadOk) ? dstFormatInfo.sRGBInternalFormat : dstFormatInfo.linearInternalFormat; + const UInt8* curDataPtr = data; + int totalUploadSize = 0; + std::vector<UInt8> convertBuffer (CalculateImageSize(width, height, dstFormat)); + + for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) + { + const int levelW = std::max<int>(width>>levelNdx, 1); + const int levelH = std::max<int>(height>>levelNdx, 1); + const int levelSize = CalculateImageSize(levelW, levelH, srcFormat); + + ImageReference src (levelW, levelH, GetRowBytesFromWidthAndFormat(levelW, srcFormat), srcFormat, (UInt8*)curDataPtr); + ImageReference dst (levelW, levelH, GetRowBytesFromWidthAndFormat(levelW, dstFormat), dstFormat, &convertBuffer[0]); + + dst.BlitImage(src); + + GLES_CHK(glTexImage2D(target, levelNdx, internalFormat, levelW, levelH, 0, dstFormatInfo.transferFormat, dstFormatInfo.dataType, &convertBuffer[0])); + + curDataPtr += levelSize; + totalUploadSize += dst.GetRowBytes()*dst.GetHeight(); + } + + return totalUploadSize; +} + +static int UploadPyramid (UInt32 target, + TextureFormat format, + bool sRGB, + int width, + int height, + int numLevels, + const UInt8* data) +{ + const TextureFormatInfoGLES30& formatInfo = GetTextureFormatInfoGLES30(format); + const bool isSRGBUploadOk = formatInfo.sRGBInternalFormat != 0; + const UInt32 internalFormat = (sRGB && isSRGBUploadOk) ? formatInfo.sRGBInternalFormat : formatInfo.linearInternalFormat; + const UInt8* curDataPtr = data; + int totalUploadSize = 0; + + for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) + { + const int levelW = std::max<int>(width>>levelNdx, 1); + const int levelH = std::max<int>(height>>levelNdx, 1); + const int levelSize = CalculateImageSize(levelW, levelH, format); + + GLES_CHK(glTexImage2D(target, levelNdx, internalFormat, levelW, levelH, 0, formatInfo.transferFormat, formatInfo.dataType, curDataPtr)); + + curDataPtr += levelSize; + totalUploadSize += levelSize; + } + + return totalUploadSize; +} + +void UploadTexture2DGLES3 (TextureID texID, + TextureDimension dimension, + UInt8* srcData, + int width, + int height, + TextureFormat format, + int mipCount, + UInt32 uploadFlags, + int skipMipLevels, + TextureColorSpace colorSpace) +{ + Assert(dimension == kTexDim2D); // \todo [2013-05-03 pyry] Remove parameter. + + const TextureFormatInfoGLES30& formatInfo = GetTextureFormatInfoGLES30(format); + const bool isSRGB = colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB; + const bool isCompressed = formatInfo.type == TextureFormatInfoGLES30::kTypeCompressed; + const bool decompress = isCompressed && !IsTextureFormatSupported(format); + const bool convertToNative = formatInfo.type == TextureFormatInfoGLES30::kTypeNonNative; + int totalUploadSize = 0; + + Assert(!decompress || !convertToNative); + Assert(skipMipLevels < mipCount); + + if (decompress) + printf_console("WARNING: %s compressed texture format not supported, decompressing!\n", GetCompressedTextureFormatName(format)); + else if (convertToNative) + printf_console("WARNING: no native support for texture format %d, converting to %d!\n", format, formatInfo.nativeFormat); + + // Create and bind texture. + TextureIdMapGLES30_QueryOrCreate(texID); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, texID, dimension, std::numeric_limits<float>::infinity()); + + // \todo [2013-05-03 pyry] Select unpack alignment based on pixel format + GLES_CHK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + + // Upload parameters. + const int baseLevelW = std::max<int>(1, width >> skipMipLevels); + const int baseLevelH = std::max<int>(1, height >> skipMipLevels); + const int numLevelsUpload = mipCount-skipMipLevels; + const UInt8* baseLevelPtr = srcData; + + // Adjust data pointer by number of levels skipped. + // \todo [2013-045-03 pyry] Skip levels if they are too large for HW. + for (int levelNdx = 0; levelNdx < skipMipLevels; levelNdx++) + { + int levelW = std::max<int>(1, width >> levelNdx); + int levelH = std::max<int>(1, height >> levelNdx); + int levelSize = CalculateImageSize(levelW, levelH, format); + + baseLevelPtr += levelSize; + } + + // Call upload. + if (isCompressed) + { + if (decompress) + totalUploadSize = UploadPyramidDecompress(GL_TEXTURE_2D, format, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, baseLevelPtr); + else + totalUploadSize = UploadPyramidCompressed(GL_TEXTURE_2D, format, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, baseLevelPtr); + } + else + { + if (convertToNative) + totalUploadSize = UploadPyramidConvert(GL_TEXTURE_2D, format, formatInfo.nativeFormat, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, baseLevelPtr); + else + totalUploadSize = UploadPyramid(GL_TEXTURE_2D, format, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, baseLevelPtr); + } + + GLES_CHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, numLevelsUpload-1)); + + REGISTER_EXTERNAL_GFX_DEALLOCATION(texID.m_ID); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texID.m_ID, totalUploadSize, texID.m_ID); +} + +void UploadTextureSubData2DGLES3 (TextureID texID, + UInt8* srcData, + int mipLevel, + int x, + int y, + int width, + int height, + TextureFormat format, + TextureColorSpace colorSpace) +{ + const TextureFormatInfoGLES30& formatInfo = GetTextureFormatInfoGLES30(format); + const bool isSRGB = colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB; + const bool isCompressed = formatInfo.type == TextureFormatInfoGLES30::kTypeCompressed; + const bool decompress = isCompressed && !IsTextureFormatSupported(format); + const bool convertToNative = formatInfo.type == TextureFormatInfoGLES30::kTypeNonNative; + const TextureFormatInfoGLES30& uploadInfo = convertToNative ? GetTextureFormatInfoGLES30(formatInfo.nativeFormat) : formatInfo; + int totalUploadSize = 0; + const UInt32 target = GL_TEXTURE_2D; + + Assert(!decompress || !convertToNative); + + if (decompress) + printf_console("WARNING: %s compressed texture format not supported, decompressing!\n", GetCompressedTextureFormatName(format)); + else if (convertToNative) + printf_console("WARNING: no native support for texture format %d, converting to %d!\n", format, formatInfo.nativeFormat); + + // Create and bind texture. + TextureIdMapGLES30_QueryOrCreate(texID); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, texID, kTexDim2D, std::numeric_limits<float>::infinity()); + + // \todo [2013-05-03 pyry] Select unpack alignment based on pixel format + GLES_CHK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + + if (isCompressed) + { + if (decompress) + { + const int blockW = GetDecompressBlockWidth(format); + const int blockH = GetDecompressBlockHeight(format); + const int decompressW = AlignToBlockSize(width, blockW); + const int decompressH = AlignToBlockSize(height, blockH); + std::vector<UInt8> decompressBuffer (CalculateImageSize(decompressW, decompressH, format)); + + if (!DecompressNativeTextureFormat(format, width, height, (const UInt32*)srcData, decompressW, decompressH, (UInt32*)&decompressBuffer[0])) + ErrorString("Decompressing texture data failed!"); + + GLES_CHK(glTexSubImage2D(target, mipLevel, x, y, width, height, uploadInfo.transferFormat, uploadInfo.dataType, &decompressBuffer[0])); + } + else + { + const int dataSize = CalculateImageSize(width, height, format); + GLES_CHK(glCompressedTexSubImage2D(target, mipLevel, x, y, width, height, uploadInfo.linearInternalFormat, dataSize, srcData)); + } + } + else + { + if (convertToNative) + { + std::vector<UInt8> convertBuffer (CalculateImageSize(width, height, formatInfo.nativeFormat)); + ImageReference src (width, height, GetRowBytesFromWidthAndFormat(width, format), format, srcData); + ImageReference dst (width, height, GetRowBytesFromWidthAndFormat(width, formatInfo.nativeFormat), formatInfo.nativeFormat, &convertBuffer[0]); + + dst.BlitImage(src); + + GLES_CHK(glTexSubImage2D(target, mipLevel, x, y, width, height, uploadInfo.transferFormat, uploadInfo.dataType, &convertBuffer[0])); + } + else + GLES_CHK(glTexSubImage2D(target, mipLevel, x, y, width, height, uploadInfo.transferFormat, uploadInfo.dataType, srcData)); + } +} + +void UploadTextureCubeGLES3 (TextureID texID, + UInt8* srcData, + int faceDataSize, + int size, + TextureFormat format, + int mipCount, + UInt32 uploadFlags, + TextureColorSpace colorSpace) +{ + const TextureFormatInfoGLES30& formatInfo = GetTextureFormatInfoGLES30(format); + const bool isSRGB = colorSpace == kTexColorSpaceSRGBXenon || colorSpace == kTexColorSpaceSRGB; + const bool isCompressed = formatInfo.type == TextureFormatInfoGLES30::kTypeCompressed; + const bool decompress = isCompressed && !IsTextureFormatSupported(format); + const bool convertToNative = formatInfo.type == TextureFormatInfoGLES30::kTypeNonNative; + int totalUploadSize = 0; + + Assert(!decompress || !convertToNative); + + if (decompress) + printf_console("WARNING: %s compressed texture format not supported, decompressing!\n", GetCompressedTextureFormatName(format)); + else if (convertToNative) + printf_console("WARNING: no native support for texture format %d, converting to %d!\n", format, formatInfo.nativeFormat); + + // Create and bind texture. + TextureIdMapGLES30_QueryOrCreate(texID); + GetRealGfxDevice().SetTexture (kShaderFragment, 0, 0, texID, kTexDimCUBE, std::numeric_limits<float>::infinity()); + + // \todo [2013-05-03 pyry] Select unpack alignment based on pixel format + GLES_CHK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + + // \todo [2013-045-03 pyry] Skip levels if they are too large for HW. + const int baseLevelOffset = 0; + const int baseLevelW = size; + const int baseLevelH = size; + const int numLevelsUpload = mipCount; + + const GLenum faces[6] = + { + GL_TEXTURE_CUBE_MAP_POSITIVE_X, + GL_TEXTURE_CUBE_MAP_NEGATIVE_X, + GL_TEXTURE_CUBE_MAP_POSITIVE_Y, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + GL_TEXTURE_CUBE_MAP_POSITIVE_Z, + GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + }; + + for (int faceNdx = 0; faceNdx < 6; faceNdx++) + { + const UInt8* facePtr = (srcData + faceNdx*faceDataSize) + baseLevelOffset; + const UInt32 target = faces[faceNdx]; + + if (isCompressed) + { + if (decompress) + totalUploadSize = UploadPyramidDecompress(target, format, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, facePtr); + else + totalUploadSize = UploadPyramidCompressed(target, format, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, facePtr); + } + else + { + if (convertToNative) + totalUploadSize = UploadPyramidConvert(target, format, formatInfo.nativeFormat, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, facePtr); + else + totalUploadSize = UploadPyramid(target, format, isSRGB, baseLevelW, baseLevelH, numLevelsUpload, facePtr); + } + } + + GLES_CHK(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, numLevelsUpload-1)); + + REGISTER_EXTERNAL_GFX_DEALLOCATION(texID.m_ID); + REGISTER_EXTERNAL_GFX_ALLOCATION_REF(texID.m_ID, totalUploadSize, texID.m_ID); +} + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/TexturesGLES30.h b/Runtime/GfxDevice/opengles30/TexturesGLES30.h new file mode 100644 index 0000000..94fbb31 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/TexturesGLES30.h @@ -0,0 +1,22 @@ +#ifndef UNITY_TEXTURES_GLES_H_ +#define UNITY_TEXTURES_GLES_H_ + +#include "Configuration/UnityConfigure.h" +#include "Runtime/Graphics/TextureFormat.h" +#include "Runtime/GfxDevice/GfxDeviceTypes.h" + +class ImageReference; + +// \todo [2013-05-03 pyry] Clean up this interface. + +void UploadTexture2DGLES3( + TextureID glname, TextureDimension dimension, UInt8* srcData, int width, int height, + TextureFormat format, int mipCount, UInt32 uploadFlags, int masterTextureLimit, TextureColorSpace colorSpace ); +void UploadTextureSubData2DGLES3( + TextureID glname, UInt8* srcData, + int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); +void UploadTextureCubeGLES3( + TextureID tid, UInt8* srcData, int faceDataSize, int size, + TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + +#endif // UNITY_TEXTURES_GLES_H_ diff --git a/Runtime/GfxDevice/opengles30/TimerQueryGLES30.cpp b/Runtime/GfxDevice/opengles30/TimerQueryGLES30.cpp new file mode 100644 index 0000000..b59b178 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/TimerQueryGLES30.cpp @@ -0,0 +1,100 @@ +#include "UnityPrefix.h" +#if ENABLE_PROFILER && GFX_SUPPORTS_OPENGLES30 +#include "TimerQueryGLES30.h" +#include "AssertGLES30.h" +#include "UnityGLES30Ext.h" +#include "Runtime/Shaders/GraphicsCaps.h" + +bool TimerQueriesGLES30::Init() +{ + Assert(!gGraphicsCaps.hasTimerQuery || QueryExtension("GL_NV_timer_query")); + + if (gGraphicsCaps.hasTimerQuery) + GLES_CHK(glGenQueries(kQueriesCount, timestamp_gl)); + + nextIndex = 0; + return true; +} + +void TimerQueriesGLES30::BeginTimerQueries() +{ + GLES_CHK(glFlush()); + SetTimestamp(); +} + +void TimerQueriesGLES30::EndTimerQueries() +{ + GLES_CHK(glFlush()); +} + +unsigned TimerQueriesGLES30::SetTimestamp() +{ + // \todo [2013-04-17 pyry] glQueryCounter is not in ES3 +#if 0 + GLES_CHK(gGles3ExtFunc.glQueryCounterNV(timestamp_gl[nextIndex], GL_TIMESTAMP_NV)); +#endif + unsigned ret = nextIndex; + + ++nextIndex; + if(nextIndex == kQueriesCount) + nextIndex = 0; + + return ret; +} + +UInt64 TimerQueriesGLES30::GetElapsedTime(unsigned idx, bool wait) +{ + GLuint available = 0; + GLES_CHK(glGetQueryObjectuiv(timestamp_gl[idx], GL_QUERY_RESULT_AVAILABLE, &available)); + // sometimes timestamp might be not ready (we still dont know why) + // the only workaround would be to add glFlush into SetTimestamp + // but then some timings will be a bit off + if(wait) + { + for(unsigned i = 0 ; i < 100 && !available ; ++i) + { + GLES_CHK(glGetQueryObjectuiv(timestamp_gl[idx], GL_QUERY_RESULT_AVAILABLE, &available)); + } + } + + if(available) + { + unsigned prev_idx = idx > 0 ? idx-1 : kQueriesCount-1; + + // \todo [2013-04-17 pyry] i64 variant? + GLuint time1, time2; + GLES_CHK(glGetQueryObjectuiv(timestamp_gl[prev_idx], GL_QUERY_RESULT, &time1)); + GLES_CHK(glGetQueryObjectuiv(timestamp_gl[idx], GL_QUERY_RESULT, &time2)); + + return time2-time1; + } + + return kInvalidProfileTime; + +} + + +TimerQueryGLES30::TimerQueryGLES30() + : m_Index(0), + m_Time(kInvalidProfileTime) +{ +} + +void TimerQueryGLES30::Measure() +{ + m_Index = g_TimerQueriesGLES30.SetTimestamp(); + m_Time = kInvalidProfileTime; +} + +ProfileTimeFormat TimerQueryGLES30::GetElapsed(UInt32 flags) +{ + if(m_Time == kInvalidProfileTime) + m_Time = g_TimerQueriesGLES30.GetElapsedTime(m_Index, (flags & kWaitRenderThread) != 0); + + return m_Time; +} + +TimerQueriesGLES30 g_TimerQueriesGLES30; + + +#endif diff --git a/Runtime/GfxDevice/opengles30/TimerQueryGLES30.h b/Runtime/GfxDevice/opengles30/TimerQueryGLES30.h new file mode 100644 index 0000000..9bf7e22 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/TimerQueryGLES30.h @@ -0,0 +1,47 @@ +#ifndef TIMERQUERYGLES_H +#define TIMERQUERYGLES_H + +#if ENABLE_PROFILER && GFX_SUPPORTS_OPENGLES30 + +#include "IncludesGLES30.h" +#include "Runtime/GfxDevice/GfxTimerQuery.h" + +struct TimerQueriesGLES30 +{ + enum + { + kQueriesCount = 128, + }; + + GLuint timestamp_gl[kQueriesCount]; + unsigned nextIndex; + + bool Init(); + + void BeginTimerQueries(); + void EndTimerQueries(); + + unsigned SetTimestamp(); + UInt64 GetElapsedTime(unsigned idx, bool wait); +}; +extern TimerQueriesGLES30 g_TimerQueriesGLES30; + + +class TimerQueryGLES30 + : public GfxTimerQuery +{ +public: + + TimerQueryGLES30(); + + virtual void Measure(); + virtual ProfileTimeFormat GetElapsed(UInt32 flags); + +private: + + unsigned m_Index; + ProfileTimeFormat m_Time; +}; + +#endif +#endif diff --git a/Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.cpp b/Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.cpp new file mode 100644 index 0000000..dc22318 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.cpp @@ -0,0 +1,762 @@ + #include "UnityPrefix.h" + +#include "Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.h" + +#include "Runtime/Filters/Mesh/Mesh.h" +#include "Runtime/Filters/Mesh/MeshSkinning.h" +#include "Runtime/Filters/Renderer.h" +#include "Runtime/GfxDevice/opengles30/VBOGLES30.h" +#include "Runtime/GfxDevice/opengles30/AssertGLES30.h" +#include "Runtime/Shaders/GraphicsCaps.h" + +// If 1, uses uniform blocks, otherwise fix bone count to 82 +#define USE_UNIFORM_BLOCK_FOR_BONES 0 + +// 1 to use glVertexAttribIPointer for bone indices, 0 to convert to floats +#define USE_INT_ATTRIBS 1 + +//! Attribute array indices. +enum { TFATTRLOC_POS = 0, TFATTRLOC_NORM = 1, TFATTRLOC_TAN = 2, TFATTRLOC_BONEIDX=3, TFATTRLOC_BONEWEIGHT = 4, TFATTRLOC_SIZE = 5 }; + +// Shader programs +enum { TFSHADER_POS = 0, TFSHADER_POSNORM = 1, TFSHADER_POSNORMTAN = 2, TFSHADER_SIZE = 3 }; + +struct TFShader +{ + TFShader() : program(0), vertShader(0), bonesLocation(0) {} + + // Not a dtor, we're storing them in a map, so delete manually in CleanupTransformFeedbackShaders + void Release() + { + if(program) + glDeleteProgram(program); + if(vertShader) + glDeleteShader(vertShader); + } + + GLuint program; + GLuint vertShader; + GLint bonesLocation; + GLint attribLocations[TFATTRLOC_SIZE]; +}; + +// Swap specialization for TFShader +namespace std +{ + template<> void swap(TFShader &a, TFShader &b) + { + swap(a.program, b.program); + swap(a.vertShader, b.vertShader); + swap(a.bonesLocation, b.bonesLocation); + swap(a.attribLocations, b.attribLocations); + } +} + +// Map to store shaders. the key is channelMap + (bonesPerVertex << 16) +typedef std::map<UInt32, TFShader> TFShaderMap; + +static TFShaderMap tfShaders; + +const char *tfShaderAttribNames[TFATTRLOC_SIZE] = {"in_vertex", "in_normal", "in_tangent", "in_boneIndices", "in_boneWeights" }; + +//! Fragment shader, common to all programs. +static GLuint tfFragShader = 0; + + +#define STRINGIFY(x) #x + +#if USE_UNIFORM_BLOCK_FOR_BONES + #define MATRIX_DECL "uniform MtxBlock { vec4 bones[max_bone_count*3]; } Matrices; \n" + #define BUILD_MATRIX "Matrices.bones[bidx + 0], Matrices.bones[bidx + 1], Matrices.bones[bidx + 2]" +#else + #define MATRIX_DECL "uniform vec4 bones[max_bone_count*3];\n" + #define BUILD_MATRIX "bones[bidx + 0], bones[bidx + 1], bones[bidx + 2]" +#endif + +// Macro to build shader source. +#define BUILD_SHADER_2(bonecount, indecl, outdecl, skincalc, outcalc ) \ + "#version 300 es\n" \ + "\n" \ + "const int max_bone_count = " STRINGIFY(bonecount) ";\n" \ + "in vec3 in_vertex;\n" \ + indecl \ + "out vec3 out_pos;\n" \ + outdecl \ + "\n" \ + MATRIX_DECL \ + "\n" \ + "mat4 getMatrix(int idx)\n" \ + "{\n"\ + " int bidx = idx*3;\n" \ + " return mat4(" BUILD_MATRIX ", vec4(0.0, 0.0, 0.0, 1.0));\n" \ + "}\n"\ + "void main(void)\n" \ + "{\n" \ + " vec4 inpos = vec4(in_vertex.xyz, 1.0);\n" \ + " mat4 localToWorldMatrix = \n" \ + skincalc \ + " out_pos = (inpos * localToWorldMatrix).xyz;\n" \ + " gl_Position = vec4(out_pos.xyz, 1.0);\n" \ + outcalc \ + "}" + +#if USE_INT_ATTRIBS +#define BONEINDEXTYPE1 "int" +#define BONEINDEXTYPE2 "ivec2" +#define BONEINDEXTYPE4 "ivec4" +#else +#define BONEINDEXTYPE1 "float" +#define BONEINDEXTYPE2 "vec2" +#define BONEINDEXTYPE4 "vec4" +#endif + +#if USE_UNIFORM_BLOCK_FOR_BONES +#define BUILD_SHADER( indecl, outdecl, skincalc, outcalc ) \ + {\ + BUILD_SHADER_2(32, indecl, outdecl, skincalc, outcalc), \ + BUILD_SHADER_2(64, indecl, outdecl, skincalc, outcalc), \ + BUILD_SHADER_2(128, indecl, outdecl, skincalc, outcalc), \ + BUILD_SHADER_2(256, indecl, outdecl, skincalc, outcalc), \ + BUILD_SHADER_2(512, indecl, outdecl, skincalc, outcalc), \ + BUILD_SHADER_2(1024, indecl, outdecl, skincalc, outcalc) } +#else +// Just one bonecount, store it in first element +#define BUILD_SHADER( indecl, outdecl, skincalc, outcalc ) \ +{\ + BUILD_SHADER_2(82, indecl, outdecl, skincalc, outcalc), "", "", "", "", ""\ +} +#endif +// Shaders for each input type, and for various max bone counts (32, 64, 128, 256, 512 and 1024) and bone-per-vertex counts (1, 2, 4 bones per vertex supported, sparse array so third slot is empty). +static const char *tfShaderSource[TFSHADER_SIZE][4][6] = { + // TFSHADER_POS + { +#define IN_DECL "\n" +#define OUT_DECL "\n" +#define OUT_CALC "\n" + // 1 bone + BUILD_SHADER( "in " BONEINDEXTYPE1 " in_boneIndices;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices));\n", + OUT_CALC + ), + + // 2 bones + BUILD_SHADER( "in " BONEINDEXTYPE2 " in_boneIndices;\n in vec2 in_boneWeights;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices.x)) * in_boneWeights[0] + \n" \ + " getMatrix(int(in_boneIndices.y)) * in_boneWeights[1] ;\n ", + OUT_CALC + ), + // 3 bones + {"", "", "", "", "", ""}, + + // 4 bones + BUILD_SHADER( "in " BONEINDEXTYPE4 " in_boneIndices;\n in vec4 in_boneWeights;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices.x)) * in_boneWeights[0] + \n" \ + " getMatrix(int(in_boneIndices.y)) * in_boneWeights[1] + \n" \ + " getMatrix(int(in_boneIndices.z)) * in_boneWeights[2] + \n" \ + " getMatrix(int(in_boneIndices.w)) * in_boneWeights[3] ;\n", + OUT_CALC + ) + } + , + // TFSHADER_POSNORM + { +#undef IN_DECL +#undef OUT_DECL +#undef OUT_CALC +#define IN_DECL "in vec3 in_normal;\n" +#define OUT_DECL "out vec3 out_normal;\n" +#define OUT_CALC " out_normal = normalize( (vec4(in_normal.xyz, 0.0) * localToWorldMatrix)).xyz;\n" + // 1 bone + BUILD_SHADER( "in " BONEINDEXTYPE1 " in_boneIndices;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices));\n", + OUT_CALC + ), + + // 2 bones + BUILD_SHADER( "in " BONEINDEXTYPE2 " in_boneIndices;\n in vec2 in_boneWeights;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices.x)) * in_boneWeights[0] + \n" \ + " getMatrix(int(in_boneIndices.y)) * in_boneWeights[1] ;\n ", + OUT_CALC + ), + // 3 bones + {"", "", "", "", "", ""}, + + // 4 bones + BUILD_SHADER( "in " BONEINDEXTYPE4 " in_boneIndices;\n in vec4 in_boneWeights;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices.x)) * in_boneWeights[0] + \n" \ + " getMatrix(int(in_boneIndices.y)) * in_boneWeights[1] + \n" \ + " getMatrix(int(in_boneIndices.z)) * in_boneWeights[2] + \n" \ + " getMatrix(int(in_boneIndices.w)) * in_boneWeights[3] ;\n", + OUT_CALC + ) + }, +// TFSHADER_POSNORMTAN + { +#undef IN_DECL +#undef OUT_DECL +#undef OUT_CALC +#define IN_DECL "in vec3 in_normal;\n in vec4 in_tangent;\n" +#define OUT_DECL "out vec3 out_normal;\n out vec4 out_tangent;\n" +#define OUT_CALC " out_normal = normalize( ( vec4(in_normal.xyz, 0.0) * localToWorldMatrix)).xyz;\n" \ + " out_tangent = vec4( normalize( ( vec4(in_tangent.xyz, 0.0) * localToWorldMatrix)).xyz, in_tangent.w);\n" + // 1 bone + BUILD_SHADER( "in " BONEINDEXTYPE1 " in_boneIndices;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices));\n", + OUT_CALC + ), + + // 2 bones + BUILD_SHADER( "in " BONEINDEXTYPE2 " in_boneIndices;\n in vec2 in_boneWeights;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices.x)) * in_boneWeights[0] + \n" \ + " getMatrix(int(in_boneIndices.y)) * in_boneWeights[1] ;\n ", + OUT_CALC + ), + // 3 bones + {"", "", "", "", "", ""}, + + // 4 bones + BUILD_SHADER( "in " BONEINDEXTYPE4 " in_boneIndices;\n in vec4 in_boneWeights;\n" IN_DECL, + OUT_DECL, + " getMatrix(int(in_boneIndices.x)) * in_boneWeights[0] + \n" \ + " getMatrix(int(in_boneIndices.y)) * in_boneWeights[1] + \n" \ + " getMatrix(int(in_boneIndices.z)) * in_boneWeights[2] + \n" \ + " getMatrix(int(in_boneIndices.w)) * in_boneWeights[3] ;\n", + OUT_CALC + ) + } + +#undef IN_DECL +#undef OUT_DECL +#undef OUT_CALC + +}; + +#undef BUILD_SHADER +#undef BUILD_SHADER_2 +#undef STRINGIFY +#undef MATRIX_DECL +#undef BUILD_MATRIX + +static const char skinFS[] = + "#version 300 es\n" + "\n" + "precision lowp float;\n" + "out vec4 outcol;\n" + "void main(void) { outcol = vec4(1.0, 1.0, 1.0, 1.0); }\n"; + +enum TfSkinShaderChannel +{ + kTFC_Position = VERTEX_FORMAT1(Vertex), + kTFC_Normal = VERTEX_FORMAT1(Normal), + kTFC_Tangent = VERTEX_FORMAT1(Tangent) +}; + +static GLuint tfTransformFeedback = 0; +static GLuint GetTransformFeedbackObject(void) +{ + if(!tfTransformFeedback) + GLES_CHK(glGenTransformFeedbacks(1, &tfTransformFeedback)); + return tfTransformFeedback; +} + +// Note: we might not support all formats all the time. +static bool DoesVertexFormatQualifyForTransformFeedback(UInt32 shaderChannelsMap) +{ + // Must have position, and if has tangents, must have normals as well. + bool qualify = (shaderChannelsMap & kTFC_Position) != 0; + if ((shaderChannelsMap & kTFC_Tangent) != 0) + qualify &= (shaderChannelsMap & kTFC_Normal) != 0; + + return qualify; + +} + +static UInt32 roundUpToNextPowerOf2(UInt32 in) +{ + // Round up to nearest power of 2 + // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 + in--; + in |= in >> 1; + in |= in >> 2; + in |= in >> 4; + in |= in >> 8; + in |= in >> 16; + in++; + return in; +} +// Get the bones bit index based on bone count. Assumes bonecount is power of 2 +static int getBonesBits(UInt32 boneCount) +{ + // Calculate ln2 + // http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn + + static const int MultiplyDeBruijnBitPosition2[32] = + { + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, + 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 + }; + UInt32 res = MultiplyDeBruijnBitPosition2[(UInt32)(boneCount * 0x077CB531U) >> 27]; + + if(res < 5) // Minimum size is 32 (= 0) + return 0; + + return res-5; // Adjust so that 32 = 0, 64 = 1 etc. +} + +static void print_long_string(std::string in) +{ + int offs = 0; + int len = in.length(); + const int split = 200; + do + { + printf_console(in.substr(offs, split).c_str()); + offs+=split; + } while (offs < len); + +} + +// maxBonesBits == Max bone count: 0 = 32, 1 = 64, etc until 5 = 1024 +static TFShader * GetTransformFeedbackShaderProgram(UInt32 shaderChannelsMap, UInt32 bonesPerVertex, UInt32 maxBonesBits) +{ + // Check if already created + TFShaderMap::iterator itr = tfShaders.find(shaderChannelsMap + (bonesPerVertex << 16) + (maxBonesBits << 19)); + if(itr != tfShaders.end()) + { + return &(itr->second); + } + + // There are only 3 different combinations, and they are always in order. We'll just cut the array length at the call site. + const char *varyings[] = {"out_pos", "out_normal", "out_tangent"}; + GLuint varyingCount = 0; + int shaderIdx = 0; + if(shaderChannelsMap & kTFC_Tangent) + { + shaderIdx = TFSHADER_POSNORMTAN; + varyingCount = 3; + } + else if(shaderChannelsMap & kTFC_Normal) + { + shaderIdx = TFSHADER_POSNORM; + varyingCount = 2; + } + else + { + shaderIdx = TFSHADER_POS; + varyingCount = 1; + } + + TFShader res; + + GLint status = 0; + GLint shaderLen = 0; + const char *code; + int i; + // Create the fragment shader if it doesn't exist already + if(tfFragShader == 0) + { + tfFragShader = glCreateShader(GL_FRAGMENT_SHADER); + shaderLen = strlen(skinFS); + code = &skinFS[0]; + GLES_CHK(glShaderSource(tfFragShader, 1, &code, &shaderLen)); + GLES_CHK(glCompileShader(tfFragShader)); + glGetShaderiv(tfFragShader, GL_COMPILE_STATUS, &status); + if(status != GL_TRUE) + { + char temp[512] = ""; + GLint len = 512; + glGetShaderInfoLog(tfFragShader, 512, &len, temp ); + + printf_console("ERROR: Unable to compile Transform Feedback fragment shader!\n Error log:\n%s", temp); + return 0; + } + } + res.program = glCreateProgram(); + res.vertShader = glCreateShader(GL_VERTEX_SHADER); + shaderLen = strlen(tfShaderSource[shaderIdx][bonesPerVertex-1][maxBonesBits]); + code = &tfShaderSource[shaderIdx][bonesPerVertex-1][maxBonesBits][0]; + GLES_CHK(glShaderSource(res.vertShader, 1, &code, &shaderLen)); + GLES_CHK(glCompileShader(res.vertShader)); + glGetShaderiv(res.vertShader, GL_COMPILE_STATUS, &status); + if(status != GL_TRUE) + { + char temp[512] = ""; + GLint len = 512; + glGetShaderInfoLog(res.vertShader, 512, &len, temp ); + + printf_console("ERROR: Unable to compile Transform Feedback vertex shader!\n Error log:\n%s", temp); + print_long_string(code); + return 0; + } + GLES_CHK(glAttachShader(res.program, res.vertShader)); + GLES_CHK(glAttachShader(res.program, tfFragShader)); + + GLES_CHK(glTransformFeedbackVaryings(res.program, varyingCount, varyings, GL_INTERLEAVED_ATTRIBS)); + + GLES_CHK(glLinkProgram(res.program)); + + glGetProgramiv(res.program, GL_LINK_STATUS, &status); + if(status != GL_TRUE) + { + char temp[512] = ""; + GLint len = 512; + glGetProgramInfoLog(res.program, 512, &len, temp ); + printf_console("ERROR: Unable to link Transform Feedback shader! Error: \n%s", temp); + print_long_string(code); + return 0; + } + +#if USE_UNIFORM_BLOCK_FOR_BONES + res.bonesLocation = glGetUniformBlockIndex(res.program, "MtxBlock"); +#else + res.bonesLocation = glGetUniformLocation(res.program, "bones"); +#endif + + // Get the attribute locations. Some of these may be missing so clear the glerror afterwards + for(i = 0; i < TFATTRLOC_SIZE; i++) + { + res.attribLocations[i] = glGetAttribLocation(res.program, tfShaderAttribNames[i]); + } + // Clear gl error + glGetError(); + + // Insert into map and return + return &(tfShaders.insert(std::make_pair(shaderChannelsMap + (bonesPerVertex << 16) + (maxBonesBits << 19), res)).first->second); + +} + +static void ReleaseShader(std::pair<UInt32, TFShader> it) +{ + it.second.Release(); +} + +void TransformFeedbackSkinningInfo::CleanupTransformFeedbackShaders(void) +{ + std::for_each(tfShaders.begin(), tfShaders.end(), ReleaseShader); + tfShaders.clear(); + + if(tfTransformFeedback) + { + glDeleteTransformFeedbacks(1, &tfTransformFeedback); + tfTransformFeedback = NULL; + } + if(tfFragShader) + { + glDeleteShader(tfFragShader); + tfFragShader = 0; + } +} + +TransformFeedbackSkinningInfo::~TransformFeedbackSkinningInfo() +{ +#define DEL_BUFFER(x) if(x != 0) { GLES_CHK(glDeleteBuffers(1, &x)); x = 0; } + DEL_BUFFER(m_SourceVBO); +#undef DEL_BUFFER + if(m_MatrixBuffer) + m_MatrixBuffer->Release(); +} + +//! Get Vertex size in floats +UInt32 TransformFeedbackSkinningInfo::GetVertexSize() +{ + // Vertex data size + UInt32 res = (GetStride() / 4); + // Add skin info size + if(GetBonesPerVertex() == 1) + return res + 1; // Index + else if(GetBonesPerVertex() == 2) + return res + 4; // 2 indices, 2 weights + else + return res + 8; // 4 indices, 4 weights +} + +bool TransformFeedbackSkinningInfo::EnsureBuffer() +{ + bool dirty = false; + if(m_SourceVBO == 0) + { + GLES_CHK(glGenBuffers(1, &m_SourceVBO)); + dirty = true; + } + GLsizei size = GetVertexSize() * GetVertexCount() * sizeof(float); + if(m_SourceVBOSize < size) + { + GLES_CHK(glBindBuffer(GL_UNIFORM_BUFFER, m_SourceVBO)); + GLES_CHK(glBufferData(GL_UNIFORM_BUFFER, size, NULL, GL_STATIC_DRAW)); + m_SourceVBOSize = size; + dirty = true; + GLES_CHK(glBindBuffer(GL_UNIFORM_BUFFER, 0)); + } + return dirty; +} + + +void TransformFeedbackSkinningInfo::UpdateSourceData(const void *vertData, const BoneInfluence *skinData, bool dirty) +{ + dirty |= EnsureBuffer(); + + if(!dirty) + return; + + std::vector<float> vboData; + vboData.resize(GetVertexSize() * GetVertexCount()); + + float *dest = &vboData[0]; + float *vertsrc = (float *)vertData; + int vertsize = GetStride() / sizeof(float); + const BoneInfluence *bonesrc4 = skinData; + const BoneInfluence2 *bonesrc2 = (BoneInfluence2 *)skinData; + const int *bonesrc1 = (int *)skinData; + + for(int i = 0; i < GetVertexCount(); i++) + { + std::copy(vertsrc, vertsrc+vertsize, dest); + dest += vertsize; + vertsrc += vertsize; + switch(GetBonesPerVertex()) + { + default: + case 1: +#if USE_INT_ATTRIBS + memcpy(dest, bonesrc1, sizeof(int)); + dest++; + bonesrc1++; +#else + *(dest++) = (float) *(bonesrc1++); +#endif + break; + case 2: + // Copy weights + std::copy(&bonesrc2->weight[0], (&bonesrc2->weight[0])+2, dest); + dest += 2; +#if USE_INT_ATTRIBS + memcpy(dest, &bonesrc2->boneIndex[0], sizeof(int)*2); + dest+= 2; +#else + *(dest++) = (float) bonesrc2->boneIndex[0]; + *(dest++) = (float) bonesrc2->boneIndex[1]; +#endif + bonesrc2++; + + break; + case 4: + // Copy weights + std::copy(&bonesrc4->weight[0], (&bonesrc4->weight[0])+4, dest); + dest += 4; +#if USE_INT_ATTRIBS + memcpy(dest, &bonesrc4->boneIndex[0], sizeof(int)*4); + dest+= 4; +#else + *(dest++) = (float) bonesrc4->boneIndex[0]; + *(dest++) = (float) bonesrc4->boneIndex[1]; + *(dest++) = (float) bonesrc4->boneIndex[2]; + *(dest++) = (float) bonesrc4->boneIndex[3]; +#endif + bonesrc4++; + + break; + } + } + GLES_CHK(glBindBuffer(GL_UNIFORM_BUFFER, m_SourceVBO)); + GLES_CHK(glBufferSubData(GL_UNIFORM_BUFFER, 0, vboData.size() * sizeof(float), &vboData[0])); + GLES_CHK(glBindBuffer(GL_UNIFORM_BUFFER, 0)); + +} + + +void TransformFeedbackSkinningInfo::UpdateSourceBones( const int boneCount, const Matrix4x4f* cachedPose ) +{ + int i; + int inputSize = boneCount * 4 * 3 * sizeof(float); + +#if USE_UNIFORM_BLOCK_FOR_BONES + m_BoneCount = roundUpToNextPowerOf2(boneCount); +#else + m_BoneCount = 82; +#endif + + UInt32 realBufSize = m_BoneCount * 4 * 3 * sizeof(float); + + // This basically shouldn't happen but just in case (should be released in SkinMesh) + if(m_MatrixBuffer) + { + m_MatrixBuffer->Release(); + } + + float *dest = NULL; + +#if USE_UNIFORM_BLOCK_FOR_BONES + m_MatrixBuffer = GetBufferManagerGLES30()->AcquireBuffer(realBufSize, GL_DYNAMIC_DRAW); + + if(gGraphicsCaps.gles30.useMapBuffer) + { + m_MatrixBuffer->RecreateStorage(realBufSize, GL_DYNAMIC_DRAW); + dest = (float *)m_MatrixBuffer->Map(0, realBufSize, GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT); + } + else +#endif + { + m_CachedPose.resize(realBufSize / sizeof(float)); + dest = &m_CachedPose[0]; + } + + int realBoneCount = boneCount; + if(boneCount > m_BoneCount) + realBoneCount = m_BoneCount; + + for(i = 0; i < realBoneCount; i++) + { + Matrix4x4f mat = cachedPose[i]; + mat.Transpose(); + float *src = mat.GetPtr(); + std::copy(src, src+12, dest); + dest+=12; + } + +#if USE_UNIFORM_BLOCK_FOR_BONES + if(gGraphicsCaps.gles30.useMapBuffer) + { + m_MatrixBuffer->Unmap(); + } + else + { + m_MatrixBuffer->RecreateWithData(realBufSize, GL_DYNAMIC_DRAW, (void *)&m_CachedPose[0]); + } + m_MatrixBuffer->RecordUpdate(); +#endif +} + +// In GfxDeviceGLES30.cpp +void GLSLUseProgramGLES30(UInt32 programID); + +void TransformFeedbackSkinningInfo::SkinMesh( bool last ) +{ + + static GLuint s_WorkaroundTFBuf = 0; + + // Qualcomm, srsly? + if(s_WorkaroundTFBuf == 0) + { + glGenBuffers(1, &s_WorkaroundTFBuf); + glBindBuffer(GL_COPY_WRITE_BUFFER, s_WorkaroundTFBuf); + glBufferData(GL_COPY_WRITE_BUFFER, 1024, NULL, GL_DYNAMIC_DRAW); + glBindBuffer(GL_COPY_WRITE_BUFFER, 0); + } + +#if USE_UNIFORM_BLOCK_FOR_BONES + TFShader *shd = GetTransformFeedbackShaderProgram(GetChannelMap(), GetBonesPerVertex(), getBonesBits(m_BoneCount)); +#else + TFShader *shd = GetTransformFeedbackShaderProgram(GetChannelMap(), GetBonesPerVertex(), 0); +#endif + + Assert(shd); + + GLuint tf = GetTransformFeedbackObject(); + GLES3VBO *vbo = static_cast<GLES3VBO *>(GetDestVBO()); + GLuint glvbo = vbo->GetSkinningTargetVBO(); + + GLES_CHK(glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, glvbo)); + + + GLSLUseProgramGLES30(shd->program); + +#if USE_UNIFORM_BLOCK_FOR_BONES + GLES_CHK(glUniformBlockBinding(shd->program, shd->bonesLocation, 0)); + + if(m_MatrixBuffer) + GLES_CHK(glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_MatrixBuffer->GetBuffer())); +#else + + GLES_CHK(glUniform4fv(shd->bonesLocation, m_CachedPose.size() / 4, &m_CachedPose[0])); +#endif + + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, m_SourceVBO)); + GLuint stride = GetVertexSize() * sizeof(float); + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_POS], 3, GL_FLOAT, GL_FALSE, stride, 0)); + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_POS])); + + GLuint nextoffs = 12; + + if(GetChannelMap() & kTFC_Normal) + { + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_NORM], 3, GL_FLOAT, GL_FALSE, stride, (void *)nextoffs)); + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_NORM])); + nextoffs += 12; + } + if(GetChannelMap() & kTFC_Tangent) + { + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_TAN], 4, GL_FLOAT, GL_FALSE, stride, (void *)nextoffs)); + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_TAN])); + nextoffs += 16; + } + + switch(GetBonesPerVertex()) + { + default: + case 1: +#if USE_INT_ATTRIBS + GLES_CHK(glVertexAttribIPointer(shd->attribLocations[TFATTRLOC_BONEIDX], 1, GL_INT, stride, (void *)nextoffs)); +#else + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_BONEIDX], 1, GL_FLOAT, GL_FALSE, stride, (void *)nextoffs)); +#endif + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_BONEIDX])); + + break; + case 2: + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_BONEWEIGHT], 2, GL_FLOAT, GL_FALSE, stride,(void *)nextoffs)); + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_BONEWEIGHT])); + nextoffs += 8; +#if USE_INT_ATTRIBS + GLES_CHK(glVertexAttribIPointer(shd->attribLocations[TFATTRLOC_BONEIDX], 2, GL_INT, stride, (void *)nextoffs)); +#else + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_BONEIDX], 2, GL_FLOAT, GL_FALSE, stride, (void *)nextoffs)); +#endif + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_BONEIDX])); + break; + + case 4: + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_BONEWEIGHT], 4, GL_FLOAT, GL_FALSE, stride,(void *)nextoffs)); + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_BONEWEIGHT])); + nextoffs += 16; +#if USE_INT_ATTRIBS + GLES_CHK(glVertexAttribIPointer(shd->attribLocations[TFATTRLOC_BONEIDX], 4, GL_INT, stride, (void *)nextoffs)); +#else + GLES_CHK(glVertexAttribPointer(shd->attribLocations[TFATTRLOC_BONEIDX], 4, GL_FLOAT,GL_FALSE, stride, (void *)nextoffs)); +#endif + GLES_CHK(glEnableVertexAttribArray(shd->attribLocations[TFATTRLOC_BONEIDX])); + + break; + } + + GLES_CHK(glBeginTransformFeedback(GL_POINTS)); + + GLES_CHK(glEnable(GL_RASTERIZER_DISCARD)); + GLES_CHK(glDrawArrays(GL_POINTS, 0, GetVertexCount())); + GLES_CHK(glDisable(GL_RASTERIZER_DISCARD)); + + GLES_CHK(glEndTransformFeedback()); + + + GLES_CHK(glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, s_WorkaroundTFBuf)); + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); + +#if USE_UNIFORM_BLOCK_FOR_BONES + + GLES_CHK(glBindBufferBase(GL_UNIFORM_BUFFER, 0, 0)); + if(m_MatrixBuffer) + { + m_MatrixBuffer->RecordRender(); + m_MatrixBuffer->Release(); + m_MatrixBuffer = NULL; + } +#endif + InvalidateVertexInputCacheGLES30(); +} diff --git a/Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.h b/Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.h new file mode 100644 index 0000000..3e0c094 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/TransformFeedbackSkinnedMesh.h @@ -0,0 +1,47 @@ +#ifndef __TRANSFORMFEEDBACKSKINNEDMESH_H__ +#define __TRANSFORMFEEDBACKSKINNEDMESH_H__ + +#include "Runtime/GfxDevice/GPUSkinningInfo.h" +#include "Runtime/GfxDevice/opengles30/IncludesGLES30.h" +#include "Runtime/GfxDevice/opengles30/DataBuffersGLES30.h" +#include <vector> + +class GfxDeviceGLES30; + +// Transform Feedback mesh skinning data. +// Source and destination VBO formats must match. +class TransformFeedbackSkinningInfo : public GPUSkinningInfo +{ + friend class GfxDeviceGLES30; +private: + GLuint m_SourceVBO; + GLsizei m_SourceVBOSize; + + std::vector<float> m_CachedPose; + + DataBufferGLES30 *m_MatrixBuffer; + + //! Stores the bone count from the previous call to UpdateSourceBones. Used to select the most suitable shader version. + int m_BoneCount; + + UInt32 GetVertexSize(); + + bool EnsureBuffer(); + + TransformFeedbackSkinningInfo() : GPUSkinningInfo(), + m_SourceVBO(0), m_SourceVBOSize(0), m_MatrixBuffer(0), m_BoneCount(0) + {} + + virtual ~TransformFeedbackSkinningInfo(); + + virtual void UpdateSourceData(const void *vertData, const BoneInfluence *skinData, bool dirty); + virtual void UpdateSourceBones(const int boneCount, const Matrix4x4f* cachedPose); + virtual void SkinMesh(bool last); + +public: + + //! Release shaders that have been created for transform feedback use. + static void CleanupTransformFeedbackShaders(void); +}; + +#endif diff --git a/Runtime/GfxDevice/opengles30/UnityGLES30Ext.cpp b/Runtime/GfxDevice/opengles30/UnityGLES30Ext.cpp new file mode 100644 index 0000000..37fcb09 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/UnityGLES30Ext.cpp @@ -0,0 +1,14 @@ +#include "UnityPrefix.h" +#include "IncludesGLES30.h" +#include "UnityGLES30Ext.h" +#include "Runtime/GfxDevice/opengles/ExtensionsGLES.h" + +void Gles3ExtFunc::InitExtFunc() +{ + glPushGroupMarkerEXT = (glPushGroupMarkerEXTFunc)GetGLExtProcAddress("glPushGroupMarkerEXT"); + glPopGroupMarkerEXT = (glPopGroupMarkerEXTFunc)GetGLExtProcAddress("glPopGroupMarkerEXT"); + + glAlphaFuncQCOM = (glAlphaFuncQCOMFunc)GetGLExtProcAddress("glAlphaFuncQCOM"); +} + +Gles3ExtFunc gGles3ExtFunc; diff --git a/Runtime/GfxDevice/opengles30/UnityGLES30Ext.h b/Runtime/GfxDevice/opengles30/UnityGLES30Ext.h new file mode 100644 index 0000000..0c8bc64 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/UnityGLES30Ext.h @@ -0,0 +1,276 @@ +#pragma once +#include "Configuration/UnityConfigure.h" +#include "Runtime/GfxDevice/opengles/ExtensionsGLES.h" + +// The reason to have this file is that we use plenty of gles extensions, +// and not all of them are handled in (all) sdk we build with. +// Still we do guard all the usages with runtime ifs, so there is no need to intro addidtional preprocessor magic + + +// ---------------------------------------------------------------------------- +// Texture Formats +// + +#ifndef GL_BGRA_EXT + #define GL_BGRA_EXT 0x80E1 +#endif +#ifndef GL_ETC1_RGB8_OES + #define GL_ETC1_RGB8_OES 0x8D64 +#endif +#ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT + #define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 +#endif +#ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 +#endif +#ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 +#endif +#ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT + #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 +#endif +#ifndef GL_COMPRESSED_SRGB_S3TC_DXT1_NV + #define GL_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C +#endif +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV + #define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D +#endif +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV + #define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E +#endif +#ifndef GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV + #define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F +#endif +#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG + #define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#endif +#ifndef GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG + #define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#endif +#ifndef GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG + #define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#endif +#ifndef GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG + #define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif +#ifndef GL_ATC_RGB_AMD + #define GL_ATC_RGB_AMD 0x8C92 +#endif +#ifndef GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD + #define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE +#endif + +#ifndef GL_HALF_FLOAT_OES + #define GL_HALF_FLOAT_OES 0x8D61 +#endif +#ifndef GL_SRGB_EXT + #define GL_SRGB_EXT 0x8C40 +#endif +#ifndef GL_SRGB_ALPHA_EXT + #define GL_SRGB_ALPHA_EXT 0x8C42 +#endif + + +// ---------------------------------------------------------------------------- +// GL_EXT_blend_minmax +// + +#ifndef GL_MIN_EXT + #define GL_MIN_EXT 0x8007 +#endif + +#ifndef GL_MAX_EXT + #define GL_MAX_EXT 0x8008 +#endif + +// ---------------------------------------------------------------------------- +// GL_EXT_debug_marker +// + +typedef void (*glPushGroupMarkerEXTFunc)(int len, const char* name); +typedef void (*glPopGroupMarkerEXTFunc)(); + + +// ---------------------------------------------------------------------------- +// GL_EXT_discard_framebuffer +// + +#ifndef GL_COLOR_EXT + #define GL_COLOR_EXT 0x1800 +#endif +#ifndef GL_DEPTH_EXT + #define GL_DEPTH_EXT 0x1801 +#endif +#ifndef GL_STENCIL_EXT + #define GL_STENCIL_EXT 0x1802 +#endif + +typedef void (*glDiscardFramebufferEXTFunc)(GLenum target, GLsizei numAttachments, const GLenum *attachments); + + +// ---------------------------------------------------------------------------- +// GL_EXT_occlusion_query_boolean +// Note: while we dont use occlusion queries, all queries ext are based on that one +// + +#ifndef GL_QUERY_RESULT_EXT + #define GL_QUERY_RESULT_EXT 0x8866 +#endif +#ifndef GL_QUERY_RESULT_AVAILABLE_EXT + #define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867 +#endif + +typedef void (*glGenQueriesEXTFunc)(GLuint n, GLuint *ids); +typedef void (*glDeleteQueriesEXTFunc)(GLuint n, const GLuint *ids); +typedef void (*glBeginQueryEXTFunc)(GLuint target, GLuint id); +typedef void (*glEndQueryEXTFunc)(GLuint target); +typedef void (*glGetQueryObjectuivEXTFunc)(GLuint id, GLuint pname, GLuint *params); + + +// ---------------------------------------------------------------------------- +// GL_EXT_shadow_samplers +// + +#ifndef GL_TEXTURE_COMPARE_MODE_EXT + #define GL_TEXTURE_COMPARE_MODE_EXT 0x884C +#endif +#ifndef GL_TEXTURE_COMPARE_FUNC_EXT + #define GL_TEXTURE_COMPARE_FUNC_EXT 0x884D +#endif +#ifndef GL_COMPARE_REF_TO_TEXTURE_EXT + #define GL_COMPARE_REF_TO_TEXTURE_EXT 0x884E +#endif +#ifndef GL_SAMPLER_2D_SHADOW_EXT + #define GL_SAMPLER_2D_SHADOW_EXT 0x8B62 +#endif + + +// ---------------------------------------------------------------------------- +// GL_EXT_texture_rg +// + +#ifndef GL_RED_EXT + #define GL_RED_EXT 0x1903 +#endif +#ifndef GL_RG_EXT + #define GL_RG_EXT 0x8227 +#endif + + +// ---------------------------------------------------------------------------- +// GL_OES_get_program_binary +// + +#ifndef GL_PROGRAM_BINARY_LENGTH_OES + #define GL_PROGRAM_BINARY_LENGTH_OES 0x8741 +#endif + +#ifndef GL_NUM_PROGRAM_BINARY_FORMATS_OES + #define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE +#endif + +typedef void (*glGetProgramBinaryOESFunc)(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary); +typedef void (*glProgramBinaryOESFunc)(GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length); + + +// ---------------------------------------------------------------------------- +// GL_OES_mapbuffer +// + +#ifndef GL_WRITE_ONLY_OES + #define GL_WRITE_ONLY_OES 0x88B9 +#endif + +typedef void* (*glMapBufferOESFunc)(GLenum target, GLenum access); +typedef GLboolean (*glUnmapBufferOESFunc)(GLenum target); + + +// ---------------------------------------------------------------------------- +// GL_APPLE_framebuffer_multisample +// + +#ifndef GL_MAX_SAMPLES_APPLE + #define GL_MAX_SAMPLES_APPLE 0x8D57 +#endif +#ifndef GL_READ_FRAMEBUFFER_APPLE + #define GL_READ_FRAMEBUFFER_APPLE 0x8CA8 +#endif +#ifndef GL_DRAW_FRAMEBUFFER_APPLE + #define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9 +#endif + + +typedef void (*glRenderbufferStorageMultisampleAPPLEFunc)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (*glResolveMultisampleFramebufferAPPLEFunc)(void); + + +// ---------------------------------------------------------------------------- +// GL_IMG_multisampled_render_to_texture +// + +#ifndef GL_MAX_SAMPLES_IMG + #define GL_MAX_SAMPLES_IMG 0x9135 +#endif + +typedef void (*glRenderbufferStorageMultisampleIMGFunc)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +typedef void (*glFramebufferTexture2DMultisampleIMGFunc)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); + + +// ---------------------------------------------------------------------------- +// GL_NV_draw_buffers +// + +#ifndef GL_MAX_DRAW_BUFFERS_NV + #define GL_MAX_DRAW_BUFFERS_NV 0x8824 +#endif +#ifndef GL_COLOR_ATTACHMENT0_NV + #define GL_COLOR_ATTACHMENT0_NV 0x8CE0 +#endif + +typedef void (*glDrawBuffersNVFunc)(int len, const GLenum* bufs); + + +// ---------------------------------------------------------------------------- +// GL_NV_timer_query +// + +#ifndef GL_TIME_ELAPSED_NV + #define GL_TIME_ELAPSED_NV 0x88BF +#endif +#ifndef GL_TIMESTAMP_NV + #define GL_TIMESTAMP_NV 0x8E28 +#endif + +typedef unsigned long long int EGLuint64NV; + +typedef void (*glQueryCounterNVFunc)(GLuint target, GLuint id); +typedef void (*glGetQueryObjectui64vNVFunc)(GLuint id, GLuint pname, EGLuint64NV *params); + + +// ---------------------------------------------------------------------------- +// GL_QCOM_alpha_test +// + +#ifndef GL_ALPHA_TEST_QCOM + #define GL_ALPHA_TEST_QCOM 0x0BC0 +#endif + +typedef void (*glAlphaFuncQCOMFunc)(GLenum func, GLfloat ref); + + +// ---------------------------------------------------------------------------- +// common place to get function pointers +// + +struct +Gles3ExtFunc +{ + glPushGroupMarkerEXTFunc glPushGroupMarkerEXT; + glPopGroupMarkerEXTFunc glPopGroupMarkerEXT; + + glAlphaFuncQCOMFunc glAlphaFuncQCOM; + + void InitExtFunc(); +}; +extern Gles3ExtFunc gGles3ExtFunc; + diff --git a/Runtime/GfxDevice/opengles30/UtilsGLES30.cpp b/Runtime/GfxDevice/opengles30/UtilsGLES30.cpp new file mode 100644 index 0000000..2c28c12 --- /dev/null +++ b/Runtime/GfxDevice/opengles30/UtilsGLES30.cpp @@ -0,0 +1,181 @@ +#include "UnityPrefix.h" +#include "UtilsGLES30.h" + +#include "IncludesGLES30.h" + +UInt32 GetColorFormatGLES30 (RenderTextureFormat format) +{ + switch (format) + { + case kRTFormatARGB32: return GL_RGBA8; + case kRTFormatDepth: return GL_NONE; + case kRTFormatARGBHalf: return GL_RGBA16F; + case kRTFormatShadowMap: return GL_NONE; + case kRTFormatRGB565: return GL_RGB565; + case kRTFormatARGB4444: return GL_RGBA4; + case kRTFormatARGB1555: return GL_RGB5_A1; + case kRTFormatDefault: return GL_RGBA8; + case kRTFormatA2R10G10B10: return GL_RGB10_A2; + case kRTFormatDefaultHDR: return GL_R11F_G11F_B10F; + case kRTFormatARGB64: return GL_RGBA8; + case kRTFormatARGBFloat: return GL_RGBA32F; + case kRTFormatRGFloat: return GL_RG32F; + case kRTFormatRGHalf: return GL_RG16F; + case kRTFormatRFloat: return GL_R32F; + case kRTFormatRHalf: return GL_R16F; + case kRTFormatR8: return GL_R8; + case kRTFormatARGBInt: return GL_RGBA32I; + case kRTFormatRGInt: return GL_RG32I; + case kRTFormatRInt: return GL_R32I; + default: + Assert("Invalid RenderTextureFormat"); + return GL_RGBA8; + } +} + +UInt32 GetDepthOnlyFormatGLES30 (DepthBufferFormat format) +{ + switch (format) + { + case kDepthFormatNone: return GL_NONE; + case kDepthFormat16: return GL_DEPTH_COMPONENT16; + case kDepthFormat24: return GL_DEPTH_COMPONENT24; + default: + Assert("Invalid DepthBufferFormat"); + return GL_NONE; + } +} + +UInt32 GetDepthStencilFormatGLES30 (DepthBufferFormat format) +{ + switch (format) + { + case kDepthFormatNone: return GL_STENCIL_INDEX8; + case kDepthFormat16: return GL_DEPTH24_STENCIL8; + case kDepthFormat24: return GL_DEPTH24_STENCIL8; + default: + Assert("Invalid DepthBufferFormat"); + return GL_NONE; + } +} + +TransferFormatGLES30 GetTransferFormatGLES30 (UInt32 internalFormat) +{ + switch (internalFormat) + { + case GL_RGBA32F: return TransferFormatGLES30(GL_RGBA, GL_FLOAT ); + case GL_RGBA32I: return TransferFormatGLES30(GL_RGBA_INTEGER, GL_INT ); + case GL_RGBA32UI: return TransferFormatGLES30(GL_RGBA_INTEGER, GL_UNSIGNED_INT ); + case GL_RGBA16F: return TransferFormatGLES30(GL_RGBA, GL_HALF_FLOAT ); + case GL_RGBA16I: return TransferFormatGLES30(GL_RGBA_INTEGER, GL_SHORT ); + case GL_RGBA16UI: return TransferFormatGLES30(GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ); + case GL_RGBA8: return TransferFormatGLES30(GL_RGBA, GL_UNSIGNED_BYTE ); + case GL_RGBA8I: return TransferFormatGLES30(GL_RGBA_INTEGER, GL_BYTE ); + case GL_RGBA8UI: return TransferFormatGLES30(GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ); + case GL_SRGB8_ALPHA8: return TransferFormatGLES30(GL_RGBA, GL_UNSIGNED_BYTE ); + case GL_RGB10_A2: return TransferFormatGLES30(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ); + case GL_RGB10_A2UI: return TransferFormatGLES30(GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ); + case GL_RGBA4: return TransferFormatGLES30(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ); + case GL_RGB5_A1: return TransferFormatGLES30(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ); + case GL_RGBA8_SNORM: return TransferFormatGLES30(GL_RGBA, GL_BYTE ); + case GL_RGB8: return TransferFormatGLES30(GL_RGB, GL_UNSIGNED_BYTE ); + case GL_RGB565: return TransferFormatGLES30(GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ); + case GL_R11F_G11F_B10F: return TransferFormatGLES30(GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ); + case GL_RGB32F: return TransferFormatGLES30(GL_RGB, GL_FLOAT ); + case GL_RGB32I: return TransferFormatGLES30(GL_RGB_INTEGER, GL_INT ); + case GL_RGB32UI: return TransferFormatGLES30(GL_RGB_INTEGER, GL_UNSIGNED_INT ); + case GL_RGB16F: return TransferFormatGLES30(GL_RGB, GL_HALF_FLOAT ); + case GL_RGB16I: return TransferFormatGLES30(GL_RGB_INTEGER, GL_SHORT ); + case GL_RGB16UI: return TransferFormatGLES30(GL_RGB_INTEGER, GL_UNSIGNED_SHORT ); + case GL_RGB8_SNORM: return TransferFormatGLES30(GL_RGB, GL_BYTE ); + case GL_RGB8I: return TransferFormatGLES30(GL_RGB_INTEGER, GL_BYTE ); + case GL_RGB8UI: return TransferFormatGLES30(GL_RGB_INTEGER, GL_UNSIGNED_BYTE ); + case GL_SRGB8: return TransferFormatGLES30(GL_RGB, GL_UNSIGNED_BYTE ); + case GL_RGB9_E5: return TransferFormatGLES30(GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ); + case GL_RG32F: return TransferFormatGLES30(GL_RG, GL_FLOAT ); + case GL_RG32I: return TransferFormatGLES30(GL_RG_INTEGER, GL_INT ); + case GL_RG32UI: return TransferFormatGLES30(GL_RG_INTEGER, GL_UNSIGNED_INT ); + case GL_RG16F: return TransferFormatGLES30(GL_RG, GL_HALF_FLOAT ); + case GL_RG16I: return TransferFormatGLES30(GL_RG_INTEGER, GL_SHORT ); + case GL_RG16UI: return TransferFormatGLES30(GL_RG_INTEGER, GL_UNSIGNED_SHORT ); + case GL_RG8: return TransferFormatGLES30(GL_RG, GL_UNSIGNED_BYTE ); + case GL_RG8I: return TransferFormatGLES30(GL_RG_INTEGER, GL_BYTE ); + case GL_RG8UI: return TransferFormatGLES30(GL_RG_INTEGER, GL_UNSIGNED_BYTE ); + case GL_RG8_SNORM: return TransferFormatGLES30(GL_RG, GL_BYTE ); + case GL_R32F: return TransferFormatGLES30(GL_RED, GL_FLOAT ); + case GL_R32I: return TransferFormatGLES30(GL_RED_INTEGER, GL_INT ); + case GL_R32UI: return TransferFormatGLES30(GL_RED_INTEGER, GL_UNSIGNED_INT ); + case GL_R16F: return TransferFormatGLES30(GL_RED, GL_HALF_FLOAT ); + case GL_R16I: return TransferFormatGLES30(GL_RED_INTEGER, GL_SHORT ); + case GL_R16UI: return TransferFormatGLES30(GL_RED_INTEGER, GL_UNSIGNED_SHORT ); + case GL_R8: return TransferFormatGLES30(GL_RED, GL_UNSIGNED_BYTE ); + case GL_R8I: return TransferFormatGLES30(GL_RED_INTEGER, GL_BYTE ); + case GL_R8UI: return TransferFormatGLES30(GL_RED_INTEGER, GL_UNSIGNED_BYTE ); + case GL_R8_SNORM: return TransferFormatGLES30(GL_RED, GL_BYTE ); + case GL_DEPTH_COMPONENT32F: return TransferFormatGLES30(GL_DEPTH_COMPONENT, GL_FLOAT ); + case GL_DEPTH_COMPONENT24: return TransferFormatGLES30(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); + case GL_DEPTH_COMPONENT16: return TransferFormatGLES30(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ); + case GL_DEPTH32F_STENCIL8: return TransferFormatGLES30(GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV ); + case GL_DEPTH24_STENCIL8: return TransferFormatGLES30(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); + default: return TransferFormatGLES30(GL_NONE, GL_NONE ); + } +} + +UInt32 GetDefaultFramebufferColorFormatGLES30 (void) +{ + int redBits = 0; + int greenBits = 0; + int blueBits = 0; + int alphaBits = 0; + + glGetIntegerv(GL_RED_BITS, &redBits); + glGetIntegerv(GL_GREEN_BITS, &greenBits); + glGetIntegerv(GL_BLUE_BITS, &blueBits); + glGetIntegerv(GL_ALPHA_BITS, &alphaBits); + +#define PACK_FMT(R, G, B, A) (((R) << 24) | ((G) << 16) | ((B) << 8) | (A)) + + // \note [pyry] This may not hold true on some implementations - best effort guess only. + switch (PACK_FMT(redBits, greenBits, blueBits, alphaBits)) + { + case PACK_FMT(8,8,8,8): return GL_RGBA8; + case PACK_FMT(8,8,8,0): return GL_RGB8; + case PACK_FMT(4,4,4,4): return GL_RGBA4; + case PACK_FMT(5,5,5,1): return GL_RGB5_A1; + case PACK_FMT(5,6,5,0): return GL_RGB565; + default: return GL_NONE; + } + +#undef PACK_FMT +} + +UInt32 GetDefaultFramebufferDepthFormatGLES30 (void) +{ + int depthBits = 0; + int stencilBits = 0; + glGetIntegerv(GL_DEPTH_BITS, &depthBits); + glGetIntegerv(GL_STENCIL_BITS, &stencilBits); + + if(stencilBits > 0) + { + switch (depthBits) + { + case 32: return GL_DEPTH32F_STENCIL8; + case 24: return GL_DEPTH24_STENCIL8; + case 16: return GL_DEPTH_COMPONENT16; // There's probably no such config? + default: return GL_NONE; + } + + } + else + { + switch (depthBits) + { + case 32: return GL_DEPTH_COMPONENT32F; + case 24: return GL_DEPTH_COMPONENT24; + case 16: return GL_DEPTH_COMPONENT16; + default: return GL_NONE; + } + + } +} diff --git a/Runtime/GfxDevice/opengles30/UtilsGLES30.h b/Runtime/GfxDevice/opengles30/UtilsGLES30.h new file mode 100644 index 0000000..cde05de --- /dev/null +++ b/Runtime/GfxDevice/opengles30/UtilsGLES30.h @@ -0,0 +1,37 @@ +#pragma once + +#include "UnityPrefix.h" +#include "Runtime/Graphics/RenderTexture.h" + +// Shared GLES3 utilities + +class TransferFormatGLES30 +{ +public: + UInt32 format; + UInt32 dataType; + + TransferFormatGLES30 (UInt32 format_, UInt32 dataType_) + : format (format_) + , dataType (dataType_) + { + } +}; + +// Map RenderTextureFormat to closest GL sized internal format. +UInt32 GetColorFormatGLES30 (RenderTextureFormat format); + +// Get closest depth internal format. +UInt32 GetDepthOnlyFormatGLES30 (DepthBufferFormat format); + +// Get closest depth&stencil internal format. +UInt32 GetDepthStencilFormatGLES30 (DepthBufferFormat format); + +// Get transfer (upload) format, dataType pair for internal format. +TransferFormatGLES30 GetTransferFormatGLES30 (UInt32 internalFormat); + +// Get default framebuffer (0) internal format (guess based on bits) +UInt32 GetDefaultFramebufferColorFormatGLES30 (void); + +// Get default framebuffer (0) depth format +UInt32 GetDefaultFramebufferDepthFormatGLES30 (void); diff --git a/Runtime/GfxDevice/opengles30/VBOGLES30.cpp b/Runtime/GfxDevice/opengles30/VBOGLES30.cpp new file mode 100644 index 0000000..24d4bba --- /dev/null +++ b/Runtime/GfxDevice/opengles30/VBOGLES30.cpp @@ -0,0 +1,1351 @@ +#include "UnityPrefix.h" + +#if GFX_SUPPORTS_OPENGLES30 +#include "VBOGLES30.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/Misc/Allocator.h" +#include "Runtime/Filters/Renderer.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/Utilities/Prefetch.h" +#include "Runtime/Math/Matrix4x4.h" +#include "Runtime/GfxDevice/BatchRendering.h" +#include "IncludesGLES30.h" +#include "AssertGLES30.h" +#include "GpuProgramsGLES30.h" +#include "DebugGLES30.h" +#include "Runtime/Profiler/TimeHelper.h" +#include "Runtime/Utilities/ArrayUtility.h" +#include "Runtime/GfxDevice/GLESChannels.h" +#include "Runtime/GfxDevice/GLDataBufferCommon.h" +#include "Runtime/Profiler/MemoryProfiler.h" + +#include <algorithm> + +#if 1 + #define DBG_LOG_VBO_GLES30(...) {} +#else + #define DBG_LOG_VBO_GLES30(...) {printf_console(__VA_ARGS__);printf_console("\n");} +#endif + +enum +{ + kDefaultBufferAlign = 64 +}; + +template <typename T> +inline T Align (T v, size_t alignment) +{ + return (v + (alignment-1)) & ~(alignment-1); +} + +template <typename T> +inline T AlignToDefault (T v) +{ + return Align(v, kDefaultBufferAlign); +} + +// Comparison operators for VertexArrayInfoGLES30 (used in caching) + +static inline bool operator< (const VertexInputInfoGLES30& a, const VertexInputInfoGLES30& b) +{ + return a.componentType < b.componentType && + a.numComponents < b.numComponents && + a.pointer < b.pointer && + a.stride < b.stride; +} + +static inline bool operator!= (const VertexInputInfoGLES30& a, const VertexInputInfoGLES30& b) +{ + return a.componentType != b.componentType || + a.numComponents != b.numComponents || + a.pointer != b.pointer || + a.stride != b.stride; +} + +static inline bool operator== (const VertexInputInfoGLES30& a, const VertexInputInfoGLES30& b) { return !(a != b); } + +static bool operator< (const VertexArrayInfoGLES30& a, const VertexArrayInfoGLES30& b) +{ + if (a.enabledArrays < b.enabledArrays) return true; + else if (b.enabledArrays < a.enabledArrays) return false; + + // Compare buffers first as they are more likely to not match. + for (int ndx = 0; ndx < kGLES3MaxVertexAttribs; ndx++) + { + if (a.enabledArrays & (1<<ndx)) + { + if (a.buffers[ndx] < b.buffers[ndx]) return true; + else if (b.buffers[ndx] < a.buffers[ndx]) return false; + } + } + + for (int ndx = 0; ndx < kGLES3MaxVertexAttribs; ndx++) + { + if (a.enabledArrays & (1<<ndx)) + { + if (a.arrays[ndx] < b.arrays[ndx]) return true; + else if (b.arrays[ndx] < a.arrays[ndx]) return false; + } + } + + return false; // Equal +} + +static bool operator!= (const VertexArrayInfoGLES30& a, const VertexArrayInfoGLES30& b) +{ + if (a.enabledArrays != b.enabledArrays) + return true; + + // Compare buffers first as they are more likely to not match. + for (int ndx = 0; ndx < kGLES3MaxVertexAttribs; ndx++) + { + if (a.enabledArrays & (1<<ndx)) + { + if (a.buffers[ndx] != b.buffers[ndx]) + return true; + } + } + + for (int ndx = 0; ndx < kGLES3MaxVertexAttribs; ndx++) + { + if (a.enabledArrays & (1<<ndx)) + { + if (a.arrays[ndx] != b.arrays[ndx]) + return true; + } + } + + return false; +} + +static bool operator== (const VertexArrayInfoGLES30& a, const VertexArrayInfoGLES30& b) { return !(a != b); } + +struct CompareVertexArrayInfoGLES30 +{ + bool operator() (const VertexArrayInfoGLES30* a, const VertexArrayInfoGLES30* b) const; +}; + +class VertexArrayObjectGLES30 +{ +public: + VertexArrayObjectGLES30 (const VertexArrayInfoGLES30& info); + ~VertexArrayObjectGLES30 (void); + + UInt32 GetVAO (void) const { return m_vao; } + const VertexArrayInfoGLES30* GetInfo (void) const { return &m_info; } + +private: + VertexArrayObjectGLES30 (const VertexArrayObjectGLES30& other); // Not allowed! + VertexArrayObjectGLES30& operator= (const VertexArrayObjectGLES30& other); // Not allowed! + + VertexArrayInfoGLES30 m_info; + UInt32 m_vao; +}; + +typedef std::map<const VertexArrayInfoGLES30*, VertexArrayObjectGLES30*, CompareVertexArrayInfoGLES30> VertexArrayMapGLES30; + +// Utilities + +static const GLenum kTopologyGLES3[] = +{ + GL_TRIANGLES, + GL_TRIANGLE_STRIP, + GL_TRIANGLES, + GL_LINES, + GL_LINE_STRIP, + GL_POINTS, +}; +typedef char kTopologyGLES3SizeAssert[ARRAY_SIZE(kTopologyGLES3) == kPrimitiveTypeCount ? 1 : -1]; + +static const GLenum kVertexTypeGLES3[] = +{ + GL_FLOAT, // kChannelFormatFloat + GL_HALF_FLOAT, // kChannelFormatFloat16 + GL_UNSIGNED_BYTE, // kChannelFormatColor + GL_BYTE, // kChannelFormatByte +}; +typedef char kVertexTypeGLES3Assert[ARRAY_SIZE(kVertexTypeGLES3) == kChannelFormatCount ? 1 : -1]; + +// Targets by attribute location +static const VertexComponent kVertexCompTargetsGLES3[] = +{ + // \note Indices must match to attribute locations. + kVertexCompVertex, + kVertexCompColor, + kVertexCompNormal, + kVertexCompTexCoord0, + kVertexCompTexCoord1, + kVertexCompTexCoord2, + kVertexCompTexCoord3, + kVertexCompTexCoord4, + kVertexCompTexCoord5, + kVertexCompTexCoord6, + kVertexCompTexCoord7 +}; +typedef char kVertexCompTargetsGLES3Assert[ARRAY_SIZE(kVertexCompTargetsGLES3) == kGLES3MaxVertexAttribs ? 1 : -1]; + +// For some reason GfxDevice needs to know whether VBO contains color +// data in order to set up state properly. So this must be called before +// doing BeforeDrawCall(). +void VBOContainsColorGLES30 (bool flag); // defined in GfxDeviceGLES30.cpp + +static bool IsVertexDataValid (const VertexBufferData& buffer) +{ + // Verify streams. + { + UInt32 shaderChannels = 0; + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + if ((buffer.streams[streamNdx].channelMask == 0) != (buffer.streams[streamNdx].stride == 0)) + return false; // No data but enabled channels, or other way around. + + if ((shaderChannels & buffer.streams[streamNdx].channelMask) != 0) + return false; // Duplicate channels! + + shaderChannels |= buffer.streams[streamNdx].channelMask; + } + } + + // Make sure channels point to correct streams. + for (int chanNdx = 0; chanNdx < kShaderChannelCount; chanNdx++) + { + if (buffer.channels[chanNdx].dimension == ChannelInfo::kInvalidDimension) + continue; + + int streamNdx = buffer.channels[chanNdx].stream; + + if (streamNdx < 0 || streamNdx >= kMaxVertexStreams) + return false; + + if (buffer.streams[streamNdx].channelMask & (1<<chanNdx) == 0) + return false; // No such channel in stream. + } + + // Verify that streams do not overlap (or otherwise we waste memory). + // \todo [pyry] O(n^2), but then again kMaxVertexStreams = 4.. + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + if (buffer.streams[streamNdx].channelMask == 0) + continue; + + const int start = buffer.streams[streamNdx].offset; + const int end = start + buffer.streams[streamNdx].stride*buffer.vertexCount; + + for (int otherStreamNdx = 0; otherStreamNdx < kMaxVertexStreams; otherStreamNdx++) + { + if (otherStreamNdx == streamNdx || + buffer.streams[otherStreamNdx].channelMask == 0) + continue; + + const int otherStart = buffer.streams[otherStreamNdx].offset; + const int otherEnd = otherStart + buffer.streams[otherStreamNdx].stride*buffer.vertexCount; + + if ((start <= otherStart && otherStart < end) || // Start lies inside buffer + (start < otherEnd && otherEnd <= end)) // End lies inside buffer + return false; + } + } + + return true; +} + +static bool IsVertexArrayNormalized (int attribNdx, VertexChannelFormat format) +{ + if (attribNdx == 0) + return false; // Position is never normalized. + else + return (format != kChannelFormatFloat && format != kChannelFormatFloat16); +} + +// VAOCacheGLES30 + +VAOCacheGLES30::VAOCacheGLES30 (void) + : m_NextEntryNdx(0) +{ +} + +VAOCacheGLES30::~VAOCacheGLES30 (void) +{ + Clear(); +} + +void VAOCacheGLES30::Clear (void) +{ + for (int ndx = 0; ndx < kCacheSize; ndx++) + { + delete m_Entries[ndx].vao; + m_Entries[ndx].vao = 0; + m_Entries[ndx].key = VAOCacheKeyGLES30(); + } + + m_NextEntryNdx = 0; // Not necessary, but this will place first VAOs in first slots. +} + +inline const VertexArrayObjectGLES30* VAOCacheGLES30::Find (const VAOCacheKeyGLES30& key) const +{ + for (int ndx = 0; ndx < kCacheSize; ndx++) + { + if (m_Entries[ndx].key == key) + return m_Entries[ndx].vao; + } + + return 0; +} + +void VAOCacheGLES30::Insert (const VAOCacheKeyGLES30& key, VertexArrayObjectGLES30* vao) +{ + Assert(!Find(key)); + + // Replace last + delete m_Entries[m_NextEntryNdx].vao; + m_Entries[m_NextEntryNdx].key = key; + m_Entries[m_NextEntryNdx].vao = vao; + m_NextEntryNdx = (m_NextEntryNdx + 1) % kCacheSize; +} + +bool VAOCacheGLES30::IsFull (void) const +{ + return m_Entries[m_NextEntryNdx].vao != 0; +} + +// VertexArrayObjectGLES30 + +VertexArrayObjectGLES30::VertexArrayObjectGLES30 (const VertexArrayInfoGLES30& info) + : m_info(info) + , m_vao (0) +{ + UInt32 boundBuffer = 0; + + GLES_CHK(glGenVertexArrays(1, (GLuint*)&m_vao)); + GLES_CHK(glBindVertexArray(m_vao)); + + for (int attribNdx = 0; attribNdx < kGLES3MaxVertexAttribs; attribNdx++) + { + if ((info.enabledArrays & (1<<attribNdx)) == 0) + continue; + + const UInt32 buffer = info.buffers[attribNdx]; + const int numComponents = info.arrays[attribNdx].numComponents; + const GLenum compType = kVertexTypeGLES3[info.arrays[attribNdx].componentType]; + const bool normalized = IsVertexArrayNormalized(attribNdx, (VertexChannelFormat)info.arrays[attribNdx].componentType); + const int stride = info.arrays[attribNdx].stride; + const void* pointer = info.arrays[attribNdx].pointer; + + if (buffer != boundBuffer) + { + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, buffer)); + boundBuffer = buffer; + } + + GLES_CHK(glEnableVertexAttribArray(attribNdx)); + GLES_CHK(glVertexAttribPointer(attribNdx, numComponents, compType, normalized ? GL_TRUE : GL_FALSE, stride, pointer)); + } + + GLES_CHK(glBindVertexArray(0)); + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); +} + +VertexArrayObjectGLES30::~VertexArrayObjectGLES30 (void) +{ + glDeleteVertexArrays(1, (const GLuint*)&m_vao); +} + +// GLES3VBO + +GLES3VBO::GLES3VBO (void) + : m_IndexBuffer(0) +{ +} + +GLES3VBO::~GLES3VBO (void) +{ + Cleanup(); +} + +static UInt32 MapStreamModeToBufferUsage (VBO::StreamMode mode) +{ + switch (mode) + { + case VBO::kStreamModeNoAccess: return GL_STATIC_DRAW; // ??? + case VBO::kStreamModeWritePersist: return GL_STATIC_DRAW; + case VBO::kStreamModeDynamic: return GL_STREAM_DRAW; + default: + return GL_STATIC_DRAW; + } +} + +inline DataBufferGLES30* GLES3VBO::GetCurrentBuffer (int streamNdx) +{ + return m_StreamBuffers[streamNdx].buffers[m_StreamBuffers[streamNdx].curBufferNdx]; +} + +void GLES3VBO::UpdateVertexData (const VertexBufferData& buffer) +{ + Assert(IsVertexDataValid(buffer)); + + bool streamHasData[kMaxVertexStreams]; + int streamBufSize[kMaxVertexStreams]; + + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + const bool hasData = (buffer.streams[streamNdx].channelMask != 0); + const int size = buffer.streams[streamNdx].stride * buffer.vertexCount; + + Assert(hasData == (size != 0)); + + streamHasData[streamNdx] = hasData; + streamBufSize[streamNdx] = size; + } + + // Discard all existing buffers. + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + Stream& stream = m_StreamBuffers[streamNdx]; + + for (int bufNdx = 0; bufNdx < kBufferSwapChainSize; bufNdx++) + { + if (stream.buffers[bufNdx]) + { + stream.buffers[bufNdx]->Release(); + stream.buffers[bufNdx] = 0; + } + } + + UNITY_FREE(kMemVertexData, stream.cpuBuf); + stream.cpuBuf = 0; + } + + m_VAOCache.Clear(); // VAO cache must be cleared + + // Allocate buffers and upload data. + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + if (!streamHasData[streamNdx]) + continue; + + const UInt32 usage = MapStreamModeToBufferUsage((StreamMode)m_StreamModes[streamNdx]); + const int size = streamBufSize[streamNdx]; + const UInt8* streamData = buffer.buffer + buffer.streams[streamNdx].offset; + Stream& dstStream = m_StreamBuffers[streamNdx]; + + Assert(!dstStream.buffers[dstStream.curBufferNdx]); + + dstStream.buffers[dstStream.curBufferNdx] = GetBufferManagerGLES30()->AcquireBuffer(size, usage); + dstStream.buffers[dstStream.curBufferNdx]->RecreateWithData(size, usage, streamData); + + dstStream.channelMask = buffer.streams[streamNdx].channelMask; + dstStream.stride = buffer.streams[streamNdx].stride; + + // \todo [2013-06-19 pyry] Allocate cpuBuf on-demand once it is not required for Recreate() + dstStream.cpuBuf = (UInt8*)UNITY_MALLOC(kMemVertexData, size); + ::memcpy(dstStream.cpuBuf, streamData, size); + } + + m_VertexCount = buffer.vertexCount; + memcpy(&m_Channels[0], &buffer.channels[0], sizeof(ChannelInfoArray)); +} + +void GLES3VBO::UpdateIndexData (const IndexBufferData& buffer) +{ + const int bufferSize = CalculateIndexBufferSize(buffer); + const UInt32 bufferUsage = m_IndicesDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; + + Assert(bufferSize > 0); + + if (m_IndexBuffer && BufferUpdateCausesStallGLES30(m_IndexBuffer)) + { + m_IndexBuffer->Release(); + m_IndexBuffer = 0; + } + + if (!m_IndexBuffer) + m_IndexBuffer = GetBufferManagerGLES30()->AcquireBuffer(bufferSize, bufferUsage); + + m_IndexBuffer->RecreateWithData(bufferSize, bufferUsage, buffer.indices); + + // Take copy for emulating quads. + Assert(kVBOIndexSize == sizeof(UInt16)); + m_Indices.resize(buffer.count); + std::copy((const UInt16*)buffer.indices, (const UInt16*)buffer.indices + buffer.count, m_Indices.begin()); +} + +bool GLES3VBO::MapVertexStream (VertexStreamData& outData, unsigned stream) +{ + Assert(0 <= stream && stream < kMaxVertexStreams); + Assert(!m_IsStreamMapped[stream]); // \note Multiple mappings will screw up buffer swap chain. + Assert(m_StreamBuffers[stream].buffers[m_StreamBuffers[stream].curBufferNdx]); + + Stream& mapStream = m_StreamBuffers[stream]; + const int size = m_VertexCount * mapStream.stride; + void* mapPtr = 0; + + if (BufferUpdateCausesStallGLES30(mapStream.buffers[mapStream.curBufferNdx])) + { + // Advance to next slot. + mapStream.curBufferNdx = (mapStream.curBufferNdx + 1) % kBufferSwapChainSize; + + if (!mapStream.buffers[mapStream.curBufferNdx]) + { + const UInt32 usage = MapStreamModeToBufferUsage((StreamMode)m_StreamModes[stream]); + DataBufferGLES30* mapBuffer = GetBufferManagerGLES30()->AcquireBuffer(size, usage); + + if (mapBuffer->GetSize() < size) + mapBuffer->RecreateStorage(size, usage); + + mapStream.buffers[mapStream.curBufferNdx] = mapBuffer; + } + } + + if (gGraphicsCaps.gles30.useMapBuffer) + { + // \note Using write-only mapping always as map is not guaranteed to return old contents anyway. + mapPtr = mapStream.buffers[mapStream.curBufferNdx]->Map(0, size, GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT); + } + else + { + // \todo [2013-06-19 pyry] Allocate cpuBuf on-demand once it is not required for Recreate() + Assert(mapStream.cpuBuf); + mapPtr = mapStream.cpuBuf; + } + + outData.channelMask = mapStream.channelMask; + outData.stride = mapStream.stride; + outData.vertexCount = m_VertexCount; + outData.buffer = (UInt8*)mapPtr; + + m_IsStreamMapped[stream] = true; + + return true; +} + +void GLES3VBO::UnmapVertexStream (unsigned stream) +{ + Assert(0 <= stream && stream < kMaxVertexStreams); + Assert(m_IsStreamMapped[stream]); + + if (gGraphicsCaps.gles30.useMapBuffer) + { + GetCurrentBuffer(stream)->Unmap(); + } + else + { + const int size = m_StreamBuffers[stream].stride*m_VertexCount; + const UInt32 usage = MapStreamModeToBufferUsage((StreamMode)m_StreamModes[stream]); + + // \note Buffer slot was advanced in MapVertexStream() + GetCurrentBuffer(stream)->RecreateWithData(size, usage, m_StreamBuffers[stream].cpuBuf); + } + + m_IsStreamMapped[stream] = false; +} + +void GLES3VBO::Cleanup (void) +{ + if (m_IndexBuffer) + { + m_IndexBuffer->Release(); + m_IndexBuffer = 0; + } + + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + for (int bufNdx = 0; bufNdx < kBufferSwapChainSize; bufNdx++) + { + if (m_StreamBuffers[streamNdx].buffers[bufNdx]) + { + m_StreamBuffers[streamNdx].buffers[bufNdx]->Release(); + m_StreamBuffers[streamNdx].buffers[bufNdx] = 0; + } + } + + UNITY_FREE(kMemVertexData, m_StreamBuffers[streamNdx].cpuBuf); + m_StreamBuffers[streamNdx].cpuBuf = 0; + } + + m_VAOCache.Clear(); +} + +void GLES3VBO::Recreate (void) +{ + // \note Called on context loss. + + if (m_IndexBuffer) + { + const int bufferSize = (int)m_Indices.size() * kVBOIndexSize; + const UInt32 bufferUsage = m_IndicesDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; + + m_IndexBuffer->Disown(); + delete m_IndexBuffer; + + m_IndexBuffer = GetBufferManagerGLES30()->AcquireBuffer(bufferSize, bufferUsage); + m_IndexBuffer->RecreateWithData(bufferSize, bufferUsage, &m_Indices[0]); + } + + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + Stream& stream = m_StreamBuffers[streamNdx]; + const int bufSize = stream.stride*m_VertexCount; + const UInt32 usage = MapStreamModeToBufferUsage((StreamMode)m_StreamModes[streamNdx]); + + for (int bufNdx = 0; bufNdx < kBufferSwapChainSize; bufNdx++) + { + if (stream.buffers[bufNdx]) + { + stream.buffers[bufNdx]->Disown(); + delete stream.buffers[bufNdx]; + stream.buffers[bufNdx] = 0; + } + } + + stream.curBufferNdx = 0; + + if (bufSize > 0) + { + Assert(stream.cpuBuf); + stream.buffers[0] = GetBufferManagerGLES30()->AcquireBuffer(bufSize, usage); + stream.buffers[0]->RecreateWithData(bufSize, usage, stream.cpuBuf); + } + } + + m_VAOCache.Clear(); +} + +bool GLES3VBO::IsVertexBufferLost (void) const +{ + return false; +} + +bool GLES3VBO::IsUsingSourceVertices (void) const +{ + return false; +} + +bool GLES3VBO::IsUsingSourceIndices (void) const +{ + return true; +} + +int GLES3VBO::GetRuntimeMemorySize (void) const +{ + int totalSize = 0; + + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + { + for (int bufNdx = 0; bufNdx < kBufferSwapChainSize; bufNdx++) + { + if (m_StreamBuffers[streamNdx].buffers[bufNdx]) + totalSize += m_StreamBuffers[streamNdx].buffers[bufNdx]->GetSize(); + } + } + + if (m_IndexBuffer) + totalSize += m_IndexBuffer->GetSize(); + + return totalSize; +} + +void GLES3VBO::ComputeVertexInputState (VertexArrayInfoGLES30& dst, const ChannelAssigns& channelAssigns) +{ + UInt32 availableShaderChannels = 0; // Channels that have data in any of streams. + UInt32 enabledTargets = channelAssigns.GetTargetMap(); + + for (int streamNdx = 0; streamNdx < kMaxVertexStreams; streamNdx++) + availableShaderChannels |= m_StreamBuffers[streamNdx].channelMask; + + for (int attribNdx = 0; attribNdx < kGLES3MaxVertexAttribs; attribNdx++) + { + const VertexComponent target = kVertexCompTargetsGLES3[attribNdx]; + + if ((enabledTargets & (1<<target)) == 0) + continue; // Not enabled. + + const ShaderChannel sourceChannel = channelAssigns.GetSourceForTarget(target); + + // \todo [pyry] Uh, what? Channel is enabled, but no valid source exists. + if (sourceChannel < 0) + continue; + + Assert(0 <= sourceChannel && sourceChannel < kShaderChannelCount); + + if ((availableShaderChannels & (1<<sourceChannel)) == 0) + continue; // Not available. + + const Stream& stream = m_StreamBuffers[m_Channels[sourceChannel].stream]; + + dst.arrays[attribNdx].componentType = m_Channels[sourceChannel].format; + dst.arrays[attribNdx].numComponents = m_Channels[sourceChannel].format == kChannelFormatColor ? 4 : m_Channels[sourceChannel].dimension; + dst.arrays[attribNdx].pointer = reinterpret_cast<const void*>(m_Channels[sourceChannel].offset); + dst.arrays[attribNdx].stride = stream.stride; + dst.buffers[attribNdx] = GetCurrentBuffer(m_Channels[sourceChannel].stream)->GetBuffer(); + + dst.enabledArrays |= (1<<attribNdx); + } + + // Fixed-function texgen stuff. + { + GfxDevice& device = GetRealGfxDevice(); + const int texArrayBase = kGLES3AttribLocationTexCoord0; + const int maxTexArrays = std::min(gGraphicsCaps.maxTexUnits, kGLES3MaxVertexAttribs-texArrayBase); + + if (device.IsPositionRequiredForTexGen() && (availableShaderChannels & (1 << kShaderChannelVertex))) + { + const ChannelInfo& posInfo = m_Channels[kShaderChannelVertex]; + const Stream& posStream = m_StreamBuffers[posInfo.stream]; + + for (int texUnit = 0; texUnit < maxTexArrays; ++texUnit) + { + if (device.IsPositionRequiredForTexGen(texUnit)) + { + const int arrNdx = texArrayBase + texUnit; + dst.arrays[arrNdx].componentType = posInfo.format; + dst.arrays[arrNdx].numComponents = posInfo.format == kChannelFormatColor ? 4 : posInfo.dimension; + dst.arrays[arrNdx].pointer = reinterpret_cast<const void*>(posInfo.offset); + dst.arrays[arrNdx].stride = posStream.stride; + dst.buffers[arrNdx] = GetCurrentBuffer(posInfo.stream)->GetBuffer(); + + dst.enabledArrays |= (1<<arrNdx); + } + } + } + + if (device.IsNormalRequiredForTexGen() && (availableShaderChannels & (1 << kShaderChannelNormal))) + { + const ChannelInfo& normInfo = m_Channels[kShaderChannelNormal]; + const Stream& normStream = m_StreamBuffers[normInfo.stream]; + + for (int texUnit = 0; texUnit < maxTexArrays; ++texUnit) + { + if (device.IsNormalRequiredForTexGen(texUnit)) + { + const int arrNdx = texArrayBase + texUnit; + dst.arrays[arrNdx].componentType = normInfo.format; + dst.arrays[arrNdx].numComponents = normInfo.format == kChannelFormatColor ? 4 : normInfo.dimension; + dst.arrays[arrNdx].pointer = reinterpret_cast<const void*>(normInfo.offset); + dst.arrays[arrNdx].stride = normStream.stride; + dst.buffers[arrNdx] = GetCurrentBuffer(normInfo.stream)->GetBuffer(); + + dst.enabledArrays |= (1<<arrNdx); + } + } + } + } +} + +void GLES3VBO::MarkBuffersRendered (const ChannelAssigns& channelAssigns) +{ + // \todo [pyry] Mark based on channel assignments + for (int ndx = 0; ndx < kMaxVertexStreams; ndx++) + { + DataBufferGLES30* buffer = GetCurrentBuffer(ndx); + if (buffer) + buffer->RecordRender(); + } +} + +void GLES3VBO::DrawVBO (const ChannelAssigns& channels, + UInt32 firstIndexByte, + UInt32 indexCount, + GfxPrimitiveType topology, + UInt32 firstVertex, + UInt32 vertexCount) +{ + Assert(0 <= firstVertex && firstVertex+vertexCount <= m_VertexCount); + + if (topology == kPrimitiveQuads) + { + // Need to emulate - oh well. + // \todo [2013-05-24 pyry] Cache this? + const int numQuads = indexCount/4; + const int emulatedIndexCount = numQuads * 6; + const int emulatedBufSize = emulatedIndexCount * sizeof(UInt16); + const UInt32 bufUsage = GL_DYNAMIC_DRAW; + std::vector<UInt16> quadIndices (emulatedIndexCount); + DataBufferGLES30* indexBuffer = GetBufferManagerGLES30()->AcquireBuffer(emulatedBufSize, bufUsage); + + FillIndexBufferForQuads(&quadIndices[0], emulatedBufSize, (const UInt16*)((UInt8*)&m_Indices[0] + firstIndexByte), numQuads); + indexBuffer->RecreateWithData(emulatedBufSize, bufUsage, &quadIndices[0]); + + Draw(indexBuffer, channels, kPrimitiveTriangles, emulatedIndexCount, 0, vertexCount); + + indexBuffer->Release(); + } + else + Draw(m_IndexBuffer, channels, topology, indexCount, firstIndexByte, vertexCount); +} + +void GLES3VBO::DrawCustomIndexed (const ChannelAssigns& channels, + void* indices, + UInt32 indexCount, + GfxPrimitiveType topology, + UInt32 vertexRangeBegin, + UInt32 vertexRangeEnd, + UInt32 drawVertexCount) +{ + Assert(0 <= vertexRangeBegin && vertexRangeBegin <= vertexRangeEnd && vertexRangeEnd <= m_VertexCount); + + // \note Called only in static batching mode which doesn't do quads. + Assert(topology != kPrimitiveQuads); + + const int ndxBufSize = indexCount * kVBOIndexSize; + const UInt32 ndxBufUsage = GL_DYNAMIC_DRAW; + DataBufferGLES30* indexBuffer = GetBufferManagerGLES30()->AcquireBuffer(ndxBufSize, ndxBufUsage); + + indexBuffer->RecreateWithData(ndxBufSize, ndxBufUsage, indices); + + Draw(indexBuffer, channels, topology, indexCount, 0, vertexRangeEnd-vertexRangeBegin); + + indexBuffer->Release(); +} + +void GLES3VBO::Draw (DataBufferGLES30* indexBuffer, + const ChannelAssigns& channels, + GfxPrimitiveType topology, + UInt32 indexCount, + UInt32 indexOffset, + UInt32 vertexCountForStats) +{ + const bool useVAO = true; // \todo [pyry] Get from GfxDevice caps + const VertexArrayObjectGLES30* vao = useVAO ? TryGetVAO(channels) : 0; + + Assert(topology != kPrimitiveQuads); + + // Setup other render state + VBOContainsColorGLES30(channels.GetSourceForTarget (kVertexCompColor) == kShaderChannelColor); + GetRealGfxDevice().BeforeDrawCall(false); + + if (vao) + { + GLES_CHK(glBindVertexArray(vao->GetVAO())); + } + else + { + VertexArrayInfoGLES30 vertexState; + ComputeVertexInputState(vertexState, channels); + SetupDefaultVertexArrayStateGLES30(vertexState); + } + + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer->GetBuffer())); + + { + ABSOLUTE_TIME drawTime = START_TIME; + const int primCount = GetPrimitiveCount(indexCount, topology, false); + + GLES_CHK(glDrawElements(kTopologyGLES3[topology], indexCount, GL_UNSIGNED_SHORT, (const void*)indexOffset)); + + drawTime = ELAPSED_TIME(drawTime); + GetRealGfxDevice().GetFrameStats().AddDrawCall(primCount, vertexCountForStats, drawTime); + } + + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + + if (vao) + { + GLES_CHK(glBindVertexArray(0)); + } + + // Record render event for used buffers + MarkBuffersRendered(channels); + indexBuffer->RecordRender(); +} + +const VertexArrayObjectGLES30* GLES3VBO::TryGetVAO (const ChannelAssigns& channels) +{ + // \note [pyry] VAO cache keys don't handle texgen. It is a rare case and we don't want to pay the + // cost of extra logic & storage. + { + GfxDevice& device = GetRealGfxDevice(); + if (device.IsPositionRequiredForTexGen() || device.IsNormalRequiredForTexGen()) + return 0; + } + + const VAOCacheKeyGLES30 cacheKey(channels, m_StreamBuffers[0].curBufferNdx, + m_StreamBuffers[1].curBufferNdx, + m_StreamBuffers[2].curBufferNdx, + m_StreamBuffers[3].curBufferNdx); + + const VertexArrayObjectGLES30* cachedVAO = m_VAOCache.Find(cacheKey); + + if (cachedVAO) + { + return cachedVAO; + } + else if (!m_VAOCache.IsFull()) + { + DBG_LOG_VBO_GLES30("GLES3VBO::GetVAO(): cache miss, creating new VAO"); + + // Map channel assigns + current layout to full vertex state + VertexArrayInfoGLES30 vertexState; + ComputeVertexInputState(vertexState, channels); + + VertexArrayObjectGLES30* vao = new VertexArrayObjectGLES30(vertexState); + m_VAOCache.Insert(cacheKey, vao); + + return vao; + } + else + { + // If VAO cache gets full, VBO falls back to using default VAO. That + // way we avoid constantly creating new objects in extreme cases. + return 0; + } +} + +UInt32 GLES3VBO::GetSkinningTargetVBO (void) +{ + const int skinStreamNdx = 0; // \todo [2013-05-31 pyry] Can this change? + Stream& skinStream = m_StreamBuffers[skinStreamNdx]; + + Assert(skinStream.buffers[skinStream.curBufferNdx]); + + if (BufferUpdateCausesStallGLES30(skinStream.buffers[skinStream.curBufferNdx])) + { + // Move to next slot. + skinStream.curBufferNdx = (skinStream.curBufferNdx + 1) % kBufferSwapChainSize; + + if (!skinStream.buffers[skinStream.curBufferNdx]) + { + const UInt32 usage = GL_STREAM_DRAW; + const int size = m_VertexCount*skinStream.stride; + DataBufferGLES30* buffer = GetBufferManagerGLES30()->AcquireBuffer(size, usage); + + if (buffer->GetSize() < size) + buffer->RecreateStorage(size, usage); + + skinStream.buffers[skinStream.curBufferNdx] = buffer; + } + } + + skinStream.buffers[skinStream.curBufferNdx]->RecordUpdate(); + return skinStream.buffers[skinStream.curBufferNdx]->GetBuffer(); +} + +DynamicGLES3VBO::DynamicGLES3VBO (void) + : m_CurVertexBuffer (0) + , m_CurIndexBuffer (0) + , m_CurRenderMode ((RenderMode)0) + , m_CurShaderChannelMask (0) + , m_CurStride (0) + , m_CurVertexCount (0) + , m_CurIndexCount (0) + , m_QuadArrayIndexBuffer (0) +{ +} + +DynamicGLES3VBO::~DynamicGLES3VBO (void) +{ + Cleanup(); +} + +static UInt32 GetDynamicChunkStride (UInt32 shaderChannelMask) +{ + UInt32 stride = 0; + for (int i = 0; i < kShaderChannelCount; ++i) + { + if (shaderChannelMask & (1<<i)) + stride += VBO::GetDefaultChannelByteSize(i); + } + return stride; +} + +bool DynamicGLES3VBO::GetChunk (UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB) +{ + Assert(maxVertices < 65536 && maxIndices < 65536*3); + Assert(!((renderMode == kDrawQuads) && (VBO::kMaxQuads*4 < maxVertices))); + DebugAssert(outVB != NULL && maxVertices > 0); + DebugAssert((renderMode == kDrawIndexedQuads && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedPoints && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedLines && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangles && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangleStrip && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawTriangleStrip && (outIB == NULL && maxIndices == 0)) || + (renderMode == kDrawQuads && (outIB == NULL && maxIndices == 0))); + DebugAssert(!m_CurVertexBuffer && !m_CurIndexBuffer); + + const UInt32 stride = GetDynamicChunkStride(shaderChannelMask); + const UInt32 usage = GL_STREAM_DRAW; + const UInt32 vertexBufferSize = AlignToDefault(stride*maxVertices); + const UInt32 indexBufferSize = AlignToDefault(kVBOIndexSize*maxIndices); + + const bool useMapBuffer = gGraphicsCaps.gles30.useMapBuffer; + const bool mapVertexBuffer = useMapBuffer && vertexBufferSize >= kDataBufferThreshold; + const bool mapIndexBuffer = useMapBuffer && indexBufferSize > 0 && indexBufferSize >= kDataBufferThreshold; + + DataBufferGLES30* vertexBuffer = mapVertexBuffer ? GetBufferManagerGLES30()->AcquireBuffer(maxVertices*stride, usage) : 0; + DataBufferGLES30* indexBuffer = mapIndexBuffer ? GetBufferManagerGLES30()->AcquireBuffer(indexBufferSize, usage) : 0; + + // \todo [2013-05-31 pyry] Grow buffers in reasonable steps (align to 1k?) + if (vertexBuffer && vertexBuffer->GetSize() < vertexBufferSize) + vertexBuffer->RecreateStorage(vertexBufferSize, usage); + + if (indexBuffer && indexBuffer->GetSize() < indexBufferSize) + indexBuffer->RecreateStorage(indexBufferSize, usage); + + if (!mapVertexBuffer && m_CurVertexData.size() < vertexBufferSize) + m_CurVertexData.resize(vertexBufferSize); + + if (!mapIndexBuffer && m_CurIndexData.size() < indexBufferSize) + m_CurIndexData.resize(indexBufferSize); + + if (vertexBuffer) + *outVB = vertexBuffer->Map(0, vertexBufferSize, GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT|GL_MAP_FLUSH_EXPLICIT_BIT); + else if (!mapVertexBuffer && vertexBufferSize > 0) + *outVB = &m_CurVertexData[0]; + + if (indexBuffer) + *outIB = indexBuffer->Map(0, indexBufferSize, GL_MAP_WRITE_BIT|GL_MAP_INVALIDATE_BUFFER_BIT|GL_MAP_FLUSH_EXPLICIT_BIT); + else if (!mapIndexBuffer && indexBufferSize > 0) + *outIB = &m_CurIndexData[0]; + + m_CurVertexBuffer = vertexBuffer; + m_CurIndexBuffer = indexBuffer; + m_CurRenderMode = renderMode; + m_CurShaderChannelMask = shaderChannelMask; + m_CurStride = stride; + + return true; +} + +void DynamicGLES3VBO::ReleaseChunk (UInt32 actualVertices, UInt32 actualIndices) +{ + Assert(m_CurVertexCount == 0 && m_CurIndexCount == 0); + + if (m_CurVertexBuffer) + { + m_CurVertexBuffer->FlushMappedRange(0, AlignToDefault(m_CurStride*actualVertices)); + m_CurVertexBuffer->Unmap(); + } + else if (actualVertices*m_CurStride >= kDataBufferThreshold) + { + // Migrate to buffer. + const int size = AlignToDefault(actualVertices*m_CurStride); + const UInt32 usage = GL_STREAM_DRAW; + + m_CurVertexBuffer = GetBufferManagerGLES30()->AcquireBuffer(size, usage); + m_CurVertexBuffer->RecreateWithData(size, usage, &m_CurVertexData[0]); + } + + if (m_CurIndexBuffer) + { + m_CurIndexBuffer->FlushMappedRange(0, AlignToDefault(actualIndices*kVBOIndexSize)); + m_CurIndexBuffer->Unmap(); + } + else if (actualIndices*kVBOIndexSize >= kDataBufferThreshold) + { + // Migrate to buffer. + const int size = AlignToDefault(actualIndices*kVBOIndexSize); + const UInt32 usage = GL_STREAM_DRAW; + + m_CurIndexBuffer = GetBufferManagerGLES30()->AcquireBuffer(size, usage); + m_CurIndexBuffer->RecreateWithData(size, usage, &m_CurIndexData[0]); + } + + m_CurVertexCount = actualVertices; + m_CurIndexCount = actualIndices; +} + +DataBufferGLES30* DynamicGLES3VBO::GetQuadArrayIndexBuffer (int vertexCount) +{ + const int quadCount = vertexCount/4; + const int quadIndexCount = quadCount * 6; + const int indexBufferSize = quadIndexCount * sizeof(UInt16); + const UInt32 indexBufferUsage = GL_STATIC_DRAW; + + if (!m_QuadArrayIndexBuffer || m_QuadArrayIndexBuffer->GetSize() < indexBufferSize) + { + // Need to re-specify index buffer since current is too small + std::vector<UInt16> quadIndices(quadIndexCount); + + for (int quadNdx = 0; quadNdx < quadCount; ++quadNdx) + { + const UInt16 srcBaseNdx = quadNdx*4; + const int dstBaseNdx = quadNdx*6; + quadIndices[dstBaseNdx + 0] = srcBaseNdx + 1; + quadIndices[dstBaseNdx + 1] = srcBaseNdx + 2; + quadIndices[dstBaseNdx + 2] = srcBaseNdx; + quadIndices[dstBaseNdx + 3] = srcBaseNdx + 2; + quadIndices[dstBaseNdx + 4] = srcBaseNdx + 3; + quadIndices[dstBaseNdx + 5] = srcBaseNdx; + } + + if (m_QuadArrayIndexBuffer && BufferUpdateCausesStallGLES30(m_QuadArrayIndexBuffer)) + { + m_QuadArrayIndexBuffer->Release(); + m_QuadArrayIndexBuffer = 0; + } + + if (!m_QuadArrayIndexBuffer) + m_QuadArrayIndexBuffer = GetBufferManagerGLES30()->AcquireBuffer(indexBufferSize, indexBufferUsage); + + m_QuadArrayIndexBuffer->RecreateWithData(indexBufferSize, indexBufferUsage, &quadIndices[0]); + } + + return m_QuadArrayIndexBuffer; +} + +void DynamicGLES3VBO::DrawChunk (const ChannelAssigns& channels) +{ + // Compute input state + VertexArrayInfoGLES30 vertexInputState; + ComputeVertexInputState(vertexInputState, channels); + + // \todo [2013-05-31 pyry] Do we want to use VAOs here? + + // Setup state + VBOContainsColorGLES30(channels.GetSourceForTarget (kVertexCompColor) == kShaderChannelColor); + GetRealGfxDevice().BeforeDrawCall(false); + SetupDefaultVertexArrayStateGLES30(vertexInputState); + + const void* indexPtr = m_CurIndexBuffer ? 0 : (m_CurIndexData.empty() ? 0 : &m_CurIndexData[0]); + int trianglesForStats = 0; + + if (m_CurIndexBuffer) + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CurIndexBuffer->GetBuffer())); + + switch (m_CurRenderMode) + { + case kDrawIndexedQuads: // \todo [2013-06-13 pyry] This enum shouldn't even be here. + case kDrawIndexedTriangles: + GLES_CHK(glDrawElements(GL_TRIANGLES, m_CurIndexCount, GL_UNSIGNED_SHORT, indexPtr)); + trianglesForStats = m_CurIndexCount/3; + break; + + case kDrawIndexedTriangleStrip: + GLES_CHK(glDrawElements(GL_TRIANGLE_STRIP, m_CurIndexCount, GL_UNSIGNED_SHORT, indexPtr)); + trianglesForStats = std::max<int>(0, m_CurIndexCount-2); + break; + case kDrawIndexedPoints: + GLES_CHK(glDrawElements(GL_POINTS, m_CurIndexCount, GL_UNSIGNED_SHORT, indexPtr)); + trianglesForStats = m_CurIndexCount*2; // Assuming one quad + break; + + case kDrawIndexedLines: + GLES_CHK(glDrawElements(GL_LINES, m_CurIndexCount, GL_UNSIGNED_SHORT, indexPtr)); + trianglesForStats = m_CurIndexCount; + break; + + case kDrawTriangleStrip: + GLES_CHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, m_CurVertexCount)); + trianglesForStats = m_CurVertexCount-2; + break; + + case kDrawQuads: + { + // Need to emulate with indices. + DataBufferGLES30* quadIndexBuf = GetQuadArrayIndexBuffer(m_CurVertexCount); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadIndexBuf->GetBuffer())); + GLES_CHK(glDrawElements(GL_TRIANGLES, m_CurVertexCount/4 * 6, GL_UNSIGNED_SHORT, 0)); + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + trianglesForStats = m_CurVertexCount/2; + quadIndexBuf->RecordRender(); + break; + } + + default: + Assert(false); + } + + if (m_CurIndexBuffer) + { + GLES_CHK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + m_CurIndexBuffer->RecordRender(); + } + + GetRealGfxDevice().GetFrameStats().AddDrawCall(trianglesForStats, m_CurVertexCount); + + // Release buffers and reset state + Cleanup(); +} + +void DynamicGLES3VBO::Recreate (void) +{ + Cleanup(); +} + +void DynamicGLES3VBO::Cleanup (void) +{ + if (m_CurVertexBuffer) + { + m_CurVertexBuffer->Release(); + m_CurVertexBuffer = 0; + } + + if (m_CurIndexBuffer) + { + m_CurIndexBuffer->Release(); + m_CurIndexBuffer = 0; + } + + if (m_QuadArrayIndexBuffer) + { + m_QuadArrayIndexBuffer->Release(); + m_QuadArrayIndexBuffer = 0; + } + + m_CurRenderMode = (RenderMode)0; + m_CurShaderChannelMask = 0; + m_CurStride = 0; + m_CurVertexCount = 0; + m_CurIndexCount = 0; + + m_CurVertexData.clear(); + m_CurIndexData.clear(); +} + +void DynamicGLES3VBO::ComputeVertexInputState (VertexArrayInfoGLES30& dst, const ChannelAssigns& channelAssigns) +{ + const UInt32 availableShaderChannels = m_CurShaderChannelMask; // Channels that have data in any of streams. + const UInt32 enabledTargets = channelAssigns.GetTargetMap(); + UInt32 channelOffsets[kShaderChannelCount]; + + const UInt8* basePointer = m_CurVertexBuffer ? 0 : &m_CurVertexData[0]; + const UInt32 buffer = m_CurVertexBuffer ? m_CurVertexBuffer->GetBuffer() : 0; + + // Compute offsets per enabled shader channel. + { + UInt32 curOffset = 0; + for (int ndx = 0; ndx < kShaderChannelCount; ndx++) + { + if (availableShaderChannels & (1<<ndx)) + { + channelOffsets[ndx] = curOffset; + curOffset += VBO::GetDefaultChannelByteSize(ndx); + } + else + channelOffsets[ndx] = 0; + } + } + + for (int attribNdx = 0; attribNdx < kGLES3MaxVertexAttribs; attribNdx++) + { + const VertexComponent target = kVertexCompTargetsGLES3[attribNdx]; + + if ((enabledTargets & (1<<target)) == 0) + continue; // Not enabled. + + const ShaderChannel sourceChannel = channelAssigns.GetSourceForTarget(target); + + // \todo [pyry] Uh, what? Channel is enabled, but no valid source exists. + if (sourceChannel < 0) + continue; + + Assert(0 <= sourceChannel && sourceChannel < kShaderChannelCount); + + if ((availableShaderChannels & (1<<sourceChannel)) == 0) + continue; // Not available. + + dst.arrays[attribNdx].componentType = VBO::GetDefaultChannelFormat(sourceChannel); + dst.arrays[attribNdx].numComponents = dst.arrays[attribNdx].componentType == kChannelFormatColor ? 4 : VBO::GetDefaultChannelDimension(sourceChannel); + dst.arrays[attribNdx].pointer = basePointer + channelOffsets[sourceChannel]; + dst.arrays[attribNdx].stride = m_CurStride; + dst.buffers[attribNdx] = buffer; + + dst.enabledArrays |= (1<<attribNdx); + } + + // Fixed-function texgen stuff. \todo [pyry] Are these even used? + { + GfxDevice& device = GetRealGfxDevice(); + const int texArrayBase = 3; + const int maxTexArrays = std::min(gGraphicsCaps.maxTexUnits, kGLES3MaxVertexAttribs-texArrayBase); + + if (device.IsPositionRequiredForTexGen() && (availableShaderChannels & (1 << kShaderChannelVertex))) + { + const ShaderChannel srcChannel = kShaderChannelVertex; + const int format = VBO::GetDefaultChannelFormat(srcChannel); + const int numComps = VBO::GetDefaultChannelDimension(srcChannel); + const UInt32 offset = channelOffsets[srcChannel]; + + for (int texUnit = 0; texUnit < maxTexArrays; ++texUnit) + { + if (device.IsPositionRequiredForTexGen(texUnit)) + { + const int arrNdx = texArrayBase + texUnit; + dst.arrays[arrNdx].componentType = format; + dst.arrays[arrNdx].numComponents = numComps; + dst.arrays[arrNdx].pointer = basePointer + offset; + dst.arrays[arrNdx].stride = m_CurStride; + dst.buffers[arrNdx] = buffer; + + dst.enabledArrays |= (1<<arrNdx); + } + } + } + + if (device.IsNormalRequiredForTexGen() && (availableShaderChannels & (1 << kShaderChannelNormal))) + { + const ShaderChannel srcChannel = kShaderChannelNormal; + const int format = VBO::GetDefaultChannelFormat(srcChannel); + const int numComps = VBO::GetDefaultChannelDimension(srcChannel); + const UInt32 offset = channelOffsets[srcChannel]; + + for (int texUnit = 0; texUnit < maxTexArrays; ++texUnit) + { + if (device.IsNormalRequiredForTexGen(texUnit)) + { + const int arrNdx = texArrayBase + texUnit; + dst.arrays[arrNdx].componentType = format; + dst.arrays[arrNdx].numComponents = numComps; + dst.arrays[arrNdx].pointer = basePointer + offset; + dst.arrays[arrNdx].stride = m_CurStride; + dst.buffers[arrNdx] = buffer; + + dst.enabledArrays |= (1<<arrNdx); + } + } + } + } +} + +// \todo [2013-05-31 pyry] Better, more generic state cache + +// \note In theory we could use whole VertexArrayInfoGLES30 as state cache, but alas +// bound buffers can be destroyed, recreated and state cache would be oblivious +// to the fact that binding is now empty. +static UInt32 sEnabledArrays = 0; + +void InvalidateVertexInputCacheGLES30() +{ + sEnabledArrays = 0; + + for (int attribNdx = 0; attribNdx < gGraphicsCaps.gles30.maxAttributes; attribNdx++) + GLES_CHK(glDisableVertexAttribArray(attribNdx)); +} + +void SetupDefaultVertexArrayStateGLES30 (const VertexArrayInfoGLES30& info) +{ + UInt32 curBoundBuffer = 0; + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, 0)); + + for (int attribNdx = 0; attribNdx < kGLES3MaxVertexAttribs; attribNdx++) + { + const UInt32 enableBit = 1<<attribNdx; + + if (info.enabledArrays & enableBit) + { + if (!(sEnabledArrays & enableBit)) + GLES_CHK(glEnableVertexAttribArray(attribNdx)); + + const UInt32 buffer = info.buffers[attribNdx]; + const int numComponents = info.arrays[attribNdx].numComponents; + const GLenum compType = kVertexTypeGLES3[info.arrays[attribNdx].componentType]; + const bool normalized = IsVertexArrayNormalized(attribNdx, (VertexChannelFormat)info.arrays[attribNdx].componentType); + const int stride = info.arrays[attribNdx].stride; + const void* pointer = info.arrays[attribNdx].pointer; + + if (curBoundBuffer != buffer) + { + GLES_CHK(glBindBuffer(GL_ARRAY_BUFFER, buffer)); + curBoundBuffer = buffer; + } + + GLES_CHK(glVertexAttribPointer(attribNdx, numComponents, compType, normalized ? GL_TRUE : GL_FALSE, stride, pointer)); + } + else if (sEnabledArrays & enableBit) + GLES_CHK(glDisableVertexAttribArray(attribNdx)); + } + + sEnabledArrays = info.enabledArrays; +} + +#endif // GFX_SUPPORTS_OPENGLES30 diff --git a/Runtime/GfxDevice/opengles30/VBOGLES30.h b/Runtime/GfxDevice/opengles30/VBOGLES30.h new file mode 100644 index 0000000..9e7f99a --- /dev/null +++ b/Runtime/GfxDevice/opengles30/VBOGLES30.h @@ -0,0 +1,262 @@ +#ifndef VBO_GLES30_H +#define VBO_GLES30_H + +#include "Runtime/Shaders/VBO.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "DataBuffersGLES30.h" +#include "IncludesGLES30.h" + +#include <map> + +enum AttribLocationGLES30 +{ + kGLES3AttribLocationPosition = 0, + kGLES3AttribLocationColor = 1, + kGLES3AttribLocationNormal = 2, + kGLES3AttribLocationTexCoord0 = 3, + kGLES3AttribLocationTexCoord1 = 4, + kGLES3AttribLocationTexCoord2 = 5, + kGLES3AttribLocationTexCoord3 = 6, + kGLES3AttribLocationTexCoord4 = 7, + kGLES3AttribLocationTexCoord5 = 8, + kGLES3AttribLocationTexCoord6 = 9, + kGLES3AttribLocationTexCoord7 = 10, + + kGLES3MaxVertexAttribs, //!< Although implementations may support more, this limits VertexArrayInfoGLES30 to a reasonable value. +}; + +struct VertexInputInfoGLES30 +{ + const void* pointer; //!< Pointer or offset. + UInt8 componentType; //!< Component type - of type VertexChannelFormat. + UInt8 numComponents; //!< Number of components. + UInt16 stride; //!< Attribute stride. + + // Following parameters come from outside: + // normalize: Deduced based on location and type. + // buffer: Comes from VertexArrayInfoGLES30 + + VertexInputInfoGLES30 (void) + : pointer (0) + , componentType (0) + , numComponents (0) + , stride (0) + { + } + + VertexInputInfoGLES30 (const void* pointer_, VertexChannelFormat componentType_, int numComponents_, UInt32 stride_) + : pointer (pointer_) + , componentType ((UInt8)componentType_) + , numComponents ((UInt8)numComponents_) + , stride ((UInt16)stride_) + { + // Check overflows. + Assert((VertexChannelFormat)componentType == componentType_ && + (int)numComponents == numComponents_ && + (UInt32)stride == stride_); + } +}; + +struct VertexArrayInfoGLES30 +{ + UInt32 enabledArrays; //!< Bitmask of enabled arrays. + UInt32 buffers[kGLES3MaxVertexAttribs]; + VertexInputInfoGLES30 arrays[kGLES3MaxVertexAttribs]; + + VertexArrayInfoGLES30 (void) + : enabledArrays(0) + { + } +}; + +// Setup vertex array state when no VAO is bound. +void SetupDefaultVertexArrayStateGLES30 (const VertexArrayInfoGLES30& info); + +// Invalidate default VA input cache. Call this if you mess up with VA bindings or state gets lost otherwise. +void InvalidateVertexInputCacheGLES30(); + +struct VertexArrayInfoGLES30; +class VertexArrayObjectGLES30; + +struct VAOCacheKeyGLES30 +{ + UInt32 bufferIndices; //!< 4 indices with 8 bits each + ChannelAssigns channels; + + inline VAOCacheKeyGLES30 (const ChannelAssigns& channels, UInt32 bufNdx0, UInt32 bufNdx1, UInt32 bufNdx2, UInt32 bufNdx3) + : bufferIndices ((bufNdx0 << 24) | (bufNdx1 << 16) | (bufNdx2 << 8) | bufNdx3) + , channels (channels) + { + Assert((bufNdx0 & ~0xff) == 0 && + (bufNdx1 & ~0xff) == 0 && + (bufNdx2 & ~0xff) == 0 && + (bufNdx3 & ~0xff) == 0); + } + + inline VAOCacheKeyGLES30 (void) + : bufferIndices (~0u) + , channels () + { + } + + inline bool operator== (const VAOCacheKeyGLES30& other) const + { + return bufferIndices == other.bufferIndices && channels == other.channels; + } +}; + +// Cache key must be changed if stream count changes. +typedef char vaoCacheStreamCountAssert[kMaxVertexStreams == 4 ? 1 : -1]; + +// VAO cache for single VBO. Can not be shared between VBOs. Cache must be cleared +// if layout or any buffer in VAO is changed. +// Linear search is used since VAO cache is very small and most static VBOs should find +// match in first slot(s) anyway. +class VAOCacheGLES30 +{ +public: + VAOCacheGLES30 (void); + ~VAOCacheGLES30 (void); + + const VertexArrayObjectGLES30* Find (const VAOCacheKeyGLES30& key) const; + void Insert (const VAOCacheKeyGLES30& key, VertexArrayObjectGLES30* vao); + bool IsFull (void) const; + + void Clear (void); + +public: + VAOCacheGLES30 (const VAOCacheGLES30&); // Not allowed! + VAOCacheGLES30& operator= (const VAOCacheGLES30&); // Not allowed! + + enum + { + kCacheSize = 8 + }; + + struct Entry + { + VAOCacheKeyGLES30 key; + VertexArrayObjectGLES30* vao; + + inline Entry (void) : vao(0) {} + }; + + Entry m_Entries[kCacheSize]; + int m_NextEntryNdx; +}; + +class GLES3VBO : public VBO +{ +public: + GLES3VBO (void); + virtual ~GLES3VBO (void); + + virtual void UpdateVertexData (const VertexBufferData& buffer); + virtual void UpdateIndexData (const IndexBufferData& buffer); + + virtual bool MapVertexStream (VertexStreamData& outData, unsigned stream); + virtual void UnmapVertexStream (unsigned stream); + + virtual void Cleanup (void); + virtual void Recreate (void); + virtual bool IsVertexBufferLost (void) const; + + virtual bool IsUsingSourceVertices (void) const; + virtual bool IsUsingSourceIndices (void) const; + + virtual int GetRuntimeMemorySize (void) const; + + virtual void DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount); + virtual void DrawCustomIndexed (const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount); + + // This will return VBO for skinned (first) stream + UInt32 GetSkinningTargetVBO (void); + + + virtual void MarkBuffersLost() {} + +private: + void ComputeVertexInputState (VertexArrayInfoGLES30& dst, const ChannelAssigns& channels); + void MarkBuffersRendered (const ChannelAssigns& channels); + + DataBufferGLES30* GetCurrentBuffer (int streamNdx); + + const VertexArrayObjectGLES30* TryGetVAO (const ChannelAssigns& channels); + + void Draw (DataBufferGLES30* indexBuffer, + const ChannelAssigns& channels, + GfxPrimitiveType topology, + UInt32 indexCount, + UInt32 indexOffset, + UInt32 vertexCountForStats); + + enum + { + kBufferSwapChainSize = kBufferUpdateMinAgeGLES30+1 + }; + + struct Stream + { + UInt32 channelMask; //!< Shader channels which this stream contains. + UInt32 stride; + int curBufferNdx; //!< Current buffer in swap chain + DataBufferGLES30* buffers[kBufferSwapChainSize]; + UInt8* cpuBuf; //!< CPU-side copy, used for Recreate() and emulating mapbuffer. + + Stream (void) : channelMask(0), stride(0), curBufferNdx(0), cpuBuf(0) { memset(&buffers[0], 0, sizeof(buffers)); } + }; + + // Vertex data + Stream m_StreamBuffers[kMaxVertexStreams]; + ChannelInfoArray m_Channels; + int m_VertexCount; + + // Index data + std::vector<UInt16> m_Indices; //!< Index data. Copy is kept for emulating quad primitive type. + DataBufferGLES30* m_IndexBuffer; + + VAOCacheGLES30 m_VAOCache; +}; + +class DynamicGLES3VBO : public DynamicVBO +{ +public: + DynamicGLES3VBO (void); + ~DynamicGLES3VBO (void); + + virtual bool GetChunk (UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB); + virtual void ReleaseChunk (UInt32 actualVertices, UInt32 actualIndices); + virtual void DrawChunk (const ChannelAssigns& channels); + + virtual void Recreate (void); + +private: + void ComputeVertexInputState (VertexArrayInfoGLES30& info, const ChannelAssigns& channels); + + void Cleanup (void); + + DataBufferGLES30* GetQuadArrayIndexBuffer (int vertexCount); + + enum + { + kDataBufferThreshold = 1024 + }; + + std::vector<UInt8> m_CurVertexData; + std::vector<UInt16> m_CurIndexData; + + DataBufferGLES30* m_CurVertexBuffer; + DataBufferGLES30* m_CurIndexBuffer; + + RenderMode m_CurRenderMode; + UInt32 m_CurShaderChannelMask; + UInt32 m_CurStride; + UInt32 m_CurVertexCount; + UInt32 m_CurIndexCount; + + DataBufferGLES30* m_QuadArrayIndexBuffer; //!< Used for kDrawQuads mode. +}; + +#endif diff --git a/Runtime/GfxDevice/threaded/ClientIDMapper.h b/Runtime/GfxDevice/threaded/ClientIDMapper.h new file mode 100644 index 0000000..4156701 --- /dev/null +++ b/Runtime/GfxDevice/threaded/ClientIDMapper.h @@ -0,0 +1,46 @@ +#ifndef CLIENTIDMAPPER_H +#define CLIENTIDMAPPER_H + +#include "Runtime/Utilities/dynamic_array.h" +#include "Runtime/GfxDevice/GfxDevice.h" + +#if ENABLE_GFXDEVICE_REMOTE_PROCESS +#define ClientIDWrapper(type) ClientIDMapper::ClientID +#define ClientIDWrapperHandle(type) ClientIDMapper::ClientID +#else +#define ClientIDWrapper(type) type* +#define ClientIDWrapperHandle(type) type +#endif + +class ClientIDMapper { +public: + typedef UInt32 ClientID; + + ClientIDMapper() : + m_HighestAllocatedID(0) + { + } + + ClientID CreateID() + { + if (m_FreeIDs.empty()) + return ++m_HighestAllocatedID; + else + { + ClientID retval = m_FreeIDs.back(); + m_FreeIDs.pop_back(); + return retval; + } + } + + void FreeID(ClientID cid) + { + m_FreeIDs.push_back(cid); + } + +private: + ClientID m_HighestAllocatedID; + dynamic_array<ClientID> m_FreeIDs; +}; + +#endif
\ No newline at end of file diff --git a/Runtime/GfxDevice/threaded/GfxCommands.h b/Runtime/GfxDevice/threaded/GfxCommands.h new file mode 100644 index 0000000..e148431 --- /dev/null +++ b/Runtime/GfxDevice/threaded/GfxCommands.h @@ -0,0 +1,669 @@ +#pragma once + +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" +#include "Runtime/GfxDevice/threaded/ThreadedDeviceStates.h" +#include "Runtime/GfxDevice/threaded/ClientIDMapper.h" + +struct ClientDeviceVBO; + + +enum GfxCommand +{ + kGfxCmd_Unused = 10000, + kGfxCmd_InvalidateState, + kGfxCmd_VerifyState, + kGfxCmd_SetMaxBufferedFrames, + kGfxCmd_Clear, + kGfxCmd_SetUserBackfaceMode, + kGfxCmd_SetInvertProjectionMatrix, + kGfxCmd_SetViewportOffset, + kGfxCmd_CreateBlendState, + kGfxCmd_CreateDepthState, + kGfxCmd_CreateStencilState, + kGfxCmd_CreateRasterState, + kGfxCmd_SetBlendState, + kGfxCmd_SetDepthState, + kGfxCmd_SetStencilState, + kGfxCmd_SetRasterState, + kGfxCmd_SetSRGBState, + kGfxCmd_SetWorldMatrix, + kGfxCmd_SetViewMatrix, + kGfxCmd_SetProjectionMatrix, + kGfxCmd_SetInverseScale, + kGfxCmd_SetNormalizationBackface, + kGfxCmd_SetFFLighting, + kGfxCmd_SetMaterial, + kGfxCmd_SetColor, + kGfxCmd_SetViewport, + kGfxCmd_SetScissorRect, + kGfxCmd_DisableScissor, + kGfxCmd_CreateTextureCombiners, + kGfxCmd_DeleteTextureCombiners, + kGfxCmd_SetTextureCombiners, + kGfxCmd_SetTexture, + kGfxCmd_SetTextureParams, + kGfxCmd_SetTextureTransform, + kGfxCmd_SetTextureName, + kGfxCmd_SetMaterialProperties, + kGfxCmd_CreateGpuProgram, + kGfxCmd_SetShaders, + kGfxCmd_CreateShaderParameters, + kGfxCmd_DestroySubProgram, + kGfxCmd_SetConstantBufferInfo, + kGfxCmd_DisableLights, + kGfxCmd_SetLight, + kGfxCmd_SetAmbient, + kGfxCmd_EnableFog, + kGfxCmd_DisableFog, + kGfxCmd_BeginSkinning, + kGfxCmd_SkinMesh, + kGfxCmd_EndSkinning, + kGfxCmd_BeginStaticBatching, + kGfxCmd_StaticBatchMesh, + kGfxCmd_EndStaticBatching, + kGfxCmd_BeginDynamicBatching, + kGfxCmd_DynamicBatchMesh, +#if ENABLE_SPRITES + kGfxCmd_DynamicBatchSprite, +#endif + kGfxCmd_EndDynamicBatching, + kGfxCmd_AddBatchingStats, + kGfxCmd_CreateRenderColorSurface, + kGfxCmd_CreateRenderDepthSurface, + kGfxCmd_DestroyRenderSurface, + kGfxCmd_DiscardContents, + kGfxCmd_SetRenderTarget, + kGfxCmd_SetRenderTargetWithFlags, + kGfxCmd_ResolveColorSurface, + kGfxCmd_ResolveDepthIntoTexture, + kGfxCmd_SetSurfaceFlags, + kGfxCmd_UploadTexture2D, + kGfxCmd_UploadTextureSubData2D, + kGfxCmd_UploadTextureCube, + kGfxCmd_UploadTexture3D, + kGfxCmd_DeleteTexture, + kGfxCmd_BeginFrame, + kGfxCmd_EndFrame, + kGfxCmd_PresentFrame, + kGfxCmd_HandleInvalidState, + kGfxCmd_FinishRendering, + kGfxCmd_InsertCPUFence, + kGfxCmd_ImmediateVertex, + kGfxCmd_ImmediateNormal, + kGfxCmd_ImmediateColor, + kGfxCmd_ImmediateTexCoordAll, + kGfxCmd_ImmediateTexCoord, + kGfxCmd_ImmediateBegin, + kGfxCmd_ImmediateEnd, + kGfxCmd_CaptureScreenshot, + kGfxCmd_ReadbackImage, + kGfxCmd_GrabIntoRenderTexture, + kGfxCmd_SetActiveContext, + kGfxCmd_ResetFrameStats, + kGfxCmd_BeginFrameStats, + kGfxCmd_EndFrameStats, + kGfxCmd_SaveDrawStats, + kGfxCmd_RestoreDrawStats, + kGfxCmd_SynchronizeStats, + kGfxCmd_SetAntiAliasFlag, + kGfxCmd_SetWireframe, + kGfxCmd_DrawUserPrimitives, + kGfxCmd_Quit, + + kGfxCmd_VBO_UpdateVertexData, + kGfxCmd_VBO_UpdateIndexData, + kGfxCmd_VBO_Draw, + kGfxCmd_VBO_DrawCustomIndexed, + kGfxCmd_VBO_Recreate, + kGfxCmd_VBO_MapVertexStream, + kGfxCmd_VBO_IsVertexBufferLost, + kGfxCmd_VBO_SetVertexStreamMode, + kGfxCmd_VBO_SetIndicesDynamic, + kGfxCmd_VBO_GetRuntimeMemorySize, + kGfxCmd_VBO_GetVertexSize, + kGfxCmd_VBO_AddExtraUvChannels, + kGfxCmd_VBO_CopyExtraUvChannels, + kGfxCmd_VBO_Constructor, + kGfxCmd_VBO_Destructor, + kGfxCmd_VBO_UseAsStreamOutput, + + kGfxCmd_DynVBO_Chunk, + kGfxCmd_DynVBO_DrawChunk, + + kGfxCmd_DisplayList_Call, + kGfxCmd_DisplayList_End, + + kGfxCmd_CreateWindow, + kGfxCmd_SetActiveWindow, + kGfxCmd_WindowReshape, + kGfxCmd_WindowDestroy, + kGfxCmd_BeginRendering, + kGfxCmd_EndRendering, + + kGfxCmd_AcquireThreadOwnership, + kGfxCmd_ReleaseThreadOwnership, + + kGfxCmd_BeginProfileEvent, + kGfxCmd_EndProfileEvent, + kGfxCmd_ProfileControl, + kGfxCmd_BeginTimerQueries, + kGfxCmd_EndTimerQueries, + + kGfxCmd_TimerQuery_Constructor, + kGfxCmd_TimerQuery_Destructor, + kGfxCmd_TimerQuery_Measure, + kGfxCmd_TimerQuery_GetElapsed, + + kGfxCmd_InsertCustomMarker, + + kGfxCmd_SetComputeBufferData, + kGfxCmd_GetComputeBufferData, + kGfxCmd_CopyComputeBufferCount, + kGfxCmd_SetRandomWriteTargetTexture, + kGfxCmd_SetRandomWriteTargetBuffer, + kGfxCmd_ClearRandomWriteTargets, + kGfxCmd_CreateComputeProgram, + kGfxCmd_DestroyComputeProgram, + kGfxCmd_CreateComputeConstantBuffers, + kGfxCmd_DestroyComputeConstantBuffers, + kGfxCmd_CreateComputeBuffer, + kGfxCmd_DestroyComputeBuffer, + kGfxCmd_UpdateComputeConstantBuffers, + kGfxCmd_UpdateComputeResources, + kGfxCmd_DispatchComputeProgram, + kGfxCmd_DrawNullGeometry, + kGfxCmd_DrawNullGeometryIndirect, + kGfxCmd_QueryGraphicsCaps, + kGfxCmd_SetGpuProgramParameters, + kGfxCmd_DeleteGPUSkinningInfo, + kGfxCmd_SkinOnGPU, + kGfxCmd_UpdateSkinSourceData, + kGfxCmd_UpdateSkinBonePoses, + + // Keep platform specific flags last +#if UNITY_XENON + kGfxCmd_RawVBO_Constructor, + kGfxCmd_RawVBO_Destructor, + kGfxCmd_RawVBO_Next, + kGfxCmd_RawVBO_Write, + kGfxCmd_RawVBO_InvalidateGpuCache, + + kGfxCmd_EnablePersistDisplayOnQuit, + kGfxCmd_OnLastFrameCallback, + + kGfxCmd_RegisterTexture2D, + kGfxCmd_PatchTexture2D, + kGfxCmd_DeleteTextureEntryOnly, + kGfxCmd_UnbindAndDelayReleaseTexture, + kGfxCmd_SetTextureWrapModes, + + kGfxCmd_VideoPlayer_Constructor, + kGfxCmd_VideoPlayer_Destructor, + kGfxCmd_VideoPlayer_Render, + kGfxCmd_VideoPlayer_Pause, + kGfxCmd_VideoPlayer_Resume, + kGfxCmd_VideoPlayer_Stop, + kGfxCmd_VideoPlayer_SetPlaySpeed, + kGfxCmd_VideoPlayer_Play, + kGfxCmd_SetHiStencilState, + kGfxCmd_HiStencilFlush, + kGfxCmd_SetNullPixelShader, + kGfxCmd_EnableHiZ, +#endif + + kGfxCmd_Count +}; + +typedef int GfxCmdBool; + + +struct GfxCmdClear +{ + UInt32 clearFlags; + Vector4f color; + float depth; + int stencil; +}; + +struct GfxCmdSetNormalizationBackface +{ + NormalizationMode mode; + bool backface; +}; + +struct GfxCmdSetFFLighting +{ + bool on; + bool separateSpecular; + ColorMaterialMode colorMaterial; +}; + +struct GfxCmdCreateTextureCombiners +{ + int count; + bool hasVertexColorOrLighting; + bool usesAddSpecular; +}; + +struct GfxCmdSetTexture +{ + ShaderType shaderType; + int unit; + int samplerUnit; + TextureID texture; + TextureDimension dim; + float bias; +}; + +struct GfxCmdSetTextureParams +{ + TextureID texture; + TextureDimension texDim; + TextureFilterMode filter; + TextureWrapMode wrap; + int anisoLevel; + bool hasMipMap; + TextureColorSpace colorSpace; +}; + +struct GfxCmdSetTextureName +{ + TextureID texture; + int nameLength; +}; + +struct GfxCmdSetTextureBias +{ + int unit; + float bias; +}; + +struct GfxCmdSetTextureTransform +{ + int unit; + TextureDimension dim; + TexGenMode texGen; + bool identity; + Matrix4x4f matrix; +}; + +struct GfxCmdSetMaterialProperties +{ + int propertyCount; + int bufferSize; +}; + +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS +struct GfxCmdCreateGpuProgram +{ + const char *source; + CreateGpuProgramOutput* output; + GpuProgram** result; +}; +#endif + +struct GfxCmdSetShaders +{ + ClientIDWrapper(GpuProgram) programs[kShaderTypeCount]; + ClientIDWrapper(const GpuProgramParameters) params[kShaderTypeCount]; + int paramsBufferSize[kShaderTypeCount]; +}; + +struct GfxCmdCreateShaderParameters +{ + ShaderLab::SubProgram* program; + FogMode fogMode; +}; + +struct GfxCmdBeginStaticBatching +{ + ChannelAssigns channels; + GfxPrimitiveType topology; +}; + +struct GfxCmdStaticBatchMesh +{ + UInt32 firstVertex; + UInt32 vertexCount; + IndexBufferData indices; + UInt32 firstIndexByte; + UInt32 indexCount; +}; + +struct GfxCmdEndStaticBatching +{ + ClientDeviceVBO* vbo; + Matrix4x4f matrix; + TransformType transformType; + int sourceChannels; +}; + +struct GfxCmdBeginDynamicBatching +{ + ChannelAssigns shaderChannels; + UInt32 channelsInVBO; + size_t maxVertices; + size_t maxIndices; + GfxPrimitiveType topology; +}; + +struct GfxCmdDynamicBatchMesh +{ + Matrix4x4f matrix; + VertexBufferData vertices; + UInt32 firstVertex; + UInt32 vertexCount; + IndexBufferData indices; + UInt32 firstIndexByte; + UInt32 indexCount; +}; + +#if ENABLE_SPRITES +struct GfxCmdDynamicBatchSprite +{ + Matrix4x4f matrix; + const SpriteRenderData *sprite; + ColorRGBA32 color; +}; +#endif +struct GfxCmdEndDynamicBatching +{ + TransformType transformType; +}; + +struct GfxCmdAddBatchingStats +{ + int batchedTris; + int batchedVerts; + int batchedCalls; +}; + +struct GfxCmdCreateRenderColorSurface +{ + TextureID textureID; + int width; + int height; + int samples; + int depth; + TextureDimension dim; + RenderTextureFormat format; + UInt32 createFlags; +}; + +struct GfxCmdCreateRenderDepthSurface +{ + TextureID textureID; + int width; + int height; + int samples; + TextureDimension dim; + DepthBufferFormat depthFormat; + UInt32 createFlags; +}; + +struct GfxCmdSetRenderTarget +{ + ClientIDWrapperHandle(RenderSurfaceHandle) colorHandles[kMaxSupportedRenderTargets]; + ClientIDWrapperHandle(RenderSurfaceHandle) depthHandle; + int colorCount; + int mipLevel; + CubemapFace face; +}; + +struct GfxCmdResolveDepthIntoTexture +{ + ClientIDWrapperHandle(RenderSurfaceHandle) colorHandle; + ClientIDWrapperHandle(RenderSurfaceHandle) depthHandle; +}; + +struct GfxCmdSetSurfaceFlags +{ + ClientIDWrapperHandle(RenderSurfaceHandle) surf; + UInt32 flags; + UInt32 keepFlags; +}; + +struct GfxCmdUploadTexture2D +{ + TextureID texture; + TextureDimension dimension; + int srcSize; + int width; + int height; + TextureFormat format; + int mipCount; + UInt32 uploadFlags; + int skipMipLevels; + TextureUsageMode usageMode; + TextureColorSpace colorSpace; +}; + +struct GfxCmdUploadTextureSubData2D +{ + TextureID texture; + int srcSize; + int mipLevel; + int x; + int y; + int width; + int height; + TextureFormat format; + TextureColorSpace colorSpace; +}; + +struct GfxCmdUploadTextureCube +{ + TextureID texture; + int srcSize; + int faceDataSize; + int size; + TextureFormat format; + int mipCount; + UInt32 uploadFlags; + TextureColorSpace colorSpace; +}; + +struct GfxCmdUploadTexture3D +{ + TextureID texture; + int srcSize; + int width; + int height; + int depth; + TextureFormat format; + int mipCount; + UInt32 uploadFlags; +}; + +struct GfxCmdDrawUserPrimitives +{ + GfxPrimitiveType type; + int vertexCount; + UInt32 vertexChannels; + int stride; +}; + +struct GfxCmdVBODraw +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo; +#else + ClientDeviceVBO* vbo; +#endif + ChannelAssigns channels; + UInt32 firstIndexByte; + UInt32 indexCount; + GfxPrimitiveType topology; + UInt32 firstVertex; + UInt32 vertexCount; +}; + +struct GfxCmdVBODrawCustomIndexed +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo; +#else + ClientDeviceVBO* vbo; +#endif + ChannelAssigns channels; + UInt32 indexCount; + GfxPrimitiveType topology; + UInt32 vertexRangeBegin; + UInt32 vertexRangeEnd; + UInt32 drawVertexCount; +}; + +struct GfxCmdVBODrawStripWireframe +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo; +#else + ClientDeviceVBO* vbo; +#endif + ChannelAssigns channels; + UInt32 indexCount; + UInt32 triCount; + UInt32 vertexCount; +}; + +struct GfxCmdVBOMapVertexStream +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo; +#else + ClientDeviceVBO* vbo; +#endif + unsigned stream; + UInt32 size; +}; + +struct GfxCmdVBOSetVertexStreamMode +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo; +#else + ClientDeviceVBO* vbo; +#endif + unsigned stream; + int mode; +}; + +struct GfxCmdVBOSetSetIndicesDynamic +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo; +#else + ClientDeviceVBO* vbo; +#endif + int dynamic; +}; + +struct GfxCmdVBOAddExtraUvChannels +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo; +#else + ClientDeviceVBO* vbo; +#endif + UInt32 size; + int extraUvCount; +}; + +struct GfxCmdVBOCopyExtraUvChannels +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO dest; + ClientDeviceVBO source; +#else + ClientDeviceVBO* dest; + ClientDeviceVBO* source; +#endif + +}; + + +struct GfxCmdVector3 +{ + float x; + float y; + float z; +}; + +struct GfxCmdVector4 +{ + float x; + float y; + float z; + float w; +}; + +struct GfxCmdImmediateTexCoord +{ + int unit; + float x; + float y; + float z; +}; + +struct GfxCmdCaptureScreenshot +{ + int left; + int bottom; + int width; + int height; + UInt8* rgba32; + bool* success; +}; + +struct GfxCmdReadbackImage +{ + ImageReference& image; + int left; + int bottom; + int width; + int height; + int destX; + int destY; + bool* success; +}; + +struct GfxCmdGrabIntoRenderTexture +{ + ClientIDWrapperHandle(RenderSurfaceHandle) rs; + ClientIDWrapperHandle(RenderSurfaceHandle) rd; + int x; + int y; + int width; + int height; +}; + +struct GfxCmdDynVboChunk +{ + UInt32 channelMask; + UInt32 vertexStride; + UInt32 actualVertices; + UInt32 actualIndices; + UInt32 renderMode; +}; + +#if UNITY_WIN && UNITY_EDITOR + +struct GfxCmdWindowReshape +{ + int width; + int height; + DepthBufferFormat depthFormat; + int antiAlias; +}; + +struct GfxCmdCreateWindow +{ + HWND window; + int width; + int height; + DepthBufferFormat depthFormat; + int antiAlias; +}; + +#endif diff --git a/Runtime/GfxDevice/threaded/GfxDeviceClient.cpp b/Runtime/GfxDevice/threaded/GfxDeviceClient.cpp new file mode 100644 index 0000000..39295c6 --- /dev/null +++ b/Runtime/GfxDevice/threaded/GfxDeviceClient.cpp @@ -0,0 +1,3922 @@ +#include "UnityPrefix.h" + +#if ENABLE_MULTITHREADED_CODE +#if ENABLE_SPRITES +#include "Runtime/Graphics/SpriteFrame.h" +#endif +#include "Runtime/GfxDevice/threaded/GfxDeviceClient.h" +#include "Runtime/GfxDevice/threaded/GfxDeviceWorker.h" +#include "Runtime/GfxDevice/threaded/GfxCommands.h" +#include "Runtime/GfxDevice/threaded/GfxReturnStructs.h" +#include "Runtime/GfxDevice/GfxDeviceSetup.h" +#include "Runtime/Threads/Thread.h" +#include "Runtime/Threads/ThreadUtility.h" +#include "Runtime/GfxDevice/threaded/ThreadedVBO.h" +#include "Runtime/Shaders/MaterialProperties.h" +#include "Runtime/GfxDevice/threaded/ThreadedWindow.h" +#include "Runtime/GfxDevice/threaded/ThreadedDisplayList.h" +#include "Runtime/GfxDevice/threaded/ThreadedTimerQuery.h" +#include "External/shaderlab/Library/program.h" +#include "External/shaderlab/Library/properties.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "External/shaderlab/Library/shaderlab.h" +#include "External/shaderlab/Library/texenv.h" +#include "External/shaderlab/Library/pass.h" +#include "Runtime/Filters/Mesh/MeshSkinning.h" +#include "Runtime/Graphics/GraphicsHelper.h" +#include "Runtime/Profiler/Profiler.h" +#include "Runtime/GfxDevice/GPUSkinningInfo.h" +#include "Runtime/Profiler/ProfilerImpl.h" +#if UNITY_XENON +#include "PlatformDependent/Xbox360/Source/GfxDevice/GfxXenonVBO.h" +#include "PlatformDependent/Xbox360/Source/Services/VideoPlayer.h" +#endif + +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT +#include <ppapi/cpp/instance.h> +#include "External/NPAPI2NaCl/Common/UnityInterfaces.h" +#include "PlatformDependent/PepperPlugin/UnityInstance.h" + +void *CreateSharedGfxDeviceAndBuffer(size_t size) +{ + struct UNITY_GfxDevice_1_0 *gfxInterface = (UNITY_GfxDevice_1_0*)pp::Module::Get()->GetBrowserInterface(UNITY_GFXDEVICE_INTERFACE_1_0); + PP_Resource res = gfxInterface->Create(GetUnityInstance().pp_instance(), size); + return gfxInterface->GetSharedMemoryBufferAddress(res); +} +#endif + +PROFILER_INFORMATION(gGfxWaitForPresentProf, "Gfx.WaitForPresent", kProfilerOverhead) + +class ClientGPUSkinningInfo : public GPUSkinningInfo +{ + friend class GfxDeviceClient; +private: + ClientGPUSkinningInfo(GPUSkinningInfo *realSkinInfo): GPUSkinningInfo(), m_realSkinInfo(realSkinInfo) {} + virtual ~ClientGPUSkinningInfo() {} + + GPUSkinningInfo *m_realSkinInfo; + +public: + virtual UInt32 GetVertexCount() { return m_realSkinInfo->GetVertexCount(); } + virtual UInt32 GetChannelMap() { return m_realSkinInfo->GetChannelMap(); } + virtual int GetStride() { return m_realSkinInfo->GetStride(); } + virtual VBO * GetDestVBO() { return m_DestVBO; } + virtual UInt32 GetBonesPerVertex() { return m_realSkinInfo->GetBonesPerVertex(); } + + /** Update vertex count */ + virtual void SetVertexCount(UInt32 count) { m_realSkinInfo->SetVertexCount(count); } + + /** Update channel map */ + virtual void SetChannelMap(UInt32 channelmap) { m_realSkinInfo->SetChannelMap(channelmap); } + + /** Update stride of the vertices in bytes (not including skin data). */ + virtual void SetStride(int stride) { m_realSkinInfo->SetStride(stride); } + + /** Update destination VBO */ + virtual void SetDestVBO(VBO *vbo) + { + m_DestVBO = vbo; + // realskininfo->m_destVBO will be updated lazily on the actual skinning call + } + + virtual void SetBonesPerVertex(UInt32 bones) + { + m_realSkinInfo->SetBonesPerVertex(bones); + } + + /** Threading support: Read from stream. */ + virtual void Read(ThreadedStreamBuffer& stream) + { + AssertBreak(false); + } + /** Threading support: Write to stream. */ + virtual void Write(ThreadedStreamBuffer& stream) + { + AssertBreak(false); + } + + /** Helper function for thread worker: clear the internal structures without releasing, + so the internal resources won't be double-released. */ + virtual void Clear() + { + AssertBreak(false); + } + +}; + + + + +GfxDevice* CreateClientGfxDevice(GfxDeviceRenderer renderer, UInt32 flags, size_t bufferSize, void *buffer) +{ + bool forceRef = (flags & kClientDeviceForceRef) != 0; + +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + if (flags & kClientDeviceUseRealDevice) + { + return CreateRealGfxDevice (renderer, forceRef); + } +#endif + + bool threaded = (flags & kClientDeviceThreaded) != 0; + bool clientProcess = (flags & kClientDeviceClientProcess) != 0; + bool workerProcess = (flags & kClientDeviceWorkerProcess) != 0; + + printf_console("GfxDevice: creating device client; threaded=%i\n", (int)threaded); + + // Threading mode must be set before creating device (so D3D9 gets correct flags) + SetGfxThreadingMode (threaded ? kGfxThreadingModeThreaded : kGfxThreadingModeNonThreaded); + + if (bufferSize == 0) + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + // The native client uses a larger default size for the ring buffer, since it cannot + // flush the buffer at arbitrary times, so it needs to be big enough to hold complete + // data for texture upload commands. + bufferSize = 64*1024*1024; +#else + bufferSize = 8*1024*1024; +#endif + } + +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + if (clientProcess) + buffer = CreateSharedGfxDeviceAndBuffer(bufferSize); +#endif + + GfxDeviceClient* device = UNITY_NEW_AS_ROOT(GfxDeviceClient(threaded, clientProcess, bufferSize, buffer), kMemGfxDevice, "GfxClientDevice", ""); + if (clientProcess) + { + device->SetRealGfxDevice (NULL); + device->QueryGraphicsCaps(); + return device; + } + + GfxDeviceWorker* worker = device->GetGfxDeviceWorker(); + if(renderer == kGfxRendererOpenGLES30) + SetGfxDevice(device); // Set this on GLES30 as we do stuff in OnDeviceCreated that requires this. Can't set it for all as it breaks NaCL build in teamcity. + GfxThreadableDevice* realDevice = worker->Startup(renderer, threaded && !workerProcess, forceRef); + + if (realDevice) + { + device->SetRealGfxDevice (realDevice); + device->AcquireThreadOwnership (); + realDevice->OnDeviceCreated (false); + device->ReleaseThreadOwnership (); + return device; + } + + // Failed to create threaded device + SetGfxThreadingMode (kGfxThreadingModeDirect); + + // Client device deletes worker + UNITY_DELETE(device, kMemGfxDevice); + return NULL; +} + +bool GfxDeviceWorkerProcessRunCommand() +{ + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + GfxDeviceWorker* worker = device.GetGfxDeviceWorker(); + return worker->RunCommandIfDataIsAvailable(); +} + +void GfxDeviceClient::WaitForSignal () +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + struct UNITY_GfxDevice_1_0 *gfxInterface = (UNITY_GfxDevice_1_0*)pp::Module::Get()->GetBrowserInterface(UNITY_GFXDEVICE_INTERFACE_1_0); + return gfxInterface->WaitForSignal(0); +#else + if (m_DeviceWorker) + m_DeviceWorker->WaitForSignal(); +#endif +} + +void GfxDeviceClient::QueryGraphicsCaps() +{ + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_QueryGraphicsCaps); + + ReadbackData(m_ReadbackData); + + // no, really, we need to properly serialize this stuff with all the strings. this is just a hack to get running. + size_t offset = (char*)&gGraphicsCaps.vendorID - (char*)&gGraphicsCaps; + memcpy (&gGraphicsCaps.vendorID, m_ReadbackData.data(), std::min(m_ReadbackData.size(), sizeof(GraphicsCaps) - offset)); +} + + +GfxDeviceClient::GfxDeviceClient(bool threaded, bool clientProcess, size_t bufferSize, void *buffer) : + m_RealDevice(NULL), + m_Threaded(threaded), + m_Serialize(threaded), + m_RecordDepth(0), + m_MaxCallDepth(1), + m_DynamicVBO(NULL), + m_sRGBWrite(false) +{ + // Create stack of display lists (including "top" level) + m_DisplayListStack = new DisplayListContext[m_MaxCallDepth + 1]; + if (m_Threaded) + { + if (buffer) + m_DisplayListStack[0].commandQueue.CreateFromMemory(ThreadedStreamBuffer::kModeCrossProcess, bufferSize, buffer); + else + m_DisplayListStack[0].commandQueue.Create(ThreadedStreamBuffer::kModeThreaded, bufferSize); + m_DynamicVBO = new ThreadedDynamicVBO(*this); + } + for (int i = 1; i <= m_MaxCallDepth; i++) + m_DisplayListStack[i].commandQueue.Create(ThreadedStreamBuffer::kModeGrowable, 0); + m_CurrentContext = &m_DisplayListStack[0]; + m_CommandQueue = &m_CurrentContext->commandQueue; + m_InvertProjectionMatrix = false; + #if GFX_USES_VIEWPORT_OFFSET + m_ViewportOffset.Set(0.0f, 0.0f); + #endif + m_TransformState.Invalidate(m_BuiltinParamValues); + m_ScissorEnabled = -1; + m_PresentPending = false; + m_Wireframe = false; + m_CurrentTargetWidth = 0; + m_CurrentTargetHeight = 0; + m_CurrentWindowWidth = 0; + m_CurrentWindowHeight = 0; + m_ThreadOwnershipCount = 0; + m_CurrentCPUFence = 0; + m_PresentFrameID = 0; + if (clientProcess) + m_DeviceWorker = NULL; + else + m_DeviceWorker = new GfxDeviceWorker(4, m_CommandQueue); + + OnCreate(); + + { + ClientDeviceRenderSurface* color = new ClientDeviceRenderSurface(0, 0); + RenderSurfaceBase_InitColor(*color); + color->backBuffer = true; + color->internalHandle = m_RealDevice ? m_RealDevice->GetBackBufferColorSurface() : RenderSurfaceHandle(); + SetBackBufferColorSurface(color); + } + { + ClientDeviceRenderSurface* depth = new ClientDeviceRenderSurface(0, 0); + RenderSurfaceBase_InitDepth(*depth); + depth->backBuffer = true; + depth->internalHandle = m_RealDevice ? m_RealDevice->GetBackBufferDepthSurface() : RenderSurfaceHandle(); + SetBackBufferDepthSurface(depth); + } + +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + posForTexGen = 0; + nrmForTexGen = 0; + CompileTimeAssert(sizeof(posForTexGen) * 8 == kMaxSupportedTextureUnitsGLES, "posForTexGen should have enough bits for tex units"); + CompileTimeAssert(sizeof(nrmForTexGen) * 8 == kMaxSupportedTextureUnitsGLES, "nrmForTexGen should have enough bits for tex units"); +#endif +} + +GfxDeviceClient::~GfxDeviceClient() +{ + CheckMainThread(); + if (m_Threaded && m_RealDevice) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_Quit); + SubmitCommands(); + WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + // m_CommandQueue was not allocated + m_CommandQueue = NULL; + delete[] m_DisplayListStack; + if (m_Threaded) + delete m_DynamicVBO; + delete m_DeviceWorker; +} + +void GfxDeviceClient::InvalidateState() +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_TransformState.Invalidate(m_BuiltinParamValues); + m_FogParams.Invalidate(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_InvalidateState); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->InvalidateState(); +} + +#if GFX_DEVICE_VERIFY_ENABLE +void GfxDeviceClient::VerifyState() +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_VerifyState); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->VerifyState(); +} +#endif + + +void GfxDeviceClient::SetMaxBufferedFrames (int bufferSize) +{ + CheckMainThread(); + GfxDevice::SetMaxBufferedFrames(bufferSize); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetMaxBufferedFrames); + m_CommandQueue->WriteValueType<int>(bufferSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetMaxBufferedFrames(bufferSize); +} + + +void GfxDeviceClient::Clear( UInt32 clearFlags, const float color[4], float depth, int stencil ) +{ + CheckMainThread(); + + // mark cleared surfaces as "no contents" if we're tracking that + if (GetFrameStats().m_StatsEnabled) + { + if (clearFlags & kGfxClearColor) + { + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + { + if (!m_ActiveRenderColorSurfaces[i].IsValid ()) + continue; + ClientDeviceRenderSurface* colorSurf = (ClientDeviceRenderSurface*)m_ActiveRenderColorSurfaces[i].object; + colorSurf->state = ClientDeviceRenderSurface::kCleared; + } + } + if ((clearFlags & kGfxClearDepthStencil) && m_ActiveRenderDepthSurface.IsValid ()) + { + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)m_ActiveRenderDepthSurface.object; + if (depthSurf) + depthSurf->state = ClientDeviceRenderSurface::kCleared; + } + } + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_Clear); + GfxCmdClear clear = { clearFlags, Vector4f(color), depth, stencil }; + m_CommandQueue->WriteValueType<GfxCmdClear>(clear); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->Clear(clearFlags, color, depth, stencil); +} + +void GfxDeviceClient::SetUserBackfaceMode( bool enable ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetUserBackfaceMode); + m_CommandQueue->WriteValueType<GfxCmdBool>(enable); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetUserBackfaceMode(enable); +} + +void GfxDeviceClient::SetWireframe(bool wire) +{ + CheckMainThread(); + m_Wireframe = wire; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetWireframe); + m_CommandQueue->WriteValueType<GfxCmdBool>(wire); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetWireframe(wire); +} + +bool GfxDeviceClient::GetWireframe() const +{ + return m_Wireframe; +} + + +void GfxDeviceClient::SetInvertProjectionMatrix( bool enable ) +{ + CheckMainThread(); + m_InvertProjectionMatrix = enable; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetInvertProjectionMatrix); + m_CommandQueue->WriteValueType<GfxCmdBool>(enable); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetInvertProjectionMatrix(enable); +} + +bool GfxDeviceClient::GetInvertProjectionMatrix() const +{ + CheckMainThread(); + return m_InvertProjectionMatrix; +} + +#if GFX_USES_VIEWPORT_OFFSET +void GfxDeviceClient::SetViewportOffset( float x, float y ) +{ + CheckMainThread(); + m_ViewportOffset = Vector2f(x, y); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetViewportOffset); + m_CommandQueue->WriteValueType<Vector2f>(m_ViewportOffset); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetViewportOffset(x, y); +} + +void GfxDeviceClient::GetViewportOffset( float &x, float &y ) const +{ + x = m_ViewportOffset.x; + y = m_ViewportOffset.y; +} +#endif + +DeviceBlendState* GfxDeviceClient::CreateBlendState(const GfxBlendState& state) +{ + CheckMainThread(); + SET_ALLOC_OWNER(this); + DebugAssert(!IsRecording()); + std::pair<CachedBlendStates::iterator, bool> added = m_CachedBlendStates.insert(std::make_pair(state, ClientDeviceBlendState(state))); + ClientDeviceBlendState* result = &added.first->second; + if (!added.second) + return result; + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateBlendState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + result->internalState = m_BlendStateMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientDeviceBlendState>(*result); +#else + m_CommandQueue->WriteValueType<ClientDeviceBlendState*>(result); +#endif + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + result->internalState = m_RealDevice->CreateBlendState(state); +#endif + + return result; +} + +DeviceDepthState* GfxDeviceClient::CreateDepthState(const GfxDepthState& state) +{ + CheckMainThread(); + SET_ALLOC_OWNER(this); + DebugAssert(!IsRecording()); + std::pair<CachedDepthStates::iterator, bool> added = m_CachedDepthStates.insert(std::make_pair(state, ClientDeviceDepthState(state))); + ClientDeviceDepthState* result = &added.first->second; + if (!added.second) + return result; + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateDepthState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + result->internalState = m_DepthStateMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientDeviceDepthState>(*result); +#else + m_CommandQueue->WriteValueType<ClientDeviceDepthState*>(result); +#endif + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + result->internalState = m_RealDevice->CreateDepthState(state); +#endif + return result; +} + +DeviceStencilState* GfxDeviceClient::CreateStencilState(const GfxStencilState& state) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + SET_ALLOC_OWNER(this); + std::pair<CachedStencilStates::iterator, bool> added = m_CachedStencilStates.insert(std::make_pair(state, ClientDeviceStencilState(state))); + ClientDeviceStencilState* result = &added.first->second; + if (!added.second) + return result; + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateStencilState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + result->internalState = m_StencilStateMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientDeviceStencilState>(*result); +#else + m_CommandQueue->WriteValueType<ClientDeviceStencilState*>(result); +#endif + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + result->internalState = m_RealDevice->CreateStencilState(state); +#endif + return result; +} + +DeviceRasterState* GfxDeviceClient::CreateRasterState(const GfxRasterState& state) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + SET_ALLOC_OWNER(this); + std::pair<CachedRasterStates::iterator, bool> added = m_CachedRasterStates.insert(std::make_pair(state, ClientDeviceRasterState(state))); + ClientDeviceRasterState* result = &added.first->second; + if (!added.second) + return result; + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateRasterState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + result->internalState = m_RasterStateMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientDeviceRasterState>(*result); +#else + m_CommandQueue->WriteValueType<ClientDeviceRasterState*>(result); +#endif + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + result->internalState = m_RealDevice->CreateRasterState(state); +#endif + + return result; +} + +void GfxDeviceClient::RecordSetBlendState(const DeviceBlendState* state, const ShaderLab::FloatVal& alphaRef, const ShaderLab::PropertySheet* props) +{ + CheckMainThread(); + DebugAssert(IsRecording()); + const ClientDeviceBlendState* clientState = static_cast<const ClientDeviceBlendState*>(state); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetBlendState); + m_CommandQueue->WriteValueType<const ClientDeviceBlendState*>(clientState); + float* dest = m_CommandQueue->GetWritePointer<float>(); + // Must call GetBuffer() after GetWritePointer() since it might be reallocated! + const void* bufferStart = m_CommandQueue->GetBuffer(); + m_CurrentContext->patchInfo.AddPatchableFloat(alphaRef, *dest, bufferStart, props); + GFXDEVICE_LOCKSTEP_CLIENT(); +} + +void GfxDeviceClient::SetBlendState(const DeviceBlendState* state, float alphaRef) +{ + CheckMainThread(); + const ClientDeviceBlendState* clientState = static_cast<const ClientDeviceBlendState*>(state); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetBlendState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<const ClientDeviceBlendState>(*clientState); +#else + m_CommandQueue->WriteValueType<const ClientDeviceBlendState*>(clientState); +#endif + m_CommandQueue->WriteValueType<float>(alphaRef); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + m_RealDevice->SetBlendState(clientState->internalState, alphaRef); +#endif +} + +void GfxDeviceClient::SetDepthState(const DeviceDepthState* state) +{ + CheckMainThread(); + const ClientDeviceDepthState* clientState = static_cast<const ClientDeviceDepthState*>(state); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetDepthState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<const ClientDeviceDepthState>(*clientState); +#else + m_CommandQueue->WriteValueType<const ClientDeviceDepthState*>(clientState); +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + m_RealDevice->SetDepthState(clientState->internalState); +#endif +} + +void GfxDeviceClient::SetStencilState(const DeviceStencilState* state, int stencilRef) +{ + CheckMainThread(); + const ClientDeviceStencilState* clientState = static_cast<const ClientDeviceStencilState*>(state); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetStencilState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<const ClientDeviceStencilState>(*clientState); +#else + m_CommandQueue->WriteValueType<const ClientDeviceStencilState*>(clientState); +#endif + m_CommandQueue->WriteValueType<int>(stencilRef); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + m_RealDevice->SetStencilState(clientState->internalState, stencilRef); +#endif +} + +#if UNITY_XENON +void GfxDeviceClient::SetNullPixelShader() +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetNullPixelShader); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetNullPixelShader(); +} + +void GfxDeviceClient::SetHiZEnable( const HiZstate hiz ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EnableHiZ); + m_CommandQueue->WriteValueType<HiZstate>( hiz ); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetHiZEnable( hiz ); +} + +void GfxDeviceClient::SetHiStencilState( const bool hiStencilEnable, const bool hiStencilWriteEnable, const int hiStencilRef, const CompareFunction cmpFunc ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetHiStencilState); + m_CommandQueue->WriteValueType<bool>(hiStencilEnable); + m_CommandQueue->WriteValueType<bool>(hiStencilWriteEnable); + m_CommandQueue->WriteValueType<int>(hiStencilRef); + m_CommandQueue->WriteValueType<CompareFunction>(cmpFunc); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetHiStencilState( hiStencilEnable, hiStencilWriteEnable, hiStencilRef, cmpFunc ); +} + +void GfxDeviceClient::HiStencilFlush( const HiSflush flushtype ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_HiStencilFlush); + m_CommandQueue->WriteValueType<HiSflush>(flushtype); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->HiStencilFlush(flushtype); +} +#endif + +void GfxDeviceClient::SetRasterState(const DeviceRasterState* state) +{ + CheckMainThread(); + const ClientDeviceRasterState* clientState = static_cast<const ClientDeviceRasterState*>(state); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetRasterState); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<const ClientDeviceRasterState>(*clientState); +#else + m_CommandQueue->WriteValueType<const ClientDeviceRasterState*>(clientState); +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + m_RealDevice->SetRasterState(clientState->internalState); +#endif +} + +void GfxDeviceClient::SetSRGBWrite (bool enable) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_sRGBWrite = enable; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetSRGBState); + m_CommandQueue->WriteValueType<GfxCmdBool>(enable); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetSRGBWrite(enable); +} + +bool GfxDeviceClient::GetSRGBWrite () +{ + CheckMainThread(); + return m_sRGBWrite; +} + +void GfxDeviceClient::SetWorldMatrix( const float matrix[16] ) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_TransformState.dirtyFlags |= TransformState::kWorldDirty; + memcpy(m_TransformState.worldMatrix.GetPtr(), matrix, 16 * sizeof(float)); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetWorldMatrix); + m_CommandQueue->WriteValueType<Matrix4x4f>(m_TransformState.worldMatrix); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetWorldMatrix(matrix); +} + +void GfxDeviceClient::SetViewMatrix( const float matrix[16] ) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_TransformState.SetViewMatrix (matrix, m_BuiltinParamValues); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetViewMatrix); + m_CommandQueue->WriteValueType<Matrix4x4f>(m_BuiltinParamValues.GetMatrixParam(kShaderMatView)); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetViewMatrix(matrix); +} + +void GfxDeviceClient::SetProjectionMatrix (const Matrix4x4f& matrix) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_TransformState.dirtyFlags |= TransformState::kProjDirty; + Matrix4x4f& m = m_BuiltinParamValues.GetWritableMatrixParam(kShaderMatProj); + CopyMatrix (matrix.GetPtr(), m.GetPtr()); + CopyMatrix (matrix.GetPtr(), m_TransformState.projectionMatrixOriginal.GetPtr()); + CalculateDeviceProjectionMatrix (m, m_UsesOpenGLTextureCoords, m_InvertProjectionMatrix); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetProjectionMatrix); + m_CommandQueue->WriteValueType<Matrix4x4f>(matrix); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetProjectionMatrix(matrix); +} + +void GfxDeviceClient::GetMatrix( float outMatrix[16] ) const +{ + m_TransformState.UpdateWorldViewMatrix(m_BuiltinParamValues); + memcpy(outMatrix, m_TransformState.worldViewMatrix.GetPtr(), 16 * sizeof(float)); +} + +const float* GfxDeviceClient::GetWorldMatrix() const +{ + return m_TransformState.worldMatrix.GetPtr(); +} + +const float* GfxDeviceClient::GetViewMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatView).GetPtr(); +} + +const float* GfxDeviceClient::GetProjectionMatrix() const +{ + return m_TransformState.projectionMatrixOriginal.GetPtr(); +} + +const float* GfxDeviceClient::GetDeviceProjectionMatrix() const +{ + return m_BuiltinParamValues.GetMatrixParam(kShaderMatProj).GetPtr(); +} + +void GfxDeviceClient::SetInverseScale( float invScale ) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + GfxDevice::SetInverseScale(invScale); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetInverseScale); + m_CommandQueue->WriteValueType<float>(invScale); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetInverseScale(invScale); +} + +void GfxDeviceClient::SetNormalizationBackface( NormalizationMode mode, bool backface ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetNormalizationBackface); + GfxCmdSetNormalizationBackface data = { mode, backface}; + m_CommandQueue->WriteValueType<GfxCmdSetNormalizationBackface>(data); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetNormalizationBackface(mode, backface); +} + +void GfxDeviceClient::SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetFFLighting); + GfxCmdSetFFLighting data = { on, separateSpecular, colorMaterial }; + m_CommandQueue->WriteValueType<GfxCmdSetFFLighting>(data); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetFFLighting(on, separateSpecular, colorMaterial); +} + +void GfxDeviceClient::RecordSetMaterial( const ShaderLab::VectorVal& ambient, const ShaderLab::VectorVal& diffuse, const ShaderLab::VectorVal& specular, const ShaderLab::VectorVal& emissive, const ShaderLab::FloatVal& shininess, const ShaderLab::PropertySheet* props ) +{ + CheckMainThread(); + DebugAssert(IsRecording()); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetMaterial); + GfxMaterialParams* dest = m_CommandQueue->GetWritePointer<GfxMaterialParams>(); + // Must call GetBuffer() after GetWritePointer() since it might be reallocated! + const void* bufferStart = m_CommandQueue->GetBuffer(); + GfxPatchInfo& patchInfo = m_CurrentContext->patchInfo; + patchInfo.AddPatchableVector(ambient, dest->ambient, bufferStart, props); + patchInfo.AddPatchableVector(diffuse, dest->diffuse, bufferStart, props); + patchInfo.AddPatchableVector(specular, dest->specular, bufferStart, props); + patchInfo.AddPatchableVector(emissive, dest->emissive, bufferStart, props); + patchInfo.AddPatchableFloat(shininess, dest->shininess, bufferStart, props); + GFXDEVICE_LOCKSTEP_CLIENT(); +} + +void GfxDeviceClient::SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetMaterial); + GfxMaterialParams mat = { Vector4f(ambient), Vector4f(diffuse), Vector4f(specular), Vector4f(emissive), shininess }; + m_CommandQueue->WriteValueType<GfxMaterialParams>(mat); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetMaterial(ambient, diffuse, specular, emissive, shininess); +} + +void GfxDeviceClient::RecordSetColor( const ShaderLab::VectorVal& color, const ShaderLab::PropertySheet* props ) +{ + CheckMainThread(); + DebugAssert(IsRecording()); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetColor); + Vector4f* dest = m_CommandQueue->GetWritePointer<Vector4f>(); + // Must call GetBuffer() after GetWritePointer() since it might be reallocated! + const void* bufferStart = m_CommandQueue->GetBuffer(); + m_CurrentContext->patchInfo.AddPatchableVector(color, *dest, bufferStart, props); + GFXDEVICE_LOCKSTEP_CLIENT(); +} + +void GfxDeviceClient::SetColor( const float color[4] ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetColor); + m_CommandQueue->WriteValueType<Vector4f>(Vector4f(color)); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetColor(color); +} + +void GfxDeviceClient::SetViewport( int x, int y, int width, int height ) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_Viewport.x = x; + m_Viewport.y = y; + m_Viewport.width = width; + m_Viewport.height = height; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetViewport); + m_CommandQueue->WriteValueType<ClientDeviceRect>(m_Viewport); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetViewport(x, y, width, height); +} + +void GfxDeviceClient::GetViewport( int* values ) const +{ + values[0] = m_Viewport.x; + values[1] = m_Viewport.y; + values[2] = m_Viewport.width; + values[3] = m_Viewport.height; +} + +void GfxDeviceClient::SetScissorRect( int x, int y, int width, int height ) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_ScissorRect.x = x; + m_ScissorRect.y = y; + m_ScissorRect.width = width; + m_ScissorRect.height = height; + m_ScissorEnabled = 1; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetScissorRect); + m_CommandQueue->WriteValueType<ClientDeviceRect>(m_ScissorRect); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetScissorRect(x, y, width, height); +} + +void GfxDeviceClient::DisableScissor() +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + m_ScissorEnabled = 0; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DisableScissor); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DisableScissor(); +} + +bool GfxDeviceClient::IsScissorEnabled() const +{ + return m_ScissorEnabled == 1; +} + +void GfxDeviceClient::GetScissorRect( int values[4] ) const +{ + values[0] = m_ScissorRect.x; + values[1] = m_ScissorRect.y; + values[2] = m_ScissorRect.width; + values[3] = m_ScissorRect.height; +} + +TextureCombinersHandle GfxDeviceClient::CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ) +{ + SET_ALLOC_OWNER(NULL); // Not set to this since these are leaked. Some shaders are created staticly and are not cleaned up. + CheckMainThread(); + + if (count > gGraphicsCaps.maxTexUnits) + return TextureCombinersHandle( NULL ); + +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + for (int i = 0; i < count; i++) + if (!m_RealDevice->IsCombineModeSupported( texEnvs[i].m_CombColor )) + return TextureCombinersHandle( NULL ); + + // check texgen modes & texture dimension are supported + for (int i = 0; i < count; i++) + { + TextureDimension texDim; + TexGenMode texGen; + ShaderLab::shaderprops::GetTexEnvInfo( props, texEnvs[i].m_TextureName, texDim, texGen ); + if (!ShaderLab::IsTexEnvSupported( texEnvs[i].m_TextureName, texDim, texGen )) + return TextureCombinersHandle( NULL ); + } +#endif + + ClientDeviceTextureCombiners* combiners = UNITY_NEW(ClientDeviceTextureCombiners, kMemGfxThread); + combiners->bindings = (ShaderLab::TextureBinding*)UNITY_MALLOC(kMemGfxThread,sizeof(ShaderLab::TextureBinding)*count); + for(int i = 0; i < count; i++) new ((void*)(&combiners->bindings[i])) ShaderLab::TextureBinding; + combiners->count = count; + for (int i = 0; i < count; i++) + combiners->bindings[i] = texEnvs[i]; + + if (m_Serialize) + { + // Don't want to create texture combiners from a display list + m_CurrentContext->recordFailed = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateTextureCombiners); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + combiners->internalHandle = m_TextureCombinerMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientIDMapper::ClientID>(combiners->internalHandle); + m_CommandQueue->WriteValueType<int>(combiners->count); + for (int i = 0; i < count; i++) + m_CommandQueue->WriteValueType<ShaderLab::TextureBinding>(combiners->bindings[i]); +#else + m_CommandQueue->WriteValueType<ClientDeviceTextureCombiners*>(combiners); +#endif + GfxCmdCreateTextureCombiners texcomb = { count, hasVertexColorOrLighting, usesAddSpecular }; + m_CommandQueue->WriteValueType<GfxCmdCreateTextureCombiners>(texcomb); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + combiners->internalHandle = m_RealDevice->CreateTextureCombiners(count, texEnvs, props, hasVertexColorOrLighting, usesAddSpecular); +#endif + + return TextureCombinersHandle( combiners ); +} +void GfxDeviceClient::DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ) +{ + CheckMainThread(); + if (!textureCombiners.IsValid()) + return; + + ClientDeviceTextureCombiners* combiners = static_cast<ClientDeviceTextureCombiners*>(textureCombiners.object); + + if (m_Serialize) + { + // Must delete when message received + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DeleteTextureCombiners); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<ClientIDMapper::ClientID>(combiners->internalHandle); + m_CommandQueue->WriteValueType<int>(combiners->count); + delete[] combiners->bindings; + delete combiners; +#else + m_CommandQueue->WriteValueType<ClientDeviceTextureCombiners*>(combiners); + textureCombiners.Reset(); +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + + for(int i = 0; i < combiners->count; i++) (&combiners->bindings[i])->~TextureBinding(); + UNITY_FREE(kMemGfxThread, combiners->bindings); + UNITY_DELETE(combiners,kMemGfxThread); + } +} + +void GfxDeviceClient::SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ) +{ + CheckMainThread(); + if (!textureCombiners.IsValid()) + return; + + ClientDeviceTextureCombiners* combiners = static_cast<ClientDeviceTextureCombiners*>(textureCombiners.object); + +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + for(int i = 0, n = combiners->count ; i < n ; ++i) + SetTexGen(i, GetTexEnvForBinding(combiners->bindings[i], props)->GetTexGen()); + for(int i = combiners->count ; i < kMaxSupportedTextureUnitsGLES ; ++i) + DropTexGen(i); +#endif + + if (m_Serialize) + { + int count = combiners->count; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetTextureCombiners); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<ClientIDMapper::ClientID>(combiners->internalHandle); + m_CommandQueue->WriteValueType<int>(combiners->count); +#else + m_CommandQueue->WriteValueType<ClientDeviceTextureCombiners*>(combiners); +#endif + void* data = m_CommandQueue->GetWriteDataPointer(count * sizeof(TexEnvData), ALIGN_OF(TexEnvData)); + // Must call GetBuffer() after GetWriteDataPointer() since it might be reallocated! + const UInt8* bufferStart = IsRecording() ? static_cast<const UInt8*>(m_CommandQueue->GetBuffer()) : NULL; + TexEnvData* dest = static_cast<TexEnvData*>(data); + for (int i = 0; i < count; i++) + { + using namespace ShaderLab::shaderprops; + ShaderLab::TextureBinding& binding = combiners->bindings[i]; + if (IsRecording()) + { + if (!m_CurrentContext->patchInfo.AddPatchableTexEnv(binding.m_TextureName, binding.m_MatrixName, + kTexDimAny, &dest[i], bufferStart, props)) + m_CurrentContext->recordFailed = true; + } + else + { + ShaderLab::TexEnv* te = GetTexEnvForBinding(binding, props); + Assert(te != NULL); + te->PrepareData(binding.m_TextureName.index, binding.m_MatrixName, props, &dest[i]); + } + } + data = m_CommandQueue->GetWriteDataPointer(count * sizeof(Vector4f), ALIGN_OF(Vector4f)); + Vector4f* texColors = static_cast<Vector4f*>(data); + for (int i = 0; i < count; i++) + { + const ShaderLab::TextureBinding& binding = combiners->bindings[i]; + texColors[i] = binding.GetTexColor().Get (props); + } + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + m_RealDevice->SetTextureCombiners(combiners->internalHandle, props); +#endif +} + +void GfxDeviceClient::SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias) +{ + CheckMainThread(); + DebugAssert( dim >= kTexDim2D && dim <= kTexDimCUBE ); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetTexture); + GfxCmdSetTexture tex = {shaderType, unit, samplerUnit, texture, dim, bias}; + m_CommandQueue->WriteValueType<GfxCmdSetTexture>(tex); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetTexture (shaderType, unit, samplerUnit, texture, dim, bias); +} + +void GfxDeviceClient::SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetTextureParams); + GfxCmdSetTextureParams params = { texture, texDim, filter, wrap, anisoLevel, hasMipMap, colorSpace }; + m_CommandQueue->WriteValueType<GfxCmdSetTextureParams>(params); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetTextureParams(texture, texDim, filter, wrap, anisoLevel, hasMipMap, colorSpace); +} + +void GfxDeviceClient::SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]) +{ + CheckMainThread(); + +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + SetTexGen(unit, texGen); +#endif + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetTextureTransform); + GfxCmdSetTextureTransform trans = { unit, dim, texGen, identity, Matrix4x4f(matrix) }; + m_CommandQueue->WriteValueType<GfxCmdSetTextureTransform>(trans); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetTextureTransform(unit, dim, texGen, identity, matrix); +} + +void GfxDeviceClient::SetTextureName( TextureID texture, char const* name ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetTextureName); + GfxCmdSetTextureName texName = { texture, strlen(name)+1 }; + m_CommandQueue->WriteValueType<GfxCmdSetTextureName>(texName); + m_CommandQueue->WriteArrayType<char>(name, strlen(name)+1); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetTextureName( texture, name ); +} + +void GfxDeviceClient::SetMaterialProperties( const MaterialPropertyBlock& block ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetMaterialProperties); + int propertyCount = block.GetPropertiesEnd() - block.GetPropertiesBegin(); + int bufferSize = block.GetBufferEnd() - block.GetBufferBegin(); + typedef MaterialPropertyBlock::Property Property; + GfxCmdSetMaterialProperties matprops = { propertyCount, bufferSize }; + m_CommandQueue->WriteValueType<GfxCmdSetMaterialProperties>(matprops); + m_CommandQueue->WriteArrayType<Property>(block.GetPropertiesBegin(), propertyCount); + m_CommandQueue->WriteArrayType<float>(block.GetBufferBegin(), bufferSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetMaterialProperties(block); +} + +GpuProgram* GfxDeviceClient::CreateGpuProgram( const std::string& source, CreateGpuProgramOutput& output ) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateGpuProgram); + GpuProgram* result = NULL; + //GfxCmdCreateGpuProgram gpuprog = { parent, source.c_str(), outErrors, &result }; + //m_CommandQueue->WriteValueType<GfxCmdCreateGpuProgram>(gpuprog); + //SubmitCommands(); + //WaitForSignal(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdCreateGpuProgram gpuprog = { source.c_str(), &output, &result }; + m_CommandQueue->WriteValueType<GfxCmdCreateGpuProgram>(gpuprog); + SubmitCommands(); + m_DeviceWorker->WaitForSignal(); +#else + size_t len = source.length(); + m_CommandQueue->WriteValueType<UInt32>(len); + m_CommandQueue->WriteArrayType<char>(source.c_str(), len + 1); + SubmitCommands(); + ReadbackData(m_ReadbackData); + const GfxRet_CreateGpuProgram* returnData = reinterpret_cast<GfxRet_CreateGpuProgram*>(m_ReadbackData.data()); + returnData->GetOutput(output); + result = (GpuProgram*)returnData->gpuProgram; +#endif + UnityMemoryBarrier(); + GFXDEVICE_LOCKSTEP_CLIENT(); + return result; + } + else + return m_RealDevice->CreateGpuProgram(source, output); +} + +void GfxDeviceClient::SetShadersMainThread( ShaderLab::SubProgram* programs[kShaderTypeCount], const ShaderLab::PropertySheet* props ) +{ + CheckMainThread(); + + FogMode fogMode = m_FogParams.mode; + DisplayListContext& context = *m_CurrentContext; + for (int pt = 0; pt < kShaderTypeCount; ++pt) + context.shadersActive[pt] = false; + + // Fill in arrays of GPU programs, parameters and buffer sizes + GfxCmdSetShaders shadersCmd; + for (int pt = 0; pt < kShaderTypeCount; ++pt) + { + if (!programs[pt]) + { + shadersCmd.programs[pt] = NULL; + shadersCmd.params[pt] = NULL; + shadersCmd.paramsBufferSize[pt] = 0; + continue; + } + GpuProgram& gpuProg = programs[pt]->GetGpuProgram(); + GpuProgramParameters& params = programs[pt]->GetParams(fogMode); + shadersCmd.programs[pt] = (ClientIDWrapper(GpuProgram))&gpuProg; +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + shadersCmd.params[pt] = ¶ms; +#else + if (!params.m_InternalHandle) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetGpuProgramParameters); + params.m_InternalHandle = m_GpuProgramParametersMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientIDMapper::ClientID>(params.m_InternalHandle); + dynamic_array<UInt8> outBuf; + dynamic_array<char> strBuf; + Gfx_GpuProgramParameters gfxParams (params, outBuf, strBuf); + m_CommandQueue->WriteValueType<Gfx_GpuProgramParameters>(gfxParams); + + int outSize = outBuf.size(); + m_CommandQueue->WriteValueType<UInt32>(outSize); + m_CommandQueue->WriteValueType<UInt32>(strBuf.size()); + outBuf.resize_uninitialized(outSize + strBuf.size()); + std::copy(strBuf.begin(), strBuf.end(), outBuf.begin()+outSize); + void* buffer = m_CommandQueue->GetWriteDataPointer(outBuf.size(), 1); + memcpy (buffer, outBuf.begin(), outBuf.size()); + } + shadersCmd.params[pt] = params.m_InternalHandle; +#endif + if (!params.IsReady()) + { + CreateShaderParameters (programs[pt], fogMode); + params.MakeReady(); + } + shadersCmd.paramsBufferSize[pt] = params.GetValuesSize(); + ShaderImplType implType = programs[pt]->GetGpuProgram().GetImplType(); + context.shadersActive[pt] = implType == pt; + + // GLSL case, where a single vertex shader SubProgram can encompass multiple stages + if (implType == kShaderImplBoth) + { + context.shadersActive[kShaderVertex] |= true; + context.shadersActive[kShaderFragment] |= true; + } + } + + context.hasSetShaders = true; + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetShaders); + m_CommandQueue->WriteValueType<GfxCmdSetShaders>(shadersCmd); + for (int pt = 0; pt < kShaderTypeCount; ++pt) + { + int bufferSize = shadersCmd.paramsBufferSize[pt]; + if (bufferSize <= 0) + continue; + + void* buffer = m_CommandQueue->GetWriteDataPointer(bufferSize, 1); + UInt8* dest = static_cast<UInt8*>(buffer); + + // Must call GetBuffer() after GetWriteDataPointer() since it might be reallocated! + const UInt8* bufferStart = IsRecording() ? static_cast<const UInt8*>(m_CommandQueue->GetBuffer()) : NULL; + GfxPatchInfo* patchInfo = IsRecording() ? &context.patchInfo : NULL; + programs[pt]->GetParams(fogMode).PrepareValues(props, dest, bufferStart, patchInfo, &context.recordFailed); + } + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + GraphicsHelper::SetShaders(*m_RealDevice, programs, props); +} + +void GfxDeviceClient::CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ) +{ + CheckMainThread(); + if (m_Threaded) + { + // Get main command queue even when recording + ThreadedStreamBuffer& stream = m_DisplayListStack[0].commandQueue; + stream.WriteValueType<GfxCommand>(kGfxCmd_CreateShaderParameters); + GfxCmdCreateShaderParameters params = { program, fogMode }; + stream.WriteValueType<GfxCmdCreateShaderParameters>(params); + stream.WriteSubmitData(); + WaitForSignal(); +#if DEBUG_GFXDEVICE_LOCKSTEP + // Lockstep even if recording + GetGfxDeviceWorker()->LockstepWait(); +#endif + } + else + { + m_RealDevice->CreateShaderParameters(program, fogMode); + } +} + +bool GfxDeviceClient::IsShaderActive( ShaderType type ) const +{ + return m_CurrentContext->shadersActive[type]; +} + +void GfxDeviceClient::DestroySubProgram( ShaderLab::SubProgram* subprogram ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DestroySubProgram); + m_CommandQueue->WriteValueType<ShaderLab::SubProgram*>(subprogram); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DestroySubProgram(subprogram); +} + +void GfxDeviceClient::SetConstantBufferInfo (int id, int size) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetConstantBufferInfo); + m_CommandQueue->WriteValueType<int>(id); + m_CommandQueue->WriteValueType<int>(size); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetConstantBufferInfo (id, size); +} + +void GfxDeviceClient::DisableLights( int startLight ) +{ + CheckMainThread(); + const Vector4f black(0.0F, 0.0F, 0.0F, 0.0F); + for (int i = startLight; i < kMaxSupportedVertexLights; ++i) + { + m_BuiltinParamValues.SetVectorParam(BuiltinShaderVectorParam(kShaderVecLight0Diffuse + i), black); + } + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DisableLights); + m_CommandQueue->WriteValueType<int>(startLight); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DisableLights(startLight); +} + +void GfxDeviceClient::SetLight( int light, const GfxVertexLight& data) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + + if (light >= kMaxSupportedVertexLights) + return; + + SetupVertexLightParams (light, data); + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetLight); + m_CommandQueue->WriteValueType<int>(light); + m_CommandQueue->WriteValueType<GfxVertexLight>(data); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetLight(light, data); +} + +void GfxDeviceClient::SetAmbient( const float ambient[4] ) +{ + CheckMainThread(); + m_BuiltinParamValues.SetVectorParam(kShaderVecLightModelAmbient, Vector4f(ambient)); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetAmbient); + m_CommandQueue->WriteValueType<Vector4f>(Vector4f(ambient)); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetAmbient(ambient); +} + +void GfxDeviceClient::RecordEnableFog( FogMode fogMode, const ShaderLab::FloatVal& fogStart, const ShaderLab::FloatVal& fogEnd, const ShaderLab::FloatVal& fogDensity, const ShaderLab::VectorVal& fogColor, const ShaderLab::PropertySheet* props ) +{ + CheckMainThread(); + DebugAssert(IsRecording()); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EnableFog); + m_CurrentContext->fogParamsOffset = m_CommandQueue->GetCurrentSize(); + GfxFogParams* fog = m_CommandQueue->GetWritePointer<GfxFogParams>(); + fog->mode = fogMode; + + // Must call GetBuffer() after GetWritePointer() since it might be reallocated! + const void* bufferStart = m_CommandQueue->GetBuffer(); + GfxPatchInfo& patchInfo = m_CurrentContext->patchInfo; + patchInfo.AddPatchableVector(fogColor, fog->color, bufferStart, props); + patchInfo.AddPatchableFloat(fogStart, fog->start, bufferStart, props); + patchInfo.AddPatchableFloat(fogEnd, fog->end, bufferStart, props); + patchInfo.AddPatchableFloat(fogDensity, fog->density, bufferStart, props); + m_FogParams = *fog; + GFXDEVICE_LOCKSTEP_CLIENT(); +} + +void GfxDeviceClient::EnableFog (const GfxFogParams& fog) +{ + CheckMainThread(); + m_FogParams = fog; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EnableFog); + if (IsRecording()) + m_CurrentContext->fogParamsOffset = m_CommandQueue->GetCurrentSize(); + m_CommandQueue->WriteValueType<GfxFogParams>(fog); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EnableFog(fog); +} + +void GfxDeviceClient::DisableFog() +{ + CheckMainThread(); + m_FogParams.mode = kFogDisabled; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DisableFog); + if (IsRecording()) + m_CurrentContext->fogParamsOffset = DisplayListContext::kFogParamsDisable; + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DisableFog(); +} + +VBO* GfxDeviceClient::CreateVBO() +{ + CheckMainThread(); + Assert(!IsRecording()); + VBO* vbo = new ThreadedVBO(*this); + OnCreateVBO(vbo); + return vbo; +} + +void GfxDeviceClient::DeleteVBO( VBO* vbo ) +{ + CheckMainThread(); + Assert(!IsRecording()); + OnDeleteVBO(vbo); + delete vbo; +} + +DynamicVBO& GfxDeviceClient::GetDynamicVBO() +{ + CheckMainThread(); + if (!m_DynamicVBO) + { + Assert(!m_Threaded); + return m_RealDevice->GetDynamicVBO(); + } + return *m_DynamicVBO; +} + +void GfxDeviceClient::BeginSkinning( int maxSkinCount ) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginSkinning); + m_CommandQueue->WriteValueType<int>(maxSkinCount); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + // Call this even when threaded + GfxDevice::BeginSkinning(maxSkinCount); +} + +bool GfxDeviceClient::SkinMesh( const SkinMeshInfo& skin, VBO* vbo ) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + // Only skin on render thread if buffer is not read back + if (m_Threaded && skin.outVertices == NULL) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SkinMesh); + m_CommandQueue->WriteValueType<SkinMeshInfo>(skin); + ThreadedVBO* threadedVBO = static_cast<ThreadedVBO*>(vbo); + m_CommandQueue->WriteValueType<ClientDeviceVBO*>(threadedVBO->GetClientDeviceVBO()); + m_CommandQueue->WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); + return true; + } + else +#endif + return GfxDevice::SkinMesh(skin, vbo); +} + +void GfxDeviceClient::EndSkinning() +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndSkinning); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + // Call this even when threaded + GfxDevice::EndSkinning(); +} + +#if GFX_ENABLE_DRAW_CALL_BATCHING +void GfxDeviceClient::BeginStaticBatching(const ChannelAssigns& channels, GfxPrimitiveType topology) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginStaticBatching); + GfxCmdBeginStaticBatching statbat = { channels, topology }; + m_CommandQueue->WriteValueType<GfxCmdBeginStaticBatching>(statbat); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->BeginStaticBatching(channels, topology); +} + +void GfxDeviceClient::StaticBatchMesh( UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_StaticBatchMesh); + GfxCmdStaticBatchMesh batch = { firstVertex, vertexCount, indices, firstIndexByte, indexCount }; + m_CommandQueue->WriteValueType<GfxCmdStaticBatchMesh>(batch); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->StaticBatchMesh(firstVertex, vertexCount, indices, firstIndexByte, indexCount); +} + +void GfxDeviceClient::EndStaticBatching( VBO& vbo, const Matrix4x4f& matrix, TransformType transformType, int sourceChannels ) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndStaticBatching); + ThreadedVBO& threadedVBO = static_cast<ThreadedVBO&>(vbo); + ClientDeviceVBO* clientVBO = threadedVBO.GetClientDeviceVBO(); + GfxCmdEndStaticBatching endbat = { clientVBO, matrix, transformType, sourceChannels }; + m_CommandQueue->WriteValueType<GfxCmdEndStaticBatching>(endbat); + m_CommandQueue->WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EndStaticBatching(vbo, matrix, transformType, sourceChannels); +} + +void GfxDeviceClient::BeginDynamicBatching( const ChannelAssigns& shaderChannels, UInt32 channelsInVBO, size_t maxVertices, size_t maxIndices, GfxPrimitiveType topology) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginDynamicBatching); + GfxCmdBeginDynamicBatching dynbat = { shaderChannels, channelsInVBO, maxVertices, maxIndices, topology }; + m_CommandQueue->WriteValueType<GfxCmdBeginDynamicBatching>(dynbat); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->BeginDynamicBatching(shaderChannels, channelsInVBO, maxVertices, maxIndices, topology); +} + +void GfxDeviceClient::DynamicBatchMesh( const Matrix4x4f& matrix, const VertexBufferData& vertices, UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DynamicBatchMesh); + GfxCmdDynamicBatchMesh batch = { matrix, vertices, firstVertex, vertexCount, indices, firstIndexByte, indexCount }; + m_CommandQueue->WriteValueType<GfxCmdDynamicBatchMesh>(batch); + m_CommandQueue->WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DynamicBatchMesh(matrix, vertices, firstVertex, vertexCount, indices, firstIndexByte, indexCount); + +} +#if ENABLE_SPRITES +void GfxDeviceClient::DynamicBatchSprite(const Matrix4x4f* matrix, const SpriteRenderData* rd, ColorRGBA32 color) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DynamicBatchSprite); + GfxCmdDynamicBatchSprite batch = { *matrix, rd, color }; + m_CommandQueue->WriteValueType<GfxCmdDynamicBatchSprite>(batch); + m_CommandQueue->WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DynamicBatchSprite(matrix, rd, color); +} +#endif +void GfxDeviceClient::EndDynamicBatching( TransformType transformType ) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndDynamicBatching); + GfxCmdEndDynamicBatching endbat = { transformType }; + m_CommandQueue->WriteValueType<GfxCmdEndDynamicBatching>(endbat); + m_CommandQueue->WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EndDynamicBatching(transformType); +} +#endif + +void GfxDeviceClient::AddBatchingStats( int batchedTris, int batchedVerts, int batchedCalls ) +{ + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_AddBatchingStats); + GfxCmdAddBatchingStats stats = { batchedTris, batchedVerts, batchedCalls }; + m_CommandQueue->WriteValueType<GfxCmdAddBatchingStats>(stats); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->AddBatchingStats(batchedTris, batchedVerts, batchedCalls); +} + + +GPUSkinningInfo* GfxDeviceClient::CreateGPUSkinningInfo() +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + SET_ALLOC_OWNER(this); + + // Call create directly. Interface spec says this is safe. + GPUSkinningInfo *realInfo = m_RealDevice->CreateGPUSkinningInfo(); + if(!realInfo) + return NULL; + return new ClientGPUSkinningInfo(realInfo); +} + +void GfxDeviceClient::DeleteGPUSkinningInfo(GPUSkinningInfo *info) +{ + CheckMainThread(); + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DeleteGPUSkinningInfo); + m_CommandQueue->WriteValueType<GPUSkinningInfo *>(((ClientGPUSkinningInfo *)info)->m_realSkinInfo); + SubmitCommands(); + delete (ClientGPUSkinningInfo *)info; + GFXDEVICE_LOCKSTEP_CLIENT(); +} + else + { + m_RealDevice->DeleteGPUSkinningInfo(((ClientGPUSkinningInfo *)info)->m_realSkinInfo); + delete (ClientGPUSkinningInfo *)info; + } + +} + +void GfxDeviceClient::SkinOnGPU(GPUSkinningInfo * info, bool lastThisFrame) +{ + CheckMainThread(); + if (m_Threaded) + { + ClientGPUSkinningInfo *ci = (ClientGPUSkinningInfo *)info; + + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SkinOnGPU); + m_CommandQueue->WriteValueType<GPUSkinningInfo *>(ci->m_realSkinInfo); + // Add the vbo object pointer to the stream, ci->m_realSkinInfo->m_destVBO will get updated in the worker. + ThreadedVBO* vbo = (ThreadedVBO*)ci->m_DestVBO; + m_CommandQueue->WriteValueType<ClientDeviceVBO *>(vbo->GetClientDeviceVBO()); + m_CommandQueue->WriteValueType<bool>(lastThisFrame); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + ClientGPUSkinningInfo *ci = (ClientGPUSkinningInfo *)info; + ThreadedVBO* vbo = (ThreadedVBO*)ci->m_DestVBO; + ci->m_realSkinInfo->SetDestVBO(vbo->GetNonThreadedVBO()); + m_RealDevice->SkinOnGPU(ci->m_realSkinInfo, lastThisFrame); + } +} + +void GfxDeviceClient::UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty) +{ + CheckMainThread(); + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UpdateSkinSourceData); + m_CommandQueue->WriteValueType<GPUSkinningInfo *>(((ClientGPUSkinningInfo *)info)->m_realSkinInfo); + m_CommandQueue->WriteValueType<const void *>(vertData); + m_CommandQueue->WriteValueType<const BoneInfluence *>(skinData); + m_CommandQueue->WriteValueType<bool>(dirty); + SubmitCommands(); + UInt32 fence = InsertCPUFence(); + WaitOnCPUFence(fence); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + m_RealDevice->UpdateSkinSourceData(((ClientGPUSkinningInfo *)info)->m_realSkinInfo, vertData, skinData, dirty); + } + +} + +void GfxDeviceClient::UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses) +{ + CheckMainThread(); + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UpdateSkinBonePoses); + m_CommandQueue->WriteValueType<GPUSkinningInfo *>(((ClientGPUSkinningInfo *)info)->m_realSkinInfo); + m_CommandQueue->WriteValueType<int>(boneCount); + m_CommandQueue->WriteArrayType<Matrix4x4f>(poses, boneCount); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + m_RealDevice->UpdateSkinBonePoses(((ClientGPUSkinningInfo *)info)->m_realSkinInfo, boneCount, poses); + } + +} + + + +#if UNITY_XENON +RawVBO* GfxDeviceClient::CreateRawVBO(UInt32 size, UInt32 flags) +{ + CheckMainThread(); + Assert(!IsRecording()); + RawVBO* vbo = new RawThreadedVBO(*this, size, flags); + return vbo; +} + +void GfxDeviceClient::DeleteRawVBO(RawVBO* vbo) +{ + CheckMainThread(); + Assert(!IsRecording()); + delete vbo; +} + + +void GfxDeviceClient::EnablePersistDisplayOnQuit(bool enabled) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EnablePersistDisplayOnQuit); + m_CommandQueue->WriteValueType<bool>(enabled); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EnablePersistDisplayOnQuit(enabled); +} + +void GfxDeviceClient::RegisterTexture2D( TextureID tid, IDirect3DBaseTexture9* texture ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_RegisterTexture2D); + m_CommandQueue->WriteValueType<TextureID>(tid); + m_CommandQueue->WriteValueType<IDirect3DBaseTexture9*>(texture); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->RegisterTexture2D(tid, texture); +} + +void GfxDeviceClient::PatchTexture2D( TextureID tid, IDirect3DBaseTexture9* texture ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_PatchTexture2D); + m_CommandQueue->WriteValueType<TextureID>(tid); + m_CommandQueue->WriteValueType<IDirect3DBaseTexture9*>(texture); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->PatchTexture2D(tid, texture); +} + +void GfxDeviceClient::DeleteTextureEntryOnly( TextureID textureID ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DeleteTextureEntryOnly); + m_CommandQueue->WriteValueType<TextureID>(textureID); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DeleteTextureEntryOnly(textureID); +} + +void GfxDeviceClient::UnbindAndDelayReleaseTexture( IDirect3DBaseTexture9* texture ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UnbindAndDelayReleaseTexture); + m_CommandQueue->WriteValueType<IDirect3DBaseTexture9*>(texture); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->UnbindAndDelayReleaseTexture(texture); +} + +void GfxDeviceClient::SetTextureWrapModes( TextureID textureID, TextureWrapMode wrapU, TextureWrapMode wrapV, TextureWrapMode wrapW ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetTextureWrapModes); + m_CommandQueue->WriteValueType<TextureID>(textureID); + m_CommandQueue->WriteValueType<TextureWrapMode>(wrapU); + m_CommandQueue->WriteValueType<TextureWrapMode>(wrapV); + m_CommandQueue->WriteValueType<TextureWrapMode>(wrapW); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetTextureWrapModes(textureID, wrapU, wrapV, wrapW); +} + +void GfxDeviceClient::OnLastFrameCallback() +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_OnLastFrameCallback); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->OnLastFrameCallback(); +} + +xenon::IVideoPlayer* GfxDeviceClient::CreateVideoPlayer(bool fullscreen) +{ + CheckMainThread(); + Assert(!IsRecording()); + xenon::VideoPlayerThreaded* vp = new xenon::VideoPlayerThreaded(*this, fullscreen); + return vp; +} + +void GfxDeviceClient::DeleteVideoPlayer(xenon::IVideoPlayer* player) +{ + CheckMainThread(); + Assert(!IsRecording()); + delete player; +} +#endif + +RenderSurfaceHandle GfxDeviceClient::CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + ClientDeviceRenderSurface* handle = new ClientDeviceRenderSurface(width, height); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateRenderColorSurface); + GfxCmdCreateRenderColorSurface create = { textureID, width, height, samples, depth, dim, format, createFlags }; +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(handle); +#else + handle->internalHandle = m_RenderSurfaceMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface>(*handle); +#endif + m_CommandQueue->WriteValueType<GfxCmdCreateRenderColorSurface>(create); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + handle->internalHandle = m_RealDevice->CreateRenderColorSurface(textureID, width, height, samples, depth, dim, format, createFlags); + } +#endif + return RenderSurfaceHandle(handle); +} + +RenderSurfaceHandle GfxDeviceClient::CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + ClientDeviceRenderSurface* handle = new ClientDeviceRenderSurface(width, height); + handle->zformat = depthFormat; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateRenderDepthSurface); + GfxCmdCreateRenderDepthSurface create = { textureID, width, height, samples, dim, depthFormat, createFlags }; +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(handle); +#else + handle->internalHandle = m_RenderSurfaceMapper.CreateID(); + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface>(*handle); +#endif + m_CommandQueue->WriteValueType<GfxCmdCreateRenderDepthSurface>(create); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + handle->internalHandle = m_RealDevice->CreateRenderDepthSurface(textureID, width, height, samples, dim, depthFormat, createFlags); + } +#endif + return RenderSurfaceHandle(handle); +} + +void GfxDeviceClient::DestroyRenderSurface (RenderSurfaceHandle& rs) +{ + CheckMainThread(); + if( !rs.IsValid() ) + return; + + ClientDeviceRenderSurface* handle = static_cast<ClientDeviceRenderSurface*>(rs.object); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DestroyRenderSurface); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(handle); +#else + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface>(*handle); +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + m_RealDevice->DestroyRenderSurface(handle->internalHandle); + delete handle; + } +#endif + rs.Reset(); +} + +void GfxDeviceClient::DiscardContents (RenderSurfaceHandle& rs) +{ + CheckMainThread(); + if( !rs.IsValid() ) + return; + + ClientDeviceRenderSurface* handle = (ClientDeviceRenderSurface*)rs.object; + handle->state = ClientDeviceRenderSurface::kInitial; // mark as "no contents" + + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DiscardContents); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(handle); +#else + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface>(*handle); +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + m_RealDevice->DiscardContents(handle->internalHandle); + } +#endif +} + +void GfxDeviceClient::SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face) +{ + CheckMainThread(); + Assert(!IsRecording()); + + BeforeRenderTargetChange(count, colorHandles, depthHandle); + for (int i = 0; i < count; ++i) + m_ActiveRenderColorSurfaces[i] = colorHandles[i]; + for (int i = count; i < kMaxSupportedRenderTargets; ++i) + m_ActiveRenderColorSurfaces[i].Reset(); + m_ActiveRenderDepthSurface = depthHandle; + AfterRenderTargetChange(); + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetRenderTarget); + GfxCmdSetRenderTarget srt; +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + srt.colorHandles[i] = m_ActiveRenderColorSurfaces[i]; + srt.depthHandle = depthHandle; +#else + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + srt.colorHandles[i] = ((ClientDeviceRenderSurface*)(m_ActiveRenderColorSurfaces[i].object))->internalHandle; + srt.depthHandle = ((ClientDeviceRenderSurface*)depthHandle.object)->internalHandle; +#endif + srt.colorCount = count; + srt.face = face; + srt.mipLevel = mipLevel; + m_CommandQueue->WriteValueType<GfxCmdSetRenderTarget>(srt); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + RenderSurfaceHandle realColorHandle[kMaxSupportedRenderTargets]; + for (int i = 0; i < count; ++i) + { + ClientDeviceRenderSurface* colorSurf = static_cast<ClientDeviceRenderSurface*>(colorHandles[i].object); + realColorHandle[i].object = colorSurf ? colorSurf->internalHandle.object : NULL; + if(!realColorHandle[i].IsValid()) + realColorHandle[i] = m_RealDevice->GetBackBufferColorSurface(); + } + ClientDeviceRenderSurface* depthSurf = static_cast<ClientDeviceRenderSurface*>(depthHandle.object); + RenderSurfaceHandle realDepthHandle(depthSurf ? depthSurf->internalHandle.object : NULL); + if(!realDepthHandle.IsValid()) + realDepthHandle = m_RealDevice->GetBackBufferDepthSurface(); + + m_RealDevice->SetRenderTargets(count, realColorHandle, realDepthHandle, mipLevel, face); + } +#endif +} + +void GfxDeviceClient::SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, UInt32 flags) +{ + CheckMainThread(); + Assert(!IsRecording()); + + BeforeRenderTargetChange(count, colorHandles, depthHandle); + for (int i = 0; i < count; ++i) + m_ActiveRenderColorSurfaces[i] = colorHandles[i]; + for (int i = count; i < kMaxSupportedRenderTargets; ++i) + m_ActiveRenderColorSurfaces[i].Reset(); + m_ActiveRenderDepthSurface = depthHandle; + AfterRenderTargetChange(); + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetRenderTargetWithFlags); + GfxCmdSetRenderTarget srt; +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + srt.colorHandles[i] = m_ActiveRenderColorSurfaces[i]; + srt.depthHandle = depthHandle; +#else + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + srt.colorHandles[i] = m_ActiveRenderColorSurfaces[i].object ? ((ClientDeviceRenderSurface*)(m_ActiveRenderColorSurfaces[i].object))->internalHandle : NULL; + srt.depthHandle = depthHandle.object ? ((ClientDeviceRenderSurface*)depthHandle.object)->internalHandle: NULL; +#endif + srt.colorCount = count; + srt.face = face; + srt.mipLevel = mipLevel; + m_CommandQueue->WriteValueType<GfxCmdSetRenderTarget>(srt); + m_CommandQueue->WriteValueType<UInt32>(flags); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + RenderSurfaceHandle realColorHandle[kMaxSupportedRenderTargets]; + for (int i = 0; i < count; ++i) + { + ClientDeviceRenderSurface* colorSurf = static_cast<ClientDeviceRenderSurface*>(colorHandles[i].object); + realColorHandle[i].object = colorSurf ? colorSurf->internalHandle.object : NULL; + if(!realColorHandle[i].IsValid()) + realColorHandle[i] = m_RealDevice->GetBackBufferColorSurface(); + } + ClientDeviceRenderSurface* depthSurf = static_cast<ClientDeviceRenderSurface*>(depthHandle.object); + RenderSurfaceHandle realDepthHandle(depthSurf ? depthSurf->internalHandle.object : NULL); + if(!realDepthHandle.IsValid()) + realDepthHandle = m_RealDevice->GetBackBufferDepthSurface(); + + m_RealDevice->SetRenderTargets (count, realColorHandle, realDepthHandle, mipLevel, face, flags); + } +#endif +} + +void GfxDeviceClient::ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle) +{ + CheckMainThread(); + ClientDeviceRenderSurface* src = static_cast<ClientDeviceRenderSurface*>(srcHandle.object); + ClientDeviceRenderSurface* dst = static_cast<ClientDeviceRenderSurface*>(dstHandle.object); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ResolveColorSurface); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(src); + m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(dst); +#else +// m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(src.object ? ((ClientDeviceRenderSurface*)(src.object))->internalHandle : NULL); +// m_CommandQueue->WriteValueType<ClientDeviceRenderSurface*>(dst.object ? ((ClientDeviceRenderSurface*)(dst.object))->internalHandle : NULL); + //todo. +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + m_RealDevice->ResolveColorSurface (src->internalHandle, dst->internalHandle); +#endif +} + +void GfxDeviceClient::ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle) +{ + CheckMainThread(); + if (m_Serialize) + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdResolveDepthIntoTexture resolve = { colorHandle, depthHandle }; +#else + GfxCmdResolveDepthIntoTexture resolve = { colorHandle.object ? ((ClientDeviceRenderSurface*)(colorHandle.object))->internalHandle : NULL , depthHandle.object ? ((ClientDeviceRenderSurface*)(depthHandle.object))->internalHandle : NULL}; +#endif + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ResolveDepthIntoTexture); + m_CommandQueue->WriteValueType<GfxCmdResolveDepthIntoTexture>(resolve); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + ClientDeviceRenderSurface* colorSurf = static_cast<ClientDeviceRenderSurface*>(colorHandle.object); + ClientDeviceRenderSurface* depthSurf = static_cast<ClientDeviceRenderSurface*>(depthHandle.object); + m_RealDevice->ResolveDepthIntoTexture (colorSurf->internalHandle, depthSurf->internalHandle); + } +#endif +} + + +RenderSurfaceHandle GfxDeviceClient::GetActiveRenderColorSurface (int index) +{ + CheckMainThread(); + return m_ActiveRenderColorSurfaces[index]; +} + +RenderSurfaceHandle GfxDeviceClient::GetActiveRenderDepthSurface () +{ + CheckMainThread(); + return m_ActiveRenderDepthSurface; +} + +void GfxDeviceClient::BeforeRenderTargetChange(int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle) +{ + if (!GetFrameStats().m_StatsEnabled) + return; + + // mark any rendered-into render target surfaces as "resolved" + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + { + if (i >= count || colorHandles[i] != m_ActiveRenderColorSurfaces[i]) + { + ClientDeviceRenderSurface* colorSurf = (ClientDeviceRenderSurface*)m_ActiveRenderColorSurfaces[i].object; + if (colorSurf && colorSurf->state != ClientDeviceRenderSurface::kInitial) + colorSurf->state = ClientDeviceRenderSurface::kResolved; + } + } + + if (depthHandle != m_ActiveRenderDepthSurface) + { + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)m_ActiveRenderDepthSurface.object; + if (depthSurf && depthSurf->state != ClientDeviceRenderSurface::kInitial) + depthSurf->state = ClientDeviceRenderSurface::kResolved; + } +} + + +void GfxDeviceClient::AfterRenderTargetChange() +{ + if (m_ActiveRenderColorSurfaces[0].IsValid() && !m_ActiveRenderColorSurfaces[0].object->backBuffer) + { + ClientDeviceRenderSurface* colorSurf = (ClientDeviceRenderSurface*)m_ActiveRenderColorSurfaces[0].object; + if (m_ActiveRenderDepthSurface.IsValid()) + { + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)m_ActiveRenderDepthSurface.object; + if (colorSurf->width != depthSurf->width || colorSurf->height != depthSurf->height) + { + ErrorString("Dimensions of color surface does not match dimensions of depth surface"); + } + } + m_CurrentTargetWidth = colorSurf->width; + m_CurrentTargetHeight = colorSurf->height; + } + else + { +#if UNITY_WINRT + if (0 == m_CurrentWindowWidth && 0 == m_CurrentWindowHeight && NULL != m_RealDevice) + { + m_CurrentTargetWidth = m_RealDevice->GetCurrentTargetWidth(); + m_CurrentTargetHeight = m_RealDevice->GetCurrentTargetHeight(); + m_CurrentWindowWidth = m_CurrentTargetWidth; + m_CurrentWindowHeight = m_CurrentTargetHeight; + } +#endif + m_CurrentTargetWidth = m_CurrentWindowWidth; + m_CurrentTargetHeight = m_CurrentWindowHeight; + } +} + +bool GfxDeviceClient::IsRenderTargetConfigValid(UInt32 width, UInt32 height, RenderTextureFormat colorFormat, DepthBufferFormat depthFormat) +{ + CheckMainThread(); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + return GfxDevice::IsRenderTargetConfigValid(width, height, colorFormat, depthFormat); +#else + return m_RealDevice->IsRenderTargetConfigValid(width, height, colorFormat, depthFormat); +#endif +} + +void GfxDeviceClient::SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetSurfaceFlags); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdSetSurfaceFlags sf = { surf, flags, keepFlags }; +#else + GfxCmdSetSurfaceFlags sf = { surf.object ? ((ClientDeviceRenderSurface*)(surf.object))->internalHandle : NULL , flags, keepFlags }; +#endif + m_CommandQueue->WriteValueType<GfxCmdSetSurfaceFlags>(sf); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + ClientDeviceRenderSurface* surface = (ClientDeviceRenderSurface*)surf.object; + m_RealDevice->SetSurfaceFlags(surface->internalHandle, flags, keepFlags); + } +#endif +} + +void GfxDeviceClient::UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ) +{ + CheckMainThread(); + if (m_Serialize) + { + // Don't want to upload textures from a display list + m_CurrentContext->recordFailed = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UploadTexture2D); + Assert(width >= 0 && height >= 0); + GfxCmdUploadTexture2D upload = { texture, dimension, srcSize, width, height, format, mipCount, uploadFlags, skipMipLevels, usageMode, colorSpace }; + m_CommandQueue->WriteValueType<GfxCmdUploadTexture2D>(upload); + WriteBufferData(srcData, srcSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->UploadTexture2D(texture, dimension, srcData, srcSize, width, height, format, mipCount, uploadFlags, skipMipLevels, usageMode, colorSpace); +} + +void GfxDeviceClient::UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ) +{ + CheckMainThread(); + if (m_Serialize) + { + // Don't want to upload textures from a display list + m_CurrentContext->recordFailed = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UploadTextureSubData2D); + GfxCmdUploadTextureSubData2D upload = { texture, srcSize, mipLevel, x, y, width, height, format, colorSpace }; + m_CommandQueue->WriteValueType<GfxCmdUploadTextureSubData2D>(upload); + WriteBufferData(srcData, srcSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->UploadTextureSubData2D(texture, srcData, srcSize, mipLevel, x, y, width, height, format, colorSpace); +} + +void GfxDeviceClient::UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ) +{ + CheckMainThread(); + if (m_Serialize) + { + // Don't want to upload textures from a display list + m_CurrentContext->recordFailed = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UploadTextureCube); + GfxCmdUploadTextureCube upload = { texture, srcSize, faceDataSize, size, format, mipCount, uploadFlags, colorSpace }; + m_CommandQueue->WriteValueType<GfxCmdUploadTextureCube>(upload); + WriteBufferData(srcData, srcSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->UploadTextureCube(texture, srcData, srcSize, faceDataSize, size, format, mipCount, uploadFlags, colorSpace); +} + +void GfxDeviceClient::UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ) +{ + CheckMainThread(); + if (m_Serialize) + { + // Don't want to upload textures from a display list + m_CurrentContext->recordFailed = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UploadTexture3D); + GfxCmdUploadTexture3D upload = { texture, srcSize, width, height, depth, format, mipCount, uploadFlags }; + m_CommandQueue->WriteValueType<GfxCmdUploadTexture3D>(upload); + WriteBufferData(srcData, srcSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->UploadTexture3D(texture, srcData, srcSize, width, height, depth, format, mipCount, uploadFlags); +} + +void GfxDeviceClient::DeleteTexture( TextureID texture ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DeleteTexture); + m_CommandQueue->WriteValueType<TextureID>(texture); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DeleteTexture(texture); +} + +GfxDevice::PresentMode GfxDeviceClient::GetPresentMode() +{ + if (!m_Threaded) + { + // If we're not threaded don't change behavior + return m_RealDevice->GetPresentMode(); + } + if (!m_RealDevice) + return kPresentAfterDraw; + GfxDeviceRenderer renderer = m_RealDevice->GetRenderer(); + switch (renderer) + { + case kGfxRendererD3D9: + { + // In D3D9 BeginFrame() waits for the last Present() to finish on the render thread + // so we catch lost device state. It's best to present immediately after drawing. + return kPresentAfterDraw; + } + case kGfxRendererD3D11: + { + // We have to to wait for the last Present() to finish before leaving message loop, + // so it's good to present as early as possible to avoid waiting much (case 488862). + return kPresentBeforeUpdate; + } + default: + { + // By default we synchronize like with D3D9, so the render thread won't fall behind. + return kPresentAfterDraw; + } + } +} + +void GfxDeviceClient::BeginFrame() +{ + CheckMainThread(); + Assert(!m_InsideFrame); + m_InsideFrame = true; + if (m_Serialize) + { + WaitForPendingPresent(); + // Worker thread should check GetNeedsBeginFrame() + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginFrame); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->BeginFrame(); +} + +void GfxDeviceClient::EndFrame() +{ + CheckMainThread(); + if (!m_InsideFrame) + return; + m_InsideFrame = false; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndFrame); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EndFrame(); +} + +void GfxDeviceClient::PresentFrame() +{ + CheckMainThread(); + + ((ClientDeviceRenderSurface*)m_BackBufferColor.object)->state = ClientDeviceRenderSurface::kInitial; + ((ClientDeviceRenderSurface*)m_BackBufferDepth.object)->state = ClientDeviceRenderSurface::kInitial; + + if (m_Serialize) + { + // Check that we waited on event before issuing a new one + bool signalEvent = !m_PresentPending; + m_PresentPending = true; + m_PresentFrameID++; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_PresentFrame); + m_CommandQueue->WriteValueType<GfxCmdBool>(signalEvent); + m_CommandQueue->WriteValueType<UInt32>(m_PresentFrameID); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->PresentFrame(); +} + +bool GfxDeviceClient::IsValidState() +{ + CheckMainThread(); + if (!m_RealDevice) + return true; + return m_RealDevice->IsValidState(); +} + +bool GfxDeviceClient::HandleInvalidState() +{ + CheckMainThread(); + if (IsValidState()) + return true; + Assert(!IsRecording()); + +#if GFX_SUPPORTS_D3D9 + // Mark threaded dynamic VBOs as lost + ResetDynamicVBs(); +#endif +#if GFX_SUPPORTS_OPENGLES20 + // Only mark VBOs lost for GLES2.0 renderers (case 570721) + if (m_Renderer == kGfxRendererOpenGLES20Desktop || m_Renderer == kGfxRendererOpenGLES20Mobile) + MarkAllVBOsLost(); +#endif + + CommonReloadResources(kReleaseRenderTextures); + + bool insideFrame = m_InsideFrame; + if (insideFrame) + EndFrame(); + AcquireThreadOwnership(); + bool success = m_RealDevice->HandleInvalidState(); + ReleaseThreadOwnership(); + if (success && insideFrame) + BeginFrame(); + return success; +} + +void GfxDeviceClient::ResetDynamicResources() +{ + #if GFX_SUPPORTS_D3D9 + // Mark threaded dynamic VBOs as lost + ResetDynamicVBs(); + #endif + + // We should have acquired thread ownership here + Assert(!m_Serialize); + GetRealGfxDevice().ResetDynamicResources(); +} + +bool GfxDeviceClient::IsReadyToBeginFrame() +{ + if (m_Threaded && m_RealDevice->GetRenderer() == kGfxRendererD3D11) + { + // DXGI requires us to keep processing events while the render thread calls Present() + // We have to wait for that before we begin preparing the next frame (case 488862) + return m_DeviceWorker->DidPresentFrame(m_PresentFrameID); + } + return true; +} + +void GfxDeviceClient::FinishRendering() +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_FinishRendering); + SubmitCommands(); + GetGfxDeviceWorker()->WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->FinishRendering(); +} + +UInt32 GfxDeviceClient::InsertCPUFence() +{ + CheckMainThread(); + if (m_Threaded) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_InsertCPUFence); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + return ++m_CurrentCPUFence; + } + return 0; +} + +UInt32 GfxDeviceClient::GetNextCPUFence() +{ + return m_Threaded ? (m_CurrentCPUFence + 1) : 0; +} + +void GfxDeviceClient::WaitOnCPUFence(UInt32 fence) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + CheckMainThread(); + if (m_Threaded) + { + // Fence must have been already inserted + if (SInt32(fence - m_CurrentCPUFence) <= 0) + { + m_DeviceWorker->WaitOnCPUFence(fence); + } + else + ErrorString("CPU fence is invalid or very old!"); + } +#endif +} + +void GfxDeviceClient::AcquireThreadOwnership() +{ + CheckMainThread(); + if (!m_Threaded) + return; + + m_ThreadOwnershipCount++; + if (m_ThreadOwnershipCount > 1) + return; + + // Worker releases ownership + Assert(m_Serialize); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ReleaseThreadOwnership); + SubmitCommands(); + WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + + // Caller acquires ownership + m_RealDevice->AcquireThreadOwnership(); + + SetRealGfxDeviceThreadOwnership(); + + // We shouldn't serialize any commands + m_Serialize = false; +} + +void GfxDeviceClient::ReleaseThreadOwnership() +{ + CheckMainThread(); + if (!m_Threaded) + return; + + Assert(m_ThreadOwnershipCount); + m_ThreadOwnershipCount--; + if (m_ThreadOwnershipCount > 0) + return; + + // Caller releases ownership + m_RealDevice->ReleaseThreadOwnership(); + + // Worker acquires ownership + m_Serialize = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_AcquireThreadOwnership); + SubmitCommands(); + WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); +} + +void GfxDeviceClient::ImmediateVertex( float x, float y, float z ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ImmediateVertex); + GfxCmdVector3 data = {x, y, z}; + m_CommandQueue->WriteValueType<GfxCmdVector3>(data); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ImmediateVertex(x, y, z); +} + +void GfxDeviceClient::ImmediateNormal( float x, float y, float z ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ImmediateNormal); + GfxCmdVector3 data = {x, y, z}; + m_CommandQueue->WriteValueType<GfxCmdVector3>(data); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ImmediateNormal(x, y, z); +} + +void GfxDeviceClient::ImmediateColor( float r, float g, float b, float a ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ImmediateColor); + GfxCmdVector4 data = {r, g, b, a}; + m_CommandQueue->WriteValueType<GfxCmdVector4>(data); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ImmediateColor(r, g, b, a); +} + +void GfxDeviceClient::ImmediateTexCoordAll( float x, float y, float z ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ImmediateTexCoordAll); + GfxCmdVector3 data = {x, y, z}; + m_CommandQueue->WriteValueType<GfxCmdVector3>(data); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ImmediateTexCoordAll(x, y, z); +} + +void GfxDeviceClient::ImmediateTexCoord( int unit, float x, float y, float z ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ImmediateTexCoord); + GfxCmdImmediateTexCoord data = {unit, x, y, z}; + m_CommandQueue->WriteValueType<GfxCmdImmediateTexCoord>(data); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ImmediateTexCoord(unit, x, y, z); +} + +void GfxDeviceClient::ImmediateBegin( GfxPrimitiveType type ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ImmediateBegin); + m_CommandQueue->WriteValueType<GfxPrimitiveType>(type); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ImmediateBegin(type); +} + +void GfxDeviceClient::ImmediateEnd() +{ + BeforeDrawCall(true); + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ImmediateEnd); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ImmediateEnd(); +} + +bool GfxDeviceClient::BeginRecording() +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + return false; +#endif + Assert(m_RecordDepth < m_MaxCallDepth); + DisplayListContext& parentContext = *m_CurrentContext; + m_RecordDepth++; + m_IsRecording = true; + m_CurrentContext = &m_DisplayListStack[m_RecordDepth]; + memcpy(m_CurrentContext->shadersActive, parentContext.shadersActive, sizeof(parentContext.shadersActive)); + m_CurrentContext->hasSetShaders = false; + m_CommandQueue = &m_CurrentContext->commandQueue; + m_Serialize = true; + return true; +} + +bool GfxDeviceClient::EndRecording( GfxDisplayList** outDisplayList ) +{ + Assert(m_RecordDepth > 0); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DisplayList_End); + const void* data = m_CommandQueue->GetBuffer(); + size_t size = m_CommandQueue->GetCurrentSize(); + bool failed = m_CurrentContext->recordFailed; + ThreadedDisplayList* displayList = new ThreadedDisplayList(data, size, *m_CurrentContext); + m_CurrentContext->Reset(); + + m_RecordDepth--; + m_IsRecording = (m_RecordDepth != 0); + m_Serialize = m_Threaded || m_IsRecording; + m_CurrentContext = &m_DisplayListStack[m_RecordDepth]; + m_CommandQueue = &m_CurrentContext->commandQueue; + + // Execute just-recorded display list + displayList->Call(); + + if (failed) + SAFE_RELEASE(displayList); + + Assert(outDisplayList && *outDisplayList==NULL); + *outDisplayList = displayList; + return !failed; +} + +bool GfxDeviceClient::CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ) +{ + CheckMainThread(); + if (m_Serialize) + { + bool success = false; + GfxCmdCaptureScreenshot capture = { left, bottom, width, height, rgba32, &success }; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CaptureScreenshot); + m_CommandQueue->WriteValueType<GfxCmdCaptureScreenshot>(capture); + SubmitCommands(); + GetGfxDeviceWorker()->WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + return success; + } + else + return m_RealDevice->CaptureScreenshot(left, bottom, width, height, rgba32); +} + +bool GfxDeviceClient::ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ) +{ + CheckMainThread(); + if (m_Serialize) + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + bool success = false; + GfxCmdReadbackImage read = { image, left, bottom, width, height, destX, destY, &success }; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ReadbackImage); + m_CommandQueue->WriteValueType<GfxCmdReadbackImage>(read); + SubmitCommands(); + GetGfxDeviceWorker()->WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + return success; +#else + // todo. + return false; +#endif + + } + else + return m_RealDevice->ReadbackImage(image, left, bottom, width, height, destX, destY); +} + +void GfxDeviceClient::GrabIntoRenderTexture (RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height) +{ + CheckMainThread(); + if (m_Serialize) + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdGrabIntoRenderTexture grab = { rs, rd, x, y, width, height }; +#else + GfxCmdGrabIntoRenderTexture grab = { rs.object ? ((ClientDeviceRenderSurface*)(rs.object))->internalHandle : NULL , rd.object ? ((ClientDeviceRenderSurface*)(rd.object))->internalHandle : NULL , x, y, width, height }; +#endif + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_GrabIntoRenderTexture); + m_CommandQueue->WriteValueType<GfxCmdGrabIntoRenderTexture>(grab); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + ClientDeviceRenderSurface* colorSurf = static_cast<ClientDeviceRenderSurface*>(rs.object); + ClientDeviceRenderSurface* depthSurf = static_cast<ClientDeviceRenderSurface*>(rd.object); + m_RealDevice->GrabIntoRenderTexture(colorSurf->internalHandle, depthSurf->internalHandle, x, y, width, height); + } +#endif +} + + +#if ENABLE_PROFILER +// Gets "what is being done" description from profiler sample +// hierarchy, e.g. "Camera.Render/RenderOpaqueGeometry" +static void GetContextDescriptionFromProfiler(std::string& outName) +{ + UnityProfilerPerThread* profiler = UnityProfilerPerThread::ms_InstanceTLS; + if (profiler) + { + // Do not get the last (most child) level, since that's usually always + // the same like DrawVBO. + for (int level = 3; level > 0; --level) + { + const ProfilerSample* sample = profiler->GetActiveSample(level); + if (sample && sample->information) + { + if (!outName.empty()) + outName += '/'; + outName += sample->information->name; + } + } + } + if (outName.empty()) + outName = "<run with profiler for info>"; +} +#endif // #if ENABLE_PROFILER + + +void GfxDeviceClient::IgnoreNextUnresolveOnCurrentRenderTarget() +{ + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + { + ClientDeviceRenderSurface* colorSurf = (ClientDeviceRenderSurface*)m_ActiveRenderColorSurfaces[i].object; + if(colorSurf) + colorSurf->state = ClientDeviceRenderSurface::kInitial; + } + + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)m_ActiveRenderDepthSurface.object; + depthSurf->state = ClientDeviceRenderSurface::kInitial; +} + +void GfxDeviceClient::IgnoreNextUnresolveOnRS(RenderSurfaceHandle rs) +{ + if (!rs.IsValid()) + return; + ((ClientDeviceRenderSurface*)rs.object)->state = ClientDeviceRenderSurface::kInitial; +} + + + +void GfxDeviceClient::BeforeDrawCall(bool immediateMode) +{ + if (!GetFrameStats().m_StatsEnabled) + return; + + ClientDeviceRenderSurface* colorWarn = NULL; + ClientDeviceRenderSurface* depthWarn = NULL; + bool backColorWarn = false; + bool backDepthWarn = false; + + // Check if any of surfaces have been resolved, not cleared/discarded and now + // we want to render into them -- warn about this situation if needed. + // Then set all surfaces as "rendered into". + for (int i = 0; i < kMaxSupportedRenderTargets; ++i) + { + ClientDeviceRenderSurface* colorSurf = (ClientDeviceRenderSurface*)m_ActiveRenderColorSurfaces[i].object; + if(colorSurf) + { + if (colorSurf->state == ClientDeviceRenderSurface::kResolved) + colorWarn = colorSurf; + colorSurf->state = ClientDeviceRenderSurface::kRendered; + } + } + + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)m_ActiveRenderDepthSurface.object; + if(depthSurf) + { + if (depthSurf->zformat != kDepthFormatNone && depthSurf->state == ClientDeviceRenderSurface::kResolved) + depthWarn = depthSurf; + depthSurf->state = ClientDeviceRenderSurface::kRendered; + } + + #if ENABLE_PROFILER + // In development builds, emit warnings if we're emulating + // a tiled GPU. + if (gGraphicsCaps.warnRenderTargetUnresolves && (colorWarn || depthWarn || backColorWarn || backDepthWarn)) + { + std::string desc; + GetContextDescriptionFromProfiler(desc); + if (colorWarn) + { + WarningStringMsg ("Tiled GPU perf. warning: RenderTexture %s (%dx%d) was not cleared/discarded, doing %s", depthWarn ? "" : "color surface ", colorWarn->width, colorWarn->height, desc.c_str()); + } + else if (depthWarn) + { + WarningStringMsg ("Tiled GPU perf. warning: RenderTexture depth surface (%dx%d) was not cleared/discarded, doing %s", depthWarn->width, depthWarn->height, desc.c_str()); + } + else if (backColorWarn) + { + WarningStringMsg ("Tiled GPU perf. warning: Backbuffer %s was not cleared/discarded, doing %s", backDepthWarn ? "" : "color surface ", desc.c_str()); + } + else if (backDepthWarn) + { + WarningStringMsg ("Tiled GPU perf. warning: Backbuffer depth surface was not cleared/discarded, doing %s", desc.c_str()); + } + } + #endif +} + +bool GfxDeviceClient::IsPositionRequiredForTexGen (int texStageIndex) const +{ +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + return m_CurrentContext->shadersActive[kShaderVertex] == 0 && (posForTexGen & (1<<texStageIndex) != 0); +#else + return m_RealDevice->IsPositionRequiredForTexGen(texStageIndex); +#endif +} + +bool GfxDeviceClient::IsNormalRequiredForTexGen (int texStageIndex) const +{ +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + return m_CurrentContext->shadersActive[kShaderVertex] == 0 && (nrmForTexGen & (1<<texStageIndex) != 0); +#else + return m_RealDevice->IsNormalRequiredForTexGen(texStageIndex); +#endif +} + +bool GfxDeviceClient::IsPositionRequiredForTexGen() const +{ +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + return m_CurrentContext->shadersActive[kShaderVertex] == 0 && posForTexGen != 0; +#else + return m_RealDevice->IsPositionRequiredForTexGen(); +#endif +} + +bool GfxDeviceClient::IsNormalRequiredForTexGen() const +{ +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + return m_CurrentContext->shadersActive[kShaderVertex] == 0 && nrmForTexGen != 0; +#else + return m_RealDevice->IsNormalRequiredForTexGen(); +#endif +} + +void GfxDeviceClient::SetActiveContext (void* ctx) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetActiveContext); + m_CommandQueue->WriteValueType<void*>(ctx); + SubmitCommands(); + GetGfxDeviceWorker()->WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetActiveContext (ctx); +} + + +void GfxDeviceClient::ResetFrameStats() +{ + CheckMainThread(); + m_Stats.ResetClientStats(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ResetFrameStats); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ResetFrameStats(); +} + +void GfxDeviceClient::BeginFrameStats() +{ + ((ClientDeviceRenderSurface*)(m_BackBufferColor.object))->state = ClientDeviceRenderSurface::kInitial; + ((ClientDeviceRenderSurface*)(m_BackBufferDepth.object))->state = ClientDeviceRenderSurface::kInitial; + + CheckMainThread(); + m_Stats.BeginFrameStats(); + if (m_Serialize) + { + m_CommandQueue->ResetWriteWaitTime(); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginFrameStats); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->BeginFrameStats(); +} + +void GfxDeviceClient::EndFrameStats() +{ + CheckMainThread(); + m_Stats.EndClientFrameStats(); + if (m_Serialize) + { + m_Stats.m_ClientFrameTime -= m_CommandQueue->GetWriteWaitTime(); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndFrameStats); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EndFrameStats(); +} + +void GfxDeviceClient::SaveDrawStats() +{ + CheckMainThread(); + m_SavedStats.CopyClientStats(m_Stats); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SaveDrawStats); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SaveDrawStats(); +} + +void GfxDeviceClient::RestoreDrawStats() +{ + CheckMainThread(); + m_Stats.CopyClientStats(m_SavedStats); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_RestoreDrawStats); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->RestoreDrawStats(); +} + +void GfxDeviceClient::SynchronizeStats() +{ + CheckMainThread(); + if (m_Threaded) + { + GetGfxDeviceWorker()->GetLastFrameStats(m_Stats); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SynchronizeStats); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_Stats.CopyAllDrawStats(m_RealDevice->GetFrameStats()); +} + +void* GfxDeviceClient::GetNativeGfxDevice() +{ + AcquireThreadOwnership (); + void* result = m_RealDevice->GetNativeGfxDevice(); + ReleaseThreadOwnership (); + return result; +} + +void* GfxDeviceClient::GetNativeTexturePointer(TextureID id) +{ + AcquireThreadOwnership (); + void* result = m_RealDevice->GetNativeTexturePointer(id); + ReleaseThreadOwnership (); + return result; +} + +UInt32 GfxDeviceClient::GetNativeTextureID(TextureID id) +{ +#if ENABLE_TEXTUREID_MAP + AcquireThreadOwnership (); + UInt32 result = m_RealDevice->GetNativeTextureID(id); + ReleaseThreadOwnership (); + return result; +#else + return id.m_ID; +#endif +} + +#if ENABLE_TEXTUREID_MAP + intptr_t GfxDeviceClient::CreateExternalTextureFromNative(intptr_t nativeTex) + { + AcquireThreadOwnership (); + intptr_t result = m_RealDevice->CreateExternalTextureFromNative(nativeTex); + ReleaseThreadOwnership (); + return result; + } + void GfxDeviceClient::UpdateExternalTextureFromNative(TextureID tex, intptr_t nativeTex) + { + AcquireThreadOwnership (); + m_RealDevice->UpdateExternalTextureFromNative(tex, nativeTex); + ReleaseThreadOwnership (); + } +#endif + +void GfxDeviceClient::InsertCustomMarker (int marker) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_InsertCustomMarker); + m_CommandQueue->WriteValueType<int>(marker); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->InsertCustomMarker (marker); +} + + +void GfxDeviceClient::SetComputeBufferData (ComputeBufferID bufferHandle, const void* data, size_t size) +{ + CheckMainThread(); + DebugAssert (bufferHandle.IsValid() && data && size); + if (m_Serialize) + { + // Don't want to upload data from a display list + m_CurrentContext->recordFailed = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetComputeBufferData); + m_CommandQueue->WriteValueType<ComputeBufferID>(bufferHandle); + m_CommandQueue->WriteValueType<size_t>(size); + m_CommandQueue->WriteStreamingData(data, size); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetComputeBufferData (bufferHandle, data, size); +} + + +void GfxDeviceClient::GetComputeBufferData (ComputeBufferID bufferHandle, void* dest, size_t destSize) +{ + CheckMainThread(); + DebugAssert (bufferHandle.IsValid() && dest && destSize); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_GetComputeBufferData); + m_CommandQueue->WriteValueType<ComputeBufferID>(bufferHandle); + m_CommandQueue->WriteValueType<size_t>(destSize); + m_CommandQueue->WriteValueType<void*>(dest); + SubmitCommands(); + GetGfxDeviceWorker()->WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->GetComputeBufferData (bufferHandle, dest, destSize); +} + + +void GfxDeviceClient::CopyComputeBufferCount (ComputeBufferID srcBuffer, ComputeBufferID dstBuffer, UInt32 dstOffset) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CopyComputeBufferCount); + m_CommandQueue->WriteValueType<ComputeBufferID>(srcBuffer); + m_CommandQueue->WriteValueType<ComputeBufferID>(dstBuffer); + m_CommandQueue->WriteValueType<UInt32>(dstOffset); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->CopyComputeBufferCount (srcBuffer, dstBuffer, dstOffset); +} + +void GfxDeviceClient::SetRandomWriteTargetTexture (int index, TextureID tid) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetRandomWriteTargetTexture); + m_CommandQueue->WriteValueType<int>(index); + m_CommandQueue->WriteValueType<TextureID>(tid); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetRandomWriteTargetTexture (index, tid); +} + +void GfxDeviceClient::SetRandomWriteTargetBuffer (int index, ComputeBufferID bufferHandle) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetRandomWriteTargetBuffer); + m_CommandQueue->WriteValueType<int>(index); + m_CommandQueue->WriteValueType<ComputeBufferID>(bufferHandle); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetRandomWriteTargetBuffer (index, bufferHandle); +} + +void GfxDeviceClient::ClearRandomWriteTargets () +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ClearRandomWriteTargets); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ClearRandomWriteTargets (); +} + +ComputeProgramHandle GfxDeviceClient::CreateComputeProgram (const UInt8* code, size_t codeSize) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + ClientDeviceComputeProgram* handle = UNITY_NEW(ClientDeviceComputeProgram, kMemGfxThread); + if (m_Serialize) + { + // Don't want to upload shaders from a display list + m_CurrentContext->recordFailed = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateComputeProgram); + m_CommandQueue->WriteValueType<ClientDeviceComputeProgram*>(handle); + m_CommandQueue->WriteValueType<size_t>(codeSize); + m_CommandQueue->WriteStreamingData(code, codeSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + handle->internalHandle = m_RealDevice->CreateComputeProgram (code, codeSize); + } + return ComputeProgramHandle(handle); +} + +void GfxDeviceClient::DestroyComputeProgram (ComputeProgramHandle& cpHandle) +{ + CheckMainThread(); + + ClientDeviceComputeProgram* cp = static_cast<ClientDeviceComputeProgram*>(cpHandle.object); + if (!cp) + return; + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DestroyComputeProgram); + m_CommandQueue->WriteValueType<ClientDeviceComputeProgram*>(cp); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + m_RealDevice->DestroyComputeProgram (cp->internalHandle); + UNITY_DELETE (cp, kMemGfxThread); + } + + cpHandle.Reset(); +} + +void GfxDeviceClient::CreateComputeConstantBuffers (unsigned count, const UInt32* sizes, ConstantBufferHandle* outCBs) +{ + Assert (count <= kMaxSupportedConstantBuffers); + + CheckMainThread(); + + for (unsigned i = 0; i < count; ++i) + outCBs[i].object = UNITY_NEW(ClientDeviceConstantBuffer(sizes[i]), kMemGfxThread); + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateComputeConstantBuffers); + m_CommandQueue->WriteValueType<unsigned>(count); + for (unsigned i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = static_cast<ClientDeviceConstantBuffer*>(outCBs[i].object); + m_CommandQueue->WriteValueType<ClientDeviceConstantBuffer*>(handle); + } + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + ConstantBufferHandle cbHandles[kMaxSupportedConstantBuffers]; + m_RealDevice->CreateComputeConstantBuffers (count, sizes, cbHandles); + for (unsigned i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = static_cast<ClientDeviceConstantBuffer*>(outCBs[i].object); + Assert (handle); + handle->internalHandle = cbHandles[i]; + } + } +} + +void GfxDeviceClient::DestroyComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs) +{ + Assert (count <= kMaxSupportedConstantBuffers); + + CheckMainThread(); + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DestroyComputeConstantBuffers); + m_CommandQueue->WriteValueType<unsigned>(count); + for (unsigned i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = static_cast<ClientDeviceConstantBuffer*>(cbs[i].object); + m_CommandQueue->WriteValueType<ClientDeviceConstantBuffer*>(handle); + } + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + ConstantBufferHandle cbHandles[kMaxSupportedConstantBuffers]; + for (unsigned i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = static_cast<ClientDeviceConstantBuffer*>(cbs[i].object); + if (handle) + cbHandles[i] = handle->internalHandle; + + UNITY_DELETE (handle, kMemGfxThread); + } + m_RealDevice->DestroyComputeConstantBuffers (count, cbHandles); + } + + for (unsigned i = 0; i < count; ++i) + cbs[i].Reset(); +} + +void GfxDeviceClient::CreateComputeBuffer (ComputeBufferID id, size_t count, size_t stride, UInt32 flags) +{ + CheckMainThread(); + DebugAssert(!IsRecording()); + Assert (id.IsValid()); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateComputeBuffer); + m_CommandQueue->WriteValueType<ComputeBufferID>(id); + m_CommandQueue->WriteValueType<size_t>(count); + m_CommandQueue->WriteValueType<size_t>(stride); + m_CommandQueue->WriteValueType<UInt32>(flags); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->CreateComputeBuffer (id, count, stride, flags); +} + +void GfxDeviceClient::DestroyComputeBuffer (ComputeBufferID handle) +{ + if (!handle.IsValid()) + return; + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DestroyComputeBuffer); + m_CommandQueue->WriteValueType<ComputeBufferID>(handle); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DestroyComputeBuffer (handle); +} + +void GfxDeviceClient::UpdateComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs, UInt32 cbDirty, size_t dataSize, const UInt8* data, const UInt32* cbSizes, const UInt32* cbOffsets, const int* bindPoints) +{ + CheckMainThread(); + + if (!count) + { + DebugAssert (dataSize == 0); + return; + } + DebugAssert (dataSize != 0); + + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UpdateComputeConstantBuffers); + m_CommandQueue->WriteValueType<unsigned>(count); + m_CommandQueue->WriteValueType<UInt32>(cbDirty); + for (int i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = static_cast<ClientDeviceConstantBuffer*>(cbs[i].object); + m_CommandQueue->WriteValueType<ClientDeviceConstantBuffer*>(handle); + m_CommandQueue->WriteValueType<UInt32>(cbSizes[i]); + m_CommandQueue->WriteValueType<UInt32>(cbOffsets[i]); + m_CommandQueue->WriteValueType<int>(bindPoints[i]); + } + m_CommandQueue->WriteValueType<size_t>(dataSize); + m_CommandQueue->WriteStreamingData(data, dataSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + ConstantBufferHandle cbHandles[kMaxSupportedConstantBuffers]; + for (unsigned i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = static_cast<ClientDeviceConstantBuffer*>(cbs[i].object); + if (handle) + cbHandles[i] = handle->internalHandle; + } + m_RealDevice->UpdateComputeConstantBuffers (count, cbHandles, cbDirty, dataSize, data, cbSizes, cbOffsets, bindPoints); + } +} + +void GfxDeviceClient::UpdateComputeResources ( + unsigned texCount, const TextureID* textures, const int* texBindPoints, + unsigned samplerCount, const unsigned* samplers, + unsigned inBufferCount, const ComputeBufferID* inBuffers, const int* inBufferBindPoints, + unsigned outBufferCount, const ComputeBufferID* outBuffers, const TextureID* outTextures, const UInt32* outBufferBindPoints) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_UpdateComputeResources); + m_CommandQueue->WriteValueType<unsigned>(texCount); + for (int i = 0; i < texCount; ++i) + { + m_CommandQueue->WriteValueType<TextureID>(textures[i]); + m_CommandQueue->WriteValueType<int>(texBindPoints[i]); + } + m_CommandQueue->WriteValueType<unsigned>(samplerCount); + for (int i = 0; i < samplerCount; ++i) + { + m_CommandQueue->WriteValueType<unsigned>(samplers[i]); + } + m_CommandQueue->WriteValueType<unsigned>(inBufferCount); + for (int i = 0; i < inBufferCount; ++i) + { + m_CommandQueue->WriteValueType<ComputeBufferID>(inBuffers[i]); + m_CommandQueue->WriteValueType<int>(inBufferBindPoints[i]); + } + m_CommandQueue->WriteValueType<unsigned>(outBufferCount); + for (int i = 0; i < outBufferCount; ++i) + { + m_CommandQueue->WriteValueType<ComputeBufferID>(outBuffers[i]); + m_CommandQueue->WriteValueType<TextureID>(outTextures[i]); + m_CommandQueue->WriteValueType<UInt32>(outBufferBindPoints[i]); + } + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->UpdateComputeResources (texCount, textures, texBindPoints, samplerCount, samplers, inBufferCount, inBuffers, inBufferBindPoints, outBufferCount, outBuffers, outTextures, outBufferBindPoints); +} + +void GfxDeviceClient::DispatchComputeProgram (ComputeProgramHandle cpHandle, unsigned threadsX, unsigned threadsY, unsigned threadsZ) +{ + CheckMainThread(); + + ClientDeviceComputeProgram* cp = static_cast<ClientDeviceComputeProgram*>(cpHandle.object); + if (!cp) + return; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DispatchComputeProgram); + m_CommandQueue->WriteValueType<ClientDeviceComputeProgram*>(cp); + m_CommandQueue->WriteValueType<unsigned>(threadsX); + m_CommandQueue->WriteValueType<unsigned>(threadsY); + m_CommandQueue->WriteValueType<unsigned>(threadsZ); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + m_RealDevice->DispatchComputeProgram (cp->internalHandle, threadsX, threadsY, threadsZ); + } +} + +void GfxDeviceClient::DrawNullGeometry (GfxPrimitiveType topology, int vertexCount, int instanceCount) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DrawNullGeometry); + m_CommandQueue->WriteValueType<GfxPrimitiveType>(topology); + m_CommandQueue->WriteValueType<int>(vertexCount); + m_CommandQueue->WriteValueType<int>(instanceCount); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DrawNullGeometry (topology, vertexCount, instanceCount); +} + +void GfxDeviceClient::DrawNullGeometryIndirect (GfxPrimitiveType topology, ComputeBufferID bufferHandle, UInt32 bufferOffset) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DrawNullGeometryIndirect); + m_CommandQueue->WriteValueType<GfxPrimitiveType>(topology); + m_CommandQueue->WriteValueType<ComputeBufferID>(bufferHandle); + m_CommandQueue->WriteValueType<UInt32>(bufferOffset); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DrawNullGeometryIndirect (topology, bufferHandle, bufferOffset); +} + + + +#if ENABLE_PROFILER + +void GfxDeviceClient::BeginProfileEvent (const char* name) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginProfileEvent); + m_CommandQueue->WriteValueType<const char*>(name); // assuming the pointer doesn't possibly go away! + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->BeginProfileEvent (name); +} +void GfxDeviceClient::EndProfileEvent () +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndProfileEvent); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EndProfileEvent (); +} + +void GfxDeviceClient::ProfileControl (GfxProfileControl ctrl, unsigned param) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_ProfileControl); + m_CommandQueue->WriteValueType<GfxProfileControl>(ctrl); + m_CommandQueue->WriteValueType<unsigned>(param); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->ProfileControl (ctrl, param); +} + + +GfxTimerQuery* GfxDeviceClient::CreateTimerQuery() +{ + CheckMainThread(); + Assert(!IsRecording()); + return new ThreadedTimerQuery(*this); +} + +void GfxDeviceClient::DeleteTimerQuery(GfxTimerQuery* query) +{ + CheckMainThread(); + Assert(!IsRecording()); + delete query; +} + +void GfxDeviceClient::BeginTimerQueries() +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginTimerQueries); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->BeginTimerQueries(); +} + +void GfxDeviceClient::EndTimerQueries() +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndTimerQueries); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->EndTimerQueries(); +} + +#endif + +// Editor-only stuff +#if UNITY_EDITOR + +void GfxDeviceClient::SetAntiAliasFlag( bool aa ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetAntiAliasFlag); + m_CommandQueue->WriteValueType<GfxCmdBool>(aa); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->SetAntiAliasFlag(aa); +} + + +void GfxDeviceClient::DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_DrawUserPrimitives); + GfxCmdDrawUserPrimitives user = { type, vertexCount, vertexChannels, stride }; + m_CommandQueue->WriteValueType<GfxCmdDrawUserPrimitives>(user); + m_CommandQueue->WriteStreamingData(data, vertexCount * stride); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_RealDevice->DrawUserPrimitives(type, vertexCount, vertexChannels, data, stride); +} + +int GfxDeviceClient::GetCurrentTargetAA() const +{ +#if UNITY_WIN + return ThreadedWindow::GetCurrentFSAALevel(); +#else + return 1; // fix this +#endif +} + +#endif + +#if UNITY_EDITOR && UNITY_WIN +//ToDo: This is windows specific code, we should replace HWND window with something more abstract +GfxDeviceWindow* GfxDeviceClient::CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) +{ + CheckMainThread(); + ThreadedWindow* result = new ThreadedWindow(window, width, height, depthFormat, antiAlias); + ClientDeviceWindow* handle = result->m_ClientWindow; + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_CreateWindow); + m_CommandQueue->WriteValueType<ClientDeviceWindow*>(handle); + GfxCmdCreateWindow create = { window, width, height, depthFormat, antiAlias }; + m_CommandQueue->WriteValueType<GfxCmdCreateWindow>(create); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + handle->internalWindow = m_RealDevice->CreateGfxWindow(window, width, height, depthFormat, antiAlias); + } + + return result; +} + +void GfxDeviceClient::SetActiveWindow(ClientDeviceWindow* handle) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_SetActiveWindow); + m_CommandQueue->WriteValueType<ClientDeviceWindow*>(handle); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + handle->GetInternal()->SetAsActiveWindow(); +} + +void GfxDeviceClient::WindowReshape(ClientDeviceWindow* handle, int width, int height, DepthBufferFormat depthFormat, int antiAlias) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_WindowReshape); + m_CommandQueue->WriteValueType<ClientDeviceWindow*>(handle); + GfxCmdWindowReshape reshape = { width, height, depthFormat, antiAlias }; + m_CommandQueue->WriteValueType<GfxCmdWindowReshape>(reshape); + SubmitCommands(); + WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + handle->GetInternal()->Reshape(width, height, depthFormat, antiAlias); +} + +void GfxDeviceClient::WindowDestroy(ClientDeviceWindow* handle) +{ + CheckMainThread(); + if (m_Serialize) + { + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_WindowDestroy); + m_CommandQueue->WriteValueType<ClientDeviceWindow*>(handle); + SubmitCommands(); + WaitForSignal(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + delete handle->GetInternal(); +} + +void GfxDeviceClient::BeginRendering(ClientDeviceWindow* handle) +{ + CheckMainThread(); + m_InsideFrame = true; + if (m_Serialize) + { + WaitForPendingPresent(); + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_BeginRendering); + m_CommandQueue->WriteValueType<ClientDeviceWindow*>(handle); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + handle->GetInternal()->BeginRendering(); +} + +void GfxDeviceClient::EndRendering(ClientDeviceWindow* handle, bool presentContent) +{ + CheckMainThread(); + m_InsideFrame = false; + if (m_Serialize) + { + // Check that we waited on event before issuing a new one + bool signalEvent = !m_PresentPending; + m_PresentPending = true; + m_CommandQueue->WriteValueType<GfxCommand>(kGfxCmd_EndRendering); + m_CommandQueue->WriteValueType<ClientDeviceWindow*>(handle); + m_CommandQueue->WriteValueType<GfxCmdBool>(presentContent); + m_CommandQueue->WriteValueType<GfxCmdBool>(signalEvent); + SubmitCommands(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + handle->GetInternal()->EndRendering(presentContent); +} + +#endif + +#if UNITY_WIN +int GfxDeviceClient::GetCurrentTargetWidth() const +{ + return m_CurrentTargetWidth; +} +int GfxDeviceClient::GetCurrentTargetHeight() const +{ + return m_CurrentTargetHeight; +} + +void GfxDeviceClient::SetCurrentTargetSize(int width, int height) +{ + m_CurrentTargetWidth = width; + m_CurrentTargetHeight = height; +} + +void GfxDeviceClient::SetCurrentWindowSize(int width, int height) +{ + m_CurrentWindowWidth = m_CurrentTargetWidth = width; + m_CurrentWindowHeight = m_CurrentTargetHeight = height; +} +#endif + +void GfxDeviceClient::SetRealGfxDevice(GfxThreadableDevice* realDevice) +{ + if (realDevice) + { + m_RealDevice = realDevice; + m_Renderer = realDevice->GetRenderer(); + m_UsesOpenGLTextureCoords = realDevice->UsesOpenGLTextureCoords(); + m_UsesHalfTexelOffset = realDevice->UsesHalfTexelOffset(); + m_MaxBufferedFrames = realDevice->GetMaxBufferedFrames(); + m_FramebufferDepthFormat = realDevice->GetFramebufferDepthFormat(); +#if UNITY_WIN + m_CurrentTargetWidth = realDevice->GetCurrentTargetWidth(); + m_CurrentTargetHeight = realDevice->GetCurrentTargetHeight(); + m_CurrentWindowWidth = m_CurrentTargetWidth; + m_CurrentWindowHeight = m_CurrentTargetHeight; +#endif + } + else + { + m_RealDevice = NULL; + m_Renderer = kGfxRendererOpenGL; + m_UsesOpenGLTextureCoords = true; + m_UsesHalfTexelOffset = false; + m_MaxBufferedFrames = 1; + } +} + +void GfxDeviceClient::UpdateFogDisabled() +{ + m_FogParams.mode = kFogDisabled; +} + +void GfxDeviceClient::UpdateFogEnabled(const GfxFogParams& fogParams) +{ + m_FogParams = fogParams; +} + +void GfxDeviceClient::UpdateShadersActive(bool shadersActive[kShaderTypeCount]) +{ + memcpy(m_CurrentContext->shadersActive, shadersActive, sizeof(bool[kShaderTypeCount])); +} + +void GfxDeviceClient::CheckMainThread() const +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); +} + +void GfxDeviceClient::WriteBufferData(const void* data, int size) +{ + int maxNonStreamedSize = m_CommandQueue->GetAllocatedSize() / 2; + if (size <= maxNonStreamedSize || IsRecording()) + { + // In the NaCl Web Player, make sure that only complete commands are submitted, as we are not truely + // asynchronous. + #if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + SubmitCommands(); + #endif + void* dest = m_CommandQueue->GetWriteDataPointer(size, ThreadedStreamBuffer::kDefaultAlignment); + memcpy(dest, data, size); + SubmitCommands(); + } + else + m_CommandQueue->WriteStreamingData(data, size); +} + +void GfxDeviceClient::ReadbackData(dynamic_array<UInt8>& data, const SInt32 chunkSize) +{ + data.resize_uninitialized(0); + m_CommandQueue->WriteValueType<SInt32>(chunkSize); + for (;;) + { + volatile void* chunkPtr = m_CommandQueue->GetWriteDataPointer(sizeof(SInt32) + chunkSize, ThreadedStreamBuffer::kDefaultAlignment); + volatile SInt32* returnedSizePtr = static_cast<volatile SInt32*>(chunkPtr); + volatile void* returnedDataPtr = &returnedSizePtr[1]; + *returnedSizePtr = -1; + m_CommandQueue->WriteSubmitData(); + while (*returnedSizePtr == -1) + { + WaitForSignal(); + // Busy wait + } + SInt32 size = *returnedSizePtr; + UnityMemoryBarrier(); + if (size > 0 && size <= chunkSize) + { + size_t oldSize = data.size(); + data.resize_uninitialized(oldSize + size); + // Const_cast needed to cast away volatile + memcpy(&data[oldSize], const_cast<const void*>(returnedDataPtr), size); + } + if (size < chunkSize) + break; + } +} + +void GfxDeviceClient::SubmitCommands() +{ + m_CommandQueue->WriteSubmitData(); +} + +void GfxDeviceClient::DoLockstep() +{ + if (!IsRecording()) + { + SubmitCommands(); + GetGfxDeviceWorker()->LockstepWait(); + } +} + +void GfxDeviceClient::WaitForPendingPresent() +{ + if (m_PresentPending) + { + PROFILER_AUTO(gGfxWaitForPresentProf, NULL); + + // We must wait for the last Present() to finish to figure out if device was lost. + // Beginning a new frame on a lost device will cause D3D debug runtime to complain. + // We may also lose any resources we upload on the render thread after seeing D3DERR_DEVICELOST. + m_DeviceWorker->WaitForEvent(GfxDeviceWorker::kEventTypePresent); + m_PresentPending = false; + } +} + +RenderTextureFormat GfxDeviceClient::GetDefaultRTFormat() const +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + return kRTFormatARGB32; +#else + return m_RealDevice->GetDefaultRTFormat(); +#endif +} + +RenderTextureFormat GfxDeviceClient::GetDefaultHDRRTFormat() const +{ +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + return kRTFormatARGBHalf; +#else + return m_RealDevice->GetDefaultHDRRTFormat();; +#endif +} + +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + void GfxDeviceClient::SetTexGen(int unit, TexGenMode mode) + { + bool posNeeded = (mode == kTexGenObject || mode == kTexGenEyeLinear); + bool nrmNeeded = (mode == kTexGenSphereMap || mode == kTexGenCubeReflect || mode == kTexGenCubeNormal); + + if(posNeeded) posForTexGen |= (1<<unit); + else posForTexGen &= ~(1<<unit); + if(nrmNeeded) nrmForTexGen |= (1<<unit); + else nrmForTexGen &= ~(1<<unit); + } + void GfxDeviceClient::DropTexGen(int unit) + { + posForTexGen &= ~(1<<unit); + nrmForTexGen &= ~(1<<unit); + } +#endif + +#endif //ENABLE_MULTITHREADED_CODE diff --git a/Runtime/GfxDevice/threaded/GfxDeviceClient.h b/Runtime/GfxDevice/threaded/GfxDeviceClient.h new file mode 100644 index 0000000..017fd88 --- /dev/null +++ b/Runtime/GfxDevice/threaded/GfxDeviceClient.h @@ -0,0 +1,423 @@ +#pragma once +#if ENABLE_MULTITHREADED_CODE + +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/TransformState.h" +#include "Runtime/GfxDevice/threaded/ClientIDMapper.h" +#include "Runtime/GfxDevice/threaded/ThreadedDeviceStates.h" +#include "Runtime/Utilities/dynamic_array.h" + +class ThreadedStreamBuffer; +class GfxDeviceWorker; +class GfxDeviceWindow; +class ThreadedWindow; +class ThreadedDynamicVBO; +struct DisplayListContext; + +enum +{ + kClientDeviceThreaded = 1 << 0, + kClientDeviceForceRef = 1 << 1, + kClientDeviceUseRealDevice = 1 << 2, + kClientDeviceClientProcess = 1 << 3, + kClientDeviceWorkerProcess = 1 << 4, +}; + +GfxDevice* CreateClientGfxDevice(GfxDeviceRenderer renderer, UInt32 flags, size_t bufferSize = 0, void *buffer=0); +bool GfxDeviceWorkerProcessRunCommand(); + +#define GFX_DEVICE_CLIENT_TRACK_TEXGEN (GFX_SUPPORTS_OPENGLES20 || GFX_SUPPORTS_OPENGLES30) + + +class GfxDeviceClient : public GfxDevice +{ +public: + GfxDeviceClient(bool threaded, bool clientProcess, size_t bufferSize = 0, void *buffer=0); + GFX_API ~GfxDeviceClient(); + + GFX_API void InvalidateState(); + #if GFX_DEVICE_VERIFY_ENABLE + GFX_API void VerifyState(); + #endif + + GFX_API void SetMaxBufferedFrames (int bufferSize); + + GFX_API void Clear (UInt32 clearFlags, const float color[4], float depth, int stencil); + GFX_API void SetUserBackfaceMode( bool enable ); + GFX_API void SetWireframe(bool wire); + GFX_API bool GetWireframe() const; + + GFX_API void SetInvertProjectionMatrix( bool enable ); + GFX_API bool GetInvertProjectionMatrix() const; + + #if GFX_USES_VIEWPORT_OFFSET + GFX_API void SetViewportOffset( float x, float y ); + GFX_API void GetViewportOffset( float &x, float &y ) const; + #endif + + GFX_API GPUSkinningInfo *CreateGPUSkinningInfo(); + GFX_API void DeleteGPUSkinningInfo(GPUSkinningInfo *info); + GFX_API void SkinOnGPU( GPUSkinningInfo * info, bool lastThisFrame ); + GFX_API void UpdateSkinSourceData(GPUSkinningInfo *info, const void *vertData, const BoneInfluence *skinData, bool dirty); + GFX_API void UpdateSkinBonePoses(GPUSkinningInfo *info, const int boneCount, const Matrix4x4f* poses); + + GFX_API DeviceBlendState* CreateBlendState(const GfxBlendState& state); + GFX_API DeviceDepthState* CreateDepthState(const GfxDepthState& state); + GFX_API DeviceStencilState* CreateStencilState(const GfxStencilState& state); + GFX_API DeviceRasterState* CreateRasterState(const GfxRasterState& state); + + GFX_API void RecordSetBlendState(const DeviceBlendState* state, const ShaderLab::FloatVal& alphaRef, const ShaderLab::PropertySheet* props); + GFX_API void SetBlendState(const DeviceBlendState* state, float alphaRef); + GFX_API void SetDepthState(const DeviceDepthState* state); + GFX_API void SetStencilState(const DeviceStencilState* state, int stencilRef); + GFX_API void SetRasterState(const DeviceRasterState* state); + GFX_API void SetSRGBWrite (const bool); + GFX_API bool GetSRGBWrite (); + + #if UNITY_XENON + GFX_API void SetNullPixelShader(); + GFX_API void SetHiZEnable( const HiZstate hiz_enable ); + GFX_API void SetHiStencilState( const bool hiStencilEnable, const bool hiStencilWriteEnable, const int hiStencilRef, const CompareFunction cmpfunc ); + GFX_API void HiStencilFlush( const HiSflush flushtype ); + #endif + + GFX_API void SetWorldMatrix( const float matrix[16] ); + GFX_API void SetViewMatrix( const float matrix[16] ); + GFX_API void SetProjectionMatrix(const Matrix4x4f& matrix); + GFX_API void GetMatrix( float outMatrix[16] ) const; + + GFX_API const float* GetWorldMatrix() const; + GFX_API const float* GetViewMatrix() const; + GFX_API const float* GetProjectionMatrix() const; + GFX_API const float* GetDeviceProjectionMatrix() const; + + GFX_API void SetInverseScale( float invScale ); + + GFX_API void SetNormalizationBackface( NormalizationMode mode, bool backface ); + + GFX_API void SetFFLighting( bool on, bool separateSpecular, ColorMaterialMode colorMaterial ); + GFX_API void RecordSetMaterial( const ShaderLab::VectorVal& ambient, const ShaderLab::VectorVal& diffuse, const ShaderLab::VectorVal& specular, const ShaderLab::VectorVal& emissive, const ShaderLab::FloatVal& shininess, const ShaderLab::PropertySheet* props ); + GFX_API void SetMaterial( const float ambient[4], const float diffuse[4], const float specular[4], const float emissive[4], const float shininess ); + GFX_API void RecordSetColor( const ShaderLab::VectorVal& color, const ShaderLab::PropertySheet* props ); + GFX_API void SetColor( const float color[4] ); + GFX_API void SetViewport( int x, int y, int width, int height ); + GFX_API void GetViewport( int* values ) const; + + GFX_API void SetScissorRect( int x, int y, int width, int height ); + GFX_API void DisableScissor(); + GFX_API bool IsScissorEnabled() const; + GFX_API void GetScissorRect( int values[4] ) const; + + GFX_API TextureCombinersHandle CreateTextureCombiners( int count, const ShaderLab::TextureBinding* texEnvs, const ShaderLab::PropertySheet* props, bool hasVertexColorOrLighting, bool usesAddSpecular ); + GFX_API void DeleteTextureCombiners( TextureCombinersHandle& textureCombiners ); + GFX_API void SetTextureCombiners( TextureCombinersHandle textureCombiners, const ShaderLab::PropertySheet* props ); + + GFX_API void SetTexture (ShaderType shaderType, int unit, int samplerUnit, TextureID texture, TextureDimension dim, float bias); + GFX_API void SetTextureParams( TextureID texture, TextureDimension texDim, TextureFilterMode filter, TextureWrapMode wrap, int anisoLevel, bool hasMipMap, TextureColorSpace colorSpace ); + GFX_API void SetTextureTransform( int unit, TextureDimension dim, TexGenMode texGen, bool identity, const float matrix[16]); + GFX_API void SetTextureName( TextureID texture, char const* name ); + + GFX_API void SetMaterialProperties(const MaterialPropertyBlock& block); + + GFX_API GpuProgram* CreateGpuProgram( const std::string& source, CreateGpuProgramOutput& output ); + GFX_API void SetShadersMainThread( ShaderLab::SubProgram* programs[kShaderTypeCount], const ShaderLab::PropertySheet* props ); + GFX_API bool IsShaderActive( ShaderType type ) const; + GFX_API void DestroySubProgram( ShaderLab::SubProgram* subprogram ); + GFX_API void SetConstantBufferInfo (int id, int size); + + GFX_API void DisableLights( int startLight ); + GFX_API void SetLight( int light, const GfxVertexLight& data); + GFX_API void SetAmbient( const float ambient[4] ); + + GFX_API void RecordEnableFog( FogMode fogMode, const ShaderLab::FloatVal& fogStart, const ShaderLab::FloatVal& fogEnd, const ShaderLab::FloatVal& fogDensity, const ShaderLab::VectorVal& fogColor, const ShaderLab::PropertySheet* props ); + GFX_API void EnableFog( const GfxFogParams& fog ); + GFX_API void DisableFog(); + + GFX_API VBO* CreateVBO(); + GFX_API void DeleteVBO( VBO* vbo ); + GFX_API DynamicVBO& GetDynamicVBO(); + + GFX_API void BeginSkinning( int maxSkinCount ); + GFX_API bool SkinMesh( const SkinMeshInfo& skin, VBO* vbo ); + GFX_API void EndSkinning(); + +#if GFX_ENABLE_DRAW_CALL_BATCHING + GFX_API void BeginStaticBatching(const ChannelAssigns& channels, GfxPrimitiveType topology); + GFX_API void StaticBatchMesh( UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ); + GFX_API void EndStaticBatching( VBO& vbo, const Matrix4x4f& matrix, TransformType transformType, int sourceChannels ); + + GFX_API void BeginDynamicBatching( const ChannelAssigns& shaderChannel, UInt32 channelsInVBO, size_t maxVertices, size_t maxIndices, GfxPrimitiveType topology); + GFX_API void DynamicBatchMesh( const Matrix4x4f& matrix, const VertexBufferData& vertices, UInt32 firstVertex, UInt32 vertexCount, const IndexBufferData& indices, UInt32 firstIndexByte, UInt32 indexCount ); +#if ENABLE_SPRITES + GFX_API void DynamicBatchSprite(const Matrix4x4f* matrix, const SpriteRenderData* rd, ColorRGBA32 color); +#endif + GFX_API void EndDynamicBatching( TransformType transformType ); +#endif + + GFX_API void AddBatchingStats( int batchedTris, int batchedVerts, int batchedCalls ); + +#if UNITY_XENON + GFX_API RawVBO* CreateRawVBO( UInt32 size, UInt32 flags ); + GFX_API void DeleteRawVBO( RawVBO* vbo ); + + GFX_API void EnablePersistDisplayOnQuit( bool enabled ); + GFX_API void OnLastFrameCallback(); + + GFX_API void RegisterTexture2D( TextureID tid, IDirect3DBaseTexture9* texture ); + GFX_API void PatchTexture2D( TextureID tid, IDirect3DBaseTexture9* texture ); + GFX_API void DeleteTextureEntryOnly( TextureID textureID ); + GFX_API void UnbindAndDelayReleaseTexture( IDirect3DBaseTexture9* texture ); + GFX_API void SetTextureWrapModes( TextureID textureID, TextureWrapMode wrapU, TextureWrapMode wrapV, TextureWrapMode wrapW ); + + GFX_API xenon::IVideoPlayer* CreateVideoPlayer(bool fullscreen); + GFX_API void DeleteVideoPlayer(xenon::IVideoPlayer* player); +#endif + + GFX_API RenderSurfaceHandle CreateRenderColorSurface (TextureID textureID, int width, int height, int samples, int depth, TextureDimension dim, RenderTextureFormat format, UInt32 createFlags); + GFX_API RenderSurfaceHandle CreateRenderDepthSurface (TextureID textureID, int width, int height, int samples, TextureDimension dim, DepthBufferFormat depthFormat, UInt32 createFlags); + GFX_API void DestroyRenderSurface (RenderSurfaceHandle& rs); + GFX_API void DiscardContents (RenderSurfaceHandle& rs); + GFX_API void IgnoreNextUnresolveOnCurrentRenderTarget(); + GFX_API void IgnoreNextUnresolveOnRS(RenderSurfaceHandle rs); + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face = kCubeFaceUnknown); + GFX_API void SetRenderTargets (int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle, int mipLevel, CubemapFace face, UInt32 flags); + GFX_API void ResolveColorSurface (RenderSurfaceHandle srcHandle, RenderSurfaceHandle dstHandle); + GFX_API void ResolveDepthIntoTexture (RenderSurfaceHandle colorHandle, RenderSurfaceHandle depthHandle); + + GFX_API RenderSurfaceHandle GetActiveRenderColorSurface (int index); + GFX_API RenderSurfaceHandle GetActiveRenderDepthSurface (); + + GFX_API bool IsRenderTargetConfigValid(UInt32 width, UInt32 height, RenderTextureFormat colorFormat, DepthBufferFormat depthFormat); + + GFX_API void SetSurfaceFlags(RenderSurfaceHandle surf, UInt32 flags, UInt32 keepFlags); + + GFX_API void UploadTexture2D( TextureID texture, TextureDimension dimension, UInt8* srcData, int srcSize, int width, int height, TextureFormat format, int mipCount, UInt32 uploadFlags, int skipMipLevels, TextureUsageMode usageMode, TextureColorSpace colorSpace ); + GFX_API void UploadTextureSubData2D( TextureID texture, UInt8* srcData, int srcSize, int mipLevel, int x, int y, int width, int height, TextureFormat format, TextureColorSpace colorSpace ); + GFX_API void UploadTextureCube( TextureID texture, UInt8* srcData, int srcSize, int faceDataSize, int size, TextureFormat format, int mipCount, UInt32 uploadFlags, TextureColorSpace colorSpace ); + GFX_API void UploadTexture3D( TextureID texture, UInt8* srcData, int srcSize, int width, int height, int depth, TextureFormat format, int mipCount, UInt32 uploadFlags ); + GFX_API void DeleteTexture( TextureID texture ); + + GFX_API PresentMode GetPresentMode(); + + GFX_API void BeginFrame(); + GFX_API void EndFrame(); + GFX_API void PresentFrame(); + GFX_API bool IsValidState(); + GFX_API bool HandleInvalidState(); + GFX_API void ResetDynamicResources(); + GFX_API bool IsReadyToBeginFrame(); + GFX_API void FinishRendering(); + GFX_API UInt32 InsertCPUFence(); + GFX_API UInt32 GetNextCPUFence(); + GFX_API void WaitOnCPUFence(UInt32 fence); + + GFX_API void AcquireThreadOwnership(); + GFX_API void ReleaseThreadOwnership(); + + GFX_API void ImmediateVertex( float x, float y, float z ); + GFX_API void ImmediateNormal( float x, float y, float z ); + GFX_API void ImmediateColor( float r, float g, float b, float a ); + GFX_API void ImmediateTexCoordAll( float x, float y, float z ); + GFX_API void ImmediateTexCoord( int unit, float x, float y, float z ); + GFX_API void ImmediateBegin( GfxPrimitiveType type ); + GFX_API void ImmediateEnd(); + + // Recording display lists + GFX_API bool BeginRecording(); + GFX_API bool EndRecording( GfxDisplayList** outDisplayList ); + + // Capturing screen shots / blits + GFX_API bool CaptureScreenshot( int left, int bottom, int width, int height, UInt8* rgba32 ); + GFX_API bool ReadbackImage( ImageReference& image, int left, int bottom, int width, int height, int destX, int destY ); + GFX_API void GrabIntoRenderTexture (RenderSurfaceHandle rs, RenderSurfaceHandle rd, int x, int y, int width, int height); + + // Any housekeeping around draw calls + GFX_API void BeforeDrawCall( bool immediateMode ); + + GFX_API bool IsPositionRequiredForTexGen (int texStageIndex) const; + GFX_API bool IsNormalRequiredForTexGen (int texStageIndex) const; + GFX_API bool IsPositionRequiredForTexGen() const; + GFX_API bool IsNormalRequiredForTexGen() const; + + GFX_API void SetActiveContext (void* ctx); + + GFX_API void ResetFrameStats(); + GFX_API void BeginFrameStats(); + GFX_API void EndFrameStats(); + GFX_API void SaveDrawStats(); + GFX_API void RestoreDrawStats(); + GFX_API void SynchronizeStats(); + + GFX_API void* GetNativeGfxDevice(); + GFX_API void* GetNativeTexturePointer(TextureID id); + GFX_API UInt32 GetNativeTextureID(TextureID id); +#if ENABLE_TEXTUREID_MAP + GFX_API intptr_t CreateExternalTextureFromNative(intptr_t nativeTex); + GFX_API void UpdateExternalTextureFromNative(TextureID tex, intptr_t nativeTex); +#endif + + GFX_API void InsertCustomMarker (int marker); + + GFX_API void SetComputeBufferData (ComputeBufferID bufferHandle, const void* data, size_t size); + GFX_API void GetComputeBufferData (ComputeBufferID bufferHandle, void* dest, size_t destSize); + GFX_API void CopyComputeBufferCount (ComputeBufferID srcBuffer, ComputeBufferID dstBuffer, UInt32 dstOffset); + + GFX_API void SetRandomWriteTargetTexture (int index, TextureID tid); + GFX_API void SetRandomWriteTargetBuffer (int index, ComputeBufferID bufferHandle); + GFX_API void ClearRandomWriteTargets (); + + GFX_API ComputeProgramHandle CreateComputeProgram (const UInt8* code, size_t codeSize); + GFX_API void DestroyComputeProgram (ComputeProgramHandle& cpHandle); + GFX_API void CreateComputeConstantBuffers (unsigned count, const UInt32* sizes, ConstantBufferHandle* outCBs); + GFX_API void DestroyComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs); + GFX_API void CreateComputeBuffer (ComputeBufferID id, size_t count, size_t stride, UInt32 flags); + GFX_API void DestroyComputeBuffer (ComputeBufferID handle); + GFX_API void UpdateComputeConstantBuffers (unsigned count, ConstantBufferHandle* cbs, UInt32 cbDirty, size_t dataSize, const UInt8* data, const UInt32* cbSizes, const UInt32* cbOffsets, const int* bindPoints); + GFX_API void UpdateComputeResources ( + unsigned texCount, const TextureID* textures, const int* texBindPoints, + unsigned samplerCount, const unsigned* samplers, + unsigned inBufferCount, const ComputeBufferID* inBuffers, const int* inBufferBindPoints, + unsigned outBufferCount, const ComputeBufferID* outBuffers, const TextureID* outTextures, const UInt32* outBufferBindPoints); + GFX_API void DispatchComputeProgram (ComputeProgramHandle cpHandle, unsigned threadsX, unsigned threadsY, unsigned threadsZ); + + GFX_API void DrawNullGeometry (GfxPrimitiveType topology, int vertexCount, int instanceCount); + GFX_API void DrawNullGeometryIndirect (GfxPrimitiveType topology, ComputeBufferID bufferHandle, UInt32 bufferOffset); + + +#if ENABLE_PROFILER + GFX_API void BeginProfileEvent (const char* name); + GFX_API void EndProfileEvent (); + GFX_API void ProfileControl (GfxProfileControl ctrl, unsigned param); + GFX_API GfxTimerQuery* CreateTimerQuery(); + GFX_API void DeleteTimerQuery(GfxTimerQuery* query); + GFX_API void BeginTimerQueries(); + GFX_API void EndTimerQueries(); +#endif + + // Editor-only stuff +#if UNITY_EDITOR + GFX_API void SetAntiAliasFlag( bool aa ); + GFX_API void DrawUserPrimitives( GfxPrimitiveType type, int vertexCount, UInt32 vertexChannels, const void* data, int stride ); + GFX_API int GetCurrentTargetAA() const; +#endif + +#if UNITY_EDITOR && UNITY_WIN + //ToDo: This is windows specific code, we should replace HWND window with something more abstract + GFX_API GfxDeviceWindow* CreateGfxWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + + void SetActiveWindow(ClientDeviceWindow* handle); + void WindowReshape(ClientDeviceWindow* handle, int width, int height, DepthBufferFormat depthFormat, int antiAlias); + void WindowDestroy(ClientDeviceWindow* handle); + void BeginRendering(ClientDeviceWindow* handle); + void EndRendering(ClientDeviceWindow* handle, bool presentContent); +#endif + +#if UNITY_WIN + GFX_API int GetCurrentTargetWidth() const; + GFX_API int GetCurrentTargetHeight() const; + GFX_API void SetCurrentTargetSize(int width, int height); + GFX_API void SetCurrentWindowSize(int width, int height); +#endif + +#if GFX_OPENGLESxx_ONLY || GFX_SUPPORTS_MOLEHILL + GFX_API void ReloadResources() {}; +#endif + + bool IsThreaded() const { return m_Threaded; } + bool IsSerializing() const { return m_Serialize; } + + ThreadedStreamBuffer* GetCommandQueue() const { return m_CommandQueue; } + GfxDeviceWorker* GetGfxDeviceWorker() const { return m_DeviceWorker; } + + void SetRealGfxDevice(GfxThreadableDevice* realDevice); + void WriteBufferData(const void* data, int size); + void ReadbackData(dynamic_array<UInt8>& data, const SInt32 chunkSize = 16384); + void SubmitCommands(); + void DoLockstep(); + + void QueryGraphicsCaps (); + + GFX_API RenderTextureFormat GetDefaultRTFormat() const; + GFX_API RenderTextureFormat GetDefaultHDRRTFormat() const; + +private: + friend class ThreadedDisplayList; + void UpdateFogDisabled(); + void UpdateFogEnabled(const GfxFogParams& fogParams); + void UpdateShadersActive(bool shadersActive[kShaderTypeCount]); + +private: + void CreateShaderParameters( ShaderLab::SubProgram* program, FogMode fogMode ); + + void CheckMainThread() const; + void BeforeRenderTargetChange(int count, RenderSurfaceHandle* colorHandles, RenderSurfaceHandle depthHandle); + void AfterRenderTargetChange(); + void WaitForPendingPresent(); + void WaitForSignal(); + + typedef std::map< GfxBlendState, ClientDeviceBlendState, memcmp_less<GfxBlendState> > CachedBlendStates; + typedef std::map< GfxDepthState, ClientDeviceDepthState, memcmp_less<GfxDepthState> > CachedDepthStates; + typedef std::map< GfxStencilState, ClientDeviceStencilState, memcmp_less<GfxStencilState> > CachedStencilStates; + typedef std::map< GfxRasterState, ClientDeviceRasterState, memcmp_less<GfxRasterState> > CachedRasterStates; + + GfxDeviceWorker* m_DeviceWorker; + GfxThreadableDevice* m_RealDevice; + bool m_Threaded; + bool m_Serialize; + int m_RecordDepth; + int m_MaxCallDepth; + ThreadedStreamBuffer* m_CommandQueue; + DisplayListContext* m_DisplayListStack; + DisplayListContext* m_CurrentContext; + DynamicVBO* m_DynamicVBO; + bool m_InvertProjectionMatrix; + #if GFX_USES_VIEWPORT_OFFSET + Vector2f m_ViewportOffset; + #endif + CachedBlendStates m_CachedBlendStates; + CachedDepthStates m_CachedDepthStates; + CachedStencilStates m_CachedStencilStates; + CachedRasterStates m_CachedRasterStates; + TransformState m_TransformState; + ClientDeviceRect m_Viewport; + ClientDeviceRect m_ScissorRect; + int m_ScissorEnabled; + RenderSurfaceHandle m_ActiveRenderColorSurfaces[kMaxSupportedRenderTargets]; + RenderSurfaceHandle m_ActiveRenderDepthSurface; + int m_CurrentTargetWidth; + int m_CurrentTargetHeight; + int m_CurrentWindowWidth; + int m_CurrentWindowHeight; + int m_ThreadOwnershipCount; + UInt32 m_CurrentCPUFence; + UInt32 m_PresentFrameID; + bool m_PresentPending; + bool m_Wireframe; + bool m_sRGBWrite; + dynamic_array<UInt8> m_ReadbackData; + +#if GFX_DEVICE_CLIENT_TRACK_TEXGEN + // TEMP: we can actually grab this info from shader, but for now lets just workaround it with minimal impact + // anyway, we should kill ffp (pretty please) + // TODO: it might be needed on more platforms, but for now i care only about gles + UInt8 posForTexGen; + UInt8 nrmForTexGen; + + void SetTexGen(int unit, TexGenMode mode); + void DropTexGen(int unit); +#endif + +public: +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientIDMapper m_BlendStateMapper; + ClientIDMapper m_DepthStateMapper; + ClientIDMapper m_StencilStateMapper; + ClientIDMapper m_RasterStateMapper; + ClientIDMapper m_TextureCombinerMapper; + ClientIDMapper m_VBOMapper; + ClientIDMapper m_RenderSurfaceMapper; + ClientIDMapper m_GpuProgramParametersMapper; +#endif +}; + +#endif diff --git a/Runtime/GfxDevice/threaded/GfxDeviceWorker.cpp b/Runtime/GfxDevice/threaded/GfxDeviceWorker.cpp new file mode 100644 index 0000000..3534e7c --- /dev/null +++ b/Runtime/GfxDevice/threaded/GfxDeviceWorker.cpp @@ -0,0 +1,2161 @@ +#include "UnityPrefix.h" + +#if ENABLE_MULTITHREADED_CODE + +#include "Runtime/GfxDevice/threaded/GfxDeviceWorker.h" +#include "Runtime/GfxDevice/threaded/GfxCommands.h" +#include "Runtime/GfxDevice/threaded/GfxReturnStructs.h" +#include "Runtime/GfxDevice/threaded/ThreadedDeviceStates.h" +#include "Runtime/Threads/ThreadedStreamBuffer.h" +#include "Runtime/Shaders/MaterialProperties.h" +#include "Runtime/Threads/Thread.h" +#include "Runtime/Threads/Semaphore.h" +#include "Runtime/Threads/ThreadUtility.h" +#include "Runtime/GfxDevice/GfxTimerQuery.h" +#include "Runtime/GfxDevice/GfxDeviceSetup.h" +#include "Runtime/GfxDevice/GPUSkinningInfo.h" +#include "Runtime/GfxDevice/threaded/ThreadedWindow.h" +#include "Runtime/GfxDevice/threaded/ThreadedDisplayList.h" +#include "Runtime/Filters/Mesh/MeshSkinning.h" +#include "Runtime/Profiler/Profiler.h" +#include "External/shaderlab/Library/program.h" +#include "External/shaderlab/Library/properties.h" +#include "External/shaderlab/Library/TextureBinding.h" + +#if GFXDEVICE_USE_CACHED_STATE + #define CHECK_CACHED_STATE(x) if (x) + #define SET_CACHED_STATE(dst, src) dst = src; +#else + #define CHECK_CACHED_STATE(x) + #define SET_CACHED_STATE(dst, src) +#endif + +#if UNITY_XENON + #include "PlatformDependent/Xbox360/Source/Services/VideoPlayer.h" + #include "PlatformDependent/Xbox360/Source/GfxDevice/GfxXenonVBO.h" + #include "PlatformDependent/Xbox360/Source/GfxDevice/GfxDeviceXenon.h" + #define GFX_DEVICE_WORKER_PROCESSOR 2 +#else + #define GFX_DEVICE_WORKER_PROCESSOR DEFAULT_UNITY_THREAD_PROCESSOR +#endif + +PROFILER_INFORMATION(gMTDrawProf, "Gfx.Draw", kProfilerRender) +PROFILER_INFORMATION(gMTDrawDynamicProf, "Gfx.DrawDynamic", kProfilerRender) +PROFILER_INFORMATION(gMTDrawStaticBatch, "Gfx.DrawStaticBatch", kProfilerRender) +PROFILER_INFORMATION(gMTDrawDynamicBatch, "Gfx.DrawDynamicBatch", kProfilerRender) + +PROFILER_INFORMATION(gMTSetRT, "Gfx.SetRenderTarget", kProfilerRender) +PROFILER_INFORMATION(gMTPresentFrame, "Gfx.PresentFrame", kProfilerRender) +PROFILER_INFORMATION(gMTBeginQueriesProf, "GPUProfiler.BeginQueries", kProfilerOverhead) +PROFILER_INFORMATION(gMTEndQueriesProf, "GPUProfiler.EndQueries", kProfilerOverhead) + + +#if GFXDEVICE_USE_CACHED_STATE +GfxDeviceWorker::CachedState::CachedState() +{ + normalization = kNormalizationUnknown; + backface = -1; + ambient = Vector4f(-1, -1, -1, -1); + fogEnabled = -1; + fogParams.Invalidate(); +} +#endif + +GfxDeviceWorker::GfxDeviceWorker(int maxCallDepth, ThreadedStreamBuffer* commandQueue) : + m_CallDepth(0), + m_MaxCallDepth(maxCallDepth), + m_WorkerThread(NULL), + m_CommandQueue(commandQueue), + m_MainCommandQueue(commandQueue), + m_CurrentCPUFence(0), + m_PresentFrameID(0), + m_IsThreadOwner(true), + m_Quit(false) +{ + m_FrameStats.ResetFrame(); + m_PlaybackCommandQueues = new ThreadedStreamBuffer[maxCallDepth]; + m_PlaybackDisplayLists = new ThreadedDisplayList*[maxCallDepth]; + memset(m_PlaybackDisplayLists, 0, sizeof(m_PlaybackDisplayLists[0]) * maxCallDepth); + // Event starts signaled so it doesn't block immediately + SignalEvent(kEventTypeTimerQueries); +} + +GfxDeviceWorker::~GfxDeviceWorker() +{ + if (m_WorkerThread) + { + m_WorkerThread->WaitForExit(); + delete m_WorkerThread; + } + SetRealGfxDeviceThreadOwnership(); + DestroyRealGfxDevice(); + delete[] m_PlaybackCommandQueues; + delete[] m_PlaybackDisplayLists; +} + + +GfxThreadableDevice* GfxDeviceWorker::Startup(GfxDeviceRenderer renderer, bool threaded, bool forceRef) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS_CLIENT + Assert (IsThreadableGfxDevice(renderer)); + + // Create actual device + GfxDevice* dev = CreateRealGfxDevice (renderer, forceRef); + if (!dev) + return NULL; + + m_Device = static_cast<GfxThreadableDevice*>(dev); + SetRealGfxDevice(dev); + + // Create worker thread + if (threaded) + { + m_WorkerThread = new Thread(); + m_WorkerThread->SetName ("UnityGfxDeviceWorker"); + m_Device->ReleaseThreadOwnership(); + m_WorkerThread->Run(GfxDeviceWorker::RunGfxDeviceWorker, this, DEFAULT_UNITY_THREAD_STACK_SIZE, GFX_DEVICE_WORKER_PROCESSOR); + + // In D3D11 we don't want to block on Present(), instead we block on IsReadyToBeginFrame() + if (renderer == kGfxRendererD3D11) + SignalEvent(kEventTypePresent); + } + + return m_Device; +#else + return NULL; +#endif +} + +void GfxDeviceWorker::Signal() +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_WaitSemaphore.Signal(); +#else + UnityMemoryBarrier(); +#endif +} + +void GfxDeviceWorker::WaitForSignal() +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_WaitSemaphore.WaitForSignal(); +#endif +} + +void GfxDeviceWorker::LockstepWait() +{ + m_LockstepSemaphore.WaitForSignal(); +} + +void GfxDeviceWorker::GetLastFrameStats(GfxDeviceStats& stats) +{ + Mutex::AutoLock lock(m_StatsMutex); + stats.CopyAllDrawStats(m_FrameStats); +} + +void GfxDeviceWorker::CallImmediate(ThreadedDisplayList* dlist) +{ + Assert(m_CallDepth == 0); + dlist->AddRef(); + m_PlaybackDisplayLists[m_CallDepth] = dlist; + m_CommandQueue = &m_PlaybackCommandQueues[m_CallDepth]; + m_CommandQueue->CreateReadOnly(dlist->GetData(), dlist->GetSize()); + m_CallDepth++; + while (m_CallDepth > 0) + { + RunCommand(*m_CommandQueue); + } +} + +void GfxDeviceWorker::WaitForEvent(EventType type) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_EventSemaphores[type].WaitForSignal(); +#endif +} + +void GfxDeviceWorker::SignalEvent(EventType type) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_EventSemaphores[type].Signal(); +#endif +} + +void GfxDeviceWorker::WaitOnCPUFence(UInt32 fence) +{ + while (SInt32(fence - m_CurrentCPUFence) > 0) + { + Thread::Sleep(0.001); + } +} + +bool GfxDeviceWorker::DidPresentFrame(UInt32 frameID) const +{ + return m_PresentFrameID == frameID; +} + +void* GfxDeviceWorker::RunGfxDeviceWorker(void* data) +{ + #if ENABLE_PROFILER + profiler_initialize_thread ("Render Thread", true); + #endif + + GfxDeviceWorker* worker = (GfxDeviceWorker*) data; + worker->m_Device->AcquireThreadOwnership(); + SetRealGfxDeviceThreadOwnership(); + worker->m_Device->OnDeviceCreated (true); + + worker->Run(); + + #if ENABLE_PROFILER + profiler_cleanup_thread(); + #endif + + return NULL; +} + +// Soft-toggle for spin-loop +bool g_enableGfxDeviceWorkerSpinLoop = false; + +GfxCommand lastCmd; +void GfxDeviceWorker::Run() +{ + +#define SPIN_WORKER_LOOP UNITY_XENON +#if SPIN_WORKER_LOOP + while (!m_Quit) + { + if (g_enableGfxDeviceWorkerSpinLoop == false || m_CommandQueue->HasDataToRead()) + { + RunCommand(*m_CommandQueue); + } + else + { + const bool presented = IsRealGfxDeviceThreadOwner() ? GetGfxDeviceX360().PresentFrameForTCR022() : false; + if (!presented) + Thread::Sleep(0.001); + } + } +#else + while (!m_Quit) + { + RunCommand(*m_CommandQueue); + } +#endif +} + +bool GfxDeviceWorker::RunCommandIfDataIsAvailable() +{ + if (!m_CommandQueue->HasData()) + return false; + + RunCommand(*m_CommandQueue); + return true; +} + +void GfxDeviceWorker::RunCommand(ThreadedStreamBuffer& stream) +{ +#if DEBUG_GFXDEVICE_LOCKSTEP + size_t pos = stream.GetDebugReadPosition(); +#endif + GfxCommand cmd = stream.ReadValueType<GfxCommand>(); + DebugAssert(m_IsThreadOwner || cmd == kGfxCmd_AcquireThreadOwnership); + switch (cmd) + { + case kGfxCmd_InvalidateState: + { + m_Device->InvalidateState(); + break; + } +#if GFX_DEVICE_VERIFY_ENABLE + case kGfxCmd_VerifyState: + { + m_Device->VerifyState(); + break; + } +#endif + case kGfxCmd_SetMaxBufferedFrames: + { + int bufferSize = stream.ReadValueType<int>(); + m_Device->SetMaxBufferedFrames(bufferSize); + break; + } + case kGfxCmd_Clear: + { + const GfxCmdClear& clear = stream.ReadValueType<GfxCmdClear>(); + m_Device->Clear(clear.clearFlags, clear.color.GetPtr(), clear.depth, clear.stencil); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_SetUserBackfaceMode: + { + bool enable = stream.ReadValueType<GfxCmdBool>(); + m_Device->SetUserBackfaceMode(enable); + break; + } + case kGfxCmd_SetWireframe: + { + bool wire = stream.ReadValueType<GfxCmdBool>(); + m_Device->SetWireframe(wire); + break; + } + case kGfxCmd_SetInvertProjectionMatrix: + { + bool enable = stream.ReadValueType<GfxCmdBool>(); + m_Device->SetInvertProjectionMatrix(enable); + break; + } +#if GFX_USES_VIEWPORT_OFFSET + case kGfxCmd_SetViewportOffset: + { + Vector2f ofs = stream.ReadValueType<Vector2f>(); + m_Device->SetViewportOffset(ofs.x, ofs.y); + break; + } +#endif + case kGfxCmd_CreateBlendState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceBlendState result = stream.ReadValueType<ClientDeviceBlendState>(); + m_BlendStateMapper[result.internalState] = m_Device->CreateBlendState(result.sourceState); +#else + ClientDeviceBlendState* result = stream.ReadValueType<ClientDeviceBlendState*>(); + result->internalState = m_Device->CreateBlendState(result->sourceState); +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_CreateDepthState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceDepthState result = stream.ReadValueType<ClientDeviceDepthState>(); + m_DepthStateMapper[result.internalState] = m_Device->CreateDepthState(result.sourceState); +#else + ClientDeviceDepthState* result = stream.ReadValueType<ClientDeviceDepthState*>(); + result->internalState = m_Device->CreateDepthState(result->sourceState); +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_CreateStencilState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceStencilState result = stream.ReadValueType<ClientDeviceStencilState>(); + m_StencilStateMapper[result.internalState] = m_Device->CreateStencilState(result.sourceState); +#else + ClientDeviceStencilState* result = stream.ReadValueType<ClientDeviceStencilState*>(); + result->internalState = m_Device->CreateStencilState(result->sourceState); +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_CreateRasterState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRasterState result = stream.ReadValueType<ClientDeviceRasterState>(); + m_RasterStateMapper[result.internalState] = m_Device->CreateRasterState(result.sourceState); +#else + ClientDeviceRasterState* result = stream.ReadValueType<ClientDeviceRasterState*>(); + result->internalState = m_Device->CreateRasterState(result->sourceState); +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_SetBlendState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + const ClientDeviceBlendState result = stream.ReadValueType<const ClientDeviceBlendState>(); + float alphaRef = stream.ReadValueType<float>(); + m_Device->SetBlendState(m_BlendStateMapper[result.internalState], alphaRef); +#else + const ClientDeviceBlendState* result = stream.ReadValueType<const ClientDeviceBlendState*>(); + float alphaRef = stream.ReadValueType<float>(); + m_Device->SetBlendState(result->internalState, alphaRef); +#endif + break; + } + case kGfxCmd_SetDepthState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + const ClientDeviceDepthState result = stream.ReadValueType<const ClientDeviceDepthState>(); + m_Device->SetDepthState(m_DepthStateMapper[result.internalState]); +#else + const ClientDeviceDepthState* result = stream.ReadValueType<const ClientDeviceDepthState*>(); + m_Device->SetDepthState(result->internalState); +#endif + break; + } + case kGfxCmd_SetStencilState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + const ClientDeviceStencilState result = stream.ReadValueType<const ClientDeviceStencilState>(); + int stencilRef = stream.ReadValueType<int>(); + m_Device->SetStencilState(m_StencilStateMapper[result.internalState], stencilRef); +#else + const ClientDeviceStencilState* result = stream.ReadValueType<const ClientDeviceStencilState*>(); + int stencilRef = stream.ReadValueType<int>(); + m_Device->SetStencilState(result->internalState, stencilRef); +#endif + break; + } + case kGfxCmd_SetRasterState: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + const ClientDeviceRasterState result = stream.ReadValueType<const ClientDeviceRasterState>(); + m_Device->SetRasterState(m_RasterStateMapper[result.internalState]); +#else + const ClientDeviceRasterState* result = stream.ReadValueType<const ClientDeviceRasterState*>(); + m_Device->SetRasterState(result->internalState); +#endif + break; + } + case kGfxCmd_SetSRGBState: + { + bool enable = stream.ReadValueType<GfxCmdBool>(); + m_Device->SetSRGBWrite(enable); + break; + } + case kGfxCmd_SetWorldMatrix: + { + const Matrix4x4f& matrix = stream.ReadValueType<Matrix4x4f>(); + m_Device->SetWorldMatrix(matrix.GetPtr()); + break; + } + case kGfxCmd_SetViewMatrix: + { + const Matrix4x4f& matrix = stream.ReadValueType<Matrix4x4f>(); + m_Device->SetViewMatrix(matrix.GetPtr()); + break; + } + case kGfxCmd_SetProjectionMatrix: + { + const Matrix4x4f& matrix = stream.ReadValueType<Matrix4x4f>(); + m_Device->SetProjectionMatrix(matrix); + break; + } + case kGfxCmd_SetInverseScale: + { + float invScale = stream.ReadValueType<float>(); + m_Device->SetInverseScale(invScale); + break; + } + case kGfxCmd_SetNormalizationBackface: + { + const GfxCmdSetNormalizationBackface& data = stream.ReadValueType<GfxCmdSetNormalizationBackface>(); + CHECK_CACHED_STATE(data.mode != m_Cached.normalization || int(data.backface) != m_Cached.backface) + { + m_Device->SetNormalizationBackface(data.mode, data.backface); + SET_CACHED_STATE(m_Cached.normalization, data.mode); + SET_CACHED_STATE(m_Cached.backface, data.backface); + } + break; + } + case kGfxCmd_SetFFLighting: + { + const GfxCmdSetFFLighting& data = stream.ReadValueType<GfxCmdSetFFLighting>(); + m_Device->SetFFLighting(data.on, data.separateSpecular, data.colorMaterial); + break; + } + case kGfxCmd_SetMaterial: + { + const GfxMaterialParams& mat = stream.ReadValueType<GfxMaterialParams>(); + m_Device->SetMaterial(mat.ambient.GetPtr(), mat.diffuse.GetPtr(), mat.specular.GetPtr(), mat.emissive.GetPtr(), mat.shininess); + break; + } + case kGfxCmd_SetColor: + { + const Vector4f& color = stream.ReadValueType<Vector4f>(); + m_Device->SetColor(color.GetPtr()); + break; + } + case kGfxCmd_SetViewport: + { + const ClientDeviceRect& rect = stream.ReadValueType<ClientDeviceRect>(); + m_Device->SetViewport(rect.x, rect.y, rect.width, rect.height); + break; + } + case kGfxCmd_SetScissorRect: + { + const ClientDeviceRect& rect = stream.ReadValueType<ClientDeviceRect>(); + m_Device->SetScissorRect(rect.x, rect.y, rect.width, rect.height); + break; + } + case kGfxCmd_DisableScissor: + { + m_Device->DisableScissor(); + break; + } + case kGfxCmd_CreateTextureCombiners: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceTextureCombiners result; + result.internalHandle = stream.ReadValueType<ClientIDMapper::ClientID>(); + result.count = stream.ReadValueType<int>(); + result.bindings = new ShaderLab::TextureBinding[result.count]; + for (int i = 0; i < result.count; i++) + result.bindings[i] = stream.ReadValueType<ShaderLab::TextureBinding>(); + + const GfxCmdCreateTextureCombiners& param = stream.ReadValueType<GfxCmdCreateTextureCombiners>(); + m_TextureCombinerMapper[result.internalHandle] = m_Device->CreateTextureCombiners(param.count, result.bindings, NULL, param.hasVertexColorOrLighting, param.usesAddSpecular).object; +#else + ClientDeviceTextureCombiners* result = stream.ReadValueType<ClientDeviceTextureCombiners*>(); + const GfxCmdCreateTextureCombiners& param = stream.ReadValueType<GfxCmdCreateTextureCombiners>(); + result->internalHandle = m_Device->CreateTextureCombiners(param.count, result->bindings, NULL, param.hasVertexColorOrLighting, param.usesAddSpecular); +#endif + break; + } + case kGfxCmd_DeleteTextureCombiners: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceTextureCombiners combiners; + combiners.internalHandle = stream.ReadValueType<ClientIDMapper::ClientID>(); + combiners.count = stream.ReadValueType<int>(); + TextureCombinersHandle handle(m_TextureCombinerMapper[combiners.internalHandle]); + m_Device->DeleteTextureCombiners(handle); +#else + ClientDeviceTextureCombiners* combiners = stream.ReadValueType<ClientDeviceTextureCombiners*>(); + m_Device->DeleteTextureCombiners(combiners->internalHandle); + for(int i = 0; i < combiners->count; i++) combiners->bindings[i].~TextureBinding(); + UNITY_FREE(kMemGfxThread,combiners->bindings); + UNITY_DELETE(combiners, kMemGfxThread); +#endif + break; + } + case kGfxCmd_SetTextureCombiners: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceTextureCombiners combiners; + combiners.internalHandle = stream.ReadValueType<ClientIDMapper::ClientID>(); + combiners.count = stream.ReadValueType<int>(); + int count = combiners.count; +#else + ClientDeviceTextureCombiners* combiners = stream.ReadValueType<ClientDeviceTextureCombiners*>(); + int count = combiners->count; +#endif + const void* data = m_CommandQueue->GetReadDataPointer(count * sizeof(TexEnvData), ALIGN_OF(TexEnvData)); + const TexEnvData* texEnvData = static_cast<const TexEnvData*>(data); + data = m_CommandQueue->GetReadDataPointer(count * sizeof(Vector4f), ALIGN_OF(Vector4f)); + const Vector4f* texColors = static_cast<const Vector4f*>(data); + // CreateTextureCombiners() might have failed on render thread, unknownst to main thread (case 435703) +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + if (combiners.internalHandle) + m_Device->SetTextureCombinersThreadable(TextureCombinersHandle(m_TextureCombinerMapper[combiners.internalHandle]), texEnvData, texColors); +#else + if (combiners->internalHandle.IsValid()) + m_Device->SetTextureCombinersThreadable(combiners->internalHandle, texEnvData, texColors); +#endif + break; + } + case kGfxCmd_SetTexture: + { + const GfxCmdSetTexture& tex = stream.ReadValueType<GfxCmdSetTexture>(); + m_Device->SetTexture(tex.shaderType, tex.unit, tex.samplerUnit, tex.texture, tex.dim, tex.bias); + break; + } + case kGfxCmd_SetTextureParams: + { + const GfxCmdSetTextureParams& params = stream.ReadValueType<GfxCmdSetTextureParams>(); + m_Device->SetTextureParams( params.texture, params.texDim, params.filter, params.wrap, params.anisoLevel, params.hasMipMap, params.colorSpace); + m_CommandQueue->ReadReleaseData(); + break; + } + case kGfxCmd_SetTextureTransform: + { + const GfxCmdSetTextureTransform& trans = stream.ReadValueType<GfxCmdSetTextureTransform>(); + m_Device->SetTextureTransform(trans.unit, trans.dim, trans.texGen, trans.identity, trans.matrix.GetPtr()); + break; + } + case kGfxCmd_SetTextureName: + { + const GfxCmdSetTextureName& texName = stream.ReadValueType<GfxCmdSetTextureName>(); + char* name = m_CommandQueue->ReadArrayType<char>(texName.nameLength); + m_Device->SetTextureName( texName.texture, name ); + break; + } + case kGfxCmd_SetMaterialProperties: + { + typedef MaterialPropertyBlock::Property Property; + GfxCmdSetMaterialProperties matprops = m_CommandQueue->ReadValueType<GfxCmdSetMaterialProperties>(); + Property* props = m_CommandQueue->ReadArrayType<Property>(matprops.propertyCount); + float* buffer = m_CommandQueue->ReadArrayType<float>(matprops.bufferSize); + MaterialPropertyBlock block(props, matprops.propertyCount, buffer, matprops.bufferSize); + m_Device->SetMaterialProperties(block); + break; + } + case kGfxCmd_CreateGpuProgram: + { + #if !ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdCreateGpuProgram gpuprog = m_CommandQueue->ReadValueType<GfxCmdCreateGpuProgram>(); + *gpuprog.result = m_Device->CreateGpuProgram(gpuprog.source, *gpuprog.output); + UnityMemoryBarrier(); + m_WaitSemaphore.Signal(); + m_CommandQueue->ReadReleaseData(); + #else + size_t len = m_CommandQueue->ReadValueType<UInt32>(); + const char* source = m_CommandQueue->ReadArrayType<char>(len + 1); + CreateGpuProgramOutput output; + GpuProgram* program = m_Device->CreateGpuProgram(source, output); + Assert(program); + // Allocate space for struct, append additional data + m_TempBuffer.resize_uninitialized(sizeof(GfxRet_CreateGpuProgram)); + GfxRet_CreateGpuProgram retStruct(output, m_TempBuffer); + retStruct.gpuProgram = m_GpuProgramClientMapper.CreateID(); + m_GpuProgramMapper[retStruct.gpuProgram] = program; + // Copy struct to start of buffer + *reinterpret_cast<GfxRet_CreateGpuProgram*>(m_TempBuffer.data()) = retStruct; + WritebackData(stream, m_TempBuffer.data(), m_TempBuffer.size()); + #endif + break; + } + case kGfxCmd_SetShaders: + { + GfxCmdSetShaders shaders = stream.ReadValueType<GfxCmdSetShaders>(); + UInt8* paramsBuffer[kShaderTypeCount]; +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + const GpuProgramParameters* params[kShaderTypeCount]; + GpuProgram* programs[kShaderTypeCount]; +#endif + for (int pt = 0; pt < kShaderTypeCount; ++pt) + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + params[pt] = m_GpuProgramParametersMapper[shaders.params[pt]]; + programs[pt] = m_GpuProgramMapper[shaders.programs[pt]]; +#endif + + paramsBuffer[pt] = NULL; + if (shaders.paramsBufferSize[pt] > 0) + { + void* buffer = m_CommandQueue->GetReadDataPointer (shaders.paramsBufferSize[pt], 1); + paramsBuffer[pt] = static_cast<UInt8*>(buffer); + } + } +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_Device->SetShadersThreadable (programs, params, paramsBuffer); +#else + m_Device->SetShadersThreadable (shaders.programs, shaders.params, paramsBuffer); +#endif + break; + } + case kGfxCmd_CreateShaderParameters: + { + GfxCmdCreateShaderParameters params = stream.ReadValueType<GfxCmdCreateShaderParameters>(); + m_Device->CreateShaderParameters(params.program, params.fogMode); + Signal(); + break; + } + case kGfxCmd_DestroySubProgram: + { + ShaderLab::SubProgram* subprogram = stream.ReadValueType<ShaderLab::SubProgram*>(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_Device->DestroySubProgram(subprogram); +#else + printf_console("fix ShaderLab::SubProgram\n"); +#endif + break; + } + case kGfxCmd_SetConstantBufferInfo: + { + int id = stream.ReadValueType<int>(); + int size = stream.ReadValueType<int>(); + m_Device->SetConstantBufferInfo (id, size); + break; + } + case kGfxCmd_DisableLights: + { + int startLight = stream.ReadValueType<int>(); + m_Device->DisableLights(startLight); + break; + } + case kGfxCmd_SetLight: + { + int light = stream.ReadValueType<int>(); + const GfxVertexLight& lightdata = stream.ReadValueType<GfxVertexLight>(); + m_Device->SetLight(light, lightdata); + break; + } + case kGfxCmd_SetAmbient: + { + const Vector4f& ambient = stream.ReadValueType<Vector4f>(); + CHECK_CACHED_STATE(!CompareMemory(ambient, m_Cached.ambient)) + { + m_Device->SetAmbient(ambient.GetPtr()); + SET_CACHED_STATE(m_Cached.ambient, ambient); + } + break; + } + case kGfxCmd_EnableFog: + { + const GfxFogParams& fog = stream.ReadValueType<GfxFogParams>(); + CHECK_CACHED_STATE(m_Cached.fogEnabled != 1 || !CompareMemory(fog, m_Cached.fogParams)) + { + m_Device->EnableFog(fog); + SET_CACHED_STATE(m_Cached.fogEnabled, 1); + SET_CACHED_STATE(m_Cached.fogParams, fog); + } + break; + } + case kGfxCmd_DisableFog: + { + CHECK_CACHED_STATE(m_Cached.fogEnabled != 0) + { + m_Device->DisableFog(); + SET_CACHED_STATE(m_Cached.fogEnabled, 0); + } + break; + } + case kGfxCmd_BeginSkinning: + { + int maxSkinCount = stream.ReadValueType<int>(); + m_SkinJobGroup = GetJobScheduler().BeginGroup(maxSkinCount); + m_ActiveSkins.reserve(maxSkinCount); + break; + } + case kGfxCmd_SkinMesh: + { + // Array must be preallocated to at least the right size + Assert(m_ActiveSkins.size() < m_ActiveSkins.capacity()); + int skinIndex = m_ActiveSkins.size(); + m_ActiveSkins.resize_uninitialized(skinIndex + 1); + SkinMeshInfo& skin = m_ActiveSkins[skinIndex]; + skin = stream.ReadValueType<SkinMeshInfo>(); + ClientDeviceVBO* vbo = stream.ReadValueType<ClientDeviceVBO*>(); + stream.ReadReleaseData(); + +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + VertexStreamData mappedVSD; + if (vbo->GetInternal()->MapVertexStream(mappedVSD, 0)) + { + skin.outVertices = mappedVSD.buffer; + GetJobScheduler().SubmitJob(m_SkinJobGroup, DeformSkinnedMeshJob, &skin, NULL); + m_MappedSkinVBOs.push_back(vbo->GetInternal()); + } +#endif + break; + } + case kGfxCmd_EndSkinning: + { + GetJobScheduler().WaitForGroup(m_SkinJobGroup); + for (int i = 0; i < m_ActiveSkins.size(); i++) + { + m_ActiveSkins[i].Release(); + } + m_ActiveSkins.resize_uninitialized(0); + for (int i = 0; i < m_MappedSkinVBOs.size(); i++) + { + m_MappedSkinVBOs[i]->UnmapVertexStream(0); + } + m_MappedSkinVBOs.resize_uninitialized(0); + break; + } +#if GFX_ENABLE_DRAW_CALL_BATCHING + case kGfxCmd_BeginStaticBatching: + { + PROFILER_BEGIN(gMTDrawStaticBatch, NULL); + const GfxCmdBeginStaticBatching& dynbat = stream.ReadValueType<GfxCmdBeginStaticBatching>(); + m_Device->BeginStaticBatching(dynbat.channels, dynbat.topology); + break; + } + case kGfxCmd_StaticBatchMesh: + { + const GfxCmdStaticBatchMesh& batch = stream.ReadValueType<GfxCmdStaticBatchMesh>(); + m_Device->StaticBatchMesh(batch.firstVertex, batch.vertexCount, + batch.indices, batch.firstIndexByte, batch.indexCount); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_EndStaticBatching: + { + const GfxCmdEndStaticBatching& endbat = stream.ReadValueType<GfxCmdEndStaticBatching>(); + m_Device->EndStaticBatching(*endbat.vbo->GetInternal(), endbat.matrix, endbat.transformType, endbat.sourceChannels); + stream.ReadReleaseData(); + PROFILER_END; + break; + } + case kGfxCmd_BeginDynamicBatching: + { + PROFILER_BEGIN(gMTDrawDynamicBatch, NULL); + const GfxCmdBeginDynamicBatching& dynbat = stream.ReadValueType<GfxCmdBeginDynamicBatching>(); + m_Device->BeginDynamicBatching(dynbat.shaderChannels, dynbat.channelsInVBO, dynbat.maxVertices, dynbat.maxIndices, dynbat.topology); + break; + } + case kGfxCmd_DynamicBatchMesh: + { + const GfxCmdDynamicBatchMesh& batch = stream.ReadValueType<GfxCmdDynamicBatchMesh>(); + m_Device->DynamicBatchMesh(batch.matrix, batch.vertices, batch.firstVertex, batch.vertexCount, + batch.indices, batch.firstIndexByte, batch.indexCount); + stream.ReadReleaseData(); + break; + } +#if ENABLE_SPRITES + case kGfxCmd_DynamicBatchSprite: + { + const GfxCmdDynamicBatchSprite& batch = stream.ReadValueType<GfxCmdDynamicBatchSprite>(); + m_Device->DynamicBatchSprite(&batch.matrix, batch.sprite, batch.color); + stream.ReadReleaseData(); + break; + } +#endif + case kGfxCmd_EndDynamicBatching: + { + const GfxCmdEndDynamicBatching& endbat = stream.ReadValueType<GfxCmdEndDynamicBatching>(); + m_Device->EndDynamicBatching(endbat.transformType); + stream.ReadReleaseData(); + PROFILER_END; + break; + } +#endif + case kGfxCmd_AddBatchingStats: + { + const GfxCmdAddBatchingStats& stats = stream.ReadValueType<GfxCmdAddBatchingStats>(); + m_Device->AddBatchingStats(stats.batchedTris, stats.batchedVerts, stats.batchedCalls); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_CreateRenderColorSurface: + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* handle = stream.ReadValueType<ClientDeviceRenderSurface*>(); +#else + ClientDeviceRenderSurface handle = stream.ReadValueType<ClientDeviceRenderSurface>(); +#endif + const GfxCmdCreateRenderColorSurface& create = stream.ReadValueType<GfxCmdCreateRenderColorSurface>(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + handle->internalHandle = m_Device->CreateRenderColorSurface(create.textureID, create.width, create.height, create.samples, create.depth, create.dim, create.format, create.createFlags); +#else + m_RenderSurfaceMapper[handle.internalHandle] = m_Device->CreateRenderColorSurface(create.textureID, create.width, create.height, create.samples, create.depth, create.dim, create.format, create.createFlags).object; +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_CreateRenderDepthSurface: + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* handle = stream.ReadValueType<ClientDeviceRenderSurface*>(); +#else + ClientDeviceRenderSurface handle = stream.ReadValueType<ClientDeviceRenderSurface>(); +#endif + const GfxCmdCreateRenderDepthSurface& create = stream.ReadValueType<GfxCmdCreateRenderDepthSurface>(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + handle->internalHandle = m_Device->CreateRenderDepthSurface(create.textureID, create.width, create.height, create.samples, create.dim, create.depthFormat, create.createFlags); +#else + m_RenderSurfaceMapper[handle.internalHandle] = m_Device->CreateRenderDepthSurface(create.textureID, create.width, create.height, create.samples, create.dim, create.depthFormat, create.createFlags).object; +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_DestroyRenderSurface: + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* handle = stream.ReadValueType<ClientDeviceRenderSurface*>(); + RenderSurfaceHandle rsHandle = handle->internalHandle; +#else + ClientDeviceRenderSurface handle = stream.ReadValueType<ClientDeviceRenderSurface>(); + RenderSurfaceHandle rsHandle(m_RenderSurfaceMapper[handle.internalHandle]); +#endif + m_Device->DestroyRenderSurface(rsHandle); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + delete handle; +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_DiscardContents: + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* handle = stream.ReadValueType<ClientDeviceRenderSurface*>(); + RenderSurfaceHandle rsHandle = handle->internalHandle; +#else + ClientDeviceRenderSurface handle = stream.ReadValueType<ClientDeviceRenderSurface>(); + RenderSurfaceHandle rsHandle(m_RenderSurfaceMapper[handle.internalHandle]); +#endif + m_Device->DiscardContents(rsHandle); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_SetRenderTarget: + { + PROFILER_AUTO(gMTSetRT, NULL); + const GfxCmdSetRenderTarget& srt = stream.ReadValueType<GfxCmdSetRenderTarget>(); + RenderSurfaceHandle colorHandle[kMaxSupportedRenderTargets]; + for (int i = 0; i < srt.colorCount; ++i) + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* colorSurf = static_cast<ClientDeviceRenderSurface*>(srt.colorHandles[i].object); + colorHandle[i].object = colorSurf ? colorSurf->internalHandle.object : NULL; +#else + colorHandle[i].object = m_RenderSurfaceMapper[srt.colorHandles[i]]; +#endif + // we cant access backbuffer handle in client device, so we write null + if(!colorHandle[i].IsValid()) + colorHandle[i] = m_Device->GetBackBufferColorSurface(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)srt.depthHandle.object; + RenderSurfaceHandle depthHandle(depthSurf ? depthSurf->internalHandle.object :NULL); +#else + RenderSurfaceHandle depthHandle(m_RenderSurfaceMapper[srt.depthHandle]); +#endif + // we cant access backbuffer handle in client device, so we write null + if(!depthHandle.IsValid()) + depthHandle = m_Device->GetBackBufferDepthSurface(); + + m_Device->SetRenderTargets (srt.colorCount, colorHandle, depthHandle, srt.mipLevel, srt.face); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_SetRenderTargetWithFlags: + { + PROFILER_AUTO(gMTSetRT, NULL); + const GfxCmdSetRenderTarget& srt = stream.ReadValueType<GfxCmdSetRenderTarget>(); + RenderSurfaceHandle colorHandle[kMaxSupportedRenderTargets]; + for (int i = 0; i < srt.colorCount; ++i) + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* colorSurf = static_cast<ClientDeviceRenderSurface*>(srt.colorHandles[i].object); + colorHandle[i].object = colorSurf ? colorSurf->internalHandle.object : NULL; +#else + colorHandle[i].object = m_RenderSurfaceMapper[srt.colorHandles[i]]; +#endif + // we cant access backbuffer handle in client device, so we write null + if(!colorHandle[i].IsValid()) + colorHandle[i] = m_Device->GetBackBufferColorSurface(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)srt.depthHandle.object; + RenderSurfaceHandle depthHandle(depthSurf ? depthSurf->internalHandle.object :NULL); +#else + RenderSurfaceHandle depthHandle(m_RenderSurfaceMapper[srt.depthHandle]); +#endif + // we cant access backbuffer handle in client device, so we write null + if(!depthHandle.IsValid()) + depthHandle = m_Device->GetBackBufferDepthSurface(); + + UInt32 flags = stream.ReadValueType<UInt32>(); + m_Device->SetRenderTargets (srt.colorCount, colorHandle, depthHandle, srt.mipLevel, srt.face, flags); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_ResolveColorSurface: + { +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* src = stream.ReadValueType<ClientDeviceRenderSurface*>(); + ClientDeviceRenderSurface* dst = stream.ReadValueType<ClientDeviceRenderSurface*>(); + m_Device->ResolveColorSurface (src->internalHandle, dst->internalHandle); +#else + //todo +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_ResolveDepthIntoTexture: + { + const GfxCmdResolveDepthIntoTexture resolve = stream.ReadValueType<GfxCmdResolveDepthIntoTexture>(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* colorSurf = (ClientDeviceRenderSurface*)resolve.colorHandle.object; + RenderSurfaceHandle colorHandle(colorSurf ? colorSurf->internalHandle.object : NULL); + + ClientDeviceRenderSurface* depthSurf = (ClientDeviceRenderSurface*)resolve.depthHandle.object; + RenderSurfaceHandle depthHandle(depthSurf ? depthSurf->internalHandle.object : NULL); +#else + RenderSurfaceHandle colorHandle(m_RenderSurfaceMapper[resolve.colorHandle]); + RenderSurfaceHandle depthHandle(m_RenderSurfaceMapper[resolve.depthHandle]); +#endif + m_Device->ResolveDepthIntoTexture (colorHandle, depthHandle); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_SetSurfaceFlags: + { + const GfxCmdSetSurfaceFlags& sf = stream.ReadValueType<GfxCmdSetSurfaceFlags>(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* surface = (ClientDeviceRenderSurface*)sf.surf.object; + RenderSurfaceHandle handle = surface->internalHandle; +#else + RenderSurfaceHandle handle(m_RenderSurfaceMapper[sf.surf]); +#endif + m_Device->SetSurfaceFlags(handle, sf.flags, sf.keepFlags); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_UploadTexture2D: + { + // Must copy since we stream data + GfxCmdUploadTexture2D upload = stream.ReadValueType<GfxCmdUploadTexture2D>(); + UInt8* srcData = ReadBufferData(stream, upload.srcSize); + m_Device->UploadTexture2D(upload.texture, upload.dimension, srcData, upload.srcSize, + upload.width, upload.height, upload.format, upload.mipCount, upload.uploadFlags, + upload.skipMipLevels, upload.usageMode, upload.colorSpace); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_UploadTextureSubData2D: + { + // Must copy since we stream data + GfxCmdUploadTextureSubData2D upload = stream.ReadValueType<GfxCmdUploadTextureSubData2D>(); + UInt8* srcData = ReadBufferData(stream, upload.srcSize); + m_Device->UploadTextureSubData2D(upload.texture, srcData, upload.srcSize, + upload.mipLevel, upload.x, upload.y, upload.width, upload.height, upload.format, upload.colorSpace); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_UploadTextureCube: + { + // Must copy since we stream data + GfxCmdUploadTextureCube upload = stream.ReadValueType<GfxCmdUploadTextureCube>(); + UInt8* srcData = ReadBufferData(stream, upload.srcSize); + m_Device->UploadTextureCube(upload.texture, srcData, upload.srcSize, + upload.faceDataSize, upload.size, upload.format, upload.mipCount, upload.uploadFlags, upload.colorSpace); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_UploadTexture3D: + { + // Must copy since we stream data + GfxCmdUploadTexture3D upload = stream.ReadValueType<GfxCmdUploadTexture3D>(); + UInt8* srcData = ReadBufferData(stream, upload.srcSize); + m_Device->UploadTexture3D(upload.texture, srcData, upload.srcSize, + upload.width, upload.height, upload.depth, upload.format, upload.mipCount, upload.uploadFlags); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_DeleteTexture: + { + TextureID texture = stream.ReadValueType<TextureID>(); + m_Device->DeleteTexture(texture); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_BeginFrame: + { + m_Device->BeginFrame(); + break; + } + case kGfxCmd_EndFrame: + { + m_Device->EndFrame(); + break; + } + case kGfxCmd_PresentFrame: + { + PROFILER_AUTO(gMTPresentFrame, NULL); + m_Device->PresentFrame(); + GfxCmdBool signalEvent = stream.ReadValueType<GfxCmdBool>(); + if (signalEvent) + SignalEvent(kEventTypePresent); + UnityMemoryBarrier(); + m_PresentFrameID = stream.ReadValueType<UInt32>(); + break; + } + case kGfxCmd_HandleInvalidState: + { + bool* success = stream.ReadValueType<bool*>(); + *success = m_Device->HandleInvalidState(); + Signal(); + break; + } + case kGfxCmd_FinishRendering: + { + m_Device->FinishRendering(); + Signal(); + break; + } + case kGfxCmd_InsertCPUFence: + { + stream.ReadReleaseData(); + m_CurrentCPUFence++; + break; + } + case kGfxCmd_ImmediateVertex: + { + const GfxCmdVector3& data = stream.ReadValueType<GfxCmdVector3>(); + m_Device->ImmediateVertex(data.x, data.y, data.z); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_ImmediateNormal: + { + const GfxCmdVector3& data = stream.ReadValueType<GfxCmdVector3>(); + m_Device->ImmediateNormal(data.x, data.y, data.z); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_ImmediateColor: + { + const GfxCmdVector4& data = stream.ReadValueType<GfxCmdVector4>(); + m_Device->ImmediateColor(data.x, data.y, data.z, data.w); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_ImmediateTexCoordAll: + { + const GfxCmdVector3& data = stream.ReadValueType<GfxCmdVector3>(); + m_Device->ImmediateTexCoordAll(data.x, data.y, data.z); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_ImmediateTexCoord: + { + const GfxCmdImmediateTexCoord& data = stream.ReadValueType<GfxCmdImmediateTexCoord>(); + m_Device->ImmediateTexCoord(data.unit, data.x, data.y, data.z); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_ImmediateBegin: + { + const GfxPrimitiveType& data = stream.ReadValueType<GfxPrimitiveType>(); + m_Device->ImmediateBegin(data); + break; + } + case kGfxCmd_ImmediateEnd: + { + m_Device->ImmediateEnd(); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_CaptureScreenshot: + { + const GfxCmdCaptureScreenshot& capture = stream.ReadValueType<GfxCmdCaptureScreenshot>(); + *capture.success = m_Device->CaptureScreenshot(capture.left, capture.bottom, capture.width, capture.height, capture.rgba32); + stream.ReadReleaseData(); + Signal(); + break; + } + case kGfxCmd_ReadbackImage: + { + const GfxCmdReadbackImage& read = stream.ReadValueType<GfxCmdReadbackImage>(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + *read.success = m_Device->ReadbackImage(read.image, read.left, read.bottom, read.width, read.height, read.destX, read.destY); +#else + //todo +#endif + stream.ReadReleaseData(); + Signal(); + break; + } + case kGfxCmd_GrabIntoRenderTexture: + { + const GfxCmdGrabIntoRenderTexture& grab = stream.ReadValueType<GfxCmdGrabIntoRenderTexture>(); +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceRenderSurface* surf = (ClientDeviceRenderSurface*)grab.rs.object; + RenderSurfaceHandle handle(surf ? surf->internalHandle.object : NULL); + ClientDeviceRenderSurface* surfZ = (ClientDeviceRenderSurface*)grab.rd.object; + RenderSurfaceHandle handleZ(surfZ ? surfZ->internalHandle.object : NULL); +#else + RenderSurfaceHandle handle(m_RenderSurfaceMapper[grab.rs]); + RenderSurfaceHandle handleZ(m_RenderSurfaceMapper[grab.rd]); +#endif + m_Device->GrabIntoRenderTexture(handle, handleZ, grab.x, grab.y, grab.width, grab.height); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_SetActiveContext: + { + void* ctx = stream.ReadValueType<void*>(); + m_Device->SetActiveContext (ctx); + Signal(); + break; + } + case kGfxCmd_ResetFrameStats: + { + m_Device->ResetFrameStats(); + break; + } + case kGfxCmd_BeginFrameStats: + { + m_Device->GetFrameStats().BeginFrameStats(); + stream.ResetReadWaitTime(); + break; + } + case kGfxCmd_EndFrameStats: + { + GfxDeviceStats& stats = m_Device->GetFrameStats(); + stats.EndRenderFrameStats(); + stats.m_RenderFrameTime -= stream.GetReadWaitTime(); + break; + } + case kGfxCmd_SaveDrawStats: + { + m_Device->SaveDrawStats(); + break; + } + case kGfxCmd_RestoreDrawStats: + { + m_Device->RestoreDrawStats(); + break; + } + case kGfxCmd_SynchronizeStats: + { + Mutex::AutoLock lock(m_StatsMutex); + m_Device->GetFrameStats().AccumulateUsedTextureUsage(); + m_FrameStats = m_Device->GetFrameStats(); + break; + } +#if UNITY_EDITOR + case kGfxCmd_SetAntiAliasFlag: + { + bool aa = stream.ReadValueType<GfxCmdBool>(); + m_Device->SetAntiAliasFlag(aa); + break; + } + case kGfxCmd_DrawUserPrimitives: + { + GfxCmdDrawUserPrimitives user = stream.ReadValueType<GfxCmdDrawUserPrimitives>(); + int dataSize = user.vertexCount * user.stride; + m_TempBuffer.resize_uninitialized(dataSize); + stream.ReadStreamingData(m_TempBuffer.data(), dataSize); + m_Device->DrawUserPrimitives(user.type, user.vertexCount, user.vertexChannels, m_TempBuffer.data(), user.stride); + break; + } +#endif + case kGfxCmd_Quit: + { + m_Quit = true; + Signal(); + break; + } + case kGfxCmd_InsertCustomMarker: + { + int marker = stream.ReadValueType<int>(); + m_Device->InsertCustomMarker (marker); + break; + } + case kGfxCmd_SetComputeBufferData: + { + ComputeBufferID buffer = stream.ReadValueType<ComputeBufferID>(); + size_t size = stream.ReadValueType<size_t>(); + DebugAssert (size); + m_TempBuffer.resize_uninitialized(size); + stream.ReadStreamingData(&m_TempBuffer[0], size); + m_Device->SetComputeBufferData (buffer, m_TempBuffer.data(), size); + break; + } + case kGfxCmd_GetComputeBufferData: + { + ComputeBufferID buffer = stream.ReadValueType<ComputeBufferID>(); + size_t size = stream.ReadValueType<size_t>(); + void* ptr = stream.ReadValueType<void*>(); + DebugAssert (size && ptr); + m_Device->GetComputeBufferData (buffer, ptr, size); + stream.ReadReleaseData(); + Signal(); + break; + } + case kGfxCmd_CopyComputeBufferCount: + { + ComputeBufferID srcBuffer = stream.ReadValueType<ComputeBufferID>(); + ComputeBufferID dstBuffer = stream.ReadValueType<ComputeBufferID>(); + UInt32 dstOffset = stream.ReadValueType<UInt32>(); + m_Device->CopyComputeBufferCount (srcBuffer, dstBuffer, dstOffset); + break; + } + case kGfxCmd_SetRandomWriteTargetTexture: + { + int index = stream.ReadValueType<int>(); + TextureID tid = stream.ReadValueType<TextureID>(); + m_Device->SetRandomWriteTargetTexture (index, tid); + break; + } + case kGfxCmd_SetRandomWriteTargetBuffer: + { + int index = stream.ReadValueType<int>(); + ComputeBufferID buffer = stream.ReadValueType<ComputeBufferID>(); + m_Device->SetRandomWriteTargetBuffer (index, buffer); + break; + } + case kGfxCmd_ClearRandomWriteTargets: + { + m_Device->ClearRandomWriteTargets (); + break; + } + case kGfxCmd_CreateComputeProgram: + { + ClientDeviceComputeProgram* handle = stream.ReadValueType<ClientDeviceComputeProgram*>(); + size_t size = stream.ReadValueType<size_t>(); + m_TempBuffer.resize_uninitialized(size); + stream.ReadStreamingData(&m_TempBuffer[0], size); + handle->internalHandle = m_Device->CreateComputeProgram (&m_TempBuffer[0], m_TempBuffer.size()); + break; + } + case kGfxCmd_DestroyComputeProgram: + { + ClientDeviceComputeProgram* handle = stream.ReadValueType<ClientDeviceComputeProgram*>(); + DebugAssert (handle); + m_Device->DestroyComputeProgram (handle->internalHandle); + UNITY_DELETE(handle, kMemGfxThread); + break; + } + case kGfxCmd_CreateComputeConstantBuffers: + { + unsigned count = stream.ReadValueType<unsigned>(); + Assert (count <= kMaxSupportedConstantBuffers); + ClientDeviceConstantBuffer* clientCBs[kMaxSupportedConstantBuffers]; + UInt32 cbSizes[kMaxSupportedConstantBuffers]; + for (unsigned i = 0; i < count; ++i) + { + clientCBs[i] = stream.ReadValueType<ClientDeviceConstantBuffer*>(); + DebugAssert (clientCBs[i]); + cbSizes[i] = clientCBs[i]->size; + } + + ConstantBufferHandle cbHandles[kMaxSupportedConstantBuffers]; + m_Device->CreateComputeConstantBuffers (count, cbSizes, cbHandles); + for (unsigned i = 0; i < count; ++i) + clientCBs[i]->internalHandle = cbHandles[i]; + + stream.ReadReleaseData(); + break; + } + case kGfxCmd_DestroyComputeConstantBuffers: + { + unsigned count = stream.ReadValueType<unsigned>(); + Assert (count <= kMaxSupportedConstantBuffers); + ConstantBufferHandle cbHandles[kMaxSupportedConstantBuffers]; + for (unsigned i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = stream.ReadValueType<ClientDeviceConstantBuffer*>(); + if (handle) + { + cbHandles[i] = handle->internalHandle; + UNITY_DELETE(handle, kMemGfxThread); + } + } + m_Device->DestroyComputeConstantBuffers (count, cbHandles); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_CreateComputeBuffer: + { + ComputeBufferID buffer = stream.ReadValueType<ComputeBufferID>(); + size_t count = stream.ReadValueType<size_t>(); + size_t stride = stream.ReadValueType<size_t>(); + UInt32 flags = stream.ReadValueType<UInt32>(); + m_Device->CreateComputeBuffer (buffer, count, stride, flags); + break; + } + case kGfxCmd_DestroyComputeBuffer: + { + ComputeBufferID buffer = stream.ReadValueType<ComputeBufferID>(); + m_Device->DestroyComputeBuffer (buffer); + break; + } + case kGfxCmd_UpdateComputeConstantBuffers: + { + unsigned count = stream.ReadValueType<unsigned>(); + Assert (count <= kMaxSupportedConstantBuffers); + UInt32 cbDirty = stream.ReadValueType<UInt32>(); + + ConstantBufferHandle cbHandles[kMaxSupportedConstantBuffers]; + UInt32 cbSizes[kMaxSupportedConstantBuffers]; + UInt32 cbOffsets[kMaxSupportedConstantBuffers]; + int bindPoints[kMaxSupportedConstantBuffers]; + for (unsigned i = 0; i < count; ++i) + { + ClientDeviceConstantBuffer* handle = stream.ReadValueType<ClientDeviceConstantBuffer*>(); + if (handle) + cbHandles[i] = handle->internalHandle; + cbSizes[i] = stream.ReadValueType<UInt32>(); + cbOffsets[i] = stream.ReadValueType<UInt32>(); + bindPoints[i] = stream.ReadValueType<int>(); + } + size_t dataSize = stream.ReadValueType<size_t>(); + DebugAssert (dataSize); + m_TempBuffer.resize_uninitialized(dataSize); + stream.ReadStreamingData(&m_TempBuffer[0], dataSize); + + m_Device->UpdateComputeConstantBuffers (count, cbHandles, cbDirty, dataSize, &m_TempBuffer[0], cbSizes, cbOffsets, bindPoints); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_UpdateComputeResources: + { + TextureID textures[kMaxSupportedComputeResources]; + int texBindPoints[kMaxSupportedComputeResources]; + unsigned samplers[kMaxSupportedComputeResources]; + ComputeBufferID inBuffers[kMaxSupportedComputeResources]; + int inBufferBindPoints[kMaxSupportedComputeResources]; + ComputeBufferID outBuffers[kMaxSupportedComputeResources]; + TextureID outTextures[kMaxSupportedComputeResources]; + UInt32 outBufferBindPoints[kMaxSupportedComputeResources]; + + unsigned texCount = stream.ReadValueType<unsigned>(); + for (int i = 0; i < texCount; ++i) + { + textures[i] = stream.ReadValueType<TextureID>(); + texBindPoints[i] = stream.ReadValueType<int>(); + } + unsigned samplerCount = stream.ReadValueType<unsigned>(); + for (int i = 0; i < samplerCount; ++i) + { + samplers[i] = stream.ReadValueType<unsigned>(); + } + unsigned inBufferCount = stream.ReadValueType<unsigned>(); + for (int i = 0; i < inBufferCount; ++i) + { + inBuffers[i] = stream.ReadValueType<ComputeBufferID>(); + inBufferBindPoints[i] = stream.ReadValueType<int>(); + } + unsigned outBufferCount = stream.ReadValueType<unsigned>(); + for (int i = 0; i < outBufferCount; ++i) + { + outBuffers[i] = stream.ReadValueType<ComputeBufferID>(); + outTextures[i] = stream.ReadValueType<TextureID>(); + outBufferBindPoints[i] = stream.ReadValueType<UInt32>(); + } + m_Device->UpdateComputeResources (texCount, textures, texBindPoints, samplerCount, samplers, inBufferCount, inBuffers, inBufferBindPoints, outBufferCount, outBuffers, outTextures, outBufferBindPoints); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_DispatchComputeProgram: + { + ClientDeviceComputeProgram* cp = stream.ReadValueType<ClientDeviceComputeProgram*>(); + DebugAssert (cp); + unsigned threadsX = stream.ReadValueType<unsigned>(); + unsigned threadsY = stream.ReadValueType<unsigned>(); + unsigned threadsZ = stream.ReadValueType<unsigned>(); + m_Device->DispatchComputeProgram (cp->internalHandle, threadsX, threadsY, threadsZ); + break; + } + case kGfxCmd_DrawNullGeometry: + { + GfxPrimitiveType topology = stream.ReadValueType<GfxPrimitiveType>(); + int vertexCount = stream.ReadValueType<int>(); + int instanceCount = stream.ReadValueType<int>(); + m_Device->DrawNullGeometry (topology, vertexCount, instanceCount); + break; + } + case kGfxCmd_DrawNullGeometryIndirect: + { + GfxPrimitiveType topology = stream.ReadValueType<GfxPrimitiveType>(); + ComputeBufferID bufferHandle = stream.ReadValueType<ComputeBufferID>(); + UInt32 bufferOffset = stream.ReadValueType<UInt32>(); + m_Device->DrawNullGeometryIndirect (topology, bufferHandle, bufferOffset); + break; + } + case kGfxCmd_VBO_UpdateVertexData: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo = stream.ReadValueType<ClientDeviceVBO>(); + ClientVertexBufferData client; + client = stream.ReadValueType<ClientVertexBufferData>(); + VertexBufferData data; + memcpy (data.channels, client.channels, sizeof(ChannelInfoArray)); + memcpy (data.streams, client.streams, sizeof(StreamInfoArray)); + data.bufferSize = client.bufferSize; + data.vertexCount = client.vertexCount; + data.buffer = (UInt8*)client.hasData; +#else + ClientDeviceVBO* vbo = stream.ReadValueType<ClientDeviceVBO*>(); + VertexBufferData data = stream.ReadValueType<VertexBufferData>(); +#endif + // Note! Buffer pointer is no longer valid but we use it to tell if data was written or not + if (data.buffer) + data.buffer = ReadBufferData(stream, data.bufferSize); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_VBOMapper[vbo.internalVBO]->UpdateVertexData(data); +#else + vbo->GetInternal()->UpdateVertexData(data); +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_VBO_UpdateIndexData: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo = stream.ReadValueType<ClientDeviceVBO>(); +#else + ClientDeviceVBO* vbo = stream.ReadValueType<ClientDeviceVBO*>(); +#endif + IndexBufferData data; + data.count = stream.ReadValueType<int>(); + data.hasTopologies = stream.ReadValueType<UInt32>(); + int bufferSize = data.count * kVBOIndexSize; + data.indices = ReadBufferData(stream, bufferSize); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_VBOMapper[vbo.internalVBO]->UpdateIndexData(data); +#else + vbo->GetInternal()->UpdateIndexData(data); +#endif + stream.ReadReleaseData(); + break; + } + case kGfxCmd_VBO_Draw: + { + PROFILER_AUTO(gMTDrawProf, NULL); + const GfxCmdVBODraw& data = stream.ReadValueType<GfxCmdVBODraw>(); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + Assert(data.vbo.internalVBO); + m_VBOMapper[data.vbo.internalVBO]->DrawVBO (data.channels, data.firstIndexByte, data.indexCount, + data.topology, data.firstVertex, data.vertexCount); +#else + Assert(data.vbo && data.vbo->GetInternal()); + data.vbo->GetInternal()->DrawVBO (data.channels, data.firstIndexByte, data.indexCount, + data.topology, data.firstVertex, data.vertexCount); +#endif + stream.ReadReleaseData(); + break; + } +#if GFX_ENABLE_DRAW_CALL_BATCHING + case kGfxCmd_VBO_DrawCustomIndexed: + { + PROFILER_AUTO(gMTDrawProf, NULL); + GfxCmdVBODrawCustomIndexed data = stream.ReadValueType<GfxCmdVBODrawCustomIndexed>(); + int dataSize = data.indexCount * kVBOIndexSize; + m_TempBuffer.resize_uninitialized(dataSize); + + stream.ReadStreamingData(m_TempBuffer.data(), dataSize); + data.vbo->GetInternal()->DrawCustomIndexed(data.channels, m_TempBuffer.data(), data.indexCount, + data.topology, data.vertexRangeBegin, data.vertexRangeEnd, data.drawVertexCount); + break; + } +#endif +#if UNITY_XENON + case kGfxCmd_VBO_AddExtraUvChannels: + { + GfxCmdVBOAddExtraUvChannels adduv = stream.ReadValueType<GfxCmdVBOAddExtraUvChannels>(); + m_TempBuffer.resize_uninitialized(adduv.size); + stream.ReadStreamingData(m_TempBuffer.data(), adduv.size); + adduv.vbo->GetInternal()->AddExtraUvChannels(m_TempBuffer.data(), adduv.size, adduv.extraUvCount); + break; + } + case kGfxCmd_VBO_CopyExtraUvChannels: + { + GfxCmdVBOCopyExtraUvChannels copyuv = stream.ReadValueType<GfxCmdVBOCopyExtraUvChannels>(); + copyuv.dest->GetInternal()->CopyExtraUvChannels(copyuv.source->GetInternal()); + break; + } +#endif + case kGfxCmd_VBO_Recreate: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo = stream.ReadValueType<ClientDeviceVBO>(); + m_VBOMapper[vbo.GetInternal()]->Recreate(); +#else + ClientDeviceVBO* vbo = stream.ReadValueType<ClientDeviceVBO*>(); + vbo->GetInternal()->Recreate(); +#endif + break; + } + case kGfxCmd_VBO_MapVertexStream: + { + // Release any old data + stream.ReadReleaseData(); + // This must be a reference since struct is updated by client thread + const GfxCmdVBOMapVertexStream& map = stream.ReadValueType<GfxCmdVBOMapVertexStream>(); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + const ClientDeviceVBO& vbo = map.vbo; +#else + ClientDeviceVBO* vbo = map.vbo; +#endif + int size = map.size; + void* dest = NULL; + VertexStreamData mappedVSD; + if (m_Device->IsValidState()) + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + if (m_VBOMapper[vbo.internalVBO]->MapVertexStream(mappedVSD, map.stream)) +#else + if (vbo->GetInternal()->MapVertexStream(mappedVSD, map.stream)) +#endif + { + Assert(mappedVSD.buffer); + dest = mappedVSD.buffer; + } + else + ErrorString("Failed to map vertex stream!"); + } + + // ReadStreamingData will skip data if dest is NULL + stream.ReadStreamingData(dest, size); + + if (dest) + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_VBOMapper[vbo.internalVBO]->UnmapVertexStream(map.stream); +#else + vbo->GetInternal()->UnmapVertexStream(map.stream); +#endif + } + break; + } + case kGfxCmd_VBO_SetVertexStreamMode: + { + GfxCmdVBOSetVertexStreamMode vsmode = stream.ReadValueType<GfxCmdVBOSetVertexStreamMode>(); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_VBOMapper[vsmode.vbo.GetInternal()]->SetVertexStreamMode(vsmode.stream, VBO::StreamMode(vsmode.mode)); +#else + vsmode.vbo->GetInternal()->SetVertexStreamMode(vsmode.stream, VBO::StreamMode(vsmode.mode)); +#endif + break; + } + case kGfxCmd_VBO_SetIndicesDynamic: + { + GfxCmdVBOSetSetIndicesDynamic vsdyn = stream.ReadValueType<GfxCmdVBOSetSetIndicesDynamic>(); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_VBOMapper[vsdyn.vbo.GetInternal()]->SetIndicesDynamic(vsdyn.dynamic); +#else + vsdyn.vbo->GetInternal()->SetIndicesDynamic(vsdyn.dynamic); +#endif + break; + } + case kGfxCmd_VBO_UseAsStreamOutput: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo = stream.ReadValueType<ClientDeviceVBO>(); + m_VBOMapper[vbo.internalVBO]->UseAsStreamOutput(); +#else + ClientDeviceVBO *vbo = stream.ReadValueType<ClientDeviceVBO *>(); + vbo->GetInternal()->UseAsStreamOutput(); +#endif + break; + } + case kGfxCmd_VBO_Constructor: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo = stream.ReadValueType<ClientDeviceVBO>(); + m_VBOMapper[vbo.internalVBO] = m_Device->CreateVBO(); +#else + ClientDeviceVBO* vbo = stream.ReadValueType<ClientDeviceVBO*>(); + vbo->internalVBO = m_Device->CreateVBO(); +#endif + break; + } + case kGfxCmd_VBO_Destructor: + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientDeviceVBO vbo = stream.ReadValueType<ClientDeviceVBO>(); + m_Device->DeleteVBO(m_VBOMapper[vbo.internalVBO]); +#else + ClientDeviceVBO* vbo = stream.ReadValueType<ClientDeviceVBO*>(); + m_Device->DeleteVBO(vbo->GetInternal()); + UNITY_DELETE( vbo, kMemGfxThread); +#endif + break; + } + case kGfxCmd_DynVBO_Chunk: + { + GfxCmdDynVboChunk chunk = m_CommandQueue->ReadValueType<GfxCmdDynVboChunk>(); + DynamicVBO& vbo = m_Device->GetDynamicVBO(); + void* vertexData; + void* indexData; + void** indexDataPtr = (chunk.actualIndices > 0) ? &indexData :NULL; + bool res = vbo.GetChunk(chunk.channelMask, chunk.actualVertices, chunk.actualIndices, DynamicVBO::RenderMode(chunk.renderMode), &vertexData, indexDataPtr); + if (!res) vertexData = indexData = NULL; + + m_CommandQueue->ReadStreamingData(vertexData, chunk.actualVertices * chunk.vertexStride); + if (chunk.actualIndices > 0) + m_CommandQueue->ReadStreamingData(indexData, chunk.actualIndices * kVBOIndexSize); + + if (res) vbo.ReleaseChunk(chunk.actualVertices, chunk.actualIndices); + + m_CommandQueue->ReadReleaseData(); + break; + } + case kGfxCmd_DynVBO_DrawChunk: + { + PROFILER_AUTO(gMTDrawDynamicProf, NULL); + const ChannelAssigns& channels = m_CommandQueue->ReadValueType<ChannelAssigns>(); + DynamicVBO& vbo = m_Device->GetDynamicVBO(); + vbo.DrawChunk(channels); + m_CommandQueue->ReadReleaseData(); + break; + } + case kGfxCmd_DisplayList_Call: + { + ThreadedDisplayList* dlist = m_CommandQueue->ReadValueType<ThreadedDisplayList*>(); + Assert(m_CallDepth < m_MaxCallDepth); + dlist->Patch(*m_CommandQueue); + m_PlaybackDisplayLists[m_CallDepth] = dlist; + m_CommandQueue = &m_PlaybackCommandQueues[m_CallDepth]; + m_CommandQueue->CreateReadOnly(dlist->GetData(), dlist->GetSize()); + m_CallDepth++; + break; + } + case kGfxCmd_DisplayList_End: + { + Assert(m_CallDepth > 0); + m_CallDepth--; + SAFE_RELEASE(m_PlaybackDisplayLists[m_CallDepth]); + if (m_CallDepth > 0) + m_CommandQueue = &m_PlaybackCommandQueues[m_CallDepth - 1]; + else + m_CommandQueue = m_MainCommandQueue; + break; + } + case kGfxCmd_QueryGraphicsCaps: + { + // no, really, we need to properly serialize this stuff with all the strings. this is just a hack to get running. + size_t offset = (char*)&gGraphicsCaps.vendorID - (char*)&gGraphicsCaps; + WritebackData(stream, &gGraphicsCaps.vendorID, sizeof(GraphicsCaps) - offset); + break; + } +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + case kGfxCmd_SetGpuProgramParameters: + { + ClientIDMapper::ClientID internalHandle = stream.ReadValueType<ClientIDMapper::ClientID>(); + GpuProgramParameters* gpu = new GpuProgramParameters; + Gfx_GpuProgramParameters gfxParams = stream.ReadValueType<Gfx_GpuProgramParameters>(); + int outSize = stream.ReadValueType<UInt32>(); + int strSize = stream.ReadValueType<UInt32>(); + + char* buffer = (char*)m_CommandQueue->GetReadDataPointer (outSize+strSize, 1); + char* strBuf = buffer + outSize; + gfxParams.GetOutput(*gpu, buffer, strBuf, strSize); + m_GpuProgramParametersMapper[internalHandle] = gpu; + break; + } +#endif +#if UNITY_EDITOR && UNITY_WIN + case kGfxCmd_CreateWindow: + { + ClientDeviceWindow* handle = stream.ReadValueType<ClientDeviceWindow*>(); + const GfxCmdCreateWindow& upload = stream.ReadValueType<GfxCmdCreateWindow>(); + handle->internalWindow = m_Device->CreateGfxWindow(upload.window, upload.width, upload.height, upload.depthFormat, upload.antiAlias); + break; + } + case kGfxCmd_SetActiveWindow: + { + ClientDeviceWindow* handle = stream.ReadValueType<ClientDeviceWindow*>(); + handle->GetInternal()->SetAsActiveWindow(); + break; + } + case kGfxCmd_WindowReshape: + { + ClientDeviceWindow* handle = stream.ReadValueType<ClientDeviceWindow*>(); + const GfxCmdWindowReshape& upload = stream.ReadValueType<GfxCmdWindowReshape>(); + handle->GetInternal()->Reshape(upload.width, upload.height, upload.depthFormat, upload.antiAlias); + Signal(); + break; + } + case kGfxCmd_WindowDestroy: + { + ClientDeviceWindow* handle = stream.ReadValueType<ClientDeviceWindow*>(); + delete handle->GetInternal(); + Signal(); + break; + } + case kGfxCmd_BeginRendering: + { + ClientDeviceWindow* handle = stream.ReadValueType<ClientDeviceWindow*>(); + handle->GetInternal()->BeginRendering(); + break; + } + case kGfxCmd_EndRendering: + { + ClientDeviceWindow* handle = stream.ReadValueType<ClientDeviceWindow*>(); + bool presentContent = stream.ReadValueType<GfxCmdBool>(); + handle->GetInternal()->EndRendering(presentContent); + GfxCmdBool signalEvent = stream.ReadValueType<GfxCmdBool>(); + if (signalEvent) + SignalEvent(kEventTypePresent); + break; + } +#endif + case kGfxCmd_AcquireThreadOwnership: + { + m_Device->AcquireThreadOwnership(); + SetRealGfxDeviceThreadOwnership(); + Signal(); + m_IsThreadOwner = true; + break; + } + case kGfxCmd_ReleaseThreadOwnership: + { + m_Device->ReleaseThreadOwnership(); + Signal(); + m_IsThreadOwner = false; + break; + } + + #if ENABLE_PROFILER + case kGfxCmd_BeginProfileEvent: + { + const char* name = stream.ReadValueType<const char*>(); + m_Device->BeginProfileEvent (name); + break; + } + case kGfxCmd_EndProfileEvent: + { + m_Device->EndProfileEvent (); + break; + } + case kGfxCmd_ProfileControl: + { + GfxDevice::GfxProfileControl ctrl = stream.ReadValueType<GfxDevice::GfxProfileControl>(); + unsigned param = stream.ReadValueType<unsigned>(); + + #if ENABLE_PROFILER + switch (ctrl) + { + case GfxDevice::kGfxProfBeginFrame: profiler_begin_frame_seperate_thread((ProfilerMode)param); break; + case GfxDevice::kGfxProfEndFrame: profiler_end_frame_seperate_thread(param); break; + case GfxDevice::kGfxProfDisableSampling: profiler_disable_sampling_seperate_thread(); break; + case GfxDevice::kGfxProfSetActive: profiler_set_active_seperate_thread(param!=0); break; + } + #else + AssertString("shouldn't be invoked"); + #endif + break; + } + case kGfxCmd_BeginTimerQueries: + { + PROFILER_AUTO(gMTBeginQueriesProf, NULL); + m_Device->BeginTimerQueries(); + // Implicitly poll queries + PollTimerQueries(); + break; + } + case kGfxCmd_EndTimerQueries: + { + PROFILER_AUTO(gMTEndQueriesProf, NULL); + m_Device->EndTimerQueries(); + stream.ReadReleaseData(); + break; + } + case kGfxCmd_TimerQuery_Constructor: + { + ClientDeviceTimerQuery* query = stream.ReadValueType<ClientDeviceTimerQuery*>(); + query->internalQuery = m_Device->CreateTimerQuery(); + break; + } + case kGfxCmd_TimerQuery_Destructor: + { + ClientDeviceTimerQuery* query = stream.ReadValueType<ClientDeviceTimerQuery*>(); + m_Device->DeleteTimerQuery(query->GetInternal()); + break; + } + case kGfxCmd_TimerQuery_Measure: + { + ClientDeviceTimerQuery* query = stream.ReadValueType<ClientDeviceTimerQuery*>(); + if (query->GetInternal()) + { + Assert(!query->pending); + query->pending = true; + query->GetInternal()->Measure(); + m_PolledTimerQueries.push_back(query); + } + break; + } + case kGfxCmd_TimerQuery_GetElapsed: + { + ClientDeviceTimerQuery* query = stream.ReadValueType<ClientDeviceTimerQuery*>(); + UInt32 flags = stream.ReadValueType<UInt32>(); + bool wait = (flags & GfxTimerQuery::kWaitRenderThread) != 0; + while (query->pending) + PollNextTimerQuery(wait); + if (flags & GfxTimerQuery::kWaitClientThread) + Signal(); + break; + } + #endif + + case kGfxCmd_DeleteGPUSkinningInfo: + { + GPUSkinningInfo *info = stream.ReadValueType<GPUSkinningInfo *>(); + m_Device->DeleteGPUSkinningInfo(info); + break; + } + case kGfxCmd_SkinOnGPU: + { + #if ENABLE_GFXDEVICE_REMOTE_PROCESS + // todo. + #else + GPUSkinningInfo *info = stream.ReadValueType<GPUSkinningInfo *>(); + ClientDeviceVBO* destVBO = stream.ReadValueType<ClientDeviceVBO*>(); + bool lastThisFrame = stream.ReadValueType<bool>(); + info->SetDestVBO(destVBO->GetInternal()); + + m_Device->SkinOnGPU(info, lastThisFrame); + #endif + break; + } + + case kGfxCmd_UpdateSkinSourceData: + { + GPUSkinningInfo *info = stream.ReadValueType<GPUSkinningInfo *>(); + void *vboData = stream.ReadValueType<void *>(); + BoneInfluence *bones = stream.ReadValueType<BoneInfluence *>(); + bool dirty = stream.ReadValueType<bool>(); + + m_Device->UpdateSkinSourceData(info, vboData, bones, dirty); + + break; + } + + case kGfxCmd_UpdateSkinBonePoses: + { + GPUSkinningInfo *info = stream.ReadValueType<GPUSkinningInfo *>(); + int boneSize = stream.ReadValueType<int>(); + Matrix4x4f *bones = stream.ReadArrayType<Matrix4x4f>(boneSize); + + m_Device->UpdateSkinBonePoses(info, boneSize, bones); + + break; + } + +#if UNITY_XENON + case kGfxCmd_RawVBO_Constructor: + { + ClientDeviceRawVBO* vbo = stream.ReadValueType<ClientDeviceRawVBO*>(); + UInt32 size = stream.ReadValueType<UInt32>(); + UInt32 flags = stream.ReadValueType<UInt32>(); + vbo->internalVBO = m_Device->CreateRawVBO(size, flags); + break; + } + case kGfxCmd_RawVBO_Destructor: + { + ClientDeviceRawVBO* vbo = stream.ReadValueType<ClientDeviceRawVBO*>(); + m_Device->DeleteRawVBO(vbo->GetInternal()); + delete vbo; + break; + } + case kGfxCmd_RawVBO_Next: + { + ClientDeviceRawVBO* vbo = stream.ReadValueType<ClientDeviceRawVBO*>(); + vbo->GetInternal()->Next(); + break; + } + case kGfxCmd_RawVBO_Write: + { + ClientDeviceRawVBO* vbo = stream.ReadValueType<ClientDeviceRawVBO*>(); + UInt32 offset = stream.ReadValueType<UInt32>(); + UInt32 size = stream.ReadValueType<UInt32>(); + void* dest = vbo->GetInternal()->GetMemory(offset, size); + stream.ReadStreamingData(dest, size); + break; + } + case kGfxCmd_RawVBO_InvalidateGpuCache: + { + ClientDeviceRawVBO* vbo = stream.ReadValueType<ClientDeviceRawVBO*>(); + vbo->GetInternal()->InvalidateGpuCache(); + break; + } + case kGfxCmd_EnablePersistDisplayOnQuit: + { + bool enabled = stream.ReadValueType<bool>(); + m_Device->EnablePersistDisplayOnQuit(enabled); + break; + } + case kGfxCmd_RegisterTexture2D: + { + TextureID tid = stream.ReadValueType<TextureID>(); + IDirect3DBaseTexture9* tex = stream.ReadValueType<IDirect3DBaseTexture9*>(); + m_Device->RegisterTexture2D(tid, tex); + break; + } + case kGfxCmd_PatchTexture2D: + { + TextureID tid = stream.ReadValueType<TextureID>(); + IDirect3DBaseTexture9* tex = stream.ReadValueType<IDirect3DBaseTexture9*>(); + m_Device->PatchTexture2D(tid, tex); + break; + } + case kGfxCmd_DeleteTextureEntryOnly: + { + TextureID tid = stream.ReadValueType<TextureID>(); + m_Device->DeleteTextureEntryOnly(tid); + break; + } + case kGfxCmd_UnbindAndDelayReleaseTexture: + { + IDirect3DBaseTexture9* tex = stream.ReadValueType<IDirect3DBaseTexture9*>(); + m_Device->UnbindAndDelayReleaseTexture(tex); + break; + } + case kGfxCmd_SetTextureWrapModes: + { + TextureID tid = stream.ReadValueType<TextureID>(); + TextureWrapMode wrapU = stream.ReadValueType<TextureWrapMode>(); + TextureWrapMode wrapV = stream.ReadValueType<TextureWrapMode>(); + TextureWrapMode wrapW = stream.ReadValueType<TextureWrapMode>(); + m_Device->SetTextureWrapModes(tid, wrapU, wrapV, wrapW); + break; + } + case kGfxCmd_OnLastFrameCallback: + { + m_Device->OnLastFrameCallback(); + break; + } + case kGfxCmd_VideoPlayer_Constructor: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + bool fullscreen = stream.ReadValueType<bool>(); + vp->internalVP = m_Device->CreateVideoPlayer(fullscreen); + break; + } + case kGfxCmd_VideoPlayer_Destructor: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + m_Device->DeleteVideoPlayer(vp->GetInternal()); + delete vp; + break; + } + case kGfxCmd_VideoPlayer_Render: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + vp->GetInternal()->Render(); + vp->isDead = vp->GetInternal()->IsDead(); + break; + } + case kGfxCmd_VideoPlayer_Pause: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + vp->GetInternal()->Pause(); + break; + } + case kGfxCmd_VideoPlayer_Resume: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + vp->GetInternal()->Resume(); + break; + } + case kGfxCmd_VideoPlayer_Stop: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + vp->GetInternal()->Stop(); + break; + } + case kGfxCmd_VideoPlayer_SetPlaySpeed: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + float speed = stream.ReadValueType<float>(); + vp->GetInternal()->SetPlaySpeed(speed); + break; + } + case kGfxCmd_VideoPlayer_Play: + { + ClientDeviceVideoPlayer* vp = stream.ReadValueType<ClientDeviceVideoPlayer*>(); + XMEDIA_XMV_CREATE_PARAMETERS xmvParams = stream.ReadValueType<XMEDIA_XMV_CREATE_PARAMETERS>(); + bool loop = stream.ReadValueType<bool>(); + if (xmvParams.createType == XMEDIA_CREATE_FROM_FILE) + { + size_t len = stream.ReadValueType<size_t>(); + char* fileName = (char*)_alloca(len); + stream.ReadStreamingData(fileName, len); + xmvParams.createFromFile.szFileName = fileName; + } + bool hasRect = stream.ReadValueType<bool>(); + RECT rect; + RECT* rectPtr = 0; + if (hasRect) + { + rect = stream.ReadValueType<RECT>(); + rectPtr = ▭ + } + vp->GetInternal()->Play(xmvParams, loop, rectPtr); + break; + } + case kGfxCmd_SetNullPixelShader: + { + m_Device->SetNullPixelShader(); + break; + } + case kGfxCmd_EnableHiZ: + { + HiZstate hiz_enable = stream.ReadValueType<HiZstate>(); + m_Device->SetHiZEnable( hiz_enable ); + break; + } + case kGfxCmd_SetHiStencilState: + { + bool hiStencilEnable = stream.ReadValueType<bool>(); + bool hiStencilWriteEnable = stream.ReadValueType<bool>(); + int hiStencilRef = stream.ReadValueType<int>(); + CompareFunction cmpFunc = stream.ReadValueType<CompareFunction>(); + + Assert( hiStencilRef < 256 ); + Assert( cmpFunc == kFuncEqual || cmpFunc == kFuncNotEqual ); + m_Device->SetHiStencilState( hiStencilEnable, hiStencilWriteEnable, hiStencilRef, cmpFunc ); + break; + } + case kGfxCmd_HiStencilFlush: + { + HiSflush flushtype = stream.ReadValueType<HiSflush>(); + m_Device->HiStencilFlush( flushtype ); + break; + } +#endif // UNITY_XENON + default: + ErrorString(Format("Gfx command not handled: %d (Last command: %d)", cmd, lastCmd)); + } + + GFXDEVICE_LOCKSTEP_WORKER(); + lastCmd = cmd; +} + +void GfxDeviceWorker::DoLockstep(int pos, int cmd) +{ + if (m_CallDepth == 0) + { + //printf_console("MT: worker pos %i cmd %i\n", pos, cmd); + m_LockstepSemaphore.Signal(); + } +} + +UInt8* GfxDeviceWorker::ReadBufferData (ThreadedStreamBuffer& stream, int size) +{ + int maxNonStreamedSize = stream.GetAllocatedSize() / 2; + if (size <= maxNonStreamedSize || m_CallDepth > 0) + { + stream.ReadReleaseData(); + void* data = stream.GetReadDataPointer(size, ThreadedStreamBuffer::kDefaultAlignment); + return reinterpret_cast<UInt8*>(data); + } + else + { + m_TempBuffer.resize_uninitialized(size); + stream.ReadStreamingData(m_TempBuffer.data(), size); + return m_TempBuffer.data(); + } +} + +void GfxDeviceWorker::WritebackData (ThreadedStreamBuffer& stream, const void* data, int size) +{ + const SInt32 maxSize = m_CommandQueue->ReadValueType<SInt32>(); + SInt32 writtenSize = 0; + do + { + void* chunkPtr = m_CommandQueue->GetReadDataPointer(sizeof(SInt32) + maxSize, ThreadedStreamBuffer::kDefaultAlignment); + SInt32* returnedSizePtr = static_cast<SInt32*>(chunkPtr); + void* returnedDataPtr = &returnedSizePtr[1]; + SInt32 chunkSize = std::min<SInt32>(size, maxSize); + if (chunkSize > 0) + memcpy(returnedDataPtr, static_cast<const UInt8*>(data) + writtenSize, chunkSize); + UnityMemoryBarrier(); + *returnedSizePtr = chunkSize; + stream.ReadReleaseData(); + writtenSize += size; + } while (writtenSize < size); +} + +#if ENABLE_PROFILER +void GfxDeviceWorker::PollTimerQueries() +{ + for (;;) + { + if (!PollNextTimerQuery(false)) + break; + } +} + +bool GfxDeviceWorker::PollNextTimerQuery(bool wait) +{ + if (m_PolledTimerQueries.empty()) + return false; + + ClientDeviceTimerQuery* query = m_PolledTimerQueries.front(); + UInt32 flags = wait ? GfxTimerQuery::kWaitAll : 0; + ProfileTimeFormat elapsed = query->GetInternal()->GetElapsed(flags); + if (elapsed != kInvalidProfileTime) + { + m_PolledTimerQueries.pop_front(); + // Make result available to client thread + query->elapsed = elapsed; + UnityMemoryBarrier(); + query->pending = false; + return true; + } + return false; +} +#endif + +#endif diff --git a/Runtime/GfxDevice/threaded/GfxDeviceWorker.h b/Runtime/GfxDevice/threaded/GfxDeviceWorker.h new file mode 100644 index 0000000..4129917 --- /dev/null +++ b/Runtime/GfxDevice/threaded/GfxDeviceWorker.h @@ -0,0 +1,135 @@ +#pragma once +#if ENABLE_MULTITHREADED_CODE + +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/threaded/WorkerIDMapper.h" +#include "Runtime/Utilities/dynamic_array.h" +#include "Runtime/Shaders/VBO.h" +#include "Runtime/Threads/Mutex.h" +#include "Runtime/Threads/Semaphore.h" +#include "Runtime/Threads/JobScheduler.h" +#include "External/shaderlab/Library/TextureBinding.h" +#include "Runtime/Filters/Mesh/MeshSkinning.h" +#include <deque> + + +#define GFXDEVICE_USE_CACHED_STATE 0 +#define DEBUG_GFXDEVICE_LOCKSTEP 0 + +#if DEBUG_GFXDEVICE_LOCKSTEP + #define GFXDEVICE_LOCKSTEP_CLIENT() { DoLockstep(); } + #define GFXDEVICE_LOCKSTEP_WORKER() { DoLockstep(pos, cmd); } +#else + #define GFXDEVICE_LOCKSTEP_CLIENT() + #define GFXDEVICE_LOCKSTEP_WORKER() +#endif + +struct ClientDeviceTimerQuery; +class ThreadedStreamBuffer; +class ThreadedDisplayList; +class Thread; + +class GfxDeviceWorker : public NonCopyable +{ +public: + GfxDeviceWorker(int maxCallDepth, ThreadedStreamBuffer* commandQueue); + ~GfxDeviceWorker(); + + GfxThreadableDevice* Startup(GfxDeviceRenderer renderer, bool threaded, bool forceRef); + + void WaitForSignal(); + void LockstepWait(); + + void GetLastFrameStats(GfxDeviceStats& stats); + + void CallImmediate(ThreadedDisplayList* dlist); + + enum EventType + { + kEventTypePresent, + kEventTypeTimerQueries, + kEventTypeCount + }; + + void WaitForEvent(EventType type); + + void WaitOnCPUFence(UInt32 fence); + + bool DidPresentFrame(UInt32 frameID) const; + + bool RunCommandIfDataIsAvailable(); + +private: + void SignalEvent(EventType type); + + static void* RunGfxDeviceWorker(void *data); + + void Run(); + void RunCommand(ThreadedStreamBuffer& stream); + void Signal(); + void DoLockstep(int pos, int cmd); + + UInt8* ReadBufferData(ThreadedStreamBuffer& stream, int size); + void WritebackData(ThreadedStreamBuffer& stream, const void* data, int size); + +#if ENABLE_PROFILER + void PollTimerQueries(); + bool PollNextTimerQuery(bool wait); +#endif + +#if GFXDEVICE_USE_CACHED_STATE + struct CachedState + { + CachedState(); + NormalizationMode normalization; + int backface; + Vector4f ambient; + int fogEnabled; + GfxFogParams fogParams; + }; +#endif + + int m_CallDepth; + int m_MaxCallDepth; + Thread* m_WorkerThread; + ThreadedStreamBuffer* m_CommandQueue; + ThreadedStreamBuffer* m_MainCommandQueue; + ThreadedStreamBuffer* m_PlaybackCommandQueues; + ThreadedDisplayList** m_PlaybackDisplayLists; + dynamic_array<UInt8> m_TempBuffer; + dynamic_array<SkinMeshInfo> m_ActiveSkins; + dynamic_array<VBO*> m_MappedSkinVBOs; + JobScheduler::JobGroupID m_SkinJobGroup; + Semaphore m_EventSemaphores[kEventTypeCount]; + Semaphore m_LockstepSemaphore; + Semaphore m_WaitSemaphore; + volatile UInt32 m_CurrentCPUFence; + volatile UInt32 m_PresentFrameID; + Mutex m_StatsMutex; + GfxDeviceStats m_FrameStats; + GfxThreadableDevice* m_Device; + bool m_IsThreadOwner; + bool m_Quit; +#if GFXDEVICE_USE_CACHED_STATE + CachedState m_Cached; +#endif +#if ENABLE_PROFILER + // Timer queries for GPU profiling + typedef std::deque<ClientDeviceTimerQuery*> TimerQueryList; + TimerQueryList m_PolledTimerQueries; +#endif +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + WorkerIDMapper<DeviceBlendState> m_BlendStateMapper; + WorkerIDMapper<DeviceDepthState> m_DepthStateMapper; + WorkerIDMapper<DeviceStencilState> m_StencilStateMapper; + WorkerIDMapper<DeviceRasterState> m_RasterStateMapper; + WorkerIDMapper<VBO> m_VBOMapper; + WorkerIDMapper<void> m_TextureCombinerMapper; + WorkerIDMapper<void> m_RenderSurfaceMapper; + WorkerIDMapper<GpuProgramParameters> m_GpuProgramParametersMapper; + WorkerIDMapper<GpuProgram> m_GpuProgramMapper; + ClientIDMapper m_GpuProgramClientMapper; +#endif +}; + +#endif diff --git a/Runtime/GfxDevice/threaded/GfxReturnStructs.cpp b/Runtime/GfxDevice/threaded/GfxReturnStructs.cpp new file mode 100644 index 0000000..dd90789 --- /dev/null +++ b/Runtime/GfxDevice/threaded/GfxReturnStructs.cpp @@ -0,0 +1,239 @@ +#include "UnityPrefix.h" +#include "GfxReturnStructs.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" + +static int AppendString(dynamic_array<char>& strBuf, const char* str) +{ + int strLen = strlen(str); + int strOfs = strBuf.size(); + strBuf.resize_uninitialized(strOfs + strLen + 1); + std::copy(str, str + strLen + 1, &strBuf[strOfs]); + return strOfs; +} + +static const char* GetStringAtOffset(int offset, const char* strBuf, int strBufLen) +{ + if (offset >= 0 && offset < strBufLen) + return &strBuf[offset]; + ErrorString("Invalid offset in GetStringAtOffset()"); + return ""; +} + +GfxRet_ValueParameter::GfxRet_ValueParameter(const GpuProgramParameters::ValueParameter& src, dynamic_array<char>& strBuf) +: index(src.m_Index) +, arraySize(src.m_ArraySize) +, rowCount(src.m_RowCount) +, colCount(src.m_ColCount) +{ + nameStrOfs = AppendString(strBuf, src.m_Name.GetName()); +} + +void GfxRet_ValueParameter::ToValueParameter(GpuProgramParameters::ValueParameter& dest, const char* strBuf, int strBufLen) const +{ + dest.m_Name = ShaderLab::Property(GetStringAtOffset(nameStrOfs, strBuf, strBufLen)); + dest.m_Index = index; + dest.m_ArraySize = arraySize; + dest.m_RowCount = rowCount; + dest.m_ColCount = colCount; +} + + +GfxRet_TextureParameter::GfxRet_TextureParameter(const GpuProgramParameters::TextureParameter& src, dynamic_array<char>& strBuf) +: index(src.m_Index) +, samplerIndex(src.m_SamplerIndex) +, dim(src.m_Dim) +{ + nameStrOfs = AppendString(strBuf, src.m_Name.GetName()); +} + +void GfxRet_TextureParameter::ToTextureParameter(GpuProgramParameters::TextureParameter& dest, const char* strBuf, int strBufLen) const +{ + dest.m_Name = ShaderLab::Property(GetStringAtOffset(nameStrOfs, strBuf, strBufLen)); + dest.m_Index = index; + dest.m_SamplerIndex = samplerIndex; + dest.m_Dim = dim; +} + + +GfxRet_BufferParameter::GfxRet_BufferParameter(const GpuProgramParameters::BufferParameter& src, dynamic_array<char>& strBuf) +: index(src.m_Index) +{ + nameStrOfs = AppendString(strBuf, src.m_Name.GetName()); +} + +void GfxRet_BufferParameter::ToBufferParameter(GpuProgramParameters::BufferParameter& dest, const char* strBuf, int strBufLen) const +{ + dest.m_Name = ShaderLab::Property(GetStringAtOffset(nameStrOfs, strBuf, strBufLen)); + dest.m_Index = index; +} + +GfxRet_ShaderError::GfxRet_ShaderError(const ShaderErrors::ShaderError& src, dynamic_array<char>& strBuf) +: line(src.line) +, warning(src.warning) +, programError(src.programError) +{ + messageStrOfs = AppendString(strBuf, src.message.c_str()); + messageDetailsStrOfs = AppendString(strBuf, src.messageDetails.c_str()); +} + +void GfxRet_ShaderError::ToShaderError(ShaderErrors::ShaderError& dest, const char* strBuf, int strBufLen) const +{ + dest.message = GetStringAtOffset(messageStrOfs, strBuf, strBufLen); + dest.messageDetails = GetStringAtOffset(messageDetailsStrOfs, strBuf, strBufLen); + dest.line = line; + dest.warning = warning; + dest.programError = programError; +} + + +GfxRet_ChannelAssigns::GfxRet_ChannelAssigns(const ChannelAssigns& src) +: targetMap(src.m_TargetMap) +, sourceMap(src.m_SourceMap) +, directlyWired(src.m_DirectlyWired) +{ + std::copy(src.m_Channels, src.m_Channels + kVertexCompCount, channels); +}; + +void GfxRet_ChannelAssigns::ToChannelAssigns(ChannelAssigns& dest) const +{ + dest.m_TargetMap = targetMap; + dest.m_SourceMap = sourceMap; + dest.m_DirectlyWired = directlyWired; + std::copy(channels, channels + kVertexCompCount, dest.m_Channels); +} + +Gfx_GpuProgramParameters::Gfx_GpuProgramParameters() +: valueParameterCount(0) +, valueParameterOffset(0) +, textureParameterCount(0) +, textureParameterOffset(0) +, bufferParameterCount(0) +, bufferParameterOffset(0) +{ +} + +Gfx_GpuProgramParameters::Gfx_GpuProgramParameters(const GpuProgramParameters& params, dynamic_array<UInt8>& outBuf, dynamic_array<char> &strBuf) +{ + const GpuProgramParameters::ValueParameterArray& srcValueParams = params.GetValueParams(); + valueParameterCount = srcValueParams.size(); + valueParameterOffset = outBuf.size(); + outBuf.resize_uninitialized(valueParameterOffset + valueParameterCount * sizeof(GfxRet_ValueParameter)); + GfxRet_ValueParameter* valueParams = reinterpret_cast<GfxRet_ValueParameter*>(outBuf.data() + valueParameterOffset); + for (int i = 0; i < valueParameterCount; ++i) + valueParams[i] = GfxRet_ValueParameter(srcValueParams[i], strBuf); + + const GpuProgramParameters::TextureParameterList& srcTextureParams = params.GetTextureParams(); + textureParameterCount = srcTextureParams.size(); + textureParameterOffset = outBuf.size(); + outBuf.resize_uninitialized(textureParameterOffset + textureParameterCount * sizeof(GfxRet_TextureParameter)); + GfxRet_TextureParameter* textureParams = reinterpret_cast<GfxRet_TextureParameter*>(outBuf.data() + textureParameterOffset); + for (int i = 0; i < textureParameterCount; ++i) + textureParams[i] = GfxRet_TextureParameter(srcTextureParams[i], strBuf); + + const GpuProgramParameters::BufferParameterArray& srcBufferParams = params.GetBufferParams(); + bufferParameterCount = srcBufferParams.size(); + bufferParameterOffset = outBuf.size(); + outBuf.resize_uninitialized(bufferParameterOffset + bufferParameterCount * sizeof(GfxRet_BufferParameter)); + GfxRet_BufferParameter* bufferParams = reinterpret_cast<GfxRet_BufferParameter*>(outBuf.data() + bufferParameterOffset); + for (int i = 0; i < bufferParameterCount; ++i) + bufferParams[i] = GfxRet_BufferParameter(srcBufferParams[i], strBuf); +} + +void Gfx_GpuProgramParameters::GetOutput(GpuProgramParameters& outParams, const char* dataBegin, const char* stringBuffer, int stringBufferLength) const +{ + const GfxRet_ValueParameter* valueParams = reinterpret_cast<const GfxRet_ValueParameter*>(dataBegin + valueParameterOffset); + for (int i = 0; i < valueParameterCount; ++i) + { + GpuProgramParameters::ValueParameter param; + valueParams[i].ToValueParameter(param, stringBuffer, stringBufferLength); + outParams.AddValueParam(param); + } + + const GfxRet_TextureParameter* textureParams = reinterpret_cast<const GfxRet_TextureParameter*>(dataBegin + textureParameterOffset); + for (int i = 0; i < textureParameterCount; ++i) + { + GpuProgramParameters::TextureParameter param; + textureParams[i].ToTextureParameter(param, stringBuffer, stringBufferLength); + outParams.AddTextureParam(param); + } +} + +GfxRet_CreateGpuProgram::GfxRet_CreateGpuProgram(const CreateGpuProgramOutput& output, dynamic_array<UInt8>& outBuf) +: channelAssignsCount(0) +, channelAssignsOffset(0) +, shaderErrorCount(0) +, shaderErrorOffset(0) +, stringBufferLength(0) +, stringBufferOffset(0) +{ + perFogModeParamsEnabled = output.GetPerFogModeParamsEnabled(); + + // Shared buffer for strings + dynamic_array<char> strBuf; + + if (output.GetParams()) + { + params = Gfx_GpuProgramParameters(*output.GetParams(), outBuf, strBuf); + } + + if (output.GetChannelAssigns()) + { + channelAssignsCount = 1; + channelAssignsOffset = outBuf.size(); + outBuf.resize_uninitialized(channelAssignsOffset + channelAssignsCount * sizeof(GfxRet_ChannelAssigns)); + GfxRet_ChannelAssigns* channelAssigns = reinterpret_cast<GfxRet_ChannelAssigns*>(outBuf.data() + channelAssignsOffset); + channelAssigns[0] = GfxRet_ChannelAssigns(*output.GetChannelAssigns()); + } + + if (output.GetShaderErrors()) + { + const ShaderErrors::ErrorContainer& srcShaderErrors = output.GetShaderErrors()->GetErrors(); + shaderErrorCount = srcShaderErrors.size(); + shaderErrorOffset = outBuf.size(); + outBuf.resize_uninitialized(shaderErrorOffset + shaderErrorCount * sizeof(GfxRet_ShaderError)); + GfxRet_ShaderError* shaderErrors = reinterpret_cast<GfxRet_ShaderError*>(outBuf.data() + shaderErrorOffset); + ShaderErrors::ErrorContainer::const_iterator srcIt = srcShaderErrors.begin(); + for (int i = 0; i < shaderErrorCount; ++srcIt, ++i) + new (shaderErrors + i) GfxRet_ShaderError(*srcIt, strBuf); + Assert(srcIt == srcShaderErrors.end()); + } + + stringBufferLength = strBuf.size(); + stringBufferOffset = outBuf.size(); + outBuf.resize_uninitialized(stringBufferOffset + stringBufferLength); + std::copy(strBuf.begin(), strBuf.end(), outBuf.begin() + stringBufferOffset); +} + +void GfxRet_CreateGpuProgram::GetOutput(CreateGpuProgramOutput& output) const +{ + output.SetPerFogModeParamsEnabled(perFogModeParamsEnabled); + + const char* dataBegin = reinterpret_cast<const char*>(this); + const char* stringBuffer = dataBegin + stringBufferOffset; + + if (params.valueParameterCount > 0 || params.textureParameterCount > 0 || params.bufferParameterCount > 0) + { + GpuProgramParameters& outParams = output.CreateParams(); + params.GetOutput(outParams, dataBegin, stringBuffer, stringBufferLength); + } + + if (channelAssignsCount > 0) + { + Assert(channelAssignsCount == 1); + const GfxRet_ChannelAssigns* channelAssigns = reinterpret_cast<const GfxRet_ChannelAssigns*>(dataBegin + channelAssignsOffset); + channelAssigns[0].ToChannelAssigns(output.CreateChannelAssigns()); + } + + if (shaderErrorCount > 0) + { + ShaderErrors& outErrors = output.CreateShaderErrors(); + + const GfxRet_ShaderError* shaderErrors = reinterpret_cast<const GfxRet_ShaderError*>(dataBegin + shaderErrorOffset); + for (int i = 0; i < shaderErrorCount; ++i) + { + ShaderErrors::ShaderError err; + shaderErrors[i].ToShaderError(err, stringBuffer, stringBufferLength); + outErrors.AddShaderError(err.message, err.messageDetails, err.line, err.warning, err.programError); + } + } +} diff --git a/Runtime/GfxDevice/threaded/GfxReturnStructs.h b/Runtime/GfxDevice/threaded/GfxReturnStructs.h new file mode 100644 index 0000000..f3e7b47 --- /dev/null +++ b/Runtime/GfxDevice/threaded/GfxReturnStructs.h @@ -0,0 +1,122 @@ +#pragma once + +#include "Runtime/GfxDevice/GpuProgram.h" +#include "Runtime/Utilities/dynamic_array.h" +#include "External/shaderlab/Library/ShaderLabErrors.h" +class ChannelAssigns; +namespace ShaderLab { class SubProgram; } + +struct GfxRet_ValueParameter +{ + GfxRet_ValueParameter(const GpuProgramParameters::ValueParameter& src, dynamic_array<char>& strBuf); + void ToValueParameter(GpuProgramParameters::ValueParameter& dest, const char* strBuf, int strBufLen) const; + + int nameStrOfs; + int index; + int arraySize; + UInt8 rowCount; + UInt8 colCount; +}; + +struct GfxRet_TextureParameter +{ + GfxRet_TextureParameter(const GpuProgramParameters::TextureParameter& src, dynamic_array<char>& strBuf); + void ToTextureParameter(GpuProgramParameters::TextureParameter& dest, const char* strBuf, int strBufLen) const; + + int nameStrOfs; + int index; + int samplerIndex; + TextureDimension dim; +}; + +struct GfxRet_BufferParameter +{ + GfxRet_BufferParameter(const GpuProgramParameters::BufferParameter& src, dynamic_array<char>& strBuf); + void ToBufferParameter(GpuProgramParameters::BufferParameter& dest, const char* strBuf, int strBufLen) const; + + int nameStrOfs; + int index; +}; + +struct GfxRet_ChannelAssigns +{ + GfxRet_ChannelAssigns(const ChannelAssigns& src); + void ToChannelAssigns(ChannelAssigns& dest) const; + + UInt32 targetMap; + UInt32 sourceMap; + SInt8 channels[kVertexCompCount]; + bool directlyWired; +}; + +struct GfxRet_ShaderError +{ + GfxRet_ShaderError(const ShaderErrors::ShaderError& src, dynamic_array<char>& strBuf); + void ToShaderError(ShaderErrors::ShaderError& dest, const char* strBuf, int strBufLen) const; + + int messageStrOfs; + int messageDetailsStrOfs; + int line; + bool warning; + bool programError; +}; + +struct Gfx_GpuProgramParameters +{ + Gfx_GpuProgramParameters(); + Gfx_GpuProgramParameters(const GpuProgramParameters& params, dynamic_array<UInt8>& outBuf, dynamic_array<char> &strBuf); + + //void GetOutput(GpuProgramParameters &output, const char* strBuf, int strBufLen) const; + void GetOutput(GpuProgramParameters& outParams, const char* dataBegin, const char* strBuf, int strBufLen) const; + + int valueParameterCount; + int valueParameterOffset; + + // Array of GfxRet_TextureParameter + int textureParameterCount; + int textureParameterOffset; + + // Array of GfxRet_BufferParameter + int bufferParameterCount; + int bufferParameterOffset; +}; + +struct GfxRet_CreateGpuProgram +{ + GfxRet_CreateGpuProgram(const CreateGpuProgramOutput& output, dynamic_array<UInt8>& outBuf); + + void GetOutput(CreateGpuProgramOutput& output) const; + + bool perFogModeParamsEnabled; + + Gfx_GpuProgramParameters params; + /* + // Array of GfxRet_ValueParameter + int valueParameterCount; + int valueParameterOffset; + + // Array of GfxRet_TextureParameter + int textureParameterCount; + int textureParameterOffset; + + // Array of GfxRet_BufferParameter + int bufferParameterCount; + int bufferParameterOffset; + */ + // Array of GfxRet_ChannelAssigns + int channelAssignsCount; + int channelAssignsOffset; + + // Array of GfxRet_ShaderError + int shaderErrorCount; + int shaderErrorOffset; + + // Shared buffer of string data + int stringBufferLength; + int stringBufferOffset; + + ClientIDMapper::ClientID gpuProgram; + + PropertyNamesSet names; +}; + diff --git a/Runtime/GfxDevice/threaded/ThreadedDeviceStates.h b/Runtime/GfxDevice/threaded/ThreadedDeviceStates.h new file mode 100644 index 0000000..a36a2fa --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedDeviceStates.h @@ -0,0 +1,134 @@ +#pragma once +#if ENABLE_MULTITHREADED_CODE + +#include "Runtime/GfxDevice/GfxDeviceObjects.h" +#include "Runtime/GfxDevice/GfxDeviceResources.h" +#include "Runtime/GfxDevice/threaded/ClientIDMapper.h" +#include "Runtime/Filters/Mesh/VertexData.h" +#include "Runtime/Graphics/RenderSurface.h" + +namespace ShaderLab { struct TextureBinding; } +namespace xenon { class IVideoPlayer; } +class VBO; +class RawVBO; +class GfxTimerQuery; +class GfxDeviceWindow; + +struct ClientDeviceRect +{ + ClientDeviceRect() : x(0), y(0), width(0), height(0) {} + int x; + int y; + int width; + int height; +}; + +struct ClientDeviceBlendState : public DeviceBlendState +{ + ClientDeviceBlendState(const GfxBlendState& src) : DeviceBlendState(src), internalState(NULL) {} + ClientIDWrapper(DeviceBlendState) internalState; +}; + +struct ClientDeviceDepthState : public DeviceDepthState +{ + ClientDeviceDepthState(const GfxDepthState& src) : DeviceDepthState(src), internalState(NULL) {} + ClientIDWrapper(DeviceDepthState) internalState; +}; + +struct ClientDeviceStencilState : public DeviceStencilState +{ + ClientDeviceStencilState(const GfxStencilState& src) : DeviceStencilState(src), internalState(NULL) {} + ClientIDWrapper(DeviceStencilState) internalState; +}; + +struct ClientDeviceRasterState : public DeviceRasterState +{ + ClientDeviceRasterState(const GfxRasterState& src) : DeviceRasterState(src), internalState(NULL) {} + ClientIDWrapper(DeviceRasterState) internalState; +}; + +struct ClientDeviceTextureCombiners +{ + ClientIDWrapperHandle(TextureCombinersHandle) internalHandle; + ShaderLab::TextureBinding* bindings; + int count; +}; + +struct ClientDeviceRenderSurface : RenderSurfaceBase +{ + enum SurfaceState { kInitial, kCleared, kRendered, kResolved }; + ClientDeviceRenderSurface(int w, int h) { RenderSurfaceBase_Init(*this); width=w; height=h; zformat=kDepthFormatNone; state=kInitial; } + ClientIDWrapperHandle(RenderSurfaceHandle) internalHandle; + DepthBufferFormat zformat; + SurfaceState state; +}; + +struct ClientDeviceVBO +{ + ClientDeviceVBO() : internalVBO(NULL) {} + +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + ClientIDWrapper(VBO) GetInternal() { return internalVBO; } +#else + VBO* GetInternal() { return const_cast<VBO*>(internalVBO); } +#endif + volatile ClientIDWrapper(VBO) internalVBO; +}; + +struct ClientVertexBufferData +{ + ChannelInfoArray channels; + StreamInfoArray streams; + int bufferSize; + int vertexCount; + int hasData; +}; + +struct ClientDeviceTimerQuery +{ + ClientDeviceTimerQuery() : internalQuery(NULL), elapsed(0), pending(false) {} + GfxTimerQuery* GetInternal() { return const_cast<GfxTimerQuery*>(internalQuery); } + volatile GfxTimerQuery* internalQuery; + volatile UInt64 elapsed; + volatile bool pending; +}; + +struct ClientDeviceWindow +{ + ClientDeviceWindow() : internalWindow(NULL) {} + GfxDeviceWindow* GetInternal() { return const_cast<GfxDeviceWindow*>(internalWindow); } + volatile GfxDeviceWindow* internalWindow; +}; + +struct ClientDeviceConstantBuffer +{ + ClientDeviceConstantBuffer(UInt32 sz) : size(sz) {} + ConstantBufferHandle internalHandle; + UInt32 size; +}; + +struct ClientDeviceComputeProgram +{ + ClientDeviceComputeProgram() {} + ComputeProgramHandle internalHandle; +}; + + +#if UNITY_XENON +struct ClientDeviceRawVBO +{ + ClientDeviceRawVBO() : internalVBO(NULL) {} + RawVBO* GetInternal() { return const_cast<RawVBO*>(internalVBO); } + volatile RawVBO* internalVBO; +}; + +struct ClientDeviceVideoPlayer +{ + ClientDeviceVideoPlayer() : internalVP(NULL), isDead(false) {} + xenon::IVideoPlayer* GetInternal() { return const_cast<xenon::IVideoPlayer*>(internalVP); } + volatile xenon::IVideoPlayer* internalVP; + volatile bool isDead; +}; +#endif + +#endif diff --git a/Runtime/GfxDevice/threaded/ThreadedDisplayList.cpp b/Runtime/GfxDevice/threaded/ThreadedDisplayList.cpp new file mode 100644 index 0000000..27fa38e --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedDisplayList.cpp @@ -0,0 +1,442 @@ +#include "UnityPrefix.h" + +#if ENABLE_MULTITHREADED_CODE + +#define DEBUG_GPU_PARAMETER_PATCHING (!UNITY_RELEASE) + +#include "Runtime/GfxDevice/threaded/ThreadedDisplayList.h" +#include "Runtime/GfxDevice/threaded/GfxDeviceClient.h" +#include "Runtime/GfxDevice/threaded/GfxDeviceWorker.h" +#include "Runtime/GfxDevice/threaded/GfxCommands.h" +#include "Runtime/Threads/ThreadedStreamBuffer.h" +#include "External/shaderlab/Library/properties.h" +#include "External/shaderlab/Library/shaderlab.h" + +DisplayListContext::DisplayListContext() +{ + ClearState(); +} + +void DisplayListContext::ClearState() +{ + recordFailed = false; + hasSetShaders = false; + memset(shadersActive, 0, sizeof(shadersActive)); + fogParamsOffset = kFogParamsNone; +} + +void DisplayListContext::Reset() +{ + ClearState(); + commandQueue.ResetGrowable(); + patchInfo.Reset(); +} + + +ThreadedDisplayList::ThreadedDisplayList(const void* data, size_t size, const DisplayListContext& context) + : m_ListData(data, size, context.patchInfo) +{ + m_HasSetShaders = context.hasSetShaders; + memcpy(m_ShadersActive, context.shadersActive, sizeof(m_ShadersActive)); + + if (context.fogParamsOffset >= 0) + m_FogParamsOffset = CopyClientData(context.fogParamsOffset, sizeof(GfxFogParams)); + else + m_FogParamsOffset = context.fogParamsOffset; +} + +ThreadedDisplayList::~ThreadedDisplayList() +{ +} + +void ThreadedDisplayList::Call() +{ + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + if (device.IsSerializing()) + { + ThreadedStreamBuffer& queue = *device.GetCommandQueue(); + AddRef(); // Release again when call is finished + queue.WriteValueType<GfxCommand>(kGfxCmd_DisplayList_Call); + queue.WriteValueType<ThreadedDisplayList*>(this); + m_ListData.WriteParameters(queue); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + m_ListData.PatchImmediate(); + device.GetGfxDeviceWorker()->CallImmediate(this); + } + UpdateClientDevice(device); +} + +void ThreadedDisplayList::Patch(ThreadedStreamBuffer& queue) +{ + m_ListData.Patch(queue); +} + +int ThreadedDisplayList::CopyClientData(int offset, int size) +{ + int newOffset = m_ClientData.AppendData(&m_ListData.m_Buffer[offset], size); + int relativeOffset = newOffset - offset; + for (int pt = 0; pt < GfxPatch::kTypeCount; pt++) + { + GfxPatch::Type patchType = GfxPatch::Type(pt); + int patchCount = m_ListData.m_PatchInfo.GetPatchCount(patchType); + for (int i = 0; i < patchCount; i++) + { + const GfxPatch& srcPatch = m_ListData.m_PatchInfo.GetPatch(patchType, i); + int patchOffset = srcPatch.patchOffset; + if (patchOffset >= offset && patchOffset < offset + size) + { + GfxPatch patch = srcPatch; + patch.patchOffset += relativeOffset; + m_ClientData.m_PatchInfo.AddPatch(patchType, patch); + } + } + } + return newOffset; +} + +void ThreadedDisplayList::UpdateClientDevice(GfxDeviceClient& device) +{ + if (!m_ClientData.m_Buffer.empty()) + m_ClientData.PatchImmediate(); + + if (m_FogParamsOffset != DisplayListContext::kFogParamsNone) + { + if (m_FogParamsOffset != DisplayListContext::kFogParamsDisable) + { + const void* data = &m_ClientData.m_Buffer[m_FogParamsOffset]; + const GfxFogParams& fogParams = *static_cast<const GfxFogParams*>(data); + device.UpdateFogEnabled(fogParams); + } + else + device.UpdateFogDisabled(); + } + + if (m_HasSetShaders) + device.UpdateShadersActive(m_ShadersActive); +} + +void ThreadedDisplayList::DoLockstep() +{ + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + device.DoLockstep(); +} + +ThreadedDisplayList::PatchableData::PatchableData(const void* data, size_t size, const GfxPatchInfo& patchInfo) + : m_PatchInfo(patchInfo) +{ + m_Buffer.resize_uninitialized(size); + memcpy(m_Buffer.begin(), data, size); +} + +ThreadedDisplayList::PatchableData::PatchableData() +{ +} + +void ThreadedDisplayList::PatchableData::CheckParametersValid() +{ +#if DEBUG_GPU_PARAMETER_PATCHING + BuiltinShaderParamValues& builtinParams = GetGfxDevice().GetBuiltinParamValues(); + using namespace ShaderLab; + + FastPropertyName name; + size_t floatCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeFloat); + for (size_t i = 0; i < floatCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeFloat, i); + const float* src = reinterpret_cast<const float*>(patch.source); + name.index = patch.nameIndex; + if (name.IsBuiltin()) + { + Assert(name.IsBuiltinVector()); + const float& val = *builtinParams.GetVectorParam(BuiltinShaderVectorParam(name.BuiltinIndex())).GetPtr(); + Assert(&val == src); + } + else + { + const float& val = g_GlobalProperties->GetFloat(name); + Assert(src == NULL || &val == src); + } + } + + size_t vectorCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeVector); + for (size_t i = 0; i < vectorCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeVector, i); + const Vector4f* src = reinterpret_cast<const Vector4f*>(patch.source); + name.index = patch.nameIndex; + if (name.IsBuiltin()) + { + Assert(name.IsBuiltinVector()); + const Vector4f& vec = builtinParams.GetVectorParam(BuiltinShaderVectorParam(name.BuiltinIndex())); + Assert(&vec == src); + } + else + { + const Vector4f& vec = g_GlobalProperties->GetVector(name); + Assert(src == NULL || &vec == src); + } + } + + size_t matrixCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeMatrix); + for (size_t i = 0; i < matrixCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeMatrix, i); + const Matrix4x4f* src = reinterpret_cast<const Matrix4x4f*>(patch.source); + name.index = patch.nameIndex; + if (name.IsBuiltin()) + { + Assert(name.IsBuiltinMatrix()); + const Matrix4x4f* mat = &builtinParams.GetMatrixParam(BuiltinShaderMatrixParam(name.BuiltinIndex())); + Assert(mat == src); + } + else + { + int count = 0; + const Matrix4x4f* mat = reinterpret_cast<const Matrix4x4f*>(g_GlobalProperties->GetValueProp (name, &count)); + Assert (src == NULL || mat == src); + } + } + + const size_t bufferCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeBuffer); + for (size_t i = 0; i < bufferCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeBuffer, i); + const ComputeBufferID* src = reinterpret_cast<const ComputeBufferID*>(patch.source); + name.index = patch.nameIndex; + Assert (!name.IsBuiltin()); + const ComputeBufferID& buf = g_GlobalProperties->GetComputeBuffer(name); + Assert(src == NULL || &buf == src); + } +#endif +} + +void ThreadedDisplayList::PatchableData::WriteParameters(ThreadedStreamBuffer& queue) +{ + CheckParametersValid(); + + size_t floatCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeFloat); + for (size_t i = 0; i < floatCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeFloat, i); + float* dest = queue.GetWritePointer<float>(); + PatchFloat(patch, dest); + } + + size_t vectorCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeVector); + for (size_t i = 0; i < vectorCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeVector, i); + Vector4f* dest = queue.GetWritePointer<Vector4f>(); + PatchVector(patch, dest); + } + + size_t matrixCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeMatrix); + for (size_t i = 0; i < matrixCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeMatrix, i); + Matrix4x4f* dest = queue.GetWritePointer<Matrix4x4f>(); + PatchMatrix(patch, dest); + } + + size_t texEnvCount = m_PatchInfo.GetTexEnvPatchCount(); + for (size_t i = 0; i < texEnvCount; i++) + { + const GfxTexEnvPatch& patch = m_PatchInfo.GetTexEnvPatch(i); + if (patch.patchFlags & GfxTexEnvPatch::kPatchProperties) + { + TexEnvProperties* dest = queue.GetWritePointer<TexEnvProperties>(); + PatchTexEnvProperties(patch, dest); + } + if (patch.patchFlags & GfxTexEnvPatch::kPatchMatrix) + { + Matrix4x4f* dest = queue.GetWritePointer<Matrix4x4f>(); + PatchTexEnvMatrix(patch, dest); + } + } + + const size_t bufferCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeBuffer); + for (size_t i = 0; i < bufferCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeBuffer, i); + ComputeBufferID* dest = queue.GetWritePointer<ComputeBufferID>(); + PatchBuffer(patch, dest); + } +} + +void ThreadedDisplayList::PatchableData::PatchImmediate() +{ + CheckParametersValid(); + + size_t floatCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeFloat); + for (size_t i = 0; i < floatCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeFloat, i); + float* dest = reinterpret_cast<float*>(&m_Buffer[patch.patchOffset]); + PatchFloat(patch, dest); + } + + size_t vectorCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeVector); + for (size_t i = 0; i < vectorCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeVector, i); + Vector4f* dest = reinterpret_cast<Vector4f*>(&m_Buffer[patch.patchOffset]); + PatchVector(patch, dest); + } + + size_t matrixCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeMatrix); + for (size_t i = 0; i < matrixCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeMatrix, i); + Matrix4x4f* dest = reinterpret_cast<Matrix4x4f*>(&m_Buffer[patch.patchOffset]); + PatchMatrix(patch, dest); + } + + size_t texEnvCount = m_PatchInfo.GetTexEnvPatchCount(); + for (size_t i = 0; i < texEnvCount; i++) + { + const GfxTexEnvPatch& patch = m_PatchInfo.GetTexEnvPatch(i); + TexEnvData* dest = reinterpret_cast<TexEnvData*>(&m_Buffer[patch.patchOffset]); + + if (patch.patchFlags & GfxTexEnvPatch::kPatchProperties) + PatchTexEnvProperties(patch, dest); + + if (patch.patchFlags & GfxTexEnvPatch::kPatchMatrix) + PatchTexEnvMatrix(patch, &dest->matrix); + } + + size_t bufferCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeBuffer); + for (size_t i = 0; i < bufferCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeBuffer, i); + ComputeBufferID* dest = reinterpret_cast<ComputeBufferID*>(&m_Buffer[patch.patchOffset]); + PatchBuffer(patch, dest); + } +} + +void ThreadedDisplayList::PatchableData::Patch(ThreadedStreamBuffer& queue) +{ + FastPropertyName name; + + size_t floatCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeFloat); + for (size_t i = 0; i < floatCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeFloat, i); + float val = queue.ReadValueType<float>(); + *reinterpret_cast<float*>(&m_Buffer[patch.patchOffset]) = val; + } + + size_t vectorCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeVector); + for (size_t i = 0; i < vectorCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeVector, i); + const Vector4f& vec = queue.ReadValueType<Vector4f>(); + *reinterpret_cast<Vector4f*>(&m_Buffer[patch.patchOffset]) = vec; + } + + size_t matrixCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeMatrix); + for (size_t i = 0; i < matrixCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeMatrix, i); + const Matrix4x4f& mat = queue.ReadValueType<Matrix4x4f>(); + *reinterpret_cast<Matrix4x4f*>(&m_Buffer[patch.patchOffset]) = mat; + } + + size_t texEnvCount = m_PatchInfo.GetTexEnvPatchCount(); + for (size_t i = 0; i < texEnvCount; i++) + { + using namespace ShaderLab; + const GfxTexEnvPatch& patch = m_PatchInfo.GetTexEnvPatch(i); + TexEnvData& data = *reinterpret_cast<TexEnvData*>(&m_Buffer[patch.patchOffset]); + if (patch.patchFlags & GfxTexEnvPatch::kPatchProperties) + { + TexEnvProperties& dest = data; + // Patch doesn't know if matrix is identity + // Fortunately we can just keep the old value + bool savedIdentityMatrix = dest.identityMatrix; + dest = queue.ReadValueType<TexEnvProperties>(); + dest.identityMatrix = savedIdentityMatrix; + } + if (patch.patchFlags & GfxTexEnvPatch::kPatchMatrix) + data.matrix = queue.ReadValueType<Matrix4x4f>(); + } + + const size_t bufferCount = m_PatchInfo.GetPatchCount(GfxPatch::kTypeBuffer); + for (size_t i = 0; i < bufferCount; i++) + { + const GfxPatch& patch = m_PatchInfo.GetPatch(GfxPatch::kTypeBuffer, i); + const ComputeBufferID& buf = queue.ReadValueType<ComputeBufferID>(); + *reinterpret_cast<ComputeBufferID*>(&m_Buffer[patch.patchOffset]) = buf; + } +} + +void ThreadedDisplayList::PatchableData::PatchFloat(const GfxPatch& patch, float* dest) +{ + using namespace ShaderLab; + FastPropertyName name; + name.index = patch.nameIndex; + DebugAssert(patch.source || (name.IsValid() && !name.IsBuiltin())); + const float* src = static_cast<const float*>(patch.source); + *dest = src ? *src : g_GlobalProperties->GetFloat(name); +} + +void ThreadedDisplayList::PatchableData::PatchVector(const GfxPatch& patch, Vector4f* dest) +{ + using namespace ShaderLab; + FastPropertyName name; + name.index = patch.nameIndex; + DebugAssert(patch.source || (name.IsValid() && !name.IsBuiltin())); + const Vector4f* src = static_cast<const Vector4f*>(patch.source); + *dest = src ? *src : g_GlobalProperties->GetVector(name); +} + +void ThreadedDisplayList::PatchableData::PatchMatrix(const GfxPatch& patch, Matrix4x4f* dest) +{ + using namespace ShaderLab; + FastPropertyName name; + name.index = patch.nameIndex; + DebugAssert(patch.source || (name.IsValid() && !name.IsBuiltin())); + const Matrix4x4f* src = static_cast<const Matrix4x4f*>(patch.source); + if (!src) + { + int count = 0; + src = reinterpret_cast<const Matrix4x4f*>(g_GlobalProperties->GetValueProp (name, &count)); + if (count < 16) + src = NULL; + } + *dest = src ? *src : Matrix4x4f::identity; +} + +void ThreadedDisplayList::PatchableData::PatchBuffer(const GfxPatch& patch, ComputeBufferID* dest) +{ + using namespace ShaderLab; + FastPropertyName name; + name.index = patch.nameIndex; + DebugAssert(patch.source || (name.IsValid() && !name.IsBuiltin())); + const ComputeBufferID* src = static_cast<const ComputeBufferID*>(patch.source); + *dest = src ? *src : g_GlobalProperties->GetComputeBuffer(name); +} + +void ThreadedDisplayList::PatchableData::PatchTexEnvProperties(const GfxTexEnvPatch& patch, TexEnvProperties* dest) +{ + patch.texEnv->PrepareProperties(patch.nameIndex, dest); +} + +void ThreadedDisplayList::PatchableData::PatchTexEnvMatrix(const GfxTexEnvPatch& patch, Matrix4x4f* dest) +{ + bool identity; + patch.texEnv->PrepareMatrix(patch.matrixName, ShaderLab::g_GlobalProperties, dest, identity); +} + +int ThreadedDisplayList::PatchableData::AppendData(const void* data, int size) +{ + int offset = m_Buffer.size(); + m_Buffer.resize_uninitialized(offset + size); + memcpy(&m_Buffer[offset], data, size); + return offset; +} + + +#endif diff --git a/Runtime/GfxDevice/threaded/ThreadedDisplayList.h b/Runtime/GfxDevice/threaded/ThreadedDisplayList.h new file mode 100644 index 0000000..5711f8e --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedDisplayList.h @@ -0,0 +1,85 @@ +#ifndef THREADED_DISPLAY_LIST_H +#define THREADED_DISPLAY_LIST_H + +#if ENABLE_MULTITHREADED_CODE + +#include "Runtime/Threads/ThreadedStreamBuffer.h" +#include "Runtime/GfxDevice/GfxDisplayList.h" +#include "Runtime/GfxDevice/GfxPatchInfo.h" +#include "Runtime/GfxDevice/GpuProgram.h" + +class GfxDeviceClient; + +struct DisplayListContext +{ + DisplayListContext(); + void ClearState(); + void Reset(); + + enum + { + kFogParamsNone = -1, + kFogParamsDisable = -2 + }; + + ThreadedStreamBuffer commandQueue; + GfxPatchInfo patchInfo; + bool recordFailed; + bool hasSetShaders; + bool shadersActive[kShaderTypeCount]; + int fogParamsOffset; +}; + + +class ThreadedDisplayList : public GfxDisplayList +{ +public: + ThreadedDisplayList(const void* data, size_t size, const DisplayListContext& context); + ~ThreadedDisplayList(); + + void Call(); + + UInt8* GetData() { return m_ListData.m_Buffer.begin(); } + const UInt8* GetData() const { return m_ListData.m_Buffer.begin(); } + size_t GetSize() const { return m_ListData.m_Buffer.size(); } + + void Patch(ThreadedStreamBuffer& queue); + +private: + int CopyClientData(int offset, int size); + void UpdateClientDevice(GfxDeviceClient& device); + void DoLockstep(); + + class PatchableData + { + public: + PatchableData(const void* data, size_t size, + const GfxPatchInfo& patchInfo); + PatchableData(); + + void CheckParametersValid(); + void WriteParameters(ThreadedStreamBuffer& queue); + void PatchImmediate(); + void Patch(ThreadedStreamBuffer& queue); + void PatchFloat(const GfxPatch& patch, float* dest); + void PatchVector(const GfxPatch& patch, Vector4f* dest); + void PatchMatrix(const GfxPatch& patch, Matrix4x4f* dest); + void PatchBuffer(const GfxPatch& patch, ComputeBufferID* dest); + void PatchTexEnvProperties(const GfxTexEnvPatch& patch, TexEnvProperties* dest); + void PatchTexEnvMatrix(const GfxTexEnvPatch& patch, Matrix4x4f* dest); + int AppendData(const void* data, int size); + + dynamic_array<UInt8> m_Buffer; + GfxPatchInfo m_PatchInfo; + }; + + PatchableData m_ListData; + PatchableData m_ClientData; + bool m_HasSetShaders; + bool m_ShadersActive[kShaderTypeCount]; + int m_FogParamsOffset; +}; + + +#endif +#endif diff --git a/Runtime/GfxDevice/threaded/ThreadedTimerQuery.cpp b/Runtime/GfxDevice/threaded/ThreadedTimerQuery.cpp new file mode 100644 index 0000000..2b1731a --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedTimerQuery.cpp @@ -0,0 +1,102 @@ +#include "UnityPrefix.h" +#if ENABLE_PROFILER +#include "ThreadedTimerQuery.h" +#include "GfxDeviceWorker.h" +#include "Runtime/Threads/ThreadUtility.h" +#include "Runtime/Threads/ThreadedStreamBuffer.h" +#include "Runtime/GfxDevice/threaded/GfxDeviceClient.h" +#include "Runtime/GfxDevice/threaded/GfxCommands.h" + +ThreadedTimerQuery::ThreadedTimerQuery(GfxDeviceClient& device) +: m_ClientDevice(device) +{ + m_ClientQuery = new ClientDeviceTimerQuery; + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + ThreadedStreamBuffer& stream = *m_ClientDevice.GetCommandQueue(); + stream.WriteValueType<GfxCommand>(kGfxCmd_TimerQuery_Constructor); + stream.WriteValueType<ClientDeviceTimerQuery*>(m_ClientQuery); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_ClientQuery->internalQuery = GetRealGfxDevice().CreateTimerQuery(); +} + +ThreadedTimerQuery::~ThreadedTimerQuery() +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + ThreadedStreamBuffer& stream = *m_ClientDevice.GetCommandQueue(); + stream.WriteValueType<GfxCommand>(kGfxCmd_TimerQuery_Destructor); + stream.WriteValueType<ClientDeviceTimerQuery*>(m_ClientQuery); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + Assert(m_ClientQuery); + GetRealGfxDevice().DeleteTimerQuery(m_ClientQuery->GetInternal()); + delete m_ClientQuery; + } + m_ClientQuery = NULL; +} + +void ThreadedTimerQuery::Measure() +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + ThreadedStreamBuffer& stream = *m_ClientDevice.GetCommandQueue(); + stream.WriteValueType<GfxCommand>(kGfxCmd_TimerQuery_Measure); + stream.WriteValueType<ClientDeviceTimerQuery*>(m_ClientQuery); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + m_ClientQuery->GetInternal()->Measure(); +} + +ProfileTimeFormat ThreadedTimerQuery::GetElapsed(UInt32 flags) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + // See if we have the result already + ProfileTimeFormat time = GetElapsedIfReady(); + if (time != kInvalidProfileTime) + return time; + + // Request result from worker thread + ThreadedStreamBuffer& stream = *m_ClientDevice.GetCommandQueue(); + stream.WriteValueType<GfxCommand>(kGfxCmd_TimerQuery_GetElapsed); + stream.WriteValueType<ClientDeviceTimerQuery*>(m_ClientQuery); + stream.WriteValueType<UInt32>(flags); + if (flags & GfxTimerQuery::kWaitClientThread) + { + m_ClientDevice.SubmitCommands(); + m_ClientDevice.GetGfxDeviceWorker()->WaitForSignal(); + } + GFXDEVICE_LOCKSTEP_CLIENT(); + return GetElapsedIfReady(); + } + else + return m_ClientQuery->GetInternal()->GetElapsed(flags); +} + +ProfileTimeFormat ThreadedTimerQuery::GetElapsedIfReady() +{ + if (!m_ClientQuery->pending) + { + // Be careful since UInt64 isn't guaranteed atomic + UnityMemoryBarrier(); + return m_ClientQuery->elapsed; + } + return kInvalidProfileTime; +} + +void ThreadedTimerQuery::DoLockstep() +{ + m_ClientDevice.DoLockstep(); +} + +#endif diff --git a/Runtime/GfxDevice/threaded/ThreadedTimerQuery.h b/Runtime/GfxDevice/threaded/ThreadedTimerQuery.h new file mode 100644 index 0000000..b8aecbd --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedTimerQuery.h @@ -0,0 +1,29 @@ +#ifndef THREADEDTIMERQUERY_H +#define THREADEDTIMERQUERY_H + +#if ENABLE_PROFILER + +#include "Runtime/GfxDevice/GfxTimerQuery.h" + +class GfxDeviceClient; +struct ClientDeviceTimerQuery; + +class ThreadedTimerQuery : public GfxTimerQuery +{ +public: + ThreadedTimerQuery(GfxDeviceClient& device); + ~ThreadedTimerQuery(); + + virtual void Measure(); + virtual ProfileTimeFormat GetElapsed(UInt32 flags); + +private: + ProfileTimeFormat GetElapsedIfReady(); + void DoLockstep(); + + GfxDeviceClient& m_ClientDevice; + ClientDeviceTimerQuery* m_ClientQuery; +}; + +#endif +#endif diff --git a/Runtime/GfxDevice/threaded/ThreadedVBO.cpp b/Runtime/GfxDevice/threaded/ThreadedVBO.cpp new file mode 100644 index 0000000..09fdd5f --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedVBO.cpp @@ -0,0 +1,511 @@ +#include "UnityPrefix.h" +#include "ThreadedVBO.h" +#include "Runtime/Threads/ThreadedStreamBuffer.h" +#include "Runtime/GfxDevice/threaded/GfxDeviceClient.h" +#include "Runtime/GfxDevice/threaded/GfxDeviceWorker.h" +#include "Runtime/GfxDevice/threaded/GfxCommands.h" +#include "Runtime/GfxDevice/ChannelAssigns.h" + + +ThreadedVBO::ThreadedVBO(GfxDeviceClient& device) : + m_ClientDevice(device), + m_ClientVBO(NULL), + m_NonThreadedVBO(NULL), + m_MappedFromRenderThread(false), + m_VertexBufferLost(false), + m_IndexBufferLost(false), + m_VertexBufferSize(0), + m_IndexBufferSize(0) +{ + SET_ALLOC_OWNER(NULL); + DebugAssert(Thread::CurrentThreadIsMainThread()); + m_ClientVBO = UNITY_NEW(ClientDeviceVBO, kMemGfxThread); + if (device.IsThreaded()) + { + + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_Constructor); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + m_ClientVBO->internalVBO = m_ClientDevice.m_VBOMapper.CreateID(); + GetCommandQueue().WriteValueType<ClientDeviceVBO>(*m_ClientVBO); +#else + GetCommandQueue().WriteValueType<ClientDeviceVBO*>(m_ClientVBO); +#endif + GetCommandQueue().WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + else + { + m_NonThreadedVBO = GetRealGfxDevice().CreateVBO(); + m_ClientVBO->internalVBO = m_NonThreadedVBO; + } +#endif +} + +ThreadedVBO::~ThreadedVBO() +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + DebugAssert(!m_ClientDevice.IsRecording()); + if (m_ClientDevice.IsThreaded()) + { + DebugAssert(!m_NonThreadedVBO); + // m_ClientVBO deleted by server + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_Destructor); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GetCommandQueue().WriteValueType<ClientDeviceVBO>(*m_ClientVBO); +#else + GetCommandQueue().WriteValueType<ClientDeviceVBO*>(m_ClientVBO); +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + GetRealGfxDevice().DeleteVBO(m_NonThreadedVBO); + UNITY_DELETE(m_ClientVBO, kMemGfxThread); + } + m_NonThreadedVBO = NULL; + m_ClientVBO = NULL; +} + +void ThreadedVBO::UpdateVertexData( const VertexBufferData& buffer ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_UpdateVertexData); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GetCommandQueue().WriteValueType<ClientDeviceVBO>(*m_ClientVBO); + ClientVertexBufferData client; + memcpy (client.channels, buffer.channels, sizeof(ChannelInfoArray)); + memcpy (client.streams, buffer.streams, sizeof(StreamInfoArray)); + client.bufferSize = buffer.bufferSize; + client.vertexCount = buffer.vertexCount; + client.hasData = buffer.buffer != NULL; + GetCommandQueue().WriteValueType<ClientVertexBufferData>(client); +#else + GetCommandQueue().WriteValueType<ClientDeviceVBO*>(m_ClientVBO); + GetCommandQueue().WriteValueType<VertexBufferData>(buffer); +#endif + if (buffer.buffer) + m_ClientDevice.WriteBufferData(buffer.buffer, buffer.bufferSize); + if (m_MappedFromRenderThread) + UnbufferVertexData(); + else + BufferAccessibleVertexData(buffer); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->UpdateVertexData(buffer); + } + m_VertexBufferSize = buffer.bufferSize; + m_VertexBufferLost = false; +} + +void ThreadedVBO::UpdateIndexData (const IndexBufferData& buffer) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_UpdateIndexData); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GetCommandQueue().WriteValueType<ClientDeviceVBO>(*m_ClientVBO); +#else + GetCommandQueue().WriteValueType<ClientDeviceVBO*>(m_ClientVBO); +#endif + GetCommandQueue().WriteValueType<int>(buffer.count); + GetCommandQueue().WriteValueType<UInt32>(buffer.hasTopologies); + m_ClientDevice.WriteBufferData(buffer.indices, CalculateIndexBufferSize(buffer)); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->UpdateIndexData(buffer); + } + m_IndexBufferSize = buffer.count * kVBOIndexSize; + m_IndexBufferLost = false; +} + +void ThreadedVBO::DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + m_ClientDevice.BeforeDrawCall(false); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_Draw); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdVBODraw data = { *m_ClientVBO, channels, firstIndexByte, indexCount, topology, firstVertex, vertexCount }; +#else + GfxCmdVBODraw data = { m_ClientVBO, channels, firstIndexByte, indexCount, topology, firstVertex, vertexCount }; +#endif + GetCommandQueue().WriteValueType<GfxCmdVBODraw>(data); + GetCommandQueue().WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->DrawVBO (channels, firstIndexByte, indexCount, topology, firstVertex, vertexCount); + } +} + +#if GFX_ENABLE_DRAW_CALL_BATCHING +void ThreadedVBO::DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + m_ClientDevice.BeforeDrawCall(false); + if (m_ClientDevice.IsSerializing()) + { + //Note: Presuming that indices are of size UInt16! + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_DrawCustomIndexed); + GfxCmdVBODrawCustomIndexed data = { m_ClientVBO, channels, indexCount, topology, vertexRangeBegin, vertexRangeEnd, drawVertexCount }; + GetCommandQueue().WriteValueType<GfxCmdVBODrawCustomIndexed>(data); + GetCommandQueue().WriteStreamingData(indices, indexCount*kVBOIndexSize); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->DrawCustomIndexed(channels, indices, indexCount, topology, + vertexRangeBegin, vertexRangeEnd, drawVertexCount); + } +} +#endif + +void ThreadedVBO::Recreate() +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_Recreate); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GetCommandQueue().WriteValueType<ClientDeviceVBO>(*m_ClientVBO); +#else + GetCommandQueue().WriteValueType<ClientDeviceVBO*>(m_ClientVBO); +#endif + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->Recreate(); + } +} + +bool ThreadedVBO::MapVertexStream( VertexStreamData& outData, unsigned stream ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + BufferedVBO::MapVertexStream(outData, stream); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_IsStreamMapped[stream] = m_NonThreadedVBO->MapVertexStream(outData, stream); + } + return m_IsStreamMapped[stream]; +} + +void ThreadedVBO::UnmapVertexStream( unsigned stream ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + BufferedVBO::UnmapVertexStream(stream); + + // Send modified vertices to render thread + size_t size = CalculateVertexStreamSize(m_VertexData, stream); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdVBOMapVertexStream map = { *m_ClientVBO, stream, size }; +#else + GfxCmdVBOMapVertexStream map = { m_ClientVBO, stream, size }; +#endif + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_MapVertexStream); + GetCommandQueue().WriteValueType<GfxCmdVBOMapVertexStream>(map); + GetCommandQueue().WriteStreamingData(GetStreamBuffer(stream), size); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->UnmapVertexStream(stream); + } + m_IsStreamMapped[0] = false; +} + +bool ThreadedVBO::IsVertexBufferLost() const +{ + if (m_NonThreadedVBO) + return m_NonThreadedVBO->IsVertexBufferLost(); + else + return m_VertexBufferLost; +} + +bool ThreadedVBO::IsIndexBufferLost() const +{ + if (m_NonThreadedVBO) + return m_NonThreadedVBO->IsIndexBufferLost(); + else + return m_IndexBufferLost; +} + +void ThreadedVBO::SetMappedFromRenderThread( bool renderThread ) +{ +#if !ENABLE_GFXDEVICE_REMOTE_PROCESS + m_MappedFromRenderThread = renderThread; +#endif +} + +void ThreadedVBO::SetVertexStreamMode( unsigned stream, StreamMode mode ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (mode == GetVertexStreamMode(stream)) + return; + VBO::SetVertexStreamMode(stream, mode); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_SetVertexStreamMode); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdVBOSetVertexStreamMode vsmode = { *m_ClientVBO, stream, mode }; +#else + GfxCmdVBOSetVertexStreamMode vsmode = { m_ClientVBO, stream, mode }; +#endif + GetCommandQueue().WriteValueType<GfxCmdVBOSetVertexStreamMode>(vsmode); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->SetVertexStreamMode(stream, mode); + } +} + +void ThreadedVBO::SetIndicesDynamic(bool dynamic) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (dynamic == AreIndicesDynamic()) + return; + VBO::SetIndicesDynamic(dynamic); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_SetIndicesDynamic); +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + GfxCmdVBOSetSetIndicesDynamic vsdyn = { *m_ClientVBO, (int)dynamic }; +#else + GfxCmdVBOSetSetIndicesDynamic vsdyn = { m_ClientVBO, (int)dynamic }; +#endif + GetCommandQueue().WriteValueType<GfxCmdVBOSetSetIndicesDynamic>(vsdyn); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->SetIndicesDynamic(dynamic); + } +} + +void ThreadedVBO::ResetDynamicVB() +{ + for (int s = 0; s < kMaxVertexStreams; s++) + { + if (m_StreamModes[s] == kStreamModeDynamic) + m_VertexBufferLost = true; + } +} + +void ThreadedVBO::MarkBuffersLost() +{ + m_VertexBufferLost = m_IndexBufferLost = true; +} + + +int ThreadedVBO::GetRuntimeMemorySize() const +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { +#if ENABLE_GFXDEVICE_REMOTE_PROCESS + return 0; +#else + return m_ClientVBO->GetInternal()?m_ClientVBO->GetInternal()->GetRuntimeMemorySize():0; +#endif + } + else + { + DebugAssert(m_NonThreadedVBO); + return m_NonThreadedVBO->GetRuntimeMemorySize(); + } +} + +void ThreadedVBO::UseAsStreamOutput() +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_UseAsStreamOutput); + GetCommandQueue().WriteValueType<ClientDeviceVBO *>(m_ClientVBO); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->UseAsStreamOutput(); + } + +} + +#if UNITY_XENON +void ThreadedVBO::AddExtraUvChannels( const UInt8* data, UInt32 size, int extraUvCount ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_AddExtraUvChannels); + GfxCmdVBOAddExtraUvChannels adduv = { m_ClientVBO, size, extraUvCount }; + GetCommandQueue().WriteValueType<GfxCmdVBOAddExtraUvChannels>(adduv); + GetCommandQueue().WriteStreamingData(data, size); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->AddExtraUvChannels(data, size, extraUvCount); + } +} + +void ThreadedVBO::CopyExtraUvChannels( VBO* source ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + DebugAssert(source != NULL); + ThreadedVBO* src = static_cast<ThreadedVBO*>(source); + if (m_ClientDevice.IsSerializing()) + { + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_VBO_CopyExtraUvChannels); + GfxCmdVBOCopyExtraUvChannels copyuv = { m_ClientVBO, src->m_ClientVBO }; + GetCommandQueue().WriteValueType<GfxCmdVBOCopyExtraUvChannels>(copyuv); + GFXDEVICE_LOCKSTEP_CLIENT(); + } + else + { + DebugAssert(m_NonThreadedVBO); + m_NonThreadedVBO->CopyExtraUvChannels(src->m_NonThreadedVBO); + } +} +#endif + +ThreadedStreamBuffer& ThreadedVBO::GetCommandQueue() +{ + return *m_ClientDevice.GetCommandQueue(); +} + +GfxDeviceWorker* ThreadedVBO::GetGfxDeviceWorker() +{ + return m_ClientDevice.GetGfxDeviceWorker(); +} + +void ThreadedVBO::SubmitCommands() +{ + m_ClientDevice.SubmitCommands(); +} + +void ThreadedVBO::DoLockstep() +{ + m_ClientDevice.DoLockstep(); +} + + +ThreadedDynamicVBO::ThreadedDynamicVBO(GfxDeviceClient& device) : + m_ClientDevice(device), + m_ValidChunk(false) +{ +} + +bool ThreadedDynamicVBO::GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + Assert( !m_LendedChunk ); + DebugAssert( outVB != NULL && maxVertices > 0 ); + DebugAssert( + (renderMode == kDrawIndexedTriangles && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawIndexedTriangleStrip && (outIB != NULL && maxIndices > 0)) || + (renderMode == kDrawTriangleStrip && (outIB == NULL && maxIndices == 0)) || + (renderMode == kDrawQuads && (outIB == NULL && maxIndices == 0))); + + m_LendedChunk = true; + m_LastChunkShaderChannelMask = shaderChannelMask; + m_LastRenderMode = renderMode; + + m_LastChunkStride = 0; + for( int i = 0; i < kShaderChannelCount; ++i ) { + if( shaderChannelMask & (1<<i) ) + m_LastChunkStride += VBO::GetDefaultChannelByteSize(i); + } + m_LastChunkVertices = maxVertices; + m_LastChunkIndices = maxIndices; + int vertexChunkSize = m_LastChunkStride * maxVertices; + m_ChunkVertices.resize_uninitialized(vertexChunkSize); + m_ChunkIndices.resize_uninitialized(maxIndices); + *outVB = &m_ChunkVertices[0]; + if (outIB) + *outIB = &m_ChunkIndices[0]; + return true; +} + +void ThreadedDynamicVBO::ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + Assert( m_LendedChunk ); + m_LendedChunk = false; + m_ValidChunk = (actualVertices > 0) && (m_LastChunkIndices == 0 || actualIndices > 0); + if (!m_ValidChunk) + return; + Assert(actualVertices <= m_LastChunkVertices); + Assert(actualIndices <= m_LastChunkIndices); + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_DynVBO_Chunk); + GfxCmdDynVboChunk chunk = { m_LastChunkShaderChannelMask, m_LastChunkStride, actualVertices, actualIndices, m_LastRenderMode }; + GetCommandQueue().WriteValueType<GfxCmdDynVboChunk>(chunk); + GetCommandQueue().WriteStreamingData(&m_ChunkVertices[0], actualVertices * m_LastChunkStride); + if (actualIndices > 0) + GetCommandQueue().WriteStreamingData(&m_ChunkIndices[0], actualIndices * kVBOIndexSize); + GetCommandQueue().WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); +} + +void ThreadedDynamicVBO::DrawChunk (const ChannelAssigns& channels) +{ + DebugAssert(Thread::CurrentThreadIsMainThread()); + Assert( !m_LendedChunk ); + if (!m_ValidChunk) + return; + m_ClientDevice.BeforeDrawCall(false); + GetCommandQueue().WriteValueType<GfxCommand>(kGfxCmd_DynVBO_DrawChunk); + GetCommandQueue().WriteValueType<ChannelAssigns>(channels); + GetCommandQueue().WriteSubmitData(); + GFXDEVICE_LOCKSTEP_CLIENT(); +} + +ThreadedStreamBuffer& ThreadedDynamicVBO::GetCommandQueue() +{ + return *m_ClientDevice.GetCommandQueue(); +} + +GfxDeviceWorker* ThreadedDynamicVBO::GetGfxDeviceWorker() +{ + return m_ClientDevice.GetGfxDeviceWorker(); +} + +void ThreadedDynamicVBO::SubmitCommands() +{ + m_ClientDevice.SubmitCommands(); +} + +void ThreadedDynamicVBO::DoLockstep() +{ + m_ClientDevice.DoLockstep(); +} diff --git a/Runtime/GfxDevice/threaded/ThreadedVBO.h b/Runtime/GfxDevice/threaded/ThreadedVBO.h new file mode 100644 index 0000000..89dbeff --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedVBO.h @@ -0,0 +1,104 @@ +#ifndef THREADEDVBO_H +#define THREADEDVBO_H + +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Configuration/UnityConfigure.h" +#include "Runtime/Shaders/BufferedVBO.h" + +class Mutex; +class GfxDeviceClient; +struct ClientDeviceVBO; +class GfxDeviceWorker; +class ThreadedStreamBuffer; + +class ThreadedVBO : public BufferedVBO { +public: + ThreadedVBO(GfxDeviceClient& device); + virtual ~ThreadedVBO(); + + virtual void UpdateVertexData( const VertexBufferData& buffer ); + virtual void UpdateIndexData (const IndexBufferData& buffer); + virtual void DrawVBO (const ChannelAssigns& channels, UInt32 firstIndexByte, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 firstVertex, UInt32 vertexCount ); + #if GFX_ENABLE_DRAW_CALL_BATCHING + virtual void DrawCustomIndexed( const ChannelAssigns& channels, void* indices, UInt32 indexCount, + GfxPrimitiveType topology, UInt32 vertexRangeBegin, UInt32 vertexRangeEnd, UInt32 drawVertexCount ); + #endif + + virtual void Recreate(); + + // For writing directly to VBO. VBO must be filled (UpdateData) + // at least once; and vertex layout + topology from the last fill + // is used. For example, for skinned meshes you have to call + // UpdateData on start and each time layout/topology changes; + // then map,write,unmap for each skinning. + // + // In some situations a vertex buffer might become lost; then you need to do UpdateData + // again before using Map. + virtual bool MapVertexStream( VertexStreamData& outData, unsigned stream ); + virtual void UnmapVertexStream( unsigned stream ); + virtual bool IsVertexBufferLost() const; + virtual bool IsIndexBufferLost() const; + + virtual void SetMappedFromRenderThread( bool renderThread ); + virtual void SetVertexStreamMode( unsigned stream, StreamMode mode ); + virtual void SetIndicesDynamic(bool dynamic); + + virtual void ResetDynamicVB(); + virtual void MarkBuffersLost(); + + virtual int GetRuntimeMemorySize() const; + + virtual void UseAsStreamOutput(); + +#if UNITY_XENON + virtual void AddExtraUvChannels( const UInt8* data, UInt32 size, int extraUvCount ); + virtual void CopyExtraUvChannels( VBO* source ); +#endif + + ClientDeviceVBO* GetClientDeviceVBO() { return m_ClientVBO; } //Todo:any nicer way? + VBO* GetNonThreadedVBO() { return m_NonThreadedVBO; } + +protected: + ThreadedStreamBuffer& GetCommandQueue(); + GfxDeviceWorker* GetGfxDeviceWorker(); + void SubmitCommands(); + void DoLockstep(); + + GfxDeviceClient& m_ClientDevice; + ClientDeviceVBO* m_ClientVBO; + VBO* m_NonThreadedVBO; + int m_VertexBufferSize; + int m_IndexBufferSize; + bool m_MappedFromRenderThread; + bool m_VertexBufferLost; + bool m_IndexBufferLost; +}; + + +class ThreadedDynamicVBO : public DynamicVBO { +public: + ThreadedDynamicVBO(GfxDeviceClient& device); + virtual ~ThreadedDynamicVBO() { } + + virtual bool GetChunk( UInt32 shaderChannelMask, UInt32 maxVertices, UInt32 maxIndices, RenderMode renderMode, void** outVB, void** outIB ); + + virtual void ReleaseChunk( UInt32 actualVertices, UInt32 actualIndices ); + + virtual void DrawChunk (const ChannelAssigns& channels); + +private: + ThreadedStreamBuffer& GetCommandQueue(); + GfxDeviceWorker* GetGfxDeviceWorker(); + void SubmitCommands(); + void DoLockstep(); + + GfxDeviceClient& m_ClientDevice; + ThreadedStreamBuffer* m_CommandQueue; + dynamic_array<UInt8> m_ChunkVertices; + dynamic_array<UInt16> m_ChunkIndices; + bool m_ValidChunk; +}; + + +#endif diff --git a/Runtime/GfxDevice/threaded/ThreadedWindow.cpp b/Runtime/GfxDevice/threaded/ThreadedWindow.cpp new file mode 100644 index 0000000..bab324f --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedWindow.cpp @@ -0,0 +1,97 @@ +#include "UnityPrefix.h" +#include "Runtime/GfxDevice/threaded/ThreadedWindow.h" +#include "Runtime/GfxDevice/threaded/GfxDeviceClient.h" +#include "Runtime/Graphics/RenderTexture.h" +#include "Runtime/Misc/QualitySettings.h" + + +#if UNITY_WIN && UNITY_EDITOR + +int ThreadedWindow::ms_CurrentFSAALevel = 0; + +ThreadedWindow::ThreadedWindow(HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ) +: GfxDeviceWindow(window, width, height, depthFormat, antiAlias) +{ + m_ClientWindow = new ClientDeviceWindow; + m_FSAALevel = antiAlias; + m_Reshaped = false; + + // Creating the actual window calls Reshape on the base class + // Threaded window should be kept in the same state + GfxDeviceWindow::Reshape(width, height, depthFormat, antiAlias); +} + +ThreadedWindow::~ThreadedWindow() +{ + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + device.WindowDestroy(m_ClientWindow); + m_ClientWindow = NULL; +} + +bool ThreadedWindow::Reshape( int width, int height, DepthBufferFormat depthFormat, int antiAlias ) +{ + if(!GfxDeviceWindow::Reshape(width, height, depthFormat, antiAlias)) + return false; + + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + device.WindowReshape(m_ClientWindow, width, height, depthFormat, antiAlias); + m_Reshaped = true; + return true; +} + +void ThreadedWindow::SetAsActiveWindow () +{ + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + device.SetActiveWindow(m_ClientWindow); + OnActivateWindow(); +} + +bool ThreadedWindow::BeginRendering() +{ + if (GfxDeviceWindow::BeginRendering()) + { + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + device.BeginRendering(m_ClientWindow); + OnActivateWindow(); + return true; + } + else + { + return false; + } +} + +bool ThreadedWindow::EndRendering( bool presentContent ) +{ + if(GfxDeviceWindow::EndRendering(presentContent)) + { + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + device.EndRendering(m_ClientWindow, presentContent); + if (m_Reshaped) + { + GfxDeviceRenderer renderer = device.GetRenderer(); + // We need to complete rendering on WM_PAINT after window was resized + // otherwise contents will look stretched in DirectX mode + if (renderer == kGfxRendererD3D9 || renderer == kGfxRendererD3D11) + device.FinishRendering(); + m_Reshaped = false; + } + return true; + } + else + { + return false; + } +} + +void ThreadedWindow::OnActivateWindow() +{ + GfxDeviceClient& device = (GfxDeviceClient&)GetGfxDevice(); + device.SetActiveRenderTexture(NULL); + device.SetCurrentWindowSize(m_Width, m_Height); + device.SetInvertProjectionMatrix(false); + ms_CurrentFSAALevel = m_FSAALevel; + +} + +#endif diff --git a/Runtime/GfxDevice/threaded/ThreadedWindow.h b/Runtime/GfxDevice/threaded/ThreadedWindow.h new file mode 100644 index 0000000..60489f4 --- /dev/null +++ b/Runtime/GfxDevice/threaded/ThreadedWindow.h @@ -0,0 +1,36 @@ +#ifndef THREADEDWINDOW_H +#define THREADEDWINDOW_H + +#if UNITY_WIN && UNITY_EDITOR + +#include "Runtime/GfxDevice/GfxDeviceWindow.h" +#include "ThreadedDeviceStates.h" + +class ThreadedWindow : public GfxDeviceWindow +{ +public: + ThreadedWindow( HWND window, int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + ~ThreadedWindow(); + + bool Reshape( int width, int height, DepthBufferFormat depthFormat, int antiAlias ); + + bool BeginRendering(); + bool EndRendering( bool presentContent ); + void SetAsActiveWindow(); + + static int GetCurrentFSAALevel() { return ms_CurrentFSAALevel; } + +private: + void OnActivateWindow(); + + friend class GfxDeviceClient; + friend class GfxDeviceWorker; + + ClientDeviceWindow* m_ClientWindow; + int m_FSAALevel; + bool m_Reshaped; + static int ms_CurrentFSAALevel; +}; + +#endif +#endif diff --git a/Runtime/GfxDevice/threaded/WorkerIDMapper.h b/Runtime/GfxDevice/threaded/WorkerIDMapper.h new file mode 100644 index 0000000..9b563f5 --- /dev/null +++ b/Runtime/GfxDevice/threaded/WorkerIDMapper.h @@ -0,0 +1,33 @@ +#ifndef WORKERIDMAPPER_H +#define WORKERIDMAPPER_H + +#include "ClientIDMapper.h" +#include "Runtime/Utilities/dynamic_array.h" + +template <class T> +class WorkerIDMapper { +public: + + WorkerIDMapper () + { + (*this)[0] = NULL; + } + + T*& operator [] (ClientIDMapper::ClientID cid) + { + if (m_IDMapping.size() <= cid) + m_IDMapping.resize_uninitialized(cid+1); + return m_IDMapping[cid]; + } + +private: + dynamic_array<T*> m_IDMapping; +}; + +#if ENABLE_GFXDEVICE_REMOTE_PROCESS +#define WorkerIDWrapper(type,val) m_##type##Mapper[val] +#else +#define WorkerIDWrapper(type,val) val +#endif + +#endif
\ No newline at end of file |