Removed HLSL cry compilers and tools
parent
08ed726faa
commit
f8a72e5a04
@ -1,494 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#pragma comment(lib, "D3Dcompiler.lib")
|
||||
|
||||
#define CRYFXC_VER "1.01"
|
||||
|
||||
|
||||
enum SwitchType
|
||||
{
|
||||
FXC_E, FXC_T, FXC_Help, FXC_CmdOptFile, FXC_Cc, FXC_Compress, FXC_D, FXC_Decompress, FXC_Fc,
|
||||
FXC_Fh, FXC_Fo, FXC_Fx, FXC_P, FXC_Gch, FXC_Gdp, FXC_Gec, FXC_Ges, FXC_Gfa, FXC_Gfp, FXC_Gis,
|
||||
FXC_Gpp, FXC_I, FXC_LD, FXC_Ni, FXC_NoLogo, FXC_Od, FXC_Op, FXC_O0, FXC_O1, FXC_O2, FXC_O3,
|
||||
FXC_Vd, FXC_Vi, FXC_Vn, FXC_Zi, FXC_Zpc, FXC_Zpr,
|
||||
|
||||
FXC_NumArgs
|
||||
};
|
||||
|
||||
|
||||
struct SwitchEntry
|
||||
{
|
||||
SwitchType type;
|
||||
const char* text;
|
||||
bool hasValue;
|
||||
bool supported;
|
||||
};
|
||||
|
||||
|
||||
const static SwitchEntry s_switchEntries[] =
|
||||
{
|
||||
{FXC_E, "/E", 1, true},
|
||||
{FXC_T, "/T", 1, true},
|
||||
{FXC_Fh, "/Fh", 1, true},
|
||||
{FXC_Fo, "/Fo", 1, true},
|
||||
|
||||
{FXC_Gec, "/Gec", 0, true},
|
||||
{FXC_Ges, "/Ges", 0, true},
|
||||
{FXC_Gfa, "/Gfa", 0, true},
|
||||
{FXC_Gfp, "/Gfp", 0, true},
|
||||
{FXC_Gis, "/Gis", 0, true},
|
||||
{FXC_Gpp, "/Gpp", 0, true},
|
||||
{FXC_Od, "/Od", 0, true},
|
||||
{FXC_O0, "/O0", 0, true},
|
||||
{FXC_O1, "/O1", 0, true},
|
||||
{FXC_O2, "/O2", 0, true},
|
||||
{FXC_O3, "/O3", 0, true},
|
||||
{FXC_Op, "/Op", 0, true},
|
||||
{FXC_Vd, "/Vd", 0, true},
|
||||
{FXC_Vn, "/Vn", 1, true},
|
||||
{FXC_Zi, "/Zi", 0, true},
|
||||
{FXC_Zpc, "/Zpc", 0, true},
|
||||
{FXC_Zpr, "/Zpr", 0, true},
|
||||
{FXC_NoLogo, "/nologo", 0, true},
|
||||
|
||||
{FXC_Help, "/?", 0, false},
|
||||
{FXC_Help, "/help", 0, false},
|
||||
{FXC_Cc, "/Cc", 0, false},
|
||||
{FXC_Compress, "/compress", 0, false},
|
||||
{FXC_D, "/D", 1, false},
|
||||
{FXC_Decompress, "/decompress", 0, false},
|
||||
{FXC_Fc, "/Fc", 1, false},
|
||||
{FXC_Fx, "/Fx", 1, false},
|
||||
{FXC_P, "/P", 1, false},
|
||||
{FXC_Gch, "/Gch", 0, false},
|
||||
{FXC_Gdp, "/Gdp", 0, false},
|
||||
{FXC_I, "/I", 1, false},
|
||||
{FXC_LD, "/LD", 0, false},
|
||||
{FXC_Ni, "/Ni", 0, false},
|
||||
{FXC_Vi, "/Vi", 0, false}
|
||||
};
|
||||
|
||||
|
||||
bool IsSwitch(const char* p)
|
||||
{
|
||||
assert(p);
|
||||
return *p == '/' || *p == '@';
|
||||
}
|
||||
|
||||
|
||||
const SwitchEntry* GetSwitch(const char* p)
|
||||
{
|
||||
assert(p);
|
||||
for (size_t i = 0; i < sizeof(s_switchEntries) / sizeof(s_switchEntries[0]); ++i)
|
||||
{
|
||||
if (_stricmp(s_switchEntries[i].text, p) == 0)
|
||||
{
|
||||
return &s_switchEntries[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (*p == '@')
|
||||
{
|
||||
const static SwitchEntry sw = {FXC_CmdOptFile, "@", 0, false};
|
||||
return &sw;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct ParserResults
|
||||
{
|
||||
const char* pProfile;
|
||||
const char* pEntry;
|
||||
const char* pOutFile;
|
||||
const char* pInFile;
|
||||
const char* pHeaderVariableName;
|
||||
unsigned int compilerFlags;
|
||||
bool disassemble;
|
||||
|
||||
void Init()
|
||||
{
|
||||
pProfile = 0;
|
||||
pEntry = 0;
|
||||
pOutFile = 0;
|
||||
pInFile = 0;
|
||||
pHeaderVariableName = 0;
|
||||
compilerFlags = 0;
|
||||
disassemble = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bool ParseCommandLine(const char* const* args, size_t numargs, ParserResults& parserRes)
|
||||
{
|
||||
parserRes.Init();
|
||||
|
||||
if (numargs < 4)
|
||||
{
|
||||
fprintf(stderr, "Failed to specify all required arguments: infile, outfile, profile and entry point\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 1; i < numargs; ++i)
|
||||
{
|
||||
if (IsSwitch(args[i]))
|
||||
{
|
||||
const SwitchEntry* sw = GetSwitch(args[i]);
|
||||
if (!sw)
|
||||
{
|
||||
fprintf(stderr, "Unknown switch: %s\n", args[i]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sw->supported)
|
||||
{
|
||||
fprintf(stderr, "Unsupported switch: %s\n", sw->text);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sw->hasValue)
|
||||
{
|
||||
if (i + 1 == numargs || IsSwitch(args[i + 1]))
|
||||
{
|
||||
fprintf(stderr, "Missing value for switch: %s\n", sw->text);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* pValue = args[i + 1];
|
||||
switch (sw->type)
|
||||
{
|
||||
case FXC_E:
|
||||
parserRes.pEntry = pValue;
|
||||
break;
|
||||
case FXC_T:
|
||||
parserRes.pProfile = pValue;
|
||||
break;
|
||||
case FXC_Fh:
|
||||
parserRes.pOutFile = pValue;
|
||||
parserRes.disassemble = true;
|
||||
break;
|
||||
case FXC_Fo:
|
||||
parserRes.pOutFile = pValue;
|
||||
break;
|
||||
case FXC_Vn:
|
||||
parserRes.pHeaderVariableName = pValue;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Failed assigning switch: %s | value: %s\n", sw->text, pValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (sw->type)
|
||||
{
|
||||
case FXC_Gec:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;
|
||||
break;
|
||||
case FXC_Od:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
|
||||
break;
|
||||
case FXC_O0:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_OPTIMIZATION_LEVEL0;
|
||||
break;
|
||||
case FXC_O1:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_OPTIMIZATION_LEVEL1;
|
||||
break;
|
||||
case FXC_O2:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_OPTIMIZATION_LEVEL2;
|
||||
break;
|
||||
case FXC_O3:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_OPTIMIZATION_LEVEL3;
|
||||
break;
|
||||
case FXC_Zi:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_DEBUG;
|
||||
break;
|
||||
case FXC_Zpc:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_PACK_MATRIX_COLUMN_MAJOR;
|
||||
break;
|
||||
case FXC_Zpr:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
|
||||
break;
|
||||
case FXC_Ges:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_ENABLE_STRICTNESS;
|
||||
break;
|
||||
case FXC_Gfa:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_AVOID_FLOW_CONTROL;
|
||||
break;
|
||||
case FXC_Gfp:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_PREFER_FLOW_CONTROL;
|
||||
break;
|
||||
case FXC_Gis:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_IEEE_STRICTNESS;
|
||||
break;
|
||||
case FXC_Gpp:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_PARTIAL_PRECISION;
|
||||
break;
|
||||
case FXC_Op:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_NO_PRESHADER;
|
||||
break;
|
||||
case FXC_Vd:
|
||||
parserRes.compilerFlags |= D3D10_SHADER_SKIP_VALIDATION;
|
||||
break;
|
||||
case FXC_NoLogo:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Failed assigning switch: %s\n", sw->text);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (i == numargs - 1)
|
||||
{
|
||||
parserRes.pInFile = args[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error in command line at token: %s\n", args[i]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const bool successful = parserRes.pProfile && parserRes.pEntry && parserRes.pInFile && parserRes.pOutFile;
|
||||
if (!successful)
|
||||
{
|
||||
fprintf(stderr, "Failed to specify all required arguments: infile, outfile, profile and entry point\n");
|
||||
}
|
||||
|
||||
return successful;
|
||||
}
|
||||
|
||||
|
||||
bool ReadInFile(const char* pInFile, std::vector<char>& data)
|
||||
{
|
||||
if (!pInFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool read = false;
|
||||
|
||||
FILE* fin = 0;
|
||||
fopen_s(&fin, pInFile, "rb");
|
||||
if (fin)
|
||||
{
|
||||
fseek(fin, 0, SEEK_END);
|
||||
const long l = ftell(fin);
|
||||
if (l >= 0)
|
||||
{
|
||||
fseek(fin, 0, SEEK_SET);
|
||||
const size_t len = l > 0 ? (size_t) l : 0;
|
||||
data.resize(len);
|
||||
fread(&data[0], 1, len, fin);
|
||||
read = true;
|
||||
}
|
||||
|
||||
fclose(fin);
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
|
||||
bool WriteByteCode(const char* pFileName, const void* pCode, size_t codeSize)
|
||||
{
|
||||
if (!pFileName || !pCode && codeSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool written = false;
|
||||
|
||||
FILE* fout = 0;
|
||||
fopen_s(&fout, pFileName, "wb");
|
||||
if (fout)
|
||||
{
|
||||
fwrite(pCode, 1, codeSize, fout);
|
||||
fclose(fout);
|
||||
written = true;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
|
||||
bool WriteHexListing(const char* pFileName, const char* pHdrVarName, const char* pDisassembly, const void* pCode, size_t codeSize)
|
||||
{
|
||||
if (!pFileName || !pHdrVarName || !pDisassembly || !pCode && codeSize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool written = false;
|
||||
|
||||
FILE* fout = 0;
|
||||
fopen_s(&fout, pFileName, "w");
|
||||
if (fout)
|
||||
{
|
||||
fprintf(fout, "#if 0\n%s#endif\n\n", pDisassembly);
|
||||
fprintf(fout, "const BYTE g_%s[] = \n{", pHdrVarName);
|
||||
|
||||
const size_t blockSize = 6;
|
||||
const size_t numBlocks = codeSize / blockSize;
|
||||
|
||||
const unsigned char* p = (const unsigned char*) pCode;
|
||||
|
||||
size_t i = 0;
|
||||
for (; i < numBlocks * blockSize; i += blockSize)
|
||||
{
|
||||
fprintf(fout, "\n %3d, %3d, %3d, %3d, %3d, %3d", p[i], p[i + 1], p[i + 2], p[i + 3], p[i + 4], p[i + 5]);
|
||||
if (i + blockSize < codeSize)
|
||||
{
|
||||
fprintf(fout, ",");
|
||||
}
|
||||
}
|
||||
|
||||
if (i < codeSize)
|
||||
{
|
||||
fprintf(fout, "\n ");
|
||||
|
||||
for (; i < codeSize; ++i)
|
||||
{
|
||||
fprintf(fout, "%3d", p[i]);
|
||||
if (i < codeSize - 1)
|
||||
{
|
||||
fprintf(fout, ", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(fout, "\n};\n");
|
||||
|
||||
fclose(fout);
|
||||
written = true;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
|
||||
void DisplayInfo()
|
||||
{
|
||||
fprintf(stdout, "FXC stub for remote shader compile server\n(C) 2012 Crytek. All rights reserved.\n\nVersion "CRYFXC_VER " for %d bit, linked against D3DCompiler_%d.dll\n\n", sizeof(void*) * 8, D3DX11_SDK_VERSION);
|
||||
fprintf(stdout, "Syntax: fxc SwitchOptions Filename\n\n");
|
||||
fprintf(stdout, "Supported switches: ");
|
||||
|
||||
bool firstSw = true;
|
||||
for (size_t i = 0; i < sizeof(s_switchEntries) / sizeof(s_switchEntries[0]); ++i)
|
||||
{
|
||||
if (s_switchEntries[i].supported)
|
||||
{
|
||||
fprintf(stdout, "%s%s", firstSw ? "" : ", ", s_switchEntries[i].text);
|
||||
firstSw = false;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
DisplayInfo();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ParserResults parserRes;
|
||||
if (!ParseCommandLine(argv, argc, parserRes))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<char> program;
|
||||
if (!ReadInFile(parserRes.pInFile, program))
|
||||
{
|
||||
fprintf(stderr, "Failed to read input file: %s\n", parserRes.pInFile);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ID3D10Blob* pShader = 0;
|
||||
ID3D10Blob* pErr = 0;
|
||||
|
||||
bool successful = SUCCEEDED(D3DCompile(&program[0], program.size(), parserRes.pInFile, 0, 0, parserRes.pEntry, parserRes.pProfile, parserRes.compilerFlags, 0, &pShader, &pErr)) && pShader;
|
||||
|
||||
if (successful)
|
||||
{
|
||||
const unsigned char* pCode = (unsigned char*) pShader->GetBufferPointer();
|
||||
const size_t codeSize = pShader->GetBufferSize();
|
||||
|
||||
if (!parserRes.disassemble)
|
||||
{
|
||||
successful = WriteByteCode(parserRes.pOutFile, pCode, codeSize);
|
||||
if (!successful)
|
||||
{
|
||||
fprintf(stderr, "Failed to write output file: %s\n", parserRes.pOutFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ID3D10Blob* pDisassembled = 0;
|
||||
successful = SUCCEEDED(D3DDisassemble(pCode, codeSize, 0, 0, &pDisassembled)) && pDisassembled;
|
||||
|
||||
if (successful)
|
||||
{
|
||||
const char* pDisassembly = (char*) pDisassembled->GetBufferPointer();
|
||||
const char* pHdrVarName = parserRes.pHeaderVariableName ? parserRes.pHeaderVariableName : parserRes.pEntry;
|
||||
successful = WriteHexListing(parserRes.pOutFile, pHdrVarName, pDisassembly, pCode, codeSize);
|
||||
if (!successful)
|
||||
{
|
||||
fprintf(stderr, "Failed to write output file: %s\n", parserRes.pOutFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Failed to disassemble shader code\n", parserRes.pOutFile);
|
||||
}
|
||||
|
||||
if (pDisassembled)
|
||||
{
|
||||
pDisassembled->Release();
|
||||
pDisassembled = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pErr)
|
||||
{
|
||||
const char* pMsg = (const char*) pErr->GetBufferPointer();
|
||||
fprintf(stderr, "%s\n", pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
if (pShader)
|
||||
{
|
||||
pShader->Release();
|
||||
pShader = 0;
|
||||
}
|
||||
|
||||
if (pErr)
|
||||
{
|
||||
pErr->Release();
|
||||
pErr = 0;
|
||||
}
|
||||
|
||||
return successful ? 0 : 1;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#include "stdafx.h"
|
||||
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "targetver.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <D3DX11.h>
|
||||
#include <D3Dcompiler.h>
|
||||
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
// Original file Copyright Crytek GMBH or its affiliates, used under license.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDKDDKVer.h>
|
||||
@ -1,57 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
ly_add_target(
|
||||
NAME HLSLcc.Headers HEADERONLY
|
||||
NAMESPACE AZ
|
||||
FILES_CMAKE
|
||||
hlslcc_header_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
INTERFACE
|
||||
include
|
||||
)
|
||||
|
||||
if (NOT PAL_TRAIT_BUILD_HOST_TOOLS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
ly_add_target(
|
||||
NAME HLSLcc EXECUTABLE
|
||||
NAMESPACE AZ
|
||||
OUTPUT_SUBDIRECTORY Compiler/PCGL/V006
|
||||
FILES_CMAKE
|
||||
hlslcc_files.cmake
|
||||
PLATFORM_INCLUDE_FILES
|
||||
Platform/${PAL_PLATFORM_NAME}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PRIVATE
|
||||
src
|
||||
src/cbstring
|
||||
offline/cjson
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
AZ::AzCore
|
||||
PUBLIC
|
||||
AZ::HLSLcc.Headers
|
||||
)
|
||||
ly_add_source_properties(
|
||||
SOURCES
|
||||
offline/compilerStandalone.cpp
|
||||
offline/cjson/cJSON.c
|
||||
src/toGLSL.c
|
||||
src/toGLSLDeclaration.c
|
||||
src/cbstring/bstrlib.c
|
||||
src/cbstring/bstraux.c
|
||||
src/reflect.c
|
||||
src/amazon_changes.c
|
||||
PROPERTY COMPILE_DEFINITIONS
|
||||
VALUES _CRT_SECURE_NO_WARNINGS
|
||||
)
|
||||
@ -1,10 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
@ -1,11 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
file(TO_CMAKE_PATH "$ENV{ProgramFiles\(x86\)}" program_files_path)
|
||||
|
||||
ly_add_target_files(
|
||||
TARGETS HLSLcc
|
||||
FILES
|
||||
"${program_files_path}/Windows Kits/10/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/x64/d3dcompiler_47.dll"
|
||||
)
|
||||
@ -1,71 +0,0 @@
|
||||
Overview:
|
||||
This is a modified version of https://github.com/James-Jones/HLSLCrossCompiler
|
||||
|
||||
It can be used either:
|
||||
1. As an executable.
|
||||
This is the default use case for release builds
|
||||
This is run by the RemoteShaderCompiler when compiling the shaders for the GL4 and GLES3 platforms.
|
||||
2. As a static library.
|
||||
This is used by the DXGL translation layer if compiled with DXGL_USE_GLSL set to 0.
|
||||
In this case DXGL translation layer to translate DirectX shader model 5 bytecode coming from the renderer front end (runtime translation).
|
||||
|
||||
Editing:
|
||||
When modifying the source code, in order to use the updated version in the engine, you will have to recompile the library.
|
||||
To do this, please follow these steps:
|
||||
|
||||
A. Edit /Code/Tools/HLSLCrossCompiler/bin/mk/rsc_version.txt and bump the version string.
|
||||
Please use the format for released branches and main:
|
||||
V[3_decimal_digits_version_number]
|
||||
and optionally for development branches:
|
||||
V[3_decimal_digits_version_number]_[custom_version_label]
|
||||
|
||||
B. From a Windows machine:
|
||||
Verify that the following folders and the contained files are writeable (checkout if needed):
|
||||
- /Code/Tools/HLSLCrossCompiler/bin
|
||||
- /Code/Tools/HLSLCrossCompiler/lib
|
||||
- /Tools/RemoteShaderCompiler/Compiler/PCGL
|
||||
Run:
|
||||
/Code/Tools/HLSLCrossCompiler/mk/build_win_all.py
|
||||
Note:
|
||||
This will compile:
|
||||
- The static library (2) for win32 and win64 in release
|
||||
- The executable (1) with the PORTABLE define enabled (required to run from machines without Direct3D runtime, such ass the RSC servers)
|
||||
for win64 release in and place it in /Tools/RemoteShaderCompiler/Compiler/PCGL/[rsc_version]/
|
||||
|
||||
C. From a Linux machine:
|
||||
Verify that the following folder and the contained files are writeable (checkout if needed):
|
||||
- /Code/Tools/HLSLCrossCompiler/lib
|
||||
Run:
|
||||
/Code/Tools/HLSLCrossCompiler/mk/build_linux_all.py
|
||||
Note:
|
||||
This will compile:
|
||||
- The static library (2) for linux (64 bit) in release
|
||||
- The static library (2) for android (android-armeabi-v7a) in release
|
||||
|
||||
D. Edit:
|
||||
/Code/CryEngine/RenderDll/Common/Shaders/ShaderCache.cpp
|
||||
and update the two command lines in CShaderMan::mfGetShaderCompileFlags:
|
||||
const char* pCompilerGL4="PCGL/[rsc_version]/HLSLcc.exe [generic_gl4_flags ...]";
|
||||
const char* pCompilerGLES3="PCGL/[rsc_version]/HLSLcc.exe [generic_gles3_flags ...]";
|
||||
with the rsc_version string chosen.
|
||||
|
||||
E. Edit:
|
||||
/Code/CryEngine/RenderDll/Common/Shaders/Shader.h
|
||||
and bump by one minor decimal unit:
|
||||
#define FX_CACHE_VER [major_decimal_digit_0].[minor_decimal_digit_0]
|
||||
Note:
|
||||
This is required to flush cached shaders generated with the previous versions that might be stored
|
||||
in ShaderCache.pak or in a user cache folder.
|
||||
|
||||
Submitting:
|
||||
Before submitting any change to HLSLCrossCompiler source code, please
|
||||
make sure to do so together with the updated:
|
||||
/Code/Tools/HLSLCrossCompiler/bin/mk/rsc_version.txt
|
||||
/Code/Tools/HLSLCrossCompiler/lib/win64/libHLSLcc.lib
|
||||
/Code/Tools/HLSLCrossCompiler/lib/win32/libHLSLcc.lib
|
||||
/Code/Tools/HLSLCrossCompiler/lib/linux/libHLSLcc.a
|
||||
/Code/Tools/HLSLCrossCompiler/lib/android-armeabi-v7a/libHLSLcc.a
|
||||
/Code/CryEngine/RenderDll/Common/Shaders/ShaderCache.cpp
|
||||
/Code/CryEngine/RenderDll/Common/Shaders/Shader.h
|
||||
/Tools/RemoteShaderCompiler/Compiler/PCGL/[rsc_version]/HLSLcc.exe
|
||||
This will make sure there is no mismatch between any cached shaders, and remotely or locally compiled shaders.
|
||||
@ -1,60 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
offline/hash.h
|
||||
offline/serializeReflection.h
|
||||
offline/timer.h
|
||||
offline/compilerStandalone.cpp
|
||||
offline/serializeReflection.cpp
|
||||
offline/timer.cpp
|
||||
offline/cjson/cJSON.h
|
||||
offline/cjson/cJSON.c
|
||||
src/amazon_changes.c
|
||||
src/decode.c
|
||||
src/decodeDX9.c
|
||||
src/reflect.c
|
||||
src/toGLSL.c
|
||||
src/toGLSLDeclaration.c
|
||||
src/toGLSLInstruction.c
|
||||
src/toGLSLOperand.c
|
||||
src/hlslccToolkit.c
|
||||
src/internal_includes/debug.h
|
||||
src/internal_includes/decode.h
|
||||
src/internal_includes/hlslcc_malloc.h
|
||||
src/internal_includes/hlslcc_malloc.c
|
||||
src/internal_includes/languages.h
|
||||
src/internal_includes/reflect.h
|
||||
src/internal_includes/shaderLimits.h
|
||||
src/internal_includes/structs.h
|
||||
src/internal_includes/toGLSLDeclaration.h
|
||||
src/internal_includes/toGLSLInstruction.h
|
||||
src/internal_includes/toGLSLOperand.h
|
||||
src/internal_includes/tokens.h
|
||||
src/internal_includes/tokensDX9.h
|
||||
src/internal_includes/hlslccToolkit.h
|
||||
src/cbstring/bsafe.h
|
||||
src/cbstring/bstraux.h
|
||||
src/cbstring/bstrlib.h
|
||||
src/cbstring/bsafe.c
|
||||
src/cbstring/bstraux.c
|
||||
src/cbstring/bstrlib.c
|
||||
include/amazon_changes.h
|
||||
include/hlslcc.h
|
||||
include/hlslcc.hpp
|
||||
include/hlslcc_bin.hpp
|
||||
include/pstdint.h
|
||||
)
|
||||
|
||||
set(SKIP_UNITY_BUILD_INCLUSION_FILES
|
||||
# 'bsafe.c' tries to forward declar 'strncpy', 'strncat', etc, but they are already declared in other modules. Remove from unity builds conideration
|
||||
src/cbstring/bsafe.c
|
||||
)
|
||||
@ -1,18 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES hlslcc_files.cmake
|
||||
include/amazon_changes.h
|
||||
include/hlslcc.h
|
||||
include/hlslcc.hpp
|
||||
include/pstdint.h
|
||||
include/hlslcc_bin.hpp
|
||||
)
|
||||
@ -1,13 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef AMAZON_CHANGES_H
|
||||
#define AMAZON_CHANGES_H
|
||||
|
||||
// There is a bug on the Adreno 420 driver where reinterpret casts can destroy a variable. We need to replace all instances that look like this:
|
||||
// floatBitsToInt(Temp2);
|
||||
// We do not need to change cases that evaluate an expression within the cast operation, like so:
|
||||
// floatBitsToInt(Temp2 + 1.0f);
|
||||
void ModifyLineForQualcommReinterpretCastBug( HLSLCrossCompilerContext* psContext, bstring* originalString, bstring* overloadString );
|
||||
|
||||
#endif // AMAZON_CHANGES_H
|
||||
@ -1,580 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef HLSLCC_H_
|
||||
#define HLSLCC_H_
|
||||
|
||||
#if defined (_WIN32) && defined(HLSLCC_DYNLIB)
|
||||
#define HLSLCC_APIENTRY __stdcall
|
||||
#if defined(libHLSLcc_EXPORTS)
|
||||
#define HLSLCC_API __declspec(dllexport)
|
||||
#else
|
||||
#define HLSLCC_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define HLSLCC_APIENTRY
|
||||
#define HLSLCC_API
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LANG_DEFAULT,// Depends on the HLSL shader model.
|
||||
LANG_ES_100,
|
||||
LANG_ES_300,
|
||||
LANG_ES_310,
|
||||
LANG_120,
|
||||
LANG_130,
|
||||
LANG_140,
|
||||
LANG_150,
|
||||
LANG_330,
|
||||
LANG_400,
|
||||
LANG_410,
|
||||
LANG_420,
|
||||
LANG_430,
|
||||
LANG_440,
|
||||
} GLLang;
|
||||
|
||||
typedef struct {
|
||||
uint32_t ARB_explicit_attrib_location : 1;
|
||||
uint32_t ARB_explicit_uniform_location : 1;
|
||||
uint32_t ARB_shading_language_420pack : 1;
|
||||
}GlExtensions;
|
||||
|
||||
enum {MAX_SHADER_VEC4_OUTPUT = 512};
|
||||
enum {MAX_SHADER_VEC4_INPUT = 512};
|
||||
enum {MAX_TEXTURES = 128};
|
||||
enum {MAX_FORK_PHASES = 2};
|
||||
enum {MAX_FUNCTION_BODIES = 1024};
|
||||
enum {MAX_CLASS_TYPES = 1024};
|
||||
enum {MAX_FUNCTION_POINTERS = 128};
|
||||
|
||||
//Reflection
|
||||
#define MAX_REFLECT_STRING_LENGTH 512
|
||||
#define MAX_SHADER_VARS 256
|
||||
#define MAX_CBUFFERS 256
|
||||
#define MAX_UAV 256
|
||||
#define MAX_FUNCTION_TABLES 256
|
||||
#define MAX_RESOURCE_BINDINGS 256
|
||||
|
||||
//Operands flags
|
||||
#define TO_FLAG_NONE 0x0
|
||||
#define TO_FLAG_INTEGER 0x1
|
||||
#define TO_FLAG_NAME_ONLY 0x2
|
||||
#define TO_FLAG_DECLARATION_NAME 0x4
|
||||
#define TO_FLAG_DESTINATION 0x8 //Operand is being written to by assignment.
|
||||
#define TO_FLAG_UNSIGNED_INTEGER 0x10
|
||||
#define TO_FLAG_DOUBLE 0x20
|
||||
#define TO_FLAG_FLOAT 0x40
|
||||
#define TO_FLAG_COPY 0x80
|
||||
|
||||
typedef enum SPECIAL_NAME
|
||||
{
|
||||
NAME_UNDEFINED = 0,
|
||||
NAME_POSITION = 1,
|
||||
NAME_CLIP_DISTANCE = 2,
|
||||
NAME_CULL_DISTANCE = 3,
|
||||
NAME_RENDER_TARGET_ARRAY_INDEX = 4,
|
||||
NAME_VIEWPORT_ARRAY_INDEX = 5,
|
||||
NAME_VERTEX_ID = 6,
|
||||
NAME_PRIMITIVE_ID = 7,
|
||||
NAME_INSTANCE_ID = 8,
|
||||
NAME_IS_FRONT_FACE = 9,
|
||||
NAME_SAMPLE_INDEX = 10,
|
||||
// The following are added for D3D11
|
||||
NAME_FINAL_QUAD_U_EQ_0_EDGE_TESSFACTOR = 11,
|
||||
NAME_FINAL_QUAD_V_EQ_0_EDGE_TESSFACTOR = 12,
|
||||
NAME_FINAL_QUAD_U_EQ_1_EDGE_TESSFACTOR = 13,
|
||||
NAME_FINAL_QUAD_V_EQ_1_EDGE_TESSFACTOR = 14,
|
||||
NAME_FINAL_QUAD_U_INSIDE_TESSFACTOR = 15,
|
||||
NAME_FINAL_QUAD_V_INSIDE_TESSFACTOR = 16,
|
||||
NAME_FINAL_TRI_U_EQ_0_EDGE_TESSFACTOR = 17,
|
||||
NAME_FINAL_TRI_V_EQ_0_EDGE_TESSFACTOR = 18,
|
||||
NAME_FINAL_TRI_W_EQ_0_EDGE_TESSFACTOR = 19,
|
||||
NAME_FINAL_TRI_INSIDE_TESSFACTOR = 20,
|
||||
NAME_FINAL_LINE_DETAIL_TESSFACTOR = 21,
|
||||
NAME_FINAL_LINE_DENSITY_TESSFACTOR = 22,
|
||||
} SPECIAL_NAME;
|
||||
|
||||
|
||||
typedef enum {
|
||||
INOUT_COMPONENT_UNKNOWN = 0,
|
||||
INOUT_COMPONENT_UINT32 = 1,
|
||||
INOUT_COMPONENT_SINT32 = 2,
|
||||
INOUT_COMPONENT_FLOAT32 = 3
|
||||
} INOUT_COMPONENT_TYPE;
|
||||
|
||||
typedef enum MIN_PRECISION {
|
||||
MIN_PRECISION_DEFAULT = 0,
|
||||
MIN_PRECISION_FLOAT_16 = 1,
|
||||
MIN_PRECISION_FLOAT_2_8 = 2,
|
||||
MIN_PRECISION_RESERVED = 3,
|
||||
MIN_PRECISION_SINT_16 = 4,
|
||||
MIN_PRECISION_UINT_16 = 5,
|
||||
MIN_PRECISION_ANY_16 = 0xf0,
|
||||
MIN_PRECISION_ANY_10 = 0xf1
|
||||
} MIN_PRECISION;
|
||||
|
||||
typedef struct InOutSignature_TAG
|
||||
{
|
||||
char SemanticName[MAX_REFLECT_STRING_LENGTH];
|
||||
uint32_t ui32SemanticIndex;
|
||||
SPECIAL_NAME eSystemValueType;
|
||||
INOUT_COMPONENT_TYPE eComponentType;
|
||||
uint32_t ui32Register;
|
||||
uint32_t ui32Mask;
|
||||
uint32_t ui32ReadWriteMask;
|
||||
|
||||
uint32_t ui32Stream;
|
||||
MIN_PRECISION eMinPrec;
|
||||
|
||||
} InOutSignature;
|
||||
|
||||
typedef enum ResourceType_TAG
|
||||
{
|
||||
RTYPE_CBUFFER,//0
|
||||
RTYPE_TBUFFER,//1
|
||||
RTYPE_TEXTURE,//2
|
||||
RTYPE_SAMPLER,//3
|
||||
RTYPE_UAV_RWTYPED,//4
|
||||
RTYPE_STRUCTURED,//5
|
||||
RTYPE_UAV_RWSTRUCTURED,//6
|
||||
RTYPE_BYTEADDRESS,//7
|
||||
RTYPE_UAV_RWBYTEADDRESS,//8
|
||||
RTYPE_UAV_APPEND_STRUCTURED,//9
|
||||
RTYPE_UAV_CONSUME_STRUCTURED,//10
|
||||
RTYPE_UAV_RWSTRUCTURED_WITH_COUNTER,//11
|
||||
RTYPE_COUNT,
|
||||
} ResourceType;
|
||||
|
||||
typedef enum ResourceGroup_TAG {
|
||||
RGROUP_CBUFFER,
|
||||
RGROUP_TEXTURE,
|
||||
RGROUP_SAMPLER,
|
||||
RGROUP_UAV,
|
||||
RGROUP_COUNT,
|
||||
} ResourceGroup;
|
||||
|
||||
typedef enum REFLECT_RESOURCE_DIMENSION
|
||||
{
|
||||
REFLECT_RESOURCE_DIMENSION_UNKNOWN = 0,
|
||||
REFLECT_RESOURCE_DIMENSION_BUFFER = 1,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE1D = 2,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE1DARRAY = 3,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2D = 4,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2DARRAY = 5,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2DMS = 6,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2DMSARRAY = 7,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE3D = 8,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURECUBE = 9,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURECUBEARRAY = 10,
|
||||
REFLECT_RESOURCE_DIMENSION_BUFFEREX = 11,
|
||||
} REFLECT_RESOURCE_DIMENSION;
|
||||
|
||||
typedef struct ResourceBinding_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
ResourceType eType;
|
||||
uint32_t ui32BindPoint;
|
||||
uint32_t ui32BindCount;
|
||||
uint32_t ui32Flags;
|
||||
REFLECT_RESOURCE_DIMENSION eDimension;
|
||||
uint32_t ui32ReturnType;
|
||||
uint32_t ui32NumSamples;
|
||||
} ResourceBinding;
|
||||
|
||||
// Do not change the value of these enums or they will not match what we find in the DXBC file
|
||||
typedef enum _SHADER_VARIABLE_TYPE {
|
||||
SVT_VOID = 0,
|
||||
SVT_BOOL = 1,
|
||||
SVT_INT = 2,
|
||||
SVT_FLOAT = 3,
|
||||
SVT_STRING = 4,
|
||||
SVT_TEXTURE = 5,
|
||||
SVT_TEXTURE1D = 6,
|
||||
SVT_TEXTURE2D = 7,
|
||||
SVT_TEXTURE3D = 8,
|
||||
SVT_TEXTURECUBE = 9,
|
||||
SVT_SAMPLER = 10,
|
||||
SVT_PIXELSHADER = 15,
|
||||
SVT_VERTEXSHADER = 16,
|
||||
SVT_UINT = 19,
|
||||
SVT_UINT8 = 20,
|
||||
SVT_GEOMETRYSHADER = 21,
|
||||
SVT_RASTERIZER = 22,
|
||||
SVT_DEPTHSTENCIL = 23,
|
||||
SVT_BLEND = 24,
|
||||
SVT_BUFFER = 25,
|
||||
SVT_CBUFFER = 26,
|
||||
SVT_TBUFFER = 27,
|
||||
SVT_TEXTURE1DARRAY = 28,
|
||||
SVT_TEXTURE2DARRAY = 29,
|
||||
SVT_RENDERTARGETVIEW = 30,
|
||||
SVT_DEPTHSTENCILVIEW = 31,
|
||||
SVT_TEXTURE2DMS = 32,
|
||||
SVT_TEXTURE2DMSARRAY = 33,
|
||||
SVT_TEXTURECUBEARRAY = 34,
|
||||
SVT_HULLSHADER = 35,
|
||||
SVT_DOMAINSHADER = 36,
|
||||
SVT_INTERFACE_POINTER = 37,
|
||||
SVT_COMPUTESHADER = 38,
|
||||
SVT_DOUBLE = 39,
|
||||
SVT_RWTEXTURE1D = 40,
|
||||
SVT_RWTEXTURE1DARRAY = 41,
|
||||
SVT_RWTEXTURE2D = 42,
|
||||
SVT_RWTEXTURE2DARRAY = 43,
|
||||
SVT_RWTEXTURE3D = 44,
|
||||
SVT_RWBUFFER = 45,
|
||||
SVT_BYTEADDRESS_BUFFER = 46,
|
||||
SVT_RWBYTEADDRESS_BUFFER = 47,
|
||||
SVT_STRUCTURED_BUFFER = 48,
|
||||
SVT_RWSTRUCTURED_BUFFER = 49,
|
||||
SVT_APPEND_STRUCTURED_BUFFER = 50,
|
||||
SVT_CONSUME_STRUCTURED_BUFFER = 51,
|
||||
|
||||
// Partial precision types
|
||||
SVT_FLOAT10 = 53,
|
||||
SVT_FLOAT16 = 54,
|
||||
SVT_INT16 = 156,
|
||||
SVT_INT12 = 157,
|
||||
SVT_UINT16 = 158,
|
||||
|
||||
SVT_FORCE_DWORD = 0x7fffffff
|
||||
} SHADER_VARIABLE_TYPE;
|
||||
|
||||
typedef enum _SHADER_VARIABLE_CLASS {
|
||||
SVC_SCALAR = 0,
|
||||
SVC_VECTOR = ( SVC_SCALAR + 1 ),
|
||||
SVC_MATRIX_ROWS = ( SVC_VECTOR + 1 ),
|
||||
SVC_MATRIX_COLUMNS = ( SVC_MATRIX_ROWS + 1 ),
|
||||
SVC_OBJECT = ( SVC_MATRIX_COLUMNS + 1 ),
|
||||
SVC_STRUCT = ( SVC_OBJECT + 1 ),
|
||||
SVC_INTERFACE_CLASS = ( SVC_STRUCT + 1 ),
|
||||
SVC_INTERFACE_POINTER = ( SVC_INTERFACE_CLASS + 1 ),
|
||||
SVC_FORCE_DWORD = 0x7fffffff
|
||||
} SHADER_VARIABLE_CLASS;
|
||||
|
||||
typedef struct ShaderVarType_TAG {
|
||||
SHADER_VARIABLE_CLASS Class;
|
||||
SHADER_VARIABLE_TYPE Type;
|
||||
uint32_t Rows;
|
||||
uint32_t Columns;
|
||||
uint32_t Elements;
|
||||
uint32_t MemberCount;
|
||||
uint32_t Offset;
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
|
||||
uint32_t ParentCount;
|
||||
struct ShaderVarType_TAG * Parent;
|
||||
|
||||
struct ShaderVarType_TAG * Members;
|
||||
} ShaderVarType;
|
||||
|
||||
typedef struct ShaderVar_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
int haveDefaultValue;
|
||||
uint32_t* pui32DefaultValues;
|
||||
//Offset/Size in bytes.
|
||||
uint32_t ui32StartOffset;
|
||||
uint32_t ui32Size;
|
||||
uint32_t ui32Flags;
|
||||
|
||||
ShaderVarType sType;
|
||||
} ShaderVar;
|
||||
|
||||
typedef struct ConstantBuffer_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
|
||||
uint32_t ui32NumVars;
|
||||
ShaderVar asVars[MAX_SHADER_VARS];
|
||||
|
||||
uint32_t ui32TotalSizeInBytes;
|
||||
int blob;
|
||||
} ConstantBuffer;
|
||||
|
||||
typedef struct ClassType_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
uint16_t ui16ID;
|
||||
uint16_t ui16ConstBufStride;
|
||||
uint16_t ui16Texture;
|
||||
uint16_t ui16Sampler;
|
||||
} ClassType;
|
||||
|
||||
typedef struct ClassInstance_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
uint16_t ui16ID;
|
||||
uint16_t ui16ConstBuf;
|
||||
uint16_t ui16ConstBufOffset;
|
||||
uint16_t ui16Texture;
|
||||
uint16_t ui16Sampler;
|
||||
} ClassInstance;
|
||||
|
||||
typedef enum TESSELLATOR_PARTITIONING
|
||||
{
|
||||
TESSELLATOR_PARTITIONING_UNDEFINED = 0,
|
||||
TESSELLATOR_PARTITIONING_INTEGER = 1,
|
||||
TESSELLATOR_PARTITIONING_POW2 = 2,
|
||||
TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3,
|
||||
TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4
|
||||
} TESSELLATOR_PARTITIONING;
|
||||
|
||||
typedef enum TESSELLATOR_OUTPUT_PRIMITIVE
|
||||
{
|
||||
TESSELLATOR_OUTPUT_UNDEFINED = 0,
|
||||
TESSELLATOR_OUTPUT_POINT = 1,
|
||||
TESSELLATOR_OUTPUT_LINE = 2,
|
||||
TESSELLATOR_OUTPUT_TRIANGLE_CW = 3,
|
||||
TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4
|
||||
} TESSELLATOR_OUTPUT_PRIMITIVE;
|
||||
|
||||
typedef enum INTERPOLATION_MODE
|
||||
{
|
||||
INTERPOLATION_UNDEFINED = 0,
|
||||
INTERPOLATION_CONSTANT = 1,
|
||||
INTERPOLATION_LINEAR = 2,
|
||||
INTERPOLATION_LINEAR_CENTROID = 3,
|
||||
INTERPOLATION_LINEAR_NOPERSPECTIVE = 4,
|
||||
INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID = 5,
|
||||
INTERPOLATION_LINEAR_SAMPLE = 6,
|
||||
INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE = 7,
|
||||
} INTERPOLATION_MODE;
|
||||
|
||||
typedef enum TRACE_VARIABLE_GROUP
|
||||
{
|
||||
TRACE_VARIABLE_INPUT = 0,
|
||||
TRACE_VARIABLE_TEMP = 1,
|
||||
TRACE_VARIABLE_OUTPUT = 2
|
||||
} TRACE_VARIABLE_GROUP;
|
||||
|
||||
typedef enum TRACE_VARIABLE_TYPE
|
||||
{
|
||||
TRACE_VARIABLE_FLOAT = 0,
|
||||
TRACE_VARIABLE_SINT = 1,
|
||||
TRACE_VARIABLE_UINT = 2,
|
||||
TRACE_VARIABLE_DOUBLE = 3,
|
||||
TRACE_VARIABLE_UNKNOWN = 4
|
||||
} TRACE_VARIABLE_TYPE;
|
||||
|
||||
typedef struct VariableTraceInfo_TAG
|
||||
{
|
||||
TRACE_VARIABLE_GROUP eGroup;
|
||||
TRACE_VARIABLE_TYPE eType;
|
||||
uint8_t ui8Index;
|
||||
uint8_t ui8Component;
|
||||
} VariableTraceInfo;
|
||||
|
||||
typedef struct StepTraceInfo_TAG
|
||||
{
|
||||
uint32_t ui32NumVariables;
|
||||
VariableTraceInfo* psVariables;
|
||||
} StepTraceInfo;
|
||||
|
||||
typedef enum SYMBOL_TYPE
|
||||
{
|
||||
SYMBOL_TESSELLATOR_PARTITIONING = 0,
|
||||
SYMBOL_TESSELLATOR_OUTPUT_PRIMITIVE = 1,
|
||||
SYMBOL_INPUT_INTERPOLATION_MODE = 2,
|
||||
SYMBOL_EMULATE_DEPTH_CLAMP = 3
|
||||
} SYMBOL_TYPE;
|
||||
|
||||
typedef struct Symbol_TAG
|
||||
{
|
||||
SYMBOL_TYPE eType;
|
||||
uint32_t ui32ID;
|
||||
uint32_t ui32Value;
|
||||
} Symbol;
|
||||
|
||||
typedef struct EmbeddedResourceName_TAG
|
||||
{
|
||||
uint32_t ui20Offset : 20;
|
||||
uint32_t ui12Size : 12;
|
||||
} EmbeddedResourceName;
|
||||
|
||||
typedef struct SamplerMask_TAG
|
||||
{
|
||||
uint32_t ui10TextureBindPoint : 10;
|
||||
uint32_t ui10SamplerBindPoint : 10;
|
||||
uint32_t ui10TextureUnit : 10;
|
||||
uint32_t bNormalSample : 1;
|
||||
uint32_t bCompareSample : 1;
|
||||
} SamplerMask;
|
||||
|
||||
typedef struct Sampler_TAG
|
||||
{
|
||||
SamplerMask sMask;
|
||||
EmbeddedResourceName sNormalName;
|
||||
EmbeddedResourceName sCompareName;
|
||||
} Sampler;
|
||||
|
||||
typedef struct Resource_TAG
|
||||
{
|
||||
uint32_t ui32BindPoint;
|
||||
ResourceGroup eGroup;
|
||||
EmbeddedResourceName sName;
|
||||
} Resource;
|
||||
|
||||
typedef struct ShaderInfo_TAG
|
||||
{
|
||||
uint32_t ui32MajorVersion;
|
||||
uint32_t ui32MinorVersion;
|
||||
|
||||
uint32_t ui32NumInputSignatures;
|
||||
InOutSignature* psInputSignatures;
|
||||
|
||||
uint32_t ui32NumOutputSignatures;
|
||||
InOutSignature* psOutputSignatures;
|
||||
|
||||
uint32_t ui32NumResourceBindings;
|
||||
ResourceBinding* psResourceBindings;
|
||||
|
||||
uint32_t ui32NumConstantBuffers;
|
||||
ConstantBuffer* psConstantBuffers;
|
||||
ConstantBuffer* psThisPointerConstBuffer;
|
||||
|
||||
uint32_t ui32NumClassTypes;
|
||||
ClassType* psClassTypes;
|
||||
|
||||
uint32_t ui32NumClassInstances;
|
||||
ClassInstance* psClassInstances;
|
||||
|
||||
//Func table ID to class name ID.
|
||||
uint32_t aui32TableIDToTypeID[MAX_FUNCTION_TABLES];
|
||||
|
||||
uint32_t aui32ResourceMap[RGROUP_COUNT][MAX_RESOURCE_BINDINGS];
|
||||
|
||||
// GLSL resources
|
||||
Sampler asSamplers[MAX_RESOURCE_BINDINGS];
|
||||
Resource asImages[MAX_RESOURCE_BINDINGS];
|
||||
Resource asUniformBuffers[MAX_RESOURCE_BINDINGS];
|
||||
Resource asStorageBuffers[MAX_RESOURCE_BINDINGS];
|
||||
uint32_t ui32NumSamplers;
|
||||
uint32_t ui32NumImages;
|
||||
uint32_t ui32NumUniformBuffers;
|
||||
uint32_t ui32NumStorageBuffers;
|
||||
|
||||
// Trace info if tracing is enabled
|
||||
uint32_t ui32NumTraceSteps;
|
||||
StepTraceInfo* psTraceSteps;
|
||||
|
||||
// Symbols imported
|
||||
uint32_t ui32NumImports;
|
||||
Symbol* psImports;
|
||||
|
||||
// Symbols exported
|
||||
uint32_t ui32NumExports;
|
||||
Symbol* psExports;
|
||||
|
||||
// Hash of the input shader for debugging purposes
|
||||
uint32_t ui32InputHash;
|
||||
|
||||
// Offset in the GLSL string where symbol definitions can be inserted
|
||||
uint32_t ui32SymbolsOffset;
|
||||
|
||||
TESSELLATOR_PARTITIONING eTessPartitioning;
|
||||
TESSELLATOR_OUTPUT_PRIMITIVE eTessOutPrim;
|
||||
|
||||
//Required if PixelInterpDependency is true
|
||||
INTERPOLATION_MODE aePixelInputInterpolation[MAX_SHADER_VEC4_INPUT];
|
||||
} ShaderInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int shaderType; //One of the GL enums.
|
||||
char* sourceCode;
|
||||
ShaderInfo reflection;
|
||||
GLLang GLSLLanguage;
|
||||
} GLSLShader;
|
||||
|
||||
typedef enum _FRAMEBUFFER_FETCH_TYPE
|
||||
{
|
||||
FBF_NONE = 0,
|
||||
FBF_EXT_COLOR = 1 << 0,
|
||||
FBF_ARM_COLOR = 1 << 1,
|
||||
FBF_ARM_DEPTH = 1 << 2,
|
||||
FBF_ARM_STENCIL = 1 << 3,
|
||||
FBF_ANY = FBF_EXT_COLOR | FBF_ARM_COLOR | FBF_ARM_DEPTH | FBF_ARM_STENCIL
|
||||
} FRAMEBUFFER_FETCH_TYPE;
|
||||
|
||||
// NOTE: HLSLCC flags are specified by command line when executing this cross compiler.
|
||||
// If these flags change, the command line switch '-flags=XXX' must change as well.
|
||||
// Open 3D Engine composes the command line in file 'dev\Code\CryEngine\RenderDll\Common\Shaders\RemoteCompiler.cpp'
|
||||
|
||||
/*HLSL constant buffers are treated as default-block unform arrays by default. This is done
|
||||
to support versions of GLSL which lack ARB_uniform_buffer_object functionality.
|
||||
Setting this flag causes each one to have its own uniform block.
|
||||
Note: Currently the nth const buffer will be named UnformBufferN. This is likey to change to the original HLSL name in the future.*/
|
||||
static const unsigned int HLSLCC_FLAG_UNIFORM_BUFFER_OBJECT = 0x1;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_ORIGIN_UPPER_LEFT = 0x2;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_PIXEL_CENTER_INTEGER = 0x4;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_GLOBAL_CONSTS_NEVER_IN_UBO = 0x8;
|
||||
|
||||
//GS enabled?
|
||||
//Affects vertex shader (i.e. need to compile vertex shader again to use with/without GS).
|
||||
//This flag is needed in order for the interfaces between stages to match when GS is in use.
|
||||
//PS inputs VtxGeoOutput
|
||||
//GS outputs VtxGeoOutput
|
||||
//Vs outputs VtxOutput if GS enabled. VtxGeoOutput otherwise.
|
||||
static const unsigned int HLSLCC_FLAG_GS_ENABLED = 0x10;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_TESS_ENABLED = 0x20;
|
||||
|
||||
//Either use this flag or glBindFragDataLocationIndexed.
|
||||
//When set the first pixel shader output is the first input to blend
|
||||
//equation, the others go to the second input.
|
||||
static const unsigned int HLSLCC_FLAG_DUAL_SOURCE_BLENDING = 0x40;
|
||||
|
||||
//If set, shader inputs and outputs are declared with their semantic name.
|
||||
static const unsigned int HLSLCC_FLAG_INOUT_SEMANTIC_NAMES = 0x80;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_INVERT_CLIP_SPACE_Y = 0x100;
|
||||
static const unsigned int HLSLCC_FLAG_CONVERT_CLIP_SPACE_Z = 0x200;
|
||||
static const unsigned int HLSLCC_FLAG_AVOID_RESOURCE_BINDINGS_AND_LOCATIONS = 0x400;
|
||||
static const unsigned int HLSLCC_FLAG_AVOID_TEMP_REGISTER_ALIASING = 0x800;
|
||||
static const unsigned int HLSLCC_FLAG_TRACING_INSTRUMENTATION = 0x1000;
|
||||
static const unsigned int HLSLCC_FLAG_HASH_INPUT = 0x2000;
|
||||
static const unsigned int HLSLCC_FLAG_ADD_DEBUG_HEADER = 0x4000;
|
||||
static const unsigned int HLSLCC_FLAG_NO_VERSION_STRING = 0x8000;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_AVOID_SHADER_LOAD_STORE_EXTENSION = 0x10000;
|
||||
|
||||
// If set, HLSLcc will generate GLSL code which contains syntactic workarounds for
|
||||
// driver bugs found in Qualcomm devices running OpenGL ES 3.0
|
||||
static const unsigned int HLSLCC_FLAG_QUALCOMM_GLES30_DRIVER_WORKAROUND = 0x20000;
|
||||
|
||||
// If set, HLSL DX9 lower precision qualifiers (e.g half) will be transformed to DX11 style (e.g min16float)
|
||||
// before compiling. Necessary to preserve precision information. If not, FXC just silently transform
|
||||
// everything to full precision (e.g float32).
|
||||
static const unsigned int HLSLCC_FLAG_HALF_FLOAT_TRANSFORM = 0x40000;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
HLSLCC_API void HLSLCC_APIENTRY HLSLcc_SetMemoryFunctions(void* (*malloc_override)(size_t),
|
||||
void* (*calloc_override)(size_t,size_t),
|
||||
void (*free_override)(void *),
|
||||
void* (*realloc_override)(void*,size_t));
|
||||
|
||||
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromFile(const char* filename, unsigned int flags, GLLang language, const GlExtensions *extensions, GLSLShader* result);
|
||||
|
||||
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromMem(const char* shader, size_t size, unsigned int flags, GLLang language, const GlExtensions *extensions, GLSLShader* result);
|
||||
|
||||
HLSLCC_API const char* HLSLCC_APIENTRY GetVersionString(GLLang language);
|
||||
|
||||
HLSLCC_API void HLSLCC_APIENTRY FreeGLSLShader(GLSLShader*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
extern "C" {
|
||||
#include "hlslcc.h"
|
||||
}
|
||||
|
||||
@ -1,419 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24 ))
|
||||
|
||||
enum
|
||||
{
|
||||
DXBC_BASE_ALIGNMENT = 4,
|
||||
FOURCC_DXBC = FOURCC('D', 'X', 'B', 'C'),
|
||||
FOURCC_RDEF = FOURCC('R', 'D', 'E', 'F'),
|
||||
FOURCC_ISGN = FOURCC('I', 'S', 'G', 'N'),
|
||||
FOURCC_OSGN = FOURCC('O', 'S', 'G', 'N'),
|
||||
FOURCC_PCSG = FOURCC('P', 'C', 'S', 'G'),
|
||||
FOURCC_SHDR = FOURCC('S', 'H', 'D', 'R'),
|
||||
FOURCC_SHEX = FOURCC('S', 'H', 'E', 'X'),
|
||||
FOURCC_GLSL = FOURCC('G', 'L', 'S', 'L'),
|
||||
FOURCC_ISG1 = FOURCC('I', 'S', 'G', '1'), // When lower precision float/int/uint is used
|
||||
FOURCC_OSG1 = FOURCC('O', 'S', 'G', '1'), // When lower precision float/int/uint is used
|
||||
};
|
||||
|
||||
#undef FOURCC
|
||||
|
||||
template <typename T>
|
||||
inline T DXBCSwapBytes(const T& kValue)
|
||||
{
|
||||
return kValue;
|
||||
}
|
||||
|
||||
#if defined(__BIG_ENDIAN__) || SYSTEM_IS_BIG_ENDIAN
|
||||
|
||||
inline uint16_t DXBCSwapBytes(const uint16_t& uValue)
|
||||
{
|
||||
return
|
||||
(((uValue) >> 8) & 0xFF) |
|
||||
(((uValue) << 8) & 0xFF);
|
||||
}
|
||||
|
||||
inline uint32_t DXBCSwapBytes(const uint32_t& uValue)
|
||||
{
|
||||
return
|
||||
(((uValue) >> 24) & 0x000000FF) |
|
||||
(((uValue) >> 8) & 0x0000FF00) |
|
||||
(((uValue) << 8) & 0x00FF0000) |
|
||||
(((uValue) << 24) & 0xFF000000);
|
||||
}
|
||||
|
||||
#endif //defined(__BIG_ENDIAN__) || SYSTEM_IS_BIG_ENDIAN
|
||||
|
||||
template <typename Element>
|
||||
struct SDXBCBufferBase
|
||||
{
|
||||
Element* m_pBegin;
|
||||
Element* m_pEnd;
|
||||
Element* m_pIter;
|
||||
|
||||
SDXBCBufferBase(Element* pBegin, Element* pEnd)
|
||||
: m_pBegin(pBegin)
|
||||
, m_pEnd(pEnd)
|
||||
, m_pIter(pBegin)
|
||||
{
|
||||
}
|
||||
|
||||
bool SeekRel(int32_t iOffset)
|
||||
{
|
||||
Element* pIterAfter(m_pIter + iOffset);
|
||||
if (pIterAfter > m_pEnd)
|
||||
return false;
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SeekAbs(uint32_t uPosition)
|
||||
{
|
||||
Element* pIterAfter(m_pBegin + uPosition);
|
||||
if (pIterAfter > m_pEnd)
|
||||
return false;
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct SDXBCInputBuffer : SDXBCBufferBase<const uint8_t>
|
||||
{
|
||||
SDXBCInputBuffer(const uint8_t* pBegin, const uint8_t* pEnd)
|
||||
: SDXBCBufferBase(pBegin, pEnd)
|
||||
{
|
||||
}
|
||||
|
||||
bool Read(void* pElements, size_t uSize)
|
||||
{
|
||||
const uint8_t* pIterAfter(m_pIter + uSize);
|
||||
if (pIterAfter > m_pEnd)
|
||||
return false;
|
||||
|
||||
memcpy(pElements, m_pIter, uSize);
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct SDXBCOutputBuffer : SDXBCBufferBase<uint8_t>
|
||||
{
|
||||
SDXBCOutputBuffer(uint8_t* pBegin, uint8_t* pEnd)
|
||||
: SDXBCBufferBase(pBegin, pEnd)
|
||||
{
|
||||
}
|
||||
|
||||
bool Write(const void* pElements, size_t uSize)
|
||||
{
|
||||
uint8_t* pIterAfter(m_pIter + uSize);
|
||||
if (pIterAfter > m_pEnd)
|
||||
return false;
|
||||
|
||||
memcpy(m_pIter, pElements, uSize);
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename S, typename External, typename Internal>
|
||||
inline bool DXBCReadAs(S& kStream, External& kValue)
|
||||
{
|
||||
Internal kInternal;
|
||||
bool bResult(kStream.Read(&kInternal, sizeof(Internal)));
|
||||
kValue = static_cast<External>(DXBCSwapBytes(kInternal));
|
||||
return bResult;
|
||||
}
|
||||
|
||||
template <typename S, typename Internal>
|
||||
inline bool DXBCWriteAs(S& kStream, Internal kValue)
|
||||
{
|
||||
Internal kInternal(DXBCSwapBytes(kValue));
|
||||
return kStream.Write(&kInternal, sizeof(Internal));
|
||||
}
|
||||
|
||||
template <typename S, typename T> bool DXBCReadUint8 (S& kStream, T& kValue) { return DXBCReadAs<S, T, uint8_t >(kStream, kValue); }
|
||||
template <typename S, typename T> bool DXBCReadUint16(S& kStream, T& kValue) { return DXBCReadAs<S, T, uint16_t>(kStream, kValue); }
|
||||
template <typename S, typename T> bool DXBCReadUint32(S& kStream, T& kValue) { return DXBCReadAs<S, T, uint32_t>(kStream, kValue); }
|
||||
|
||||
template <typename S> bool DXBCWriteUint8 (S& kStream, uint8_t kValue) { return DXBCWriteAs<S, uint8_t >(kStream, kValue); }
|
||||
template <typename S> bool DXBCWriteUint16(S& kStream, uint16_t kValue) { return DXBCWriteAs<S, uint16_t>(kStream, kValue); }
|
||||
template <typename S> bool DXBCWriteUint32(S& kStream, uint32_t kValue) { return DXBCWriteAs<S, uint32_t>(kStream, kValue); }
|
||||
|
||||
template <typename O, typename I>
|
||||
bool DXBCCopy(O& kOutput, I& kInput, size_t uSize)
|
||||
{
|
||||
char acBuffer[1024];
|
||||
while (uSize > 0)
|
||||
{
|
||||
size_t uToCopy(std::min<size_t>(uSize, sizeof(acBuffer)));
|
||||
if (!kInput.Read(acBuffer, uToCopy) ||
|
||||
!kOutput.Write(acBuffer, uToCopy))
|
||||
return false;
|
||||
uSize -= uToCopy;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
DXBC_SIZE_POSITION = 6 * 4,
|
||||
DXBC_HEADER_SIZE = 7 * 4,
|
||||
DXBC_CHUNK_HEADER_SIZE = 2 * 4,
|
||||
DXBC_MAX_NUM_CHUNKS_IN = 128,
|
||||
DXBC_MAX_NUM_CHUNKS_OUT = 8,
|
||||
DXBC_OUT_CHUNKS_INDEX_SIZE = (1 + 1 + DXBC_MAX_NUM_CHUNKS_OUT) * 4,
|
||||
DXBC_OUT_FIXED_SIZE = DXBC_HEADER_SIZE + DXBC_OUT_CHUNKS_INDEX_SIZE,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
GLSL_HEADER_SIZE = 4 * 8, // uNumSamplers, uNumImages, uNumStorageBuffers, uNumUniformBuffers, uNumImports, uNumExports, uInputHash, uSymbolsOffset
|
||||
GLSL_SAMPLER_SIZE = 4 * 3, // uSamplerField, uEmbeddedNormalName, uEmbeddedCompareName
|
||||
GLSL_RESOURCE_SIZE = 4 * 2, // uBindPoint, uName
|
||||
GLSL_SYMBOL_SIZE = 4 * 3, // uType, uID, uValue
|
||||
};
|
||||
|
||||
inline void DXBCSizeGLSLChunk(uint32_t& uGLSLChunkSize, uint32_t& uGLSLSourceSize, const GLSLShader* pShader)
|
||||
{
|
||||
uint32_t uNumSymbols(
|
||||
pShader->reflection.ui32NumImports +
|
||||
pShader->reflection.ui32NumExports);
|
||||
uint32_t uGLSLInfoSize(
|
||||
DXBC_CHUNK_HEADER_SIZE +
|
||||
GLSL_HEADER_SIZE +
|
||||
pShader->reflection.ui32NumSamplers * GLSL_SAMPLER_SIZE +
|
||||
pShader->reflection.ui32NumImages * GLSL_RESOURCE_SIZE +
|
||||
pShader->reflection.ui32NumStorageBuffers * GLSL_RESOURCE_SIZE +
|
||||
pShader->reflection.ui32NumUniformBuffers * GLSL_RESOURCE_SIZE +
|
||||
uNumSymbols * GLSL_SYMBOL_SIZE);
|
||||
uGLSLSourceSize = (uint32_t)strlen(pShader->sourceCode) + 1;
|
||||
uGLSLChunkSize = uGLSLInfoSize + uGLSLSourceSize;
|
||||
uGLSLChunkSize += DXBC_BASE_ALIGNMENT - 1 - (uGLSLChunkSize - 1) % DXBC_BASE_ALIGNMENT;
|
||||
}
|
||||
|
||||
inline uint32_t DXBCSizeOutputChunk(uint32_t uCode, uint32_t uSizeIn)
|
||||
{
|
||||
uint32_t uSizeOut;
|
||||
switch (uCode)
|
||||
{
|
||||
case FOURCC_RDEF:
|
||||
case FOURCC_ISGN:
|
||||
case FOURCC_OSGN:
|
||||
case FOURCC_PCSG:
|
||||
case FOURCC_OSG1:
|
||||
case FOURCC_ISG1:
|
||||
// Preserve entire chunk
|
||||
uSizeOut = uSizeIn;
|
||||
break;
|
||||
case FOURCC_SHDR:
|
||||
case FOURCC_SHEX:
|
||||
// Only keep the shader version
|
||||
uSizeOut = uSizeIn < 4u ? uSizeIn : 4u;
|
||||
break;
|
||||
default:
|
||||
// Discard the chunk
|
||||
uSizeOut = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return uSizeOut + DXBC_BASE_ALIGNMENT - 1 - (uSizeOut - 1) % DXBC_BASE_ALIGNMENT;
|
||||
}
|
||||
|
||||
template <typename I>
|
||||
size_t DXBCGetCombinedSize(I& kDXBCInput, const GLSLShader* pShader)
|
||||
{
|
||||
uint32_t uNumChunksIn;
|
||||
if (!kDXBCInput.SeekAbs(DXBC_HEADER_SIZE) ||
|
||||
!DXBCReadUint32(kDXBCInput, uNumChunksIn))
|
||||
return 0;
|
||||
|
||||
uint32_t auChunkOffsetsIn[DXBC_MAX_NUM_CHUNKS_IN];
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
|
||||
{
|
||||
if (!DXBCReadUint32(kDXBCInput, auChunkOffsetsIn[uChunk]))
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t uNumChunksOut(0);
|
||||
uint32_t uOutSize(DXBC_OUT_FIXED_SIZE);
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn && uNumChunksOut < DXBC_MAX_NUM_CHUNKS_OUT; ++uChunk)
|
||||
{
|
||||
uint32_t uChunkCode, uChunkSizeIn;
|
||||
if (!kDXBCInput.SeekAbs(auChunkOffsetsIn[uChunk]) ||
|
||||
!DXBCReadUint32(kDXBCInput, uChunkCode) ||
|
||||
!DXBCReadUint32(kDXBCInput, uChunkSizeIn))
|
||||
return 0;
|
||||
|
||||
uint32_t uChunkSizeOut(DXBCSizeOutputChunk(uChunkCode, uChunkSizeIn));
|
||||
if (uChunkSizeOut > 0)
|
||||
{
|
||||
uOutSize += DXBC_CHUNK_HEADER_SIZE + uChunkSizeOut;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t uGLSLSourceSize, uGLSLChunkSize;
|
||||
DXBCSizeGLSLChunk(uGLSLChunkSize, uGLSLSourceSize, pShader);
|
||||
uOutSize += uGLSLChunkSize;
|
||||
|
||||
return uOutSize;
|
||||
}
|
||||
|
||||
template <typename I, typename O>
|
||||
bool DXBCCombineWithGLSL(I& kInput, O& kOutput, const GLSLShader* pShader)
|
||||
{
|
||||
uint32_t uNumChunksIn;
|
||||
if (!DXBCCopy(kOutput, kInput, DXBC_HEADER_SIZE) ||
|
||||
!DXBCReadUint32(kInput, uNumChunksIn) ||
|
||||
uNumChunksIn > DXBC_MAX_NUM_CHUNKS_IN)
|
||||
return false;
|
||||
|
||||
uint32_t auChunkOffsetsIn[DXBC_MAX_NUM_CHUNKS_IN];
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
|
||||
{
|
||||
if (!DXBCReadUint32(kInput, auChunkOffsetsIn[uChunk]))
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t auZeroChunkIndex[DXBC_OUT_CHUNKS_INDEX_SIZE] = {0};
|
||||
if (!kOutput.Write(auZeroChunkIndex, DXBC_OUT_CHUNKS_INDEX_SIZE))
|
||||
return false;
|
||||
|
||||
// Copy required input chunks just after the chunk index
|
||||
uint32_t uOutSize(DXBC_OUT_FIXED_SIZE);
|
||||
uint32_t uNumChunksOut(0);
|
||||
uint32_t auChunkOffsetsOut[DXBC_MAX_NUM_CHUNKS_OUT];
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
|
||||
{
|
||||
uint32_t uChunkCode, uChunkSizeIn;
|
||||
if (!kInput.SeekAbs(auChunkOffsetsIn[uChunk]) ||
|
||||
!DXBCReadUint32(kInput, uChunkCode) ||
|
||||
!DXBCReadUint32(kInput, uChunkSizeIn))
|
||||
return false;
|
||||
|
||||
// Filter only input chunks of the specified types
|
||||
uint32_t uChunkSizeOut(DXBCSizeOutputChunk(uChunkCode, uChunkSizeIn));
|
||||
if (uChunkSizeOut > 0)
|
||||
{
|
||||
if (uNumChunksOut >= DXBC_MAX_NUM_CHUNKS_OUT)
|
||||
return false;
|
||||
|
||||
if (!DXBCWriteUint32(kOutput, uChunkCode) ||
|
||||
!DXBCWriteUint32(kOutput, uChunkSizeOut) ||
|
||||
!DXBCCopy(kOutput, kInput, uChunkSizeOut))
|
||||
return false;
|
||||
|
||||
auChunkOffsetsOut[uNumChunksOut] = uOutSize;
|
||||
++uNumChunksOut;
|
||||
uOutSize += DXBC_CHUNK_HEADER_SIZE + uChunkSizeOut;
|
||||
}
|
||||
}
|
||||
|
||||
// Write GLSL chunk
|
||||
uint32_t uGLSLChunkOffset(uOutSize);
|
||||
uint32_t uGLSLChunkSize, uGLSLSourceSize;
|
||||
DXBCSizeGLSLChunk(uGLSLChunkSize, uGLSLSourceSize, pShader);
|
||||
if (!DXBCWriteUint32(kOutput, (uint32_t)FOURCC_GLSL) ||
|
||||
!DXBCWriteUint32(kOutput, uGLSLChunkSize) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumSamplers) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumImages) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumStorageBuffers) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumUniformBuffers) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumImports) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumExports) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32InputHash) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32SymbolsOffset))
|
||||
return false;
|
||||
for (uint32_t uSampler = 0; uSampler < pShader->reflection.ui32NumSamplers; ++uSampler)
|
||||
{
|
||||
uint32_t uSamplerField =
|
||||
(pShader->reflection.asSamplers[uSampler].sMask.ui10TextureBindPoint << 22) |
|
||||
(pShader->reflection.asSamplers[uSampler].sMask.ui10SamplerBindPoint << 12) |
|
||||
(pShader->reflection.asSamplers[uSampler].sMask.ui10TextureUnit << 2) |
|
||||
(pShader->reflection.asSamplers[uSampler].sMask.bNormalSample << 1) |
|
||||
(pShader->reflection.asSamplers[uSampler].sMask.bCompareSample << 0);
|
||||
if (!DXBCWriteUint32(kOutput, uSamplerField))
|
||||
return false;
|
||||
|
||||
uint32_t uEmbeddedNormalName =
|
||||
(pShader->reflection.asSamplers[uSampler].sNormalName.ui20Offset << 12) |
|
||||
(pShader->reflection.asSamplers[uSampler].sNormalName.ui12Size << 0);
|
||||
if (!DXBCWriteUint32(kOutput, uEmbeddedNormalName))
|
||||
return false;
|
||||
|
||||
uint32_t uEmbeddedCompareName =
|
||||
(pShader->reflection.asSamplers[uSampler].sCompareName.ui20Offset << 12) |
|
||||
(pShader->reflection.asSamplers[uSampler].sCompareName.ui12Size << 0);
|
||||
if (!DXBCWriteUint32(kOutput, uEmbeddedCompareName))
|
||||
return false;
|
||||
}
|
||||
for (uint32_t uImage = 0; uImage < pShader->reflection.ui32NumImages; ++uImage)
|
||||
{
|
||||
const Resource* psResource = pShader->reflection.asImages + uImage;
|
||||
uint32_t uEmbeddedName =
|
||||
(psResource->sName.ui20Offset << 12) |
|
||||
(psResource->sName.ui12Size << 0);
|
||||
if (!DXBCWriteUint32(kOutput, psResource->ui32BindPoint) ||
|
||||
!DXBCWriteUint32(kOutput, uEmbeddedName))
|
||||
return false;
|
||||
}
|
||||
for (uint32_t uStorageBuffer = 0; uStorageBuffer < pShader->reflection.ui32NumStorageBuffers; ++uStorageBuffer)
|
||||
{
|
||||
const Resource* psResource = pShader->reflection.asStorageBuffers + uStorageBuffer;
|
||||
uint32_t uEmbeddedName =
|
||||
(psResource->sName.ui20Offset << 12) |
|
||||
(psResource->sName.ui12Size << 0);
|
||||
if (!DXBCWriteUint32(kOutput, psResource->ui32BindPoint) ||
|
||||
!DXBCWriteUint32(kOutput, uEmbeddedName))
|
||||
return false;
|
||||
}
|
||||
for (uint32_t uUniformBuffer = 0; uUniformBuffer < pShader->reflection.ui32NumUniformBuffers; ++uUniformBuffer)
|
||||
{
|
||||
const Resource* psResource = pShader->reflection.asUniformBuffers + uUniformBuffer;
|
||||
uint32_t uEmbeddedName =
|
||||
(psResource->sName.ui20Offset << 12) |
|
||||
(psResource->sName.ui12Size << 0);
|
||||
if (!DXBCWriteUint32(kOutput, psResource->ui32BindPoint) ||
|
||||
!DXBCWriteUint32(kOutput, uEmbeddedName))
|
||||
return false;
|
||||
}
|
||||
for (uint32_t uSymbol = 0; uSymbol < pShader->reflection.ui32NumImports; ++uSymbol)
|
||||
{
|
||||
if (!DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].eType) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].ui32ID) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].ui32Value))
|
||||
return false;
|
||||
}
|
||||
for (uint32_t uSymbol = 0; uSymbol < pShader->reflection.ui32NumExports; ++uSymbol)
|
||||
{
|
||||
if (!DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].eType) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].ui32ID) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].ui32Value))
|
||||
return false;
|
||||
}
|
||||
if (!kOutput.Write(pShader->sourceCode, uGLSLSourceSize))
|
||||
return false;
|
||||
uOutSize += uGLSLChunkSize;
|
||||
|
||||
// Write total size and chunk index
|
||||
if (!kOutput.SeekAbs(DXBC_SIZE_POSITION) ||
|
||||
!DXBCWriteUint32(kOutput, uOutSize) ||
|
||||
!kOutput.SeekAbs(DXBC_HEADER_SIZE) ||
|
||||
!DXBCWriteUint32(kOutput, uNumChunksOut + 1))
|
||||
return false;
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksOut; ++uChunk)
|
||||
{
|
||||
if (!DXBCWriteUint32(kOutput, auChunkOffsetsOut[uChunk]))
|
||||
return false;
|
||||
}
|
||||
DXBCWriteUint32(kOutput, uGLSLChunkOffset);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1,801 +0,0 @@
|
||||
/* A portable stdint.h
|
||||
****************************************************************************
|
||||
* BSD License:
|
||||
****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2005-2011 Paul Hsieh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* Version 0.1.12
|
||||
*
|
||||
* The ANSI C standard committee, for the C99 standard, specified the
|
||||
* inclusion of a new standard include file called stdint.h. This is
|
||||
* a very useful and long desired include file which contains several
|
||||
* very precise definitions for integer scalar types that is
|
||||
* critically important for making portable several classes of
|
||||
* applications including cryptography, hashing, variable length
|
||||
* integer libraries and so on. But for most developers its likely
|
||||
* useful just for programming sanity.
|
||||
*
|
||||
* The problem is that most compiler vendors have decided not to
|
||||
* implement the C99 standard, and the next C++ language standard
|
||||
* (which has a lot more mindshare these days) will be a long time in
|
||||
* coming and its unknown whether or not it will include stdint.h or
|
||||
* how much adoption it will have. Either way, it will be a long time
|
||||
* before all compilers come with a stdint.h and it also does nothing
|
||||
* for the extremely large number of compilers available today which
|
||||
* do not include this file, or anything comparable to it.
|
||||
*
|
||||
* So that's what this file is all about. Its an attempt to build a
|
||||
* single universal include file that works on as many platforms as
|
||||
* possible to deliver what stdint.h is supposed to. A few things
|
||||
* that should be noted about this file:
|
||||
*
|
||||
* 1) It is not guaranteed to be portable and/or present an identical
|
||||
* interface on all platforms. The extreme variability of the
|
||||
* ANSI C standard makes this an impossibility right from the
|
||||
* very get go. Its really only meant to be useful for the vast
|
||||
* majority of platforms that possess the capability of
|
||||
* implementing usefully and precisely defined, standard sized
|
||||
* integer scalars. Systems which are not intrinsically 2s
|
||||
* complement may produce invalid constants.
|
||||
*
|
||||
* 2) There is an unavoidable use of non-reserved symbols.
|
||||
*
|
||||
* 3) Other standard include files are invoked.
|
||||
*
|
||||
* 4) This file may come in conflict with future platforms that do
|
||||
* include stdint.h. The hope is that one or the other can be
|
||||
* used with no real difference.
|
||||
*
|
||||
* 5) In the current verison, if your platform can't represent
|
||||
* int32_t, int16_t and int8_t, it just dumps out with a compiler
|
||||
* error.
|
||||
*
|
||||
* 6) 64 bit integers may or may not be defined. Test for their
|
||||
* presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
|
||||
* Note that this is different from the C99 specification which
|
||||
* requires the existence of 64 bit support in the compiler. If
|
||||
* this is not defined for your platform, yet it is capable of
|
||||
* dealing with 64 bits then it is because this file has not yet
|
||||
* been extended to cover all of your system's capabilities.
|
||||
*
|
||||
* 7) (u)intptr_t may or may not be defined. Test for its presence
|
||||
* with the test: #ifdef PTRDIFF_MAX. If this is not defined
|
||||
* for your platform, then it is because this file has not yet
|
||||
* been extended to cover all of your system's capabilities, not
|
||||
* because its optional.
|
||||
*
|
||||
* 8) The following might not been defined even if your platform is
|
||||
* capable of defining it:
|
||||
*
|
||||
* WCHAR_MIN
|
||||
* WCHAR_MAX
|
||||
* (u)int64_t
|
||||
* PTRDIFF_MIN
|
||||
* PTRDIFF_MAX
|
||||
* (u)intptr_t
|
||||
*
|
||||
* 9) The following have not been defined:
|
||||
*
|
||||
* WINT_MIN
|
||||
* WINT_MAX
|
||||
*
|
||||
* 10) The criteria for defining (u)int_least(*)_t isn't clear,
|
||||
* except for systems which don't have a type that precisely
|
||||
* defined 8, 16, or 32 bit types (which this include file does
|
||||
* not support anyways). Default definitions have been given.
|
||||
*
|
||||
* 11) The criteria for defining (u)int_fast(*)_t isn't something I
|
||||
* would trust to any particular compiler vendor or the ANSI C
|
||||
* committee. It is well known that "compatible systems" are
|
||||
* commonly created that have very different performance
|
||||
* characteristics from the systems they are compatible with,
|
||||
* especially those whose vendors make both the compiler and the
|
||||
* system. Default definitions have been given, but its strongly
|
||||
* recommended that users never use these definitions for any
|
||||
* reason (they do *NOT* deliver any serious guarantee of
|
||||
* improved performance -- not in this file, nor any vendor's
|
||||
* stdint.h).
|
||||
*
|
||||
* 12) The following macros:
|
||||
*
|
||||
* PRINTF_INTMAX_MODIFIER
|
||||
* PRINTF_INT64_MODIFIER
|
||||
* PRINTF_INT32_MODIFIER
|
||||
* PRINTF_INT16_MODIFIER
|
||||
* PRINTF_LEAST64_MODIFIER
|
||||
* PRINTF_LEAST32_MODIFIER
|
||||
* PRINTF_LEAST16_MODIFIER
|
||||
* PRINTF_INTPTR_MODIFIER
|
||||
*
|
||||
* are strings which have been defined as the modifiers required
|
||||
* for the "d", "u" and "x" printf formats to correctly output
|
||||
* (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
|
||||
* (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
|
||||
* PRINTF_INTPTR_MODIFIER is not defined for some systems which
|
||||
* provide their own stdint.h. PRINTF_INT64_MODIFIER is not
|
||||
* defined if INT64_MAX is not defined. These are an extension
|
||||
* beyond what C99 specifies must be in stdint.h.
|
||||
*
|
||||
* In addition, the following macros are defined:
|
||||
*
|
||||
* PRINTF_INTMAX_HEX_WIDTH
|
||||
* PRINTF_INT64_HEX_WIDTH
|
||||
* PRINTF_INT32_HEX_WIDTH
|
||||
* PRINTF_INT16_HEX_WIDTH
|
||||
* PRINTF_INT8_HEX_WIDTH
|
||||
* PRINTF_INTMAX_DEC_WIDTH
|
||||
* PRINTF_INT64_DEC_WIDTH
|
||||
* PRINTF_INT32_DEC_WIDTH
|
||||
* PRINTF_INT16_DEC_WIDTH
|
||||
* PRINTF_INT8_DEC_WIDTH
|
||||
*
|
||||
* Which specifies the maximum number of characters required to
|
||||
* print the number of that type in either hexadecimal or decimal.
|
||||
* These are an extension beyond what C99 specifies must be in
|
||||
* stdint.h.
|
||||
*
|
||||
* Compilers tested (all with 0 warnings at their highest respective
|
||||
* settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
|
||||
* bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
|
||||
* .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
|
||||
*
|
||||
* This file should be considered a work in progress. Suggestions for
|
||||
* improvements, especially those which increase coverage are strongly
|
||||
* encouraged.
|
||||
*
|
||||
* Acknowledgements
|
||||
*
|
||||
* The following people have made significant contributions to the
|
||||
* development and testing of this file:
|
||||
*
|
||||
* Chris Howie
|
||||
* John Steele Scott
|
||||
* Dave Thorup
|
||||
* John Dill
|
||||
*
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
* For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
|
||||
* do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
|
||||
*/
|
||||
|
||||
#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
|
||||
#include <stdint.h>
|
||||
#define _PSTDINT_H_INCLUDED
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INT64_HEX_WIDTH
|
||||
# define PRINTF_INT64_HEX_WIDTH "16"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_HEX_WIDTH
|
||||
# define PRINTF_INT32_HEX_WIDTH "8"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_HEX_WIDTH
|
||||
# define PRINTF_INT16_HEX_WIDTH "4"
|
||||
# endif
|
||||
# ifndef PRINTF_INT8_HEX_WIDTH
|
||||
# define PRINTF_INT8_HEX_WIDTH "2"
|
||||
# endif
|
||||
# ifndef PRINTF_INT64_DEC_WIDTH
|
||||
# define PRINTF_INT64_DEC_WIDTH "20"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_DEC_WIDTH
|
||||
# define PRINTF_INT32_DEC_WIDTH "10"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_DEC_WIDTH
|
||||
# define PRINTF_INT16_DEC_WIDTH "5"
|
||||
# endif
|
||||
# ifndef PRINTF_INT8_DEC_WIDTH
|
||||
# define PRINTF_INT8_DEC_WIDTH "3"
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
|
||||
# endif
|
||||
|
||||
/*
|
||||
* Something really weird is going on with Open Watcom. Just pull some of
|
||||
* these duplicated definitions from Open Watcom's stdint.h file for now.
|
||||
*/
|
||||
|
||||
# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
|
||||
# if !defined (INT64_C)
|
||||
# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
|
||||
# endif
|
||||
# if !defined (UINT64_C)
|
||||
# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
|
||||
# endif
|
||||
# if !defined (INT32_C)
|
||||
# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
|
||||
# endif
|
||||
# if !defined (UINT32_C)
|
||||
# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
|
||||
# endif
|
||||
# if !defined (INT16_C)
|
||||
# define INT16_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT16_C)
|
||||
# define UINT16_C(x) (x)
|
||||
# endif
|
||||
# if !defined (INT8_C)
|
||||
# define INT8_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT8_C)
|
||||
# define UINT8_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT64_MAX)
|
||||
# define UINT64_MAX 18446744073709551615ULL
|
||||
# endif
|
||||
# if !defined (INT64_MAX)
|
||||
# define INT64_MAX 9223372036854775807LL
|
||||
# endif
|
||||
# if !defined (UINT32_MAX)
|
||||
# define UINT32_MAX 4294967295UL
|
||||
# endif
|
||||
# if !defined (INT32_MAX)
|
||||
# define INT32_MAX 2147483647L
|
||||
# endif
|
||||
# if !defined (INTMAX_MAX)
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# endif
|
||||
# if !defined (INTMAX_MIN)
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _PSTDINT_H_INCLUDED
|
||||
#define _PSTDINT_H_INCLUDED
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX (~(size_t)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Deduce the type assignments from limits.h under the assumption that
|
||||
* integer sizes in bits are powers of 2, and follow the ANSI
|
||||
* definitions.
|
||||
*/
|
||||
|
||||
#ifndef UINT8_MAX
|
||||
# define UINT8_MAX 0xff
|
||||
#endif
|
||||
#ifndef uint8_t
|
||||
# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned char uint8_t;
|
||||
# define UINT8_C(v) ((uint8_t) v)
|
||||
# else
|
||||
# error "Platform not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef INT8_MAX
|
||||
# define INT8_MAX 0x7f
|
||||
#endif
|
||||
#ifndef INT8_MIN
|
||||
# define INT8_MIN INT8_C(0x80)
|
||||
#endif
|
||||
#ifndef int8_t
|
||||
# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed char int8_t;
|
||||
# define INT8_C(v) ((int8_t) v)
|
||||
# else
|
||||
# error "Platform not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MAX
|
||||
# define UINT16_MAX 0xffff
|
||||
#endif
|
||||
#ifndef uint16_t
|
||||
#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned int uint16_t;
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER ""
|
||||
# endif
|
||||
# define UINT16_C(v) ((uint16_t) (v))
|
||||
#elif (USHRT_MAX == UINT16_MAX)
|
||||
typedef unsigned short uint16_t;
|
||||
# define UINT16_C(v) ((uint16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
# define INT16_MAX 0x7fff
|
||||
#endif
|
||||
#ifndef INT16_MIN
|
||||
# define INT16_MIN INT16_C(0x8000)
|
||||
#endif
|
||||
#ifndef int16_t
|
||||
#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed int int16_t;
|
||||
# define INT16_C(v) ((int16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER ""
|
||||
# endif
|
||||
#elif (SHRT_MAX == INT16_MAX)
|
||||
typedef signed short int16_t;
|
||||
# define INT16_C(v) ((int16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
# define UINT32_MAX (0xffffffffUL)
|
||||
#endif
|
||||
#ifndef uint32_t
|
||||
#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned long uint32_t;
|
||||
# define UINT32_C(v) v ## UL
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
#elif (UINT_MAX == UINT32_MAX)
|
||||
typedef unsigned int uint32_t;
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
# define UINT32_C(v) v ## U
|
||||
#elif (USHRT_MAX == UINT32_MAX)
|
||||
typedef unsigned short uint32_t;
|
||||
# define UINT32_C(v) ((unsigned short) (v))
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
# define INT32_MAX (0x7fffffffL)
|
||||
#endif
|
||||
#ifndef INT32_MIN
|
||||
# define INT32_MIN INT32_C(0x80000000)
|
||||
#endif
|
||||
#ifndef int32_t
|
||||
#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed long int32_t;
|
||||
# define INT32_C(v) v ## L
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
#elif (INT_MAX == INT32_MAX)
|
||||
typedef signed int int32_t;
|
||||
# define INT32_C(v) v
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#elif (SHRT_MAX == INT32_MAX)
|
||||
typedef signed short int32_t;
|
||||
# define INT32_C(v) ((short) (v))
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The macro stdint_int64_defined is temporarily used to record
|
||||
* whether or not 64 integer support is available. It must be
|
||||
* defined for any 64 integer extensions for new platforms that are
|
||||
* added.
|
||||
*/
|
||||
|
||||
#undef stdint_int64_defined
|
||||
#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
|
||||
# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
|
||||
# define stdint_int64_defined
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (stdint_int64_defined)
|
||||
# if defined(__GNUC__)
|
||||
# define stdint_int64_defined
|
||||
__extension__ typedef long long int64_t;
|
||||
__extension__ typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
|
||||
# define stdint_int64_defined
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
|
||||
# define stdint_int64_defined
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
# define UINT64_C(v) v ## UI64
|
||||
# define INT64_C(v) v ## I64
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "I64"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (LONG_LONG_MAX) && defined (INT64_C)
|
||||
# define LONG_LONG_MAX INT64_C (9223372036854775807)
|
||||
#endif
|
||||
#ifndef ULONG_LONG_MAX
|
||||
# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
|
||||
#endif
|
||||
|
||||
#if !defined (INT64_MAX) && defined (INT64_C)
|
||||
# define INT64_MAX INT64_C (9223372036854775807)
|
||||
#endif
|
||||
#if !defined (INT64_MIN) && defined (INT64_C)
|
||||
# define INT64_MIN INT64_C (-9223372036854775808)
|
||||
#endif
|
||||
#if !defined (UINT64_MAX) && defined (INT64_C)
|
||||
# define UINT64_MAX UINT64_C (18446744073709551615)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Width of hexadecimal for number field.
|
||||
*/
|
||||
|
||||
#ifndef PRINTF_INT64_HEX_WIDTH
|
||||
# define PRINTF_INT64_HEX_WIDTH "16"
|
||||
#endif
|
||||
#ifndef PRINTF_INT32_HEX_WIDTH
|
||||
# define PRINTF_INT32_HEX_WIDTH "8"
|
||||
#endif
|
||||
#ifndef PRINTF_INT16_HEX_WIDTH
|
||||
# define PRINTF_INT16_HEX_WIDTH "4"
|
||||
#endif
|
||||
#ifndef PRINTF_INT8_HEX_WIDTH
|
||||
# define PRINTF_INT8_HEX_WIDTH "2"
|
||||
#endif
|
||||
|
||||
#ifndef PRINTF_INT64_DEC_WIDTH
|
||||
# define PRINTF_INT64_DEC_WIDTH "20"
|
||||
#endif
|
||||
#ifndef PRINTF_INT32_DEC_WIDTH
|
||||
# define PRINTF_INT32_DEC_WIDTH "10"
|
||||
#endif
|
||||
#ifndef PRINTF_INT16_DEC_WIDTH
|
||||
# define PRINTF_INT16_DEC_WIDTH "5"
|
||||
#endif
|
||||
#ifndef PRINTF_INT8_DEC_WIDTH
|
||||
# define PRINTF_INT8_DEC_WIDTH "3"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Ok, lets not worry about 128 bit integers for now. Moore's law says
|
||||
* we don't need to worry about that until about 2040 at which point
|
||||
* we'll have bigger things to worry about.
|
||||
*/
|
||||
|
||||
#ifdef stdint_int64_defined
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# define UINTMAX_MAX UINT64_MAX
|
||||
# define UINTMAX_C(v) UINT64_C(v)
|
||||
# define INTMAX_C(v) INT64_C(v)
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
|
||||
# endif
|
||||
#else
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# define INTMAX_MAX INT32_MAX
|
||||
# define UINTMAX_MAX UINT32_MAX
|
||||
# define UINTMAX_C(v) UINT32_C(v)
|
||||
# define INTMAX_C(v) INT32_C(v)
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Because this file currently only supports platforms which have
|
||||
* precise powers of 2 as bit sizes for the default integers, the
|
||||
* least definitions are all trivial. Its possible that a future
|
||||
* version of this file could have different definitions.
|
||||
*/
|
||||
|
||||
#ifndef stdint_least_defined
|
||||
typedef int8_t int_least8_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
|
||||
# define UINT_LEAST8_MAX UINT8_MAX
|
||||
# define INT_LEAST8_MAX INT8_MAX
|
||||
# define UINT_LEAST16_MAX UINT16_MAX
|
||||
# define INT_LEAST16_MAX INT16_MAX
|
||||
# define UINT_LEAST32_MAX UINT32_MAX
|
||||
# define INT_LEAST32_MAX INT32_MAX
|
||||
# define INT_LEAST8_MIN INT8_MIN
|
||||
# define INT_LEAST16_MIN INT16_MIN
|
||||
# define INT_LEAST32_MIN INT32_MIN
|
||||
# ifdef stdint_int64_defined
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# define UINT_LEAST64_MAX UINT64_MAX
|
||||
# define INT_LEAST64_MAX INT64_MAX
|
||||
# define INT_LEAST64_MIN INT64_MIN
|
||||
# endif
|
||||
#endif
|
||||
#undef stdint_least_defined
|
||||
|
||||
/*
|
||||
* The ANSI C committee pretending to know or specify anything about
|
||||
* performance is the epitome of misguided arrogance. The mandate of
|
||||
* this file is to *ONLY* ever support that absolute minimum
|
||||
* definition of the fast integer types, for compatibility purposes.
|
||||
* No extensions, and no attempt to suggest what may or may not be a
|
||||
* faster integer type will ever be made in this file. Developers are
|
||||
* warned to stay away from these types when using this or any other
|
||||
* stdint.h.
|
||||
*/
|
||||
|
||||
typedef int_least8_t int_fast8_t;
|
||||
typedef uint_least8_t uint_fast8_t;
|
||||
typedef int_least16_t int_fast16_t;
|
||||
typedef uint_least16_t uint_fast16_t;
|
||||
typedef int_least32_t int_fast32_t;
|
||||
typedef uint_least32_t uint_fast32_t;
|
||||
#define UINT_FAST8_MAX UINT_LEAST8_MAX
|
||||
#define INT_FAST8_MAX INT_LEAST8_MAX
|
||||
#define UINT_FAST16_MAX UINT_LEAST16_MAX
|
||||
#define INT_FAST16_MAX INT_LEAST16_MAX
|
||||
#define UINT_FAST32_MAX UINT_LEAST32_MAX
|
||||
#define INT_FAST32_MAX INT_LEAST32_MAX
|
||||
#define INT_FAST8_MIN INT_LEAST8_MIN
|
||||
#define INT_FAST16_MIN INT_LEAST16_MIN
|
||||
#define INT_FAST32_MIN INT_LEAST32_MIN
|
||||
#ifdef stdint_int64_defined
|
||||
typedef int_least64_t int_fast64_t;
|
||||
typedef uint_least64_t uint_fast64_t;
|
||||
# define UINT_FAST64_MAX UINT_LEAST64_MAX
|
||||
# define INT_FAST64_MAX INT_LEAST64_MAX
|
||||
# define INT_FAST64_MIN INT_LEAST64_MIN
|
||||
#endif
|
||||
|
||||
#undef stdint_int64_defined
|
||||
|
||||
/*
|
||||
* Whatever piecemeal, per compiler thing we can do about the wchar_t
|
||||
* type limits.
|
||||
*/
|
||||
|
||||
#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
|
||||
# include <wchar.h>
|
||||
# ifndef WCHAR_MIN
|
||||
# define WCHAR_MIN 0
|
||||
# endif
|
||||
# ifndef WCHAR_MAX
|
||||
# define WCHAR_MAX ((wchar_t)-1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whatever piecemeal, per compiler/platform thing we can do about the
|
||||
* (u)intptr_t types and limits.
|
||||
*/
|
||||
|
||||
#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
|
||||
# define STDINT_H_UINTPTR_T_DEFINED
|
||||
#endif
|
||||
|
||||
#ifndef STDINT_H_UINTPTR_T_DEFINED
|
||||
# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
|
||||
# define stdint_intptr_bits 64
|
||||
# elif defined (__WATCOMC__) || defined (__TURBOC__)
|
||||
# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
# define stdint_intptr_bits 16
|
||||
# else
|
||||
# define stdint_intptr_bits 32
|
||||
# endif
|
||||
# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
|
||||
# define stdint_intptr_bits 32
|
||||
# elif defined (__INTEL_COMPILER)
|
||||
/* TODO -- what did Intel do about x86-64? */
|
||||
# endif
|
||||
|
||||
# ifdef stdint_intptr_bits
|
||||
# define stdint_intptr_glue3_i(a,b,c) a##b##c
|
||||
# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
|
||||
# ifndef PRINTF_INTPTR_MODIFIER
|
||||
# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
|
||||
# endif
|
||||
# ifndef PTRDIFF_MAX
|
||||
# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef PTRDIFF_MIN
|
||||
# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
|
||||
# endif
|
||||
# ifndef UINTPTR_MAX
|
||||
# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef INTPTR_MAX
|
||||
# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef INTPTR_MIN
|
||||
# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
|
||||
# endif
|
||||
# ifndef INTPTR_C
|
||||
# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
|
||||
# endif
|
||||
# ifndef UINTPTR_C
|
||||
# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
|
||||
# endif
|
||||
typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
|
||||
typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
|
||||
# else
|
||||
/* TODO -- This following is likely wrong for some platforms, and does
|
||||
nothing for the definition of uintptr_t. */
|
||||
typedef ptrdiff_t intptr_t;
|
||||
# endif
|
||||
# define STDINT_H_UINTPTR_T_DEFINED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Assumes sig_atomic_t is signed and we have a 2s complement machine.
|
||||
*/
|
||||
|
||||
#ifndef SIG_ATOMIC_MAX
|
||||
# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
|
||||
|
||||
/*
|
||||
* Please compile with the maximum warning settings to make sure macros are not
|
||||
* defined more than once.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define glue3_aux(x,y,z) x ## y ## z
|
||||
#define glue3(x,y,z) glue3_aux(x,y,z)
|
||||
|
||||
#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
|
||||
#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
|
||||
|
||||
#define DECL(us,bits) glue3(DECL,us,) (bits)
|
||||
|
||||
#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
|
||||
|
||||
int main () {
|
||||
DECL(I,8)
|
||||
DECL(U,8)
|
||||
DECL(I,16)
|
||||
DECL(U,16)
|
||||
DECL(I,32)
|
||||
DECL(U,32)
|
||||
#ifdef INT64_MAX
|
||||
DECL(I,64)
|
||||
DECL(U,64)
|
||||
#endif
|
||||
intmax_t imax = INTMAX_C(0);
|
||||
uintmax_t umax = UINTMAX_C(0);
|
||||
char str0[256], str1[256];
|
||||
|
||||
sprintf (str0, "%d %x\n", 0, ~0);
|
||||
|
||||
sprintf (str1, "%d %x\n", i8, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
|
||||
sprintf (str1, "%u %x\n", u8, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
|
||||
sprintf (str1, "%d %x\n", i16, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
|
||||
sprintf (str1, "%u %x\n", u16, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
|
||||
#ifdef INT64_MAX
|
||||
sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
|
||||
#endif
|
||||
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
|
||||
|
||||
TESTUMAX(8);
|
||||
TESTUMAX(16);
|
||||
TESTUMAX(32);
|
||||
#ifdef INT64_MAX
|
||||
TESTUMAX(64);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,32 +0,0 @@
|
||||
#
|
||||
# Android Makefile conversion
|
||||
#
|
||||
# Leander Beernaert
|
||||
#
|
||||
# How to build: $ANDROID_NDK/ndk-build
|
||||
#
|
||||
VERSION=1.17
|
||||
|
||||
LOCAL_PATH := $(call my-dir)/../
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_ARM_MODE := arm
|
||||
LOCAL_ARM_NEON := true
|
||||
|
||||
LOCAL_MODULE := HLSLcc
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/include \
|
||||
$(LOCAL_PATH)/src \
|
||||
$(LOCAL_PATH)/src/cbstring
|
||||
LOCAL_CFLAGS += -Wall -W
|
||||
# For dynamic library
|
||||
#LOCAL_CFLAGS += -DHLSLCC_DYNLIB
|
||||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/src/*.c) \
|
||||
$(wildcard $(LOCAL_PATH)/src/cbstring/*.c) \
|
||||
$(wildcard $(LOCAL_PATH)/src/internal_includes/*.c)
|
||||
#LOCAL_LDLIBS += -lGLESv3
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
APP_PLATFORM := android-18
|
||||
APP_ABI := armeabi-v7a
|
||||
APP_OPTIM := release
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:35c73c9602dbd539ddd4874c4231fe21d40e0db813394f89e1c837a59d4be755
|
||||
size 1092754
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:51ed960398777ebee83d838e344e4a1dd331acb4ae0e77cbf8a64f2c1146b2ce
|
||||
size 184304
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:26083d66db7a82295514575af1160ab7aec52aa32f8431edbd1a09011154901b
|
||||
size 190552
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3b322870fdff43b12034b4d9bcf72b59a5ef2f0cdd1f3042369c9f1a6911931b
|
||||
size 374904
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4ea9be963e0674546c2e8af2fd9a34e95100d9a1806399457b1e06d033149456
|
||||
size 375378
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:544de0a5688c776e28b42bb189a738bc87743828b737d4bf653e46cd2e05938b
|
||||
size 1171448
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:af9216c54d23dd3754f7ae18d56b97ae256eb29a0046d8e0d2a0716054d8c230
|
||||
size 218888
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6a07bec349614cdd3e40c3577bddace1203148016f9276c7ef807bdbc37dcabf
|
||||
size 671232
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:88acec4cedad5699900ec2d1a3ce83ab5e9365ebea4b4af0ababba562382f399
|
||||
size 296852
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4c0625b7f534df5817646dd1335f9d7916389f27a83b7d118fadab504064d910
|
||||
size 1144250
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4d49f4f011fe2835d5aafa7ac77fb660cf12078763ddef25e935da919bc65e6b
|
||||
size 440242
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3a4a291f8b3d00e1865a98ad3c740d28ff10d43ca87b718403cfc920df2be9ab
|
||||
size 618776
|
||||
@ -1,53 +0,0 @@
|
||||
Copyright (c) 2012 James Jones
|
||||
Further improvements Copyright (c) 2014-2016 Unity Technologies
|
||||
All Rights Reserved.
|
||||
|
||||
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 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
|
||||
AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
|
||||
This software makes use of the bstring library which is provided under the following license:
|
||||
|
||||
Copyright (c) 2002-2008 Paul Hsieh
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
Neither the name of bstrlib nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
@ -1,247 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2009 Dave Gamble
|
||||
|
||||
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 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
|
||||
AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
*/
|
||||
|
||||
Welcome to cJSON.
|
||||
|
||||
cJSON aims to be the dumbest possible parser that you can get your job done with.
|
||||
It's a single file of C, and a single header file.
|
||||
|
||||
JSON is described best here: http://www.json.org/
|
||||
It's like XML, but fat-free. You use it to move data around, store things, or just
|
||||
generally represent your program's state.
|
||||
|
||||
|
||||
First up, how do I build?
|
||||
Add cJSON.c to your project, and put cJSON.h somewhere in the header search path.
|
||||
For example, to build the test app:
|
||||
|
||||
gcc cJSON.c test.c -o test -lm
|
||||
./test
|
||||
|
||||
|
||||
As a library, cJSON exists to take away as much legwork as it can, but not get in your way.
|
||||
As a point of pragmatism (i.e. ignoring the truth), I'm going to say that you can use it
|
||||
in one of two modes: Auto and Manual. Let's have a quick run-through.
|
||||
|
||||
|
||||
I lifted some JSON from this page: http://www.json.org/fatfree.html
|
||||
That page inspired me to write cJSON, which is a parser that tries to share the same
|
||||
philosophy as JSON itself. Simple, dumb, out of the way.
|
||||
|
||||
Some JSON:
|
||||
{
|
||||
"name": "Jack (\"Bee\") Nimble",
|
||||
"format": {
|
||||
"type": "rect",
|
||||
"width": 1920,
|
||||
"height": 1080,
|
||||
"interlace": false,
|
||||
"frame rate": 24
|
||||
}
|
||||
}
|
||||
|
||||
Assume that you got this from a file, a webserver, or magic JSON elves, whatever,
|
||||
you have a char * to it. Everything is a cJSON struct.
|
||||
Get it parsed:
|
||||
cJSON *root = cJSON_Parse(my_json_string);
|
||||
|
||||
This is an object. We're in C. We don't have objects. But we do have structs.
|
||||
What's the framerate?
|
||||
|
||||
cJSON *format = cJSON_GetObjectItem(root,"format");
|
||||
int framerate = cJSON_GetObjectItem(format,"frame rate")->valueint;
|
||||
|
||||
|
||||
Want to change the framerate?
|
||||
cJSON_GetObjectItem(format,"frame rate")->valueint=25;
|
||||
|
||||
Back to disk?
|
||||
char *rendered=cJSON_Print(root);
|
||||
|
||||
Finished? Delete the root (this takes care of everything else).
|
||||
cJSON_Delete(root);
|
||||
|
||||
That's AUTO mode. If you're going to use Auto mode, you really ought to check pointers
|
||||
before you dereference them. If you want to see how you'd build this struct in code?
|
||||
cJSON *root,*fmt;
|
||||
root=cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble"));
|
||||
cJSON_AddItemToObject(root, "format", fmt=cJSON_CreateObject());
|
||||
cJSON_AddStringToObject(fmt,"type", "rect");
|
||||
cJSON_AddNumberToObject(fmt,"width", 1920);
|
||||
cJSON_AddNumberToObject(fmt,"height", 1080);
|
||||
cJSON_AddFalseToObject (fmt,"interlace");
|
||||
cJSON_AddNumberToObject(fmt,"frame rate", 24);
|
||||
|
||||
Hopefully we can agree that's not a lot of code? There's no overhead, no unnecessary setup.
|
||||
Look at test.c for a bunch of nice examples, mostly all ripped off the json.org site, and
|
||||
a few from elsewhere.
|
||||
|
||||
What about manual mode? First up you need some detail.
|
||||
Let's cover how the cJSON objects represent the JSON data.
|
||||
cJSON doesn't distinguish arrays from objects in handling; just type.
|
||||
Each cJSON has, potentially, a child, siblings, value, a name.
|
||||
|
||||
The root object has: Object Type and a Child
|
||||
The Child has name "name", with value "Jack ("Bee") Nimble", and a sibling:
|
||||
Sibling has type Object, name "format", and a child.
|
||||
That child has type String, name "type", value "rect", and a sibling:
|
||||
Sibling has type Number, name "width", value 1920, and a sibling:
|
||||
Sibling has type Number, name "height", value 1080, and a sibling:
|
||||
Sibling hs type False, name "interlace", and a sibling:
|
||||
Sibling has type Number, name "frame rate", value 24
|
||||
|
||||
Here's the structure:
|
||||
typedef struct cJSON {
|
||||
struct cJSON *next,*prev;
|
||||
struct cJSON *child;
|
||||
|
||||
int type;
|
||||
|
||||
char *valuestring;
|
||||
int valueint;
|
||||
double valuedouble;
|
||||
|
||||
char *string;
|
||||
} cJSON;
|
||||
|
||||
By default all values are 0 unless set by virtue of being meaningful.
|
||||
|
||||
next/prev is a doubly linked list of siblings. next takes you to your sibling,
|
||||
prev takes you back from your sibling to you.
|
||||
Only objects and arrays have a "child", and it's the head of the doubly linked list.
|
||||
A "child" entry will have prev==0, but next potentially points on. The last sibling has next=0.
|
||||
The type expresses Null/True/False/Number/String/Array/Object, all of which are #defined in
|
||||
cJSON.h
|
||||
|
||||
A Number has valueint and valuedouble. If you're expecting an int, read valueint, if not read
|
||||
valuedouble.
|
||||
|
||||
Any entry which is in the linked list which is the child of an object will have a "string"
|
||||
which is the "name" of the entry. When I said "name" in the above example, that's "string".
|
||||
"string" is the JSON name for the 'variable name' if you will.
|
||||
|
||||
Now you can trivially walk the lists, recursively, and parse as you please.
|
||||
You can invoke cJSON_Parse to get cJSON to parse for you, and then you can take
|
||||
the root object, and traverse the structure (which is, formally, an N-tree),
|
||||
and tokenise as you please. If you wanted to build a callback style parser, this is how
|
||||
you'd do it (just an example, since these things are very specific):
|
||||
|
||||
void parse_and_callback(cJSON *item,const char *prefix)
|
||||
{
|
||||
while (item)
|
||||
{
|
||||
char *newprefix=malloc(strlen(prefix)+strlen(item->name)+2);
|
||||
sprintf(newprefix,"%s/%s",prefix,item->name);
|
||||
int dorecurse=callback(newprefix, item->type, item);
|
||||
if (item->child && dorecurse) parse_and_callback(item->child,newprefix);
|
||||
item=item->next;
|
||||
free(newprefix);
|
||||
}
|
||||
}
|
||||
|
||||
The prefix process will build you a separated list, to simplify your callback handling.
|
||||
The 'dorecurse' flag would let the callback decide to handle sub-arrays on it's own, or
|
||||
let you invoke it per-item. For the item above, your callback might look like this:
|
||||
|
||||
int callback(const char *name,int type,cJSON *item)
|
||||
{
|
||||
if (!strcmp(name,"name")) { /* populate name */ }
|
||||
else if (!strcmp(name,"format/type") { /* handle "rect" */ }
|
||||
else if (!strcmp(name,"format/width") { /* 800 */ }
|
||||
else if (!strcmp(name,"format/height") { /* 600 */ }
|
||||
else if (!strcmp(name,"format/interlace") { /* false */ }
|
||||
else if (!strcmp(name,"format/frame rate") { /* 24 */ }
|
||||
return 1;
|
||||
}
|
||||
|
||||
Alternatively, you might like to parse iteratively.
|
||||
You'd use:
|
||||
|
||||
void parse_object(cJSON *item)
|
||||
{
|
||||
int i; for (i=0;i<cJSON_GetArraySize(item);i++)
|
||||
{
|
||||
cJSON *subitem=cJSON_GetArrayItem(item,i);
|
||||
// handle subitem.
|
||||
}
|
||||
}
|
||||
|
||||
Or, for PROPER manual mode:
|
||||
|
||||
void parse_object(cJSON *item)
|
||||
{
|
||||
cJSON *subitem=item->child;
|
||||
while (subitem)
|
||||
{
|
||||
// handle subitem
|
||||
if (subitem->child) parse_object(subitem->child);
|
||||
|
||||
subitem=subitem->next;
|
||||
}
|
||||
}
|
||||
|
||||
Of course, this should look familiar, since this is just a stripped-down version
|
||||
of the callback-parser.
|
||||
|
||||
This should cover most uses you'll find for parsing. The rest should be possible
|
||||
to infer.. and if in doubt, read the source! There's not a lot of it! ;)
|
||||
|
||||
|
||||
In terms of constructing JSON data, the example code above is the right way to do it.
|
||||
You can, of course, hand your sub-objects to other functions to populate.
|
||||
Also, if you find a use for it, you can manually build the objects.
|
||||
For instance, suppose you wanted to build an array of objects?
|
||||
|
||||
cJSON *objects[24];
|
||||
|
||||
cJSON *Create_array_of_anything(cJSON **items,int num)
|
||||
{
|
||||
int i;cJSON *prev, *root=cJSON_CreateArray();
|
||||
for (i=0;i<24;i++)
|
||||
{
|
||||
if (!i) root->child=objects[i];
|
||||
else prev->next=objects[i], objects[i]->prev=prev;
|
||||
prev=objects[i];
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
and simply: Create_array_of_anything(objects,24);
|
||||
|
||||
cJSON doesn't make any assumptions about what order you create things in.
|
||||
You can attach the objects, as above, and later add children to each
|
||||
of those objects.
|
||||
|
||||
As soon as you call cJSON_Print, it renders the structure to text.
|
||||
|
||||
|
||||
|
||||
The test.c code shows how to handle a bunch of typical cases. If you uncomment
|
||||
the code, it'll load, parse and print a bunch of test files, also from json.org,
|
||||
which are more complex than I'd care to try and stash into a const char array[].
|
||||
|
||||
|
||||
Enjoy cJSON!
|
||||
|
||||
|
||||
- Dave Gamble, Aug 2009
|
||||
@ -1,578 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2009 Dave Gamble
|
||||
|
||||
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 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
|
||||
AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates.
|
||||
|
||||
/* cJSON */
|
||||
/* JSON parser in C. */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include "cJSON.h"
|
||||
#include <AzCore/PlatformDef.h>
|
||||
|
||||
static const char *ep;
|
||||
|
||||
const char *cJSON_GetErrorPtr(void) {return ep;}
|
||||
|
||||
static int cJSON_strcasecmp(const char *s1,const char *s2)
|
||||
{
|
||||
if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
|
||||
for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
|
||||
return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
|
||||
}
|
||||
|
||||
AZ_PUSH_DISABLE_WARNING(4232, "-Wunknown-warning-option") // address of malloc/free are not static
|
||||
static void *(*cJSON_malloc)(size_t sz) = malloc;
|
||||
static void (*cJSON_free)(void *ptr) = free;
|
||||
AZ_POP_DISABLE_WARNING
|
||||
|
||||
static char* cJSON_strdup(const char* str)
|
||||
{
|
||||
size_t len = strlen(str) + 1;
|
||||
char* copy = (char*)cJSON_malloc(len);
|
||||
|
||||
if (!copy) return 0;
|
||||
memcpy(copy,str,len);
|
||||
return copy;
|
||||
}
|
||||
|
||||
void cJSON_InitHooks(cJSON_Hooks* hooks)
|
||||
{
|
||||
if (!hooks) { /* Reset hooks */
|
||||
cJSON_malloc = malloc;
|
||||
cJSON_free = free;
|
||||
return;
|
||||
}
|
||||
|
||||
cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
|
||||
cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
|
||||
}
|
||||
|
||||
/* Internal constructor. */
|
||||
static cJSON *cJSON_New_Item(void)
|
||||
{
|
||||
cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
|
||||
if (node) memset(node,0,sizeof(cJSON));
|
||||
return node;
|
||||
}
|
||||
|
||||
/* Delete a cJSON structure. */
|
||||
void cJSON_Delete(cJSON *c)
|
||||
{
|
||||
cJSON *next;
|
||||
while (c)
|
||||
{
|
||||
next=c->next;
|
||||
if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
|
||||
if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
|
||||
if (c->string) cJSON_free(c->string);
|
||||
cJSON_free(c);
|
||||
c=next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse the input text to generate a number, and populate the result into item. */
|
||||
static const char *parse_number(cJSON *item,const char *num)
|
||||
{
|
||||
double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
|
||||
|
||||
/* Could use sscanf for this? */
|
||||
if (*num=='-') sign=-1,num++; /* Has sign? */
|
||||
if (*num=='0') num++; /* is zero */
|
||||
if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
|
||||
if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
|
||||
if (*num=='e' || *num=='E') /* Exponent? */
|
||||
{ num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
|
||||
while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
|
||||
}
|
||||
|
||||
n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
|
||||
|
||||
item->valuedouble=n;
|
||||
item->valueint=(int)n;
|
||||
item->type=cJSON_Number;
|
||||
return num;
|
||||
}
|
||||
|
||||
/* Render the number nicely from the given item into a string. */
|
||||
static char *print_number(cJSON *item)
|
||||
{
|
||||
char *str;
|
||||
double d=item->valuedouble;
|
||||
if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
|
||||
{
|
||||
str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
|
||||
if (str) sprintf(str,"%d",item->valueint);
|
||||
}
|
||||
else
|
||||
{
|
||||
str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
|
||||
if (str)
|
||||
{
|
||||
if (fabs(floor(d)-d)<=DBL_EPSILON && fabs(d)<1.0e60)sprintf(str,"%.0f",d);
|
||||
else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
|
||||
else sprintf(str,"%f",d);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/* Parse the input text into an unescaped cstring, and populate item. */
|
||||
static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
||||
static const char *parse_string(cJSON *item,const char *str)
|
||||
{
|
||||
const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
|
||||
if (*str!='\"') {ep=str;return 0;} /* not a string! */
|
||||
|
||||
while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
|
||||
|
||||
out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
|
||||
if (!out) return 0;
|
||||
|
||||
ptr=str+1;ptr2=out;
|
||||
while (*ptr!='\"' && *ptr)
|
||||
{
|
||||
if (*ptr!='\\') *ptr2++=*ptr++;
|
||||
else
|
||||
{
|
||||
ptr++;
|
||||
switch (*ptr)
|
||||
{
|
||||
case 'b': *ptr2++='\b'; break;
|
||||
case 'f': *ptr2++='\f'; break;
|
||||
case 'n': *ptr2++='\n'; break;
|
||||
case 'r': *ptr2++='\r'; break;
|
||||
case 't': *ptr2++='\t'; break;
|
||||
case 'u': /* transcode utf16 to utf8. */
|
||||
sscanf(ptr+1,"%4x",&uc);ptr+=4; /* get the unicode char. */
|
||||
|
||||
if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; /* check for invalid. */
|
||||
|
||||
if (uc>=0xD800 && uc<=0xDBFF) /* UTF16 surrogate pairs. */
|
||||
{
|
||||
if (ptr[1]!='\\' || ptr[2]!='u') break; /* missing second-half of surrogate. */
|
||||
sscanf(ptr+3,"%4x",&uc2);ptr+=6;
|
||||
if (uc2<0xDC00 || uc2>0xDFFF) break; /* invalid second-half of surrogate. */
|
||||
uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF));
|
||||
}
|
||||
|
||||
len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;
|
||||
|
||||
switch (len) {
|
||||
case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
|
||||
case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
|
||||
case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
|
||||
case 1: *--ptr2 =(uc | firstByteMark[len]);
|
||||
}
|
||||
ptr2+=len;
|
||||
break;
|
||||
default: *ptr2++=*ptr; break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
*ptr2=0;
|
||||
if (*ptr=='\"') ptr++;
|
||||
item->valuestring=out;
|
||||
item->type=cJSON_String;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* Render the cstring provided to an escaped version that can be printed. */
|
||||
static char *print_string_ptr(const char *str)
|
||||
{
|
||||
const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
|
||||
|
||||
if (!str) return cJSON_strdup("");
|
||||
ptr=str;
|
||||
token = *ptr;
|
||||
while (token && ++len)
|
||||
{
|
||||
if (strchr("\"\\\b\f\n\r\t",token)) len++;
|
||||
else if (token<32) len+=5;
|
||||
ptr++;
|
||||
token = *ptr;
|
||||
}
|
||||
|
||||
out=(char*)cJSON_malloc(len+3);
|
||||
if (!out) return 0;
|
||||
|
||||
ptr2=out;ptr=str;
|
||||
*ptr2++='\"';
|
||||
while (*ptr)
|
||||
{
|
||||
if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
|
||||
else
|
||||
{
|
||||
*ptr2++='\\';
|
||||
switch (token=*ptr++)
|
||||
{
|
||||
case '\\': *ptr2++='\\'; break;
|
||||
case '\"': *ptr2++='\"'; break;
|
||||
case '\b': *ptr2++='b'; break;
|
||||
case '\f': *ptr2++='f'; break;
|
||||
case '\n': *ptr2++='n'; break;
|
||||
case '\r': *ptr2++='r'; break;
|
||||
case '\t': *ptr2++='t'; break;
|
||||
default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */
|
||||
}
|
||||
}
|
||||
}
|
||||
*ptr2++='\"';*ptr2++=0;
|
||||
return out;
|
||||
}
|
||||
/* Invote print_string_ptr (which is useful) on an item. */
|
||||
static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);}
|
||||
|
||||
/* Predeclare these prototypes. */
|
||||
static const char *parse_value(cJSON *item,const char *value);
|
||||
static char *print_value(cJSON *item,int depth,int fmt);
|
||||
static const char *parse_array(cJSON *item,const char *value);
|
||||
static char *print_array(cJSON *item,int depth,int fmt);
|
||||
static const char *parse_object(cJSON *item,const char *value);
|
||||
static char *print_object(cJSON *item,int depth,int fmt);
|
||||
|
||||
/* Utility to jump whitespace and cr/lf */
|
||||
static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
|
||||
|
||||
/* Parse an object - create a new root, and populate. */
|
||||
cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated)
|
||||
{
|
||||
const char *end=0;
|
||||
cJSON *c=cJSON_New_Item();
|
||||
ep=0;
|
||||
if (!c) return 0; /* memory fail */
|
||||
|
||||
end=parse_value(c,skip(value));
|
||||
if (!end) {cJSON_Delete(c);return 0;} /* parse failure. ep is set. */
|
||||
|
||||
/* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
|
||||
if (require_null_terminated) {end=skip(end);if (*end) {cJSON_Delete(c);ep=end;return 0;}}
|
||||
if (return_parse_end) *return_parse_end=end;
|
||||
return c;
|
||||
}
|
||||
/* Default options for cJSON_Parse */
|
||||
cJSON *cJSON_Parse(const char *value) {return cJSON_ParseWithOpts(value,0,0);}
|
||||
|
||||
/* Render a cJSON item/entity/structure to text. */
|
||||
char *cJSON_Print(cJSON *item) {return print_value(item,0,1);}
|
||||
char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);}
|
||||
|
||||
/* Parser core - when encountering text, process appropriately. */
|
||||
static const char *parse_value(cJSON *item,const char *value)
|
||||
{
|
||||
if (!value) return 0; /* Fail on null. */
|
||||
if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; }
|
||||
if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; }
|
||||
if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; }
|
||||
if (*value=='\"') { return parse_string(item,value); }
|
||||
if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); }
|
||||
if (*value=='[') { return parse_array(item,value); }
|
||||
if (*value=='{') { return parse_object(item,value); }
|
||||
|
||||
ep=value;return 0; /* failure. */
|
||||
}
|
||||
|
||||
/* Render a value to text. */
|
||||
static char *print_value(cJSON *item,int depth,int fmt)
|
||||
{
|
||||
char *out=0;
|
||||
if (!item) return 0;
|
||||
switch ((item->type)&255)
|
||||
{
|
||||
case cJSON_NULL: out=cJSON_strdup("null"); break;
|
||||
case cJSON_False: out=cJSON_strdup("false");break;
|
||||
case cJSON_True: out=cJSON_strdup("true"); break;
|
||||
case cJSON_Number: out=print_number(item);break;
|
||||
case cJSON_String: out=print_string(item);break;
|
||||
case cJSON_Array: out=print_array(item,depth,fmt);break;
|
||||
case cJSON_Object: out=print_object(item,depth,fmt);break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Build an array from input text. */
|
||||
static const char *parse_array(cJSON *item,const char *value)
|
||||
{
|
||||
cJSON *child;
|
||||
if (*value!='[') {ep=value;return 0;} /* not an array! */
|
||||
|
||||
item->type=cJSON_Array;
|
||||
value=skip(value+1);
|
||||
if (*value==']') return value+1; /* empty array. */
|
||||
|
||||
item->child=child=cJSON_New_Item();
|
||||
if (!item->child) return 0; /* memory fail */
|
||||
value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
|
||||
if (!value) return 0;
|
||||
|
||||
while (*value==',')
|
||||
{
|
||||
cJSON *new_item = cJSON_New_Item();
|
||||
if (!new_item) return 0; /* memory fail */
|
||||
child->next=new_item;new_item->prev=child;child=new_item;
|
||||
value=skip(parse_value(child,skip(value+1)));
|
||||
if (!value) return 0; /* memory fail */
|
||||
}
|
||||
|
||||
if (*value==']') return value+1; /* end of array */
|
||||
ep=value;return 0; /* malformed. */
|
||||
}
|
||||
|
||||
/* Render an array to text */
|
||||
static char *print_array(cJSON *item,int depth,int fmt)
|
||||
{
|
||||
char **entries;
|
||||
char *out=0,*ptr,*ret;int len=5;
|
||||
cJSON *child=item->child;
|
||||
int numentries=0,i=0,fail=0;
|
||||
|
||||
/* How many entries in the array? */
|
||||
while (child) numentries++,child=child->next;
|
||||
/* Explicitly handle numentries==0 */
|
||||
if (!numentries)
|
||||
{
|
||||
out=(char*)cJSON_malloc(3);
|
||||
if (out) strcpy(out,"[]");
|
||||
return out;
|
||||
}
|
||||
/* Allocate an array to hold the values for each */
|
||||
entries=(char**)cJSON_malloc(numentries*sizeof(char*));
|
||||
if (!entries) return 0;
|
||||
memset(entries,0,numentries*sizeof(char*));
|
||||
/* Retrieve all the results: */
|
||||
child=item->child;
|
||||
while (child && !fail)
|
||||
{
|
||||
ret=print_value(child,depth+1,fmt);
|
||||
entries[i++]=ret;
|
||||
if (ret) len+=(int)strlen(ret)+2+(fmt?1:0); else fail=1;
|
||||
child=child->next;
|
||||
}
|
||||
|
||||
/* If we didn't fail, try to malloc the output string */
|
||||
if (!fail) out=(char*)cJSON_malloc(len);
|
||||
/* If that fails, we fail. */
|
||||
if (!out) fail=1;
|
||||
|
||||
/* Handle failure. */
|
||||
if (fail)
|
||||
{
|
||||
for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
|
||||
cJSON_free(entries);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compose the output array. */
|
||||
*out='[';
|
||||
ptr=out+1;*ptr=0;
|
||||
for (i=0;i<numentries;i++)
|
||||
{
|
||||
strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
|
||||
if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
|
||||
cJSON_free(entries[i]);
|
||||
}
|
||||
cJSON_free(entries);
|
||||
*ptr++=']';*ptr++=0;
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Build an object from the text. */
|
||||
static const char *parse_object(cJSON *item,const char *value)
|
||||
{
|
||||
cJSON *child;
|
||||
if (*value!='{') {ep=value;return 0;} /* not an object! */
|
||||
|
||||
item->type=cJSON_Object;
|
||||
value=skip(value+1);
|
||||
if (*value=='}') return value+1; /* empty array. */
|
||||
|
||||
item->child=child=cJSON_New_Item();
|
||||
if (!item->child) return 0;
|
||||
value=skip(parse_string(child,skip(value)));
|
||||
if (!value) return 0;
|
||||
child->string=child->valuestring;child->valuestring=0;
|
||||
if (*value!=':') {ep=value;return 0;} /* fail! */
|
||||
value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
|
||||
if (!value) return 0;
|
||||
|
||||
while (*value==',')
|
||||
{
|
||||
cJSON* new_item = cJSON_New_Item();
|
||||
if (!new_item) return 0; /* memory fail */
|
||||
child->next=new_item;new_item->prev=child;child=new_item;
|
||||
value=skip(parse_string(child,skip(value+1)));
|
||||
if (!value) return 0;
|
||||
child->string=child->valuestring;child->valuestring=0;
|
||||
if (*value!=':') {ep=value;return 0;} /* fail! */
|
||||
value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
|
||||
if (!value) return 0;
|
||||
}
|
||||
|
||||
if (*value=='}') return value+1; /* end of array */
|
||||
ep=value;return 0; /* malformed. */
|
||||
}
|
||||
|
||||
/* Render an object to text. */
|
||||
static char *print_object(cJSON *item,int depth,int fmt)
|
||||
{
|
||||
char **entries=0,**names=0;
|
||||
char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
|
||||
cJSON *child=item->child;
|
||||
int numentries=0,fail=0;
|
||||
/* Count the number of entries. */
|
||||
while (child) numentries++,child=child->next;
|
||||
/* Explicitly handle empty object case */
|
||||
if (!numentries)
|
||||
{
|
||||
out=(char*)cJSON_malloc(fmt?depth+3:3);
|
||||
if (!out) return 0;
|
||||
ptr=out;*ptr++='{';
|
||||
if (fmt) {*ptr++='\n';for (i=0;i<depth-1;i++) *ptr++='\t';}
|
||||
*ptr++='}';*ptr++=0;
|
||||
return out;
|
||||
}
|
||||
/* Allocate space for the names and the objects */
|
||||
entries=(char**)cJSON_malloc(numentries*sizeof(char*));
|
||||
if (!entries) return 0;
|
||||
names=(char**)cJSON_malloc(numentries*sizeof(char*));
|
||||
if (!names) {cJSON_free(entries);return 0;}
|
||||
memset(entries,0,sizeof(char*)*numentries);
|
||||
memset(names,0,sizeof(char*)*numentries);
|
||||
|
||||
/* Collect all the results into our arrays: */
|
||||
child=item->child;depth++;if (fmt) len+=depth;
|
||||
while (child)
|
||||
{
|
||||
names[i]=str=print_string_ptr(child->string);
|
||||
entries[i++]=ret=print_value(child,depth,fmt);
|
||||
if (str && ret) len+=(int)(strlen(ret)+strlen(str))+2+(fmt?2+depth:0); else fail=1;
|
||||
child=child->next;
|
||||
}
|
||||
|
||||
/* Try to allocate the output string */
|
||||
if (!fail) out=(char*)cJSON_malloc(len);
|
||||
if (!out) fail=1;
|
||||
|
||||
/* Handle failure */
|
||||
if (fail)
|
||||
{
|
||||
for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
|
||||
cJSON_free(names);cJSON_free(entries);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Compose the output: */
|
||||
*out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
|
||||
for (i=0;i<numentries;i++)
|
||||
{
|
||||
if (fmt) for (j=0;j<depth;j++) *ptr++='\t';
|
||||
strcpy(ptr,names[i]);ptr+=strlen(names[i]);
|
||||
*ptr++=':';if (fmt) *ptr++='\t';
|
||||
strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
|
||||
if (i!=numentries-1) *ptr++=',';
|
||||
if (fmt) *ptr++='\n';*ptr=0;
|
||||
cJSON_free(names[i]);cJSON_free(entries[i]);
|
||||
}
|
||||
|
||||
cJSON_free(names);cJSON_free(entries);
|
||||
if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
|
||||
*ptr++='}';*ptr++=0;
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Get Array size/item / object item. */
|
||||
int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
|
||||
cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
|
||||
cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
|
||||
|
||||
/* Utility for array list handling. */
|
||||
static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
|
||||
/* Utility for handling references. */
|
||||
static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;}
|
||||
|
||||
/* Add item to array/object. */
|
||||
void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
|
||||
void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
|
||||
void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
|
||||
void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
|
||||
|
||||
cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
|
||||
if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
|
||||
void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
|
||||
cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
|
||||
void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
|
||||
|
||||
/* Replace array/object items with new ones. */
|
||||
void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
|
||||
newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
|
||||
if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
|
||||
void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
|
||||
|
||||
/* Create basic types: */
|
||||
cJSON *cJSON_CreateNull(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
|
||||
cJSON *cJSON_CreateTrue(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
|
||||
cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
|
||||
cJSON *cJSON_CreateBool(int b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
|
||||
cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;}return item;}
|
||||
cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
|
||||
cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
|
||||
cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
|
||||
|
||||
/* Create Arrays: */
|
||||
cJSON *cJSON_CreateIntArray(int *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
||||
cJSON *cJSON_CreateFloatArray(float *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
||||
cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
||||
cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateString(strings[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
||||
|
||||
/* Duplication */
|
||||
cJSON *cJSON_Duplicate(cJSON *item,int recurse)
|
||||
{
|
||||
cJSON *newitem,*cptr,*nptr=0,*newchild;
|
||||
/* Bail on bad ptr */
|
||||
if (!item) return 0;
|
||||
/* Create new item */
|
||||
newitem=cJSON_New_Item();
|
||||
if (!newitem) return 0;
|
||||
/* Copy over all vars */
|
||||
newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble;
|
||||
if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}}
|
||||
if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}}
|
||||
/* If non-recursive, then we're done! */
|
||||
if (!recurse) return newitem;
|
||||
/* Walk the ->next chain for the child. */
|
||||
cptr=item->child;
|
||||
while (cptr)
|
||||
{
|
||||
newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */
|
||||
if (!newchild) {cJSON_Delete(newitem);return 0;}
|
||||
if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */
|
||||
else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */
|
||||
cptr=cptr->next;
|
||||
}
|
||||
return newitem;
|
||||
}
|
||||
@ -1,142 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2009 Dave Gamble
|
||||
|
||||
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 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
|
||||
AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_False 0
|
||||
#define cJSON_True 1
|
||||
#define cJSON_NULL 2
|
||||
#define cJSON_Number 3
|
||||
#define cJSON_String 4
|
||||
#define cJSON_Array 5
|
||||
#define cJSON_Object 6
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON {
|
||||
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
|
||||
int type; /* The type of the item, as above. */
|
||||
|
||||
char *valuestring; /* The item's string, if type==cJSON_String */
|
||||
int valueint; /* The item's number, if type==cJSON_Number */
|
||||
double valuedouble; /* The item's number, if type==cJSON_Number */
|
||||
|
||||
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks {
|
||||
void *(*malloc_fn)(size_t sz);
|
||||
void (*free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
extern void cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
|
||||
extern cJSON *cJSON_Parse(const char *value);
|
||||
/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
|
||||
extern char *cJSON_Print(cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
|
||||
extern char *cJSON_PrintUnformatted(cJSON *item);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
extern void cJSON_Delete(cJSON *c);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
extern int cJSON_GetArraySize(cJSON *array);
|
||||
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
|
||||
extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
|
||||
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
extern const char *cJSON_GetErrorPtr(void);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
extern cJSON *cJSON_CreateNull(void);
|
||||
extern cJSON *cJSON_CreateTrue(void);
|
||||
extern cJSON *cJSON_CreateFalse(void);
|
||||
extern cJSON *cJSON_CreateBool(int b);
|
||||
extern cJSON *cJSON_CreateNumber(double num);
|
||||
extern cJSON *cJSON_CreateString(const char *string);
|
||||
extern cJSON *cJSON_CreateArray(void);
|
||||
extern cJSON *cJSON_CreateObject(void);
|
||||
|
||||
/* These utilities create an Array of count items. */
|
||||
extern cJSON *cJSON_CreateIntArray(int *numbers,int count);
|
||||
extern cJSON *cJSON_CreateFloatArray(float *numbers,int count);
|
||||
extern cJSON *cJSON_CreateDoubleArray(double *numbers,int count);
|
||||
extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
|
||||
|
||||
/* Remove/Detatch items from Arrays/Objects. */
|
||||
extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
|
||||
extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
|
||||
extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
|
||||
extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
|
||||
extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
extern cJSON *cJSON_Duplicate(cJSON *item,int recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated);
|
||||
|
||||
/* Macros for creating things quickly. */
|
||||
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
|
||||
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
|
||||
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
|
||||
#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
|
||||
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
|
||||
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,803 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "hlslcc.hpp"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include "hash.h"
|
||||
#include "serializeReflection.h"
|
||||
#include "hlslcc_bin.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(PORTABLE)
|
||||
//#define VALIDATE_OUTPUT // NOTE: THIS IS OK DURING HLSLcc DEV BUT SHOULD NOT BE USED IN PRODUCTION. SOME EXT USED ARE NO SUPPORTED ON WINDOWS.
|
||||
#endif
|
||||
|
||||
#if defined(VALIDATE_OUTPUT)
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <gl/GL.h>
|
||||
|
||||
#pragma comment(lib, "opengl32.lib")
|
||||
|
||||
typedef char GLcharARB; /* native character */
|
||||
typedef unsigned int GLhandleARB; /* shader object handle */
|
||||
#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
|
||||
#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
|
||||
#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
|
||||
typedef void (WINAPI * PFNGLDELETEOBJECTARBPROC)(GLhandleARB obj);
|
||||
typedef GLhandleARB (WINAPI * PFNGLCREATESHADEROBJECTARBPROC)(GLenum shaderType);
|
||||
typedef void (WINAPI * PFNGLSHADERSOURCEARBPROC)(GLhandleARB shaderObj, GLsizei count, const GLcharARB** string, const GLint* length);
|
||||
typedef void (WINAPI * PFNGLCOMPILESHADERARBPROC)(GLhandleARB shaderObj);
|
||||
typedef void (WINAPI * PFNGLGETINFOLOGARBPROC)(GLhandleARB obj, GLsizei maxLength, GLsizei* length, GLcharARB* infoLog);
|
||||
typedef void (WINAPI * PFNGLGETOBJECTPARAMETERIVARBPROC)(GLhandleARB obj, GLenum pname, GLint* params);
|
||||
typedef GLhandleARB (WINAPI * PFNGLCREATEPROGRAMOBJECTARBPROC)(void);
|
||||
typedef void (WINAPI * PFNGLATTACHOBJECTARBPROC)(GLhandleARB containerObj, GLhandleARB obj);
|
||||
typedef void (WINAPI * PFNGLLINKPROGRAMARBPROC)(GLhandleARB programObj);
|
||||
typedef void (WINAPI * PFNGLUSEPROGRAMOBJECTARBPROC)(GLhandleARB programObj);
|
||||
typedef void (WINAPI * PFNGLGETSHADERINFOLOGPROC)(GLuint shader, GLsizei bufSize, GLsizei* length, GLcharARB* infoLog);
|
||||
|
||||
static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
|
||||
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
|
||||
static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
|
||||
static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
|
||||
static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
|
||||
static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
|
||||
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
|
||||
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
|
||||
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
|
||||
static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
|
||||
static PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
|
||||
|
||||
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
|
||||
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
|
||||
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
|
||||
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
|
||||
#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
|
||||
#define WGL_CONTEXT_FLAGS_ARB 0x2094
|
||||
#define ERROR_INVALID_VERSION_ARB 0x2095
|
||||
#define ERROR_INVALID_PROFILE_ARB 0x2096
|
||||
|
||||
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
|
||||
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
|
||||
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
|
||||
|
||||
typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC, HGLRC hShareContext, const int* attribList);
|
||||
static PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
|
||||
|
||||
void InitOpenGL()
|
||||
{
|
||||
HGLRC rc;
|
||||
|
||||
// setup minimal required GL
|
||||
HWND wnd = CreateWindowA(
|
||||
"STATIC",
|
||||
"GL",
|
||||
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
|
||||
0, 0, 16, 16,
|
||||
NULL, NULL,
|
||||
GetModuleHandle(NULL), NULL);
|
||||
HDC dc = GetDC(wnd);
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR), 1,
|
||||
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
|
||||
PFD_TYPE_RGBA, 32,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
16, 0,
|
||||
0, PFD_MAIN_PLANE, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
int fmt = ChoosePixelFormat(dc, &pfd);
|
||||
SetPixelFormat(dc, fmt, &pfd);
|
||||
|
||||
rc = wglCreateContext(dc);
|
||||
wglMakeCurrent(dc, rc);
|
||||
|
||||
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
||||
|
||||
if (wglCreateContextAttribsARB)
|
||||
{
|
||||
const int OpenGLContextAttribs [] = {
|
||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
|
||||
#if defined(_DEBUG)
|
||||
//WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | WGL_CONTEXT_DEBUG_BIT_ARB,
|
||||
#else
|
||||
//WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
||||
#endif
|
||||
//WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
||||
0, 0
|
||||
};
|
||||
|
||||
const HGLRC OpenGLContext = wglCreateContextAttribsARB(dc, 0, OpenGLContextAttribs);
|
||||
|
||||
wglMakeCurrent(dc, OpenGLContext);
|
||||
|
||||
wglDeleteContext(rc);
|
||||
|
||||
rc = OpenGLContext;
|
||||
}
|
||||
|
||||
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)wglGetProcAddress("glDeleteObjectARB");
|
||||
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)wglGetProcAddress("glCompileShaderARB");
|
||||
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)wglGetProcAddress("glGetInfoLogARB");
|
||||
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)wglGetProcAddress("glGetObjectParameterivARB");
|
||||
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)wglGetProcAddress("glCreateProgramObjectARB");
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)wglGetProcAddress("glAttachObjectARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)wglGetProcAddress("glLinkProgramARB");
|
||||
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)wglGetProcAddress("glUseProgramObjectARB");
|
||||
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)wglGetProcAddress("glGetShaderInfoLog");
|
||||
}
|
||||
#endif
|
||||
|
||||
void PrintSingleLineError(FILE* pFile, const char* error)
|
||||
{
|
||||
while (*error != '\0')
|
||||
{
|
||||
const char* pLineEnd = strchr(error, '\n');
|
||||
if (pLineEnd == 0)
|
||||
{
|
||||
pLineEnd = error + strlen(error) - 1;
|
||||
}
|
||||
fwrite(error, 1, pLineEnd - error, pFile);
|
||||
fwrite("\r", 1, 1, pFile);
|
||||
error = pLineEnd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int TryCompileShader(GLenum eShaderType, const char* inFilename, const char* shader, double* pCompileTime, int useStdErr)
|
||||
{
|
||||
GLint iCompileStatus;
|
||||
GLuint hShader;
|
||||
Timer_t timer;
|
||||
|
||||
InitTimer(&timer);
|
||||
|
||||
InitOpenGL();
|
||||
|
||||
hShader = glCreateShaderObjectARB(eShaderType);
|
||||
glShaderSourceARB(hShader, 1, (const char**)&shader, NULL);
|
||||
|
||||
ResetTimer(&timer);
|
||||
glCompileShaderARB(hShader);
|
||||
*pCompileTime = ReadTimer(&timer);
|
||||
|
||||
/* Check it compiled OK */
|
||||
glGetObjectParameterivARB (hShader, GL_OBJECT_COMPILE_STATUS_ARB, &iCompileStatus);
|
||||
|
||||
if (iCompileStatus != GL_TRUE)
|
||||
{
|
||||
FILE* errorFile = NULL;
|
||||
GLint iInfoLogLength = 0;
|
||||
char* pszInfoLog;
|
||||
|
||||
glGetObjectParameterivARB (hShader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &iInfoLogLength);
|
||||
|
||||
pszInfoLog = new char[iInfoLogLength];
|
||||
|
||||
printf("Error: Failed to compile GLSL shader\n");
|
||||
|
||||
glGetInfoLogARB (hShader, iInfoLogLength, NULL, pszInfoLog);
|
||||
|
||||
printf(pszInfoLog);
|
||||
|
||||
if (!useStdErr)
|
||||
{
|
||||
std::string filename;
|
||||
filename += inFilename;
|
||||
filename += "_compileErrors.txt";
|
||||
|
||||
//Dump to file
|
||||
fopen_s(&errorFile, filename.c_str(), "w");
|
||||
|
||||
fclose(errorFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Present error to stderror with no "new lines" as required by remote shader compiler
|
||||
fprintf(stderr, "%s(-) error: ", inFilename);
|
||||
PrintSingleLineError(stderr, pszInfoLog);
|
||||
fprintf(stderr, "\rshader: ");
|
||||
PrintSingleLineError(stderr, shader);
|
||||
}
|
||||
|
||||
delete [] pszInfoLog;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int fileExists(const char* path)
|
||||
{
|
||||
FILE* shaderFile;
|
||||
shaderFile = fopen(path, "rb");
|
||||
|
||||
if (shaderFile)
|
||||
{
|
||||
fclose(shaderFile);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GLLang LanguageFromString(const char* str)
|
||||
{
|
||||
if (strcmp(str, "es100") == 0)
|
||||
{
|
||||
return LANG_ES_100;
|
||||
}
|
||||
if (strcmp(str, "es300") == 0)
|
||||
{
|
||||
return LANG_ES_300;
|
||||
}
|
||||
if (strcmp(str, "es310") == 0)
|
||||
{
|
||||
return LANG_ES_310;
|
||||
}
|
||||
if (strcmp(str, "120") == 0)
|
||||
{
|
||||
return LANG_120;
|
||||
}
|
||||
if (strcmp(str, "130") == 0)
|
||||
{
|
||||
return LANG_130;
|
||||
}
|
||||
if (strcmp(str, "140") == 0)
|
||||
{
|
||||
return LANG_140;
|
||||
}
|
||||
if (strcmp(str, "150") == 0)
|
||||
{
|
||||
return LANG_150;
|
||||
}
|
||||
if (strcmp(str, "330") == 0)
|
||||
{
|
||||
return LANG_330;
|
||||
}
|
||||
if (strcmp(str, "400") == 0)
|
||||
{
|
||||
return LANG_400;
|
||||
}
|
||||
if (strcmp(str, "410") == 0)
|
||||
{
|
||||
return LANG_410;
|
||||
}
|
||||
if (strcmp(str, "420") == 0)
|
||||
{
|
||||
return LANG_420;
|
||||
}
|
||||
if (strcmp(str, "430") == 0)
|
||||
{
|
||||
return LANG_430;
|
||||
}
|
||||
if (strcmp(str, "440") == 0)
|
||||
{
|
||||
return LANG_440;
|
||||
}
|
||||
return LANG_DEFAULT;
|
||||
}
|
||||
|
||||
#define MAX_PATH_CHARS 256
|
||||
#define MAX_FXC_CMD_CHARS 1024
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLLang language;
|
||||
|
||||
int flags;
|
||||
|
||||
const char* shaderFile;
|
||||
char* outputShaderFile;
|
||||
|
||||
char* reflectPath;
|
||||
|
||||
char cacheKey[MAX_PATH_CHARS];
|
||||
|
||||
int bUseFxc;
|
||||
std::string fxcCmdLine;
|
||||
} Options;
|
||||
|
||||
void InitOptions(Options* psOptions)
|
||||
{
|
||||
psOptions->language = LANG_DEFAULT;
|
||||
psOptions->flags = 0;
|
||||
psOptions->reflectPath = NULL;
|
||||
|
||||
psOptions->shaderFile = NULL;
|
||||
|
||||
psOptions->bUseFxc = 0;
|
||||
}
|
||||
|
||||
void PrintHelp()
|
||||
{
|
||||
printf("Command line options:\n");
|
||||
|
||||
printf("\t-lang=X \t GLSL language to use. e.g. es100 or 140 or metal.\n");
|
||||
printf("\t-flags=X \t The integer value of the HLSLCC_FLAGS to used.\n");
|
||||
printf("\t-reflect=X \t File to write reflection JSON to.\n");
|
||||
printf("\t-in=X \t Shader file to compile.\n");
|
||||
printf("\t-out=X \t File to write the compiled shader from -in to.\n");
|
||||
|
||||
printf("\t-hashout=[dir/]out-file-name \t Output file name is a hash of 'out-file-name', put in the directory 'dir'.\n");
|
||||
|
||||
printf("\t-fxc=\"CMD\" HLSL compiler command line. If specified the input shader will be first compiled through this command first and then the resulting bytecode translated.\n");
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int GetOptions(int argc, char** argv, Options* psOptions)
|
||||
{
|
||||
int i;
|
||||
int fullShaderChain = -1;
|
||||
|
||||
InitOptions(psOptions);
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
char* option;
|
||||
|
||||
option = strstr(argv[i], "-help");
|
||||
if (option != NULL)
|
||||
{
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
option = strstr(argv[i], "-reflect=");
|
||||
if (option != NULL)
|
||||
{
|
||||
psOptions->reflectPath = option + strlen("-reflect=");
|
||||
}
|
||||
|
||||
option = strstr(argv[i], "-lang=");
|
||||
if (option != NULL)
|
||||
{
|
||||
psOptions->language = LanguageFromString((&option[strlen("-lang=")]));
|
||||
}
|
||||
|
||||
option = strstr(argv[i], "-flags=");
|
||||
if (option != NULL)
|
||||
{
|
||||
psOptions->flags = atol(&option[strlen("-flags=")]);
|
||||
}
|
||||
|
||||
option = strstr(argv[i], "-in=");
|
||||
if (option != NULL)
|
||||
{
|
||||
fullShaderChain = 0;
|
||||
psOptions->shaderFile = option + strlen("-in=");
|
||||
if (!fileExists(psOptions->shaderFile))
|
||||
{
|
||||
printf("Invalid path: %s\n", psOptions->shaderFile);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
option = strstr(argv[i], "-out=");
|
||||
if (option != NULL)
|
||||
{
|
||||
fullShaderChain = 0;
|
||||
psOptions->outputShaderFile = option + strlen("-out=");
|
||||
}
|
||||
|
||||
option = strstr(argv[i], "-hashout");
|
||||
if (option != NULL)
|
||||
{
|
||||
fullShaderChain = 0;
|
||||
psOptions->outputShaderFile = option + strlen("-hashout=");
|
||||
|
||||
char* dir;
|
||||
int64_t length;
|
||||
|
||||
uint64_t hash = hash64((const uint8_t*)psOptions->outputShaderFile, (uint32_t)strlen(psOptions->outputShaderFile), 0);
|
||||
|
||||
|
||||
dir = strrchr(psOptions->outputShaderFile, '\\');
|
||||
|
||||
if (!dir)
|
||||
{
|
||||
dir = strrchr(psOptions->outputShaderFile, '//');
|
||||
}
|
||||
|
||||
if (!dir)
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
length = (int)(dir - psOptions->outputShaderFile) + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
psOptions->cacheKey[i] = psOptions->outputShaderFile[i];
|
||||
}
|
||||
|
||||
//sprintf(psOptions->cacheKey, "%x%x", high, low);
|
||||
sprintf(&psOptions->cacheKey[i], "%010" PRIX64, hash);
|
||||
|
||||
psOptions->outputShaderFile = psOptions->cacheKey;
|
||||
}
|
||||
|
||||
option = strstr(argv[i], "-fxc=");
|
||||
if (option != NULL)
|
||||
{
|
||||
char* cmdLine = option + strlen("-fxc=");
|
||||
size_t cmdLineLen = strlen(cmdLine);
|
||||
if (cmdLineLen == 0 || cmdLineLen + 1 >= MAX_FXC_CMD_CHARS)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
psOptions->fxcCmdLine = std::string(cmdLine, cmdLineLen);
|
||||
psOptions->bUseFxc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void* malloc_hook(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
void* calloc_hook(size_t num, size_t size)
|
||||
{
|
||||
return calloc(num, size);
|
||||
}
|
||||
void* realloc_hook(void* p, size_t size)
|
||||
{
|
||||
return realloc(p, size);
|
||||
}
|
||||
void free_hook(void* p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
int Run(const char* srcPath, const char* destPath, GLLang language, int flags, const char* reflectPath, GLSLShader* shader, int useStdErr)
|
||||
{
|
||||
FILE* outputFile;
|
||||
GLSLShader tempShader;
|
||||
GLSLShader* result = shader ? shader : &tempShader;
|
||||
Timer_t timer;
|
||||
int compiledOK = 0;
|
||||
double crossCompileTime = 0;
|
||||
|
||||
HLSLcc_SetMemoryFunctions(malloc_hook, calloc_hook, free_hook, realloc_hook);
|
||||
|
||||
InitTimer(&timer);
|
||||
|
||||
ResetTimer(&timer);
|
||||
GlExtensions ext;
|
||||
ext.ARB_explicit_attrib_location = 0;
|
||||
ext.ARB_explicit_uniform_location = 0;
|
||||
ext.ARB_shading_language_420pack = 0;
|
||||
compiledOK = TranslateHLSLFromFile(srcPath, flags, language, &ext, result);
|
||||
|
||||
crossCompileTime = ReadTimer(&timer);
|
||||
|
||||
if (compiledOK)
|
||||
{
|
||||
printf("cc time: %.2f us\n", crossCompileTime);
|
||||
|
||||
if (destPath)
|
||||
{
|
||||
//Dump to file
|
||||
outputFile = fopen(destPath, "w");
|
||||
fprintf(outputFile, result->sourceCode);
|
||||
fclose(outputFile);
|
||||
}
|
||||
|
||||
if (reflectPath)
|
||||
{
|
||||
const char* jsonString = SerializeReflection(&result->reflection);
|
||||
outputFile = fopen(reflectPath, "w");
|
||||
fprintf(outputFile, jsonString);
|
||||
fclose(outputFile);
|
||||
}
|
||||
|
||||
#if defined(VALIDATE_OUTPUT)
|
||||
std::string shaderSource;
|
||||
if (flags & HLSLCC_FLAG_NO_VERSION_STRING)
|
||||
{
|
||||
// Need to add the version string so that the shader will compile
|
||||
shaderSource = GetVersionString(language);
|
||||
shaderSource += result->sourceCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
shaderSource = result->sourceCode;
|
||||
}
|
||||
compiledOK = TryCompileShader(result->shaderType, destPath ? destPath : "", shaderSource.c_str(), &glslCompileTime, useStdErr);
|
||||
|
||||
if (compiledOK)
|
||||
{
|
||||
printf("glsl time: %.2f us\n", glslCompileTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!shader)
|
||||
{
|
||||
FreeGLSLShader(result);
|
||||
}
|
||||
}
|
||||
else if (useStdErr)
|
||||
{
|
||||
fprintf(stderr, "TranslateHLSLFromFile failed");
|
||||
}
|
||||
|
||||
return compiledOK;
|
||||
}
|
||||
|
||||
struct SDXBCFile
|
||||
{
|
||||
FILE* m_pFile;
|
||||
|
||||
bool Read(void* pElements, size_t uSize)
|
||||
{
|
||||
return fread(pElements, 1, uSize, m_pFile) == uSize;
|
||||
}
|
||||
|
||||
bool Write(const void* pElements, size_t uSize)
|
||||
{
|
||||
return fwrite(pElements, 1, uSize, m_pFile) == uSize;
|
||||
}
|
||||
|
||||
bool SeekRel(int32_t iOffset)
|
||||
{
|
||||
return fseek(m_pFile, iOffset, SEEK_CUR) == 0;
|
||||
}
|
||||
|
||||
bool SeekAbs(uint32_t uPosition)
|
||||
{
|
||||
return fseek(m_pFile, uPosition, SEEK_SET) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
int CombineDXBCWithGLSL(char* dxbcFileName, char* outputFileName, GLSLShader* shader)
|
||||
{
|
||||
SDXBCFile dxbcFile = { fopen(dxbcFileName, "rb") };
|
||||
SDXBCFile outputFile = { fopen(outputFileName, "wb") };
|
||||
|
||||
bool result =
|
||||
dxbcFile.m_pFile != NULL && outputFile.m_pFile != NULL &&
|
||||
DXBCCombineWithGLSL(dxbcFile, outputFile, shader);
|
||||
|
||||
if (dxbcFile.m_pFile != NULL)
|
||||
{
|
||||
fclose(dxbcFile.m_pFile);
|
||||
}
|
||||
if (outputFile.m_pFile != NULL)
|
||||
{
|
||||
fclose(outputFile.m_pFile);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
#define sprintf_s(dest, size, ...) sprintf(dest, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && defined(PORTABLE)
|
||||
|
||||
DWORD FilterException(DWORD uExceptionCode)
|
||||
{
|
||||
const char* szExceptionName;
|
||||
char acTemp[10];
|
||||
switch (uExceptionCode)
|
||||
{
|
||||
#define _CASE(_Name) \
|
||||
case _Name: \
|
||||
szExceptionName = #_Name; \
|
||||
break;
|
||||
_CASE(EXCEPTION_ACCESS_VIOLATION)
|
||||
_CASE(EXCEPTION_DATATYPE_MISALIGNMENT)
|
||||
_CASE(EXCEPTION_BREAKPOINT)
|
||||
_CASE(EXCEPTION_SINGLE_STEP)
|
||||
_CASE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
|
||||
_CASE(EXCEPTION_FLT_DENORMAL_OPERAND)
|
||||
_CASE(EXCEPTION_FLT_DIVIDE_BY_ZERO)
|
||||
_CASE(EXCEPTION_FLT_INEXACT_RESULT)
|
||||
_CASE(EXCEPTION_FLT_INVALID_OPERATION)
|
||||
_CASE(EXCEPTION_FLT_OVERFLOW)
|
||||
_CASE(EXCEPTION_FLT_STACK_CHECK)
|
||||
_CASE(EXCEPTION_FLT_UNDERFLOW)
|
||||
_CASE(EXCEPTION_INT_DIVIDE_BY_ZERO)
|
||||
_CASE(EXCEPTION_INT_OVERFLOW)
|
||||
_CASE(EXCEPTION_PRIV_INSTRUCTION)
|
||||
_CASE(EXCEPTION_IN_PAGE_ERROR)
|
||||
_CASE(EXCEPTION_ILLEGAL_INSTRUCTION)
|
||||
_CASE(EXCEPTION_NONCONTINUABLE_EXCEPTION)
|
||||
_CASE(EXCEPTION_STACK_OVERFLOW)
|
||||
_CASE(EXCEPTION_INVALID_DISPOSITION)
|
||||
_CASE(EXCEPTION_GUARD_PAGE)
|
||||
_CASE(EXCEPTION_INVALID_HANDLE)
|
||||
//_CASE(EXCEPTION_POSSIBLE_DEADLOCK)
|
||||
#undef _CASE
|
||||
default:
|
||||
sprintf_s(acTemp, "0x%08X", uExceptionCode);
|
||||
szExceptionName = acTemp;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Hardware exception thrown (%s)\n", szExceptionName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const char* PatchHLSLShaderFile(const char* path)
|
||||
{
|
||||
// Need to transform "half" into "min16float" so FXC preserve min precision to the operands.
|
||||
static char patchedFileName[MAX_PATH_CHARS];
|
||||
const char* defines = "#define half min16float\n"
|
||||
"#define half2 min16float2\n"
|
||||
"#define half3 min16float3\n"
|
||||
"#define half4 min16float4\n";
|
||||
|
||||
sprintf_s(patchedFileName, sizeof(patchedFileName), "%s.hlslPatched", path);
|
||||
FILE* shaderFile = fopen(path, "rb");
|
||||
if (!shaderFile)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FILE* patchedFile = fopen(patchedFileName, "wb");
|
||||
if (!patchedFile)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Get size of file
|
||||
bool result = false;
|
||||
fseek(shaderFile, 0, SEEK_END);
|
||||
long size = ftell(shaderFile);
|
||||
fseek(shaderFile, 0, SEEK_SET);
|
||||
unsigned char* data = new unsigned char[size + 1]; // Extra byte for the '/0' character.
|
||||
if (fread(data, 1, size, shaderFile) == size)
|
||||
{
|
||||
data[size] = '\0';
|
||||
fprintf(patchedFile, "%s%s", defines, data);
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (shaderFile)
|
||||
{
|
||||
fclose(shaderFile);
|
||||
}
|
||||
|
||||
if (patchedFile)
|
||||
{
|
||||
fclose(patchedFile);
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
return result ? patchedFileName : NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Options options;
|
||||
|
||||
#if defined(_WIN32) && defined(PORTABLE)
|
||||
__try
|
||||
{
|
||||
#endif
|
||||
|
||||
if (!GetOptions(argc, argv, &options))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (options.bUseFxc)
|
||||
{
|
||||
char dxbcFileName[MAX_PATH_CHARS];
|
||||
char glslFileName[MAX_PATH_CHARS];
|
||||
char fullFxcCmdLine[MAX_FXC_CMD_CHARS];
|
||||
int retValue;
|
||||
|
||||
if (options.flags & HLSLCC_FLAG_HALF_FLOAT_TRANSFORM)
|
||||
{
|
||||
options.shaderFile = PatchHLSLShaderFile(options.shaderFile);
|
||||
if (!options.shaderFile)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf_s(dxbcFileName, sizeof(dxbcFileName), "%s.dxbc", options.shaderFile);
|
||||
sprintf_s(glslFileName, sizeof(glslFileName), "%s.patched", options.shaderFile);
|
||||
|
||||
// Need to extract the path to the executable so we can enclose it in quotes
|
||||
// in case it contains spaces.
|
||||
const std::string fxcExeName = "fxc.exe";
|
||||
|
||||
// Case insensitive search
|
||||
std::string::iterator fxcPos = std::search(
|
||||
options.fxcCmdLine.begin(), options.fxcCmdLine.end(),
|
||||
fxcExeName.begin(), fxcExeName.end(),
|
||||
[](char ch1, char ch2) { return std::tolower(ch1) == std::tolower(ch2); }
|
||||
);
|
||||
|
||||
if (fxcPos == options.fxcCmdLine.end())
|
||||
{
|
||||
fprintf(stderr, "Could not find fxc.exe in command line");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Add the fxcExeName so it gets copied to the fxcExe path.
|
||||
fxcPos += fxcExeName.length();
|
||||
std::string fxcExe(options.fxcCmdLine.begin(), fxcPos);
|
||||
std::string fxcArguments(fxcPos, options.fxcCmdLine.end());
|
||||
|
||||
#if defined(APPLE)
|
||||
fprintf(stderr, "fxc.exe cannot be executed on Mac");
|
||||
return 1;
|
||||
#else
|
||||
// Need an extra set of quotes around the full command line because the way "system" executes it using cmd.
|
||||
sprintf_s(fullFxcCmdLine, sizeof(fullFxcCmdLine), "\"\"%s\" %s \"%s\" \"%s\"\"", fxcExe.c_str(), fxcArguments.c_str(), dxbcFileName, options.shaderFile);
|
||||
#endif
|
||||
|
||||
retValue = system(fullFxcCmdLine);
|
||||
|
||||
if (retValue == 0)
|
||||
{
|
||||
GLSLShader shader;
|
||||
retValue = !Run(dxbcFileName, glslFileName, options.language, options.flags, options.reflectPath, &shader, 1);
|
||||
|
||||
if (retValue == 0)
|
||||
{
|
||||
retValue = !CombineDXBCWithGLSL(dxbcFileName, options.outputShaderFile, &shader);
|
||||
FreeGLSLShader(&shader);
|
||||
}
|
||||
}
|
||||
|
||||
remove(dxbcFileName);
|
||||
remove(glslFileName);
|
||||
if (options.flags & HLSLCC_FLAG_HALF_FLOAT_TRANSFORM)
|
||||
{
|
||||
// Removed the hlsl patched file that was created.
|
||||
remove(options.shaderFile);
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
if (options.shaderFile)
|
||||
{
|
||||
if (!Run(options.shaderFile, options.outputShaderFile, options.language, options.flags, options.reflectPath, NULL, 0))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(PORTABLE)
|
||||
}
|
||||
__except (FilterException(GetExceptionCode()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1,152 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef HASH_H_
|
||||
#define HASH_H_
|
||||
|
||||
/*
|
||||
--------------------------------------------------------------------
|
||||
mix -- mix 3 64-bit values reversibly.
|
||||
mix() takes 48 machine instructions, but only 24 cycles on a superscalar
|
||||
machine (like Intel's new MMX architecture). It requires 4 64-bit
|
||||
registers for 4::2 parallelism.
|
||||
All 1-bit deltas, all 2-bit deltas, all deltas composed of top bits of
|
||||
(a,b,c), and all deltas of bottom bits were tested. All deltas were
|
||||
tested both on random keys and on keys that were nearly all zero.
|
||||
These deltas all cause every bit of c to change between 1/3 and 2/3
|
||||
of the time (well, only 113/400 to 287/400 of the time for some
|
||||
2-bit delta). These deltas all cause at least 80 bits to change
|
||||
among (a,b,c) when the mix is run either forward or backward (yes it
|
||||
is reversible).
|
||||
This implies that a hash using mix64 has no funnels. There may be
|
||||
characteristics with 3-bit deltas or bigger, I didn't test for
|
||||
those.
|
||||
--------------------------------------------------------------------
|
||||
*/
|
||||
#define mix64(a, b, c) \
|
||||
{ \
|
||||
a -= b; a -= c; a ^= (c >> 43); \
|
||||
b -= c; b -= a; b ^= (a << 9); \
|
||||
c -= a; c -= b; c ^= (b >> 8); \
|
||||
a -= b; a -= c; a ^= (c >> 38); \
|
||||
b -= c; b -= a; b ^= (a << 23); \
|
||||
c -= a; c -= b; c ^= (b >> 5); \
|
||||
a -= b; a -= c; a ^= (c >> 35); \
|
||||
b -= c; b -= a; b ^= (a << 49); \
|
||||
c -= a; c -= b; c ^= (b >> 11); \
|
||||
a -= b; a -= c; a ^= (c >> 12); \
|
||||
b -= c; b -= a; b ^= (a << 18); \
|
||||
c -= a; c -= b; c ^= (b >> 22); \
|
||||
}
|
||||
|
||||
/*
|
||||
--------------------------------------------------------------------
|
||||
hash64() -- hash a variable-length key into a 64-bit value
|
||||
k : the key (the unaligned variable-length array of bytes)
|
||||
len : the length of the key, counting by bytes
|
||||
level : can be any 8-byte value
|
||||
Returns a 64-bit value. Every bit of the key affects every bit of
|
||||
the return value. No funnels. Every 1-bit and 2-bit delta achieves
|
||||
avalanche. About 41+5len instructions.
|
||||
|
||||
The best hash table sizes are powers of 2. There is no need to do
|
||||
mod a prime (mod is sooo slow!). If you need less than 64 bits,
|
||||
use a bitmask. For example, if you need only 10 bits, do
|
||||
h = (h & hashmask(10));
|
||||
In which case, the hash table should have hashsize(10) elements.
|
||||
|
||||
If you are hashing n strings (ub1 **)k, do it like this:
|
||||
for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
|
||||
|
||||
By Bob Jenkins, Jan 4 1997. bob_jenkins@burtleburtle.net. You may
|
||||
use this code any way you wish, private, educational, or commercial,
|
||||
but I would appreciate if you give me credit.
|
||||
|
||||
See http://burtleburtle.net/bob/hash/evahash.html
|
||||
Use for hash table lookup, or anything where one collision in 2^^64
|
||||
is acceptable. Do NOT use for cryptographic purposes.
|
||||
--------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static uint64_t hash64(const uint8_t* k, uint32_t length, uint64_t initval)
|
||||
{
|
||||
uint64_t a, b, c, len;
|
||||
|
||||
/* Set up the internal state */
|
||||
len = length;
|
||||
a = b = initval; /* the previous hash value */
|
||||
c = 0x9e3779b97f4a7c13LL; /* the golden ratio; an arbitrary value */
|
||||
|
||||
/*---------------------------------------- handle most of the key */
|
||||
while (len >= 24)
|
||||
{
|
||||
a += (k[0] + ((uint64_t)k[ 1] << 8) + ((uint64_t)k[ 2] << 16) + ((uint64_t)k[ 3] << 24)
|
||||
+ ((uint64_t)k[4 ] << 32) + ((uint64_t)k[ 5] << 40) + ((uint64_t)k[ 6] << 48) + ((uint64_t)k[ 7] << 56));
|
||||
b += (k[8] + ((uint64_t)k[ 9] << 8) + ((uint64_t)k[10] << 16) + ((uint64_t)k[11] << 24)
|
||||
+ ((uint64_t)k[12] << 32) + ((uint64_t)k[13] << 40) + ((uint64_t)k[14] << 48) + ((uint64_t)k[15] << 56));
|
||||
c += (k[16] + ((uint64_t)k[17] << 8) + ((uint64_t)k[18] << 16) + ((uint64_t)k[19] << 24)
|
||||
+ ((uint64_t)k[20] << 32) + ((uint64_t)k[21] << 40) + ((uint64_t)k[22] << 48) + ((uint64_t)k[23] << 56));
|
||||
mix64(a, b, c);
|
||||
k += 24;
|
||||
len -= 24;
|
||||
}
|
||||
|
||||
/*------------------------------------- handle the last 23 bytes */
|
||||
c += length;
|
||||
switch (len) /* all the case statements fall through */
|
||||
{
|
||||
case 23:
|
||||
c += ((uint64_t)k[22] << 56);
|
||||
case 22:
|
||||
c += ((uint64_t)k[21] << 48);
|
||||
case 21:
|
||||
c += ((uint64_t)k[20] << 40);
|
||||
case 20:
|
||||
c += ((uint64_t)k[19] << 32);
|
||||
case 19:
|
||||
c += ((uint64_t)k[18] << 24);
|
||||
case 18:
|
||||
c += ((uint64_t)k[17] << 16);
|
||||
case 17:
|
||||
c += ((uint64_t)k[16] << 8);
|
||||
/* the first byte of c is reserved for the length */
|
||||
case 16:
|
||||
b += ((uint64_t)k[15] << 56);
|
||||
case 15:
|
||||
b += ((uint64_t)k[14] << 48);
|
||||
case 14:
|
||||
b += ((uint64_t)k[13] << 40);
|
||||
case 13:
|
||||
b += ((uint64_t)k[12] << 32);
|
||||
case 12:
|
||||
b += ((uint64_t)k[11] << 24);
|
||||
case 11:
|
||||
b += ((uint64_t)k[10] << 16);
|
||||
case 10:
|
||||
b += ((uint64_t)k[ 9] << 8);
|
||||
case 9:
|
||||
b += ((uint64_t)k[ 8]);
|
||||
case 8:
|
||||
a += ((uint64_t)k[ 7] << 56);
|
||||
case 7:
|
||||
a += ((uint64_t)k[ 6] << 48);
|
||||
case 6:
|
||||
a += ((uint64_t)k[ 5] << 40);
|
||||
case 5:
|
||||
a += ((uint64_t)k[ 4] << 32);
|
||||
case 4:
|
||||
a += ((uint64_t)k[ 3] << 24);
|
||||
case 3:
|
||||
a += ((uint64_t)k[ 2] << 16);
|
||||
case 2:
|
||||
a += ((uint64_t)k[ 1] << 8);
|
||||
case 1:
|
||||
a += ((uint64_t)k[ 0]);
|
||||
/* case 0: nothing left to add */
|
||||
}
|
||||
mix64(a, b, c);
|
||||
/*-------------------------------------------- report the result */
|
||||
return c;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,207 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#include "serializeReflection.h"
|
||||
#include "cJSON.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
void* jsonMalloc(size_t sz)
|
||||
{
|
||||
return new char[sz];
|
||||
}
|
||||
void jsonFree(void* ptr)
|
||||
{
|
||||
char* charPtr = static_cast<char*>(ptr);
|
||||
delete [] charPtr;
|
||||
}
|
||||
|
||||
static void AppendIntToString(std::string& str, uint32_t num)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << num;
|
||||
str += ss.str();
|
||||
}
|
||||
|
||||
static void WriteInOutSignature(InOutSignature* psSignature, cJSON* obj)
|
||||
{
|
||||
cJSON_AddItemToObject(obj, "SemanticName", cJSON_CreateString(psSignature->SemanticName));
|
||||
cJSON_AddItemToObject(obj, "ui32SemanticIndex", cJSON_CreateNumber(psSignature->ui32SemanticIndex));
|
||||
cJSON_AddItemToObject(obj, "eSystemValueType", cJSON_CreateNumber(psSignature->eSystemValueType));
|
||||
cJSON_AddItemToObject(obj, "eComponentType", cJSON_CreateNumber(psSignature->eComponentType));
|
||||
cJSON_AddItemToObject(obj, "ui32Register", cJSON_CreateNumber(psSignature->ui32Register));
|
||||
cJSON_AddItemToObject(obj, "ui32Mask", cJSON_CreateNumber(psSignature->ui32Mask));
|
||||
cJSON_AddItemToObject(obj, "ui32ReadWriteMask", cJSON_CreateNumber(psSignature->ui32ReadWriteMask));
|
||||
}
|
||||
|
||||
static void WriteResourceBinding(ResourceBinding* psBinding, cJSON* obj)
|
||||
{
|
||||
cJSON_AddItemToObject(obj, "Name", cJSON_CreateString(psBinding->Name));
|
||||
cJSON_AddItemToObject(obj, "eType", cJSON_CreateNumber(psBinding->eType));
|
||||
cJSON_AddItemToObject(obj, "ui32BindPoint", cJSON_CreateNumber(psBinding->ui32BindPoint));
|
||||
cJSON_AddItemToObject(obj, "ui32BindCount", cJSON_CreateNumber(psBinding->ui32BindCount));
|
||||
cJSON_AddItemToObject(obj, "ui32Flags", cJSON_CreateNumber(psBinding->ui32Flags));
|
||||
cJSON_AddItemToObject(obj, "eDimension", cJSON_CreateNumber(psBinding->eDimension));
|
||||
cJSON_AddItemToObject(obj, "ui32ReturnType", cJSON_CreateNumber(psBinding->ui32ReturnType));
|
||||
cJSON_AddItemToObject(obj, "ui32NumSamples", cJSON_CreateNumber(psBinding->ui32NumSamples));
|
||||
}
|
||||
|
||||
static void WriteShaderVar(ShaderVar* psVar, cJSON* obj)
|
||||
{
|
||||
cJSON_AddItemToObject(obj, "Name", cJSON_CreateString(psVar->Name));
|
||||
if(psVar->haveDefaultValue)
|
||||
{
|
||||
cJSON_AddItemToObject(obj, "aui32DefaultValues", cJSON_CreateIntArray((int*)psVar->pui32DefaultValues, psVar->ui32Size/4));
|
||||
}
|
||||
cJSON_AddItemToObject(obj, "ui32StartOffset", cJSON_CreateNumber(psVar->ui32StartOffset));
|
||||
cJSON_AddItemToObject(obj, "ui32Size", cJSON_CreateNumber(psVar->ui32Size));
|
||||
}
|
||||
|
||||
static void WriteConstantBuffer(ConstantBuffer* psCBuf, cJSON* obj)
|
||||
{
|
||||
cJSON_AddItemToObject(obj, "Name", cJSON_CreateString(psCBuf->Name));
|
||||
cJSON_AddItemToObject(obj, "ui32NumVars", cJSON_CreateNumber(psCBuf->ui32NumVars));
|
||||
|
||||
for(uint32_t i = 0; i < psCBuf->ui32NumVars; ++i)
|
||||
{
|
||||
std::string name;
|
||||
name += "var";
|
||||
AppendIntToString(name, i);
|
||||
|
||||
cJSON* varObj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(obj, name.c_str(), varObj);
|
||||
|
||||
WriteShaderVar(&psCBuf->asVars[i], varObj);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(obj, "ui32TotalSizeInBytes", cJSON_CreateNumber(psCBuf->ui32TotalSizeInBytes));
|
||||
}
|
||||
|
||||
static void WriteClassType(ClassType* psClassType, cJSON* obj)
|
||||
{
|
||||
cJSON_AddItemToObject(obj, "Name", cJSON_CreateString(psClassType->Name));
|
||||
cJSON_AddItemToObject(obj, "ui16ID", cJSON_CreateNumber(psClassType->ui16ID));
|
||||
cJSON_AddItemToObject(obj, "ui16ConstBufStride", cJSON_CreateNumber(psClassType->ui16ConstBufStride));
|
||||
cJSON_AddItemToObject(obj, "ui16Texture", cJSON_CreateNumber(psClassType->ui16Texture));
|
||||
cJSON_AddItemToObject(obj, "ui16Sampler", cJSON_CreateNumber(psClassType->ui16Sampler));
|
||||
}
|
||||
|
||||
static void WriteClassInstance(ClassInstance* psClassInst, cJSON* obj)
|
||||
{
|
||||
cJSON_AddItemToObject(obj, "Name", cJSON_CreateString(psClassInst->Name));
|
||||
cJSON_AddItemToObject(obj, "ui16ID", cJSON_CreateNumber(psClassInst->ui16ID));
|
||||
cJSON_AddItemToObject(obj, "ui16ConstBuf", cJSON_CreateNumber(psClassInst->ui16ConstBuf));
|
||||
cJSON_AddItemToObject(obj, "ui16ConstBufOffset", cJSON_CreateNumber(psClassInst->ui16ConstBufOffset));
|
||||
cJSON_AddItemToObject(obj, "ui16Texture", cJSON_CreateNumber(psClassInst->ui16Texture));
|
||||
cJSON_AddItemToObject(obj, "ui16Sampler", cJSON_CreateNumber(psClassInst->ui16Sampler));
|
||||
}
|
||||
|
||||
const char* SerializeReflection(ShaderInfo* psReflection)
|
||||
{
|
||||
cJSON* root;
|
||||
|
||||
cJSON_Hooks hooks;
|
||||
hooks.malloc_fn = jsonMalloc;
|
||||
hooks.free_fn = jsonFree;
|
||||
cJSON_InitHooks(&hooks);
|
||||
|
||||
root=cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "ui32MajorVersion", cJSON_CreateNumber(psReflection->ui32MajorVersion));
|
||||
cJSON_AddItemToObject(root, "ui32MinorVersion", cJSON_CreateNumber(psReflection->ui32MinorVersion));
|
||||
|
||||
cJSON_AddItemToObject(root, "ui32NumInputSignatures", cJSON_CreateNumber(psReflection->ui32NumInputSignatures));
|
||||
|
||||
for(uint32_t i = 0; i < psReflection->ui32NumInputSignatures; ++i)
|
||||
{
|
||||
std::string name;
|
||||
name += "input";
|
||||
AppendIntToString(name, i);
|
||||
|
||||
cJSON* obj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, name.c_str(), obj);
|
||||
|
||||
WriteInOutSignature(psReflection->psInputSignatures+i, obj);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(root, "ui32NumOutputSignatures", cJSON_CreateNumber(psReflection->ui32NumOutputSignatures));
|
||||
|
||||
for(uint32_t i = 0; i < psReflection->ui32NumOutputSignatures; ++i)
|
||||
{
|
||||
std::string name;
|
||||
name += "output";
|
||||
AppendIntToString(name, i);
|
||||
|
||||
cJSON* obj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, name.c_str(), obj);
|
||||
|
||||
WriteInOutSignature(psReflection->psOutputSignatures+i, obj);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(root, "ui32NumResourceBindings", cJSON_CreateNumber(psReflection->ui32NumResourceBindings));
|
||||
|
||||
for(uint32_t i = 0; i < psReflection->ui32NumResourceBindings; ++i)
|
||||
{
|
||||
std::string name;
|
||||
name += "resource";
|
||||
AppendIntToString(name, i);
|
||||
|
||||
cJSON* obj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, name.c_str(), obj);
|
||||
|
||||
WriteResourceBinding(psReflection->psResourceBindings+i, obj);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(root, "ui32NumConstantBuffers", cJSON_CreateNumber(psReflection->ui32NumConstantBuffers));
|
||||
|
||||
for(uint32_t i = 0; i < psReflection->ui32NumConstantBuffers; ++i)
|
||||
{
|
||||
std::string name;
|
||||
name += "cbuf";
|
||||
AppendIntToString(name, i);
|
||||
|
||||
cJSON* obj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, name.c_str(), obj);
|
||||
|
||||
WriteConstantBuffer(psReflection->psConstantBuffers+i, obj);
|
||||
}
|
||||
|
||||
//psThisPointerConstBuffer is a cache. Don't need to write this out.
|
||||
//It just points to the $ThisPointer cbuffer within the psConstantBuffers array.
|
||||
|
||||
for(uint32_t i = 0; i < psReflection->ui32NumClassTypes; ++i)
|
||||
{
|
||||
std::string name;
|
||||
name += "classType";
|
||||
AppendIntToString(name, i);
|
||||
|
||||
cJSON* obj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, name.c_str(), obj);
|
||||
|
||||
WriteClassType(psReflection->psClassTypes+i, obj);
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < psReflection->ui32NumClassInstances; ++i)
|
||||
{
|
||||
std::string name;
|
||||
name += "classInst";
|
||||
AppendIntToString(name, i);
|
||||
|
||||
cJSON* obj = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, name.c_str(), obj);
|
||||
|
||||
WriteClassInstance(psReflection->psClassInstances+i, obj);
|
||||
}
|
||||
|
||||
//psReflection->aui32TableIDToTypeID
|
||||
//psReflection->aui32ConstBufferBindpointRemap
|
||||
|
||||
cJSON_AddItemToObject(root, "eTessPartitioning", cJSON_CreateNumber(psReflection->eTessPartitioning));
|
||||
cJSON_AddItemToObject(root, "eTessOutPrim", cJSON_CreateNumber(psReflection->eTessOutPrim));
|
||||
|
||||
|
||||
const char* jsonString = cJSON_Print(root);
|
||||
|
||||
cJSON_Delete(root);
|
||||
|
||||
return jsonString;
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef SERIALIZE_REFLECTION_H_
|
||||
#define SERIALIZE_REFLECTION_H_
|
||||
|
||||
#include "hlslcc.h"
|
||||
|
||||
const char* SerializeReflection(ShaderInfo* psReflection);
|
||||
|
||||
#endif
|
||||
@ -1,40 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
void InitTimer(Timer_t* psTimer)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
QueryPerformanceFrequency(&psTimer->frequency);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ResetTimer(Timer_t* psTimer)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
QueryPerformanceCounter(&psTimer->startCount);
|
||||
#else
|
||||
gettimeofday(&psTimer->startCount, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Returns time in micro seconds */
|
||||
double ReadTimer(Timer_t* psTimer)
|
||||
{
|
||||
double startTimeInMicroSec, endTimeInMicroSec;
|
||||
|
||||
#if defined(_WIN32)
|
||||
const double freq = (1000000.0 / psTimer->frequency.QuadPart);
|
||||
QueryPerformanceCounter(&psTimer->endCount);
|
||||
startTimeInMicroSec = psTimer->startCount.QuadPart * freq;
|
||||
endTimeInMicroSec = psTimer->endCount.QuadPart * freq;
|
||||
#else
|
||||
gettimeofday(&psTimer->endCount, 0);
|
||||
startTimeInMicroSec = (psTimer->startCount.tv_sec * 1000000.0) + psTimer->startCount.tv_usec;
|
||||
endTimeInMicroSec = (psTimer->endCount.tv_sec * 1000000.0) + psTimer->endCount.tv_usec;
|
||||
#endif
|
||||
|
||||
return endTimeInMicroSec - startTimeInMicroSec;
|
||||
}
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#ifdef _WIN32
|
||||
LARGE_INTEGER frequency;
|
||||
LARGE_INTEGER startCount;
|
||||
LARGE_INTEGER endCount;
|
||||
#else
|
||||
struct timeval startCount;
|
||||
struct timeval endCount;
|
||||
#endif
|
||||
} Timer_t;
|
||||
|
||||
void InitTimer(Timer_t* psTimer);
|
||||
void ResetTimer(Timer_t* psTimer);
|
||||
double ReadTimer(Timer_t* psTimer);
|
||||
|
||||
#endif
|
||||
@ -1,219 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#include "internal_includes/toGLSLInstruction.h"
|
||||
#include "internal_includes/toGLSLOperand.h"
|
||||
#include "internal_includes/languages.h"
|
||||
#include "bstrlib.h"
|
||||
#include "stdio.h"
|
||||
#include "internal_includes/debug.h"
|
||||
#include "internal_includes/hlslcc_malloc.h"
|
||||
#include "amazon_changes.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic ignored "-Wpointer-sign"
|
||||
#endif
|
||||
|
||||
extern void AddIndentation(HLSLCrossCompilerContext* psContext);
|
||||
|
||||
// These are .c files, so no C++ or C++11 for us :(
|
||||
#define MAX_VARIABLE_LENGTH 16
|
||||
|
||||
// This struct is used to keep track of each valid occurance of xxxBitsToxxx(variable) and store all relevant information for fixing that instance
|
||||
typedef struct ShaderCastLocation
|
||||
{
|
||||
char tempVariableName[MAX_VARIABLE_LENGTH];
|
||||
char replacementVariableName[MAX_VARIABLE_LENGTH];
|
||||
unsigned int castType;
|
||||
|
||||
// Since we have no stl, here's our list
|
||||
struct ShaderCastLocation* next;
|
||||
} ShaderCastLocation;
|
||||
|
||||
// Structure used to prebuild the list of all functions that need to be replaced.
|
||||
typedef struct ShaderCastType
|
||||
{
|
||||
const char* functionName;
|
||||
unsigned int castType;
|
||||
const char* variableTypeName; // String for the variable type used when declaring a temporary variable to replace the source temp vector
|
||||
} ShaderCastType;
|
||||
|
||||
enum ShaderCasts
|
||||
{
|
||||
CAST_UINTBITSTOFLOAT,
|
||||
CAST_INTBITSTOFLOAT,
|
||||
CAST_FLOATBITSTOUINT,
|
||||
CAST_FLOATBITSTOINT,
|
||||
CAST_NUMCASTS
|
||||
};
|
||||
|
||||
// NOTICE: Order is important here because intBitsToFloat is a substring of uintBitsToFloat, so do not change the ordering here!
|
||||
static const ShaderCastType s_castFunctions[CAST_NUMCASTS] =
|
||||
{
|
||||
{ "uintBitsToFloat", CAST_UINTBITSTOFLOAT, "uvec4" },
|
||||
{ "intBitsToFloat", CAST_INTBITSTOFLOAT, "ivec4" },
|
||||
{ "floatBitsToUint", CAST_FLOATBITSTOUINT, "vec4" },
|
||||
{ "floatBitsToInt", CAST_FLOATBITSTOINT, "vec4" }
|
||||
};
|
||||
|
||||
int IsValidUseCase( char* variableStart, char* outVariableName, ShaderCastLocation* foundShaderCastsHead, int currentType )
|
||||
{
|
||||
// Cases we have to replace (this is very strict in definition):
|
||||
// 1) floatBitsToInt(Temp2)
|
||||
// 2) floatBitsToInt(Temp2.x)
|
||||
// 3) floatBitsToInt(Temp[0])
|
||||
// 4) floatBitsToInt(Temp[0].x)
|
||||
// Cases we do not have to replace:
|
||||
// 1) floatBitsToInt(vec4(Temp2))
|
||||
// 2) floatBitsToInt(Output0.x != 0.0f ? 1.0f : 0.0f)
|
||||
// 3) Any other version that evaluates an expression within the ()
|
||||
if ( strncmp(variableStart, "Temp", 4) != 0 )
|
||||
return 0;
|
||||
|
||||
unsigned int lengthOfVariable = 4; // Start at 4 for temp
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
char val = *(variableStart + lengthOfVariable);
|
||||
|
||||
// If alphanumeric or [] (array), we have a valid variable name
|
||||
if ( isalnum( val ) || (val == '[') || (val == ']') )
|
||||
{
|
||||
lengthOfVariable++;
|
||||
}
|
||||
else if ( (val == ')') || (val == '.') )
|
||||
{
|
||||
// Found end of variable
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Found something unexpected, so abort
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT( lengthOfVariable < MAX_VARIABLE_LENGTH );
|
||||
|
||||
// Now ensure that no duplicates of this declaration already exist
|
||||
ShaderCastLocation* currentLink = foundShaderCastsHead;
|
||||
while ( currentLink )
|
||||
{
|
||||
// If we have the same type and the same name
|
||||
if ( (currentType == currentLink->castType) && (strncmp(variableStart, currentLink->tempVariableName, lengthOfVariable) == 0) )
|
||||
return 0; // Do not add because an entry already exists for this variable and this cast function
|
||||
|
||||
// Hmm...I guess this scenario is possible, but it has not shown up in any shaders.
|
||||
// The only time we could ever hit this is if the same line casts a float to both an int and uint in separate calls
|
||||
// Seems highly unlikely, so let's just assert for now and fix it if we have to.
|
||||
if ( strncmp(variableStart, currentLink->tempVariableName, lengthOfVariable) == 0 )
|
||||
{
|
||||
// TODO: Implement this case where we cast the same variable to multiple types on the same line of GLSL
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
currentLink = currentLink->next;
|
||||
}
|
||||
|
||||
// We found a unique instance, so store it
|
||||
strncpy( outVariableName, variableStart, lengthOfVariable );
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ModifyLineForQualcommReinterpretCastBug( HLSLCrossCompilerContext* psContext, bstring* originalString, bstring* overloadString )
|
||||
{
|
||||
unsigned int numFoundCasts = 0;
|
||||
|
||||
ShaderCastLocation* foundShaderCastsHead = NULL;
|
||||
ShaderCastLocation* currentShaderCasts = NULL;
|
||||
|
||||
// Find all occurances of the *BitsTo* functions
|
||||
// Note that this would be cleaner, but 'intBitsToFloat' is a substring of 'uintBitsToFloat' so parsing order is important here.
|
||||
char* parsingString = bdataofs(*overloadString, 0);
|
||||
while ( parsingString )
|
||||
{
|
||||
char* result = NULL;
|
||||
|
||||
for ( int index=0; index<CAST_NUMCASTS; ++index )
|
||||
{
|
||||
result = strstr( parsingString, s_castFunctions[index].functionName );
|
||||
if ( result != NULL )
|
||||
{
|
||||
// Now determine if this is a case that requires a workaround
|
||||
char* variableStart = result + strlen( s_castFunctions[index].functionName ) + 1; // Add the function name + first parenthesis
|
||||
char tempVariableName[MAX_VARIABLE_LENGTH];
|
||||
memset( tempVariableName, 0, MAX_VARIABLE_LENGTH );
|
||||
|
||||
// Now the next word must be Temp, or this is not a valid case
|
||||
if ( IsValidUseCase( variableStart, tempVariableName, foundShaderCastsHead, index ) )
|
||||
{
|
||||
// Now store the information about this cast. Allocate a new link in the list.
|
||||
if ( !foundShaderCastsHead )
|
||||
{
|
||||
foundShaderCastsHead = (ShaderCastLocation*)hlslcc_malloc( sizeof(ShaderCastLocation) );
|
||||
memset( foundShaderCastsHead, 0x0, sizeof(ShaderCastLocation) );
|
||||
currentShaderCasts = foundShaderCastsHead;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT( !currentShaderCasts->next );
|
||||
currentShaderCasts->next = (ShaderCastLocation*)hlslcc_malloc( sizeof(ShaderCastLocation) );
|
||||
memset( currentShaderCasts->next, 0x0, sizeof(ShaderCastLocation) );
|
||||
currentShaderCasts = currentShaderCasts->next;
|
||||
}
|
||||
|
||||
currentShaderCasts->castType = index;
|
||||
strcpy( currentShaderCasts->tempVariableName, tempVariableName );
|
||||
|
||||
numFoundCasts++;
|
||||
}
|
||||
result += strlen( s_castFunctions[index].functionName );
|
||||
|
||||
// Break out of the loop because we have to advance the search string and start over with uintBitsToFloat again due to the problem with intBitsToFloat being a substring
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
parsingString = result;
|
||||
}
|
||||
|
||||
// If we have found no casts, then append the line to the primary string
|
||||
if ( numFoundCasts == 0 )
|
||||
{
|
||||
bconcat( *originalString, *overloadString );
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we start creating our temporary variables to workaround the crash
|
||||
currentShaderCasts = foundShaderCastsHead;
|
||||
|
||||
// NOTE: We want a count of all variables processed for this entire shader. This could be fancier...
|
||||
static unsigned int currentVariableIndex = 0;
|
||||
|
||||
while ( currentShaderCasts )
|
||||
{
|
||||
// Generate new variable name
|
||||
sprintf( currentShaderCasts->replacementVariableName, "LYTemp%i", currentVariableIndex );
|
||||
|
||||
// Write out the new variable name declaration and initialize it
|
||||
AddIndentation( psContext );
|
||||
bformata( *originalString, "%s %s=%s;\n", s_castFunctions[currentShaderCasts->castType].variableTypeName, currentShaderCasts->replacementVariableName, currentShaderCasts->tempVariableName );
|
||||
|
||||
// Now replace all instances of the variable in question with the new variable name.
|
||||
// Note: We can't do a breplace on the temp variable name because the variable can still be legally used without a reinterpret cast in that line.
|
||||
// Do a full replace on the xxBitsToxx(TempVar) here
|
||||
bstring tempVarName = bformat( "%s(%s)", s_castFunctions[currentShaderCasts->castType].functionName, currentShaderCasts->tempVariableName );
|
||||
bstring replacementVarName = bformat( "%s(%s)", s_castFunctions[currentShaderCasts->castType].functionName, currentShaderCasts->replacementVariableName );
|
||||
bfindreplace( *overloadString, tempVarName, replacementVarName, 0 );
|
||||
|
||||
// Cleanup bstrings allocated from bformat
|
||||
bdestroy( tempVarName );
|
||||
bdestroy( replacementVarName );
|
||||
|
||||
currentVariableIndex++;
|
||||
currentShaderCasts = currentShaderCasts->next;
|
||||
}
|
||||
|
||||
// Now append our modified string to the full shader file
|
||||
bconcat( *originalString, *overloadString );
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the bstring string library. This code was
|
||||
* written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause
|
||||
* BSD open source license or GPL v2.0. Refer to the accompanying documentation
|
||||
* for details on usage and license.
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
|
||||
/*
|
||||
* bsafe.c
|
||||
*
|
||||
* This is an optional module that can be used to help enforce a safety
|
||||
* standard based on pervasive usage of bstrlib. This file is not necessarily
|
||||
* portable, however, it has been tested to work correctly with Intel's C/C++
|
||||
* compiler, WATCOM C/C++ v11.x and Microsoft Visual C++.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "bsafe.h"
|
||||
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the bstring string library. This code was
|
||||
* written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause
|
||||
* BSD open source license or GPL v2.0. Refer to the accompanying documentation
|
||||
* for details on usage and license.
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
|
||||
/*
|
||||
* bsafe.h
|
||||
*
|
||||
* This is an optional module that can be used to help enforce a safety
|
||||
* standard based on pervasive usage of bstrlib. This file is not necessarily
|
||||
* portable, however, it has been tested to work correctly with Intel's C/C++
|
||||
* compiler, WATCOM C/C++ v11.x and Microsoft Visual C++.
|
||||
*/
|
||||
|
||||
#ifndef BSTRLIB_BSAFE_INCLUDE
|
||||
#define BSTRLIB_BSAFE_INCLUDE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(__GNUC__) && !defined(__clang__)
|
||||
#if !defined (__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310))
|
||||
/* This is caught in the linker, so its not necessary for gcc. */
|
||||
extern char * (gets) (char * buf);
|
||||
#endif
|
||||
|
||||
extern char * (strncpy) (char *dst, const char *src, size_t n);
|
||||
extern char * (strncat) (char *dst, const char *src, size_t n);
|
||||
extern char * (strtok) (char *s1, const char *s2);
|
||||
extern char * (strdup) (const char *s);
|
||||
|
||||
#undef strcpy
|
||||
#undef strcat
|
||||
#define strcpy(a,b) bsafe_strcpy(a,b)
|
||||
#define strcat(a,b) bsafe_strcat(a,b)
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,113 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the bstring string library. This code was
|
||||
* written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause
|
||||
* BSD open source license or GPL v2.0. Refer to the accompanying documentation
|
||||
* for details on usage and license.
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
|
||||
/*
|
||||
* bstraux.h
|
||||
*
|
||||
* This file is not a necessary part of the core bstring library itself, but
|
||||
* is just an auxilliary module which includes miscellaneous or trivial
|
||||
* functions.
|
||||
*/
|
||||
|
||||
#ifndef BSTRAUX_INCLUDE
|
||||
#define BSTRAUX_INCLUDE
|
||||
|
||||
#include <time.h>
|
||||
#include "bstrlib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Safety mechanisms */
|
||||
#define bstrDeclare(b) bstring (b) = NULL;
|
||||
#define bstrFree(b) {if ((b) != NULL && (b)->slen >= 0 && (b)->mlen >= (b)->slen) { bdestroy (b); (b) = NULL; }}
|
||||
|
||||
/* Backward compatibilty with previous versions of Bstrlib */
|
||||
#define bAssign(a,b) ((bassign)((a), (b)))
|
||||
#define bSubs(b,pos,len,a,c) ((breplace)((b),(pos),(len),(a),(unsigned char)(c)))
|
||||
#define bStrchr(b,c) ((bstrchr)((b), (c)))
|
||||
#define bStrchrFast(b,c) ((bstrchr)((b), (c)))
|
||||
#define bCatCstr(b,s) ((bcatcstr)((b), (s)))
|
||||
#define bCatBlk(b,s,len) ((bcatblk)((b),(s),(len)))
|
||||
#define bCatStatic(b,s) bCatBlk ((b), ("" s ""), sizeof (s) - 1)
|
||||
#define bTrunc(b,n) ((btrunc)((b), (n)))
|
||||
#define bReplaceAll(b,find,repl,pos) ((bfindreplace)((b),(find),(repl),(pos)))
|
||||
#define bUppercase(b) ((btoupper)(b))
|
||||
#define bLowercase(b) ((btolower)(b))
|
||||
#define bCaselessCmp(a,b) ((bstricmp)((a), (b)))
|
||||
#define bCaselessNCmp(a,b,n) ((bstrnicmp)((a), (b), (n)))
|
||||
#define bBase64Decode(b) (bBase64DecodeEx ((b), NULL))
|
||||
#define bUuDecode(b) (bUuDecodeEx ((b), NULL))
|
||||
|
||||
/* Unusual functions */
|
||||
extern struct bStream * bsFromBstr (const_bstring b);
|
||||
extern bstring bTail (bstring b, int n);
|
||||
extern bstring bHead (bstring b, int n);
|
||||
extern int bSetCstrChar (bstring a, int pos, char c);
|
||||
extern int bSetChar (bstring b, int pos, char c);
|
||||
extern int bFill (bstring a, char c, int len);
|
||||
extern int bReplicate (bstring b, int n);
|
||||
extern int bReverse (bstring b);
|
||||
extern int bInsertChrs (bstring b, int pos, int len, unsigned char c, unsigned char fill);
|
||||
extern bstring bStrfTime (const char * fmt, const struct tm * timeptr);
|
||||
#define bAscTime(t) (bStrfTime ("%c\n", (t)))
|
||||
#define bCTime(t) ((t) ? bAscTime (localtime (t)) : NULL)
|
||||
|
||||
/* Spacing formatting */
|
||||
extern int bJustifyLeft (bstring b, int space);
|
||||
extern int bJustifyRight (bstring b, int width, int space);
|
||||
extern int bJustifyMargin (bstring b, int width, int space);
|
||||
extern int bJustifyCenter (bstring b, int width, int space);
|
||||
|
||||
/* Esoteric standards specific functions */
|
||||
extern char * bStr2NetStr (const_bstring b);
|
||||
extern bstring bNetStr2Bstr (const char * buf);
|
||||
extern bstring bBase64Encode (const_bstring b);
|
||||
extern bstring bBase64DecodeEx (const_bstring b, int * boolTruncError);
|
||||
extern struct bStream * bsUuDecode (struct bStream * sInp, int * badlines);
|
||||
extern bstring bUuDecodeEx (const_bstring src, int * badlines);
|
||||
extern bstring bUuEncode (const_bstring src);
|
||||
extern bstring bYEncode (const_bstring src);
|
||||
extern bstring bYDecode (const_bstring src);
|
||||
|
||||
/* Writable stream */
|
||||
typedef int (* bNwrite) (const void * buf, size_t elsize, size_t nelem, void * parm);
|
||||
|
||||
struct bwriteStream * bwsOpen (bNwrite writeFn, void * parm);
|
||||
int bwsWriteBstr (struct bwriteStream * stream, const_bstring b);
|
||||
int bwsWriteBlk (struct bwriteStream * stream, void * blk, int len);
|
||||
int bwsWriteFlush (struct bwriteStream * stream);
|
||||
int bwsIsEOF (const struct bwriteStream * stream);
|
||||
int bwsBuffLength (struct bwriteStream * stream, int sz);
|
||||
void * bwsClose (struct bwriteStream * stream);
|
||||
|
||||
/* Security functions */
|
||||
#define bSecureDestroy(b) { \
|
||||
bstring bstr__tmp = (b); \
|
||||
if (bstr__tmp && bstr__tmp->mlen > 0 && bstr__tmp->data) { \
|
||||
(void) memset (bstr__tmp->data, 0, (size_t) bstr__tmp->mlen); \
|
||||
bdestroy (bstr__tmp); \
|
||||
} \
|
||||
}
|
||||
#define bSecureWriteProtect(t) { \
|
||||
if ((t).mlen >= 0) { \
|
||||
if ((t).mlen > (t).slen)) { \
|
||||
(void) memset ((t).data + (t).slen, 0, (size_t) (t).mlen - (t).slen); \
|
||||
} \
|
||||
(t).mlen = -1; \
|
||||
} \
|
||||
}
|
||||
extern bstring bSecureInput (int maxlen, int termchar,
|
||||
bNgetc vgetchar, void * vgcCtx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,305 +0,0 @@
|
||||
/*
|
||||
* This source file is part of the bstring string library. This code was
|
||||
* written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause
|
||||
* BSD open source license or GPL v2.0. Refer to the accompanying documentation
|
||||
* for details on usage and license.
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
|
||||
/*
|
||||
* bstrlib.h
|
||||
*
|
||||
* This file is the header file for the core module for implementing the
|
||||
* bstring functions.
|
||||
*/
|
||||
|
||||
#ifndef BSTRLIB_INCLUDE
|
||||
#define BSTRLIB_INCLUDE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if !defined (BSTRLIB_VSNP_OK) && !defined (BSTRLIB_NOVSNP)
|
||||
# if defined (__TURBOC__) && !defined (__BORLANDC__)
|
||||
# define BSTRLIB_NOVSNP
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BSTR_ERR (-1)
|
||||
#define BSTR_OK (0)
|
||||
#define BSTR_BS_BUFF_LENGTH_GET (0)
|
||||
|
||||
typedef struct tagbstring * bstring;
|
||||
typedef const struct tagbstring * const_bstring;
|
||||
|
||||
/* Copy functions */
|
||||
#define cstr2bstr bfromcstr
|
||||
extern bstring bfromcstr (const char * str);
|
||||
extern bstring bfromcstralloc (int mlen, const char * str);
|
||||
extern bstring blk2bstr (const void * blk, int len);
|
||||
extern char * bstr2cstr (const_bstring s, char z);
|
||||
extern int bcstrfree (char * s);
|
||||
extern bstring bstrcpy (const_bstring b1);
|
||||
extern int bassign (bstring a, const_bstring b);
|
||||
extern int bassignmidstr (bstring a, const_bstring b, int left, int len);
|
||||
extern int bassigncstr (bstring a, const char * str);
|
||||
extern int bassignblk (bstring a, const void * s, int len);
|
||||
|
||||
/* Destroy function */
|
||||
extern int bdestroy (bstring b);
|
||||
|
||||
/* Space allocation hinting functions */
|
||||
extern int balloc (bstring s, int len);
|
||||
extern int ballocmin (bstring b, int len);
|
||||
|
||||
/* Substring extraction */
|
||||
extern bstring bmidstr (const_bstring b, int left, int len);
|
||||
|
||||
/* Various standard manipulations */
|
||||
extern int bconcat (bstring b0, const_bstring b1);
|
||||
extern int bconchar (bstring b0, char c);
|
||||
extern int bcatcstr (bstring b, const char * s);
|
||||
extern int bcatblk (bstring b, const void * s, int len);
|
||||
extern int binsert (bstring s1, int pos, const_bstring s2, unsigned char fill);
|
||||
extern int binsertch (bstring s1, int pos, int len, unsigned char fill);
|
||||
extern int breplace (bstring b1, int pos, int len, const_bstring b2, unsigned char fill);
|
||||
extern int bdelete (bstring s1, int pos, int len);
|
||||
extern int bsetstr (bstring b0, int pos, const_bstring b1, unsigned char fill);
|
||||
extern int btrunc (bstring b, int n);
|
||||
|
||||
/* Scan/search functions */
|
||||
extern int bstricmp (const_bstring b0, const_bstring b1);
|
||||
extern int bstrnicmp (const_bstring b0, const_bstring b1, int n);
|
||||
extern int biseqcaseless (const_bstring b0, const_bstring b1);
|
||||
extern int bisstemeqcaselessblk (const_bstring b0, const void * blk, int len);
|
||||
extern int biseq (const_bstring b0, const_bstring b1);
|
||||
extern int bisstemeqblk (const_bstring b0, const void * blk, int len);
|
||||
extern int biseqcstr (const_bstring b, const char * s);
|
||||
extern int biseqcstrcaseless (const_bstring b, const char * s);
|
||||
extern int bstrcmp (const_bstring b0, const_bstring b1);
|
||||
extern int bstrncmp (const_bstring b0, const_bstring b1, int n);
|
||||
extern int binstr (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int binstrr (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int binstrcaseless (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int binstrrcaseless (const_bstring s1, int pos, const_bstring s2);
|
||||
extern int bstrchrp (const_bstring b, int c, int pos);
|
||||
extern int bstrrchrp (const_bstring b, int c, int pos);
|
||||
#define bstrchr(b,c) bstrchrp ((b), (c), 0)
|
||||
#define bstrrchr(b,c) bstrrchrp ((b), (c), blength(b)-1)
|
||||
extern int binchr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int binchrr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int bninchr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int bninchrr (const_bstring b0, int pos, const_bstring b1);
|
||||
extern int bfindreplace (bstring b, const_bstring find, const_bstring repl, int pos);
|
||||
extern int bfindreplacecaseless (bstring b, const_bstring find, const_bstring repl, int pos);
|
||||
|
||||
/* List of string container functions */
|
||||
struct bstrList {
|
||||
int qty, mlen;
|
||||
bstring * entry;
|
||||
};
|
||||
extern struct bstrList * bstrListCreate (void);
|
||||
extern int bstrListDestroy (struct bstrList * sl);
|
||||
extern int bstrListAlloc (struct bstrList * sl, int msz);
|
||||
extern int bstrListAllocMin (struct bstrList * sl, int msz);
|
||||
|
||||
/* String split and join functions */
|
||||
extern struct bstrList * bsplit (const_bstring str, unsigned char splitChar);
|
||||
extern struct bstrList * bsplits (const_bstring str, const_bstring splitStr);
|
||||
extern struct bstrList * bsplitstr (const_bstring str, const_bstring splitStr);
|
||||
extern bstring bjoin (const struct bstrList * bl, const_bstring sep);
|
||||
extern int bsplitcb (const_bstring str, unsigned char splitChar, int pos,
|
||||
int (* cb) (void * parm, int ofs, int len), void * parm);
|
||||
extern int bsplitscb (const_bstring str, const_bstring splitStr, int pos,
|
||||
int (* cb) (void * parm, int ofs, int len), void * parm);
|
||||
extern int bsplitstrcb (const_bstring str, const_bstring splitStr, int pos,
|
||||
int (* cb) (void * parm, int ofs, int len), void * parm);
|
||||
|
||||
/* Miscellaneous functions */
|
||||
extern int bpattern (bstring b, int len);
|
||||
extern int btoupper (bstring b);
|
||||
extern int btolower (bstring b);
|
||||
extern int bltrimws (bstring b);
|
||||
extern int brtrimws (bstring b);
|
||||
extern int btrimws (bstring b);
|
||||
|
||||
/* <*>printf format functions */
|
||||
#if !defined (BSTRLIB_NOVSNP)
|
||||
extern bstring bformat (const char * fmt, ...);
|
||||
extern int bformata (bstring b, const char * fmt, ...);
|
||||
extern int bassignformat (bstring b, const char * fmt, ...);
|
||||
extern int bvcformata (bstring b, int count, const char * fmt, va_list arglist);
|
||||
|
||||
#define bvformata(ret, b, fmt, lastarg) { \
|
||||
bstring bstrtmp_b = (b); \
|
||||
const char * bstrtmp_fmt = (fmt); \
|
||||
int bstrtmp_r = BSTR_ERR, bstrtmp_sz = 16; \
|
||||
for (;;) { \
|
||||
va_list bstrtmp_arglist; \
|
||||
va_start (bstrtmp_arglist, lastarg); \
|
||||
bstrtmp_r = bvcformata (bstrtmp_b, bstrtmp_sz, bstrtmp_fmt, bstrtmp_arglist); \
|
||||
va_end (bstrtmp_arglist); \
|
||||
if (bstrtmp_r >= 0) { /* Everything went ok */ \
|
||||
bstrtmp_r = BSTR_OK; \
|
||||
break; \
|
||||
} else if (-bstrtmp_r <= bstrtmp_sz) { /* A real error? */ \
|
||||
bstrtmp_r = BSTR_ERR; \
|
||||
break; \
|
||||
} \
|
||||
bstrtmp_sz = -bstrtmp_r; /* Doubled or target size */ \
|
||||
} \
|
||||
ret = bstrtmp_r; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef int (*bNgetc) (void *parm);
|
||||
typedef size_t (* bNread) (void *buff, size_t elsize, size_t nelem, void *parm);
|
||||
|
||||
/* Input functions */
|
||||
extern bstring bgets (bNgetc getcPtr, void * parm, char terminator);
|
||||
extern bstring bread (bNread readPtr, void * parm);
|
||||
extern int bgetsa (bstring b, bNgetc getcPtr, void * parm, char terminator);
|
||||
extern int bassigngets (bstring b, bNgetc getcPtr, void * parm, char terminator);
|
||||
extern int breada (bstring b, bNread readPtr, void * parm);
|
||||
|
||||
/* Stream functions */
|
||||
extern struct bStream * bsopen (bNread readPtr, void * parm);
|
||||
extern void * bsclose (struct bStream * s);
|
||||
extern int bsbufflength (struct bStream * s, int sz);
|
||||
extern int bsreadln (bstring b, struct bStream * s, char terminator);
|
||||
extern int bsreadlns (bstring r, struct bStream * s, const_bstring term);
|
||||
extern int bsread (bstring b, struct bStream * s, int n);
|
||||
extern int bsreadlna (bstring b, struct bStream * s, char terminator);
|
||||
extern int bsreadlnsa (bstring r, struct bStream * s, const_bstring term);
|
||||
extern int bsreada (bstring b, struct bStream * s, int n);
|
||||
extern int bsunread (struct bStream * s, const_bstring b);
|
||||
extern int bspeek (bstring r, const struct bStream * s);
|
||||
extern int bssplitscb (struct bStream * s, const_bstring splitStr,
|
||||
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
|
||||
extern int bssplitstrcb (struct bStream * s, const_bstring splitStr,
|
||||
int (* cb) (void * parm, int ofs, const_bstring entry), void * parm);
|
||||
extern int bseof (const struct bStream * s);
|
||||
|
||||
struct tagbstring {
|
||||
int mlen;
|
||||
int slen;
|
||||
unsigned char * data;
|
||||
};
|
||||
|
||||
/* Accessor macros */
|
||||
#define blengthe(b, e) (((b) == (void *)0 || (b)->slen < 0) ? (int)(e) : ((b)->slen))
|
||||
#define blength(b) (blengthe ((b), 0))
|
||||
#define bdataofse(b, o, e) (((b) == (void *)0 || (b)->data == (void*)0) ? (char *)(e) : ((char *)(b)->data) + (o))
|
||||
#define bdataofs(b, o) (bdataofse ((b), (o), (void *)0))
|
||||
#define bdatae(b, e) (bdataofse (b, 0, e))
|
||||
#define bdata(b) (bdataofs (b, 0))
|
||||
#define bchare(b, p, e) ((((unsigned)(p)) < (unsigned)blength(b)) ? ((b)->data[(p)]) : (e))
|
||||
#define bchar(b, p) bchare ((b), (p), '\0')
|
||||
|
||||
/* Static constant string initialization macro */
|
||||
#define bsStaticMlen(q,m) {(m), (int) sizeof(q)-1, (unsigned char *) ("" q "")}
|
||||
#if defined(_MSC_VER)
|
||||
/* There are many versions of MSVC which emit __LINE__ as a non-constant. */
|
||||
# define bsStatic(q) bsStaticMlen(q,-32)
|
||||
#endif
|
||||
#ifndef bsStatic
|
||||
# define bsStatic(q) bsStaticMlen(q,-__LINE__)
|
||||
#endif
|
||||
|
||||
/* Static constant block parameter pair */
|
||||
#define bsStaticBlkParms(q) ((void *)("" q "")), ((int) sizeof(q)-1)
|
||||
|
||||
/* Reference building macros */
|
||||
#define cstr2tbstr btfromcstr
|
||||
#define btfromcstr(t,s) { \
|
||||
(t).data = (unsigned char *) (s); \
|
||||
(t).slen = ((t).data) ? ((int) (strlen) ((char *)(t).data)) : 0; \
|
||||
(t).mlen = -1; \
|
||||
}
|
||||
#define blk2tbstr(t,s,l) { \
|
||||
(t).data = (unsigned char *) (s); \
|
||||
(t).slen = l; \
|
||||
(t).mlen = -1; \
|
||||
}
|
||||
#define btfromblk(t,s,l) blk2tbstr(t,s,l)
|
||||
#define bmid2tbstr(t,b,p,l) { \
|
||||
const_bstring bstrtmp_s = (b); \
|
||||
if (bstrtmp_s && bstrtmp_s->data && bstrtmp_s->slen >= 0) { \
|
||||
int bstrtmp_left = (p); \
|
||||
int bstrtmp_len = (l); \
|
||||
if (bstrtmp_left < 0) { \
|
||||
bstrtmp_len += bstrtmp_left; \
|
||||
bstrtmp_left = 0; \
|
||||
} \
|
||||
if (bstrtmp_len > bstrtmp_s->slen - bstrtmp_left) \
|
||||
bstrtmp_len = bstrtmp_s->slen - bstrtmp_left; \
|
||||
if (bstrtmp_len <= 0) { \
|
||||
(t).data = (unsigned char *)""; \
|
||||
(t).slen = 0; \
|
||||
} else { \
|
||||
(t).data = bstrtmp_s->data + bstrtmp_left; \
|
||||
(t).slen = bstrtmp_len; \
|
||||
} \
|
||||
} else { \
|
||||
(t).data = (unsigned char *)""; \
|
||||
(t).slen = 0; \
|
||||
} \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
#define btfromblkltrimws(t,s,l) { \
|
||||
int bstrtmp_idx = 0, bstrtmp_len = (l); \
|
||||
unsigned char * bstrtmp_s = (s); \
|
||||
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
||||
for (; bstrtmp_idx < bstrtmp_len; bstrtmp_idx++) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
|
||||
} \
|
||||
} \
|
||||
(t).data = bstrtmp_s + bstrtmp_idx; \
|
||||
(t).slen = bstrtmp_len - bstrtmp_idx; \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
#define btfromblkrtrimws(t,s,l) { \
|
||||
int bstrtmp_len = (l) - 1; \
|
||||
unsigned char * bstrtmp_s = (s); \
|
||||
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
||||
for (; bstrtmp_len >= 0; bstrtmp_len--) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
|
||||
} \
|
||||
} \
|
||||
(t).data = bstrtmp_s; \
|
||||
(t).slen = bstrtmp_len + 1; \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
#define btfromblktrimws(t,s,l) { \
|
||||
int bstrtmp_idx = 0, bstrtmp_len = (l) - 1; \
|
||||
unsigned char * bstrtmp_s = (s); \
|
||||
if (bstrtmp_s && bstrtmp_len >= 0) { \
|
||||
for (; bstrtmp_idx <= bstrtmp_len; bstrtmp_idx++) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_idx])) break; \
|
||||
} \
|
||||
for (; bstrtmp_len >= bstrtmp_idx; bstrtmp_len--) { \
|
||||
if (!isspace (bstrtmp_s[bstrtmp_len])) break; \
|
||||
} \
|
||||
} \
|
||||
(t).data = bstrtmp_s + bstrtmp_idx; \
|
||||
(t).slen = bstrtmp_len + 1 - bstrtmp_idx; \
|
||||
(t).mlen = -__LINE__; \
|
||||
}
|
||||
|
||||
/* Write protection macros */
|
||||
#define bwriteprotect(t) { if ((t).mlen >= 0) (t).mlen = -1; }
|
||||
#define bwriteallow(t) { if ((t).mlen == -1) (t).mlen = (t).slen + ((t).slen == 0); }
|
||||
#define biswriteprotected(t) ((t).mlen <= 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,29 +0,0 @@
|
||||
Copyright (c) 2002-2008 Paul Hsieh
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
Neither the name of bstrlib nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
@ -1,172 +0,0 @@
|
||||
Better String library Porting Guide
|
||||
-----------------------------------
|
||||
|
||||
by Paul Hsieh
|
||||
|
||||
The bstring library is an attempt to provide improved string processing
|
||||
functionality to the C and C++ language. At the heart of the bstring library
|
||||
is the management of "bstring"s which are a significant improvement over '\0'
|
||||
terminated char buffers. See the accompanying documenation file bstrlib.txt
|
||||
for more information.
|
||||
|
||||
===============================================================================
|
||||
|
||||
Identifying the Compiler
|
||||
------------------------
|
||||
|
||||
Bstrlib has been tested on the following compilers:
|
||||
|
||||
Microsoft Visual C++
|
||||
Watcom C/C++ (32 bit flat)
|
||||
Intel's C/C++ compiler (on Windows)
|
||||
The GNU C/C++ compiler (on Windows/Linux on x86 and PPC64)
|
||||
Borland C++
|
||||
Turbo C
|
||||
|
||||
There are slight differences in these compilers which requires slight
|
||||
differences in the implementation of Bstrlib. These are accomodated in the
|
||||
same sources using #ifdef/#if defined() on compiler specific macros. To
|
||||
port Bstrlib to a new compiler not listed above, it is recommended that the
|
||||
same strategy be followed. If you are unaware of the compiler specific
|
||||
identifying preprocessor macro for your compiler you might find it here:
|
||||
|
||||
http://predef.sourceforge.net/precomp.html
|
||||
|
||||
Note that Intel C/C++ on Windows sets the Microsoft identifier: _MSC_VER.
|
||||
|
||||
16-bit vs. 32-bit vs. 64-bit Systems
|
||||
------------------------------------
|
||||
|
||||
Bstrlib has been architected to deal with strings of length between 0 and
|
||||
INT_MAX (inclusive). Since the values of int are never higher than size_t
|
||||
there will be no issue here. Note that on most 64-bit systems int is 32-bit.
|
||||
|
||||
Dependency on The C-Library
|
||||
---------------------------
|
||||
|
||||
Bstrlib uses the functions memcpy, memmove, malloc, realloc, free and
|
||||
vsnprintf. Many free standing C compiler implementations that have a mode in
|
||||
which the C library is not available will typically not include these
|
||||
functions which will make porting Bstrlib to it onerous. Bstrlib is not
|
||||
designed for such bare bones compiler environments. This usually includes
|
||||
compilers that target ROM environments.
|
||||
|
||||
Porting Issues
|
||||
--------------
|
||||
|
||||
Bstrlib has been written completely in ANSI/ISO C and ISO C++, however, there
|
||||
are still a few porting issues. These are described below.
|
||||
|
||||
1. The vsnprintf () function.
|
||||
|
||||
Unfortunately, the earlier ANSI/ISO C standards did not include this function.
|
||||
If the compiler of interest does not support this function then the
|
||||
BSTRLIB_NOVSNP should be defined via something like:
|
||||
|
||||
#if !defined (BSTRLIB_VSNP_OK) && !defined (BSTRLIB_NOVSNP)
|
||||
# if defined (__TURBOC__) || defined (__COMPILERVENDORSPECIFICMACRO__)
|
||||
# define BSTRLIB_NOVSNP
|
||||
# endif
|
||||
#endif
|
||||
|
||||
which appears at the top of bstrlib.h. Note that the bformat(a) functions
|
||||
will not be declared or implemented if the BSTRLIB_NOVSNP macro is set. If
|
||||
the compiler has renamed vsnprintf() to some other named function, then
|
||||
search for the definition of the exvsnprintf macro in bstrlib.c file and be
|
||||
sure its defined appropriately:
|
||||
|
||||
#if defined (__COMPILERVENDORSPECIFICMACRO__)
|
||||
# define exvsnprintf(r,b,n,f,a) {r=__compiler_specific_vsnprintf(b,n,f,a);}
|
||||
#else
|
||||
# define exvsnprintf(r,b,n,f,a) {r=vsnprintf(b,n,f,a);}
|
||||
#endif
|
||||
|
||||
Take notice of the return value being captured in the variable r. It is
|
||||
assumed that r exceeds n if and only if the underlying vsnprintf function has
|
||||
determined what the true maximal output length would be for output if the
|
||||
buffer were large enough to hold it. Non-modern implementations must output a
|
||||
lesser number (the macro can and should be modified to ensure this).
|
||||
|
||||
2. Weak C++ compiler.
|
||||
|
||||
C++ is a much more complicated language to implement than C. This has lead
|
||||
to varying quality of compiler implementations. The weaknesses isolated in
|
||||
the initial ports are inclusion of the Standard Template Library,
|
||||
std::iostream and exception handling. By default it is assumed that the C++
|
||||
compiler supports all of these things correctly. If your compiler does not
|
||||
support one or more of these define the corresponding macro:
|
||||
|
||||
BSTRLIB_CANNOT_USE_STL
|
||||
BSTRLIB_CANNOT_USE_IOSTREAM
|
||||
BSTRLIB_DOESNT_THROW_EXCEPTIONS
|
||||
|
||||
The compiler specific detected macro should be defined at the top of
|
||||
bstrwrap.h in the Configuration defines section. Note that these disabling
|
||||
macros can be overrided with the associated enabling macro if a subsequent
|
||||
version of the compiler gains support. (For example, its possible to rig
|
||||
up STLport to provide STL support for WATCOM C/C++, so -DBSTRLIB_CAN_USE_STL
|
||||
can be passed in as a compiler option.)
|
||||
|
||||
3. The bsafe module, and reserved words.
|
||||
|
||||
The bsafe module is in gross violation of the ANSI/ISO C standard in the
|
||||
sense that it redefines what could be implemented as reserved words on a
|
||||
given compiler. The typical problem is that a compiler may inline some of the
|
||||
functions and thus not be properly overridden by the definitions in the bsafe
|
||||
module. It is also possible that a compiler may prohibit the redefinitions in
|
||||
the bsafe module. Compiler specific action will be required to deal with
|
||||
these situations.
|
||||
|
||||
Platform Specific Files
|
||||
-----------------------
|
||||
|
||||
The makefiles for the examples are basically setup of for particular
|
||||
environments for each platform. In general these makefiles are not portable
|
||||
and should be constructed as necessary from scratch for each platform.
|
||||
|
||||
Testing a port
|
||||
--------------
|
||||
|
||||
To test that a port compiles correctly do the following:
|
||||
|
||||
1. Build a sample project that includes the bstrlib, bstraux, bstrwrap, and
|
||||
bsafe modules.
|
||||
2. Compile bstest against the bstrlib module.
|
||||
3. Run bstest and ensure that 0 errors are reported.
|
||||
4. Compile test against the bstrlib and bstrwrap modules.
|
||||
5. Run test and ensure that 0 errors are reported.
|
||||
6. Compile each of the examples (except for the "re" example, which may be
|
||||
complicated and is not a real test of bstrlib and except for the mfcbench
|
||||
example which is Windows specific.)
|
||||
7. Run each of the examples.
|
||||
|
||||
The builds must have 0 errors, and should have the absolute minimum number of
|
||||
warnings (in most cases can be reduced to 0.) The result of execution should
|
||||
be essentially identical on each platform.
|
||||
|
||||
Performance
|
||||
-----------
|
||||
|
||||
Different CPU and compilers have different capabilities in terms of
|
||||
performance. It is possible for Bstrlib to assume performance
|
||||
characteristics that a platform doesn't have (since it was primarily
|
||||
developed on just one platform). The goal of Bstrlib is to provide very good
|
||||
performance on all platforms regardless of this but without resorting to
|
||||
extreme measures (such as using assembly language, or non-portable intrinsics
|
||||
or library extensions.)
|
||||
|
||||
There are two performance benchmarks that can be found in the example/
|
||||
directory. They are: cbench.c and cppbench.cpp. These are variations and
|
||||
expansions of a benchmark for another string library. They don't cover all
|
||||
string functionality, but do include the most basic functions which will be
|
||||
common in most string manipulation kernels.
|
||||
|
||||
...............................................................................
|
||||
|
||||
Feedback
|
||||
--------
|
||||
|
||||
In all cases, you may email issues found to the primary author of Bstrlib at
|
||||
the email address: websnarf@users.sourceforge.net
|
||||
|
||||
===============================================================================
|
||||
@ -1,221 +0,0 @@
|
||||
Better String library Security Statement
|
||||
----------------------------------------
|
||||
|
||||
by Paul Hsieh
|
||||
|
||||
===============================================================================
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
The Better String library (hereafter referred to as Bstrlib) is an attempt to
|
||||
provide improved string processing functionality to the C and C++ languages.
|
||||
At the heart of the Bstrlib is the management of "bstring"s which are a
|
||||
significant improvement over '\0' terminated char buffers. See the
|
||||
accompanying documenation file bstrlib.txt for more information.
|
||||
|
||||
DISCLAIMER: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
|
||||
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Like any software, there is always a possibility of failure due to a flawed
|
||||
implementation. Nevertheless a good faith effort has been made to minimize
|
||||
such flaws in Bstrlib. Also, use of Bstrlib by itself will not make an
|
||||
application secure or free from implementation failures. However, it is the
|
||||
author's conviction that use of Bstrlib can greatly facilitate the creation
|
||||
of software meeting the highest possible standards of security.
|
||||
|
||||
Part of the reason why this document has been created, is for the purpose of
|
||||
security auditing, or the creation of further "Statements on Security" for
|
||||
software that is created that uses Bstrlib. An auditor may check the claims
|
||||
below against Bstrlib, and use this as a basis for analysis of software which
|
||||
uses Bstrlib.
|
||||
|
||||
===============================================================================
|
||||
|
||||
Statement on Security
|
||||
---------------------
|
||||
|
||||
This is a document intended to give consumers of the Better String Library
|
||||
who are interested in security an idea of where the Better String Library
|
||||
stands on various security issues. Any deviation observed in the actual
|
||||
library itself from the descriptions below should be considered an
|
||||
implementation error, not a design flaw.
|
||||
|
||||
This statement is not an analytical proof of correctness or an outline of one
|
||||
but rather an assertion similar to a scientific claim or hypothesis. By use,
|
||||
testing and open independent examination (otherwise known as scientific
|
||||
falsifiability), the credibility of the claims made below can rise to the
|
||||
level of an established theory.
|
||||
|
||||
Common security issues:
|
||||
.......................
|
||||
|
||||
1. Buffer Overflows
|
||||
|
||||
The Bstrlib API allows the programmer a way to deal with strings without
|
||||
having to deal with the buffers containing them. Ordinary usage of the
|
||||
Bstrlib API itself makes buffer overflows impossible.
|
||||
|
||||
Furthermore, the Bstrlib API has a superset of basic string functionality as
|
||||
compared to the C library's char * functions, C++'s std::string class and
|
||||
Microsoft's MFC based CString class. It also has abstracted mechanisms for
|
||||
dealing with IO. This is important as it gives developers a way of migrating
|
||||
all their code from a functionality point of view.
|
||||
|
||||
2. Memory size overflow/wrap around attack
|
||||
|
||||
Bstrlib is, by design, impervious to memory size overflow attacks. The
|
||||
reason is it is resiliant to length overflows is that bstring lengths are
|
||||
bounded above by INT_MAX, instead of ~(size_t)0. So length addition
|
||||
overflows cause a wrap around of the integer value making them negative
|
||||
causing balloc() to fail before an erroneous operation can occurr. Attempted
|
||||
conversions of char * strings which may have lengths greater than INT_MAX are
|
||||
detected and the conversion is aborted.
|
||||
|
||||
It is unknown if this property holds on machines that don't represent
|
||||
integers as 2s complement. It is recommended that Bstrlib be carefully
|
||||
auditted by anyone using a system which is not 2s complement based.
|
||||
|
||||
3. Constant string protection
|
||||
|
||||
Bstrlib implements runtime enforced constant and read-only string semantics.
|
||||
I.e., bstrings which are declared as constant via the bsStatic() macro cannot
|
||||
be modified or deallocated directly through the Bstrlib API, and this cannot
|
||||
be subverted by casting or other type coercion. This is independent of the
|
||||
use of the const_bstring data type.
|
||||
|
||||
The Bstrlib C API uses the type const_bstring to specify bstring parameters
|
||||
whose contents do not change. Although the C language cannot enforce this,
|
||||
this is nevertheless guaranteed by the implementation of the Bstrlib library
|
||||
of C functions. The C++ API enforces the const attribute on CBString types
|
||||
correctly.
|
||||
|
||||
4. Aliased bstring support
|
||||
|
||||
Bstrlib detects and supports aliased parameter management throughout the API.
|
||||
The kind of aliasing that is allowed is the one where pointers of the same
|
||||
basic type may be pointing to overlapping objects (this is the assumption the
|
||||
ANSI C99 specification makes.) Each function behaves as if all read-only
|
||||
parameters were copied to temporaries which are used in their stead before
|
||||
the function is enacted (it rarely actually does this). No function in the
|
||||
Bstrlib uses the "restrict" parameter attribute from the ANSI C99
|
||||
specification.
|
||||
|
||||
5. Information leaking
|
||||
|
||||
In bstraux.h, using the semantically equivalent macros bSecureDestroy() and
|
||||
bSecureWriteProtect() in place of bdestroy() and bwriteprotect() respectively
|
||||
will ensure that stale data does not linger in the heap's free space after
|
||||
strings have been released back to memory. Created bstrings or CBStrings
|
||||
are not linked to anything external to themselves, and thus cannot expose
|
||||
deterministic data leaking. If a bstring is resized, the preimage may exist
|
||||
as a copy that is released to the heap. Thus for sensitive data, the bstring
|
||||
should be sufficiently presized before manipulated so that it is not resized.
|
||||
bSecureInput() has been supplied in bstraux.c, which can be used to obtain
|
||||
input securely without any risk of leaving any part of the input image in the
|
||||
heap except for the allocated bstring that is returned.
|
||||
|
||||
6. Memory leaking
|
||||
|
||||
Bstrlib can be built using memdbg.h enabled via the BSTRLIB_MEMORY_DEBUG
|
||||
macro. User generated definitions for malloc, realloc and free can then be
|
||||
supplied which can implement special strategies for memory corruption
|
||||
detection or memory leaking. Otherwise, bstrlib does not do anything out of
|
||||
the ordinary to attempt to deal with the standard problem of memory leaking
|
||||
(i.e., losing references to allocated memory) when programming in the C and
|
||||
C++ languages. However, it does not compound the problem any more than exists
|
||||
either, as it doesn't have any intrinsic inescapable leaks in it. Bstrlib
|
||||
does not preclude the use of automatic garbage collection mechanisms such as
|
||||
the Boehm garbage collector.
|
||||
|
||||
7. Encryption
|
||||
|
||||
Bstrlib does not present any built-in encryption mechanism. However, it
|
||||
supports full binary contents in its data buffers, so any standard block
|
||||
based encryption mechanism can make direct use of bstrings/CBStrings for
|
||||
buffer management.
|
||||
|
||||
8. Double freeing
|
||||
|
||||
Freeing a pointer that is already free is an extremely rare, but nevertheless
|
||||
a potentially ruthlessly corrupting operation (its possible to cause Win 98 to
|
||||
reboot, by calling free mulitiple times on already freed data using the WATCOM
|
||||
CRT.) Bstrlib invalidates the bstring header data before freeing, so that in
|
||||
many cases a double free will be detected and an error will be reported
|
||||
(though this behaviour is not guaranteed and should not be relied on).
|
||||
|
||||
Using bstrFree pervasively (instead of bdestroy) can lead to somewhat
|
||||
improved invalid free avoidance (it is completely safe whenever bstring
|
||||
instances are only stored in unique variables). For example:
|
||||
|
||||
struct tagbstring hw = bsStatic ("Hello, world");
|
||||
bstring cpHw = bstrcpy (&hw);
|
||||
|
||||
#ifdef NOT_QUITE_AS_SAFE
|
||||
bdestroy (cpHw); /* Never fail */
|
||||
bdestroy (cpHw); /* Error sometimes detected at runtime */
|
||||
bdestroy (&hw); /* Error detected at run time */
|
||||
#else
|
||||
bstrFree (cpHw); /* Never fail */
|
||||
bstrFree (cpHw); /* Will do nothing */
|
||||
bstrFree (&hw); /* Will lead to a compile time error */
|
||||
#endif
|
||||
|
||||
9. Resource based denial of service
|
||||
|
||||
bSecureInput() has been supplied in bstraux.c. It has an optional upper limit
|
||||
for input length. But unlike fgets(), it is also easily determined if the
|
||||
buffer has been truncated early. In this way, a program can set an upper limit
|
||||
on input sizes while still allowing for implementing context specific
|
||||
truncation semantics (i.e., does the program consume but dump the extra
|
||||
input, or does it consume it in later inputs?)
|
||||
|
||||
10. Mixing char *'s and bstrings
|
||||
|
||||
The bstring and char * representations are not identical. So there is a risk
|
||||
when converting back and forth that data may lost. Essentially bstrings can
|
||||
contain '\0' as a valid non-terminating character, while char * strings
|
||||
cannot and in fact must use the character as a terminator. The risk of data
|
||||
loss is very low, since:
|
||||
|
||||
A) the simple method of only using bstrings in a char * semantically
|
||||
compatible way is both easy to achieve and pervasively supported.
|
||||
B) obtaining '\0' content in a string is either deliberate or indicative
|
||||
of another, likely more serious problem in the code.
|
||||
C) the library comes with various functions which deal with this issue
|
||||
(namely: bfromcstr(), bstr2cstr (), and bSetCstrChar ())
|
||||
|
||||
Marginal security issues:
|
||||
.........................
|
||||
|
||||
11. 8-bit versus 9-bit portability
|
||||
|
||||
Bstrlib uses CHAR_BIT and other limits.h constants to the maximum extent
|
||||
possible to avoid portability problems. However, Bstrlib has not been tested
|
||||
on any system that does not represent char as 8-bits. So whether or not it
|
||||
works on 9-bit systems is an open question. It is recommended that Bstrlib be
|
||||
carefully auditted by anyone using a system in which CHAR_BIT is not 8.
|
||||
|
||||
12. EBCDIC/ASCII/UTF-8 data representation attacks.
|
||||
|
||||
Bstrlib uses ctype.h functions to ensure that it remains portable to non-
|
||||
ASCII systems. It also checks range to make sure it is well defined even for
|
||||
data that ANSI does not define for the ctype functions.
|
||||
|
||||
Obscure issues:
|
||||
...............
|
||||
|
||||
13. Data attributes
|
||||
|
||||
There is no support for a Perl-like "taint" attribute, however, an example of
|
||||
how to do this using C++'s type system is given as an example.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,167 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
#include "internal_includes/hlslccToolkit.h"
|
||||
#include "internal_includes/debug.h"
|
||||
#include "internal_includes/languages.h"
|
||||
|
||||
bool DoAssignmentDataTypesMatch(SHADER_VARIABLE_TYPE dest, SHADER_VARIABLE_TYPE src)
|
||||
{
|
||||
if (src == dest)
|
||||
return true;
|
||||
|
||||
if ((dest == SVT_FLOAT || dest == SVT_FLOAT10 || dest == SVT_FLOAT16) &&
|
||||
(src == SVT_FLOAT || src == SVT_FLOAT10 || src == SVT_FLOAT16))
|
||||
return true;
|
||||
|
||||
if ((dest == SVT_INT || dest == SVT_INT12 || dest == SVT_INT16) &&
|
||||
(src == SVT_INT || src == SVT_INT12 || src == SVT_INT16))
|
||||
return true;
|
||||
|
||||
if ((dest == SVT_UINT || dest == SVT_UINT16) &&
|
||||
(src == SVT_UINT || src == SVT_UINT16))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * GetConstructorForTypeGLSL(HLSLCrossCompilerContext* psContext, const SHADER_VARIABLE_TYPE eType, const int components, bool useGLSLPrecision)
|
||||
{
|
||||
const bool usePrecision = useGLSLPrecision && HavePrecisionQualifers(psContext->psShader->eTargetLanguage);
|
||||
|
||||
static const char * const uintTypes[] = { " ", "uint", "uvec2", "uvec3", "uvec4" };
|
||||
static const char * const uint16Types[] = { " ", "mediump uint", "mediump uvec2", "mediump uvec3", "mediump uvec4" };
|
||||
static const char * const intTypes[] = { " ", "int", "ivec2", "ivec3", "ivec4" };
|
||||
static const char * const int16Types[] = { " ", "mediump int", "mediump ivec2", "mediump ivec3", "mediump ivec4" };
|
||||
static const char * const int12Types[] = { " ", "lowp int", "lowp ivec2", "lowp ivec3", "lowp ivec4" };
|
||||
static const char * const floatTypes[] = { " ", "float", "vec2", "vec3", "vec4" };
|
||||
static const char * const float16Types[] = { " ", "mediump float", "mediump vec2", "mediump vec3", "mediump vec4" };
|
||||
static const char * const float10Types[] = { " ", "lowp float", "lowp vec2", "lowp vec3", "lowp vec4" };
|
||||
static const char * const boolTypes[] = { " ", "bool", "bvec2", "bvec3", "bvec4" };
|
||||
|
||||
ASSERT(components >= 1 && components <= 4);
|
||||
|
||||
switch (eType)
|
||||
{
|
||||
case SVT_UINT:
|
||||
return uintTypes[components];
|
||||
case SVT_UINT16:
|
||||
return usePrecision ? uint16Types[components] : uintTypes[components];
|
||||
case SVT_INT:
|
||||
return intTypes[components];
|
||||
case SVT_INT16:
|
||||
return usePrecision ? int16Types[components] : intTypes[components];
|
||||
case SVT_INT12:
|
||||
return usePrecision ? int12Types[components] : intTypes[components];
|
||||
case SVT_FLOAT:
|
||||
return floatTypes[components];
|
||||
case SVT_FLOAT16:
|
||||
return usePrecision ? float16Types[components] : floatTypes[components];
|
||||
case SVT_FLOAT10:
|
||||
return usePrecision ? float10Types[components] : floatTypes[components];
|
||||
case SVT_BOOL:
|
||||
return boolTypes[components];
|
||||
default:
|
||||
ASSERT(0);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
SHADER_VARIABLE_TYPE TypeFlagsToSVTType(const uint32_t typeflags)
|
||||
{
|
||||
if (typeflags & TO_FLAG_INTEGER)
|
||||
return SVT_INT;
|
||||
if (typeflags & TO_FLAG_UNSIGNED_INTEGER)
|
||||
return SVT_UINT;
|
||||
return SVT_FLOAT;
|
||||
}
|
||||
|
||||
uint32_t SVTTypeToFlag(const SHADER_VARIABLE_TYPE eType)
|
||||
{
|
||||
if (eType == SVT_FLOAT16 || eType == SVT_FLOAT10 || eType == SVT_FLOAT)
|
||||
{
|
||||
return TO_FLAG_FLOAT;
|
||||
}
|
||||
if (eType == SVT_UINT || eType == SVT_UINT16)
|
||||
{
|
||||
return TO_FLAG_UNSIGNED_INTEGER;
|
||||
}
|
||||
else if (eType == SVT_INT || eType == SVT_INT16 || eType == SVT_INT12)
|
||||
{
|
||||
return TO_FLAG_INTEGER;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TO_FLAG_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
bool CanDoDirectCast(SHADER_VARIABLE_TYPE src, SHADER_VARIABLE_TYPE dest)
|
||||
{
|
||||
// uint<->int<->bool conversions possible
|
||||
if ((src == SVT_INT || src == SVT_UINT || src == SVT_BOOL || src == SVT_INT12 || src == SVT_INT16 || src == SVT_UINT16) &&
|
||||
(dest == SVT_INT || dest == SVT_UINT || dest == SVT_BOOL || dest == SVT_INT12 || dest == SVT_INT16 || dest == SVT_UINT16))
|
||||
return true;
|
||||
|
||||
// float<->double possible
|
||||
if ((src == SVT_FLOAT || src == SVT_DOUBLE || src == SVT_FLOAT16 || src == SVT_FLOAT10) &&
|
||||
(dest == SVT_FLOAT || dest == SVT_DOUBLE || dest == SVT_FLOAT16 || dest == SVT_FLOAT10))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* GetBitcastOp(SHADER_VARIABLE_TYPE from, SHADER_VARIABLE_TYPE to)
|
||||
{
|
||||
static const char* intToFloat = "intBitsToFloat";
|
||||
static const char* uintToFloat = "uintBitsToFloat";
|
||||
static const char* floatToInt = "floatBitsToInt";
|
||||
static const char* floatToUint = "floatBitsToUint";
|
||||
|
||||
if ((to == SVT_FLOAT || to == SVT_FLOAT16 || to == SVT_FLOAT10) && from == SVT_INT)
|
||||
return intToFloat;
|
||||
else if ((to == SVT_FLOAT || to == SVT_FLOAT16 || to == SVT_FLOAT10) && from == SVT_UINT)
|
||||
return uintToFloat;
|
||||
else if (to == SVT_INT && (from == SVT_FLOAT || from == SVT_FLOAT16 || from == SVT_FLOAT10))
|
||||
return floatToInt;
|
||||
else if (to == SVT_UINT && (from == SVT_FLOAT || from == SVT_FLOAT16 || from == SVT_FLOAT10))
|
||||
return floatToUint;
|
||||
|
||||
ASSERT(0);
|
||||
return "";
|
||||
}
|
||||
|
||||
bool IsGmemReservedSlot(FRAMEBUFFER_FETCH_TYPE typeMask, const uint32_t regNumber)
|
||||
{
|
||||
if (((typeMask & FBF_ARM_COLOR) && regNumber == GMEM_ARM_COLOR_SLOT) ||
|
||||
((typeMask & FBF_ARM_DEPTH) && regNumber == GMEM_ARM_DEPTH_SLOT) ||
|
||||
((typeMask & FBF_ARM_STENCIL) && regNumber == GMEM_ARM_STENCIL_SLOT) ||
|
||||
((typeMask & FBF_EXT_COLOR) && regNumber >= GMEM_FLOAT_START_SLOT))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * GetAuxArgumentName(const SHADER_VARIABLE_TYPE varType)
|
||||
{
|
||||
switch (varType)
|
||||
{
|
||||
case SVT_UINT:
|
||||
case SVT_UINT8:
|
||||
case SVT_UINT16:
|
||||
return "uArg";
|
||||
case SVT_INT:
|
||||
case SVT_INT16:
|
||||
case SVT_INT12:
|
||||
return "iArg";
|
||||
case SVT_FLOAT:
|
||||
case SVT_FLOAT16:
|
||||
case SVT_FLOAT10:
|
||||
return "fArg";
|
||||
case SVT_BOOL:
|
||||
return "bArg";
|
||||
default:
|
||||
ASSERT(0);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef DEBUG_H_
|
||||
#define DEBUG_H_
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include "assert.h"
|
||||
#define ASSERT(expr) CustomAssert(expr)
|
||||
static void CustomAssert(int expression)
|
||||
{
|
||||
if(!expression)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define ASSERT(expr)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -1,21 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef DECODE_H
|
||||
#define DECODE_H
|
||||
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
Shader* DecodeDXBC(uint32_t* data);
|
||||
|
||||
//You don't need to call this directly because DecodeDXBC
|
||||
//will call DecodeDX9BC if the shader looks
|
||||
//like it is SM1/2/3.
|
||||
Shader* DecodeDX9BC(const uint32_t* pui32Tokens);
|
||||
|
||||
void UpdateDeclarationReferences(Shader* psShader, Declaration* psDeclaration);
|
||||
void UpdateInstructionReferences(Shader* psShader, Instruction* psInstruction);
|
||||
|
||||
#define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24))
|
||||
|
||||
#endif
|
||||
@ -1,35 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
#ifndef HLSLCC_TOOLKIT_DECLARATION_H
|
||||
#define HLSLCC_TOOLKIT_DECLARATION_H
|
||||
|
||||
#include "hlslcc.h"
|
||||
#include "bstrlib.h"
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
// Check if "src" type can be assigned directly to the "dest" type.
|
||||
bool DoAssignmentDataTypesMatch(SHADER_VARIABLE_TYPE dest, SHADER_VARIABLE_TYPE src);
|
||||
|
||||
// Returns the constructor needed depending on the type, the number of components and the use of precision qualifier.
|
||||
const char * GetConstructorForTypeGLSL(HLSLCrossCompilerContext* psContext, const SHADER_VARIABLE_TYPE eType, const int components, bool useGLSLPrecision);
|
||||
|
||||
// Transform from a variable type to a shader variable flag.
|
||||
uint32_t SVTTypeToFlag(const SHADER_VARIABLE_TYPE eType);
|
||||
|
||||
// Transform from a shader variable flag to a shader variable type.
|
||||
SHADER_VARIABLE_TYPE TypeFlagsToSVTType(const uint32_t typeflags);
|
||||
|
||||
// Check if the "src" type can be casted using a constructor to the "dest" type (without bitcasting).
|
||||
bool CanDoDirectCast(SHADER_VARIABLE_TYPE src, SHADER_VARIABLE_TYPE dest);
|
||||
|
||||
// Returns the bitcast operation needed to assign the "src" type to the "dest" type
|
||||
const char* GetBitcastOp(SHADER_VARIABLE_TYPE src, SHADER_VARIABLE_TYPE dest);
|
||||
|
||||
// Check if the register number is part of the ones we used for signaling GMEM input
|
||||
bool IsGmemReservedSlot(FRAMEBUFFER_FETCH_TYPE type, const uint32_t regNumber);
|
||||
|
||||
// Return the name of an auxiliary variable used to save intermediate values to bypass driver issues
|
||||
const char * GetAuxArgumentName(const SHADER_VARIABLE_TYPE varType);
|
||||
|
||||
#endif
|
||||
@ -1,16 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <AzCore/PlatformDef.h>
|
||||
|
||||
AZ_PUSH_DISABLE_WARNING(4232, "-Wunknown-warning-option") // address of malloc/free/calloc/realloc are not static
|
||||
void* (*hlslcc_malloc)(size_t size) = malloc;
|
||||
void* (*hlslcc_calloc)(size_t num,size_t size) = calloc;
|
||||
void (*hlslcc_free)(void *p) = free;
|
||||
void* (*hlslcc_realloc)(void *p,size_t size) = realloc;
|
||||
AZ_POP_DISABLE_WARNING
|
||||
@ -1,15 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef __HLSCC_MALLOC_H
|
||||
#define __HLSCC_MALLOC_H
|
||||
|
||||
extern void* (*hlslcc_malloc)(size_t size);
|
||||
extern void* (* hlslcc_calloc)(size_t num, size_t size);
|
||||
extern void (* hlslcc_free)(void* p);
|
||||
extern void* (* hlslcc_realloc)(void* p, size_t size);
|
||||
|
||||
#define bstr__alloc hlslcc_malloc
|
||||
#define bstr__free hlslcc_free
|
||||
#define bstr__realloc hlslcc_realloc
|
||||
#endif
|
||||
@ -1,242 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef LANGUAGES_H
|
||||
#define LANGUAGES_H
|
||||
|
||||
#include "hlslcc.h"
|
||||
|
||||
static int InOutSupported(const GLLang eLang)
|
||||
{
|
||||
if(eLang == LANG_ES_100 || eLang == LANG_120)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int WriteToFragData(const GLLang eLang)
|
||||
{
|
||||
if(eLang == LANG_ES_100 || eLang == LANG_120)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ShaderBitEncodingSupported(const GLLang eLang)
|
||||
{
|
||||
if( eLang != LANG_ES_300 &&
|
||||
eLang != LANG_ES_310 &&
|
||||
eLang < LANG_330)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int HaveOverloadedTextureFuncs(const GLLang eLang)
|
||||
{
|
||||
if(eLang == LANG_ES_100 || eLang == LANG_120)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Only enable for ES.
|
||||
//Not present in 120, ignored in other desktop languages.
|
||||
static int HavePrecisionQualifers(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_ES_100 && eLang <= LANG_ES_310)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Only on vertex inputs and pixel outputs.
|
||||
static int HaveLimitedInOutLocationQualifier(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_330 || eLang == LANG_ES_300 || eLang == LANG_ES_310)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveInOutLocationQualifier(const GLLang eLang,const struct GlExtensions *extensions)
|
||||
{
|
||||
if(eLang >= LANG_410 || eLang == LANG_ES_310 || (extensions && ((GlExtensions*)extensions)->ARB_explicit_attrib_location))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//layout(binding = X) uniform {uniformA; uniformB;}
|
||||
//layout(location = X) uniform uniform_name;
|
||||
static int HaveUniformBindingsAndLocations(const GLLang eLang,const struct GlExtensions *extensions)
|
||||
{
|
||||
if(eLang >= LANG_430 || eLang == LANG_ES_310 || (extensions && ((GlExtensions*)extensions)->ARB_explicit_uniform_location))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DualSourceBlendSupported(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_330)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SubroutinesSupported(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_400)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Before 430, flat/smooth/centroid/noperspective must match
|
||||
//between fragment and its previous stage.
|
||||
//HLSL bytecode only tells us the interpolation in pixel shader.
|
||||
static int PixelInterpDependency(const GLLang eLang)
|
||||
{
|
||||
if(eLang < LANG_430)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveUVec(const GLLang eLang)
|
||||
{
|
||||
switch(eLang)
|
||||
{
|
||||
case LANG_ES_100:
|
||||
case LANG_120:
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int HaveGather(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_400 || eLang == LANG_ES_310)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveGatherNonConstOffset(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_420 || eLang == LANG_ES_310)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int HaveQueryLod(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_400)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveQueryLevels(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_430)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int HaveAtomicCounter(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_420 || eLang == LANG_ES_310)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveAtomicMem(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_430)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveCompute(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_430 || eLang == LANG_ES_310)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveImageLoadStore(const GLLang eLang)
|
||||
{
|
||||
if(eLang >= LANG_420 || eLang == LANG_ES_310)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int EmulateDepthClamp(const GLLang eLang)
|
||||
{
|
||||
if (eLang >= LANG_ES_300 && eLang < LANG_120) //Requires gl_FragDepth available in fragment shader
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HaveNoperspectiveInterpolation(const GLLang eLang)
|
||||
{
|
||||
if (eLang >= LANG_330)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int EarlyDepthTestSupported(const GLLang eLang)
|
||||
{
|
||||
if ((eLang > LANG_410) || (eLang == LANG_ES_310))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int StorageBlockBindingSupported(const GLLang eLang)
|
||||
{
|
||||
if (eLang >= LANG_430)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@ -1,42 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef REFLECT_H
|
||||
#define REFLECT_H
|
||||
|
||||
#include "hlslcc.h"
|
||||
|
||||
ResourceGroup ResourceTypeToResourceGroup(ResourceType);
|
||||
|
||||
int GetResourceFromBindingPoint(const ResourceGroup eGroup, const uint32_t ui32BindPoint, const ShaderInfo* psShaderInfo, ResourceBinding** ppsOutBinding);
|
||||
|
||||
void GetConstantBufferFromBindingPoint(const ResourceGroup eGroup, const uint32_t ui32BindPoint, const ShaderInfo* psShaderInfo, ConstantBuffer** ppsConstBuf);
|
||||
|
||||
int GetInterfaceVarFromOffset(uint32_t ui32Offset, ShaderInfo* psShaderInfo, ShaderVar** ppsShaderVar);
|
||||
|
||||
int GetInputSignatureFromRegister(const uint32_t ui32Register, const ShaderInfo* psShaderInfo, InOutSignature** ppsOut);
|
||||
int GetOutputSignatureFromRegister(const uint32_t ui32Register, const uint32_t ui32Stream, const uint32_t ui32CompMask, ShaderInfo* psShaderInfo, InOutSignature** ppsOut);
|
||||
|
||||
int GetOutputSignatureFromSystemValue(SPECIAL_NAME eSystemValueType, uint32_t ui32SemanticIndex, ShaderInfo* psShaderInfo, InOutSignature** ppsOut);
|
||||
|
||||
int GetShaderVarFromOffset(const uint32_t ui32Vec4Offset, const uint32_t* pui32Swizzle, ConstantBuffer* psCBuf, ShaderVarType** ppsShaderVar, int32_t* pi32Index, int32_t* pi32Rebase);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t* pui32Inputs;
|
||||
uint32_t* pui32Outputs;
|
||||
uint32_t* pui32Resources;
|
||||
uint32_t* pui32Interfaces;
|
||||
uint32_t* pui32Inputs11;
|
||||
uint32_t* pui32Outputs11;
|
||||
uint32_t* pui32OutputsWithStreams;
|
||||
} ReflectionChunks;
|
||||
|
||||
void LoadShaderInfo(const uint32_t ui32MajorVersion, const uint32_t ui32MinorVersion, const ReflectionChunks* psChunks, ShaderInfo* psInfo);
|
||||
|
||||
void LoadD3D9ConstantTable(const char* data, ShaderInfo* psInfo);
|
||||
|
||||
void FreeShaderInfo(ShaderInfo* psShaderInfo);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef HLSLCC_SHADER_LIMITS_H
|
||||
#define HLSLCC_SHADER_LIMITS_H
|
||||
|
||||
static enum
|
||||
{
|
||||
MAX_SHADER_VEC4_OUTPUT = 512
|
||||
};
|
||||
static enum
|
||||
{
|
||||
MAX_SHADER_VEC4_INPUT = 512
|
||||
};
|
||||
static enum
|
||||
{
|
||||
MAX_TEXTURES = 128
|
||||
};
|
||||
static enum
|
||||
{
|
||||
MAX_FORK_PHASES = 2
|
||||
};
|
||||
static enum
|
||||
{
|
||||
MAX_FUNCTION_BODIES = 1024
|
||||
};
|
||||
static enum
|
||||
{
|
||||
MAX_CLASS_TYPES = 1024
|
||||
};
|
||||
static enum
|
||||
{
|
||||
MAX_FUNCTION_POINTERS = 128
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,374 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef STRUCTS_H
|
||||
#define STRUCTS_H
|
||||
|
||||
#include "hlslcc.h"
|
||||
#include "bstrlib.h"
|
||||
|
||||
#include "internal_includes/tokens.h"
|
||||
#include "internal_includes/reflect.h"
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_SUB_OPERANDS = 3
|
||||
};
|
||||
|
||||
typedef struct Operand_TAG
|
||||
{
|
||||
int iExtended;
|
||||
OPERAND_TYPE eType;
|
||||
OPERAND_MODIFIER eModifier;
|
||||
OPERAND_MIN_PRECISION eMinPrecision;
|
||||
int iIndexDims;
|
||||
int indexRepresentation[4];
|
||||
int writeMask;
|
||||
int iGSInput;
|
||||
int iWriteMaskEnabled;
|
||||
|
||||
int iNumComponents;
|
||||
|
||||
OPERAND_4_COMPONENT_SELECTION_MODE eSelMode;
|
||||
uint32_t ui32CompMask;
|
||||
uint32_t ui32Swizzle;
|
||||
uint32_t aui32Swizzle[4];
|
||||
|
||||
uint32_t aui32ArraySizes[3];
|
||||
uint32_t ui32RegisterNumber;
|
||||
//If eType is OPERAND_TYPE_IMMEDIATE32
|
||||
float afImmediates[4];
|
||||
//If eType is OPERAND_TYPE_IMMEDIATE64
|
||||
double adImmediates[4];
|
||||
|
||||
int iIntegerImmediate;
|
||||
|
||||
SPECIAL_NAME eSpecialName;
|
||||
char pszSpecialName[64];
|
||||
|
||||
OPERAND_INDEX_REPRESENTATION eIndexRep[3];
|
||||
|
||||
struct Operand_TAG* psSubOperand[MAX_SUB_OPERANDS];
|
||||
|
||||
//One type for each component.
|
||||
SHADER_VARIABLE_TYPE aeDataType[4];
|
||||
|
||||
#ifdef _DEBUG
|
||||
uint64_t id;
|
||||
#endif
|
||||
} Operand;
|
||||
|
||||
typedef struct Instruction_TAG
|
||||
{
|
||||
OPCODE_TYPE eOpcode;
|
||||
INSTRUCTION_TEST_BOOLEAN eBooleanTestType;
|
||||
COMPARISON_DX9 eDX9TestType;
|
||||
uint32_t ui32SyncFlags;
|
||||
uint32_t ui32NumOperands;
|
||||
uint32_t ui32FirstSrc;
|
||||
Operand asOperands[6];
|
||||
uint32_t bSaturate;
|
||||
uint32_t ui32FuncIndexWithinInterface;
|
||||
RESINFO_RETURN_TYPE eResInfoReturnType;
|
||||
|
||||
int bAddressOffset;
|
||||
int iUAddrOffset;
|
||||
int iVAddrOffset;
|
||||
int iWAddrOffset;
|
||||
RESOURCE_RETURN_TYPE xType, yType, zType, wType;
|
||||
RESOURCE_DIMENSION eResDim;
|
||||
|
||||
#ifdef _DEBUG
|
||||
uint64_t id;
|
||||
#endif
|
||||
} Instruction;
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_IMMEDIATE_CONST_BUFFER_VEC4_SIZE = 1024
|
||||
};
|
||||
|
||||
typedef struct ICBVec4_TAG
|
||||
{
|
||||
uint32_t a;
|
||||
uint32_t b;
|
||||
uint32_t c;
|
||||
uint32_t d;
|
||||
} ICBVec4;
|
||||
|
||||
typedef struct Declaration_TAG
|
||||
{
|
||||
OPCODE_TYPE eOpcode;
|
||||
|
||||
uint32_t ui32NumOperands;
|
||||
|
||||
Operand asOperands[2];
|
||||
|
||||
ICBVec4 asImmediateConstBuffer[MAX_IMMEDIATE_CONST_BUFFER_VEC4_SIZE];
|
||||
//The declaration can set one of these
|
||||
//values depending on the opcode.
|
||||
union
|
||||
{
|
||||
uint32_t ui32GlobalFlags;
|
||||
uint32_t ui32NumTemps;
|
||||
RESOURCE_DIMENSION eResourceDimension;
|
||||
CONSTANT_BUFFER_ACCESS_PATTERN eCBAccessPattern;
|
||||
INTERPOLATION_MODE eInterpolation;
|
||||
PRIMITIVE_TOPOLOGY eOutputPrimitiveTopology;
|
||||
PRIMITIVE eInputPrimitive;
|
||||
uint32_t ui32MaxOutputVertexCount;
|
||||
TESSELLATOR_DOMAIN eTessDomain;
|
||||
TESSELLATOR_PARTITIONING eTessPartitioning;
|
||||
TESSELLATOR_OUTPUT_PRIMITIVE eTessOutPrim;
|
||||
uint32_t aui32WorkGroupSize[3];
|
||||
//Fork phase index followed by the instance count.
|
||||
uint32_t aui32HullPhaseInstanceInfo[2];
|
||||
float fMaxTessFactor;
|
||||
uint32_t ui32IndexRange;
|
||||
uint32_t ui32GSInstanceCount;
|
||||
|
||||
struct Interface_TAG
|
||||
{
|
||||
uint32_t ui32InterfaceID;
|
||||
uint32_t ui32NumFuncTables;
|
||||
uint32_t ui32ArraySize;
|
||||
} interface;
|
||||
} value;
|
||||
|
||||
struct UAV_TAG
|
||||
{
|
||||
uint32_t ui32GloballyCoherentAccess;
|
||||
uint32_t ui32BufferSize;
|
||||
uint8_t bCounter;
|
||||
RESOURCE_RETURN_TYPE Type;
|
||||
} sUAV;
|
||||
|
||||
struct TGSM_TAG
|
||||
{
|
||||
uint32_t ui32Stride;
|
||||
uint32_t ui32Count;
|
||||
} sTGSM;
|
||||
|
||||
struct IndexableTemp_TAG
|
||||
{
|
||||
uint32_t ui32RegIndex;
|
||||
uint32_t ui32RegCount;
|
||||
uint32_t ui32RegComponentSize;
|
||||
} sIdxTemp;
|
||||
|
||||
uint32_t ui32TableLength;
|
||||
|
||||
uint32_t ui32TexReturnType;
|
||||
} Declaration;
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_TEMP_VEC4 = 512
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_GROUPSHARED = 8
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_DX9_IMMCONST = 256
|
||||
};
|
||||
|
||||
typedef struct Shader_TAG
|
||||
{
|
||||
uint32_t ui32MajorVersion;
|
||||
uint32_t ui32MinorVersion;
|
||||
SHADER_TYPE eShaderType;
|
||||
|
||||
GLLang eTargetLanguage;
|
||||
const struct GlExtensions *extensions;
|
||||
|
||||
int fp64;
|
||||
|
||||
//DWORDs in program code, including version and length tokens.
|
||||
uint32_t ui32ShaderLength;
|
||||
|
||||
uint32_t ui32DeclCount;
|
||||
Declaration* psDecl;
|
||||
|
||||
//Instruction* functions;//non-main subroutines
|
||||
|
||||
uint32_t aui32FuncTableToFuncPointer[MAX_FUNCTION_TABLES];//FIXME dynamic alloc
|
||||
uint32_t aui32FuncBodyToFuncTable[MAX_FUNCTION_BODIES];
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t aui32FuncBodies[MAX_FUNCTION_BODIES];
|
||||
}funcTable[MAX_FUNCTION_TABLES];
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t aui32FuncTables[MAX_FUNCTION_TABLES];
|
||||
uint32_t ui32NumBodiesPerTable;
|
||||
}funcPointer[MAX_FUNCTION_POINTERS];
|
||||
|
||||
uint32_t ui32NextClassFuncName[MAX_CLASS_TYPES];
|
||||
|
||||
uint32_t ui32InstCount;
|
||||
Instruction* psInst;
|
||||
|
||||
const uint32_t* pui32FirstToken;//Reference for calculating current position in token stream.
|
||||
|
||||
//Hull shader declarations and instructions.
|
||||
//psDecl, psInst are null for hull shaders.
|
||||
uint32_t ui32HSDeclCount;
|
||||
Declaration* psHSDecl;
|
||||
|
||||
uint32_t ui32HSControlPointDeclCount;
|
||||
Declaration* psHSControlPointPhaseDecl;
|
||||
|
||||
uint32_t ui32HSControlPointInstrCount;
|
||||
Instruction* psHSControlPointPhaseInstr;
|
||||
|
||||
uint32_t ui32ForkPhaseCount;
|
||||
|
||||
uint32_t aui32HSForkDeclCount[MAX_FORK_PHASES];
|
||||
Declaration* apsHSForkPhaseDecl[MAX_FORK_PHASES];
|
||||
|
||||
uint32_t aui32HSForkInstrCount[MAX_FORK_PHASES];
|
||||
Instruction* apsHSForkPhaseInstr[MAX_FORK_PHASES];
|
||||
|
||||
uint32_t ui32HSJoinDeclCount;
|
||||
Declaration* psHSJoinPhaseDecl;
|
||||
|
||||
uint32_t ui32HSJoinInstrCount;
|
||||
Instruction* psHSJoinPhaseInstr;
|
||||
|
||||
ShaderInfo sInfo;
|
||||
|
||||
int abScalarInput[MAX_SHADER_VEC4_INPUT];
|
||||
|
||||
int aIndexedOutput[MAX_SHADER_VEC4_OUTPUT];
|
||||
|
||||
int aIndexedInput[MAX_SHADER_VEC4_INPUT];
|
||||
int aIndexedInputParents[MAX_SHADER_VEC4_INPUT];
|
||||
|
||||
RESOURCE_DIMENSION aeResourceDims[MAX_TEXTURES];
|
||||
|
||||
int aiInputDeclaredSize[MAX_SHADER_VEC4_INPUT];
|
||||
|
||||
int aiOutputDeclared[MAX_SHADER_VEC4_OUTPUT];
|
||||
|
||||
//Does not track built-in inputs.
|
||||
int abInputReferencedByInstruction[MAX_SHADER_VEC4_INPUT];
|
||||
|
||||
int aiOpcodeUsed[NUM_OPCODES];
|
||||
|
||||
uint32_t ui32CurrentVertexOutputStream;
|
||||
|
||||
uint32_t ui32NumDx9ImmConst;
|
||||
uint32_t aui32Dx9ImmConstArrayRemap[MAX_DX9_IMMCONST];
|
||||
|
||||
ShaderVarType sGroupSharedVarType[MAX_GROUPSHARED];
|
||||
|
||||
SHADER_VARIABLE_TYPE aeCommonTempVecType[MAX_TEMP_VEC4];
|
||||
uint32_t bUseTempCopy;
|
||||
FRAMEBUFFER_FETCH_TYPE eGmemType;
|
||||
} Shader;
|
||||
|
||||
/* CONFETTI NOTE: DAVID SROUR
|
||||
* The following is super sketchy, but at the moment,
|
||||
* there is no way to figure out the type of a resource
|
||||
* since HLSL has only register sets for the following:
|
||||
* bool, int4, float4, sampler.
|
||||
* THIS CODE IS DUPLICATED FROM HLSLcc METAL.
|
||||
* IF ANYTHING CHANGES, BOTH TRANSLATORS SHOULD HAVE THE CHANGE.
|
||||
* TODO: CONSOLIDATE THE 2 HLSLcc PROJECTS.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
GMEM_FLOAT4_START_SLOT = 120
|
||||
};
|
||||
enum
|
||||
{
|
||||
GMEM_FLOAT3_START_SLOT = 112
|
||||
};
|
||||
enum
|
||||
{
|
||||
GMEM_FLOAT2_START_SLOT = 104
|
||||
};
|
||||
enum
|
||||
{
|
||||
GMEM_FLOAT_START_SLOT = 96
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
GMEM_ARM_COLOR_SLOT = 93,
|
||||
GMEM_ARM_DEPTH_SLOT = 94,
|
||||
GMEM_ARM_STENCIL_SLOT = 95
|
||||
};
|
||||
|
||||
/* CONFETTI NOTE: DAVID SROUR
|
||||
* Following is the reserved slot for PLS extension (https://www.khronos.org/registry/gles/extensions/EXT/EXT_shader_pixel_local_storage.txt).
|
||||
* It will get picked up when a RWStructuredBuffer resource is defined at the following reserved slot.
|
||||
* Note that only one PLS struct can be present at a time otherwise the behavior is undefined.
|
||||
*
|
||||
* Types in the struct and their output conversion (each output variable will always be 4 bytes):
|
||||
* float2 -> rg16f
|
||||
* float3 -> r11f_g11f_b10f
|
||||
* float4 -> rgba8
|
||||
* uint -> r32ui
|
||||
* int2 -> rg16i
|
||||
* int4 -> rgba8i
|
||||
*/
|
||||
enum
|
||||
{
|
||||
GMEM_PLS_RO_SLOT = 60
|
||||
}; // READ-ONLY
|
||||
enum
|
||||
{
|
||||
GMEM_PLS_WO_SLOT = 61
|
||||
}; // WRITE-ONLY
|
||||
enum
|
||||
{
|
||||
GMEM_PLS_RW_SLOT = 62
|
||||
}; // READ/WRITE
|
||||
|
||||
static const uint32_t MAIN_PHASE = 0;
|
||||
static const uint32_t HS_FORK_PHASE = 1;
|
||||
static const uint32_t HS_CTRL_POINT_PHASE = 2;
|
||||
static const uint32_t HS_JOIN_PHASE = 3;
|
||||
enum
|
||||
{
|
||||
NUM_PHASES = 4
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_COLOR_MRT = 8
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
INPUT_RENDERTARGET = 1 << 0,
|
||||
OUTPUT_RENDERTARGET = 1 << 1
|
||||
};
|
||||
|
||||
typedef struct HLSLCrossCompilerContext_TAG
|
||||
{
|
||||
bstring glsl;
|
||||
bstring earlyMain;//Code to be inserted at the start of main()
|
||||
bstring postShaderCode[NUM_PHASES];//End of main or before emit()
|
||||
bstring debugHeader;
|
||||
|
||||
bstring* currentGLSLString;//either glsl or earlyMain
|
||||
|
||||
int havePostShaderCode[NUM_PHASES];
|
||||
uint32_t currentPhase;
|
||||
|
||||
uint32_t rendertargetUse[MAX_COLOR_MRT];
|
||||
|
||||
int indent;
|
||||
unsigned int flags;
|
||||
Shader* psShader;
|
||||
} HLSLCrossCompilerContext;
|
||||
|
||||
#endif
|
||||
@ -1,19 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TO_GLSL_DECLARATION_H
|
||||
#define TO_GLSL_DECLARATION_H
|
||||
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
void TranslateDeclaration(HLSLCrossCompilerContext* psContext, const Declaration* psDecl);
|
||||
|
||||
char* GetDeclaredInputName(const HLSLCrossCompilerContext* psContext, const SHADER_TYPE eShaderType, const Operand* psOperand);
|
||||
char* GetDeclaredOutputName(const HLSLCrossCompilerContext* psContext, const SHADER_TYPE eShaderType, const Operand* psOperand, int* stream);
|
||||
|
||||
//Hull shaders have multiple phases.
|
||||
//Each phase has its own temps.
|
||||
//Convert to global temps for GLSL.
|
||||
void ConsolidateHullTempVars(Shader* psShader);
|
||||
|
||||
#endif
|
||||
@ -1,18 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TO_GLSL_INSTRUCTION_H
|
||||
#define TO_GLSL_INSTRUCTION_H
|
||||
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
void TranslateInstruction(HLSLCrossCompilerContext* psContext, Instruction* psInst);
|
||||
|
||||
//For each MOV temp, immediate; check to see if the next instruction
|
||||
//using that temp has an integer opcode. If so then the immediate value
|
||||
//is flaged as having an integer encoding.
|
||||
void MarkIntegerImmediates(HLSLCrossCompilerContext* psContext);
|
||||
|
||||
void SetDataTypes(HLSLCrossCompilerContext* psContext, Instruction* psInst, const int32_t i32InstCount, SHADER_VARIABLE_TYPE* aeCommonTempVecType);
|
||||
|
||||
#endif
|
||||
@ -1,46 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TO_GLSL_OPERAND_H
|
||||
#define TO_GLSL_OPERAND_H
|
||||
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
void TranslateOperand(HLSLCrossCompilerContext* psContext, const Operand* psOperand, uint32_t ui32TOFlag);
|
||||
|
||||
int GetMaxComponentFromComponentMask(const Operand* psOperand);
|
||||
void TranslateOperandIndex(HLSLCrossCompilerContext* psContext, const Operand* psOperand, int index);
|
||||
void TranslateOperandIndexMAD(HLSLCrossCompilerContext* psContext, const Operand* psOperand, int index, uint32_t multiply, uint32_t add);
|
||||
void TranslateVariableName(HLSLCrossCompilerContext* psContext, const Operand* psOperand, uint32_t ui32TOFlag, uint32_t* pui32IgnoreSwizzle);
|
||||
void TranslateOperandSwizzle(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
|
||||
|
||||
uint32_t GetNumSwizzleElements(const Operand* psOperand);
|
||||
void AddSwizzleUsingElementCount(HLSLCrossCompilerContext* psContext, uint32_t count);
|
||||
int GetFirstOperandSwizzle(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
|
||||
uint32_t IsSwizzleReplacated(const Operand* psOperand);
|
||||
|
||||
void TextureName(bstring output, Shader* psShader, const uint32_t ui32TextureRegister, const uint32_t ui32SamplerRegister, const int bCompare);
|
||||
void UAVName(bstring output, Shader* psShader, const uint32_t ui32RegisterNumber);
|
||||
void UniformBufferName(bstring output, Shader* psShader, const uint32_t ui32RegisterNumber);
|
||||
|
||||
void ConvertToTextureName(bstring output, Shader* psShader, const char* szName, const char* szSamplerName, const int bCompare);
|
||||
void ConvertToUAVName(bstring output, Shader* psShader, const char* szOriginalUAVName);
|
||||
void ConvertToUniformBufferName(bstring output, Shader* psShader, const char* szConstantBufferName);
|
||||
|
||||
void ShaderVarName(bstring output, Shader* psShader, const char* OriginalName);
|
||||
void ShaderVarFullName(bstring output, Shader* psShader, const ShaderVarType* psShaderVar);
|
||||
|
||||
uint32_t ConvertOperandSwizzleToComponentMask(const Operand* psOperand);
|
||||
//Non-zero means the components overlap
|
||||
int CompareOperandSwizzles(const Operand* psOperandA, const Operand* psOperandB);
|
||||
|
||||
SHADER_VARIABLE_TYPE GetOperandDataType(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
|
||||
|
||||
|
||||
// NOTE: CODE DUPLICATION FROM HLSLcc METAL ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void TranslateGmemOperandSwizzleWithMask(HLSLCrossCompilerContext* psContext, const Operand* psOperand, uint32_t ui32ComponentMask, uint32_t gmemNumElements);
|
||||
uint32_t GetGmemInputResourceSlot(uint32_t const slotIn);
|
||||
uint32_t GetGmemInputResourceNumElements(uint32_t const slotIn);
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
@ -1,16 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TO_METAL_DECLARATION_H
|
||||
#define TO_METAL_DECLARATION_H
|
||||
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
void TranslateDeclarationMETAL(HLSLCrossCompilerContext* psContext, const Declaration* psDecl);
|
||||
|
||||
char* GetDeclaredInputNameMETAL(const HLSLCrossCompilerContext* psContext, const SHADER_TYPE eShaderType, const Operand* psOperand);
|
||||
char* GetDeclaredOutputNameMETAL(const HLSLCrossCompilerContext* psContext, const SHADER_TYPE eShaderType, const Operand* psOperand);
|
||||
|
||||
const char* GetMangleSuffixMETAL(const SHADER_TYPE eShaderType);
|
||||
|
||||
#endif
|
||||
@ -1,18 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TO_METAL_INSTRUCTION_H
|
||||
#define TO_METAL_INSTRUCTION_H
|
||||
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
void TranslateInstructionMETAL(HLSLCrossCompilerContext* psContext, Instruction* psInst);
|
||||
|
||||
//For each MOV temp, immediate; check to see if the next instruction
|
||||
//using that temp has an integer opcode. If so then the immediate value
|
||||
//is flaged as having an integer encoding.
|
||||
void MarkIntegerImmediatesMETAL(HLSLCrossCompilerContext* psContext);
|
||||
|
||||
void SetDataTypesMETAL(HLSLCrossCompilerContext* psContext, Instruction* psInst, const int32_t i32InstCount, SHADER_VARIABLE_TYPE* aeCommonTempVecType);
|
||||
|
||||
#endif
|
||||
@ -1,38 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TO_METAL_OPERAND_H
|
||||
#define TO_METAL_OPERAND_H
|
||||
|
||||
#include "internal_includes/structs.h"
|
||||
|
||||
#define TO_FLAG_NONE 0x0
|
||||
#define TO_FLAG_INTEGER 0x1
|
||||
#define TO_FLAG_NAME_ONLY 0x2
|
||||
#define TO_FLAG_DECLARATION_NAME 0x4
|
||||
#define TO_FLAG_DESTINATION 0x8 //Operand is being written to by assignment.
|
||||
#define TO_FLAG_UNSIGNED_INTEGER 0x10
|
||||
#define TO_FLAG_DOUBLE 0x20
|
||||
#define TO_FLAG_FLOAT 0x40
|
||||
|
||||
void TranslateOperandMETAL(HLSLCrossCompilerContext* psContext, const Operand* psOperand, uint32_t ui32TOFlag);
|
||||
|
||||
int GetMaxComponentFromComponentMaskMETAL(const Operand* psOperand);
|
||||
void TranslateOperandMETALIndex(HLSLCrossCompilerContext* psContext, const Operand* psOperand, int index);
|
||||
void TranslateOperandMETALIndexMAD(HLSLCrossCompilerContext* psContext, const Operand* psOperand, int index, uint32_t multiply, uint32_t add);
|
||||
void TranslateVariableNameMETAL(HLSLCrossCompilerContext* psContext, const Operand* psOperand, uint32_t ui32TOFlag, uint32_t* pui32IgnoreSwizzle);
|
||||
void TranslateOperandMETALSwizzle(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
|
||||
uint32_t GetNumSwizzleElementsMETAL(const Operand* psOperand);
|
||||
void AddSwizzleUsingElementCountMETAL(HLSLCrossCompilerContext* psContext, uint32_t count);
|
||||
int GetFirstOperandSwizzleMETAL(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
|
||||
uint32_t IsSwizzleReplacatedMETAL(const Operand* psOperand);
|
||||
|
||||
void TextureNameMETAL(HLSLCrossCompilerContext* psContext, const uint32_t ui32RegisterNumber, const int bZCompare);
|
||||
|
||||
uint32_t ConvertOperandSwizzleToComponentMaskMETAL(const Operand* psOperand);
|
||||
//Non-zero means the components overlap
|
||||
int CompareOperandSwizzlesMETAL(const Operand* psOperandA, const Operand* psOperandB);
|
||||
|
||||
SHADER_VARIABLE_TYPE GetOperandDataTypeMETAL(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
|
||||
|
||||
#endif
|
||||
@ -1,812 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef TOKENS_H
|
||||
#define TOKENS_H
|
||||
|
||||
#include "hlslcc.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INVALID_SHADER = -1,
|
||||
PIXEL_SHADER,
|
||||
VERTEX_SHADER,
|
||||
GEOMETRY_SHADER,
|
||||
HULL_SHADER,
|
||||
DOMAIN_SHADER,
|
||||
COMPUTE_SHADER,
|
||||
} SHADER_TYPE;
|
||||
|
||||
static SHADER_TYPE DecodeShaderType(uint32_t ui32Token)
|
||||
{
|
||||
return (SHADER_TYPE)((ui32Token & 0xffff0000) >> 16);
|
||||
}
|
||||
|
||||
static uint32_t DecodeProgramMajorVersion(uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x000000f0) >> 4;
|
||||
}
|
||||
|
||||
static uint32_t DecodeProgramMinorVersion(uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x0000000f);
|
||||
}
|
||||
|
||||
static uint32_t DecodeInstructionLength(uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x7f000000) >> 24;
|
||||
}
|
||||
|
||||
static uint32_t DecodeIsOpcodeExtended(uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x80000000) >> 31;
|
||||
}
|
||||
|
||||
typedef enum EXTENDED_OPCODE_TYPE
|
||||
{
|
||||
EXTENDED_OPCODE_EMPTY = 0,
|
||||
EXTENDED_OPCODE_SAMPLE_CONTROLS = 1,
|
||||
EXTENDED_OPCODE_RESOURCE_DIM = 2,
|
||||
EXTENDED_OPCODE_RESOURCE_RETURN_TYPE = 3,
|
||||
} EXTENDED_OPCODE_TYPE;
|
||||
|
||||
static EXTENDED_OPCODE_TYPE DecodeExtendedOpcodeType(uint32_t ui32Token)
|
||||
{
|
||||
return (EXTENDED_OPCODE_TYPE)(ui32Token & 0x0000003f);
|
||||
}
|
||||
|
||||
typedef enum RESOURCE_RETURN_TYPE
|
||||
{
|
||||
RETURN_TYPE_UNORM = 1,
|
||||
RETURN_TYPE_SNORM = 2,
|
||||
RETURN_TYPE_SINT = 3,
|
||||
RETURN_TYPE_UINT = 4,
|
||||
RETURN_TYPE_FLOAT = 5,
|
||||
RETURN_TYPE_MIXED = 6,
|
||||
RETURN_TYPE_DOUBLE = 7,
|
||||
RETURN_TYPE_CONTINUED = 8,
|
||||
RETURN_TYPE_UNUSED = 9,
|
||||
} RESOURCE_RETURN_TYPE;
|
||||
|
||||
static RESOURCE_RETURN_TYPE DecodeResourceReturnType(uint32_t ui32Coord, uint32_t ui32Token)
|
||||
{
|
||||
return (RESOURCE_RETURN_TYPE)((ui32Token>>(ui32Coord * 4))&0xF);
|
||||
}
|
||||
|
||||
static RESOURCE_RETURN_TYPE DecodeExtendedResourceReturnType(uint32_t ui32Coord, uint32_t ui32Token)
|
||||
{
|
||||
return (RESOURCE_RETURN_TYPE)((ui32Token>>(ui32Coord * 4 + 6))&0xF);
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
//For DX9
|
||||
OPCODE_POW = -6,
|
||||
OPCODE_DP2ADD = -5,
|
||||
OPCODE_LRP = -4,
|
||||
OPCODE_ENDREP = -3,
|
||||
OPCODE_REP = -2,
|
||||
OPCODE_SPECIAL_DCL_IMMCONST = -1,
|
||||
|
||||
OPCODE_ADD,
|
||||
OPCODE_AND,
|
||||
OPCODE_BREAK,
|
||||
OPCODE_BREAKC,
|
||||
OPCODE_CALL,
|
||||
OPCODE_CALLC,
|
||||
OPCODE_CASE,
|
||||
OPCODE_CONTINUE,
|
||||
OPCODE_CONTINUEC,
|
||||
OPCODE_CUT,
|
||||
OPCODE_DEFAULT,
|
||||
OPCODE_DERIV_RTX,
|
||||
OPCODE_DERIV_RTY,
|
||||
OPCODE_DISCARD,
|
||||
OPCODE_DIV,
|
||||
OPCODE_DP2,
|
||||
OPCODE_DP3,
|
||||
OPCODE_DP4,
|
||||
OPCODE_ELSE,
|
||||
OPCODE_EMIT,
|
||||
OPCODE_EMITTHENCUT,
|
||||
OPCODE_ENDIF,
|
||||
OPCODE_ENDLOOP,
|
||||
OPCODE_ENDSWITCH,
|
||||
OPCODE_EQ,
|
||||
OPCODE_EXP,
|
||||
OPCODE_FRC,
|
||||
OPCODE_FTOI,
|
||||
OPCODE_FTOU,
|
||||
OPCODE_GE,
|
||||
OPCODE_IADD,
|
||||
OPCODE_IF,
|
||||
OPCODE_IEQ,
|
||||
OPCODE_IGE,
|
||||
OPCODE_ILT,
|
||||
OPCODE_IMAD,
|
||||
OPCODE_IMAX,
|
||||
OPCODE_IMIN,
|
||||
OPCODE_IMUL,
|
||||
OPCODE_INE,
|
||||
OPCODE_INEG,
|
||||
OPCODE_ISHL,
|
||||
OPCODE_ISHR,
|
||||
OPCODE_ITOF,
|
||||
OPCODE_LABEL,
|
||||
OPCODE_LD,
|
||||
OPCODE_LD_MS,
|
||||
OPCODE_LOG,
|
||||
OPCODE_LOOP,
|
||||
OPCODE_LT,
|
||||
OPCODE_MAD,
|
||||
OPCODE_MIN,
|
||||
OPCODE_MAX,
|
||||
OPCODE_CUSTOMDATA,
|
||||
OPCODE_MOV,
|
||||
OPCODE_MOVC,
|
||||
OPCODE_MUL,
|
||||
OPCODE_NE,
|
||||
OPCODE_NOP,
|
||||
OPCODE_NOT,
|
||||
OPCODE_OR,
|
||||
OPCODE_RESINFO,
|
||||
OPCODE_RET,
|
||||
OPCODE_RETC,
|
||||
OPCODE_ROUND_NE,
|
||||
OPCODE_ROUND_NI,
|
||||
OPCODE_ROUND_PI,
|
||||
OPCODE_ROUND_Z,
|
||||
OPCODE_RSQ,
|
||||
OPCODE_SAMPLE,
|
||||
OPCODE_SAMPLE_C,
|
||||
OPCODE_SAMPLE_C_LZ,
|
||||
OPCODE_SAMPLE_L,
|
||||
OPCODE_SAMPLE_D,
|
||||
OPCODE_SAMPLE_B,
|
||||
OPCODE_SQRT,
|
||||
OPCODE_SWITCH,
|
||||
OPCODE_SINCOS,
|
||||
OPCODE_UDIV,
|
||||
OPCODE_ULT,
|
||||
OPCODE_UGE,
|
||||
OPCODE_UMUL,
|
||||
OPCODE_UMAD,
|
||||
OPCODE_UMAX,
|
||||
OPCODE_UMIN,
|
||||
OPCODE_USHR,
|
||||
OPCODE_UTOF,
|
||||
OPCODE_XOR,
|
||||
OPCODE_DCL_RESOURCE, // DCL* opcodes have
|
||||
OPCODE_DCL_CONSTANT_BUFFER, // custom operand formats.
|
||||
OPCODE_DCL_SAMPLER,
|
||||
OPCODE_DCL_INDEX_RANGE,
|
||||
OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY,
|
||||
OPCODE_DCL_GS_INPUT_PRIMITIVE,
|
||||
OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT,
|
||||
OPCODE_DCL_INPUT,
|
||||
OPCODE_DCL_INPUT_SGV,
|
||||
OPCODE_DCL_INPUT_SIV,
|
||||
OPCODE_DCL_INPUT_PS,
|
||||
OPCODE_DCL_INPUT_PS_SGV,
|
||||
OPCODE_DCL_INPUT_PS_SIV,
|
||||
OPCODE_DCL_OUTPUT,
|
||||
OPCODE_DCL_OUTPUT_SGV,
|
||||
OPCODE_DCL_OUTPUT_SIV,
|
||||
OPCODE_DCL_TEMPS,
|
||||
OPCODE_DCL_INDEXABLE_TEMP,
|
||||
OPCODE_DCL_GLOBAL_FLAGS,
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
OPCODE_RESERVED_10,
|
||||
|
||||
// ---------- DX 10.1 op codes---------------------
|
||||
|
||||
OPCODE_LOD,
|
||||
OPCODE_GATHER4,
|
||||
OPCODE_SAMPLE_POS,
|
||||
OPCODE_SAMPLE_INFO,
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
// This should be 10.1's version of NUM_OPCODES
|
||||
OPCODE_RESERVED_10_1,
|
||||
|
||||
// ---------- DX 11 op codes---------------------
|
||||
OPCODE_HS_DECLS, // token marks beginning of HS sub-shader
|
||||
OPCODE_HS_CONTROL_POINT_PHASE, // token marks beginning of HS sub-shader
|
||||
OPCODE_HS_FORK_PHASE, // token marks beginning of HS sub-shader
|
||||
OPCODE_HS_JOIN_PHASE, // token marks beginning of HS sub-shader
|
||||
|
||||
OPCODE_EMIT_STREAM,
|
||||
OPCODE_CUT_STREAM,
|
||||
OPCODE_EMITTHENCUT_STREAM,
|
||||
OPCODE_INTERFACE_CALL,
|
||||
|
||||
OPCODE_BUFINFO,
|
||||
OPCODE_DERIV_RTX_COARSE,
|
||||
OPCODE_DERIV_RTX_FINE,
|
||||
OPCODE_DERIV_RTY_COARSE,
|
||||
OPCODE_DERIV_RTY_FINE,
|
||||
OPCODE_GATHER4_C,
|
||||
OPCODE_GATHER4_PO,
|
||||
OPCODE_GATHER4_PO_C,
|
||||
OPCODE_RCP,
|
||||
OPCODE_F32TOF16,
|
||||
OPCODE_F16TOF32,
|
||||
OPCODE_UADDC,
|
||||
OPCODE_USUBB,
|
||||
OPCODE_COUNTBITS,
|
||||
OPCODE_FIRSTBIT_HI,
|
||||
OPCODE_FIRSTBIT_LO,
|
||||
OPCODE_FIRSTBIT_SHI,
|
||||
OPCODE_UBFE,
|
||||
OPCODE_IBFE,
|
||||
OPCODE_BFI,
|
||||
OPCODE_BFREV,
|
||||
OPCODE_SWAPC,
|
||||
|
||||
OPCODE_DCL_STREAM,
|
||||
OPCODE_DCL_FUNCTION_BODY,
|
||||
OPCODE_DCL_FUNCTION_TABLE,
|
||||
OPCODE_DCL_INTERFACE,
|
||||
|
||||
OPCODE_DCL_INPUT_CONTROL_POINT_COUNT,
|
||||
OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT,
|
||||
OPCODE_DCL_TESS_DOMAIN,
|
||||
OPCODE_DCL_TESS_PARTITIONING,
|
||||
OPCODE_DCL_TESS_OUTPUT_PRIMITIVE,
|
||||
OPCODE_DCL_HS_MAX_TESSFACTOR,
|
||||
OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT,
|
||||
OPCODE_DCL_HS_JOIN_PHASE_INSTANCE_COUNT,
|
||||
|
||||
OPCODE_DCL_THREAD_GROUP,
|
||||
OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED,
|
||||
OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW,
|
||||
OPCODE_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED,
|
||||
OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW,
|
||||
OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED,
|
||||
OPCODE_DCL_RESOURCE_RAW,
|
||||
OPCODE_DCL_RESOURCE_STRUCTURED,
|
||||
OPCODE_LD_UAV_TYPED,
|
||||
OPCODE_STORE_UAV_TYPED,
|
||||
OPCODE_LD_RAW,
|
||||
OPCODE_STORE_RAW,
|
||||
OPCODE_LD_STRUCTURED,
|
||||
OPCODE_STORE_STRUCTURED,
|
||||
OPCODE_ATOMIC_AND,
|
||||
OPCODE_ATOMIC_OR,
|
||||
OPCODE_ATOMIC_XOR,
|
||||
OPCODE_ATOMIC_CMP_STORE,
|
||||
OPCODE_ATOMIC_IADD,
|
||||
OPCODE_ATOMIC_IMAX,
|
||||
OPCODE_ATOMIC_IMIN,
|
||||
OPCODE_ATOMIC_UMAX,
|
||||
OPCODE_ATOMIC_UMIN,
|
||||
OPCODE_IMM_ATOMIC_ALLOC,
|
||||
OPCODE_IMM_ATOMIC_CONSUME,
|
||||
OPCODE_IMM_ATOMIC_IADD,
|
||||
OPCODE_IMM_ATOMIC_AND,
|
||||
OPCODE_IMM_ATOMIC_OR,
|
||||
OPCODE_IMM_ATOMIC_XOR,
|
||||
OPCODE_IMM_ATOMIC_EXCH,
|
||||
OPCODE_IMM_ATOMIC_CMP_EXCH,
|
||||
OPCODE_IMM_ATOMIC_IMAX,
|
||||
OPCODE_IMM_ATOMIC_IMIN,
|
||||
OPCODE_IMM_ATOMIC_UMAX,
|
||||
OPCODE_IMM_ATOMIC_UMIN,
|
||||
OPCODE_SYNC,
|
||||
|
||||
OPCODE_DADD,
|
||||
OPCODE_DMAX,
|
||||
OPCODE_DMIN,
|
||||
OPCODE_DMUL,
|
||||
OPCODE_DEQ,
|
||||
OPCODE_DGE,
|
||||
OPCODE_DLT,
|
||||
OPCODE_DNE,
|
||||
OPCODE_DMOV,
|
||||
OPCODE_DMOVC,
|
||||
OPCODE_DTOF,
|
||||
OPCODE_FTOD,
|
||||
|
||||
OPCODE_EVAL_SNAPPED,
|
||||
OPCODE_EVAL_SAMPLE_INDEX,
|
||||
OPCODE_EVAL_CENTROID,
|
||||
|
||||
OPCODE_DCL_GS_INSTANCE_COUNT,
|
||||
|
||||
OPCODE_ABORT,
|
||||
OPCODE_DEBUG_BREAK,
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
// This marks the end of D3D11.0 opcodes
|
||||
OPCODE_RESERVED_11,
|
||||
|
||||
OPCODE_DDIV,
|
||||
OPCODE_DFMA,
|
||||
OPCODE_DRCP,
|
||||
|
||||
OPCODE_MSAD,
|
||||
|
||||
OPCODE_DTOI,
|
||||
OPCODE_DTOU,
|
||||
OPCODE_ITOD,
|
||||
OPCODE_UTOD,
|
||||
|
||||
// -----------------------------------------------
|
||||
|
||||
// This marks the end of D3D11.1 opcodes
|
||||
OPCODE_RESERVED_11_1,
|
||||
|
||||
NUM_OPCODES,
|
||||
OPCODE_INVAILD = NUM_OPCODES,
|
||||
} OPCODE_TYPE;
|
||||
|
||||
static OPCODE_TYPE DecodeOpcodeType(uint32_t ui32Token)
|
||||
{
|
||||
return (OPCODE_TYPE)(ui32Token & 0x00007ff);
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INDEX_0D,
|
||||
INDEX_1D,
|
||||
INDEX_2D,
|
||||
INDEX_3D,
|
||||
} OPERAND_INDEX_DIMENSION;
|
||||
|
||||
static OPERAND_INDEX_DIMENSION DecodeOperandIndexDimension(uint32_t ui32Token)
|
||||
{
|
||||
return (OPERAND_INDEX_DIMENSION)((ui32Token & 0x00300000) >> 20);
|
||||
}
|
||||
|
||||
typedef enum OPERAND_TYPE
|
||||
{
|
||||
OPERAND_TYPE_SPECIAL_LOOPCOUNTER = -10,
|
||||
OPERAND_TYPE_SPECIAL_IMMCONSTINT = -9,
|
||||
OPERAND_TYPE_SPECIAL_TEXCOORD = -8,
|
||||
OPERAND_TYPE_SPECIAL_POSITION = -7,
|
||||
OPERAND_TYPE_SPECIAL_FOG = -6,
|
||||
OPERAND_TYPE_SPECIAL_POINTSIZE = -5,
|
||||
OPERAND_TYPE_SPECIAL_OUTOFFSETCOLOUR = -4,
|
||||
OPERAND_TYPE_SPECIAL_OUTBASECOLOUR = -3,
|
||||
OPERAND_TYPE_SPECIAL_ADDRESS = -2,
|
||||
OPERAND_TYPE_SPECIAL_IMMCONST = -1,
|
||||
OPERAND_TYPE_TEMP = 0, // Temporary Register File
|
||||
OPERAND_TYPE_INPUT = 1, // General Input Register File
|
||||
OPERAND_TYPE_OUTPUT = 2, // General Output Register File
|
||||
OPERAND_TYPE_INDEXABLE_TEMP = 3, // Temporary Register File (indexable)
|
||||
OPERAND_TYPE_IMMEDIATE32 = 4, // 32bit/component immediate value(s)
|
||||
// If for example, operand token bits
|
||||
// [01:00]==OPERAND_4_COMPONENT,
|
||||
// this means that the operand type:
|
||||
// OPERAND_TYPE_IMMEDIATE32
|
||||
// results in 4 additional 32bit
|
||||
// DWORDS present for the operand.
|
||||
OPERAND_TYPE_IMMEDIATE64 = 5, // 64bit/comp.imm.val(s)HI:LO
|
||||
OPERAND_TYPE_SAMPLER = 6, // Reference to sampler state
|
||||
OPERAND_TYPE_RESOURCE = 7, // Reference to memory resource (e.g. texture)
|
||||
OPERAND_TYPE_CONSTANT_BUFFER= 8, // Reference to constant buffer
|
||||
OPERAND_TYPE_IMMEDIATE_CONSTANT_BUFFER= 9, // Reference to immediate constant buffer
|
||||
OPERAND_TYPE_LABEL = 10, // Label
|
||||
OPERAND_TYPE_INPUT_PRIMITIVEID = 11, // Input primitive ID
|
||||
OPERAND_TYPE_OUTPUT_DEPTH = 12, // Output Depth
|
||||
OPERAND_TYPE_NULL = 13, // Null register, used to discard results of operations
|
||||
// Below Are operands new in DX 10.1
|
||||
OPERAND_TYPE_RASTERIZER = 14, // DX10.1 Rasterizer register, used to denote the depth/stencil and render target resources
|
||||
OPERAND_TYPE_OUTPUT_COVERAGE_MASK = 15, // DX10.1 PS output MSAA coverage mask (scalar)
|
||||
// Below Are operands new in DX 11
|
||||
OPERAND_TYPE_STREAM = 16, // Reference to GS stream output resource
|
||||
OPERAND_TYPE_FUNCTION_BODY = 17, // Reference to a function definition
|
||||
OPERAND_TYPE_FUNCTION_TABLE = 18, // Reference to a set of functions used by a class
|
||||
OPERAND_TYPE_INTERFACE = 19, // Reference to an interface
|
||||
OPERAND_TYPE_FUNCTION_INPUT = 20, // Reference to an input parameter to a function
|
||||
OPERAND_TYPE_FUNCTION_OUTPUT = 21, // Reference to an output parameter to a function
|
||||
OPERAND_TYPE_OUTPUT_CONTROL_POINT_ID = 22, // HS Control Point phase input saying which output control point ID this is
|
||||
OPERAND_TYPE_INPUT_FORK_INSTANCE_ID = 23, // HS Fork Phase input instance ID
|
||||
OPERAND_TYPE_INPUT_JOIN_INSTANCE_ID = 24, // HS Join Phase input instance ID
|
||||
OPERAND_TYPE_INPUT_CONTROL_POINT = 25, // HS Fork+Join, DS phase input control points (array of them)
|
||||
OPERAND_TYPE_OUTPUT_CONTROL_POINT = 26, // HS Fork+Join phase output control points (array of them)
|
||||
OPERAND_TYPE_INPUT_PATCH_CONSTANT = 27, // DS+HSJoin Input Patch Constants (array of them)
|
||||
OPERAND_TYPE_INPUT_DOMAIN_POINT = 28, // DS Input Domain point
|
||||
OPERAND_TYPE_THIS_POINTER = 29, // Reference to an interface this pointer
|
||||
OPERAND_TYPE_UNORDERED_ACCESS_VIEW = 30, // Reference to UAV u#
|
||||
OPERAND_TYPE_THREAD_GROUP_SHARED_MEMORY = 31, // Reference to Thread Group Shared Memory g#
|
||||
OPERAND_TYPE_INPUT_THREAD_ID = 32, // Compute Shader Thread ID
|
||||
OPERAND_TYPE_INPUT_THREAD_GROUP_ID = 33, // Compute Shader Thread Group ID
|
||||
OPERAND_TYPE_INPUT_THREAD_ID_IN_GROUP = 34, // Compute Shader Thread ID In Thread Group
|
||||
OPERAND_TYPE_INPUT_COVERAGE_MASK = 35, // Pixel shader coverage mask input
|
||||
OPERAND_TYPE_INPUT_THREAD_ID_IN_GROUP_FLATTENED = 36, // Compute Shader Thread ID In Group Flattened to a 1D value.
|
||||
OPERAND_TYPE_INPUT_GS_INSTANCE_ID = 37, // Input GS instance ID
|
||||
OPERAND_TYPE_OUTPUT_DEPTH_GREATER_EQUAL = 38, // Output Depth, forced to be greater than or equal than current depth
|
||||
OPERAND_TYPE_OUTPUT_DEPTH_LESS_EQUAL = 39, // Output Depth, forced to be less than or equal to current depth
|
||||
OPERAND_TYPE_CYCLE_COUNTER = 40, // Cycle counter
|
||||
} OPERAND_TYPE;
|
||||
|
||||
static OPERAND_TYPE DecodeOperandType(uint32_t ui32Token)
|
||||
{
|
||||
return (OPERAND_TYPE)((ui32Token & 0x000ff000) >> 12);
|
||||
}
|
||||
|
||||
static SPECIAL_NAME DecodeOperandSpecialName(uint32_t ui32Token)
|
||||
{
|
||||
return (SPECIAL_NAME)(ui32Token & 0x0000ffff);
|
||||
}
|
||||
|
||||
typedef enum OPERAND_INDEX_REPRESENTATION
|
||||
{
|
||||
OPERAND_INDEX_IMMEDIATE32 = 0, // Extra DWORD
|
||||
OPERAND_INDEX_IMMEDIATE64 = 1, // 2 Extra DWORDs
|
||||
// (HI32:LO32)
|
||||
OPERAND_INDEX_RELATIVE = 2, // Extra operand
|
||||
OPERAND_INDEX_IMMEDIATE32_PLUS_RELATIVE = 3, // Extra DWORD followed by
|
||||
// extra operand
|
||||
OPERAND_INDEX_IMMEDIATE64_PLUS_RELATIVE = 4, // 2 Extra DWORDS
|
||||
// (HI32:LO32) followed
|
||||
// by extra operand
|
||||
} OPERAND_INDEX_REPRESENTATION;
|
||||
|
||||
static OPERAND_INDEX_REPRESENTATION DecodeOperandIndexRepresentation(uint32_t ui32Dimension, uint32_t ui32Token)
|
||||
{
|
||||
return (OPERAND_INDEX_REPRESENTATION)((ui32Token & (0x3<<(22+3*((ui32Dimension)&3)))) >> (22+3*((ui32Dimension)&3)));
|
||||
}
|
||||
|
||||
typedef enum OPERAND_NUM_COMPONENTS
|
||||
{
|
||||
OPERAND_0_COMPONENT = 0,
|
||||
OPERAND_1_COMPONENT = 1,
|
||||
OPERAND_4_COMPONENT = 2,
|
||||
OPERAND_N_COMPONENT = 3 // unused for now
|
||||
} OPERAND_NUM_COMPONENTS;
|
||||
|
||||
static OPERAND_NUM_COMPONENTS DecodeOperandNumComponents(uint32_t ui32Token)
|
||||
{
|
||||
return (OPERAND_NUM_COMPONENTS)(ui32Token & 0x00000003);
|
||||
}
|
||||
|
||||
typedef enum OPERAND_4_COMPONENT_SELECTION_MODE
|
||||
{
|
||||
OPERAND_4_COMPONENT_MASK_MODE = 0, // mask 4 components
|
||||
OPERAND_4_COMPONENT_SWIZZLE_MODE = 1, // swizzle 4 components
|
||||
OPERAND_4_COMPONENT_SELECT_1_MODE = 2, // select 1 of 4 components
|
||||
} OPERAND_4_COMPONENT_SELECTION_MODE;
|
||||
|
||||
static OPERAND_4_COMPONENT_SELECTION_MODE DecodeOperand4CompSelMode(uint32_t ui32Token)
|
||||
{
|
||||
return (OPERAND_4_COMPONENT_SELECTION_MODE)((ui32Token & 0x0000000c) >> 2);
|
||||
}
|
||||
|
||||
#define OPERAND_4_COMPONENT_MASK_X 0x00000001
|
||||
#define OPERAND_4_COMPONENT_MASK_Y 0x00000002
|
||||
#define OPERAND_4_COMPONENT_MASK_Z 0x00000004
|
||||
#define OPERAND_4_COMPONENT_MASK_W 0x00000008
|
||||
#define OPERAND_4_COMPONENT_MASK_R OPERAND_4_COMPONENT_MASK_X
|
||||
#define OPERAND_4_COMPONENT_MASK_G OPERAND_4_COMPONENT_MASK_Y
|
||||
#define OPERAND_4_COMPONENT_MASK_B OPERAND_4_COMPONENT_MASK_Z
|
||||
#define OPERAND_4_COMPONENT_MASK_A OPERAND_4_COMPONENT_MASK_W
|
||||
#define OPERAND_4_COMPONENT_MASK_ALL 0x0000000f
|
||||
|
||||
static uint32_t DecodeOperand4CompMask(uint32_t ui32Token)
|
||||
{
|
||||
return (uint32_t)((ui32Token & 0x000000f0) >> 4);
|
||||
}
|
||||
|
||||
static uint32_t DecodeOperand4CompSwizzle(uint32_t ui32Token)
|
||||
{
|
||||
return (uint32_t)((ui32Token & 0x00000ff0) >> 4);
|
||||
}
|
||||
|
||||
static uint32_t DecodeOperand4CompSel1(uint32_t ui32Token)
|
||||
{
|
||||
return (uint32_t)((ui32Token & 0x00000030) >> 4);
|
||||
}
|
||||
|
||||
#define OPERAND_4_COMPONENT_X 0
|
||||
#define OPERAND_4_COMPONENT_Y 1
|
||||
#define OPERAND_4_COMPONENT_Z 2
|
||||
#define OPERAND_4_COMPONENT_W 3
|
||||
|
||||
static uint32_t NO_SWIZZLE = (( (OPERAND_4_COMPONENT_X) | (OPERAND_4_COMPONENT_Y<<2) | (OPERAND_4_COMPONENT_Z << 4) | (OPERAND_4_COMPONENT_W << 6))/*<<4*/);
|
||||
|
||||
static uint32_t XXXX_SWIZZLE = (((OPERAND_4_COMPONENT_X) | (OPERAND_4_COMPONENT_X<<2) | (OPERAND_4_COMPONENT_X << 4) | (OPERAND_4_COMPONENT_X << 6)));
|
||||
static uint32_t YYYY_SWIZZLE = (((OPERAND_4_COMPONENT_Y) | (OPERAND_4_COMPONENT_Y<<2) | (OPERAND_4_COMPONENT_Y << 4) | (OPERAND_4_COMPONENT_Y << 6)));
|
||||
static uint32_t ZZZZ_SWIZZLE = (((OPERAND_4_COMPONENT_Z) | (OPERAND_4_COMPONENT_Z<<2) | (OPERAND_4_COMPONENT_Z << 4) | (OPERAND_4_COMPONENT_Z << 6)));
|
||||
static uint32_t WWWW_SWIZZLE = (((OPERAND_4_COMPONENT_W) | (OPERAND_4_COMPONENT_W<<2) | (OPERAND_4_COMPONENT_W << 4) | (OPERAND_4_COMPONENT_W << 6)));
|
||||
|
||||
static uint32_t DecodeOperand4CompSwizzleSource(uint32_t ui32Token, uint32_t comp)
|
||||
{
|
||||
return (uint32_t)(((ui32Token)>>(4+2*((comp)&3)))&3);
|
||||
}
|
||||
|
||||
typedef enum RESOURCE_DIMENSION
|
||||
{
|
||||
RESOURCE_DIMENSION_UNKNOWN = 0,
|
||||
RESOURCE_DIMENSION_BUFFER = 1,
|
||||
RESOURCE_DIMENSION_TEXTURE1D = 2,
|
||||
RESOURCE_DIMENSION_TEXTURE2D = 3,
|
||||
RESOURCE_DIMENSION_TEXTURE2DMS = 4,
|
||||
RESOURCE_DIMENSION_TEXTURE3D = 5,
|
||||
RESOURCE_DIMENSION_TEXTURECUBE = 6,
|
||||
RESOURCE_DIMENSION_TEXTURE1DARRAY = 7,
|
||||
RESOURCE_DIMENSION_TEXTURE2DARRAY = 8,
|
||||
RESOURCE_DIMENSION_TEXTURE2DMSARRAY = 9,
|
||||
RESOURCE_DIMENSION_TEXTURECUBEARRAY = 10,
|
||||
RESOURCE_DIMENSION_RAW_BUFFER = 11,
|
||||
RESOURCE_DIMENSION_STRUCTURED_BUFFER = 12,
|
||||
} RESOURCE_DIMENSION;
|
||||
|
||||
static RESOURCE_DIMENSION DecodeResourceDimension(uint32_t ui32Token)
|
||||
{
|
||||
return (RESOURCE_DIMENSION)((ui32Token & 0x0000f800) >> 11);
|
||||
}
|
||||
|
||||
static RESOURCE_DIMENSION DecodeExtendedResourceDimension(uint32_t ui32Token)
|
||||
{
|
||||
return (RESOURCE_DIMENSION)((ui32Token & 0x000007C0) >> 6);
|
||||
}
|
||||
|
||||
typedef enum CONSTANT_BUFFER_ACCESS_PATTERN
|
||||
{
|
||||
CONSTANT_BUFFER_ACCESS_PATTERN_IMMEDIATEINDEXED = 0,
|
||||
CONSTANT_BUFFER_ACCESS_PATTERN_DYNAMICINDEXED = 1
|
||||
} CONSTANT_BUFFER_ACCESS_PATTERN;
|
||||
|
||||
static CONSTANT_BUFFER_ACCESS_PATTERN DecodeConstantBufferAccessPattern(uint32_t ui32Token)
|
||||
{
|
||||
return (CONSTANT_BUFFER_ACCESS_PATTERN)((ui32Token & 0x00000800) >> 11);
|
||||
}
|
||||
|
||||
typedef enum INSTRUCTION_TEST_BOOLEAN
|
||||
{
|
||||
INSTRUCTION_TEST_ZERO = 0,
|
||||
INSTRUCTION_TEST_NONZERO = 1
|
||||
} INSTRUCTION_TEST_BOOLEAN;
|
||||
|
||||
static INSTRUCTION_TEST_BOOLEAN DecodeInstrTestBool(uint32_t ui32Token)
|
||||
{
|
||||
return (INSTRUCTION_TEST_BOOLEAN)((ui32Token & 0x00040000) >> 18);
|
||||
}
|
||||
|
||||
static uint32_t DecodeIsOperandExtended(uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x80000000) >> 31;
|
||||
}
|
||||
|
||||
typedef enum EXTENDED_OPERAND_TYPE
|
||||
{
|
||||
EXTENDED_OPERAND_EMPTY = 0,
|
||||
EXTENDED_OPERAND_MODIFIER = 1,
|
||||
} EXTENDED_OPERAND_TYPE;
|
||||
|
||||
static EXTENDED_OPERAND_TYPE DecodeExtendedOperandType(uint32_t ui32Token)
|
||||
{
|
||||
return (EXTENDED_OPERAND_TYPE)(ui32Token & 0x0000003f);
|
||||
}
|
||||
|
||||
typedef enum OPERAND_MODIFIER
|
||||
{
|
||||
OPERAND_MODIFIER_NONE = 0,
|
||||
OPERAND_MODIFIER_NEG = 1,
|
||||
OPERAND_MODIFIER_ABS = 2,
|
||||
OPERAND_MODIFIER_ABSNEG = 3,
|
||||
} OPERAND_MODIFIER;
|
||||
|
||||
static OPERAND_MODIFIER DecodeExtendedOperandModifier(uint32_t ui32Token)
|
||||
{
|
||||
return (OPERAND_MODIFIER)((ui32Token & 0x00003fc0) >> 6);
|
||||
}
|
||||
|
||||
static const uint32_t GLOBAL_FLAG_REFACTORING_ALLOWED = (1<<11);
|
||||
static const uint32_t GLOBAL_FLAG_ENABLE_DOUBLE_PRECISION_FLOAT_OPS = (1<<12);
|
||||
static const uint32_t GLOBAL_FLAG_FORCE_EARLY_DEPTH_STENCIL = (1<<13);
|
||||
static const uint32_t GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS = (1<<14);
|
||||
static const uint32_t GLOBAL_FLAG_SKIP_OPTIMIZATION = (1<<15);
|
||||
static const uint32_t GLOBAL_FLAG_ENABLE_MINIMUM_PRECISION = (1<<16);
|
||||
static const uint32_t GLOBAL_FLAG_ENABLE_DOUBLE_EXTENSIONS = (1<<17);
|
||||
static const uint32_t GLOBAL_FLAG_ENABLE_SHADER_EXTENSIONS = (1<<18);
|
||||
|
||||
static uint32_t DecodeGlobalFlags(uint32_t ui32Token)
|
||||
{
|
||||
return (uint32_t)(ui32Token & 0x00fff800);
|
||||
}
|
||||
|
||||
static INTERPOLATION_MODE DecodeInterpolationMode(uint32_t ui32Token)
|
||||
{
|
||||
return (INTERPOLATION_MODE)((ui32Token & 0x00007800) >> 11);
|
||||
}
|
||||
|
||||
|
||||
typedef enum PRIMITIVE_TOPOLOGY
|
||||
{
|
||||
PRIMITIVE_TOPOLOGY_UNDEFINED = 0,
|
||||
PRIMITIVE_TOPOLOGY_POINTLIST = 1,
|
||||
PRIMITIVE_TOPOLOGY_LINELIST = 2,
|
||||
PRIMITIVE_TOPOLOGY_LINESTRIP = 3,
|
||||
PRIMITIVE_TOPOLOGY_TRIANGLELIST = 4,
|
||||
PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = 5,
|
||||
// 6 is reserved for legacy triangle fans
|
||||
// Adjacency values should be equal to (0x8 & non-adjacency):
|
||||
PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10,
|
||||
PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = 11,
|
||||
PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = 12,
|
||||
PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = 13,
|
||||
} PRIMITIVE_TOPOLOGY;
|
||||
|
||||
static PRIMITIVE_TOPOLOGY DecodeGSOutputPrimitiveTopology(uint32_t ui32Token)
|
||||
{
|
||||
return (PRIMITIVE_TOPOLOGY)((ui32Token & 0x0001f800) >> 11);
|
||||
}
|
||||
|
||||
typedef enum PRIMITIVE
|
||||
{
|
||||
PRIMITIVE_UNDEFINED = 0,
|
||||
PRIMITIVE_POINT = 1,
|
||||
PRIMITIVE_LINE = 2,
|
||||
PRIMITIVE_TRIANGLE = 3,
|
||||
// Adjacency values should be equal to (0x4 & non-adjacency):
|
||||
PRIMITIVE_LINE_ADJ = 6,
|
||||
PRIMITIVE_TRIANGLE_ADJ = 7,
|
||||
PRIMITIVE_1_CONTROL_POINT_PATCH = 8,
|
||||
PRIMITIVE_2_CONTROL_POINT_PATCH = 9,
|
||||
PRIMITIVE_3_CONTROL_POINT_PATCH = 10,
|
||||
PRIMITIVE_4_CONTROL_POINT_PATCH = 11,
|
||||
PRIMITIVE_5_CONTROL_POINT_PATCH = 12,
|
||||
PRIMITIVE_6_CONTROL_POINT_PATCH = 13,
|
||||
PRIMITIVE_7_CONTROL_POINT_PATCH = 14,
|
||||
PRIMITIVE_8_CONTROL_POINT_PATCH = 15,
|
||||
PRIMITIVE_9_CONTROL_POINT_PATCH = 16,
|
||||
PRIMITIVE_10_CONTROL_POINT_PATCH = 17,
|
||||
PRIMITIVE_11_CONTROL_POINT_PATCH = 18,
|
||||
PRIMITIVE_12_CONTROL_POINT_PATCH = 19,
|
||||
PRIMITIVE_13_CONTROL_POINT_PATCH = 20,
|
||||
PRIMITIVE_14_CONTROL_POINT_PATCH = 21,
|
||||
PRIMITIVE_15_CONTROL_POINT_PATCH = 22,
|
||||
PRIMITIVE_16_CONTROL_POINT_PATCH = 23,
|
||||
PRIMITIVE_17_CONTROL_POINT_PATCH = 24,
|
||||
PRIMITIVE_18_CONTROL_POINT_PATCH = 25,
|
||||
PRIMITIVE_19_CONTROL_POINT_PATCH = 26,
|
||||
PRIMITIVE_20_CONTROL_POINT_PATCH = 27,
|
||||
PRIMITIVE_21_CONTROL_POINT_PATCH = 28,
|
||||
PRIMITIVE_22_CONTROL_POINT_PATCH = 29,
|
||||
PRIMITIVE_23_CONTROL_POINT_PATCH = 30,
|
||||
PRIMITIVE_24_CONTROL_POINT_PATCH = 31,
|
||||
PRIMITIVE_25_CONTROL_POINT_PATCH = 32,
|
||||
PRIMITIVE_26_CONTROL_POINT_PATCH = 33,
|
||||
PRIMITIVE_27_CONTROL_POINT_PATCH = 34,
|
||||
PRIMITIVE_28_CONTROL_POINT_PATCH = 35,
|
||||
PRIMITIVE_29_CONTROL_POINT_PATCH = 36,
|
||||
PRIMITIVE_30_CONTROL_POINT_PATCH = 37,
|
||||
PRIMITIVE_31_CONTROL_POINT_PATCH = 38,
|
||||
PRIMITIVE_32_CONTROL_POINT_PATCH = 39,
|
||||
} PRIMITIVE;
|
||||
|
||||
static PRIMITIVE DecodeGSInputPrimitive(uint32_t ui32Token)
|
||||
{
|
||||
return (PRIMITIVE)((ui32Token & 0x0001f800) >> 11);
|
||||
}
|
||||
|
||||
static TESSELLATOR_PARTITIONING DecodeTessPartitioning(uint32_t ui32Token)
|
||||
{
|
||||
return (TESSELLATOR_PARTITIONING)((ui32Token & 0x00003800) >> 11);
|
||||
}
|
||||
|
||||
typedef enum TESSELLATOR_DOMAIN
|
||||
{
|
||||
TESSELLATOR_DOMAIN_UNDEFINED = 0,
|
||||
TESSELLATOR_DOMAIN_ISOLINE = 1,
|
||||
TESSELLATOR_DOMAIN_TRI = 2,
|
||||
TESSELLATOR_DOMAIN_QUAD = 3
|
||||
} TESSELLATOR_DOMAIN;
|
||||
|
||||
static TESSELLATOR_DOMAIN DecodeTessDomain(uint32_t ui32Token)
|
||||
{
|
||||
return (TESSELLATOR_DOMAIN)((ui32Token & 0x00001800) >> 11);
|
||||
}
|
||||
|
||||
static TESSELLATOR_OUTPUT_PRIMITIVE DecodeTessOutPrim(uint32_t ui32Token)
|
||||
{
|
||||
return (TESSELLATOR_OUTPUT_PRIMITIVE)((ui32Token & 0x00003800) >> 11);
|
||||
}
|
||||
|
||||
static const uint32_t SYNC_THREADS_IN_GROUP = 0x00000800;
|
||||
static const uint32_t SYNC_THREAD_GROUP_SHARED_MEMORY = 0x00001000;
|
||||
static const uint32_t SYNC_UNORDERED_ACCESS_VIEW_MEMORY_GROUP = 0x00002000;
|
||||
static const uint32_t SYNC_UNORDERED_ACCESS_VIEW_MEMORY_GLOBAL = 0x00004000;
|
||||
|
||||
static uint32_t DecodeSyncFlags(uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & 0x00007800;
|
||||
}
|
||||
|
||||
// The number of types that implement this interface
|
||||
static uint32_t DecodeInterfaceTableLength(uint32_t ui32Token)
|
||||
{
|
||||
return (uint32_t)((ui32Token & 0x0000ffff) >> 0);
|
||||
}
|
||||
|
||||
// The number of interfaces that are defined in this array.
|
||||
static uint32_t DecodeInterfaceArrayLength(uint32_t ui32Token)
|
||||
{
|
||||
return (uint32_t)((ui32Token & 0xffff0000) >> 16);
|
||||
}
|
||||
|
||||
typedef enum CUSTOMDATA_CLASS
|
||||
{
|
||||
CUSTOMDATA_COMMENT = 0,
|
||||
CUSTOMDATA_DEBUGINFO,
|
||||
CUSTOMDATA_OPAQUE,
|
||||
CUSTOMDATA_DCL_IMMEDIATE_CONSTANT_BUFFER,
|
||||
CUSTOMDATA_SHADER_MESSAGE,
|
||||
} CUSTOMDATA_CLASS;
|
||||
|
||||
static CUSTOMDATA_CLASS DecodeCustomDataClass(uint32_t ui32Token)
|
||||
{
|
||||
return (CUSTOMDATA_CLASS)((ui32Token & 0xfffff800) >> 11);
|
||||
}
|
||||
|
||||
static uint32_t DecodeInstructionSaturate(uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x00002000) ? 1 : 0;
|
||||
}
|
||||
|
||||
typedef enum OPERAND_MIN_PRECISION
|
||||
{
|
||||
OPERAND_MIN_PRECISION_DEFAULT = 0, // Default precision
|
||||
// for the shader model
|
||||
OPERAND_MIN_PRECISION_FLOAT_16 = 1, // Min 16 bit/component float
|
||||
OPERAND_MIN_PRECISION_FLOAT_2_8 = 2, // Min 10(2.8)bit/comp. float
|
||||
OPERAND_MIN_PRECISION_SINT_16 = 4, // Min 16 bit/comp. signed integer
|
||||
OPERAND_MIN_PRECISION_UINT_16 = 5, // Min 16 bit/comp. unsigned integer
|
||||
} OPERAND_MIN_PRECISION;
|
||||
|
||||
static uint32_t DecodeOperandMinPrecision(uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x0001C000) >> 14;
|
||||
}
|
||||
|
||||
static uint32_t DecodeOutputControlPointCount(uint32_t ui32Token)
|
||||
{
|
||||
return ((ui32Token & 0x0001f800) >> 11);
|
||||
}
|
||||
|
||||
typedef enum IMMEDIATE_ADDRESS_OFFSET_COORD
|
||||
{
|
||||
IMMEDIATE_ADDRESS_OFFSET_U = 0,
|
||||
IMMEDIATE_ADDRESS_OFFSET_V = 1,
|
||||
IMMEDIATE_ADDRESS_OFFSET_W = 2,
|
||||
} IMMEDIATE_ADDRESS_OFFSET_COORD;
|
||||
|
||||
|
||||
#define IMMEDIATE_ADDRESS_OFFSET_SHIFT(Coord) (9+4*((Coord)&3))
|
||||
#define IMMEDIATE_ADDRESS_OFFSET_MASK(Coord) (0x0000000f<<IMMEDIATE_ADDRESS_OFFSET_SHIFT(Coord))
|
||||
|
||||
static uint32_t DecodeImmediateAddressOffset(IMMEDIATE_ADDRESS_OFFSET_COORD eCoord, uint32_t ui32Token)
|
||||
{
|
||||
return ((((ui32Token)&IMMEDIATE_ADDRESS_OFFSET_MASK(eCoord))>>(IMMEDIATE_ADDRESS_OFFSET_SHIFT(eCoord))));
|
||||
}
|
||||
|
||||
// UAV access scope flags
|
||||
static const uint32_t GLOBALLY_COHERENT_ACCESS = 0x00010000;
|
||||
static uint32_t DecodeAccessCoherencyFlags(uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & 0x00010000;
|
||||
}
|
||||
|
||||
|
||||
typedef enum RESINFO_RETURN_TYPE
|
||||
{
|
||||
RESINFO_INSTRUCTION_RETURN_FLOAT = 0,
|
||||
RESINFO_INSTRUCTION_RETURN_RCPFLOAT = 1,
|
||||
RESINFO_INSTRUCTION_RETURN_UINT = 2
|
||||
} RESINFO_RETURN_TYPE;
|
||||
|
||||
static RESINFO_RETURN_TYPE DecodeResInfoReturnType(uint32_t ui32Token)
|
||||
{
|
||||
return (RESINFO_RETURN_TYPE)((ui32Token & 0x00001800) >> 11);
|
||||
}
|
||||
|
||||
#include "tokensDX9.h"
|
||||
|
||||
#endif
|
||||
@ -1,304 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
static const uint32_t D3D9SHADER_TYPE_VERTEX = 0xFFFE0000;
|
||||
static const uint32_t D3D9SHADER_TYPE_PIXEL = 0xFFFF0000;
|
||||
|
||||
static SHADER_TYPE DecodeShaderTypeDX9(const uint32_t ui32Token)
|
||||
{
|
||||
uint32_t ui32Type = ui32Token & 0xFFFF0000;
|
||||
if(ui32Type == D3D9SHADER_TYPE_VERTEX)
|
||||
return VERTEX_SHADER;
|
||||
|
||||
if(ui32Type == D3D9SHADER_TYPE_PIXEL)
|
||||
return PIXEL_SHADER;
|
||||
|
||||
return INVALID_SHADER;
|
||||
}
|
||||
|
||||
static uint32_t DecodeProgramMajorVersionDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ((ui32Token)>>8)&0xFF;
|
||||
}
|
||||
|
||||
static uint32_t DecodeProgramMinorVersionDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & 0xFF;
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OPCODE_DX9_NOP = 0,
|
||||
OPCODE_DX9_MOV ,
|
||||
OPCODE_DX9_ADD ,
|
||||
OPCODE_DX9_SUB ,
|
||||
OPCODE_DX9_MAD ,
|
||||
OPCODE_DX9_MUL ,
|
||||
OPCODE_DX9_RCP ,
|
||||
OPCODE_DX9_RSQ ,
|
||||
OPCODE_DX9_DP3 ,
|
||||
OPCODE_DX9_DP4 ,
|
||||
OPCODE_DX9_MIN ,
|
||||
OPCODE_DX9_MAX ,
|
||||
OPCODE_DX9_SLT ,
|
||||
OPCODE_DX9_SGE ,
|
||||
OPCODE_DX9_EXP ,
|
||||
OPCODE_DX9_LOG ,
|
||||
OPCODE_DX9_LIT ,
|
||||
OPCODE_DX9_DST ,
|
||||
OPCODE_DX9_LRP ,
|
||||
OPCODE_DX9_FRC ,
|
||||
OPCODE_DX9_M4x4 ,
|
||||
OPCODE_DX9_M4x3 ,
|
||||
OPCODE_DX9_M3x4 ,
|
||||
OPCODE_DX9_M3x3 ,
|
||||
OPCODE_DX9_M3x2 ,
|
||||
OPCODE_DX9_CALL ,
|
||||
OPCODE_DX9_CALLNZ ,
|
||||
OPCODE_DX9_LOOP ,
|
||||
OPCODE_DX9_RET ,
|
||||
OPCODE_DX9_ENDLOOP ,
|
||||
OPCODE_DX9_LABEL ,
|
||||
OPCODE_DX9_DCL ,
|
||||
OPCODE_DX9_POW ,
|
||||
OPCODE_DX9_CRS ,
|
||||
OPCODE_DX9_SGN ,
|
||||
OPCODE_DX9_ABS ,
|
||||
OPCODE_DX9_NRM ,
|
||||
OPCODE_DX9_SINCOS ,
|
||||
OPCODE_DX9_REP ,
|
||||
OPCODE_DX9_ENDREP ,
|
||||
OPCODE_DX9_IF ,
|
||||
OPCODE_DX9_IFC ,
|
||||
OPCODE_DX9_ELSE ,
|
||||
OPCODE_DX9_ENDIF ,
|
||||
OPCODE_DX9_BREAK ,
|
||||
OPCODE_DX9_BREAKC ,
|
||||
OPCODE_DX9_MOVA ,
|
||||
OPCODE_DX9_DEFB ,
|
||||
OPCODE_DX9_DEFI ,
|
||||
|
||||
OPCODE_DX9_TEXCOORD = 64,
|
||||
OPCODE_DX9_TEXKILL ,
|
||||
OPCODE_DX9_TEX ,
|
||||
OPCODE_DX9_TEXBEM ,
|
||||
OPCODE_DX9_TEXBEML ,
|
||||
OPCODE_DX9_TEXREG2AR ,
|
||||
OPCODE_DX9_TEXREG2GB ,
|
||||
OPCODE_DX9_TEXM3x2PAD ,
|
||||
OPCODE_DX9_TEXM3x2TEX ,
|
||||
OPCODE_DX9_TEXM3x3PAD ,
|
||||
OPCODE_DX9_TEXM3x3TEX ,
|
||||
OPCODE_DX9_RESERVED0 ,
|
||||
OPCODE_DX9_TEXM3x3SPEC ,
|
||||
OPCODE_DX9_TEXM3x3VSPEC ,
|
||||
OPCODE_DX9_EXPP ,
|
||||
OPCODE_DX9_LOGP ,
|
||||
OPCODE_DX9_CND ,
|
||||
OPCODE_DX9_DEF ,
|
||||
OPCODE_DX9_TEXREG2RGB ,
|
||||
OPCODE_DX9_TEXDP3TEX ,
|
||||
OPCODE_DX9_TEXM3x2DEPTH ,
|
||||
OPCODE_DX9_TEXDP3 ,
|
||||
OPCODE_DX9_TEXM3x3 ,
|
||||
OPCODE_DX9_TEXDEPTH ,
|
||||
OPCODE_DX9_CMP ,
|
||||
OPCODE_DX9_BEM ,
|
||||
OPCODE_DX9_DP2ADD ,
|
||||
OPCODE_DX9_DSX ,
|
||||
OPCODE_DX9_DSY ,
|
||||
OPCODE_DX9_TEXLDD ,
|
||||
OPCODE_DX9_SETP ,
|
||||
OPCODE_DX9_TEXLDL ,
|
||||
OPCODE_DX9_BREAKP ,
|
||||
|
||||
OPCODE_DX9_PHASE = 0xFFFD,
|
||||
OPCODE_DX9_COMMENT = 0xFFFE,
|
||||
OPCODE_DX9_END = 0xFFFF,
|
||||
|
||||
OPCODE_DX9_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
|
||||
} OPCODE_TYPE_DX9;
|
||||
|
||||
static OPCODE_TYPE_DX9 DecodeOpcodeTypeDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return (OPCODE_TYPE_DX9)(ui32Token & 0x0000FFFF);
|
||||
}
|
||||
|
||||
static uint32_t DecodeInstructionLengthDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x0F000000)>>24;
|
||||
}
|
||||
|
||||
static uint32_t DecodeCommentLengthDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x7FFF0000)>>16;
|
||||
}
|
||||
|
||||
static uint32_t DecodeOperandRegisterNumberDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & 0x000007FF;
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OPERAND_TYPE_DX9_TEMP = 0, // Temporary Register File
|
||||
OPERAND_TYPE_DX9_INPUT = 1, // Input Register File
|
||||
OPERAND_TYPE_DX9_CONST = 2, // Constant Register File
|
||||
OPERAND_TYPE_DX9_ADDR = 3, // Address Register (VS)
|
||||
OPERAND_TYPE_DX9_TEXTURE = 3, // Texture Register File (PS)
|
||||
OPERAND_TYPE_DX9_RASTOUT = 4, // Rasterizer Register File
|
||||
OPERAND_TYPE_DX9_ATTROUT = 5, // Attribute Output Register File
|
||||
OPERAND_TYPE_DX9_TEXCRDOUT = 6, // Texture Coordinate Output Register File
|
||||
OPERAND_TYPE_DX9_OUTPUT = 6, // Output register file for VS3.0+
|
||||
OPERAND_TYPE_DX9_CONSTINT = 7, // Constant Integer Vector Register File
|
||||
OPERAND_TYPE_DX9_COLOROUT = 8, // Color Output Register File
|
||||
OPERAND_TYPE_DX9_DEPTHOUT = 9, // Depth Output Register File
|
||||
OPERAND_TYPE_DX9_SAMPLER = 10, // Sampler State Register File
|
||||
OPERAND_TYPE_DX9_CONST2 = 11, // Constant Register File 2048 - 4095
|
||||
OPERAND_TYPE_DX9_CONST3 = 12, // Constant Register File 4096 - 6143
|
||||
OPERAND_TYPE_DX9_CONST4 = 13, // Constant Register File 6144 - 8191
|
||||
OPERAND_TYPE_DX9_CONSTBOOL = 14, // Constant Boolean register file
|
||||
OPERAND_TYPE_DX9_LOOP = 15, // Loop counter register file
|
||||
OPERAND_TYPE_DX9_TEMPFLOAT16 = 16, // 16-bit float temp register file
|
||||
OPERAND_TYPE_DX9_MISCTYPE = 17, // Miscellaneous (single) registers.
|
||||
OPERAND_TYPE_DX9_LABEL = 18, // Label
|
||||
OPERAND_TYPE_DX9_PREDICATE = 19, // Predicate register
|
||||
OPERAND_TYPE_DX9_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
|
||||
} OPERAND_TYPE_DX9;
|
||||
|
||||
static OPERAND_TYPE_DX9 DecodeOperandTypeDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return (OPERAND_TYPE_DX9)(((ui32Token & 0x70000000) >> 28) |
|
||||
((ui32Token & 0x00001800) >> 8));
|
||||
}
|
||||
|
||||
static uint32_t CreateOperandTokenDX9(const uint32_t ui32RegNum, const OPERAND_TYPE_DX9 eType)
|
||||
{
|
||||
uint32_t ui32Token = ui32RegNum;
|
||||
ASSERT(ui32RegNum <2048);
|
||||
ui32Token |= (eType <<28) & 0x70000000;
|
||||
ui32Token |= (eType <<8) & 0x00001800;
|
||||
return ui32Token;
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
DECLUSAGE_POSITION = 0,
|
||||
DECLUSAGE_BLENDWEIGHT = 1,
|
||||
DECLUSAGE_BLENDINDICES = 2,
|
||||
DECLUSAGE_NORMAL = 3,
|
||||
DECLUSAGE_PSIZE = 4,
|
||||
DECLUSAGE_TEXCOORD = 5,
|
||||
DECLUSAGE_TANGENT = 6,
|
||||
DECLUSAGE_BINORMAL = 7,
|
||||
DECLUSAGE_TESSFACTOR = 8,
|
||||
DECLUSAGE_POSITIONT = 9,
|
||||
DECLUSAGE_COLOR = 10,
|
||||
DECLUSAGE_FOG = 11,
|
||||
DECLUSAGE_DEPTH = 12,
|
||||
DECLUSAGE_SAMPLE = 13
|
||||
} DECLUSAGE_DX9;
|
||||
|
||||
static DECLUSAGE_DX9 DecodeUsageDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return (DECLUSAGE_DX9) (ui32Token & 0x0000000f);
|
||||
}
|
||||
|
||||
static uint32_t DecodeUsageIndexDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return (ui32Token & 0x000f0000)>>16;
|
||||
}
|
||||
|
||||
static uint32_t DecodeOperandIsRelativeAddressModeDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & (1<<13);
|
||||
}
|
||||
|
||||
static const uint32_t DX9_SWIZZLE_SHIFT = 16;
|
||||
#define NO_SWIZZLE_DX9 ((0<<DX9_SWIZZLE_SHIFT)|(1<<DX9_SWIZZLE_SHIFT)|(2<<DX9_SWIZZLE_SHIFT)|(3<<DX9_SWIZZLE_SHIFT))
|
||||
|
||||
#define REPLICATE_SWIZZLE_DX9(CHANNEL) ((CHANNEL<<DX9_SWIZZLE_SHIFT)|(CHANNEL<<(DX9_SWIZZLE_SHIFT+2))|(CHANNEL<<(DX9_SWIZZLE_SHIFT+4))|(CHANNEL<<(DX9_SWIZZLE_SHIFT+6)))
|
||||
|
||||
static uint32_t DecodeOperandSwizzleDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & 0x00FF0000;
|
||||
}
|
||||
|
||||
static const uint32_t DX9_WRITEMASK_0 = 0x00010000; // Component 0 (X;Red)
|
||||
static const uint32_t DX9_WRITEMASK_1 = 0x00020000; // Component 1 (Y;Green)
|
||||
static const uint32_t DX9_WRITEMASK_2 = 0x00040000; // Component 2 (Z;Blue)
|
||||
static const uint32_t DX9_WRITEMASK_3 = 0x00080000; // Component 3 (W;Alpha)
|
||||
static const uint32_t DX9_WRITEMASK_ALL = 0x000F0000; // All Components
|
||||
|
||||
static uint32_t DecodeDestWriteMaskDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & DX9_WRITEMASK_ALL;
|
||||
}
|
||||
|
||||
static RESOURCE_DIMENSION DecodeTextureTypeMaskDX9(const uint32_t ui32Token)
|
||||
{
|
||||
|
||||
switch(ui32Token & 0x78000000)
|
||||
{
|
||||
case 2 << 27:
|
||||
return RESOURCE_DIMENSION_TEXTURE2D;
|
||||
case 3 << 27:
|
||||
return RESOURCE_DIMENSION_TEXTURECUBE;
|
||||
case 4 << 27:
|
||||
return RESOURCE_DIMENSION_TEXTURE3D;
|
||||
default:
|
||||
return RESOURCE_DIMENSION_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const uint32_t DESTMOD_DX9_NONE = 0;
|
||||
static const uint32_t DESTMOD_DX9_SATURATE = (1 << 20);
|
||||
static const uint32_t DESTMOD_DX9_PARTIALPRECISION = (2 << 20);
|
||||
static const uint32_t DESTMOD_DX9_MSAMPCENTROID = (4 << 20);
|
||||
static uint32_t DecodeDestModifierDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & 0xf00000;
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SRCMOD_DX9_NONE = 0 << 24,
|
||||
SRCMOD_DX9_NEG = 1 << 24,
|
||||
SRCMOD_DX9_BIAS = 2 << 24,
|
||||
SRCMOD_DX9_BIASNEG = 3 << 24,
|
||||
SRCMOD_DX9_SIGN = 4 << 24,
|
||||
SRCMOD_DX9_SIGNNEG = 5 << 24,
|
||||
SRCMOD_DX9_COMP = 6 << 24,
|
||||
SRCMOD_DX9_X2 = 7 << 24,
|
||||
SRCMOD_DX9_X2NEG = 8 << 24,
|
||||
SRCMOD_DX9_DZ = 9 << 24,
|
||||
SRCMOD_DX9_DW = 10 << 24,
|
||||
SRCMOD_DX9_ABS = 11 << 24,
|
||||
SRCMOD_DX9_ABSNEG = 12 << 24,
|
||||
SRCMOD_DX9_NOT = 13 << 24,
|
||||
SRCMOD_DX9_FORCE_DWORD = 0xffffffff
|
||||
} SRCMOD_DX9;
|
||||
static uint32_t DecodeSrcModifierDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return ui32Token & 0xf000000;
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
D3DSPC_RESERVED0 = 0,
|
||||
D3DSPC_GT = 1,
|
||||
D3DSPC_EQ = 2,
|
||||
D3DSPC_GE = 3,
|
||||
D3DSPC_LT = 4,
|
||||
D3DSPC_NE = 5,
|
||||
D3DSPC_LE = 6,
|
||||
D3DSPC_BOOLEAN = 7, //Make use of the RESERVED1 bit to indicate if-bool opcode.
|
||||
} COMPARISON_DX9;
|
||||
|
||||
static COMPARISON_DX9 DecodeComparisonDX9(const uint32_t ui32Token)
|
||||
{
|
||||
return (COMPARISON_DX9)((ui32Token & (0x07<<16))>>16);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,54 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
if (PAL_TRAIT_BUILD_HOST_TOOLS)
|
||||
|
||||
ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME})
|
||||
|
||||
include(${pal_dir}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
|
||||
if (NOT PAL_TRAIT_BUILD_HLSLCC_METAL)
|
||||
return()
|
||||
endif()
|
||||
|
||||
ly_add_target(
|
||||
NAME HLSLcc_Metal EXECUTABLE
|
||||
NAMESPACE AZ
|
||||
OUTPUT_NAME HLSLcc
|
||||
OUTPUT_SUBDIRECTORY Compiler/PCGMETAL/HLSLcc
|
||||
FILES_CMAKE
|
||||
hlslcc_metal_files.cmake
|
||||
INCLUDE_DIRECTORIES
|
||||
PRIVATE
|
||||
include
|
||||
src
|
||||
src/cbstring
|
||||
offline/cjson
|
||||
BUILD_DEPENDENCIES
|
||||
PRIVATE
|
||||
AZ::AzCore
|
||||
)
|
||||
ly_add_source_properties(
|
||||
SOURCES
|
||||
offline/compilerStandalone.cpp
|
||||
offline/cjson/cJSON.c
|
||||
src/toGLSL.c
|
||||
src/toGLSLDeclaration.c
|
||||
src/cbstring/bstrlib.c
|
||||
src/cbstring/bstraux.c
|
||||
src/reflect.c
|
||||
src/decode.c
|
||||
src/toMETAL.c
|
||||
src/toMETALDeclaration.c
|
||||
PROPERTY COMPILE_DEFINITIONS
|
||||
VALUES _CRT_SECURE_NO_WARNINGS
|
||||
)
|
||||
|
||||
endif()
|
||||
@ -1,12 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_BUILD_HLSLCC_METAL FALSE)
|
||||
@ -1,12 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_BUILD_HLSLCC_METAL FALSE)
|
||||
@ -1,12 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(PAL_TRAIT_BUILD_HLSLCC_METAL TRUE)
|
||||
@ -1,52 +0,0 @@
|
||||
What does this software do?
|
||||
Cross compiles HLSL bytecode to GLSL or GLSL ES. It also provides functions to
|
||||
decode the reflection information embedded in HLSL bytecode. Both offline and online compiliation
|
||||
is supported.
|
||||
|
||||
Supported bytecode formats:
|
||||
cs_4_0 cs_4_1 cs_5_0
|
||||
ds_5_0
|
||||
hs_5_0
|
||||
gs_4_0 gs_4_1 gs_5_0
|
||||
ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3 ps_4_0_level_9_0 ps_4_1 ps_5_0
|
||||
vs_4_0_level_9_3 vs_4_0_level_9_0 vs_4_1 vs_5_0
|
||||
|
||||
Work is underway to support the DX9 bytecode formats:
|
||||
ps_2_0 ps_2_a ps_2_b ps_3_0
|
||||
vs_1_1 vs_2_0 vs_2_a vs_3_0
|
||||
|
||||
Supported target languages:
|
||||
GLSL ES 100
|
||||
GLSL ES 300
|
||||
GLSL ES 310
|
||||
GLSL 120
|
||||
GLSL 130
|
||||
GLSL 140
|
||||
GLSL 150
|
||||
GLSL 330
|
||||
GLSL 400
|
||||
GLSL 410
|
||||
GLSL 420
|
||||
GLSL 430
|
||||
GLSL 440
|
||||
METAL
|
||||
|
||||
I have plans to add support for more target languages including:
|
||||
ARB assembly (ARB_vertex_program et al.)
|
||||
NVIDIA assembly (NV_vertex_program et al.)
|
||||
|
||||
If the source shader contains instructions not support by the target language then compilation is allowed
|
||||
to fail at the GLSL compile stage, i.e. the cross compiler may not generate errors/warnings but an OpenGL
|
||||
driver will reject the shader.
|
||||
|
||||
The tests directory contains HLSL, bytecode and asm versions of some shaders used to verify this decoder.
|
||||
There are also a few sample applications used to make sure that generated GLSL is correct.
|
||||
|
||||
A cmake makefile can be found in the mk directory.
|
||||
|
||||
Generating hlsl_opcode_funcs_glsl.h
|
||||
Use fwrap.py -f hlsl_opcode_funcs.glsl
|
||||
fwrap.py can be found in my Helpful-scripts github repository.
|
||||
|
||||
For further information please see the Wiki page for this project at
|
||||
https://github.com/James-Jones/HLSLCrossCompiler/wiki.
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:35285dbf53617bf58f22035bb502d0b3328678344245635de578c2e73d484d04
|
||||
size 216064
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:99f686d3fc04c80f3460e6d35507acb09f5975f7c4d5e5cae95834e48a46898a
|
||||
size 462848
|
||||
@ -1,65 +0,0 @@
|
||||
#
|
||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
# its licensors.
|
||||
#
|
||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||
# distribution (the "License"). All use of this software is governed by the License,
|
||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
include/hlslcc.h
|
||||
include/hlslcc.hpp
|
||||
include/pstdint.h
|
||||
include/hlslcc_bin.hpp
|
||||
offline/hash.h
|
||||
offline/serializeReflection.h
|
||||
offline/timer.h
|
||||
offline/compilerStandalone.cpp
|
||||
offline/serializeReflection.cpp
|
||||
offline/timer.cpp
|
||||
offline/cjson/cJSON.h
|
||||
offline/cjson/cJSON.c
|
||||
src/decode.c
|
||||
src/decodeDX9.c
|
||||
src/reflect.c
|
||||
src/toGLSL.c
|
||||
src/toMETAL.c
|
||||
src/toMETALDeclaration.c
|
||||
src/toMETALInstruction.c
|
||||
src/toMETALOperand.c
|
||||
src/toGLSLDeclaration.c
|
||||
src/toGLSLInstruction.c
|
||||
src/toGLSLOperand.c
|
||||
src/internal_includes/debug.h
|
||||
src/internal_includes/decode.h
|
||||
src/internal_includes/hlslcc_malloc.h
|
||||
src/internal_includes/hlslcc_malloc.c
|
||||
src/internal_includes/languages.h
|
||||
src/internal_includes/reflect.h
|
||||
src/internal_includes/shaderLimits.h
|
||||
src/internal_includes/structs.h
|
||||
src/internal_includes/toMETALDeclaration.h
|
||||
src/internal_includes/toMETALInstruction.h
|
||||
src/internal_includes/toMETALOperand.h
|
||||
src/internal_includes/toGLSLDeclaration.h
|
||||
src/internal_includes/toGLSLInstruction.h
|
||||
src/internal_includes/toGLSLOperand.h
|
||||
src/internal_includes/tokens.h
|
||||
src/internal_includes/tokensDX9.h
|
||||
src/internal_includes/structsMetal.h
|
||||
src/internal_includes/structsMetal.c
|
||||
src/cbstring/bsafe.h
|
||||
src/cbstring/bstraux.h
|
||||
src/cbstring/bstrlib.h
|
||||
src/cbstring/bsafe.c
|
||||
src/cbstring/bstraux.c
|
||||
src/cbstring/bstrlib.c
|
||||
)
|
||||
|
||||
set(SKIP_UNITY_BUILD_INCLUSION_FILES
|
||||
# 'bsafe.c' tries to forward declar 'strncpy', 'strncat', etc, but they are already declared in other modules. Remove from unity builds conideration
|
||||
src/cbstring/bsafe.c
|
||||
)
|
||||
@ -1,537 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#ifndef HLSLCC_H_
|
||||
#define HLSLCC_H_
|
||||
|
||||
#if defined (_WIN32) && defined(HLSLCC_DYNLIB)
|
||||
#define HLSLCC_APIENTRY __stdcall
|
||||
#if defined(libHLSLcc_EXPORTS)
|
||||
#define HLSLCC_API __declspec(dllexport)
|
||||
#else
|
||||
#define HLSLCC_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define HLSLCC_APIENTRY
|
||||
#define HLSLCC_API
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifndef max
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
#endif //__cplusplus
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LANG_DEFAULT,// Depends on the HLSL shader model.
|
||||
LANG_ES_100,
|
||||
LANG_ES_300,
|
||||
LANG_ES_310,
|
||||
LANG_120,
|
||||
LANG_130,
|
||||
LANG_140,
|
||||
LANG_150,
|
||||
LANG_330,
|
||||
LANG_400,
|
||||
LANG_410,
|
||||
LANG_420,
|
||||
LANG_430,
|
||||
LANG_440,
|
||||
// CONFETTI
|
||||
LANG_METAL,
|
||||
} ShaderLang;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t ARB_explicit_attrib_location : 1;
|
||||
uint32_t ARB_explicit_uniform_location : 1;
|
||||
uint32_t ARB_shading_language_420pack : 1;
|
||||
}GlExtensions;
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_SHADER_VEC4_OUTPUT = 512
|
||||
};
|
||||
enum
|
||||
{
|
||||
MAX_SHADER_VEC4_INPUT = 512
|
||||
};
|
||||
enum
|
||||
{
|
||||
MAX_TEXTURES = 128
|
||||
};
|
||||
enum
|
||||
{
|
||||
MAX_FORK_PHASES = 2
|
||||
};
|
||||
enum
|
||||
{
|
||||
MAX_FUNCTION_BODIES = 1024
|
||||
};
|
||||
enum
|
||||
{
|
||||
MAX_CLASS_TYPES = 1024
|
||||
};
|
||||
enum
|
||||
{
|
||||
MAX_FUNCTION_POINTERS = 128
|
||||
};
|
||||
|
||||
//Reflection
|
||||
#define MAX_REFLECT_STRING_LENGTH 512
|
||||
#define MAX_CBUFFERS 256
|
||||
#define MAX_UAV 256
|
||||
#define MAX_FUNCTION_TABLES 256
|
||||
#define MAX_RESOURCE_BINDINGS 256
|
||||
|
||||
typedef enum SPECIAL_NAME
|
||||
{
|
||||
NAME_UNDEFINED = 0,
|
||||
NAME_POSITION = 1,
|
||||
NAME_CLIP_DISTANCE = 2,
|
||||
NAME_CULL_DISTANCE = 3,
|
||||
NAME_RENDER_TARGET_ARRAY_INDEX = 4,
|
||||
NAME_VIEWPORT_ARRAY_INDEX = 5,
|
||||
NAME_VERTEX_ID = 6,
|
||||
NAME_PRIMITIVE_ID = 7,
|
||||
NAME_INSTANCE_ID = 8,
|
||||
NAME_IS_FRONT_FACE = 9,
|
||||
NAME_SAMPLE_INDEX = 10,
|
||||
// The following are added for D3D11
|
||||
NAME_FINAL_QUAD_U_EQ_0_EDGE_TESSFACTOR = 11,
|
||||
NAME_FINAL_QUAD_V_EQ_0_EDGE_TESSFACTOR = 12,
|
||||
NAME_FINAL_QUAD_U_EQ_1_EDGE_TESSFACTOR = 13,
|
||||
NAME_FINAL_QUAD_V_EQ_1_EDGE_TESSFACTOR = 14,
|
||||
NAME_FINAL_QUAD_U_INSIDE_TESSFACTOR = 15,
|
||||
NAME_FINAL_QUAD_V_INSIDE_TESSFACTOR = 16,
|
||||
NAME_FINAL_TRI_U_EQ_0_EDGE_TESSFACTOR = 17,
|
||||
NAME_FINAL_TRI_V_EQ_0_EDGE_TESSFACTOR = 18,
|
||||
NAME_FINAL_TRI_W_EQ_0_EDGE_TESSFACTOR = 19,
|
||||
NAME_FINAL_TRI_INSIDE_TESSFACTOR = 20,
|
||||
NAME_FINAL_LINE_DETAIL_TESSFACTOR = 21,
|
||||
NAME_FINAL_LINE_DENSITY_TESSFACTOR = 22,
|
||||
} SPECIAL_NAME;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INOUT_COMPONENT_UNKNOWN = 0,
|
||||
INOUT_COMPONENT_UINT32 = 1,
|
||||
INOUT_COMPONENT_SINT32 = 2,
|
||||
INOUT_COMPONENT_FLOAT32 = 3
|
||||
} INOUT_COMPONENT_TYPE;
|
||||
|
||||
typedef enum MIN_PRECISION
|
||||
{
|
||||
MIN_PRECISION_DEFAULT = 0,
|
||||
MIN_PRECISION_FLOAT_16 = 1,
|
||||
MIN_PRECISION_FLOAT_2_8 = 2,
|
||||
MIN_PRECISION_RESERVED = 3,
|
||||
MIN_PRECISION_SINT_16 = 4,
|
||||
MIN_PRECISION_UINT_16 = 5,
|
||||
MIN_PRECISION_ANY_16 = 0xf0,
|
||||
MIN_PRECISION_ANY_10 = 0xf1
|
||||
} MIN_PRECISION;
|
||||
|
||||
typedef struct InOutSignature_TAG
|
||||
{
|
||||
char SemanticName[MAX_REFLECT_STRING_LENGTH];
|
||||
uint32_t ui32SemanticIndex;
|
||||
SPECIAL_NAME eSystemValueType;
|
||||
INOUT_COMPONENT_TYPE eComponentType;
|
||||
uint32_t ui32Register;
|
||||
uint32_t ui32Mask;
|
||||
uint32_t ui32ReadWriteMask;
|
||||
|
||||
uint32_t ui32Stream;
|
||||
MIN_PRECISION eMinPrec;
|
||||
} InOutSignature;
|
||||
|
||||
typedef enum ResourceType_TAG
|
||||
{
|
||||
RTYPE_CBUFFER,//0
|
||||
RTYPE_TBUFFER,//1
|
||||
RTYPE_TEXTURE,//2
|
||||
RTYPE_SAMPLER,//3
|
||||
RTYPE_UAV_RWTYPED,//4
|
||||
RTYPE_STRUCTURED,//5
|
||||
RTYPE_UAV_RWSTRUCTURED,//6
|
||||
RTYPE_BYTEADDRESS,//7
|
||||
RTYPE_UAV_RWBYTEADDRESS,//8
|
||||
RTYPE_UAV_APPEND_STRUCTURED,//9
|
||||
RTYPE_UAV_CONSUME_STRUCTURED,//10
|
||||
RTYPE_UAV_RWSTRUCTURED_WITH_COUNTER,//11
|
||||
RTYPE_COUNT,
|
||||
} ResourceType;
|
||||
|
||||
typedef enum ResourceGroup_TAG
|
||||
{
|
||||
RGROUP_CBUFFER,
|
||||
RGROUP_TEXTURE,
|
||||
RGROUP_SAMPLER,
|
||||
RGROUP_UAV,
|
||||
RGROUP_COUNT,
|
||||
} ResourceGroup;
|
||||
|
||||
typedef enum UAVBindingArea_TAG
|
||||
{
|
||||
UAVAREA_INVALID,
|
||||
UAVAREA_CBUFFER,
|
||||
UAVAREA_TEXTURE,
|
||||
UAVAREA_COUNT,
|
||||
} UAVBindingArea;
|
||||
|
||||
typedef enum REFLECT_RESOURCE_DIMENSION
|
||||
{
|
||||
REFLECT_RESOURCE_DIMENSION_UNKNOWN = 0,
|
||||
REFLECT_RESOURCE_DIMENSION_BUFFER = 1,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE1D = 2,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE1DARRAY = 3,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2D = 4,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2DARRAY = 5,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2DMS = 6,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE2DMSARRAY = 7,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURE3D = 8,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURECUBE = 9,
|
||||
REFLECT_RESOURCE_DIMENSION_TEXTURECUBEARRAY = 10,
|
||||
REFLECT_RESOURCE_DIMENSION_BUFFEREX = 11,
|
||||
} REFLECT_RESOURCE_DIMENSION;
|
||||
|
||||
typedef struct ResourceBinding_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
ResourceType eType;
|
||||
uint32_t ui32BindPoint;
|
||||
uint32_t ui32BindCount;
|
||||
uint32_t ui32Flags;
|
||||
REFLECT_RESOURCE_DIMENSION eDimension;
|
||||
uint32_t ui32ReturnType;
|
||||
uint32_t ui32NumSamples;
|
||||
UAVBindingArea eBindArea;
|
||||
} ResourceBinding;
|
||||
|
||||
typedef enum _SHADER_VARIABLE_TYPE
|
||||
{
|
||||
SVT_VOID = 0,
|
||||
SVT_BOOL = 1,
|
||||
SVT_INT = 2,
|
||||
SVT_FLOAT = 3,
|
||||
SVT_STRING = 4,
|
||||
SVT_TEXTURE = 5,
|
||||
SVT_TEXTURE1D = 6,
|
||||
SVT_TEXTURE2D = 7,
|
||||
SVT_TEXTURE3D = 8,
|
||||
SVT_TEXTURECUBE = 9,
|
||||
SVT_SAMPLER = 10,
|
||||
SVT_PIXELSHADER = 15,
|
||||
SVT_VERTEXSHADER = 16,
|
||||
SVT_UINT = 19,
|
||||
SVT_UINT8 = 20,
|
||||
SVT_GEOMETRYSHADER = 21,
|
||||
SVT_RASTERIZER = 22,
|
||||
SVT_DEPTHSTENCIL = 23,
|
||||
SVT_BLEND = 24,
|
||||
SVT_BUFFER = 25,
|
||||
SVT_CBUFFER = 26,
|
||||
SVT_TBUFFER = 27,
|
||||
SVT_TEXTURE1DARRAY = 28,
|
||||
SVT_TEXTURE2DARRAY = 29,
|
||||
SVT_RENDERTARGETVIEW = 30,
|
||||
SVT_DEPTHSTENCILVIEW = 31,
|
||||
SVT_TEXTURE2DMS = 32,
|
||||
SVT_TEXTURE2DMSARRAY = 33,
|
||||
SVT_TEXTURECUBEARRAY = 34,
|
||||
SVT_HULLSHADER = 35,
|
||||
SVT_DOMAINSHADER = 36,
|
||||
SVT_INTERFACE_POINTER = 37,
|
||||
SVT_COMPUTESHADER = 38,
|
||||
SVT_DOUBLE = 39,
|
||||
SVT_RWTEXTURE1D = 40,
|
||||
SVT_RWTEXTURE1DARRAY = 41,
|
||||
SVT_RWTEXTURE2D = 42,
|
||||
SVT_RWTEXTURE2DARRAY = 43,
|
||||
SVT_RWTEXTURE3D = 44,
|
||||
SVT_RWBUFFER = 45,
|
||||
SVT_BYTEADDRESS_BUFFER = 46,
|
||||
SVT_RWBYTEADDRESS_BUFFER = 47,
|
||||
SVT_STRUCTURED_BUFFER = 48,
|
||||
SVT_RWSTRUCTURED_BUFFER = 49,
|
||||
SVT_APPEND_STRUCTURED_BUFFER = 50,
|
||||
SVT_CONSUME_STRUCTURED_BUFFER = 51,
|
||||
|
||||
// Partial precision types
|
||||
SVT_FLOAT10 = 53,
|
||||
SVT_FLOAT16 = 54,
|
||||
|
||||
|
||||
SVT_FORCE_DWORD = 0x7fffffff
|
||||
} SHADER_VARIABLE_TYPE;
|
||||
|
||||
typedef enum _SHADER_VARIABLE_CLASS
|
||||
{
|
||||
SVC_SCALAR = 0,
|
||||
SVC_VECTOR = (SVC_SCALAR + 1),
|
||||
SVC_MATRIX_ROWS = (SVC_VECTOR + 1),
|
||||
SVC_MATRIX_COLUMNS = (SVC_MATRIX_ROWS + 1),
|
||||
SVC_OBJECT = (SVC_MATRIX_COLUMNS + 1),
|
||||
SVC_STRUCT = (SVC_OBJECT + 1),
|
||||
SVC_INTERFACE_CLASS = (SVC_STRUCT + 1),
|
||||
SVC_INTERFACE_POINTER = (SVC_INTERFACE_CLASS + 1),
|
||||
SVC_FORCE_DWORD = 0x7fffffff
|
||||
} SHADER_VARIABLE_CLASS;
|
||||
|
||||
typedef struct ShaderVarType_TAG
|
||||
{
|
||||
SHADER_VARIABLE_CLASS Class;
|
||||
SHADER_VARIABLE_TYPE Type;
|
||||
uint32_t Rows;
|
||||
uint32_t Columns;
|
||||
uint32_t Elements;
|
||||
uint32_t MemberCount;
|
||||
uint32_t Offset;
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
|
||||
uint32_t ParentCount;
|
||||
struct ShaderVarType_TAG* Parent;
|
||||
//Includes all parent names.
|
||||
char FullName[MAX_REFLECT_STRING_LENGTH];
|
||||
|
||||
struct ShaderVarType_TAG* Members;
|
||||
} ShaderVarType;
|
||||
|
||||
typedef struct ShaderVar_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
int haveDefaultValue;
|
||||
uint32_t* pui32DefaultValues;
|
||||
//Offset/Size in bytes.
|
||||
uint32_t ui32StartOffset;
|
||||
uint32_t ui32Size;
|
||||
|
||||
ShaderVarType sType;
|
||||
} ShaderVar;
|
||||
|
||||
typedef struct ConstantBuffer_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
|
||||
uint32_t ui32NumVars;
|
||||
ShaderVar* asVars;
|
||||
|
||||
uint32_t ui32TotalSizeInBytes;
|
||||
int blob; // Used with dynamic indexed const. buffers
|
||||
} ConstantBuffer;
|
||||
|
||||
typedef struct ClassType_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
uint16_t ui16ID;
|
||||
uint16_t ui16ConstBufStride;
|
||||
uint16_t ui16Texture;
|
||||
uint16_t ui16Sampler;
|
||||
} ClassType;
|
||||
|
||||
typedef struct ClassInstance_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
uint16_t ui16ID;
|
||||
uint16_t ui16ConstBuf;
|
||||
uint16_t ui16ConstBufOffset;
|
||||
uint16_t ui16Texture;
|
||||
uint16_t ui16Sampler;
|
||||
} ClassInstance;
|
||||
|
||||
typedef enum TESSELLATOR_PARTITIONING
|
||||
{
|
||||
TESSELLATOR_PARTITIONING_UNDEFINED = 0,
|
||||
TESSELLATOR_PARTITIONING_INTEGER = 1,
|
||||
TESSELLATOR_PARTITIONING_POW2 = 2,
|
||||
TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3,
|
||||
TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4
|
||||
} TESSELLATOR_PARTITIONING;
|
||||
|
||||
typedef enum TESSELLATOR_OUTPUT_PRIMITIVE
|
||||
{
|
||||
TESSELLATOR_OUTPUT_UNDEFINED = 0,
|
||||
TESSELLATOR_OUTPUT_POINT = 1,
|
||||
TESSELLATOR_OUTPUT_LINE = 2,
|
||||
TESSELLATOR_OUTPUT_TRIANGLE_CW = 3,
|
||||
TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4
|
||||
} TESSELLATOR_OUTPUT_PRIMITIVE;
|
||||
|
||||
typedef struct TextureSamplerPair_TAG
|
||||
{
|
||||
char Name[MAX_REFLECT_STRING_LENGTH];
|
||||
} TextureSamplerPair;
|
||||
|
||||
typedef struct TextureSamplerInfo_TAG
|
||||
{
|
||||
uint32_t ui32NumTextureSamplerPairs;
|
||||
TextureSamplerPair aTextureSamplerPair[MAX_RESOURCE_BINDINGS];
|
||||
} TextureSamplerInfo;
|
||||
|
||||
typedef struct ShaderInfo_TAG
|
||||
{
|
||||
uint32_t ui32MajorVersion;
|
||||
uint32_t ui32MinorVersion;
|
||||
|
||||
uint32_t ui32NumInputSignatures;
|
||||
InOutSignature* psInputSignatures;
|
||||
|
||||
uint32_t ui32NumOutputSignatures;
|
||||
InOutSignature* psOutputSignatures;
|
||||
|
||||
uint32_t ui32NumPatchConstantSignatures;
|
||||
InOutSignature* psPatchConstantSignatures;
|
||||
|
||||
uint32_t ui32NumResourceBindings;
|
||||
ResourceBinding* psResourceBindings;
|
||||
|
||||
uint32_t ui32NumConstantBuffers;
|
||||
ConstantBuffer* psConstantBuffers;
|
||||
ConstantBuffer* psThisPointerConstBuffer;
|
||||
|
||||
uint32_t ui32NumClassTypes;
|
||||
ClassType* psClassTypes;
|
||||
|
||||
uint32_t ui32NumClassInstances;
|
||||
ClassInstance* psClassInstances;
|
||||
|
||||
//Func table ID to class name ID.
|
||||
uint32_t aui32TableIDToTypeID[MAX_FUNCTION_TABLES];
|
||||
|
||||
uint32_t aui32ResourceMap[RGROUP_COUNT][MAX_RESOURCE_BINDINGS];
|
||||
|
||||
// Texture index to sampler slot
|
||||
uint32_t aui32SamplerMap[MAX_RESOURCE_BINDINGS];
|
||||
|
||||
TESSELLATOR_PARTITIONING eTessPartitioning;
|
||||
TESSELLATOR_OUTPUT_PRIMITIVE eTessOutPrim;
|
||||
|
||||
//compute shader thread number
|
||||
uint32_t ui32Thread_x;
|
||||
uint32_t ui32Thread_y;
|
||||
uint32_t ui32Thread_z;
|
||||
} ShaderInfo;
|
||||
|
||||
typedef enum INTERPOLATION_MODE
|
||||
{
|
||||
INTERPOLATION_UNDEFINED = 0,
|
||||
INTERPOLATION_CONSTANT = 1,
|
||||
INTERPOLATION_LINEAR = 2,
|
||||
INTERPOLATION_LINEAR_CENTROID = 3,
|
||||
INTERPOLATION_LINEAR_NOPERSPECTIVE = 4,
|
||||
INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID = 5,
|
||||
INTERPOLATION_LINEAR_SAMPLE = 6,
|
||||
INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE = 7,
|
||||
} INTERPOLATION_MODE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int shaderType; //One of the GL enums.
|
||||
char* sourceCode;
|
||||
ShaderInfo reflection;
|
||||
ShaderLang GLSLLanguage;
|
||||
TextureSamplerInfo textureSamplerInfo; // HLSLCC_FLAG_COMBINE_TEXTURE_SAMPLERS fills this out
|
||||
} Shader;
|
||||
|
||||
// NOTE: HLSLCC flags are specified by command line when executing this cross compiler.
|
||||
// If these flags change, the command line switch '-flags=XXX' must change as well.
|
||||
// Open 3D Engine composes the command line in file 'dev\Code\CryEngine\RenderDll\Common\Shaders\RemoteCompiler.cpp'
|
||||
|
||||
/*HLSL constant buffers are treated as default-block unform arrays by default. This is done
|
||||
to support versions of GLSL which lack ARB_uniform_buffer_object functionality.
|
||||
Setting this flag causes each one to have its own uniform block.
|
||||
Note: Currently the nth const buffer will be named UnformBufferN. This is likey to change to the original HLSL name in the future.*/
|
||||
static const unsigned int HLSLCC_FLAG_UNIFORM_BUFFER_OBJECT = 0x1;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_ORIGIN_UPPER_LEFT = 0x2;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_PIXEL_CENTER_INTEGER = 0x4;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_GLOBAL_CONSTS_NEVER_IN_UBO = 0x8;
|
||||
|
||||
//GS enabled?
|
||||
//Affects vertex shader (i.e. need to compile vertex shader again to use with/without GS).
|
||||
//This flag is needed in order for the interfaces between stages to match when GS is in use.
|
||||
//PS inputs VtxGeoOutput
|
||||
//GS outputs VtxGeoOutput
|
||||
//Vs outputs VtxOutput if GS enabled. VtxGeoOutput otherwise.
|
||||
static const unsigned int HLSLCC_FLAG_GS_ENABLED = 0x10;
|
||||
|
||||
static const unsigned int HLSLCC_FLAG_TESS_ENABLED = 0x20;
|
||||
|
||||
//Either use this flag or glBindFragDataLocationIndexed.
|
||||
//When set the first pixel shader output is the first input to blend
|
||||
//equation, the others go to the second input.
|
||||
static const unsigned int HLSLCC_FLAG_DUAL_SOURCE_BLENDING = 0x40;
|
||||
|
||||
//If set, shader inputs and outputs are declared with their semantic name.
|
||||
static const unsigned int HLSLCC_FLAG_INOUT_SEMANTIC_NAMES = 0x80;
|
||||
//If set, shader inputs and outputs are declared with their semantic name appended.
|
||||
static const unsigned int HLSLCC_FLAG_INOUT_APPEND_SEMANTIC_NAMES = 0x100;
|
||||
|
||||
//If set, combines texture/sampler pairs used together into samplers named "texturename_X_samplername".
|
||||
static const unsigned int HLSLCC_FLAG_COMBINE_TEXTURE_SAMPLERS = 0x200;
|
||||
|
||||
//If set, attribute and uniform explicit location qualifiers are disabled (even if the language version supports that)
|
||||
static const unsigned int HLSLCC_FLAG_DISABLE_EXPLICIT_LOCATIONS = 0x400;
|
||||
|
||||
//If set, global uniforms are not stored in a struct.
|
||||
static const unsigned int HLSLCC_FLAG_DISABLE_GLOBALS_STRUCT = 0x800;
|
||||
|
||||
// If set, HLSL DX9 lower precision qualifiers (e.g half) will be transformed to DX11 style (e.g min16float)
|
||||
// before compiling. Necessary to preserve precision information. If not, FXC just silently transform
|
||||
// everything to full precision (e.g float32).
|
||||
static const unsigned int HLSLCC_FLAG_HALF_FLOAT_TRANSFORM = 0x40000;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
HLSLCC_API void HLSLCC_APIENTRY HLSLcc_SetMemoryFunctions(void* (*malloc_override)(size_t),
|
||||
void* (*calloc_override)(size_t, size_t),
|
||||
void (* free_override)(void*),
|
||||
void* (*realloc_override)(void*, size_t));
|
||||
|
||||
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromFileToGLSL(const char* filename,
|
||||
unsigned int flags,
|
||||
ShaderLang language,
|
||||
const GlExtensions* extensions,
|
||||
Shader* result
|
||||
);
|
||||
|
||||
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromMemToGLSL(const char* shader,
|
||||
unsigned int flags,
|
||||
ShaderLang language,
|
||||
const GlExtensions* extensions,
|
||||
Shader* result);
|
||||
|
||||
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromFileToMETAL(const char* filename,
|
||||
unsigned int flags,
|
||||
ShaderLang language,
|
||||
Shader* result
|
||||
);
|
||||
|
||||
HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromMemToMETAL(const char* shader,
|
||||
unsigned int flags,
|
||||
ShaderLang language,
|
||||
Shader* result);
|
||||
|
||||
|
||||
HLSLCC_API void HLSLCC_APIENTRY FreeShader(Shader*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
extern "C" {
|
||||
#include "hlslcc.h"
|
||||
}
|
||||
|
||||
@ -1,448 +0,0 @@
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
// Modifications copyright Crytek GmbH
|
||||
|
||||
#define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24))
|
||||
|
||||
enum
|
||||
{
|
||||
DXBC_BASE_ALIGNMENT = 4,
|
||||
FOURCC_DXBC = FOURCC('D', 'X', 'B', 'C'),
|
||||
FOURCC_RDEF = FOURCC('R', 'D', 'E', 'F'),
|
||||
FOURCC_ISGN = FOURCC('I', 'S', 'G', 'N'),
|
||||
FOURCC_OSGN = FOURCC('O', 'S', 'G', 'N'),
|
||||
FOURCC_PCSG = FOURCC('P', 'C', 'S', 'G'),
|
||||
FOURCC_SHDR = FOURCC('S', 'H', 'D', 'R'),
|
||||
FOURCC_SHEX = FOURCC('S', 'H', 'E', 'X'),
|
||||
FOURCC_GLSL = FOURCC('G', 'L', 'S', 'L'),
|
||||
FOURCC_ISG1 = FOURCC('I', 'S', 'G', '1'), // When lower precision float/int/uint is used
|
||||
FOURCC_OSG1 = FOURCC('O', 'S', 'G', '1'), // When lower precision float/int/uint is used
|
||||
};
|
||||
|
||||
#undef FOURCC
|
||||
|
||||
template <typename T>
|
||||
inline T DXBCSwapBytes(const T& kValue)
|
||||
{
|
||||
return kValue;
|
||||
}
|
||||
|
||||
#if defined(__BIG_ENDIAN__) || SYSTEM_IS_BIG_ENDIAN
|
||||
|
||||
inline uint16_t DXBCSwapBytes(const uint16_t& uValue)
|
||||
{
|
||||
return
|
||||
(((uValue) >> 8) & 0xFF) |
|
||||
(((uValue) << 8) & 0xFF);
|
||||
}
|
||||
|
||||
inline uint32_t DXBCSwapBytes(const uint32_t& uValue)
|
||||
{
|
||||
return
|
||||
(((uValue) >> 24) & 0x000000FF) |
|
||||
(((uValue) >> 8) & 0x0000FF00) |
|
||||
(((uValue) << 8) & 0x00FF0000) |
|
||||
(((uValue) << 24) & 0xFF000000);
|
||||
}
|
||||
|
||||
#endif //defined(__BIG_ENDIAN__) || SYSTEM_IS_BIG_ENDIAN
|
||||
|
||||
template <typename Element>
|
||||
struct SDXBCBufferBase
|
||||
{
|
||||
Element* m_pBegin;
|
||||
Element* m_pEnd;
|
||||
Element* m_pIter;
|
||||
|
||||
SDXBCBufferBase(Element* pBegin, Element* pEnd)
|
||||
: m_pBegin(pBegin)
|
||||
, m_pEnd(pEnd)
|
||||
, m_pIter(pBegin)
|
||||
{
|
||||
}
|
||||
|
||||
bool SeekRel(int32_t iOffset)
|
||||
{
|
||||
Element* pIterAfter(m_pIter + iOffset);
|
||||
if (pIterAfter > m_pEnd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SeekAbs(uint32_t uPosition)
|
||||
{
|
||||
Element* pIterAfter(m_pBegin + uPosition);
|
||||
if (pIterAfter > m_pEnd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct SDXBCInputBuffer
|
||||
: SDXBCBufferBase<const uint8_t>
|
||||
{
|
||||
SDXBCInputBuffer(const uint8_t* pBegin, const uint8_t* pEnd)
|
||||
: SDXBCBufferBase(pBegin, pEnd)
|
||||
{
|
||||
}
|
||||
|
||||
bool Read(void* pElements, size_t uSize)
|
||||
{
|
||||
const uint8_t* pIterAfter(m_pIter + uSize);
|
||||
if (pIterAfter > m_pEnd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(pElements, m_pIter, uSize);
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct SDXBCOutputBuffer
|
||||
: SDXBCBufferBase<uint8_t>
|
||||
{
|
||||
SDXBCOutputBuffer(uint8_t* pBegin, uint8_t* pEnd)
|
||||
: SDXBCBufferBase(pBegin, pEnd)
|
||||
{
|
||||
}
|
||||
|
||||
bool Write(const void* pElements, size_t uSize)
|
||||
{
|
||||
uint8_t* pIterAfter(m_pIter + uSize);
|
||||
if (pIterAfter > m_pEnd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(m_pIter, pElements, uSize);
|
||||
|
||||
m_pIter = pIterAfter;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename S, typename External, typename Internal>
|
||||
inline bool DXBCReadAs(S& kStream, External& kValue)
|
||||
{
|
||||
Internal kInternal;
|
||||
bool bResult(kStream.Read(&kInternal, sizeof(Internal)));
|
||||
kValue = static_cast<External>(DXBCSwapBytes(kInternal));
|
||||
return bResult;
|
||||
}
|
||||
|
||||
template <typename S, typename Internal>
|
||||
inline bool DXBCWriteAs(S& kStream, Internal kValue)
|
||||
{
|
||||
Internal kInternal(DXBCSwapBytes(kValue));
|
||||
return kStream.Write(&kInternal, sizeof(Internal));
|
||||
}
|
||||
|
||||
template <typename S, typename T>
|
||||
bool DXBCReadUint8 (S& kStream, T& kValue) { return DXBCReadAs<S, T, uint8_t >(kStream, kValue); }
|
||||
template <typename S, typename T>
|
||||
bool DXBCReadUint16(S& kStream, T& kValue) { return DXBCReadAs<S, T, uint16_t>(kStream, kValue); }
|
||||
template <typename S, typename T>
|
||||
bool DXBCReadUint32(S& kStream, T& kValue) { return DXBCReadAs<S, T, uint32_t>(kStream, kValue); }
|
||||
|
||||
template <typename S>
|
||||
bool DXBCWriteUint8 (S& kStream, uint8_t kValue) { return DXBCWriteAs<S, uint8_t >(kStream, kValue); }
|
||||
template <typename S>
|
||||
bool DXBCWriteUint16(S& kStream, uint16_t kValue) { return DXBCWriteAs<S, uint16_t>(kStream, kValue); }
|
||||
template <typename S>
|
||||
bool DXBCWriteUint32(S& kStream, uint32_t kValue) { return DXBCWriteAs<S, uint32_t>(kStream, kValue); }
|
||||
|
||||
template <typename O, typename I>
|
||||
bool DXBCCopy(O& kOutput, I& kInput, size_t uSize)
|
||||
{
|
||||
char acBuffer[1024];
|
||||
while (uSize > 0)
|
||||
{
|
||||
size_t uToCopy(std::min<size_t>(uSize, sizeof(acBuffer)));
|
||||
if (!kInput.Read(acBuffer, uToCopy) ||
|
||||
!kOutput.Write(acBuffer, uToCopy))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uSize -= uToCopy;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
DXBC_SIZE_POSITION = 6 * 4,
|
||||
DXBC_HEADER_SIZE = 7 * 4,
|
||||
DXBC_CHUNK_HEADER_SIZE = 2 * 4,
|
||||
DXBC_MAX_NUM_CHUNKS_IN = 128,
|
||||
DXBC_MAX_NUM_CHUNKS_OUT = 8,
|
||||
DXBC_OUT_CHUNKS_INDEX_SIZE = (1 + 1 + DXBC_MAX_NUM_CHUNKS_OUT) * 4,
|
||||
DXBC_OUT_FIXED_SIZE = DXBC_HEADER_SIZE + DXBC_OUT_CHUNKS_INDEX_SIZE,
|
||||
};
|
||||
|
||||
inline void DXBCSizeGLSLChunk(uint32_t& uGLSLChunkSize, uint32_t& uNumSamplers, uint32_t& uGLSLSourceSize, const Shader* pShader)
|
||||
{
|
||||
enum
|
||||
{
|
||||
GLSL_HEADER_SIZE = 4 * 8, // {uint32 uNumSamplers; uint32 uNumImports; uint32 uNumExports; uint32 uInputHash;uint32 uResources; uint32 ui32Thread_x; uint32 ui32Thread_y; uint32 ui32Thread_z}
|
||||
GLSL_SAMPLER_SIZE = 4 * 2, // {uint32 uTexture; uint32 uSampler;}
|
||||
GLSL_SYMBOL_SIZE = 4 * 3, // {uint32 uType; uint32 uID; uint32 uValue}
|
||||
//extend for metal compute UAV type
|
||||
GLSL_UAV_RESOURCES_AREA = 4 * 2, //{uint32 uResource; uint32 eBindArea}
|
||||
};
|
||||
|
||||
// Only texture registers that are used are written
|
||||
uNumSamplers = 0;
|
||||
for (uint32_t uTexture = 0; uTexture < MAX_RESOURCE_BINDINGS; ++uTexture)
|
||||
{
|
||||
if (pShader->reflection.aui32SamplerMap[uTexture] != MAX_RESOURCE_BINDINGS)
|
||||
{
|
||||
++uNumSamplers;
|
||||
}
|
||||
}
|
||||
|
||||
//uint32_t uNumSymbols(
|
||||
// pShader->reflection.ui32NumImports +
|
||||
// pShader->reflection.ui32NumExports);
|
||||
uint32_t uNumSymbols(0); // always 0
|
||||
uint32_t uNumResources(pShader->reflection.ui32NumResourceBindings);
|
||||
|
||||
uint32_t uGLSLInfoSize(
|
||||
DXBC_CHUNK_HEADER_SIZE +
|
||||
GLSL_HEADER_SIZE +
|
||||
uNumSamplers * GLSL_SAMPLER_SIZE +
|
||||
uNumSymbols * GLSL_SYMBOL_SIZE +
|
||||
uNumResources * GLSL_UAV_RESOURCES_AREA
|
||||
);
|
||||
uGLSLSourceSize = (uint32_t)strlen(pShader->sourceCode) + 1;
|
||||
uGLSLChunkSize = uGLSLInfoSize + uGLSLSourceSize;
|
||||
uGLSLChunkSize += DXBC_BASE_ALIGNMENT - 1 - (uGLSLChunkSize - 1) % DXBC_BASE_ALIGNMENT;
|
||||
}
|
||||
|
||||
inline uint32_t DXBCSizeOutputChunk(uint32_t uCode, uint32_t uSizeIn)
|
||||
{
|
||||
uint32_t uSizeOut;
|
||||
switch (uCode)
|
||||
{
|
||||
case FOURCC_RDEF:
|
||||
case FOURCC_ISGN:
|
||||
case FOURCC_OSGN:
|
||||
case FOURCC_PCSG:
|
||||
case FOURCC_OSG1:
|
||||
case FOURCC_ISG1:
|
||||
// Preserve entire chunk
|
||||
uSizeOut = uSizeIn;
|
||||
break;
|
||||
case FOURCC_SHDR:
|
||||
case FOURCC_SHEX:
|
||||
// Only keep the shader version
|
||||
uSizeOut = uSizeIn < 4u ? uSizeIn : 4u;
|
||||
break;
|
||||
default:
|
||||
// Discard the chunk
|
||||
uSizeOut = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return uSizeOut + DXBC_BASE_ALIGNMENT - 1 - (uSizeOut - 1) % DXBC_BASE_ALIGNMENT;
|
||||
}
|
||||
|
||||
template <typename I>
|
||||
size_t DXBCGetCombinedSize(I& kDXBCInput, const Shader* pShader)
|
||||
{
|
||||
uint32_t uNumChunksIn;
|
||||
if (!kDXBCInput.SeekAbs(DXBC_HEADER_SIZE) ||
|
||||
!DXBCReadUint32(kDXBCInput, uNumChunksIn))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t auChunkOffsetsIn[DXBC_MAX_NUM_CHUNKS_IN];
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
|
||||
{
|
||||
if (!DXBCReadUint32(kDXBCInput, auChunkOffsetsIn[uChunk]))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t uNumChunksOut(0);
|
||||
uint32_t uOutSize(DXBC_OUT_FIXED_SIZE);
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn && uNumChunksOut < DXBC_MAX_NUM_CHUNKS_OUT; ++uChunk)
|
||||
{
|
||||
uint32_t uChunkCode, uChunkSizeIn;
|
||||
if (!kDXBCInput.SeekAbs(auChunkOffsetsIn[uChunk]) ||
|
||||
!DXBCReadUint32(kDXBCInput, uChunkCode) ||
|
||||
!DXBCReadUint32(kDXBCInput, uChunkSizeIn))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t uChunkSizeOut(DXBCSizeOutputChunk(uChunkCode, uChunkSizeIn));
|
||||
if (uChunkSizeOut > 0)
|
||||
{
|
||||
uOutSize += DXBC_CHUNK_HEADER_SIZE + uChunkSizeOut;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t uNumSamplers, uGLSLSourceSize, uGLSLChunkSize;
|
||||
DXBCSizeGLSLChunk(uGLSLChunkSize, uNumSamplers, uGLSLSourceSize, pShader);
|
||||
uOutSize += uGLSLChunkSize;
|
||||
|
||||
return uOutSize;
|
||||
}
|
||||
|
||||
template <typename I, typename O>
|
||||
bool DXBCCombineWithGLSL(I& kInput, O& kOutput, const Shader* pShader)
|
||||
{
|
||||
uint32_t uNumChunksIn;
|
||||
if (!DXBCCopy(kOutput, kInput, DXBC_HEADER_SIZE) ||
|
||||
!DXBCReadUint32(kInput, uNumChunksIn) ||
|
||||
uNumChunksIn > DXBC_MAX_NUM_CHUNKS_IN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t auChunkOffsetsIn[DXBC_MAX_NUM_CHUNKS_IN];
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
|
||||
{
|
||||
if (!DXBCReadUint32(kInput, auChunkOffsetsIn[uChunk]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t auZeroChunkIndex[DXBC_OUT_CHUNKS_INDEX_SIZE] = {0};
|
||||
if (!kOutput.Write(auZeroChunkIndex, DXBC_OUT_CHUNKS_INDEX_SIZE))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy required input chunks just after the chunk index
|
||||
uint32_t uOutSize(DXBC_OUT_FIXED_SIZE);
|
||||
uint32_t uNumChunksOut(0);
|
||||
uint32_t auChunkOffsetsOut[DXBC_MAX_NUM_CHUNKS_OUT];
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksIn; ++uChunk)
|
||||
{
|
||||
uint32_t uChunkCode, uChunkSizeIn;
|
||||
if (!kInput.SeekAbs(auChunkOffsetsIn[uChunk]) ||
|
||||
!DXBCReadUint32(kInput, uChunkCode) ||
|
||||
!DXBCReadUint32(kInput, uChunkSizeIn))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter only input chunks of the specified types
|
||||
uint32_t uChunkSizeOut(DXBCSizeOutputChunk(uChunkCode, uChunkSizeIn));
|
||||
if (uChunkSizeOut > 0)
|
||||
{
|
||||
if (uNumChunksOut >= DXBC_MAX_NUM_CHUNKS_OUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DXBCWriteUint32(kOutput, uChunkCode) ||
|
||||
!DXBCWriteUint32(kOutput, uChunkSizeOut) ||
|
||||
!DXBCCopy(kOutput, kInput, uChunkSizeOut))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auChunkOffsetsOut[uNumChunksOut] = uOutSize;
|
||||
++uNumChunksOut;
|
||||
uOutSize += DXBC_CHUNK_HEADER_SIZE + uChunkSizeOut;
|
||||
}
|
||||
}
|
||||
// Write GLSL chunk
|
||||
uint32_t uGLSLChunkOffset(uOutSize);
|
||||
uint32_t uGLSLChunkSize, uNumSamplers, uGLSLSourceSize;
|
||||
DXBCSizeGLSLChunk(uGLSLChunkSize, uNumSamplers, uGLSLSourceSize, pShader);
|
||||
if (!DXBCWriteUint32(kOutput, (uint32_t)FOURCC_GLSL) ||
|
||||
!DXBCWriteUint32(kOutput, uGLSLChunkSize) ||
|
||||
!DXBCWriteUint32(kOutput, uNumSamplers) ||
|
||||
!DXBCWriteUint32(kOutput, 0) ||
|
||||
!DXBCWriteUint32(kOutput, 0) ||
|
||||
!DXBCWriteUint32(kOutput, 0) ||
|
||||
/*!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumImports) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumExports) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32InputHash)*/
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32NumResourceBindings) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32Thread_x) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32Thread_y) ||
|
||||
!DXBCWriteUint32(kOutput, pShader->reflection.ui32Thread_z))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (uint32_t uTexture = 0; uTexture < MAX_RESOURCE_BINDINGS; ++uTexture)
|
||||
{
|
||||
uint32_t uSampler(pShader->reflection.aui32SamplerMap[uTexture]);
|
||||
if (uSampler != MAX_RESOURCE_BINDINGS)
|
||||
{
|
||||
if (!DXBCWriteUint32(kOutput, uTexture) ||
|
||||
!DXBCWriteUint32(kOutput, uSampler))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//for (uint32_t uSymbol = 0; uSymbol < pShader->reflection.ui32NumImports; ++uSymbol)
|
||||
//{
|
||||
// if (!DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].eType) ||
|
||||
// !DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].ui32ID) ||
|
||||
// !DXBCWriteUint32(kOutput, pShader->reflection.psImports[uSymbol].ui32Value))
|
||||
// return false;
|
||||
//}
|
||||
//for (uint32_t uSymbol = 0; uSymbol < pShader->reflection.ui32NumExports; ++uSymbol)
|
||||
//{
|
||||
// if (!DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].eType) ||
|
||||
// !DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].ui32ID) ||
|
||||
// !DXBCWriteUint32(kOutput, pShader->reflection.psExports[uSymbol].ui32Value))
|
||||
// return false;
|
||||
//}
|
||||
for (uint32_t uResource = 0; uResource < pShader->reflection.ui32NumResourceBindings; ++uResource)
|
||||
{
|
||||
ResourceBinding* rb = pShader->reflection.psResourceBindings + uResource;
|
||||
if (uResource != MAX_RESOURCE_BINDINGS)
|
||||
{
|
||||
if (!DXBCWriteUint32(kOutput, uResource) ||
|
||||
!DXBCWriteUint32(kOutput, rb->eBindArea))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!kOutput.Write(pShader->sourceCode, uGLSLSourceSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uOutSize += uGLSLChunkSize;
|
||||
|
||||
// Write total size and chunk index
|
||||
if (!kOutput.SeekAbs(DXBC_SIZE_POSITION) ||
|
||||
!DXBCWriteUint32(kOutput, uOutSize) ||
|
||||
!kOutput.SeekAbs(DXBC_HEADER_SIZE) ||
|
||||
!DXBCWriteUint32(kOutput, uNumChunksOut + 1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (uint32_t uChunk = 0; uChunk < uNumChunksOut; ++uChunk)
|
||||
{
|
||||
if (!DXBCWriteUint32(kOutput, auChunkOffsetsOut[uChunk]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DXBCWriteUint32(kOutput, uGLSLChunkOffset);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1,801 +0,0 @@
|
||||
/* A portable stdint.h
|
||||
****************************************************************************
|
||||
* BSD License:
|
||||
****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2005-2011 Paul Hsieh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************
|
||||
*
|
||||
* Version 0.1.12
|
||||
*
|
||||
* The ANSI C standard committee, for the C99 standard, specified the
|
||||
* inclusion of a new standard include file called stdint.h. This is
|
||||
* a very useful and long desired include file which contains several
|
||||
* very precise definitions for integer scalar types that is
|
||||
* critically important for making portable several classes of
|
||||
* applications including cryptography, hashing, variable length
|
||||
* integer libraries and so on. But for most developers its likely
|
||||
* useful just for programming sanity.
|
||||
*
|
||||
* The problem is that most compiler vendors have decided not to
|
||||
* implement the C99 standard, and the next C++ language standard
|
||||
* (which has a lot more mindshare these days) will be a long time in
|
||||
* coming and its unknown whether or not it will include stdint.h or
|
||||
* how much adoption it will have. Either way, it will be a long time
|
||||
* before all compilers come with a stdint.h and it also does nothing
|
||||
* for the extremely large number of compilers available today which
|
||||
* do not include this file, or anything comparable to it.
|
||||
*
|
||||
* So that's what this file is all about. Its an attempt to build a
|
||||
* single universal include file that works on as many platforms as
|
||||
* possible to deliver what stdint.h is supposed to. A few things
|
||||
* that should be noted about this file:
|
||||
*
|
||||
* 1) It is not guaranteed to be portable and/or present an identical
|
||||
* interface on all platforms. The extreme variability of the
|
||||
* ANSI C standard makes this an impossibility right from the
|
||||
* very get go. Its really only meant to be useful for the vast
|
||||
* majority of platforms that possess the capability of
|
||||
* implementing usefully and precisely defined, standard sized
|
||||
* integer scalars. Systems which are not intrinsically 2s
|
||||
* complement may produce invalid constants.
|
||||
*
|
||||
* 2) There is an unavoidable use of non-reserved symbols.
|
||||
*
|
||||
* 3) Other standard include files are invoked.
|
||||
*
|
||||
* 4) This file may come in conflict with future platforms that do
|
||||
* include stdint.h. The hope is that one or the other can be
|
||||
* used with no real difference.
|
||||
*
|
||||
* 5) In the current verison, if your platform can't represent
|
||||
* int32_t, int16_t and int8_t, it just dumps out with a compiler
|
||||
* error.
|
||||
*
|
||||
* 6) 64 bit integers may or may not be defined. Test for their
|
||||
* presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
|
||||
* Note that this is different from the C99 specification which
|
||||
* requires the existence of 64 bit support in the compiler. If
|
||||
* this is not defined for your platform, yet it is capable of
|
||||
* dealing with 64 bits then it is because this file has not yet
|
||||
* been extended to cover all of your system's capabilities.
|
||||
*
|
||||
* 7) (u)intptr_t may or may not be defined. Test for its presence
|
||||
* with the test: #ifdef PTRDIFF_MAX. If this is not defined
|
||||
* for your platform, then it is because this file has not yet
|
||||
* been extended to cover all of your system's capabilities, not
|
||||
* because its optional.
|
||||
*
|
||||
* 8) The following might not been defined even if your platform is
|
||||
* capable of defining it:
|
||||
*
|
||||
* WCHAR_MIN
|
||||
* WCHAR_MAX
|
||||
* (u)int64_t
|
||||
* PTRDIFF_MIN
|
||||
* PTRDIFF_MAX
|
||||
* (u)intptr_t
|
||||
*
|
||||
* 9) The following have not been defined:
|
||||
*
|
||||
* WINT_MIN
|
||||
* WINT_MAX
|
||||
*
|
||||
* 10) The criteria for defining (u)int_least(*)_t isn't clear,
|
||||
* except for systems which don't have a type that precisely
|
||||
* defined 8, 16, or 32 bit types (which this include file does
|
||||
* not support anyways). Default definitions have been given.
|
||||
*
|
||||
* 11) The criteria for defining (u)int_fast(*)_t isn't something I
|
||||
* would trust to any particular compiler vendor or the ANSI C
|
||||
* committee. It is well known that "compatible systems" are
|
||||
* commonly created that have very different performance
|
||||
* characteristics from the systems they are compatible with,
|
||||
* especially those whose vendors make both the compiler and the
|
||||
* system. Default definitions have been given, but its strongly
|
||||
* recommended that users never use these definitions for any
|
||||
* reason (they do *NOT* deliver any serious guarantee of
|
||||
* improved performance -- not in this file, nor any vendor's
|
||||
* stdint.h).
|
||||
*
|
||||
* 12) The following macros:
|
||||
*
|
||||
* PRINTF_INTMAX_MODIFIER
|
||||
* PRINTF_INT64_MODIFIER
|
||||
* PRINTF_INT32_MODIFIER
|
||||
* PRINTF_INT16_MODIFIER
|
||||
* PRINTF_LEAST64_MODIFIER
|
||||
* PRINTF_LEAST32_MODIFIER
|
||||
* PRINTF_LEAST16_MODIFIER
|
||||
* PRINTF_INTPTR_MODIFIER
|
||||
*
|
||||
* are strings which have been defined as the modifiers required
|
||||
* for the "d", "u" and "x" printf formats to correctly output
|
||||
* (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
|
||||
* (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
|
||||
* PRINTF_INTPTR_MODIFIER is not defined for some systems which
|
||||
* provide their own stdint.h. PRINTF_INT64_MODIFIER is not
|
||||
* defined if INT64_MAX is not defined. These are an extension
|
||||
* beyond what C99 specifies must be in stdint.h.
|
||||
*
|
||||
* In addition, the following macros are defined:
|
||||
*
|
||||
* PRINTF_INTMAX_HEX_WIDTH
|
||||
* PRINTF_INT64_HEX_WIDTH
|
||||
* PRINTF_INT32_HEX_WIDTH
|
||||
* PRINTF_INT16_HEX_WIDTH
|
||||
* PRINTF_INT8_HEX_WIDTH
|
||||
* PRINTF_INTMAX_DEC_WIDTH
|
||||
* PRINTF_INT64_DEC_WIDTH
|
||||
* PRINTF_INT32_DEC_WIDTH
|
||||
* PRINTF_INT16_DEC_WIDTH
|
||||
* PRINTF_INT8_DEC_WIDTH
|
||||
*
|
||||
* Which specifies the maximum number of characters required to
|
||||
* print the number of that type in either hexadecimal or decimal.
|
||||
* These are an extension beyond what C99 specifies must be in
|
||||
* stdint.h.
|
||||
*
|
||||
* Compilers tested (all with 0 warnings at their highest respective
|
||||
* settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
|
||||
* bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
|
||||
* .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
|
||||
*
|
||||
* This file should be considered a work in progress. Suggestions for
|
||||
* improvements, especially those which increase coverage are strongly
|
||||
* encouraged.
|
||||
*
|
||||
* Acknowledgements
|
||||
*
|
||||
* The following people have made significant contributions to the
|
||||
* development and testing of this file:
|
||||
*
|
||||
* Chris Howie
|
||||
* John Steele Scott
|
||||
* Dave Thorup
|
||||
* John Dill
|
||||
*
|
||||
*/
|
||||
// Modifications copyright Amazon.com, Inc. or its affiliates
|
||||
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
* For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
|
||||
* do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
|
||||
*/
|
||||
|
||||
#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_) || defined (__UINT_FAST64_TYPE__)) )) && !defined (_PSTDINT_H_INCLUDED)
|
||||
#include <stdint.h>
|
||||
#define _PSTDINT_H_INCLUDED
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INT64_HEX_WIDTH
|
||||
# define PRINTF_INT64_HEX_WIDTH "16"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_HEX_WIDTH
|
||||
# define PRINTF_INT32_HEX_WIDTH "8"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_HEX_WIDTH
|
||||
# define PRINTF_INT16_HEX_WIDTH "4"
|
||||
# endif
|
||||
# ifndef PRINTF_INT8_HEX_WIDTH
|
||||
# define PRINTF_INT8_HEX_WIDTH "2"
|
||||
# endif
|
||||
# ifndef PRINTF_INT64_DEC_WIDTH
|
||||
# define PRINTF_INT64_DEC_WIDTH "20"
|
||||
# endif
|
||||
# ifndef PRINTF_INT32_DEC_WIDTH
|
||||
# define PRINTF_INT32_DEC_WIDTH "10"
|
||||
# endif
|
||||
# ifndef PRINTF_INT16_DEC_WIDTH
|
||||
# define PRINTF_INT16_DEC_WIDTH "5"
|
||||
# endif
|
||||
# ifndef PRINTF_INT8_DEC_WIDTH
|
||||
# define PRINTF_INT8_DEC_WIDTH "3"
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
|
||||
# endif
|
||||
|
||||
/*
|
||||
* Something really weird is going on with Open Watcom. Just pull some of
|
||||
* these duplicated definitions from Open Watcom's stdint.h file for now.
|
||||
*/
|
||||
|
||||
# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
|
||||
# if !defined (INT64_C)
|
||||
# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
|
||||
# endif
|
||||
# if !defined (UINT64_C)
|
||||
# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
|
||||
# endif
|
||||
# if !defined (INT32_C)
|
||||
# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
|
||||
# endif
|
||||
# if !defined (UINT32_C)
|
||||
# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
|
||||
# endif
|
||||
# if !defined (INT16_C)
|
||||
# define INT16_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT16_C)
|
||||
# define UINT16_C(x) (x)
|
||||
# endif
|
||||
# if !defined (INT8_C)
|
||||
# define INT8_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT8_C)
|
||||
# define UINT8_C(x) (x)
|
||||
# endif
|
||||
# if !defined (UINT64_MAX)
|
||||
# define UINT64_MAX 18446744073709551615ULL
|
||||
# endif
|
||||
# if !defined (INT64_MAX)
|
||||
# define INT64_MAX 9223372036854775807LL
|
||||
# endif
|
||||
# if !defined (UINT32_MAX)
|
||||
# define UINT32_MAX 4294967295UL
|
||||
# endif
|
||||
# if !defined (INT32_MAX)
|
||||
# define INT32_MAX 2147483647L
|
||||
# endif
|
||||
# if !defined (INTMAX_MAX)
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# endif
|
||||
# if !defined (INTMAX_MIN)
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _PSTDINT_H_INCLUDED
|
||||
#define _PSTDINT_H_INCLUDED
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX (~(size_t)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Deduce the type assignments from limits.h under the assumption that
|
||||
* integer sizes in bits are powers of 2, and follow the ANSI
|
||||
* definitions.
|
||||
*/
|
||||
|
||||
#ifndef UINT8_MAX
|
||||
# define UINT8_MAX 0xff
|
||||
#endif
|
||||
#ifndef uint8_t
|
||||
# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned char uint8_t;
|
||||
# define UINT8_C(v) ((uint8_t) v)
|
||||
# else
|
||||
# error "Platform not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef INT8_MAX
|
||||
# define INT8_MAX 0x7f
|
||||
#endif
|
||||
#ifndef INT8_MIN
|
||||
# define INT8_MIN INT8_C(0x80)
|
||||
#endif
|
||||
#ifndef int8_t
|
||||
# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed char int8_t;
|
||||
# define INT8_C(v) ((int8_t) v)
|
||||
# else
|
||||
# error "Platform not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UINT16_MAX
|
||||
# define UINT16_MAX 0xffff
|
||||
#endif
|
||||
#ifndef uint16_t
|
||||
#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned int uint16_t;
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER ""
|
||||
# endif
|
||||
# define UINT16_C(v) ((uint16_t) (v))
|
||||
#elif (USHRT_MAX == UINT16_MAX)
|
||||
typedef unsigned short uint16_t;
|
||||
# define UINT16_C(v) ((uint16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
# define INT16_MAX 0x7fff
|
||||
#endif
|
||||
#ifndef INT16_MIN
|
||||
# define INT16_MIN INT16_C(0x8000)
|
||||
#endif
|
||||
#ifndef int16_t
|
||||
#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed int int16_t;
|
||||
# define INT16_C(v) ((int16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER ""
|
||||
# endif
|
||||
#elif (SHRT_MAX == INT16_MAX)
|
||||
typedef signed short int16_t;
|
||||
# define INT16_C(v) ((int16_t) (v))
|
||||
# ifndef PRINTF_INT16_MODIFIER
|
||||
# define PRINTF_INT16_MODIFIER "h"
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UINT32_MAX
|
||||
# define UINT32_MAX (0xffffffffUL)
|
||||
#endif
|
||||
#ifndef uint32_t
|
||||
#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
|
||||
typedef unsigned long uint32_t;
|
||||
# define UINT32_C(v) v ## UL
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
#elif (UINT_MAX == UINT32_MAX)
|
||||
typedef unsigned int uint32_t;
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
# define UINT32_C(v) v ## U
|
||||
#elif (USHRT_MAX == UINT32_MAX)
|
||||
typedef unsigned short uint32_t;
|
||||
# define UINT32_C(v) ((unsigned short) (v))
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef INT32_MAX
|
||||
# define INT32_MAX (0x7fffffffL)
|
||||
#endif
|
||||
#ifndef INT32_MIN
|
||||
# define INT32_MIN INT32_C(0x80000000)
|
||||
#endif
|
||||
#ifndef int32_t
|
||||
#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
|
||||
typedef signed long int32_t;
|
||||
# define INT32_C(v) v ## L
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER "l"
|
||||
# endif
|
||||
#elif (INT_MAX == INT32_MAX)
|
||||
typedef signed int int32_t;
|
||||
# define INT32_C(v) v
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#elif (SHRT_MAX == INT32_MAX)
|
||||
typedef signed short int32_t;
|
||||
# define INT32_C(v) ((short) (v))
|
||||
# ifndef PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_INT32_MODIFIER ""
|
||||
# endif
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The macro stdint_int64_defined is temporarily used to record
|
||||
* whether or not 64 integer support is available. It must be
|
||||
* defined for any 64 integer extensions for new platforms that are
|
||||
* added.
|
||||
*/
|
||||
|
||||
#undef stdint_int64_defined
|
||||
#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
|
||||
# if (__STDC__ && __STDC_VERSION__ >= 199901L) || defined (S_SPLINT_S)
|
||||
# define stdint_int64_defined
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (stdint_int64_defined)
|
||||
# if defined(__GNUC__)
|
||||
# define stdint_int64_defined
|
||||
__extension__ typedef long long int64_t;
|
||||
__extension__ typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
|
||||
# define stdint_int64_defined
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
# define UINT64_C(v) v ## ULL
|
||||
# define INT64_C(v) v ## LL
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "ll"
|
||||
# endif
|
||||
# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
|
||||
# define stdint_int64_defined
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
# define UINT64_C(v) v ## UI64
|
||||
# define INT64_C(v) v ## I64
|
||||
# ifndef PRINTF_INT64_MODIFIER
|
||||
# define PRINTF_INT64_MODIFIER "I64"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined (LONG_LONG_MAX) && defined (INT64_C)
|
||||
# define LONG_LONG_MAX INT64_C (9223372036854775807)
|
||||
#endif
|
||||
#ifndef ULONG_LONG_MAX
|
||||
# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
|
||||
#endif
|
||||
|
||||
#if !defined (INT64_MAX) && defined (INT64_C)
|
||||
# define INT64_MAX INT64_C (9223372036854775807)
|
||||
#endif
|
||||
#if !defined (INT64_MIN) && defined (INT64_C)
|
||||
# define INT64_MIN INT64_C (-9223372036854775808)
|
||||
#endif
|
||||
#if !defined (UINT64_MAX) && defined (INT64_C)
|
||||
# define UINT64_MAX UINT64_C (18446744073709551615)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Width of hexadecimal for number field.
|
||||
*/
|
||||
|
||||
#ifndef PRINTF_INT64_HEX_WIDTH
|
||||
# define PRINTF_INT64_HEX_WIDTH "16"
|
||||
#endif
|
||||
#ifndef PRINTF_INT32_HEX_WIDTH
|
||||
# define PRINTF_INT32_HEX_WIDTH "8"
|
||||
#endif
|
||||
#ifndef PRINTF_INT16_HEX_WIDTH
|
||||
# define PRINTF_INT16_HEX_WIDTH "4"
|
||||
#endif
|
||||
#ifndef PRINTF_INT8_HEX_WIDTH
|
||||
# define PRINTF_INT8_HEX_WIDTH "2"
|
||||
#endif
|
||||
|
||||
#ifndef PRINTF_INT64_DEC_WIDTH
|
||||
# define PRINTF_INT64_DEC_WIDTH "20"
|
||||
#endif
|
||||
#ifndef PRINTF_INT32_DEC_WIDTH
|
||||
# define PRINTF_INT32_DEC_WIDTH "10"
|
||||
#endif
|
||||
#ifndef PRINTF_INT16_DEC_WIDTH
|
||||
# define PRINTF_INT16_DEC_WIDTH "5"
|
||||
#endif
|
||||
#ifndef PRINTF_INT8_DEC_WIDTH
|
||||
# define PRINTF_INT8_DEC_WIDTH "3"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Ok, lets not worry about 128 bit integers for now. Moore's law says
|
||||
* we don't need to worry about that until about 2040 at which point
|
||||
* we'll have bigger things to worry about.
|
||||
*/
|
||||
|
||||
#ifdef stdint_int64_defined
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
# define INTMAX_MAX INT64_MAX
|
||||
# define INTMAX_MIN INT64_MIN
|
||||
# define UINTMAX_MAX UINT64_MAX
|
||||
# define UINTMAX_C(v) UINT64_C(v)
|
||||
# define INTMAX_C(v) INT64_C(v)
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
|
||||
# endif
|
||||
#else
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# define INTMAX_MAX INT32_MAX
|
||||
# define UINTMAX_MAX UINT32_MAX
|
||||
# define UINTMAX_C(v) UINT32_C(v)
|
||||
# define INTMAX_C(v) INT32_C(v)
|
||||
# ifndef PRINTF_INTMAX_MODIFIER
|
||||
# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_HEX_WIDTH
|
||||
# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
|
||||
# endif
|
||||
# ifndef PRINTF_INTMAX_DEC_WIDTH
|
||||
# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Because this file currently only supports platforms which have
|
||||
* precise powers of 2 as bit sizes for the default integers, the
|
||||
* least definitions are all trivial. Its possible that a future
|
||||
* version of this file could have different definitions.
|
||||
*/
|
||||
|
||||
#ifndef stdint_least_defined
|
||||
typedef int8_t int_least8_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
|
||||
# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
|
||||
# define UINT_LEAST8_MAX UINT8_MAX
|
||||
# define INT_LEAST8_MAX INT8_MAX
|
||||
# define UINT_LEAST16_MAX UINT16_MAX
|
||||
# define INT_LEAST16_MAX INT16_MAX
|
||||
# define UINT_LEAST32_MAX UINT32_MAX
|
||||
# define INT_LEAST32_MAX INT32_MAX
|
||||
# define INT_LEAST8_MIN INT8_MIN
|
||||
# define INT_LEAST16_MIN INT16_MIN
|
||||
# define INT_LEAST32_MIN INT32_MIN
|
||||
# ifdef stdint_int64_defined
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
|
||||
# define UINT_LEAST64_MAX UINT64_MAX
|
||||
# define INT_LEAST64_MAX INT64_MAX
|
||||
# define INT_LEAST64_MIN INT64_MIN
|
||||
# endif
|
||||
#endif
|
||||
#undef stdint_least_defined
|
||||
|
||||
/*
|
||||
* The ANSI C committee pretending to know or specify anything about
|
||||
* performance is the epitome of misguided arrogance. The mandate of
|
||||
* this file is to *ONLY* ever support that absolute minimum
|
||||
* definition of the fast integer types, for compatibility purposes.
|
||||
* No extensions, and no attempt to suggest what may or may not be a
|
||||
* faster integer type will ever be made in this file. Developers are
|
||||
* warned to stay away from these types when using this or any other
|
||||
* stdint.h.
|
||||
*/
|
||||
|
||||
typedef int_least8_t int_fast8_t;
|
||||
typedef uint_least8_t uint_fast8_t;
|
||||
typedef int_least16_t int_fast16_t;
|
||||
typedef uint_least16_t uint_fast16_t;
|
||||
typedef int_least32_t int_fast32_t;
|
||||
typedef uint_least32_t uint_fast32_t;
|
||||
#define UINT_FAST8_MAX UINT_LEAST8_MAX
|
||||
#define INT_FAST8_MAX INT_LEAST8_MAX
|
||||
#define UINT_FAST16_MAX UINT_LEAST16_MAX
|
||||
#define INT_FAST16_MAX INT_LEAST16_MAX
|
||||
#define UINT_FAST32_MAX UINT_LEAST32_MAX
|
||||
#define INT_FAST32_MAX INT_LEAST32_MAX
|
||||
#define INT_FAST8_MIN INT_LEAST8_MIN
|
||||
#define INT_FAST16_MIN INT_LEAST16_MIN
|
||||
#define INT_FAST32_MIN INT_LEAST32_MIN
|
||||
#ifdef stdint_int64_defined
|
||||
typedef int_least64_t int_fast64_t;
|
||||
typedef uint_least64_t uint_fast64_t;
|
||||
# define UINT_FAST64_MAX UINT_LEAST64_MAX
|
||||
# define INT_FAST64_MAX INT_LEAST64_MAX
|
||||
# define INT_FAST64_MIN INT_LEAST64_MIN
|
||||
#endif
|
||||
|
||||
#undef stdint_int64_defined
|
||||
|
||||
/*
|
||||
* Whatever piecemeal, per compiler thing we can do about the wchar_t
|
||||
* type limits.
|
||||
*/
|
||||
|
||||
#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
|
||||
# include <wchar.h>
|
||||
# ifndef WCHAR_MIN
|
||||
# define WCHAR_MIN 0
|
||||
# endif
|
||||
# ifndef WCHAR_MAX
|
||||
# define WCHAR_MAX ((wchar_t)-1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whatever piecemeal, per compiler/platform thing we can do about the
|
||||
* (u)intptr_t types and limits.
|
||||
*/
|
||||
|
||||
#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
|
||||
# define STDINT_H_UINTPTR_T_DEFINED
|
||||
#endif
|
||||
|
||||
#ifndef STDINT_H_UINTPTR_T_DEFINED
|
||||
# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
|
||||
# define stdint_intptr_bits 64
|
||||
# elif defined (__WATCOMC__) || defined (__TURBOC__)
|
||||
# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
# define stdint_intptr_bits 16
|
||||
# else
|
||||
# define stdint_intptr_bits 32
|
||||
# endif
|
||||
# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
|
||||
# define stdint_intptr_bits 32
|
||||
# elif defined (__INTEL_COMPILER)
|
||||
/* TODO -- what did Intel do about x86-64? */
|
||||
# endif
|
||||
|
||||
# ifdef stdint_intptr_bits
|
||||
# define stdint_intptr_glue3_i(a,b,c) a##b##c
|
||||
# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
|
||||
# ifndef PRINTF_INTPTR_MODIFIER
|
||||
# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
|
||||
# endif
|
||||
# ifndef PTRDIFF_MAX
|
||||
# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef PTRDIFF_MIN
|
||||
# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
|
||||
# endif
|
||||
# ifndef UINTPTR_MAX
|
||||
# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef INTPTR_MAX
|
||||
# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
|
||||
# endif
|
||||
# ifndef INTPTR_MIN
|
||||
# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
|
||||
# endif
|
||||
# ifndef INTPTR_C
|
||||
# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
|
||||
# endif
|
||||
# ifndef UINTPTR_C
|
||||
# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
|
||||
# endif
|
||||
typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
|
||||
typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
|
||||
# else
|
||||
/* TODO -- This following is likely wrong for some platforms, and does
|
||||
nothing for the definition of uintptr_t. */
|
||||
typedef ptrdiff_t intptr_t;
|
||||
# endif
|
||||
# define STDINT_H_UINTPTR_T_DEFINED
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Assumes sig_atomic_t is signed and we have a 2s complement machine.
|
||||
*/
|
||||
|
||||
#ifndef SIG_ATOMIC_MAX
|
||||
# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
|
||||
|
||||
/*
|
||||
* Please compile with the maximum warning settings to make sure macros are not
|
||||
* defined more than once.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define glue3_aux(x,y,z) x ## y ## z
|
||||
#define glue3(x,y,z) glue3_aux(x,y,z)
|
||||
|
||||
#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
|
||||
#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
|
||||
|
||||
#define DECL(us,bits) glue3(DECL,us,) (bits)
|
||||
|
||||
#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
|
||||
|
||||
int main () {
|
||||
DECL(I,8)
|
||||
DECL(U,8)
|
||||
DECL(I,16)
|
||||
DECL(U,16)
|
||||
DECL(I,32)
|
||||
DECL(U,32)
|
||||
#ifdef INT64_MAX
|
||||
DECL(I,64)
|
||||
DECL(U,64)
|
||||
#endif
|
||||
intmax_t imax = INTMAX_C(0);
|
||||
uintmax_t umax = UINTMAX_C(0);
|
||||
char str0[256], str1[256];
|
||||
|
||||
sprintf (str0, "%d %x\n", 0, ~0);
|
||||
|
||||
sprintf (str1, "%d %x\n", i8, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
|
||||
sprintf (str1, "%u %x\n", u8, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
|
||||
sprintf (str1, "%d %x\n", i16, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
|
||||
sprintf (str1, "%u %x\n", u16, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
|
||||
#ifdef INT64_MAX
|
||||
sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
|
||||
#endif
|
||||
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
|
||||
sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
|
||||
if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
|
||||
|
||||
TESTUMAX(8);
|
||||
TESTUMAX(16);
|
||||
TESTUMAX(32);
|
||||
#ifdef INT64_MAX
|
||||
TESTUMAX(64);
|
||||
#endif
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1,32 +0,0 @@
|
||||
#
|
||||
# Android Makefile conversion
|
||||
#
|
||||
# Leander Beernaert
|
||||
#
|
||||
# How to build: $ANDROID_NDK/ndk-build
|
||||
#
|
||||
VERSION=1.17
|
||||
|
||||
LOCAL_PATH := $(call my-dir)/../
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_ARM_MODE := arm
|
||||
LOCAL_ARM_NEON := true
|
||||
|
||||
LOCAL_MODULE := HLSLcc
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/include \
|
||||
$(LOCAL_PATH)/src \
|
||||
$(LOCAL_PATH)/src/cbstring
|
||||
LOCAL_CFLAGS += -Wall -W
|
||||
# For dynamic library
|
||||
#LOCAL_CFLAGS += -DHLSLCC_DYNLIB
|
||||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/src/*.c) \
|
||||
$(wildcard $(LOCAL_PATH)/src/cbstring/*.c) \
|
||||
$(wildcard $(LOCAL_PATH)/src/internal_includes/*.c)
|
||||
#LOCAL_LDLIBS += -lGLESv3
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
APP_PLATFORM := android-18
|
||||
APP_ABI := armeabi-v7a
|
||||
APP_OPTIM := release
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3469d419dc589eb7a68be97885d7a55b8b0bbbffd74c5c1586959be4698fb273
|
||||
size 1046940
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:98fbcc0779c4a400530ad643e1125727c50fdbf01912f059ca296153f209eec5
|
||||
size 466488
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:270583c8762539856bf9f7c7cccf743c37db7fd4128cabd8fdfcfe3586177e27
|
||||
size 360488
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:85f1fcddb62db461ff1012f91c38d323591a220ef3f6c1e41277161a43959333
|
||||
size 1139822
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:af9216c54d23dd3754f7ae18d56b97ae256eb29a0046d8e0d2a0716054d8c230
|
||||
size 218888
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6a07bec349614cdd3e40c3577bddace1203148016f9276c7ef807bdbc37dcabf
|
||||
size 671232
|
||||
@ -1,3 +0,0 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:88acec4cedad5699900ec2d1a3ce83ab5e9365ebea4b4af0ababba562382f399
|
||||
size 296852
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue