diff --git a/3rdparty/d3d4linux/Makefile b/3rdparty/d3d4linux/Makefile new file mode 100644 index 000000000..94033b4db --- /dev/null +++ b/3rdparty/d3d4linux/Makefile @@ -0,0 +1,24 @@ +BINARIES = ../../tools/bin/windows/d3d4linux.exe + +INCLUDE = include/d3d4linux.h \ + include/d3d4linux_common.h \ + include/d3d4linux_enums.h \ + include/d3d4linux_impl.h \ + include/d3d4linux_types.h + +CXXFLAGS += -O2 -Wall -I./include -std=c++11 + +ifeq ($(OS), Windows_NT) +CXX := x86_64-w64-mingw32-c++ +LDFLAGS = -s -static-libgcc -static-libstdc++ -ldxguid -static -ld3dcompiler -static -lpthread +else +LDFLAGS = -g +endif + +all: $(BINARIES) + +../../tools/bin/windows/d3d4linux.exe: d3d4linux.cpp $(INCLUDE) Makefile + x86_64-w64-mingw32-c++ $(CXXFLAGS) $(filter %.cpp, $^) -static -o $@ -ldxguid + +clean: + rm -f $(BINARIES) diff --git a/3rdparty/d3d4linux/d3d4linux.cpp b/3rdparty/d3d4linux/d3d4linux.cpp new file mode 100644 index 000000000..ce67a5479 --- /dev/null +++ b/3rdparty/d3d4linux/d3d4linux.cpp @@ -0,0 +1,304 @@ +// +// D3D4Linux — access Direct3D DLLs from Linux programs +// +// Copyright © 2016 Sam Hocevar +// +// This library is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#include +#include + +#include +#include +#include + +#include + +#include + +/* Allow multiple definitions of this GUID depending on whether we are using + * d3dcompiler_43.dll or d3dcompiler_47.dll. Microsoft states that the GUID + * value will change each time the API changes. */ +#define D3D4LINUX_GUID(x, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k) \ +struct x { uint32_t a; uint16_t b, c; uint8_t d, e, f, g, h, i, j, k; } \ + x = { _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k }; + +D3D4LINUX_GUID(IID_ID3D11ShaderReflection_43, + 0x0a233719, 0x3960, 0x4578, 0x9d, 0x7c, 0x20, 0x3b, 0x8b, 0x1d, 0x9c, 0xc1); +D3D4LINUX_GUID(IID_ID3D11ShaderReflection_47, + 0x8d536ca1, 0x0cca, 0x4956, 0xa8, 0x37, 0x78, 0x69, 0x63, 0x75, 0x55, 0x84); + +int main(void) +{ + char const *verbose_var = getenv("D3D4LINUX_VERBOSE"); + int verbose = verbose_var && *verbose_var == '1'; + + char const *dll_var = getenv("D3D4LINUX_DLL"); + dll_var = dll_var ? dll_var : "d3dcompiler_47.dll"; + + HMODULE lib = LoadLibrary(dll_var); + + /* Ensure stdout is in binary mode */ + setmode(fileno(stdout), O_BINARY); + setmode(fileno(stdin), O_BINARY); + + interop p(stdin, stdout); + + while (!feof(stdin)) + { + int syscall = p.read_i64(); + int marker = 0; + + if (syscall == D3D4LINUX_OP_COMPILE) + { + HRESULT (*compile)(void const *pSrcData, size_t SrcDataSize, + char const *pFileName, + D3D_SHADER_MACRO const *pDefines, + ID3DInclude *pInclude, + char const *pEntrypoint, char const *pTarget, + uint32_t Flags1, uint32_t Flags2, + ID3DBlob **ppCode, ID3DBlob **ppErrorMsgs); + compile = (decltype(compile))GetProcAddress(lib, "D3DCompile"); + + /* This is a D3DCompile() call */ + std::string shader_source = p.read_string(); + + int has_filename = (int)p.read_i64(); + std::string shader_file; + if (has_filename) + shader_file = p.read_string(); + + std::string shader_main = p.read_string(); + std::string shader_type = p.read_string(); + uint32_t flags1 = (uint32_t)p.read_i64(); + uint32_t flags2 = (uint32_t)p.read_i64(); + marker = (int)p.read_i64(); + if (marker != D3D4LINUX_FINISHED) + goto error; + + ID3DBlob *shader_blob = nullptr, *error_blob = nullptr; + HRESULT ret = compile(shader_source.c_str(), shader_source.size(), + shader_file.c_str(), + nullptr, /* unimplemented */ + nullptr, /* unimplemented */ + shader_main.c_str(), + shader_type.c_str(), + flags1, flags2, &shader_blob, &error_blob); + if (verbose) + fprintf(stderr, "[D3D4LINUX] D3DCompile([%d bytes], \"%s\", ?, ?, \"%s\", \"%s\", %04x, %04x ) = 0x%x\n", + (int)shader_source.size(), has_filename ? shader_file.c_str() : "(nullptr)", shader_main.c_str(), shader_type.c_str(), + flags1, flags2, (int)ret); + + p.write_i64(ret); + p.write_blob(shader_blob); + p.write_blob(error_blob); + p.write_i64(D3D4LINUX_FINISHED); + + if (shader_blob) + shader_blob->Release(); + if (error_blob) + error_blob->Release(); + } + else if (syscall == D3D4LINUX_OP_REFLECT) + { + HRESULT (*reflect)(void const *pSrcData, + size_t SrcDataSize, + REFIID pInterface, + void **ppReflector); + reflect = (decltype(reflect))GetProcAddress(lib, "D3DReflect"); + + std::vector *data = p.read_data(); + int iid_code = p.read_i64(); + marker = (int)p.read_i64(); + if (marker != D3D4LINUX_FINISHED) + goto error; + + char const *iid_name = ""; + IID iid; + switch (iid_code) + { + case D3D4LINUX_IID_SHADER_REFLECTION: + if (strstr(dll_var, "d3dcompiler_47")) + { + memcpy(&iid, &IID_ID3D11ShaderReflection_47, sizeof(iid)); + iid_name = "IID_ID3D11ShaderReflection [47]"; + } + else + { + memcpy(&iid, &IID_ID3D11ShaderReflection_43, sizeof(iid)); + iid_name = "IID_ID3D11ShaderReflection [43]"; + } + break; + default: + fprintf(stderr, "[D3D4LINUX] unknown iid_code %d\n", iid_code); + goto error; + } + + void *object; + HRESULT ret = reflect(data ? data->data() : nullptr, + data ? data->size() : 0, + iid, &object); + if (verbose) + fprintf(stderr, "[D3D4LINUX] D3DReflect([%d bytes], %s) = 0x%x\n", + data ? (int)data->size() : 0, iid_name, (int)ret); + + p.write_i64(ret); + + if (SUCCEEDED(ret) && iid_code == D3D4LINUX_IID_SHADER_REFLECTION) + { + D3D11_SIGNATURE_PARAMETER_DESC param_desc; + D3D11_SHADER_INPUT_BIND_DESC bind_desc; + D3D11_SHADER_VARIABLE_DESC variable_desc; + D3D11_SHADER_BUFFER_DESC buffer_desc; + D3D11_SHADER_TYPE_DESC type_desc; + D3D11_SHADER_DESC shader_desc; + + ID3D11ShaderReflection *reflector = (ID3D11ShaderReflection *)object; + + /* Serialise D3D11_SHADER_DESC */ + reflector->GetDesc(&shader_desc); + p.write_raw(&shader_desc, sizeof(shader_desc)); + p.write_string(shader_desc.Creator); + + /* Serialize all InputParameterDesc */ + for (uint32_t i = 0; i < shader_desc.InputParameters; ++i) + { + reflector->GetInputParameterDesc(i, ¶m_desc); + p.write_raw(¶m_desc, sizeof(param_desc)); + p.write_string(param_desc.SemanticName); + } + + /* Serialize all OutParameterDesc */ + for (uint32_t i = 0; i < shader_desc.OutputParameters; ++i) + { + reflector->GetOutputParameterDesc(i, ¶m_desc); + p.write_raw(¶m_desc, sizeof(param_desc)); + p.write_string(param_desc.SemanticName); + } + + /* Serialize all ResourceBindingDesc */ + for (uint32_t i = 0; i < shader_desc.BoundResources; ++i) + { + reflector->GetResourceBindingDesc(i, &bind_desc); + p.write_raw(&bind_desc, sizeof(bind_desc)); + p.write_string(bind_desc.Name); + } + + /* Serialize all ConstantBuffer */ + for (uint32_t i = 0; i < shader_desc.ConstantBuffers; ++i) + { + ID3D11ShaderReflectionConstantBuffer *cbuffer + = reflector->GetConstantBufferByIndex(i); + + /* Serialize D3D11_SHADER_BUFFER_DESC */ + cbuffer->GetDesc(&buffer_desc); + p.write_raw(&buffer_desc, sizeof(buffer_desc)); + p.write_string(buffer_desc.Name); + + /* Serialize all Variable */ + for (uint32_t j = 0; j < buffer_desc.Variables; ++j) + { + ID3D11ShaderReflectionVariable *var + = cbuffer->GetVariableByIndex(j); + + /* Serialize D3D11_SHADER_VARIABLE_DESC */ + var->GetDesc(&variable_desc); + p.write_raw(&variable_desc, sizeof(variable_desc)); + p.write_string(variable_desc.Name); + p.write_i64(variable_desc.DefaultValue ? 1 : 0); + if (variable_desc.DefaultValue) + p.write_raw(variable_desc.DefaultValue, variable_desc.Size); + + /* Serialize D3D11_SHADER_TYPE_DESC for this variable */ + ID3D11ShaderReflectionType *type = var->GetType(); + type->GetDesc(&type_desc); + p.write_raw(&type_desc, sizeof(type_desc)); + p.write_string(type_desc.Name ? type_desc.Name : ""); + } + } + } + + p.write_i64(D3D4LINUX_FINISHED); + + delete data; + } + else if (syscall == D3D4LINUX_OP_STRIP) + { + HRESULT (*strip)(void const *pShaderBytecode, + size_t BytecodeLength, + uint32_t uStripFlags, + ID3DBlob **ppStrippedBlob); + strip = (decltype(strip))GetProcAddress(lib, "D3DStripShader"); + + std::vector *data = p.read_data(); + uint32_t flags = (uint32_t)p.read_i64(); + marker = (int)p.read_i64(); + if (marker != D3D4LINUX_FINISHED) + goto error; + + ID3DBlob *strip_blob = nullptr; + HRESULT ret = strip(data ? data->data() : nullptr, + data ? data->size() : 0, + flags, &strip_blob); + if (verbose) + fprintf(stderr, "[D3D4LINUX] D3DStripShader([%d bytes], %04x) = 0x%x\n", + data ? (int)data->size() : 0, flags, (int)ret); + + p.write_i64(ret); + p.write_blob(strip_blob); + p.write_i64(D3D4LINUX_FINISHED); + + if (strip_blob) + strip_blob->Release(); + } + else if (syscall == D3D4LINUX_OP_DISASSEMBLE) + { + HRESULT (*disas)(void const *pSrcData, + size_t SrcDataSize, + uint32_t Flags, + char const *szComments, + ID3DBlob **ppDisassembly); + disas = (decltype(disas))GetProcAddress(lib, "D3DDisassemble"); + + std::vector *data = p.read_data(); + uint32_t flags = (uint32_t)p.read_i64(); + int has_comments = (int)p.read_i64(); + std::string comments; + if (has_comments) + comments = p.read_string(); + marker = (int)p.read_i64(); + if (marker != D3D4LINUX_FINISHED) + goto error; + + ID3DBlob *disas_blob = nullptr; + HRESULT ret = disas(data ? data->data() : nullptr, + data ? data->size() : 0, + flags, + has_comments ? comments.c_str() : nullptr, + &disas_blob); + if (verbose) + fprintf(stderr, "[D3D4LINUX] D3DDisassemble([%d bytes], %04x, %s) = 0x%x\n", + data ? (int)data->size() : 0, flags, has_comments ? "[comments]" : "(nullptr)", (int)ret); + + p.write_i64(ret); + p.write_blob(disas_blob); + p.write_i64(D3D4LINUX_FINISHED); + + if (disas_blob) + disas_blob->Release(); + } + + continue; + + error: + if (verbose) + fprintf(stderr, "[D3D4LINUX] Bad message received: 0x%x 0x%x\n", syscall, marker); + } + + return EXIT_SUCCESS; +} diff --git a/3rdparty/d3d4linux/include/d3d4linux.h b/3rdparty/d3d4linux/include/d3d4linux.h new file mode 100644 index 000000000..fbc50ec33 --- /dev/null +++ b/3rdparty/d3d4linux/include/d3d4linux.h @@ -0,0 +1,341 @@ +// +// D3D4Linux — access Direct3D DLLs from Linux programs +// +// Copyright © 2016 Sam Hocevar +// +// This library is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +#include /* for uint32_t */ +#include /* for size_t */ +#include /* for strcmp */ + +#include /* for std::vector */ +#include /* for std::string */ +#include + +/* + * Default values for some runtime settings + */ + +#if !defined D3D4LINUX_DLL + // NOTE: this variable has a Z: prefix because it will be interpreted by + // a Windows process run by Wine, so it needs a Windows path. +# define D3D4LINUX_DLL "z:/usr/lib/d3d4linux/d3dcompiler_47.dll" +#endif + +#if !defined D3D4LINUX_EXE +# define D3D4LINUX_EXE "/usr/lib/d3d4linux/d3d4linux.exe" +#endif + +#if !defined D3D4LINUX_WINE + // Wine 11+ uses "wine" for both 32/64-bit, older versions use "wine64" +# define D3D4LINUX_WINE "/usr/bin/wine" +# define D3D4LINUX_WINE_FALLBACK "/usr/bin/wine64" +#endif + +#ifndef WSL_WINADAPTER_H +/* + * Types and macros that come from Windows + */ + +typedef long HRESULT; +typedef long HMODULE; +typedef void const * LPCVOID; +typedef char const * LPCSTR; + +typedef long GUID; +typedef GUID REFIID; /* FIXME */ + +#define CONST const + +#define S_FALSE ((HRESULT)1) +#define S_OK ((HRESULT)0) +#define E_FAIL ((HRESULT)0x80004005) + +#define SUCCEEDED(x) ((HRESULT)(x) == S_OK) +#define FAILED(x) (!SUCCEEDED(x)) + +#define EXCEPTION_EXECUTE_HANDLER 1 + +#define MAKE_HRESULT(x, y, z) ((HRESULT) (((unsigned long)(x)<<31) | ((unsigned long)(y)<<16) | ((unsigned long)(z))) ) + +/* + * Fake values; we don’t care + */ + +#define IID_ID3D11ShaderReflection D3D4LINUX_IID_SHADER_REFLECTION +#endif // WSL_WINADAPTER_H + +/* + * Types that come from D3D + */ + +#include +#include + +struct ID3DInclude +{ + // FIXME: unimplemented +}; + +struct ID3D11ShaderReflectionType +{ + HRESULT GetDesc(D3D11_SHADER_TYPE_DESC *desc) + { + *desc = m_desc; + desc->Name = m_name.empty() ? nullptr : m_name.c_str(); + return S_OK; + } + + D3D11_SHADER_TYPE_DESC m_desc; + std::string m_name; +}; + +struct ID3D11ShaderReflectionVariable +{ + HRESULT GetDesc(D3D11_SHADER_VARIABLE_DESC *desc) + { + *desc = m_desc; + desc->Name = m_strings[0].c_str(); + desc->DefaultValue = m_has_default ? m_default_value.data() : nullptr; + return S_OK; + } + + ID3D11ShaderReflectionType *GetType() + { + return &m_type; + } + + D3D11_SHADER_VARIABLE_DESC m_desc; + ID3D11ShaderReflectionType m_type; + std::vector m_strings; + int m_has_default; + std::vector m_default_value; +}; + +struct ID3D11ShaderReflectionConstantBuffer +{ + HRESULT GetDesc(D3D11_SHADER_BUFFER_DESC *desc) + { + *desc = m_desc; + desc->Name = m_strings[0].c_str(); + return S_OK; + } + + struct ID3D11ShaderReflectionVariable *GetVariableByIndex(uint32_t index) + { + return index < m_variables.size() ? &m_variables[index] : nullptr; + } + + struct ID3D11ShaderReflectionVariable *GetVariableByName(char const *name) + { + for (size_t i = 0; i < m_variables.size(); ++i) + if (!strcmp(m_variables[i].m_strings[0].c_str(), name)) + return &m_variables[i]; + + return nullptr; + } + + D3D11_SHADER_BUFFER_DESC m_desc; + std::vector m_variables; + std::vector m_strings; +}; + +struct ID3D11ShaderReflection +{ + ID3D11ShaderReflection() : m_refcount(1) {} + + HRESULT GetDesc(D3D11_SHADER_DESC *Desc) + { + *Desc = m_desc; + Desc->Creator = m_strings[0].c_str(); + return S_OK; + } + + HRESULT GetInputParameterDesc(uint32_t index, D3D11_SIGNATURE_PARAMETER_DESC *desc) + { + if (index >= m_input_params.size()) + return E_FAIL; + + *desc = m_input_params[index]; + desc->SemanticName = m_strings[1 + index].c_str(); + return S_OK; + } + + HRESULT GetOutputParameterDesc(uint32_t index, D3D11_SIGNATURE_PARAMETER_DESC *desc) + { + if (index >= m_output_params.size()) + return E_FAIL; + + *desc = m_output_params[index]; + desc->SemanticName = m_strings[1 + m_input_params.size() + index].c_str(); + return S_OK; + } + + HRESULT GetResourceBindingDesc(uint32_t index, D3D11_SHADER_INPUT_BIND_DESC *desc) + { + if (index >= m_binds.size()) + return E_FAIL; + + *desc = m_binds[index]; + desc->Name = m_strings[1 + m_input_params.size() + m_output_params.size() + index].c_str(); + return S_OK; + } + + struct ID3D11ShaderReflectionConstantBuffer *GetConstantBufferByName(char const *name) + { + for (size_t i = 0; i < m_buffers.size(); ++i) + if (!strcmp(m_buffers[i].m_strings[0].c_str(), name)) + return &m_buffers[i]; + return nullptr; + } + + struct ID3D11ShaderReflectionConstantBuffer *GetConstantBufferByIndex(uint32_t index) + { + return index < m_buffers.size() ? &m_buffers[index] : nullptr; + } + + void AddRef() { ++m_refcount; } + void Release() { /*if (this && --m_refcount <= 0) delete this;*/ } + + D3D11_SHADER_DESC m_desc; + std::vector m_input_params; + std::vector m_output_params; + std::vector m_binds; + std::vector m_buffers; + std::vector m_strings; + +private: + int m_refcount; +}; + +struct ID3DBlob +{ + ID3DBlob(size_t size) : m_refcount(1) { m_data.resize(size); } + + void const *GetBufferPointer() const { return m_data.data(); } + void *GetBufferPointer() { return m_data.data(); } + size_t GetBufferSize() const { return m_data.size(); } + void AddRef() { ++m_refcount; } + void Release() { /*if (this && --m_refcount <= 0) delete this;*/ } + +private: + std::vector m_data; + int m_refcount; +}; + +/* + * Helper class + */ + +#include + +/* + * Functions that come from D3D + */ + +static inline +HRESULT D3DCreateBlob(size_t Size, ID3DBlob **ppBlob) +{ + return d3d4linux::create_blob(Size, ppBlob); +} + +static inline +HRESULT D3DCompile(void const *pSrcData, size_t SrcDataSize, + char const *pFileName, + D3D_SHADER_MACRO const *pDefines, + ID3DInclude *pInclude, + char const *pEntrypoint, char const *pTarget, + uint32_t Flags1, uint32_t Flags2, + ID3DBlob **ppCode, ID3DBlob **ppErrorMsgs) +{ + return d3d4linux::compile(pSrcData, SrcDataSize, pFileName, pDefines, + pInclude, pEntrypoint, pTarget, Flags1, + Flags2, ppCode, ppErrorMsgs); +} + +static inline +HRESULT D3DDisassemble(void const *pSrcData, + size_t SrcDataSize, + uint32_t Flags, + char const *szComments, + ID3DBlob **ppDisassembly) +{ + return d3d4linux::disassemble(pSrcData, SrcDataSize, Flags, + szComments, ppDisassembly); +} + +static inline +HRESULT D3DReflect(void const *pSrcData, + size_t SrcDataSize, + REFIID pInterface, + void **ppReflector) +{ + return d3d4linux::reflect(pSrcData, SrcDataSize, pInterface, ppReflector); +} + +static inline +HRESULT D3DStripShader(void const *pShaderBytecode, + size_t BytecodeLength, + uint32_t uStripFlags, + ID3DBlob **ppStrippedBlob) +{ + return d3d4linux::strip_shader(pShaderBytecode, BytecodeLength, + uStripFlags, ppStrippedBlob); +} + +/* + * Only Compile, Disassemble and Preprocess have associated types + */ + +typedef decltype(&d3d4linux::compile) pD3DCompile; +typedef decltype(&d3d4linux::disassemble) pD3DDisassemble; + +/* + * Helper functions for Windows + */ + +static inline HMODULE LoadLibrary(char const *name) +{ + static char const *prefix = "d3dcompiler_"; + char const *pos = strstr(name, prefix); + if (pos) + d3d4linux::compiler_version() = atoi(pos + strlen(prefix)); + return (HMODULE)1; +} + +static inline HMODULE LoadLibrary(wchar_t const *name) +{ + static wchar_t const *prefix = L"d3dcompiler_"; + wchar_t const *pos = wcsstr(name, prefix); + if (pos) + d3d4linux::compiler_version() = wcstol(pos + wcslen(prefix), nullptr, 10); + return (HMODULE)1; +} + +static inline void FreeLibrary(HMODULE handle) +{ +} + +static void *GetProcAddress(HMODULE, char const *name) +{ + if (!strcmp(name, "D3DCompile")) + return (void *)&d3d4linux::compile; + if (!strcmp(name, "D3DReflect")) + return (void *)&d3d4linux::reflect; + if (!strcmp(name, "D3DDisassemble")) + return (void *)&d3d4linux::disassemble; + if (!strcmp(name, "D3DStripShader")) + return (void *)&d3d4linux::strip_shader; + if (!strcmp(name, "D3DCreateBlob")) + return (void *)&d3d4linux::create_blob; + return nullptr; +} + diff --git a/3rdparty/d3d4linux/include/d3d4linux_common.h b/3rdparty/d3d4linux/include/d3d4linux_common.h new file mode 100644 index 000000000..967ba6027 --- /dev/null +++ b/3rdparty/d3d4linux/include/d3d4linux_common.h @@ -0,0 +1,112 @@ +// +// D3D4Linux — access Direct3D DLLs from Linux programs +// +// Copyright © 2016 Sam Hocevar +// +// This library is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +#include +#include + +#define D3D4LINUX_FINISHED 0x42000000 + +#define D3D4LINUX_OP_COMPILE 0x42001000 +#define D3D4LINUX_OP_REFLECT 0x42001001 +#define D3D4LINUX_OP_STRIP 0x42001002 +#define D3D4LINUX_OP_DISASSEMBLE 0x42001003 + +#define D3D4LINUX_IID_SHADER_REFLECTION 0x42002000 + +// +// Support class for low-level serialization through stdio streams. +// +// These functions cannot crash in case of bad data, but they may +// return garbage. +// We do not care about endianness (because the guest runs on the same +// machine) and we do not care about read errors (because the protocol +// above us does the necessary checks). +// +struct interop +{ + interop(FILE *in, FILE *out) + : m_in(in), + m_out(out) + {} + + // + // Simple read/write methods for arbitrary data + // + + void read_raw(void *ptr, size_t len) + { + fread(ptr, len, 1, m_in); + } + + void write_raw(void const *data, size_t size) + { + fwrite(data, size, 1, m_out); + } + + // + // Type-specific read/write methods + // + + int64_t read_i64() + { + int64_t ret; + read_raw(&ret, sizeof(ret)); + return ret; + } + + std::string read_string() + { + std::string ret; + size_t len = read_i64(); + ret.resize(len); + read_raw(&ret[0], len); + return ret; + } + + std::vector *read_data() + { + size_t len = (size_t)read_i64(); + if (len < 0) + return nullptr; + std::vector *v = new std::vector(); + v->resize(len); + read_raw(v->data(), (int)v->size()); + return v; + } + + void write_i64(int64_t x) + { + write_raw(&x, sizeof(x)); + if (x == D3D4LINUX_FINISHED) + fflush(m_out); + } + + void write_string(char const *s) + { + size_t len = strlen(s); + write_i64(len); + write_raw(s, len); + } + + void write_blob(ID3DBlob *blob) + { + write_i64(blob ? blob->GetBufferSize() : -1); + if (blob) + write_raw(blob->GetBufferPointer(), blob->GetBufferSize()); + } + +protected: + FILE *m_in, *m_out; +}; + diff --git a/3rdparty/d3d4linux/include/d3d4linux_enums.h b/3rdparty/d3d4linux/include/d3d4linux_enums.h new file mode 100644 index 000000000..7f93d29b8 --- /dev/null +++ b/3rdparty/d3d4linux/include/d3d4linux_enums.h @@ -0,0 +1,675 @@ +// +// D3D4Linux — access Direct3D DLLs from Linux programs +// +// Copyright © 2016 Sam Hocevar +// +// This library is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +/* + * Enums/macros from D3D + */ + +#define D3DCOMPILE_DEBUG 0x0001 +#define D3DCOMPILE_SKIP_VALIDATION 0x0002 +#define D3DCOMPILE_SKIP_OPTIMIZATION 0x0004 +#define D3DCOMPILE_PACK_MATRIX_ROW_MAJOR 0x0008 +#define D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR 0x0010 +#define D3DCOMPILE_PARTIAL_PRECISION 0x0020 +#define D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT 0x0040 +#define D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT 0x0080 +#define D3DCOMPILE_NO_PRESHADER 0x0100 +#define D3DCOMPILE_AVOID_FLOW_CONTROL 0x0200 +#define D3DCOMPILE_PREFER_FLOW_CONTROL 0x0400 +#define D3DCOMPILE_ENABLE_STRICTNESS 0x0800 +#define D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY 0x1000 +#define D3DCOMPILE_IEEE_STRICTNESS 0x2000 +#define D3DCOMPILE_WARNINGS_ARE_ERRORS 0x40000 + +#define D3DCOMPILE_OPTIMIZATION_LEVEL0 0x4000 +#define D3DCOMPILE_OPTIMIZATION_LEVEL1 0x0000 +#define D3DCOMPILE_OPTIMIZATION_LEVEL2 0xc000 +#define D3DCOMPILE_OPTIMIZATION_LEVEL3 0x8000 + +/* + * Enums/macros from D3D10 + */ + +#define _FACD3D10 0x87 +#define MAKE_D3D10_HRESULT(x) MAKE_HRESULT(1, _FACD3D10, x) + +#define D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS MAKE_D3D10_HRESULT(1) +#define D3D10_ERROR_FILE_NOT_FOUND MAKE_D3D10_HRESULT(2) + +#define D3D10_SHADER_DEBUG 0x0001 +#define D3D10_SHADER_SKIP_VALIDATION 0x0002 +#define D3D10_SHADER_SKIP_OPTIMIZATION 0x0004 +#define D3D10_SHADER_PACK_MATRIX_ROW_MAJOR 0x0008 +#define D3D10_SHADER_AVOID_FLOW_CONTROL 0x0200 +#define D3D10_SHADER_PREFER_FLOW_CONTROL 0x0400 +#define D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY 0x1000 + +#define D3D10_SHADER_OPTIMIZATION_LEVEL0 0x4000 +#define D3D10_SHADER_OPTIMIZATION_LEVEL1 0x0000 +#define D3D10_SHADER_OPTIMIZATION_LEVEL2 0xc000 +#define D3D10_SHADER_OPTIMIZATION_LEVEL3 0x8000 + +typedef enum D3DCOMPILER_STRIP_FLAGS +{ + D3DCOMPILER_STRIP_REFLECTION_DATA = 0x00000001, + D3DCOMPILER_STRIP_DEBUG_INFO = 0x00000002, + D3DCOMPILER_STRIP_TEST_BLOBS = 0x00000004, + D3DCOMPILER_STRIP_FORCE_DWORD = 0x7fffffff, +} +D3DCOMPILER_STRIP_FLAGS; + +typedef enum D3D_NAME +{ + D3D_NAME_UNDEFINED = 0, + D3D_NAME_POSITION = 1, + D3D_NAME_CLIP_DISTANCE = 2, + D3D_NAME_CULL_DISTANCE = 3, + D3D_NAME_RENDER_TARGET_ARRAY_INDEX = 4, + D3D_NAME_VIEWPORT_ARRAY_INDEX = 5, + D3D_NAME_VERTEX_ID = 6, + D3D_NAME_PRIMITIVE_ID = 7, + D3D_NAME_INSTANCE_ID = 8, + D3D_NAME_IS_FRONT_FACE = 9, + D3D_NAME_SAMPLE_INDEX = 10, + D3D_NAME_FINAL_QUAD_EDGE_TESSFACTOR = 11, + D3D_NAME_FINAL_QUAD_INSIDE_TESSFACTOR = 12, + D3D_NAME_FINAL_TRI_EDGE_TESSFACTOR = 13, + D3D_NAME_FINAL_TRI_INSIDE_TESSFACTOR = 14, + D3D_NAME_FINAL_LINE_DETAIL_TESSFACTOR = 15, + D3D_NAME_FINAL_LINE_DENSITY_TESSFACTOR = 16, + D3D_NAME_TARGET = 64, + D3D_NAME_DEPTH = 65, + D3D_NAME_COVERAGE = 66, + D3D_NAME_DEPTH_GREATER_EQUAL = 67, + D3D_NAME_DEPTH_LESS_EQUAL = 68, + + D3D10_NAME_UNDEFINED = 0, + D3D10_NAME_POSITION = 1, + D3D10_NAME_CLIP_DISTANCE = 2, + D3D10_NAME_CULL_DISTANCE = 3, + D3D10_NAME_RENDER_TARGET_ARRAY_INDEX = 4, + D3D10_NAME_VIEWPORT_ARRAY_INDEX = 5, + D3D10_NAME_VERTEX_ID = 6, + D3D10_NAME_PRIMITIVE_ID = 7, + D3D10_NAME_INSTANCE_ID = 8, + D3D10_NAME_IS_FRONT_FACE = 9, + D3D10_NAME_SAMPLE_INDEX = 10, + D3D10_NAME_TARGET = 64, + D3D10_NAME_DEPTH = 65, + D3D10_NAME_COVERAGE = 66, + + D3D11_NAME_FINAL_QUAD_EDGE_TESSFACTOR = 11, + D3D11_NAME_FINAL_QUAD_INSIDE_TESSFACTOR = 12, + D3D11_NAME_FINAL_TRI_EDGE_TESSFACTOR = 13, + D3D11_NAME_FINAL_TRI_INSIDE_TESSFACTOR = 14, + D3D11_NAME_FINAL_LINE_DETAIL_TESSFACTOR = 15, + D3D11_NAME_FINAL_LINE_DENSITY_TESSFACTOR = 16, + D3D11_NAME_DEPTH_GREATER_EQUAL = 67, + D3D11_NAME_DEPTH_LESS_EQUAL = 68, +} +D3D_NAME; + +typedef enum D3D_REGISTER_COMPONENT_TYPE +{ + D3D_REGISTER_COMPONENT_UNKNOWN = 0, + D3D_REGISTER_COMPONENT_UINT32 = 1, + D3D_REGISTER_COMPONENT_SINT32 = 2, + D3D_REGISTER_COMPONENT_FLOAT32 = 3, + + D3D10_REGISTER_COMPONENT_UNKNOWN = 0, + D3D10_REGISTER_COMPONENT_UINT32 = 1, + D3D10_REGISTER_COMPONENT_SINT32 = 2, + D3D10_REGISTER_COMPONENT_FLOAT32 = 3, +} +D3D_REGISTER_COMPONENT_TYPE; + +typedef enum D3D_MIN_PRECISION +{ + D3D_MIN_PRECISION_DEFAULT = 0, + D3D_MIN_PRECISION_FLOAT_16 = 1, + D3D_MIN_PRECISION_FLOAT_2_8 = 2, + D3D_MIN_PRECISION_RESERVED = 3, + D3D_MIN_PRECISION_SINT_16 = 4, + D3D_MIN_PRECISION_UINT_16 = 5, + D3D_MIN_PRECISION_ANY_16 = 0xf0, + D3D_MIN_PRECISION_ANY_10 = 0xf1, +} +D3D_MIN_PRECISION; + +typedef enum D3D_SHADER_INPUT_TYPE +{ + D3D_SIT_CBUFFER = 0, + D3D_SIT_TBUFFER = 1, + D3D_SIT_TEXTURE = 2, + D3D_SIT_SAMPLER = 3, + D3D_SIT_UAV_RWTYPED = 4, + D3D_SIT_STRUCTURED = 5, + D3D_SIT_UAV_RWSTRUCTURED = 6, + D3D_SIT_BYTEADDRESS = 7, + D3D_SIT_UAV_RWBYTEADDRESS = 8, + D3D_SIT_UAV_APPEND_STRUCTURED = 9, + D3D_SIT_UAV_CONSUME_STRUCTURED = 10, + D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER = 11, + + D3D10_SIT_CBUFFER = 0, + D3D10_SIT_TBUFFER = 1, + D3D10_SIT_TEXTURE = 2, + D3D10_SIT_SAMPLER = 3, + + D3D11_SIT_UAV_RWTYPED = 4, + D3D11_SIT_STRUCTURED = 5, + D3D11_SIT_UAV_RWSTRUCTURED = 6, + D3D11_SIT_BYTEADDRESS = 7, + D3D11_SIT_UAV_RWBYTEADDRESS = 8, + D3D11_SIT_UAV_APPEND_STRUCTURED = 9, + D3D11_SIT_UAV_CONSUME_STRUCTURED = 10, + D3D11_SIT_UAV_RWSTRUCTURED_WITH_COUNTER = 11, +} +D3D_SHADER_INPUT_TYPE; + +typedef enum D3D_SHADER_VARIABLE_FLAGS +{ + D3D_SVF_USERPACKED = 1, + D3D_SVF_USED = 2, + D3D_SVF_INTERFACE_POINTER = 4, + D3D_SVF_INTERFACE_PARAMETER = 8, + + D3D10_SVF_USERPACKED = D3D_SVF_USERPACKED, + D3D10_SVF_USED = D3D_SVF_USED, + D3D11_SVF_INTERFACE_POINTER = D3D_SVF_INTERFACE_POINTER, + D3D11_SVF_INTERFACE_PARAMETER = D3D_SVF_INTERFACE_PARAMETER, + + D3D_SVF_FORCE_DWORD = 0x7fffffff, +} +D3D_SHADER_VARIABLE_FLAGS; + +typedef enum D3D_RESOURCE_RETURN_TYPE +{ + D3D_RETURN_TYPE_UNORM = 1, + D3D_RETURN_TYPE_SNORM = 2, + D3D_RETURN_TYPE_SINT = 3, + D3D_RETURN_TYPE_UINT = 4, + D3D_RETURN_TYPE_FLOAT = 5, + D3D_RETURN_TYPE_MIXED = 6, + D3D_RETURN_TYPE_DOUBLE = 7, + D3D_RETURN_TYPE_CONTINUED = 8, + + D3D10_RETURN_TYPE_UNORM = D3D_RETURN_TYPE_UNORM, + D3D10_RETURN_TYPE_SNORM = D3D_RETURN_TYPE_SNORM, + D3D10_RETURN_TYPE_SINT = D3D_RETURN_TYPE_SINT, + D3D10_RETURN_TYPE_UINT = D3D_RETURN_TYPE_UINT, + D3D10_RETURN_TYPE_FLOAT = D3D_RETURN_TYPE_FLOAT, + D3D10_RETURN_TYPE_MIXED = D3D_RETURN_TYPE_MIXED, + + D3D11_RETURN_TYPE_UNORM = D3D_RETURN_TYPE_UNORM, + D3D11_RETURN_TYPE_SNORM = D3D_RETURN_TYPE_SNORM, + D3D11_RETURN_TYPE_SINT = D3D_RETURN_TYPE_SINT, + D3D11_RETURN_TYPE_UINT = D3D_RETURN_TYPE_UINT, + D3D11_RETURN_TYPE_FLOAT = D3D_RETURN_TYPE_FLOAT, + D3D11_RETURN_TYPE_MIXED = D3D_RETURN_TYPE_MIXED, + D3D11_RETURN_TYPE_DOUBLE = D3D_RETURN_TYPE_DOUBLE, + D3D11_RETURN_TYPE_CONTINUED = D3D_RETURN_TYPE_CONTINUED, +} +D3D_RESOURCE_RETURN_TYPE; + +typedef enum D3D_SRV_DIMENSION +{ + D3D_SRV_DIMENSION_UNKNOWN = 0, + D3D_SRV_DIMENSION_BUFFER = 1, + D3D_SRV_DIMENSION_TEXTURE1D = 2, + D3D_SRV_DIMENSION_TEXTURE1DARRAY = 3, + D3D_SRV_DIMENSION_TEXTURE2D = 4, + D3D_SRV_DIMENSION_TEXTURE2DARRAY = 5, + D3D_SRV_DIMENSION_TEXTURE2DMS = 6, + D3D_SRV_DIMENSION_TEXTURE2DMSARRAY = 7, + D3D_SRV_DIMENSION_TEXTURE3D = 8, + D3D_SRV_DIMENSION_TEXTURECUBE = 9, + D3D_SRV_DIMENSION_TEXTURECUBEARRAY = 10, + D3D_SRV_DIMENSION_BUFFEREX = 11, + + D3D10_SRV_DIMENSION_UNKNOWN = D3D_SRV_DIMENSION_UNKNOWN, + D3D10_SRV_DIMENSION_BUFFER = D3D_SRV_DIMENSION_BUFFER, + D3D10_SRV_DIMENSION_TEXTURE1D = D3D_SRV_DIMENSION_TEXTURE1D, + D3D10_SRV_DIMENSION_TEXTURE1DARRAY = D3D_SRV_DIMENSION_TEXTURE1DARRAY, + D3D10_SRV_DIMENSION_TEXTURE2D = D3D_SRV_DIMENSION_TEXTURE2D, + D3D10_SRV_DIMENSION_TEXTURE2DARRAY = D3D_SRV_DIMENSION_TEXTURE2DARRAY, + D3D10_SRV_DIMENSION_TEXTURE2DMS = D3D_SRV_DIMENSION_TEXTURE2DMS, + D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY, + D3D10_SRV_DIMENSION_TEXTURE3D = D3D_SRV_DIMENSION_TEXTURE3D, + D3D10_SRV_DIMENSION_TEXTURECUBE = D3D_SRV_DIMENSION_TEXTURECUBE, + + D3D10_1_SRV_DIMENSION_UNKNOWN = D3D_SRV_DIMENSION_UNKNOWN, + D3D10_1_SRV_DIMENSION_BUFFER = D3D_SRV_DIMENSION_BUFFER, + D3D10_1_SRV_DIMENSION_TEXTURE1D = D3D_SRV_DIMENSION_TEXTURE1D, + D3D10_1_SRV_DIMENSION_TEXTURE1DARRAY = D3D_SRV_DIMENSION_TEXTURE1DARRAY, + D3D10_1_SRV_DIMENSION_TEXTURE2D = D3D_SRV_DIMENSION_TEXTURE2D, + D3D10_1_SRV_DIMENSION_TEXTURE2DARRAY = D3D_SRV_DIMENSION_TEXTURE2DARRAY, + D3D10_1_SRV_DIMENSION_TEXTURE2DMS = D3D_SRV_DIMENSION_TEXTURE2DMS, + D3D10_1_SRV_DIMENSION_TEXTURE2DMSARRAY = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY, + D3D10_1_SRV_DIMENSION_TEXTURE3D = D3D_SRV_DIMENSION_TEXTURE3D, + D3D10_1_SRV_DIMENSION_TEXTURECUBE = D3D_SRV_DIMENSION_TEXTURECUBE, + D3D10_1_SRV_DIMENSION_TEXTURECUBEARRAY = D3D_SRV_DIMENSION_TEXTURECUBEARRAY, + + D3D11_SRV_DIMENSION_UNKNOWN = D3D_SRV_DIMENSION_UNKNOWN, + D3D11_SRV_DIMENSION_BUFFER = D3D_SRV_DIMENSION_BUFFER, + D3D11_SRV_DIMENSION_TEXTURE1D = D3D_SRV_DIMENSION_TEXTURE1D, + D3D11_SRV_DIMENSION_TEXTURE1DARRAY = D3D_SRV_DIMENSION_TEXTURE1DARRAY, + D3D11_SRV_DIMENSION_TEXTURE2D = D3D_SRV_DIMENSION_TEXTURE2D, + D3D11_SRV_DIMENSION_TEXTURE2DARRAY = D3D_SRV_DIMENSION_TEXTURE2DARRAY, + D3D11_SRV_DIMENSION_TEXTURE2DMS = D3D_SRV_DIMENSION_TEXTURE2DMS, + D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY, + D3D11_SRV_DIMENSION_TEXTURE3D = D3D_SRV_DIMENSION_TEXTURE3D, + D3D11_SRV_DIMENSION_TEXTURECUBE = D3D_SRV_DIMENSION_TEXTURECUBE, + D3D11_SRV_DIMENSION_TEXTURECUBEARRAY = D3D_SRV_DIMENSION_TEXTURECUBEARRAY, + D3D11_SRV_DIMENSION_BUFFEREX = D3D_SRV_DIMENSION_BUFFEREX, +} +D3D_SRV_DIMENSION; + +typedef enum D3D_PRIMITIVE +{ + D3D_PRIMITIVE_UNDEFINED = 0, + D3D_PRIMITIVE_POINT = 1, + D3D_PRIMITIVE_LINE = 2, + D3D_PRIMITIVE_TRIANGLE = 3, + D3D_PRIMITIVE_LINE_ADJ = 6, + D3D_PRIMITIVE_TRIANGLE_ADJ = 7, + D3D_PRIMITIVE_1_CONTROL_POINT_PATCH = 8, + D3D_PRIMITIVE_2_CONTROL_POINT_PATCH = 9, + D3D_PRIMITIVE_3_CONTROL_POINT_PATCH = 10, + D3D_PRIMITIVE_4_CONTROL_POINT_PATCH = 11, + D3D_PRIMITIVE_5_CONTROL_POINT_PATCH = 12, + D3D_PRIMITIVE_6_CONTROL_POINT_PATCH = 13, + D3D_PRIMITIVE_7_CONTROL_POINT_PATCH = 14, + D3D_PRIMITIVE_8_CONTROL_POINT_PATCH = 15, + D3D_PRIMITIVE_9_CONTROL_POINT_PATCH = 16, + D3D_PRIMITIVE_10_CONTROL_POINT_PATCH = 17, + D3D_PRIMITIVE_11_CONTROL_POINT_PATCH = 18, + D3D_PRIMITIVE_12_CONTROL_POINT_PATCH = 19, + D3D_PRIMITIVE_13_CONTROL_POINT_PATCH = 20, + D3D_PRIMITIVE_14_CONTROL_POINT_PATCH = 21, + D3D_PRIMITIVE_15_CONTROL_POINT_PATCH = 22, + D3D_PRIMITIVE_16_CONTROL_POINT_PATCH = 23, + D3D_PRIMITIVE_17_CONTROL_POINT_PATCH = 24, + D3D_PRIMITIVE_18_CONTROL_POINT_PATCH = 25, + D3D_PRIMITIVE_19_CONTROL_POINT_PATCH = 26, + D3D_PRIMITIVE_20_CONTROL_POINT_PATCH = 27, + D3D_PRIMITIVE_21_CONTROL_POINT_PATCH = 28, + D3D_PRIMITIVE_22_CONTROL_POINT_PATCH = 29, + D3D_PRIMITIVE_23_CONTROL_POINT_PATCH = 30, + D3D_PRIMITIVE_24_CONTROL_POINT_PATCH = 31, + D3D_PRIMITIVE_25_CONTROL_POINT_PATCH = 32, + D3D_PRIMITIVE_26_CONTROL_POINT_PATCH = 33, + D3D_PRIMITIVE_27_CONTROL_POINT_PATCH = 34, + D3D_PRIMITIVE_28_CONTROL_POINT_PATCH = 35, + D3D_PRIMITIVE_29_CONTROL_POINT_PATCH = 36, + D3D_PRIMITIVE_30_CONTROL_POINT_PATCH = 37, + D3D_PRIMITIVE_31_CONTROL_POINT_PATCH = 38, + D3D_PRIMITIVE_32_CONTROL_POINT_PATCH = 39, + + D3D10_PRIMITIVE_UNDEFINED = D3D_PRIMITIVE_UNDEFINED, + D3D10_PRIMITIVE_POINT = D3D_PRIMITIVE_POINT, + D3D10_PRIMITIVE_LINE = D3D_PRIMITIVE_LINE, + D3D10_PRIMITIVE_TRIANGLE = D3D_PRIMITIVE_TRIANGLE, + D3D10_PRIMITIVE_LINE_ADJ = D3D_PRIMITIVE_LINE_ADJ, + D3D10_PRIMITIVE_TRIANGLE_ADJ = D3D_PRIMITIVE_TRIANGLE_ADJ, + + D3D11_PRIMITIVE_UNDEFINED = D3D_PRIMITIVE_UNDEFINED, + D3D11_PRIMITIVE_POINT = D3D_PRIMITIVE_POINT, + D3D11_PRIMITIVE_LINE = D3D_PRIMITIVE_LINE, + D3D11_PRIMITIVE_TRIANGLE = D3D_PRIMITIVE_TRIANGLE, + D3D11_PRIMITIVE_LINE_ADJ = D3D_PRIMITIVE_LINE_ADJ, + D3D11_PRIMITIVE_TRIANGLE_ADJ = D3D_PRIMITIVE_TRIANGLE_ADJ, + D3D11_PRIMITIVE_1_CONTROL_POINT_PATCH = D3D_PRIMITIVE_1_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_2_CONTROL_POINT_PATCH = D3D_PRIMITIVE_2_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_3_CONTROL_POINT_PATCH = D3D_PRIMITIVE_3_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_4_CONTROL_POINT_PATCH = D3D_PRIMITIVE_4_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_5_CONTROL_POINT_PATCH = D3D_PRIMITIVE_5_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_6_CONTROL_POINT_PATCH = D3D_PRIMITIVE_6_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_7_CONTROL_POINT_PATCH = D3D_PRIMITIVE_7_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_8_CONTROL_POINT_PATCH = D3D_PRIMITIVE_8_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_9_CONTROL_POINT_PATCH = D3D_PRIMITIVE_9_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_10_CONTROL_POINT_PATCH = D3D_PRIMITIVE_10_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_11_CONTROL_POINT_PATCH = D3D_PRIMITIVE_11_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_12_CONTROL_POINT_PATCH = D3D_PRIMITIVE_12_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_13_CONTROL_POINT_PATCH = D3D_PRIMITIVE_13_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_14_CONTROL_POINT_PATCH = D3D_PRIMITIVE_14_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_15_CONTROL_POINT_PATCH = D3D_PRIMITIVE_15_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_16_CONTROL_POINT_PATCH = D3D_PRIMITIVE_16_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_17_CONTROL_POINT_PATCH = D3D_PRIMITIVE_17_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_18_CONTROL_POINT_PATCH = D3D_PRIMITIVE_18_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_19_CONTROL_POINT_PATCH = D3D_PRIMITIVE_19_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_20_CONTROL_POINT_PATCH = D3D_PRIMITIVE_20_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_21_CONTROL_POINT_PATCH = D3D_PRIMITIVE_21_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_22_CONTROL_POINT_PATCH = D3D_PRIMITIVE_22_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_23_CONTROL_POINT_PATCH = D3D_PRIMITIVE_23_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_24_CONTROL_POINT_PATCH = D3D_PRIMITIVE_24_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_25_CONTROL_POINT_PATCH = D3D_PRIMITIVE_25_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_26_CONTROL_POINT_PATCH = D3D_PRIMITIVE_26_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_27_CONTROL_POINT_PATCH = D3D_PRIMITIVE_27_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_28_CONTROL_POINT_PATCH = D3D_PRIMITIVE_28_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_29_CONTROL_POINT_PATCH = D3D_PRIMITIVE_29_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_30_CONTROL_POINT_PATCH = D3D_PRIMITIVE_30_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_31_CONTROL_POINT_PATCH = D3D_PRIMITIVE_31_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_32_CONTROL_POINT_PATCH = D3D_PRIMITIVE_32_CONTROL_POINT_PATCH, +} +D3D_PRIMITIVE; + +typedef enum D3D_PRIMITIVE_TOPOLOGY +{ + D3D_PRIMITIVE_TOPOLOGY_UNDEFINED = 0, + D3D_PRIMITIVE_TOPOLOGY_POINTLIST = 1, + D3D_PRIMITIVE_TOPOLOGY_LINELIST = 2, + D3D_PRIMITIVE_TOPOLOGY_LINESTRIP = 3, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST = 4, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = 5, + D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10, + D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = 11, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = 12, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = 13, + D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = 33, + D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST = 34, + D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST = 35, + D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST = 36, + D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST = 37, + D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST = 38, + D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST = 39, + D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST = 40, + D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST = 41, + D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST = 42, + D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST = 43, + D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST = 44, + D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST = 45, + D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST = 46, + D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST = 47, + D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST = 48, + D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST = 49, + D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST = 50, + D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST = 51, + D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST = 52, + D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST = 53, + D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST = 54, + D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST = 55, + D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST = 56, + D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST = 57, + D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST = 58, + D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST = 59, + D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST = 60, + D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST = 61, + D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST = 62, + D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST = 63, + D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST = 64, + + D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED, + D3D10_PRIMITIVE_TOPOLOGY_POINTLIST = D3D_PRIMITIVE_TOPOLOGY_POINTLIST, + D3D10_PRIMITIVE_TOPOLOGY_LINELIST = D3D_PRIMITIVE_TOPOLOGY_LINELIST, + D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, + D3D10_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ, + D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ, + + D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED, + D3D11_PRIMITIVE_TOPOLOGY_POINTLIST = D3D_PRIMITIVE_TOPOLOGY_POINTLIST, + D3D11_PRIMITIVE_TOPOLOGY_LINELIST = D3D_PRIMITIVE_TOPOLOGY_LINELIST, + D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, + D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST, +} +D3D_PRIMITIVE_TOPOLOGY; + +typedef enum D3D_CBUFFER_TYPE +{ + D3D_CT_CBUFFER = 0, + D3D_CT_TBUFFER = (D3D_CT_CBUFFER + 1), + D3D_CT_INTERFACE_POINTERS = (D3D_CT_TBUFFER + 1), + D3D_CT_RESOURCE_BIND_INFO = (D3D_CT_INTERFACE_POINTERS + 1), + + D3D10_CT_CBUFFER = D3D_CT_CBUFFER, + D3D10_CT_TBUFFER = D3D_CT_TBUFFER, + + D3D11_CT_CBUFFER = D3D_CT_CBUFFER, + D3D11_CT_TBUFFER = D3D_CT_TBUFFER, + D3D11_CT_INTERFACE_POINTERS = D3D_CT_INTERFACE_POINTERS, + D3D11_CT_RESOURCE_BIND_INFO = D3D_CT_RESOURCE_BIND_INFO, +} +D3D_CBUFFER_TYPE; + +typedef enum D3D_SHADER_VARIABLE_CLASS +{ + D3D_SVC_SCALAR = 0, + D3D_SVC_VECTOR = (D3D_SVC_SCALAR + 1), + D3D_SVC_MATRIX_ROWS = (D3D_SVC_VECTOR + 1), + D3D_SVC_MATRIX_COLUMNS = (D3D_SVC_MATRIX_ROWS + 1), + D3D_SVC_OBJECT = (D3D_SVC_MATRIX_COLUMNS + 1), + D3D_SVC_STRUCT = (D3D_SVC_OBJECT + 1), + D3D_SVC_INTERFACE_CLASS = (D3D_SVC_STRUCT + 1), + D3D_SVC_INTERFACE_POINTER = (D3D_SVC_INTERFACE_CLASS + 1), + + D3D10_SVC_SCALAR = D3D_SVC_SCALAR, + D3D10_SVC_VECTOR = D3D_SVC_VECTOR, + D3D10_SVC_MATRIX_ROWS = D3D_SVC_MATRIX_ROWS, + D3D10_SVC_MATRIX_COLUMNS = D3D_SVC_MATRIX_COLUMNS, + D3D10_SVC_OBJECT = D3D_SVC_OBJECT, + D3D10_SVC_STRUCT = D3D_SVC_STRUCT, + + D3D11_SVC_INTERFACE_CLASS = D3D_SVC_INTERFACE_CLASS, + D3D11_SVC_INTERFACE_POINTER = D3D_SVC_INTERFACE_POINTER, + + D3D_SVC_FORCE_DWORD = 0x7fffffff, +} +D3D_SHADER_VARIABLE_CLASS; + +typedef enum _D3D_SHADER_VARIABLE_TYPE +{ + D3D_SVT_VOID = 0, + D3D_SVT_BOOL = 1, + D3D_SVT_INT = 2, + D3D_SVT_FLOAT = 3, + D3D_SVT_STRING = 4, + D3D_SVT_TEXTURE = 5, + D3D_SVT_TEXTURE1D = 6, + D3D_SVT_TEXTURE2D = 7, + D3D_SVT_TEXTURE3D = 8, + D3D_SVT_TEXTURECUBE = 9, + D3D_SVT_SAMPLER = 10, + D3D_SVT_SAMPLER1D = 11, + D3D_SVT_SAMPLER2D = 12, + D3D_SVT_SAMPLER3D = 13, + D3D_SVT_SAMPLERCUBE = 14, + D3D_SVT_PIXELSHADER = 15, + D3D_SVT_VERTEXSHADER = 16, + D3D_SVT_PIXELFRAGMENT = 17, + D3D_SVT_VERTEXFRAGMENT = 18, + D3D_SVT_UINT = 19, + D3D_SVT_UINT8 = 20, + D3D_SVT_GEOMETRYSHADER = 21, + D3D_SVT_RASTERIZER = 22, + D3D_SVT_DEPTHSTENCIL = 23, + D3D_SVT_BLEND = 24, + D3D_SVT_BUFFER = 25, + D3D_SVT_CBUFFER = 26, + D3D_SVT_TBUFFER = 27, + D3D_SVT_TEXTURE1DARRAY = 28, + D3D_SVT_TEXTURE2DARRAY = 29, + D3D_SVT_RENDERTARGETVIEW = 30, + D3D_SVT_DEPTHSTENCILVIEW = 31, + D3D_SVT_TEXTURE2DMS = 32, + D3D_SVT_TEXTURE2DMSARRAY = 33, + D3D_SVT_TEXTURECUBEARRAY = 34, + D3D_SVT_HULLSHADER = 35, + D3D_SVT_DOMAINSHADER = 36, + D3D_SVT_INTERFACE_POINTER = 37, + D3D_SVT_COMPUTESHADER = 38, + D3D_SVT_DOUBLE = 39, + D3D_SVT_RWTEXTURE1D = 40, + D3D_SVT_RWTEXTURE1DARRAY = 41, + D3D_SVT_RWTEXTURE2D = 42, + D3D_SVT_RWTEXTURE2DARRAY = 43, + D3D_SVT_RWTEXTURE3D = 44, + D3D_SVT_RWBUFFER = 45, + D3D_SVT_BYTEADDRESS_BUFFER = 46, + D3D_SVT_RWBYTEADDRESS_BUFFER = 47, + D3D_SVT_STRUCTURED_BUFFER = 48, + D3D_SVT_RWSTRUCTURED_BUFFER = 49, + D3D_SVT_APPEND_STRUCTURED_BUFFER = 50, + D3D_SVT_CONSUME_STRUCTURED_BUFFER = 51, + D3D_SVT_MIN8FLOAT = 52, + D3D_SVT_MIN10FLOAT = 53, + D3D_SVT_MIN16FLOAT = 54, + D3D_SVT_MIN12INT = 55, + D3D_SVT_MIN16INT = 56, + D3D_SVT_MIN16UINT = 57, + + D3D10_SVT_VOID = D3D_SVT_VOID, + D3D10_SVT_BOOL = D3D_SVT_BOOL, + D3D10_SVT_INT = D3D_SVT_INT, + D3D10_SVT_FLOAT = D3D_SVT_FLOAT, + D3D10_SVT_STRING = D3D_SVT_STRING, + D3D10_SVT_TEXTURE = D3D_SVT_TEXTURE, + D3D10_SVT_TEXTURE1D = D3D_SVT_TEXTURE1D, + D3D10_SVT_TEXTURE2D = D3D_SVT_TEXTURE2D, + D3D10_SVT_TEXTURE3D = D3D_SVT_TEXTURE3D, + D3D10_SVT_TEXTURECUBE = D3D_SVT_TEXTURECUBE, + D3D10_SVT_SAMPLER = D3D_SVT_SAMPLER, + D3D10_SVT_SAMPLER1D = D3D_SVT_SAMPLER1D, + D3D10_SVT_SAMPLER2D = D3D_SVT_SAMPLER2D, + D3D10_SVT_SAMPLER3D = D3D_SVT_SAMPLER3D, + D3D10_SVT_SAMPLERCUBE = D3D_SVT_SAMPLERCUBE, + D3D10_SVT_PIXELSHADER = D3D_SVT_PIXELSHADER, + D3D10_SVT_VERTEXSHADER = D3D_SVT_VERTEXSHADER, + D3D10_SVT_PIXELFRAGMENT = D3D_SVT_PIXELFRAGMENT, + D3D10_SVT_VERTEXFRAGMENT = D3D_SVT_VERTEXFRAGMENT, + D3D10_SVT_UINT = D3D_SVT_UINT, + D3D10_SVT_UINT8 = D3D_SVT_UINT8, + D3D10_SVT_GEOMETRYSHADER = D3D_SVT_GEOMETRYSHADER, + D3D10_SVT_RASTERIZER = D3D_SVT_RASTERIZER, + D3D10_SVT_DEPTHSTENCIL = D3D_SVT_DEPTHSTENCIL, + D3D10_SVT_BLEND = D3D_SVT_BLEND, + D3D10_SVT_BUFFER = D3D_SVT_BUFFER, + D3D10_SVT_CBUFFER = D3D_SVT_CBUFFER, + D3D10_SVT_TBUFFER = D3D_SVT_TBUFFER, + D3D10_SVT_TEXTURE1DARRAY = D3D_SVT_TEXTURE1DARRAY, + D3D10_SVT_TEXTURE2DARRAY = D3D_SVT_TEXTURE2DARRAY, + D3D10_SVT_RENDERTARGETVIEW = D3D_SVT_RENDERTARGETVIEW, + D3D10_SVT_DEPTHSTENCILVIEW = D3D_SVT_DEPTHSTENCILVIEW, + D3D10_SVT_TEXTURE2DMS = D3D_SVT_TEXTURE2DMS, + D3D10_SVT_TEXTURE2DMSARRAY = D3D_SVT_TEXTURE2DMSARRAY, + D3D10_SVT_TEXTURECUBEARRAY = D3D_SVT_TEXTURECUBEARRAY, + + D3D11_SVT_HULLSHADER = D3D_SVT_HULLSHADER, + D3D11_SVT_DOMAINSHADER = D3D_SVT_DOMAINSHADER, + D3D11_SVT_INTERFACE_POINTER = D3D_SVT_INTERFACE_POINTER, + D3D11_SVT_COMPUTESHADER = D3D_SVT_COMPUTESHADER, + D3D11_SVT_DOUBLE = D3D_SVT_DOUBLE, + D3D11_SVT_RWTEXTURE1D = D3D_SVT_RWTEXTURE1D, + D3D11_SVT_RWTEXTURE1DARRAY = D3D_SVT_RWTEXTURE1DARRAY, + D3D11_SVT_RWTEXTURE2D = D3D_SVT_RWTEXTURE2D, + D3D11_SVT_RWTEXTURE2DARRAY = D3D_SVT_RWTEXTURE2DARRAY, + D3D11_SVT_RWTEXTURE3D = D3D_SVT_RWTEXTURE3D, + D3D11_SVT_RWBUFFER = D3D_SVT_RWBUFFER, + D3D11_SVT_BYTEADDRESS_BUFFER = D3D_SVT_BYTEADDRESS_BUFFER, + D3D11_SVT_RWBYTEADDRESS_BUFFER = D3D_SVT_RWBYTEADDRESS_BUFFER, + D3D11_SVT_STRUCTURED_BUFFER = D3D_SVT_STRUCTURED_BUFFER, + D3D11_SVT_RWSTRUCTURED_BUFFER = D3D_SVT_RWSTRUCTURED_BUFFER, + D3D11_SVT_APPEND_STRUCTURED_BUFFER = D3D_SVT_APPEND_STRUCTURED_BUFFER, + D3D11_SVT_CONSUME_STRUCTURED_BUFFER = D3D_SVT_CONSUME_STRUCTURED_BUFFER, + + D3D_SVT_FORCE_DWORD = 0x7fffffff, +} +D3D_SHADER_VARIABLE_TYPE; + +typedef enum D3D_TESSELLATOR_OUTPUT_PRIMITIVE +{ + D3D_TESSELLATOR_OUTPUT_UNDEFINED = 0, + D3D_TESSELLATOR_OUTPUT_POINT = 1, + D3D_TESSELLATOR_OUTPUT_LINE = 2, + D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3, + D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4, + + D3D11_TESSELLATOR_OUTPUT_UNDEFINED = D3D_TESSELLATOR_OUTPUT_UNDEFINED, + D3D11_TESSELLATOR_OUTPUT_POINT = D3D_TESSELLATOR_OUTPUT_POINT, + D3D11_TESSELLATOR_OUTPUT_LINE = D3D_TESSELLATOR_OUTPUT_LINE, + D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CW = D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW, + D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CCW = D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW, +} +D3D_TESSELLATOR_OUTPUT_PRIMITIVE; + +typedef enum D3D_TESSELLATOR_PARTITIONING +{ + D3D_TESSELLATOR_PARTITIONING_UNDEFINED = 0, + D3D_TESSELLATOR_PARTITIONING_INTEGER = 1, + D3D_TESSELLATOR_PARTITIONING_POW2 = 2, + D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3, + D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4, + + D3D11_TESSELLATOR_PARTITIONING_UNDEFINED = D3D_TESSELLATOR_PARTITIONING_UNDEFINED, + D3D11_TESSELLATOR_PARTITIONING_INTEGER = D3D_TESSELLATOR_PARTITIONING_INTEGER, + D3D11_TESSELLATOR_PARTITIONING_POW2 = D3D_TESSELLATOR_PARTITIONING_POW2, + D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD, + D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN, +} +D3D_TESSELLATOR_PARTITIONING; + +typedef enum D3D_TESSELLATOR_DOMAIN +{ + D3D_TESSELLATOR_DOMAIN_UNDEFINED = 0, + D3D_TESSELLATOR_DOMAIN_ISOLINE = 1, + D3D_TESSELLATOR_DOMAIN_TRI = 2, + D3D_TESSELLATOR_DOMAIN_QUAD = 3, + + D3D11_TESSELLATOR_DOMAIN_UNDEFINED = D3D_TESSELLATOR_DOMAIN_UNDEFINED, + D3D11_TESSELLATOR_DOMAIN_ISOLINE = D3D_TESSELLATOR_DOMAIN_ISOLINE, + D3D11_TESSELLATOR_DOMAIN_TRI = D3D_TESSELLATOR_DOMAIN_TRI, + D3D11_TESSELLATOR_DOMAIN_QUAD = D3D_TESSELLATOR_DOMAIN_QUAD, +} +D3D_TESSELLATOR_DOMAIN; + diff --git a/3rdparty/d3d4linux/include/d3d4linux_impl.h b/3rdparty/d3d4linux/include/d3d4linux_impl.h new file mode 100644 index 000000000..63d4f322e --- /dev/null +++ b/3rdparty/d3d4linux/include/d3d4linux_impl.h @@ -0,0 +1,335 @@ +// +// D3D4Linux — access Direct3D DLLs from Linux programs +// +// Copyright © 2016 Sam Hocevar +// +// This library is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +#include /* for uint32_t */ +#include /* for size_t */ +#include /* for FILE */ +#include /* for strcmp() */ + +#include /* for fork() */ +#include /* for waitpid() */ +#include /* for O_WRONLY */ + +#include /* for std::string */ + +#include + +struct d3d4linux +{ + static int &compiler_version() + { + static int ret = 0; + return ret; + } + + static HRESULT compile(void const *pSrcData, + size_t SrcDataSize, + char const *pFileName, + D3D_SHADER_MACRO const *pDefines, + ID3DInclude *pInclude, + char const *pEntrypoint, + char const *pTarget, + uint32_t Flags1, + uint32_t Flags2, + ID3DBlob **ppCode, + ID3DBlob **ppErrorMsgs) + { + fork_process p; + if (p.error()) + { + static char const *error_msg = "Cannot fork in d3d4linux::compile()"; + *ppErrorMsgs = new ID3DBlob(strlen(error_msg)); + memcpy((*ppErrorMsgs)->GetBufferPointer(), error_msg, (*ppErrorMsgs)->GetBufferSize()); + return E_FAIL; + } + + p.write_i64(D3D4LINUX_OP_COMPILE); + p.write_string((char const *)pSrcData); + p.write_i64(pFileName ? 1 : 0); + p.write_string(pFileName ? pFileName : ""); + p.write_string(pEntrypoint); + p.write_string(pTarget); + p.write_i64(Flags1); + p.write_i64(Flags2); + p.write_i64(D3D4LINUX_FINISHED); + + HRESULT ret = p.read_i64(); + ID3DBlob *code_blob = p.read_blob(); + ID3DBlob *error_blob = p.read_blob(); + int end = p.read_i64(); + if (end != D3D4LINUX_FINISHED) + return E_FAIL; + + *ppCode = code_blob; + *ppErrorMsgs = error_blob; + return ret; + } + + static HRESULT reflect(void const *pSrcData, + size_t SrcDataSize, + REFIID pInterface, + void **ppReflector) + { + fork_process p; + if (p.error()) + return E_FAIL; + + p.write_i64(D3D4LINUX_OP_REFLECT); + p.write_i64(SrcDataSize); + p.write_raw(pSrcData, SrcDataSize); + p.write_i64(D3D4LINUX_IID_SHADER_REFLECTION); + p.write_i64(D3D4LINUX_FINISHED); + + HRESULT ret = p.read_i64(); + + if (SUCCEEDED(ret) ) //&& pInterface == IID_ID3D11ShaderReflection) + { + ID3D11ShaderReflection *r = new ID3D11ShaderReflection; + + p.read_raw(&r->m_desc, sizeof(r->m_desc)); + r->m_strings.push_back(p.read_string()); + + for (uint32_t i = 0; i < r->m_desc.InputParameters; ++i) + { + r->m_input_params.push_back(D3D11_SIGNATURE_PARAMETER_DESC()); + p.read_raw(&r->m_input_params.back(), sizeof(r->m_input_params.back())); + r->m_strings.push_back(p.read_string()); + } + + for (uint32_t i = 0; i < r->m_desc.OutputParameters; ++i) + { + r->m_output_params.push_back(D3D11_SIGNATURE_PARAMETER_DESC()); + p.read_raw(&r->m_output_params.back(), sizeof(r->m_output_params.back())); + r->m_strings.push_back(p.read_string()); + } + + for (uint32_t i = 0; i < r->m_desc.BoundResources; ++i) + { + r->m_binds.push_back(D3D11_SHADER_INPUT_BIND_DESC()); + p.read_raw(&r->m_binds.back(), sizeof(r->m_binds.back())); + r->m_strings.push_back(p.read_string()); + } + + for (uint32_t i = 0; i < r->m_desc.ConstantBuffers; ++i) + { + r->m_buffers.push_back(ID3D11ShaderReflectionConstantBuffer()); + ID3D11ShaderReflectionConstantBuffer &buf = r->m_buffers.back(); + + p.read_raw(&buf.m_desc, sizeof(buf.m_desc)); + buf.m_strings.push_back(p.read_string()); + + for (uint32_t j = 0; j < buf.m_desc.Variables; ++j) + { + buf.m_variables.push_back(ID3D11ShaderReflectionVariable()); + ID3D11ShaderReflectionVariable &var = buf.m_variables.back(); + + p.read_raw(&var.m_desc, sizeof(var.m_desc)); + var.m_desc.uFlags |= D3D_SVF_USED; // Force all uniforms to be marked as used + var.m_strings.push_back(p.read_string()); + var.m_has_default = p.read_i64(); + if (var.m_has_default) + { + var.m_default_value.resize(var.m_desc.Size); + p.read_raw(var.m_default_value.data(), var.m_desc.Size); + } + + // Read D3D11_SHADER_TYPE_DESC for this variable + p.read_raw(&var.m_type.m_desc, sizeof(var.m_type.m_desc)); + var.m_type.m_name = p.read_string(); + } + } + + *ppReflector = r; + } + + int end = p.read_i64(); + if (end != D3D4LINUX_FINISHED) + return E_FAIL; + + return ret; + } + + static HRESULT strip_shader(void const *pShaderBytecode, + size_t BytecodeLength, + uint32_t uStripFlags, + ID3DBlob **ppStrippedBlob) + { + fork_process p; + if (p.error()) + return E_FAIL; + + p.write_i64(D3D4LINUX_OP_STRIP); + p.write_i64(BytecodeLength); + p.write_raw(pShaderBytecode, BytecodeLength); + p.write_i64(uStripFlags); + p.write_i64(D3D4LINUX_FINISHED); + + HRESULT ret = p.read_i64(); + ID3DBlob *strip_blob = p.read_blob(); + int end = p.read_i64(); + if (end != D3D4LINUX_FINISHED) + return E_FAIL; + + *ppStrippedBlob = strip_blob; + return ret; + } + + static HRESULT disassemble(void const *pSrcData, + size_t SrcDataSize, + uint32_t Flags, + char const *szComments, + ID3DBlob **ppDisassembly) + { + fork_process p; + if (p.error()) + return E_FAIL; + + p.write_i64(D3D4LINUX_OP_DISASSEMBLE); + p.write_i64(SrcDataSize); + p.write_raw(pSrcData, SrcDataSize); + p.write_i64(Flags); + p.write_i64(szComments ? 1 : 0); + if (szComments) + p.write_string(szComments); + p.write_i64(D3D4LINUX_FINISHED); + + HRESULT ret = p.read_i64(); + ID3DBlob *disassembly_blob = p.read_blob(); + int end = p.read_i64(); + if (end != D3D4LINUX_FINISHED) + return E_FAIL; + + *ppDisassembly = disassembly_blob; + return ret; + } + + static HRESULT create_blob(size_t Size, + ID3DBlob **ppBlob) + { + *ppBlob = new ID3DBlob(Size); + return S_OK; + } + +private: + struct fork_process : interop + { + public: + fork_process() + : interop(nullptr, nullptr), + m_pid(-1) + { + static thread_local pid_t pid = -1; + static thread_local int pipe_read[2], pipe_write[2]; + static thread_local FILE *in, *out; + + /* If this is the first run in this thread, then fork a new + * child process. */ + if (pid < 0) + { + pipe(pipe_read); + pipe(pipe_write); + + pid = fork(); + + if (pid == 0) + { + dup2(pipe_write[0], STDIN_FILENO); + dup2(pipe_read[1], STDOUT_FILENO); + + char const *verbose_var = getenv("D3D4LINUX_VERBOSE"); + if (!verbose_var || *verbose_var != '1') + dup2(open("/dev/null", O_WRONLY), STDERR_FILENO); + + char const *exe_var = getenv("D3D4LINUX_EXE"); + if (!exe_var) + exe_var = D3D4LINUX_EXE; + + char const *wine_var = getenv("D3D4LINUX_WINE"); + if (!wine_var) + { + // Try Wine 11+ path first, then fall back to wine64 + wine_var = D3D4LINUX_WINE; + if (access(wine_var, X_OK) != 0) + { +#if defined(D3D4LINUX_WINE_FALLBACK) + wine_var = D3D4LINUX_WINE_FALLBACK; +#endif + } + } + + close(pipe_read[0]); + close(pipe_read[1]); + close(pipe_write[0]); + close(pipe_write[1]); + + static char *const argv[] = { (char *)"wine", (char *)exe_var, 0 }; + execv(wine_var, argv); + /* Never going past here */ + } + + close(pipe_write[0]); + close(pipe_read[1]); + + if (pid > 0) + { + in = fdopen(pipe_read[0], "r"); + out = fdopen(pipe_write[1], "w"); + } + } + + m_pid = pid; + m_pipe_in = pipe_read[0]; + m_pipe_out = pipe_write[1]; + m_in = in; + m_out = out; + } + + ~fork_process() + { + /* FIXME: we cannot close anything here since the child + * process is persistent across calls. */ +#if 0 + if (m_pid > 0) + { + waitpid(m_pid, nullptr, 0); + fclose(m_in); + fclose(m_out); + } + + close(m_pipe_in); + close(m_pipe_out); +#endif + } + + bool error() const + { + return m_pid <= 0; + } + + ID3DBlob *read_blob() + { + int len = read_i64(); + if (len < 0) + return nullptr; + + ID3DBlob *blob = new ID3DBlob(len); + read_raw(blob->GetBufferPointer(), len); + return blob; + } + + private: + int m_pipe_in, m_pipe_out; + pid_t m_pid; + }; +}; diff --git a/3rdparty/d3d4linux/include/d3d4linux_types.h b/3rdparty/d3d4linux/include/d3d4linux_types.h new file mode 100644 index 000000000..19b622299 --- /dev/null +++ b/3rdparty/d3d4linux/include/d3d4linux_types.h @@ -0,0 +1,128 @@ +// +// D3D4Linux — access Direct3D DLLs from Linux programs +// +// Copyright © 2016 Sam Hocevar +// +// This library is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +struct D3D_SHADER_MACRO +{ + char const *Name; + char const *Definition; +}; + +struct D3D_SHADER_DATA +{ + void const *pBytecode; + size_t BytecodeLength; +}; + +struct D3D11_SIGNATURE_PARAMETER_DESC +{ + char const *SemanticName; // 8 bytes (pointer) + uint32_t SemanticIndex; // 4 bytes + uint32_t Register; // 4 bytes + D3D_NAME SystemValueType; // 4 bytes (enum) + D3D_REGISTER_COMPONENT_TYPE ComponentType; // 4 bytes (enum) + uint8_t Mask; // 1 byte + uint8_t ReadWriteMask; // 1 byte + uint8_t _padding[2]; // 2 bytes padding for alignment + uint32_t Stream; // 4 bytes + D3D_MIN_PRECISION MinPrecision; // 4 bytes (enum) + 4 bytes padding = 40 total +}; + +struct D3D11_SHADER_INPUT_BIND_DESC +{ + char const *Name; + D3D_SHADER_INPUT_TYPE Type; + uint32_t BindPoint; + uint32_t BindCount; + uint32_t uFlags; + D3D_RESOURCE_RETURN_TYPE ReturnType; + D3D_SRV_DIMENSION Dimension; + uint32_t NumSamples; +}; + +struct D3D11_SHADER_DESC +{ + uint32_t Version; + char const *Creator; + uint32_t Flags; + uint32_t ConstantBuffers; + uint32_t BoundResources; + uint32_t InputParameters; + uint32_t OutputParameters; + uint32_t InstructionCount; + uint32_t TempRegisterCount; + uint32_t TempArrayCount; + uint32_t DefCount; + uint32_t DclCount; + uint32_t TextureNormalInstructions; + uint32_t TextureLoadInstructions; + uint32_t TextureCompInstructions; + uint32_t TextureBiasInstructions; + uint32_t TextureGradientInstructions; + uint32_t FloatInstructionCount; + uint32_t IntInstructionCount; + uint32_t UintInstructionCount; + uint32_t StaticFlowControlCount; + uint32_t DynamicFlowControlCount; + uint32_t MacroInstructionCount; + uint32_t ArrayInstructionCount; + uint32_t CutInstructionCount; + uint32_t EmitInstructionCount; + D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; + uint32_t GSMaxOutputVertexCount; + D3D_PRIMITIVE InputPrimitive; + uint32_t PatchConstantParameters; + uint32_t cGSInstanceCount; + uint32_t cControlPoints; + D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; + D3D_TESSELLATOR_PARTITIONING HSPartitioning; + D3D_TESSELLATOR_DOMAIN TessellatorDomain; + uint32_t cBarrierInstructions; + uint32_t cInterlockedInstructions; + uint32_t cTextureStoreInstructions; +}; + +struct D3D11_SHADER_TYPE_DESC +{ + D3D_SHADER_VARIABLE_CLASS Class; + D3D_SHADER_VARIABLE_TYPE Type; + uint32_t Rows; + uint32_t Columns; + uint32_t Elements; + uint32_t Members; + uint32_t Offset; + char const *Name; +}; + +struct D3D11_SHADER_VARIABLE_DESC +{ + char const *Name; + uint32_t StartOffset; + uint32_t Size; + uint32_t uFlags; + void *DefaultValue; + uint32_t StartTexture; + uint32_t TextureSize; + uint32_t StartSampler; + uint32_t SamplerSize; +}; + +struct D3D11_SHADER_BUFFER_DESC +{ + char const *Name; + D3D_CBUFFER_TYPE Type; + uint32_t Variables; + uint32_t Size; + uint32_t uFlags; +}; + diff --git a/3rdparty/directx-headers/include/wsl/winadapter.h b/3rdparty/directx-headers/include/wsl/winadapter.h index ccb2b3c12..2ff022bae 100644 --- a/3rdparty/directx-headers/include/wsl/winadapter.h +++ b/3rdparty/directx-headers/include/wsl/winadapter.h @@ -3,4 +3,6 @@ #pragma once +#define WSL_WINADAPTER_H + #include diff --git a/examples/runtime/shaders/dx11/fs_cubes.bin b/examples/runtime/shaders/dx11/fs_cubes.bin index ad8da66e3..b56f9a513 100644 Binary files a/examples/runtime/shaders/dx11/fs_cubes.bin and b/examples/runtime/shaders/dx11/fs_cubes.bin differ diff --git a/examples/runtime/shaders/dx11/vs_cubes.bin b/examples/runtime/shaders/dx11/vs_cubes.bin deleted file mode 100644 index 762007cc9..000000000 Binary files a/examples/runtime/shaders/dx11/vs_cubes.bin and /dev/null differ diff --git a/scripts/shaderc.lua b/scripts/shaderc.lua index 25cef8f6d..cca6d5a8c 100644 --- a/scripts/shaderc.lua +++ b/scripts/shaderc.lua @@ -12,6 +12,7 @@ local SPIRV_CROSS = path.join(BGFX_DIR, "3rdparty/spirv-cross") local SPIRV_HEADERS = path.join(BGFX_DIR, "3rdparty/spirv-headers") local SPIRV_TOOLS = path.join(BGFX_DIR, "3rdparty/spirv-tools") local TINT = path.join(BGFX_DIR, "3rdparty/dawn") +local D3D4LINUX = path.join(BGFX_DIR, "3rdparty/d3d4linux") project "tint-core" kind "StaticLib" @@ -749,8 +750,11 @@ project "shaderc" "pthread", } - configuration { "linux-*" } + -- Linux/macOS: d3d4linux for legacy HLSL (SM 5.0) + -- Linux only: directx-headers for DXIL (SM 6.0+, no macOS DXC library available) + configuration { "linux* or osx*" } includedirs { + path.join(D3D4LINUX, "include"), path.join(BGFX_DIR, "3rdparty/directx-headers/include"), path.join(BGFX_DIR, "3rdparty/directx-headers/include/wsl/stubs"), } diff --git a/tools/shaderc/shaderc.h b/tools/shaderc/shaderc.h index 09bef9eb5..f68398265 100644 --- a/tools/shaderc/shaderc.h +++ b/tools/shaderc/shaderc.h @@ -11,14 +11,24 @@ namespace bgfx extern bool g_verbose; } +// HLSL compilation support: +// - Windows: Native D3DCompiler DLL +// - Linux/macOS: d3d4linux (Wine-based D3DCompiler via IPC) #ifndef SHADERC_CONFIG_HLSL -# define SHADERC_CONFIG_HLSL BX_PLATFORM_WINDOWS +# define SHADERC_CONFIG_HLSL (0 \ + || BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_LINUX \ + ) #endif // SHADERC_CONFIG_HLSL +// DXIL compilation support (Shader Model 6.0+): +// - Windows: Native DXC (dxcompiler.dll) +// - Linux: DXC (libdxcompiler.so) via directx-headers +// - macOS: Not supported (no DXC dynamic library available) #ifndef SHADERC_CONFIG_DXIL -# define SHADERC_CONFIG_DXIL (0 \ - || BX_PLATFORM_WINDOWS \ - || BX_PLATFORM_LINUX \ +# define SHADERC_CONFIG_DXIL (0 \ + || BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_LINUX \ ) #endif // SHADERC_CONFIG_DXIL diff --git a/tools/shaderc/shaderc_hlsl.cpp b/tools/shaderc/shaderc_hlsl.cpp index 878f79755..99cb5f36a 100644 --- a/tools/shaderc/shaderc_hlsl.cpp +++ b/tools/shaderc/shaderc_hlsl.cpp @@ -14,8 +14,13 @@ #endif // defined(__MINGW32__) #define COM_NO_WINDOWS_H -#include -#include +#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX +# include +# include +#else +# include +# include +#endif // BX_PLATFORM_LINUX || BX_PLATFORM_OSX #include #ifndef D3D_SVF_USED @@ -24,36 +29,40 @@ namespace bgfx { namespace hlsl { - typedef HRESULT(WINAPI* PFN_D3D_COMPILE)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData - , _In_ SIZE_T SrcDataSize - , _In_opt_ LPCSTR pSourceName - , _In_reads_opt_(_Inexpressible_(pDefines->Name != NULL) ) CONST D3D_SHADER_MACRO* pDefines - , _In_opt_ ID3DInclude* pInclude - , _In_opt_ LPCSTR pEntrypoint - , _In_ LPCSTR pTarget - , _In_ UINT Flags1 - , _In_ UINT Flags2 - , _Out_ ID3DBlob** ppCode - , _Always_(_Outptr_opt_result_maybenull_) ID3DBlob** ppErrorMsgs + typedef HRESULT(WINAPI* PFN_D3D_COMPILE)( + LPCVOID pSrcData + , SIZE_T SrcDataSize + , LPCSTR pSourceName + , CONST D3D_SHADER_MACRO* pDefines + , ID3DInclude* pInclude + , LPCSTR pEntrypoint + , LPCSTR pTarget + , UINT Flags1 + , UINT Flags2 + , ID3DBlob** ppCode + , ID3DBlob** ppErrorMsgs ); - typedef HRESULT(WINAPI* PFN_D3D_DISASSEMBLE)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData - , _In_ SIZE_T SrcDataSize - , _In_ UINT Flags - , _In_opt_ LPCSTR szComments - , _Out_ ID3DBlob** ppDisassembly + typedef HRESULT(WINAPI* PFN_D3D_DISASSEMBLE)( + LPCVOID pSrcData + , SIZE_T SrcDataSize + , UINT Flags + , LPCSTR szComments + , ID3DBlob** ppDisassembly ); - typedef HRESULT(WINAPI* PFN_D3D_REFLECT)(_In_reads_bytes_(SrcDataSize) LPCVOID pSrcData - , _In_ SIZE_T SrcDataSize - , _In_ REFIID pInterface - , _Out_ void** ppReflector + typedef HRESULT(WINAPI* PFN_D3D_REFLECT)( + LPCVOID pSrcData + , SIZE_T SrcDataSize + , REFIID pInterface + , void** ppReflector ); - typedef HRESULT(WINAPI* PFN_D3D_STRIP_SHADER)(_In_reads_bytes_(BytecodeLength) LPCVOID pShaderBytecode - , _In_ SIZE_T BytecodeLength - , _In_ UINT uStripFlags - , _Out_ ID3DBlob** ppStrippedBlob + typedef HRESULT(WINAPI* PFN_D3D_STRIP_SHADER)( + LPCVOID pShaderBytecode + , SIZE_T BytecodeLength + , UINT uStripFlags + , ID3DBlob** ppStrippedBlob ); PFN_D3D_COMPILE D3DCompile; @@ -64,7 +73,7 @@ namespace bgfx { namespace hlsl struct D3DCompiler { const char* fileName; - const GUID IID_ID3D11ShaderReflection; + const GUID reflectionGuid; }; static const D3DCompiler s_d3dcompiler[] = @@ -78,10 +87,59 @@ namespace bgfx { namespace hlsl }; static const D3DCompiler* s_compiler = NULL; + +#if BX_PLATFORM_WINDOWS static void* s_d3dcompilerdll = NULL; +#endif // BX_PLATFORM_WINDOWS const D3DCompiler* load(bx::WriterI* _messageWriter) { +#if BX_PLATFORM_LINUX || BX_PLATFORM_OSX + BX_TRACE("Using d3d4linux for HLSL compilation (Wine-based D3DCompiler)."); + + bx::Error messageErr; + bx::FileInfo fi; + + bx::FilePath executableDir = bx::FilePath(bx::Dir::Executable).getPath(); + + bx::FilePath d3d4linuxExe(executableDir); + d3d4linuxExe.join("../windows/d3d4linux.exe"); + + if (bx::stat(fi, d3d4linuxExe) ) + { + bx::setEnv("D3D4LINUX_EXE", d3d4linuxExe); + } + else + { + bx::write(_messageWriter, &messageErr, "Error: `%s` not found.\n", d3d4linuxExe.getCPtr() ); + return NULL; + } + + bx::FilePath d3d4linuxDll(executableDir); + d3d4linuxDll.join("../windows/d3dcompiler_47.dll"); + + if (bx::stat(fi, d3d4linuxDll) ) + { + bx::setEnv("D3D4LINUX_DLL", d3d4linuxDll); + } + else + { + bx::write(_messageWriter, &messageErr, "Error: `%s` not found.\n", d3d4linuxDll.getCPtr() ); + return NULL; + } + + if (g_verbose) + { + bx::setEnv("D3D4LINUX_VERBOSE", "1"); + } + + D3DCompile = (PFN_D3D_COMPILE )&d3d4linux::compile; + D3DReflect = (PFN_D3D_REFLECT )&d3d4linux::reflect; + D3DDisassemble = (PFN_D3D_DISASSEMBLE )&d3d4linux::disassemble; + D3DStripShader = (PFN_D3D_STRIP_SHADER)&d3d4linux::strip_shader; + + return &s_d3dcompiler[0]; +#else if (NULL != s_d3dcompilerdll) { return s_compiler; @@ -109,6 +167,7 @@ namespace bgfx { namespace hlsl || NULL == D3DStripShader) { bx::dlclose(s_d3dcompilerdll); + s_d3dcompilerdll = NULL; continue; } @@ -124,15 +183,18 @@ namespace bgfx { namespace hlsl bx::write(_messageWriter, &messageErr, "Error: Unable to open D3DCompiler_*.dll shader compiler.\n"); return NULL; +#endif // BX_PLATFORM_LINUX || BX_PLATFORM_OSX } void unload() { +#if BX_PLATFORM_WINDOWS if (NULL != s_d3dcompilerdll) { bx::dlclose(s_d3dcompilerdll); s_d3dcompilerdll = NULL; } +#endif // BX_PLATFORM_WINDOWS s_compiler = NULL; D3DCompile = NULL; @@ -214,7 +276,7 @@ namespace bgfx { namespace hlsl const UniformRemap& remap = s_uniformRemap[ii]; if (remap.paramClass == constDesc.Class - && remap.paramType == constDesc.Type) + && remap.paramType == constDesc.Type) { if (D3D_SVC_MATRIX_COLUMNS != constDesc.Class) { @@ -222,7 +284,7 @@ namespace bgfx { namespace hlsl } if (remap.columns == constDesc.Columns - && remap.rows == constDesc.Rows) + && remap.rows == constDesc.Rows) { return remap.id; } @@ -249,9 +311,10 @@ namespace bgfx { namespace hlsl ID3D11ShaderReflection* reflect = NULL; HRESULT hr = D3DReflect(_code->GetBufferPointer() , _code->GetBufferSize() - , s_compiler->IID_ID3D11ShaderReflection + , s_compiler->reflectionGuid , (void**)&reflect ); + if (FAILED(hr) ) { bx::write(_messageWriter, &messageErr, "Error: D3DReflect failed 0x%08x\n", (uint32_t)hr); @@ -427,6 +490,11 @@ namespace bgfx { namespace hlsl bx::strCat(profileAndType, BX_COUNTOF(profileAndType), profile); s_compiler = load(_messageWriter); + if (NULL == s_compiler) + { + bx::write(_messageWriter, &messageErr, "Error: Unabled to load D3D compiler!\n"); + return false; + } bool result = false; bool debug = _options.debugInformation; @@ -519,7 +587,7 @@ namespace bgfx { namespace hlsl } printCode(_code.c_str(), line, start, end, column); - bx::write(_messageWriter, &messageErr, "Error: D3DCompile failed 0x%08x %s\n", (uint32_t)hr, log); + bx::write(_messageWriter, &messageErr, "Error: D3DCompile failed 0x%08x `%s`\n", (uint32_t)hr, log); errorMsg->Release(); return false; }