mirror of
https://github.com/InoriRus/Kyty.git
synced 2026-08-28 05:06:40 +00:00
Initial commit
This commit is contained in:
+725
@@ -0,0 +1,725 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// dxcapi.h //
|
||||
// Copyright (C) Microsoft Corporation. All rights reserved. //
|
||||
// This file is distributed under the University of Illinois Open Source //
|
||||
// License. See LICENSE.TXT for details. //
|
||||
// //
|
||||
// Provides declarations for the DirectX Compiler API entry point. //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __DXC_API__
|
||||
#define __DXC_API__
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef DXC_API_IMPORT
|
||||
#define DXC_API_IMPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#ifndef DXC_API_IMPORT
|
||||
#define DXC_API_IMPORT __attribute__ ((visibility ("default")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef CROSS_PLATFORM_UUIDOF
|
||||
// Warning: This macro exists in WinAdapter.h as well
|
||||
#define CROSS_PLATFORM_UUIDOF(interface, spec) \
|
||||
struct __declspec(uuid(spec)) interface;
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include "dxc/Support/WinAdapter.h"
|
||||
#endif
|
||||
|
||||
struct IMalloc;
|
||||
|
||||
struct IDxcIncludeHandler;
|
||||
|
||||
typedef HRESULT (__stdcall *DxcCreateInstanceProc)(
|
||||
_In_ REFCLSID rclsid,
|
||||
_In_ REFIID riid,
|
||||
_Out_ LPVOID* ppv
|
||||
);
|
||||
|
||||
typedef HRESULT(__stdcall *DxcCreateInstance2Proc)(
|
||||
_In_ IMalloc *pMalloc,
|
||||
_In_ REFCLSID rclsid,
|
||||
_In_ REFIID riid,
|
||||
_Out_ LPVOID* ppv
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single uninitialized object of the class associated with a specified CLSID.
|
||||
/// </summary>
|
||||
/// <param name="rclsid">
|
||||
/// The CLSID associated with the data and code that will be used to create the object.
|
||||
/// </param>
|
||||
/// <param name="riid">
|
||||
/// A reference to the identifier of the interface to be used to communicate
|
||||
/// with the object.
|
||||
/// </param>
|
||||
/// <param name="ppv">
|
||||
/// Address of pointer variable that receives the interface pointer requested
|
||||
/// in riid. Upon successful return, *ppv contains the requested interface
|
||||
/// pointer. Upon failure, *ppv contains NULL.</param>
|
||||
/// <remarks>
|
||||
/// While this function is similar to CoCreateInstance, there is no COM involvement.
|
||||
/// </remarks>
|
||||
|
||||
extern "C"
|
||||
DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance(
|
||||
_In_ REFCLSID rclsid,
|
||||
_In_ REFIID riid,
|
||||
_Out_ LPVOID* ppv
|
||||
);
|
||||
|
||||
extern "C"
|
||||
DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance2(
|
||||
_In_ IMalloc *pMalloc,
|
||||
_In_ REFCLSID rclsid,
|
||||
_In_ REFIID riid,
|
||||
_Out_ LPVOID* ppv
|
||||
);
|
||||
|
||||
// For convenience, equivalent definitions to CP_UTF8 and CP_UTF16.
|
||||
#define DXC_CP_UTF8 65001
|
||||
#define DXC_CP_UTF16 1200
|
||||
// Use DXC_CP_ACP for: Binary; ANSI Text; Autodetect UTF with BOM
|
||||
#define DXC_CP_ACP 0
|
||||
|
||||
// This flag indicates that the shader hash was computed taking into account source information (-Zss)
|
||||
#define DXC_HASHFLAG_INCLUDES_SOURCE 1
|
||||
|
||||
// Hash digest type for ShaderHash
|
||||
typedef struct DxcShaderHash {
|
||||
UINT32 Flags; // DXC_HASHFLAG_*
|
||||
BYTE HashDigest[16];
|
||||
} DxcShaderHash;
|
||||
|
||||
#define DXC_FOURCC(ch0, ch1, ch2, ch3) ( \
|
||||
(UINT32)(UINT8)(ch0) | (UINT32)(UINT8)(ch1) << 8 | \
|
||||
(UINT32)(UINT8)(ch2) << 16 | (UINT32)(UINT8)(ch3) << 24 \
|
||||
)
|
||||
#define DXC_PART_PDB DXC_FOURCC('I', 'L', 'D', 'B')
|
||||
#define DXC_PART_PDB_NAME DXC_FOURCC('I', 'L', 'D', 'N')
|
||||
#define DXC_PART_PRIVATE_DATA DXC_FOURCC('P', 'R', 'I', 'V')
|
||||
#define DXC_PART_ROOT_SIGNATURE DXC_FOURCC('R', 'T', 'S', '0')
|
||||
#define DXC_PART_DXIL DXC_FOURCC('D', 'X', 'I', 'L')
|
||||
#define DXC_PART_REFLECTION_DATA DXC_FOURCC('S', 'T', 'A', 'T')
|
||||
#define DXC_PART_SHADER_HASH DXC_FOURCC('H', 'A', 'S', 'H')
|
||||
#define DXC_PART_INPUT_SIGNATURE DXC_FOURCC('I', 'S', 'G', '1')
|
||||
#define DXC_PART_OUTPUT_SIGNATURE DXC_FOURCC('O', 'S', 'G', '1')
|
||||
#define DXC_PART_PATCH_CONSTANT_SIGNATURE DXC_FOURCC('P', 'S', 'G', '1')
|
||||
|
||||
// Some option arguments are defined here for continuity with D3DCompile interface
|
||||
#define DXC_ARG_DEBUG L"-Zi"
|
||||
#define DXC_ARG_SKIP_VALIDATION L"-Vd"
|
||||
#define DXC_ARG_SKIP_OPTIMIZATIONS L"-Od"
|
||||
#define DXC_ARG_PACK_MATRIX_ROW_MAJOR L"-Zpr"
|
||||
#define DXC_ARG_PACK_MATRIX_COLUMN_MAJOR L"-Zpc"
|
||||
#define DXC_ARG_AVOID_FLOW_CONTROL L"-Gfa"
|
||||
#define DXC_ARG_PREFER_FLOW_CONTROL L"-Gfp"
|
||||
#define DXC_ARG_ENABLE_STRICTNESS L"-Ges"
|
||||
#define DXC_ARG_ENABLE_BACKWARDS_COMPATIBILITY L"-Gec"
|
||||
#define DXC_ARG_IEEE_STRICTNESS L"-Gis"
|
||||
#define DXC_ARG_OPTIMIZATION_LEVEL0 L"-O0"
|
||||
#define DXC_ARG_OPTIMIZATION_LEVEL1 L"-O1"
|
||||
#define DXC_ARG_OPTIMIZATION_LEVEL2 L"-O2"
|
||||
#define DXC_ARG_OPTIMIZATION_LEVEL3 L"-O3"
|
||||
#define DXC_ARG_WARNINGS_ARE_ERRORS L"-WX"
|
||||
#define DXC_ARG_RESOURCES_MAY_ALIAS L"-res_may_alias"
|
||||
#define DXC_ARG_ALL_RESOURCES_BOUND L"-all_resources_bound"
|
||||
#define DXC_ARG_DEBUG_NAME_FOR_SOURCE L"-Zss"
|
||||
#define DXC_ARG_DEBUG_NAME_FOR_BINARY L"-Zsb"
|
||||
|
||||
// IDxcBlob is an alias of ID3D10Blob and ID3DBlob
|
||||
CROSS_PLATFORM_UUIDOF(IDxcBlob, "8BA5FB08-5195-40e2-AC58-0D989C3A0102")
|
||||
struct IDxcBlob : public IUnknown {
|
||||
public:
|
||||
virtual LPVOID STDMETHODCALLTYPE GetBufferPointer(void) = 0;
|
||||
virtual SIZE_T STDMETHODCALLTYPE GetBufferSize(void) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcBlobEncoding, "7241d424-2646-4191-97c0-98e96e42fc68")
|
||||
struct IDxcBlobEncoding : public IDxcBlob {
|
||||
public:
|
||||
virtual HRESULT STDMETHODCALLTYPE GetEncoding(_Out_ BOOL *pKnown,
|
||||
_Out_ UINT32 *pCodePage) = 0;
|
||||
};
|
||||
|
||||
// Notes on IDxcBlobUtf16 and IDxcBlobUtf8
|
||||
// These guarantee null-terminated text and the stated encoding.
|
||||
// GetBufferSize() will return the size in bytes, including null-terminator
|
||||
// GetStringLength() will return the length in characters, excluding the null-terminator
|
||||
// Name strings will use IDxcBlobUtf16, while other string output blobs,
|
||||
// such as errors/warnings, preprocessed HLSL, or other text will be based
|
||||
// on the -encoding option.
|
||||
|
||||
// The API will use this interface for output name strings
|
||||
CROSS_PLATFORM_UUIDOF(IDxcBlobUtf16, "A3F84EAB-0FAA-497E-A39C-EE6ED60B2D84")
|
||||
struct IDxcBlobUtf16 : public IDxcBlobEncoding {
|
||||
public:
|
||||
virtual LPCWSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;
|
||||
virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;
|
||||
};
|
||||
CROSS_PLATFORM_UUIDOF(IDxcBlobUtf8, "3DA636C9-BA71-4024-A301-30CBF125305B")
|
||||
struct IDxcBlobUtf8 : public IDxcBlobEncoding {
|
||||
public:
|
||||
virtual LPCSTR STDMETHODCALLTYPE GetStringPointer(void) = 0;
|
||||
virtual SIZE_T STDMETHODCALLTYPE GetStringLength(void) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcIncludeHandler, "7f61fc7d-950d-467f-b3e3-3c02fb49187c")
|
||||
struct IDxcIncludeHandler : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE LoadSource(
|
||||
_In_z_ LPCWSTR pFilename, // Candidate filename.
|
||||
_COM_Outptr_result_maybenull_ IDxcBlob **ppIncludeSource // Resultant source object for included file, nullptr if not found.
|
||||
) = 0;
|
||||
};
|
||||
|
||||
// Structure for supplying bytes or text input to Dxc APIs.
|
||||
// Use Encoding = 0 for non-text bytes, ANSI text, or unknown with BOM.
|
||||
typedef struct DxcBuffer {
|
||||
LPCVOID Ptr;
|
||||
SIZE_T Size;
|
||||
UINT Encoding;
|
||||
} DxcText;
|
||||
|
||||
struct DxcDefine {
|
||||
LPCWSTR Name;
|
||||
_Maybenull_ LPCWSTR Value;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcCompilerArgs, "73EFFE2A-70DC-45F8-9690-EFF64C02429D")
|
||||
struct IDxcCompilerArgs : public IUnknown {
|
||||
// Pass GetArguments() and GetCount() to Compile
|
||||
virtual LPCWSTR* STDMETHODCALLTYPE GetArguments() = 0;
|
||||
virtual UINT32 STDMETHODCALLTYPE GetCount() = 0;
|
||||
|
||||
// Add additional arguments or defines here, if desired.
|
||||
virtual HRESULT STDMETHODCALLTYPE AddArguments(
|
||||
_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments to add
|
||||
_In_ UINT32 argCount // Number of arguments to add
|
||||
) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE AddArgumentsUTF8(
|
||||
_In_opt_count_(argCount)LPCSTR *pArguments, // Array of pointers to UTF-8 arguments to add
|
||||
_In_ UINT32 argCount // Number of arguments to add
|
||||
) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE AddDefines(
|
||||
_In_count_(defineCount) const DxcDefine *pDefines, // Array of defines
|
||||
_In_ UINT32 defineCount // Number of defines
|
||||
) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////
|
||||
// Legacy Interfaces
|
||||
/////////////////////////
|
||||
|
||||
// NOTE: IDxcUtils replaces IDxcLibrary
|
||||
CROSS_PLATFORM_UUIDOF(IDxcLibrary, "e5204dc7-d18c-4c3c-bdfb-851673980fe7")
|
||||
struct IDxcLibrary : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE SetMalloc(_In_opt_ IMalloc *pMalloc) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(
|
||||
_In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlobFromFile(
|
||||
_In_z_ LPCWSTR pFileName, _In_opt_ UINT32* codePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingFromPinned(
|
||||
_In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnHeapCopy(
|
||||
_In_bytecount_(size) LPCVOID pText, UINT32 size, UINT32 codePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlobWithEncodingOnMalloc(
|
||||
_In_bytecount_(size) LPCVOID pText, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateIncludeHandler(
|
||||
_COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateStreamFromBlobReadOnly(
|
||||
_In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(
|
||||
_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(
|
||||
_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
};
|
||||
|
||||
// NOTE: IDxcResult replaces IDxcOperationResult
|
||||
CROSS_PLATFORM_UUIDOF(IDxcOperationResult, "CEDB484A-D4E9-445A-B991-CA21CA157DC2")
|
||||
struct IDxcOperationResult : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE GetStatus(_Out_ HRESULT *pStatus) = 0;
|
||||
|
||||
// GetResult returns the main result of the operation.
|
||||
// This corresponds to:
|
||||
// DXC_OUT_OBJECT - Compile() with shader or library target
|
||||
// DXC_OUT_DISASSEMBLY - Disassemble()
|
||||
// DXC_OUT_HLSL - Compile() with -P
|
||||
// DXC_OUT_ROOT_SIGNATURE - Compile() with rootsig_* target
|
||||
virtual HRESULT STDMETHODCALLTYPE GetResult(_COM_Outptr_result_maybenull_ IDxcBlob **ppResult) = 0;
|
||||
|
||||
// GetErrorBuffer Corresponds to DXC_OUT_ERRORS.
|
||||
virtual HRESULT STDMETHODCALLTYPE GetErrorBuffer(_COM_Outptr_result_maybenull_ IDxcBlobEncoding **ppErrors) = 0;
|
||||
};
|
||||
|
||||
// NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2
|
||||
CROSS_PLATFORM_UUIDOF(IDxcCompiler, "8c210bf3-011f-4422-8d70-6f9acb8db617")
|
||||
struct IDxcCompiler : public IUnknown {
|
||||
// Compile a single entry point to the target shader model
|
||||
virtual HRESULT STDMETHODCALLTYPE Compile(
|
||||
_In_ IDxcBlob *pSource, // Source text to compile
|
||||
_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
|
||||
_In_opt_z_ LPCWSTR pEntryPoint, // entry point name
|
||||
_In_z_ LPCWSTR pTargetProfile, // shader profile to compile
|
||||
_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
|
||||
_In_ UINT32 argCount, // Number of arguments
|
||||
_In_count_(defineCount)
|
||||
const DxcDefine *pDefines, // Array of defines
|
||||
_In_ UINT32 defineCount, // Number of defines
|
||||
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
|
||||
_COM_Outptr_ IDxcOperationResult **ppResult // Compiler output status, buffer, and errors
|
||||
) = 0;
|
||||
|
||||
// Preprocess source text
|
||||
virtual HRESULT STDMETHODCALLTYPE Preprocess(
|
||||
_In_ IDxcBlob *pSource, // Source text to preprocess
|
||||
_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
|
||||
_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
|
||||
_In_ UINT32 argCount, // Number of arguments
|
||||
_In_count_(defineCount)
|
||||
const DxcDefine *pDefines, // Array of defines
|
||||
_In_ UINT32 defineCount, // Number of defines
|
||||
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
|
||||
_COM_Outptr_ IDxcOperationResult **ppResult // Preprocessor output status, buffer, and errors
|
||||
) = 0;
|
||||
|
||||
// Disassemble a program.
|
||||
virtual HRESULT STDMETHODCALLTYPE Disassemble(
|
||||
_In_ IDxcBlob *pSource, // Program to disassemble.
|
||||
_COM_Outptr_ IDxcBlobEncoding **ppDisassembly // Disassembly text.
|
||||
) = 0;
|
||||
};
|
||||
|
||||
// NOTE: IDxcCompiler3 replaces IDxcCompiler and IDxcCompiler2
|
||||
CROSS_PLATFORM_UUIDOF(IDxcCompiler2, "A005A9D9-B8BB-4594-B5C9-0E633BEC4D37")
|
||||
struct IDxcCompiler2 : public IDxcCompiler {
|
||||
// Compile a single entry point to the target shader model with debug information.
|
||||
virtual HRESULT STDMETHODCALLTYPE CompileWithDebug(
|
||||
_In_ IDxcBlob *pSource, // Source text to compile
|
||||
_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
|
||||
_In_opt_z_ LPCWSTR pEntryPoint, // Entry point name
|
||||
_In_z_ LPCWSTR pTargetProfile, // Shader profile to compile
|
||||
_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
|
||||
_In_ UINT32 argCount, // Number of arguments
|
||||
_In_count_(defineCount)
|
||||
const DxcDefine *pDefines, // Array of defines
|
||||
_In_ UINT32 defineCount, // Number of defines
|
||||
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
|
||||
_COM_Outptr_ IDxcOperationResult **ppResult, // Compiler output status, buffer, and errors
|
||||
_Outptr_opt_result_z_ LPWSTR *ppDebugBlobName,// Suggested file name for debug blob. (Must be CoTaskMemFree()'d!)
|
||||
_COM_Outptr_opt_ IDxcBlob **ppDebugBlob // Debug blob
|
||||
) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcLinker, "F1B5BE2A-62DD-4327-A1C2-42AC1E1E78E6")
|
||||
struct IDxcLinker : public IUnknown {
|
||||
public:
|
||||
// Register a library with name to ref it later.
|
||||
virtual HRESULT RegisterLibrary(
|
||||
_In_opt_ LPCWSTR pLibName, // Name of the library.
|
||||
_In_ IDxcBlob *pLib // Library blob.
|
||||
) = 0;
|
||||
|
||||
// Links the shader and produces a shader blob that the Direct3D runtime can
|
||||
// use.
|
||||
virtual HRESULT STDMETHODCALLTYPE Link(
|
||||
_In_opt_ LPCWSTR pEntryName, // Entry point name
|
||||
_In_ LPCWSTR pTargetProfile, // shader profile to link
|
||||
_In_count_(libCount)
|
||||
const LPCWSTR *pLibNames, // Array of library names to link
|
||||
_In_ UINT32 libCount, // Number of libraries to link
|
||||
_In_opt_count_(argCount) const LPCWSTR *pArguments, // Array of pointers to arguments
|
||||
_In_ UINT32 argCount, // Number of arguments
|
||||
_COM_Outptr_
|
||||
IDxcOperationResult **ppResult // Linker output status, buffer, and errors
|
||||
) = 0;
|
||||
};
|
||||
|
||||
/////////////////////////
|
||||
// Latest interfaces. Please use these
|
||||
////////////////////////
|
||||
|
||||
// NOTE: IDxcUtils replaces IDxcLibrary
|
||||
CROSS_PLATFORM_UUIDOF(IDxcUtils, "4605C4CB-2019-492A-ADA4-65F20BB7D67F")
|
||||
struct IDxcUtils : public IUnknown {
|
||||
// Create a sub-blob that holds a reference to the outer blob and points to its memory.
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlobFromBlob(
|
||||
_In_ IDxcBlob *pBlob, UINT32 offset, UINT32 length, _COM_Outptr_ IDxcBlob **ppResult) = 0;
|
||||
|
||||
// For codePage, use 0 (or DXC_CP_ACP) for raw binary or ANSI code page
|
||||
|
||||
// Creates a blob referencing existing memory, with no copy.
|
||||
// User must manage the memory lifetime separately.
|
||||
// (was: CreateBlobWithEncodingFromPinned)
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlobFromPinned(
|
||||
_In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
|
||||
// Create blob, taking ownership of memory allocated with supplied allocator.
|
||||
// (was: CreateBlobWithEncodingOnMalloc)
|
||||
virtual HRESULT STDMETHODCALLTYPE MoveToBlob(
|
||||
_In_bytecount_(size) LPCVOID pData, IMalloc *pIMalloc, UINT32 size, UINT32 codePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
|
||||
////
|
||||
// New blobs and copied contents are allocated with the current allocator
|
||||
|
||||
// Copy blob contents to memory owned by the new blob.
|
||||
// (was: CreateBlobWithEncodingOnHeapCopy)
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateBlob(
|
||||
_In_bytecount_(size) LPCVOID pData, UINT32 size, UINT32 codePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
|
||||
// (was: CreateBlobFromFile)
|
||||
virtual HRESULT STDMETHODCALLTYPE LoadFile(
|
||||
_In_z_ LPCWSTR pFileName, _In_opt_ UINT32* pCodePage,
|
||||
_COM_Outptr_ IDxcBlobEncoding **pBlobEncoding) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateReadOnlyStreamFromBlob(
|
||||
_In_ IDxcBlob *pBlob, _COM_Outptr_ IStream **ppStream) = 0;
|
||||
|
||||
// Create default file-based include handler
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateDefaultIncludeHandler(
|
||||
_COM_Outptr_ IDxcIncludeHandler **ppResult) = 0;
|
||||
|
||||
// Convert or return matching encoded text blobs
|
||||
virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf8(
|
||||
_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobUtf8 **pBlobEncoding) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetBlobAsUtf16(
|
||||
_In_ IDxcBlob *pBlob, _COM_Outptr_ IDxcBlobUtf16 **pBlobEncoding) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetDxilContainerPart(
|
||||
_In_ const DxcBuffer *pShader,
|
||||
_In_ UINT32 DxcPart,
|
||||
_Outptr_result_nullonfailure_ void **ppPartData,
|
||||
_Out_ UINT32 *pPartSizeInBytes) = 0;
|
||||
|
||||
// Create reflection interface from serialized Dxil container, or DXC_PART_REFLECTION_DATA.
|
||||
// TBD: Require part header for RDAT? (leaning towards yes)
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateReflection(
|
||||
_In_ const DxcBuffer *pData, REFIID iid, void **ppvReflection) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE BuildArguments(
|
||||
_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in errors and include handlers.
|
||||
_In_opt_z_ LPCWSTR pEntryPoint, // Entry point name. (-E)
|
||||
_In_z_ LPCWSTR pTargetProfile, // Shader profile to compile. (-T)
|
||||
_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
|
||||
_In_ UINT32 argCount, // Number of arguments
|
||||
_In_count_(defineCount)
|
||||
const DxcDefine *pDefines, // Array of defines
|
||||
_In_ UINT32 defineCount, // Number of defines
|
||||
_COM_Outptr_ IDxcCompilerArgs **ppArgs // Arguments you can use with Compile() method
|
||||
) = 0;
|
||||
|
||||
// Takes the shader PDB and returns the hash and the container inside it
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPDBContents(
|
||||
_In_ IDxcBlob *pPDBBlob, _COM_Outptr_ IDxcBlob **ppHash, _COM_Outptr_ IDxcBlob **ppContainer) = 0;
|
||||
};
|
||||
|
||||
// For use with IDxcResult::[Has|Get]Output dxcOutKind argument
|
||||
// Note: text outputs returned from version 2 APIs are UTF-8 or UTF-16 based on -encoding option
|
||||
typedef enum DXC_OUT_KIND {
|
||||
DXC_OUT_NONE = 0,
|
||||
DXC_OUT_OBJECT = 1, // IDxcBlob - Shader or library object
|
||||
DXC_OUT_ERRORS = 2, // IDxcBlobUtf8 or IDxcBlobUtf16
|
||||
DXC_OUT_PDB = 3, // IDxcBlob
|
||||
DXC_OUT_SHADER_HASH = 4, // IDxcBlob - DxcShaderHash of shader or shader with source info (-Zsb/-Zss)
|
||||
DXC_OUT_DISASSEMBLY = 5, // IDxcBlobUtf8 or IDxcBlobUtf16 - from Disassemble
|
||||
DXC_OUT_HLSL = 6, // IDxcBlobUtf8 or IDxcBlobUtf16 - from Preprocessor or Rewriter
|
||||
DXC_OUT_TEXT = 7, // IDxcBlobUtf8 or IDxcBlobUtf16 - other text, such as -ast-dump or -Odump
|
||||
DXC_OUT_REFLECTION = 8, // IDxcBlob - RDAT part with reflection data
|
||||
DXC_OUT_ROOT_SIGNATURE = 9, // IDxcBlob - Serialized root signature output
|
||||
DXC_OUT_EXTRA_OUTPUTS = 10,// IDxcExtraResults - Extra outputs
|
||||
|
||||
DXC_OUT_FORCE_DWORD = 0xFFFFFFFF
|
||||
} DXC_OUT_KIND;
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcResult, "58346CDA-DDE7-4497-9461-6F87AF5E0659")
|
||||
struct IDxcResult : public IDxcOperationResult {
|
||||
virtual BOOL STDMETHODCALLTYPE HasOutput(_In_ DXC_OUT_KIND dxcOutKind) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ DXC_OUT_KIND dxcOutKind,
|
||||
_In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,
|
||||
_COM_Outptr_ IDxcBlobUtf16 **ppOutputName) = 0;
|
||||
|
||||
virtual UINT32 GetNumOutputs() = 0;
|
||||
virtual DXC_OUT_KIND GetOutputByIndex(UINT32 Index) = 0;
|
||||
virtual DXC_OUT_KIND PrimaryOutput() = 0;
|
||||
};
|
||||
|
||||
// Special names for extra output that should get written to specific streams
|
||||
#define DXC_EXTRA_OUTPUT_NAME_STDOUT L"*stdout*"
|
||||
#define DXC_EXTRA_OUTPUT_NAME_STDERR L"*stderr*"
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcExtraOutputs, "319b37a2-a5c2-494a-a5de-4801b2faf989")
|
||||
struct IDxcExtraOutputs : public IUnknown {
|
||||
|
||||
virtual UINT32 STDMETHODCALLTYPE GetOutputCount() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetOutput(_In_ UINT32 uIndex,
|
||||
_In_ REFIID iid, _COM_Outptr_opt_result_maybenull_ void **ppvObject,
|
||||
_COM_Outptr_opt_result_maybenull_ IDxcBlobUtf16 **ppOutputType,
|
||||
_COM_Outptr_opt_result_maybenull_ IDxcBlobUtf16 **ppOutputName) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcCompiler3, "228B4687-5A6A-4730-900C-9702B2203F54")
|
||||
struct IDxcCompiler3 : public IUnknown {
|
||||
// Compile a single entry point to the target shader model,
|
||||
// Compile a library to a library target (-T lib_*),
|
||||
// Compile a root signature (-T rootsig_*), or
|
||||
// Preprocess HLSL source (-P)
|
||||
virtual HRESULT STDMETHODCALLTYPE Compile(
|
||||
_In_ const DxcBuffer *pSource, // Source text to compile
|
||||
_In_opt_count_(argCount) LPCWSTR *pArguments, // Array of pointers to arguments
|
||||
_In_ UINT32 argCount, // Number of arguments
|
||||
_In_opt_ IDxcIncludeHandler *pIncludeHandler, // user-provided interface to handle #include directives (optional)
|
||||
_In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, buffer, and errors
|
||||
) = 0;
|
||||
|
||||
// Disassemble a program.
|
||||
virtual HRESULT STDMETHODCALLTYPE Disassemble(
|
||||
_In_ const DxcBuffer *pObject, // Program to disassemble: dxil container or bitcode.
|
||||
_In_ REFIID riid, _Out_ LPVOID *ppResult // IDxcResult: status, disassembly text, and errors
|
||||
) = 0;
|
||||
};
|
||||
|
||||
static const UINT32 DxcValidatorFlags_Default = 0;
|
||||
static const UINT32 DxcValidatorFlags_InPlaceEdit = 1; // Validator is allowed to update shader blob in-place.
|
||||
static const UINT32 DxcValidatorFlags_RootSignatureOnly = 2;
|
||||
static const UINT32 DxcValidatorFlags_ModuleOnly = 4;
|
||||
static const UINT32 DxcValidatorFlags_ValidMask = 0x7;
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcValidator, "A6E82BD2-1FD7-4826-9811-2857E797F49A")
|
||||
struct IDxcValidator : public IUnknown {
|
||||
// Validate a shader.
|
||||
virtual HRESULT STDMETHODCALLTYPE Validate(
|
||||
_In_ IDxcBlob *pShader, // Shader to validate.
|
||||
_In_ UINT32 Flags, // Validation flags.
|
||||
_COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
|
||||
) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcValidator2, "458e1fd1-b1b2-4750-a6e1-9c10f03bed92")
|
||||
struct IDxcValidator2 : public IDxcValidator {
|
||||
// Validate a shader.
|
||||
virtual HRESULT STDMETHODCALLTYPE ValidateWithDebug(
|
||||
_In_ IDxcBlob *pShader, // Shader to validate.
|
||||
_In_ UINT32 Flags, // Validation flags.
|
||||
_In_opt_ DxcBuffer *pOptDebugBitcode, // Optional debug module bitcode to provide line numbers
|
||||
_COM_Outptr_ IDxcOperationResult **ppResult // Validation output status, buffer, and errors
|
||||
) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcContainerBuilder, "334b1f50-2292-4b35-99a1-25588d8c17fe")
|
||||
struct IDxcContainerBuilder : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) = 0; // Loads DxilContainer to the builder
|
||||
virtual HRESULT STDMETHODCALLTYPE AddPart(_In_ UINT32 fourCC, _In_ IDxcBlob *pSource) = 0; // Part to add to the container
|
||||
virtual HRESULT STDMETHODCALLTYPE RemovePart(_In_ UINT32 fourCC) = 0; // Remove the part with fourCC
|
||||
virtual HRESULT STDMETHODCALLTYPE SerializeContainer(_Out_ IDxcOperationResult **ppResult) = 0; // Builds a container of the given container builder state
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcAssembler, "091f7a26-1c1f-4948-904b-e6e3a8a771d5")
|
||||
struct IDxcAssembler : public IUnknown {
|
||||
// Assemble dxil in ll or llvm bitcode to DXIL container.
|
||||
virtual HRESULT STDMETHODCALLTYPE AssembleToContainer(
|
||||
_In_ IDxcBlob *pShader, // Shader to assemble.
|
||||
_COM_Outptr_ IDxcOperationResult **ppResult // Assembly output status, buffer, and errors
|
||||
) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcContainerReflection, "d2c21b26-8350-4bdc-976a-331ce6f4c54c")
|
||||
struct IDxcContainerReflection : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pContainer) = 0; // Container to load.
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPartCount(_Out_ UINT32 *pResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPartKind(UINT32 idx, _Out_ UINT32 *pResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPartContent(UINT32 idx, _COM_Outptr_ IDxcBlob **ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE FindFirstPartKind(UINT32 kind, _Out_ UINT32 *pResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPartReflection(UINT32 idx, REFIID iid, void **ppvObject) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcOptimizerPass, "AE2CD79F-CC22-453F-9B6B-B124E7A5204C")
|
||||
struct IDxcOptimizerPass : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE GetOptionName(_COM_Outptr_ LPWSTR *ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetDescription(_COM_Outptr_ LPWSTR *ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetOptionArgCount(_Out_ UINT32 *pCount) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetOptionArgName(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetOptionArgDescription(UINT32 argIndex, _COM_Outptr_ LPWSTR *ppResult) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcOptimizer, "25740E2E-9CBA-401B-9119-4FB42F39F270")
|
||||
struct IDxcOptimizer : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE GetAvailablePassCount(_Out_ UINT32 *pCount) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetAvailablePass(UINT32 index, _COM_Outptr_ IDxcOptimizerPass** ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE RunOptimizer(IDxcBlob *pBlob,
|
||||
_In_count_(optionCount) LPCWSTR *ppOptions, UINT32 optionCount,
|
||||
_COM_Outptr_ IDxcBlob **pOutputModule,
|
||||
_COM_Outptr_opt_ IDxcBlobEncoding **ppOutputText) = 0;
|
||||
};
|
||||
|
||||
static const UINT32 DxcVersionInfoFlags_None = 0;
|
||||
static const UINT32 DxcVersionInfoFlags_Debug = 1; // Matches VS_FF_DEBUG
|
||||
static const UINT32 DxcVersionInfoFlags_Internal = 2; // Internal Validator (non-signing)
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcVersionInfo, "b04f5b50-2059-4f12-a8ff-a1e0cde1cc7e")
|
||||
struct IDxcVersionInfo : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE GetVersion(_Out_ UINT32 *pMajor, _Out_ UINT32 *pMinor) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFlags(_Out_ UINT32 *pFlags) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcVersionInfo2, "fb6904c4-42f0-4b62-9c46-983af7da7c83")
|
||||
struct IDxcVersionInfo2 : public IDxcVersionInfo {
|
||||
virtual HRESULT STDMETHODCALLTYPE GetCommitInfo(
|
||||
_Out_ UINT32 *pCommitCount, // The total number commits.
|
||||
_Outptr_result_z_ char **pCommitHash // The SHA of the latest commit. (Must be CoTaskMemFree()'d!)
|
||||
) = 0;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcVersionInfo3, "5e13e843-9d25-473c-9ad2-03b2d0b44b1e")
|
||||
struct IDxcVersionInfo3 : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE GetCustomVersionString(
|
||||
_Outptr_result_z_ char **pVersionString // Custom version string for compiler. (Must be CoTaskMemFree()'d!)
|
||||
) = 0;
|
||||
};
|
||||
|
||||
struct DxcArgPair {
|
||||
const WCHAR *pName;
|
||||
const WCHAR *pValue;
|
||||
};
|
||||
|
||||
CROSS_PLATFORM_UUIDOF(IDxcPdbUtils, "E6C9647E-9D6A-4C3B-B94C-524B5A6C343D")
|
||||
struct IDxcPdbUtils : public IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pPdbOrDxil) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetSourceCount(_Out_ UINT32 *pCount) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetSource(_In_ UINT32 uIndex, _COM_Outptr_ IDxcBlobEncoding **ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetSourceName(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFlagCount(_Out_ UINT32 *pCount) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFlag(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetArgCount(_Out_ UINT32 *pCount) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetArg(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetArgPairCount(_Out_ UINT32 *pCount) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetArgPair(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pName, _Outptr_result_z_ BSTR *pValue) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetDefineCount(_Out_ UINT32 *pCount) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetDefine(_In_ UINT32 uIndex, _Outptr_result_z_ BSTR *pResult) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetTargetProfile(_Outptr_result_z_ BSTR *pResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetEntryPoint(_Outptr_result_z_ BSTR *pResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetMainFileName(_Outptr_result_z_ BSTR *pResult) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetHash(_COM_Outptr_ IDxcBlob **ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetName(_Outptr_result_z_ BSTR *pResult) = 0;
|
||||
|
||||
virtual BOOL STDMETHODCALLTYPE IsFullPDB() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetVersionInfo(_COM_Outptr_ IDxcVersionInfo **ppVersionInfo) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE OverrideArgs(_In_ DxcArgPair *pArgPairs, UINT32 uNumArgPairs) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE OverrideRootSignature(_In_ const WCHAR *pRootSignature) = 0;
|
||||
};
|
||||
|
||||
// Note: __declspec(selectany) requires 'extern'
|
||||
// On Linux __declspec(selectany) is removed and using 'extern' results in link error.
|
||||
#ifdef _MSC_VER
|
||||
#define CLSID_SCOPE __declspec(selectany) extern
|
||||
#else
|
||||
#define CLSID_SCOPE
|
||||
#endif
|
||||
|
||||
CLSID_SCOPE const CLSID CLSID_DxcCompiler = {
|
||||
0x73e22d93,
|
||||
0xe6ce,
|
||||
0x47f3,
|
||||
{0xb5, 0xbf, 0xf0, 0x66, 0x4f, 0x39, 0xc1, 0xb0}};
|
||||
|
||||
// {EF6A8087-B0EA-4D56-9E45-D07E1A8B7806}
|
||||
CLSID_SCOPE const GUID CLSID_DxcLinker = {
|
||||
0xef6a8087,
|
||||
0xb0ea,
|
||||
0x4d56,
|
||||
{0x9e, 0x45, 0xd0, 0x7e, 0x1a, 0x8b, 0x78, 0x6}};
|
||||
|
||||
// {CD1F6B73-2AB0-484D-8EDC-EBE7A43CA09F}
|
||||
CLSID_SCOPE const CLSID CLSID_DxcDiaDataSource = {
|
||||
0xcd1f6b73,
|
||||
0x2ab0,
|
||||
0x484d,
|
||||
{0x8e, 0xdc, 0xeb, 0xe7, 0xa4, 0x3c, 0xa0, 0x9f}};
|
||||
|
||||
// {3E56AE82-224D-470F-A1A1-FE3016EE9F9D}
|
||||
CLSID_SCOPE const CLSID CLSID_DxcCompilerArgs = {
|
||||
0x3e56ae82,
|
||||
0x224d,
|
||||
0x470f,
|
||||
{0xa1, 0xa1, 0xfe, 0x30, 0x16, 0xee, 0x9f, 0x9d}};
|
||||
|
||||
// {6245D6AF-66E0-48FD-80B4-4D271796748C}
|
||||
CLSID_SCOPE const GUID CLSID_DxcLibrary = {
|
||||
0x6245d6af,
|
||||
0x66e0,
|
||||
0x48fd,
|
||||
{0x80, 0xb4, 0x4d, 0x27, 0x17, 0x96, 0x74, 0x8c}};
|
||||
|
||||
CLSID_SCOPE const GUID CLSID_DxcUtils = CLSID_DxcLibrary;
|
||||
|
||||
// {8CA3E215-F728-4CF3-8CDD-88AF917587A1}
|
||||
CLSID_SCOPE const GUID CLSID_DxcValidator = {
|
||||
0x8ca3e215,
|
||||
0xf728,
|
||||
0x4cf3,
|
||||
{0x8c, 0xdd, 0x88, 0xaf, 0x91, 0x75, 0x87, 0xa1}};
|
||||
|
||||
// {D728DB68-F903-4F80-94CD-DCCF76EC7151}
|
||||
CLSID_SCOPE const GUID CLSID_DxcAssembler = {
|
||||
0xd728db68,
|
||||
0xf903,
|
||||
0x4f80,
|
||||
{0x94, 0xcd, 0xdc, 0xcf, 0x76, 0xec, 0x71, 0x51}};
|
||||
|
||||
// {b9f54489-55b8-400c-ba3a-1675e4728b91}
|
||||
CLSID_SCOPE const GUID CLSID_DxcContainerReflection = {
|
||||
0xb9f54489,
|
||||
0x55b8,
|
||||
0x400c,
|
||||
{0xba, 0x3a, 0x16, 0x75, 0xe4, 0x72, 0x8b, 0x91}};
|
||||
|
||||
// {AE2CD79F-CC22-453F-9B6B-B124E7A5204C}
|
||||
CLSID_SCOPE const GUID CLSID_DxcOptimizer = {
|
||||
0xae2cd79f,
|
||||
0xcc22,
|
||||
0x453f,
|
||||
{0x9b, 0x6b, 0xb1, 0x24, 0xe7, 0xa5, 0x20, 0x4c}};
|
||||
|
||||
// {94134294-411f-4574-b4d0-8741e25240d2}
|
||||
CLSID_SCOPE const GUID CLSID_DxcContainerBuilder = {
|
||||
0x94134294,
|
||||
0x411f,
|
||||
0x4574,
|
||||
{0xb4, 0xd0, 0x87, 0x41, 0xe2, 0x52, 0x40, 0xd2}};
|
||||
|
||||
// {54621dfb-f2ce-457e-ae8c-ec355faeec7c}
|
||||
CLSID_SCOPE const GUID CLSID_DxcPdbUtils = {
|
||||
0x54621dfb,
|
||||
0xf2ce,
|
||||
0x457e,
|
||||
{0xae, 0x8c, 0xec, 0x35, 0x5f, 0xae, 0xec, 0x7c}};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,577 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
// Copyright (C) 2017 ARM Limited.
|
||||
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
#ifndef _BASICTYPES_INCLUDED_
|
||||
#define _BASICTYPES_INCLUDED_
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Basic type. Arrays, vectors, sampler details, etc., are orthogonal to this.
|
||||
//
|
||||
enum TBasicType {
|
||||
EbtVoid,
|
||||
EbtFloat,
|
||||
EbtDouble,
|
||||
EbtFloat16,
|
||||
EbtInt8,
|
||||
EbtUint8,
|
||||
EbtInt16,
|
||||
EbtUint16,
|
||||
EbtInt,
|
||||
EbtUint,
|
||||
EbtInt64,
|
||||
EbtUint64,
|
||||
EbtBool,
|
||||
EbtAtomicUint,
|
||||
EbtSampler,
|
||||
EbtStruct,
|
||||
EbtBlock,
|
||||
EbtAccStruct,
|
||||
EbtReference,
|
||||
EbtRayQuery,
|
||||
|
||||
// HLSL types that live only temporarily.
|
||||
EbtString,
|
||||
|
||||
EbtNumTypes
|
||||
};
|
||||
|
||||
//
|
||||
// Storage qualifiers. Should align with different kinds of storage or
|
||||
// resource or GLSL storage qualifier. Expansion is deprecated.
|
||||
//
|
||||
// N.B.: You probably DON'T want to add anything here, but rather just add it
|
||||
// to the built-in variables. See the comment above TBuiltInVariable.
|
||||
//
|
||||
// A new built-in variable will normally be an existing qualifier, like 'in', 'out', etc.
|
||||
// DO NOT follow the design pattern of, say EvqInstanceId, etc.
|
||||
//
|
||||
enum TStorageQualifier {
|
||||
EvqTemporary, // For temporaries (within a function), read/write
|
||||
EvqGlobal, // For globals read/write
|
||||
EvqConst, // User-defined constant values, will be semantically constant and constant folded
|
||||
EvqVaryingIn, // pipeline input, read only, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
|
||||
EvqVaryingOut, // pipeline output, read/write, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
|
||||
EvqUniform, // read only, shared with app
|
||||
EvqBuffer, // read/write, shared with app
|
||||
EvqShared, // compute shader's read/write 'shared' qualifier
|
||||
|
||||
EvqPayload,
|
||||
EvqPayloadIn,
|
||||
EvqHitAttr,
|
||||
EvqCallableData,
|
||||
EvqCallableDataIn,
|
||||
|
||||
// parameters
|
||||
EvqIn, // also, for 'in' in the grammar before we know if it's a pipeline input or an 'in' parameter
|
||||
EvqOut, // also, for 'out' in the grammar before we know if it's a pipeline output or an 'out' parameter
|
||||
EvqInOut,
|
||||
EvqConstReadOnly, // input; also other read-only types having neither a constant value nor constant-value semantics
|
||||
|
||||
// built-ins read by vertex shader
|
||||
EvqVertexId,
|
||||
EvqInstanceId,
|
||||
|
||||
// built-ins written by vertex shader
|
||||
EvqPosition,
|
||||
EvqPointSize,
|
||||
EvqClipVertex,
|
||||
|
||||
// built-ins read by fragment shader
|
||||
EvqFace,
|
||||
EvqFragCoord,
|
||||
EvqPointCoord,
|
||||
|
||||
// built-ins written by fragment shader
|
||||
EvqFragColor,
|
||||
EvqFragDepth,
|
||||
|
||||
// end of list
|
||||
EvqLast
|
||||
};
|
||||
|
||||
//
|
||||
// Subcategories of the TStorageQualifier, simply to give a direct mapping
|
||||
// between built-in variable names and an numerical value (the enum).
|
||||
//
|
||||
// For backward compatibility, there is some redundancy between the
|
||||
// TStorageQualifier and these. Existing members should both be maintained accurately.
|
||||
// However, any new built-in variable (and any existing non-redundant one)
|
||||
// must follow the pattern that the specific built-in is here, and only its
|
||||
// general qualifier is in TStorageQualifier.
|
||||
//
|
||||
// Something like gl_Position, which is sometimes 'in' and sometimes 'out'
|
||||
// shows up as two different built-in variables in a single stage, but
|
||||
// only has a single enum in TBuiltInVariable, so both the
|
||||
// TStorageQualifier and the TBuitinVariable are needed to distinguish
|
||||
// between them.
|
||||
//
|
||||
enum TBuiltInVariable {
|
||||
EbvNone,
|
||||
EbvNumWorkGroups,
|
||||
EbvWorkGroupSize,
|
||||
EbvWorkGroupId,
|
||||
EbvLocalInvocationId,
|
||||
EbvGlobalInvocationId,
|
||||
EbvLocalInvocationIndex,
|
||||
EbvNumSubgroups,
|
||||
EbvSubgroupID,
|
||||
EbvSubGroupSize,
|
||||
EbvSubGroupInvocation,
|
||||
EbvSubGroupEqMask,
|
||||
EbvSubGroupGeMask,
|
||||
EbvSubGroupGtMask,
|
||||
EbvSubGroupLeMask,
|
||||
EbvSubGroupLtMask,
|
||||
EbvSubgroupSize2,
|
||||
EbvSubgroupInvocation2,
|
||||
EbvSubgroupEqMask2,
|
||||
EbvSubgroupGeMask2,
|
||||
EbvSubgroupGtMask2,
|
||||
EbvSubgroupLeMask2,
|
||||
EbvSubgroupLtMask2,
|
||||
EbvVertexId,
|
||||
EbvInstanceId,
|
||||
EbvVertexIndex,
|
||||
EbvInstanceIndex,
|
||||
EbvBaseVertex,
|
||||
EbvBaseInstance,
|
||||
EbvDrawId,
|
||||
EbvPosition,
|
||||
EbvPointSize,
|
||||
EbvClipVertex,
|
||||
EbvClipDistance,
|
||||
EbvCullDistance,
|
||||
EbvNormal,
|
||||
EbvVertex,
|
||||
EbvMultiTexCoord0,
|
||||
EbvMultiTexCoord1,
|
||||
EbvMultiTexCoord2,
|
||||
EbvMultiTexCoord3,
|
||||
EbvMultiTexCoord4,
|
||||
EbvMultiTexCoord5,
|
||||
EbvMultiTexCoord6,
|
||||
EbvMultiTexCoord7,
|
||||
EbvFrontColor,
|
||||
EbvBackColor,
|
||||
EbvFrontSecondaryColor,
|
||||
EbvBackSecondaryColor,
|
||||
EbvTexCoord,
|
||||
EbvFogFragCoord,
|
||||
EbvInvocationId,
|
||||
EbvPrimitiveId,
|
||||
EbvLayer,
|
||||
EbvViewportIndex,
|
||||
EbvPatchVertices,
|
||||
EbvTessLevelOuter,
|
||||
EbvTessLevelInner,
|
||||
EbvBoundingBox,
|
||||
EbvTessCoord,
|
||||
EbvColor,
|
||||
EbvSecondaryColor,
|
||||
EbvFace,
|
||||
EbvFragCoord,
|
||||
EbvPointCoord,
|
||||
EbvFragColor,
|
||||
EbvFragData,
|
||||
EbvFragDepth,
|
||||
EbvFragStencilRef,
|
||||
EbvSampleId,
|
||||
EbvSamplePosition,
|
||||
EbvSampleMask,
|
||||
EbvHelperInvocation,
|
||||
|
||||
EbvBaryCoordNoPersp,
|
||||
EbvBaryCoordNoPerspCentroid,
|
||||
EbvBaryCoordNoPerspSample,
|
||||
EbvBaryCoordSmooth,
|
||||
EbvBaryCoordSmoothCentroid,
|
||||
EbvBaryCoordSmoothSample,
|
||||
EbvBaryCoordPullModel,
|
||||
|
||||
EbvViewIndex,
|
||||
EbvDeviceIndex,
|
||||
|
||||
EbvShadingRateKHR,
|
||||
EbvPrimitiveShadingRateKHR,
|
||||
|
||||
EbvFragSizeEXT,
|
||||
EbvFragInvocationCountEXT,
|
||||
|
||||
EbvSecondaryFragDataEXT,
|
||||
EbvSecondaryFragColorEXT,
|
||||
|
||||
EbvViewportMaskNV,
|
||||
EbvSecondaryPositionNV,
|
||||
EbvSecondaryViewportMaskNV,
|
||||
EbvPositionPerViewNV,
|
||||
EbvViewportMaskPerViewNV,
|
||||
EbvFragFullyCoveredNV,
|
||||
EbvFragmentSizeNV,
|
||||
EbvInvocationsPerPixelNV,
|
||||
// ray tracing
|
||||
EbvLaunchId,
|
||||
EbvLaunchSize,
|
||||
EbvInstanceCustomIndex,
|
||||
EbvGeometryIndex,
|
||||
EbvWorldRayOrigin,
|
||||
EbvWorldRayDirection,
|
||||
EbvObjectRayOrigin,
|
||||
EbvObjectRayDirection,
|
||||
EbvRayTmin,
|
||||
EbvRayTmax,
|
||||
EbvHitT,
|
||||
EbvHitKind,
|
||||
EbvObjectToWorld,
|
||||
EbvObjectToWorld3x4,
|
||||
EbvWorldToObject,
|
||||
EbvWorldToObject3x4,
|
||||
EbvIncomingRayFlags,
|
||||
// barycentrics
|
||||
EbvBaryCoordNV,
|
||||
EbvBaryCoordNoPerspNV,
|
||||
// mesh shaders
|
||||
EbvTaskCountNV,
|
||||
EbvPrimitiveCountNV,
|
||||
EbvPrimitiveIndicesNV,
|
||||
EbvClipDistancePerViewNV,
|
||||
EbvCullDistancePerViewNV,
|
||||
EbvLayerPerViewNV,
|
||||
EbvMeshViewCountNV,
|
||||
EbvMeshViewIndicesNV,
|
||||
|
||||
// sm builtins
|
||||
EbvWarpsPerSM,
|
||||
EbvSMCount,
|
||||
EbvWarpID,
|
||||
EbvSMID,
|
||||
|
||||
// HLSL built-ins that live only temporarily, until they get remapped
|
||||
// to one of the above.
|
||||
EbvFragDepthGreater,
|
||||
EbvFragDepthLesser,
|
||||
EbvGsOutputStream,
|
||||
EbvOutputPatch,
|
||||
EbvInputPatch,
|
||||
|
||||
// structbuffer types
|
||||
EbvAppendConsume, // no need to differentiate append and consume
|
||||
EbvRWStructuredBuffer,
|
||||
EbvStructuredBuffer,
|
||||
EbvByteAddressBuffer,
|
||||
EbvRWByteAddressBuffer,
|
||||
|
||||
EbvLast
|
||||
};
|
||||
|
||||
// In this enum, order matters; users can assume higher precision is a bigger value
|
||||
// and EpqNone is 0.
|
||||
enum TPrecisionQualifier {
|
||||
EpqNone = 0,
|
||||
EpqLow,
|
||||
EpqMedium,
|
||||
EpqHigh
|
||||
};
|
||||
|
||||
#ifdef GLSLANG_WEB
|
||||
__inline const char* GetStorageQualifierString(TStorageQualifier q) { return ""; }
|
||||
__inline const char* GetPrecisionQualifierString(TPrecisionQualifier p) { return ""; }
|
||||
#else
|
||||
// These will show up in error messages
|
||||
__inline const char* GetStorageQualifierString(TStorageQualifier q)
|
||||
{
|
||||
switch (q) {
|
||||
case EvqTemporary: return "temp"; break;
|
||||
case EvqGlobal: return "global"; break;
|
||||
case EvqConst: return "const"; break;
|
||||
case EvqConstReadOnly: return "const (read only)"; break;
|
||||
case EvqVaryingIn: return "in"; break;
|
||||
case EvqVaryingOut: return "out"; break;
|
||||
case EvqUniform: return "uniform"; break;
|
||||
case EvqBuffer: return "buffer"; break;
|
||||
case EvqShared: return "shared"; break;
|
||||
case EvqIn: return "in"; break;
|
||||
case EvqOut: return "out"; break;
|
||||
case EvqInOut: return "inout"; break;
|
||||
case EvqVertexId: return "gl_VertexId"; break;
|
||||
case EvqInstanceId: return "gl_InstanceId"; break;
|
||||
case EvqPosition: return "gl_Position"; break;
|
||||
case EvqPointSize: return "gl_PointSize"; break;
|
||||
case EvqClipVertex: return "gl_ClipVertex"; break;
|
||||
case EvqFace: return "gl_FrontFacing"; break;
|
||||
case EvqFragCoord: return "gl_FragCoord"; break;
|
||||
case EvqPointCoord: return "gl_PointCoord"; break;
|
||||
case EvqFragColor: return "fragColor"; break;
|
||||
case EvqFragDepth: return "gl_FragDepth"; break;
|
||||
case EvqPayload: return "rayPayloadNV"; break;
|
||||
case EvqPayloadIn: return "rayPayloadInNV"; break;
|
||||
case EvqHitAttr: return "hitAttributeNV"; break;
|
||||
case EvqCallableData: return "callableDataNV"; break;
|
||||
case EvqCallableDataIn: return "callableDataInNV"; break;
|
||||
default: return "unknown qualifier";
|
||||
}
|
||||
}
|
||||
|
||||
__inline const char* GetBuiltInVariableString(TBuiltInVariable v)
|
||||
{
|
||||
switch (v) {
|
||||
case EbvNone: return "";
|
||||
case EbvNumWorkGroups: return "NumWorkGroups";
|
||||
case EbvWorkGroupSize: return "WorkGroupSize";
|
||||
case EbvWorkGroupId: return "WorkGroupID";
|
||||
case EbvLocalInvocationId: return "LocalInvocationID";
|
||||
case EbvGlobalInvocationId: return "GlobalInvocationID";
|
||||
case EbvLocalInvocationIndex: return "LocalInvocationIndex";
|
||||
case EbvNumSubgroups: return "NumSubgroups";
|
||||
case EbvSubgroupID: return "SubgroupID";
|
||||
case EbvSubGroupSize: return "SubGroupSize";
|
||||
case EbvSubGroupInvocation: return "SubGroupInvocation";
|
||||
case EbvSubGroupEqMask: return "SubGroupEqMask";
|
||||
case EbvSubGroupGeMask: return "SubGroupGeMask";
|
||||
case EbvSubGroupGtMask: return "SubGroupGtMask";
|
||||
case EbvSubGroupLeMask: return "SubGroupLeMask";
|
||||
case EbvSubGroupLtMask: return "SubGroupLtMask";
|
||||
case EbvSubgroupSize2: return "SubgroupSize";
|
||||
case EbvSubgroupInvocation2: return "SubgroupInvocationID";
|
||||
case EbvSubgroupEqMask2: return "SubgroupEqMask";
|
||||
case EbvSubgroupGeMask2: return "SubgroupGeMask";
|
||||
case EbvSubgroupGtMask2: return "SubgroupGtMask";
|
||||
case EbvSubgroupLeMask2: return "SubgroupLeMask";
|
||||
case EbvSubgroupLtMask2: return "SubgroupLtMask";
|
||||
case EbvVertexId: return "VertexId";
|
||||
case EbvInstanceId: return "InstanceId";
|
||||
case EbvVertexIndex: return "VertexIndex";
|
||||
case EbvInstanceIndex: return "InstanceIndex";
|
||||
case EbvBaseVertex: return "BaseVertex";
|
||||
case EbvBaseInstance: return "BaseInstance";
|
||||
case EbvDrawId: return "DrawId";
|
||||
case EbvPosition: return "Position";
|
||||
case EbvPointSize: return "PointSize";
|
||||
case EbvClipVertex: return "ClipVertex";
|
||||
case EbvClipDistance: return "ClipDistance";
|
||||
case EbvCullDistance: return "CullDistance";
|
||||
case EbvNormal: return "Normal";
|
||||
case EbvVertex: return "Vertex";
|
||||
case EbvMultiTexCoord0: return "MultiTexCoord0";
|
||||
case EbvMultiTexCoord1: return "MultiTexCoord1";
|
||||
case EbvMultiTexCoord2: return "MultiTexCoord2";
|
||||
case EbvMultiTexCoord3: return "MultiTexCoord3";
|
||||
case EbvMultiTexCoord4: return "MultiTexCoord4";
|
||||
case EbvMultiTexCoord5: return "MultiTexCoord5";
|
||||
case EbvMultiTexCoord6: return "MultiTexCoord6";
|
||||
case EbvMultiTexCoord7: return "MultiTexCoord7";
|
||||
case EbvFrontColor: return "FrontColor";
|
||||
case EbvBackColor: return "BackColor";
|
||||
case EbvFrontSecondaryColor: return "FrontSecondaryColor";
|
||||
case EbvBackSecondaryColor: return "BackSecondaryColor";
|
||||
case EbvTexCoord: return "TexCoord";
|
||||
case EbvFogFragCoord: return "FogFragCoord";
|
||||
case EbvInvocationId: return "InvocationID";
|
||||
case EbvPrimitiveId: return "PrimitiveID";
|
||||
case EbvLayer: return "Layer";
|
||||
case EbvViewportIndex: return "ViewportIndex";
|
||||
case EbvPatchVertices: return "PatchVertices";
|
||||
case EbvTessLevelOuter: return "TessLevelOuter";
|
||||
case EbvTessLevelInner: return "TessLevelInner";
|
||||
case EbvBoundingBox: return "BoundingBox";
|
||||
case EbvTessCoord: return "TessCoord";
|
||||
case EbvColor: return "Color";
|
||||
case EbvSecondaryColor: return "SecondaryColor";
|
||||
case EbvFace: return "Face";
|
||||
case EbvFragCoord: return "FragCoord";
|
||||
case EbvPointCoord: return "PointCoord";
|
||||
case EbvFragColor: return "FragColor";
|
||||
case EbvFragData: return "FragData";
|
||||
case EbvFragDepth: return "FragDepth";
|
||||
case EbvFragStencilRef: return "FragStencilRef";
|
||||
case EbvSampleId: return "SampleId";
|
||||
case EbvSamplePosition: return "SamplePosition";
|
||||
case EbvSampleMask: return "SampleMaskIn";
|
||||
case EbvHelperInvocation: return "HelperInvocation";
|
||||
|
||||
case EbvBaryCoordNoPersp: return "BaryCoordNoPersp";
|
||||
case EbvBaryCoordNoPerspCentroid: return "BaryCoordNoPerspCentroid";
|
||||
case EbvBaryCoordNoPerspSample: return "BaryCoordNoPerspSample";
|
||||
case EbvBaryCoordSmooth: return "BaryCoordSmooth";
|
||||
case EbvBaryCoordSmoothCentroid: return "BaryCoordSmoothCentroid";
|
||||
case EbvBaryCoordSmoothSample: return "BaryCoordSmoothSample";
|
||||
case EbvBaryCoordPullModel: return "BaryCoordPullModel";
|
||||
|
||||
case EbvViewIndex: return "ViewIndex";
|
||||
case EbvDeviceIndex: return "DeviceIndex";
|
||||
|
||||
case EbvFragSizeEXT: return "FragSizeEXT";
|
||||
case EbvFragInvocationCountEXT: return "FragInvocationCountEXT";
|
||||
|
||||
case EbvSecondaryFragDataEXT: return "SecondaryFragDataEXT";
|
||||
case EbvSecondaryFragColorEXT: return "SecondaryFragColorEXT";
|
||||
|
||||
case EbvViewportMaskNV: return "ViewportMaskNV";
|
||||
case EbvSecondaryPositionNV: return "SecondaryPositionNV";
|
||||
case EbvSecondaryViewportMaskNV: return "SecondaryViewportMaskNV";
|
||||
case EbvPositionPerViewNV: return "PositionPerViewNV";
|
||||
case EbvViewportMaskPerViewNV: return "ViewportMaskPerViewNV";
|
||||
case EbvFragFullyCoveredNV: return "FragFullyCoveredNV";
|
||||
case EbvFragmentSizeNV: return "FragmentSizeNV";
|
||||
case EbvInvocationsPerPixelNV: return "InvocationsPerPixelNV";
|
||||
case EbvLaunchId: return "LaunchIdNV";
|
||||
case EbvLaunchSize: return "LaunchSizeNV";
|
||||
case EbvInstanceCustomIndex: return "InstanceCustomIndexNV";
|
||||
case EbvGeometryIndex: return "GeometryIndexEXT";
|
||||
case EbvWorldRayOrigin: return "WorldRayOriginNV";
|
||||
case EbvWorldRayDirection: return "WorldRayDirectionNV";
|
||||
case EbvObjectRayOrigin: return "ObjectRayOriginNV";
|
||||
case EbvObjectRayDirection: return "ObjectRayDirectionNV";
|
||||
case EbvRayTmin: return "ObjectRayTminNV";
|
||||
case EbvRayTmax: return "ObjectRayTmaxNV";
|
||||
case EbvHitT: return "HitTNV";
|
||||
case EbvHitKind: return "HitKindNV";
|
||||
case EbvIncomingRayFlags: return "IncomingRayFlagsNV";
|
||||
case EbvObjectToWorld: return "ObjectToWorldNV";
|
||||
case EbvWorldToObject: return "WorldToObjectNV";
|
||||
|
||||
case EbvBaryCoordNV: return "BaryCoordNV";
|
||||
case EbvBaryCoordNoPerspNV: return "BaryCoordNoPerspNV";
|
||||
|
||||
case EbvTaskCountNV: return "TaskCountNV";
|
||||
case EbvPrimitiveCountNV: return "PrimitiveCountNV";
|
||||
case EbvPrimitiveIndicesNV: return "PrimitiveIndicesNV";
|
||||
case EbvClipDistancePerViewNV: return "ClipDistancePerViewNV";
|
||||
case EbvCullDistancePerViewNV: return "CullDistancePerViewNV";
|
||||
case EbvLayerPerViewNV: return "LayerPerViewNV";
|
||||
case EbvMeshViewCountNV: return "MeshViewCountNV";
|
||||
case EbvMeshViewIndicesNV: return "MeshViewIndicesNV";
|
||||
|
||||
case EbvWarpsPerSM: return "WarpsPerSMNV";
|
||||
case EbvSMCount: return "SMCountNV";
|
||||
case EbvWarpID: return "WarpIDNV";
|
||||
case EbvSMID: return "SMIDNV";
|
||||
|
||||
case EbvShadingRateKHR: return "ShadingRateKHR";
|
||||
case EbvPrimitiveShadingRateKHR: return "PrimitiveShadingRateKHR";
|
||||
|
||||
default: return "unknown built-in variable";
|
||||
}
|
||||
}
|
||||
|
||||
__inline const char* GetPrecisionQualifierString(TPrecisionQualifier p)
|
||||
{
|
||||
switch (p) {
|
||||
case EpqNone: return ""; break;
|
||||
case EpqLow: return "lowp"; break;
|
||||
case EpqMedium: return "mediump"; break;
|
||||
case EpqHigh: return "highp"; break;
|
||||
default: return "unknown precision qualifier";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
__inline bool isTypeSignedInt(TBasicType type)
|
||||
{
|
||||
switch (type) {
|
||||
case EbtInt8:
|
||||
case EbtInt16:
|
||||
case EbtInt:
|
||||
case EbtInt64:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__inline bool isTypeUnsignedInt(TBasicType type)
|
||||
{
|
||||
switch (type) {
|
||||
case EbtUint8:
|
||||
case EbtUint16:
|
||||
case EbtUint:
|
||||
case EbtUint64:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__inline bool isTypeInt(TBasicType type)
|
||||
{
|
||||
return isTypeSignedInt(type) || isTypeUnsignedInt(type);
|
||||
}
|
||||
|
||||
__inline bool isTypeFloat(TBasicType type)
|
||||
{
|
||||
switch (type) {
|
||||
case EbtFloat:
|
||||
case EbtDouble:
|
||||
case EbtFloat16:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__inline int getTypeRank(TBasicType type)
|
||||
{
|
||||
int res = -1;
|
||||
switch(type) {
|
||||
case EbtInt8:
|
||||
case EbtUint8:
|
||||
res = 0;
|
||||
break;
|
||||
case EbtInt16:
|
||||
case EbtUint16:
|
||||
res = 1;
|
||||
break;
|
||||
case EbtInt:
|
||||
case EbtUint:
|
||||
res = 2;
|
||||
break;
|
||||
case EbtInt64:
|
||||
case EbtUint64:
|
||||
res = 3;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _BASICTYPES_INCLUDED_
|
||||
@@ -0,0 +1,303 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
#ifndef _COMMON_INCLUDED_
|
||||
#define _COMMON_INCLUDED_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#if defined(__ANDROID__) || (defined(_MSC_VER) && _MSC_VER < 1700)
|
||||
#include <sstream>
|
||||
namespace std {
|
||||
template<typename T>
|
||||
std::string to_string(const T& val) {
|
||||
std::ostringstream os;
|
||||
os << val;
|
||||
return os.str();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/) || defined MINGW_HAS_SECURE_API
|
||||
#include <basetsd.h>
|
||||
#ifndef snprintf
|
||||
#define snprintf sprintf_s
|
||||
#endif
|
||||
#define safe_vsprintf(buf,max,format,args) vsnprintf_s((buf), (max), (max), (format), (args))
|
||||
#elif defined (solaris)
|
||||
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
|
||||
#include <sys/int_types.h>
|
||||
#define UINT_PTR uintptr_t
|
||||
#else
|
||||
#define safe_vsprintf(buf,max,format,args) vsnprintf((buf), (max), (format), (args))
|
||||
#include <stdint.h>
|
||||
#define UINT_PTR uintptr_t
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1800
|
||||
#include <stdlib.h>
|
||||
inline long long int strtoll (const char* str, char** endptr, int base)
|
||||
{
|
||||
return _strtoi64(str, endptr, base);
|
||||
}
|
||||
inline unsigned long long int strtoull (const char* str, char** endptr, int base)
|
||||
{
|
||||
return _strtoui64(str, endptr, base);
|
||||
}
|
||||
inline long long int atoll (const char* str)
|
||||
{
|
||||
return strtoll(str, NULL, 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
/* windows only pragma */
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4786) // Don't warn about too long identifiers
|
||||
#pragma warning(disable : 4514) // unused inline method
|
||||
#pragma warning(disable : 4201) // nameless union
|
||||
#endif
|
||||
|
||||
#include "PoolAlloc.h"
|
||||
|
||||
//
|
||||
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
|
||||
//
|
||||
#define POOL_ALLOCATOR_NEW_DELETE(A) \
|
||||
void* operator new(size_t s) { return (A).allocate(s); } \
|
||||
void* operator new(size_t, void *_Where) { return (_Where); } \
|
||||
void operator delete(void*) { } \
|
||||
void operator delete(void *, void *) { } \
|
||||
void* operator new[](size_t s) { return (A).allocate(s); } \
|
||||
void* operator new[](size_t, void *_Where) { return (_Where); } \
|
||||
void operator delete[](void*) { } \
|
||||
void operator delete[](void *, void *) { }
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Pool version of string.
|
||||
//
|
||||
typedef pool_allocator<char> TStringAllocator;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
// Repackage the std::hash for use by unordered map/set with a TString key.
|
||||
namespace std {
|
||||
|
||||
template<> struct hash<glslang::TString> {
|
||||
std::size_t operator()(const glslang::TString& s) const
|
||||
{
|
||||
const unsigned _FNV_offset_basis = 2166136261U;
|
||||
const unsigned _FNV_prime = 16777619U;
|
||||
unsigned _Val = _FNV_offset_basis;
|
||||
size_t _Count = s.size();
|
||||
const char* _First = s.c_str();
|
||||
for (size_t _Next = 0; _Next < _Count; ++_Next)
|
||||
{
|
||||
_Val ^= (unsigned)_First[_Next];
|
||||
_Val *= _FNV_prime;
|
||||
}
|
||||
|
||||
return _Val;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace glslang {
|
||||
|
||||
inline TString* NewPoolTString(const char* s)
|
||||
{
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TString));
|
||||
return new(memory) TString(s);
|
||||
}
|
||||
|
||||
template<class T> inline T* NewPoolObject(T*)
|
||||
{
|
||||
return new(GetThreadPoolAllocator().allocate(sizeof(T))) T;
|
||||
}
|
||||
|
||||
template<class T> inline T* NewPoolObject(T, int instances)
|
||||
{
|
||||
return new(GetThreadPoolAllocator().allocate(instances * sizeof(T))) T[instances];
|
||||
}
|
||||
|
||||
//
|
||||
// Pool allocator versions of vectors, lists, and maps
|
||||
//
|
||||
template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
|
||||
TVector() : std::vector<T, pool_allocator<T> >() {}
|
||||
TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
|
||||
TVector(size_type i) : std::vector<T, pool_allocator<T> >(i) {}
|
||||
TVector(size_type i, const T& val) : std::vector<T, pool_allocator<T> >(i, val) {}
|
||||
};
|
||||
|
||||
template <class T> class TList : public std::list<T, pool_allocator<T> > {
|
||||
};
|
||||
|
||||
template <class K, class D, class CMP = std::less<K> >
|
||||
class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<K const, D> > > {
|
||||
};
|
||||
|
||||
template <class K, class D, class HASH = std::hash<K>, class PRED = std::equal_to<K> >
|
||||
class TUnorderedMap : public std::unordered_map<K, D, HASH, PRED, pool_allocator<std::pair<K const, D> > > {
|
||||
};
|
||||
|
||||
//
|
||||
// Persistent string memory. Should only be used for strings that survive
|
||||
// across compiles/links.
|
||||
//
|
||||
typedef std::basic_string<char> TPersistString;
|
||||
|
||||
//
|
||||
// templatized min and max functions.
|
||||
//
|
||||
template <class T> T Min(const T a, const T b) { return a < b ? a : b; }
|
||||
template <class T> T Max(const T a, const T b) { return a > b ? a : b; }
|
||||
|
||||
//
|
||||
// Create a TString object from an integer.
|
||||
//
|
||||
#if defined _MSC_VER || defined MINGW_HAS_SECURE_API
|
||||
inline const TString String(const int i, const int base = 10)
|
||||
{
|
||||
char text[16]; // 32 bit ints are at most 10 digits in base 10
|
||||
_itoa_s(i, text, sizeof(text), base);
|
||||
return text;
|
||||
}
|
||||
#else
|
||||
inline const TString String(const int i, const int /*base*/ = 10)
|
||||
{
|
||||
char text[16]; // 32 bit ints are at most 10 digits in base 10
|
||||
|
||||
// we assume base 10 for all cases
|
||||
snprintf(text, sizeof(text), "%d", i);
|
||||
|
||||
return text;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct TSourceLoc {
|
||||
void init()
|
||||
{
|
||||
name = nullptr; string = 0; line = 0; column = 0;
|
||||
}
|
||||
void init(int stringNum) { init(); string = stringNum; }
|
||||
// Returns the name if it exists. Otherwise, returns the string number.
|
||||
std::string getStringNameOrNum(bool quoteStringName = true) const
|
||||
{
|
||||
if (name != nullptr) {
|
||||
TString qstr = quoteStringName ? ("\"" + *name + "\"") : *name;
|
||||
std::string ret_str(qstr.c_str());
|
||||
return ret_str;
|
||||
}
|
||||
return std::to_string((long long)string);
|
||||
}
|
||||
const char* getFilename() const
|
||||
{
|
||||
if (name == nullptr)
|
||||
return nullptr;
|
||||
return name->c_str();
|
||||
}
|
||||
const char* getFilenameStr() const { return name == nullptr ? "" : name->c_str(); }
|
||||
TString* name; // descriptive name for this string, when a textual name is available, otherwise nullptr
|
||||
int string;
|
||||
int line;
|
||||
int column;
|
||||
};
|
||||
|
||||
class TPragmaTable : public TMap<TString, TString> {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
};
|
||||
|
||||
const int MaxTokenLength = 1024;
|
||||
|
||||
template <class T> bool IsPow2(T powerOf2)
|
||||
{
|
||||
if (powerOf2 <= 0)
|
||||
return false;
|
||||
|
||||
return (powerOf2 & (powerOf2 - 1)) == 0;
|
||||
}
|
||||
|
||||
// Round number up to a multiple of the given powerOf2, which is not
|
||||
// a power, just a number that must be a power of 2.
|
||||
template <class T> void RoundToPow2(T& number, int powerOf2)
|
||||
{
|
||||
assert(IsPow2(powerOf2));
|
||||
number = (number + powerOf2 - 1) & ~(powerOf2 - 1);
|
||||
}
|
||||
|
||||
template <class T> bool IsMultipleOfPow2(T number, int powerOf2)
|
||||
{
|
||||
assert(IsPow2(powerOf2));
|
||||
return ! (number & (powerOf2 - 1));
|
||||
}
|
||||
|
||||
// Returns log2 of an integer power of 2.
|
||||
// T should be integral.
|
||||
template <class T> int IntLog2(T n)
|
||||
{
|
||||
assert(IsPow2(n));
|
||||
int result = 0;
|
||||
while ((T(1) << result) != n) {
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _COMMON_INCLUDED_
|
||||
@@ -0,0 +1,974 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013 LunarG, Inc.
|
||||
// Copyright (C) 2017 ARM Limited.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
#ifndef _CONSTANT_UNION_INCLUDED_
|
||||
#define _CONSTANT_UNION_INCLUDED_
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/BaseTypes.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TConstUnion {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TConstUnion() : iConst(0), type(EbtInt) { }
|
||||
|
||||
void setI8Const(signed char i)
|
||||
{
|
||||
i8Const = i;
|
||||
type = EbtInt8;
|
||||
}
|
||||
|
||||
void setU8Const(unsigned char u)
|
||||
{
|
||||
u8Const = u;
|
||||
type = EbtUint8;
|
||||
}
|
||||
|
||||
void setI16Const(signed short i)
|
||||
{
|
||||
i16Const = i;
|
||||
type = EbtInt16;
|
||||
}
|
||||
|
||||
void setU16Const(unsigned short u)
|
||||
{
|
||||
u16Const = u;
|
||||
type = EbtUint16;
|
||||
}
|
||||
|
||||
void setIConst(int i)
|
||||
{
|
||||
iConst = i;
|
||||
type = EbtInt;
|
||||
}
|
||||
|
||||
void setUConst(unsigned int u)
|
||||
{
|
||||
uConst = u;
|
||||
type = EbtUint;
|
||||
}
|
||||
|
||||
void setI64Const(long long i64)
|
||||
{
|
||||
i64Const = i64;
|
||||
type = EbtInt64;
|
||||
}
|
||||
|
||||
void setU64Const(unsigned long long u64)
|
||||
{
|
||||
u64Const = u64;
|
||||
type = EbtUint64;
|
||||
}
|
||||
|
||||
void setDConst(double d)
|
||||
{
|
||||
dConst = d;
|
||||
type = EbtDouble;
|
||||
}
|
||||
|
||||
void setBConst(bool b)
|
||||
{
|
||||
bConst = b;
|
||||
type = EbtBool;
|
||||
}
|
||||
|
||||
void setSConst(const TString* s)
|
||||
{
|
||||
sConst = s;
|
||||
type = EbtString;
|
||||
}
|
||||
|
||||
signed char getI8Const() const { return i8Const; }
|
||||
unsigned char getU8Const() const { return u8Const; }
|
||||
signed short getI16Const() const { return i16Const; }
|
||||
unsigned short getU16Const() const { return u16Const; }
|
||||
int getIConst() const { return iConst; }
|
||||
unsigned int getUConst() const { return uConst; }
|
||||
long long getI64Const() const { return i64Const; }
|
||||
unsigned long long getU64Const() const { return u64Const; }
|
||||
double getDConst() const { return dConst; }
|
||||
bool getBConst() const { return bConst; }
|
||||
const TString* getSConst() const { return sConst; }
|
||||
|
||||
bool operator==(const signed char i) const
|
||||
{
|
||||
if (i == i8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned char u) const
|
||||
{
|
||||
if (u == u8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const signed short i) const
|
||||
{
|
||||
if (i == i16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned short u) const
|
||||
{
|
||||
if (u == u16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const int i) const
|
||||
{
|
||||
if (i == iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned int u) const
|
||||
{
|
||||
if (u == uConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const long long i64) const
|
||||
{
|
||||
if (i64 == i64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const unsigned long long u64) const
|
||||
{
|
||||
if (u64 == u64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const double d) const
|
||||
{
|
||||
if (d == dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const bool b) const
|
||||
{
|
||||
if (b == bConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const TConstUnion& constant) const
|
||||
{
|
||||
if (constant.type != type)
|
||||
return false;
|
||||
|
||||
switch (type) {
|
||||
case EbtInt:
|
||||
if (constant.iConst == iConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint:
|
||||
if (constant.uConst == uConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtBool:
|
||||
if (constant.bConst == bConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtDouble:
|
||||
if (constant.dConst == dConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt16:
|
||||
if (constant.i16Const == i16Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint16:
|
||||
if (constant.u16Const == u16Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtInt8:
|
||||
if (constant.i8Const == i8Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint8:
|
||||
if (constant.u8Const == u8Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtInt64:
|
||||
if (constant.i64Const == i64Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtUint64:
|
||||
if (constant.u64Const == u64Const)
|
||||
return true;
|
||||
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=(const signed char i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned char u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const signed short i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned short u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const int i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned int u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const long long i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const unsigned long long u) const
|
||||
{
|
||||
return !operator==(u);
|
||||
}
|
||||
|
||||
bool operator!=(const float f) const
|
||||
{
|
||||
return !operator==(f);
|
||||
}
|
||||
|
||||
bool operator!=(const bool b) const
|
||||
{
|
||||
return !operator==(b);
|
||||
}
|
||||
|
||||
bool operator!=(const TConstUnion& constant) const
|
||||
{
|
||||
return !operator==(constant);
|
||||
}
|
||||
|
||||
bool operator>(const TConstUnion& constant) const
|
||||
{
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt:
|
||||
if (iConst > constant.iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint:
|
||||
if (uConst > constant.uConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtDouble:
|
||||
if (dConst > constant.dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
if (i8Const > constant.i8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint8:
|
||||
if (u8Const > constant.u8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt16:
|
||||
if (i16Const > constant.i16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint16:
|
||||
if (u16Const > constant.u16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt64:
|
||||
if (i64Const > constant.i64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint64:
|
||||
if (u64Const > constant.u64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#endif
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(const TConstUnion& constant) const
|
||||
{
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
if (i8Const < constant.i8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint8:
|
||||
if (u8Const < constant.u8Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt16:
|
||||
if (i16Const < constant.i16Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint16:
|
||||
if (u16Const < constant.u16Const)
|
||||
return true;
|
||||
return false;
|
||||
case EbtInt64:
|
||||
if (i64Const < constant.i64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint64:
|
||||
if (u64Const < constant.u64Const)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#endif
|
||||
case EbtDouble:
|
||||
if (dConst < constant.dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtInt:
|
||||
if (iConst < constant.iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtUint:
|
||||
if (uConst < constant.uConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TConstUnion operator+(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst + constant.uConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const + constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const + constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const + constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const + constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const + constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const + constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator-(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst - constant.uConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const - constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const - constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const - constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const - constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const - constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const - constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator*(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst * constant.uConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const * constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const * constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const * constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const * constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const * constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const * constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator%(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst % constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const % constant.i8Const); break;
|
||||
case EbtInt16: returnValue.setI8Const(i8Const % constant.i16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const % constant.i64Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const % constant.u8Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const % constant.u16Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const % constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator>>(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
switch (type) {
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI8Const(i8Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI8Const(i8Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI8Const(i8Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI8Const(i8Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI8Const(i8Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setI8Const(i8Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI8Const(i8Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI8Const(i8Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU8Const(u8Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU8Const(u8Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU8Const(u8Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU8Const(u8Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setU8Const(u8Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU8Const(u8Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU8Const(u8Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtInt16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI16Const(i16Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI16Const(i16Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI16Const(i16Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI16Const(i16Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setI16Const(i16Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI16Const(i16Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI16Const(i16Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU16Const(u16Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU16Const(u16Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU16Const(u16Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU16Const(u16Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setU16Const(u16Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU16Const(u16Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU16Const(u16Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case EbtInt:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setIConst(iConst >> constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setIConst(iConst >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setIConst(iConst >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setIConst(iConst >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setIConst(iConst >> constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setIConst(iConst >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setIConst(iConst >> constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setUConst(uConst >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst >> constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setUConst(uConst >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setUConst(uConst >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setUConst(uConst >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setUConst(uConst >> constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setUConst(uConst >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setUConst(uConst >> constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI64Const(i64Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI64Const(i64Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI64Const(i64Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI64Const(i64Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI64Const(i64Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setI64Const(i64Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI64Const(i64Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU64Const(u64Const >> constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU64Const(u64Const >> constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU64Const(u64Const >> constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU64Const(u64Const >> constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU64Const(u64Const >> constant.iConst); break;
|
||||
case EbtUint: returnValue.setU64Const(u64Const >> constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU64Const(u64Const >> constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const >> constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator<<(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
switch (type) {
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI8Const(i8Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI8Const(i8Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI8Const(i8Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI8Const(i8Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI8Const(i8Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setI8Const(i8Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI8Const(i8Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI8Const(i8Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint8:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU8Const(u8Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU8Const(u8Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU8Const(u8Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU8Const(u8Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setU8Const(u8Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU8Const(u8Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU8Const(u8Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtInt16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI16Const(i16Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI16Const(i16Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI16Const(i16Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI16Const(i16Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setI16Const(i16Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI16Const(i16Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI16Const(i16Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint16:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU16Const(u16Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU16Const(u16Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU16Const(u16Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU16Const(u16Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setU16Const(u16Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU16Const(u16Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU16Const(u16Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtInt64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setI64Const(i64Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setI64Const(i64Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI64Const(i64Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setI64Const(i64Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setI64Const(i64Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setI64Const(i64Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setI64Const(i64Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint64:
|
||||
switch (constant.type) {
|
||||
case EbtInt8: returnValue.setU64Const(u64Const << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU64Const(u64Const << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setU64Const(u64Const << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU64Const(u64Const << constant.u16Const); break;
|
||||
case EbtInt: returnValue.setU64Const(u64Const << constant.iConst); break;
|
||||
case EbtUint: returnValue.setU64Const(u64Const << constant.uConst); break;
|
||||
case EbtInt64: returnValue.setU64Const(u64Const << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const << constant.u64Const); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case EbtInt:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
|
||||
case EbtUint: returnValue.setIConst(iConst << constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setIConst(iConst << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setIConst(iConst << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setIConst(iConst << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setIConst(iConst << constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setIConst(iConst << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setIConst(iConst << constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
case EbtUint:
|
||||
switch (constant.type) {
|
||||
case EbtInt: returnValue.setUConst(uConst << constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst << constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setUConst(uConst << constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setUConst(uConst << constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setUConst(uConst << constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setUConst(uConst << constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setUConst(uConst << constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setUConst(uConst << constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator&(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst & constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const & constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const & constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const & constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const & constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const & constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const & constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator|(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst | constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const | constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const | constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const | constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const | constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const | constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const | constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator^(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
|
||||
case EbtUint: returnValue.setUConst(uConst ^ constant.uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(i8Const ^ constant.i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(u8Const ^ constant.u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(i16Const ^ constant.i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(u16Const ^ constant.u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(i64Const ^ constant.i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(u64Const ^ constant.u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator~() const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(~iConst); break;
|
||||
case EbtUint: returnValue.setUConst(~uConst); break;
|
||||
#ifndef GLSLANG_WEB
|
||||
case EbtInt8: returnValue.setI8Const(~i8Const); break;
|
||||
case EbtUint8: returnValue.setU8Const(~u8Const); break;
|
||||
case EbtInt16: returnValue.setI16Const(~i16Const); break;
|
||||
case EbtUint16: returnValue.setU16Const(~u16Const); break;
|
||||
case EbtInt64: returnValue.setI64Const(~i64Const); break;
|
||||
case EbtUint64: returnValue.setU64Const(~u64Const); break;
|
||||
#endif
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator&&(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TConstUnion operator||(const TConstUnion& constant) const
|
||||
{
|
||||
TConstUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TBasicType getType() const { return type; }
|
||||
|
||||
private:
|
||||
union {
|
||||
signed char i8Const; // used for i8vec, scalar int8s
|
||||
unsigned char u8Const; // used for u8vec, scalar uint8s
|
||||
signed short i16Const; // used for i16vec, scalar int16s
|
||||
unsigned short u16Const; // used for u16vec, scalar uint16s
|
||||
int iConst; // used for ivec, scalar ints
|
||||
unsigned int uConst; // used for uvec, scalar uints
|
||||
long long i64Const; // used for i64vec, scalar int64s
|
||||
unsigned long long u64Const; // used for u64vec, scalar uint64s
|
||||
bool bConst; // used for bvec, scalar bools
|
||||
double dConst; // used for vec, dvec, mat, dmat, scalar floats and doubles
|
||||
const TString* sConst; // string constant
|
||||
};
|
||||
|
||||
TBasicType type;
|
||||
};
|
||||
|
||||
// Encapsulate having a pointer to an array of TConstUnion,
|
||||
// which only needs to be allocated if its size is going to be
|
||||
// bigger than 0.
|
||||
//
|
||||
// One convenience is being able to use [] to go inside the array, instead
|
||||
// of C++ assuming it as an array of pointers to vectors.
|
||||
//
|
||||
// General usage is that the size is known up front, and it is
|
||||
// created once with the proper size.
|
||||
//
|
||||
class TConstUnionArray {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TConstUnionArray() : unionArray(nullptr) { }
|
||||
virtual ~TConstUnionArray() { }
|
||||
|
||||
explicit TConstUnionArray(int size)
|
||||
{
|
||||
if (size == 0)
|
||||
unionArray = nullptr;
|
||||
else
|
||||
unionArray = new TConstUnionVector(size);
|
||||
}
|
||||
TConstUnionArray(const TConstUnionArray& a) = default;
|
||||
TConstUnionArray(const TConstUnionArray& a, int start, int size)
|
||||
{
|
||||
unionArray = new TConstUnionVector(size);
|
||||
for (int i = 0; i < size; ++i)
|
||||
(*unionArray)[i] = a[start + i];
|
||||
}
|
||||
|
||||
// Use this constructor for a smear operation
|
||||
TConstUnionArray(int size, const TConstUnion& val)
|
||||
{
|
||||
unionArray = new TConstUnionVector(size, val);
|
||||
}
|
||||
|
||||
int size() const { return unionArray ? (int)unionArray->size() : 0; }
|
||||
TConstUnion& operator[](size_t index) { return (*unionArray)[index]; }
|
||||
const TConstUnion& operator[](size_t index) const { return (*unionArray)[index]; }
|
||||
bool operator==(const TConstUnionArray& rhs) const
|
||||
{
|
||||
// this includes the case that both are unallocated
|
||||
if (unionArray == rhs.unionArray)
|
||||
return true;
|
||||
|
||||
if (! unionArray || ! rhs.unionArray)
|
||||
return false;
|
||||
|
||||
return *unionArray == *rhs.unionArray;
|
||||
}
|
||||
bool operator!=(const TConstUnionArray& rhs) const { return ! operator==(rhs); }
|
||||
|
||||
double dot(const TConstUnionArray& rhs)
|
||||
{
|
||||
assert(rhs.unionArray->size() == unionArray->size());
|
||||
double sum = 0.0;
|
||||
|
||||
for (size_t comp = 0; comp < unionArray->size(); ++comp)
|
||||
sum += (*this)[comp].getDConst() * rhs[comp].getDConst();
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool empty() const { return unionArray == nullptr; }
|
||||
|
||||
protected:
|
||||
typedef TVector<TConstUnion> TConstUnionVector;
|
||||
TConstUnionVector* unionArray;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _CONSTANT_UNION_INCLUDED_
|
||||
@@ -0,0 +1,316 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
#ifndef _POOLALLOC_INCLUDED_
|
||||
#define _POOLALLOC_INCLUDED_
|
||||
|
||||
#ifdef _DEBUG
|
||||
# define GUARD_BLOCKS // define to enable guard block sanity checking
|
||||
#endif
|
||||
|
||||
//
|
||||
// This header defines an allocator that can be used to efficiently
|
||||
// allocate a large number of small requests for heap memory, with the
|
||||
// intention that they are not individually deallocated, but rather
|
||||
// collectively deallocated at one time.
|
||||
//
|
||||
// This simultaneously
|
||||
//
|
||||
// * Makes each individual allocation much more efficient; the
|
||||
// typical allocation is trivial.
|
||||
// * Completely avoids the cost of doing individual deallocation.
|
||||
// * Saves the trouble of tracking down and plugging a large class of leaks.
|
||||
//
|
||||
// Individual classes can use this allocator by supplying their own
|
||||
// new and delete methods.
|
||||
//
|
||||
// STL containers can use this allocator by using the pool_allocator
|
||||
// class as the allocator (second) template argument.
|
||||
//
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// If we are using guard blocks, we must track each individual
|
||||
// allocation. If we aren't using guard blocks, these
|
||||
// never get instantiated, so won't have any impact.
|
||||
//
|
||||
|
||||
class TAllocation {
|
||||
public:
|
||||
TAllocation(size_t size, unsigned char* mem, TAllocation* prev = 0) :
|
||||
size(size), mem(mem), prevAlloc(prev) {
|
||||
// Allocations are bracketed:
|
||||
// [allocationHeader][initialGuardBlock][userData][finalGuardBlock]
|
||||
// This would be cleaner with if (guardBlockSize)..., but that
|
||||
// makes the compiler print warnings about 0 length memsets,
|
||||
// even with the if() protecting them.
|
||||
# ifdef GUARD_BLOCKS
|
||||
memset(preGuard(), guardBlockBeginVal, guardBlockSize);
|
||||
memset(data(), userDataFill, size);
|
||||
memset(postGuard(), guardBlockEndVal, guardBlockSize);
|
||||
# endif
|
||||
}
|
||||
|
||||
void check() const {
|
||||
checkGuardBlock(preGuard(), guardBlockBeginVal, "before");
|
||||
checkGuardBlock(postGuard(), guardBlockEndVal, "after");
|
||||
}
|
||||
|
||||
void checkAllocList() const;
|
||||
|
||||
// Return total size needed to accommodate user buffer of 'size',
|
||||
// plus our tracking data.
|
||||
inline static size_t allocationSize(size_t size) {
|
||||
return size + 2 * guardBlockSize + headerSize();
|
||||
}
|
||||
|
||||
// Offset from surrounding buffer to get to user data buffer.
|
||||
inline static unsigned char* offsetAllocation(unsigned char* m) {
|
||||
return m + guardBlockSize + headerSize();
|
||||
}
|
||||
|
||||
private:
|
||||
void checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const;
|
||||
|
||||
// Find offsets to pre and post guard blocks, and user data buffer
|
||||
unsigned char* preGuard() const { return mem + headerSize(); }
|
||||
unsigned char* data() const { return preGuard() + guardBlockSize; }
|
||||
unsigned char* postGuard() const { return data() + size; }
|
||||
|
||||
size_t size; // size of the user data area
|
||||
unsigned char* mem; // beginning of our allocation (pts to header)
|
||||
TAllocation* prevAlloc; // prior allocation in the chain
|
||||
|
||||
const static unsigned char guardBlockBeginVal;
|
||||
const static unsigned char guardBlockEndVal;
|
||||
const static unsigned char userDataFill;
|
||||
|
||||
const static size_t guardBlockSize;
|
||||
# ifdef GUARD_BLOCKS
|
||||
inline static size_t headerSize() { return sizeof(TAllocation); }
|
||||
# else
|
||||
inline static size_t headerSize() { return 0; }
|
||||
# endif
|
||||
};
|
||||
|
||||
//
|
||||
// There are several stacks. One is to track the pushing and popping
|
||||
// of the user, and not yet implemented. The others are simply a
|
||||
// repositories of free pages or used pages.
|
||||
//
|
||||
// Page stacks are linked together with a simple header at the beginning
|
||||
// of each allocation obtained from the underlying OS. Multi-page allocations
|
||||
// are returned to the OS. Individual page allocations are kept for future
|
||||
// re-use.
|
||||
//
|
||||
// The "page size" used is not, nor must it match, the underlying OS
|
||||
// page size. But, having it be about that size or equal to a set of
|
||||
// pages is likely most optimal.
|
||||
//
|
||||
class TPoolAllocator {
|
||||
public:
|
||||
TPoolAllocator(int growthIncrement = 8*1024, int allocationAlignment = 16);
|
||||
|
||||
//
|
||||
// Don't call the destructor just to free up the memory, call pop()
|
||||
//
|
||||
~TPoolAllocator();
|
||||
|
||||
//
|
||||
// Call push() to establish a new place to pop memory too. Does not
|
||||
// have to be called to get things started.
|
||||
//
|
||||
void push();
|
||||
|
||||
//
|
||||
// Call pop() to free all memory allocated since the last call to push(),
|
||||
// or if no last call to push, frees all memory since first allocation.
|
||||
//
|
||||
void pop();
|
||||
|
||||
//
|
||||
// Call popAll() to free all memory allocated.
|
||||
//
|
||||
void popAll();
|
||||
|
||||
//
|
||||
// Call allocate() to actually acquire memory. Returns 0 if no memory
|
||||
// available, otherwise a properly aligned pointer to 'numBytes' of memory.
|
||||
//
|
||||
void* allocate(size_t numBytes);
|
||||
|
||||
//
|
||||
// There is no deallocate. The point of this class is that
|
||||
// deallocation can be skipped by the user of it, as the model
|
||||
// of use is to simultaneously deallocate everything at once
|
||||
// by calling pop(), and to not have to solve memory leak problems.
|
||||
//
|
||||
|
||||
protected:
|
||||
friend struct tHeader;
|
||||
|
||||
struct tHeader {
|
||||
tHeader(tHeader* nextPage, size_t pageCount) :
|
||||
#ifdef GUARD_BLOCKS
|
||||
lastAllocation(0),
|
||||
#endif
|
||||
nextPage(nextPage), pageCount(pageCount) { }
|
||||
|
||||
~tHeader() {
|
||||
#ifdef GUARD_BLOCKS
|
||||
if (lastAllocation)
|
||||
lastAllocation->checkAllocList();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef GUARD_BLOCKS
|
||||
TAllocation* lastAllocation;
|
||||
#endif
|
||||
tHeader* nextPage;
|
||||
size_t pageCount;
|
||||
};
|
||||
|
||||
struct tAllocState {
|
||||
size_t offset;
|
||||
tHeader* page;
|
||||
};
|
||||
typedef std::vector<tAllocState> tAllocStack;
|
||||
|
||||
// Track allocations if and only if we're using guard blocks
|
||||
#ifndef GUARD_BLOCKS
|
||||
void* initializeAllocation(tHeader*, unsigned char* memory, size_t) {
|
||||
#else
|
||||
void* initializeAllocation(tHeader* block, unsigned char* memory, size_t numBytes) {
|
||||
new(memory) TAllocation(numBytes, memory, block->lastAllocation);
|
||||
block->lastAllocation = reinterpret_cast<TAllocation*>(memory);
|
||||
#endif
|
||||
|
||||
// This is optimized entirely away if GUARD_BLOCKS is not defined.
|
||||
return TAllocation::offsetAllocation(memory);
|
||||
}
|
||||
|
||||
size_t pageSize; // granularity of allocation from the OS
|
||||
size_t alignment; // all returned allocations will be aligned at
|
||||
// this granularity, which will be a power of 2
|
||||
size_t alignmentMask;
|
||||
size_t headerSkip; // amount of memory to skip to make room for the
|
||||
// header (basically, size of header, rounded
|
||||
// up to make it aligned
|
||||
size_t currentPageOffset; // next offset in top of inUseList to allocate from
|
||||
tHeader* freeList; // list of popped memory
|
||||
tHeader* inUseList; // list of all memory currently being used
|
||||
tAllocStack stack; // stack of where to allocate from, to partition pool
|
||||
|
||||
int numCalls; // just an interesting statistic
|
||||
size_t totalBytes; // just an interesting statistic
|
||||
private:
|
||||
TPoolAllocator& operator=(const TPoolAllocator&); // don't allow assignment operator
|
||||
TPoolAllocator(const TPoolAllocator&); // don't allow default copy constructor
|
||||
};
|
||||
|
||||
//
|
||||
// There could potentially be many pools with pops happening at
|
||||
// different times. But a simple use is to have a global pop
|
||||
// with everyone using the same global allocator.
|
||||
//
|
||||
extern TPoolAllocator& GetThreadPoolAllocator();
|
||||
void SetThreadPoolAllocator(TPoolAllocator* poolAllocator);
|
||||
|
||||
//
|
||||
// This STL compatible allocator is intended to be used as the allocator
|
||||
// parameter to templatized STL containers, like vector and map.
|
||||
//
|
||||
// It will use the pools for allocation, and not
|
||||
// do any deallocation, but will still do destruction.
|
||||
//
|
||||
template<class T>
|
||||
class pool_allocator {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
template<class Other>
|
||||
struct rebind {
|
||||
typedef pool_allocator<Other> other;
|
||||
};
|
||||
pointer address(reference x) const { return &x; }
|
||||
const_pointer address(const_reference x) const { return &x; }
|
||||
|
||||
pool_allocator() : allocator(GetThreadPoolAllocator()) { }
|
||||
pool_allocator(TPoolAllocator& a) : allocator(a) { }
|
||||
pool_allocator(const pool_allocator<T>& p) : allocator(p.allocator) { }
|
||||
|
||||
template<class Other>
|
||||
pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }
|
||||
|
||||
pointer allocate(size_type n) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||
pointer allocate(size_type n, const void*) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||
|
||||
void deallocate(void*, size_type) { }
|
||||
void deallocate(pointer, size_type) { }
|
||||
|
||||
pointer _Charalloc(size_t n) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n)); }
|
||||
|
||||
void construct(pointer p, const T& val) { new ((void *)p) T(val); }
|
||||
void destroy(pointer p) { p->T::~T(); }
|
||||
|
||||
bool operator==(const pool_allocator& rhs) const { return &getAllocator() == &rhs.getAllocator(); }
|
||||
bool operator!=(const pool_allocator& rhs) const { return &getAllocator() != &rhs.getAllocator(); }
|
||||
|
||||
size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); }
|
||||
size_type max_size(int size) const { return static_cast<size_type>(-1) / size; }
|
||||
|
||||
TPoolAllocator& getAllocator() const { return allocator; }
|
||||
|
||||
protected:
|
||||
pool_allocator& operator=(const pool_allocator&) { return *this; }
|
||||
TPoolAllocator& allocator;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _POOLALLOC_INCLUDED_
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013 LunarG, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
#ifndef _RESOURCE_LIMITS_INCLUDED_
|
||||
#define _RESOURCE_LIMITS_INCLUDED_
|
||||
|
||||
struct TLimits {
|
||||
bool nonInductiveForLoops;
|
||||
bool whileLoops;
|
||||
bool doWhileLoops;
|
||||
bool generalUniformIndexing;
|
||||
bool generalAttributeMatrixVectorIndexing;
|
||||
bool generalVaryingIndexing;
|
||||
bool generalSamplerIndexing;
|
||||
bool generalVariableIndexing;
|
||||
bool generalConstantMatrixVectorIndexing;
|
||||
};
|
||||
|
||||
struct TBuiltInResource {
|
||||
int maxLights;
|
||||
int maxClipPlanes;
|
||||
int maxTextureUnits;
|
||||
int maxTextureCoords;
|
||||
int maxVertexAttribs;
|
||||
int maxVertexUniformComponents;
|
||||
int maxVaryingFloats;
|
||||
int maxVertexTextureImageUnits;
|
||||
int maxCombinedTextureImageUnits;
|
||||
int maxTextureImageUnits;
|
||||
int maxFragmentUniformComponents;
|
||||
int maxDrawBuffers;
|
||||
int maxVertexUniformVectors;
|
||||
int maxVaryingVectors;
|
||||
int maxFragmentUniformVectors;
|
||||
int maxVertexOutputVectors;
|
||||
int maxFragmentInputVectors;
|
||||
int minProgramTexelOffset;
|
||||
int maxProgramTexelOffset;
|
||||
int maxClipDistances;
|
||||
int maxComputeWorkGroupCountX;
|
||||
int maxComputeWorkGroupCountY;
|
||||
int maxComputeWorkGroupCountZ;
|
||||
int maxComputeWorkGroupSizeX;
|
||||
int maxComputeWorkGroupSizeY;
|
||||
int maxComputeWorkGroupSizeZ;
|
||||
int maxComputeUniformComponents;
|
||||
int maxComputeTextureImageUnits;
|
||||
int maxComputeImageUniforms;
|
||||
int maxComputeAtomicCounters;
|
||||
int maxComputeAtomicCounterBuffers;
|
||||
int maxVaryingComponents;
|
||||
int maxVertexOutputComponents;
|
||||
int maxGeometryInputComponents;
|
||||
int maxGeometryOutputComponents;
|
||||
int maxFragmentInputComponents;
|
||||
int maxImageUnits;
|
||||
int maxCombinedImageUnitsAndFragmentOutputs;
|
||||
int maxCombinedShaderOutputResources;
|
||||
int maxImageSamples;
|
||||
int maxVertexImageUniforms;
|
||||
int maxTessControlImageUniforms;
|
||||
int maxTessEvaluationImageUniforms;
|
||||
int maxGeometryImageUniforms;
|
||||
int maxFragmentImageUniforms;
|
||||
int maxCombinedImageUniforms;
|
||||
int maxGeometryTextureImageUnits;
|
||||
int maxGeometryOutputVertices;
|
||||
int maxGeometryTotalOutputComponents;
|
||||
int maxGeometryUniformComponents;
|
||||
int maxGeometryVaryingComponents;
|
||||
int maxTessControlInputComponents;
|
||||
int maxTessControlOutputComponents;
|
||||
int maxTessControlTextureImageUnits;
|
||||
int maxTessControlUniformComponents;
|
||||
int maxTessControlTotalOutputComponents;
|
||||
int maxTessEvaluationInputComponents;
|
||||
int maxTessEvaluationOutputComponents;
|
||||
int maxTessEvaluationTextureImageUnits;
|
||||
int maxTessEvaluationUniformComponents;
|
||||
int maxTessPatchComponents;
|
||||
int maxPatchVertices;
|
||||
int maxTessGenLevel;
|
||||
int maxViewports;
|
||||
int maxVertexAtomicCounters;
|
||||
int maxTessControlAtomicCounters;
|
||||
int maxTessEvaluationAtomicCounters;
|
||||
int maxGeometryAtomicCounters;
|
||||
int maxFragmentAtomicCounters;
|
||||
int maxCombinedAtomicCounters;
|
||||
int maxAtomicCounterBindings;
|
||||
int maxVertexAtomicCounterBuffers;
|
||||
int maxTessControlAtomicCounterBuffers;
|
||||
int maxTessEvaluationAtomicCounterBuffers;
|
||||
int maxGeometryAtomicCounterBuffers;
|
||||
int maxFragmentAtomicCounterBuffers;
|
||||
int maxCombinedAtomicCounterBuffers;
|
||||
int maxAtomicCounterBufferSize;
|
||||
int maxTransformFeedbackBuffers;
|
||||
int maxTransformFeedbackInterleavedComponents;
|
||||
int maxCullDistances;
|
||||
int maxCombinedClipAndCullDistances;
|
||||
int maxSamples;
|
||||
int maxMeshOutputVerticesNV;
|
||||
int maxMeshOutputPrimitivesNV;
|
||||
int maxMeshWorkGroupSizeX_NV;
|
||||
int maxMeshWorkGroupSizeY_NV;
|
||||
int maxMeshWorkGroupSizeZ_NV;
|
||||
int maxTaskWorkGroupSizeX_NV;
|
||||
int maxTaskWorkGroupSizeY_NV;
|
||||
int maxTaskWorkGroupSizeZ_NV;
|
||||
int maxMeshViewCountNV;
|
||||
int maxDualSourceDrawBuffersEXT;
|
||||
|
||||
TLimits limits;
|
||||
};
|
||||
|
||||
#endif // _RESOURCE_LIMITS_INCLUDED_
|
||||
+2590
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,341 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
//
|
||||
// Implement types for tracking GLSL arrays, arrays of arrays, etc.
|
||||
//
|
||||
|
||||
#ifndef _ARRAYS_INCLUDED
|
||||
#define _ARRAYS_INCLUDED
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace glslang {
|
||||
|
||||
// This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else.
|
||||
const int UnsizedArraySize = 0;
|
||||
|
||||
class TIntermTyped;
|
||||
extern bool SameSpecializationConstants(TIntermTyped*, TIntermTyped*);
|
||||
|
||||
// Specialization constants need both a nominal size and a node that defines
|
||||
// the specialization constant being used. Array types are the same when their
|
||||
// size and specialization constant nodes are the same.
|
||||
struct TArraySize {
|
||||
unsigned int size;
|
||||
TIntermTyped* node; // nullptr means no specialization constant node
|
||||
bool operator==(const TArraySize& rhs) const
|
||||
{
|
||||
if (size != rhs.size)
|
||||
return false;
|
||||
if (node == nullptr || rhs.node == nullptr)
|
||||
return node == rhs.node;
|
||||
|
||||
return SameSpecializationConstants(node, rhs.node);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// TSmallArrayVector is used as the container for the set of sizes in TArraySizes.
|
||||
// It has generic-container semantics, while TArraySizes has array-of-array semantics.
|
||||
// That is, TSmallArrayVector should be more focused on mechanism and TArraySizes on policy.
|
||||
//
|
||||
struct TSmallArrayVector {
|
||||
//
|
||||
// TODO: memory: TSmallArrayVector is intended to be smaller.
|
||||
// Almost all arrays could be handled by two sizes each fitting
|
||||
// in 16 bits, needing a real vector only in the cases where there
|
||||
// are more than 3 sizes or a size needing more than 16 bits.
|
||||
//
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TSmallArrayVector() : sizes(nullptr) { }
|
||||
virtual ~TSmallArrayVector() { dealloc(); }
|
||||
|
||||
// For breaking into two non-shared copies, independently modifiable.
|
||||
TSmallArrayVector& operator=(const TSmallArrayVector& from)
|
||||
{
|
||||
if (from.sizes == nullptr)
|
||||
sizes = nullptr;
|
||||
else {
|
||||
alloc();
|
||||
*sizes = *from.sizes;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int size() const
|
||||
{
|
||||
if (sizes == nullptr)
|
||||
return 0;
|
||||
return (int)sizes->size();
|
||||
}
|
||||
|
||||
unsigned int frontSize() const
|
||||
{
|
||||
assert(sizes != nullptr && sizes->size() > 0);
|
||||
return sizes->front().size;
|
||||
}
|
||||
|
||||
TIntermTyped* frontNode() const
|
||||
{
|
||||
assert(sizes != nullptr && sizes->size() > 0);
|
||||
return sizes->front().node;
|
||||
}
|
||||
|
||||
void changeFront(unsigned int s)
|
||||
{
|
||||
assert(sizes != nullptr);
|
||||
// this should only happen for implicitly sized arrays, not specialization constants
|
||||
assert(sizes->front().node == nullptr);
|
||||
sizes->front().size = s;
|
||||
}
|
||||
|
||||
void push_back(unsigned int e, TIntermTyped* n)
|
||||
{
|
||||
alloc();
|
||||
TArraySize pair = { e, n };
|
||||
sizes->push_back(pair);
|
||||
}
|
||||
|
||||
void push_back(const TSmallArrayVector& newDims)
|
||||
{
|
||||
alloc();
|
||||
sizes->insert(sizes->end(), newDims.sizes->begin(), newDims.sizes->end());
|
||||
}
|
||||
|
||||
void pop_front()
|
||||
{
|
||||
assert(sizes != nullptr && sizes->size() > 0);
|
||||
if (sizes->size() == 1)
|
||||
dealloc();
|
||||
else
|
||||
sizes->erase(sizes->begin());
|
||||
}
|
||||
|
||||
// 'this' should currently not be holding anything, and copyNonFront
|
||||
// will make it hold a copy of all but the first element of rhs.
|
||||
// (This would be useful for making a type that is dereferenced by
|
||||
// one dimension.)
|
||||
void copyNonFront(const TSmallArrayVector& rhs)
|
||||
{
|
||||
assert(sizes == nullptr);
|
||||
if (rhs.size() > 1) {
|
||||
alloc();
|
||||
sizes->insert(sizes->begin(), rhs.sizes->begin() + 1, rhs.sizes->end());
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int getDimSize(int i) const
|
||||
{
|
||||
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||
return (*sizes)[i].size;
|
||||
}
|
||||
|
||||
void setDimSize(int i, unsigned int size) const
|
||||
{
|
||||
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||
assert((*sizes)[i].node == nullptr);
|
||||
(*sizes)[i].size = size;
|
||||
}
|
||||
|
||||
TIntermTyped* getDimNode(int i) const
|
||||
{
|
||||
assert(sizes != nullptr && (int)sizes->size() > i);
|
||||
return (*sizes)[i].node;
|
||||
}
|
||||
|
||||
bool operator==(const TSmallArrayVector& rhs) const
|
||||
{
|
||||
if (sizes == nullptr && rhs.sizes == nullptr)
|
||||
return true;
|
||||
if (sizes == nullptr || rhs.sizes == nullptr)
|
||||
return false;
|
||||
return *sizes == *rhs.sizes;
|
||||
}
|
||||
bool operator!=(const TSmallArrayVector& rhs) const { return ! operator==(rhs); }
|
||||
|
||||
protected:
|
||||
TSmallArrayVector(const TSmallArrayVector&);
|
||||
|
||||
void alloc()
|
||||
{
|
||||
if (sizes == nullptr)
|
||||
sizes = new TVector<TArraySize>;
|
||||
}
|
||||
void dealloc()
|
||||
{
|
||||
delete sizes;
|
||||
sizes = nullptr;
|
||||
}
|
||||
|
||||
TVector<TArraySize>* sizes; // will either hold such a pointer, or in the future, hold the two array sizes
|
||||
};
|
||||
|
||||
//
|
||||
// Represent an array, or array of arrays, to arbitrary depth. This is not
|
||||
// done through a hierarchy of types in a type tree, rather all contiguous arrayness
|
||||
// in the type hierarchy is localized into this single cumulative object.
|
||||
//
|
||||
// The arrayness in TTtype is a pointer, so that it can be non-allocated and zero
|
||||
// for the vast majority of types that are non-array types.
|
||||
//
|
||||
// Order Policy: these are all identical:
|
||||
// - left to right order within a contiguous set of ...[..][..][..]... in the source language
|
||||
// - index order 0, 1, 2, ... within the 'sizes' member below
|
||||
// - outer-most to inner-most
|
||||
//
|
||||
struct TArraySizes {
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TArraySizes() : implicitArraySize(1), variablyIndexed(false) { }
|
||||
|
||||
// For breaking into two non-shared copies, independently modifiable.
|
||||
TArraySizes& operator=(const TArraySizes& from)
|
||||
{
|
||||
implicitArraySize = from.implicitArraySize;
|
||||
variablyIndexed = from.variablyIndexed;
|
||||
sizes = from.sizes;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// translate from array-of-array semantics to container semantics
|
||||
int getNumDims() const { return sizes.size(); }
|
||||
int getDimSize(int dim) const { return sizes.getDimSize(dim); }
|
||||
TIntermTyped* getDimNode(int dim) const { return sizes.getDimNode(dim); }
|
||||
void setDimSize(int dim, int size) { sizes.setDimSize(dim, size); }
|
||||
int getOuterSize() const { return sizes.frontSize(); }
|
||||
TIntermTyped* getOuterNode() const { return sizes.frontNode(); }
|
||||
int getCumulativeSize() const
|
||||
{
|
||||
int size = 1;
|
||||
for (int d = 0; d < sizes.size(); ++d) {
|
||||
// this only makes sense in paths that have a known array size
|
||||
assert(sizes.getDimSize(d) != UnsizedArraySize);
|
||||
size *= sizes.getDimSize(d);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
void addInnerSize() { addInnerSize((unsigned)UnsizedArraySize); }
|
||||
void addInnerSize(int s) { addInnerSize((unsigned)s, nullptr); }
|
||||
void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); }
|
||||
void addInnerSize(TArraySize pair) {
|
||||
sizes.push_back(pair.size, pair.node);
|
||||
}
|
||||
void addInnerSizes(const TArraySizes& s) { sizes.push_back(s.sizes); }
|
||||
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
|
||||
int getImplicitSize() const { return implicitArraySize; }
|
||||
void updateImplicitSize(int s) { implicitArraySize = std::max(implicitArraySize, s); }
|
||||
bool isInnerUnsized() const
|
||||
{
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool clearInnerUnsized()
|
||||
{
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimSize(d) == (unsigned)UnsizedArraySize)
|
||||
setDimSize(d, 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool isInnerSpecialization() const
|
||||
{
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimNode(d) != nullptr)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool isOuterSpecialization()
|
||||
{
|
||||
return sizes.getDimNode(0) != nullptr;
|
||||
}
|
||||
|
||||
bool hasUnsized() const { return getOuterSize() == UnsizedArraySize || isInnerUnsized(); }
|
||||
bool isSized() const { return getOuterSize() != UnsizedArraySize; }
|
||||
void dereference() { sizes.pop_front(); }
|
||||
void copyDereferenced(const TArraySizes& rhs)
|
||||
{
|
||||
assert(sizes.size() == 0);
|
||||
if (rhs.sizes.size() > 1)
|
||||
sizes.copyNonFront(rhs.sizes);
|
||||
}
|
||||
|
||||
bool sameInnerArrayness(const TArraySizes& rhs) const
|
||||
{
|
||||
if (sizes.size() != rhs.sizes.size())
|
||||
return false;
|
||||
|
||||
for (int d = 1; d < sizes.size(); ++d) {
|
||||
if (sizes.getDimSize(d) != rhs.sizes.getDimSize(d) ||
|
||||
sizes.getDimNode(d) != rhs.sizes.getDimNode(d))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void setVariablyIndexed() { variablyIndexed = true; }
|
||||
bool isVariablyIndexed() const { return variablyIndexed; }
|
||||
|
||||
bool operator==(const TArraySizes& rhs) const { return sizes == rhs.sizes; }
|
||||
bool operator!=(const TArraySizes& rhs) const { return sizes != rhs.sizes; }
|
||||
|
||||
protected:
|
||||
TSmallArrayVector sizes;
|
||||
|
||||
TArraySizes(const TArraySizes&);
|
||||
|
||||
// For tracking maximum referenced compile-time constant index.
|
||||
// Applies only to the outer-most dimension. Potentially becomes
|
||||
// the implicit size of the array, if not variably indexed and
|
||||
// otherwise legal.
|
||||
int implicitArraySize;
|
||||
bool variablyIndexed; // true if array is indexed with a non compile-time constant
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _ARRAYS_INCLUDED_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,340 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2012-2013 LunarG, Inc.
|
||||
// Copyright (C) 2017 ARM Limited.
|
||||
// Copyright (C) 2015-2018 Google, Inc.
|
||||
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
#ifndef _VERSIONS_INCLUDED_
|
||||
#define _VERSIONS_INCLUDED_
|
||||
|
||||
#define LAST_ELEMENT_MARKER(x) x
|
||||
|
||||
//
|
||||
// Help manage multiple profiles, versions, extensions etc.
|
||||
//
|
||||
|
||||
//
|
||||
// Profiles are set up for masking operations, so queries can be done on multiple
|
||||
// profiles at the same time.
|
||||
//
|
||||
// Don't maintain an ordinal set of enums (0,1,2,3...) to avoid all possible
|
||||
// defects from mixing the two different forms.
|
||||
//
|
||||
typedef enum : unsigned {
|
||||
EBadProfile = 0,
|
||||
ENoProfile = (1 << 0), // only for desktop, before profiles showed up
|
||||
ECoreProfile = (1 << 1),
|
||||
ECompatibilityProfile = (1 << 2),
|
||||
EEsProfile = (1 << 3),
|
||||
LAST_ELEMENT_MARKER(EProfileCount),
|
||||
} EProfile;
|
||||
|
||||
namespace glslang {
|
||||
|
||||
//
|
||||
// Map from profile enum to externally readable text name.
|
||||
//
|
||||
inline const char* ProfileName(EProfile profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case ENoProfile: return "none";
|
||||
case ECoreProfile: return "core";
|
||||
case ECompatibilityProfile: return "compatibility";
|
||||
case EEsProfile: return "es";
|
||||
default: return "unknown profile";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// What source rules, validation rules, target language, etc. are needed or
|
||||
// desired for SPIR-V?
|
||||
//
|
||||
// 0 means a target or rule set is not enabled (ignore rules from that entity).
|
||||
// Non-0 means to apply semantic rules arising from that version of its rule set.
|
||||
// The union of all requested rule sets will be applied.
|
||||
//
|
||||
struct SpvVersion {
|
||||
SpvVersion() : spv(0), vulkanGlsl(0), vulkan(0), openGl(0), vulkanRelaxed(false) {}
|
||||
unsigned int spv; // the version of SPIR-V to target, as defined by "word 1" of the SPIR-V binary header
|
||||
int vulkanGlsl; // the version of GLSL semantics for Vulkan, from GL_KHR_vulkan_glsl, for "#define VULKAN XXX"
|
||||
int vulkan; // the version of Vulkan, for which SPIR-V execution environment rules to use
|
||||
int openGl; // the version of GLSL semantics for OpenGL, from GL_ARB_gl_spirv, for "#define GL_SPIRV XXX"
|
||||
bool vulkanRelaxed; // relax changes to GLSL for Vulkan, allowing some GL-specific to be compiled to Vulkan SPIR-V target
|
||||
};
|
||||
|
||||
//
|
||||
// The behaviors from the GLSL "#extension extension_name : behavior"
|
||||
//
|
||||
typedef enum {
|
||||
EBhMissing = 0,
|
||||
EBhRequire,
|
||||
EBhEnable,
|
||||
EBhWarn,
|
||||
EBhDisable,
|
||||
EBhDisablePartial // use as initial state of an extension that is only partially implemented
|
||||
} TExtensionBehavior;
|
||||
|
||||
//
|
||||
// Symbolic names for extensions. Strings may be directly used when calling the
|
||||
// functions, but better to have the compiler do spelling checks.
|
||||
//
|
||||
const char* const E_GL_OES_texture_3D = "GL_OES_texture_3D";
|
||||
const char* const E_GL_OES_standard_derivatives = "GL_OES_standard_derivatives";
|
||||
const char* const E_GL_EXT_frag_depth = "GL_EXT_frag_depth";
|
||||
const char* const E_GL_OES_EGL_image_external = "GL_OES_EGL_image_external";
|
||||
const char* const E_GL_OES_EGL_image_external_essl3 = "GL_OES_EGL_image_external_essl3";
|
||||
const char* const E_GL_EXT_YUV_target = "GL_EXT_YUV_target";
|
||||
const char* const E_GL_EXT_shader_texture_lod = "GL_EXT_shader_texture_lod";
|
||||
const char* const E_GL_EXT_shadow_samplers = "GL_EXT_shadow_samplers";
|
||||
|
||||
const char* const E_GL_ARB_texture_rectangle = "GL_ARB_texture_rectangle";
|
||||
const char* const E_GL_3DL_array_objects = "GL_3DL_array_objects";
|
||||
const char* const E_GL_ARB_shading_language_420pack = "GL_ARB_shading_language_420pack";
|
||||
const char* const E_GL_ARB_texture_gather = "GL_ARB_texture_gather";
|
||||
const char* const E_GL_ARB_gpu_shader5 = "GL_ARB_gpu_shader5";
|
||||
const char* const E_GL_ARB_separate_shader_objects = "GL_ARB_separate_shader_objects";
|
||||
const char* const E_GL_ARB_compute_shader = "GL_ARB_compute_shader";
|
||||
const char* const E_GL_ARB_tessellation_shader = "GL_ARB_tessellation_shader";
|
||||
const char* const E_GL_ARB_enhanced_layouts = "GL_ARB_enhanced_layouts";
|
||||
const char* const E_GL_ARB_texture_cube_map_array = "GL_ARB_texture_cube_map_array";
|
||||
const char* const E_GL_ARB_texture_multisample = "GL_ARB_texture_multisample";
|
||||
const char* const E_GL_ARB_shader_texture_lod = "GL_ARB_shader_texture_lod";
|
||||
const char* const E_GL_ARB_explicit_attrib_location = "GL_ARB_explicit_attrib_location";
|
||||
const char* const E_GL_ARB_explicit_uniform_location = "GL_ARB_explicit_uniform_location";
|
||||
const char* const E_GL_ARB_shader_image_load_store = "GL_ARB_shader_image_load_store";
|
||||
const char* const E_GL_ARB_shader_atomic_counters = "GL_ARB_shader_atomic_counters";
|
||||
const char* const E_GL_ARB_shader_draw_parameters = "GL_ARB_shader_draw_parameters";
|
||||
const char* const E_GL_ARB_shader_group_vote = "GL_ARB_shader_group_vote";
|
||||
const char* const E_GL_ARB_derivative_control = "GL_ARB_derivative_control";
|
||||
const char* const E_GL_ARB_shader_texture_image_samples = "GL_ARB_shader_texture_image_samples";
|
||||
const char* const E_GL_ARB_viewport_array = "GL_ARB_viewport_array";
|
||||
const char* const E_GL_ARB_gpu_shader_int64 = "GL_ARB_gpu_shader_int64";
|
||||
const char* const E_GL_ARB_gpu_shader_fp64 = "GL_ARB_gpu_shader_fp64";
|
||||
const char* const E_GL_ARB_shader_ballot = "GL_ARB_shader_ballot";
|
||||
const char* const E_GL_ARB_sparse_texture2 = "GL_ARB_sparse_texture2";
|
||||
const char* const E_GL_ARB_sparse_texture_clamp = "GL_ARB_sparse_texture_clamp";
|
||||
const char* const E_GL_ARB_shader_stencil_export = "GL_ARB_shader_stencil_export";
|
||||
// const char* const E_GL_ARB_cull_distance = "GL_ARB_cull_distance"; // present for 4.5, but need extension control over block members
|
||||
const char* const E_GL_ARB_post_depth_coverage = "GL_ARB_post_depth_coverage";
|
||||
const char* const E_GL_ARB_shader_viewport_layer_array = "GL_ARB_shader_viewport_layer_array";
|
||||
const char* const E_GL_ARB_fragment_shader_interlock = "GL_ARB_fragment_shader_interlock";
|
||||
const char* const E_GL_ARB_shader_clock = "GL_ARB_shader_clock";
|
||||
const char* const E_GL_ARB_uniform_buffer_object = "GL_ARB_uniform_buffer_object";
|
||||
const char* const E_GL_ARB_sample_shading = "GL_ARB_sample_shading";
|
||||
const char* const E_GL_ARB_shader_bit_encoding = "GL_ARB_shader_bit_encoding";
|
||||
const char* const E_GL_ARB_shader_image_size = "GL_ARB_shader_image_size";
|
||||
const char* const E_GL_ARB_shader_storage_buffer_object = "GL_ARB_shader_storage_buffer_object";
|
||||
const char* const E_GL_ARB_shading_language_packing = "GL_ARB_shading_language_packing";
|
||||
const char* const E_GL_ARB_texture_query_lod = "GL_ARB_texture_query_lod";
|
||||
const char* const E_GL_ARB_vertex_attrib_64bit = "GL_ARB_vertex_attrib_64bit";
|
||||
|
||||
const char* const E_GL_KHR_shader_subgroup_basic = "GL_KHR_shader_subgroup_basic";
|
||||
const char* const E_GL_KHR_shader_subgroup_vote = "GL_KHR_shader_subgroup_vote";
|
||||
const char* const E_GL_KHR_shader_subgroup_arithmetic = "GL_KHR_shader_subgroup_arithmetic";
|
||||
const char* const E_GL_KHR_shader_subgroup_ballot = "GL_KHR_shader_subgroup_ballot";
|
||||
const char* const E_GL_KHR_shader_subgroup_shuffle = "GL_KHR_shader_subgroup_shuffle";
|
||||
const char* const E_GL_KHR_shader_subgroup_shuffle_relative = "GL_KHR_shader_subgroup_shuffle_relative";
|
||||
const char* const E_GL_KHR_shader_subgroup_clustered = "GL_KHR_shader_subgroup_clustered";
|
||||
const char* const E_GL_KHR_shader_subgroup_quad = "GL_KHR_shader_subgroup_quad";
|
||||
const char* const E_GL_KHR_memory_scope_semantics = "GL_KHR_memory_scope_semantics";
|
||||
|
||||
const char* const E_GL_EXT_shader_atomic_int64 = "GL_EXT_shader_atomic_int64";
|
||||
|
||||
const char* const E_GL_EXT_shader_non_constant_global_initializers = "GL_EXT_shader_non_constant_global_initializers";
|
||||
const char* const E_GL_EXT_shader_image_load_formatted = "GL_EXT_shader_image_load_formatted";
|
||||
|
||||
const char* const E_GL_EXT_shader_16bit_storage = "GL_EXT_shader_16bit_storage";
|
||||
const char* const E_GL_EXT_shader_8bit_storage = "GL_EXT_shader_8bit_storage";
|
||||
|
||||
|
||||
// EXT extensions
|
||||
const char* const E_GL_EXT_device_group = "GL_EXT_device_group";
|
||||
const char* const E_GL_EXT_multiview = "GL_EXT_multiview";
|
||||
const char* const E_GL_EXT_post_depth_coverage = "GL_EXT_post_depth_coverage";
|
||||
const char* const E_GL_EXT_control_flow_attributes = "GL_EXT_control_flow_attributes";
|
||||
const char* const E_GL_EXT_nonuniform_qualifier = "GL_EXT_nonuniform_qualifier";
|
||||
const char* const E_GL_EXT_samplerless_texture_functions = "GL_EXT_samplerless_texture_functions";
|
||||
const char* const E_GL_EXT_scalar_block_layout = "GL_EXT_scalar_block_layout";
|
||||
const char* const E_GL_EXT_fragment_invocation_density = "GL_EXT_fragment_invocation_density";
|
||||
const char* const E_GL_EXT_buffer_reference = "GL_EXT_buffer_reference";
|
||||
const char* const E_GL_EXT_buffer_reference2 = "GL_EXT_buffer_reference2";
|
||||
const char* const E_GL_EXT_buffer_reference_uvec2 = "GL_EXT_buffer_reference_uvec2";
|
||||
const char* const E_GL_EXT_demote_to_helper_invocation = "GL_EXT_demote_to_helper_invocation";
|
||||
const char* const E_GL_EXT_shader_realtime_clock = "GL_EXT_shader_realtime_clock";
|
||||
const char* const E_GL_EXT_debug_printf = "GL_EXT_debug_printf";
|
||||
const char* const E_GL_EXT_ray_tracing = "GL_EXT_ray_tracing";
|
||||
const char* const E_GL_EXT_ray_query = "GL_EXT_ray_query";
|
||||
const char* const E_GL_EXT_ray_flags_primitive_culling = "GL_EXT_ray_flags_primitive_culling";
|
||||
const char* const E_GL_EXT_blend_func_extended = "GL_EXT_blend_func_extended";
|
||||
const char* const E_GL_EXT_shader_implicit_conversions = "GL_EXT_shader_implicit_conversions";
|
||||
const char* const E_GL_EXT_fragment_shading_rate = "GL_EXT_fragment_shading_rate";
|
||||
const char* const E_GL_EXT_shader_image_int64 = "GL_EXT_shader_image_int64";
|
||||
const char* const E_GL_EXT_null_initializer = "GL_EXT_null_initializer";
|
||||
const char* const E_GL_EXT_shared_memory_block = "GL_EXT_shared_memory_block";
|
||||
|
||||
// Arrays of extensions for the above viewportEXTs duplications
|
||||
|
||||
const char* const post_depth_coverageEXTs[] = { E_GL_ARB_post_depth_coverage, E_GL_EXT_post_depth_coverage };
|
||||
const int Num_post_depth_coverageEXTs = sizeof(post_depth_coverageEXTs) / sizeof(post_depth_coverageEXTs[0]);
|
||||
|
||||
// OVR extensions
|
||||
const char* const E_GL_OVR_multiview = "GL_OVR_multiview";
|
||||
const char* const E_GL_OVR_multiview2 = "GL_OVR_multiview2";
|
||||
|
||||
const char* const OVR_multiview_EXTs[] = { E_GL_OVR_multiview, E_GL_OVR_multiview2 };
|
||||
const int Num_OVR_multiview_EXTs = sizeof(OVR_multiview_EXTs) / sizeof(OVR_multiview_EXTs[0]);
|
||||
|
||||
// #line and #include
|
||||
const char* const E_GL_GOOGLE_cpp_style_line_directive = "GL_GOOGLE_cpp_style_line_directive";
|
||||
const char* const E_GL_GOOGLE_include_directive = "GL_GOOGLE_include_directive";
|
||||
|
||||
const char* const E_GL_AMD_shader_ballot = "GL_AMD_shader_ballot";
|
||||
const char* const E_GL_AMD_shader_trinary_minmax = "GL_AMD_shader_trinary_minmax";
|
||||
const char* const E_GL_AMD_shader_explicit_vertex_parameter = "GL_AMD_shader_explicit_vertex_parameter";
|
||||
const char* const E_GL_AMD_gcn_shader = "GL_AMD_gcn_shader";
|
||||
const char* const E_GL_AMD_gpu_shader_half_float = "GL_AMD_gpu_shader_half_float";
|
||||
const char* const E_GL_AMD_texture_gather_bias_lod = "GL_AMD_texture_gather_bias_lod";
|
||||
const char* const E_GL_AMD_gpu_shader_int16 = "GL_AMD_gpu_shader_int16";
|
||||
const char* const E_GL_AMD_shader_image_load_store_lod = "GL_AMD_shader_image_load_store_lod";
|
||||
const char* const E_GL_AMD_shader_fragment_mask = "GL_AMD_shader_fragment_mask";
|
||||
const char* const E_GL_AMD_gpu_shader_half_float_fetch = "GL_AMD_gpu_shader_half_float_fetch";
|
||||
|
||||
const char* const E_GL_INTEL_shader_integer_functions2 = "GL_INTEL_shader_integer_functions2";
|
||||
|
||||
const char* const E_GL_NV_sample_mask_override_coverage = "GL_NV_sample_mask_override_coverage";
|
||||
const char* const E_SPV_NV_geometry_shader_passthrough = "GL_NV_geometry_shader_passthrough";
|
||||
const char* const E_GL_NV_viewport_array2 = "GL_NV_viewport_array2";
|
||||
const char* const E_GL_NV_stereo_view_rendering = "GL_NV_stereo_view_rendering";
|
||||
const char* const E_GL_NVX_multiview_per_view_attributes = "GL_NVX_multiview_per_view_attributes";
|
||||
const char* const E_GL_NV_shader_atomic_int64 = "GL_NV_shader_atomic_int64";
|
||||
const char* const E_GL_NV_conservative_raster_underestimation = "GL_NV_conservative_raster_underestimation";
|
||||
const char* const E_GL_NV_shader_noperspective_interpolation = "GL_NV_shader_noperspective_interpolation";
|
||||
const char* const E_GL_NV_shader_subgroup_partitioned = "GL_NV_shader_subgroup_partitioned";
|
||||
const char* const E_GL_NV_shading_rate_image = "GL_NV_shading_rate_image";
|
||||
const char* const E_GL_NV_ray_tracing = "GL_NV_ray_tracing";
|
||||
const char* const E_GL_NV_fragment_shader_barycentric = "GL_NV_fragment_shader_barycentric";
|
||||
const char* const E_GL_NV_compute_shader_derivatives = "GL_NV_compute_shader_derivatives";
|
||||
const char* const E_GL_NV_shader_texture_footprint = "GL_NV_shader_texture_footprint";
|
||||
const char* const E_GL_NV_mesh_shader = "GL_NV_mesh_shader";
|
||||
|
||||
// Arrays of extensions for the above viewportEXTs duplications
|
||||
|
||||
const char* const viewportEXTs[] = { E_GL_ARB_shader_viewport_layer_array, E_GL_NV_viewport_array2 };
|
||||
const int Num_viewportEXTs = sizeof(viewportEXTs) / sizeof(viewportEXTs[0]);
|
||||
|
||||
const char* const E_GL_NV_cooperative_matrix = "GL_NV_cooperative_matrix";
|
||||
const char* const E_GL_NV_shader_sm_builtins = "GL_NV_shader_sm_builtins";
|
||||
const char* const E_GL_NV_integer_cooperative_matrix = "GL_NV_integer_cooperative_matrix";
|
||||
|
||||
// AEP
|
||||
const char* const E_GL_ANDROID_extension_pack_es31a = "GL_ANDROID_extension_pack_es31a";
|
||||
const char* const E_GL_KHR_blend_equation_advanced = "GL_KHR_blend_equation_advanced";
|
||||
const char* const E_GL_OES_sample_variables = "GL_OES_sample_variables";
|
||||
const char* const E_GL_OES_shader_image_atomic = "GL_OES_shader_image_atomic";
|
||||
const char* const E_GL_OES_shader_multisample_interpolation = "GL_OES_shader_multisample_interpolation";
|
||||
const char* const E_GL_OES_texture_storage_multisample_2d_array = "GL_OES_texture_storage_multisample_2d_array";
|
||||
const char* const E_GL_EXT_geometry_shader = "GL_EXT_geometry_shader";
|
||||
const char* const E_GL_EXT_geometry_point_size = "GL_EXT_geometry_point_size";
|
||||
const char* const E_GL_EXT_gpu_shader5 = "GL_EXT_gpu_shader5";
|
||||
const char* const E_GL_EXT_primitive_bounding_box = "GL_EXT_primitive_bounding_box";
|
||||
const char* const E_GL_EXT_shader_io_blocks = "GL_EXT_shader_io_blocks";
|
||||
const char* const E_GL_EXT_tessellation_shader = "GL_EXT_tessellation_shader";
|
||||
const char* const E_GL_EXT_tessellation_point_size = "GL_EXT_tessellation_point_size";
|
||||
const char* const E_GL_EXT_texture_buffer = "GL_EXT_texture_buffer";
|
||||
const char* const E_GL_EXT_texture_cube_map_array = "GL_EXT_texture_cube_map_array";
|
||||
const char* const E_GL_EXT_shader_integer_mix = "GL_EXT_shader_integer_mix";
|
||||
|
||||
// OES matching AEP
|
||||
const char* const E_GL_OES_geometry_shader = "GL_OES_geometry_shader";
|
||||
const char* const E_GL_OES_geometry_point_size = "GL_OES_geometry_point_size";
|
||||
const char* const E_GL_OES_gpu_shader5 = "GL_OES_gpu_shader5";
|
||||
const char* const E_GL_OES_primitive_bounding_box = "GL_OES_primitive_bounding_box";
|
||||
const char* const E_GL_OES_shader_io_blocks = "GL_OES_shader_io_blocks";
|
||||
const char* const E_GL_OES_tessellation_shader = "GL_OES_tessellation_shader";
|
||||
const char* const E_GL_OES_tessellation_point_size = "GL_OES_tessellation_point_size";
|
||||
const char* const E_GL_OES_texture_buffer = "GL_OES_texture_buffer";
|
||||
const char* const E_GL_OES_texture_cube_map_array = "GL_OES_texture_cube_map_array";
|
||||
|
||||
// EXT
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types = "GL_EXT_shader_explicit_arithmetic_types";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int8 = "GL_EXT_shader_explicit_arithmetic_types_int8";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int16 = "GL_EXT_shader_explicit_arithmetic_types_int16";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int32 = "GL_EXT_shader_explicit_arithmetic_types_int32";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_int64 = "GL_EXT_shader_explicit_arithmetic_types_int64";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float16 = "GL_EXT_shader_explicit_arithmetic_types_float16";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float32 = "GL_EXT_shader_explicit_arithmetic_types_float32";
|
||||
const char* const E_GL_EXT_shader_explicit_arithmetic_types_float64 = "GL_EXT_shader_explicit_arithmetic_types_float64";
|
||||
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_int8 = "GL_EXT_shader_subgroup_extended_types_int8";
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_int16 = "GL_EXT_shader_subgroup_extended_types_int16";
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_int64 = "GL_EXT_shader_subgroup_extended_types_int64";
|
||||
const char* const E_GL_EXT_shader_subgroup_extended_types_float16 = "GL_EXT_shader_subgroup_extended_types_float16";
|
||||
const char* const E_GL_EXT_terminate_invocation = "GL_EXT_terminate_invocation";
|
||||
|
||||
const char* const E_GL_EXT_shader_atomic_float = "GL_EXT_shader_atomic_float";
|
||||
|
||||
// Arrays of extensions for the above AEP duplications
|
||||
|
||||
const char* const AEP_geometry_shader[] = { E_GL_EXT_geometry_shader, E_GL_OES_geometry_shader };
|
||||
const int Num_AEP_geometry_shader = sizeof(AEP_geometry_shader)/sizeof(AEP_geometry_shader[0]);
|
||||
|
||||
const char* const AEP_geometry_point_size[] = { E_GL_EXT_geometry_point_size, E_GL_OES_geometry_point_size };
|
||||
const int Num_AEP_geometry_point_size = sizeof(AEP_geometry_point_size)/sizeof(AEP_geometry_point_size[0]);
|
||||
|
||||
const char* const AEP_gpu_shader5[] = { E_GL_EXT_gpu_shader5, E_GL_OES_gpu_shader5 };
|
||||
const int Num_AEP_gpu_shader5 = sizeof(AEP_gpu_shader5)/sizeof(AEP_gpu_shader5[0]);
|
||||
|
||||
const char* const AEP_primitive_bounding_box[] = { E_GL_EXT_primitive_bounding_box, E_GL_OES_primitive_bounding_box };
|
||||
const int Num_AEP_primitive_bounding_box = sizeof(AEP_primitive_bounding_box)/sizeof(AEP_primitive_bounding_box[0]);
|
||||
|
||||
const char* const AEP_shader_io_blocks[] = { E_GL_EXT_shader_io_blocks, E_GL_OES_shader_io_blocks };
|
||||
const int Num_AEP_shader_io_blocks = sizeof(AEP_shader_io_blocks)/sizeof(AEP_shader_io_blocks[0]);
|
||||
|
||||
const char* const AEP_tessellation_shader[] = { E_GL_EXT_tessellation_shader, E_GL_OES_tessellation_shader };
|
||||
const int Num_AEP_tessellation_shader = sizeof(AEP_tessellation_shader)/sizeof(AEP_tessellation_shader[0]);
|
||||
|
||||
const char* const AEP_tessellation_point_size[] = { E_GL_EXT_tessellation_point_size, E_GL_OES_tessellation_point_size };
|
||||
const int Num_AEP_tessellation_point_size = sizeof(AEP_tessellation_point_size)/sizeof(AEP_tessellation_point_size[0]);
|
||||
|
||||
const char* const AEP_texture_buffer[] = { E_GL_EXT_texture_buffer, E_GL_OES_texture_buffer };
|
||||
const int Num_AEP_texture_buffer = sizeof(AEP_texture_buffer)/sizeof(AEP_texture_buffer[0]);
|
||||
|
||||
const char* const AEP_texture_cube_map_array[] = { E_GL_EXT_texture_cube_map_array, E_GL_OES_texture_cube_map_array };
|
||||
const int Num_AEP_texture_cube_map_array = sizeof(AEP_texture_cube_map_array)/sizeof(AEP_texture_cube_map_array[0]);
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _VERSIONS_INCLUDED_
|
||||
+1149
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,970 @@
|
||||
//
|
||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
// Copyright (C) 2013-2016 LunarG, Inc.
|
||||
// Copyright (C) 2015-2018 Google, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
#ifndef _COMPILER_INTERFACE_INCLUDED_
|
||||
#define _COMPILER_INTERFACE_INCLUDED_
|
||||
|
||||
#include "../Include/ResourceLimits.h"
|
||||
#include "../MachineIndependent/Versions.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define C_DECL __cdecl
|
||||
#else
|
||||
#define C_DECL
|
||||
#endif
|
||||
|
||||
#ifdef GLSLANG_IS_SHARED_LIBRARY
|
||||
#ifdef _WIN32
|
||||
#ifdef GLSLANG_EXPORTING
|
||||
#define GLSLANG_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define GLSLANG_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#elif __GNUC__ >= 4
|
||||
#define GLSLANG_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
#endif // GLSLANG_IS_SHARED_LIBRARY
|
||||
|
||||
#ifndef GLSLANG_EXPORT
|
||||
#define GLSLANG_EXPORT
|
||||
#endif
|
||||
|
||||
//
|
||||
// This is the platform independent interface between an OGL driver
|
||||
// and the shading language compiler/linker.
|
||||
//
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//
|
||||
// Call before doing any other compiler/linker operations.
|
||||
//
|
||||
// (Call once per process, not once per thread.)
|
||||
//
|
||||
GLSLANG_EXPORT int ShInitialize();
|
||||
|
||||
//
|
||||
// Call this at process shutdown to clean up memory.
|
||||
//
|
||||
GLSLANG_EXPORT int ShFinalize();
|
||||
|
||||
//
|
||||
// Types of languages the compiler can consume.
|
||||
//
|
||||
typedef enum {
|
||||
EShLangVertex,
|
||||
EShLangTessControl,
|
||||
EShLangTessEvaluation,
|
||||
EShLangGeometry,
|
||||
EShLangFragment,
|
||||
EShLangCompute,
|
||||
EShLangRayGen,
|
||||
EShLangRayGenNV = EShLangRayGen,
|
||||
EShLangIntersect,
|
||||
EShLangIntersectNV = EShLangIntersect,
|
||||
EShLangAnyHit,
|
||||
EShLangAnyHitNV = EShLangAnyHit,
|
||||
EShLangClosestHit,
|
||||
EShLangClosestHitNV = EShLangClosestHit,
|
||||
EShLangMiss,
|
||||
EShLangMissNV = EShLangMiss,
|
||||
EShLangCallable,
|
||||
EShLangCallableNV = EShLangCallable,
|
||||
EShLangTaskNV,
|
||||
EShLangMeshNV,
|
||||
LAST_ELEMENT_MARKER(EShLangCount),
|
||||
} EShLanguage; // would be better as stage, but this is ancient now
|
||||
|
||||
typedef enum : unsigned {
|
||||
EShLangVertexMask = (1 << EShLangVertex),
|
||||
EShLangTessControlMask = (1 << EShLangTessControl),
|
||||
EShLangTessEvaluationMask = (1 << EShLangTessEvaluation),
|
||||
EShLangGeometryMask = (1 << EShLangGeometry),
|
||||
EShLangFragmentMask = (1 << EShLangFragment),
|
||||
EShLangComputeMask = (1 << EShLangCompute),
|
||||
EShLangRayGenMask = (1 << EShLangRayGen),
|
||||
EShLangRayGenNVMask = EShLangRayGenMask,
|
||||
EShLangIntersectMask = (1 << EShLangIntersect),
|
||||
EShLangIntersectNVMask = EShLangIntersectMask,
|
||||
EShLangAnyHitMask = (1 << EShLangAnyHit),
|
||||
EShLangAnyHitNVMask = EShLangAnyHitMask,
|
||||
EShLangClosestHitMask = (1 << EShLangClosestHit),
|
||||
EShLangClosestHitNVMask = EShLangClosestHitMask,
|
||||
EShLangMissMask = (1 << EShLangMiss),
|
||||
EShLangMissNVMask = EShLangMissMask,
|
||||
EShLangCallableMask = (1 << EShLangCallable),
|
||||
EShLangCallableNVMask = EShLangCallableMask,
|
||||
EShLangTaskNVMask = (1 << EShLangTaskNV),
|
||||
EShLangMeshNVMask = (1 << EShLangMeshNV),
|
||||
LAST_ELEMENT_MARKER(EShLanguageMaskCount),
|
||||
} EShLanguageMask;
|
||||
|
||||
namespace glslang {
|
||||
|
||||
class TType;
|
||||
|
||||
typedef enum {
|
||||
EShSourceNone,
|
||||
EShSourceGlsl, // GLSL, includes ESSL (OpenGL ES GLSL)
|
||||
EShSourceHlsl, // HLSL
|
||||
LAST_ELEMENT_MARKER(EShSourceCount),
|
||||
} EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead
|
||||
|
||||
typedef enum {
|
||||
EShClientNone, // use when there is no client, e.g. for validation
|
||||
EShClientVulkan,
|
||||
EShClientOpenGL,
|
||||
LAST_ELEMENT_MARKER(EShClientCount),
|
||||
} EShClient;
|
||||
|
||||
typedef enum {
|
||||
EShTargetNone,
|
||||
EShTargetSpv, // SPIR-V (preferred spelling)
|
||||
EshTargetSpv = EShTargetSpv, // legacy spelling
|
||||
LAST_ELEMENT_MARKER(EShTargetCount),
|
||||
} EShTargetLanguage;
|
||||
|
||||
typedef enum {
|
||||
EShTargetVulkan_1_0 = (1 << 22), // Vulkan 1.0
|
||||
EShTargetVulkan_1_1 = (1 << 22) | (1 << 12), // Vulkan 1.1
|
||||
EShTargetVulkan_1_2 = (1 << 22) | (2 << 12), // Vulkan 1.2
|
||||
EShTargetOpenGL_450 = 450, // OpenGL
|
||||
LAST_ELEMENT_MARKER(EShTargetClientVersionCount = 4),
|
||||
} EShTargetClientVersion;
|
||||
|
||||
typedef EShTargetClientVersion EshTargetClientVersion;
|
||||
|
||||
typedef enum {
|
||||
EShTargetSpv_1_0 = (1 << 16), // SPIR-V 1.0
|
||||
EShTargetSpv_1_1 = (1 << 16) | (1 << 8), // SPIR-V 1.1
|
||||
EShTargetSpv_1_2 = (1 << 16) | (2 << 8), // SPIR-V 1.2
|
||||
EShTargetSpv_1_3 = (1 << 16) | (3 << 8), // SPIR-V 1.3
|
||||
EShTargetSpv_1_4 = (1 << 16) | (4 << 8), // SPIR-V 1.4
|
||||
EShTargetSpv_1_5 = (1 << 16) | (5 << 8), // SPIR-V 1.5
|
||||
LAST_ELEMENT_MARKER(EShTargetLanguageVersionCount = 6),
|
||||
} EShTargetLanguageVersion;
|
||||
|
||||
struct TInputLanguage {
|
||||
EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone
|
||||
EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone
|
||||
EShClient dialect;
|
||||
int dialectVersion; // version of client's language definition, not the client (when not EShClientNone)
|
||||
bool vulkanRulesRelaxed;
|
||||
};
|
||||
|
||||
struct TClient {
|
||||
EShClient client;
|
||||
EShTargetClientVersion version; // version of client itself (not the client's input dialect)
|
||||
};
|
||||
|
||||
struct TTarget {
|
||||
EShTargetLanguage language;
|
||||
EShTargetLanguageVersion version; // version to target, if SPIR-V, defined by "word 1" of the SPIR-V header
|
||||
bool hlslFunctionality1; // can target hlsl_functionality1 extension(s)
|
||||
};
|
||||
|
||||
// All source/client/target versions and settings.
|
||||
// Can override previous methods of setting, when items are set here.
|
||||
// Expected to grow, as more are added, rather than growing parameter lists.
|
||||
struct TEnvironment {
|
||||
TInputLanguage input; // definition of the input language
|
||||
TClient client; // what client is the overall compilation being done for?
|
||||
TTarget target; // what to generate
|
||||
};
|
||||
|
||||
GLSLANG_EXPORT const char* StageName(EShLanguage);
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
//
|
||||
// Types of output the linker will create.
|
||||
//
|
||||
typedef enum {
|
||||
EShExVertexFragment,
|
||||
EShExFragment
|
||||
} EShExecutable;
|
||||
|
||||
//
|
||||
// Optimization level for the compiler.
|
||||
//
|
||||
typedef enum {
|
||||
EShOptNoGeneration,
|
||||
EShOptNone,
|
||||
EShOptSimple, // Optimizations that can be done quickly
|
||||
EShOptFull, // Optimizations that will take more time
|
||||
LAST_ELEMENT_MARKER(EshOptLevelCount),
|
||||
} EShOptimizationLevel;
|
||||
|
||||
//
|
||||
// Texture and Sampler transformation mode.
|
||||
//
|
||||
typedef enum {
|
||||
EShTexSampTransKeep, // keep textures and samplers as is (default)
|
||||
EShTexSampTransUpgradeTextureRemoveSampler, // change texture w/o embeded sampler into sampled texture and throw away all samplers
|
||||
LAST_ELEMENT_MARKER(EShTexSampTransCount),
|
||||
} EShTextureSamplerTransformMode;
|
||||
|
||||
//
|
||||
// Message choices for what errors and warnings are given.
|
||||
//
|
||||
enum EShMessages : unsigned {
|
||||
EShMsgDefault = 0, // default is to give all required errors and extra warnings
|
||||
EShMsgRelaxedErrors = (1 << 0), // be liberal in accepting input
|
||||
EShMsgSuppressWarnings = (1 << 1), // suppress all warnings, except those required by the specification
|
||||
EShMsgAST = (1 << 2), // print the AST intermediate representation
|
||||
EShMsgSpvRules = (1 << 3), // issue messages for SPIR-V generation
|
||||
EShMsgVulkanRules = (1 << 4), // issue messages for Vulkan-requirements of GLSL for SPIR-V
|
||||
EShMsgOnlyPreprocessor = (1 << 5), // only print out errors produced by the preprocessor
|
||||
EShMsgReadHlsl = (1 << 6), // use HLSL parsing rules and semantics
|
||||
EShMsgCascadingErrors = (1 << 7), // get cascading errors; risks error-recovery issues, instead of an early exit
|
||||
EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions
|
||||
EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules
|
||||
EShMsgDebugInfo = (1 << 10), // save debug information
|
||||
EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
|
||||
EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages
|
||||
EShMsgHlslDX9Compatible = (1 << 13), // enable HLSL DX9 compatible mode (for samplers and semantics)
|
||||
EShMsgBuiltinSymbolTable = (1 << 14), // print the builtin symbol table
|
||||
LAST_ELEMENT_MARKER(EShMsgCount),
|
||||
};
|
||||
|
||||
//
|
||||
// Options for building reflection
|
||||
//
|
||||
typedef enum {
|
||||
EShReflectionDefault = 0, // default is original behaviour before options were added
|
||||
EShReflectionStrictArraySuffix = (1 << 0), // reflection will follow stricter rules for array-of-structs suffixes
|
||||
EShReflectionBasicArraySuffix = (1 << 1), // arrays of basic types will be appended with [0] as in GL reflection
|
||||
EShReflectionIntermediateIO = (1 << 2), // reflect inputs and outputs to program, even with no vertex shader
|
||||
EShReflectionSeparateBuffers = (1 << 3), // buffer variables and buffer blocks are reflected separately
|
||||
EShReflectionAllBlockVariables = (1 << 4), // reflect all variables in blocks, even if they are inactive
|
||||
EShReflectionUnwrapIOBlocks = (1 << 5), // unwrap input/output blocks the same as with uniform blocks
|
||||
EShReflectionAllIOVariables = (1 << 6), // reflect all input/output variables, even if they are inactive
|
||||
EShReflectionSharedStd140SSBO = (1 << 7), // Apply std140/shared rules for ubo to ssbo
|
||||
EShReflectionSharedStd140UBO = (1 << 8), // Apply std140/shared rules for ubo to ssbo
|
||||
LAST_ELEMENT_MARKER(EShReflectionCount),
|
||||
} EShReflectionOptions;
|
||||
|
||||
//
|
||||
// Build a table for bindings. This can be used for locating
|
||||
// attributes, uniforms, globals, etc., as needed.
|
||||
//
|
||||
typedef struct {
|
||||
const char* name;
|
||||
int binding;
|
||||
} ShBinding;
|
||||
|
||||
typedef struct {
|
||||
int numBindings;
|
||||
ShBinding* bindings; // array of bindings
|
||||
} ShBindingTable;
|
||||
|
||||
//
|
||||
// ShHandle held by but opaque to the driver. It is allocated,
|
||||
// managed, and de-allocated by the compiler/linker. It's contents
|
||||
// are defined by and used by the compiler and linker. For example,
|
||||
// symbol table information and object code passed from the compiler
|
||||
// to the linker can be stored where ShHandle points.
|
||||
//
|
||||
// If handle creation fails, 0 will be returned.
|
||||
//
|
||||
typedef void* ShHandle;
|
||||
|
||||
//
|
||||
// Driver calls these to create and destroy compiler/linker
|
||||
// objects.
|
||||
//
|
||||
GLSLANG_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int debugOptions); // one per shader
|
||||
GLSLANG_EXPORT ShHandle ShConstructLinker(const EShExecutable, int debugOptions); // one per shader pair
|
||||
GLSLANG_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object)
|
||||
GLSLANG_EXPORT void ShDestruct(ShHandle);
|
||||
|
||||
//
|
||||
// The return value of ShCompile is boolean, non-zero indicating
|
||||
// success.
|
||||
//
|
||||
// The info-log should be written by ShCompile into
|
||||
// ShHandle, so it can answer future queries.
|
||||
//
|
||||
GLSLANG_EXPORT int ShCompile(
|
||||
const ShHandle,
|
||||
const char* const shaderStrings[],
|
||||
const int numStrings,
|
||||
const int* lengths,
|
||||
const EShOptimizationLevel,
|
||||
const TBuiltInResource *resources,
|
||||
int debugOptions,
|
||||
int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
|
||||
bool forwardCompatible = false, // give errors for use of deprecated features
|
||||
EShMessages messages = EShMsgDefault // warnings and errors
|
||||
);
|
||||
|
||||
GLSLANG_EXPORT int ShLinkExt(
|
||||
const ShHandle, // linker object
|
||||
const ShHandle h[], // compiler objects to link together
|
||||
const int numHandles);
|
||||
|
||||
//
|
||||
// ShSetEncrpytionMethod is a place-holder for specifying
|
||||
// how source code is encrypted.
|
||||
//
|
||||
GLSLANG_EXPORT void ShSetEncryptionMethod(ShHandle);
|
||||
|
||||
//
|
||||
// All the following return 0 if the information is not
|
||||
// available in the object passed down, or the object is bad.
|
||||
//
|
||||
GLSLANG_EXPORT const char* ShGetInfoLog(const ShHandle);
|
||||
GLSLANG_EXPORT const void* ShGetExecutable(const ShHandle);
|
||||
GLSLANG_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing
|
||||
GLSLANG_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings
|
||||
//
|
||||
// Tell the linker to never assign a vertex attribute to this list of physical attributes
|
||||
//
|
||||
GLSLANG_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);
|
||||
|
||||
//
|
||||
// Returns the location ID of the named uniform.
|
||||
// Returns -1 if error.
|
||||
//
|
||||
GLSLANG_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end extern "C"
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Deferred-Lowering C++ Interface
|
||||
// -----------------------------------
|
||||
//
|
||||
// Below is a new alternate C++ interface, which deprecates the above
|
||||
// opaque handle-based interface.
|
||||
//
|
||||
// The below is further designed to handle multiple compilation units per stage, where
|
||||
// the intermediate results, including the parse tree, are preserved until link time,
|
||||
// rather than the above interface which is designed to have each compilation unit
|
||||
// lowered at compile time. In the above model, linking occurs on the lowered results,
|
||||
// whereas in this model intra-stage linking can occur at the parse tree
|
||||
// (treeRoot in TIntermediate) level, and then a full stage can be lowered.
|
||||
//
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
class TCompiler;
|
||||
class TInfoSink;
|
||||
|
||||
namespace glslang {
|
||||
|
||||
struct Version {
|
||||
int major;
|
||||
int minor;
|
||||
int patch;
|
||||
const char* flavor;
|
||||
};
|
||||
|
||||
GLSLANG_EXPORT Version GetVersion();
|
||||
GLSLANG_EXPORT const char* GetEsslVersionString();
|
||||
GLSLANG_EXPORT const char* GetGlslVersionString();
|
||||
GLSLANG_EXPORT int GetKhronosToolId();
|
||||
|
||||
class TIntermediate;
|
||||
class TProgram;
|
||||
class TPoolAllocator;
|
||||
|
||||
// Call this exactly once per process before using anything else
|
||||
GLSLANG_EXPORT bool InitializeProcess();
|
||||
|
||||
// Call once per process to tear down everything
|
||||
GLSLANG_EXPORT void FinalizeProcess();
|
||||
|
||||
// Resource type for IO resolver
|
||||
enum TResourceType {
|
||||
EResSampler,
|
||||
EResTexture,
|
||||
EResImage,
|
||||
EResUbo,
|
||||
EResSsbo,
|
||||
EResUav,
|
||||
EResCount
|
||||
};
|
||||
|
||||
enum TBlockStorageClass
|
||||
{
|
||||
EbsUniform = 0,
|
||||
EbsStorageBuffer,
|
||||
EbsPushConstant,
|
||||
EbsNone, // not a uniform or buffer variable
|
||||
EbsCount,
|
||||
};
|
||||
|
||||
// Make one TShader per shader that you will link into a program. Then
|
||||
// - provide the shader through setStrings() or setStringsWithLengths()
|
||||
// - optionally call setEnv*(), see below for more detail
|
||||
// - optionally use setPreamble() to set a special shader string that will be
|
||||
// processed before all others but won't affect the validity of #version
|
||||
// - optionally call addProcesses() for each setting/transform,
|
||||
// see comment for class TProcesses
|
||||
// - call parse(): source language and target environment must be selected
|
||||
// either by correct setting of EShMessages sent to parse(), or by
|
||||
// explicitly calling setEnv*()
|
||||
// - query the info logs
|
||||
//
|
||||
// N.B.: Does not yet support having the same TShader instance being linked into
|
||||
// multiple programs.
|
||||
//
|
||||
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||
//
|
||||
class TShader {
|
||||
public:
|
||||
GLSLANG_EXPORT explicit TShader(EShLanguage);
|
||||
GLSLANG_EXPORT virtual ~TShader();
|
||||
GLSLANG_EXPORT void setStrings(const char* const* s, int n);
|
||||
GLSLANG_EXPORT void setStringsWithLengths(
|
||||
const char* const* s, const int* l, int n);
|
||||
GLSLANG_EXPORT void setStringsWithLengthsAndNames(
|
||||
const char* const* s, const int* l, const char* const* names, int n);
|
||||
void setPreamble(const char* s) { preamble = s; }
|
||||
GLSLANG_EXPORT void setEntryPoint(const char* entryPoint);
|
||||
GLSLANG_EXPORT void setSourceEntryPoint(const char* sourceEntryPointName);
|
||||
GLSLANG_EXPORT void addProcesses(const std::vector<std::string>&);
|
||||
GLSLANG_EXPORT void setUniqueId(unsigned long long id);
|
||||
|
||||
// IO resolver binding data: see comments in ShaderLang.cpp
|
||||
GLSLANG_EXPORT void setShiftBinding(TResourceType res, unsigned int base);
|
||||
GLSLANG_EXPORT void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
GLSLANG_EXPORT void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
GLSLANG_EXPORT void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
GLSLANG_EXPORT void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
GLSLANG_EXPORT void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
GLSLANG_EXPORT void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
|
||||
GLSLANG_EXPORT void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
|
||||
GLSLANG_EXPORT void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set);
|
||||
GLSLANG_EXPORT void setResourceSetBinding(const std::vector<std::string>& base);
|
||||
GLSLANG_EXPORT void setAutoMapBindings(bool map);
|
||||
GLSLANG_EXPORT void setAutoMapLocations(bool map);
|
||||
GLSLANG_EXPORT void addUniformLocationOverride(const char* name, int loc);
|
||||
GLSLANG_EXPORT void setUniformLocationBase(int base);
|
||||
GLSLANG_EXPORT void setInvertY(bool invert);
|
||||
#ifdef ENABLE_HLSL
|
||||
GLSLANG_EXPORT void setHlslIoMapping(bool hlslIoMap);
|
||||
GLSLANG_EXPORT void setFlattenUniformArrays(bool flatten);
|
||||
#endif
|
||||
GLSLANG_EXPORT void setNoStorageFormat(bool useUnknownFormat);
|
||||
GLSLANG_EXPORT void setNanMinMaxClamp(bool nanMinMaxClamp);
|
||||
GLSLANG_EXPORT void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode);
|
||||
GLSLANG_EXPORT void addBlockStorageOverride(const char* nameStr, glslang::TBlockStorageClass backing);
|
||||
|
||||
GLSLANG_EXPORT void setGlobalUniformBlockName(const char* name);
|
||||
GLSLANG_EXPORT void setAtomicCounterBlockName(const char* name);
|
||||
GLSLANG_EXPORT void setGlobalUniformSet(unsigned int set);
|
||||
GLSLANG_EXPORT void setGlobalUniformBinding(unsigned int binding);
|
||||
GLSLANG_EXPORT void setAtomicCounterBlockSet(unsigned int set);
|
||||
GLSLANG_EXPORT void setAtomicCounterBlockBinding(unsigned int binding);
|
||||
|
||||
// For setting up the environment (cleared to nothingness in the constructor).
|
||||
// These must be called so that parsing is done for the right source language and
|
||||
// target environment, either indirectly through TranslateEnvironment() based on
|
||||
// EShMessages et. al., or directly by the user.
|
||||
//
|
||||
// setEnvInput: The input source language and stage. If generating code for a
|
||||
// specific client, the input client semantics to use and the
|
||||
// version of that client's input semantics to use, otherwise
|
||||
// use EShClientNone and version of 0, e.g. for validation mode.
|
||||
// Note 'version' does not describe the target environment,
|
||||
// just the version of the source dialect to compile under.
|
||||
//
|
||||
// See the definitions of TEnvironment, EShSource, EShLanguage,
|
||||
// and EShClient for choices and more detail.
|
||||
//
|
||||
// setEnvClient: The client that will be hosting the execution, and it's version.
|
||||
// Note 'version' is not the version of the languages involved, but
|
||||
// the version of the client environment.
|
||||
// Use EShClientNone and version of 0 if there is no client, e.g.
|
||||
// for validation mode.
|
||||
//
|
||||
// See EShTargetClientVersion for choices.
|
||||
//
|
||||
// setEnvTarget: The language to translate to when generating code, and that
|
||||
// language's version.
|
||||
// Use EShTargetNone and version of 0 if there is no client, e.g.
|
||||
// for validation mode.
|
||||
//
|
||||
void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version)
|
||||
{
|
||||
environment.input.languageFamily = lang;
|
||||
environment.input.stage = envStage;
|
||||
environment.input.dialect = client;
|
||||
environment.input.dialectVersion = version;
|
||||
}
|
||||
void setEnvClient(EShClient client, EShTargetClientVersion version)
|
||||
{
|
||||
environment.client.client = client;
|
||||
environment.client.version = version;
|
||||
}
|
||||
void setEnvTarget(EShTargetLanguage lang, EShTargetLanguageVersion version)
|
||||
{
|
||||
environment.target.language = lang;
|
||||
environment.target.version = version;
|
||||
}
|
||||
|
||||
void getStrings(const char* const* &s, int& n) { s = strings; n = numStrings; }
|
||||
|
||||
#ifdef ENABLE_HLSL
|
||||
void setEnvTargetHlslFunctionality1() { environment.target.hlslFunctionality1 = true; }
|
||||
bool getEnvTargetHlslFunctionality1() const { return environment.target.hlslFunctionality1; }
|
||||
#else
|
||||
bool getEnvTargetHlslFunctionality1() const { return false; }
|
||||
#endif
|
||||
|
||||
void setEnvInputVulkanRulesRelaxed() { environment.input.vulkanRulesRelaxed = true; }
|
||||
bool getEnvInputVulkanRulesRelaxed() const { return environment.input.vulkanRulesRelaxed; }
|
||||
|
||||
// Interface to #include handlers.
|
||||
//
|
||||
// To support #include, a client of Glslang does the following:
|
||||
// 1. Call setStringsWithNames to set the source strings and associated
|
||||
// names. For example, the names could be the names of the files
|
||||
// containing the shader sources.
|
||||
// 2. Call parse with an Includer.
|
||||
//
|
||||
// When the Glslang parser encounters an #include directive, it calls
|
||||
// the Includer's include method with the requested include name
|
||||
// together with the current string name. The returned IncludeResult
|
||||
// contains the fully resolved name of the included source, together
|
||||
// with the source text that should replace the #include directive
|
||||
// in the source stream. After parsing that source, Glslang will
|
||||
// release the IncludeResult object.
|
||||
class Includer {
|
||||
public:
|
||||
// An IncludeResult contains the resolved name and content of a source
|
||||
// inclusion.
|
||||
struct IncludeResult {
|
||||
IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) :
|
||||
headerName(headerName), headerData(headerData), headerLength(headerLength), userData(userData) { }
|
||||
// For a successful inclusion, the fully resolved name of the requested
|
||||
// include. For example, in a file system-based includer, full resolution
|
||||
// should convert a relative path name into an absolute path name.
|
||||
// For a failed inclusion, this is an empty string.
|
||||
const std::string headerName;
|
||||
// The content and byte length of the requested inclusion. The
|
||||
// Includer producing this IncludeResult retains ownership of the
|
||||
// storage.
|
||||
// For a failed inclusion, the header
|
||||
// field points to a string containing error details.
|
||||
const char* const headerData;
|
||||
const size_t headerLength;
|
||||
// Include resolver's context.
|
||||
void* userData;
|
||||
protected:
|
||||
IncludeResult& operator=(const IncludeResult&);
|
||||
IncludeResult();
|
||||
};
|
||||
|
||||
// For both include methods below:
|
||||
//
|
||||
// Resolves an inclusion request by name, current source name,
|
||||
// and include depth.
|
||||
// On success, returns an IncludeResult containing the resolved name
|
||||
// and content of the include.
|
||||
// On failure, returns a nullptr, or an IncludeResult
|
||||
// with an empty string for the headerName and error details in the
|
||||
// header field.
|
||||
// The Includer retains ownership of the contents
|
||||
// of the returned IncludeResult value, and those contents must
|
||||
// remain valid until the releaseInclude method is called on that
|
||||
// IncludeResult object.
|
||||
//
|
||||
// Note "local" vs. "system" is not an "either/or": "local" is an
|
||||
// extra thing to do over "system". Both might get called, as per
|
||||
// the C++ specification.
|
||||
|
||||
// For the "system" or <>-style includes; search the "system" paths.
|
||||
virtual IncludeResult* includeSystem(const char* /*headerName*/,
|
||||
const char* /*includerName*/,
|
||||
size_t /*inclusionDepth*/) { return nullptr; }
|
||||
|
||||
// For the "local"-only aspect of a "" include. Should not search in the
|
||||
// "system" paths, because on returning a failure, the parser will
|
||||
// call includeSystem() to look in the "system" locations.
|
||||
virtual IncludeResult* includeLocal(const char* /*headerName*/,
|
||||
const char* /*includerName*/,
|
||||
size_t /*inclusionDepth*/) { return nullptr; }
|
||||
|
||||
// Signals that the parser will no longer use the contents of the
|
||||
// specified IncludeResult.
|
||||
virtual void releaseInclude(IncludeResult*) = 0;
|
||||
virtual ~Includer() {}
|
||||
};
|
||||
|
||||
// Fail all Includer searches
|
||||
class ForbidIncluder : public Includer {
|
||||
public:
|
||||
virtual void releaseInclude(IncludeResult*) override { }
|
||||
};
|
||||
|
||||
GLSLANG_EXPORT bool parse(
|
||||
const TBuiltInResource*, int defaultVersion, EProfile defaultProfile,
|
||||
bool forceDefaultVersionAndProfile, bool forwardCompatible,
|
||||
EShMessages, Includer&);
|
||||
|
||||
bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, EShMessages messages)
|
||||
{
|
||||
TShader::ForbidIncluder includer;
|
||||
return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
|
||||
}
|
||||
|
||||
// Equivalent to parse() without a default profile and without forcing defaults.
|
||||
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
|
||||
{
|
||||
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages);
|
||||
}
|
||||
|
||||
bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages,
|
||||
Includer& includer)
|
||||
{
|
||||
return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages, includer);
|
||||
}
|
||||
|
||||
// NOTE: Doing just preprocessing to obtain a correct preprocessed shader string
|
||||
// is not an officially supported or fully working path.
|
||||
GLSLANG_EXPORT bool preprocess(
|
||||
const TBuiltInResource* builtInResources, int defaultVersion,
|
||||
EProfile defaultProfile, bool forceDefaultVersionAndProfile,
|
||||
bool forwardCompatible, EShMessages message, std::string* outputString,
|
||||
Includer& includer);
|
||||
|
||||
GLSLANG_EXPORT const char* getInfoLog();
|
||||
GLSLANG_EXPORT const char* getInfoDebugLog();
|
||||
EShLanguage getStage() const { return stage; }
|
||||
TIntermediate* getIntermediate() const { return intermediate; }
|
||||
|
||||
protected:
|
||||
TPoolAllocator* pool;
|
||||
EShLanguage stage;
|
||||
TCompiler* compiler;
|
||||
TIntermediate* intermediate;
|
||||
TInfoSink* infoSink;
|
||||
// strings and lengths follow the standard for glShaderSource:
|
||||
// strings is an array of numStrings pointers to string data.
|
||||
// lengths can be null, but if not it is an array of numStrings
|
||||
// integers containing the length of the associated strings.
|
||||
// if lengths is null or lengths[n] < 0 the associated strings[n] is
|
||||
// assumed to be null-terminated.
|
||||
// stringNames is the optional names for all the strings. If stringNames
|
||||
// is null, then none of the strings has name. If a certain element in
|
||||
// stringNames is null, then the corresponding string does not have name.
|
||||
const char* const* strings; // explicit code to compile, see previous comment
|
||||
const int* lengths;
|
||||
const char* const* stringNames;
|
||||
int numStrings; // size of the above arrays
|
||||
const char* preamble; // string of implicit code to compile before the explicitly provided code
|
||||
|
||||
// a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
|
||||
std::string sourceEntryPointName;
|
||||
|
||||
TEnvironment environment;
|
||||
|
||||
friend class TProgram;
|
||||
|
||||
private:
|
||||
TShader& operator=(TShader&);
|
||||
};
|
||||
|
||||
#if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
|
||||
|
||||
//
|
||||
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
|
||||
//
|
||||
|
||||
// Data needed for just a single object at the granularity exchanged by the reflection API
|
||||
class TObjectReflection {
|
||||
public:
|
||||
GLSLANG_EXPORT TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
|
||||
|
||||
GLSLANG_EXPORT const TType* getType() const { return type; }
|
||||
GLSLANG_EXPORT int getBinding() const;
|
||||
GLSLANG_EXPORT void dump() const;
|
||||
static TObjectReflection badReflection() { return TObjectReflection(); }
|
||||
|
||||
std::string name;
|
||||
int offset;
|
||||
int glDefineType;
|
||||
int size; // data size in bytes for a block, array size for a (non-block) object that's an array
|
||||
int index;
|
||||
int counterIndex;
|
||||
int numMembers;
|
||||
int arrayStride; // stride of an array variable
|
||||
int topLevelArraySize; // size of the top-level variable in a storage buffer member
|
||||
int topLevelArrayStride; // stride of the top-level variable in a storage buffer member
|
||||
EShLanguageMask stages;
|
||||
|
||||
protected:
|
||||
TObjectReflection()
|
||||
: offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), numMembers(-1), arrayStride(0),
|
||||
topLevelArrayStride(0), stages(EShLanguageMask(0)), type(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
const TType* type;
|
||||
};
|
||||
|
||||
class TReflection;
|
||||
class TIoMapper;
|
||||
struct TVarEntryInfo;
|
||||
|
||||
// Allows to customize the binding layout after linking.
|
||||
// All used uniform variables will invoke at least validateBinding.
|
||||
// If validateBinding returned true then the other resolveBinding,
|
||||
// resolveSet, and resolveLocation are invoked to resolve the binding
|
||||
// and descriptor set index respectively.
|
||||
//
|
||||
// Invocations happen in a particular order:
|
||||
// 1) all shader inputs
|
||||
// 2) all shader outputs
|
||||
// 3) all uniforms with binding and set already defined
|
||||
// 4) all uniforms with binding but no set defined
|
||||
// 5) all uniforms with set but no binding defined
|
||||
// 6) all uniforms with no binding and no set defined
|
||||
//
|
||||
// mapIO will use this resolver in two phases. The first
|
||||
// phase is a notification phase, calling the corresponging
|
||||
// notifiy callbacks, this phase ends with a call to endNotifications.
|
||||
// Phase two starts directly after the call to endNotifications
|
||||
// and calls all other callbacks to validate and to get the
|
||||
// bindings, sets, locations, component and color indices.
|
||||
//
|
||||
// NOTE: that still limit checks are applied to bindings and sets
|
||||
// and may result in an error.
|
||||
class TIoMapResolver
|
||||
{
|
||||
public:
|
||||
virtual ~TIoMapResolver() {}
|
||||
|
||||
// Should return true if the resulting/current binding would be okay.
|
||||
// Basic idea is to do aliasing binding checks with this.
|
||||
virtual bool validateBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current binding should be overridden.
|
||||
// Return -1 if the current binding (including no binding) should be kept.
|
||||
virtual int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current set should be overridden.
|
||||
// Return -1 if the current set (including no set) should be kept.
|
||||
virtual int resolveSet(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current location should be overridden.
|
||||
// Return -1 if the current location (including no location) should be kept.
|
||||
virtual int resolveUniformLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return true if the resulting/current setup would be okay.
|
||||
// Basic idea is to do aliasing checks and reject invalid semantic names.
|
||||
virtual bool validateInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current location should be overridden.
|
||||
// Return -1 if the current location (including no location) should be kept.
|
||||
virtual int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current component index should be overridden.
|
||||
// Return -1 if the current component index (including no index) should be kept.
|
||||
virtual int resolveInOutComponent(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Should return a value >= 0 if the current color index should be overridden.
|
||||
// Return -1 if the current color index (including no index) should be kept.
|
||||
virtual int resolveInOutIndex(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Notification of a uniform variable
|
||||
virtual void notifyBinding(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Notification of a in or out variable
|
||||
virtual void notifyInOut(EShLanguage stage, TVarEntryInfo& ent) = 0;
|
||||
// Called by mapIO when it starts its notify pass for the given stage
|
||||
virtual void beginNotifications(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it has finished the notify pass
|
||||
virtual void endNotifications(EShLanguage stage) = 0;
|
||||
// Called by mipIO when it starts its resolve pass for the given stage
|
||||
virtual void beginResolve(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it has finished the resolve pass
|
||||
virtual void endResolve(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it starts its symbol collect for teh given stage
|
||||
virtual void beginCollect(EShLanguage stage) = 0;
|
||||
// Called by mapIO when it has finished the symbol collect
|
||||
virtual void endCollect(EShLanguage stage) = 0;
|
||||
// Called by TSlotCollector to resolve storage locations or bindings
|
||||
virtual void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
|
||||
// Called by TSlotCollector to resolve resource locations or bindings
|
||||
virtual void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0;
|
||||
// Called by mapIO.addStage to set shader stage mask to mark a stage be added to this pipeline
|
||||
virtual void addStage(EShLanguage stage, TIntermediate& stageIntermediate) = 0;
|
||||
};
|
||||
|
||||
#endif // !GLSLANG_WEB && !GLSLANG_ANGLE
|
||||
|
||||
// Make one TProgram per set of shaders that will get linked together. Add all
|
||||
// the shaders that are to be linked together. After calling shader.parse()
|
||||
// for all shaders, call link().
|
||||
//
|
||||
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||
//
|
||||
class TProgram {
|
||||
public:
|
||||
GLSLANG_EXPORT TProgram();
|
||||
GLSLANG_EXPORT virtual ~TProgram();
|
||||
void addShader(TShader* shader) { stages[shader->stage].push_back(shader); }
|
||||
std::list<TShader*>& getShaders(EShLanguage stage) { return stages[stage]; }
|
||||
// Link Validation interface
|
||||
GLSLANG_EXPORT bool link(EShMessages);
|
||||
GLSLANG_EXPORT const char* getInfoLog();
|
||||
GLSLANG_EXPORT const char* getInfoDebugLog();
|
||||
|
||||
TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; }
|
||||
|
||||
#if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
|
||||
|
||||
// Reflection Interface
|
||||
|
||||
// call first, to do liveness analysis, index mapping, etc.; returns false on failure
|
||||
GLSLANG_EXPORT bool buildReflection(int opts = EShReflectionDefault);
|
||||
GLSLANG_EXPORT unsigned getLocalSize(int dim) const; // return dim'th local size
|
||||
GLSLANG_EXPORT int getReflectionIndex(const char *name) const;
|
||||
GLSLANG_EXPORT int getReflectionPipeIOIndex(const char* name, const bool inOrOut) const;
|
||||
GLSLANG_EXPORT int getNumUniformVariables() const;
|
||||
GLSLANG_EXPORT const TObjectReflection& getUniform(int index) const;
|
||||
GLSLANG_EXPORT int getNumUniformBlocks() const;
|
||||
GLSLANG_EXPORT const TObjectReflection& getUniformBlock(int index) const;
|
||||
GLSLANG_EXPORT int getNumPipeInputs() const;
|
||||
GLSLANG_EXPORT const TObjectReflection& getPipeInput(int index) const;
|
||||
GLSLANG_EXPORT int getNumPipeOutputs() const;
|
||||
GLSLANG_EXPORT const TObjectReflection& getPipeOutput(int index) const;
|
||||
GLSLANG_EXPORT int getNumBufferVariables() const;
|
||||
GLSLANG_EXPORT const TObjectReflection& getBufferVariable(int index) const;
|
||||
GLSLANG_EXPORT int getNumBufferBlocks() const;
|
||||
GLSLANG_EXPORT const TObjectReflection& getBufferBlock(int index) const;
|
||||
GLSLANG_EXPORT int getNumAtomicCounters() const;
|
||||
GLSLANG_EXPORT const TObjectReflection& getAtomicCounter(int index) const;
|
||||
|
||||
// Legacy Reflection Interface - expressed in terms of above interface
|
||||
|
||||
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
|
||||
int getNumLiveUniformVariables() const { return getNumUniformVariables(); }
|
||||
|
||||
// can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
|
||||
int getNumLiveUniformBlocks() const { return getNumUniformBlocks(); }
|
||||
|
||||
// can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
|
||||
int getNumLiveAttributes() const { return getNumPipeInputs(); }
|
||||
|
||||
// can be used for glGetUniformIndices()
|
||||
int getUniformIndex(const char *name) const { return getReflectionIndex(name); }
|
||||
|
||||
int getPipeIOIndex(const char *name, const bool inOrOut) const
|
||||
{ return getReflectionPipeIOIndex(name, inOrOut); }
|
||||
|
||||
// can be used for "name" part of glGetActiveUniform()
|
||||
const char *getUniformName(int index) const { return getUniform(index).name.c_str(); }
|
||||
|
||||
// returns the binding number
|
||||
int getUniformBinding(int index) const { return getUniform(index).getBinding(); }
|
||||
|
||||
// returns Shaders Stages where a Uniform is present
|
||||
EShLanguageMask getUniformStages(int index) const { return getUniform(index).stages; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
|
||||
int getUniformBlockIndex(int index) const { return getUniform(index).index; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
|
||||
int getUniformType(int index) const { return getUniform(index).glDefineType; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
|
||||
int getUniformBufferOffset(int index) const { return getUniform(index).offset; }
|
||||
|
||||
// can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
|
||||
int getUniformArraySize(int index) const { return getUniform(index).size; }
|
||||
|
||||
// returns a TType*
|
||||
const TType *getUniformTType(int index) const { return getUniform(index).getType(); }
|
||||
|
||||
// can be used for glGetActiveUniformBlockName()
|
||||
const char *getUniformBlockName(int index) const { return getUniformBlock(index).name.c_str(); }
|
||||
|
||||
// can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
|
||||
int getUniformBlockSize(int index) const { return getUniformBlock(index).size; }
|
||||
|
||||
// returns the block binding number
|
||||
int getUniformBlockBinding(int index) const { return getUniformBlock(index).getBinding(); }
|
||||
|
||||
// returns block index of associated counter.
|
||||
int getUniformBlockCounterIndex(int index) const { return getUniformBlock(index).counterIndex; }
|
||||
|
||||
// returns a TType*
|
||||
const TType *getUniformBlockTType(int index) const { return getUniformBlock(index).getType(); }
|
||||
|
||||
// can be used for glGetActiveAttrib()
|
||||
const char *getAttributeName(int index) const { return getPipeInput(index).name.c_str(); }
|
||||
|
||||
// can be used for glGetActiveAttrib()
|
||||
int getAttributeType(int index) const { return getPipeInput(index).glDefineType; }
|
||||
|
||||
// returns a TType*
|
||||
const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); }
|
||||
|
||||
GLSLANG_EXPORT void dumpReflection();
|
||||
// I/O mapping: apply base offsets and map live unbound variables
|
||||
// If resolver is not provided it uses the previous approach
|
||||
// and respects auto assignment and offsets.
|
||||
GLSLANG_EXPORT bool mapIO(TIoMapResolver* pResolver = nullptr, TIoMapper* pIoMapper = nullptr);
|
||||
#endif // !GLSLANG_WEB && !GLSLANG_ANGLE
|
||||
|
||||
protected:
|
||||
GLSLANG_EXPORT bool linkStage(EShLanguage, EShMessages);
|
||||
GLSLANG_EXPORT bool crossStageCheck(EShMessages);
|
||||
|
||||
TPoolAllocator* pool;
|
||||
std::list<TShader*> stages[EShLangCount];
|
||||
TIntermediate* intermediate[EShLangCount];
|
||||
bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage
|
||||
TInfoSink* infoSink;
|
||||
#if !defined(GLSLANG_WEB) && !defined(GLSLANG_ANGLE)
|
||||
TReflection* reflection;
|
||||
#endif
|
||||
bool linked;
|
||||
|
||||
private:
|
||||
TProgram(TProgram&);
|
||||
TProgram& operator=(TProgram&);
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _COMPILER_INTERFACE_INCLUDED_
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// Copyright (C) 2014 LunarG, Inc.
|
||||
// Copyright (C) 2015-2018 Google, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1900
|
||||
#pragma warning(disable : 4464) // relative include path contains '..'
|
||||
#endif
|
||||
|
||||
#include "SpvTools.h"
|
||||
#include "glslang/Include/intermediate.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
void GetSpirvVersion(std::string&);
|
||||
int GetSpirvGeneratorVersion();
|
||||
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
SpvOptions* options = nullptr);
|
||||
void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger* logger, SpvOptions* options = nullptr);
|
||||
void OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName);
|
||||
void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName, const char* varName);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// Copyright (C) 2016 Google, Inc.
|
||||
//
|
||||
// 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 Google Inc. 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 HOLDERS 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.
|
||||
|
||||
#ifndef GLSLANG_SPIRV_LOGGER_H
|
||||
#define GLSLANG_SPIRV_LOGGER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace spv {
|
||||
|
||||
// A class for holding all SPIR-V build status messages, including
|
||||
// missing/TBD functionalities, warnings, and errors.
|
||||
class SpvBuildLogger {
|
||||
public:
|
||||
SpvBuildLogger() {}
|
||||
|
||||
#ifdef GLSLANG_WEB
|
||||
void tbdFunctionality(const std::string& f) { }
|
||||
void missingFunctionality(const std::string& f) { }
|
||||
void warning(const std::string& w) { }
|
||||
void error(const std::string& e) { errors.push_back(e); }
|
||||
std::string getAllMessages() { return ""; }
|
||||
#else
|
||||
|
||||
// Registers a TBD functionality.
|
||||
void tbdFunctionality(const std::string& f);
|
||||
// Registers a missing functionality.
|
||||
void missingFunctionality(const std::string& f);
|
||||
|
||||
// Logs a warning.
|
||||
void warning(const std::string& w) { warnings.push_back(w); }
|
||||
// Logs an error.
|
||||
void error(const std::string& e) { errors.push_back(e); }
|
||||
|
||||
// Returns all messages accumulated in the order of:
|
||||
// TBD functionalities, missing functionalities, warnings, errors.
|
||||
std::string getAllMessages() const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
SpvBuildLogger(const SpvBuildLogger&);
|
||||
|
||||
std::vector<std::string> tbdFeatures;
|
||||
std::vector<std::string> missingFeatures;
|
||||
std::vector<std::string> warnings;
|
||||
std::vector<std::string> errors;
|
||||
};
|
||||
|
||||
} // end spv namespace
|
||||
|
||||
#endif // GLSLANG_SPIRV_LOGGER_H
|
||||
@@ -0,0 +1,304 @@
|
||||
//
|
||||
// Copyright (C) 2015 LunarG, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
//
|
||||
|
||||
#ifndef SPIRVREMAPPER_H
|
||||
#define SPIRVREMAPPER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
|
||||
namespace spv {
|
||||
|
||||
// MSVC defines __cplusplus as an older value, even when it supports almost all of 11.
|
||||
// We handle that here by making our own symbol.
|
||||
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1700)
|
||||
# define use_cpp11 1
|
||||
#endif
|
||||
|
||||
class spirvbin_base_t
|
||||
{
|
||||
public:
|
||||
enum Options {
|
||||
NONE = 0,
|
||||
STRIP = (1<<0),
|
||||
MAP_TYPES = (1<<1),
|
||||
MAP_NAMES = (1<<2),
|
||||
MAP_FUNCS = (1<<3),
|
||||
DCE_FUNCS = (1<<4),
|
||||
DCE_VARS = (1<<5),
|
||||
DCE_TYPES = (1<<6),
|
||||
OPT_LOADSTORE = (1<<7),
|
||||
OPT_FWD_LS = (1<<8), // EXPERIMENTAL: PRODUCES INVALID SCHEMA-0 SPIRV
|
||||
MAP_ALL = (MAP_TYPES | MAP_NAMES | MAP_FUNCS),
|
||||
DCE_ALL = (DCE_FUNCS | DCE_VARS | DCE_TYPES),
|
||||
OPT_ALL = (OPT_LOADSTORE),
|
||||
|
||||
ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL),
|
||||
DO_EVERYTHING = (STRIP | ALL_BUT_STRIP)
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace SPV
|
||||
|
||||
#if !defined (use_cpp11)
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
namespace spv {
|
||||
class spirvbin_t : public spirvbin_base_t
|
||||
{
|
||||
public:
|
||||
spirvbin_t(int /*verbose = 0*/) { }
|
||||
|
||||
void remap(std::vector<std::uint32_t>& /*spv*/, unsigned int /*opts = 0*/)
|
||||
{
|
||||
printf("Tool not compiled for C++11, which is required for SPIR-V remapping.\n");
|
||||
exit(5);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace SPV
|
||||
|
||||
#else // defined (use_cpp11)
|
||||
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <cassert>
|
||||
|
||||
#include "spirv.hpp"
|
||||
#include "spvIR.h"
|
||||
|
||||
namespace spv {
|
||||
|
||||
// class to hold SPIR-V binary data for remapping, DCE, and debug stripping
|
||||
class spirvbin_t : public spirvbin_base_t
|
||||
{
|
||||
public:
|
||||
spirvbin_t(int verbose = 0) : entryPoint(spv::NoResult), largestNewId(0), verbose(verbose), errorLatch(false)
|
||||
{ }
|
||||
|
||||
virtual ~spirvbin_t() { }
|
||||
|
||||
// remap on an existing binary in memory
|
||||
void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
|
||||
|
||||
// Type for error/log handler functions
|
||||
typedef std::function<void(const std::string&)> errorfn_t;
|
||||
typedef std::function<void(const std::string&)> logfn_t;
|
||||
|
||||
// Register error/log handling functions (can be lambda fn / functor / etc)
|
||||
static void registerErrorHandler(errorfn_t handler) { errorHandler = handler; }
|
||||
static void registerLogHandler(logfn_t handler) { logHandler = handler; }
|
||||
|
||||
protected:
|
||||
// This can be overridden to provide other message behavior if needed
|
||||
virtual void msg(int minVerbosity, int indent, const std::string& txt) const;
|
||||
|
||||
private:
|
||||
// Local to global, or global to local ID map
|
||||
typedef std::unordered_map<spv::Id, spv::Id> idmap_t;
|
||||
typedef std::unordered_set<spv::Id> idset_t;
|
||||
typedef std::unordered_map<spv::Id, int> blockmap_t;
|
||||
|
||||
void remap(std::uint32_t opts = DO_EVERYTHING);
|
||||
|
||||
// Map of names to IDs
|
||||
typedef std::unordered_map<std::string, spv::Id> namemap_t;
|
||||
|
||||
typedef std::uint32_t spirword_t;
|
||||
|
||||
typedef std::pair<unsigned, unsigned> range_t;
|
||||
typedef std::function<void(spv::Id&)> idfn_t;
|
||||
typedef std::function<bool(spv::Op, unsigned start)> instfn_t;
|
||||
|
||||
// Special Values for ID map:
|
||||
static const spv::Id unmapped; // unchanged from default value
|
||||
static const spv::Id unused; // unused ID
|
||||
static const int header_size; // SPIR header = 5 words
|
||||
|
||||
class id_iterator_t;
|
||||
|
||||
// For mapping type entries between different shaders
|
||||
typedef std::vector<spirword_t> typeentry_t;
|
||||
typedef std::map<spv::Id, typeentry_t> globaltypes_t;
|
||||
|
||||
// A set that preserves position order, and a reverse map
|
||||
typedef std::set<int> posmap_t;
|
||||
typedef std::unordered_map<spv::Id, int> posmap_rev_t;
|
||||
|
||||
// Maps and ID to the size of its base type, if known.
|
||||
typedef std::unordered_map<spv::Id, unsigned> typesize_map_t;
|
||||
|
||||
// handle error
|
||||
void error(const std::string& txt) const { errorLatch = true; errorHandler(txt); }
|
||||
|
||||
bool isConstOp(spv::Op opCode) const;
|
||||
bool isTypeOp(spv::Op opCode) const;
|
||||
bool isStripOp(spv::Op opCode) const;
|
||||
bool isFlowCtrl(spv::Op opCode) const;
|
||||
range_t literalRange(spv::Op opCode) const;
|
||||
range_t typeRange(spv::Op opCode) const;
|
||||
range_t constRange(spv::Op opCode) const;
|
||||
unsigned typeSizeInWords(spv::Id id) const;
|
||||
unsigned idTypeSizeInWords(spv::Id id) const;
|
||||
|
||||
spv::Id& asId(unsigned word) { return spv[word]; }
|
||||
const spv::Id& asId(unsigned word) const { return spv[word]; }
|
||||
spv::Op asOpCode(unsigned word) const { return opOpCode(spv[word]); }
|
||||
std::uint32_t asOpCodeHash(unsigned word);
|
||||
spv::Decoration asDecoration(unsigned word) const { return spv::Decoration(spv[word]); }
|
||||
unsigned asWordCount(unsigned word) const { return opWordCount(spv[word]); }
|
||||
spv::Id asTypeConstId(unsigned word) const { return asId(word + (isTypeOp(asOpCode(word)) ? 1 : 2)); }
|
||||
unsigned idPos(spv::Id id) const;
|
||||
|
||||
static unsigned opWordCount(spirword_t data) { return data >> spv::WordCountShift; }
|
||||
static spv::Op opOpCode(spirword_t data) { return spv::Op(data & spv::OpCodeMask); }
|
||||
|
||||
// Header access & set methods
|
||||
spirword_t magic() const { return spv[0]; } // return magic number
|
||||
spirword_t bound() const { return spv[3]; } // return Id bound from header
|
||||
spirword_t bound(spirword_t b) { return spv[3] = b; }
|
||||
spirword_t genmagic() const { return spv[2]; } // generator magic
|
||||
spirword_t genmagic(spirword_t m) { return spv[2] = m; }
|
||||
spirword_t schemaNum() const { return spv[4]; } // schema number from header
|
||||
|
||||
// Mapping fns: get
|
||||
spv::Id localId(spv::Id id) const { return idMapL[id]; }
|
||||
|
||||
// Mapping fns: set
|
||||
inline spv::Id localId(spv::Id id, spv::Id newId);
|
||||
void countIds(spv::Id id);
|
||||
|
||||
// Return next unused new local ID.
|
||||
// NOTE: boost::dynamic_bitset would be more efficient due to find_next(),
|
||||
// which std::vector<bool> doens't have.
|
||||
inline spv::Id nextUnusedId(spv::Id id);
|
||||
|
||||
void buildLocalMaps();
|
||||
std::string literalString(unsigned word) const; // Return literal as a std::string
|
||||
int literalStringWords(const std::string& str) const { return (int(str.size())+4)/4; }
|
||||
|
||||
bool isNewIdMapped(spv::Id newId) const { return isMapped(newId); }
|
||||
bool isOldIdUnmapped(spv::Id oldId) const { return localId(oldId) == unmapped; }
|
||||
bool isOldIdUnused(spv::Id oldId) const { return localId(oldId) == unused; }
|
||||
bool isOldIdMapped(spv::Id oldId) const { return !isOldIdUnused(oldId) && !isOldIdUnmapped(oldId); }
|
||||
bool isFunction(spv::Id oldId) const { return fnPos.find(oldId) != fnPos.end(); }
|
||||
|
||||
// bool matchType(const globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const;
|
||||
// spv::Id findType(const globaltypes_t& globalTypes, spv::Id lt) const;
|
||||
std::uint32_t hashType(unsigned typeStart) const;
|
||||
|
||||
spirvbin_t& process(instfn_t, idfn_t, unsigned begin = 0, unsigned end = 0);
|
||||
int processInstruction(unsigned word, instfn_t, idfn_t);
|
||||
|
||||
void validate() const;
|
||||
void mapTypeConst();
|
||||
void mapFnBodies();
|
||||
void optLoadStore();
|
||||
void dceFuncs();
|
||||
void dceVars();
|
||||
void dceTypes();
|
||||
void mapNames();
|
||||
void foldIds(); // fold IDs to smallest space
|
||||
void forwardLoadStores(); // load store forwarding (EXPERIMENTAL)
|
||||
void offsetIds(); // create relative offset IDs
|
||||
|
||||
void applyMap(); // remap per local name map
|
||||
void mapRemainder(); // map any IDs we haven't touched yet
|
||||
void stripDebug(); // strip all debug info
|
||||
void stripDeadRefs(); // strips debug info for now-dead references after DCE
|
||||
void strip(); // remove debug symbols
|
||||
|
||||
std::vector<spirword_t> spv; // SPIR words
|
||||
|
||||
namemap_t nameMap; // ID names from OpName
|
||||
|
||||
// Since we want to also do binary ops, we can't use std::vector<bool>. we could use
|
||||
// boost::dynamic_bitset, but we're trying to avoid a boost dependency.
|
||||
typedef std::uint64_t bits_t;
|
||||
std::vector<bits_t> mapped; // which new IDs have been mapped
|
||||
static const int mBits = sizeof(bits_t) * 4;
|
||||
|
||||
bool isMapped(spv::Id id) const { return id < maxMappedId() && ((mapped[id/mBits] & (1LL<<(id%mBits))) != 0); }
|
||||
void setMapped(spv::Id id) { resizeMapped(id); mapped[id/mBits] |= (1LL<<(id%mBits)); }
|
||||
void resizeMapped(spv::Id id) { if (id >= maxMappedId()) mapped.resize(id/mBits+1, 0); }
|
||||
size_t maxMappedId() const { return mapped.size() * mBits; }
|
||||
|
||||
// Add a strip range for a given instruction starting at 'start'
|
||||
// Note: avoiding brace initializers to please older versions os MSVC.
|
||||
void stripInst(unsigned start) { stripRange.push_back(range_t(start, start + asWordCount(start))); }
|
||||
|
||||
// Function start and end. use unordered_map because we'll have
|
||||
// many fewer functions than IDs.
|
||||
std::unordered_map<spv::Id, range_t> fnPos;
|
||||
|
||||
// Which functions are called, anywhere in the module, with a call count
|
||||
std::unordered_map<spv::Id, int> fnCalls;
|
||||
|
||||
posmap_t typeConstPos; // word positions that define types & consts (ordered)
|
||||
posmap_rev_t idPosR; // reverse map from IDs to positions
|
||||
typesize_map_t idTypeSizeMap; // maps each ID to its type size, if known.
|
||||
|
||||
std::vector<spv::Id> idMapL; // ID {M}ap from {L}ocal to {G}lobal IDs
|
||||
|
||||
spv::Id entryPoint; // module entry point
|
||||
spv::Id largestNewId; // biggest new ID we have mapped anything to
|
||||
|
||||
// Sections of the binary to strip, given as [begin,end)
|
||||
std::vector<range_t> stripRange;
|
||||
|
||||
// processing options:
|
||||
std::uint32_t options;
|
||||
int verbose; // verbosity level
|
||||
|
||||
// Error latch: this is set if the error handler is ever executed. It would be better to
|
||||
// use a try/catch block and throw, but that's not desired for certain environments, so
|
||||
// this is the alternative.
|
||||
mutable bool errorLatch;
|
||||
|
||||
static errorfn_t errorHandler;
|
||||
static logfn_t logHandler;
|
||||
};
|
||||
|
||||
} // namespace SPV
|
||||
|
||||
#endif // defined (use_cpp11)
|
||||
#endif // SPIRVREMAPPER_H
|
||||
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Copyright (C) 2014-2016 LunarG, Inc.
|
||||
// Copyright (C) 2018 Google, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
|
||||
//
|
||||
// Call into SPIRV-Tools to disassemble, validate, and optimize.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef GLSLANG_SPV_TOOLS_H
|
||||
#define GLSLANG_SPV_TOOLS_H
|
||||
|
||||
#if ENABLE_OPT
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
#include "spirv-tools/libspirv.h"
|
||||
#endif
|
||||
|
||||
#include "glslang/MachineIndependent/localintermediate.h"
|
||||
#include "Logger.h"
|
||||
|
||||
namespace glslang {
|
||||
|
||||
struct SpvOptions {
|
||||
SpvOptions() : generateDebugInfo(false), stripDebugInfo(false), disableOptimizer(true),
|
||||
optimizeSize(false), disassemble(false), validate(false) { }
|
||||
bool generateDebugInfo;
|
||||
bool stripDebugInfo;
|
||||
bool disableOptimizer;
|
||||
bool optimizeSize;
|
||||
bool disassemble;
|
||||
bool validate;
|
||||
};
|
||||
|
||||
#if ENABLE_OPT
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);
|
||||
|
||||
// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.
|
||||
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,
|
||||
spv_target_env requested_context);
|
||||
|
||||
// Apply the SPIRV-Tools validator to generated SPIR-V.
|
||||
void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger*, bool prelegalization);
|
||||
|
||||
// Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process.
|
||||
void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
|
||||
spv::SpvBuildLogger*, const SpvOptions*);
|
||||
|
||||
// Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by
|
||||
// SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if
|
||||
// optimization is disabled.
|
||||
void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,
|
||||
std::vector<unsigned int>& spirv, spv::SpvBuildLogger*);
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // GLSLANG_SPV_TOOLS_H
|
||||
+2293
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,508 @@
|
||||
//
|
||||
// Copyright (C) 2014 LunarG, Inc.
|
||||
// Copyright (C) 2015-2018 Google, Inc.
|
||||
//
|
||||
// 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 3Dlabs Inc. Ltd. 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 HOLDERS 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.
|
||||
|
||||
// SPIRV-IR
|
||||
//
|
||||
// Simple in-memory representation (IR) of SPIRV. Just for holding
|
||||
// Each function's CFG of blocks. Has this hierarchy:
|
||||
// - Module, which is a list of
|
||||
// - Function, which is a list of
|
||||
// - Block, which is a list of
|
||||
// - Instruction
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#ifndef spvIR_H
|
||||
#define spvIR_H
|
||||
|
||||
#include "spirv.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace spv {
|
||||
|
||||
class Block;
|
||||
class Function;
|
||||
class Module;
|
||||
|
||||
const Id NoResult = 0;
|
||||
const Id NoType = 0;
|
||||
|
||||
const Decoration NoPrecision = DecorationMax;
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define POTENTIALLY_UNUSED __attribute__((unused))
|
||||
#else
|
||||
# define POTENTIALLY_UNUSED
|
||||
#endif
|
||||
|
||||
POTENTIALLY_UNUSED
|
||||
const MemorySemanticsMask MemorySemanticsAllMemory =
|
||||
(MemorySemanticsMask)(MemorySemanticsUniformMemoryMask |
|
||||
MemorySemanticsWorkgroupMemoryMask |
|
||||
MemorySemanticsAtomicCounterMemoryMask |
|
||||
MemorySemanticsImageMemoryMask);
|
||||
|
||||
struct IdImmediate {
|
||||
bool isId; // true if word is an Id, false if word is an immediate
|
||||
unsigned word;
|
||||
IdImmediate(bool i, unsigned w) : isId(i), word(w) {}
|
||||
};
|
||||
|
||||
//
|
||||
// SPIR-V IR instruction.
|
||||
//
|
||||
|
||||
class Instruction {
|
||||
public:
|
||||
Instruction(Id resultId, Id typeId, Op opCode) : resultId(resultId), typeId(typeId), opCode(opCode), block(nullptr) { }
|
||||
explicit Instruction(Op opCode) : resultId(NoResult), typeId(NoType), opCode(opCode), block(nullptr) { }
|
||||
virtual ~Instruction() {}
|
||||
void addIdOperand(Id id) {
|
||||
operands.push_back(id);
|
||||
idOperand.push_back(true);
|
||||
}
|
||||
void addImmediateOperand(unsigned int immediate) {
|
||||
operands.push_back(immediate);
|
||||
idOperand.push_back(false);
|
||||
}
|
||||
void setImmediateOperand(unsigned idx, unsigned int immediate) {
|
||||
assert(!idOperand[idx]);
|
||||
operands[idx] = immediate;
|
||||
}
|
||||
|
||||
void addStringOperand(const char* str)
|
||||
{
|
||||
unsigned int word;
|
||||
char* wordString = (char*)&word;
|
||||
char* wordPtr = wordString;
|
||||
int charCount = 0;
|
||||
char c;
|
||||
do {
|
||||
c = *(str++);
|
||||
*(wordPtr++) = c;
|
||||
++charCount;
|
||||
if (charCount == 4) {
|
||||
addImmediateOperand(word);
|
||||
wordPtr = wordString;
|
||||
charCount = 0;
|
||||
}
|
||||
} while (c != 0);
|
||||
|
||||
// deal with partial last word
|
||||
if (charCount > 0) {
|
||||
// pad with 0s
|
||||
for (; charCount < 4; ++charCount)
|
||||
*(wordPtr++) = 0;
|
||||
addImmediateOperand(word);
|
||||
}
|
||||
}
|
||||
bool isIdOperand(int op) const { return idOperand[op]; }
|
||||
void setBlock(Block* b) { block = b; }
|
||||
Block* getBlock() const { return block; }
|
||||
Op getOpCode() const { return opCode; }
|
||||
int getNumOperands() const
|
||||
{
|
||||
assert(operands.size() == idOperand.size());
|
||||
return (int)operands.size();
|
||||
}
|
||||
Id getResultId() const { return resultId; }
|
||||
Id getTypeId() const { return typeId; }
|
||||
Id getIdOperand(int op) const {
|
||||
assert(idOperand[op]);
|
||||
return operands[op];
|
||||
}
|
||||
unsigned int getImmediateOperand(int op) const {
|
||||
assert(!idOperand[op]);
|
||||
return operands[op];
|
||||
}
|
||||
|
||||
// Write out the binary form.
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
// Compute the wordCount
|
||||
unsigned int wordCount = 1;
|
||||
if (typeId)
|
||||
++wordCount;
|
||||
if (resultId)
|
||||
++wordCount;
|
||||
wordCount += (unsigned int)operands.size();
|
||||
|
||||
// Write out the beginning of the instruction
|
||||
out.push_back(((wordCount) << WordCountShift) | opCode);
|
||||
if (typeId)
|
||||
out.push_back(typeId);
|
||||
if (resultId)
|
||||
out.push_back(resultId);
|
||||
|
||||
// Write out the operands
|
||||
for (int op = 0; op < (int)operands.size(); ++op)
|
||||
out.push_back(operands[op]);
|
||||
}
|
||||
|
||||
protected:
|
||||
Instruction(const Instruction&);
|
||||
Id resultId;
|
||||
Id typeId;
|
||||
Op opCode;
|
||||
std::vector<Id> operands; // operands, both <id> and immediates (both are unsigned int)
|
||||
std::vector<bool> idOperand; // true for operands that are <id>, false for immediates
|
||||
Block* block;
|
||||
};
|
||||
|
||||
//
|
||||
// SPIR-V IR block.
|
||||
//
|
||||
|
||||
class Block {
|
||||
public:
|
||||
Block(Id id, Function& parent);
|
||||
virtual ~Block()
|
||||
{
|
||||
}
|
||||
|
||||
Id getId() { return instructions.front()->getResultId(); }
|
||||
|
||||
Function& getParent() const { return parent; }
|
||||
void addInstruction(std::unique_ptr<Instruction> inst);
|
||||
void addPredecessor(Block* pred) { predecessors.push_back(pred); pred->successors.push_back(this);}
|
||||
void addLocalVariable(std::unique_ptr<Instruction> inst) { localVariables.push_back(std::move(inst)); }
|
||||
const std::vector<Block*>& getPredecessors() const { return predecessors; }
|
||||
const std::vector<Block*>& getSuccessors() const { return successors; }
|
||||
const std::vector<std::unique_ptr<Instruction> >& getInstructions() const {
|
||||
return instructions;
|
||||
}
|
||||
const std::vector<std::unique_ptr<Instruction> >& getLocalVariables() const { return localVariables; }
|
||||
void setUnreachable() { unreachable = true; }
|
||||
bool isUnreachable() const { return unreachable; }
|
||||
// Returns the block's merge instruction, if one exists (otherwise null).
|
||||
const Instruction* getMergeInstruction() const {
|
||||
if (instructions.size() < 2) return nullptr;
|
||||
const Instruction* nextToLast = (instructions.cend() - 2)->get();
|
||||
switch (nextToLast->getOpCode()) {
|
||||
case OpSelectionMerge:
|
||||
case OpLoopMerge:
|
||||
return nextToLast;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Change this block into a canonical dead merge block. Delete instructions
|
||||
// as necessary. A canonical dead merge block has only an OpLabel and an
|
||||
// OpUnreachable.
|
||||
void rewriteAsCanonicalUnreachableMerge() {
|
||||
assert(localVariables.empty());
|
||||
// Delete all instructions except for the label.
|
||||
assert(instructions.size() > 0);
|
||||
instructions.resize(1);
|
||||
successors.clear();
|
||||
addInstruction(std::unique_ptr<Instruction>(new Instruction(OpUnreachable)));
|
||||
}
|
||||
// Change this block into a canonical dead continue target branching to the
|
||||
// given header ID. Delete instructions as necessary. A canonical dead continue
|
||||
// target has only an OpLabel and an unconditional branch back to the corresponding
|
||||
// header.
|
||||
void rewriteAsCanonicalUnreachableContinue(Block* header) {
|
||||
assert(localVariables.empty());
|
||||
// Delete all instructions except for the label.
|
||||
assert(instructions.size() > 0);
|
||||
instructions.resize(1);
|
||||
successors.clear();
|
||||
// Add OpBranch back to the header.
|
||||
assert(header != nullptr);
|
||||
Instruction* branch = new Instruction(OpBranch);
|
||||
branch->addIdOperand(header->getId());
|
||||
addInstruction(std::unique_ptr<Instruction>(branch));
|
||||
successors.push_back(header);
|
||||
}
|
||||
|
||||
bool isTerminated() const
|
||||
{
|
||||
switch (instructions.back()->getOpCode()) {
|
||||
case OpBranch:
|
||||
case OpBranchConditional:
|
||||
case OpSwitch:
|
||||
case OpKill:
|
||||
case OpTerminateInvocation:
|
||||
case OpReturn:
|
||||
case OpReturnValue:
|
||||
case OpUnreachable:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
instructions[0]->dump(out);
|
||||
for (int i = 0; i < (int)localVariables.size(); ++i)
|
||||
localVariables[i]->dump(out);
|
||||
for (int i = 1; i < (int)instructions.size(); ++i)
|
||||
instructions[i]->dump(out);
|
||||
}
|
||||
|
||||
protected:
|
||||
Block(const Block&);
|
||||
Block& operator=(Block&);
|
||||
|
||||
// To enforce keeping parent and ownership in sync:
|
||||
friend Function;
|
||||
|
||||
std::vector<std::unique_ptr<Instruction> > instructions;
|
||||
std::vector<Block*> predecessors, successors;
|
||||
std::vector<std::unique_ptr<Instruction> > localVariables;
|
||||
Function& parent;
|
||||
|
||||
// track whether this block is known to be uncreachable (not necessarily
|
||||
// true for all unreachable blocks, but should be set at least
|
||||
// for the extraneous ones introduced by the builder).
|
||||
bool unreachable;
|
||||
};
|
||||
|
||||
// The different reasons for reaching a block in the inReadableOrder traversal.
|
||||
enum ReachReason {
|
||||
// Reachable from the entry block via transfers of control, i.e. branches.
|
||||
ReachViaControlFlow = 0,
|
||||
// A continue target that is not reachable via control flow.
|
||||
ReachDeadContinue,
|
||||
// A merge block that is not reachable via control flow.
|
||||
ReachDeadMerge
|
||||
};
|
||||
|
||||
// Traverses the control-flow graph rooted at root in an order suited for
|
||||
// readable code generation. Invokes callback at every node in the traversal
|
||||
// order. The callback arguments are:
|
||||
// - the block,
|
||||
// - the reason we reached the block,
|
||||
// - if the reason was that block is an unreachable continue or unreachable merge block
|
||||
// then the last parameter is the corresponding header block.
|
||||
void inReadableOrder(Block* root, std::function<void(Block*, ReachReason, Block* header)> callback);
|
||||
|
||||
//
|
||||
// SPIR-V IR Function.
|
||||
//
|
||||
|
||||
class Function {
|
||||
public:
|
||||
Function(Id id, Id resultType, Id functionType, Id firstParam, Module& parent);
|
||||
virtual ~Function()
|
||||
{
|
||||
for (int i = 0; i < (int)parameterInstructions.size(); ++i)
|
||||
delete parameterInstructions[i];
|
||||
|
||||
for (int i = 0; i < (int)blocks.size(); ++i)
|
||||
delete blocks[i];
|
||||
}
|
||||
Id getId() const { return functionInstruction.getResultId(); }
|
||||
Id getParamId(int p) const { return parameterInstructions[p]->getResultId(); }
|
||||
Id getParamType(int p) const { return parameterInstructions[p]->getTypeId(); }
|
||||
|
||||
void addBlock(Block* block) { blocks.push_back(block); }
|
||||
void removeBlock(Block* block)
|
||||
{
|
||||
auto found = find(blocks.begin(), blocks.end(), block);
|
||||
assert(found != blocks.end());
|
||||
blocks.erase(found);
|
||||
delete block;
|
||||
}
|
||||
|
||||
Module& getParent() const { return parent; }
|
||||
Block* getEntryBlock() const { return blocks.front(); }
|
||||
Block* getLastBlock() const { return blocks.back(); }
|
||||
const std::vector<Block*>& getBlocks() const { return blocks; }
|
||||
void addLocalVariable(std::unique_ptr<Instruction> inst);
|
||||
Id getReturnType() const { return functionInstruction.getTypeId(); }
|
||||
void setReturnPrecision(Decoration precision)
|
||||
{
|
||||
if (precision == DecorationRelaxedPrecision)
|
||||
reducedPrecisionReturn = true;
|
||||
}
|
||||
Decoration getReturnPrecision() const
|
||||
{ return reducedPrecisionReturn ? DecorationRelaxedPrecision : NoPrecision; }
|
||||
|
||||
void setImplicitThis() { implicitThis = true; }
|
||||
bool hasImplicitThis() const { return implicitThis; }
|
||||
|
||||
void addParamPrecision(unsigned param, Decoration precision)
|
||||
{
|
||||
if (precision == DecorationRelaxedPrecision)
|
||||
reducedPrecisionParams.insert(param);
|
||||
}
|
||||
Decoration getParamPrecision(unsigned param) const
|
||||
{
|
||||
return reducedPrecisionParams.find(param) != reducedPrecisionParams.end() ?
|
||||
DecorationRelaxedPrecision : NoPrecision;
|
||||
}
|
||||
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
// OpFunction
|
||||
functionInstruction.dump(out);
|
||||
|
||||
// OpFunctionParameter
|
||||
for (int p = 0; p < (int)parameterInstructions.size(); ++p)
|
||||
parameterInstructions[p]->dump(out);
|
||||
|
||||
// Blocks
|
||||
inReadableOrder(blocks[0], [&out](const Block* b, ReachReason, Block*) { b->dump(out); });
|
||||
Instruction end(0, 0, OpFunctionEnd);
|
||||
end.dump(out);
|
||||
}
|
||||
|
||||
protected:
|
||||
Function(const Function&);
|
||||
Function& operator=(Function&);
|
||||
|
||||
Module& parent;
|
||||
Instruction functionInstruction;
|
||||
std::vector<Instruction*> parameterInstructions;
|
||||
std::vector<Block*> blocks;
|
||||
bool implicitThis; // true if this is a member function expecting to be passed a 'this' as the first argument
|
||||
bool reducedPrecisionReturn;
|
||||
std::set<int> reducedPrecisionParams; // list of parameter indexes that need a relaxed precision arg
|
||||
};
|
||||
|
||||
//
|
||||
// SPIR-V IR Module.
|
||||
//
|
||||
|
||||
class Module {
|
||||
public:
|
||||
Module() {}
|
||||
virtual ~Module()
|
||||
{
|
||||
// TODO delete things
|
||||
}
|
||||
|
||||
void addFunction(Function *fun) { functions.push_back(fun); }
|
||||
|
||||
void mapInstruction(Instruction *instruction)
|
||||
{
|
||||
spv::Id resultId = instruction->getResultId();
|
||||
// map the instruction's result id
|
||||
if (resultId >= idToInstruction.size())
|
||||
idToInstruction.resize(resultId + 16);
|
||||
idToInstruction[resultId] = instruction;
|
||||
}
|
||||
|
||||
Instruction* getInstruction(Id id) const { return idToInstruction[id]; }
|
||||
const std::vector<Function*>& getFunctions() const { return functions; }
|
||||
spv::Id getTypeId(Id resultId) const {
|
||||
return idToInstruction[resultId] == nullptr ? NoType : idToInstruction[resultId]->getTypeId();
|
||||
}
|
||||
StorageClass getStorageClass(Id typeId) const
|
||||
{
|
||||
assert(idToInstruction[typeId]->getOpCode() == spv::OpTypePointer);
|
||||
return (StorageClass)idToInstruction[typeId]->getImmediateOperand(0);
|
||||
}
|
||||
|
||||
void dump(std::vector<unsigned int>& out) const
|
||||
{
|
||||
for (int f = 0; f < (int)functions.size(); ++f)
|
||||
functions[f]->dump(out);
|
||||
}
|
||||
|
||||
protected:
|
||||
Module(const Module&);
|
||||
std::vector<Function*> functions;
|
||||
|
||||
// map from result id to instruction having that result id
|
||||
std::vector<Instruction*> idToInstruction;
|
||||
|
||||
// map from a result id to its type id
|
||||
};
|
||||
|
||||
//
|
||||
// Implementation (it's here due to circular type definitions).
|
||||
//
|
||||
|
||||
// Add both
|
||||
// - the OpFunction instruction
|
||||
// - all the OpFunctionParameter instructions
|
||||
__inline Function::Function(Id id, Id resultType, Id functionType, Id firstParamId, Module& parent)
|
||||
: parent(parent), functionInstruction(id, resultType, OpFunction), implicitThis(false),
|
||||
reducedPrecisionReturn(false)
|
||||
{
|
||||
// OpFunction
|
||||
functionInstruction.addImmediateOperand(FunctionControlMaskNone);
|
||||
functionInstruction.addIdOperand(functionType);
|
||||
parent.mapInstruction(&functionInstruction);
|
||||
parent.addFunction(this);
|
||||
|
||||
// OpFunctionParameter
|
||||
Instruction* typeInst = parent.getInstruction(functionType);
|
||||
int numParams = typeInst->getNumOperands() - 1;
|
||||
for (int p = 0; p < numParams; ++p) {
|
||||
Instruction* param = new Instruction(firstParamId + p, typeInst->getIdOperand(p + 1), OpFunctionParameter);
|
||||
parent.mapInstruction(param);
|
||||
parameterInstructions.push_back(param);
|
||||
}
|
||||
}
|
||||
|
||||
__inline void Function::addLocalVariable(std::unique_ptr<Instruction> inst)
|
||||
{
|
||||
Instruction* raw_instruction = inst.get();
|
||||
blocks[0]->addLocalVariable(std::move(inst));
|
||||
parent.mapInstruction(raw_instruction);
|
||||
}
|
||||
|
||||
__inline Block::Block(Id id, Function& parent) : parent(parent), unreachable(false)
|
||||
{
|
||||
instructions.push_back(std::unique_ptr<Instruction>(new Instruction(id, NoType, OpLabel)));
|
||||
instructions.back()->setBlock(this);
|
||||
parent.getParent().mapInstruction(instructions.back().get());
|
||||
}
|
||||
|
||||
__inline void Block::addInstruction(std::unique_ptr<Instruction> inst)
|
||||
{
|
||||
Instruction* raw_instruction = inst.get();
|
||||
instructions.push_back(std::move(inst));
|
||||
raw_instruction->setBlock(this);
|
||||
if (raw_instruction->getResultId())
|
||||
parent.getParent().mapInstruction(raw_instruction);
|
||||
}
|
||||
|
||||
} // end spv namespace
|
||||
|
||||
#endif // spvIR_H
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
// Copyright 2018 The Shaderc Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SHADERC_ENV_H_
|
||||
#define SHADERC_ENV_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
shaderc_target_env_vulkan, // SPIR-V under Vulkan semantics
|
||||
shaderc_target_env_opengl, // SPIR-V under OpenGL semantics
|
||||
// NOTE: SPIR-V code generation is not supported for shaders under OpenGL
|
||||
// compatibility profile.
|
||||
shaderc_target_env_opengl_compat, // SPIR-V under OpenGL semantics,
|
||||
// including compatibility profile
|
||||
// functions
|
||||
shaderc_target_env_webgpu, // Deprecated, SPIR-V under WebGPU
|
||||
// semantics
|
||||
shaderc_target_env_default = shaderc_target_env_vulkan
|
||||
} shaderc_target_env;
|
||||
|
||||
typedef enum {
|
||||
// For Vulkan, use Vulkan's mapping of version numbers to integers.
|
||||
// See vulkan.h
|
||||
shaderc_env_version_vulkan_1_0 = ((1u << 22)),
|
||||
shaderc_env_version_vulkan_1_1 = ((1u << 22) | (1 << 12)),
|
||||
shaderc_env_version_vulkan_1_2 = ((1u << 22) | (2 << 12)),
|
||||
// For OpenGL, use the number from #version in shaders.
|
||||
// TODO(dneto): Currently no difference between OpenGL 4.5 and 4.6.
|
||||
// See glslang/Standalone/Standalone.cpp
|
||||
// TODO(dneto): Glslang doesn't accept a OpenGL client version of 460.
|
||||
shaderc_env_version_opengl_4_5 = 450,
|
||||
shaderc_env_version_webgpu, // Deprecated, WebGPU env never defined versions
|
||||
} shaderc_env_version;
|
||||
|
||||
// The known versions of SPIR-V.
|
||||
typedef enum {
|
||||
// Use the values used for word 1 of a SPIR-V binary:
|
||||
// - bits 24 to 31: zero
|
||||
// - bits 16 to 23: major version number
|
||||
// - bits 8 to 15: minor version number
|
||||
// - bits 0 to 7: zero
|
||||
shaderc_spirv_version_1_0 = 0x010000u,
|
||||
shaderc_spirv_version_1_1 = 0x010100u,
|
||||
shaderc_spirv_version_1_2 = 0x010200u,
|
||||
shaderc_spirv_version_1_3 = 0x010300u,
|
||||
shaderc_spirv_version_1_4 = 0x010400u,
|
||||
shaderc_spirv_version_1_5 = 0x010500u
|
||||
} shaderc_spirv_version;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // SHADERC_ENV_H_
|
||||
+580
@@ -0,0 +1,580 @@
|
||||
// Copyright 2015 The Shaderc Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SHADERC_SHADERC_H_
|
||||
#define SHADERC_SHADERC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "shaderc/env.h"
|
||||
#include "shaderc/status.h"
|
||||
#include "shaderc/visibility.h"
|
||||
|
||||
// Source language kind.
|
||||
typedef enum {
|
||||
shaderc_source_language_glsl,
|
||||
shaderc_source_language_hlsl,
|
||||
} shaderc_source_language;
|
||||
|
||||
typedef enum {
|
||||
// Forced shader kinds. These shader kinds force the compiler to compile the
|
||||
// source code as the specified kind of shader.
|
||||
shaderc_vertex_shader,
|
||||
shaderc_fragment_shader,
|
||||
shaderc_compute_shader,
|
||||
shaderc_geometry_shader,
|
||||
shaderc_tess_control_shader,
|
||||
shaderc_tess_evaluation_shader,
|
||||
|
||||
shaderc_glsl_vertex_shader = shaderc_vertex_shader,
|
||||
shaderc_glsl_fragment_shader = shaderc_fragment_shader,
|
||||
shaderc_glsl_compute_shader = shaderc_compute_shader,
|
||||
shaderc_glsl_geometry_shader = shaderc_geometry_shader,
|
||||
shaderc_glsl_tess_control_shader = shaderc_tess_control_shader,
|
||||
shaderc_glsl_tess_evaluation_shader = shaderc_tess_evaluation_shader,
|
||||
|
||||
// Deduce the shader kind from #pragma annotation in the source code. Compiler
|
||||
// will emit error if #pragma annotation is not found.
|
||||
shaderc_glsl_infer_from_source,
|
||||
// Default shader kinds. Compiler will fall back to compile the source code as
|
||||
// the specified kind of shader when #pragma annotation is not found in the
|
||||
// source code.
|
||||
shaderc_glsl_default_vertex_shader,
|
||||
shaderc_glsl_default_fragment_shader,
|
||||
shaderc_glsl_default_compute_shader,
|
||||
shaderc_glsl_default_geometry_shader,
|
||||
shaderc_glsl_default_tess_control_shader,
|
||||
shaderc_glsl_default_tess_evaluation_shader,
|
||||
shaderc_spirv_assembly,
|
||||
shaderc_raygen_shader,
|
||||
shaderc_anyhit_shader,
|
||||
shaderc_closesthit_shader,
|
||||
shaderc_miss_shader,
|
||||
shaderc_intersection_shader,
|
||||
shaderc_callable_shader,
|
||||
shaderc_glsl_raygen_shader = shaderc_raygen_shader,
|
||||
shaderc_glsl_anyhit_shader = shaderc_anyhit_shader,
|
||||
shaderc_glsl_closesthit_shader = shaderc_closesthit_shader,
|
||||
shaderc_glsl_miss_shader = shaderc_miss_shader,
|
||||
shaderc_glsl_intersection_shader = shaderc_intersection_shader,
|
||||
shaderc_glsl_callable_shader = shaderc_callable_shader,
|
||||
shaderc_glsl_default_raygen_shader,
|
||||
shaderc_glsl_default_anyhit_shader,
|
||||
shaderc_glsl_default_closesthit_shader,
|
||||
shaderc_glsl_default_miss_shader,
|
||||
shaderc_glsl_default_intersection_shader,
|
||||
shaderc_glsl_default_callable_shader,
|
||||
shaderc_task_shader,
|
||||
shaderc_mesh_shader,
|
||||
shaderc_glsl_task_shader = shaderc_task_shader,
|
||||
shaderc_glsl_mesh_shader = shaderc_mesh_shader,
|
||||
shaderc_glsl_default_task_shader,
|
||||
shaderc_glsl_default_mesh_shader,
|
||||
} shaderc_shader_kind;
|
||||
|
||||
typedef enum {
|
||||
shaderc_profile_none, // Used if and only if GLSL version did not specify
|
||||
// profiles.
|
||||
shaderc_profile_core,
|
||||
shaderc_profile_compatibility,
|
||||
shaderc_profile_es,
|
||||
} shaderc_profile;
|
||||
|
||||
// Optimization level.
|
||||
typedef enum {
|
||||
shaderc_optimization_level_zero, // no optimization
|
||||
shaderc_optimization_level_size, // optimize towards reducing code size
|
||||
shaderc_optimization_level_performance, // optimize towards performance
|
||||
} shaderc_optimization_level;
|
||||
|
||||
// Resource limits.
|
||||
typedef enum {
|
||||
shaderc_limit_max_lights,
|
||||
shaderc_limit_max_clip_planes,
|
||||
shaderc_limit_max_texture_units,
|
||||
shaderc_limit_max_texture_coords,
|
||||
shaderc_limit_max_vertex_attribs,
|
||||
shaderc_limit_max_vertex_uniform_components,
|
||||
shaderc_limit_max_varying_floats,
|
||||
shaderc_limit_max_vertex_texture_image_units,
|
||||
shaderc_limit_max_combined_texture_image_units,
|
||||
shaderc_limit_max_texture_image_units,
|
||||
shaderc_limit_max_fragment_uniform_components,
|
||||
shaderc_limit_max_draw_buffers,
|
||||
shaderc_limit_max_vertex_uniform_vectors,
|
||||
shaderc_limit_max_varying_vectors,
|
||||
shaderc_limit_max_fragment_uniform_vectors,
|
||||
shaderc_limit_max_vertex_output_vectors,
|
||||
shaderc_limit_max_fragment_input_vectors,
|
||||
shaderc_limit_min_program_texel_offset,
|
||||
shaderc_limit_max_program_texel_offset,
|
||||
shaderc_limit_max_clip_distances,
|
||||
shaderc_limit_max_compute_work_group_count_x,
|
||||
shaderc_limit_max_compute_work_group_count_y,
|
||||
shaderc_limit_max_compute_work_group_count_z,
|
||||
shaderc_limit_max_compute_work_group_size_x,
|
||||
shaderc_limit_max_compute_work_group_size_y,
|
||||
shaderc_limit_max_compute_work_group_size_z,
|
||||
shaderc_limit_max_compute_uniform_components,
|
||||
shaderc_limit_max_compute_texture_image_units,
|
||||
shaderc_limit_max_compute_image_uniforms,
|
||||
shaderc_limit_max_compute_atomic_counters,
|
||||
shaderc_limit_max_compute_atomic_counter_buffers,
|
||||
shaderc_limit_max_varying_components,
|
||||
shaderc_limit_max_vertex_output_components,
|
||||
shaderc_limit_max_geometry_input_components,
|
||||
shaderc_limit_max_geometry_output_components,
|
||||
shaderc_limit_max_fragment_input_components,
|
||||
shaderc_limit_max_image_units,
|
||||
shaderc_limit_max_combined_image_units_and_fragment_outputs,
|
||||
shaderc_limit_max_combined_shader_output_resources,
|
||||
shaderc_limit_max_image_samples,
|
||||
shaderc_limit_max_vertex_image_uniforms,
|
||||
shaderc_limit_max_tess_control_image_uniforms,
|
||||
shaderc_limit_max_tess_evaluation_image_uniforms,
|
||||
shaderc_limit_max_geometry_image_uniforms,
|
||||
shaderc_limit_max_fragment_image_uniforms,
|
||||
shaderc_limit_max_combined_image_uniforms,
|
||||
shaderc_limit_max_geometry_texture_image_units,
|
||||
shaderc_limit_max_geometry_output_vertices,
|
||||
shaderc_limit_max_geometry_total_output_components,
|
||||
shaderc_limit_max_geometry_uniform_components,
|
||||
shaderc_limit_max_geometry_varying_components,
|
||||
shaderc_limit_max_tess_control_input_components,
|
||||
shaderc_limit_max_tess_control_output_components,
|
||||
shaderc_limit_max_tess_control_texture_image_units,
|
||||
shaderc_limit_max_tess_control_uniform_components,
|
||||
shaderc_limit_max_tess_control_total_output_components,
|
||||
shaderc_limit_max_tess_evaluation_input_components,
|
||||
shaderc_limit_max_tess_evaluation_output_components,
|
||||
shaderc_limit_max_tess_evaluation_texture_image_units,
|
||||
shaderc_limit_max_tess_evaluation_uniform_components,
|
||||
shaderc_limit_max_tess_patch_components,
|
||||
shaderc_limit_max_patch_vertices,
|
||||
shaderc_limit_max_tess_gen_level,
|
||||
shaderc_limit_max_viewports,
|
||||
shaderc_limit_max_vertex_atomic_counters,
|
||||
shaderc_limit_max_tess_control_atomic_counters,
|
||||
shaderc_limit_max_tess_evaluation_atomic_counters,
|
||||
shaderc_limit_max_geometry_atomic_counters,
|
||||
shaderc_limit_max_fragment_atomic_counters,
|
||||
shaderc_limit_max_combined_atomic_counters,
|
||||
shaderc_limit_max_atomic_counter_bindings,
|
||||
shaderc_limit_max_vertex_atomic_counter_buffers,
|
||||
shaderc_limit_max_tess_control_atomic_counter_buffers,
|
||||
shaderc_limit_max_tess_evaluation_atomic_counter_buffers,
|
||||
shaderc_limit_max_geometry_atomic_counter_buffers,
|
||||
shaderc_limit_max_fragment_atomic_counter_buffers,
|
||||
shaderc_limit_max_combined_atomic_counter_buffers,
|
||||
shaderc_limit_max_atomic_counter_buffer_size,
|
||||
shaderc_limit_max_transform_feedback_buffers,
|
||||
shaderc_limit_max_transform_feedback_interleaved_components,
|
||||
shaderc_limit_max_cull_distances,
|
||||
shaderc_limit_max_combined_clip_and_cull_distances,
|
||||
shaderc_limit_max_samples,
|
||||
} shaderc_limit;
|
||||
|
||||
// Uniform resource kinds.
|
||||
// In Vulkan, uniform resources are bound to the pipeline via descriptors
|
||||
// with numbered bindings and sets.
|
||||
typedef enum {
|
||||
// Image and image buffer.
|
||||
shaderc_uniform_kind_image,
|
||||
// Pure sampler.
|
||||
shaderc_uniform_kind_sampler,
|
||||
// Sampled texture in GLSL, and Shader Resource View in HLSL.
|
||||
shaderc_uniform_kind_texture,
|
||||
// Uniform Buffer Object (UBO) in GLSL. Cbuffer in HLSL.
|
||||
shaderc_uniform_kind_buffer,
|
||||
// Shader Storage Buffer Object (SSBO) in GLSL.
|
||||
shaderc_uniform_kind_storage_buffer,
|
||||
// Unordered Access View, in HLSL. (Writable storage image or storage
|
||||
// buffer.)
|
||||
shaderc_uniform_kind_unordered_access_view,
|
||||
} shaderc_uniform_kind;
|
||||
|
||||
// Usage examples:
|
||||
//
|
||||
// Aggressively release compiler resources, but spend time in initialization
|
||||
// for each new use.
|
||||
// shaderc_compiler_t compiler = shaderc_compiler_initialize();
|
||||
// shaderc_compilation_result_t result = shaderc_compile_into_spv(
|
||||
// compiler, "#version 450\nvoid main() {}", 27,
|
||||
// shaderc_glsl_vertex_shader, "main.vert", "main", nullptr);
|
||||
// // Do stuff with compilation results.
|
||||
// shaderc_result_release(result);
|
||||
// shaderc_compiler_release(compiler);
|
||||
//
|
||||
// Keep the compiler object around for a long time, but pay for extra space
|
||||
// occupied.
|
||||
// shaderc_compiler_t compiler = shaderc_compiler_initialize();
|
||||
// // On the same, other or multiple simultaneous threads.
|
||||
// shaderc_compilation_result_t result = shaderc_compile_into_spv(
|
||||
// compiler, "#version 450\nvoid main() {}", 27,
|
||||
// shaderc_glsl_vertex_shader, "main.vert", "main", nullptr);
|
||||
// // Do stuff with compilation results.
|
||||
// shaderc_result_release(result);
|
||||
// // Once no more compilations are to happen.
|
||||
// shaderc_compiler_release(compiler);
|
||||
|
||||
// An opaque handle to an object that manages all compiler state.
|
||||
typedef struct shaderc_compiler* shaderc_compiler_t;
|
||||
|
||||
// Returns a shaderc_compiler_t that can be used to compile modules.
|
||||
// A return of NULL indicates that there was an error initializing the compiler.
|
||||
// Any function operating on shaderc_compiler_t must offer the basic
|
||||
// thread-safety guarantee.
|
||||
// [http://herbsutter.com/2014/01/13/gotw-95-solution-thread-safety-and-synchronization/]
|
||||
// That is: concurrent invocation of these functions on DIFFERENT objects needs
|
||||
// no synchronization; concurrent invocation of these functions on the SAME
|
||||
// object requires synchronization IF AND ONLY IF some of them take a non-const
|
||||
// argument.
|
||||
SHADERC_EXPORT shaderc_compiler_t shaderc_compiler_initialize(void);
|
||||
|
||||
// Releases the resources held by the shaderc_compiler_t.
|
||||
// After this call it is invalid to make any future calls to functions
|
||||
// involving this shaderc_compiler_t.
|
||||
SHADERC_EXPORT void shaderc_compiler_release(shaderc_compiler_t);
|
||||
|
||||
// An opaque handle to an object that manages options to a single compilation
|
||||
// result.
|
||||
typedef struct shaderc_compile_options* shaderc_compile_options_t;
|
||||
|
||||
// Returns a default-initialized shaderc_compile_options_t that can be used
|
||||
// to modify the functionality of a compiled module.
|
||||
// A return of NULL indicates that there was an error initializing the options.
|
||||
// Any function operating on shaderc_compile_options_t must offer the
|
||||
// basic thread-safety guarantee.
|
||||
SHADERC_EXPORT shaderc_compile_options_t
|
||||
shaderc_compile_options_initialize(void);
|
||||
|
||||
// Returns a copy of the given shaderc_compile_options_t.
|
||||
// If NULL is passed as the parameter the call is the same as
|
||||
// shaderc_compile_options_init.
|
||||
SHADERC_EXPORT shaderc_compile_options_t shaderc_compile_options_clone(
|
||||
const shaderc_compile_options_t options);
|
||||
|
||||
// Releases the compilation options. It is invalid to use the given
|
||||
// shaderc_compile_options_t object in any future calls. It is safe to pass
|
||||
// NULL to this function, and doing such will have no effect.
|
||||
SHADERC_EXPORT void shaderc_compile_options_release(
|
||||
shaderc_compile_options_t options);
|
||||
|
||||
// Adds a predefined macro to the compilation options. This has the same
|
||||
// effect as passing -Dname=value to the command-line compiler. If value
|
||||
// is NULL, it has the same effect as passing -Dname to the command-line
|
||||
// compiler. If a macro definition with the same name has previously been
|
||||
// added, the value is replaced with the new value. The macro name and
|
||||
// value are passed in with char pointers, which point to their data, and
|
||||
// the lengths of their data. The strings that the name and value pointers
|
||||
// point to must remain valid for the duration of the call, but can be
|
||||
// modified or deleted after this function has returned. In case of adding
|
||||
// a valueless macro, the value argument should be a null pointer or the
|
||||
// value_length should be 0u.
|
||||
SHADERC_EXPORT void shaderc_compile_options_add_macro_definition(
|
||||
shaderc_compile_options_t options, const char* name, size_t name_length,
|
||||
const char* value, size_t value_length);
|
||||
|
||||
// Sets the source language. The default is GLSL.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_source_language(
|
||||
shaderc_compile_options_t options, shaderc_source_language lang);
|
||||
|
||||
// Sets the compiler mode to generate debug information in the output.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_generate_debug_info(
|
||||
shaderc_compile_options_t options);
|
||||
|
||||
// Sets the compiler optimization level to the given level. Only the last one
|
||||
// takes effect if multiple calls of this function exist.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_optimization_level(
|
||||
shaderc_compile_options_t options, shaderc_optimization_level level);
|
||||
|
||||
// Forces the GLSL language version and profile to a given pair. The version
|
||||
// number is the same as would appear in the #version annotation in the source.
|
||||
// Version and profile specified here overrides the #version annotation in the
|
||||
// source. Use profile: 'shaderc_profile_none' for GLSL versions that do not
|
||||
// define profiles, e.g. versions below 150.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_forced_version_profile(
|
||||
shaderc_compile_options_t options, int version, shaderc_profile profile);
|
||||
|
||||
// Source text inclusion via #include is supported with a pair of callbacks
|
||||
// to an "includer" on the client side. The first callback processes an
|
||||
// inclusion request, and returns an include result. The includer owns
|
||||
// the contents of the result, and those contents must remain valid until the
|
||||
// second callback is invoked to release the result. Both callbacks take a
|
||||
// user_data argument to specify the client context.
|
||||
// To return an error, set the source_name to an empty string and put your
|
||||
// error message in content.
|
||||
|
||||
// An include result.
|
||||
typedef struct shaderc_include_result {
|
||||
// The name of the source file. The name should be fully resolved
|
||||
// in the sense that it should be a unique name in the context of the
|
||||
// includer. For example, if the includer maps source names to files in
|
||||
// a filesystem, then this name should be the absolute path of the file.
|
||||
// For a failed inclusion, this string is empty.
|
||||
const char* source_name;
|
||||
size_t source_name_length;
|
||||
// The text contents of the source file in the normal case.
|
||||
// For a failed inclusion, this contains the error message.
|
||||
const char* content;
|
||||
size_t content_length;
|
||||
// User data to be passed along with this request.
|
||||
void* user_data;
|
||||
} shaderc_include_result;
|
||||
|
||||
// The kinds of include requests.
|
||||
enum shaderc_include_type {
|
||||
shaderc_include_type_relative, // E.g. #include "source"
|
||||
shaderc_include_type_standard // E.g. #include <source>
|
||||
};
|
||||
|
||||
// An includer callback type for mapping an #include request to an include
|
||||
// result. The user_data parameter specifies the client context. The
|
||||
// requested_source parameter specifies the name of the source being requested.
|
||||
// The type parameter specifies the kind of inclusion request being made.
|
||||
// The requesting_source parameter specifies the name of the source containing
|
||||
// the #include request. The includer owns the result object and its contents,
|
||||
// and both must remain valid until the release callback is called on the result
|
||||
// object.
|
||||
typedef shaderc_include_result* (*shaderc_include_resolve_fn)(
|
||||
void* user_data, const char* requested_source, int type,
|
||||
const char* requesting_source, size_t include_depth);
|
||||
|
||||
// An includer callback type for destroying an include result.
|
||||
typedef void (*shaderc_include_result_release_fn)(
|
||||
void* user_data, shaderc_include_result* include_result);
|
||||
|
||||
// Sets includer callback functions.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_include_callbacks(
|
||||
shaderc_compile_options_t options, shaderc_include_resolve_fn resolver,
|
||||
shaderc_include_result_release_fn result_releaser, void* user_data);
|
||||
|
||||
// Sets the compiler mode to suppress warnings, overriding warnings-as-errors
|
||||
// mode. When both suppress-warnings and warnings-as-errors modes are
|
||||
// turned on, warning messages will be inhibited, and will not be emitted
|
||||
// as error messages.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_suppress_warnings(
|
||||
shaderc_compile_options_t options);
|
||||
|
||||
// Sets the target shader environment, affecting which warnings or errors will
|
||||
// be issued. The version will be for distinguishing between different versions
|
||||
// of the target environment. The version value should be either 0 or
|
||||
// a value listed in shaderc_env_version. The 0 value maps to Vulkan 1.0 if
|
||||
// |target| is Vulkan, and it maps to OpenGL 4.5 if |target| is OpenGL.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_target_env(
|
||||
shaderc_compile_options_t options,
|
||||
shaderc_target_env target,
|
||||
uint32_t version);
|
||||
|
||||
// Sets the target SPIR-V version. The generated module will use this version
|
||||
// of SPIR-V. Each target environment determines what versions of SPIR-V
|
||||
// it can consume. Defaults to the highest version of SPIR-V 1.0 which is
|
||||
// required to be supported by the target environment. E.g. Default to SPIR-V
|
||||
// 1.0 for Vulkan 1.0 and SPIR-V 1.3 for Vulkan 1.1.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_target_spirv(
|
||||
shaderc_compile_options_t options, shaderc_spirv_version version);
|
||||
|
||||
// Sets the compiler mode to treat all warnings as errors. Note the
|
||||
// suppress-warnings mode overrides this option, i.e. if both
|
||||
// warning-as-errors and suppress-warnings modes are set, warnings will not
|
||||
// be emitted as error messages.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_warnings_as_errors(
|
||||
shaderc_compile_options_t options);
|
||||
|
||||
// Sets a resource limit.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_limit(
|
||||
shaderc_compile_options_t options, shaderc_limit limit, int value);
|
||||
|
||||
// Sets whether the compiler should automatically assign bindings to uniforms
|
||||
// that aren't already explicitly bound in the shader source.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_auto_bind_uniforms(
|
||||
shaderc_compile_options_t options, bool auto_bind);
|
||||
|
||||
// Sets whether the compiler should use HLSL IO mapping rules for bindings.
|
||||
// Defaults to false.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_io_mapping(
|
||||
shaderc_compile_options_t options, bool hlsl_iomap);
|
||||
|
||||
// Sets whether the compiler should determine block member offsets using HLSL
|
||||
// packing rules instead of standard GLSL rules. Defaults to false. Only
|
||||
// affects GLSL compilation. HLSL rules are always used when compiling HLSL.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_offsets(
|
||||
shaderc_compile_options_t options, bool hlsl_offsets);
|
||||
|
||||
// Sets the base binding number used for for a uniform resource type when
|
||||
// automatically assigning bindings. For GLSL compilation, sets the lowest
|
||||
// automatically assigned number. For HLSL compilation, the regsiter number
|
||||
// assigned to the resource is added to this specified base.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_binding_base(
|
||||
shaderc_compile_options_t options,
|
||||
shaderc_uniform_kind kind,
|
||||
uint32_t base);
|
||||
|
||||
// Like shaderc_compile_options_set_binding_base, but only takes effect when
|
||||
// compiling a given shader stage. The stage is assumed to be one of vertex,
|
||||
// fragment, tessellation evaluation, tesselation control, geometry, or compute.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_binding_base_for_stage(
|
||||
shaderc_compile_options_t options, shaderc_shader_kind shader_kind,
|
||||
shaderc_uniform_kind kind, uint32_t base);
|
||||
|
||||
// Sets whether the compiler should automatically assign locations to
|
||||
// uniform variables that don't have explicit locations in the shader source.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_auto_map_locations(
|
||||
shaderc_compile_options_t options, bool auto_map);
|
||||
|
||||
// Sets a descriptor set and binding for an HLSL register in the given stage.
|
||||
// This method keeps a copy of the string data.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
|
||||
shaderc_compile_options_t options, shaderc_shader_kind shader_kind,
|
||||
const char* reg, const char* set, const char* binding);
|
||||
|
||||
// Like shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage,
|
||||
// but affects all shader stages.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_register_set_and_binding(
|
||||
shaderc_compile_options_t options, const char* reg, const char* set,
|
||||
const char* binding);
|
||||
|
||||
// Sets whether the compiler should enable extension
|
||||
// SPV_GOOGLE_hlsl_functionality1.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_hlsl_functionality1(
|
||||
shaderc_compile_options_t options, bool enable);
|
||||
|
||||
// Sets whether the compiler should invert position.Y output in vertex shader.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_invert_y(
|
||||
shaderc_compile_options_t options, bool enable);
|
||||
|
||||
// Sets whether the compiler generates code for max and min builtins which,
|
||||
// if given a NaN operand, will return the other operand. Similarly, the clamp
|
||||
// builtin will favour the non-NaN operands, as if clamp were implemented
|
||||
// as a composition of max and min.
|
||||
SHADERC_EXPORT void shaderc_compile_options_set_nan_clamp(
|
||||
shaderc_compile_options_t options, bool enable);
|
||||
|
||||
// An opaque handle to the results of a call to any shaderc_compile_into_*()
|
||||
// function.
|
||||
typedef struct shaderc_compilation_result* shaderc_compilation_result_t;
|
||||
|
||||
// Takes a GLSL source string and the associated shader kind, input file
|
||||
// name, compiles it according to the given additional_options. If the shader
|
||||
// kind is not set to a specified kind, but shaderc_glslc_infer_from_source,
|
||||
// the compiler will try to deduce the shader kind from the source
|
||||
// string and a failure in deducing will generate an error. Currently only
|
||||
// #pragma annotation is supported. If the shader kind is set to one of the
|
||||
// default shader kinds, the compiler will fall back to the default shader
|
||||
// kind in case it failed to deduce the shader kind from source string.
|
||||
// The input_file_name is a null-termintated string. It is used as a tag to
|
||||
// identify the source string in cases like emitting error messages. It
|
||||
// doesn't have to be a 'file name'.
|
||||
// The source string will be compiled into SPIR-V binary and a
|
||||
// shaderc_compilation_result will be returned to hold the results.
|
||||
// The entry_point_name null-terminated string defines the name of the entry
|
||||
// point to associate with this GLSL source. If the additional_options
|
||||
// parameter is not null, then the compilation is modified by any options
|
||||
// present. May be safely called from multiple threads without explicit
|
||||
// synchronization. If there was failure in allocating the compiler object,
|
||||
// null will be returned.
|
||||
SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_spv(
|
||||
const shaderc_compiler_t compiler, const char* source_text,
|
||||
size_t source_text_size, shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name, const char* entry_point_name,
|
||||
const shaderc_compile_options_t additional_options);
|
||||
|
||||
// Like shaderc_compile_into_spv, but the result contains SPIR-V assembly text
|
||||
// instead of a SPIR-V binary module. The SPIR-V assembly syntax is as defined
|
||||
// by the SPIRV-Tools open source project.
|
||||
SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_spv_assembly(
|
||||
const shaderc_compiler_t compiler, const char* source_text,
|
||||
size_t source_text_size, shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name, const char* entry_point_name,
|
||||
const shaderc_compile_options_t additional_options);
|
||||
|
||||
// Like shaderc_compile_into_spv, but the result contains preprocessed source
|
||||
// code instead of a SPIR-V binary module
|
||||
SHADERC_EXPORT shaderc_compilation_result_t shaderc_compile_into_preprocessed_text(
|
||||
const shaderc_compiler_t compiler, const char* source_text,
|
||||
size_t source_text_size, shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name, const char* entry_point_name,
|
||||
const shaderc_compile_options_t additional_options);
|
||||
|
||||
// Takes an assembly string of the format defined in the SPIRV-Tools project
|
||||
// (https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md),
|
||||
// assembles it into SPIR-V binary and a shaderc_compilation_result will be
|
||||
// returned to hold the results.
|
||||
// The assembling will pick options suitable for assembling specified in the
|
||||
// additional_options parameter.
|
||||
// May be safely called from multiple threads without explicit synchronization.
|
||||
// If there was failure in allocating the compiler object, null will be
|
||||
// returned.
|
||||
SHADERC_EXPORT shaderc_compilation_result_t shaderc_assemble_into_spv(
|
||||
const shaderc_compiler_t compiler, const char* source_assembly,
|
||||
size_t source_assembly_size,
|
||||
const shaderc_compile_options_t additional_options);
|
||||
|
||||
// The following functions, operating on shaderc_compilation_result_t objects,
|
||||
// offer only the basic thread-safety guarantee.
|
||||
|
||||
// Releases the resources held by the result object. It is invalid to use the
|
||||
// result object for any further operations.
|
||||
SHADERC_EXPORT void shaderc_result_release(shaderc_compilation_result_t result);
|
||||
|
||||
// Returns the number of bytes of the compilation output data in a result
|
||||
// object.
|
||||
SHADERC_EXPORT size_t shaderc_result_get_length(const shaderc_compilation_result_t result);
|
||||
|
||||
// Returns the number of warnings generated during the compilation.
|
||||
SHADERC_EXPORT size_t shaderc_result_get_num_warnings(
|
||||
const shaderc_compilation_result_t result);
|
||||
|
||||
// Returns the number of errors generated during the compilation.
|
||||
SHADERC_EXPORT size_t shaderc_result_get_num_errors(const shaderc_compilation_result_t result);
|
||||
|
||||
// Returns the compilation status, indicating whether the compilation succeeded,
|
||||
// or failed due to some reasons, like invalid shader stage or compilation
|
||||
// errors.
|
||||
SHADERC_EXPORT shaderc_compilation_status shaderc_result_get_compilation_status(
|
||||
const shaderc_compilation_result_t);
|
||||
|
||||
// Returns a pointer to the start of the compilation output data bytes, either
|
||||
// SPIR-V binary or char string. When the source string is compiled into SPIR-V
|
||||
// binary, this is guaranteed to be castable to a uint32_t*. If the result
|
||||
// contains assembly text or preprocessed source text, the pointer will point to
|
||||
// the resulting array of characters.
|
||||
SHADERC_EXPORT const char* shaderc_result_get_bytes(const shaderc_compilation_result_t result);
|
||||
|
||||
// Returns a null-terminated string that contains any error messages generated
|
||||
// during the compilation.
|
||||
SHADERC_EXPORT const char* shaderc_result_get_error_message(
|
||||
const shaderc_compilation_result_t result);
|
||||
|
||||
// Provides the version & revision of the SPIR-V which will be produced
|
||||
SHADERC_EXPORT void shaderc_get_spv_version(unsigned int* version, unsigned int* revision);
|
||||
|
||||
// Parses the version and profile from a given null-terminated string
|
||||
// containing both version and profile, like: '450core'. Returns false if
|
||||
// the string can not be parsed. Returns true when the parsing succeeds. The
|
||||
// parsed version and profile are returned through arguments.
|
||||
SHADERC_EXPORT bool shaderc_parse_version_profile(const char* str, int* version,
|
||||
shaderc_profile* profile);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // SHADERC_SHADERC_H_
|
||||
+595
@@ -0,0 +1,595 @@
|
||||
// Copyright 2015 The Shaderc Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SHADERC_SHADERC_HPP_
|
||||
#define SHADERC_SHADERC_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "shaderc.h"
|
||||
|
||||
namespace shaderc {
|
||||
// A CompilationResult contains the compiler output, compilation status,
|
||||
// and messages.
|
||||
//
|
||||
// The compiler output is stored as an array of elements and accessed
|
||||
// via random access iterators provided by cbegin() and cend(). The iterators
|
||||
// are contiguous in the sense of "Contiguous Iterators: A Refinement of
|
||||
// Random Access Iterators", Nevin Liber, C++ Library Evolution Working
|
||||
// Group Working Paper N3884.
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3884.pdf
|
||||
//
|
||||
// Methods begin() and end() are also provided to enable range-based for.
|
||||
// They are synonyms to cbegin() and cend(), respectively.
|
||||
template <typename OutputElementType>
|
||||
class CompilationResult {
|
||||
public:
|
||||
typedef OutputElementType element_type;
|
||||
// The type used to describe the begin and end iterators on the
|
||||
// compiler output.
|
||||
typedef const OutputElementType* const_iterator;
|
||||
|
||||
// Upon creation, the CompilationResult takes ownership of the
|
||||
// shaderc_compilation_result instance. During destruction of the
|
||||
// CompilationResult, the shaderc_compilation_result will be released.
|
||||
explicit CompilationResult(shaderc_compilation_result_t compilation_result)
|
||||
: compilation_result_(compilation_result) {}
|
||||
CompilationResult() : compilation_result_(nullptr) {}
|
||||
~CompilationResult() { shaderc_result_release(compilation_result_); }
|
||||
|
||||
CompilationResult(CompilationResult&& other) : compilation_result_(nullptr) {
|
||||
*this = std::move(other);
|
||||
}
|
||||
|
||||
CompilationResult& operator=(CompilationResult&& other) {
|
||||
if (compilation_result_) {
|
||||
shaderc_result_release(compilation_result_);
|
||||
}
|
||||
compilation_result_ = other.compilation_result_;
|
||||
other.compilation_result_ = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Returns any error message found during compilation.
|
||||
std::string GetErrorMessage() const {
|
||||
if (!compilation_result_) {
|
||||
return "";
|
||||
}
|
||||
return shaderc_result_get_error_message(compilation_result_);
|
||||
}
|
||||
|
||||
// Returns the compilation status, indicating whether the compilation
|
||||
// succeeded, or failed due to some reasons, like invalid shader stage or
|
||||
// compilation errors.
|
||||
shaderc_compilation_status GetCompilationStatus() const {
|
||||
if (!compilation_result_) {
|
||||
return shaderc_compilation_status_null_result_object;
|
||||
}
|
||||
return shaderc_result_get_compilation_status(compilation_result_);
|
||||
}
|
||||
|
||||
// Returns a random access (contiguous) iterator pointing to the start
|
||||
// of the compilation output. It is valid for the lifetime of this object.
|
||||
// If there is no compilation result, then returns nullptr.
|
||||
const_iterator cbegin() const {
|
||||
if (!compilation_result_) return nullptr;
|
||||
return reinterpret_cast<const_iterator>(
|
||||
shaderc_result_get_bytes(compilation_result_));
|
||||
}
|
||||
|
||||
// Returns a random access (contiguous) iterator pointing to the end of
|
||||
// the compilation output. It is valid for the lifetime of this object.
|
||||
// If there is no compilation result, then returns nullptr.
|
||||
const_iterator cend() const {
|
||||
if (!compilation_result_) return nullptr;
|
||||
return cbegin() +
|
||||
shaderc_result_get_length(compilation_result_) /
|
||||
sizeof(OutputElementType);
|
||||
}
|
||||
|
||||
// Returns the same iterator as cbegin().
|
||||
const_iterator begin() const { return cbegin(); }
|
||||
// Returns the same iterator as cend().
|
||||
const_iterator end() const { return cend(); }
|
||||
|
||||
// Returns the number of warnings generated during the compilation.
|
||||
size_t GetNumWarnings() const {
|
||||
if (!compilation_result_) {
|
||||
return 0;
|
||||
}
|
||||
return shaderc_result_get_num_warnings(compilation_result_);
|
||||
}
|
||||
|
||||
// Returns the number of errors generated during the compilation.
|
||||
size_t GetNumErrors() const {
|
||||
if (!compilation_result_) {
|
||||
return 0;
|
||||
}
|
||||
return shaderc_result_get_num_errors(compilation_result_);
|
||||
}
|
||||
|
||||
private:
|
||||
CompilationResult(const CompilationResult& other) = delete;
|
||||
CompilationResult& operator=(const CompilationResult& other) = delete;
|
||||
|
||||
shaderc_compilation_result_t compilation_result_;
|
||||
};
|
||||
|
||||
// A compilation result for a SPIR-V binary module, which is an array
|
||||
// of uint32_t words.
|
||||
using SpvCompilationResult = CompilationResult<uint32_t>;
|
||||
// A compilation result in SPIR-V assembly syntax.
|
||||
using AssemblyCompilationResult = CompilationResult<char>;
|
||||
// Preprocessed source text.
|
||||
using PreprocessedSourceCompilationResult = CompilationResult<char>;
|
||||
|
||||
// Contains any options that can have default values for a compilation.
|
||||
class CompileOptions {
|
||||
public:
|
||||
CompileOptions() { options_ = shaderc_compile_options_initialize(); }
|
||||
~CompileOptions() { shaderc_compile_options_release(options_); }
|
||||
CompileOptions(const CompileOptions& other) {
|
||||
options_ = shaderc_compile_options_clone(other.options_);
|
||||
}
|
||||
CompileOptions(CompileOptions&& other) {
|
||||
options_ = other.options_;
|
||||
other.options_ = nullptr;
|
||||
}
|
||||
|
||||
// Adds a predefined macro to the compilation options. It behaves the same as
|
||||
// shaderc_compile_options_add_macro_definition in shaderc.h.
|
||||
void AddMacroDefinition(const char* name, size_t name_length,
|
||||
const char* value, size_t value_length) {
|
||||
shaderc_compile_options_add_macro_definition(options_, name, name_length,
|
||||
value, value_length);
|
||||
}
|
||||
|
||||
// Adds a valueless predefined macro to the compilation options.
|
||||
void AddMacroDefinition(const std::string& name) {
|
||||
AddMacroDefinition(name.c_str(), name.size(), nullptr, 0u);
|
||||
}
|
||||
|
||||
// Adds a predefined macro to the compilation options.
|
||||
void AddMacroDefinition(const std::string& name, const std::string& value) {
|
||||
AddMacroDefinition(name.c_str(), name.size(), value.c_str(), value.size());
|
||||
}
|
||||
|
||||
// Sets the compiler mode to generate debug information in the output.
|
||||
void SetGenerateDebugInfo() {
|
||||
shaderc_compile_options_set_generate_debug_info(options_);
|
||||
}
|
||||
|
||||
// Sets the compiler optimization level to the given level. Only the last one
|
||||
// takes effect if multiple calls of this function exist.
|
||||
void SetOptimizationLevel(shaderc_optimization_level level) {
|
||||
shaderc_compile_options_set_optimization_level(options_, level);
|
||||
}
|
||||
|
||||
// A C++ version of the libshaderc includer interface.
|
||||
class IncluderInterface {
|
||||
public:
|
||||
// Handles shaderc_include_resolver_fn callbacks.
|
||||
virtual shaderc_include_result* GetInclude(const char* requested_source,
|
||||
shaderc_include_type type,
|
||||
const char* requesting_source,
|
||||
size_t include_depth) = 0;
|
||||
|
||||
// Handles shaderc_include_result_release_fn callbacks.
|
||||
virtual void ReleaseInclude(shaderc_include_result* data) = 0;
|
||||
|
||||
virtual ~IncluderInterface() = default;
|
||||
};
|
||||
|
||||
// Sets the includer instance for libshaderc to call during compilation, as
|
||||
// described in shaderc_compile_options_set_include_callbacks(). Callbacks
|
||||
// are routed to this includer's methods.
|
||||
void SetIncluder(std::unique_ptr<IncluderInterface>&& includer) {
|
||||
includer_ = std::move(includer);
|
||||
shaderc_compile_options_set_include_callbacks(
|
||||
options_,
|
||||
[](void* user_data, const char* requested_source, int type,
|
||||
const char* requesting_source, size_t include_depth) {
|
||||
auto* sub_includer = static_cast<IncluderInterface*>(user_data);
|
||||
return sub_includer->GetInclude(
|
||||
requested_source, static_cast<shaderc_include_type>(type),
|
||||
requesting_source, include_depth);
|
||||
},
|
||||
[](void* user_data, shaderc_include_result* include_result) {
|
||||
auto* sub_includer = static_cast<IncluderInterface*>(user_data);
|
||||
return sub_includer->ReleaseInclude(include_result);
|
||||
},
|
||||
includer_.get());
|
||||
}
|
||||
|
||||
// Forces the GLSL language version and profile to a given pair. The version
|
||||
// number is the same as would appear in the #version annotation in the
|
||||
// source. Version and profile specified here overrides the #version
|
||||
// annotation in the source. Use profile: 'shaderc_profile_none' for GLSL
|
||||
// versions that do not define profiles, e.g. versions below 150.
|
||||
void SetForcedVersionProfile(int version, shaderc_profile profile) {
|
||||
shaderc_compile_options_set_forced_version_profile(options_, version,
|
||||
profile);
|
||||
}
|
||||
|
||||
// Sets the compiler mode to suppress warnings. Note this option overrides
|
||||
// warnings-as-errors mode. When both suppress-warnings and warnings-as-errors
|
||||
// modes are turned on, warning messages will be inhibited, and will not be
|
||||
// emitted as error message.
|
||||
void SetSuppressWarnings() {
|
||||
shaderc_compile_options_set_suppress_warnings(options_);
|
||||
}
|
||||
|
||||
// Sets the source language. The default is GLSL.
|
||||
void SetSourceLanguage(shaderc_source_language lang) {
|
||||
shaderc_compile_options_set_source_language(options_, lang);
|
||||
}
|
||||
|
||||
// Sets the target shader environment, affecting which warnings or errors will
|
||||
// be issued. The version will be for distinguishing between different
|
||||
// versions of the target environment. The version value should be either 0
|
||||
// or a value listed in shaderc_env_version. The 0 value maps to Vulkan 1.0
|
||||
// if |target| is Vulkan, and it maps to OpenGL 4.5 if |target| is OpenGL.
|
||||
void SetTargetEnvironment(shaderc_target_env target, uint32_t version) {
|
||||
shaderc_compile_options_set_target_env(options_, target, version);
|
||||
}
|
||||
|
||||
// Sets the target SPIR-V version. The generated module will use this version
|
||||
// of SPIR-V. Each target environment determines what versions of SPIR-V
|
||||
// it can consume. Defaults to the highest version of SPIR-V 1.0 which is
|
||||
// required to be supported by the target environment. E.g. Default to SPIR-V
|
||||
// 1.0 for Vulkan 1.0 and SPIR-V 1.3 for Vulkan 1.1.
|
||||
void SetTargetSpirv(shaderc_spirv_version version) {
|
||||
shaderc_compile_options_set_target_spirv(options_, version);
|
||||
}
|
||||
|
||||
// Sets the compiler mode to make all warnings into errors. Note the
|
||||
// suppress-warnings mode overrides this option, i.e. if both
|
||||
// warning-as-errors and suppress-warnings modes are set on, warnings will not
|
||||
// be emitted as error message.
|
||||
void SetWarningsAsErrors() {
|
||||
shaderc_compile_options_set_warnings_as_errors(options_);
|
||||
}
|
||||
|
||||
// Sets a resource limit.
|
||||
void SetLimit(shaderc_limit limit, int value) {
|
||||
shaderc_compile_options_set_limit(options_, limit, value);
|
||||
}
|
||||
|
||||
// Sets whether the compiler should automatically assign bindings to uniforms
|
||||
// that aren't already explicitly bound in the shader source.
|
||||
void SetAutoBindUniforms(bool auto_bind) {
|
||||
shaderc_compile_options_set_auto_bind_uniforms(options_, auto_bind);
|
||||
}
|
||||
|
||||
// Sets whether the compiler should use HLSL IO mapping rules for bindings.
|
||||
// Defaults to false.
|
||||
void SetHlslIoMapping(bool hlsl_iomap) {
|
||||
shaderc_compile_options_set_hlsl_io_mapping(options_, hlsl_iomap);
|
||||
}
|
||||
|
||||
// Sets whether the compiler should determine block member offsets using HLSL
|
||||
// packing rules instead of standard GLSL rules. Defaults to false. Only
|
||||
// affects GLSL compilation. HLSL rules are always used when compiling HLSL.
|
||||
void SetHlslOffsets(bool hlsl_offsets) {
|
||||
shaderc_compile_options_set_hlsl_offsets(options_, hlsl_offsets);
|
||||
}
|
||||
|
||||
// Sets the base binding number used for for a uniform resource type when
|
||||
// automatically assigning bindings. For GLSL compilation, sets the lowest
|
||||
// automatically assigned number. For HLSL compilation, the regsiter number
|
||||
// assigned to the resource is added to this specified base.
|
||||
void SetBindingBase(shaderc_uniform_kind kind, uint32_t base) {
|
||||
shaderc_compile_options_set_binding_base(options_, kind, base);
|
||||
}
|
||||
|
||||
// Like SetBindingBase, but only takes effect when compiling a given shader
|
||||
// stage. The stage is assumed to be one of vertex, fragment, tessellation
|
||||
// evaluation, tesselation control, geometry, or compute.
|
||||
void SetBindingBaseForStage(shaderc_shader_kind shader_kind,
|
||||
shaderc_uniform_kind kind, uint32_t base) {
|
||||
shaderc_compile_options_set_binding_base_for_stage(options_, shader_kind,
|
||||
kind, base);
|
||||
}
|
||||
|
||||
// Sets whether the compiler automatically assigns locations to
|
||||
// uniform variables that don't have explicit locations.
|
||||
void SetAutoMapLocations(bool auto_map) {
|
||||
shaderc_compile_options_set_auto_map_locations(options_, auto_map);
|
||||
}
|
||||
|
||||
// Sets a descriptor set and binding for an HLSL register in the given stage.
|
||||
// Copies the parameter strings.
|
||||
void SetHlslRegisterSetAndBindingForStage(shaderc_shader_kind shader_kind,
|
||||
const std::string& reg,
|
||||
const std::string& set,
|
||||
const std::string& binding) {
|
||||
shaderc_compile_options_set_hlsl_register_set_and_binding_for_stage(
|
||||
options_, shader_kind, reg.c_str(), set.c_str(), binding.c_str());
|
||||
}
|
||||
|
||||
// Sets a descriptor set and binding for an HLSL register in any stage.
|
||||
// Copies the parameter strings.
|
||||
void SetHlslRegisterSetAndBinding(const std::string& reg,
|
||||
const std::string& set,
|
||||
const std::string& binding) {
|
||||
shaderc_compile_options_set_hlsl_register_set_and_binding(
|
||||
options_, reg.c_str(), set.c_str(), binding.c_str());
|
||||
}
|
||||
|
||||
// Sets whether the compiler should enable extension
|
||||
// SPV_GOOGLE_hlsl_functionality1.
|
||||
void SetHlslFunctionality1(bool enable) {
|
||||
shaderc_compile_options_set_hlsl_functionality1(options_, enable);
|
||||
}
|
||||
|
||||
// Sets whether the compiler should invert position.Y output in vertex shader.
|
||||
void SetInvertY(bool enable) {
|
||||
shaderc_compile_options_set_invert_y(options_, enable);
|
||||
}
|
||||
|
||||
// Sets whether the compiler should generates code for max an min which,
|
||||
// if given a NaN operand, will return the other operand. Similarly, the
|
||||
// clamp builtin will favour the non-NaN operands, as if clamp were
|
||||
// implemented as a composition of max and min.
|
||||
void SetNanClamp(bool enable) {
|
||||
shaderc_compile_options_set_nan_clamp(options_, enable);
|
||||
}
|
||||
|
||||
private:
|
||||
CompileOptions& operator=(const CompileOptions& other) = delete;
|
||||
shaderc_compile_options_t options_;
|
||||
std::unique_ptr<IncluderInterface> includer_;
|
||||
|
||||
friend class Compiler;
|
||||
};
|
||||
|
||||
// The compilation context for compiling source to SPIR-V.
|
||||
class Compiler {
|
||||
public:
|
||||
Compiler() : compiler_(shaderc_compiler_initialize()) {}
|
||||
~Compiler() { shaderc_compiler_release(compiler_); }
|
||||
|
||||
Compiler(Compiler&& other) {
|
||||
compiler_ = other.compiler_;
|
||||
other.compiler_ = nullptr;
|
||||
}
|
||||
|
||||
bool IsValid() const { return compiler_ != nullptr; }
|
||||
|
||||
// Compiles the given source GLSL and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// The source_text parameter must be a valid pointer.
|
||||
// The source_text_size parameter must be the length of the source text.
|
||||
// The shader_kind parameter either forces the compilation to be done with a
|
||||
// specified shader kind, or hint the compiler how to determine the exact
|
||||
// shader kind. If the shader kind is set to shaderc_glslc_infer_from_source,
|
||||
// the compiler will try to deduce the shader kind from the source string and
|
||||
// a failure in this proess will generate an error. Currently only #pragma
|
||||
// annotation is supported. If the shader kind is set to one of the default
|
||||
// shader kinds, the compiler will fall back to the specified default shader
|
||||
// kind in case it failed to deduce the shader kind from the source string.
|
||||
// The input_file_name is a null-termintated string. It is used as a tag to
|
||||
// identify the source string in cases like emitting error messages. It
|
||||
// doesn't have to be a 'file name'.
|
||||
// The entry_point_name parameter is a null-terminated string specifying
|
||||
// the entry point name for HLSL compilation. For GLSL compilation, the
|
||||
// entry point name is assumed to be "main".
|
||||
// The compilation is passed any options specified in the CompileOptions
|
||||
// parameter.
|
||||
// It is valid for the returned CompilationResult object to outlive this
|
||||
// compiler object.
|
||||
// Note when the options_ has disassembly mode or preprocessing only mode set
|
||||
// on, the returned CompilationResult will hold a text string, instead of a
|
||||
// SPIR-V binary generated with default options.
|
||||
SpvCompilationResult CompileGlslToSpv(const char* source_text,
|
||||
size_t source_text_size,
|
||||
shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name,
|
||||
const char* entry_point_name,
|
||||
const CompileOptions& options) const {
|
||||
shaderc_compilation_result_t compilation_result = shaderc_compile_into_spv(
|
||||
compiler_, source_text, source_text_size, shader_kind, input_file_name,
|
||||
entry_point_name, options.options_);
|
||||
return SpvCompilationResult(compilation_result);
|
||||
}
|
||||
|
||||
// Compiles the given source shader and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the first CompileGlslToSpv method but assumes the entry point name
|
||||
// is "main".
|
||||
SpvCompilationResult CompileGlslToSpv(const char* source_text,
|
||||
size_t source_text_size,
|
||||
shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name,
|
||||
const CompileOptions& options) const {
|
||||
return CompileGlslToSpv(source_text, source_text_size, shader_kind,
|
||||
input_file_name, "main", options);
|
||||
}
|
||||
|
||||
// Compiles the given source GLSL and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the previous CompileGlslToSpv method but uses default options.
|
||||
SpvCompilationResult CompileGlslToSpv(const char* source_text,
|
||||
size_t source_text_size,
|
||||
shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name) const {
|
||||
shaderc_compilation_result_t compilation_result =
|
||||
shaderc_compile_into_spv(compiler_, source_text, source_text_size,
|
||||
shader_kind, input_file_name, "main", nullptr);
|
||||
return SpvCompilationResult(compilation_result);
|
||||
}
|
||||
|
||||
// Compiles the given source shader and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the first CompileGlslToSpv method but the source is provided as
|
||||
// a std::string, and we assume the entry point is "main".
|
||||
SpvCompilationResult CompileGlslToSpv(const std::string& source_text,
|
||||
shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name,
|
||||
const CompileOptions& options) const {
|
||||
return CompileGlslToSpv(source_text.data(), source_text.size(), shader_kind,
|
||||
input_file_name, options);
|
||||
}
|
||||
|
||||
// Compiles the given source shader and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the first CompileGlslToSpv method but the source is provided as
|
||||
// a std::string.
|
||||
SpvCompilationResult CompileGlslToSpv(const std::string& source_text,
|
||||
shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name,
|
||||
const char* entry_point_name,
|
||||
const CompileOptions& options) const {
|
||||
return CompileGlslToSpv(source_text.data(), source_text.size(), shader_kind,
|
||||
input_file_name, entry_point_name, options);
|
||||
}
|
||||
|
||||
// Compiles the given source GLSL and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the previous CompileGlslToSpv method but assumes the entry point
|
||||
// name is "main".
|
||||
SpvCompilationResult CompileGlslToSpv(const std::string& source_text,
|
||||
shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name) const {
|
||||
return CompileGlslToSpv(source_text.data(), source_text.size(), shader_kind,
|
||||
input_file_name);
|
||||
}
|
||||
|
||||
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// The assembly should follow the syntax defined in the SPIRV-Tools project
|
||||
// (https://github.com/KhronosGroup/SPIRV-Tools/blob/master/syntax.md).
|
||||
// It is valid for the returned CompilationResult object to outlive this
|
||||
// compiler object.
|
||||
// The assembling will pick options suitable for assembling specified in the
|
||||
// CompileOptions parameter.
|
||||
SpvCompilationResult AssembleToSpv(const char* source_assembly,
|
||||
size_t source_assembly_size,
|
||||
const CompileOptions& options) const {
|
||||
return SpvCompilationResult(shaderc_assemble_into_spv(
|
||||
compiler_, source_assembly, source_assembly_size, options.options_));
|
||||
}
|
||||
|
||||
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the first AssembleToSpv method but uses the default compiler options.
|
||||
SpvCompilationResult AssembleToSpv(const char* source_assembly,
|
||||
size_t source_assembly_size) const {
|
||||
return SpvCompilationResult(shaderc_assemble_into_spv(
|
||||
compiler_, source_assembly, source_assembly_size, nullptr));
|
||||
}
|
||||
|
||||
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the first AssembleToSpv method but the source is provided as a
|
||||
// std::string.
|
||||
SpvCompilationResult AssembleToSpv(const std::string& source_assembly,
|
||||
const CompileOptions& options) const {
|
||||
return SpvCompilationResult(
|
||||
shaderc_assemble_into_spv(compiler_, source_assembly.data(),
|
||||
source_assembly.size(), options.options_));
|
||||
}
|
||||
|
||||
// Assembles the given SPIR-V assembly and returns a SPIR-V binary module
|
||||
// compilation result.
|
||||
// Like the first AssembleToSpv method but the source is provided as a
|
||||
// std::string and also uses default compiler options.
|
||||
SpvCompilationResult AssembleToSpv(const std::string& source_assembly) const {
|
||||
return SpvCompilationResult(shaderc_assemble_into_spv(
|
||||
compiler_, source_assembly.data(), source_assembly.size(), nullptr));
|
||||
}
|
||||
|
||||
// Compiles the given source GLSL and returns the SPIR-V assembly text
|
||||
// compilation result.
|
||||
// Options are similar to the first CompileToSpv method.
|
||||
AssemblyCompilationResult CompileGlslToSpvAssembly(
|
||||
const char* source_text, size_t source_text_size,
|
||||
shaderc_shader_kind shader_kind, const char* input_file_name,
|
||||
const char* entry_point_name, const CompileOptions& options) const {
|
||||
shaderc_compilation_result_t compilation_result =
|
||||
shaderc_compile_into_spv_assembly(
|
||||
compiler_, source_text, source_text_size, shader_kind,
|
||||
input_file_name, entry_point_name, options.options_);
|
||||
return AssemblyCompilationResult(compilation_result);
|
||||
}
|
||||
|
||||
// Compiles the given source GLSL and returns the SPIR-V assembly text
|
||||
// compilation result.
|
||||
// Similare to the previous method, but assumes entry point name is "main".
|
||||
AssemblyCompilationResult CompileGlslToSpvAssembly(
|
||||
const char* source_text, size_t source_text_size,
|
||||
shaderc_shader_kind shader_kind, const char* input_file_name,
|
||||
const CompileOptions& options) const {
|
||||
return CompileGlslToSpvAssembly(source_text, source_text_size, shader_kind,
|
||||
input_file_name, "main", options);
|
||||
}
|
||||
|
||||
// Compiles the given source GLSL and returns the SPIR-V assembly text
|
||||
// result. Like the first CompileGlslToSpvAssembly method but the source
|
||||
// is provided as a std::string. Options are otherwise similar to
|
||||
// the first CompileToSpv method.
|
||||
AssemblyCompilationResult CompileGlslToSpvAssembly(
|
||||
const std::string& source_text, shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name, const char* entry_point_name,
|
||||
const CompileOptions& options) const {
|
||||
return CompileGlslToSpvAssembly(source_text.data(), source_text.size(),
|
||||
shader_kind, input_file_name,
|
||||
entry_point_name, options);
|
||||
}
|
||||
|
||||
// Compiles the given source GLSL and returns the SPIR-V assembly text
|
||||
// result. Like the previous CompileGlslToSpvAssembly method but assumes
|
||||
// the entry point name is "main".
|
||||
AssemblyCompilationResult CompileGlslToSpvAssembly(
|
||||
const std::string& source_text, shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name, const CompileOptions& options) const {
|
||||
return CompileGlslToSpvAssembly(source_text, shader_kind, input_file_name,
|
||||
"main", options);
|
||||
}
|
||||
|
||||
// Preprocesses the given source GLSL and returns the preprocessed
|
||||
// source text as a compilation result.
|
||||
// Options are similar to the first CompileToSpv method.
|
||||
PreprocessedSourceCompilationResult PreprocessGlsl(
|
||||
const char* source_text, size_t source_text_size,
|
||||
shaderc_shader_kind shader_kind, const char* input_file_name,
|
||||
const CompileOptions& options) const {
|
||||
shaderc_compilation_result_t compilation_result =
|
||||
shaderc_compile_into_preprocessed_text(
|
||||
compiler_, source_text, source_text_size, shader_kind,
|
||||
input_file_name, "main", options.options_);
|
||||
return PreprocessedSourceCompilationResult(compilation_result);
|
||||
}
|
||||
|
||||
// Preprocesses the given source GLSL and returns text result. Like the first
|
||||
// PreprocessGlsl method but the source is provided as a std::string.
|
||||
// Options are otherwise similar to the first CompileToSpv method.
|
||||
PreprocessedSourceCompilationResult PreprocessGlsl(
|
||||
const std::string& source_text, shaderc_shader_kind shader_kind,
|
||||
const char* input_file_name, const CompileOptions& options) const {
|
||||
return PreprocessGlsl(source_text.data(), source_text.size(), shader_kind,
|
||||
input_file_name, options);
|
||||
}
|
||||
|
||||
private:
|
||||
Compiler(const Compiler&) = delete;
|
||||
Compiler& operator=(const Compiler& other) = delete;
|
||||
|
||||
shaderc_compiler_t compiler_;
|
||||
};
|
||||
} // namespace shaderc
|
||||
|
||||
#endif // SHADERC_SHADERC_HPP_
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// Copyright 2018 The Shaderc Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SHADERC_STATUS_H_
|
||||
#define SHADERC_STATUS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Indicate the status of a compilation.
|
||||
typedef enum {
|
||||
shaderc_compilation_status_success = 0,
|
||||
shaderc_compilation_status_invalid_stage = 1, // error stage deduction
|
||||
shaderc_compilation_status_compilation_error = 2,
|
||||
shaderc_compilation_status_internal_error = 3, // unexpected failure
|
||||
shaderc_compilation_status_null_result_object = 4,
|
||||
shaderc_compilation_status_invalid_assembly = 5,
|
||||
shaderc_compilation_status_validation_error = 6,
|
||||
shaderc_compilation_status_transformation_error = 7,
|
||||
shaderc_compilation_status_configuration_error = 8,
|
||||
} shaderc_compilation_status;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // SHADERC_STATUS_H_
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2018 The Shaderc Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SHADERC_VISIBILITY_H_
|
||||
#define SHADERC_VISIBILITY_H_
|
||||
|
||||
// SHADERC_EXPORT tags symbol that will be exposed by the shared libraries.
|
||||
#if defined(SHADERC_SHAREDLIB)
|
||||
#if defined(_WIN32)
|
||||
#if defined(SHADERC_IMPLEMENTATION)
|
||||
#define SHADERC_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define SHADERC_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#if defined(SHADERC_IMPLEMENTATION)
|
||||
#define SHADERC_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SHADERC_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define SHADERC_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // SHADERC_VISIBILITY_H_
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
** Copyright (c) 2014-2016 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and/or associated documentation files (the "Materials"),
|
||||
** to deal in the Materials without restriction, including without limitation
|
||||
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
** and/or sell copies of the Materials, and to permit persons to whom the
|
||||
** Materials are 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 Materials.
|
||||
**
|
||||
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
**
|
||||
** THE MATERIALS ARE 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 MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
** IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#ifndef GLSLstd450_H
|
||||
#define GLSLstd450_H
|
||||
|
||||
static const int GLSLstd450Version = 100;
|
||||
static const int GLSLstd450Revision = 3;
|
||||
|
||||
enum GLSLstd450 {
|
||||
GLSLstd450Bad = 0, // Don't use
|
||||
|
||||
GLSLstd450Round = 1,
|
||||
GLSLstd450RoundEven = 2,
|
||||
GLSLstd450Trunc = 3,
|
||||
GLSLstd450FAbs = 4,
|
||||
GLSLstd450SAbs = 5,
|
||||
GLSLstd450FSign = 6,
|
||||
GLSLstd450SSign = 7,
|
||||
GLSLstd450Floor = 8,
|
||||
GLSLstd450Ceil = 9,
|
||||
GLSLstd450Fract = 10,
|
||||
|
||||
GLSLstd450Radians = 11,
|
||||
GLSLstd450Degrees = 12,
|
||||
GLSLstd450Sin = 13,
|
||||
GLSLstd450Cos = 14,
|
||||
GLSLstd450Tan = 15,
|
||||
GLSLstd450Asin = 16,
|
||||
GLSLstd450Acos = 17,
|
||||
GLSLstd450Atan = 18,
|
||||
GLSLstd450Sinh = 19,
|
||||
GLSLstd450Cosh = 20,
|
||||
GLSLstd450Tanh = 21,
|
||||
GLSLstd450Asinh = 22,
|
||||
GLSLstd450Acosh = 23,
|
||||
GLSLstd450Atanh = 24,
|
||||
GLSLstd450Atan2 = 25,
|
||||
|
||||
GLSLstd450Pow = 26,
|
||||
GLSLstd450Exp = 27,
|
||||
GLSLstd450Log = 28,
|
||||
GLSLstd450Exp2 = 29,
|
||||
GLSLstd450Log2 = 30,
|
||||
GLSLstd450Sqrt = 31,
|
||||
GLSLstd450InverseSqrt = 32,
|
||||
|
||||
GLSLstd450Determinant = 33,
|
||||
GLSLstd450MatrixInverse = 34,
|
||||
|
||||
GLSLstd450Modf = 35, // second operand needs an OpVariable to write to
|
||||
GLSLstd450ModfStruct = 36, // no OpVariable operand
|
||||
GLSLstd450FMin = 37,
|
||||
GLSLstd450UMin = 38,
|
||||
GLSLstd450SMin = 39,
|
||||
GLSLstd450FMax = 40,
|
||||
GLSLstd450UMax = 41,
|
||||
GLSLstd450SMax = 42,
|
||||
GLSLstd450FClamp = 43,
|
||||
GLSLstd450UClamp = 44,
|
||||
GLSLstd450SClamp = 45,
|
||||
GLSLstd450FMix = 46,
|
||||
GLSLstd450IMix = 47, // Reserved
|
||||
GLSLstd450Step = 48,
|
||||
GLSLstd450SmoothStep = 49,
|
||||
|
||||
GLSLstd450Fma = 50,
|
||||
GLSLstd450Frexp = 51, // second operand needs an OpVariable to write to
|
||||
GLSLstd450FrexpStruct = 52, // no OpVariable operand
|
||||
GLSLstd450Ldexp = 53,
|
||||
|
||||
GLSLstd450PackSnorm4x8 = 54,
|
||||
GLSLstd450PackUnorm4x8 = 55,
|
||||
GLSLstd450PackSnorm2x16 = 56,
|
||||
GLSLstd450PackUnorm2x16 = 57,
|
||||
GLSLstd450PackHalf2x16 = 58,
|
||||
GLSLstd450PackDouble2x32 = 59,
|
||||
GLSLstd450UnpackSnorm2x16 = 60,
|
||||
GLSLstd450UnpackUnorm2x16 = 61,
|
||||
GLSLstd450UnpackHalf2x16 = 62,
|
||||
GLSLstd450UnpackSnorm4x8 = 63,
|
||||
GLSLstd450UnpackUnorm4x8 = 64,
|
||||
GLSLstd450UnpackDouble2x32 = 65,
|
||||
|
||||
GLSLstd450Length = 66,
|
||||
GLSLstd450Distance = 67,
|
||||
GLSLstd450Cross = 68,
|
||||
GLSLstd450Normalize = 69,
|
||||
GLSLstd450FaceForward = 70,
|
||||
GLSLstd450Reflect = 71,
|
||||
GLSLstd450Refract = 72,
|
||||
|
||||
GLSLstd450FindILsb = 73,
|
||||
GLSLstd450FindSMsb = 74,
|
||||
GLSLstd450FindUMsb = 75,
|
||||
|
||||
GLSLstd450InterpolateAtCentroid = 76,
|
||||
GLSLstd450InterpolateAtSample = 77,
|
||||
GLSLstd450InterpolateAtOffset = 78,
|
||||
|
||||
GLSLstd450NMin = 79,
|
||||
GLSLstd450NMax = 80,
|
||||
GLSLstd450NClamp = 81,
|
||||
|
||||
GLSLstd450Count
|
||||
};
|
||||
|
||||
#endif // #ifndef GLSLstd450_H
|
||||
+2295
File diff suppressed because it is too large
Load Diff
+2306
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+1696
File diff suppressed because it is too large
Load Diff
+1659
File diff suppressed because it is too large
Load Diff
+1659
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,259 @@
|
||||
// Copyright (c) 2018 The Khronos Group Inc.
|
||||
// Copyright (c) 2018 Valve Corporation
|
||||
// Copyright (c) 2018 LunarG Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_
|
||||
#define INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_
|
||||
|
||||
// Shader Instrumentation Interface
|
||||
//
|
||||
// This file provides an external interface for applications that wish to
|
||||
// communicate with shaders instrumented by passes created by:
|
||||
//
|
||||
// CreateInstBindlessCheckPass
|
||||
// CreateInstBuffAddrCheckPass
|
||||
// CreateInstDebugPrintfPass
|
||||
//
|
||||
// More detailed documentation of these routines can be found in optimizer.hpp
|
||||
|
||||
namespace spvtools {
|
||||
|
||||
// Stream Output Buffer Offsets
|
||||
//
|
||||
// The following values provide offsets into the output buffer struct
|
||||
// generated by InstrumentPass::GenDebugStreamWrite. This method is utilized
|
||||
// by InstBindlessCheckPass, InstBuffAddrCheckPass, and InstDebugPrintfPass.
|
||||
//
|
||||
// The first member of the debug output buffer contains the next available word
|
||||
// in the data stream to be written. Shaders will atomically read and update
|
||||
// this value so as not to overwrite each others records. This value must be
|
||||
// initialized to zero
|
||||
static const int kDebugOutputSizeOffset = 0;
|
||||
|
||||
// The second member of the output buffer is the start of the stream of records
|
||||
// written by the instrumented shaders. Each record represents a validation
|
||||
// error. The format of the records is documented below.
|
||||
static const int kDebugOutputDataOffset = 1;
|
||||
|
||||
// Common Stream Record Offsets
|
||||
//
|
||||
// The following are offsets to fields which are common to all records written
|
||||
// to the output stream.
|
||||
//
|
||||
// Each record first contains the size of the record in 32-bit words, including
|
||||
// the size word.
|
||||
static const int kInstCommonOutSize = 0;
|
||||
|
||||
// This is the shader id passed by the layer when the instrumentation pass is
|
||||
// created.
|
||||
static const int kInstCommonOutShaderId = 1;
|
||||
|
||||
// This is the ordinal position of the instruction within the SPIR-V shader
|
||||
// which generated the validation error.
|
||||
static const int kInstCommonOutInstructionIdx = 2;
|
||||
|
||||
// This is the stage which generated the validation error. This word is used
|
||||
// to determine the contents of the next two words in the record.
|
||||
// 0:Vert, 1:TessCtrl, 2:TessEval, 3:Geom, 4:Frag, 5:Compute
|
||||
static const int kInstCommonOutStageIdx = 3;
|
||||
static const int kInstCommonOutCnt = 4;
|
||||
|
||||
// Stage-specific Stream Record Offsets
|
||||
//
|
||||
// Each stage will contain different values in the next set of words of the
|
||||
// record used to identify which instantiation of the shader generated the
|
||||
// validation error.
|
||||
//
|
||||
// Vertex Shader Output Record Offsets
|
||||
static const int kInstVertOutVertexIndex = kInstCommonOutCnt;
|
||||
static const int kInstVertOutInstanceIndex = kInstCommonOutCnt + 1;
|
||||
static const int kInstVertOutUnused = kInstCommonOutCnt + 2;
|
||||
|
||||
// Frag Shader Output Record Offsets
|
||||
static const int kInstFragOutFragCoordX = kInstCommonOutCnt;
|
||||
static const int kInstFragOutFragCoordY = kInstCommonOutCnt + 1;
|
||||
static const int kInstFragOutUnused = kInstCommonOutCnt + 2;
|
||||
|
||||
// Compute Shader Output Record Offsets
|
||||
static const int kInstCompOutGlobalInvocationIdX = kInstCommonOutCnt;
|
||||
static const int kInstCompOutGlobalInvocationIdY = kInstCommonOutCnt + 1;
|
||||
static const int kInstCompOutGlobalInvocationIdZ = kInstCommonOutCnt + 2;
|
||||
|
||||
// Tessellation Control Shader Output Record Offsets
|
||||
static const int kInstTessCtlOutInvocationId = kInstCommonOutCnt;
|
||||
static const int kInstTessCtlOutPrimitiveId = kInstCommonOutCnt + 1;
|
||||
static const int kInstTessCtlOutUnused = kInstCommonOutCnt + 2;
|
||||
|
||||
// Tessellation Eval Shader Output Record Offsets
|
||||
static const int kInstTessEvalOutPrimitiveId = kInstCommonOutCnt;
|
||||
static const int kInstTessEvalOutTessCoordU = kInstCommonOutCnt + 1;
|
||||
static const int kInstTessEvalOutTessCoordV = kInstCommonOutCnt + 2;
|
||||
|
||||
// Geometry Shader Output Record Offsets
|
||||
static const int kInstGeomOutPrimitiveId = kInstCommonOutCnt;
|
||||
static const int kInstGeomOutInvocationId = kInstCommonOutCnt + 1;
|
||||
static const int kInstGeomOutUnused = kInstCommonOutCnt + 2;
|
||||
|
||||
// Ray Tracing Shader Output Record Offsets
|
||||
static const int kInstRayTracingOutLaunchIdX = kInstCommonOutCnt;
|
||||
static const int kInstRayTracingOutLaunchIdY = kInstCommonOutCnt + 1;
|
||||
static const int kInstRayTracingOutLaunchIdZ = kInstCommonOutCnt + 2;
|
||||
|
||||
// Mesh Shader Output Record Offsets
|
||||
static const int kInstMeshOutGlobalInvocationIdX = kInstCommonOutCnt;
|
||||
static const int kInstMeshOutGlobalInvocationIdY = kInstCommonOutCnt + 1;
|
||||
static const int kInstMeshOutGlobalInvocationIdZ = kInstCommonOutCnt + 2;
|
||||
|
||||
// Task Shader Output Record Offsets
|
||||
static const int kInstTaskOutGlobalInvocationIdX = kInstCommonOutCnt;
|
||||
static const int kInstTaskOutGlobalInvocationIdY = kInstCommonOutCnt + 1;
|
||||
static const int kInstTaskOutGlobalInvocationIdZ = kInstCommonOutCnt + 2;
|
||||
|
||||
// Size of Common and Stage-specific Members
|
||||
static const int kInstStageOutCnt = kInstCommonOutCnt + 3;
|
||||
|
||||
// Validation Error Code Offset
|
||||
//
|
||||
// This identifies the validation error. It also helps to identify
|
||||
// how many words follow in the record and their meaning.
|
||||
static const int kInstValidationOutError = kInstStageOutCnt;
|
||||
|
||||
// Validation-specific Output Record Offsets
|
||||
//
|
||||
// Each different validation will generate a potentially different
|
||||
// number of words at the end of the record giving more specifics
|
||||
// about the validation error.
|
||||
//
|
||||
// A bindless bounds error will output the index and the bound.
|
||||
static const int kInstBindlessBoundsOutDescIndex = kInstStageOutCnt + 1;
|
||||
static const int kInstBindlessBoundsOutDescBound = kInstStageOutCnt + 2;
|
||||
static const int kInstBindlessBoundsOutUnused = kInstStageOutCnt + 3;
|
||||
static const int kInstBindlessBoundsOutCnt = kInstStageOutCnt + 4;
|
||||
|
||||
// A descriptor uninitialized error will output the index.
|
||||
static const int kInstBindlessUninitOutDescIndex = kInstStageOutCnt + 1;
|
||||
static const int kInstBindlessUninitOutUnused = kInstStageOutCnt + 2;
|
||||
static const int kInstBindlessUninitOutUnused2 = kInstStageOutCnt + 3;
|
||||
static const int kInstBindlessUninitOutCnt = kInstStageOutCnt + 4;
|
||||
|
||||
// A buffer out-of-bounds error will output the descriptor
|
||||
// index, the buffer offset and the buffer size
|
||||
static const int kInstBindlessBuffOOBOutDescIndex = kInstStageOutCnt + 1;
|
||||
static const int kInstBindlessBuffOOBOutBuffOff = kInstStageOutCnt + 2;
|
||||
static const int kInstBindlessBuffOOBOutBuffSize = kInstStageOutCnt + 3;
|
||||
static const int kInstBindlessBuffOOBOutCnt = kInstStageOutCnt + 4;
|
||||
|
||||
// A buffer address unalloc error will output the 64-bit pointer in
|
||||
// two 32-bit pieces, lower bits first.
|
||||
static const int kInstBuffAddrUnallocOutDescPtrLo = kInstStageOutCnt + 1;
|
||||
static const int kInstBuffAddrUnallocOutDescPtrHi = kInstStageOutCnt + 2;
|
||||
static const int kInstBuffAddrUnallocOutCnt = kInstStageOutCnt + 3;
|
||||
|
||||
// Maximum Output Record Member Count
|
||||
static const int kInstMaxOutCnt = kInstStageOutCnt + 4;
|
||||
|
||||
// Validation Error Codes
|
||||
//
|
||||
// These are the possible validation error codes.
|
||||
static const int kInstErrorBindlessBounds = 0;
|
||||
static const int kInstErrorBindlessUninit = 1;
|
||||
static const int kInstErrorBuffAddrUnallocRef = 2;
|
||||
// Deleted: static const int kInstErrorBindlessBuffOOB = 3;
|
||||
// This comment will will remain for 2 releases to allow
|
||||
// for the transition of all builds. Buffer OOB is
|
||||
// generating the following four differentiated codes instead:
|
||||
static const int kInstErrorBuffOOBUniform = 4;
|
||||
static const int kInstErrorBuffOOBStorage = 5;
|
||||
static const int kInstErrorBuffOOBUniformTexel = 6;
|
||||
static const int kInstErrorBuffOOBStorageTexel = 7;
|
||||
static const int kInstErrorMax = kInstErrorBuffOOBStorageTexel;
|
||||
|
||||
// Direct Input Buffer Offsets
|
||||
//
|
||||
// The following values provide member offsets into the input buffers
|
||||
// consumed by InstrumentPass::GenDebugDirectRead(). This method is utilized
|
||||
// by InstBindlessCheckPass.
|
||||
//
|
||||
// The only object in an input buffer is a runtime array of unsigned
|
||||
// integers. Each validation will have its own formatting of this array.
|
||||
static const int kDebugInputDataOffset = 0;
|
||||
|
||||
// Debug Buffer Bindings
|
||||
//
|
||||
// These are the bindings for the different buffers which are
|
||||
// read or written by the instrumentation passes.
|
||||
//
|
||||
// This is the output buffer written by InstBindlessCheckPass,
|
||||
// InstBuffAddrCheckPass, and possibly other future validations.
|
||||
static const int kDebugOutputBindingStream = 0;
|
||||
|
||||
// The binding for the input buffer read by InstBindlessCheckPass.
|
||||
static const int kDebugInputBindingBindless = 1;
|
||||
|
||||
// The binding for the input buffer read by InstBuffAddrCheckPass.
|
||||
static const int kDebugInputBindingBuffAddr = 2;
|
||||
|
||||
// This is the output buffer written by InstDebugPrintfPass.
|
||||
static const int kDebugOutputPrintfStream = 3;
|
||||
|
||||
// Bindless Validation Input Buffer Format
|
||||
//
|
||||
// An input buffer for bindless validation consists of a single array of
|
||||
// unsigned integers we will call Data[]. This array is formatted as follows.
|
||||
//
|
||||
// At offset kDebugInputBindlessInitOffset in Data[] is a single uint which
|
||||
// gives an offset to the start of the bindless initialization data. More
|
||||
// specifically, if the following value is zero, we know that the descriptor at
|
||||
// (set = s, binding = b, index = i) is not initialized; if the value is
|
||||
// non-zero, and the descriptor points to a buffer, the value is the length of
|
||||
// the buffer in bytes and can be used to check for out-of-bounds buffer
|
||||
// references:
|
||||
// Data[ i + Data[ b + Data[ s + Data[ kDebugInputBindlessInitOffset ] ] ] ]
|
||||
static const int kDebugInputBindlessInitOffset = 0;
|
||||
|
||||
// At offset kDebugInputBindlessOffsetLengths is some number of uints which
|
||||
// provide the bindless length data. More specifically, the number of
|
||||
// descriptors at (set=s, binding=b) is:
|
||||
// Data[ Data[ s + kDebugInputBindlessOffsetLengths ] + b ]
|
||||
static const int kDebugInputBindlessOffsetLengths = 1;
|
||||
|
||||
// Buffer Device Address Input Buffer Format
|
||||
//
|
||||
// An input buffer for buffer device address validation consists of a single
|
||||
// array of unsigned 64-bit integers we will call Data[]. This array is
|
||||
// formatted as follows:
|
||||
//
|
||||
// At offset kDebugInputBuffAddrPtrOffset is a list of sorted valid buffer
|
||||
// addresses. The list is terminated with the address 0xffffffffffffffff.
|
||||
// If 0x0 is not a valid buffer address, this address is inserted at the
|
||||
// start of the list.
|
||||
//
|
||||
static const int kDebugInputBuffAddrPtrOffset = 1;
|
||||
//
|
||||
// At offset kDebugInputBuffAddrLengthOffset in Data[] is a single uint64 which
|
||||
// gives an offset to the start of the buffer length data. More
|
||||
// specifically, for a buffer whose pointer is located at input buffer offset
|
||||
// i, the length is located at:
|
||||
//
|
||||
// Data[ i - kDebugInputBuffAddrPtrOffset
|
||||
// + Data[ kDebugInputBuffAddrLengthOffset ] ]
|
||||
//
|
||||
// The length associated with the 0xffffffffffffffff address is zero. If
|
||||
// not a valid buffer, the length associated with the 0x0 address is zero.
|
||||
static const int kDebugInputBuffAddrLengthOffset = 0;
|
||||
|
||||
} // namespace spvtools
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_INSTRUMENT_HPP_
|
||||
@@ -0,0 +1,892 @@
|
||||
// Copyright (c) 2015-2020 The Khronos Group Inc.
|
||||
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
|
||||
// reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef INCLUDE_SPIRV_TOOLS_LIBSPIRV_H_
|
||||
#define INCLUDE_SPIRV_TOOLS_LIBSPIRV_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(SPIRV_TOOLS_SHAREDLIB)
|
||||
#if defined(_WIN32)
|
||||
#if defined(SPIRV_TOOLS_IMPLEMENTATION)
|
||||
#define SPIRV_TOOLS_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define SPIRV_TOOLS_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#if defined(SPIRV_TOOLS_IMPLEMENTATION)
|
||||
#define SPIRV_TOOLS_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define SPIRV_TOOLS_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define SPIRV_TOOLS_EXPORT
|
||||
#endif
|
||||
|
||||
// Helpers
|
||||
|
||||
#define SPV_BIT(shift) (1 << (shift))
|
||||
|
||||
#define SPV_FORCE_16_BIT_ENUM(name) SPV_FORCE_16BIT_##name = 0x7fff
|
||||
#define SPV_FORCE_32_BIT_ENUM(name) SPV_FORCE_32BIT_##name = 0x7fffffff
|
||||
|
||||
// Enumerations
|
||||
|
||||
typedef enum spv_result_t {
|
||||
SPV_SUCCESS = 0,
|
||||
SPV_UNSUPPORTED = 1,
|
||||
SPV_END_OF_STREAM = 2,
|
||||
SPV_WARNING = 3,
|
||||
SPV_FAILED_MATCH = 4,
|
||||
SPV_REQUESTED_TERMINATION = 5, // Success, but signals early termination.
|
||||
SPV_ERROR_INTERNAL = -1,
|
||||
SPV_ERROR_OUT_OF_MEMORY = -2,
|
||||
SPV_ERROR_INVALID_POINTER = -3,
|
||||
SPV_ERROR_INVALID_BINARY = -4,
|
||||
SPV_ERROR_INVALID_TEXT = -5,
|
||||
SPV_ERROR_INVALID_TABLE = -6,
|
||||
SPV_ERROR_INVALID_VALUE = -7,
|
||||
SPV_ERROR_INVALID_DIAGNOSTIC = -8,
|
||||
SPV_ERROR_INVALID_LOOKUP = -9,
|
||||
SPV_ERROR_INVALID_ID = -10,
|
||||
SPV_ERROR_INVALID_CFG = -11,
|
||||
SPV_ERROR_INVALID_LAYOUT = -12,
|
||||
SPV_ERROR_INVALID_CAPABILITY = -13,
|
||||
SPV_ERROR_INVALID_DATA = -14, // Indicates data rules validation failure.
|
||||
SPV_ERROR_MISSING_EXTENSION = -15,
|
||||
SPV_ERROR_WRONG_VERSION = -16, // Indicates wrong SPIR-V version
|
||||
SPV_FORCE_32_BIT_ENUM(spv_result_t)
|
||||
} spv_result_t;
|
||||
|
||||
// Severity levels of messages communicated to the consumer.
|
||||
typedef enum spv_message_level_t {
|
||||
SPV_MSG_FATAL, // Unrecoverable error due to environment.
|
||||
// Will exit the program immediately. E.g.,
|
||||
// out of memory.
|
||||
SPV_MSG_INTERNAL_ERROR, // Unrecoverable error due to SPIRV-Tools
|
||||
// internals.
|
||||
// Will exit the program immediately. E.g.,
|
||||
// unimplemented feature.
|
||||
SPV_MSG_ERROR, // Normal error due to user input.
|
||||
SPV_MSG_WARNING, // Warning information.
|
||||
SPV_MSG_INFO, // General information.
|
||||
SPV_MSG_DEBUG, // Debug information.
|
||||
} spv_message_level_t;
|
||||
|
||||
typedef enum spv_endianness_t {
|
||||
SPV_ENDIANNESS_LITTLE,
|
||||
SPV_ENDIANNESS_BIG,
|
||||
SPV_FORCE_32_BIT_ENUM(spv_endianness_t)
|
||||
} spv_endianness_t;
|
||||
|
||||
// The kinds of operands that an instruction may have.
|
||||
//
|
||||
// Some operand types are "concrete". The binary parser uses a concrete
|
||||
// operand type to describe an operand of a parsed instruction.
|
||||
//
|
||||
// The assembler uses all operand types. In addition to determining what
|
||||
// kind of value an operand may be, non-concrete operand types capture the
|
||||
// fact that an operand might be optional (may be absent, or present exactly
|
||||
// once), or might occur zero or more times.
|
||||
//
|
||||
// Sometimes we also need to be able to express the fact that an operand
|
||||
// is a member of an optional tuple of values. In that case the first member
|
||||
// would be optional, and the subsequent members would be required.
|
||||
//
|
||||
// NOTE: Although we don't promise binary compatibility, as a courtesy, please
|
||||
// add new enum values at the end.
|
||||
typedef enum spv_operand_type_t {
|
||||
// A sentinel value.
|
||||
SPV_OPERAND_TYPE_NONE = 0,
|
||||
|
||||
// Set 1: Operands that are IDs.
|
||||
SPV_OPERAND_TYPE_ID,
|
||||
SPV_OPERAND_TYPE_TYPE_ID,
|
||||
SPV_OPERAND_TYPE_RESULT_ID,
|
||||
SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID, // SPIR-V Sec 3.25
|
||||
SPV_OPERAND_TYPE_SCOPE_ID, // SPIR-V Sec 3.27
|
||||
|
||||
// Set 2: Operands that are literal numbers.
|
||||
SPV_OPERAND_TYPE_LITERAL_INTEGER, // Always unsigned 32-bits.
|
||||
// The Instruction argument to OpExtInst. It's an unsigned 32-bit literal
|
||||
// number indicating which instruction to use from an extended instruction
|
||||
// set.
|
||||
SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER,
|
||||
// The Opcode argument to OpSpecConstantOp. It determines the operation
|
||||
// to be performed on constant operands to compute a specialization constant
|
||||
// result.
|
||||
SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER,
|
||||
// A literal number whose format and size are determined by a previous operand
|
||||
// in the same instruction. It's a signed integer, an unsigned integer, or a
|
||||
// floating point number. It also has a specified bit width. The width
|
||||
// may be larger than 32, which would require such a typed literal value to
|
||||
// occupy multiple SPIR-V words.
|
||||
SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER,
|
||||
|
||||
// Set 3: The literal string operand type.
|
||||
SPV_OPERAND_TYPE_LITERAL_STRING,
|
||||
|
||||
// Set 4: Operands that are a single word enumerated value.
|
||||
SPV_OPERAND_TYPE_SOURCE_LANGUAGE, // SPIR-V Sec 3.2
|
||||
SPV_OPERAND_TYPE_EXECUTION_MODEL, // SPIR-V Sec 3.3
|
||||
SPV_OPERAND_TYPE_ADDRESSING_MODEL, // SPIR-V Sec 3.4
|
||||
SPV_OPERAND_TYPE_MEMORY_MODEL, // SPIR-V Sec 3.5
|
||||
SPV_OPERAND_TYPE_EXECUTION_MODE, // SPIR-V Sec 3.6
|
||||
SPV_OPERAND_TYPE_STORAGE_CLASS, // SPIR-V Sec 3.7
|
||||
SPV_OPERAND_TYPE_DIMENSIONALITY, // SPIR-V Sec 3.8
|
||||
SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE, // SPIR-V Sec 3.9
|
||||
SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE, // SPIR-V Sec 3.10
|
||||
SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT, // SPIR-V Sec 3.11
|
||||
SPV_OPERAND_TYPE_IMAGE_CHANNEL_ORDER, // SPIR-V Sec 3.12
|
||||
SPV_OPERAND_TYPE_IMAGE_CHANNEL_DATA_TYPE, // SPIR-V Sec 3.13
|
||||
SPV_OPERAND_TYPE_FP_ROUNDING_MODE, // SPIR-V Sec 3.16
|
||||
SPV_OPERAND_TYPE_LINKAGE_TYPE, // SPIR-V Sec 3.17
|
||||
SPV_OPERAND_TYPE_ACCESS_QUALIFIER, // SPIR-V Sec 3.18
|
||||
SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE, // SPIR-V Sec 3.19
|
||||
SPV_OPERAND_TYPE_DECORATION, // SPIR-V Sec 3.20
|
||||
SPV_OPERAND_TYPE_BUILT_IN, // SPIR-V Sec 3.21
|
||||
SPV_OPERAND_TYPE_GROUP_OPERATION, // SPIR-V Sec 3.28
|
||||
SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS, // SPIR-V Sec 3.29
|
||||
SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO, // SPIR-V Sec 3.30
|
||||
SPV_OPERAND_TYPE_CAPABILITY, // SPIR-V Sec 3.31
|
||||
|
||||
// NOTE: New concrete enum values should be added at the end.
|
||||
|
||||
// Set 5: Operands that are a single word bitmask.
|
||||
// Sometimes a set bit indicates the instruction requires still more operands.
|
||||
SPV_OPERAND_TYPE_IMAGE, // SPIR-V Sec 3.14
|
||||
SPV_OPERAND_TYPE_FP_FAST_MATH_MODE, // SPIR-V Sec 3.15
|
||||
SPV_OPERAND_TYPE_SELECTION_CONTROL, // SPIR-V Sec 3.22
|
||||
SPV_OPERAND_TYPE_LOOP_CONTROL, // SPIR-V Sec 3.23
|
||||
SPV_OPERAND_TYPE_FUNCTION_CONTROL, // SPIR-V Sec 3.24
|
||||
SPV_OPERAND_TYPE_MEMORY_ACCESS, // SPIR-V Sec 3.26
|
||||
SPV_OPERAND_TYPE_FRAGMENT_SHADING_RATE, // SPIR-V Sec 3.FSR
|
||||
|
||||
// NOTE: New concrete enum values should be added at the end.
|
||||
|
||||
// The "optional" and "variable" operand types are only used internally by
|
||||
// the assembler and the binary parser.
|
||||
// There are two categories:
|
||||
// Optional : expands to 0 or 1 operand, like ? in regular expressions.
|
||||
// Variable : expands to 0, 1 or many operands or pairs of operands.
|
||||
// This is similar to * in regular expressions.
|
||||
|
||||
// NOTE: These FIRST_* and LAST_* enum values are DEPRECATED.
|
||||
// The concept of "optional" and "variable" operand types are only intended
|
||||
// for use as an implementation detail of parsing SPIR-V, either in text or
|
||||
// binary form. Instead of using enum ranges, use characteristic function
|
||||
// spvOperandIsConcrete.
|
||||
// The use of enum value ranges in a public API makes it difficult to insert
|
||||
// new values into a range without also breaking binary compatibility.
|
||||
//
|
||||
// Macros for defining bounds on optional and variable operand types.
|
||||
// Any variable operand type is also optional.
|
||||
// TODO(dneto): Remove SPV_OPERAND_TYPE_FIRST_* and SPV_OPERAND_TYPE_LAST_*
|
||||
#define FIRST_OPTIONAL(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_OPTIONAL_TYPE = ENUM
|
||||
#define FIRST_VARIABLE(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_VARIABLE_TYPE = ENUM
|
||||
#define LAST_VARIABLE(ENUM) \
|
||||
ENUM, SPV_OPERAND_TYPE_LAST_VARIABLE_TYPE = ENUM, \
|
||||
SPV_OPERAND_TYPE_LAST_OPTIONAL_TYPE = ENUM
|
||||
|
||||
// An optional operand represents zero or one logical operands.
|
||||
// In an instruction definition, this may only appear at the end of the
|
||||
// operand types.
|
||||
FIRST_OPTIONAL(SPV_OPERAND_TYPE_OPTIONAL_ID),
|
||||
// An optional image operand type.
|
||||
SPV_OPERAND_TYPE_OPTIONAL_IMAGE,
|
||||
// An optional memory access type.
|
||||
SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS,
|
||||
// An optional literal integer.
|
||||
SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER,
|
||||
// An optional literal number, which may be either integer or floating point.
|
||||
SPV_OPERAND_TYPE_OPTIONAL_LITERAL_NUMBER,
|
||||
// Like SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER, but optional, and integral.
|
||||
SPV_OPERAND_TYPE_OPTIONAL_TYPED_LITERAL_INTEGER,
|
||||
// An optional literal string.
|
||||
SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING,
|
||||
// An optional access qualifier
|
||||
SPV_OPERAND_TYPE_OPTIONAL_ACCESS_QUALIFIER,
|
||||
// An optional context-independent value, or CIV. CIVs are tokens that we can
|
||||
// assemble regardless of where they occur -- literals, IDs, immediate
|
||||
// integers, etc.
|
||||
SPV_OPERAND_TYPE_OPTIONAL_CIV,
|
||||
|
||||
// A variable operand represents zero or more logical operands.
|
||||
// In an instruction definition, this may only appear at the end of the
|
||||
// operand types.
|
||||
FIRST_VARIABLE(SPV_OPERAND_TYPE_VARIABLE_ID),
|
||||
SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER,
|
||||
// A sequence of zero or more pairs of (typed literal integer, Id).
|
||||
// Expands to zero or more:
|
||||
// (SPV_OPERAND_TYPE_TYPED_LITERAL_INTEGER, SPV_OPERAND_TYPE_ID)
|
||||
// where the literal number must always be an integer of some sort.
|
||||
SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER_ID,
|
||||
// A sequence of zero or more pairs of (Id, Literal integer)
|
||||
LAST_VARIABLE(SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_INTEGER),
|
||||
|
||||
// The following are concrete enum types from the DebugInfo extended
|
||||
// instruction set.
|
||||
SPV_OPERAND_TYPE_DEBUG_INFO_FLAGS, // DebugInfo Sec 3.2. A mask.
|
||||
SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING, // DebugInfo Sec 3.3
|
||||
SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE, // DebugInfo Sec 3.4
|
||||
SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER, // DebugInfo Sec 3.5
|
||||
SPV_OPERAND_TYPE_DEBUG_OPERATION, // DebugInfo Sec 3.6
|
||||
|
||||
// The following are concrete enum types from the OpenCL.DebugInfo.100
|
||||
// extended instruction set.
|
||||
SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_INFO_FLAGS, // Sec 3.2. A Mask
|
||||
SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING, // Sec 3.3
|
||||
SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_COMPOSITE_TYPE, // Sec 3.4
|
||||
SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_TYPE_QUALIFIER, // Sec 3.5
|
||||
SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_OPERATION, // Sec 3.6
|
||||
SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_IMPORTED_ENTITY, // Sec 3.7
|
||||
|
||||
// The following are concrete enum types from SPV_INTEL_float_controls2
|
||||
// https://github.com/intel/llvm/blob/39fa9b0cbfbae88327118990a05c5b387b56d2ef/sycl/doc/extensions/SPIRV/SPV_INTEL_float_controls2.asciidoc
|
||||
SPV_OPERAND_TYPE_FPDENORM_MODE, // Sec 3.17 FP Denorm Mode
|
||||
SPV_OPERAND_TYPE_FPOPERATION_MODE, // Sec 3.18 FP Operation Mode
|
||||
// A value enum from https://github.com/KhronosGroup/SPIRV-Headers/pull/177
|
||||
SPV_OPERAND_TYPE_QUANTIZATION_MODES,
|
||||
// A value enum from https://github.com/KhronosGroup/SPIRV-Headers/pull/177
|
||||
SPV_OPERAND_TYPE_OVERFLOW_MODES,
|
||||
|
||||
// Concrete operand types for the provisional Vulkan ray tracing feature.
|
||||
SPV_OPERAND_TYPE_RAY_FLAGS, // SPIR-V Sec 3.RF
|
||||
SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION, // SPIR-V Sec 3.RQIntersection
|
||||
SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE, // SPIR-V Sec
|
||||
// 3.RQCommitted
|
||||
SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE, // SPIR-V Sec
|
||||
// 3.RQCandidate
|
||||
|
||||
// Concrete operand types for integer dot product.
|
||||
// Packed vector format
|
||||
SPV_OPERAND_TYPE_PACKED_VECTOR_FORMAT, // SPIR-V Sec 3.x
|
||||
// An optional packed vector format
|
||||
SPV_OPERAND_TYPE_OPTIONAL_PACKED_VECTOR_FORMAT,
|
||||
|
||||
// This is a sentinel value, and does not represent an operand type.
|
||||
// It should come last.
|
||||
SPV_OPERAND_TYPE_NUM_OPERAND_TYPES,
|
||||
|
||||
SPV_FORCE_32_BIT_ENUM(spv_operand_type_t)
|
||||
} spv_operand_type_t;
|
||||
|
||||
// Returns true if the given type is concrete.
|
||||
bool spvOperandIsConcrete(spv_operand_type_t type);
|
||||
|
||||
// Returns true if the given type is concrete and also a mask.
|
||||
bool spvOperandIsConcreteMask(spv_operand_type_t type);
|
||||
|
||||
typedef enum spv_ext_inst_type_t {
|
||||
SPV_EXT_INST_TYPE_NONE = 0,
|
||||
SPV_EXT_INST_TYPE_GLSL_STD_450,
|
||||
SPV_EXT_INST_TYPE_OPENCL_STD,
|
||||
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER,
|
||||
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_TRINARY_MINMAX,
|
||||
SPV_EXT_INST_TYPE_SPV_AMD_GCN_SHADER,
|
||||
SPV_EXT_INST_TYPE_SPV_AMD_SHADER_BALLOT,
|
||||
SPV_EXT_INST_TYPE_DEBUGINFO,
|
||||
SPV_EXT_INST_TYPE_OPENCL_DEBUGINFO_100,
|
||||
SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
|
||||
SPV_EXT_INST_TYPE_NONSEMANTIC_VULKAN_DEBUGINFO_100,
|
||||
|
||||
// Multiple distinct extended instruction set types could return this
|
||||
// value, if they are prefixed with NonSemantic. and are otherwise
|
||||
// unrecognised
|
||||
SPV_EXT_INST_TYPE_NONSEMANTIC_UNKNOWN,
|
||||
|
||||
SPV_FORCE_32_BIT_ENUM(spv_ext_inst_type_t)
|
||||
} spv_ext_inst_type_t;
|
||||
|
||||
// This determines at a high level the kind of a binary-encoded literal
|
||||
// number, but not the bit width.
|
||||
// In principle, these could probably be folded into new entries in
|
||||
// spv_operand_type_t. But then we'd have some special case differences
|
||||
// between the assembler and disassembler.
|
||||
typedef enum spv_number_kind_t {
|
||||
SPV_NUMBER_NONE = 0, // The default for value initialization.
|
||||
SPV_NUMBER_UNSIGNED_INT,
|
||||
SPV_NUMBER_SIGNED_INT,
|
||||
SPV_NUMBER_FLOATING,
|
||||
} spv_number_kind_t;
|
||||
|
||||
typedef enum spv_text_to_binary_options_t {
|
||||
SPV_TEXT_TO_BINARY_OPTION_NONE = SPV_BIT(0),
|
||||
// Numeric IDs in the binary will have the same values as in the source.
|
||||
// Non-numeric IDs are allocated by filling in the gaps, starting with 1
|
||||
// and going up.
|
||||
SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS = SPV_BIT(1),
|
||||
SPV_FORCE_32_BIT_ENUM(spv_text_to_binary_options_t)
|
||||
} spv_text_to_binary_options_t;
|
||||
|
||||
typedef enum spv_binary_to_text_options_t {
|
||||
SPV_BINARY_TO_TEXT_OPTION_NONE = SPV_BIT(0),
|
||||
SPV_BINARY_TO_TEXT_OPTION_PRINT = SPV_BIT(1),
|
||||
SPV_BINARY_TO_TEXT_OPTION_COLOR = SPV_BIT(2),
|
||||
SPV_BINARY_TO_TEXT_OPTION_INDENT = SPV_BIT(3),
|
||||
SPV_BINARY_TO_TEXT_OPTION_SHOW_BYTE_OFFSET = SPV_BIT(4),
|
||||
// Do not output the module header as leading comments in the assembly.
|
||||
SPV_BINARY_TO_TEXT_OPTION_NO_HEADER = SPV_BIT(5),
|
||||
// Use friendly names where possible. The heuristic may expand over
|
||||
// time, but will use common names for scalar types, and debug names from
|
||||
// OpName instructions.
|
||||
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES = SPV_BIT(6),
|
||||
// Add some comments to the generated assembly
|
||||
SPV_BINARY_TO_TEXT_OPTION_COMMENT = SPV_BIT(7),
|
||||
SPV_FORCE_32_BIT_ENUM(spv_binary_to_text_options_t)
|
||||
} spv_binary_to_text_options_t;
|
||||
|
||||
// Constants
|
||||
|
||||
// The default id bound is to the minimum value for the id limit
|
||||
// in the spir-v specification under the section "Universal Limits".
|
||||
const uint32_t kDefaultMaxIdBound = 0x3FFFFF;
|
||||
|
||||
// Structures
|
||||
|
||||
// Information about an operand parsed from a binary SPIR-V module.
|
||||
// Note that the values are not included. You still need access to the binary
|
||||
// to extract the values.
|
||||
typedef struct spv_parsed_operand_t {
|
||||
// Location of the operand, in words from the start of the instruction.
|
||||
uint16_t offset;
|
||||
// Number of words occupied by this operand.
|
||||
uint16_t num_words;
|
||||
// The "concrete" operand type. See the definition of spv_operand_type_t
|
||||
// for details.
|
||||
spv_operand_type_t type;
|
||||
// If type is a literal number type, then number_kind says whether it's
|
||||
// a signed integer, an unsigned integer, or a floating point number.
|
||||
spv_number_kind_t number_kind;
|
||||
// The number of bits for a literal number type.
|
||||
uint32_t number_bit_width;
|
||||
} spv_parsed_operand_t;
|
||||
|
||||
// An instruction parsed from a binary SPIR-V module.
|
||||
typedef struct spv_parsed_instruction_t {
|
||||
// An array of words for this instruction, in native endianness.
|
||||
const uint32_t* words;
|
||||
// The number of words in this instruction.
|
||||
uint16_t num_words;
|
||||
uint16_t opcode;
|
||||
// The extended instruction type, if opcode is OpExtInst. Otherwise
|
||||
// this is the "none" value.
|
||||
spv_ext_inst_type_t ext_inst_type;
|
||||
// The type id, or 0 if this instruction doesn't have one.
|
||||
uint32_t type_id;
|
||||
// The result id, or 0 if this instruction doesn't have one.
|
||||
uint32_t result_id;
|
||||
// The array of parsed operands.
|
||||
const spv_parsed_operand_t* operands;
|
||||
uint16_t num_operands;
|
||||
} spv_parsed_instruction_t;
|
||||
|
||||
typedef struct spv_const_binary_t {
|
||||
const uint32_t* code;
|
||||
const size_t wordCount;
|
||||
} spv_const_binary_t;
|
||||
|
||||
typedef struct spv_binary_t {
|
||||
uint32_t* code;
|
||||
size_t wordCount;
|
||||
} spv_binary_t;
|
||||
|
||||
typedef struct spv_text_t {
|
||||
const char* str;
|
||||
size_t length;
|
||||
} spv_text_t;
|
||||
|
||||
typedef struct spv_position_t {
|
||||
size_t line;
|
||||
size_t column;
|
||||
size_t index;
|
||||
} spv_position_t;
|
||||
|
||||
typedef struct spv_diagnostic_t {
|
||||
spv_position_t position;
|
||||
char* error;
|
||||
bool isTextSource;
|
||||
} spv_diagnostic_t;
|
||||
|
||||
// Opaque struct containing the context used to operate on a SPIR-V module.
|
||||
// Its object is used by various translation API functions.
|
||||
typedef struct spv_context_t spv_context_t;
|
||||
|
||||
typedef struct spv_validator_options_t spv_validator_options_t;
|
||||
|
||||
typedef struct spv_optimizer_options_t spv_optimizer_options_t;
|
||||
|
||||
typedef struct spv_reducer_options_t spv_reducer_options_t;
|
||||
|
||||
typedef struct spv_fuzzer_options_t spv_fuzzer_options_t;
|
||||
|
||||
// Type Definitions
|
||||
|
||||
typedef spv_const_binary_t* spv_const_binary;
|
||||
typedef spv_binary_t* spv_binary;
|
||||
typedef spv_text_t* spv_text;
|
||||
typedef spv_position_t* spv_position;
|
||||
typedef spv_diagnostic_t* spv_diagnostic;
|
||||
typedef const spv_context_t* spv_const_context;
|
||||
typedef spv_context_t* spv_context;
|
||||
typedef spv_validator_options_t* spv_validator_options;
|
||||
typedef const spv_validator_options_t* spv_const_validator_options;
|
||||
typedef spv_optimizer_options_t* spv_optimizer_options;
|
||||
typedef const spv_optimizer_options_t* spv_const_optimizer_options;
|
||||
typedef spv_reducer_options_t* spv_reducer_options;
|
||||
typedef const spv_reducer_options_t* spv_const_reducer_options;
|
||||
typedef spv_fuzzer_options_t* spv_fuzzer_options;
|
||||
typedef const spv_fuzzer_options_t* spv_const_fuzzer_options;
|
||||
|
||||
// Platform API
|
||||
|
||||
// Returns the SPIRV-Tools software version as a null-terminated string.
|
||||
// The contents of the underlying storage is valid for the remainder of
|
||||
// the process.
|
||||
SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionString(void);
|
||||
// Returns a null-terminated string containing the name of the project,
|
||||
// the software version string, and commit details.
|
||||
// The contents of the underlying storage is valid for the remainder of
|
||||
// the process.
|
||||
SPIRV_TOOLS_EXPORT const char* spvSoftwareVersionDetailsString(void);
|
||||
|
||||
// Certain target environments impose additional restrictions on SPIR-V, so it's
|
||||
// often necessary to specify which one applies. SPV_ENV_UNIVERSAL_* implies an
|
||||
// environment-agnostic SPIR-V.
|
||||
//
|
||||
// When an API method needs to derive a SPIR-V version from a target environment
|
||||
// (from the spv_context object), the method will choose the highest version of
|
||||
// SPIR-V supported by the target environment. Examples:
|
||||
// SPV_ENV_VULKAN_1_0 -> SPIR-V 1.0
|
||||
// SPV_ENV_VULKAN_1_1 -> SPIR-V 1.3
|
||||
// SPV_ENV_VULKAN_1_1_SPIRV_1_4 -> SPIR-V 1.4
|
||||
// SPV_ENV_VULKAN_1_2 -> SPIR-V 1.5
|
||||
// Consult the description of API entry points for specific rules.
|
||||
typedef enum {
|
||||
SPV_ENV_UNIVERSAL_1_0, // SPIR-V 1.0 latest revision, no other restrictions.
|
||||
SPV_ENV_VULKAN_1_0, // Vulkan 1.0 latest revision.
|
||||
SPV_ENV_UNIVERSAL_1_1, // SPIR-V 1.1 latest revision, no other restrictions.
|
||||
SPV_ENV_OPENCL_2_1, // OpenCL Full Profile 2.1 latest revision.
|
||||
SPV_ENV_OPENCL_2_2, // OpenCL Full Profile 2.2 latest revision.
|
||||
SPV_ENV_OPENGL_4_0, // OpenGL 4.0 plus GL_ARB_gl_spirv, latest revisions.
|
||||
SPV_ENV_OPENGL_4_1, // OpenGL 4.1 plus GL_ARB_gl_spirv, latest revisions.
|
||||
SPV_ENV_OPENGL_4_2, // OpenGL 4.2 plus GL_ARB_gl_spirv, latest revisions.
|
||||
SPV_ENV_OPENGL_4_3, // OpenGL 4.3 plus GL_ARB_gl_spirv, latest revisions.
|
||||
// There is no variant for OpenGL 4.4.
|
||||
SPV_ENV_OPENGL_4_5, // OpenGL 4.5 plus GL_ARB_gl_spirv, latest revisions.
|
||||
SPV_ENV_UNIVERSAL_1_2, // SPIR-V 1.2, latest revision, no other restrictions.
|
||||
SPV_ENV_OPENCL_1_2, // OpenCL Full Profile 1.2 plus cl_khr_il_program,
|
||||
// latest revision.
|
||||
SPV_ENV_OPENCL_EMBEDDED_1_2, // OpenCL Embedded Profile 1.2 plus
|
||||
// cl_khr_il_program, latest revision.
|
||||
SPV_ENV_OPENCL_2_0, // OpenCL Full Profile 2.0 plus cl_khr_il_program,
|
||||
// latest revision.
|
||||
SPV_ENV_OPENCL_EMBEDDED_2_0, // OpenCL Embedded Profile 2.0 plus
|
||||
// cl_khr_il_program, latest revision.
|
||||
SPV_ENV_OPENCL_EMBEDDED_2_1, // OpenCL Embedded Profile 2.1 latest revision.
|
||||
SPV_ENV_OPENCL_EMBEDDED_2_2, // OpenCL Embedded Profile 2.2 latest revision.
|
||||
SPV_ENV_UNIVERSAL_1_3, // SPIR-V 1.3 latest revision, no other restrictions.
|
||||
SPV_ENV_VULKAN_1_1, // Vulkan 1.1 latest revision.
|
||||
SPV_ENV_WEBGPU_0, // DEPRECATED, may be removed in the future.
|
||||
SPV_ENV_UNIVERSAL_1_4, // SPIR-V 1.4 latest revision, no other restrictions.
|
||||
|
||||
// Vulkan 1.1 with VK_KHR_spirv_1_4, i.e. SPIR-V 1.4 binary.
|
||||
SPV_ENV_VULKAN_1_1_SPIRV_1_4,
|
||||
|
||||
SPV_ENV_UNIVERSAL_1_5, // SPIR-V 1.5 latest revision, no other restrictions.
|
||||
SPV_ENV_VULKAN_1_2, // Vulkan 1.2 latest revision.
|
||||
} spv_target_env;
|
||||
|
||||
// SPIR-V Validator can be parameterized with the following Universal Limits.
|
||||
typedef enum {
|
||||
spv_validator_limit_max_struct_members,
|
||||
spv_validator_limit_max_struct_depth,
|
||||
spv_validator_limit_max_local_variables,
|
||||
spv_validator_limit_max_global_variables,
|
||||
spv_validator_limit_max_switch_branches,
|
||||
spv_validator_limit_max_function_args,
|
||||
spv_validator_limit_max_control_flow_nesting_depth,
|
||||
spv_validator_limit_max_access_chain_indexes,
|
||||
spv_validator_limit_max_id_bound,
|
||||
} spv_validator_limit;
|
||||
|
||||
// Returns a string describing the given SPIR-V target environment.
|
||||
SPIRV_TOOLS_EXPORT const char* spvTargetEnvDescription(spv_target_env env);
|
||||
|
||||
// Parses s into *env and returns true if successful. If unparsable, returns
|
||||
// false and sets *env to SPV_ENV_UNIVERSAL_1_0.
|
||||
SPIRV_TOOLS_EXPORT bool spvParseTargetEnv(const char* s, spv_target_env* env);
|
||||
|
||||
// Determines the target env value with the least features but which enables
|
||||
// the given Vulkan and SPIR-V versions. If such a target is supported, returns
|
||||
// true and writes the value to |env|, otherwise returns false.
|
||||
//
|
||||
// The Vulkan version is given as an unsigned 32-bit number as specified in
|
||||
// Vulkan section "29.2.1 Version Numbers": the major version number appears
|
||||
// in bits 22 to 21, and the minor version is in bits 12 to 21. The SPIR-V
|
||||
// version is given in the SPIR-V version header word: major version in bits
|
||||
// 16 to 23, and minor version in bits 8 to 15.
|
||||
SPIRV_TOOLS_EXPORT bool spvParseVulkanEnv(uint32_t vulkan_ver,
|
||||
uint32_t spirv_ver,
|
||||
spv_target_env* env);
|
||||
|
||||
// Creates a context object for most of the SPIRV-Tools API.
|
||||
// Returns null if env is invalid.
|
||||
//
|
||||
// See specific API calls for how the target environment is interpeted
|
||||
// (particularly assembly and validation).
|
||||
SPIRV_TOOLS_EXPORT spv_context spvContextCreate(spv_target_env env);
|
||||
|
||||
// Destroys the given context object.
|
||||
SPIRV_TOOLS_EXPORT void spvContextDestroy(spv_context context);
|
||||
|
||||
// Creates a Validator options object with default options. Returns a valid
|
||||
// options object. The object remains valid until it is passed into
|
||||
// spvValidatorOptionsDestroy.
|
||||
SPIRV_TOOLS_EXPORT spv_validator_options spvValidatorOptionsCreate(void);
|
||||
|
||||
// Destroys the given Validator options object.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsDestroy(
|
||||
spv_validator_options options);
|
||||
|
||||
// Records the maximum Universal Limit that is considered valid in the given
|
||||
// Validator options object. <options> argument must be a valid options object.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetUniversalLimit(
|
||||
spv_validator_options options, spv_validator_limit limit_type,
|
||||
uint32_t limit);
|
||||
|
||||
// Record whether or not the validator should relax the rules on types for
|
||||
// stores to structs. When relaxed, it will allow a type mismatch as long as
|
||||
// the types are structs with the same layout. Two structs have the same layout
|
||||
// if
|
||||
//
|
||||
// 1) the members of the structs are either the same type or are structs with
|
||||
// same layout, and
|
||||
//
|
||||
// 2) the decorations that affect the memory layout are identical for both
|
||||
// types. Other decorations are not relevant.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxStoreStruct(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Records whether or not the validator should relax the rules on pointer usage
|
||||
// in logical addressing mode.
|
||||
//
|
||||
// When relaxed, it will allow the following usage cases of pointers:
|
||||
// 1) OpVariable allocating an object whose type is a pointer type
|
||||
// 2) OpReturnValue returning a pointer value
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxLogicalPointer(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Records whether or not the validator should relax the rules because it is
|
||||
// expected that the optimizations will make the code legal.
|
||||
//
|
||||
// When relaxed, it will allow the following:
|
||||
// 1) It will allow relaxed logical pointers. Setting this option will also
|
||||
// set that option.
|
||||
// 2) Pointers that are pass as parameters to function calls do not have to
|
||||
// match the storage class of the formal parameter.
|
||||
// 3) Pointers that are actaul parameters on function calls do not have to point
|
||||
// to the same type pointed as the formal parameter. The types just need to
|
||||
// logically match.
|
||||
// 4) GLSLstd450 Interpolate* instructions can have a load of an interpolant
|
||||
// for a first argument.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetBeforeHlslLegalization(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Records whether the validator should use "relaxed" block layout rules.
|
||||
// Relaxed layout rules are described by Vulkan extension
|
||||
// VK_KHR_relaxed_block_layout, and they affect uniform blocks, storage blocks,
|
||||
// and push constants.
|
||||
//
|
||||
// This is enabled by default when targeting Vulkan 1.1 or later.
|
||||
// Relaxed layout is more permissive than the default rules in Vulkan 1.0.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetRelaxBlockLayout(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Records whether the validator should use standard block layout rules for
|
||||
// uniform blocks.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetUniformBufferStandardLayout(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Records whether the validator should use "scalar" block layout rules.
|
||||
// Scalar layout rules are more permissive than relaxed block layout.
|
||||
//
|
||||
// See Vulkan extnesion VK_EXT_scalar_block_layout. The scalar alignment is
|
||||
// defined as follows:
|
||||
// - scalar alignment of a scalar is the scalar size
|
||||
// - scalar alignment of a vector is the scalar alignment of its component
|
||||
// - scalar alignment of a matrix is the scalar alignment of its component
|
||||
// - scalar alignment of an array is the scalar alignment of its element
|
||||
// - scalar alignment of a struct is the max scalar alignment among its
|
||||
// members
|
||||
//
|
||||
// For a struct in Uniform, StorageClass, or PushConstant:
|
||||
// - a member Offset must be a multiple of the member's scalar alignment
|
||||
// - ArrayStride or MatrixStride must be a multiple of the array or matrix
|
||||
// scalar alignment
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetScalarBlockLayout(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Records whether the validator should use "scalar" block layout
|
||||
// rules (as defined above) for Workgroup blocks. See Vulkan
|
||||
// extension VK_KHR_workgroup_memory_explicit_layout.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetWorkgroupScalarBlockLayout(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Records whether or not the validator should skip validating standard
|
||||
// uniform/storage block layout.
|
||||
SPIRV_TOOLS_EXPORT void spvValidatorOptionsSetSkipBlockLayout(
|
||||
spv_validator_options options, bool val);
|
||||
|
||||
// Creates an optimizer options object with default options. Returns a valid
|
||||
// options object. The object remains valid until it is passed into
|
||||
// |spvOptimizerOptionsDestroy|.
|
||||
SPIRV_TOOLS_EXPORT spv_optimizer_options spvOptimizerOptionsCreate(void);
|
||||
|
||||
// Destroys the given optimizer options object.
|
||||
SPIRV_TOOLS_EXPORT void spvOptimizerOptionsDestroy(
|
||||
spv_optimizer_options options);
|
||||
|
||||
// Records whether or not the optimizer should run the validator before
|
||||
// optimizing. If |val| is true, the validator will be run.
|
||||
SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetRunValidator(
|
||||
spv_optimizer_options options, bool val);
|
||||
|
||||
// Records the validator options that should be passed to the validator if it is
|
||||
// run.
|
||||
SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetValidatorOptions(
|
||||
spv_optimizer_options options, spv_validator_options val);
|
||||
|
||||
// Records the maximum possible value for the id bound.
|
||||
SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetMaxIdBound(
|
||||
spv_optimizer_options options, uint32_t val);
|
||||
|
||||
// Records whether all bindings within the module should be preserved.
|
||||
SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetPreserveBindings(
|
||||
spv_optimizer_options options, bool val);
|
||||
|
||||
// Records whether all specialization constants within the module
|
||||
// should be preserved.
|
||||
SPIRV_TOOLS_EXPORT void spvOptimizerOptionsSetPreserveSpecConstants(
|
||||
spv_optimizer_options options, bool val);
|
||||
|
||||
// Creates a reducer options object with default options. Returns a valid
|
||||
// options object. The object remains valid until it is passed into
|
||||
// |spvReducerOptionsDestroy|.
|
||||
SPIRV_TOOLS_EXPORT spv_reducer_options spvReducerOptionsCreate(void);
|
||||
|
||||
// Destroys the given reducer options object.
|
||||
SPIRV_TOOLS_EXPORT void spvReducerOptionsDestroy(spv_reducer_options options);
|
||||
|
||||
// Sets the maximum number of reduction steps that should run before the reducer
|
||||
// gives up.
|
||||
SPIRV_TOOLS_EXPORT void spvReducerOptionsSetStepLimit(
|
||||
spv_reducer_options options, uint32_t step_limit);
|
||||
|
||||
// Sets the fail-on-validation-error option; if true, the reducer will return
|
||||
// kStateInvalid if a reduction step yields a state that fails SPIR-V
|
||||
// validation. Otherwise, an invalid state is treated as uninteresting and the
|
||||
// reduction backtracks and continues.
|
||||
SPIRV_TOOLS_EXPORT void spvReducerOptionsSetFailOnValidationError(
|
||||
spv_reducer_options options, bool fail_on_validation_error);
|
||||
|
||||
// Sets the function that the reducer should target. If set to zero the reducer
|
||||
// will target all functions as well as parts of the module that lie outside
|
||||
// functions. Otherwise the reducer will restrict reduction to the function
|
||||
// with result id |target_function|, which is required to exist.
|
||||
SPIRV_TOOLS_EXPORT void spvReducerOptionsSetTargetFunction(
|
||||
spv_reducer_options options, uint32_t target_function);
|
||||
|
||||
// Creates a fuzzer options object with default options. Returns a valid
|
||||
// options object. The object remains valid until it is passed into
|
||||
// |spvFuzzerOptionsDestroy|.
|
||||
SPIRV_TOOLS_EXPORT spv_fuzzer_options spvFuzzerOptionsCreate(void);
|
||||
|
||||
// Destroys the given fuzzer options object.
|
||||
SPIRV_TOOLS_EXPORT void spvFuzzerOptionsDestroy(spv_fuzzer_options options);
|
||||
|
||||
// Enables running the validator after every transformation is applied during
|
||||
// a replay.
|
||||
SPIRV_TOOLS_EXPORT void spvFuzzerOptionsEnableReplayValidation(
|
||||
spv_fuzzer_options options);
|
||||
|
||||
// Sets the seed with which the random number generator used by the fuzzer
|
||||
// should be initialized.
|
||||
SPIRV_TOOLS_EXPORT void spvFuzzerOptionsSetRandomSeed(
|
||||
spv_fuzzer_options options, uint32_t seed);
|
||||
|
||||
// Sets the range of transformations that should be applied during replay: 0
|
||||
// means all transformations, +N means the first N transformations, -N means all
|
||||
// except the final N transformations.
|
||||
SPIRV_TOOLS_EXPORT void spvFuzzerOptionsSetReplayRange(
|
||||
spv_fuzzer_options options, int32_t replay_range);
|
||||
|
||||
// Sets the maximum number of steps that the shrinker should take before giving
|
||||
// up.
|
||||
SPIRV_TOOLS_EXPORT void spvFuzzerOptionsSetShrinkerStepLimit(
|
||||
spv_fuzzer_options options, uint32_t shrinker_step_limit);
|
||||
|
||||
// Enables running the validator after every pass is applied during a fuzzing
|
||||
// run.
|
||||
SPIRV_TOOLS_EXPORT void spvFuzzerOptionsEnableFuzzerPassValidation(
|
||||
spv_fuzzer_options options);
|
||||
|
||||
// Enables all fuzzer passes during a fuzzing run (instead of a random subset
|
||||
// of passes).
|
||||
SPIRV_TOOLS_EXPORT void spvFuzzerOptionsEnableAllPasses(
|
||||
spv_fuzzer_options options);
|
||||
|
||||
// Encodes the given SPIR-V assembly text to its binary representation. The
|
||||
// length parameter specifies the number of bytes for text. Encoded binary will
|
||||
// be stored into *binary. Any error will be written into *diagnostic if
|
||||
// diagnostic is non-null, otherwise the context's message consumer will be
|
||||
// used. The generated binary is independent of the context and may outlive it.
|
||||
// The SPIR-V binary version is set to the highest version of SPIR-V supported
|
||||
// by the context's target environment.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinary(const spv_const_context context,
|
||||
const char* text,
|
||||
const size_t length,
|
||||
spv_binary* binary,
|
||||
spv_diagnostic* diagnostic);
|
||||
|
||||
// Encodes the given SPIR-V assembly text to its binary representation. Same as
|
||||
// spvTextToBinary but with options. The options parameter is a bit field of
|
||||
// spv_text_to_binary_options_t.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t spvTextToBinaryWithOptions(
|
||||
const spv_const_context context, const char* text, const size_t length,
|
||||
const uint32_t options, spv_binary* binary, spv_diagnostic* diagnostic);
|
||||
|
||||
// Frees an allocated text stream. This is a no-op if the text parameter
|
||||
// is a null pointer.
|
||||
SPIRV_TOOLS_EXPORT void spvTextDestroy(spv_text text);
|
||||
|
||||
// Decodes the given SPIR-V binary representation to its assembly text. The
|
||||
// word_count parameter specifies the number of words for binary. The options
|
||||
// parameter is a bit field of spv_binary_to_text_options_t. Decoded text will
|
||||
// be stored into *text. Any error will be written into *diagnostic if
|
||||
// diagnostic is non-null, otherwise the context's message consumer will be
|
||||
// used.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t spvBinaryToText(const spv_const_context context,
|
||||
const uint32_t* binary,
|
||||
const size_t word_count,
|
||||
const uint32_t options,
|
||||
spv_text* text,
|
||||
spv_diagnostic* diagnostic);
|
||||
|
||||
// Frees a binary stream from memory. This is a no-op if binary is a null
|
||||
// pointer.
|
||||
SPIRV_TOOLS_EXPORT void spvBinaryDestroy(spv_binary binary);
|
||||
|
||||
// Validates a SPIR-V binary for correctness. Any errors will be written into
|
||||
// *diagnostic if diagnostic is non-null, otherwise the context's message
|
||||
// consumer will be used.
|
||||
//
|
||||
// Validate for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the context target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t spvValidate(const spv_const_context context,
|
||||
const spv_const_binary binary,
|
||||
spv_diagnostic* diagnostic);
|
||||
|
||||
// Validates a SPIR-V binary for correctness. Uses the provided Validator
|
||||
// options. Any errors will be written into *diagnostic if diagnostic is
|
||||
// non-null, otherwise the context's message consumer will be used.
|
||||
//
|
||||
// Validate for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the context target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself, or in the validator options.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t spvValidateWithOptions(
|
||||
const spv_const_context context, const spv_const_validator_options options,
|
||||
const spv_const_binary binary, spv_diagnostic* diagnostic);
|
||||
|
||||
// Validates a raw SPIR-V binary for correctness. Any errors will be written
|
||||
// into *diagnostic if diagnostic is non-null, otherwise the context's message
|
||||
// consumer will be used.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t
|
||||
spvValidateBinary(const spv_const_context context, const uint32_t* words,
|
||||
const size_t num_words, spv_diagnostic* diagnostic);
|
||||
|
||||
// Creates a diagnostic object. The position parameter specifies the location in
|
||||
// the text/binary stream. The message parameter, copied into the diagnostic
|
||||
// object, contains the error message to display.
|
||||
SPIRV_TOOLS_EXPORT spv_diagnostic
|
||||
spvDiagnosticCreate(const spv_position position, const char* message);
|
||||
|
||||
// Destroys a diagnostic object. This is a no-op if diagnostic is a null
|
||||
// pointer.
|
||||
SPIRV_TOOLS_EXPORT void spvDiagnosticDestroy(spv_diagnostic diagnostic);
|
||||
|
||||
// Prints the diagnostic to stderr.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t
|
||||
spvDiagnosticPrint(const spv_diagnostic diagnostic);
|
||||
|
||||
// Gets the name of an instruction, without the "Op" prefix.
|
||||
SPIRV_TOOLS_EXPORT const char* spvOpcodeString(const uint32_t opcode);
|
||||
|
||||
// The binary parser interface.
|
||||
|
||||
// A pointer to a function that accepts a parsed SPIR-V header.
|
||||
// The integer arguments are the 32-bit words from the header, as specified
|
||||
// in SPIR-V 1.0 Section 2.3 Table 1.
|
||||
// The function should return SPV_SUCCESS if parsing should continue.
|
||||
typedef spv_result_t (*spv_parsed_header_fn_t)(
|
||||
void* user_data, spv_endianness_t endian, uint32_t magic, uint32_t version,
|
||||
uint32_t generator, uint32_t id_bound, uint32_t reserved);
|
||||
|
||||
// A pointer to a function that accepts a parsed SPIR-V instruction.
|
||||
// The parsed_instruction value is transient: it may be overwritten
|
||||
// or released immediately after the function has returned. That also
|
||||
// applies to the words array member of the parsed instruction. The
|
||||
// function should return SPV_SUCCESS if and only if parsing should
|
||||
// continue.
|
||||
typedef spv_result_t (*spv_parsed_instruction_fn_t)(
|
||||
void* user_data, const spv_parsed_instruction_t* parsed_instruction);
|
||||
|
||||
// Parses a SPIR-V binary, specified as counted sequence of 32-bit words.
|
||||
// Parsing feedback is provided via two callbacks provided as function
|
||||
// pointers. Each callback function pointer can be a null pointer, in
|
||||
// which case it is never called. Otherwise, in a valid parse the
|
||||
// parsed-header callback is called once, and then the parsed-instruction
|
||||
// callback once for each instruction in the stream. The user_data parameter
|
||||
// is supplied as context to the callbacks. Returns SPV_SUCCESS on successful
|
||||
// parse where the callbacks always return SPV_SUCCESS. For an invalid parse,
|
||||
// returns a status code other than SPV_SUCCESS, and if diagnostic is non-null
|
||||
// also emits a diagnostic. If diagnostic is null the context's message consumer
|
||||
// will be used to emit any errors. If a callback returns anything other than
|
||||
// SPV_SUCCESS, then that status code is returned, no further callbacks are
|
||||
// issued, and no additional diagnostics are emitted.
|
||||
SPIRV_TOOLS_EXPORT spv_result_t spvBinaryParse(
|
||||
const spv_const_context context, void* user_data, const uint32_t* words,
|
||||
const size_t num_words, spv_parsed_header_fn_t parse_header,
|
||||
spv_parsed_instruction_fn_t parse_instruction, spv_diagnostic* diagnostic);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_LIBSPIRV_H_
|
||||
@@ -0,0 +1,364 @@
|
||||
// Copyright (c) 2016 Google Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
|
||||
#define INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "spirv-tools/libspirv.h"
|
||||
|
||||
namespace spvtools {
|
||||
|
||||
// Message consumer. The C strings for source and message are only alive for the
|
||||
// specific invocation.
|
||||
using MessageConsumer = std::function<void(
|
||||
spv_message_level_t /* level */, const char* /* source */,
|
||||
const spv_position_t& /* position */, const char* /* message */
|
||||
)>;
|
||||
|
||||
// C++ RAII wrapper around the C context object spv_context.
|
||||
class Context {
|
||||
public:
|
||||
// Constructs a context targeting the given environment |env|.
|
||||
//
|
||||
// See specific API calls for how the target environment is interpeted
|
||||
// (particularly assembly and validation).
|
||||
//
|
||||
// The constructed instance will have an empty message consumer, which just
|
||||
// ignores all messages from the library. Use SetMessageConsumer() to supply
|
||||
// one if messages are of concern.
|
||||
explicit Context(spv_target_env env);
|
||||
|
||||
// Enables move constructor/assignment operations.
|
||||
Context(Context&& other);
|
||||
Context& operator=(Context&& other);
|
||||
|
||||
// Disables copy constructor/assignment operations.
|
||||
Context(const Context&) = delete;
|
||||
Context& operator=(const Context&) = delete;
|
||||
|
||||
// Destructs this instance.
|
||||
~Context();
|
||||
|
||||
// Sets the message consumer to the given |consumer|. The |consumer| will be
|
||||
// invoked once for each message communicated from the library.
|
||||
void SetMessageConsumer(MessageConsumer consumer);
|
||||
|
||||
// Returns the underlying spv_context.
|
||||
spv_context& CContext();
|
||||
const spv_context& CContext() const;
|
||||
|
||||
private:
|
||||
spv_context context_;
|
||||
};
|
||||
|
||||
// A RAII wrapper around a validator options object.
|
||||
class ValidatorOptions {
|
||||
public:
|
||||
ValidatorOptions() : options_(spvValidatorOptionsCreate()) {}
|
||||
~ValidatorOptions() { spvValidatorOptionsDestroy(options_); }
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_validator_options() const { return options_; }
|
||||
|
||||
// Sets a limit.
|
||||
void SetUniversalLimit(spv_validator_limit limit_type, uint32_t limit) {
|
||||
spvValidatorOptionsSetUniversalLimit(options_, limit_type, limit);
|
||||
}
|
||||
|
||||
void SetRelaxStructStore(bool val) {
|
||||
spvValidatorOptionsSetRelaxStoreStruct(options_, val);
|
||||
}
|
||||
|
||||
// Enables VK_KHR_relaxed_block_layout when validating standard
|
||||
// uniform/storage buffer/push-constant layout. If true, disables
|
||||
// scalar block layout rules.
|
||||
void SetRelaxBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetRelaxBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Enables VK_KHR_uniform_buffer_standard_layout when validating standard
|
||||
// uniform layout. If true, disables scalar block layout rules.
|
||||
void SetUniformBufferStandardLayout(bool val) {
|
||||
spvValidatorOptionsSetUniformBufferStandardLayout(options_, val);
|
||||
}
|
||||
|
||||
// Enables VK_EXT_scalar_block_layout when validating standard
|
||||
// uniform/storage buffer/push-constant layout. If true, disables
|
||||
// relaxed block layout rules.
|
||||
void SetScalarBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetScalarBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Enables scalar layout when validating Workgroup blocks. See
|
||||
// VK_KHR_workgroup_memory_explicit_layout.
|
||||
void SetWorkgroupScalarBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetWorkgroupScalarBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Skips validating standard uniform/storage buffer/push-constant layout.
|
||||
void SetSkipBlockLayout(bool val) {
|
||||
spvValidatorOptionsSetSkipBlockLayout(options_, val);
|
||||
}
|
||||
|
||||
// Records whether or not the validator should relax the rules on pointer
|
||||
// usage in logical addressing mode.
|
||||
//
|
||||
// When relaxed, it will allow the following usage cases of pointers:
|
||||
// 1) OpVariable allocating an object whose type is a pointer type
|
||||
// 2) OpReturnValue returning a pointer value
|
||||
void SetRelaxLogicalPointer(bool val) {
|
||||
spvValidatorOptionsSetRelaxLogicalPointer(options_, val);
|
||||
}
|
||||
|
||||
// Records whether or not the validator should relax the rules because it is
|
||||
// expected that the optimizations will make the code legal.
|
||||
//
|
||||
// When relaxed, it will allow the following:
|
||||
// 1) It will allow relaxed logical pointers. Setting this option will also
|
||||
// set that option.
|
||||
// 2) Pointers that are pass as parameters to function calls do not have to
|
||||
// match the storage class of the formal parameter.
|
||||
// 3) Pointers that are actaul parameters on function calls do not have to
|
||||
// point to the same type pointed as the formal parameter. The types just
|
||||
// need to logically match.
|
||||
// 4) GLSLstd450 Interpolate* instructions can have a load of an interpolant
|
||||
// for a first argument.
|
||||
void SetBeforeHlslLegalization(bool val) {
|
||||
spvValidatorOptionsSetBeforeHlslLegalization(options_, val);
|
||||
}
|
||||
|
||||
private:
|
||||
spv_validator_options options_;
|
||||
};
|
||||
|
||||
// A C++ wrapper around an optimization options object.
|
||||
class OptimizerOptions {
|
||||
public:
|
||||
OptimizerOptions() : options_(spvOptimizerOptionsCreate()) {}
|
||||
~OptimizerOptions() { spvOptimizerOptionsDestroy(options_); }
|
||||
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_optimizer_options() const { return options_; }
|
||||
|
||||
// Records whether or not the optimizer should run the validator before
|
||||
// optimizing. If |run| is true, the validator will be run.
|
||||
void set_run_validator(bool run) {
|
||||
spvOptimizerOptionsSetRunValidator(options_, run);
|
||||
}
|
||||
|
||||
// Records the validator options that should be passed to the validator if it
|
||||
// is run.
|
||||
void set_validator_options(const ValidatorOptions& val_options) {
|
||||
spvOptimizerOptionsSetValidatorOptions(options_, val_options);
|
||||
}
|
||||
|
||||
// Records the maximum possible value for the id bound.
|
||||
void set_max_id_bound(uint32_t new_bound) {
|
||||
spvOptimizerOptionsSetMaxIdBound(options_, new_bound);
|
||||
}
|
||||
|
||||
// Records whether all bindings within the module should be preserved.
|
||||
void set_preserve_bindings(bool preserve_bindings) {
|
||||
spvOptimizerOptionsSetPreserveBindings(options_, preserve_bindings);
|
||||
}
|
||||
|
||||
// Records whether all specialization constants within the module
|
||||
// should be preserved.
|
||||
void set_preserve_spec_constants(bool preserve_spec_constants) {
|
||||
spvOptimizerOptionsSetPreserveSpecConstants(options_,
|
||||
preserve_spec_constants);
|
||||
}
|
||||
|
||||
private:
|
||||
spv_optimizer_options options_;
|
||||
};
|
||||
|
||||
// A C++ wrapper around a reducer options object.
|
||||
class ReducerOptions {
|
||||
public:
|
||||
ReducerOptions() : options_(spvReducerOptionsCreate()) {}
|
||||
~ReducerOptions() { spvReducerOptionsDestroy(options_); }
|
||||
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_reducer_options() const { // NOLINT(google-explicit-constructor)
|
||||
return options_;
|
||||
}
|
||||
|
||||
// See spvReducerOptionsSetStepLimit.
|
||||
void set_step_limit(uint32_t step_limit) {
|
||||
spvReducerOptionsSetStepLimit(options_, step_limit);
|
||||
}
|
||||
|
||||
// See spvReducerOptionsSetFailOnValidationError.
|
||||
void set_fail_on_validation_error(bool fail_on_validation_error) {
|
||||
spvReducerOptionsSetFailOnValidationError(options_,
|
||||
fail_on_validation_error);
|
||||
}
|
||||
|
||||
// See spvReducerOptionsSetTargetFunction.
|
||||
void set_target_function(uint32_t target_function) {
|
||||
spvReducerOptionsSetTargetFunction(options_, target_function);
|
||||
}
|
||||
|
||||
private:
|
||||
spv_reducer_options options_;
|
||||
};
|
||||
|
||||
// A C++ wrapper around a fuzzer options object.
|
||||
class FuzzerOptions {
|
||||
public:
|
||||
FuzzerOptions() : options_(spvFuzzerOptionsCreate()) {}
|
||||
~FuzzerOptions() { spvFuzzerOptionsDestroy(options_); }
|
||||
|
||||
// Allow implicit conversion to the underlying object.
|
||||
operator spv_fuzzer_options() const { // NOLINT(google-explicit-constructor)
|
||||
return options_;
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsEnableReplayValidation.
|
||||
void enable_replay_validation() {
|
||||
spvFuzzerOptionsEnableReplayValidation(options_);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsSetRandomSeed.
|
||||
void set_random_seed(uint32_t seed) {
|
||||
spvFuzzerOptionsSetRandomSeed(options_, seed);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsSetReplayRange.
|
||||
void set_replay_range(int32_t replay_range) {
|
||||
spvFuzzerOptionsSetReplayRange(options_, replay_range);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsSetShrinkerStepLimit.
|
||||
void set_shrinker_step_limit(uint32_t shrinker_step_limit) {
|
||||
spvFuzzerOptionsSetShrinkerStepLimit(options_, shrinker_step_limit);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsEnableFuzzerPassValidation.
|
||||
void enable_fuzzer_pass_validation() {
|
||||
spvFuzzerOptionsEnableFuzzerPassValidation(options_);
|
||||
}
|
||||
|
||||
// See spvFuzzerOptionsEnableAllPasses.
|
||||
void enable_all_passes() { spvFuzzerOptionsEnableAllPasses(options_); }
|
||||
|
||||
private:
|
||||
spv_fuzzer_options options_;
|
||||
};
|
||||
|
||||
// C++ interface for SPIRV-Tools functionalities. It wraps the context
|
||||
// (including target environment and the corresponding SPIR-V grammar) and
|
||||
// provides methods for assembling, disassembling, and validating.
|
||||
//
|
||||
// Instances of this class provide basic thread-safety guarantee.
|
||||
class SpirvTools {
|
||||
public:
|
||||
enum {
|
||||
// Default assembling option used by assemble():
|
||||
kDefaultAssembleOption = SPV_TEXT_TO_BINARY_OPTION_NONE,
|
||||
|
||||
// Default disassembling option used by Disassemble():
|
||||
// * Avoid prefix comments from decoding the SPIR-V module header, and
|
||||
// * Use friendly names for variables.
|
||||
kDefaultDisassembleOption = SPV_BINARY_TO_TEXT_OPTION_NO_HEADER |
|
||||
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES
|
||||
};
|
||||
|
||||
// Constructs an instance targeting the given environment |env|.
|
||||
//
|
||||
// The constructed instance will have an empty message consumer, which just
|
||||
// ignores all messages from the library. Use SetMessageConsumer() to supply
|
||||
// one if messages are of concern.
|
||||
explicit SpirvTools(spv_target_env env);
|
||||
|
||||
// Disables copy/move constructor/assignment operations.
|
||||
SpirvTools(const SpirvTools&) = delete;
|
||||
SpirvTools(SpirvTools&&) = delete;
|
||||
SpirvTools& operator=(const SpirvTools&) = delete;
|
||||
SpirvTools& operator=(SpirvTools&&) = delete;
|
||||
|
||||
// Destructs this instance.
|
||||
~SpirvTools();
|
||||
|
||||
// Sets the message consumer to the given |consumer|. The |consumer| will be
|
||||
// invoked once for each message communicated from the library.
|
||||
void SetMessageConsumer(MessageConsumer consumer);
|
||||
|
||||
// Assembles the given assembly |text| and writes the result to |binary|.
|
||||
// Returns true on successful assembling. |binary| will be kept untouched if
|
||||
// assembling is unsuccessful.
|
||||
// The SPIR-V binary version is set to the highest version of SPIR-V supported
|
||||
// by the target environment with which this SpirvTools object was created.
|
||||
bool Assemble(const std::string& text, std::vector<uint32_t>* binary,
|
||||
uint32_t options = kDefaultAssembleOption) const;
|
||||
// |text_size| specifies the number of bytes in |text|. A terminating null
|
||||
// character is not required to present in |text| as long as |text| is valid.
|
||||
// The SPIR-V binary version is set to the highest version of SPIR-V supported
|
||||
// by the target environment with which this SpirvTools object was created.
|
||||
bool Assemble(const char* text, size_t text_size,
|
||||
std::vector<uint32_t>* binary,
|
||||
uint32_t options = kDefaultAssembleOption) const;
|
||||
|
||||
// Disassembles the given SPIR-V |binary| with the given |options| and writes
|
||||
// the assembly to |text|. Returns true on successful disassembling. |text|
|
||||
// will be kept untouched if diassembling is unsuccessful.
|
||||
bool Disassemble(const std::vector<uint32_t>& binary, std::string* text,
|
||||
uint32_t options = kDefaultDisassembleOption) const;
|
||||
// |binary_size| specifies the number of words in |binary|.
|
||||
bool Disassemble(const uint32_t* binary, size_t binary_size,
|
||||
std::string* text,
|
||||
uint32_t options = kDefaultDisassembleOption) const;
|
||||
|
||||
// Validates the given SPIR-V |binary|. Returns true if no issues are found.
|
||||
// Otherwise, returns false and communicates issues via the message consumer
|
||||
// registered.
|
||||
// Validates for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself.
|
||||
bool Validate(const std::vector<uint32_t>& binary) const;
|
||||
// Like the previous overload, but provides the binary as a pointer and size:
|
||||
// |binary_size| specifies the number of words in |binary|.
|
||||
// Validates for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself.
|
||||
bool Validate(const uint32_t* binary, size_t binary_size) const;
|
||||
// Like the previous overload, but takes an options object.
|
||||
// Validates for SPIR-V spec rules for the SPIR-V version named in the
|
||||
// binary's header (at word offset 1). Additionally, if the target
|
||||
// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
// client API version, to the extent that it is verifiable from data in the
|
||||
// binary itself, or in the validator options.
|
||||
bool Validate(const uint32_t* binary, size_t binary_size,
|
||||
spv_validator_options options) const;
|
||||
|
||||
// Was this object successfully constructed.
|
||||
bool IsValid() const;
|
||||
|
||||
private:
|
||||
struct Impl; // Opaque struct for holding the data fields used by this class.
|
||||
std::unique_ptr<Impl> impl_; // Unique pointer to implementation data.
|
||||
};
|
||||
|
||||
} // namespace spvtools
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright (c) 2017 Pierre Moreau
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef INCLUDE_SPIRV_TOOLS_LINKER_HPP_
|
||||
#define INCLUDE_SPIRV_TOOLS_LINKER_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "libspirv.hpp"
|
||||
|
||||
namespace spvtools {
|
||||
|
||||
class LinkerOptions {
|
||||
public:
|
||||
LinkerOptions()
|
||||
: create_library_(false),
|
||||
verify_ids_(false),
|
||||
allow_partial_linkage_(false) {}
|
||||
|
||||
// Returns whether a library or an executable should be produced by the
|
||||
// linking phase.
|
||||
//
|
||||
// All exported symbols are kept when creating a library, whereas they will
|
||||
// be removed when creating an executable.
|
||||
// The returned value will be true if creating a library, and false if
|
||||
// creating an executable.
|
||||
bool GetCreateLibrary() const { return create_library_; }
|
||||
|
||||
// Sets whether a library or an executable should be produced.
|
||||
void SetCreateLibrary(bool create_library) {
|
||||
create_library_ = create_library;
|
||||
}
|
||||
|
||||
// Returns whether to verify the uniqueness of the unique ids in the merged
|
||||
// context.
|
||||
bool GetVerifyIds() const { return verify_ids_; }
|
||||
|
||||
// Sets whether to verify the uniqueness of the unique ids in the merged
|
||||
// context.
|
||||
void SetVerifyIds(bool verify_ids) { verify_ids_ = verify_ids; }
|
||||
|
||||
// Returns whether to allow for imported symbols to have no corresponding
|
||||
// exported symbols
|
||||
bool GetAllowPartialLinkage() const { return allow_partial_linkage_; }
|
||||
|
||||
// Sets whether to allow for imported symbols to have no corresponding
|
||||
// exported symbols
|
||||
void SetAllowPartialLinkage(bool allow_partial_linkage) {
|
||||
allow_partial_linkage_ = allow_partial_linkage;
|
||||
}
|
||||
|
||||
private:
|
||||
bool create_library_;
|
||||
bool verify_ids_;
|
||||
bool allow_partial_linkage_;
|
||||
};
|
||||
|
||||
// Links one or more SPIR-V modules into a new SPIR-V module. That is, combine
|
||||
// several SPIR-V modules into one, resolving link dependencies between them.
|
||||
//
|
||||
// At least one binary has to be provided in |binaries|. Those binaries do not
|
||||
// have to be valid, but they should be at least parseable.
|
||||
// The functions can fail due to the following:
|
||||
// * The given context was not initialised using `spvContextCreate()`;
|
||||
// * No input modules were given;
|
||||
// * One or more of those modules were not parseable;
|
||||
// * The input modules used different addressing or memory models;
|
||||
// * The ID or global variable number limit were exceeded;
|
||||
// * Some entry points were defined multiple times;
|
||||
// * Some imported symbols did not have an exported counterpart;
|
||||
// * Possibly other reasons.
|
||||
spv_result_t Link(const Context& context,
|
||||
const std::vector<std::vector<uint32_t>>& binaries,
|
||||
std::vector<uint32_t>* linked_binary,
|
||||
const LinkerOptions& options = LinkerOptions());
|
||||
spv_result_t Link(const Context& context, const uint32_t* const* binaries,
|
||||
const size_t* binary_sizes, size_t num_binaries,
|
||||
std::vector<uint32_t>* linked_binary,
|
||||
const LinkerOptions& options = LinkerOptions());
|
||||
|
||||
} // namespace spvtools
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_LINKER_HPP_
|
||||
@@ -0,0 +1,859 @@
|
||||
// Copyright (c) 2016 Google Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
|
||||
#define INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "libspirv.hpp"
|
||||
|
||||
namespace spvtools {
|
||||
|
||||
namespace opt {
|
||||
class Pass;
|
||||
}
|
||||
|
||||
// C++ interface for SPIR-V optimization functionalities. It wraps the context
|
||||
// (including target environment and the corresponding SPIR-V grammar) and
|
||||
// provides methods for registering optimization passes and optimizing.
|
||||
//
|
||||
// Instances of this class provides basic thread-safety guarantee.
|
||||
class Optimizer {
|
||||
public:
|
||||
// The token for an optimization pass. It is returned via one of the
|
||||
// Create*Pass() standalone functions at the end of this header file and
|
||||
// consumed by the RegisterPass() method. Tokens are one-time objects that
|
||||
// only support move; copying is not allowed.
|
||||
struct PassToken {
|
||||
struct Impl; // Opaque struct for holding inernal data.
|
||||
|
||||
PassToken(std::unique_ptr<Impl>);
|
||||
|
||||
// Tokens for built-in passes should be created using Create*Pass functions
|
||||
// below; for out-of-tree passes, use this constructor instead.
|
||||
// Note that this API isn't guaranteed to be stable and may change without
|
||||
// preserving source or binary compatibility in the future.
|
||||
PassToken(std::unique_ptr<opt::Pass>&& pass);
|
||||
|
||||
// Tokens can only be moved. Copying is disabled.
|
||||
PassToken(const PassToken&) = delete;
|
||||
PassToken(PassToken&&);
|
||||
PassToken& operator=(const PassToken&) = delete;
|
||||
PassToken& operator=(PassToken&&);
|
||||
|
||||
~PassToken();
|
||||
|
||||
std::unique_ptr<Impl> impl_; // Unique pointer to internal data.
|
||||
};
|
||||
|
||||
// Constructs an instance with the given target |env|, which is used to decode
|
||||
// the binaries to be optimized later.
|
||||
//
|
||||
// The instance will have an empty message consumer, which ignores all
|
||||
// messages from the library. Use SetMessageConsumer() to supply a consumer
|
||||
// if messages are of concern.
|
||||
explicit Optimizer(spv_target_env env);
|
||||
|
||||
// Disables copy/move constructor/assignment operations.
|
||||
Optimizer(const Optimizer&) = delete;
|
||||
Optimizer(Optimizer&&) = delete;
|
||||
Optimizer& operator=(const Optimizer&) = delete;
|
||||
Optimizer& operator=(Optimizer&&) = delete;
|
||||
|
||||
// Destructs this instance.
|
||||
~Optimizer();
|
||||
|
||||
// Sets the message consumer to the given |consumer|. The |consumer| will be
|
||||
// invoked once for each message communicated from the library.
|
||||
void SetMessageConsumer(MessageConsumer consumer);
|
||||
|
||||
// Returns a reference to the registered message consumer.
|
||||
const MessageConsumer& consumer() const;
|
||||
|
||||
// Registers the given |pass| to this optimizer. Passes will be run in the
|
||||
// exact order of registration. The token passed in will be consumed by this
|
||||
// method.
|
||||
Optimizer& RegisterPass(PassToken&& pass);
|
||||
|
||||
// Registers passes that attempt to improve performance of generated code.
|
||||
// This sequence of passes is subject to constant review and will change
|
||||
// from time to time.
|
||||
Optimizer& RegisterPerformancePasses();
|
||||
|
||||
// Registers passes that attempt to improve the size of generated code.
|
||||
// This sequence of passes is subject to constant review and will change
|
||||
// from time to time.
|
||||
Optimizer& RegisterSizePasses();
|
||||
|
||||
// Registers passes that attempt to legalize the generated code.
|
||||
//
|
||||
// Note: this recipe is specially designed for legalizing SPIR-V. It should be
|
||||
// used by compilers after translating HLSL source code literally. It should
|
||||
// *not* be used by general workloads for performance or size improvement.
|
||||
//
|
||||
// This sequence of passes is subject to constant review and will change
|
||||
// from time to time.
|
||||
Optimizer& RegisterLegalizationPasses();
|
||||
|
||||
// Register passes specified in the list of |flags|. Each flag must be a
|
||||
// string of a form accepted by Optimizer::FlagHasValidForm().
|
||||
//
|
||||
// If the list of flags contains an invalid entry, it returns false and an
|
||||
// error message is emitted to the MessageConsumer object (use
|
||||
// Optimizer::SetMessageConsumer to define a message consumer, if needed).
|
||||
//
|
||||
// If all the passes are registered successfully, it returns true.
|
||||
bool RegisterPassesFromFlags(const std::vector<std::string>& flags);
|
||||
|
||||
// Registers the optimization pass associated with |flag|. This only accepts
|
||||
// |flag| values of the form "--pass_name[=pass_args]". If no such pass
|
||||
// exists, it returns false. Otherwise, the pass is registered and it returns
|
||||
// true.
|
||||
//
|
||||
// The following flags have special meaning:
|
||||
//
|
||||
// -O: Registers all performance optimization passes
|
||||
// (Optimizer::RegisterPerformancePasses)
|
||||
//
|
||||
// -Os: Registers all size optimization passes
|
||||
// (Optimizer::RegisterSizePasses).
|
||||
//
|
||||
// --legalize-hlsl: Registers all passes that legalize SPIR-V generated by an
|
||||
// HLSL front-end.
|
||||
bool RegisterPassFromFlag(const std::string& flag);
|
||||
|
||||
// Validates that |flag| has a valid format. Strings accepted:
|
||||
//
|
||||
// --pass_name[=pass_args]
|
||||
// -O
|
||||
// -Os
|
||||
//
|
||||
// If |flag| takes one of the forms above, it returns true. Otherwise, it
|
||||
// returns false.
|
||||
bool FlagHasValidForm(const std::string& flag) const;
|
||||
|
||||
// Allows changing, after creation time, the target environment to be
|
||||
// optimized for and validated. Should be called before calling Run().
|
||||
void SetTargetEnv(const spv_target_env env);
|
||||
|
||||
// Optimizes the given SPIR-V module |original_binary| and writes the
|
||||
// optimized binary into |optimized_binary|. The optimized binary uses
|
||||
// the same SPIR-V version as the original binary.
|
||||
//
|
||||
// Returns true on successful optimization, whether or not the module is
|
||||
// modified. Returns false if |original_binary| fails to validate or if errors
|
||||
// occur when processing |original_binary| using any of the registered passes.
|
||||
// In that case, no further passes are executed and the contents in
|
||||
// |optimized_binary| may be invalid.
|
||||
//
|
||||
// By default, the binary is validated before any transforms are performed,
|
||||
// and optionally after each transform. Validation uses SPIR-V spec rules
|
||||
// for the SPIR-V version named in the binary's header (at word offset 1).
|
||||
// Additionally, if the target environment is a client API (such as
|
||||
// Vulkan 1.1), then validate for that client API version, to the extent
|
||||
// that it is verifiable from data in the binary itself.
|
||||
//
|
||||
// It's allowed to alias |original_binary| to the start of |optimized_binary|.
|
||||
bool Run(const uint32_t* original_binary, size_t original_binary_size,
|
||||
std::vector<uint32_t>* optimized_binary) const;
|
||||
|
||||
// DEPRECATED: Same as above, except passes |options| to the validator when
|
||||
// trying to validate the binary. If |skip_validation| is true, then the
|
||||
// caller is guaranteeing that |original_binary| is valid, and the validator
|
||||
// will not be run. The |max_id_bound| is the limit on the max id in the
|
||||
// module.
|
||||
bool Run(const uint32_t* original_binary, const size_t original_binary_size,
|
||||
std::vector<uint32_t>* optimized_binary,
|
||||
const ValidatorOptions& options, bool skip_validation) const;
|
||||
|
||||
// Same as above, except it takes an options object. See the documentation
|
||||
// for |OptimizerOptions| to see which options can be set.
|
||||
//
|
||||
// By default, the binary is validated before any transforms are performed,
|
||||
// and optionally after each transform. Validation uses SPIR-V spec rules
|
||||
// for the SPIR-V version named in the binary's header (at word offset 1).
|
||||
// Additionally, if the target environment is a client API (such as
|
||||
// Vulkan 1.1), then validate for that client API version, to the extent
|
||||
// that it is verifiable from data in the binary itself, or from the
|
||||
// validator options set on the optimizer options.
|
||||
bool Run(const uint32_t* original_binary, const size_t original_binary_size,
|
||||
std::vector<uint32_t>* optimized_binary,
|
||||
const spv_optimizer_options opt_options) const;
|
||||
|
||||
// Returns a vector of strings with all the pass names added to this
|
||||
// optimizer's pass manager. These strings are valid until the associated
|
||||
// pass manager is destroyed.
|
||||
std::vector<const char*> GetPassNames() const;
|
||||
|
||||
// Sets the option to print the disassembly before each pass and after the
|
||||
// last pass. If |out| is null, then no output is generated. Otherwise,
|
||||
// output is sent to the |out| output stream.
|
||||
Optimizer& SetPrintAll(std::ostream* out);
|
||||
|
||||
// Sets the option to print the resource utilization of each pass. If |out|
|
||||
// is null, then no output is generated. Otherwise, output is sent to the
|
||||
// |out| output stream.
|
||||
Optimizer& SetTimeReport(std::ostream* out);
|
||||
|
||||
// Sets the option to validate the module after each pass.
|
||||
Optimizer& SetValidateAfterAll(bool validate);
|
||||
|
||||
private:
|
||||
struct Impl; // Opaque struct for holding internal data.
|
||||
std::unique_ptr<Impl> impl_; // Unique pointer to internal data.
|
||||
};
|
||||
|
||||
// Creates a null pass.
|
||||
// A null pass does nothing to the SPIR-V module to be optimized.
|
||||
Optimizer::PassToken CreateNullPass();
|
||||
|
||||
// Creates a strip-debug-info pass.
|
||||
// A strip-debug-info pass removes all debug instructions (as documented in
|
||||
// Section 3.32.2 of the SPIR-V spec) of the SPIR-V module to be optimized.
|
||||
Optimizer::PassToken CreateStripDebugInfoPass();
|
||||
|
||||
// Creates a strip-reflect-info pass.
|
||||
// A strip-reflect-info pass removes all reflections instructions.
|
||||
// For now, this is limited to removing decorations defined in
|
||||
// SPV_GOOGLE_hlsl_functionality1. The coverage may expand in
|
||||
// the future.
|
||||
Optimizer::PassToken CreateStripReflectInfoPass();
|
||||
|
||||
// Creates an eliminate-dead-functions pass.
|
||||
// An eliminate-dead-functions pass will remove all functions that are not in
|
||||
// the call trees rooted at entry points and exported functions. These
|
||||
// functions are not needed because they will never be called.
|
||||
Optimizer::PassToken CreateEliminateDeadFunctionsPass();
|
||||
|
||||
// Creates an eliminate-dead-members pass.
|
||||
// An eliminate-dead-members pass will remove all unused members of structures.
|
||||
// This will not affect the data layout of the remaining members.
|
||||
Optimizer::PassToken CreateEliminateDeadMembersPass();
|
||||
|
||||
// Creates a set-spec-constant-default-value pass from a mapping from spec-ids
|
||||
// to the default values in the form of string.
|
||||
// A set-spec-constant-default-value pass sets the default values for the
|
||||
// spec constants that have SpecId decorations (i.e., those defined by
|
||||
// OpSpecConstant{|True|False} instructions).
|
||||
Optimizer::PassToken CreateSetSpecConstantDefaultValuePass(
|
||||
const std::unordered_map<uint32_t, std::string>& id_value_map);
|
||||
|
||||
// Creates a set-spec-constant-default-value pass from a mapping from spec-ids
|
||||
// to the default values in the form of bit pattern.
|
||||
// A set-spec-constant-default-value pass sets the default values for the
|
||||
// spec constants that have SpecId decorations (i.e., those defined by
|
||||
// OpSpecConstant{|True|False} instructions).
|
||||
Optimizer::PassToken CreateSetSpecConstantDefaultValuePass(
|
||||
const std::unordered_map<uint32_t, std::vector<uint32_t>>& id_value_map);
|
||||
|
||||
// Creates a flatten-decoration pass.
|
||||
// A flatten-decoration pass replaces grouped decorations with equivalent
|
||||
// ungrouped decorations. That is, it replaces each OpDecorationGroup
|
||||
// instruction and associated OpGroupDecorate and OpGroupMemberDecorate
|
||||
// instructions with equivalent OpDecorate and OpMemberDecorate instructions.
|
||||
// The pass does not attempt to preserve debug information for instructions
|
||||
// it removes.
|
||||
Optimizer::PassToken CreateFlattenDecorationPass();
|
||||
|
||||
// Creates a freeze-spec-constant-value pass.
|
||||
// A freeze-spec-constant pass specializes the value of spec constants to
|
||||
// their default values. This pass only processes the spec constants that have
|
||||
// SpecId decorations (defined by OpSpecConstant, OpSpecConstantTrue, or
|
||||
// OpSpecConstantFalse instructions) and replaces them with their normal
|
||||
// counterparts (OpConstant, OpConstantTrue, or OpConstantFalse). The
|
||||
// corresponding SpecId annotation instructions will also be removed. This
|
||||
// pass does not fold the newly added normal constants and does not process
|
||||
// other spec constants defined by OpSpecConstantComposite or
|
||||
// OpSpecConstantOp.
|
||||
Optimizer::PassToken CreateFreezeSpecConstantValuePass();
|
||||
|
||||
// Creates a fold-spec-constant-op-and-composite pass.
|
||||
// A fold-spec-constant-op-and-composite pass folds spec constants defined by
|
||||
// OpSpecConstantOp or OpSpecConstantComposite instruction, to normal Constants
|
||||
// defined by OpConstantTrue, OpConstantFalse, OpConstant, OpConstantNull, or
|
||||
// OpConstantComposite instructions. Note that spec constants defined with
|
||||
// OpSpecConstant, OpSpecConstantTrue, or OpSpecConstantFalse instructions are
|
||||
// not handled, as these instructions indicate their value are not determined
|
||||
// and can be changed in future. A spec constant is foldable if all of its
|
||||
// value(s) can be determined from the module. E.g., an integer spec constant
|
||||
// defined with OpSpecConstantOp instruction can be folded if its value won't
|
||||
// change later. This pass will replace the original OpSpecContantOp instruction
|
||||
// with an OpConstant instruction. When folding composite spec constants,
|
||||
// new instructions may be inserted to define the components of the composite
|
||||
// constant first, then the original spec constants will be replaced by
|
||||
// OpConstantComposite instructions.
|
||||
//
|
||||
// There are some operations not supported yet:
|
||||
// OpSConvert, OpFConvert, OpQuantizeToF16 and
|
||||
// all the operations under Kernel capability.
|
||||
// TODO(qining): Add support for the operations listed above.
|
||||
Optimizer::PassToken CreateFoldSpecConstantOpAndCompositePass();
|
||||
|
||||
// Creates a unify-constant pass.
|
||||
// A unify-constant pass de-duplicates the constants. Constants with the exact
|
||||
// same value and identical form will be unified and only one constant will
|
||||
// be kept for each unique pair of type and value.
|
||||
// There are several cases not handled by this pass:
|
||||
// 1) Constants defined by OpConstantNull instructions (null constants) and
|
||||
// constants defined by OpConstantFalse, OpConstant or OpConstantComposite
|
||||
// with value 0 (zero-valued normal constants) are not considered equivalent.
|
||||
// So null constants won't be used to replace zero-valued normal constants,
|
||||
// vice versa.
|
||||
// 2) Whenever there are decorations to the constant's result id id, the
|
||||
// constant won't be handled, which means, it won't be used to replace any
|
||||
// other constants, neither can other constants replace it.
|
||||
// 3) NaN in float point format with different bit patterns are not unified.
|
||||
Optimizer::PassToken CreateUnifyConstantPass();
|
||||
|
||||
// Creates a eliminate-dead-constant pass.
|
||||
// A eliminate-dead-constant pass removes dead constants, including normal
|
||||
// contants defined by OpConstant, OpConstantComposite, OpConstantTrue, or
|
||||
// OpConstantFalse and spec constants defined by OpSpecConstant,
|
||||
// OpSpecConstantComposite, OpSpecConstantTrue, OpSpecConstantFalse or
|
||||
// OpSpecConstantOp.
|
||||
Optimizer::PassToken CreateEliminateDeadConstantPass();
|
||||
|
||||
// Creates a strength-reduction pass.
|
||||
// A strength-reduction pass will look for opportunities to replace an
|
||||
// instruction with an equivalent and less expensive one. For example,
|
||||
// multiplying by a power of 2 can be replaced by a bit shift.
|
||||
Optimizer::PassToken CreateStrengthReductionPass();
|
||||
|
||||
// Creates a block merge pass.
|
||||
// This pass searches for blocks with a single Branch to a block with no
|
||||
// other predecessors and merges the blocks into a single block. Continue
|
||||
// blocks and Merge blocks are not candidates for the second block.
|
||||
//
|
||||
// The pass is most useful after Dead Branch Elimination, which can leave
|
||||
// such sequences of blocks. Merging them makes subsequent passes more
|
||||
// effective, such as single block local store-load elimination.
|
||||
//
|
||||
// While this pass reduces the number of occurrences of this sequence, at
|
||||
// this time it does not guarantee all such sequences are eliminated.
|
||||
//
|
||||
// Presence of phi instructions can inhibit this optimization. Handling
|
||||
// these is left for future improvements.
|
||||
Optimizer::PassToken CreateBlockMergePass();
|
||||
|
||||
// Creates an exhaustive inline pass.
|
||||
// An exhaustive inline pass attempts to exhaustively inline all function
|
||||
// calls in all functions in an entry point call tree. The intent is to enable,
|
||||
// albeit through brute force, analysis and optimization across function
|
||||
// calls by subsequent optimization passes. As the inlining is exhaustive,
|
||||
// there is no attempt to optimize for size or runtime performance. Functions
|
||||
// that are not in the call tree of an entry point are not changed.
|
||||
Optimizer::PassToken CreateInlineExhaustivePass();
|
||||
|
||||
// Creates an opaque inline pass.
|
||||
// An opaque inline pass inlines all function calls in all functions in all
|
||||
// entry point call trees where the called function contains an opaque type
|
||||
// in either its parameter types or return type. An opaque type is currently
|
||||
// defined as Image, Sampler or SampledImage. The intent is to enable, albeit
|
||||
// through brute force, analysis and optimization across these function calls
|
||||
// by subsequent passes in order to remove the storing of opaque types which is
|
||||
// not legal in Vulkan. Functions that are not in the call tree of an entry
|
||||
// point are not changed.
|
||||
Optimizer::PassToken CreateInlineOpaquePass();
|
||||
|
||||
// Creates a single-block local variable load/store elimination pass.
|
||||
// For every entry point function, do single block memory optimization of
|
||||
// function variables referenced only with non-access-chain loads and stores.
|
||||
// For each targeted variable load, if previous store to that variable in the
|
||||
// block, replace the load's result id with the value id of the store.
|
||||
// If previous load within the block, replace the current load's result id
|
||||
// with the previous load's result id. In either case, delete the current
|
||||
// load. Finally, check if any remaining stores are useless, and delete store
|
||||
// and variable if possible.
|
||||
//
|
||||
// The presence of access chain references and function calls can inhibit
|
||||
// the above optimization.
|
||||
//
|
||||
// Only modules with relaxed logical addressing (see opt/instruction.h) are
|
||||
// currently processed.
|
||||
//
|
||||
// This pass is most effective if preceeded by Inlining and
|
||||
// LocalAccessChainConvert. This pass will reduce the work needed to be done
|
||||
// by LocalSingleStoreElim and LocalMultiStoreElim.
|
||||
//
|
||||
// Only functions in the call tree of an entry point are processed.
|
||||
Optimizer::PassToken CreateLocalSingleBlockLoadStoreElimPass();
|
||||
|
||||
// Create dead branch elimination pass.
|
||||
// For each entry point function, this pass will look for SelectionMerge
|
||||
// BranchConditionals with constant condition and convert to a Branch to
|
||||
// the indicated label. It will delete resulting dead blocks.
|
||||
//
|
||||
// For all phi functions in merge block, replace all uses with the id
|
||||
// corresponding to the living predecessor.
|
||||
//
|
||||
// Note that some branches and blocks may be left to avoid creating invalid
|
||||
// control flow. Improving this is left to future work.
|
||||
//
|
||||
// This pass is most effective when preceeded by passes which eliminate
|
||||
// local loads and stores, effectively propagating constant values where
|
||||
// possible.
|
||||
Optimizer::PassToken CreateDeadBranchElimPass();
|
||||
|
||||
// Creates an SSA local variable load/store elimination pass.
|
||||
// For every entry point function, eliminate all loads and stores of function
|
||||
// scope variables only referenced with non-access-chain loads and stores.
|
||||
// Eliminate the variables as well.
|
||||
//
|
||||
// The presence of access chain references and function calls can inhibit
|
||||
// the above optimization.
|
||||
//
|
||||
// Only shader modules with relaxed logical addressing (see opt/instruction.h)
|
||||
// are currently processed. Currently modules with any extensions enabled are
|
||||
// not processed. This is left for future work.
|
||||
//
|
||||
// This pass is most effective if preceeded by Inlining and
|
||||
// LocalAccessChainConvert. LocalSingleStoreElim and LocalSingleBlockElim
|
||||
// will reduce the work that this pass has to do.
|
||||
Optimizer::PassToken CreateLocalMultiStoreElimPass();
|
||||
|
||||
// Creates a local access chain conversion pass.
|
||||
// A local access chain conversion pass identifies all function scope
|
||||
// variables which are accessed only with loads, stores and access chains
|
||||
// with constant indices. It then converts all loads and stores of such
|
||||
// variables into equivalent sequences of loads, stores, extracts and inserts.
|
||||
//
|
||||
// This pass only processes entry point functions. It currently only converts
|
||||
// non-nested, non-ptr access chains. It does not process modules with
|
||||
// non-32-bit integer types present. Optional memory access options on loads
|
||||
// and stores are ignored as we are only processing function scope variables.
|
||||
//
|
||||
// This pass unifies access to these variables to a single mode and simplifies
|
||||
// subsequent analysis and elimination of these variables along with their
|
||||
// loads and stores allowing values to propagate to their points of use where
|
||||
// possible.
|
||||
Optimizer::PassToken CreateLocalAccessChainConvertPass();
|
||||
|
||||
// Creates a local single store elimination pass.
|
||||
// For each entry point function, this pass eliminates loads and stores for
|
||||
// function scope variable that are stored to only once, where possible. Only
|
||||
// whole variable loads and stores are eliminated; access-chain references are
|
||||
// not optimized. Replace all loads of such variables with the value that is
|
||||
// stored and eliminate any resulting dead code.
|
||||
//
|
||||
// Currently, the presence of access chains and function calls can inhibit this
|
||||
// pass, however the Inlining and LocalAccessChainConvert passes can make it
|
||||
// more effective. In additional, many non-load/store memory operations are
|
||||
// not supported and will prohibit optimization of a function. Support of
|
||||
// these operations are future work.
|
||||
//
|
||||
// Only shader modules with relaxed logical addressing (see opt/instruction.h)
|
||||
// are currently processed.
|
||||
//
|
||||
// This pass will reduce the work needed to be done by LocalSingleBlockElim
|
||||
// and LocalMultiStoreElim and can improve the effectiveness of other passes
|
||||
// such as DeadBranchElimination which depend on values for their analysis.
|
||||
Optimizer::PassToken CreateLocalSingleStoreElimPass();
|
||||
|
||||
// Creates an insert/extract elimination pass.
|
||||
// This pass processes each entry point function in the module, searching for
|
||||
// extracts on a sequence of inserts. It further searches the sequence for an
|
||||
// insert with indices identical to the extract. If such an insert can be
|
||||
// found before hitting a conflicting insert, the extract's result id is
|
||||
// replaced with the id of the values from the insert.
|
||||
//
|
||||
// Besides removing extracts this pass enables subsequent dead code elimination
|
||||
// passes to delete the inserts. This pass performs best after access chains are
|
||||
// converted to inserts and extracts and local loads and stores are eliminated.
|
||||
Optimizer::PassToken CreateInsertExtractElimPass();
|
||||
|
||||
// Creates a dead insert elimination pass.
|
||||
// This pass processes each entry point function in the module, searching for
|
||||
// unreferenced inserts into composite types. These are most often unused
|
||||
// stores to vector components. They are unused because they are never
|
||||
// referenced, or because there is another insert to the same component between
|
||||
// the insert and the reference. After removing the inserts, dead code
|
||||
// elimination is attempted on the inserted values.
|
||||
//
|
||||
// This pass performs best after access chains are converted to inserts and
|
||||
// extracts and local loads and stores are eliminated. While executing this
|
||||
// pass can be advantageous on its own, it is also advantageous to execute
|
||||
// this pass after CreateInsertExtractPass() as it will remove any unused
|
||||
// inserts created by that pass.
|
||||
Optimizer::PassToken CreateDeadInsertElimPass();
|
||||
|
||||
// Create aggressive dead code elimination pass
|
||||
// This pass eliminates unused code from the module. In addition,
|
||||
// it detects and eliminates code which may have spurious uses but which do
|
||||
// not contribute to the output of the function. The most common cause of
|
||||
// such code sequences is summations in loops whose result is no longer used
|
||||
// due to dead code elimination. This optimization has additional compile
|
||||
// time cost over standard dead code elimination.
|
||||
//
|
||||
// This pass only processes entry point functions. It also only processes
|
||||
// shaders with relaxed logical addressing (see opt/instruction.h). It
|
||||
// currently will not process functions with function calls. Unreachable
|
||||
// functions are deleted.
|
||||
//
|
||||
// This pass will be made more effective by first running passes that remove
|
||||
// dead control flow and inlines function calls.
|
||||
//
|
||||
// This pass can be especially useful after running Local Access Chain
|
||||
// Conversion, which tends to cause cycles of dead code to be left after
|
||||
// Store/Load elimination passes are completed. These cycles cannot be
|
||||
// eliminated with standard dead code elimination.
|
||||
Optimizer::PassToken CreateAggressiveDCEPass();
|
||||
|
||||
// Creates a remove-unused-interface-variables pass.
|
||||
// Removes variables referenced on the |OpEntryPoint| instruction that are not
|
||||
// referenced in the entry point function or any function in its call tree. Note
|
||||
// that this could cause the shader interface to no longer match other shader
|
||||
// stages.
|
||||
Optimizer::PassToken CreateRemoveUnusedInterfaceVariablesPass();
|
||||
|
||||
// Creates an empty pass.
|
||||
// This is deprecated and will be removed.
|
||||
// TODO(jaebaek): remove this pass after handling glslang's broken unit tests.
|
||||
// https://github.com/KhronosGroup/glslang/pull/2440
|
||||
Optimizer::PassToken CreatePropagateLineInfoPass();
|
||||
|
||||
// Creates an empty pass.
|
||||
// This is deprecated and will be removed.
|
||||
// TODO(jaebaek): remove this pass after handling glslang's broken unit tests.
|
||||
// https://github.com/KhronosGroup/glslang/pull/2440
|
||||
Optimizer::PassToken CreateRedundantLineInfoElimPass();
|
||||
|
||||
// Creates a compact ids pass.
|
||||
// The pass remaps result ids to a compact and gapless range starting from %1.
|
||||
Optimizer::PassToken CreateCompactIdsPass();
|
||||
|
||||
// Creates a remove duplicate pass.
|
||||
// This pass removes various duplicates:
|
||||
// * duplicate capabilities;
|
||||
// * duplicate extended instruction imports;
|
||||
// * duplicate types;
|
||||
// * duplicate decorations.
|
||||
Optimizer::PassToken CreateRemoveDuplicatesPass();
|
||||
|
||||
// Creates a CFG cleanup pass.
|
||||
// This pass removes cruft from the control flow graph of functions that are
|
||||
// reachable from entry points and exported functions. It currently includes the
|
||||
// following functionality:
|
||||
//
|
||||
// - Removal of unreachable basic blocks.
|
||||
Optimizer::PassToken CreateCFGCleanupPass();
|
||||
|
||||
// Create dead variable elimination pass.
|
||||
// This pass will delete module scope variables, along with their decorations,
|
||||
// that are not referenced.
|
||||
Optimizer::PassToken CreateDeadVariableEliminationPass();
|
||||
|
||||
// create merge return pass.
|
||||
// changes functions that have multiple return statements so they have a single
|
||||
// return statement.
|
||||
//
|
||||
// for structured control flow it is assumed that the only unreachable blocks in
|
||||
// the function are trivial merge and continue blocks.
|
||||
//
|
||||
// a trivial merge block contains the label and an opunreachable instructions,
|
||||
// nothing else. a trivial continue block contain a label and an opbranch to
|
||||
// the header, nothing else.
|
||||
//
|
||||
// these conditions are guaranteed to be met after running dead-branch
|
||||
// elimination.
|
||||
Optimizer::PassToken CreateMergeReturnPass();
|
||||
|
||||
// Create value numbering pass.
|
||||
// This pass will look for instructions in the same basic block that compute the
|
||||
// same value, and remove the redundant ones.
|
||||
Optimizer::PassToken CreateLocalRedundancyEliminationPass();
|
||||
|
||||
// Create LICM pass.
|
||||
// This pass will look for invariant instructions inside loops and hoist them to
|
||||
// the loops preheader.
|
||||
Optimizer::PassToken CreateLoopInvariantCodeMotionPass();
|
||||
|
||||
// Creates a loop fission pass.
|
||||
// This pass will split all top level loops whose register pressure exceedes the
|
||||
// given |threshold|.
|
||||
Optimizer::PassToken CreateLoopFissionPass(size_t threshold);
|
||||
|
||||
// Creates a loop fusion pass.
|
||||
// This pass will look for adjacent loops that are compatible and legal to be
|
||||
// fused. The fuse all such loops as long as the register usage for the fused
|
||||
// loop stays under the threshold defined by |max_registers_per_loop|.
|
||||
Optimizer::PassToken CreateLoopFusionPass(size_t max_registers_per_loop);
|
||||
|
||||
// Creates a loop peeling pass.
|
||||
// This pass will look for conditions inside a loop that are true or false only
|
||||
// for the N first or last iteration. For loop with such condition, those N
|
||||
// iterations of the loop will be executed outside of the main loop.
|
||||
// To limit code size explosion, the loop peeling can only happen if the code
|
||||
// size growth for each loop is under |code_growth_threshold|.
|
||||
Optimizer::PassToken CreateLoopPeelingPass();
|
||||
|
||||
// Creates a loop unswitch pass.
|
||||
// This pass will look for loop independent branch conditions and move the
|
||||
// condition out of the loop and version the loop based on the taken branch.
|
||||
// Works best after LICM and local multi store elimination pass.
|
||||
Optimizer::PassToken CreateLoopUnswitchPass();
|
||||
|
||||
// Create global value numbering pass.
|
||||
// This pass will look for instructions where the same value is computed on all
|
||||
// paths leading to the instruction. Those instructions are deleted.
|
||||
Optimizer::PassToken CreateRedundancyEliminationPass();
|
||||
|
||||
// Create scalar replacement pass.
|
||||
// This pass replaces composite function scope variables with variables for each
|
||||
// element if those elements are accessed individually. The parameter is a
|
||||
// limit on the number of members in the composite variable that the pass will
|
||||
// consider replacing.
|
||||
Optimizer::PassToken CreateScalarReplacementPass(uint32_t size_limit = 100);
|
||||
|
||||
// Create a private to local pass.
|
||||
// This pass looks for variables delcared in the private storage class that are
|
||||
// used in only one function. Those variables are moved to the function storage
|
||||
// class in the function that they are used.
|
||||
Optimizer::PassToken CreatePrivateToLocalPass();
|
||||
|
||||
// Creates a conditional constant propagation (CCP) pass.
|
||||
// This pass implements the SSA-CCP algorithm in
|
||||
//
|
||||
// Constant propagation with conditional branches,
|
||||
// Wegman and Zadeck, ACM TOPLAS 13(2):181-210.
|
||||
//
|
||||
// Constant values in expressions and conditional jumps are folded and
|
||||
// simplified. This may reduce code size by removing never executed jump targets
|
||||
// and computations with constant operands.
|
||||
Optimizer::PassToken CreateCCPPass();
|
||||
|
||||
// Creates a workaround driver bugs pass. This pass attempts to work around
|
||||
// a known driver bug (issue #1209) by identifying the bad code sequences and
|
||||
// rewriting them.
|
||||
//
|
||||
// Current workaround: Avoid OpUnreachable instructions in loops.
|
||||
Optimizer::PassToken CreateWorkaround1209Pass();
|
||||
|
||||
// Creates a pass that converts if-then-else like assignments into OpSelect.
|
||||
Optimizer::PassToken CreateIfConversionPass();
|
||||
|
||||
// Creates a pass that will replace instructions that are not valid for the
|
||||
// current shader stage by constants. Has no effect on non-shader modules.
|
||||
Optimizer::PassToken CreateReplaceInvalidOpcodePass();
|
||||
|
||||
// Creates a pass that simplifies instructions using the instruction folder.
|
||||
Optimizer::PassToken CreateSimplificationPass();
|
||||
|
||||
// Create loop unroller pass.
|
||||
// Creates a pass to unroll loops which have the "Unroll" loop control
|
||||
// mask set. The loops must meet a specific criteria in order to be unrolled
|
||||
// safely this criteria is checked before doing the unroll by the
|
||||
// LoopUtils::CanPerformUnroll method. Any loop that does not meet the criteria
|
||||
// won't be unrolled. See CanPerformUnroll LoopUtils.h for more information.
|
||||
Optimizer::PassToken CreateLoopUnrollPass(bool fully_unroll, int factor = 0);
|
||||
|
||||
// Create the SSA rewrite pass.
|
||||
// This pass converts load/store operations on function local variables into
|
||||
// operations on SSA IDs. This allows SSA optimizers to act on these variables.
|
||||
// Only variables that are local to the function and of supported types are
|
||||
// processed (see IsSSATargetVar for details).
|
||||
Optimizer::PassToken CreateSSARewritePass();
|
||||
|
||||
// Create pass to convert relaxed precision instructions to half precision.
|
||||
// This pass converts as many relaxed float32 arithmetic operations to half as
|
||||
// possible. It converts any float32 operands to half if needed. It converts
|
||||
// any resulting half precision values back to float32 as needed. No variables
|
||||
// are changed. No image operations are changed.
|
||||
//
|
||||
// Best if run after function scope store/load and composite operation
|
||||
// eliminations are run. Also best if followed by instruction simplification,
|
||||
// redundancy elimination and DCE.
|
||||
Optimizer::PassToken CreateConvertRelaxedToHalfPass();
|
||||
|
||||
// Create relax float ops pass.
|
||||
// This pass decorates all float32 result instructions with RelaxedPrecision
|
||||
// if not already so decorated.
|
||||
Optimizer::PassToken CreateRelaxFloatOpsPass();
|
||||
|
||||
// Create copy propagate arrays pass.
|
||||
// This pass looks to copy propagate memory references for arrays. It looks
|
||||
// for specific code patterns to recognize array copies.
|
||||
Optimizer::PassToken CreateCopyPropagateArraysPass();
|
||||
|
||||
// Create a vector dce pass.
|
||||
// This pass looks for components of vectors that are unused, and removes them
|
||||
// from the vector. Note this would still leave around lots of dead code that
|
||||
// a pass of ADCE will be able to remove.
|
||||
Optimizer::PassToken CreateVectorDCEPass();
|
||||
|
||||
// Create a pass to reduce the size of loads.
|
||||
// This pass looks for loads of structures where only a few of its members are
|
||||
// used. It replaces the loads feeding an OpExtract with an OpAccessChain and
|
||||
// a load of the specific elements.
|
||||
Optimizer::PassToken CreateReduceLoadSizePass();
|
||||
|
||||
// Create a pass to combine chained access chains.
|
||||
// This pass looks for access chains fed by other access chains and combines
|
||||
// them into a single instruction where possible.
|
||||
Optimizer::PassToken CreateCombineAccessChainsPass();
|
||||
|
||||
// Create a pass to instrument bindless descriptor checking
|
||||
// This pass instruments all bindless references to check that descriptor
|
||||
// array indices are inbounds, and if the descriptor indexing extension is
|
||||
// enabled, that the descriptor has been initialized. If the reference is
|
||||
// invalid, a record is written to the debug output buffer (if space allows)
|
||||
// and a null value is returned. This pass is designed to support bindless
|
||||
// validation in the Vulkan validation layers.
|
||||
//
|
||||
// TODO(greg-lunarg): Add support for buffer references. Currently only does
|
||||
// checking for image references.
|
||||
//
|
||||
// Dead code elimination should be run after this pass as the original,
|
||||
// potentially invalid code is not removed and could cause undefined behavior,
|
||||
// including crashes. It may also be beneficial to run Simplification
|
||||
// (ie Constant Propagation), DeadBranchElim and BlockMerge after this pass to
|
||||
// optimize instrument code involving the testing of compile-time constants.
|
||||
// It is also generally recommended that this pass (and all
|
||||
// instrumentation passes) be run after any legalization and optimization
|
||||
// passes. This will give better analysis for the instrumentation and avoid
|
||||
// potentially de-optimizing the instrument code, for example, inlining
|
||||
// the debug record output function throughout the module.
|
||||
//
|
||||
// The instrumentation will read and write buffers in debug
|
||||
// descriptor set |desc_set|. It will write |shader_id| in each output record
|
||||
// to identify the shader module which generated the record.
|
||||
// |desc_length_enable| controls instrumentation of runtime descriptor array
|
||||
// references, |desc_init_enable| controls instrumentation of descriptor
|
||||
// initialization checking, and |buff_oob_enable| controls instrumentation
|
||||
// of storage and uniform buffer bounds checking, all of which require input
|
||||
// buffer support. |texbuff_oob_enable| controls instrumentation of texel
|
||||
// buffers, which does not require input buffer support.
|
||||
Optimizer::PassToken CreateInstBindlessCheckPass(
|
||||
uint32_t desc_set, uint32_t shader_id, bool desc_length_enable = false,
|
||||
bool desc_init_enable = false, bool buff_oob_enable = false,
|
||||
bool texbuff_oob_enable = false);
|
||||
|
||||
// Create a pass to instrument physical buffer address checking
|
||||
// This pass instruments all physical buffer address references to check that
|
||||
// all referenced bytes fall in a valid buffer. If the reference is
|
||||
// invalid, a record is written to the debug output buffer (if space allows)
|
||||
// and a null value is returned. This pass is designed to support buffer
|
||||
// address validation in the Vulkan validation layers.
|
||||
//
|
||||
// Dead code elimination should be run after this pass as the original,
|
||||
// potentially invalid code is not removed and could cause undefined behavior,
|
||||
// including crashes. Instruction simplification would likely also be
|
||||
// beneficial. It is also generally recommended that this pass (and all
|
||||
// instrumentation passes) be run after any legalization and optimization
|
||||
// passes. This will give better analysis for the instrumentation and avoid
|
||||
// potentially de-optimizing the instrument code, for example, inlining
|
||||
// the debug record output function throughout the module.
|
||||
//
|
||||
// The instrumentation will read and write buffers in debug
|
||||
// descriptor set |desc_set|. It will write |shader_id| in each output record
|
||||
// to identify the shader module which generated the record.
|
||||
Optimizer::PassToken CreateInstBuffAddrCheckPass(uint32_t desc_set,
|
||||
uint32_t shader_id);
|
||||
|
||||
// Create a pass to instrument OpDebugPrintf instructions.
|
||||
// This pass replaces all OpDebugPrintf instructions with instructions to write
|
||||
// a record containing the string id and the all specified values into a special
|
||||
// printf output buffer (if space allows). This pass is designed to support
|
||||
// the printf validation in the Vulkan validation layers.
|
||||
//
|
||||
// The instrumentation will write buffers in debug descriptor set |desc_set|.
|
||||
// It will write |shader_id| in each output record to identify the shader
|
||||
// module which generated the record.
|
||||
Optimizer::PassToken CreateInstDebugPrintfPass(uint32_t desc_set,
|
||||
uint32_t shader_id);
|
||||
|
||||
// Create a pass to upgrade to the VulkanKHR memory model.
|
||||
// This pass upgrades the Logical GLSL450 memory model to Logical VulkanKHR.
|
||||
// Additionally, it modifies memory, image, atomic and barrier operations to
|
||||
// conform to that model's requirements.
|
||||
Optimizer::PassToken CreateUpgradeMemoryModelPass();
|
||||
|
||||
// Create a pass to do code sinking. Code sinking is a transformation
|
||||
// where an instruction is moved into a more deeply nested construct.
|
||||
Optimizer::PassToken CreateCodeSinkingPass();
|
||||
|
||||
// Create a pass to fix incorrect storage classes. In order to make code
|
||||
// generation simpler, DXC may generate code where the storage classes do not
|
||||
// match up correctly. This pass will fix the errors that it can.
|
||||
Optimizer::PassToken CreateFixStorageClassPass();
|
||||
|
||||
// Creates a graphics robust access pass.
|
||||
//
|
||||
// This pass injects code to clamp indexed accesses to buffers and internal
|
||||
// arrays, providing guarantees satisfying Vulkan's robustBufferAccess rules.
|
||||
//
|
||||
// TODO(dneto): Clamps coordinates and sample index for pointer calculations
|
||||
// into storage images (OpImageTexelPointer). For an cube array image, it
|
||||
// assumes the maximum layer count times 6 is at most 0xffffffff.
|
||||
//
|
||||
// NOTE: This pass will fail with a message if:
|
||||
// - The module is not a Shader module.
|
||||
// - The module declares VariablePointers, VariablePointersStorageBuffer, or
|
||||
// RuntimeDescriptorArrayEXT capabilities.
|
||||
// - The module uses an addressing model other than Logical
|
||||
// - Access chain indices are wider than 64 bits.
|
||||
// - Access chain index for a struct is not an OpConstant integer or is out
|
||||
// of range. (The module is already invalid if that is the case.)
|
||||
// - TODO(dneto): The OpImageTexelPointer coordinate component is not 32-bits
|
||||
// wide.
|
||||
//
|
||||
// NOTE: Access chain indices are always treated as signed integers. So
|
||||
// if an array has a fixed size of more than 2^31 elements, then elements
|
||||
// from 2^31 and above are never accessible with a 32-bit index,
|
||||
// signed or unsigned. For this case, this pass will clamp the index
|
||||
// between 0 and at 2^31-1, inclusive.
|
||||
// Similarly, if an array has more then 2^15 element and is accessed with
|
||||
// a 16-bit index, then elements from 2^15 and above are not accessible.
|
||||
// In this case, the pass will clamp the index between 0 and 2^15-1
|
||||
// inclusive.
|
||||
Optimizer::PassToken CreateGraphicsRobustAccessPass();
|
||||
|
||||
// Create descriptor scalar replacement pass.
|
||||
// This pass replaces every array variable |desc| that has a DescriptorSet and
|
||||
// Binding decorations with a new variable for each element of the array.
|
||||
// Suppose |desc| was bound at binding |b|. Then the variable corresponding to
|
||||
// |desc[i]| will have binding |b+i|. The descriptor set will be the same. It
|
||||
// is assumed that no other variable already has a binding that will used by one
|
||||
// of the new variables. If not, the pass will generate invalid Spir-V. All
|
||||
// accesses to |desc| must be OpAccessChain instructions with a literal index
|
||||
// for the first index.
|
||||
Optimizer::PassToken CreateDescriptorScalarReplacementPass();
|
||||
|
||||
// Create a pass to replace each OpKill instruction with a function call to a
|
||||
// function that has a single OpKill. Also replace each OpTerminateInvocation
|
||||
// instruction with a function call to a function that has a single
|
||||
// OpTerminateInvocation. This allows more code to be inlined.
|
||||
Optimizer::PassToken CreateWrapOpKillPass();
|
||||
|
||||
// Replaces the extensions VK_AMD_shader_ballot,VK_AMD_gcn_shader, and
|
||||
// VK_AMD_shader_trinary_minmax with equivalent code using core instructions and
|
||||
// capabilities.
|
||||
Optimizer::PassToken CreateAmdExtToKhrPass();
|
||||
|
||||
// Replaces the internal version of GLSLstd450 InterpolateAt* extended
|
||||
// instructions with the externally valid version. The internal version allows
|
||||
// an OpLoad of the interpolant for the first argument. This pass removes the
|
||||
// OpLoad and replaces it with its pointer. glslang and possibly other
|
||||
// frontends will create the internal version for HLSL. This pass will be part
|
||||
// of HLSL legalization and should be called after interpolants have been
|
||||
// propagated into their final positions.
|
||||
Optimizer::PassToken CreateInterpolateFixupPass();
|
||||
|
||||
} // namespace spvtools
|
||||
|
||||
#endif // INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
** Copyright (c) 2014-2016 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
** of this software and/or associated documentation files (the "Materials"),
|
||||
** to deal in the Materials without restriction, including without limitation
|
||||
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
** and/or sell copies of the Materials, and to permit persons to whom the
|
||||
** Materials are 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 Materials.
|
||||
**
|
||||
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
|
||||
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
|
||||
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
|
||||
**
|
||||
** THE MATERIALS ARE 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 MATERIALS OR THE USE OR OTHER DEALINGS
|
||||
** IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#ifndef GLSLstd450_H
|
||||
#define GLSLstd450_H
|
||||
|
||||
static const int GLSLstd450Version = 100;
|
||||
static const int GLSLstd450Revision = 3;
|
||||
|
||||
enum GLSLstd450 {
|
||||
GLSLstd450Bad = 0, // Don't use
|
||||
|
||||
GLSLstd450Round = 1,
|
||||
GLSLstd450RoundEven = 2,
|
||||
GLSLstd450Trunc = 3,
|
||||
GLSLstd450FAbs = 4,
|
||||
GLSLstd450SAbs = 5,
|
||||
GLSLstd450FSign = 6,
|
||||
GLSLstd450SSign = 7,
|
||||
GLSLstd450Floor = 8,
|
||||
GLSLstd450Ceil = 9,
|
||||
GLSLstd450Fract = 10,
|
||||
|
||||
GLSLstd450Radians = 11,
|
||||
GLSLstd450Degrees = 12,
|
||||
GLSLstd450Sin = 13,
|
||||
GLSLstd450Cos = 14,
|
||||
GLSLstd450Tan = 15,
|
||||
GLSLstd450Asin = 16,
|
||||
GLSLstd450Acos = 17,
|
||||
GLSLstd450Atan = 18,
|
||||
GLSLstd450Sinh = 19,
|
||||
GLSLstd450Cosh = 20,
|
||||
GLSLstd450Tanh = 21,
|
||||
GLSLstd450Asinh = 22,
|
||||
GLSLstd450Acosh = 23,
|
||||
GLSLstd450Atanh = 24,
|
||||
GLSLstd450Atan2 = 25,
|
||||
|
||||
GLSLstd450Pow = 26,
|
||||
GLSLstd450Exp = 27,
|
||||
GLSLstd450Log = 28,
|
||||
GLSLstd450Exp2 = 29,
|
||||
GLSLstd450Log2 = 30,
|
||||
GLSLstd450Sqrt = 31,
|
||||
GLSLstd450InverseSqrt = 32,
|
||||
|
||||
GLSLstd450Determinant = 33,
|
||||
GLSLstd450MatrixInverse = 34,
|
||||
|
||||
GLSLstd450Modf = 35, // second operand needs an OpVariable to write to
|
||||
GLSLstd450ModfStruct = 36, // no OpVariable operand
|
||||
GLSLstd450FMin = 37,
|
||||
GLSLstd450UMin = 38,
|
||||
GLSLstd450SMin = 39,
|
||||
GLSLstd450FMax = 40,
|
||||
GLSLstd450UMax = 41,
|
||||
GLSLstd450SMax = 42,
|
||||
GLSLstd450FClamp = 43,
|
||||
GLSLstd450UClamp = 44,
|
||||
GLSLstd450SClamp = 45,
|
||||
GLSLstd450FMix = 46,
|
||||
GLSLstd450IMix = 47, // Reserved
|
||||
GLSLstd450Step = 48,
|
||||
GLSLstd450SmoothStep = 49,
|
||||
|
||||
GLSLstd450Fma = 50,
|
||||
GLSLstd450Frexp = 51, // second operand needs an OpVariable to write to
|
||||
GLSLstd450FrexpStruct = 52, // no OpVariable operand
|
||||
GLSLstd450Ldexp = 53,
|
||||
|
||||
GLSLstd450PackSnorm4x8 = 54,
|
||||
GLSLstd450PackUnorm4x8 = 55,
|
||||
GLSLstd450PackSnorm2x16 = 56,
|
||||
GLSLstd450PackUnorm2x16 = 57,
|
||||
GLSLstd450PackHalf2x16 = 58,
|
||||
GLSLstd450PackDouble2x32 = 59,
|
||||
GLSLstd450UnpackSnorm2x16 = 60,
|
||||
GLSLstd450UnpackUnorm2x16 = 61,
|
||||
GLSLstd450UnpackHalf2x16 = 62,
|
||||
GLSLstd450UnpackSnorm4x8 = 63,
|
||||
GLSLstd450UnpackUnorm4x8 = 64,
|
||||
GLSLstd450UnpackDouble2x32 = 65,
|
||||
|
||||
GLSLstd450Length = 66,
|
||||
GLSLstd450Distance = 67,
|
||||
GLSLstd450Cross = 68,
|
||||
GLSLstd450Normalize = 69,
|
||||
GLSLstd450FaceForward = 70,
|
||||
GLSLstd450Reflect = 71,
|
||||
GLSLstd450Refract = 72,
|
||||
|
||||
GLSLstd450FindILsb = 73,
|
||||
GLSLstd450FindSMsb = 74,
|
||||
GLSLstd450FindUMsb = 75,
|
||||
|
||||
GLSLstd450InterpolateAtCentroid = 76,
|
||||
GLSLstd450InterpolateAtSample = 77,
|
||||
GLSLstd450InterpolateAtOffset = 78,
|
||||
|
||||
GLSLstd450NMin = 79,
|
||||
GLSLstd450NMax = 80,
|
||||
GLSLstd450NClamp = 81,
|
||||
|
||||
GLSLstd450Count
|
||||
};
|
||||
|
||||
#endif // #ifndef GLSLstd450_H
|
||||
+2192
File diff suppressed because it is too large
Load Diff
+2203
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright 2016-2021 Arm Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_CFG_HPP
|
||||
#define SPIRV_CROSS_CFG_HPP
|
||||
|
||||
#include "spirv_common.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class Compiler;
|
||||
class CFG
|
||||
{
|
||||
public:
|
||||
CFG(Compiler &compiler, const SPIRFunction &function);
|
||||
|
||||
Compiler &get_compiler()
|
||||
{
|
||||
return compiler;
|
||||
}
|
||||
|
||||
const Compiler &get_compiler() const
|
||||
{
|
||||
return compiler;
|
||||
}
|
||||
|
||||
const SPIRFunction &get_function() const
|
||||
{
|
||||
return func;
|
||||
}
|
||||
|
||||
uint32_t get_immediate_dominator(uint32_t block) const
|
||||
{
|
||||
auto itr = immediate_dominators.find(block);
|
||||
if (itr != std::end(immediate_dominators))
|
||||
return itr->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t get_visit_order(uint32_t block) const
|
||||
{
|
||||
auto itr = visit_order.find(block);
|
||||
assert(itr != std::end(visit_order));
|
||||
int v = itr->second.get();
|
||||
assert(v > 0);
|
||||
return uint32_t(v);
|
||||
}
|
||||
|
||||
uint32_t find_common_dominator(uint32_t a, uint32_t b) const;
|
||||
|
||||
const SmallVector<uint32_t> &get_preceding_edges(uint32_t block) const
|
||||
{
|
||||
auto itr = preceding_edges.find(block);
|
||||
if (itr != std::end(preceding_edges))
|
||||
return itr->second;
|
||||
else
|
||||
return empty_vector;
|
||||
}
|
||||
|
||||
const SmallVector<uint32_t> &get_succeeding_edges(uint32_t block) const
|
||||
{
|
||||
auto itr = succeeding_edges.find(block);
|
||||
if (itr != std::end(succeeding_edges))
|
||||
return itr->second;
|
||||
else
|
||||
return empty_vector;
|
||||
}
|
||||
|
||||
template <typename Op>
|
||||
void walk_from(std::unordered_set<uint32_t> &seen_blocks, uint32_t block, const Op &op) const
|
||||
{
|
||||
if (seen_blocks.count(block))
|
||||
return;
|
||||
seen_blocks.insert(block);
|
||||
|
||||
if (op(block))
|
||||
{
|
||||
for (auto b : get_succeeding_edges(block))
|
||||
walk_from(seen_blocks, b, op);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t find_loop_dominator(uint32_t block) const;
|
||||
|
||||
bool node_terminates_control_flow_in_sub_graph(BlockID from, BlockID to) const;
|
||||
|
||||
private:
|
||||
struct VisitOrder
|
||||
{
|
||||
int &get()
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
const int &get() const
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
int v = -1;
|
||||
};
|
||||
|
||||
Compiler &compiler;
|
||||
const SPIRFunction &func;
|
||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> preceding_edges;
|
||||
std::unordered_map<uint32_t, SmallVector<uint32_t>> succeeding_edges;
|
||||
std::unordered_map<uint32_t, uint32_t> immediate_dominators;
|
||||
std::unordered_map<uint32_t, VisitOrder> visit_order;
|
||||
SmallVector<uint32_t> post_order;
|
||||
SmallVector<uint32_t> empty_vector;
|
||||
|
||||
void add_branch(uint32_t from, uint32_t to);
|
||||
void build_post_order_visit_order();
|
||||
void build_immediate_dominators();
|
||||
bool post_order_visit(uint32_t block);
|
||||
uint32_t visit_count = 0;
|
||||
|
||||
bool is_back_edge(uint32_t to) const;
|
||||
bool has_visited_forward_edge(uint32_t to) const;
|
||||
};
|
||||
|
||||
class DominatorBuilder
|
||||
{
|
||||
public:
|
||||
DominatorBuilder(const CFG &cfg);
|
||||
|
||||
void add_block(uint32_t block);
|
||||
uint32_t get_dominator() const
|
||||
{
|
||||
return dominator;
|
||||
}
|
||||
|
||||
void lift_continue_block_dominator();
|
||||
|
||||
private:
|
||||
const CFG &cfg;
|
||||
uint32_t dominator = 0;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
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
@@ -0,0 +1,747 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Hans-Kristian Arntzen
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_CONTAINERS_HPP
|
||||
#define SPIRV_CROSS_CONTAINERS_HPP
|
||||
|
||||
#include "spirv_cross_error_handling.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifdef SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#define SPIRV_CROSS_NAMESPACE SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#else
|
||||
#define SPIRV_CROSS_NAMESPACE spirv_cross
|
||||
#endif
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
#ifndef SPIRV_CROSS_FORCE_STL_TYPES
|
||||
// std::aligned_storage does not support size == 0, so roll our own.
|
||||
template <typename T, size_t N>
|
||||
class AlignedBuffer
|
||||
{
|
||||
public:
|
||||
T *data()
|
||||
{
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
// MSVC 2013 workarounds, sigh ...
|
||||
// Only use this workaround on MSVC 2013 due to some confusion around default initialized unions.
|
||||
// Spec seems to suggest the memory will be zero-initialized, which is *not* what we want.
|
||||
return reinterpret_cast<T *>(u.aligned_char);
|
||||
#else
|
||||
return reinterpret_cast<T *>(aligned_char);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
// MSVC 2013 workarounds, sigh ...
|
||||
union
|
||||
{
|
||||
char aligned_char[sizeof(T) * N];
|
||||
double dummy_aligner;
|
||||
} u;
|
||||
#else
|
||||
alignas(T) char aligned_char[sizeof(T) * N];
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class AlignedBuffer<T, 0>
|
||||
{
|
||||
public:
|
||||
T *data()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// An immutable version of SmallVector which erases type information about storage.
|
||||
template <typename T>
|
||||
class VectorView
|
||||
{
|
||||
public:
|
||||
T &operator[](size_t i) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
const T &operator[](size_t i) const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
bool empty() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return buffer_size == 0;
|
||||
}
|
||||
|
||||
size_t size() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return buffer_size;
|
||||
}
|
||||
|
||||
T *data() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const T *data() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T *begin() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
T *end() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr + buffer_size;
|
||||
}
|
||||
|
||||
const T *begin() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const T *end() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr + buffer_size;
|
||||
}
|
||||
|
||||
T &front() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[0];
|
||||
}
|
||||
|
||||
const T &front() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[0];
|
||||
}
|
||||
|
||||
T &back() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[buffer_size - 1];
|
||||
}
|
||||
|
||||
const T &back() const SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
return ptr[buffer_size - 1];
|
||||
}
|
||||
|
||||
// Makes it easier to consume SmallVector.
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
explicit operator std::vector<T>() const
|
||||
{
|
||||
// Another MSVC 2013 workaround. It does not understand lvalue/rvalue qualified operations.
|
||||
return std::vector<T>(ptr, ptr + buffer_size);
|
||||
}
|
||||
#else
|
||||
// Makes it easier to consume SmallVector.
|
||||
explicit operator std::vector<T>() const &
|
||||
{
|
||||
return std::vector<T>(ptr, ptr + buffer_size);
|
||||
}
|
||||
|
||||
// If we are converting as an r-value, we can pilfer our elements.
|
||||
explicit operator std::vector<T>() &&
|
||||
{
|
||||
return std::vector<T>(std::make_move_iterator(ptr), std::make_move_iterator(ptr + buffer_size));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Avoid sliced copies. Base class should only be read as a reference.
|
||||
VectorView(const VectorView &) = delete;
|
||||
void operator=(const VectorView &) = delete;
|
||||
|
||||
protected:
|
||||
VectorView() = default;
|
||||
T *ptr = nullptr;
|
||||
size_t buffer_size = 0;
|
||||
};
|
||||
|
||||
// Simple vector which supports up to N elements inline, without malloc/free.
|
||||
// We use a lot of throwaway vectors all over the place which triggers allocations.
|
||||
// This class only implements the subset of std::vector we need in SPIRV-Cross.
|
||||
// It is *NOT* a drop-in replacement in general projects.
|
||||
template <typename T, size_t N = 8>
|
||||
class SmallVector : public VectorView<T>
|
||||
{
|
||||
public:
|
||||
SmallVector() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
this->ptr = stack_storage.data();
|
||||
buffer_capacity = N;
|
||||
}
|
||||
|
||||
SmallVector(const T *arg_list_begin, const T *arg_list_end) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
auto count = size_t(arg_list_end - arg_list_begin);
|
||||
reserve(count);
|
||||
for (size_t i = 0; i < count; i++, arg_list_begin++)
|
||||
new (&this->ptr[i]) T(*arg_list_begin);
|
||||
this->buffer_size = count;
|
||||
}
|
||||
|
||||
SmallVector(std::initializer_list<T> init) SPIRV_CROSS_NOEXCEPT : SmallVector(init.begin(), init.end())
|
||||
{
|
||||
}
|
||||
|
||||
SmallVector(SmallVector &&other) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
*this = std::move(other);
|
||||
}
|
||||
|
||||
SmallVector &operator=(SmallVector &&other) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
clear();
|
||||
if (other.ptr != other.stack_storage.data())
|
||||
{
|
||||
// Pilfer allocated pointer.
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
this->ptr = other.ptr;
|
||||
this->buffer_size = other.buffer_size;
|
||||
buffer_capacity = other.buffer_capacity;
|
||||
other.ptr = nullptr;
|
||||
other.buffer_size = 0;
|
||||
other.buffer_capacity = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Need to move the stack contents individually.
|
||||
reserve(other.buffer_size);
|
||||
for (size_t i = 0; i < other.buffer_size; i++)
|
||||
{
|
||||
new (&this->ptr[i]) T(std::move(other.ptr[i]));
|
||||
other.ptr[i].~T();
|
||||
}
|
||||
this->buffer_size = other.buffer_size;
|
||||
other.buffer_size = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SmallVector(const SmallVector &other) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
SmallVector &operator=(const SmallVector &other) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
clear();
|
||||
reserve(other.buffer_size);
|
||||
for (size_t i = 0; i < other.buffer_size; i++)
|
||||
new (&this->ptr[i]) T(other.ptr[i]);
|
||||
this->buffer_size = other.buffer_size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit SmallVector(size_t count) SPIRV_CROSS_NOEXCEPT : SmallVector()
|
||||
{
|
||||
resize(count);
|
||||
}
|
||||
|
||||
~SmallVector()
|
||||
{
|
||||
clear();
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
}
|
||||
|
||||
void clear() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
for (size_t i = 0; i < this->buffer_size; i++)
|
||||
this->ptr[i].~T();
|
||||
this->buffer_size = 0;
|
||||
}
|
||||
|
||||
void push_back(const T &t) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
reserve(this->buffer_size + 1);
|
||||
new (&this->ptr[this->buffer_size]) T(t);
|
||||
this->buffer_size++;
|
||||
}
|
||||
|
||||
void push_back(T &&t) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
reserve(this->buffer_size + 1);
|
||||
new (&this->ptr[this->buffer_size]) T(std::move(t));
|
||||
this->buffer_size++;
|
||||
}
|
||||
|
||||
void pop_back() SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
// Work around false positive warning on GCC 8.3.
|
||||
// Calling pop_back on empty vector is undefined.
|
||||
if (!this->empty())
|
||||
resize(this->buffer_size - 1);
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void emplace_back(Ts &&... ts) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
reserve(this->buffer_size + 1);
|
||||
new (&this->ptr[this->buffer_size]) T(std::forward<Ts>(ts)...);
|
||||
this->buffer_size++;
|
||||
}
|
||||
|
||||
void reserve(size_t count) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if ((count > std::numeric_limits<size_t>::max() / sizeof(T)) ||
|
||||
(count > std::numeric_limits<size_t>::max() / 2))
|
||||
{
|
||||
// Only way this should ever happen is with garbage input, terminate.
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
if (count > buffer_capacity)
|
||||
{
|
||||
size_t target_capacity = buffer_capacity;
|
||||
if (target_capacity == 0)
|
||||
target_capacity = 1;
|
||||
|
||||
// Weird parens works around macro issues on Windows if NOMINMAX is not used.
|
||||
target_capacity = (std::max)(target_capacity, N);
|
||||
|
||||
// Need to ensure there is a POT value of target capacity which is larger than count,
|
||||
// otherwise this will overflow.
|
||||
while (target_capacity < count)
|
||||
target_capacity <<= 1u;
|
||||
|
||||
T *new_buffer =
|
||||
target_capacity > N ? static_cast<T *>(malloc(target_capacity * sizeof(T))) : stack_storage.data();
|
||||
|
||||
// If we actually fail this malloc, we are hosed anyways, there is no reason to attempt recovery.
|
||||
if (!new_buffer)
|
||||
std::terminate();
|
||||
|
||||
// In case for some reason two allocations both come from same stack.
|
||||
if (new_buffer != this->ptr)
|
||||
{
|
||||
// We don't deal with types which can throw in move constructor.
|
||||
for (size_t i = 0; i < this->buffer_size; i++)
|
||||
{
|
||||
new (&new_buffer[i]) T(std::move(this->ptr[i]));
|
||||
this->ptr[i].~T();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
this->ptr = new_buffer;
|
||||
buffer_capacity = target_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
void insert(T *itr, const T *insert_begin, const T *insert_end) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
auto count = size_t(insert_end - insert_begin);
|
||||
if (itr == this->end())
|
||||
{
|
||||
reserve(this->buffer_size + count);
|
||||
for (size_t i = 0; i < count; i++, insert_begin++)
|
||||
new (&this->ptr[this->buffer_size + i]) T(*insert_begin);
|
||||
this->buffer_size += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->buffer_size + count > buffer_capacity)
|
||||
{
|
||||
auto target_capacity = this->buffer_size + count;
|
||||
if (target_capacity == 0)
|
||||
target_capacity = 1;
|
||||
if (target_capacity < N)
|
||||
target_capacity = N;
|
||||
|
||||
while (target_capacity < count)
|
||||
target_capacity <<= 1u;
|
||||
|
||||
// Need to allocate new buffer. Move everything to a new buffer.
|
||||
T *new_buffer =
|
||||
target_capacity > N ? static_cast<T *>(malloc(target_capacity * sizeof(T))) : stack_storage.data();
|
||||
|
||||
// If we actually fail this malloc, we are hosed anyways, there is no reason to attempt recovery.
|
||||
if (!new_buffer)
|
||||
std::terminate();
|
||||
|
||||
// First, move elements from source buffer to new buffer.
|
||||
// We don't deal with types which can throw in move constructor.
|
||||
auto *target_itr = new_buffer;
|
||||
auto *original_source_itr = this->begin();
|
||||
|
||||
if (new_buffer != this->ptr)
|
||||
{
|
||||
while (original_source_itr != itr)
|
||||
{
|
||||
new (target_itr) T(std::move(*original_source_itr));
|
||||
original_source_itr->~T();
|
||||
++original_source_itr;
|
||||
++target_itr;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy-construct new elements.
|
||||
for (auto *source_itr = insert_begin; source_itr != insert_end; ++source_itr, ++target_itr)
|
||||
new (target_itr) T(*source_itr);
|
||||
|
||||
// Move over the other half.
|
||||
if (new_buffer != this->ptr || insert_begin != insert_end)
|
||||
{
|
||||
while (original_source_itr != this->end())
|
||||
{
|
||||
new (target_itr) T(std::move(*original_source_itr));
|
||||
original_source_itr->~T();
|
||||
++original_source_itr;
|
||||
++target_itr;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->ptr != stack_storage.data())
|
||||
free(this->ptr);
|
||||
this->ptr = new_buffer;
|
||||
buffer_capacity = target_capacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move in place, need to be a bit careful about which elements are constructed and which are not.
|
||||
// Move the end and construct the new elements.
|
||||
auto *target_itr = this->end() + count;
|
||||
auto *source_itr = this->end();
|
||||
while (target_itr != this->end() && source_itr != itr)
|
||||
{
|
||||
--target_itr;
|
||||
--source_itr;
|
||||
new (target_itr) T(std::move(*source_itr));
|
||||
}
|
||||
|
||||
// For already constructed elements we can move-assign.
|
||||
std::move_backward(itr, source_itr, target_itr);
|
||||
|
||||
// For the inserts which go to already constructed elements, we can do a plain copy.
|
||||
while (itr != this->end() && insert_begin != insert_end)
|
||||
*itr++ = *insert_begin++;
|
||||
|
||||
// For inserts into newly allocated memory, we must copy-construct instead.
|
||||
while (insert_begin != insert_end)
|
||||
{
|
||||
new (itr) T(*insert_begin);
|
||||
++itr;
|
||||
++insert_begin;
|
||||
}
|
||||
}
|
||||
|
||||
this->buffer_size += count;
|
||||
}
|
||||
}
|
||||
|
||||
void insert(T *itr, const T &value) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
insert(itr, &value, &value + 1);
|
||||
}
|
||||
|
||||
T *erase(T *itr) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
std::move(itr + 1, this->end(), itr);
|
||||
this->ptr[--this->buffer_size].~T();
|
||||
return itr;
|
||||
}
|
||||
|
||||
void erase(T *start_erase, T *end_erase) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if (end_erase == this->end())
|
||||
{
|
||||
resize(size_t(start_erase - this->begin()));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto new_size = this->buffer_size - (end_erase - start_erase);
|
||||
std::move(end_erase, this->end(), start_erase);
|
||||
resize(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void resize(size_t new_size) SPIRV_CROSS_NOEXCEPT
|
||||
{
|
||||
if (new_size < this->buffer_size)
|
||||
{
|
||||
for (size_t i = new_size; i < this->buffer_size; i++)
|
||||
this->ptr[i].~T();
|
||||
}
|
||||
else if (new_size > this->buffer_size)
|
||||
{
|
||||
reserve(new_size);
|
||||
for (size_t i = this->buffer_size; i < new_size; i++)
|
||||
new (&this->ptr[i]) T();
|
||||
}
|
||||
|
||||
this->buffer_size = new_size;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t buffer_capacity = 0;
|
||||
AlignedBuffer<T, N> stack_storage;
|
||||
};
|
||||
|
||||
// A vector without stack storage.
|
||||
// Could also be a typedef-ed to std::vector,
|
||||
// but might as well use the one we have.
|
||||
template <typename T>
|
||||
using Vector = SmallVector<T, 0>;
|
||||
|
||||
#else // SPIRV_CROSS_FORCE_STL_TYPES
|
||||
|
||||
template <typename T, size_t N = 8>
|
||||
using SmallVector = std::vector<T>;
|
||||
template <typename T>
|
||||
using Vector = std::vector<T>;
|
||||
template <typename T>
|
||||
using VectorView = std::vector<T>;
|
||||
|
||||
#endif // SPIRV_CROSS_FORCE_STL_TYPES
|
||||
|
||||
// An object pool which we use for allocating IVariant-derived objects.
|
||||
// We know we are going to allocate a bunch of objects of each type,
|
||||
// so amortize the mallocs.
|
||||
class ObjectPoolBase
|
||||
{
|
||||
public:
|
||||
virtual ~ObjectPoolBase() = default;
|
||||
virtual void free_opaque(void *ptr) = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ObjectPool : public ObjectPoolBase
|
||||
{
|
||||
public:
|
||||
explicit ObjectPool(unsigned start_object_count_ = 16)
|
||||
: start_object_count(start_object_count_)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename... P>
|
||||
T *allocate(P &&... p)
|
||||
{
|
||||
if (vacants.empty())
|
||||
{
|
||||
unsigned num_objects = start_object_count << memory.size();
|
||||
T *ptr = static_cast<T *>(malloc(num_objects * sizeof(T)));
|
||||
if (!ptr)
|
||||
return nullptr;
|
||||
|
||||
for (unsigned i = 0; i < num_objects; i++)
|
||||
vacants.push_back(&ptr[i]);
|
||||
|
||||
memory.emplace_back(ptr);
|
||||
}
|
||||
|
||||
T *ptr = vacants.back();
|
||||
vacants.pop_back();
|
||||
new (ptr) T(std::forward<P>(p)...);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void free(T *ptr)
|
||||
{
|
||||
ptr->~T();
|
||||
vacants.push_back(ptr);
|
||||
}
|
||||
|
||||
void free_opaque(void *ptr) override
|
||||
{
|
||||
free(static_cast<T *>(ptr));
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
vacants.clear();
|
||||
memory.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
Vector<T *> vacants;
|
||||
|
||||
struct MallocDeleter
|
||||
{
|
||||
void operator()(T *ptr)
|
||||
{
|
||||
::free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
SmallVector<std::unique_ptr<T, MallocDeleter>> memory;
|
||||
unsigned start_object_count;
|
||||
};
|
||||
|
||||
template <size_t StackSize = 4096, size_t BlockSize = 4096>
|
||||
class StringStream
|
||||
{
|
||||
public:
|
||||
StringStream()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
~StringStream()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
// Disable copies and moves. Makes it easier to implement, and we don't need it.
|
||||
StringStream(const StringStream &) = delete;
|
||||
void operator=(const StringStream &) = delete;
|
||||
|
||||
template <typename T, typename std::enable_if<!std::is_floating_point<T>::value, int>::type = 0>
|
||||
StringStream &operator<<(const T &t)
|
||||
{
|
||||
auto s = std::to_string(t);
|
||||
append(s.data(), s.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Only overload this to make float/double conversions ambiguous.
|
||||
StringStream &operator<<(uint32_t v)
|
||||
{
|
||||
auto s = std::to_string(v);
|
||||
append(s.data(), s.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringStream &operator<<(char c)
|
||||
{
|
||||
append(&c, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringStream &operator<<(const std::string &s)
|
||||
{
|
||||
append(s.data(), s.size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringStream &operator<<(const char *s)
|
||||
{
|
||||
append(s, strlen(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
StringStream &operator<<(const char (&s)[N])
|
||||
{
|
||||
append(s, strlen(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string str() const
|
||||
{
|
||||
std::string ret;
|
||||
size_t target_size = 0;
|
||||
for (auto &saved : saved_buffers)
|
||||
target_size += saved.offset;
|
||||
target_size += current_buffer.offset;
|
||||
ret.reserve(target_size);
|
||||
|
||||
for (auto &saved : saved_buffers)
|
||||
ret.insert(ret.end(), saved.buffer, saved.buffer + saved.offset);
|
||||
ret.insert(ret.end(), current_buffer.buffer, current_buffer.buffer + current_buffer.offset);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
for (auto &saved : saved_buffers)
|
||||
if (saved.buffer != stack_buffer)
|
||||
free(saved.buffer);
|
||||
if (current_buffer.buffer != stack_buffer)
|
||||
free(current_buffer.buffer);
|
||||
|
||||
saved_buffers.clear();
|
||||
current_buffer.buffer = stack_buffer;
|
||||
current_buffer.offset = 0;
|
||||
current_buffer.size = sizeof(stack_buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
struct Buffer
|
||||
{
|
||||
char *buffer = nullptr;
|
||||
size_t offset = 0;
|
||||
size_t size = 0;
|
||||
};
|
||||
Buffer current_buffer;
|
||||
char stack_buffer[StackSize];
|
||||
SmallVector<Buffer> saved_buffers;
|
||||
|
||||
void append(const char *s, size_t len)
|
||||
{
|
||||
size_t avail = current_buffer.size - current_buffer.offset;
|
||||
if (avail < len)
|
||||
{
|
||||
if (avail > 0)
|
||||
{
|
||||
memcpy(current_buffer.buffer + current_buffer.offset, s, avail);
|
||||
s += avail;
|
||||
len -= avail;
|
||||
current_buffer.offset += avail;
|
||||
}
|
||||
|
||||
saved_buffers.push_back(current_buffer);
|
||||
size_t target_size = len > BlockSize ? len : BlockSize;
|
||||
current_buffer.buffer = static_cast<char *>(malloc(target_size));
|
||||
if (!current_buffer.buffer)
|
||||
SPIRV_CROSS_THROW("Out of memory.");
|
||||
|
||||
memcpy(current_buffer.buffer, s, len);
|
||||
current_buffer.offset = len;
|
||||
current_buffer.size = target_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(current_buffer.buffer + current_buffer.offset, s, len);
|
||||
current_buffer.offset += len;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2015-2021 Arm Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_ERROR_HANDLING
|
||||
#define SPIRV_CROSS_ERROR_HANDLING
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#ifndef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
|
||||
#ifdef SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#define SPIRV_CROSS_NAMESPACE SPIRV_CROSS_NAMESPACE_OVERRIDE
|
||||
#else
|
||||
#define SPIRV_CROSS_NAMESPACE spirv_cross
|
||||
#endif
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
#ifdef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS
|
||||
#if !defined(_MSC_VER) || defined(__clang__)
|
||||
[[noreturn]]
|
||||
#elif defined(_MSC_VER)
|
||||
__declspec(noreturn)
|
||||
#endif
|
||||
inline void
|
||||
report_and_abort(const std::string &msg)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
(void)msg;
|
||||
#else
|
||||
fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
|
||||
#endif
|
||||
fflush(stderr);
|
||||
abort();
|
||||
}
|
||||
|
||||
#define SPIRV_CROSS_THROW(x) report_and_abort(x)
|
||||
#else
|
||||
class CompilerError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
explicit CompilerError(const std::string &str)
|
||||
: std::runtime_error(str)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#define SPIRV_CROSS_THROW(x) throw CompilerError(x)
|
||||
#endif
|
||||
|
||||
// MSVC 2013 does not have noexcept. We need this for Variant to get move constructor to work correctly
|
||||
// instead of copy constructor.
|
||||
// MSVC 2013 ignores that move constructors cannot throw in std::vector, so just don't define it.
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define SPIRV_CROSS_NOEXCEPT
|
||||
#else
|
||||
#define SPIRV_CROSS_NOEXCEPT noexcept
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201402l
|
||||
#define SPIRV_CROSS_DEPRECATED(reason) [[deprecated(reason)]]
|
||||
#elif defined(__GNUC__)
|
||||
#define SPIRV_CROSS_DEPRECATED(reason) __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER)
|
||||
#define SPIRV_CROSS_DEPRECATED(reason) __declspec(deprecated(reason))
|
||||
#else
|
||||
#define SPIRV_CROSS_DEPRECATED(reason)
|
||||
#endif
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright 2018-2021 Arm Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_PARSED_IR_HPP
|
||||
#define SPIRV_CROSS_PARSED_IR_HPP
|
||||
|
||||
#include "spirv_common.hpp"
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
|
||||
// This data structure holds all information needed to perform cross-compilation and reflection.
|
||||
// It is the output of the Parser, but any implementation could create this structure.
|
||||
// It is intentionally very "open" and struct-like with some helper functions to deal with decorations.
|
||||
// Parser is the reference implementation of how this data structure should be filled in.
|
||||
|
||||
class ParsedIR
|
||||
{
|
||||
private:
|
||||
// This must be destroyed after the "ids" vector.
|
||||
std::unique_ptr<ObjectPoolGroup> pool_group;
|
||||
|
||||
public:
|
||||
ParsedIR();
|
||||
|
||||
// Due to custom allocations from object pools, we cannot use a default copy constructor.
|
||||
ParsedIR(const ParsedIR &other);
|
||||
ParsedIR &operator=(const ParsedIR &other);
|
||||
|
||||
// Moves are unproblematic, but we need to implement it anyways, since MSVC 2013 does not understand
|
||||
// how to default-implement these.
|
||||
ParsedIR(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
ParsedIR &operator=(ParsedIR &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
|
||||
// Resizes ids, meta and block_meta.
|
||||
void set_id_bounds(uint32_t bounds);
|
||||
|
||||
// The raw SPIR-V, instructions and opcodes refer to this by offset + count.
|
||||
std::vector<uint32_t> spirv;
|
||||
|
||||
// Holds various data structures which inherit from IVariant.
|
||||
SmallVector<Variant> ids;
|
||||
|
||||
// Various meta data for IDs, decorations, names, etc.
|
||||
std::unordered_map<ID, Meta> meta;
|
||||
|
||||
// Holds all IDs which have a certain type.
|
||||
// This is needed so we can iterate through a specific kind of resource quickly,
|
||||
// and in-order of module declaration.
|
||||
SmallVector<ID> ids_for_type[TypeCount];
|
||||
|
||||
// Special purpose lists which contain a union of types.
|
||||
// This is needed so we can declare specialization constants and structs in an interleaved fashion,
|
||||
// among other things.
|
||||
// Constants can be of struct type, and struct array sizes can use specialization constants.
|
||||
SmallVector<ID> ids_for_constant_or_type;
|
||||
SmallVector<ID> ids_for_constant_or_variable;
|
||||
|
||||
// Declared capabilities and extensions in the SPIR-V module.
|
||||
// Not really used except for reflection at the moment.
|
||||
SmallVector<spv::Capability> declared_capabilities;
|
||||
SmallVector<std::string> declared_extensions;
|
||||
|
||||
// Meta data about blocks. The cross-compiler needs to query if a block is either of these types.
|
||||
// It is a bitset as there can be more than one tag per block.
|
||||
enum BlockMetaFlagBits
|
||||
{
|
||||
BLOCK_META_LOOP_HEADER_BIT = 1 << 0,
|
||||
BLOCK_META_CONTINUE_BIT = 1 << 1,
|
||||
BLOCK_META_LOOP_MERGE_BIT = 1 << 2,
|
||||
BLOCK_META_SELECTION_MERGE_BIT = 1 << 3,
|
||||
BLOCK_META_MULTISELECT_MERGE_BIT = 1 << 4
|
||||
};
|
||||
using BlockMetaFlags = uint8_t;
|
||||
SmallVector<BlockMetaFlags> block_meta;
|
||||
std::unordered_map<BlockID, BlockID> continue_block_to_loop_header;
|
||||
|
||||
// Normally, we'd stick SPIREntryPoint in ids array, but it conflicts with SPIRFunction.
|
||||
// Entry points can therefore be seen as some sort of meta structure.
|
||||
std::unordered_map<FunctionID, SPIREntryPoint> entry_points;
|
||||
FunctionID default_entry_point = 0;
|
||||
|
||||
struct Source
|
||||
{
|
||||
uint32_t version = 0;
|
||||
bool es = false;
|
||||
bool known = false;
|
||||
bool hlsl = false;
|
||||
|
||||
Source() = default;
|
||||
};
|
||||
|
||||
Source source;
|
||||
|
||||
spv::AddressingModel addressing_model = spv::AddressingModelMax;
|
||||
spv::MemoryModel memory_model = spv::MemoryModelMax;
|
||||
|
||||
// Decoration handling methods.
|
||||
// Can be useful for simple "raw" reflection.
|
||||
// However, most members are here because the Parser needs most of these,
|
||||
// and might as well just have the whole suite of decoration/name handling in one place.
|
||||
void set_name(ID id, const std::string &name);
|
||||
const std::string &get_name(ID id) const;
|
||||
void set_decoration(ID id, spv::Decoration decoration, uint32_t argument = 0);
|
||||
void set_decoration_string(ID id, spv::Decoration decoration, const std::string &argument);
|
||||
bool has_decoration(ID id, spv::Decoration decoration) const;
|
||||
uint32_t get_decoration(ID id, spv::Decoration decoration) const;
|
||||
const std::string &get_decoration_string(ID id, spv::Decoration decoration) const;
|
||||
const Bitset &get_decoration_bitset(ID id) const;
|
||||
void unset_decoration(ID id, spv::Decoration decoration);
|
||||
|
||||
// Decoration handling methods (for members of a struct).
|
||||
void set_member_name(TypeID id, uint32_t index, const std::string &name);
|
||||
const std::string &get_member_name(TypeID id, uint32_t index) const;
|
||||
void set_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration, uint32_t argument = 0);
|
||||
void set_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration,
|
||||
const std::string &argument);
|
||||
uint32_t get_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||
const std::string &get_member_decoration_string(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||
bool has_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration) const;
|
||||
const Bitset &get_member_decoration_bitset(TypeID id, uint32_t index) const;
|
||||
void unset_member_decoration(TypeID id, uint32_t index, spv::Decoration decoration);
|
||||
|
||||
void mark_used_as_array_length(ID id);
|
||||
uint32_t increase_bound_by(uint32_t count);
|
||||
Bitset get_buffer_block_flags(const SPIRVariable &var) const;
|
||||
Bitset get_buffer_block_type_flags(const SPIRType &type) const;
|
||||
|
||||
void add_typed_id(Types type, ID id);
|
||||
void remove_typed_id(Types type, ID id);
|
||||
|
||||
class LoopLock
|
||||
{
|
||||
public:
|
||||
explicit LoopLock(uint32_t *counter);
|
||||
LoopLock(const LoopLock &) = delete;
|
||||
void operator=(const LoopLock &) = delete;
|
||||
LoopLock(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
LoopLock &operator=(LoopLock &&other) SPIRV_CROSS_NOEXCEPT;
|
||||
~LoopLock();
|
||||
|
||||
private:
|
||||
uint32_t *lock;
|
||||
};
|
||||
|
||||
// This must be held while iterating over a type ID array.
|
||||
// It is undefined if someone calls set<>() while we're iterating over a data structure, so we must
|
||||
// make sure that this case is avoided.
|
||||
|
||||
// If we have a hard lock, it is an error to call set<>(), and an exception is thrown.
|
||||
// If we have a soft lock, we silently ignore any additions to the typed arrays.
|
||||
// This should only be used for physical ID remapping where we need to create an ID, but we will never
|
||||
// care about iterating over them.
|
||||
LoopLock create_loop_hard_lock() const;
|
||||
LoopLock create_loop_soft_lock() const;
|
||||
|
||||
template <typename T, typename Op>
|
||||
void for_each_typed_id(const Op &op)
|
||||
{
|
||||
auto loop_lock = create_loop_hard_lock();
|
||||
for (auto &id : ids_for_type[T::type])
|
||||
{
|
||||
if (ids[id].get_type() == static_cast<Types>(T::type))
|
||||
op(id, get<T>(id));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename Op>
|
||||
void for_each_typed_id(const Op &op) const
|
||||
{
|
||||
auto loop_lock = create_loop_hard_lock();
|
||||
for (auto &id : ids_for_type[T::type])
|
||||
{
|
||||
if (ids[id].get_type() == static_cast<Types>(T::type))
|
||||
op(id, get<T>(id));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void reset_all_of_type()
|
||||
{
|
||||
reset_all_of_type(static_cast<Types>(T::type));
|
||||
}
|
||||
|
||||
void reset_all_of_type(Types type);
|
||||
|
||||
Meta *find_meta(ID id);
|
||||
const Meta *find_meta(ID id) const;
|
||||
|
||||
const std::string &get_empty_string() const
|
||||
{
|
||||
return empty_string;
|
||||
}
|
||||
|
||||
void make_constant_null(uint32_t id, uint32_t type, bool add_to_typed_id_set);
|
||||
|
||||
void fixup_reserved_names();
|
||||
|
||||
static void sanitize_underscores(std::string &str);
|
||||
static void sanitize_identifier(std::string &str, bool member, bool allow_reserved_prefixes);
|
||||
static bool is_globally_reserved_identifier(std::string &str, bool allow_reserved_prefixes);
|
||||
|
||||
uint32_t get_spirv_version() const;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
T &get(uint32_t id)
|
||||
{
|
||||
return variant_get<T>(ids[id]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &get(uint32_t id) const
|
||||
{
|
||||
return variant_get<T>(ids[id]);
|
||||
}
|
||||
|
||||
mutable uint32_t loop_iteration_depth_hard = 0;
|
||||
mutable uint32_t loop_iteration_depth_soft = 0;
|
||||
std::string empty_string;
|
||||
Bitset cleared_bitset;
|
||||
|
||||
std::unordered_set<uint32_t> meta_needing_name_fixup;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,938 @@
|
||||
/*
|
||||
* Copyright 2015-2021 Arm Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_GLSL_HPP
|
||||
#define SPIRV_CROSS_GLSL_HPP
|
||||
|
||||
#include "GLSL.std.450.h"
|
||||
#include "spirv_cross.hpp"
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
enum PlsFormat
|
||||
{
|
||||
PlsNone = 0,
|
||||
|
||||
PlsR11FG11FB10F,
|
||||
PlsR32F,
|
||||
PlsRG16F,
|
||||
PlsRGB10A2,
|
||||
PlsRGBA8,
|
||||
PlsRG16,
|
||||
|
||||
PlsRGBA8I,
|
||||
PlsRG16I,
|
||||
|
||||
PlsRGB10A2UI,
|
||||
PlsRGBA8UI,
|
||||
PlsRG16UI,
|
||||
PlsR32UI
|
||||
};
|
||||
|
||||
struct PlsRemap
|
||||
{
|
||||
uint32_t id;
|
||||
PlsFormat format;
|
||||
};
|
||||
|
||||
enum AccessChainFlagBits
|
||||
{
|
||||
ACCESS_CHAIN_INDEX_IS_LITERAL_BIT = 1 << 0,
|
||||
ACCESS_CHAIN_CHAIN_ONLY_BIT = 1 << 1,
|
||||
ACCESS_CHAIN_PTR_CHAIN_BIT = 1 << 2,
|
||||
ACCESS_CHAIN_SKIP_REGISTER_EXPRESSION_READ_BIT = 1 << 3,
|
||||
ACCESS_CHAIN_LITERAL_MSB_FORCE_ID = 1 << 4,
|
||||
ACCESS_CHAIN_FLATTEN_ALL_MEMBERS_BIT = 1 << 5,
|
||||
ACCESS_CHAIN_FORCE_COMPOSITE_BIT = 1 << 6
|
||||
};
|
||||
typedef uint32_t AccessChainFlags;
|
||||
|
||||
class CompilerGLSL : public Compiler
|
||||
{
|
||||
public:
|
||||
struct Options
|
||||
{
|
||||
// The shading language version. Corresponds to #version $VALUE.
|
||||
uint32_t version = 450;
|
||||
|
||||
// Emit the OpenGL ES shading language instead of desktop OpenGL.
|
||||
bool es = false;
|
||||
|
||||
// Debug option to always emit temporary variables for all expressions.
|
||||
bool force_temporary = false;
|
||||
|
||||
// If true, Vulkan GLSL features are used instead of GL-compatible features.
|
||||
// Mostly useful for debugging SPIR-V files.
|
||||
bool vulkan_semantics = false;
|
||||
|
||||
// If true, gl_PerVertex is explicitly redeclared in vertex, geometry and tessellation shaders.
|
||||
// The members of gl_PerVertex is determined by which built-ins are declared by the shader.
|
||||
// This option is ignored in ES versions, as redeclaration in ES is not required, and it depends on a different extension
|
||||
// (EXT_shader_io_blocks) which makes things a bit more fuzzy.
|
||||
bool separate_shader_objects = false;
|
||||
|
||||
// Flattens multidimensional arrays, e.g. float foo[a][b][c] into single-dimensional arrays,
|
||||
// e.g. float foo[a * b * c].
|
||||
// This function does not change the actual SPIRType of any object.
|
||||
// Only the generated code, including declarations of interface variables are changed to be single array dimension.
|
||||
bool flatten_multidimensional_arrays = false;
|
||||
|
||||
// For older desktop GLSL targets than version 420, the
|
||||
// GL_ARB_shading_language_420pack extensions is used to be able to support
|
||||
// layout(binding) on UBOs and samplers.
|
||||
// If disabled on older targets, binding decorations will be stripped.
|
||||
bool enable_420pack_extension = true;
|
||||
|
||||
// In non-Vulkan GLSL, emit push constant blocks as UBOs rather than plain uniforms.
|
||||
bool emit_push_constant_as_uniform_buffer = false;
|
||||
|
||||
// Always emit uniform blocks as plain uniforms, regardless of the GLSL version, even when UBOs are supported.
|
||||
// Does not apply to shader storage or push constant blocks.
|
||||
bool emit_uniform_buffer_as_plain_uniforms = false;
|
||||
|
||||
// Emit OpLine directives if present in the module.
|
||||
// May not correspond exactly to original source, but should be a good approximation.
|
||||
bool emit_line_directives = false;
|
||||
|
||||
// In cases where readonly/writeonly decoration are not used at all,
|
||||
// we try to deduce which qualifier(s) we should actually used, since actually emitting
|
||||
// read-write decoration is very rare, and older glslang/HLSL compilers tend to just emit readwrite as a matter of fact.
|
||||
// The default (true) is to enable automatic deduction for these cases, but if you trust the decorations set
|
||||
// by the SPIR-V, it's recommended to set this to false.
|
||||
bool enable_storage_image_qualifier_deduction = true;
|
||||
|
||||
// On some targets (WebGPU), uninitialized variables are banned.
|
||||
// If this is enabled, all variables (temporaries, Private, Function)
|
||||
// which would otherwise be uninitialized will now be initialized to 0 instead.
|
||||
bool force_zero_initialized_variables = false;
|
||||
|
||||
// In GLSL, force use of I/O block flattening, similar to
|
||||
// what happens on legacy GLSL targets for blocks and structs.
|
||||
bool force_flattened_io_blocks = false;
|
||||
|
||||
enum Precision
|
||||
{
|
||||
DontCare,
|
||||
Lowp,
|
||||
Mediump,
|
||||
Highp
|
||||
};
|
||||
|
||||
struct VertexOptions
|
||||
{
|
||||
// "Vertex-like shader" here is any shader stage that can write BuiltInPosition.
|
||||
|
||||
// GLSL: In vertex-like shaders, rewrite [0, w] depth (Vulkan/D3D style) to [-w, w] depth (GL style).
|
||||
// MSL: In vertex-like shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
// HLSL: In vertex-like shaders, rewrite [-w, w] depth (GL style) to [0, w] depth.
|
||||
bool fixup_clipspace = false;
|
||||
|
||||
// In vertex-like shaders, inverts gl_Position.y or equivalent.
|
||||
bool flip_vert_y = false;
|
||||
|
||||
// GLSL only, for HLSL version of this option, see CompilerHLSL.
|
||||
// If true, the backend will assume that InstanceIndex will need to apply
|
||||
// a base instance offset. Set to false if you know you will never use base instance
|
||||
// functionality as it might remove some internal uniforms.
|
||||
bool support_nonzero_base_instance = true;
|
||||
} vertex;
|
||||
|
||||
struct FragmentOptions
|
||||
{
|
||||
// Add precision mediump float in ES targets when emitting GLES source.
|
||||
// Add precision highp int in ES targets when emitting GLES source.
|
||||
Precision default_float_precision = Mediump;
|
||||
Precision default_int_precision = Highp;
|
||||
} fragment;
|
||||
};
|
||||
|
||||
void remap_pixel_local_storage(std::vector<PlsRemap> inputs, std::vector<PlsRemap> outputs)
|
||||
{
|
||||
pls_inputs = std::move(inputs);
|
||||
pls_outputs = std::move(outputs);
|
||||
remap_pls_variables();
|
||||
}
|
||||
|
||||
// Redirect a subpassInput reading from input_attachment_index to instead load its value from
|
||||
// the color attachment at location = color_location. Requires ESSL.
|
||||
void remap_ext_framebuffer_fetch(uint32_t input_attachment_index, uint32_t color_location);
|
||||
|
||||
explicit CompilerGLSL(std::vector<uint32_t> spirv_)
|
||||
: Compiler(std::move(spirv_))
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
CompilerGLSL(const uint32_t *ir_, size_t word_count)
|
||||
: Compiler(ir_, word_count)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
explicit CompilerGLSL(const ParsedIR &ir_)
|
||||
: Compiler(ir_)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
explicit CompilerGLSL(ParsedIR &&ir_)
|
||||
: Compiler(std::move(ir_))
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
const Options &get_common_options() const
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
void set_common_options(const Options &opts)
|
||||
{
|
||||
options = opts;
|
||||
}
|
||||
|
||||
std::string compile() override;
|
||||
|
||||
// Returns the current string held in the conversion buffer. Useful for
|
||||
// capturing what has been converted so far when compile() throws an error.
|
||||
std::string get_partial_source();
|
||||
|
||||
// Adds a line to be added right after #version in GLSL backend.
|
||||
// This is useful for enabling custom extensions which are outside the scope of SPIRV-Cross.
|
||||
// This can be combined with variable remapping.
|
||||
// A new-line will be added.
|
||||
//
|
||||
// While add_header_line() is a more generic way of adding arbitrary text to the header
|
||||
// of a GLSL file, require_extension() should be used when adding extensions since it will
|
||||
// avoid creating collisions with SPIRV-Cross generated extensions.
|
||||
//
|
||||
// Code added via add_header_line() is typically backend-specific.
|
||||
void add_header_line(const std::string &str);
|
||||
|
||||
// Adds an extension which is required to run this shader, e.g.
|
||||
// require_extension("GL_KHR_my_extension");
|
||||
void require_extension(const std::string &ext);
|
||||
|
||||
// Legacy GLSL compatibility method.
|
||||
// Takes a uniform or push constant variable and flattens it into a (i|u)vec4 array[N]; array instead.
|
||||
// For this to work, all types in the block must be the same basic type, e.g. mixing vec2 and vec4 is fine, but
|
||||
// mixing int and float is not.
|
||||
// The name of the uniform array will be the same as the interface block name.
|
||||
void flatten_buffer_block(VariableID id);
|
||||
|
||||
// After compilation, query if a variable ID was used as a depth resource.
|
||||
// This is meaningful for MSL since descriptor types depend on this knowledge.
|
||||
// Cases which return true:
|
||||
// - Images which are declared with depth = 1 image type.
|
||||
// - Samplers which are statically used at least once with Dref opcodes.
|
||||
// - Images which are statically used at least once with Dref opcodes.
|
||||
bool variable_is_depth_or_compare(VariableID id) const;
|
||||
|
||||
// If a shader output is active in this stage, but inactive in a subsequent stage,
|
||||
// this can be signalled here. This can be used to work around certain cross-stage matching problems
|
||||
// which plagues MSL and HLSL in certain scenarios.
|
||||
// An output which matches one of these will not be emitted in stage output interfaces, but rather treated as a private
|
||||
// variable.
|
||||
// This option is only meaningful for MSL and HLSL, since GLSL matches by location directly.
|
||||
// Masking builtins only takes effect if the builtin in question is part of the stage output interface.
|
||||
void mask_stage_output_by_location(uint32_t location, uint32_t component);
|
||||
void mask_stage_output_by_builtin(spv::BuiltIn builtin);
|
||||
|
||||
protected:
|
||||
struct ShaderSubgroupSupportHelper
|
||||
{
|
||||
// lower enum value = greater priority
|
||||
enum Candidate
|
||||
{
|
||||
KHR_shader_subgroup_ballot,
|
||||
KHR_shader_subgroup_basic,
|
||||
KHR_shader_subgroup_vote,
|
||||
NV_gpu_shader_5,
|
||||
NV_shader_thread_group,
|
||||
NV_shader_thread_shuffle,
|
||||
ARB_shader_ballot,
|
||||
ARB_shader_group_vote,
|
||||
AMD_gcn_shader,
|
||||
|
||||
CandidateCount
|
||||
};
|
||||
|
||||
static const char *get_extension_name(Candidate c);
|
||||
static SmallVector<std::string> get_extra_required_extension_names(Candidate c);
|
||||
static const char *get_extra_required_extension_predicate(Candidate c);
|
||||
|
||||
enum Feature
|
||||
{
|
||||
SubgroupMask = 0,
|
||||
SubgroupSize = 1,
|
||||
SubgroupInvocationID = 2,
|
||||
SubgroupID = 3,
|
||||
NumSubgroups = 4,
|
||||
SubgroupBroadcast_First = 5,
|
||||
SubgroupBallotFindLSB_MSB = 6,
|
||||
SubgroupAll_Any_AllEqualBool = 7,
|
||||
SubgroupAllEqualT = 8,
|
||||
SubgroupElect = 9,
|
||||
SubgroupBarrier = 10,
|
||||
SubgroupMemBarrier = 11,
|
||||
SubgroupBallot = 12,
|
||||
SubgroupInverseBallot_InclBitCount_ExclBitCout = 13,
|
||||
SubgroupBallotBitExtract = 14,
|
||||
SubgroupBallotBitCount = 15,
|
||||
|
||||
FeatureCount
|
||||
};
|
||||
|
||||
using FeatureMask = uint32_t;
|
||||
static_assert(sizeof(FeatureMask) * 8u >= FeatureCount, "Mask type needs more bits.");
|
||||
|
||||
using CandidateVector = SmallVector<Candidate, CandidateCount>;
|
||||
using FeatureVector = SmallVector<Feature>;
|
||||
|
||||
static FeatureVector get_feature_dependencies(Feature feature);
|
||||
static FeatureMask get_feature_dependency_mask(Feature feature);
|
||||
static bool can_feature_be_implemented_without_extensions(Feature feature);
|
||||
static Candidate get_KHR_extension_for_feature(Feature feature);
|
||||
|
||||
struct Result
|
||||
{
|
||||
Result();
|
||||
uint32_t weights[CandidateCount];
|
||||
};
|
||||
|
||||
void request_feature(Feature feature);
|
||||
bool is_feature_requested(Feature feature) const;
|
||||
Result resolve() const;
|
||||
|
||||
static CandidateVector get_candidates_for_feature(Feature ft, const Result &r);
|
||||
|
||||
private:
|
||||
static CandidateVector get_candidates_for_feature(Feature ft);
|
||||
static FeatureMask build_mask(const SmallVector<Feature> &features);
|
||||
FeatureMask feature_mask = 0;
|
||||
};
|
||||
|
||||
// TODO remove this function when all subgroup ops are supported (or make it always return true)
|
||||
static bool is_supported_subgroup_op_in_opengl(spv::Op op);
|
||||
|
||||
void reset();
|
||||
void emit_function(SPIRFunction &func, const Bitset &return_flags);
|
||||
|
||||
bool has_extension(const std::string &ext) const;
|
||||
void require_extension_internal(const std::string &ext);
|
||||
|
||||
// Virtualize methods which need to be overridden by subclass targets like C++ and such.
|
||||
virtual void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags);
|
||||
|
||||
SPIRBlock *current_emitting_block = nullptr;
|
||||
SPIRBlock *current_emitting_switch = nullptr;
|
||||
bool current_emitting_switch_fallthrough = false;
|
||||
|
||||
virtual void emit_instruction(const Instruction &instr);
|
||||
void emit_block_instructions(SPIRBlock &block);
|
||||
virtual void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||
uint32_t count);
|
||||
virtual void emit_spv_amd_shader_ballot_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
||||
const uint32_t *args, uint32_t count);
|
||||
virtual void emit_spv_amd_shader_explicit_vertex_parameter_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
||||
const uint32_t *args, uint32_t count);
|
||||
virtual void emit_spv_amd_shader_trinary_minmax_op(uint32_t result_type, uint32_t result_id, uint32_t op,
|
||||
const uint32_t *args, uint32_t count);
|
||||
virtual void emit_spv_amd_gcn_shader_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||
uint32_t count);
|
||||
virtual void emit_header();
|
||||
void emit_line_directive(uint32_t file_id, uint32_t line_literal);
|
||||
void build_workgroup_size(SmallVector<std::string> &arguments, const SpecializationConstant &x,
|
||||
const SpecializationConstant &y, const SpecializationConstant &z);
|
||||
|
||||
void request_subgroup_feature(ShaderSubgroupSupportHelper::Feature feature);
|
||||
|
||||
virtual void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id);
|
||||
virtual void emit_texture_op(const Instruction &i, bool sparse);
|
||||
virtual std::string to_texture_op(const Instruction &i, bool sparse, bool *forward,
|
||||
SmallVector<uint32_t> &inherited_expressions);
|
||||
virtual void emit_subgroup_op(const Instruction &i);
|
||||
virtual std::string type_to_glsl(const SPIRType &type, uint32_t id = 0);
|
||||
virtual std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage);
|
||||
virtual void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index,
|
||||
const std::string &qualifier = "", uint32_t base_offset = 0);
|
||||
virtual void emit_struct_padding_target(const SPIRType &type);
|
||||
virtual std::string image_type_glsl(const SPIRType &type, uint32_t id = 0);
|
||||
std::string constant_expression(const SPIRConstant &c);
|
||||
std::string constant_op_expression(const SPIRConstantOp &cop);
|
||||
virtual std::string constant_expression_vector(const SPIRConstant &c, uint32_t vector);
|
||||
virtual void emit_fixup();
|
||||
virtual std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id = 0);
|
||||
virtual bool variable_decl_is_remapped_storage(const SPIRVariable &var, spv::StorageClass storage) const;
|
||||
virtual std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id);
|
||||
|
||||
struct TextureFunctionBaseArguments
|
||||
{
|
||||
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
||||
TextureFunctionBaseArguments() = default;
|
||||
VariableID img = 0;
|
||||
const SPIRType *imgtype = nullptr;
|
||||
bool is_fetch = false, is_gather = false, is_proj = false;
|
||||
};
|
||||
|
||||
struct TextureFunctionNameArguments
|
||||
{
|
||||
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
||||
TextureFunctionNameArguments() = default;
|
||||
TextureFunctionBaseArguments base;
|
||||
bool has_array_offsets = false, has_offset = false, has_grad = false;
|
||||
bool has_dref = false, is_sparse_feedback = false, has_min_lod = false;
|
||||
uint32_t lod = 0;
|
||||
};
|
||||
virtual std::string to_function_name(const TextureFunctionNameArguments &args);
|
||||
|
||||
struct TextureFunctionArguments
|
||||
{
|
||||
// GCC 4.8 workarounds, it doesn't understand '{}' constructor here, use explicit default constructor.
|
||||
TextureFunctionArguments() = default;
|
||||
TextureFunctionBaseArguments base;
|
||||
uint32_t coord = 0, coord_components = 0, dref = 0;
|
||||
uint32_t grad_x = 0, grad_y = 0, lod = 0, coffset = 0, offset = 0;
|
||||
uint32_t bias = 0, component = 0, sample = 0, sparse_texel = 0, min_lod = 0;
|
||||
bool nonuniform_expression = false;
|
||||
};
|
||||
virtual std::string to_function_args(const TextureFunctionArguments &args, bool *p_forward);
|
||||
|
||||
void emit_sparse_feedback_temporaries(uint32_t result_type_id, uint32_t id, uint32_t &feedback_id,
|
||||
uint32_t &texel_id);
|
||||
uint32_t get_sparse_feedback_texel_id(uint32_t id) const;
|
||||
virtual void emit_buffer_block(const SPIRVariable &type);
|
||||
virtual void emit_push_constant_block(const SPIRVariable &var);
|
||||
virtual void emit_uniform(const SPIRVariable &var);
|
||||
virtual std::string unpack_expression_type(std::string expr_str, const SPIRType &type, uint32_t physical_type_id,
|
||||
bool packed_type, bool row_major);
|
||||
|
||||
virtual bool builtin_translates_to_nonarray(spv::BuiltIn builtin) const;
|
||||
|
||||
void emit_copy_logical_type(uint32_t lhs_id, uint32_t lhs_type_id, uint32_t rhs_id, uint32_t rhs_type_id,
|
||||
SmallVector<uint32_t> chain);
|
||||
|
||||
StringStream<> buffer;
|
||||
|
||||
template <typename T>
|
||||
inline void statement_inner(T &&t)
|
||||
{
|
||||
buffer << std::forward<T>(t);
|
||||
statement_count++;
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
inline void statement_inner(T &&t, Ts &&... ts)
|
||||
{
|
||||
buffer << std::forward<T>(t);
|
||||
statement_count++;
|
||||
statement_inner(std::forward<Ts>(ts)...);
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
inline void statement(Ts &&... ts)
|
||||
{
|
||||
if (is_forcing_recompilation())
|
||||
{
|
||||
// Do not bother emitting code while force_recompile is active.
|
||||
// We will compile again.
|
||||
statement_count++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (redirect_statement)
|
||||
{
|
||||
redirect_statement->push_back(join(std::forward<Ts>(ts)...));
|
||||
statement_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint32_t i = 0; i < indent; i++)
|
||||
buffer << " ";
|
||||
statement_inner(std::forward<Ts>(ts)...);
|
||||
buffer << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
inline void statement_no_indent(Ts &&... ts)
|
||||
{
|
||||
auto old_indent = indent;
|
||||
indent = 0;
|
||||
statement(std::forward<Ts>(ts)...);
|
||||
indent = old_indent;
|
||||
}
|
||||
|
||||
// Used for implementing continue blocks where
|
||||
// we want to obtain a list of statements we can merge
|
||||
// on a single line separated by comma.
|
||||
SmallVector<std::string> *redirect_statement = nullptr;
|
||||
const SPIRBlock *current_continue_block = nullptr;
|
||||
|
||||
void begin_scope();
|
||||
void end_scope();
|
||||
void end_scope(const std::string &trailer);
|
||||
void end_scope_decl();
|
||||
void end_scope_decl(const std::string &decl);
|
||||
|
||||
Options options;
|
||||
|
||||
virtual std::string type_to_array_glsl(
|
||||
const SPIRType &type); // Allow Metal to use the array<T> template to make arrays a value type
|
||||
std::string to_array_size(const SPIRType &type, uint32_t index);
|
||||
uint32_t to_array_size_literal(const SPIRType &type, uint32_t index) const;
|
||||
uint32_t to_array_size_literal(const SPIRType &type) const;
|
||||
virtual std::string variable_decl(const SPIRVariable &variable); // Threadgroup arrays can't have a wrapper type
|
||||
std::string variable_decl_function_local(SPIRVariable &variable);
|
||||
|
||||
void add_local_variable_name(uint32_t id);
|
||||
void add_resource_name(uint32_t id);
|
||||
void add_member_name(SPIRType &type, uint32_t name);
|
||||
void add_function_overload(const SPIRFunction &func);
|
||||
|
||||
virtual bool is_non_native_row_major_matrix(uint32_t id);
|
||||
virtual bool member_is_non_native_row_major_matrix(const SPIRType &type, uint32_t index);
|
||||
bool member_is_remapped_physical_type(const SPIRType &type, uint32_t index) const;
|
||||
bool member_is_packed_physical_type(const SPIRType &type, uint32_t index) const;
|
||||
virtual std::string convert_row_major_matrix(std::string exp_str, const SPIRType &exp_type,
|
||||
uint32_t physical_type_id, bool is_packed);
|
||||
|
||||
std::unordered_set<std::string> local_variable_names;
|
||||
std::unordered_set<std::string> resource_names;
|
||||
std::unordered_set<std::string> block_input_names;
|
||||
std::unordered_set<std::string> block_output_names;
|
||||
std::unordered_set<std::string> block_ubo_names;
|
||||
std::unordered_set<std::string> block_ssbo_names;
|
||||
std::unordered_set<std::string> block_names; // A union of all block_*_names.
|
||||
std::unordered_map<std::string, std::unordered_set<uint64_t>> function_overloads;
|
||||
std::unordered_map<uint32_t, std::string> preserved_aliases;
|
||||
void preserve_alias_on_reset(uint32_t id);
|
||||
void reset_name_caches();
|
||||
|
||||
bool processing_entry_point = false;
|
||||
|
||||
// Can be overriden by subclass backends for trivial things which
|
||||
// shouldn't need polymorphism.
|
||||
struct BackendVariations
|
||||
{
|
||||
std::string discard_literal = "discard";
|
||||
std::string demote_literal = "demote";
|
||||
std::string null_pointer_literal = "";
|
||||
bool float_literal_suffix = false;
|
||||
bool double_literal_suffix = true;
|
||||
bool uint32_t_literal_suffix = true;
|
||||
bool long_long_literal_suffix = false;
|
||||
const char *basic_int_type = "int";
|
||||
const char *basic_uint_type = "uint";
|
||||
const char *basic_int8_type = "int8_t";
|
||||
const char *basic_uint8_type = "uint8_t";
|
||||
const char *basic_int16_type = "int16_t";
|
||||
const char *basic_uint16_type = "uint16_t";
|
||||
const char *int16_t_literal_suffix = "s";
|
||||
const char *uint16_t_literal_suffix = "us";
|
||||
const char *nonuniform_qualifier = "nonuniformEXT";
|
||||
const char *boolean_mix_function = "mix";
|
||||
bool swizzle_is_function = false;
|
||||
bool shared_is_implied = false;
|
||||
bool unsized_array_supported = true;
|
||||
bool explicit_struct_type = false;
|
||||
bool use_initializer_list = false;
|
||||
bool use_typed_initializer_list = false;
|
||||
bool can_declare_struct_inline = true;
|
||||
bool can_declare_arrays_inline = true;
|
||||
bool native_row_major_matrix = true;
|
||||
bool use_constructor_splatting = true;
|
||||
bool allow_precision_qualifiers = false;
|
||||
bool can_swizzle_scalar = false;
|
||||
bool force_gl_in_out_block = false;
|
||||
bool can_return_array = true;
|
||||
bool allow_truncated_access_chain = false;
|
||||
bool supports_extensions = false;
|
||||
bool supports_empty_struct = false;
|
||||
bool array_is_value_type = true;
|
||||
bool buffer_offset_array_is_value_type = true;
|
||||
bool comparison_image_samples_scalar = false;
|
||||
bool native_pointers = false;
|
||||
bool support_small_type_sampling_result = false;
|
||||
bool support_case_fallthrough = true;
|
||||
bool use_array_constructor = false;
|
||||
bool needs_row_major_load_workaround = false;
|
||||
bool support_pointer_to_pointer = false;
|
||||
} backend;
|
||||
|
||||
void emit_struct(SPIRType &type);
|
||||
void emit_resources();
|
||||
void emit_extension_workarounds(spv::ExecutionModel model);
|
||||
void emit_buffer_block_native(const SPIRVariable &var);
|
||||
void emit_buffer_reference_block(SPIRType &type, bool forward_declaration);
|
||||
void emit_buffer_block_legacy(const SPIRVariable &var);
|
||||
void emit_buffer_block_flattened(const SPIRVariable &type);
|
||||
void fixup_implicit_builtin_block_names();
|
||||
void emit_declared_builtin_block(spv::StorageClass storage, spv::ExecutionModel model);
|
||||
bool should_force_emit_builtin_block(spv::StorageClass storage);
|
||||
void emit_push_constant_block_vulkan(const SPIRVariable &var);
|
||||
void emit_push_constant_block_glsl(const SPIRVariable &var);
|
||||
void emit_interface_block(const SPIRVariable &type);
|
||||
void emit_flattened_io_block(const SPIRVariable &var, const char *qual);
|
||||
void emit_flattened_io_block_struct(const std::string &basename, const SPIRType &type, const char *qual,
|
||||
const SmallVector<uint32_t> &indices);
|
||||
void emit_flattened_io_block_member(const std::string &basename, const SPIRType &type, const char *qual,
|
||||
const SmallVector<uint32_t> &indices);
|
||||
void emit_block_chain(SPIRBlock &block);
|
||||
void emit_hoisted_temporaries(SmallVector<std::pair<TypeID, ID>> &temporaries);
|
||||
std::string constant_value_macro_name(uint32_t id);
|
||||
void emit_constant(const SPIRConstant &constant);
|
||||
void emit_specialization_constant_op(const SPIRConstantOp &constant);
|
||||
std::string emit_continue_block(uint32_t continue_block, bool follow_true_block, bool follow_false_block);
|
||||
bool attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method method);
|
||||
|
||||
void branch(BlockID from, BlockID to);
|
||||
void branch_to_continue(BlockID from, BlockID to);
|
||||
void branch(BlockID from, uint32_t cond, BlockID true_block, BlockID false_block);
|
||||
void flush_phi(BlockID from, BlockID to);
|
||||
void flush_variable_declaration(uint32_t id);
|
||||
void flush_undeclared_variables(SPIRBlock &block);
|
||||
void emit_variable_temporary_copies(const SPIRVariable &var);
|
||||
|
||||
bool should_dereference(uint32_t id);
|
||||
bool should_forward(uint32_t id) const;
|
||||
bool should_suppress_usage_tracking(uint32_t id) const;
|
||||
void emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left, uint32_t right, uint32_t lerp);
|
||||
void emit_nminmax_op(uint32_t result_type, uint32_t id, uint32_t op0, uint32_t op1, GLSLstd450 op);
|
||||
bool to_trivial_mix_op(const SPIRType &type, std::string &op, uint32_t left, uint32_t right, uint32_t lerp);
|
||||
void emit_quaternary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
uint32_t op3, const char *op);
|
||||
void emit_trinary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
const char *op);
|
||||
void emit_binary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
||||
void emit_atomic_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
||||
void emit_atomic_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2, const char *op);
|
||||
|
||||
void emit_unary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op,
|
||||
SPIRType::BaseType input_type, SPIRType::BaseType expected_result_type);
|
||||
void emit_binary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
||||
SPIRType::BaseType input_type, bool skip_cast_if_equal_type);
|
||||
void emit_binary_func_op_cast_clustered(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
|
||||
const char *op, SPIRType::BaseType input_type);
|
||||
void emit_trinary_func_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
const char *op, SPIRType::BaseType input_type);
|
||||
void emit_trinary_func_op_bitextract(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1,
|
||||
uint32_t op2, const char *op, SPIRType::BaseType expected_result_type,
|
||||
SPIRType::BaseType input_type0, SPIRType::BaseType input_type1,
|
||||
SPIRType::BaseType input_type2);
|
||||
void emit_bitfield_insert_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, uint32_t op2,
|
||||
uint32_t op3, const char *op, SPIRType::BaseType offset_count_type);
|
||||
|
||||
void emit_unary_func_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
||||
void emit_unrolled_unary_op(uint32_t result_type, uint32_t result_id, uint32_t operand, const char *op);
|
||||
void emit_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op);
|
||||
void emit_unrolled_binary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
||||
bool negate, SPIRType::BaseType expected_type);
|
||||
void emit_binary_op_cast(uint32_t result_type, uint32_t result_id, uint32_t op0, uint32_t op1, const char *op,
|
||||
SPIRType::BaseType input_type, bool skip_cast_if_equal_type);
|
||||
|
||||
SPIRType binary_op_bitcast_helper(std::string &cast_op0, std::string &cast_op1, SPIRType::BaseType &input_type,
|
||||
uint32_t op0, uint32_t op1, bool skip_cast_if_equal_type);
|
||||
|
||||
virtual bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0);
|
||||
|
||||
std::string to_ternary_expression(const SPIRType &result_type, uint32_t select, uint32_t true_value,
|
||||
uint32_t false_value);
|
||||
|
||||
void emit_unary_op(uint32_t result_type, uint32_t result_id, uint32_t op0, const char *op);
|
||||
bool expression_is_forwarded(uint32_t id) const;
|
||||
bool expression_suppresses_usage_tracking(uint32_t id) const;
|
||||
bool expression_read_implies_multiple_reads(uint32_t id) const;
|
||||
SPIRExpression &emit_op(uint32_t result_type, uint32_t result_id, const std::string &rhs, bool forward_rhs,
|
||||
bool suppress_usage_tracking = false);
|
||||
|
||||
void access_chain_internal_append_index(std::string &expr, uint32_t base, const SPIRType *type,
|
||||
AccessChainFlags flags, bool &access_chain_is_arrayed, uint32_t index);
|
||||
|
||||
std::string access_chain_internal(uint32_t base, const uint32_t *indices, uint32_t count, AccessChainFlags flags,
|
||||
AccessChainMeta *meta);
|
||||
|
||||
spv::StorageClass get_expression_effective_storage_class(uint32_t ptr);
|
||||
virtual bool access_chain_needs_stage_io_builtin_translation(uint32_t base);
|
||||
|
||||
virtual void prepare_access_chain_for_scalar_access(std::string &expr, const SPIRType &type,
|
||||
spv::StorageClass storage, bool &is_packed);
|
||||
|
||||
std::string access_chain(uint32_t base, const uint32_t *indices, uint32_t count, const SPIRType &target_type,
|
||||
AccessChainMeta *meta = nullptr, bool ptr_chain = false);
|
||||
|
||||
std::string flattened_access_chain(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
||||
uint32_t array_stride, bool need_transpose);
|
||||
std::string flattened_access_chain_struct(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset);
|
||||
std::string flattened_access_chain_matrix(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
||||
bool need_transpose);
|
||||
std::string flattened_access_chain_vector(uint32_t base, const uint32_t *indices, uint32_t count,
|
||||
const SPIRType &target_type, uint32_t offset, uint32_t matrix_stride,
|
||||
bool need_transpose);
|
||||
std::pair<std::string, uint32_t> flattened_access_chain_offset(const SPIRType &basetype, const uint32_t *indices,
|
||||
uint32_t count, uint32_t offset,
|
||||
uint32_t word_stride, bool *need_transpose = nullptr,
|
||||
uint32_t *matrix_stride = nullptr,
|
||||
uint32_t *array_stride = nullptr,
|
||||
bool ptr_chain = false);
|
||||
|
||||
const char *index_to_swizzle(uint32_t index);
|
||||
std::string remap_swizzle(const SPIRType &result_type, uint32_t input_components, const std::string &expr);
|
||||
std::string declare_temporary(uint32_t type, uint32_t id);
|
||||
void emit_uninitialized_temporary(uint32_t type, uint32_t id);
|
||||
SPIRExpression &emit_uninitialized_temporary_expression(uint32_t type, uint32_t id);
|
||||
void append_global_func_args(const SPIRFunction &func, uint32_t index, SmallVector<std::string> &arglist);
|
||||
std::string to_non_uniform_aware_expression(uint32_t id);
|
||||
std::string to_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_composite_constructor_expression(uint32_t id, bool uses_buffer_offset);
|
||||
std::string to_rerolled_array_expression(const std::string &expr, const SPIRType &type);
|
||||
std::string to_enclosed_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_unpacked_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_unpacked_row_major_matrix_expression(uint32_t id);
|
||||
std::string to_enclosed_unpacked_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_dereferenced_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_pointer_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_enclosed_pointer_expression(uint32_t id, bool register_expression_read = true);
|
||||
std::string to_extract_component_expression(uint32_t id, uint32_t index);
|
||||
std::string to_extract_constant_composite_expression(uint32_t result_type, const SPIRConstant &c,
|
||||
const uint32_t *chain, uint32_t length);
|
||||
std::string enclose_expression(const std::string &expr);
|
||||
std::string dereference_expression(const SPIRType &expression_type, const std::string &expr);
|
||||
std::string address_of_expression(const std::string &expr);
|
||||
void strip_enclosed_expression(std::string &expr);
|
||||
std::string to_member_name(const SPIRType &type, uint32_t index);
|
||||
virtual std::string to_member_reference(uint32_t base, const SPIRType &type, uint32_t index, bool ptr_chain);
|
||||
std::string to_multi_member_reference(const SPIRType &type, const SmallVector<uint32_t> &indices);
|
||||
std::string type_to_glsl_constructor(const SPIRType &type);
|
||||
std::string argument_decl(const SPIRFunction::Parameter &arg);
|
||||
virtual std::string to_qualifiers_glsl(uint32_t id);
|
||||
void fixup_io_block_patch_qualifiers(const SPIRVariable &var);
|
||||
void emit_output_variable_initializer(const SPIRVariable &var);
|
||||
const char *to_precision_qualifiers_glsl(uint32_t id);
|
||||
virtual const char *to_storage_qualifiers_glsl(const SPIRVariable &var);
|
||||
const char *flags_to_qualifiers_glsl(const SPIRType &type, const Bitset &flags);
|
||||
const char *format_to_glsl(spv::ImageFormat format);
|
||||
virtual std::string layout_for_member(const SPIRType &type, uint32_t index);
|
||||
virtual std::string to_interpolation_qualifiers(const Bitset &flags);
|
||||
std::string layout_for_variable(const SPIRVariable &variable);
|
||||
std::string to_combined_image_sampler(VariableID image_id, VariableID samp_id);
|
||||
virtual bool skip_argument(uint32_t id) const;
|
||||
virtual void emit_array_copy(const std::string &lhs, uint32_t lhs_id, uint32_t rhs_id,
|
||||
spv::StorageClass lhs_storage, spv::StorageClass rhs_storage);
|
||||
virtual void emit_block_hints(const SPIRBlock &block);
|
||||
virtual std::string to_initializer_expression(const SPIRVariable &var);
|
||||
virtual std::string to_zero_initialized_expression(uint32_t type_id);
|
||||
bool type_can_zero_initialize(const SPIRType &type) const;
|
||||
|
||||
bool buffer_is_packing_standard(const SPIRType &type, BufferPackingStandard packing,
|
||||
uint32_t *failed_index = nullptr, uint32_t start_offset = 0,
|
||||
uint32_t end_offset = ~(0u));
|
||||
std::string buffer_to_packing_standard(const SPIRType &type, bool support_std430_without_scalar_layout);
|
||||
|
||||
uint32_t type_to_packed_base_size(const SPIRType &type, BufferPackingStandard packing);
|
||||
uint32_t type_to_packed_alignment(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
||||
uint32_t type_to_packed_array_stride(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
||||
uint32_t type_to_packed_size(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing);
|
||||
uint32_t type_to_location_count(const SPIRType &type) const;
|
||||
|
||||
std::string bitcast_glsl(const SPIRType &result_type, uint32_t arg);
|
||||
virtual std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type);
|
||||
|
||||
std::string bitcast_expression(SPIRType::BaseType target_type, uint32_t arg);
|
||||
std::string bitcast_expression(const SPIRType &target_type, SPIRType::BaseType expr_type, const std::string &expr);
|
||||
|
||||
std::string build_composite_combiner(uint32_t result_type, const uint32_t *elems, uint32_t length);
|
||||
bool remove_duplicate_swizzle(std::string &op);
|
||||
bool remove_unity_swizzle(uint32_t base, std::string &op);
|
||||
|
||||
// Can modify flags to remote readonly/writeonly if image type
|
||||
// and force recompile.
|
||||
bool check_atomic_image(uint32_t id);
|
||||
|
||||
virtual void replace_illegal_names();
|
||||
void replace_illegal_names(const std::unordered_set<std::string> &keywords);
|
||||
virtual void emit_entry_point_declarations();
|
||||
|
||||
void replace_fragment_output(SPIRVariable &var);
|
||||
void replace_fragment_outputs();
|
||||
std::string legacy_tex_op(const std::string &op, const SPIRType &imgtype, uint32_t id);
|
||||
|
||||
uint32_t indent = 0;
|
||||
|
||||
std::unordered_set<uint32_t> emitted_functions;
|
||||
|
||||
// Ensure that we declare phi-variable copies even if the original declaration isn't deferred
|
||||
std::unordered_set<uint32_t> flushed_phi_variables;
|
||||
|
||||
std::unordered_set<uint32_t> flattened_buffer_blocks;
|
||||
std::unordered_map<uint32_t, bool> flattened_structs;
|
||||
|
||||
ShaderSubgroupSupportHelper shader_subgroup_supporter;
|
||||
|
||||
std::string load_flattened_struct(const std::string &basename, const SPIRType &type);
|
||||
std::string to_flattened_struct_member(const std::string &basename, const SPIRType &type, uint32_t index);
|
||||
void store_flattened_struct(uint32_t lhs_id, uint32_t value);
|
||||
void store_flattened_struct(const std::string &basename, uint32_t rhs, const SPIRType &type,
|
||||
const SmallVector<uint32_t> &indices);
|
||||
std::string to_flattened_access_chain_expression(uint32_t id);
|
||||
|
||||
// Usage tracking. If a temporary is used more than once, use the temporary instead to
|
||||
// avoid AST explosion when SPIRV is generated with pure SSA and doesn't write stuff to variables.
|
||||
std::unordered_map<uint32_t, uint32_t> expression_usage_counts;
|
||||
void track_expression_read(uint32_t id);
|
||||
|
||||
SmallVector<std::string> forced_extensions;
|
||||
SmallVector<std::string> header_lines;
|
||||
|
||||
// Used when expressions emit extra opcodes with their own unique IDs,
|
||||
// and we need to reuse the IDs across recompilation loops.
|
||||
// Currently used by NMin/Max/Clamp implementations.
|
||||
std::unordered_map<uint32_t, uint32_t> extra_sub_expressions;
|
||||
|
||||
SmallVector<TypeID> workaround_ubo_load_overload_types;
|
||||
void request_workaround_wrapper_overload(TypeID id);
|
||||
void rewrite_load_for_wrapped_row_major(std::string &expr, TypeID loaded_type, ID ptr);
|
||||
|
||||
uint32_t statement_count = 0;
|
||||
|
||||
inline bool is_legacy() const
|
||||
{
|
||||
return (options.es && options.version < 300) || (!options.es && options.version < 130);
|
||||
}
|
||||
|
||||
inline bool is_legacy_es() const
|
||||
{
|
||||
return options.es && options.version < 300;
|
||||
}
|
||||
|
||||
inline bool is_legacy_desktop() const
|
||||
{
|
||||
return !options.es && options.version < 130;
|
||||
}
|
||||
|
||||
bool requires_transpose_2x2 = false;
|
||||
bool requires_transpose_3x3 = false;
|
||||
bool requires_transpose_4x4 = false;
|
||||
bool ray_tracing_is_khr = false;
|
||||
void ray_tracing_khr_fixup_locations();
|
||||
|
||||
bool args_will_forward(uint32_t id, const uint32_t *args, uint32_t num_args, bool pure);
|
||||
void register_call_out_argument(uint32_t id);
|
||||
void register_impure_function_call();
|
||||
void register_control_dependent_expression(uint32_t expr);
|
||||
|
||||
// GL_EXT_shader_pixel_local_storage support.
|
||||
std::vector<PlsRemap> pls_inputs;
|
||||
std::vector<PlsRemap> pls_outputs;
|
||||
std::string pls_decl(const PlsRemap &variable);
|
||||
const char *to_pls_qualifiers_glsl(const SPIRVariable &variable);
|
||||
void emit_pls();
|
||||
void remap_pls_variables();
|
||||
|
||||
// GL_EXT_shader_framebuffer_fetch support.
|
||||
std::vector<std::pair<uint32_t, uint32_t>> subpass_to_framebuffer_fetch_attachment;
|
||||
std::unordered_set<uint32_t> inout_color_attachments;
|
||||
bool subpass_input_is_framebuffer_fetch(uint32_t id) const;
|
||||
void emit_inout_fragment_outputs_copy_to_subpass_inputs();
|
||||
const SPIRVariable *find_subpass_input_by_attachment_index(uint32_t index) const;
|
||||
const SPIRVariable *find_color_output_by_location(uint32_t location) const;
|
||||
|
||||
// A variant which takes two sets of name. The secondary is only used to verify there are no collisions,
|
||||
// but the set is not updated when we have found a new name.
|
||||
// Used primarily when adding block interface names.
|
||||
void add_variable(std::unordered_set<std::string> &variables_primary,
|
||||
const std::unordered_set<std::string> &variables_secondary, std::string &name);
|
||||
|
||||
void check_function_call_constraints(const uint32_t *args, uint32_t length);
|
||||
void handle_invalid_expression(uint32_t id);
|
||||
void find_static_extensions();
|
||||
|
||||
std::string emit_for_loop_initializers(const SPIRBlock &block);
|
||||
void emit_while_loop_initializers(const SPIRBlock &block);
|
||||
bool for_loop_initializers_are_same_type(const SPIRBlock &block);
|
||||
bool optimize_read_modify_write(const SPIRType &type, const std::string &lhs, const std::string &rhs);
|
||||
void fixup_image_load_store_access();
|
||||
|
||||
bool type_is_empty(const SPIRType &type);
|
||||
|
||||
virtual void declare_undefined_values();
|
||||
|
||||
bool can_use_io_location(spv::StorageClass storage, bool block);
|
||||
const Instruction *get_next_instruction_in_block(const Instruction &instr);
|
||||
static uint32_t mask_relevant_memory_semantics(uint32_t semantics);
|
||||
|
||||
std::string convert_half_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
||||
std::string convert_float_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
||||
std::string convert_double_to_string(const SPIRConstant &value, uint32_t col, uint32_t row);
|
||||
|
||||
std::string convert_separate_image_to_expression(uint32_t id);
|
||||
|
||||
// Builtins in GLSL are always specific signedness, but the SPIR-V can declare them
|
||||
// as either unsigned or signed.
|
||||
// Sometimes we will need to automatically perform casts on load and store to make this work.
|
||||
virtual void cast_to_builtin_store(uint32_t target_id, std::string &expr, const SPIRType &expr_type);
|
||||
virtual void cast_from_builtin_load(uint32_t source_id, std::string &expr, const SPIRType &expr_type);
|
||||
void unroll_array_from_complex_load(uint32_t target_id, uint32_t source_id, std::string &expr);
|
||||
bool unroll_array_to_complex_store(uint32_t target_id, uint32_t source_id);
|
||||
void convert_non_uniform_expression(std::string &expr, uint32_t ptr_id);
|
||||
|
||||
void handle_store_to_invariant_variable(uint32_t store_id, uint32_t value_id);
|
||||
void disallow_forwarding_in_expression_chain(const SPIRExpression &expr);
|
||||
|
||||
bool expression_is_constant_null(uint32_t id) const;
|
||||
bool expression_is_non_value_type_array(uint32_t ptr);
|
||||
virtual void emit_store_statement(uint32_t lhs_expression, uint32_t rhs_expression);
|
||||
|
||||
uint32_t get_integer_width_for_instruction(const Instruction &instr) const;
|
||||
uint32_t get_integer_width_for_glsl_instruction(GLSLstd450 op, const uint32_t *arguments, uint32_t length) const;
|
||||
|
||||
bool variable_is_lut(const SPIRVariable &var) const;
|
||||
|
||||
char current_locale_radix_character = '.';
|
||||
|
||||
void fixup_type_alias();
|
||||
void reorder_type_alias();
|
||||
|
||||
static const char *vector_swizzle(int vecsize, int index);
|
||||
|
||||
bool is_stage_output_location_masked(uint32_t location, uint32_t component) const;
|
||||
bool is_stage_output_builtin_masked(spv::BuiltIn builtin) const;
|
||||
bool is_stage_output_variable_masked(const SPIRVariable &var) const;
|
||||
bool is_stage_output_block_member_masked(const SPIRVariable &var, uint32_t index, bool strip_array) const;
|
||||
uint32_t get_accumulated_member_location(const SPIRVariable &var, uint32_t mbr_idx, bool strip_array) const;
|
||||
uint32_t get_declared_member_location(const SPIRVariable &var, uint32_t mbr_idx, bool strip_array) const;
|
||||
std::unordered_set<LocationComponentPair, InternalHasher> masked_output_locations;
|
||||
std::unordered_set<uint32_t> masked_output_builtins;
|
||||
|
||||
private:
|
||||
void init();
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,375 @@
|
||||
/*
|
||||
* Copyright 2016-2021 Robert Konrad
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_HLSL_HPP
|
||||
#define SPIRV_HLSL_HPP
|
||||
|
||||
#include "spirv_glsl.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
// Interface which remaps vertex inputs to a fixed semantic name to make linking easier.
|
||||
struct HLSLVertexAttributeRemap
|
||||
{
|
||||
uint32_t location;
|
||||
std::string semantic;
|
||||
};
|
||||
// Specifying a root constant (d3d12) or push constant range (vulkan).
|
||||
//
|
||||
// `start` and `end` denotes the range of the root constant in bytes.
|
||||
// Both values need to be multiple of 4.
|
||||
struct RootConstants
|
||||
{
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
|
||||
uint32_t binding;
|
||||
uint32_t space;
|
||||
};
|
||||
|
||||
// For finer control, decorations may be removed from specific resources instead with unset_decoration().
|
||||
enum HLSLBindingFlagBits
|
||||
{
|
||||
HLSL_BINDING_AUTO_NONE_BIT = 0,
|
||||
|
||||
// Push constant (root constant) resources will be declared as CBVs (b-space) without a register() declaration.
|
||||
// A register will be automatically assigned by the D3D compiler, but must therefore be reflected in D3D-land.
|
||||
// Push constants do not normally have a DecorationBinding set, but if they do, this can be used to ignore it.
|
||||
HLSL_BINDING_AUTO_PUSH_CONSTANT_BIT = 1 << 0,
|
||||
|
||||
// cbuffer resources will be declared as CBVs (b-space) without a register() declaration.
|
||||
// A register will be automatically assigned, but must be reflected in D3D-land.
|
||||
HLSL_BINDING_AUTO_CBV_BIT = 1 << 1,
|
||||
|
||||
// All SRVs (t-space) will be declared without a register() declaration.
|
||||
HLSL_BINDING_AUTO_SRV_BIT = 1 << 2,
|
||||
|
||||
// All UAVs (u-space) will be declared without a register() declaration.
|
||||
HLSL_BINDING_AUTO_UAV_BIT = 1 << 3,
|
||||
|
||||
// All samplers (s-space) will be declared without a register() declaration.
|
||||
HLSL_BINDING_AUTO_SAMPLER_BIT = 1 << 4,
|
||||
|
||||
// No resources will be declared with register().
|
||||
HLSL_BINDING_AUTO_ALL = 0x7fffffff
|
||||
};
|
||||
using HLSLBindingFlags = uint32_t;
|
||||
|
||||
// By matching stage, desc_set and binding for a SPIR-V resource,
|
||||
// register bindings are set based on whether the HLSL resource is a
|
||||
// CBV, UAV, SRV or Sampler. A single binding in SPIR-V might contain multiple
|
||||
// resource types, e.g. COMBINED_IMAGE_SAMPLER, and SRV/Sampler bindings will be used respectively.
|
||||
// On SM 5.0 and lower, register_space is ignored.
|
||||
//
|
||||
// To remap a push constant block which does not have any desc_set/binding associated with it,
|
||||
// use ResourceBindingPushConstant{DescriptorSet,Binding} as values for desc_set/binding.
|
||||
// For deeper control of push constants, set_root_constant_layouts() can be used instead.
|
||||
struct HLSLResourceBinding
|
||||
{
|
||||
spv::ExecutionModel stage = spv::ExecutionModelMax;
|
||||
uint32_t desc_set = 0;
|
||||
uint32_t binding = 0;
|
||||
|
||||
struct Binding
|
||||
{
|
||||
uint32_t register_space = 0;
|
||||
uint32_t register_binding = 0;
|
||||
} cbv, uav, srv, sampler;
|
||||
};
|
||||
|
||||
class CompilerHLSL : public CompilerGLSL
|
||||
{
|
||||
public:
|
||||
struct Options
|
||||
{
|
||||
uint32_t shader_model = 30; // TODO: map ps_4_0_level_9_0,... somehow
|
||||
|
||||
// Allows the PointSize builtin, and ignores it, as PointSize is not supported in HLSL.
|
||||
bool point_size_compat = false;
|
||||
|
||||
// Allows the PointCoord builtin, returns float2(0.5, 0.5), as PointCoord is not supported in HLSL.
|
||||
bool point_coord_compat = false;
|
||||
|
||||
// If true, the backend will assume that VertexIndex and InstanceIndex will need to apply
|
||||
// a base offset, and you will need to fill in a cbuffer with offsets.
|
||||
// Set to false if you know you will never use base instance or base vertex
|
||||
// functionality as it might remove an internal cbuffer.
|
||||
bool support_nonzero_base_vertex_base_instance = false;
|
||||
|
||||
// Forces a storage buffer to always be declared as UAV, even if the readonly decoration is used.
|
||||
// By default, a readonly storage buffer will be declared as ByteAddressBuffer (SRV) instead.
|
||||
// Alternatively, use set_hlsl_force_storage_buffer_as_uav to specify individually.
|
||||
bool force_storage_buffer_as_uav = false;
|
||||
|
||||
// Forces any storage image type marked as NonWritable to be considered an SRV instead.
|
||||
// For this to work with function call parameters, NonWritable must be considered to be part of the type system
|
||||
// so that NonWritable image arguments are also translated to Texture rather than RWTexture.
|
||||
bool nonwritable_uav_texture_as_srv = false;
|
||||
|
||||
// Enables native 16-bit types. Needs SM 6.2.
|
||||
// Uses half/int16_t/uint16_t instead of min16* types.
|
||||
// Also adds support for 16-bit load-store from (RW)ByteAddressBuffer.
|
||||
bool enable_16bit_types = false;
|
||||
|
||||
// If matrices are used as IO variables, flatten the attribute declaration to use
|
||||
// TEXCOORD{N,N+1,N+2,...} rather than TEXCOORDN_{0,1,2,3}.
|
||||
// If add_vertex_attribute_remap is used and this feature is used,
|
||||
// the semantic name will be queried once per active location.
|
||||
bool flatten_matrix_vertex_input_semantics = false;
|
||||
};
|
||||
|
||||
explicit CompilerHLSL(std::vector<uint32_t> spirv_)
|
||||
: CompilerGLSL(std::move(spirv_))
|
||||
{
|
||||
}
|
||||
|
||||
CompilerHLSL(const uint32_t *ir_, size_t size)
|
||||
: CompilerGLSL(ir_, size)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CompilerHLSL(const ParsedIR &ir_)
|
||||
: CompilerGLSL(ir_)
|
||||
{
|
||||
}
|
||||
|
||||
explicit CompilerHLSL(ParsedIR &&ir_)
|
||||
: CompilerGLSL(std::move(ir_))
|
||||
{
|
||||
}
|
||||
|
||||
const Options &get_hlsl_options() const
|
||||
{
|
||||
return hlsl_options;
|
||||
}
|
||||
|
||||
void set_hlsl_options(const Options &opts)
|
||||
{
|
||||
hlsl_options = opts;
|
||||
}
|
||||
|
||||
// Optionally specify a custom root constant layout.
|
||||
//
|
||||
// Push constants ranges will be split up according to the
|
||||
// layout specified.
|
||||
void set_root_constant_layouts(std::vector<RootConstants> layout);
|
||||
|
||||
// Compiles and remaps vertex attributes at specific locations to a fixed semantic.
|
||||
// The default is TEXCOORD# where # denotes location.
|
||||
// Matrices are unrolled to vectors with notation ${SEMANTIC}_#, where # denotes row.
|
||||
// $SEMANTIC is either TEXCOORD# or a semantic name specified here.
|
||||
void add_vertex_attribute_remap(const HLSLVertexAttributeRemap &vertex_attributes);
|
||||
std::string compile() override;
|
||||
|
||||
// This is a special HLSL workaround for the NumWorkGroups builtin.
|
||||
// This does not exist in HLSL, so the calling application must create a dummy cbuffer in
|
||||
// which the application will store this builtin.
|
||||
// The cbuffer layout will be:
|
||||
// cbuffer SPIRV_Cross_NumWorkgroups : register(b#, space#) { uint3 SPIRV_Cross_NumWorkgroups_count; };
|
||||
// This must be called before compile().
|
||||
// The function returns 0 if NumWorkGroups builtin is not statically used in the shader from the current entry point.
|
||||
// If non-zero, this returns the variable ID of a cbuffer which corresponds to
|
||||
// the cbuffer declared above. By default, no binding or descriptor set decoration is set,
|
||||
// so the calling application should declare explicit bindings on this ID before calling compile().
|
||||
VariableID remap_num_workgroups_builtin();
|
||||
|
||||
// Controls how resource bindings are declared in the output HLSL.
|
||||
void set_resource_binding_flags(HLSLBindingFlags flags);
|
||||
|
||||
// resource is a resource binding to indicate the HLSL CBV, SRV, UAV or sampler binding
|
||||
// to use for a particular SPIR-V description set
|
||||
// and binding. If resource bindings are provided,
|
||||
// is_hlsl_resource_binding_used() will return true after calling ::compile() if
|
||||
// the set/binding combination was used by the HLSL code.
|
||||
void add_hlsl_resource_binding(const HLSLResourceBinding &resource);
|
||||
bool is_hlsl_resource_binding_used(spv::ExecutionModel model, uint32_t set, uint32_t binding) const;
|
||||
|
||||
// Controls which storage buffer bindings will be forced to be declared as UAVs.
|
||||
void set_hlsl_force_storage_buffer_as_uav(uint32_t desc_set, uint32_t binding);
|
||||
|
||||
private:
|
||||
std::string type_to_glsl(const SPIRType &type, uint32_t id = 0) override;
|
||||
std::string image_type_hlsl(const SPIRType &type, uint32_t id);
|
||||
std::string image_type_hlsl_modern(const SPIRType &type, uint32_t id);
|
||||
std::string image_type_hlsl_legacy(const SPIRType &type, uint32_t id);
|
||||
void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
|
||||
void emit_hlsl_entry_point();
|
||||
void emit_header() override;
|
||||
void emit_resources();
|
||||
void declare_undefined_values() override;
|
||||
void emit_interface_block_globally(const SPIRVariable &type);
|
||||
void emit_interface_block_in_struct(const SPIRVariable &type, std::unordered_set<uint32_t> &active_locations);
|
||||
void emit_builtin_inputs_in_struct();
|
||||
void emit_builtin_outputs_in_struct();
|
||||
void emit_texture_op(const Instruction &i, bool sparse) override;
|
||||
void emit_instruction(const Instruction &instruction) override;
|
||||
void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args,
|
||||
uint32_t count) override;
|
||||
void emit_buffer_block(const SPIRVariable &type) override;
|
||||
void emit_push_constant_block(const SPIRVariable &var) override;
|
||||
void emit_uniform(const SPIRVariable &var) override;
|
||||
void emit_modern_uniform(const SPIRVariable &var);
|
||||
void emit_legacy_uniform(const SPIRVariable &var);
|
||||
void emit_specialization_constants_and_structs();
|
||||
void emit_composite_constants();
|
||||
void emit_fixup() override;
|
||||
std::string builtin_to_glsl(spv::BuiltIn builtin, spv::StorageClass storage) override;
|
||||
std::string layout_for_member(const SPIRType &type, uint32_t index) override;
|
||||
std::string to_interpolation_qualifiers(const Bitset &flags) override;
|
||||
std::string bitcast_glsl_op(const SPIRType &result_type, const SPIRType &argument_type) override;
|
||||
bool emit_complex_bitcast(uint32_t result_type, uint32_t id, uint32_t op0) override;
|
||||
std::string to_func_call_arg(const SPIRFunction::Parameter &arg, uint32_t id) override;
|
||||
std::string to_sampler_expression(uint32_t id);
|
||||
std::string to_resource_binding(const SPIRVariable &var);
|
||||
std::string to_resource_binding_sampler(const SPIRVariable &var);
|
||||
std::string to_resource_register(HLSLBindingFlagBits flag, char space, uint32_t binding, uint32_t set);
|
||||
std::string to_initializer_expression(const SPIRVariable &var) override;
|
||||
void emit_sampled_image_op(uint32_t result_type, uint32_t result_id, uint32_t image_id, uint32_t samp_id) override;
|
||||
void emit_access_chain(const Instruction &instruction);
|
||||
void emit_load(const Instruction &instruction);
|
||||
void read_access_chain(std::string *expr, const std::string &lhs, const SPIRAccessChain &chain);
|
||||
void read_access_chain_struct(const std::string &lhs, const SPIRAccessChain &chain);
|
||||
void read_access_chain_array(const std::string &lhs, const SPIRAccessChain &chain);
|
||||
void write_access_chain(const SPIRAccessChain &chain, uint32_t value, const SmallVector<uint32_t> &composite_chain);
|
||||
void write_access_chain_struct(const SPIRAccessChain &chain, uint32_t value,
|
||||
const SmallVector<uint32_t> &composite_chain);
|
||||
void write_access_chain_array(const SPIRAccessChain &chain, uint32_t value,
|
||||
const SmallVector<uint32_t> &composite_chain);
|
||||
std::string write_access_chain_value(uint32_t value, const SmallVector<uint32_t> &composite_chain, bool enclose);
|
||||
void emit_store(const Instruction &instruction);
|
||||
void emit_atomic(const uint32_t *ops, uint32_t length, spv::Op op);
|
||||
void emit_subgroup_op(const Instruction &i) override;
|
||||
void emit_block_hints(const SPIRBlock &block) override;
|
||||
|
||||
void emit_struct_member(const SPIRType &type, uint32_t member_type_id, uint32_t index, const std::string &qualifier,
|
||||
uint32_t base_offset = 0) override;
|
||||
|
||||
const char *to_storage_qualifiers_glsl(const SPIRVariable &var) override;
|
||||
void replace_illegal_names() override;
|
||||
|
||||
bool is_hlsl_force_storage_buffer_as_uav(ID id) const;
|
||||
|
||||
Options hlsl_options;
|
||||
|
||||
// TODO: Refactor this to be more similar to MSL, maybe have some common system in place?
|
||||
bool requires_op_fmod = false;
|
||||
bool requires_fp16_packing = false;
|
||||
bool requires_uint2_packing = false;
|
||||
bool requires_explicit_fp16_packing = false;
|
||||
bool requires_unorm8_packing = false;
|
||||
bool requires_snorm8_packing = false;
|
||||
bool requires_unorm16_packing = false;
|
||||
bool requires_snorm16_packing = false;
|
||||
bool requires_bitfield_insert = false;
|
||||
bool requires_bitfield_extract = false;
|
||||
bool requires_inverse_2x2 = false;
|
||||
bool requires_inverse_3x3 = false;
|
||||
bool requires_inverse_4x4 = false;
|
||||
bool requires_scalar_reflect = false;
|
||||
bool requires_scalar_refract = false;
|
||||
bool requires_scalar_faceforward = false;
|
||||
|
||||
struct TextureSizeVariants
|
||||
{
|
||||
// MSVC 2013 workaround.
|
||||
TextureSizeVariants()
|
||||
{
|
||||
srv = 0;
|
||||
for (auto &unorm : uav)
|
||||
for (auto &u : unorm)
|
||||
u = 0;
|
||||
}
|
||||
uint64_t srv;
|
||||
uint64_t uav[3][4];
|
||||
} required_texture_size_variants;
|
||||
|
||||
void require_texture_query_variant(uint32_t var_id);
|
||||
void emit_texture_size_variants(uint64_t variant_mask, const char *vecsize_qualifier, bool uav,
|
||||
const char *type_qualifier);
|
||||
|
||||
enum TextureQueryVariantDim
|
||||
{
|
||||
Query1D = 0,
|
||||
Query1DArray,
|
||||
Query2D,
|
||||
Query2DArray,
|
||||
Query3D,
|
||||
QueryBuffer,
|
||||
QueryCube,
|
||||
QueryCubeArray,
|
||||
Query2DMS,
|
||||
Query2DMSArray,
|
||||
QueryDimCount
|
||||
};
|
||||
|
||||
enum TextureQueryVariantType
|
||||
{
|
||||
QueryTypeFloat = 0,
|
||||
QueryTypeInt = 16,
|
||||
QueryTypeUInt = 32,
|
||||
QueryTypeCount = 3
|
||||
};
|
||||
|
||||
enum BitcastType
|
||||
{
|
||||
TypeNormal,
|
||||
TypePackUint2x32,
|
||||
TypeUnpackUint64
|
||||
};
|
||||
|
||||
BitcastType get_bitcast_type(uint32_t result_type, uint32_t op0);
|
||||
|
||||
void emit_builtin_variables();
|
||||
bool require_output = false;
|
||||
bool require_input = false;
|
||||
SmallVector<HLSLVertexAttributeRemap> remap_vertex_attributes;
|
||||
|
||||
uint32_t type_to_consumed_locations(const SPIRType &type) const;
|
||||
|
||||
void emit_io_block(const SPIRVariable &var);
|
||||
std::string to_semantic(uint32_t location, spv::ExecutionModel em, spv::StorageClass sc);
|
||||
|
||||
uint32_t num_workgroups_builtin = 0;
|
||||
HLSLBindingFlags resource_binding_flags = 0;
|
||||
|
||||
// Custom root constant layout, which should be emitted
|
||||
// when translating push constant ranges.
|
||||
std::vector<RootConstants> root_constants_layout;
|
||||
|
||||
void validate_shader_model();
|
||||
|
||||
std::string get_unique_identifier();
|
||||
uint32_t unique_identifier_count = 0;
|
||||
|
||||
std::unordered_map<StageSetBinding, std::pair<HLSLResourceBinding, bool>, InternalHasher> resource_bindings;
|
||||
void remap_hlsl_resource_binding(HLSLBindingFlagBits type, uint32_t &desc_set, uint32_t &binding);
|
||||
|
||||
std::unordered_set<SetBindingPair, InternalHasher> force_uav_buffer_bindings;
|
||||
|
||||
// Returns true for BuiltInSampleMask because gl_SampleMask[] is an array in SPIR-V, but SV_Coverage is a scalar in HLSL.
|
||||
bool builtin_translates_to_nonarray(spv::BuiltIn builtin) const override;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2018-2021 Arm Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_PARSER_HPP
|
||||
#define SPIRV_CROSS_PARSER_HPP
|
||||
|
||||
#include "spirv_cross_parsed_ir.hpp"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
Parser(const uint32_t *spirv_data, size_t word_count);
|
||||
Parser(std::vector<uint32_t> spirv);
|
||||
|
||||
void parse();
|
||||
|
||||
ParsedIR &get_parsed_ir()
|
||||
{
|
||||
return ir;
|
||||
}
|
||||
|
||||
private:
|
||||
ParsedIR ir;
|
||||
SPIRFunction *current_function = nullptr;
|
||||
SPIRBlock *current_block = nullptr;
|
||||
|
||||
void parse(const Instruction &instr);
|
||||
const uint32_t *stream(const Instruction &instr) const;
|
||||
|
||||
template <typename T, typename... P>
|
||||
T &set(uint32_t id, P &&... args)
|
||||
{
|
||||
ir.add_typed_id(static_cast<Types>(T::type), id);
|
||||
auto &var = variant_set<T>(ir.ids[id], std::forward<P>(args)...);
|
||||
var.self = id;
|
||||
return var;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &get(uint32_t id)
|
||||
{
|
||||
return variant_get<T>(ir.ids[id]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T *maybe_get(uint32_t id)
|
||||
{
|
||||
if (ir.ids[id].get_type() == static_cast<Types>(T::type))
|
||||
return &get<T>(id);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T &get(uint32_t id) const
|
||||
{
|
||||
return variant_get<T>(ir.ids[id]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T *maybe_get(uint32_t id) const
|
||||
{
|
||||
if (ir.ids[id].get_type() == T::type)
|
||||
return &get<T>(id);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// This must be an ordered data structure so we always pick the same type aliases.
|
||||
SmallVector<uint32_t> global_struct_cache;
|
||||
SmallVector<std::pair<uint32_t, uint32_t>> forward_pointer_fixups;
|
||||
|
||||
bool types_are_logically_equivalent(const SPIRType &a, const SPIRType &b) const;
|
||||
bool variable_storage_is_aliased(const SPIRVariable &v) const;
|
||||
};
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2018-2021 Bradley Austin Davis
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* At your option, you may choose to accept this material under either:
|
||||
* 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
|
||||
* 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT.
|
||||
*/
|
||||
|
||||
#ifndef SPIRV_CROSS_REFLECT_HPP
|
||||
#define SPIRV_CROSS_REFLECT_HPP
|
||||
|
||||
#include "spirv_glsl.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace simple_json
|
||||
{
|
||||
class Stream;
|
||||
}
|
||||
|
||||
namespace SPIRV_CROSS_NAMESPACE
|
||||
{
|
||||
class CompilerReflection : public CompilerGLSL
|
||||
{
|
||||
using Parent = CompilerGLSL;
|
||||
|
||||
public:
|
||||
explicit CompilerReflection(std::vector<uint32_t> spirv_)
|
||||
: Parent(std::move(spirv_))
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
CompilerReflection(const uint32_t *ir_, size_t word_count)
|
||||
: Parent(ir_, word_count)
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
explicit CompilerReflection(const ParsedIR &ir_)
|
||||
: CompilerGLSL(ir_)
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
explicit CompilerReflection(ParsedIR &&ir_)
|
||||
: CompilerGLSL(std::move(ir_))
|
||||
{
|
||||
options.vulkan_semantics = true;
|
||||
}
|
||||
|
||||
void set_format(const std::string &format);
|
||||
std::string compile() override;
|
||||
|
||||
private:
|
||||
static std::string execution_model_to_str(spv::ExecutionModel model);
|
||||
|
||||
void emit_entry_points();
|
||||
void emit_types();
|
||||
void emit_resources();
|
||||
void emit_specialization_constants();
|
||||
|
||||
void emit_type(uint32_t type_id, bool &emitted_open_tag);
|
||||
void emit_type_member(const SPIRType &type, uint32_t index);
|
||||
void emit_type_member_qualifiers(const SPIRType &type, uint32_t index);
|
||||
void emit_type_array(const SPIRType &type);
|
||||
void emit_resources(const char *tag, const SmallVector<Resource> &resources);
|
||||
bool type_is_reference(const SPIRType &type) const;
|
||||
|
||||
std::string to_member_name(const SPIRType &type, uint32_t index) const;
|
||||
|
||||
std::shared_ptr<simple_json::Stream> json_stream;
|
||||
};
|
||||
|
||||
} // namespace SPIRV_CROSS_NAMESPACE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
** Copyright (c) 2019-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_VIDEO_CODEC_H264STD_H_
|
||||
#define VULKAN_VIDEO_CODEC_H264STD_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vk_video/vulkan_video_codecs_common.h"
|
||||
|
||||
// Vulkan 0.9 provisional Vulkan video H.264 encode and decode std specification version number
|
||||
#define VK_STD_VULKAN_VIDEO_CODEC_H264_API_VERSION_0_9 VK_MAKE_VIDEO_STD_VERSION(0, 9, 0) // Patch version should always be set to 0
|
||||
|
||||
// Format must be in the form XX.XX where the first two digits are the major and the second two, the minor.
|
||||
#define VK_STD_VULKAN_VIDEO_CODEC_H264_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_API_VERSION_0_9
|
||||
#define VK_STD_VULKAN_VIDEO_CODEC_H264_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264"
|
||||
|
||||
// *************************************************
|
||||
// Video H.264 common definitions:
|
||||
// *************************************************
|
||||
|
||||
typedef enum StdVideoH264ChromaFormatIdc {
|
||||
std_video_h264_chroma_format_idc_monochrome = 0,
|
||||
std_video_h264_chroma_format_idc_420 = 1,
|
||||
std_video_h264_chroma_format_idc_422 = 2,
|
||||
std_video_h264_chroma_format_idc_444 = 3,
|
||||
} StdVideoH264ChromaFormatIdc;
|
||||
|
||||
typedef enum StdVideoH264ProfileIdc {
|
||||
std_video_h264_profile_idc_baseline = 66, /* Only constrained baseline is supported */
|
||||
std_video_h264_profile_idc_main = 77,
|
||||
std_video_h264_profile_idc_high = 100,
|
||||
std_video_h264_profile_idc_high_444_predictive = 244,
|
||||
std_video_h264_profile_idc_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264ProfileIdc;
|
||||
|
||||
typedef enum StdVideoH264Level {
|
||||
std_video_h264_level_1_0 = 0,
|
||||
std_video_h264_level_1_1 = 1,
|
||||
std_video_h264_level_1_2 = 2,
|
||||
std_video_h264_level_1_3 = 3,
|
||||
std_video_h264_level_2_0 = 4,
|
||||
std_video_h264_level_2_1 = 5,
|
||||
std_video_h264_level_2_2 = 6,
|
||||
std_video_h264_level_3_0 = 7,
|
||||
std_video_h264_level_3_1 = 8,
|
||||
std_video_h264_level_3_2 = 9,
|
||||
std_video_h264_level_4_0 = 10,
|
||||
std_video_h264_level_4_1 = 11,
|
||||
std_video_h264_level_4_2 = 12,
|
||||
std_video_h264_level_5_0 = 13,
|
||||
std_video_h264_level_5_1 = 14,
|
||||
std_video_h264_level_5_2 = 15,
|
||||
std_video_h264_level_6_0 = 16,
|
||||
std_video_h264_level_6_1 = 17,
|
||||
std_video_h264_level_6_2 = 18,
|
||||
std_video_h264_level_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264Level;
|
||||
|
||||
typedef enum StdVideoH264PocType {
|
||||
std_video_h264_poc_type_0 = 0,
|
||||
std_video_h264_poc_type_1 = 1,
|
||||
std_video_h264_poc_type_2 = 2,
|
||||
std_video_h264_poc_type_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264PocType;
|
||||
|
||||
typedef enum StdVideoH264AspectRatioIdc {
|
||||
std_video_h264_aspect_ratio_idc_unspecified = 0,
|
||||
std_video_h264_aspect_ratio_idc_square = 1,
|
||||
std_video_h264_aspect_ratio_idc_12_11 = 2,
|
||||
std_video_h264_aspect_ratio_idc_10_11 = 3,
|
||||
std_video_h264_aspect_ratio_idc_16_11 = 4,
|
||||
std_video_h264_aspect_ratio_idc_40_33 = 5,
|
||||
std_video_h264_aspect_ratio_idc_24_11 = 6,
|
||||
std_video_h264_aspect_ratio_idc_20_11 = 7,
|
||||
std_video_h264_aspect_ratio_idc_32_11 = 8,
|
||||
std_video_h264_aspect_ratio_idc_80_33 = 9,
|
||||
std_video_h264_aspect_ratio_idc_18_11 = 10,
|
||||
std_video_h264_aspect_ratio_idc_15_11 = 11,
|
||||
std_video_h264_aspect_ratio_idc_64_33 = 12,
|
||||
std_video_h264_aspect_ratio_idc_160_99 = 13,
|
||||
std_video_h264_aspect_ratio_idc_4_3 = 14,
|
||||
std_video_h264_aspect_ratio_idc_3_2 = 15,
|
||||
std_video_h264_aspect_ratio_idc_2_1 = 16,
|
||||
std_video_h264_aspect_ratio_idc_extended_sar = 255,
|
||||
std_video_h264_aspect_ratio_idc_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264AspectRatioIdc;
|
||||
|
||||
typedef enum StdVideoH264WeightedBiPredIdc {
|
||||
std_video_h264_default_weighted_b_slices_prediction_idc = 0,
|
||||
std_video_h264_explicit_weighted_b_slices_prediction_idc = 1,
|
||||
std_video_h264_implicit_weighted_b_slices_prediction_idc = 2,
|
||||
std_video_h264_invalid_weighted_b_slices_prediction_idc = 0x7FFFFFFF
|
||||
} StdVideoH264WeightedBiPredIdc;
|
||||
|
||||
typedef enum StdVideoH264ModificationOfPicNumsIdc {
|
||||
std_video_h264_modification_of_pic_nums_idc_short_term_subtract = 0,
|
||||
std_video_h264_modification_of_pic_nums_idc_short_term_add = 1,
|
||||
std_video_h264_modification_of_pic_nums_idc_long_term = 2,
|
||||
std_video_h264_modification_of_pic_nums_idc_end = 3,
|
||||
std_video_h264_modification_of_pic_nums_idc_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264ModificationOfPicNumsIdc;
|
||||
|
||||
typedef enum StdVideoH264MemMgmtControlOp {
|
||||
std_video_h264_mem_mgmt_control_op_end = 0,
|
||||
std_video_h264_mem_mgmt_control_op_unmark_short_term = 1,
|
||||
std_video_h264_mem_mgmt_control_op_unmark_long_term = 2,
|
||||
std_video_h264_mem_mgmt_control_op_mark_long_term = 3,
|
||||
std_video_h264_mem_mgmt_control_op_set_max_long_term_index = 4,
|
||||
std_video_h264_mem_mgmt_control_op_unmark_all = 5,
|
||||
std_video_h264_mem_mgmt_control_op_mark_current_as_long_term = 6,
|
||||
std_video_h264_mem_mgmt_control_op_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264MemMgmtControlOp;
|
||||
|
||||
typedef enum StdVideoH264CabacInitIdc {
|
||||
std_video_h264_cabac_init_idc_0 = 0,
|
||||
std_video_h264_cabac_init_idc_1 = 1,
|
||||
std_video_h264_cabac_init_idc_2 = 2,
|
||||
std_video_h264_cabac_init_idc_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264CabacInitIdc;
|
||||
|
||||
typedef enum StdVideoH264DisableDeblockingFilterIdc {
|
||||
std_video_h264_disable_deblocking_filter_idc_disabled = 0,
|
||||
std_video_h264_disable_deblocking_filter_idc_enabled = 1,
|
||||
std_video_h264_disable_deblocking_filter_idc_partial = 2,
|
||||
std_video_h264_disable_deblocking_filter_idc_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264DisableDeblockingFilterIdc;
|
||||
|
||||
typedef enum StdVideoH264PictureType {
|
||||
std_video_h264_picture_type_i = 0,
|
||||
std_video_h264_picture_type_p = 1,
|
||||
std_video_h264_picture_type_b = 2,
|
||||
std_video_h264_picture_type_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264PictureType;
|
||||
|
||||
typedef enum StdVideoH264SliceType {
|
||||
std_video_h264_slice_type_i = 0,
|
||||
std_video_h264_slice_type_p = 1,
|
||||
std_video_h264_slice_type_b = 2,
|
||||
std_video_h264_slice_type_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264SliceType;
|
||||
|
||||
typedef enum StdVideoH264NonVclNaluType {
|
||||
std_video_h264_non_vcl_nalu_type_sps = 0,
|
||||
std_video_h264_non_vcl_nalu_type_pps = 1,
|
||||
std_video_h264_non_vcl_nalu_type_aud = 2,
|
||||
std_video_h264_non_vcl_nalu_type_prefix = 3,
|
||||
std_video_h264_non_vcl_nalu_type_end_of_sequence = 4,
|
||||
std_video_h264_non_vcl_nalu_type_end_of_stream = 5,
|
||||
std_video_h264_non_vcl_nalu_type_precoded = 6,
|
||||
std_video_h264_non_vcl_nalu_type_invalid = 0x7FFFFFFF
|
||||
} StdVideoH264NonVclNaluType;
|
||||
|
||||
typedef struct StdVideoH264SpsVuiFlags {
|
||||
uint32_t aspect_ratio_info_present_flag:1;
|
||||
uint32_t overscan_info_present_flag:1;
|
||||
uint32_t overscan_appropriate_flag:1;
|
||||
uint32_t video_signal_type_present_flag:1;
|
||||
uint32_t video_full_range_flag:1;
|
||||
uint32_t color_description_present_flag:1;
|
||||
uint32_t chroma_loc_info_present_flag:1;
|
||||
uint32_t timing_info_present_flag:1;
|
||||
uint32_t fixed_frame_rate_flag:1;
|
||||
uint32_t bitstream_restriction_flag:1;
|
||||
uint32_t nal_hrd_parameters_present_flag:1;
|
||||
uint32_t vcl_hrd_parameters_present_flag:1;
|
||||
} StdVideoH264SpsVuiFlags;
|
||||
|
||||
typedef struct StdVideoH264HrdParameters {
|
||||
uint8_t cpb_cnt_minus1;
|
||||
uint8_t bit_rate_scale;
|
||||
uint8_t cpb_size_scale;
|
||||
uint32_t bit_rate_value_minus1[32];
|
||||
uint32_t cpb_size_value_minus1[32];
|
||||
uint8_t cbr_flag[32];
|
||||
uint32_t initial_cpb_removal_delay_length_minus1;
|
||||
uint32_t cpb_removal_delay_length_minus1;
|
||||
uint32_t dpb_output_delay_length_minus1;
|
||||
uint32_t time_offset_length;
|
||||
} StdVideoH264HrdParameters;
|
||||
|
||||
typedef struct StdVideoH264SequenceParameterSetVui {
|
||||
StdVideoH264AspectRatioIdc aspect_ratio_idc;
|
||||
uint16_t sar_width;
|
||||
uint16_t sar_height;
|
||||
uint8_t video_format;
|
||||
uint8_t color_primaries;
|
||||
uint8_t transfer_characteristics;
|
||||
uint8_t matrix_coefficients;
|
||||
uint32_t num_units_in_tick;
|
||||
uint32_t time_scale;
|
||||
StdVideoH264HrdParameters hrd_parameters;
|
||||
uint8_t num_reorder_frames;
|
||||
uint8_t max_dec_frame_buffering;
|
||||
StdVideoH264SpsVuiFlags flags;
|
||||
} StdVideoH264SequenceParameterSetVui;
|
||||
|
||||
typedef struct StdVideoH264SpsFlags {
|
||||
uint32_t constraint_set0_flag:1;
|
||||
uint32_t constraint_set1_flag:1;
|
||||
uint32_t constraint_set2_flag:1;
|
||||
uint32_t constraint_set3_flag:1;
|
||||
uint32_t constraint_set4_flag:1;
|
||||
uint32_t constraint_set5_flag:1;
|
||||
uint32_t direct_8x8_inference_flag:1;
|
||||
uint32_t mb_adaptive_frame_field_flag:1;
|
||||
uint32_t frame_mbs_only_flag:1;
|
||||
uint32_t delta_pic_order_always_zero_flag:1;
|
||||
uint32_t residual_colour_transform_flag:1;
|
||||
uint32_t gaps_in_frame_num_value_allowed_flag:1;
|
||||
uint32_t first_picture_after_seek_flag:1; // where is this being documented?
|
||||
uint32_t qpprime_y_zero_transform_bypass_flag:1;
|
||||
uint32_t frame_cropping_flag:1;
|
||||
uint32_t scaling_matrix_present_flag:1;
|
||||
uint32_t vui_parameters_present_flag:1;
|
||||
} StdVideoH264SpsFlags;
|
||||
|
||||
typedef struct StdVideoH264ScalingLists
|
||||
{
|
||||
// scaling_list_present_mask has one bit for each
|
||||
// seq_scaling_list_present_flag[i] for SPS OR
|
||||
// pic_scaling_list_present_flag[i] for PPS,
|
||||
// bit 0 - 5 are for each entry of ScalingList4x4
|
||||
// bit 6 - 7 are for each entry plus 6 for ScalingList8x8
|
||||
uint8_t scaling_list_present_mask;
|
||||
// use_default_scaling_matrix_mask has one bit for each
|
||||
// UseDefaultScalingMatrix4x4Flag[ i ] and
|
||||
// UseDefaultScalingMatrix8x8Flag[ i − 6 ] for SPS OR PPS
|
||||
// bit 0 - 5 are for each entry of ScalingList4x4
|
||||
// bit 6 - 7 are for each entry plus 6 for ScalingList8x8
|
||||
uint8_t use_default_scaling_matrix_mask;
|
||||
uint8_t ScalingList4x4[6][16];
|
||||
uint8_t ScalingList8x8[2][64];
|
||||
} StdVideoH264ScalingLists;
|
||||
|
||||
typedef struct StdVideoH264SequenceParameterSet
|
||||
{
|
||||
StdVideoH264ProfileIdc profile_idc;
|
||||
StdVideoH264Level level_idc;
|
||||
uint8_t seq_parameter_set_id;
|
||||
StdVideoH264ChromaFormatIdc chroma_format_idc;
|
||||
uint8_t bit_depth_luma_minus8;
|
||||
uint8_t bit_depth_chroma_minus8;
|
||||
uint8_t log2_max_frame_num_minus4;
|
||||
StdVideoH264PocType pic_order_cnt_type;
|
||||
uint8_t log2_max_pic_order_cnt_lsb_minus4;
|
||||
int32_t offset_for_non_ref_pic;
|
||||
int32_t offset_for_top_to_bottom_field;
|
||||
uint8_t num_ref_frames_in_pic_order_cnt_cycle;
|
||||
uint8_t max_num_ref_frames;
|
||||
uint32_t pic_width_in_mbs_minus1;
|
||||
uint32_t pic_height_in_map_units_minus1;
|
||||
uint32_t frame_crop_left_offset;
|
||||
uint32_t frame_crop_right_offset;
|
||||
uint32_t frame_crop_top_offset;
|
||||
uint32_t frame_crop_bottom_offset;
|
||||
StdVideoH264SpsFlags flags;
|
||||
int32_t offset_for_ref_frame[255]; // The number of valid values are defined by the num_ref_frames_in_pic_order_cnt_cycle
|
||||
StdVideoH264ScalingLists* pScalingLists; // Must be a valid pointer if scaling_matrix_present_flag is set
|
||||
StdVideoH264SequenceParameterSetVui* pSequenceParameterSetVui; // Must be a valid pointer if StdVideoH264SpsFlags:vui_parameters_present_flag is set
|
||||
} StdVideoH264SequenceParameterSet;
|
||||
|
||||
typedef struct StdVideoH264PpsFlags {
|
||||
uint32_t transform_8x8_mode_flag:1;
|
||||
uint32_t redundant_pic_cnt_present_flag:1;
|
||||
uint32_t constrained_intra_pred_flag:1;
|
||||
uint32_t deblocking_filter_control_present_flag:1;
|
||||
uint32_t weighted_bipred_idc_flag:1;
|
||||
uint32_t weighted_pred_flag:1;
|
||||
uint32_t pic_order_present_flag:1;
|
||||
uint32_t entropy_coding_mode_flag:1;
|
||||
uint32_t scaling_matrix_present_flag:1;
|
||||
} StdVideoH264PpsFlags;
|
||||
|
||||
typedef struct StdVideoH264PictureParameterSet
|
||||
{
|
||||
uint8_t seq_parameter_set_id;
|
||||
uint8_t pic_parameter_set_id;
|
||||
uint8_t num_ref_idx_l0_default_active_minus1;
|
||||
uint8_t num_ref_idx_l1_default_active_minus1;
|
||||
StdVideoH264WeightedBiPredIdc weighted_bipred_idc;
|
||||
int8_t pic_init_qp_minus26;
|
||||
int8_t pic_init_qs_minus26;
|
||||
int8_t chroma_qp_index_offset;
|
||||
int8_t second_chroma_qp_index_offset;
|
||||
StdVideoH264PpsFlags flags;
|
||||
StdVideoH264ScalingLists* pScalingLists; // Must be a valid pointer if StdVideoH264PpsFlags::scaling_matrix_present_flag is set.
|
||||
} StdVideoH264PictureParameterSet;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VULKAN_VIDEO_CODEC_H264STD_H_
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
** Copyright (c) 2019-2020 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_VIDEO_CODEC_H264STD_DECODE_H_
|
||||
#define VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vk_video/vulkan_video_codec_h264std.h"
|
||||
|
||||
// *************************************************
|
||||
// Video H.264 Decode related parameters:
|
||||
// *************************************************
|
||||
|
||||
typedef struct StdVideoDecodeH264PictureInfoFlags {
|
||||
uint32_t field_pic_flag:1; // Is field picture
|
||||
uint32_t is_intra:1; // Is intra picture
|
||||
uint32_t bottom_field_flag:1; // bottom (true) or top (false) field if field_pic_flag is set.
|
||||
uint32_t is_reference:1; // This only applies to picture info, and not to the DPB lists.
|
||||
uint32_t complementary_field_pair:1; // complementary field pair, complementary non-reference field pair, complementary reference field pair
|
||||
} StdVideoDecodeH264PictureInfoFlags;
|
||||
|
||||
typedef struct StdVideoDecodeH264PictureInfo {
|
||||
uint8_t seq_parameter_set_id; // Selecting SPS from the Picture Parameters
|
||||
uint8_t pic_parameter_set_id; // Selecting PPS from the Picture Parameters and the SPS
|
||||
uint16_t reserved; // for structure members 32-bit packing/alignment
|
||||
uint16_t frame_num; // 7.4.3 Slice header semantics
|
||||
uint16_t idr_pic_id; // 7.4.3 Slice header semantics
|
||||
// PicOrderCnt is based on TopFieldOrderCnt and BottomFieldOrderCnt. See 8.2.1 Decoding process for picture order count type 0 - 2
|
||||
int32_t PicOrderCnt[2]; // TopFieldOrderCnt and BottomFieldOrderCnt fields.
|
||||
StdVideoDecodeH264PictureInfoFlags flags;
|
||||
} StdVideoDecodeH264PictureInfo;
|
||||
|
||||
typedef struct StdVideoDecodeH264ReferenceInfoFlags {
|
||||
uint32_t top_field_flag:1; // Reference is used for top field reference.
|
||||
uint32_t bottom_field_flag:1; // Reference is used for bottom field reference.
|
||||
uint32_t is_long_term:1; // this is a long term reference
|
||||
uint32_t is_non_existing:1; // Must be handled in accordance with 8.2.5.2: Decoding process for gaps in frame_num
|
||||
} StdVideoDecodeH264ReferenceInfoFlags;
|
||||
|
||||
typedef struct StdVideoDecodeH264ReferenceInfo {
|
||||
// FrameNum = is_long_term ? long_term_frame_idx : frame_num
|
||||
uint16_t FrameNum; // 7.4.3.3 Decoded reference picture marking semantics
|
||||
uint16_t reserved; // for structure members 32-bit packing/alignment
|
||||
int32_t PicOrderCnt[2]; // TopFieldOrderCnt and BottomFieldOrderCnt fields.
|
||||
StdVideoDecodeH264ReferenceInfoFlags flags;
|
||||
} StdVideoDecodeH264ReferenceInfo;
|
||||
|
||||
typedef struct StdVideoDecodeH264MvcElementFlags {
|
||||
uint32_t non_idr:1;
|
||||
uint32_t anchor_pic:1;
|
||||
uint32_t inter_view:1;
|
||||
} StdVideoDecodeH264MvcElementFlags;
|
||||
|
||||
typedef struct StdVideoDecodeH264MvcElement {
|
||||
StdVideoDecodeH264MvcElementFlags flags;
|
||||
uint16_t viewOrderIndex;
|
||||
uint16_t viewId;
|
||||
uint16_t temporalId; // move out?
|
||||
uint16_t priorityId; // move out?
|
||||
uint16_t numOfAnchorRefsInL0;
|
||||
uint16_t viewIdOfAnchorRefsInL0[15];
|
||||
uint16_t numOfAnchorRefsInL1;
|
||||
uint16_t viewIdOfAnchorRefsInL1[15];
|
||||
uint16_t numOfNonAnchorRefsInL0;
|
||||
uint16_t viewIdOfNonAnchorRefsInL0[15];
|
||||
uint16_t numOfNonAnchorRefsInL1;
|
||||
uint16_t viewIdOfNonAnchorRefsInL1[15];
|
||||
} StdVideoDecodeH264MvcElement;
|
||||
|
||||
typedef struct StdVideoDecodeH264Mvc {
|
||||
uint32_t viewId0;
|
||||
uint32_t mvcElementCount;
|
||||
StdVideoDecodeH264MvcElement* pMvcElements;
|
||||
} StdVideoDecodeH264Mvc;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VULKAN_VIDEO_CODEC_H264STD_DECODE_H_
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
** Copyright (c) 2019-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_
|
||||
#define VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vk_video/vulkan_video_codec_h264std.h"
|
||||
|
||||
// *************************************************
|
||||
// Video H.264 Encode related parameters:
|
||||
// *************************************************
|
||||
|
||||
typedef struct StdVideoEncodeH264SliceHeaderFlags {
|
||||
uint32_t idr_flag:1;
|
||||
uint32_t is_reference_flag:1;
|
||||
uint32_t num_ref_idx_active_override_flag:1;
|
||||
uint32_t no_output_of_prior_pics_flag:1;
|
||||
uint32_t long_term_reference_flag:1;
|
||||
uint32_t adaptive_ref_pic_marking_mode_flag:1;
|
||||
uint32_t no_prior_references_available_flag:1;
|
||||
} StdVideoEncodeH264SliceHeaderFlags;
|
||||
|
||||
typedef struct StdVideoEncodeH264PictureInfoFlags {
|
||||
uint32_t idr_flag:1;
|
||||
uint32_t is_reference_flag:1;
|
||||
uint32_t long_term_reference_flag:1;
|
||||
} StdVideoEncodeH264PictureInfoFlags;
|
||||
|
||||
typedef struct StdVideoEncodeH264RefMgmtFlags {
|
||||
uint32_t ref_pic_list_modification_l0_flag:1;
|
||||
uint32_t ref_pic_list_modification_l1_flag:1;
|
||||
} StdVideoEncodeH264RefMgmtFlags;
|
||||
|
||||
typedef struct StdVideoEncodeH264RefListModEntry {
|
||||
StdVideoH264ModificationOfPicNumsIdc modification_of_pic_nums_idc;
|
||||
uint16_t abs_diff_pic_num_minus1;
|
||||
uint16_t long_term_pic_num;
|
||||
} StdVideoEncodeH264RefListModEntry;
|
||||
|
||||
typedef struct StdVideoEncodeH264RefPicMarkingEntry {
|
||||
StdVideoH264MemMgmtControlOp operation;
|
||||
uint16_t difference_of_pic_nums_minus1;
|
||||
uint16_t long_term_pic_num;
|
||||
uint16_t long_term_frame_idx;
|
||||
uint16_t max_long_term_frame_idx_plus1;
|
||||
} StdVideoEncodeH264RefPicMarkingEntry;
|
||||
|
||||
typedef struct StdVideoEncodeH264RefMemMgmtCtrlOperations {
|
||||
StdVideoEncodeH264RefMgmtFlags flags;
|
||||
uint8_t refList0ModOpCount;
|
||||
StdVideoEncodeH264RefListModEntry* pRefList0ModOperations;
|
||||
uint8_t refList1ModOpCount;
|
||||
StdVideoEncodeH264RefListModEntry* pRefList1ModOperations;
|
||||
uint8_t refPicMarkingOpCount;
|
||||
StdVideoEncodeH264RefPicMarkingEntry* pRefPicMarkingOperations;
|
||||
} StdVideoEncodeH264RefMemMgmtCtrlOperations;
|
||||
|
||||
typedef struct StdVideoEncodeH264PictureInfo {
|
||||
StdVideoEncodeH264PictureInfoFlags flags;
|
||||
StdVideoH264PictureType pictureType;
|
||||
uint32_t frameNum;
|
||||
uint32_t pictureOrderCount;
|
||||
uint16_t long_term_pic_num;
|
||||
uint16_t long_term_frame_idx;
|
||||
} StdVideoEncodeH264PictureInfo;
|
||||
|
||||
typedef struct StdVideoEncodeH264SliceHeader {
|
||||
StdVideoEncodeH264SliceHeaderFlags flags;
|
||||
StdVideoH264SliceType slice_type;
|
||||
uint8_t seq_parameter_set_id;
|
||||
uint8_t pic_parameter_set_id;
|
||||
uint16_t idr_pic_id;
|
||||
uint8_t num_ref_idx_l0_active_minus1;
|
||||
uint8_t num_ref_idx_l1_active_minus1;
|
||||
StdVideoH264CabacInitIdc cabac_init_idc;
|
||||
StdVideoH264DisableDeblockingFilterIdc disable_deblocking_filter_idc;
|
||||
int8_t slice_alpha_c0_offset_div2;
|
||||
int8_t slice_beta_offset_div2;
|
||||
StdVideoEncodeH264RefMemMgmtCtrlOperations* pMemMgmtCtrlOperations;
|
||||
} StdVideoEncodeH264SliceHeader;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_
|
||||
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
** Copyright (c) 2019-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_VIDEO_CODEC_H265STD_H_
|
||||
#define VULKAN_VIDEO_CODEC_H265STD_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vk_video/vulkan_video_codecs_common.h"
|
||||
|
||||
// Vulkan 0.5 version number WIP
|
||||
#define VK_STD_VULKAN_VIDEO_CODEC_H265_API_VERSION_0_5 VK_MAKE_VIDEO_STD_VERSION(0, 5, 0) // Patch version should always be set to 0
|
||||
|
||||
// Format must be in the form XX.XX where the first two digits are the major and the second two, the minor.
|
||||
#define VK_STD_VULKAN_VIDEO_CODEC_H265_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_API_VERSION_0_5
|
||||
#define VK_STD_VULKAN_VIDEO_CODEC_H265_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265"
|
||||
|
||||
typedef enum StdVideoH265ChromaFormatIdc {
|
||||
std_video_h265_chroma_format_idc_monochrome = 0,
|
||||
std_video_h265_chroma_format_idc_420 = 1,
|
||||
std_video_h265_chroma_format_idc_422 = 2,
|
||||
std_video_h265_chroma_format_idc_444 = 3,
|
||||
} StdVideoH265ChromaFormatIdc;
|
||||
|
||||
typedef enum StdVideoH265ProfileIdc {
|
||||
std_video_h265_profile_idc_main = 1,
|
||||
std_video_h265_profile_idc_main_10 = 2,
|
||||
std_video_h265_profile_idc_main_still_picture = 3,
|
||||
std_video_h265_profile_idc_format_range_extensions = 4,
|
||||
std_video_h265_profile_idc_scc_extensions = 9,
|
||||
std_video_h265_profile_idc_invalid = 0x7FFFFFFF
|
||||
} StdVideoH265ProfileIdc;
|
||||
|
||||
typedef enum StdVideoH265Level {
|
||||
std_video_h265_level_1_0 = 0,
|
||||
std_video_h265_level_2_0 = 1,
|
||||
std_video_h265_level_2_1 = 2,
|
||||
std_video_h265_level_3_0 = 3,
|
||||
std_video_h265_level_3_1 = 4,
|
||||
std_video_h265_level_4_0 = 5,
|
||||
std_video_h265_level_4_1 = 6,
|
||||
std_video_h265_level_5_0 = 7,
|
||||
std_video_h265_level_5_1 = 8,
|
||||
std_video_h265_level_5_2 = 9,
|
||||
std_video_h265_level_6_0 = 10,
|
||||
std_video_h265_level_6_1 = 11,
|
||||
std_video_h265_level_6_2 = 12,
|
||||
std_video_h265_level_invalid = 0x7FFFFFFF
|
||||
} StdVideoH265Level;
|
||||
|
||||
|
||||
typedef struct StdVideoH265DecPicBufMgr
|
||||
{
|
||||
uint32_t max_latency_increase_plus1[7];
|
||||
uint8_t max_dec_pic_buffering_minus1[7];
|
||||
uint8_t max_num_reorder_pics[7];
|
||||
} StdVideoH265DecPicBufMgr;
|
||||
|
||||
typedef struct StdVideoH265SubLayerHrdParameters {
|
||||
uint32_t bit_rate_value_minus1[32];
|
||||
uint32_t cpb_size_value_minus1[32];
|
||||
uint32_t cpb_size_du_value_minus1[32];
|
||||
uint32_t bit_rate_du_value_minus1[32];
|
||||
uint32_t cbr_flag; // each bit represents a range of CpbCounts (bit 0 - cpb_cnt_minus1) per sub-layer
|
||||
} StdVideoH265SubLayerHrdParameters;
|
||||
|
||||
typedef struct StdVideoH265HrdFlags {
|
||||
uint32_t nal_hrd_parameters_present_flag : 1;
|
||||
uint32_t vcl_hrd_parameters_present_flag : 1;
|
||||
uint32_t sub_pic_hrd_params_present_flag : 1;
|
||||
uint32_t sub_pic_cpb_params_in_pic_timing_sei_flag : 1;
|
||||
uint8_t fixed_pic_rate_general_flag; // each bit represents a sublayer, bit 0 - vps_max_sub_layers_minus1
|
||||
uint8_t fixed_pic_rate_within_cvs_flag; // each bit represents a sublayer, bit 0 - vps_max_sub_layers_minus1
|
||||
uint8_t low_delay_hrd_flag; // each bit represents a sublayer, bit 0 - vps_max_sub_layers_minus1
|
||||
} StdVideoH265HrdFlags;
|
||||
|
||||
typedef struct StdVideoH265HrdParameters {
|
||||
uint8_t tick_divisor_minus2;
|
||||
uint8_t du_cpb_removal_delay_increment_length_minus1;
|
||||
uint8_t dpb_output_delay_du_length_minus1;
|
||||
uint8_t bit_rate_scale;
|
||||
uint8_t cpb_size_scale;
|
||||
uint8_t cpb_size_du_scale;
|
||||
uint8_t initial_cpb_removal_delay_length_minus1;
|
||||
uint8_t au_cpb_removal_delay_length_minus1;
|
||||
uint8_t dpb_output_delay_length_minus1;
|
||||
uint8_t cpb_cnt_minus1[7];
|
||||
uint16_t elemental_duration_in_tc_minus1[7];
|
||||
StdVideoH265SubLayerHrdParameters* SubLayerHrdParametersNal[7];
|
||||
StdVideoH265SubLayerHrdParameters* SubLayerHrdParametersVcl[7];
|
||||
StdVideoH265HrdFlags flags;
|
||||
} StdVideoH265HrdParameters;
|
||||
|
||||
typedef struct StdVideoH265VpsFlags {
|
||||
uint32_t vps_temporal_id_nesting_flag : 1;
|
||||
uint32_t vps_sub_layer_ordering_info_present_flag : 1;
|
||||
uint32_t vps_timing_info_present_flag : 1;
|
||||
uint32_t vps_poc_proportional_to_timing_flag : 1;
|
||||
} StdVideoH265VpsFlags;
|
||||
|
||||
typedef struct StdVideoH265VideoParameterSet
|
||||
{
|
||||
uint8_t vps_video_parameter_set_id;
|
||||
uint8_t vps_max_sub_layers_minus1;
|
||||
uint32_t vps_num_units_in_tick;
|
||||
uint32_t vps_time_scale;
|
||||
uint32_t vps_num_ticks_poc_diff_one_minus1;
|
||||
StdVideoH265DecPicBufMgr* pDecPicBufMgr;
|
||||
StdVideoH265HrdParameters* hrd_parameters;
|
||||
StdVideoH265VpsFlags flags;
|
||||
} StdVideoH265VideoParameterSet;
|
||||
|
||||
typedef struct StdVideoH265ScalingLists
|
||||
{
|
||||
uint8_t ScalingList4x4[6][16]; // ScalingList[ 0 ][ MatrixID ][ i ] (sizeID = 0)
|
||||
uint8_t ScalingList8x8[6][64]; // ScalingList[ 1 ][ MatrixID ][ i ] (sizeID = 1)
|
||||
uint8_t ScalingList16x16[6][64]; // ScalingList[ 2 ][ MatrixID ][ i ] (sizeID = 2)
|
||||
uint8_t ScalingList32x32[2][64]; // ScalingList[ 3 ][ MatrixID ][ i ] (sizeID = 3)
|
||||
uint8_t ScalingListDCCoef16x16[6]; // scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8, sizeID = 2
|
||||
uint8_t ScalingListDCCoef32x32[2]; // scaling_list_dc_coef_minus8[ sizeID - 2 ][ matrixID ] + 8. sizeID = 3
|
||||
} StdVideoH265ScalingLists;
|
||||
|
||||
typedef struct StdVideoH265SpsVuiFlags {
|
||||
uint32_t aspect_ratio_info_present_flag : 1;
|
||||
uint32_t overscan_info_present_flag : 1;
|
||||
uint32_t overscan_appropriate_flag : 1;
|
||||
uint32_t video_signal_type_present_flag : 1;
|
||||
uint32_t video_full_range_flag : 1;
|
||||
uint32_t colour_description_present_flag : 1;
|
||||
uint32_t chroma_loc_info_present_flag : 1;
|
||||
uint32_t neutral_chroma_indication_flag : 1;
|
||||
uint32_t field_seq_flag : 1;
|
||||
uint32_t frame_field_info_present_flag : 1;
|
||||
uint32_t default_display_window_flag : 1;
|
||||
uint32_t vui_timing_info_present_flag : 1;
|
||||
uint32_t vui_poc_proportional_to_timing_flag : 1;
|
||||
uint32_t vui_hrd_parameters_present_flag : 1;
|
||||
uint32_t bitstream_restriction_flag : 1;
|
||||
uint32_t tiles_fixed_structure_flag : 1;
|
||||
uint32_t motion_vectors_over_pic_boundaries_flag : 1;
|
||||
uint32_t restricted_ref_pic_lists_flag : 1;
|
||||
} StdVideoH265SpsVuiFlags;
|
||||
|
||||
typedef struct StdVideoH265SequenceParameterSetVui {
|
||||
uint8_t aspect_ratio_idc;
|
||||
uint16_t sar_width;
|
||||
uint16_t sar_height;
|
||||
uint8_t video_format;
|
||||
uint8_t colour_primaries;
|
||||
uint8_t transfer_characteristics;
|
||||
uint8_t matrix_coeffs;
|
||||
uint8_t chroma_sample_loc_type_top_field;
|
||||
uint8_t chroma_sample_loc_type_bottom_field;
|
||||
uint16_t def_disp_win_left_offset;
|
||||
uint16_t def_disp_win_right_offset;
|
||||
uint16_t def_disp_win_top_offset;
|
||||
uint16_t def_disp_win_bottom_offset;
|
||||
uint32_t vui_num_units_in_tick;
|
||||
uint32_t vui_time_scale;
|
||||
uint32_t vui_num_ticks_poc_diff_one_minus1;
|
||||
StdVideoH265HrdParameters* hrd_parameters;
|
||||
uint16_t min_spatial_segmentation_idc;
|
||||
uint8_t max_bytes_per_pic_denom;
|
||||
uint8_t max_bits_per_min_cu_denom;
|
||||
uint8_t log2_max_mv_length_horizontal;
|
||||
uint8_t log2_max_mv_length_vertical;
|
||||
StdVideoH265SpsVuiFlags flags;
|
||||
} StdVideoH265SequenceParameterSetVui;
|
||||
|
||||
typedef struct StdVideoH265PredictorPaletteEntries
|
||||
{
|
||||
uint16_t PredictorPaletteEntries[3][128];
|
||||
} StdVideoH265PredictorPaletteEntries;
|
||||
|
||||
|
||||
typedef struct StdVideoH265SpsFlags {
|
||||
uint32_t sps_temporal_id_nesting_flag : 1;
|
||||
uint32_t separate_colour_plane_flag : 1;
|
||||
uint32_t scaling_list_enabled_flag : 1;
|
||||
uint32_t sps_scaling_list_data_present_flag : 1;
|
||||
uint32_t amp_enabled_flag : 1;
|
||||
uint32_t sample_adaptive_offset_enabled_flag : 1;
|
||||
uint32_t pcm_enabled_flag : 1;
|
||||
uint32_t pcm_loop_filter_disabled_flag : 1;
|
||||
uint32_t long_term_ref_pics_present_flag : 1;
|
||||
uint32_t sps_temporal_mvp_enabled_flag : 1;
|
||||
uint32_t strong_intra_smoothing_enabled_flag : 1;
|
||||
uint32_t vui_parameters_present_flag : 1;
|
||||
uint32_t sps_extension_present_flag : 1;
|
||||
uint32_t sps_range_extension_flag : 1;
|
||||
|
||||
// extension SPS flags, valid when std_video_h265_profile_idc_format_range_extensions is set
|
||||
uint32_t transform_skip_rotation_enabled_flag : 1;
|
||||
uint32_t transform_skip_context_enabled_flag : 1;
|
||||
uint32_t implicit_rdpcm_enabled_flag : 1;
|
||||
uint32_t explicit_rdpcm_enabled_flag : 1;
|
||||
uint32_t extended_precision_processing_flag : 1;
|
||||
uint32_t intra_smoothing_disabled_flag : 1;
|
||||
uint32_t high_precision_offsets_enabled_flag : 1;
|
||||
uint32_t persistent_rice_adaptation_enabled_flag : 1;
|
||||
uint32_t cabac_bypass_alignment_enabled_flag : 1;
|
||||
|
||||
// extension SPS flags, valid when std_video_h265_profile_idc_scc_extensions is set
|
||||
uint32_t sps_curr_pic_ref_enabled_flag : 1;
|
||||
uint32_t palette_mode_enabled_flag : 1;
|
||||
uint32_t sps_palette_predictor_initializer_present_flag : 1;
|
||||
uint32_t intra_boundary_filtering_disabled_flag : 1;
|
||||
} StdVideoH265SpsFlags;
|
||||
|
||||
typedef struct StdVideoH265SequenceParameterSet
|
||||
{
|
||||
StdVideoH265ProfileIdc profile_idc;
|
||||
StdVideoH265Level level_idc;
|
||||
uint32_t pic_width_in_luma_samples;
|
||||
uint32_t pic_height_in_luma_samples;
|
||||
uint8_t sps_video_parameter_set_id;
|
||||
uint8_t sps_max_sub_layers_minus1;
|
||||
uint8_t sps_seq_parameter_set_id;
|
||||
uint8_t chroma_format_idc;
|
||||
uint8_t bit_depth_luma_minus8;
|
||||
uint8_t bit_depth_chroma_minus8;
|
||||
uint8_t log2_max_pic_order_cnt_lsb_minus4;
|
||||
uint8_t sps_max_dec_pic_buffering_minus1;
|
||||
uint8_t log2_min_luma_coding_block_size_minus3;
|
||||
uint8_t log2_diff_max_min_luma_coding_block_size;
|
||||
uint8_t log2_min_luma_transform_block_size_minus2;
|
||||
uint8_t log2_diff_max_min_luma_transform_block_size;
|
||||
uint8_t max_transform_hierarchy_depth_inter;
|
||||
uint8_t max_transform_hierarchy_depth_intra;
|
||||
uint8_t num_short_term_ref_pic_sets;
|
||||
uint8_t num_long_term_ref_pics_sps;
|
||||
uint8_t pcm_sample_bit_depth_luma_minus1;
|
||||
uint8_t pcm_sample_bit_depth_chroma_minus1;
|
||||
uint8_t log2_min_pcm_luma_coding_block_size_minus3;
|
||||
uint8_t log2_diff_max_min_pcm_luma_coding_block_size;
|
||||
uint32_t conf_win_left_offset;
|
||||
uint32_t conf_win_right_offset;
|
||||
uint32_t conf_win_top_offset;
|
||||
uint32_t conf_win_bottom_offset;
|
||||
StdVideoH265DecPicBufMgr* pDecPicBufMgr;
|
||||
StdVideoH265SpsFlags flags;
|
||||
StdVideoH265ScalingLists* pScalingLists; // Must be a valid pointer if sps_scaling_list_data_present_flag is set
|
||||
StdVideoH265SequenceParameterSetVui* pSequenceParameterSetVui; // Must be a valid pointer if StdVideoH265SpsFlags:vui_parameters_present_flag is set palette_max_size;
|
||||
|
||||
// extension SPS flags, valid when std_video_h265_profile_idc_scc_extensions is set
|
||||
uint8_t palette_max_size;
|
||||
uint8_t delta_palette_max_predictor_size;
|
||||
uint8_t motion_vector_resolution_control_idc;
|
||||
uint8_t sps_num_palette_predictor_initializer_minus1;
|
||||
StdVideoH265PredictorPaletteEntries* pPredictorPaletteEntries; // Must be a valid pointer if sps_palette_predictor_initializer_present_flag is set
|
||||
} StdVideoH265SequenceParameterSet;
|
||||
|
||||
|
||||
typedef struct StdVideoH265PpsFlags {
|
||||
uint32_t dependent_slice_segments_enabled_flag : 1;
|
||||
uint32_t output_flag_present_flag : 1;
|
||||
uint32_t sign_data_hiding_enabled_flag : 1;
|
||||
uint32_t cabac_init_present_flag : 1;
|
||||
uint32_t constrained_intra_pred_flag : 1;
|
||||
uint32_t transform_skip_enabled_flag : 1;
|
||||
uint32_t cu_qp_delta_enabled_flag : 1;
|
||||
uint32_t pps_slice_chroma_qp_offsets_present_flag : 1;
|
||||
uint32_t weighted_pred_flag : 1;
|
||||
uint32_t weighted_bipred_flag : 1;
|
||||
uint32_t transquant_bypass_enabled_flag : 1;
|
||||
uint32_t tiles_enabled_flag : 1;
|
||||
uint32_t entropy_coding_sync_enabled_flag : 1;
|
||||
uint32_t uniform_spacing_flag : 1;
|
||||
uint32_t loop_filter_across_tiles_enabled_flag : 1;
|
||||
uint32_t pps_loop_filter_across_slices_enabled_flag : 1;
|
||||
uint32_t deblocking_filter_control_present_flag : 1;
|
||||
uint32_t deblocking_filter_override_enabled_flag : 1;
|
||||
uint32_t pps_deblocking_filter_disabled_flag : 1;
|
||||
uint32_t pps_scaling_list_data_present_flag : 1;
|
||||
uint32_t lists_modification_present_flag : 1;
|
||||
uint32_t slice_segment_header_extension_present_flag : 1;
|
||||
uint32_t pps_extension_present_flag : 1;
|
||||
|
||||
// extension PPS flags, valid when std_video_h265_profile_idc_format_range_extensions is set
|
||||
uint32_t cross_component_prediction_enabled_flag : 1;
|
||||
uint32_t chroma_qp_offset_list_enabled_flag : 1;
|
||||
|
||||
// extension PPS flags, valid when std_video_h265_profile_idc_scc_extensions is set
|
||||
uint32_t pps_curr_pic_ref_enabled_flag : 1;
|
||||
uint32_t residual_adaptive_colour_transform_enabled_flag : 1;
|
||||
uint32_t pps_slice_act_qp_offsets_present_flag : 1;
|
||||
uint32_t pps_palette_predictor_initializer_present_flag : 1;
|
||||
uint32_t monochrome_palette_flag : 1;
|
||||
uint32_t pps_range_extension_flag : 1;
|
||||
} StdVideoH265PpsFlags;
|
||||
|
||||
typedef struct StdVideoH265PictureParameterSet
|
||||
{
|
||||
uint8_t pps_pic_parameter_set_id;
|
||||
uint8_t pps_seq_parameter_set_id;
|
||||
uint8_t num_extra_slice_header_bits;
|
||||
uint8_t num_ref_idx_l0_default_active_minus1;
|
||||
uint8_t num_ref_idx_l1_default_active_minus1;
|
||||
int8_t init_qp_minus26;
|
||||
uint8_t diff_cu_qp_delta_depth;
|
||||
int8_t pps_cb_qp_offset;
|
||||
int8_t pps_cr_qp_offset;
|
||||
uint8_t num_tile_columns_minus1;
|
||||
uint8_t num_tile_rows_minus1;
|
||||
uint16_t column_width_minus1[19];
|
||||
uint16_t row_height_minus1[21];
|
||||
int8_t pps_beta_offset_div2;
|
||||
int8_t pps_tc_offset_div2;
|
||||
uint8_t log2_parallel_merge_level_minus2;
|
||||
StdVideoH265PpsFlags flags;
|
||||
StdVideoH265ScalingLists* pScalingLists; // Must be a valid pointer if pps_scaling_list_data_present_flag is set
|
||||
|
||||
// extension PPS, valid when std_video_h265_profile_idc_format_range_extensions is set
|
||||
uint8_t log2_max_transform_skip_block_size_minus2;
|
||||
uint8_t diff_cu_chroma_qp_offset_depth;
|
||||
uint8_t chroma_qp_offset_list_len_minus1;
|
||||
int8_t cb_qp_offset_list[6];
|
||||
int8_t cr_qp_offset_list[6];
|
||||
uint8_t log2_sao_offset_scale_luma;
|
||||
uint8_t log2_sao_offset_scale_chroma;
|
||||
|
||||
// extension PPS, valid when std_video_h265_profile_idc_scc_extensions is set
|
||||
int8_t pps_act_y_qp_offset_plus5;
|
||||
int8_t pps_act_cb_qp_offset_plus5;
|
||||
int8_t pps_act_cr_qp_offset_plus5;
|
||||
uint8_t pps_num_palette_predictor_initializer;
|
||||
uint8_t luma_bit_depth_entry_minus8;
|
||||
uint8_t chroma_bit_depth_entry_minus8;
|
||||
StdVideoH265PredictorPaletteEntries* pPredictorPaletteEntries; // Must be a valid pointer if pps_palette_predictor_initializer_present_flag is set
|
||||
} StdVideoH265PictureParameterSet;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VULKAN_VIDEO_CODEC_H265STD_H_
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
** Copyright (c) 2019-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_VIDEO_CODEC_H265STD_DECODE_H_
|
||||
#define VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vk_video/vulkan_video_codec_h265std.h"
|
||||
|
||||
// *************************************************
|
||||
// Video h265 Decode related parameters:
|
||||
// *************************************************
|
||||
|
||||
typedef struct StdVideoDecodeH265PictureInfoFlags {
|
||||
uint32_t IrapPicFlag : 1;
|
||||
uint32_t IdrPicFlag : 1;
|
||||
uint32_t IsReference : 1;
|
||||
uint32_t short_term_ref_pic_set_sps_flag : 1;
|
||||
} StdVideoDecodeH265PictureInfoFlags;
|
||||
|
||||
typedef struct StdVideoDecodeH265PictureInfo {
|
||||
uint8_t vps_video_parameter_set_id;
|
||||
uint8_t sps_seq_parameter_set_id;
|
||||
uint8_t pps_pic_parameter_set_id;
|
||||
uint8_t num_short_term_ref_pic_sets;
|
||||
int32_t PicOrderCntVal;
|
||||
uint16_t NumBitsForSTRefPicSetInSlice; // number of bits used in st_ref_pic_set()
|
||||
//when short_term_ref_pic_set_sps_flag is 0; otherwise set to 0.
|
||||
uint8_t NumDeltaPocsOfRefRpsIdx; // NumDeltaPocs[ RefRpsIdx ] when short_term_ref_pic_set_sps_flag = 1, otherwise 0
|
||||
uint8_t RefPicSetStCurrBefore[8]; // slotIndex as used in VkVideoReferenceSlotKHR structures representing
|
||||
//pReferenceSlots in VkVideoDecodeInfoKHR, 0xff for invalid slotIndex
|
||||
uint8_t RefPicSetStCurrAfter[8]; // slotIndex as used in VkVideoReferenceSlotKHR structures representing
|
||||
//pReferenceSlots in VkVideoDecodeInfoKHR, 0xff for invalid slotIndex
|
||||
uint8_t RefPicSetLtCurr[8]; // slotIndex as used in VkVideoReferenceSlotKHR structures representing
|
||||
//pReferenceSlots in VkVideoDecodeInfoKHR, 0xff for invalid slotIndex
|
||||
StdVideoDecodeH265PictureInfoFlags flags;
|
||||
} StdVideoDecodeH265PictureInfo;
|
||||
|
||||
typedef struct StdVideoDecodeH265ReferenceInfoFlags {
|
||||
uint32_t is_long_term : 1;
|
||||
uint32_t is_non_existing : 1;
|
||||
} StdVideoDecodeH265ReferenceInfoFlags;
|
||||
|
||||
typedef struct StdVideoDecodeH265ReferenceInfo {
|
||||
int32_t PicOrderCntVal;
|
||||
StdVideoDecodeH265ReferenceInfoFlags flags;
|
||||
} StdVideoDecodeH265ReferenceInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VULKAN_VIDEO_CODEC_H265STD_DECODE_H_
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
** Copyright (c) 2019-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef VULKAN_VIDEO_CODEC_COMMON_H_
|
||||
#define VULKAN_VIDEO_CODEC_COMMON_H_ 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \
|
||||
((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VULKAN_VIDEO_CODEC_COMMON_H_
|
||||
File diff suppressed because it is too large
Load Diff
+245
@@ -0,0 +1,245 @@
|
||||
//
|
||||
// File: vk_icd.h
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2015-2016 The Khronos Group Inc.
|
||||
* Copyright (c) 2015-2016 Valve Corporation
|
||||
* Copyright (c) 2015-2016 LunarG, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VKICD_H
|
||||
#define VKICD_H
|
||||
|
||||
#include "vulkan.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
// Loader-ICD version negotiation API. Versions add the following features:
|
||||
// Version 0 - Initial. Doesn't support vk_icdGetInstanceProcAddr
|
||||
// or vk_icdNegotiateLoaderICDInterfaceVersion.
|
||||
// Version 1 - Add support for vk_icdGetInstanceProcAddr.
|
||||
// Version 2 - Add Loader/ICD Interface version negotiation
|
||||
// via vk_icdNegotiateLoaderICDInterfaceVersion.
|
||||
// Version 3 - Add ICD creation/destruction of KHR_surface objects.
|
||||
// Version 4 - Add unknown physical device extension qyering via
|
||||
// vk_icdGetPhysicalDeviceProcAddr.
|
||||
// Version 5 - Tells ICDs that the loader is now paying attention to the
|
||||
// application version of Vulkan passed into the ApplicationInfo
|
||||
// structure during vkCreateInstance. This will tell the ICD
|
||||
// that if the loader is older, it should automatically fail a
|
||||
// call for any API version > 1.0. Otherwise, the loader will
|
||||
// manually determine if it can support the expected version.
|
||||
// Version 6 - Add support for vk_icdEnumerateAdapterPhysicalDevices.
|
||||
#define CURRENT_LOADER_ICD_INTERFACE_VERSION 6
|
||||
#define MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION 0
|
||||
#define MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION 4
|
||||
|
||||
// Old typedefs that don't follow a proper naming convention but are preserved for compatibility
|
||||
typedef VkResult(VKAPI_PTR *PFN_vkNegotiateLoaderICDInterfaceVersion)(uint32_t *pVersion);
|
||||
// This is defined in vk_layer.h which will be found by the loader, but if an ICD is building against this
|
||||
// file directly, it won't be found.
|
||||
#ifndef PFN_GetPhysicalDeviceProcAddr
|
||||
typedef PFN_vkVoidFunction(VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char *pName);
|
||||
#endif
|
||||
|
||||
// Typedefs for loader/ICD interface
|
||||
typedef VkResult (VKAPI_PTR *PFN_vk_icdNegotiateLoaderICDInterfaceVersion)(uint32_t* pVersion);
|
||||
typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetInstanceProcAddr)(VkInstance instance, const char* pName);
|
||||
typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vk_icdGetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
|
||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||
typedef VkResult (VKAPI_PTR *PFN_vk_icdEnumerateAdapterPhysicalDevices)(VkInstance instance, LUID adapterLUID,
|
||||
uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
|
||||
#endif
|
||||
|
||||
// Prototypes for loader/ICD interface
|
||||
#if !defined(VK_NO_PROTOTYPES)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pVersion);
|
||||
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetInstanceProcAddr(VkInstance instance, const char* pName);
|
||||
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_icdGetPhysicalDeviceProcAddr(VkInstance isntance, const char* pName);
|
||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vk_icdEnumerateAdapterPhysicalDevices(VkInstance instance, LUID adapterLUID,
|
||||
uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The ICD must reserve space for a pointer for the loader's dispatch
|
||||
* table, at the start of <each object>.
|
||||
* The ICD must initialize this variable using the SET_LOADER_MAGIC_VALUE macro.
|
||||
*/
|
||||
|
||||
#define ICD_LOADER_MAGIC 0x01CDC0DE
|
||||
|
||||
typedef union {
|
||||
uintptr_t loaderMagic;
|
||||
void *loaderData;
|
||||
} VK_LOADER_DATA;
|
||||
|
||||
static inline void set_loader_magic_value(void *pNewObject) {
|
||||
VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
|
||||
loader_info->loaderMagic = ICD_LOADER_MAGIC;
|
||||
}
|
||||
|
||||
static inline bool valid_loader_magic_value(void *pNewObject) {
|
||||
const VK_LOADER_DATA *loader_info = (VK_LOADER_DATA *)pNewObject;
|
||||
return (loader_info->loaderMagic & 0xffffffff) == ICD_LOADER_MAGIC;
|
||||
}
|
||||
|
||||
/*
|
||||
* Windows and Linux ICDs will treat VkSurfaceKHR as a pointer to a struct that
|
||||
* contains the platform-specific connection and surface information.
|
||||
*/
|
||||
typedef enum {
|
||||
VK_ICD_WSI_PLATFORM_MIR,
|
||||
VK_ICD_WSI_PLATFORM_WAYLAND,
|
||||
VK_ICD_WSI_PLATFORM_WIN32,
|
||||
VK_ICD_WSI_PLATFORM_XCB,
|
||||
VK_ICD_WSI_PLATFORM_XLIB,
|
||||
VK_ICD_WSI_PLATFORM_ANDROID,
|
||||
VK_ICD_WSI_PLATFORM_MACOS,
|
||||
VK_ICD_WSI_PLATFORM_IOS,
|
||||
VK_ICD_WSI_PLATFORM_DISPLAY,
|
||||
VK_ICD_WSI_PLATFORM_HEADLESS,
|
||||
VK_ICD_WSI_PLATFORM_METAL,
|
||||
VK_ICD_WSI_PLATFORM_DIRECTFB,
|
||||
VK_ICD_WSI_PLATFORM_VI,
|
||||
VK_ICD_WSI_PLATFORM_GGP,
|
||||
VK_ICD_WSI_PLATFORM_SCREEN,
|
||||
} VkIcdWsiPlatform;
|
||||
|
||||
typedef struct {
|
||||
VkIcdWsiPlatform platform;
|
||||
} VkIcdSurfaceBase;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MIR_KHR
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
MirConnection *connection;
|
||||
MirSurface *mirSurface;
|
||||
} VkIcdSurfaceMir;
|
||||
#endif // VK_USE_PLATFORM_MIR_KHR
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
struct wl_display *display;
|
||||
struct wl_surface *surface;
|
||||
} VkIcdSurfaceWayland;
|
||||
#endif // VK_USE_PLATFORM_WAYLAND_KHR
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
HINSTANCE hinstance;
|
||||
HWND hwnd;
|
||||
} VkIcdSurfaceWin32;
|
||||
#endif // VK_USE_PLATFORM_WIN32_KHR
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
xcb_connection_t *connection;
|
||||
xcb_window_t window;
|
||||
} VkIcdSurfaceXcb;
|
||||
#endif // VK_USE_PLATFORM_XCB_KHR
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
Display *dpy;
|
||||
Window window;
|
||||
} VkIcdSurfaceXlib;
|
||||
#endif // VK_USE_PLATFORM_XLIB_KHR
|
||||
|
||||
#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
IDirectFB *dfb;
|
||||
IDirectFBSurface *surface;
|
||||
} VkIcdSurfaceDirectFB;
|
||||
#endif // VK_USE_PLATFORM_DIRECTFB_EXT
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
struct ANativeWindow *window;
|
||||
} VkIcdSurfaceAndroid;
|
||||
#endif // VK_USE_PLATFORM_ANDROID_KHR
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
const void *pView;
|
||||
} VkIcdSurfaceMacOS;
|
||||
#endif // VK_USE_PLATFORM_MACOS_MVK
|
||||
|
||||
#ifdef VK_USE_PLATFORM_IOS_MVK
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
const void *pView;
|
||||
} VkIcdSurfaceIOS;
|
||||
#endif // VK_USE_PLATFORM_IOS_MVK
|
||||
|
||||
#ifdef VK_USE_PLATFORM_GGP
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
GgpStreamDescriptor streamDescriptor;
|
||||
} VkIcdSurfaceGgp;
|
||||
#endif // VK_USE_PLATFORM_GGP
|
||||
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
VkDisplayModeKHR displayMode;
|
||||
uint32_t planeIndex;
|
||||
uint32_t planeStackIndex;
|
||||
VkSurfaceTransformFlagBitsKHR transform;
|
||||
float globalAlpha;
|
||||
VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
|
||||
VkExtent2D imageExtent;
|
||||
} VkIcdSurfaceDisplay;
|
||||
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
} VkIcdSurfaceHeadless;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
const CAMetalLayer *pLayer;
|
||||
} VkIcdSurfaceMetal;
|
||||
#endif // VK_USE_PLATFORM_METAL_EXT
|
||||
|
||||
#ifdef VK_USE_PLATFORM_VI_NN
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
void *window;
|
||||
} VkIcdSurfaceVi;
|
||||
#endif // VK_USE_PLATFORM_VI_NN
|
||||
|
||||
#ifdef VK_USE_PLATFORM_SCREEN_QNX
|
||||
typedef struct {
|
||||
VkIcdSurfaceBase base;
|
||||
struct _screen_context *context;
|
||||
struct _screen_window *window;
|
||||
} VkIcdSurfaceScreen;
|
||||
#endif // VK_USE_PLATFORM_SCREEN_QNX
|
||||
|
||||
#endif // VKICD_H
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
//
|
||||
// File: vk_layer.h
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2015-2017 The Khronos Group Inc.
|
||||
* Copyright (c) 2015-2017 Valve Corporation
|
||||
* Copyright (c) 2015-2017 LunarG, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/* Need to define dispatch table
|
||||
* Core struct can then have ptr to dispatch table at the top
|
||||
* Along with object ptrs for current and next OBJ
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "vulkan.h"
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
#define VK_LAYER_EXPORT __attribute__((visibility("default")))
|
||||
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
|
||||
#define VK_LAYER_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define VK_LAYER_EXPORT
|
||||
#endif
|
||||
|
||||
#define MAX_NUM_UNKNOWN_EXTS 250
|
||||
|
||||
// Loader-Layer version negotiation API. Versions add the following features:
|
||||
// Versions 0/1 - Initial. Doesn't support vk_layerGetPhysicalDeviceProcAddr
|
||||
// or vk_icdNegotiateLoaderLayerInterfaceVersion.
|
||||
// Version 2 - Add support for vk_layerGetPhysicalDeviceProcAddr and
|
||||
// vk_icdNegotiateLoaderLayerInterfaceVersion.
|
||||
#define CURRENT_LOADER_LAYER_INTERFACE_VERSION 2
|
||||
#define MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION 1
|
||||
|
||||
#define VK_CURRENT_CHAIN_VERSION 1
|
||||
|
||||
// Typedef for use in the interfaces below
|
||||
typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
|
||||
|
||||
// Version negotiation values
|
||||
typedef enum VkNegotiateLayerStructType {
|
||||
LAYER_NEGOTIATE_UNINTIALIZED = 0,
|
||||
LAYER_NEGOTIATE_INTERFACE_STRUCT = 1,
|
||||
} VkNegotiateLayerStructType;
|
||||
|
||||
// Version negotiation structures
|
||||
typedef struct VkNegotiateLayerInterface {
|
||||
VkNegotiateLayerStructType sType;
|
||||
void *pNext;
|
||||
uint32_t loaderLayerInterfaceVersion;
|
||||
PFN_vkGetInstanceProcAddr pfnGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr;
|
||||
PFN_GetPhysicalDeviceProcAddr pfnGetPhysicalDeviceProcAddr;
|
||||
} VkNegotiateLayerInterface;
|
||||
|
||||
// Version negotiation functions
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkNegotiateLoaderLayerInterfaceVersion)(VkNegotiateLayerInterface *pVersionStruct);
|
||||
|
||||
// Function prototype for unknown physical device extension command
|
||||
typedef VkResult(VKAPI_PTR *PFN_PhysDevExt)(VkPhysicalDevice phys_device);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// CreateInstance and CreateDevice support structures
|
||||
|
||||
/* Sub type of structure for instance and device loader ext of CreateInfo.
|
||||
* When sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO
|
||||
* or sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO
|
||||
* then VkLayerFunction indicates struct type pointed to by pNext
|
||||
*/
|
||||
typedef enum VkLayerFunction_ {
|
||||
VK_LAYER_LINK_INFO = 0,
|
||||
VK_LOADER_DATA_CALLBACK = 1,
|
||||
VK_LOADER_LAYER_CREATE_DEVICE_CALLBACK = 2,
|
||||
VK_LOADER_FEATURES = 3,
|
||||
} VkLayerFunction;
|
||||
|
||||
typedef struct VkLayerInstanceLink_ {
|
||||
struct VkLayerInstanceLink_ *pNext;
|
||||
PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
|
||||
PFN_GetPhysicalDeviceProcAddr pfnNextGetPhysicalDeviceProcAddr;
|
||||
} VkLayerInstanceLink;
|
||||
|
||||
/*
|
||||
* When creating the device chain the loader needs to pass
|
||||
* down information about it's device structure needed at
|
||||
* the end of the chain. Passing the data via the
|
||||
* VkLayerDeviceInfo avoids issues with finding the
|
||||
* exact instance being used.
|
||||
*/
|
||||
typedef struct VkLayerDeviceInfo_ {
|
||||
void *device_info;
|
||||
PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
|
||||
} VkLayerDeviceInfo;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkSetInstanceLoaderData)(VkInstance instance,
|
||||
void *object);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkSetDeviceLoaderData)(VkDevice device,
|
||||
void *object);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkLayerCreateDevice)(VkInstance instance, VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA);
|
||||
typedef void (VKAPI_PTR *PFN_vkLayerDestroyDevice)(VkDevice physicalDevice, const VkAllocationCallbacks *pAllocator, PFN_vkDestroyDevice destroyFunction);
|
||||
|
||||
typedef enum VkLoaderFeastureFlagBits {
|
||||
VK_LOADER_FEATURE_PHYSICAL_DEVICE_SORTING = 0x00000001,
|
||||
} VkLoaderFlagBits;
|
||||
typedef VkFlags VkLoaderFeatureFlags;
|
||||
|
||||
typedef struct {
|
||||
VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO
|
||||
const void *pNext;
|
||||
VkLayerFunction function;
|
||||
union {
|
||||
VkLayerInstanceLink *pLayerInfo;
|
||||
PFN_vkSetInstanceLoaderData pfnSetInstanceLoaderData;
|
||||
struct {
|
||||
PFN_vkLayerCreateDevice pfnLayerCreateDevice;
|
||||
PFN_vkLayerDestroyDevice pfnLayerDestroyDevice;
|
||||
} layerDevice;
|
||||
VkLoaderFeatureFlags loaderFeatures;
|
||||
} u;
|
||||
} VkLayerInstanceCreateInfo;
|
||||
|
||||
typedef struct VkLayerDeviceLink_ {
|
||||
struct VkLayerDeviceLink_ *pNext;
|
||||
PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr pfnNextGetDeviceProcAddr;
|
||||
} VkLayerDeviceLink;
|
||||
|
||||
typedef struct {
|
||||
VkStructureType sType; // VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO
|
||||
const void *pNext;
|
||||
VkLayerFunction function;
|
||||
union {
|
||||
VkLayerDeviceLink *pLayerInfo;
|
||||
PFN_vkSetDeviceLoaderData pfnSetDeviceLoaderData;
|
||||
} u;
|
||||
} VkLayerDeviceCreateInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct);
|
||||
|
||||
typedef enum VkChainType {
|
||||
VK_CHAIN_TYPE_UNKNOWN = 0,
|
||||
VK_CHAIN_TYPE_ENUMERATE_INSTANCE_EXTENSION_PROPERTIES = 1,
|
||||
VK_CHAIN_TYPE_ENUMERATE_INSTANCE_LAYER_PROPERTIES = 2,
|
||||
VK_CHAIN_TYPE_ENUMERATE_INSTANCE_VERSION = 3,
|
||||
} VkChainType;
|
||||
|
||||
typedef struct VkChainHeader {
|
||||
VkChainType type;
|
||||
uint32_t version;
|
||||
uint32_t size;
|
||||
} VkChainHeader;
|
||||
|
||||
typedef struct VkEnumerateInstanceExtensionPropertiesChain {
|
||||
VkChainHeader header;
|
||||
VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceExtensionPropertiesChain *, const char *, uint32_t *,
|
||||
VkExtensionProperties *);
|
||||
const struct VkEnumerateInstanceExtensionPropertiesChain *pNextLink;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
inline VkResult CallDown(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties) const {
|
||||
return pfnNextLayer(pNextLink, pLayerName, pPropertyCount, pProperties);
|
||||
}
|
||||
#endif
|
||||
} VkEnumerateInstanceExtensionPropertiesChain;
|
||||
|
||||
typedef struct VkEnumerateInstanceLayerPropertiesChain {
|
||||
VkChainHeader header;
|
||||
VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceLayerPropertiesChain *, uint32_t *, VkLayerProperties *);
|
||||
const struct VkEnumerateInstanceLayerPropertiesChain *pNextLink;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
inline VkResult CallDown(uint32_t *pPropertyCount, VkLayerProperties *pProperties) const {
|
||||
return pfnNextLayer(pNextLink, pPropertyCount, pProperties);
|
||||
}
|
||||
#endif
|
||||
} VkEnumerateInstanceLayerPropertiesChain;
|
||||
|
||||
typedef struct VkEnumerateInstanceVersionChain {
|
||||
VkChainHeader header;
|
||||
VkResult(VKAPI_PTR *pfnNextLayer)(const struct VkEnumerateInstanceVersionChain *, uint32_t *);
|
||||
const struct VkEnumerateInstanceVersionChain *pNextLink;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
inline VkResult CallDown(uint32_t *pApiVersion) const {
|
||||
return pfnNextLayer(pNextLink, pApiVersion);
|
||||
}
|
||||
#endif
|
||||
} VkEnumerateInstanceVersionChain;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// File: vk_platform.h
|
||||
//
|
||||
/*
|
||||
** Copyright 2014-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VK_PLATFORM_H_
|
||||
#define VK_PLATFORM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif // __cplusplus
|
||||
|
||||
/*
|
||||
***************************************************************************************************
|
||||
* Platform-specific directives and type declarations
|
||||
***************************************************************************************************
|
||||
*/
|
||||
|
||||
/* Platform-specific calling convention macros.
|
||||
*
|
||||
* Platforms should define these so that Vulkan clients call Vulkan commands
|
||||
* with the same calling conventions that the Vulkan implementation expects.
|
||||
*
|
||||
* VKAPI_ATTR - Placed before the return type in function declarations.
|
||||
* Useful for C++11 and GCC/Clang-style function attribute syntax.
|
||||
* VKAPI_CALL - Placed after the return type in function declarations.
|
||||
* Useful for MSVC-style calling convention syntax.
|
||||
* VKAPI_PTR - Placed between the '(' and '*' in function pointer types.
|
||||
*
|
||||
* Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void);
|
||||
* Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void);
|
||||
*/
|
||||
#if defined(_WIN32)
|
||||
// On Windows, Vulkan commands use the stdcall convention
|
||||
#define VKAPI_ATTR
|
||||
#define VKAPI_CALL __stdcall
|
||||
#define VKAPI_PTR VKAPI_CALL
|
||||
#elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7
|
||||
#error "Vulkan isn't supported for the 'armeabi' NDK ABI"
|
||||
#elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE)
|
||||
// On Android 32-bit ARM targets, Vulkan functions use the "hardfloat"
|
||||
// calling convention, i.e. float parameters are passed in registers. This
|
||||
// is true even if the rest of the application passes floats on the stack,
|
||||
// as it does by default when compiling for the armeabi-v7a NDK ABI.
|
||||
#define VKAPI_ATTR __attribute__((pcs("aapcs-vfp")))
|
||||
#define VKAPI_CALL
|
||||
#define VKAPI_PTR VKAPI_ATTR
|
||||
#else
|
||||
// On other platforms, use the default calling convention
|
||||
#define VKAPI_ATTR
|
||||
#define VKAPI_CALL
|
||||
#define VKAPI_PTR
|
||||
#endif
|
||||
|
||||
#if !defined(VK_NO_STDDEF_H)
|
||||
#include <stddef.h>
|
||||
#endif // !defined(VK_NO_STDDEF_H)
|
||||
|
||||
#if !defined(VK_NO_STDINT_H)
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600)
|
||||
typedef signed __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#endif // !defined(VK_NO_STDINT_H)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// File: vk_sdk_platform.h
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2015-2016 The Khronos Group Inc.
|
||||
* Copyright (c) 2015-2016 Valve Corporation
|
||||
* Copyright (c) 2015-2016 LunarG, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef VK_SDK_PLATFORM_H
|
||||
#define VK_SDK_PLATFORM_H
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define NOMINMAX
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#define inline __inline
|
||||
#endif // __cplusplus
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER < 1900 /*vs2015*/)
|
||||
// C99:
|
||||
// Microsoft didn't implement C99 in Visual Studio; but started adding it with
|
||||
// VS2013. However, VS2013 still didn't have snprintf(). The following is a
|
||||
// work-around (Note: The _CRT_SECURE_NO_WARNINGS macro must be set in the
|
||||
// "CMakeLists.txt" file).
|
||||
// NOTE: This is fixed in Visual Studio 2015.
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#define strdup _strdup
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
// Check for noexcept support using clang, with fallback to Windows or GCC version numbers
|
||||
#ifndef NOEXCEPT
|
||||
#if defined(__clang__)
|
||||
#if __has_feature(cxx_noexcept)
|
||||
#define HAS_NOEXCEPT
|
||||
#endif
|
||||
#else
|
||||
#if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46
|
||||
#define HAS_NOEXCEPT
|
||||
#else
|
||||
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS
|
||||
#define HAS_NOEXCEPT
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAS_NOEXCEPT
|
||||
#define NOEXCEPT noexcept
|
||||
#else
|
||||
#define NOEXCEPT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // VK_SDK_PLATFORM_H
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#ifndef VULKAN_H_
|
||||
#define VULKAN_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "vk_platform.h"
|
||||
#include "vulkan_core.h"
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
#include "vulkan_android.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_FUCHSIA
|
||||
#include <zircon/types.h>
|
||||
#include "vulkan_fuchsia.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_IOS_MVK
|
||||
#include "vulkan_ios.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_MACOS_MVK
|
||||
#include "vulkan_macos.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_METAL_EXT
|
||||
#include "vulkan_metal.h"
|
||||
#endif
|
||||
|
||||
#ifdef VK_USE_PLATFORM_VI_NN
|
||||
#include "vulkan_vi.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
#include <wayland-client.h>
|
||||
#include "vulkan_wayland.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_WIN32_KHR
|
||||
#include <windows.h>
|
||||
#include "vulkan_win32.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XCB_KHR
|
||||
#include <xcb/xcb.h>
|
||||
#include "vulkan_xcb.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_KHR
|
||||
#include <X11/Xlib.h>
|
||||
#include "vulkan_xlib.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
|
||||
#include <directfb.h>
|
||||
#include "vulkan_directfb.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "vulkan_xlib_xrandr.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_GGP
|
||||
#include <ggp_c/vulkan_types.h>
|
||||
#include "vulkan_ggp.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_USE_PLATFORM_SCREEN_QNX
|
||||
#include <screen/screen.h>
|
||||
#include "vulkan_screen.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
||||
#include "vulkan_beta.h"
|
||||
#endif
|
||||
|
||||
#endif // VULKAN_H_
|
||||
+124390
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,112 @@
|
||||
#ifndef VULKAN_ANDROID_H_
|
||||
#define VULKAN_ANDROID_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_android_surface 1
|
||||
struct ANativeWindow;
|
||||
#define VK_KHR_ANDROID_SURFACE_SPEC_VERSION 6
|
||||
#define VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "VK_KHR_android_surface"
|
||||
typedef VkFlags VkAndroidSurfaceCreateFlagsKHR;
|
||||
typedef struct VkAndroidSurfaceCreateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkAndroidSurfaceCreateFlagsKHR flags;
|
||||
struct ANativeWindow* window;
|
||||
} VkAndroidSurfaceCreateInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateAndroidSurfaceKHR)(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
|
||||
VkInstance instance,
|
||||
const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_ANDROID_external_memory_android_hardware_buffer 1
|
||||
struct AHardwareBuffer;
|
||||
#define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_SPEC_VERSION 3
|
||||
#define VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME "VK_ANDROID_external_memory_android_hardware_buffer"
|
||||
typedef struct VkAndroidHardwareBufferUsageANDROID {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint64_t androidHardwareBufferUsage;
|
||||
} VkAndroidHardwareBufferUsageANDROID;
|
||||
|
||||
typedef struct VkAndroidHardwareBufferPropertiesANDROID {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkDeviceSize allocationSize;
|
||||
uint32_t memoryTypeBits;
|
||||
} VkAndroidHardwareBufferPropertiesANDROID;
|
||||
|
||||
typedef struct VkAndroidHardwareBufferFormatPropertiesANDROID {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkFormat format;
|
||||
uint64_t externalFormat;
|
||||
VkFormatFeatureFlags formatFeatures;
|
||||
VkComponentMapping samplerYcbcrConversionComponents;
|
||||
VkSamplerYcbcrModelConversion suggestedYcbcrModel;
|
||||
VkSamplerYcbcrRange suggestedYcbcrRange;
|
||||
VkChromaLocation suggestedXChromaOffset;
|
||||
VkChromaLocation suggestedYChromaOffset;
|
||||
} VkAndroidHardwareBufferFormatPropertiesANDROID;
|
||||
|
||||
typedef struct VkImportAndroidHardwareBufferInfoANDROID {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
struct AHardwareBuffer* buffer;
|
||||
} VkImportAndroidHardwareBufferInfoANDROID;
|
||||
|
||||
typedef struct VkMemoryGetAndroidHardwareBufferInfoANDROID {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkDeviceMemory memory;
|
||||
} VkMemoryGetAndroidHardwareBufferInfoANDROID;
|
||||
|
||||
typedef struct VkExternalFormatANDROID {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint64_t externalFormat;
|
||||
} VkExternalFormatANDROID;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetAndroidHardwareBufferPropertiesANDROID)(VkDevice device, const struct AHardwareBuffer* buffer, VkAndroidHardwareBufferPropertiesANDROID* pProperties);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryAndroidHardwareBufferANDROID)(VkDevice device, const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, struct AHardwareBuffer** pBuffer);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetAndroidHardwareBufferPropertiesANDROID(
|
||||
VkDevice device,
|
||||
const struct AHardwareBuffer* buffer,
|
||||
VkAndroidHardwareBufferPropertiesANDROID* pProperties);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryAndroidHardwareBufferANDROID(
|
||||
VkDevice device,
|
||||
const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo,
|
||||
struct AHardwareBuffer** pBuffer);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+704
@@ -0,0 +1,704 @@
|
||||
#ifndef VULKAN_BETA_H_
|
||||
#define VULKAN_BETA_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_video_queue 1
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkVideoSessionKHR)
|
||||
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkVideoSessionParametersKHR)
|
||||
#define VK_KHR_VIDEO_QUEUE_SPEC_VERSION 1
|
||||
#define VK_KHR_VIDEO_QUEUE_EXTENSION_NAME "VK_KHR_video_queue"
|
||||
|
||||
typedef enum VkQueryResultStatusKHR {
|
||||
VK_QUERY_RESULT_STATUS_ERROR_KHR = -1,
|
||||
VK_QUERY_RESULT_STATUS_NOT_READY_KHR = 0,
|
||||
VK_QUERY_RESULT_STATUS_COMPLETE_KHR = 1,
|
||||
VK_QUERY_RESULT_STATUS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkQueryResultStatusKHR;
|
||||
|
||||
typedef enum VkVideoCodecOperationFlagBitsKHR {
|
||||
VK_VIDEO_CODEC_OPERATION_INVALID_BIT_KHR = 0,
|
||||
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
||||
VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_EXT = 0x00010000,
|
||||
#endif
|
||||
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
||||
VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_EXT = 0x00000001,
|
||||
#endif
|
||||
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
||||
VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_EXT = 0x00000002,
|
||||
#endif
|
||||
VK_VIDEO_CODEC_OPERATION_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoCodecOperationFlagBitsKHR;
|
||||
typedef VkFlags VkVideoCodecOperationFlagsKHR;
|
||||
|
||||
typedef enum VkVideoChromaSubsamplingFlagBitsKHR {
|
||||
VK_VIDEO_CHROMA_SUBSAMPLING_INVALID_BIT_KHR = 0,
|
||||
VK_VIDEO_CHROMA_SUBSAMPLING_MONOCHROME_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR = 0x00000002,
|
||||
VK_VIDEO_CHROMA_SUBSAMPLING_422_BIT_KHR = 0x00000004,
|
||||
VK_VIDEO_CHROMA_SUBSAMPLING_444_BIT_KHR = 0x00000008,
|
||||
VK_VIDEO_CHROMA_SUBSAMPLING_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoChromaSubsamplingFlagBitsKHR;
|
||||
typedef VkFlags VkVideoChromaSubsamplingFlagsKHR;
|
||||
|
||||
typedef enum VkVideoComponentBitDepthFlagBitsKHR {
|
||||
VK_VIDEO_COMPONENT_BIT_DEPTH_INVALID_KHR = 0,
|
||||
VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_COMPONENT_BIT_DEPTH_10_BIT_KHR = 0x00000004,
|
||||
VK_VIDEO_COMPONENT_BIT_DEPTH_12_BIT_KHR = 0x00000010,
|
||||
VK_VIDEO_COMPONENT_BIT_DEPTH_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoComponentBitDepthFlagBitsKHR;
|
||||
typedef VkFlags VkVideoComponentBitDepthFlagsKHR;
|
||||
|
||||
typedef enum VkVideoCapabilitiesFlagBitsKHR {
|
||||
VK_VIDEO_CAPABILITIES_PROTECTED_CONTENT_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_CAPABILITIES_SEPARATE_REFERENCE_IMAGES_BIT_KHR = 0x00000002,
|
||||
VK_VIDEO_CAPABILITIES_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoCapabilitiesFlagBitsKHR;
|
||||
typedef VkFlags VkVideoCapabilitiesFlagsKHR;
|
||||
|
||||
typedef enum VkVideoSessionCreateFlagBitsKHR {
|
||||
VK_VIDEO_SESSION_CREATE_DEFAULT_KHR = 0,
|
||||
VK_VIDEO_SESSION_CREATE_PROTECTED_CONTENT_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_SESSION_CREATE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoSessionCreateFlagBitsKHR;
|
||||
typedef VkFlags VkVideoSessionCreateFlagsKHR;
|
||||
typedef VkFlags VkVideoBeginCodingFlagsKHR;
|
||||
typedef VkFlags VkVideoEndCodingFlagsKHR;
|
||||
|
||||
typedef enum VkVideoCodingControlFlagBitsKHR {
|
||||
VK_VIDEO_CODING_CONTROL_DEFAULT_KHR = 0,
|
||||
VK_VIDEO_CODING_CONTROL_RESET_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_CODING_CONTROL_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoCodingControlFlagBitsKHR;
|
||||
typedef VkFlags VkVideoCodingControlFlagsKHR;
|
||||
|
||||
typedef enum VkVideoCodingQualityPresetFlagBitsKHR {
|
||||
VK_VIDEO_CODING_QUALITY_PRESET_DEFAULT_BIT_KHR = 0,
|
||||
VK_VIDEO_CODING_QUALITY_PRESET_NORMAL_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_CODING_QUALITY_PRESET_POWER_BIT_KHR = 0x00000002,
|
||||
VK_VIDEO_CODING_QUALITY_PRESET_QUALITY_BIT_KHR = 0x00000004,
|
||||
VK_VIDEO_CODING_QUALITY_PRESET_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoCodingQualityPresetFlagBitsKHR;
|
||||
typedef VkFlags VkVideoCodingQualityPresetFlagsKHR;
|
||||
typedef struct VkVideoQueueFamilyProperties2KHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkVideoCodecOperationFlagsKHR videoCodecOperations;
|
||||
} VkVideoQueueFamilyProperties2KHR;
|
||||
|
||||
typedef struct VkVideoProfileKHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkVideoCodecOperationFlagBitsKHR videoCodecOperation;
|
||||
VkVideoChromaSubsamplingFlagsKHR chromaSubsampling;
|
||||
VkVideoComponentBitDepthFlagsKHR lumaBitDepth;
|
||||
VkVideoComponentBitDepthFlagsKHR chromaBitDepth;
|
||||
} VkVideoProfileKHR;
|
||||
|
||||
typedef struct VkVideoProfilesKHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint32_t profileCount;
|
||||
const VkVideoProfileKHR* pProfiles;
|
||||
} VkVideoProfilesKHR;
|
||||
|
||||
typedef struct VkVideoCapabilitiesKHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkVideoCapabilitiesFlagsKHR capabilityFlags;
|
||||
VkDeviceSize minBitstreamBufferOffsetAlignment;
|
||||
VkDeviceSize minBitstreamBufferSizeAlignment;
|
||||
VkExtent2D videoPictureExtentGranularity;
|
||||
VkExtent2D minExtent;
|
||||
VkExtent2D maxExtent;
|
||||
uint32_t maxReferencePicturesSlotsCount;
|
||||
uint32_t maxReferencePicturesActiveCount;
|
||||
} VkVideoCapabilitiesKHR;
|
||||
|
||||
typedef struct VkPhysicalDeviceVideoFormatInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkImageUsageFlags imageUsage;
|
||||
const VkVideoProfilesKHR* pVideoProfiles;
|
||||
} VkPhysicalDeviceVideoFormatInfoKHR;
|
||||
|
||||
typedef struct VkVideoFormatPropertiesKHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkFormat format;
|
||||
} VkVideoFormatPropertiesKHR;
|
||||
|
||||
typedef struct VkVideoPictureResourceKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkOffset2D codedOffset;
|
||||
VkExtent2D codedExtent;
|
||||
uint32_t baseArrayLayer;
|
||||
VkImageView imageViewBinding;
|
||||
} VkVideoPictureResourceKHR;
|
||||
|
||||
typedef struct VkVideoReferenceSlotKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
int8_t slotIndex;
|
||||
const VkVideoPictureResourceKHR* pPictureResource;
|
||||
} VkVideoReferenceSlotKHR;
|
||||
|
||||
typedef struct VkVideoGetMemoryPropertiesKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t memoryBindIndex;
|
||||
VkMemoryRequirements2* pMemoryRequirements;
|
||||
} VkVideoGetMemoryPropertiesKHR;
|
||||
|
||||
typedef struct VkVideoBindMemoryKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t memoryBindIndex;
|
||||
VkDeviceMemory memory;
|
||||
VkDeviceSize memoryOffset;
|
||||
VkDeviceSize memorySize;
|
||||
} VkVideoBindMemoryKHR;
|
||||
|
||||
typedef struct VkVideoSessionCreateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t queueFamilyIndex;
|
||||
VkVideoSessionCreateFlagsKHR flags;
|
||||
const VkVideoProfileKHR* pVideoProfile;
|
||||
VkFormat pictureFormat;
|
||||
VkExtent2D maxCodedExtent;
|
||||
VkFormat referencePicturesFormat;
|
||||
uint32_t maxReferencePicturesSlotsCount;
|
||||
uint32_t maxReferencePicturesActiveCount;
|
||||
} VkVideoSessionCreateInfoKHR;
|
||||
|
||||
typedef struct VkVideoSessionParametersCreateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoSessionParametersKHR videoSessionParametersTemplate;
|
||||
VkVideoSessionKHR videoSession;
|
||||
} VkVideoSessionParametersCreateInfoKHR;
|
||||
|
||||
typedef struct VkVideoSessionParametersUpdateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t updateSequenceCount;
|
||||
} VkVideoSessionParametersUpdateInfoKHR;
|
||||
|
||||
typedef struct VkVideoBeginCodingInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoBeginCodingFlagsKHR flags;
|
||||
VkVideoCodingQualityPresetFlagsKHR codecQualityPreset;
|
||||
VkVideoSessionKHR videoSession;
|
||||
VkVideoSessionParametersKHR videoSessionParameters;
|
||||
uint32_t referenceSlotCount;
|
||||
const VkVideoReferenceSlotKHR* pReferenceSlots;
|
||||
} VkVideoBeginCodingInfoKHR;
|
||||
|
||||
typedef struct VkVideoEndCodingInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoEndCodingFlagsKHR flags;
|
||||
} VkVideoEndCodingInfoKHR;
|
||||
|
||||
typedef struct VkVideoCodingControlInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoCodingControlFlagsKHR flags;
|
||||
} VkVideoCodingControlInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceVideoCapabilitiesKHR)(VkPhysicalDevice physicalDevice, const VkVideoProfileKHR* pVideoProfile, VkVideoCapabilitiesKHR* pCapabilities);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceVideoFormatPropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceVideoFormatInfoKHR* pVideoFormatInfo, uint32_t* pVideoFormatPropertyCount, VkVideoFormatPropertiesKHR* pVideoFormatProperties);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateVideoSessionKHR)(VkDevice device, const VkVideoSessionCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkVideoSessionKHR* pVideoSession);
|
||||
typedef void (VKAPI_PTR *PFN_vkDestroyVideoSessionKHR)(VkDevice device, VkVideoSessionKHR videoSession, const VkAllocationCallbacks* pAllocator);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetVideoSessionMemoryRequirementsKHR)(VkDevice device, VkVideoSessionKHR videoSession, uint32_t* pVideoSessionMemoryRequirementsCount, VkVideoGetMemoryPropertiesKHR* pVideoSessionMemoryRequirements);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkBindVideoSessionMemoryKHR)(VkDevice device, VkVideoSessionKHR videoSession, uint32_t videoSessionBindMemoryCount, const VkVideoBindMemoryKHR* pVideoSessionBindMemories);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateVideoSessionParametersKHR)(VkDevice device, const VkVideoSessionParametersCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkVideoSessionParametersKHR* pVideoSessionParameters);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkUpdateVideoSessionParametersKHR)(VkDevice device, VkVideoSessionParametersKHR videoSessionParameters, const VkVideoSessionParametersUpdateInfoKHR* pUpdateInfo);
|
||||
typedef void (VKAPI_PTR *PFN_vkDestroyVideoSessionParametersKHR)(VkDevice device, VkVideoSessionParametersKHR videoSessionParameters, const VkAllocationCallbacks* pAllocator);
|
||||
typedef void (VKAPI_PTR *PFN_vkCmdBeginVideoCodingKHR)(VkCommandBuffer commandBuffer, const VkVideoBeginCodingInfoKHR* pBeginInfo);
|
||||
typedef void (VKAPI_PTR *PFN_vkCmdEndVideoCodingKHR)(VkCommandBuffer commandBuffer, const VkVideoEndCodingInfoKHR* pEndCodingInfo);
|
||||
typedef void (VKAPI_PTR *PFN_vkCmdControlVideoCodingKHR)(VkCommandBuffer commandBuffer, const VkVideoCodingControlInfoKHR* pCodingControlInfo);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceVideoCapabilitiesKHR(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkVideoProfileKHR* pVideoProfile,
|
||||
VkVideoCapabilitiesKHR* pCapabilities);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceVideoFormatPropertiesKHR(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkPhysicalDeviceVideoFormatInfoKHR* pVideoFormatInfo,
|
||||
uint32_t* pVideoFormatPropertyCount,
|
||||
VkVideoFormatPropertiesKHR* pVideoFormatProperties);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateVideoSessionKHR(
|
||||
VkDevice device,
|
||||
const VkVideoSessionCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkVideoSessionKHR* pVideoSession);
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyVideoSessionKHR(
|
||||
VkDevice device,
|
||||
VkVideoSessionKHR videoSession,
|
||||
const VkAllocationCallbacks* pAllocator);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetVideoSessionMemoryRequirementsKHR(
|
||||
VkDevice device,
|
||||
VkVideoSessionKHR videoSession,
|
||||
uint32_t* pVideoSessionMemoryRequirementsCount,
|
||||
VkVideoGetMemoryPropertiesKHR* pVideoSessionMemoryRequirements);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkBindVideoSessionMemoryKHR(
|
||||
VkDevice device,
|
||||
VkVideoSessionKHR videoSession,
|
||||
uint32_t videoSessionBindMemoryCount,
|
||||
const VkVideoBindMemoryKHR* pVideoSessionBindMemories);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateVideoSessionParametersKHR(
|
||||
VkDevice device,
|
||||
const VkVideoSessionParametersCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkVideoSessionParametersKHR* pVideoSessionParameters);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkUpdateVideoSessionParametersKHR(
|
||||
VkDevice device,
|
||||
VkVideoSessionParametersKHR videoSessionParameters,
|
||||
const VkVideoSessionParametersUpdateInfoKHR* pUpdateInfo);
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyVideoSessionParametersKHR(
|
||||
VkDevice device,
|
||||
VkVideoSessionParametersKHR videoSessionParameters,
|
||||
const VkAllocationCallbacks* pAllocator);
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkCmdBeginVideoCodingKHR(
|
||||
VkCommandBuffer commandBuffer,
|
||||
const VkVideoBeginCodingInfoKHR* pBeginInfo);
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkCmdEndVideoCodingKHR(
|
||||
VkCommandBuffer commandBuffer,
|
||||
const VkVideoEndCodingInfoKHR* pEndCodingInfo);
|
||||
|
||||
VKAPI_ATTR void VKAPI_CALL vkCmdControlVideoCodingKHR(
|
||||
VkCommandBuffer commandBuffer,
|
||||
const VkVideoCodingControlInfoKHR* pCodingControlInfo);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_KHR_video_decode_queue 1
|
||||
#define VK_KHR_VIDEO_DECODE_QUEUE_SPEC_VERSION 1
|
||||
#define VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME "VK_KHR_video_decode_queue"
|
||||
|
||||
typedef enum VkVideoDecodeFlagBitsKHR {
|
||||
VK_VIDEO_DECODE_DEFAULT_KHR = 0,
|
||||
VK_VIDEO_DECODE_RESERVED_0_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_DECODE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoDecodeFlagBitsKHR;
|
||||
typedef VkFlags VkVideoDecodeFlagsKHR;
|
||||
typedef struct VkVideoDecodeInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoDecodeFlagsKHR flags;
|
||||
VkOffset2D codedOffset;
|
||||
VkExtent2D codedExtent;
|
||||
VkBuffer srcBuffer;
|
||||
VkDeviceSize srcBufferOffset;
|
||||
VkDeviceSize srcBufferRange;
|
||||
VkVideoPictureResourceKHR dstPictureResource;
|
||||
const VkVideoReferenceSlotKHR* pSetupReferenceSlot;
|
||||
uint32_t referenceSlotCount;
|
||||
const VkVideoReferenceSlotKHR* pReferenceSlots;
|
||||
} VkVideoDecodeInfoKHR;
|
||||
|
||||
typedef void (VKAPI_PTR *PFN_vkCmdDecodeVideoKHR)(VkCommandBuffer commandBuffer, const VkVideoDecodeInfoKHR* pFrameInfo);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR void VKAPI_CALL vkCmdDecodeVideoKHR(
|
||||
VkCommandBuffer commandBuffer,
|
||||
const VkVideoDecodeInfoKHR* pFrameInfo);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_KHR_portability_subset 1
|
||||
#define VK_KHR_PORTABILITY_SUBSET_SPEC_VERSION 1
|
||||
#define VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME "VK_KHR_portability_subset"
|
||||
typedef struct VkPhysicalDevicePortabilitySubsetFeaturesKHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkBool32 constantAlphaColorBlendFactors;
|
||||
VkBool32 events;
|
||||
VkBool32 imageViewFormatReinterpretation;
|
||||
VkBool32 imageViewFormatSwizzle;
|
||||
VkBool32 imageView2DOn3DImage;
|
||||
VkBool32 multisampleArrayImage;
|
||||
VkBool32 mutableComparisonSamplers;
|
||||
VkBool32 pointPolygons;
|
||||
VkBool32 samplerMipLodBias;
|
||||
VkBool32 separateStencilMaskRef;
|
||||
VkBool32 shaderSampleRateInterpolationFunctions;
|
||||
VkBool32 tessellationIsolines;
|
||||
VkBool32 tessellationPointMode;
|
||||
VkBool32 triangleFans;
|
||||
VkBool32 vertexAttributeAccessBeyondStride;
|
||||
} VkPhysicalDevicePortabilitySubsetFeaturesKHR;
|
||||
|
||||
typedef struct VkPhysicalDevicePortabilitySubsetPropertiesKHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint32_t minVertexInputBindingStrideAlignment;
|
||||
} VkPhysicalDevicePortabilitySubsetPropertiesKHR;
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_video_encode_queue 1
|
||||
#define VK_KHR_VIDEO_ENCODE_QUEUE_SPEC_VERSION 2
|
||||
#define VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME "VK_KHR_video_encode_queue"
|
||||
|
||||
typedef enum VkVideoEncodeFlagBitsKHR {
|
||||
VK_VIDEO_ENCODE_DEFAULT_KHR = 0,
|
||||
VK_VIDEO_ENCODE_RESERVED_0_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_ENCODE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoEncodeFlagBitsKHR;
|
||||
typedef VkFlags VkVideoEncodeFlagsKHR;
|
||||
|
||||
typedef enum VkVideoEncodeRateControlFlagBitsKHR {
|
||||
VK_VIDEO_ENCODE_RATE_CONTROL_DEFAULT_KHR = 0,
|
||||
VK_VIDEO_ENCODE_RATE_CONTROL_RESET_BIT_KHR = 0x00000001,
|
||||
VK_VIDEO_ENCODE_RATE_CONTROL_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoEncodeRateControlFlagBitsKHR;
|
||||
typedef VkFlags VkVideoEncodeRateControlFlagsKHR;
|
||||
|
||||
typedef enum VkVideoEncodeRateControlModeFlagBitsKHR {
|
||||
VK_VIDEO_ENCODE_RATE_CONTROL_MODE_NONE_BIT_KHR = 0,
|
||||
VK_VIDEO_ENCODE_RATE_CONTROL_MODE_CBR_BIT_KHR = 1,
|
||||
VK_VIDEO_ENCODE_RATE_CONTROL_MODE_VBR_BIT_KHR = 2,
|
||||
VK_VIDEO_ENCODE_RATE_CONTROL_MODE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
|
||||
} VkVideoEncodeRateControlModeFlagBitsKHR;
|
||||
typedef VkFlags VkVideoEncodeRateControlModeFlagsKHR;
|
||||
typedef struct VkVideoEncodeInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoEncodeFlagsKHR flags;
|
||||
uint32_t qualityLevel;
|
||||
VkExtent2D codedExtent;
|
||||
VkBuffer dstBitstreamBuffer;
|
||||
VkDeviceSize dstBitstreamBufferOffset;
|
||||
VkDeviceSize dstBitstreamBufferMaxRange;
|
||||
VkVideoPictureResourceKHR srcPictureResource;
|
||||
const VkVideoReferenceSlotKHR* pSetupReferenceSlot;
|
||||
uint32_t referenceSlotCount;
|
||||
const VkVideoReferenceSlotKHR* pReferenceSlots;
|
||||
} VkVideoEncodeInfoKHR;
|
||||
|
||||
typedef struct VkVideoEncodeRateControlInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoEncodeRateControlFlagsKHR flags;
|
||||
VkVideoEncodeRateControlModeFlagBitsKHR rateControlMode;
|
||||
uint32_t averageBitrate;
|
||||
uint16_t peakToAverageBitrateRatio;
|
||||
uint16_t frameRateNumerator;
|
||||
uint16_t frameRateDenominator;
|
||||
uint32_t virtualBufferSizeInMs;
|
||||
} VkVideoEncodeRateControlInfoKHR;
|
||||
|
||||
typedef void (VKAPI_PTR *PFN_vkCmdEncodeVideoKHR)(VkCommandBuffer commandBuffer, const VkVideoEncodeInfoKHR* pEncodeInfo);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR void VKAPI_CALL vkCmdEncodeVideoKHR(
|
||||
VkCommandBuffer commandBuffer,
|
||||
const VkVideoEncodeInfoKHR* pEncodeInfo);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_EXT_video_encode_h264 1
|
||||
#include "vk_video/vulkan_video_codec_h264std.h"
|
||||
#include "vk_video/vulkan_video_codec_h264std_encode.h"
|
||||
#define VK_EXT_VIDEO_ENCODE_H264_SPEC_VERSION 1
|
||||
#define VK_EXT_VIDEO_ENCODE_H264_EXTENSION_NAME "VK_EXT_video_encode_h264"
|
||||
|
||||
typedef enum VkVideoEncodeH264CapabilitiesFlagBitsEXT {
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_CABAC_BIT_EXT = 0x00000001,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_CAVLC_BIT_EXT = 0x00000002,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_WEIGHTED_BI_PRED_IMPLICIT_BIT_EXT = 0x00000004,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_TRANSFORM_8X8_BIT_EXT = 0x00000008,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_CHROMA_QP_OFFSET_BIT_EXT = 0x00000010,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_SECOND_CHROMA_QP_OFFSET_BIT_EXT = 0x00000020,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_DEBLOCKING_FILTER_DISABLED_BIT_EXT = 0x00000040,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_DEBLOCKING_FILTER_ENABLED_BIT_EXT = 0x00000080,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_DEBLOCKING_FILTER_PARTIAL_BIT_EXT = 0x00000100,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_MULTIPLE_SLICE_PER_FRAME_BIT_EXT = 0x00000200,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITY_EVENLY_DISTRIBUTED_SLICE_SIZE_BIT_EXT = 0x00000400,
|
||||
VK_VIDEO_ENCODE_H264_CAPABILITIES_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
|
||||
} VkVideoEncodeH264CapabilitiesFlagBitsEXT;
|
||||
typedef VkFlags VkVideoEncodeH264CapabilitiesFlagsEXT;
|
||||
|
||||
typedef enum VkVideoEncodeH264InputModeFlagBitsEXT {
|
||||
VK_VIDEO_ENCODE_H264_INPUT_MODE_FRAME_BIT_EXT = 0x00000001,
|
||||
VK_VIDEO_ENCODE_H264_INPUT_MODE_SLICE_BIT_EXT = 0x00000002,
|
||||
VK_VIDEO_ENCODE_H264_INPUT_MODE_NON_VCL_BIT_EXT = 0x00000004,
|
||||
VK_VIDEO_ENCODE_H264_INPUT_MODE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
|
||||
} VkVideoEncodeH264InputModeFlagBitsEXT;
|
||||
typedef VkFlags VkVideoEncodeH264InputModeFlagsEXT;
|
||||
|
||||
typedef enum VkVideoEncodeH264OutputModeFlagBitsEXT {
|
||||
VK_VIDEO_ENCODE_H264_OUTPUT_MODE_FRAME_BIT_EXT = 0x00000001,
|
||||
VK_VIDEO_ENCODE_H264_OUTPUT_MODE_SLICE_BIT_EXT = 0x00000002,
|
||||
VK_VIDEO_ENCODE_H264_OUTPUT_MODE_NON_VCL_BIT_EXT = 0x00000004,
|
||||
VK_VIDEO_ENCODE_H264_OUTPUT_MODE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
|
||||
} VkVideoEncodeH264OutputModeFlagBitsEXT;
|
||||
typedef VkFlags VkVideoEncodeH264OutputModeFlagsEXT;
|
||||
|
||||
typedef enum VkVideoEncodeH264CreateFlagBitsEXT {
|
||||
VK_VIDEO_ENCODE_H264_CREATE_DEFAULT_EXT = 0,
|
||||
VK_VIDEO_ENCODE_H264_CREATE_RESERVED_0_BIT_EXT = 0x00000001,
|
||||
VK_VIDEO_ENCODE_H264_CREATE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
|
||||
} VkVideoEncodeH264CreateFlagBitsEXT;
|
||||
typedef VkFlags VkVideoEncodeH264CreateFlagsEXT;
|
||||
typedef struct VkVideoEncodeH264CapabilitiesEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoEncodeH264CapabilitiesFlagsEXT flags;
|
||||
VkVideoEncodeH264InputModeFlagsEXT inputModeFlags;
|
||||
VkVideoEncodeH264OutputModeFlagsEXT outputModeFlags;
|
||||
VkExtent2D minPictureSizeInMbs;
|
||||
VkExtent2D maxPictureSizeInMbs;
|
||||
VkExtent2D inputImageDataAlignment;
|
||||
uint8_t maxNumL0ReferenceForP;
|
||||
uint8_t maxNumL0ReferenceForB;
|
||||
uint8_t maxNumL1Reference;
|
||||
uint8_t qualityLevelCount;
|
||||
VkExtensionProperties stdExtensionVersion;
|
||||
} VkVideoEncodeH264CapabilitiesEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264SessionCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoEncodeH264CreateFlagsEXT flags;
|
||||
VkExtent2D maxPictureSizeInMbs;
|
||||
const VkExtensionProperties* pStdExtensionVersion;
|
||||
} VkVideoEncodeH264SessionCreateInfoEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264SessionParametersAddInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t spsStdCount;
|
||||
const StdVideoH264SequenceParameterSet* pSpsStd;
|
||||
uint32_t ppsStdCount;
|
||||
const StdVideoH264PictureParameterSet* pPpsStd;
|
||||
} VkVideoEncodeH264SessionParametersAddInfoEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264SessionParametersCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t maxSpsStdCount;
|
||||
uint32_t maxPpsStdCount;
|
||||
const VkVideoEncodeH264SessionParametersAddInfoEXT* pParametersAddInfo;
|
||||
} VkVideoEncodeH264SessionParametersCreateInfoEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264DpbSlotInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
int8_t slotIndex;
|
||||
const StdVideoEncodeH264PictureInfo* pStdPictureInfo;
|
||||
} VkVideoEncodeH264DpbSlotInfoEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264NaluSliceEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const StdVideoEncodeH264SliceHeader* pSliceHeaderStd;
|
||||
uint32_t mbCount;
|
||||
uint8_t refFinalList0EntryCount;
|
||||
const VkVideoEncodeH264DpbSlotInfoEXT* pRefFinalList0Entries;
|
||||
uint8_t refFinalList1EntryCount;
|
||||
const VkVideoEncodeH264DpbSlotInfoEXT* pRefFinalList1Entries;
|
||||
uint32_t precedingNaluBytes;
|
||||
uint8_t minQp;
|
||||
uint8_t maxQp;
|
||||
} VkVideoEncodeH264NaluSliceEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264VclFrameInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint8_t refDefaultFinalList0EntryCount;
|
||||
const VkVideoEncodeH264DpbSlotInfoEXT* pRefDefaultFinalList0Entries;
|
||||
uint8_t refDefaultFinalList1EntryCount;
|
||||
const VkVideoEncodeH264DpbSlotInfoEXT* pRefDefaultFinalList1Entries;
|
||||
uint32_t naluSliceEntryCount;
|
||||
const VkVideoEncodeH264NaluSliceEXT* pNaluSliceEntries;
|
||||
const VkVideoEncodeH264DpbSlotInfoEXT* pCurrentPictureInfo;
|
||||
} VkVideoEncodeH264VclFrameInfoEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264EmitPictureParametersEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint8_t spsId;
|
||||
VkBool32 emitSpsEnable;
|
||||
uint32_t ppsIdEntryCount;
|
||||
const uint8_t* ppsIdEntries;
|
||||
} VkVideoEncodeH264EmitPictureParametersEXT;
|
||||
|
||||
typedef struct VkVideoEncodeH264ProfileEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
StdVideoH264ProfileIdc stdProfileIdc;
|
||||
} VkVideoEncodeH264ProfileEXT;
|
||||
|
||||
|
||||
|
||||
#define VK_EXT_video_decode_h264 1
|
||||
#include "vk_video/vulkan_video_codec_h264std_decode.h"
|
||||
#define VK_EXT_VIDEO_DECODE_H264_SPEC_VERSION 1
|
||||
#define VK_EXT_VIDEO_DECODE_H264_EXTENSION_NAME "VK_EXT_video_decode_h264"
|
||||
|
||||
typedef enum VkVideoDecodeH264FieldLayoutFlagBitsEXT {
|
||||
VK_VIDEO_DECODE_H264_PROGRESSIVE_PICTURES_ONLY_EXT = 0,
|
||||
VK_VIDEO_DECODE_H264_FIELD_LAYOUT_LINE_INTERLACED_PLANE_BIT_EXT = 0x00000001,
|
||||
VK_VIDEO_DECODE_H264_FIELD_LAYOUT_SEPARATE_INTERLACED_PLANE_BIT_EXT = 0x00000002,
|
||||
VK_VIDEO_DECODE_H264_FIELD_LAYOUT_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
|
||||
} VkVideoDecodeH264FieldLayoutFlagBitsEXT;
|
||||
typedef VkFlags VkVideoDecodeH264FieldLayoutFlagsEXT;
|
||||
typedef VkFlags VkVideoDecodeH264CreateFlagsEXT;
|
||||
typedef struct VkVideoDecodeH264ProfileEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
StdVideoH264ProfileIdc stdProfileIdc;
|
||||
VkVideoDecodeH264FieldLayoutFlagsEXT fieldLayout;
|
||||
} VkVideoDecodeH264ProfileEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH264CapabilitiesEXT {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint32_t maxLevel;
|
||||
VkOffset2D fieldOffsetGranularity;
|
||||
VkExtensionProperties stdExtensionVersion;
|
||||
} VkVideoDecodeH264CapabilitiesEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH264SessionCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoDecodeH264CreateFlagsEXT flags;
|
||||
const VkExtensionProperties* pStdExtensionVersion;
|
||||
} VkVideoDecodeH264SessionCreateInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH264SessionParametersAddInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t spsStdCount;
|
||||
const StdVideoH264SequenceParameterSet* pSpsStd;
|
||||
uint32_t ppsStdCount;
|
||||
const StdVideoH264PictureParameterSet* pPpsStd;
|
||||
} VkVideoDecodeH264SessionParametersAddInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH264SessionParametersCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t maxSpsStdCount;
|
||||
uint32_t maxPpsStdCount;
|
||||
const VkVideoDecodeH264SessionParametersAddInfoEXT* pParametersAddInfo;
|
||||
} VkVideoDecodeH264SessionParametersCreateInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH264PictureInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const StdVideoDecodeH264PictureInfo* pStdPictureInfo;
|
||||
uint32_t slicesCount;
|
||||
const uint32_t* pSlicesDataOffsets;
|
||||
} VkVideoDecodeH264PictureInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH264MvcEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const StdVideoDecodeH264Mvc* pStdMvc;
|
||||
} VkVideoDecodeH264MvcEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH264DpbSlotInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const StdVideoDecodeH264ReferenceInfo* pStdReferenceInfo;
|
||||
} VkVideoDecodeH264DpbSlotInfoEXT;
|
||||
|
||||
|
||||
|
||||
#define VK_EXT_video_decode_h265 1
|
||||
#include "vk_video/vulkan_video_codec_h265std.h"
|
||||
#include "vk_video/vulkan_video_codec_h265std_decode.h"
|
||||
#define VK_EXT_VIDEO_DECODE_H265_SPEC_VERSION 1
|
||||
#define VK_EXT_VIDEO_DECODE_H265_EXTENSION_NAME "VK_EXT_video_decode_h265"
|
||||
typedef VkFlags VkVideoDecodeH265CreateFlagsEXT;
|
||||
typedef struct VkVideoDecodeH265ProfileEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
StdVideoH265ProfileIdc stdProfileIdc;
|
||||
} VkVideoDecodeH265ProfileEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH265CapabilitiesEXT {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint32_t maxLevel;
|
||||
VkExtensionProperties stdExtensionVersion;
|
||||
} VkVideoDecodeH265CapabilitiesEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH265SessionCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkVideoDecodeH265CreateFlagsEXT flags;
|
||||
const VkExtensionProperties* pStdExtensionVersion;
|
||||
} VkVideoDecodeH265SessionCreateInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH265SessionParametersAddInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t spsStdCount;
|
||||
const StdVideoH265SequenceParameterSet* pSpsStd;
|
||||
uint32_t ppsStdCount;
|
||||
const StdVideoH265PictureParameterSet* pPpsStd;
|
||||
} VkVideoDecodeH265SessionParametersAddInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH265SessionParametersCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t maxSpsStdCount;
|
||||
uint32_t maxPpsStdCount;
|
||||
const VkVideoDecodeH265SessionParametersAddInfoEXT* pParametersAddInfo;
|
||||
} VkVideoDecodeH265SessionParametersCreateInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH265PictureInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
StdVideoDecodeH265PictureInfo* pStdPictureInfo;
|
||||
uint32_t slicesCount;
|
||||
const uint32_t* pSlicesDataOffsets;
|
||||
} VkVideoDecodeH265PictureInfoEXT;
|
||||
|
||||
typedef struct VkVideoDecodeH265DpbSlotInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const StdVideoDecodeH265ReferenceInfo* pStdReferenceInfo;
|
||||
} VkVideoDecodeH265DpbSlotInfoEXT;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+12620
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
#ifndef VULKAN_DIRECTFB_H_
|
||||
#define VULKAN_DIRECTFB_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_EXT_directfb_surface 1
|
||||
#define VK_EXT_DIRECTFB_SURFACE_SPEC_VERSION 1
|
||||
#define VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME "VK_EXT_directfb_surface"
|
||||
typedef VkFlags VkDirectFBSurfaceCreateFlagsEXT;
|
||||
typedef struct VkDirectFBSurfaceCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkDirectFBSurfaceCreateFlagsEXT flags;
|
||||
IDirectFB* dfb;
|
||||
IDirectFBSurface* surface;
|
||||
} VkDirectFBSurfaceCreateInfoEXT;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateDirectFBSurfaceEXT)(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceDirectFBPresentationSupportEXT)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, IDirectFB* dfb);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT(
|
||||
VkInstance instance,
|
||||
const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceDirectFBPresentationSupportEXT(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
IDirectFB* dfb);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,121 @@
|
||||
#ifndef VULKAN_FUCHSIA_H_
|
||||
#define VULKAN_FUCHSIA_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_FUCHSIA_imagepipe_surface 1
|
||||
#define VK_FUCHSIA_IMAGEPIPE_SURFACE_SPEC_VERSION 1
|
||||
#define VK_FUCHSIA_IMAGEPIPE_SURFACE_EXTENSION_NAME "VK_FUCHSIA_imagepipe_surface"
|
||||
typedef VkFlags VkImagePipeSurfaceCreateFlagsFUCHSIA;
|
||||
typedef struct VkImagePipeSurfaceCreateInfoFUCHSIA {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkImagePipeSurfaceCreateFlagsFUCHSIA flags;
|
||||
zx_handle_t imagePipeHandle;
|
||||
} VkImagePipeSurfaceCreateInfoFUCHSIA;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateImagePipeSurfaceFUCHSIA)(VkInstance instance, const VkImagePipeSurfaceCreateInfoFUCHSIA* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateImagePipeSurfaceFUCHSIA(
|
||||
VkInstance instance,
|
||||
const VkImagePipeSurfaceCreateInfoFUCHSIA* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_FUCHSIA_external_memory 1
|
||||
#define VK_FUCHSIA_EXTERNAL_MEMORY_SPEC_VERSION 1
|
||||
#define VK_FUCHSIA_EXTERNAL_MEMORY_EXTENSION_NAME "VK_FUCHSIA_external_memory"
|
||||
typedef struct VkImportMemoryZirconHandleInfoFUCHSIA {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkExternalMemoryHandleTypeFlagBits handleType;
|
||||
zx_handle_t handle;
|
||||
} VkImportMemoryZirconHandleInfoFUCHSIA;
|
||||
|
||||
typedef struct VkMemoryZirconHandlePropertiesFUCHSIA {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint32_t memoryTypeBits;
|
||||
} VkMemoryZirconHandlePropertiesFUCHSIA;
|
||||
|
||||
typedef struct VkMemoryGetZirconHandleInfoFUCHSIA {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkDeviceMemory memory;
|
||||
VkExternalMemoryHandleTypeFlagBits handleType;
|
||||
} VkMemoryGetZirconHandleInfoFUCHSIA;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryZirconHandleFUCHSIA)(VkDevice device, const VkMemoryGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo, zx_handle_t* pZirconHandle);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryZirconHandlePropertiesFUCHSIA)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, zx_handle_t zirconHandle, VkMemoryZirconHandlePropertiesFUCHSIA* pMemoryZirconHandleProperties);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryZirconHandleFUCHSIA(
|
||||
VkDevice device,
|
||||
const VkMemoryGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo,
|
||||
zx_handle_t* pZirconHandle);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryZirconHandlePropertiesFUCHSIA(
|
||||
VkDevice device,
|
||||
VkExternalMemoryHandleTypeFlagBits handleType,
|
||||
zx_handle_t zirconHandle,
|
||||
VkMemoryZirconHandlePropertiesFUCHSIA* pMemoryZirconHandleProperties);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_FUCHSIA_external_semaphore 1
|
||||
#define VK_FUCHSIA_EXTERNAL_SEMAPHORE_SPEC_VERSION 1
|
||||
#define VK_FUCHSIA_EXTERNAL_SEMAPHORE_EXTENSION_NAME "VK_FUCHSIA_external_semaphore"
|
||||
typedef struct VkImportSemaphoreZirconHandleInfoFUCHSIA {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkSemaphore semaphore;
|
||||
VkSemaphoreImportFlags flags;
|
||||
VkExternalSemaphoreHandleTypeFlagBits handleType;
|
||||
zx_handle_t zirconHandle;
|
||||
} VkImportSemaphoreZirconHandleInfoFUCHSIA;
|
||||
|
||||
typedef struct VkSemaphoreGetZirconHandleInfoFUCHSIA {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkSemaphore semaphore;
|
||||
VkExternalSemaphoreHandleTypeFlagBits handleType;
|
||||
} VkSemaphoreGetZirconHandleInfoFUCHSIA;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreZirconHandleFUCHSIA)(VkDevice device, const VkImportSemaphoreZirconHandleInfoFUCHSIA* pImportSemaphoreZirconHandleInfo);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreZirconHandleFUCHSIA)(VkDevice device, const VkSemaphoreGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo, zx_handle_t* pZirconHandle);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreZirconHandleFUCHSIA(
|
||||
VkDevice device,
|
||||
const VkImportSemaphoreZirconHandleInfoFUCHSIA* pImportSemaphoreZirconHandleInfo);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreZirconHandleFUCHSIA(
|
||||
VkDevice device,
|
||||
const VkSemaphoreGetZirconHandleInfoFUCHSIA* pGetZirconHandleInfo,
|
||||
zx_handle_t* pZirconHandle);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef VULKAN_GGP_H_
|
||||
#define VULKAN_GGP_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_GGP_stream_descriptor_surface 1
|
||||
#define VK_GGP_STREAM_DESCRIPTOR_SURFACE_SPEC_VERSION 1
|
||||
#define VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME "VK_GGP_stream_descriptor_surface"
|
||||
typedef VkFlags VkStreamDescriptorSurfaceCreateFlagsGGP;
|
||||
typedef struct VkStreamDescriptorSurfaceCreateInfoGGP {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkStreamDescriptorSurfaceCreateFlagsGGP flags;
|
||||
GgpStreamDescriptor streamDescriptor;
|
||||
} VkStreamDescriptorSurfaceCreateInfoGGP;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateStreamDescriptorSurfaceGGP)(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP(
|
||||
VkInstance instance,
|
||||
const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_GGP_frame_token 1
|
||||
#define VK_GGP_FRAME_TOKEN_SPEC_VERSION 1
|
||||
#define VK_GGP_FRAME_TOKEN_EXTENSION_NAME "VK_GGP_frame_token"
|
||||
typedef struct VkPresentFrameTokenGGP {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
GgpFrameToken frameToken;
|
||||
} VkPresentFrameTokenGGP;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef VULKAN_IOS_H_
|
||||
#define VULKAN_IOS_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_MVK_ios_surface 1
|
||||
#define VK_MVK_IOS_SURFACE_SPEC_VERSION 3
|
||||
#define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface"
|
||||
typedef VkFlags VkIOSSurfaceCreateFlagsMVK;
|
||||
typedef struct VkIOSSurfaceCreateInfoMVK {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkIOSSurfaceCreateFlagsMVK flags;
|
||||
const void* pView;
|
||||
} VkIOSSurfaceCreateInfoMVK;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(
|
||||
VkInstance instance,
|
||||
const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef VULKAN_MACOS_H_
|
||||
#define VULKAN_MACOS_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_MVK_macos_surface 1
|
||||
#define VK_MVK_MACOS_SURFACE_SPEC_VERSION 3
|
||||
#define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface"
|
||||
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
|
||||
typedef struct VkMacOSSurfaceCreateInfoMVK {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkMacOSSurfaceCreateFlagsMVK flags;
|
||||
const void* pView;
|
||||
} VkMacOSSurfaceCreateInfoMVK;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(
|
||||
VkInstance instance,
|
||||
const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef VULKAN_METAL_H_
|
||||
#define VULKAN_METAL_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_EXT_metal_surface 1
|
||||
|
||||
#ifdef __OBJC__
|
||||
@class CAMetalLayer;
|
||||
#else
|
||||
typedef void CAMetalLayer;
|
||||
#endif
|
||||
|
||||
#define VK_EXT_METAL_SURFACE_SPEC_VERSION 1
|
||||
#define VK_EXT_METAL_SURFACE_EXTENSION_NAME "VK_EXT_metal_surface"
|
||||
typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
|
||||
typedef struct VkMetalSurfaceCreateInfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkMetalSurfaceCreateFlagsEXT flags;
|
||||
const CAMetalLayer* pLayer;
|
||||
} VkMetalSurfaceCreateInfoEXT;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateMetalSurfaceEXT)(VkInstance instance, const VkMetalSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT(
|
||||
VkInstance instance,
|
||||
const VkMetalSurfaceCreateInfoEXT* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef VULKAN_SCREEN_H_
|
||||
#define VULKAN_SCREEN_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_QNX_screen_surface 1
|
||||
#define VK_QNX_SCREEN_SURFACE_SPEC_VERSION 1
|
||||
#define VK_QNX_SCREEN_SURFACE_EXTENSION_NAME "VK_QNX_screen_surface"
|
||||
typedef VkFlags VkScreenSurfaceCreateFlagsQNX;
|
||||
typedef struct VkScreenSurfaceCreateInfoQNX {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkScreenSurfaceCreateFlagsQNX flags;
|
||||
struct _screen_context* context;
|
||||
struct _screen_window* window;
|
||||
} VkScreenSurfaceCreateInfoQNX;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateScreenSurfaceQNX)(VkInstance instance, const VkScreenSurfaceCreateInfoQNX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceScreenPresentationSupportQNX)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct _screen_window* window);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateScreenSurfaceQNX(
|
||||
VkInstance instance,
|
||||
const VkScreenSurfaceCreateInfoQNX* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceScreenPresentationSupportQNX(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
struct _screen_window* window);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef VULKAN_VI_H_
|
||||
#define VULKAN_VI_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_NN_vi_surface 1
|
||||
#define VK_NN_VI_SURFACE_SPEC_VERSION 1
|
||||
#define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface"
|
||||
typedef VkFlags VkViSurfaceCreateFlagsNN;
|
||||
typedef struct VkViSurfaceCreateInfoNN {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkViSurfaceCreateFlagsNN flags;
|
||||
void* window;
|
||||
} VkViSurfaceCreateInfoNN;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN(
|
||||
VkInstance instance,
|
||||
const VkViSurfaceCreateInfoNN* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef VULKAN_WAYLAND_H_
|
||||
#define VULKAN_WAYLAND_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_wayland_surface 1
|
||||
#define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6
|
||||
#define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface"
|
||||
typedef VkFlags VkWaylandSurfaceCreateFlagsKHR;
|
||||
typedef struct VkWaylandSurfaceCreateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkWaylandSurfaceCreateFlagsKHR flags;
|
||||
struct wl_display* display;
|
||||
struct wl_surface* surface;
|
||||
} VkWaylandSurfaceCreateInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
|
||||
VkInstance instance,
|
||||
const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
struct wl_display* display);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,315 @@
|
||||
#ifndef VULKAN_WIN32_H_
|
||||
#define VULKAN_WIN32_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_win32_surface 1
|
||||
#define VK_KHR_WIN32_SURFACE_SPEC_VERSION 6
|
||||
#define VK_KHR_WIN32_SURFACE_EXTENSION_NAME "VK_KHR_win32_surface"
|
||||
typedef VkFlags VkWin32SurfaceCreateFlagsKHR;
|
||||
typedef struct VkWin32SurfaceCreateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkWin32SurfaceCreateFlagsKHR flags;
|
||||
HINSTANCE hinstance;
|
||||
HWND hwnd;
|
||||
} VkWin32SurfaceCreateInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateWin32SurfaceKHR)(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
|
||||
VkInstance instance,
|
||||
const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_KHR_external_memory_win32 1
|
||||
#define VK_KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1
|
||||
#define VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_KHR_external_memory_win32"
|
||||
typedef struct VkImportMemoryWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkExternalMemoryHandleTypeFlagBits handleType;
|
||||
HANDLE handle;
|
||||
LPCWSTR name;
|
||||
} VkImportMemoryWin32HandleInfoKHR;
|
||||
|
||||
typedef struct VkExportMemoryWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const SECURITY_ATTRIBUTES* pAttributes;
|
||||
DWORD dwAccess;
|
||||
LPCWSTR name;
|
||||
} VkExportMemoryWin32HandleInfoKHR;
|
||||
|
||||
typedef struct VkMemoryWin32HandlePropertiesKHR {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
uint32_t memoryTypeBits;
|
||||
} VkMemoryWin32HandlePropertiesKHR;
|
||||
|
||||
typedef struct VkMemoryGetWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkDeviceMemory memory;
|
||||
VkExternalMemoryHandleTypeFlagBits handleType;
|
||||
} VkMemoryGetWin32HandleInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleKHR)(VkDevice device, const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandlePropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, HANDLE handle, VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleKHR(
|
||||
VkDevice device,
|
||||
const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo,
|
||||
HANDLE* pHandle);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandlePropertiesKHR(
|
||||
VkDevice device,
|
||||
VkExternalMemoryHandleTypeFlagBits handleType,
|
||||
HANDLE handle,
|
||||
VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_KHR_win32_keyed_mutex 1
|
||||
#define VK_KHR_WIN32_KEYED_MUTEX_SPEC_VERSION 1
|
||||
#define VK_KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_KHR_win32_keyed_mutex"
|
||||
typedef struct VkWin32KeyedMutexAcquireReleaseInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t acquireCount;
|
||||
const VkDeviceMemory* pAcquireSyncs;
|
||||
const uint64_t* pAcquireKeys;
|
||||
const uint32_t* pAcquireTimeouts;
|
||||
uint32_t releaseCount;
|
||||
const VkDeviceMemory* pReleaseSyncs;
|
||||
const uint64_t* pReleaseKeys;
|
||||
} VkWin32KeyedMutexAcquireReleaseInfoKHR;
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_external_semaphore_win32 1
|
||||
#define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_SPEC_VERSION 1
|
||||
#define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME "VK_KHR_external_semaphore_win32"
|
||||
typedef struct VkImportSemaphoreWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkSemaphore semaphore;
|
||||
VkSemaphoreImportFlags flags;
|
||||
VkExternalSemaphoreHandleTypeFlagBits handleType;
|
||||
HANDLE handle;
|
||||
LPCWSTR name;
|
||||
} VkImportSemaphoreWin32HandleInfoKHR;
|
||||
|
||||
typedef struct VkExportSemaphoreWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const SECURITY_ATTRIBUTES* pAttributes;
|
||||
DWORD dwAccess;
|
||||
LPCWSTR name;
|
||||
} VkExportSemaphoreWin32HandleInfoKHR;
|
||||
|
||||
typedef struct VkD3D12FenceSubmitInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t waitSemaphoreValuesCount;
|
||||
const uint64_t* pWaitSemaphoreValues;
|
||||
uint32_t signalSemaphoreValuesCount;
|
||||
const uint64_t* pSignalSemaphoreValues;
|
||||
} VkD3D12FenceSubmitInfoKHR;
|
||||
|
||||
typedef struct VkSemaphoreGetWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkSemaphore semaphore;
|
||||
VkExternalSemaphoreHandleTypeFlagBits handleType;
|
||||
} VkSemaphoreGetWin32HandleInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreWin32HandleKHR)(VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreWin32HandleKHR)(VkDevice device, const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreWin32HandleKHR(
|
||||
VkDevice device,
|
||||
const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreWin32HandleKHR(
|
||||
VkDevice device,
|
||||
const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo,
|
||||
HANDLE* pHandle);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_KHR_external_fence_win32 1
|
||||
#define VK_KHR_EXTERNAL_FENCE_WIN32_SPEC_VERSION 1
|
||||
#define VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME "VK_KHR_external_fence_win32"
|
||||
typedef struct VkImportFenceWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkFence fence;
|
||||
VkFenceImportFlags flags;
|
||||
VkExternalFenceHandleTypeFlagBits handleType;
|
||||
HANDLE handle;
|
||||
LPCWSTR name;
|
||||
} VkImportFenceWin32HandleInfoKHR;
|
||||
|
||||
typedef struct VkExportFenceWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const SECURITY_ATTRIBUTES* pAttributes;
|
||||
DWORD dwAccess;
|
||||
LPCWSTR name;
|
||||
} VkExportFenceWin32HandleInfoKHR;
|
||||
|
||||
typedef struct VkFenceGetWin32HandleInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkFence fence;
|
||||
VkExternalFenceHandleTypeFlagBits handleType;
|
||||
} VkFenceGetWin32HandleInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkImportFenceWin32HandleKHR)(VkDevice device, const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetFenceWin32HandleKHR)(VkDevice device, const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceWin32HandleKHR(
|
||||
VkDevice device,
|
||||
const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceWin32HandleKHR(
|
||||
VkDevice device,
|
||||
const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo,
|
||||
HANDLE* pHandle);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_NV_external_memory_win32 1
|
||||
#define VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1
|
||||
#define VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_NV_external_memory_win32"
|
||||
typedef struct VkImportMemoryWin32HandleInfoNV {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkExternalMemoryHandleTypeFlagsNV handleType;
|
||||
HANDLE handle;
|
||||
} VkImportMemoryWin32HandleInfoNV;
|
||||
|
||||
typedef struct VkExportMemoryWin32HandleInfoNV {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
const SECURITY_ATTRIBUTES* pAttributes;
|
||||
DWORD dwAccess;
|
||||
} VkExportMemoryWin32HandleInfoNV;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleNV)(VkDevice device, VkDeviceMemory memory, VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE* pHandle);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV(
|
||||
VkDevice device,
|
||||
VkDeviceMemory memory,
|
||||
VkExternalMemoryHandleTypeFlagsNV handleType,
|
||||
HANDLE* pHandle);
|
||||
#endif
|
||||
|
||||
|
||||
#define VK_NV_win32_keyed_mutex 1
|
||||
#define VK_NV_WIN32_KEYED_MUTEX_SPEC_VERSION 2
|
||||
#define VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_NV_win32_keyed_mutex"
|
||||
typedef struct VkWin32KeyedMutexAcquireReleaseInfoNV {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
uint32_t acquireCount;
|
||||
const VkDeviceMemory* pAcquireSyncs;
|
||||
const uint64_t* pAcquireKeys;
|
||||
const uint32_t* pAcquireTimeoutMilliseconds;
|
||||
uint32_t releaseCount;
|
||||
const VkDeviceMemory* pReleaseSyncs;
|
||||
const uint64_t* pReleaseKeys;
|
||||
} VkWin32KeyedMutexAcquireReleaseInfoNV;
|
||||
|
||||
|
||||
|
||||
#define VK_EXT_full_screen_exclusive 1
|
||||
#define VK_EXT_FULL_SCREEN_EXCLUSIVE_SPEC_VERSION 4
|
||||
#define VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME "VK_EXT_full_screen_exclusive"
|
||||
|
||||
typedef enum VkFullScreenExclusiveEXT {
|
||||
VK_FULL_SCREEN_EXCLUSIVE_DEFAULT_EXT = 0,
|
||||
VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT = 1,
|
||||
VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT = 2,
|
||||
VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT = 3,
|
||||
VK_FULL_SCREEN_EXCLUSIVE_MAX_ENUM_EXT = 0x7FFFFFFF
|
||||
} VkFullScreenExclusiveEXT;
|
||||
typedef struct VkSurfaceFullScreenExclusiveInfoEXT {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkFullScreenExclusiveEXT fullScreenExclusive;
|
||||
} VkSurfaceFullScreenExclusiveInfoEXT;
|
||||
|
||||
typedef struct VkSurfaceCapabilitiesFullScreenExclusiveEXT {
|
||||
VkStructureType sType;
|
||||
void* pNext;
|
||||
VkBool32 fullScreenExclusiveSupported;
|
||||
} VkSurfaceCapabilitiesFullScreenExclusiveEXT;
|
||||
|
||||
typedef struct VkSurfaceFullScreenExclusiveWin32InfoEXT {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
HMONITOR hmonitor;
|
||||
} VkSurfaceFullScreenExclusiveWin32InfoEXT;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfacePresentModes2EXT)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkAcquireFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkReleaseFullScreenExclusiveModeEXT)(VkDevice device, VkSwapchainKHR swapchain);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupSurfacePresentModes2EXT)(VkDevice device, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkDeviceGroupPresentModeFlagsKHR* pModes);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModes2EXT(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
|
||||
uint32_t* pPresentModeCount,
|
||||
VkPresentModeKHR* pPresentModes);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkAcquireFullScreenExclusiveModeEXT(
|
||||
VkDevice device,
|
||||
VkSwapchainKHR swapchain);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkReleaseFullScreenExclusiveModeEXT(
|
||||
VkDevice device,
|
||||
VkSwapchainKHR swapchain);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModes2EXT(
|
||||
VkDevice device,
|
||||
const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
|
||||
VkDeviceGroupPresentModeFlagsKHR* pModes);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef VULKAN_XCB_H_
|
||||
#define VULKAN_XCB_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_xcb_surface 1
|
||||
#define VK_KHR_XCB_SURFACE_SPEC_VERSION 6
|
||||
#define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface"
|
||||
typedef VkFlags VkXcbSurfaceCreateFlagsKHR;
|
||||
typedef struct VkXcbSurfaceCreateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkXcbSurfaceCreateFlagsKHR flags;
|
||||
xcb_connection_t* connection;
|
||||
xcb_window_t window;
|
||||
} VkXcbSurfaceCreateInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
|
||||
VkInstance instance,
|
||||
const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
xcb_connection_t* connection,
|
||||
xcb_visualid_t visual_id);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef VULKAN_XLIB_H_
|
||||
#define VULKAN_XLIB_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_KHR_xlib_surface 1
|
||||
#define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6
|
||||
#define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface"
|
||||
typedef VkFlags VkXlibSurfaceCreateFlagsKHR;
|
||||
typedef struct VkXlibSurfaceCreateInfoKHR {
|
||||
VkStructureType sType;
|
||||
const void* pNext;
|
||||
VkXlibSurfaceCreateFlagsKHR flags;
|
||||
Display* dpy;
|
||||
Window window;
|
||||
} VkXlibSurfaceCreateInfoKHR;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
|
||||
typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
|
||||
VkInstance instance,
|
||||
const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkSurfaceKHR* pSurface);
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
uint32_t queueFamilyIndex,
|
||||
Display* dpy,
|
||||
VisualID visualID);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef VULKAN_XLIB_XRANDR_H_
|
||||
#define VULKAN_XLIB_XRANDR_H_ 1
|
||||
|
||||
/*
|
||||
** Copyright 2015-2021 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
** This header is generated from the Khronos Vulkan XML API Registry.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define VK_EXT_acquire_xlib_display 1
|
||||
#define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1
|
||||
#define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display"
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay);
|
||||
|
||||
#ifndef VK_NO_PROTOTYPES
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
Display* dpy,
|
||||
VkDisplayKHR display);
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT(
|
||||
VkPhysicalDevice physicalDevice,
|
||||
Display* dpy,
|
||||
RROutput rrOutput,
|
||||
VkDisplayKHR* pDisplay);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user