diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 440af547..5f946766 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -124,6 +124,4 @@ set(CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL}) add_subdirectory(Core) add_subdirectory(Tests) add_subdirectory(Tools) -if(SC_WITH_CSHARP) - add_subdirectory(Wrapper) -endif() +add_subdirectory(Wrapper) diff --git a/Source/Core/ShaderConductor.cpp b/Source/Core/ShaderConductor.cpp index 7eab82fa..d51691d5 100644 --- a/Source/Core/ShaderConductor.cpp +++ b/Source/Core/ShaderConductor.cpp @@ -128,7 +128,23 @@ namespace const char* functionName = "DxcCreateInstance"; #ifdef _WIN32 - m_dxcompilerDll = ::LoadLibraryA(dllName); + HMODULE hm = NULL; + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) "DllMain", + &hm) != 0) + { + char path[MAX_PATH]; + if (GetModuleFileName(hm, path, sizeof(path)) != 0) + { + PathRemoveFileSpec(path); + char finalPath[MAX_PATH]; + m_dxcompilerDll = ::LoadLibraryA(PathCombine(finalPath, path, dllName)); + } + } + + if (m_dxcompilerDll == nullptr) + { + m_dxcompilerDll = ::LoadLibraryA(dllName); + } #else m_dxcompilerDll = ::dlopen(dllName, RTLD_LAZY); #endif @@ -719,6 +735,8 @@ namespace for (auto& remap : compiler->get_combined_image_samplers()) { + uint32_t binding = compiler->get_decoration(remap.image_id, spv::DecorationBinding); // or sampler_id. + compiler->set_decoration(remap.combined_id, spv::DecorationBinding, binding); compiler->set_name(remap.combined_id, "SPIRV_Cross_Combined" + compiler->get_name(remap.image_id) + compiler->get_name(remap.sampler_id)); } diff --git a/Source/Tests/Data/Expected/ToneMapping_PS.310.essl b/Source/Tests/Data/Expected/ToneMapping_PS.310.essl index c7f216fb..141520f7 100644 --- a/Source/Tests/Data/Expected/ToneMapping_PS.310.essl +++ b/Source/Tests/Data/Expected/ToneMapping_PS.310.essl @@ -7,9 +7,9 @@ layout(binding = 0, std140) uniform type_cbPS highp float lumStrength; } cbPS; -uniform highp sampler2D SPIRV_Cross_CombinedcolorTexpointSampler; -uniform highp sampler2D SPIRV_Cross_CombinedbloomTexlinearSampler; -uniform highp sampler2D SPIRV_Cross_CombinedlumTexpointSampler; +layout(binding = 0) uniform highp sampler2D SPIRV_Cross_CombinedcolorTexpointSampler; +layout(binding = 2) uniform highp sampler2D SPIRV_Cross_CombinedbloomTexlinearSampler; +layout(binding = 1) uniform highp sampler2D SPIRV_Cross_CombinedlumTexpointSampler; layout(location = 0) in highp vec2 in_var_TEXCOORD0; layout(location = 0) out highp vec4 out_var_SV_Target; diff --git a/Source/Wrapper/CMakeLists.txt b/Source/Wrapper/CMakeLists.txt index 739c53e6..8805ba39 100644 --- a/Source/Wrapper/CMakeLists.txt +++ b/Source/Wrapper/CMakeLists.txt @@ -22,24 +22,28 @@ add_dependencies(${DLL_NAME} ShaderConductor) set_target_properties(${DLL_NAME} PROPERTIES FOLDER "Wrapper") -set(CSHARP_TEST CSharpPinvoke) +if(SC_WITH_CSHARP) -set(SOURCE_FILES - Program.cs - Wrapper.cs -) + set(CSHARP_TEST CSharpPinvoke) -set(DATA_FILES - shader.hlsl -) + set(SOURCE_FILES + Program.cs + Wrapper.cs + ) -set_source_files_properties(${DATA_FILES} - PROPERTIES VS_TOOL_OVERRIDE "None" - VS_COPY_TO_OUT_DIR "PreserveNewest" -) + set(DATA_FILES + shader.hlsl + ) + + set_source_files_properties(${DATA_FILES} + PROPERTIES VS_TOOL_OVERRIDE "None" + VS_COPY_TO_OUT_DIR "PreserveNewest" + ) + + add_executable(${CSHARP_TEST} ${SOURCE_FILES} ${DATA_FILES}) + add_dependencies(${CSHARP_TEST} ShaderConductorWrapper) -add_executable(${CSHARP_TEST} ${SOURCE_FILES} ${DATA_FILES}) -add_dependencies(${CSHARP_TEST} ShaderConductorWrapper) + set_target_properties(${CSHARP_TEST} PROPERTIES FOLDER "Wrapper") -set_target_properties(${CSHARP_TEST} PROPERTIES FOLDER "Wrapper") +endif() diff --git a/Source/Wrapper/Native.cpp b/Source/Wrapper/Native.cpp index c1bc26fb..d9dd50e9 100644 --- a/Source/Wrapper/Native.cpp +++ b/Source/Wrapper/Native.cpp @@ -25,6 +25,7 @@ #include "Native.h" #include +#include #include using namespace ShaderConductor; diff --git a/Source/Wrapper/Native.h b/Source/Wrapper/Native.h index 5851bf33..857674fb 100644 --- a/Source/Wrapper/Native.h +++ b/Source/Wrapper/Native.h @@ -82,12 +82,27 @@ struct DisassembleDescription int binarySize; }; -#define DLLEXPORT extern "C" __declspec(dllexport) - -DLLEXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, ResultDescription* result); -DLLEXPORT void Disassemble(DisassembleDescription* source, ResultDescription* result); - -DLLEXPORT ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size); -DLLEXPORT void DestroyShaderConductorBlob(ShaderConductorBlob* blob); -DLLEXPORT const void* GetShaderConductorBlobData(ShaderConductorBlob* blob); -DLLEXPORT int GetShaderConductorBlobSize(ShaderConductorBlob* blob); +#if defined(__clang__) +#define SC_SYMBOL_EXPORT __attribute__((__visibility__("default"))) +#define SC_SYMBOL_IMPORT +#elif defined(__GNUC__) +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +#define SC_SYMBOL_EXPORT __attribute__((__dllexport__)) +#define SC_SYMBOL_IMPORT __attribute__((__dllimport__)) +#else +#define SC_SYMBOL_EXPORT __attribute__((__visibility__("default"))) +#define SC_SYMBOL_IMPORT +#endif +#elif defined(_MSC_VER) +#define SC_SYMBOL_EXPORT __declspec(dllexport) +#define SC_SYMBOL_IMPORT __declspec(dllimport) +#endif + +extern "C" SC_SYMBOL_EXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, + ResultDescription* result); +extern "C" SC_SYMBOL_EXPORT void Disassemble(DisassembleDescription* source, ResultDescription* result); + +extern "C" SC_SYMBOL_EXPORT ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size); +extern "C" SC_SYMBOL_EXPORT void DestroyShaderConductorBlob(ShaderConductorBlob* blob); +extern "C" SC_SYMBOL_EXPORT const void* GetShaderConductorBlobData(ShaderConductorBlob* blob); +extern "C" SC_SYMBOL_EXPORT int GetShaderConductorBlobSize(ShaderConductorBlob* blob); diff --git a/Source/Wrapper/shader.hlsl b/Source/Wrapper/shader.hlsl index 0e8a7af5..05f35ac5 100644 --- a/Source/Wrapper/shader.hlsl +++ b/Source/Wrapper/shader.hlsl @@ -8,6 +8,7 @@ cbuffer Matrices : register(b0) Texture2D DiffuseTexture : register(t0); SamplerState Sampler : register(s0); +Texture2D DiffuseTexture2 : register(t1); struct VS_IN { @@ -36,5 +37,5 @@ PS_IN VS(VS_IN input) float4 PS(PS_IN input) : SV_Target { - return DiffuseTexture.Sample(Sampler, input.tex); + return DiffuseTexture.Sample(Sampler, input.tex) + DiffuseTexture2.Sample(Sampler, input.tex); } \ No newline at end of file