mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-04-21 10:58:44 +00:00
feat: compile shaders on linux via vkd3d
This commit is contained in:
@@ -5,12 +5,15 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#else
|
||||||
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -64,6 +67,19 @@ namespace
|
|||||||
#define OAT_D3DCOMPILE_DEBUG_NAME_FOR_SOURCE 0x00400000
|
#define OAT_D3DCOMPILE_DEBUG_NAME_FOR_SOURCE 0x00400000
|
||||||
#define OAT_D3DCOMPILE_DEBUG_NAME_FOR_BINARY 0x00800000
|
#define OAT_D3DCOMPILE_DEBUG_NAME_FOR_BINARY 0x00800000
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#ifdef __x86_64__
|
||||||
|
#define __stdcall __attribute__((ms_abi))
|
||||||
|
#else
|
||||||
|
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || defined(__APPLE__)
|
||||||
|
#define __stdcall __attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))
|
||||||
|
#else
|
||||||
|
#define __stdcall __attribute__((__stdcall__))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#define STDMETHODCALLTYPE __stdcall
|
||||||
|
|
||||||
enum OAT_D3D_INCLUDE_TYPE : uint32_t
|
enum OAT_D3D_INCLUDE_TYPE : uint32_t
|
||||||
{
|
{
|
||||||
OAT_D3D_INCLUDE_LOCAL = 0,
|
OAT_D3D_INCLUDE_LOCAL = 0,
|
||||||
@@ -72,9 +88,10 @@ namespace
|
|||||||
|
|
||||||
struct OAT_ID3DInclude
|
struct OAT_ID3DInclude
|
||||||
{
|
{
|
||||||
virtual OAT_HRESULT __stdcall Open(
|
// clang-format off
|
||||||
OAT_D3D_INCLUDE_TYPE includeType, const char* fileName, const void* parentData, const void** data, unsigned int* size) = 0;
|
virtual OAT_HRESULT STDMETHODCALLTYPE Open(OAT_D3D_INCLUDE_TYPE includeType, const char* fileName, const void* parentData, const void** data, unsigned int* size) = 0;
|
||||||
virtual OAT_HRESULT __stdcall Close(const void* data) = 0;
|
virtual OAT_HRESULT STDMETHODCALLTYPE Close(const void* data) = 0;
|
||||||
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OAT_GUID
|
struct OAT_GUID
|
||||||
@@ -89,18 +106,18 @@ namespace
|
|||||||
|
|
||||||
struct OAT_IUnknown
|
struct OAT_IUnknown
|
||||||
{
|
{
|
||||||
virtual OAT_HRESULT __stdcall QueryInterface(const OAT_IID& riid, void** object) = 0;
|
virtual OAT_HRESULT STDMETHODCALLTYPE QueryInterface(const OAT_IID& riid, void** object) = 0;
|
||||||
|
|
||||||
virtual OAT_ULONG __stdcall AddRef() = 0;
|
virtual OAT_ULONG STDMETHODCALLTYPE AddRef() = 0;
|
||||||
|
|
||||||
virtual OAT_ULONG __stdcall Release() = 0;
|
virtual OAT_ULONG STDMETHODCALLTYPE Release() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OAT_ID3DBlob : OAT_IUnknown
|
struct OAT_ID3DBlob : OAT_IUnknown
|
||||||
{
|
{
|
||||||
virtual void* __stdcall GetBufferPointer() = 0;
|
virtual void* STDMETHODCALLTYPE GetBufferPointer() = 0;
|
||||||
|
|
||||||
virtual OAT_SIZE_T __stdcall GetBufferSize() = 0;
|
virtual OAT_SIZE_T STDMETHODCALLTYPE GetBufferSize() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OAT_D3D_SHADER_MACRO
|
struct OAT_D3D_SHADER_MACRO
|
||||||
@@ -109,7 +126,7 @@ namespace
|
|||||||
const char* Definition;
|
const char* Definition;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef OAT_HRESULT(__stdcall* D3DCompile_t)(const void* data,
|
typedef OAT_HRESULT(STDMETHODCALLTYPE* D3DCompile_t)(const void* data,
|
||||||
OAT_SIZE_T dataSize,
|
OAT_SIZE_T dataSize,
|
||||||
const char* filename,
|
const char* filename,
|
||||||
const OAT_D3D_SHADER_MACRO* defines,
|
const OAT_D3D_SHADER_MACRO* defines,
|
||||||
@@ -132,7 +149,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
OAT_HRESULT
|
OAT_HRESULT
|
||||||
__stdcall Open(OAT_D3D_INCLUDE_TYPE includeType, const char* fileName, const void* parentData, const void** data, unsigned int* size) override
|
STDMETHODCALLTYPE Open(OAT_D3D_INCLUDE_TYPE includeType, const char* fileName, const void* parentData, const void** data, unsigned int* size) override
|
||||||
{
|
{
|
||||||
const auto fullFileName = shader::GetSourceFileNameForShaderAssetName(fileName);
|
const auto fullFileName = shader::GetSourceFileNameForShaderAssetName(fileName);
|
||||||
auto file = m_search_path.Open(fullFileName);
|
auto file = m_search_path.Open(fullFileName);
|
||||||
@@ -158,7 +175,7 @@ namespace
|
|||||||
return OAT_S_OK;
|
return OAT_S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
OAT_HRESULT __stdcall Close(const void* data) override
|
OAT_HRESULT STDMETHODCALLTYPE Close(const void* data) override
|
||||||
{
|
{
|
||||||
for (auto i = m_file_buffers_in_use.begin(); i != m_file_buffers_in_use.end(); ++i)
|
for (auto i = m_file_buffers_in_use.begin(); i != m_file_buffers_in_use.end(); ++i)
|
||||||
{
|
{
|
||||||
@@ -185,6 +202,13 @@ namespace
|
|||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
con::warn("Could not initialize shader compilation. Make sure DirectX is installed on your machine if you want to make use of it.");
|
con::warn("Could not initialize shader compilation. Make sure DirectX is installed on your machine if you want to make use of it.");
|
||||||
|
#else
|
||||||
|
#ifdef ARCH_x86
|
||||||
|
#define REQUIRED_VKD3D "lib32-vkd3d"
|
||||||
|
#else
|
||||||
|
#define REQUIRED_VKD3D "vkd3d"
|
||||||
|
#endif
|
||||||
|
con::warn("Could not initialize shader compilation. Make sure " REQUIRED_VKD3D " is installed if you want to make use of it.");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,6 +231,23 @@ namespace
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d3dCompile = reinterpret_cast<D3DCompile_t>(d3dCompileAddress);
|
||||||
|
compilationAvailable = true;
|
||||||
|
#else
|
||||||
|
const auto libvkd3dUtils = dlopen("libvkd3d-utils.so", RTLD_NOW);
|
||||||
|
if (!libvkd3dUtils)
|
||||||
|
{
|
||||||
|
PrintInitializationFailedMessage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto d3dCompileAddress = dlsym(libvkd3dUtils, "D3DCompile");
|
||||||
|
if (!d3dCompileAddress)
|
||||||
|
{
|
||||||
|
PrintInitializationFailedMessage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
d3dCompile = reinterpret_cast<D3DCompile_t>(d3dCompileAddress);
|
d3dCompile = reinterpret_cast<D3DCompile_t>(d3dCompileAddress);
|
||||||
compilationAvailable = true;
|
compilationAvailable = true;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user