From fd42b6fc9d0e2efad84a3f044e1e3c204df37ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Wed, 28 Aug 2019 14:11:23 +0200 Subject: [PATCH 01/11] - Added Options parameters to C# wrapper --- Source/Wrapper/Native.cpp | 10 ++++-- Source/Wrapper/Native.h | 25 ++++++++++++--- Source/Wrapper/Program.cs | 64 ++++++++++++++++++++++----------------- Source/Wrapper/Wrapper.cs | 57 +++++++++++++++++++++++++++++++--- 4 files changed, 118 insertions(+), 38 deletions(-) diff --git a/Source/Wrapper/Native.cpp b/Source/Wrapper/Native.cpp index ca828c0e..08af000e 100644 --- a/Source/Wrapper/Native.cpp +++ b/Source/Wrapper/Native.cpp @@ -29,8 +29,8 @@ using namespace ShaderConductor; -void Compile(SourceDescription* source, TargetDescription* target, ResultDescription* result) -{ +void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, ResultDescription* result) +{ Compiler::SourceDesc sourceDesc; sourceDesc.entryPoint = source->entryPoint; sourceDesc.source = source->source; @@ -40,6 +40,12 @@ void Compile(SourceDescription* source, TargetDescription* target, ResultDescrip sourceDesc.numDefines = 0; Compiler::Options options; + options.packMatricesInRowMajor = optionsDesc->packMatricesInRowMajor; + options.enable16bitTypes = optionsDesc->enable16bitTypes; + options.enableDebugInfo = optionsDesc->enableDebugInfo; + options.disableOptimizations = optionsDesc->disableOptimizations; + options.optimizationLevel = optionsDesc->optimizationLevel; + options.shaderModel = { static_cast(optionsDesc->shaderModel.major), static_cast(optionsDesc->shaderModel.minor) }; Compiler::TargetDesc targetDesc; targetDesc.language = target->shadingLanguage; diff --git a/Source/Wrapper/Native.h b/Source/Wrapper/Native.h index df3142c0..976f3618 100644 --- a/Source/Wrapper/Native.h +++ b/Source/Wrapper/Native.h @@ -33,9 +33,26 @@ struct ShaderConductorBlob; struct SourceDescription { - const char* source; + const char* source; const char* entryPoint; - ShaderStage stage; + ShaderStage stage; +}; + +struct ShaderModel +{ + int major; + int minor; +}; + +struct OptionsDescription +{ + bool packMatricesInRowMajor = true; // Experimental: Decide how a matrix get packed + bool enable16bitTypes = false; // Enable 16-bit types, such as half, uint16_t. Requires shader model 6.2+ + bool enableDebugInfo = false; // Embed debug info into the binary + bool disableOptimizations = false; // Force to turn off optimizations. Ignore optimizationLevel below. + int optimizationLevel = 3; // 0 to 3, no optimization to most optimization + + ShaderModel shaderModel = { 6, 0 }; }; struct TargetDescription @@ -45,7 +62,7 @@ struct TargetDescription }; struct ResultDescription -{ +{ ShaderConductorBlob* target; bool isText; @@ -62,7 +79,7 @@ struct DisassembleDescription #define DLLEXPORT extern "C" __declspec(dllexport) -DLLEXPORT void Compile(SourceDescription* source, TargetDescription* target, ResultDescription* result); +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); diff --git a/Source/Wrapper/Program.cs b/Source/Wrapper/Program.cs index e5393085..b9385da1 100644 --- a/Source/Wrapper/Program.cs +++ b/Source/Wrapper/Program.cs @@ -43,38 +43,21 @@ static void Main(string[] args) source = source, }; + Wrapper.OptionsDesc optionsDesc = Wrapper.OptionsDesc.Default; + //optionsDesc.packMatricesInRowMajor = true; + //optionsDesc.enable16bitTypes = true; + //optionsDesc.enableDebugInfo = true; + //optionsDesc.disableOptimizations = true; + //optionsDesc.optimizationLevel = 3; + //optionsDesc.shaderModel = new Wrapper.ShaderModel(6, 2); + Wrapper.TargetDesc targetDesc = new Wrapper.TargetDesc() { - language = Wrapper.ShadingLanguage.SpirV, + language = Wrapper.ShadingLanguage.Glsl, version = "460", }; - Wrapper.Compile(ref sourceDesc, ref targetDesc, out Wrapper.ResultDesc result); - - if (!result.isText) - { - Wrapper.DisassembleDesc disassembleDesc = new Wrapper.DisassembleDesc() - { - language = targetDesc.language, - binarySize = Wrapper.GetShaderConductorBlobSize(result.target), - binary = Wrapper.GetShaderConductorBlobData(result.target), - }; - - Wrapper.Disassemble(ref disassembleDesc, out Wrapper.ResultDesc disassembleResult); - Wrapper.DestroyShaderConductorBlob(result.target); - Wrapper.DestroyShaderConductorBlob(result.errorWarningMsg); - result = disassembleResult; - } - - if (result.isText) - { - string translation = Marshal.PtrToStringAnsi(Wrapper.GetShaderConductorBlobData(result.target), - Wrapper.GetShaderConductorBlobSize(result.target)); - Console.WriteLine("*************************\n" + - "** Translation **\n" + - "*************************\n"); - Console.WriteLine(translation); - } + Wrapper.Compile(ref sourceDesc, ref optionsDesc, ref targetDesc, out Wrapper.ResultDesc result); if (result.hasError) { @@ -85,6 +68,33 @@ static void Main(string[] args) "*************************\n"); Console.WriteLine(warning); } + else + { + if (!result.isText) + { + Wrapper.DisassembleDesc disassembleDesc = new Wrapper.DisassembleDesc() + { + language = targetDesc.language, + binarySize = Wrapper.GetShaderConductorBlobSize(result.target), + binary = Wrapper.GetShaderConductorBlobData(result.target), + }; + + Wrapper.Disassemble(ref disassembleDesc, out Wrapper.ResultDesc disassembleResult); + Wrapper.DestroyShaderConductorBlob(result.target); + Wrapper.DestroyShaderConductorBlob(result.errorWarningMsg); + result = disassembleResult; + } + + if (result.isText) + { + string translation = Marshal.PtrToStringAnsi(Wrapper.GetShaderConductorBlobData(result.target), + Wrapper.GetShaderConductorBlobSize(result.target)); + Console.WriteLine("*************************\n" + + "** Translation **\n" + + "*************************\n"); + Console.WriteLine(translation); + } + } Wrapper.DestroyShaderConductorBlob(result.target); Wrapper.DestroyShaderConductorBlob(result.errorWarningMsg); diff --git a/Source/Wrapper/Wrapper.cs b/Source/Wrapper/Wrapper.cs index 2da65578..ebaa135a 100644 --- a/Source/Wrapper/Wrapper.cs +++ b/Source/Wrapper/Wrapper.cs @@ -33,9 +33,9 @@ namespace CSharpConsole { public class Wrapper - { + { [DllImport("ShaderConductorWrapper.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] - public static extern void Compile([In] ref SourceDesc source, [In] ref TargetDesc target, out ResultDesc result); + public static extern void Compile([In] ref SourceDesc source, [In] ref OptionsDesc options, [In] ref TargetDesc target, out ResultDesc result); [DllImport("ShaderConductorWrapper.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern void Disassemble([In] ref DisassembleDesc source, out ResultDesc result); @@ -72,7 +72,8 @@ public enum ShadingLanguage Hlsl, Glsl, Essl, - Msl, + Msl_macOS, + Msl_iOS, NumShadingLanguages, } @@ -87,11 +88,57 @@ public struct MacroDefine [StructLayout(LayoutKind.Sequential)] public struct SourceDesc { - public string source; + public string source; public string entryPoint; public ShaderStage stage; } + [StructLayout(LayoutKind.Sequential)] + public struct ShaderModel + { + public int major; + public int minor; + + public ShaderModel(int major, int minor) + { + this.major = major; + this.minor = minor; + } + } + + [StructLayout(LayoutKind.Sequential)] + public struct OptionsDesc + { + [MarshalAs(UnmanagedType.I1)] + public bool packMatricesInRowMajor; // Experimental: Decide how a matrix get packed + [MarshalAs(UnmanagedType.I1)] + public bool enable16bitTypes; // Enable 16-bit types, such as half, uint16_t. Requires shader model 6.2+ + [MarshalAs(UnmanagedType.I1)] + public bool enableDebugInfo; // Embed debug info into the binary + [MarshalAs(UnmanagedType.I1)] + public bool disableOptimizations; // Force to turn off optimizations. Ignore optimizationLevel below. + public int optimizationLevel; // 0 to 3, no optimization to most optimization + + public ShaderModel shaderModel; + + public static OptionsDesc Default + { + get + { + var defaultInstance = new OptionsDesc(); + + defaultInstance.packMatricesInRowMajor = true; + defaultInstance.enable16bitTypes = false; + defaultInstance.enableDebugInfo = false; + defaultInstance.disableOptimizations = false; + defaultInstance.optimizationLevel = 3; + defaultInstance.shaderModel = new ShaderModel(6, 0); + + return defaultInstance; + } + } + } + [StructLayout(LayoutKind.Sequential)] public struct TargetDesc { @@ -107,7 +154,7 @@ public struct ResultDesc public IntPtr errorWarningMsg; public bool hasError; } - + [StructLayout(LayoutKind.Sequential)] public struct DisassembleDesc { From 508c680b4d1ab36955a0f53759935d3e3041227a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Wed, 28 Aug 2019 14:57:20 +0200 Subject: [PATCH 02/11] - Added Vulkan Shift resource binding options - Fixed issue packMatricesInRowMajor is inverted --- Include/ShaderConductor/ShaderConductor.hpp | 5 +++ Source/Core/ShaderConductor.cpp | 32 +++++++++++++++-- Source/Wrapper/Native.cpp | 6 +++- Source/Wrapper/Native.h | 5 +++ Source/Wrapper/Program.cs | 6 +++- Source/Wrapper/Wrapper.cs | 5 +++ Source/Wrapper/shader.hlsl | 39 +++++++++++++-------- 7 files changed, 79 insertions(+), 19 deletions(-) diff --git a/Include/ShaderConductor/ShaderConductor.hpp b/Include/ShaderConductor/ShaderConductor.hpp index b098e1fa..13fd7ba0 100644 --- a/Include/ShaderConductor/ShaderConductor.hpp +++ b/Include/ShaderConductor/ShaderConductor.hpp @@ -153,6 +153,11 @@ namespace ShaderConductor int optimizationLevel = 3; // 0 to 3, no optimization to most optimization ShaderModel shaderModel = { 6, 0 }; + + int shiftAllTexturesBindings; + int shiftAllSamplersBindings; + int shiftAllCBuffersBindings; + int shiftAllUABuffersBindings; }; struct TargetDesc diff --git a/Source/Core/ShaderConductor.cpp b/Source/Core/ShaderConductor.cpp index a5a6877e..ddf7d939 100644 --- a/Source/Core/ShaderConductor.cpp +++ b/Source/Core/ShaderConductor.cpp @@ -392,11 +392,11 @@ namespace // See also https://antiagainst.github.io/post/hlsl-for-vulkan-matrices/ if (options.packMatricesInRowMajor) { - dxcArgStrings.push_back(L"-Zpc"); + dxcArgStrings.push_back(L"-Zpr"); } else { - dxcArgStrings.push_back(L"-Zpr"); + dxcArgStrings.push_back(L"-Zpc"); } if (options.enable16bitTypes) @@ -432,6 +432,34 @@ namespace } } + if (options.shiftAllCBuffersBindings > 0) + { + dxcArgStrings.push_back(L"-fvk-b-shift"); + dxcArgStrings.push_back(std::to_wstring(options.shiftAllCBuffersBindings)); + dxcArgStrings.push_back(L"all"); + } + + if (options.shiftAllUABuffersBindings > 0) + { + dxcArgStrings.push_back(L"-fvk-u-shift"); + dxcArgStrings.push_back(std::to_wstring(options.shiftAllUABuffersBindings)); + dxcArgStrings.push_back(L"all"); + } + + if (options.shiftAllSamplersBindings > 0) + { + dxcArgStrings.push_back(L"-fvk-s-shift"); + dxcArgStrings.push_back(std::to_wstring(options.shiftAllSamplersBindings)); + dxcArgStrings.push_back(L"all"); + } + + if (options.shiftAllTexturesBindings > 0) + { + dxcArgStrings.push_back(L"-fvk-t-shift"); + dxcArgStrings.push_back(std::to_wstring(options.shiftAllTexturesBindings)); + dxcArgStrings.push_back(L"all"); + } + switch (targetLanguage) { case ShadingLanguage::Dxil: diff --git a/Source/Wrapper/Native.cpp b/Source/Wrapper/Native.cpp index 08af000e..908f41d3 100644 --- a/Source/Wrapper/Native.cpp +++ b/Source/Wrapper/Native.cpp @@ -45,7 +45,11 @@ void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetD options.enableDebugInfo = optionsDesc->enableDebugInfo; options.disableOptimizations = optionsDesc->disableOptimizations; options.optimizationLevel = optionsDesc->optimizationLevel; - options.shaderModel = { static_cast(optionsDesc->shaderModel.major), static_cast(optionsDesc->shaderModel.minor) }; + options.shaderModel = { static_cast(optionsDesc->shaderModel.major), static_cast(optionsDesc->shaderModel.minor) }; + options.shiftAllTexturesBindings = optionsDesc->shiftAllTexturesBindings; + options.shiftAllSamplersBindings = optionsDesc->shiftAllSamplersBindings; + options.shiftAllCBuffersBindings = optionsDesc->shiftAllCBuffersBindings; + options.shiftAllUABuffersBindings = optionsDesc->shiftAllUABuffersBindings; Compiler::TargetDesc targetDesc; targetDesc.language = target->shadingLanguage; diff --git a/Source/Wrapper/Native.h b/Source/Wrapper/Native.h index 976f3618..736b1113 100644 --- a/Source/Wrapper/Native.h +++ b/Source/Wrapper/Native.h @@ -53,6 +53,11 @@ struct OptionsDescription int optimizationLevel = 3; // 0 to 3, no optimization to most optimization ShaderModel shaderModel = { 6, 0 }; + + int shiftAllTexturesBindings; + int shiftAllSamplersBindings; + int shiftAllCBuffersBindings; + int shiftAllUABuffersBindings; }; struct TargetDescription diff --git a/Source/Wrapper/Program.cs b/Source/Wrapper/Program.cs index b9385da1..ad4fc9c3 100644 --- a/Source/Wrapper/Program.cs +++ b/Source/Wrapper/Program.cs @@ -50,10 +50,14 @@ static void Main(string[] args) //optionsDesc.disableOptimizations = true; //optionsDesc.optimizationLevel = 3; //optionsDesc.shaderModel = new Wrapper.ShaderModel(6, 2); + //optionsDesc.shiftAllCBuffersBindings = 10; + //optionsDesc.shiftAllTexturesBindings = 20; + //optionsDesc.shiftAllSamplersBindings = 30; + //optionsDesc.shiftAllUABuffersBindings = 40; Wrapper.TargetDesc targetDesc = new Wrapper.TargetDesc() { - language = Wrapper.ShadingLanguage.Glsl, + language = Wrapper.ShadingLanguage.SpirV, version = "460", }; diff --git a/Source/Wrapper/Wrapper.cs b/Source/Wrapper/Wrapper.cs index ebaa135a..f1640e0d 100644 --- a/Source/Wrapper/Wrapper.cs +++ b/Source/Wrapper/Wrapper.cs @@ -121,6 +121,11 @@ public struct OptionsDesc public ShaderModel shaderModel; + public int shiftAllTexturesBindings; + public int shiftAllSamplersBindings; + public int shiftAllCBuffersBindings; + public int shiftAllUABuffersBindings; + public static OptionsDesc Default { get diff --git a/Source/Wrapper/shader.hlsl b/Source/Wrapper/shader.hlsl index 137b972e..0e8a7af5 100644 --- a/Source/Wrapper/shader.hlsl +++ b/Source/Wrapper/shader.hlsl @@ -1,31 +1,40 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -float4x4 worldViewProj; +cbuffer Matrices : register(b0) +{ + float4x4 worldViewProj; +}; + +Texture2D DiffuseTexture : register(t0); +SamplerState Sampler : register(s0); struct VS_IN { - float4 pos : POSITION; - float4 col : COLOR; + float4 pos : POSITION; + float4 col : COLOR; + float2 tex : TEXCOORD; }; struct PS_IN { - float4 pos : SV_POSITION; - float4 col : COLOR; + float4 pos : SV_POSITION; + float4 col : COLOR; + float2 tex : TEXCOORD; }; -PS_IN VS( VS_IN input ) +PS_IN VS(VS_IN input) { - PS_IN output = (PS_IN)0; - - output.pos = mul(input.pos, worldViewProj); - output.col = input.col; - - return output; + PS_IN output = (PS_IN)0; + + output.pos = mul(input.pos, worldViewProj); + output.col = input.col; + output.tex = input.tex; + + return output; } -float4 PS( PS_IN input ) : SV_Target +float4 PS(PS_IN input) : SV_Target { - return input.col; -} + return DiffuseTexture.Sample(Sampler, input.tex); +} \ No newline at end of file From 4dd3cfd158d2a713097bff5b77125e860cf4d598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Thu, 29 Aug 2019 10:28:58 +0200 Subject: [PATCH 03/11] - Added explicit resources layout bindings in GLSL/ESSL --- Source/Core/ShaderConductor.cpp | 5 +++-- Source/Wrapper/Program.cs | 2 +- Source/Wrapper/shader.hlsl | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/Core/ShaderConductor.cpp b/Source/Core/ShaderConductor.cpp index ddf7d939..9567f2ba 100644 --- a/Source/Core/ShaderConductor.cpp +++ b/Source/Core/ShaderConductor.cpp @@ -719,8 +719,9 @@ namespace for (auto& remap : compiler->get_combined_image_samplers()) { - compiler->set_name(remap.combined_id, - "SPIRV_Cross_Combined" + compiler->get_name(remap.image_id) + compiler->get_name(remap.sampler_id)); + 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/Wrapper/Program.cs b/Source/Wrapper/Program.cs index ad4fc9c3..a298e66c 100644 --- a/Source/Wrapper/Program.cs +++ b/Source/Wrapper/Program.cs @@ -57,7 +57,7 @@ static void Main(string[] args) Wrapper.TargetDesc targetDesc = new Wrapper.TargetDesc() { - language = Wrapper.ShadingLanguage.SpirV, + language = Wrapper.ShadingLanguage.Glsl, version = "460", }; 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 From 3c0484dcf451c9a2200663da30aa22ec52a59d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Fri, 6 Sep 2019 11:29:35 +0200 Subject: [PATCH 04/11] Applied clang-format --- Include/ShaderConductor/ShaderConductor.hpp | 8 ++++---- Source/Core/ShaderConductor.cpp | 6 +++--- Source/Wrapper/Native.cpp | 6 +++--- Source/Wrapper/Native.h | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Include/ShaderConductor/ShaderConductor.hpp b/Include/ShaderConductor/ShaderConductor.hpp index 13fd7ba0..c9f619c7 100644 --- a/Include/ShaderConductor/ShaderConductor.hpp +++ b/Include/ShaderConductor/ShaderConductor.hpp @@ -147,14 +147,14 @@ namespace ShaderConductor struct Options { bool packMatricesInRowMajor = true; // Experimental: Decide how a matrix get packed - bool enable16bitTypes = false; // Enable 16-bit types, such as half, uint16_t. Requires shader model 6.2+ - bool enableDebugInfo = false; // Embed debug info into the binary - bool disableOptimizations = false; // Force to turn off optimizations. Ignore optimizationLevel below. + bool enable16bitTypes = false; // Enable 16-bit types, such as half, uint16_t. Requires shader model 6.2+ + bool enableDebugInfo = false; // Embed debug info into the binary + bool disableOptimizations = false; // Force to turn off optimizations. Ignore optimizationLevel below. int optimizationLevel = 3; // 0 to 3, no optimization to most optimization ShaderModel shaderModel = { 6, 0 }; - int shiftAllTexturesBindings; + int shiftAllTexturesBindings; int shiftAllSamplersBindings; int shiftAllCBuffersBindings; int shiftAllUABuffersBindings; diff --git a/Source/Core/ShaderConductor.cpp b/Source/Core/ShaderConductor.cpp index ddf7d939..7eab82fa 100644 --- a/Source/Core/ShaderConductor.cpp +++ b/Source/Core/ShaderConductor.cpp @@ -200,8 +200,8 @@ namespace } *includeSource = nullptr; - return Dxcompiler::Instance().Library()->CreateBlobWithEncodingOnHeapCopy( - source->Data(), source->Size(), CP_UTF8, reinterpret_cast(includeSource)); + return Dxcompiler::Instance().Library()->CreateBlobWithEncodingOnHeapCopy(source->Data(), source->Size(), CP_UTF8, + reinterpret_cast(includeSource)); } ULONG STDMETHODCALLTYPE AddRef() override @@ -432,7 +432,7 @@ namespace } } - if (options.shiftAllCBuffersBindings > 0) + if (options.shiftAllCBuffersBindings > 0) { dxcArgStrings.push_back(L"-fvk-b-shift"); dxcArgStrings.push_back(std::to_wstring(options.shiftAllCBuffersBindings)); diff --git a/Source/Wrapper/Native.cpp b/Source/Wrapper/Native.cpp index 908f41d3..c1bc26fb 100644 --- a/Source/Wrapper/Native.cpp +++ b/Source/Wrapper/Native.cpp @@ -30,7 +30,7 @@ using namespace ShaderConductor; void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, ResultDescription* result) -{ +{ Compiler::SourceDesc sourceDesc; sourceDesc.entryPoint = source->entryPoint; sourceDesc.source = source->source; @@ -45,8 +45,8 @@ void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetD options.enableDebugInfo = optionsDesc->enableDebugInfo; options.disableOptimizations = optionsDesc->disableOptimizations; options.optimizationLevel = optionsDesc->optimizationLevel; - options.shaderModel = { static_cast(optionsDesc->shaderModel.major), static_cast(optionsDesc->shaderModel.minor) }; - options.shiftAllTexturesBindings = optionsDesc->shiftAllTexturesBindings; + options.shaderModel = { static_cast(optionsDesc->shaderModel.major), static_cast(optionsDesc->shaderModel.minor) }; + options.shiftAllTexturesBindings = optionsDesc->shiftAllTexturesBindings; options.shiftAllSamplersBindings = optionsDesc->shiftAllSamplersBindings; options.shiftAllCBuffersBindings = optionsDesc->shiftAllCBuffersBindings; options.shiftAllUABuffersBindings = optionsDesc->shiftAllUABuffersBindings; diff --git a/Source/Wrapper/Native.h b/Source/Wrapper/Native.h index 736b1113..5851bf33 100644 --- a/Source/Wrapper/Native.h +++ b/Source/Wrapper/Native.h @@ -50,11 +50,11 @@ struct OptionsDescription bool enable16bitTypes = false; // Enable 16-bit types, such as half, uint16_t. Requires shader model 6.2+ bool enableDebugInfo = false; // Embed debug info into the binary bool disableOptimizations = false; // Force to turn off optimizations. Ignore optimizationLevel below. - int optimizationLevel = 3; // 0 to 3, no optimization to most optimization + int optimizationLevel = 3; // 0 to 3, no optimization to most optimization ShaderModel shaderModel = { 6, 0 }; - int shiftAllTexturesBindings; + int shiftAllTexturesBindings; int shiftAllSamplersBindings; int shiftAllCBuffersBindings; int shiftAllUABuffersBindings; From 4cb44f6ac5a1a5c0bfa8d112ff0929199a939643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Mon, 16 Sep 2019 13:07:57 +0200 Subject: [PATCH 05/11] Fixed expected tests --- Source/Tests/Data/Expected/PNTriangles_DS.300.essl | 2 +- Source/Tests/Data/Expected/PNTriangles_DS.300.glsl | 2 +- Source/Tests/Data/Expected/PNTriangles_DS.310.essl | 2 +- Source/Tests/Data/Expected/PNTriangles_DS.410.glsl | 2 +- Source/Tests/Data/Expected/PNTriangles_DS.msl | 2 +- Source/Tests/Data/Expected/Particle_GS.300.essl | 4 ++-- Source/Tests/Data/Expected/Particle_GS.300.glsl | 4 ++-- Source/Tests/Data/Expected/Particle_GS.310.essl | 4 ++-- Source/Tests/Data/Expected/Particle_GS.410.glsl | 4 ++-- Source/Tests/Data/Expected/Transform_VS.30.hlsl | 2 +- Source/Tests/Data/Expected/Transform_VS.300.essl | 2 +- Source/Tests/Data/Expected/Transform_VS.300.glsl | 2 +- Source/Tests/Data/Expected/Transform_VS.310.essl | 2 +- Source/Tests/Data/Expected/Transform_VS.40.hlsl | 2 +- Source/Tests/Data/Expected/Transform_VS.410.glsl | 2 +- Source/Tests/Data/Expected/Transform_VS.50.hlsl | 2 +- Source/Tests/Data/Expected/Transform_VS.msl | 2 +- Source/Tests/Data/Expected/Transform_VS_ColumnMajor.300.glsl | 2 +- 18 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Source/Tests/Data/Expected/PNTriangles_DS.300.essl b/Source/Tests/Data/Expected/PNTriangles_DS.300.essl index e54ae369..ca4978f6 100644 --- a/Source/Tests/Data/Expected/PNTriangles_DS.300.essl +++ b/Source/Tests/Data/Expected/PNTriangles_DS.300.essl @@ -4,7 +4,7 @@ layout(triangles) in; layout(std140) uniform type_cbPNTriangles { - layout(row_major) mat4 viewProj; + mat4 viewProj; vec4 lightDir; } cbPNTriangles; diff --git a/Source/Tests/Data/Expected/PNTriangles_DS.300.glsl b/Source/Tests/Data/Expected/PNTriangles_DS.300.glsl index fdfa96f6..f386bd51 100644 --- a/Source/Tests/Data/Expected/PNTriangles_DS.300.glsl +++ b/Source/Tests/Data/Expected/PNTriangles_DS.300.glsl @@ -10,7 +10,7 @@ out gl_PerVertex layout(std140) uniform type_cbPNTriangles { - layout(row_major) mat4 viewProj; + mat4 viewProj; vec4 lightDir; } cbPNTriangles; diff --git a/Source/Tests/Data/Expected/PNTriangles_DS.310.essl b/Source/Tests/Data/Expected/PNTriangles_DS.310.essl index b0e6f7e1..34991c96 100644 --- a/Source/Tests/Data/Expected/PNTriangles_DS.310.essl +++ b/Source/Tests/Data/Expected/PNTriangles_DS.310.essl @@ -4,7 +4,7 @@ layout(triangles) in; layout(binding = 0, std140) uniform type_cbPNTriangles { - layout(row_major) mat4 viewProj; + mat4 viewProj; vec4 lightDir; } cbPNTriangles; diff --git a/Source/Tests/Data/Expected/PNTriangles_DS.410.glsl b/Source/Tests/Data/Expected/PNTriangles_DS.410.glsl index 2ddb79bb..58003438 100644 --- a/Source/Tests/Data/Expected/PNTriangles_DS.410.glsl +++ b/Source/Tests/Data/Expected/PNTriangles_DS.410.glsl @@ -8,7 +8,7 @@ out gl_PerVertex layout(std140) uniform type_cbPNTriangles { - layout(row_major) mat4 viewProj; + mat4 viewProj; vec4 lightDir; } cbPNTriangles; diff --git a/Source/Tests/Data/Expected/PNTriangles_DS.msl b/Source/Tests/Data/Expected/PNTriangles_DS.msl index cfd7e8de..9effce55 100644 --- a/Source/Tests/Data/Expected/PNTriangles_DS.msl +++ b/Source/Tests/Data/Expected/PNTriangles_DS.msl @@ -42,7 +42,7 @@ struct main0_patchIn float _70 = _67 * 3.0; float _71 = _68 * 3.0; float _72 = _69 * 3.0; - out.gl_Position = float4(((((((((((in_var_POSITION[0] * _69) * gl_TessCoord.z) + ((in_var_POSITION[1] * _67) * gl_TessCoord.x)) + ((in_var_POSITION[2] * _68) * gl_TessCoord.y)) + ((patchIn.in_var_POSITION3 * _72) * gl_TessCoord.x)) + ((patchIn.in_var_POSITION4 * gl_TessCoord.z) * _70)) + ((patchIn.in_var_POSITION8 * _72) * gl_TessCoord.y)) + ((patchIn.in_var_POSITION5 * _70) * gl_TessCoord.y)) + ((patchIn.in_var_POSITION7 * gl_TessCoord.z) * _71)) + ((patchIn.in_var_POSITION6 * gl_TessCoord.x) * _71)) + ((((patchIn.in_var_CENTER * 6.0) * gl_TessCoord.z) * gl_TessCoord.x) * gl_TessCoord.y), 1.0) * cbPNTriangles.viewProj; + out.gl_Position = cbPNTriangles.viewProj * float4(((((((((((in_var_POSITION[0] * _69) * gl_TessCoord.z) + ((in_var_POSITION[1] * _67) * gl_TessCoord.x)) + ((in_var_POSITION[2] * _68) * gl_TessCoord.y)) + ((patchIn.in_var_POSITION3 * _72) * gl_TessCoord.x)) + ((patchIn.in_var_POSITION4 * gl_TessCoord.z) * _70)) + ((patchIn.in_var_POSITION8 * _72) * gl_TessCoord.y)) + ((patchIn.in_var_POSITION5 * _70) * gl_TessCoord.y)) + ((patchIn.in_var_POSITION7 * gl_TessCoord.z) * _71)) + ((patchIn.in_var_POSITION6 * gl_TessCoord.x) * _71)) + ((((patchIn.in_var_CENTER * 6.0) * gl_TessCoord.z) * gl_TessCoord.x) * gl_TessCoord.y), 1.0); out.out_var_TEXCOORD0 = ((in_var_TEXCOORD[0] * gl_TessCoord.z) + (in_var_TEXCOORD[1] * gl_TessCoord.x)) + (in_var_TEXCOORD[2] * gl_TessCoord.y); return out; } diff --git a/Source/Tests/Data/Expected/Particle_GS.300.essl b/Source/Tests/Data/Expected/Particle_GS.300.essl index c7df5854..96b5827a 100644 --- a/Source/Tests/Data/Expected/Particle_GS.300.essl +++ b/Source/Tests/Data/Expected/Particle_GS.300.essl @@ -8,8 +8,8 @@ const vec2 _48[4] = vec2[](vec2(0.0, 1.0), vec2(1.0), vec2(0.0), vec2(1.0, 0.0)) layout(std140) uniform type_cbMain { - layout(row_major) mat4 invView; - layout(row_major) mat4 viewProj; + mat4 invView; + mat4 viewProj; } cbMain; in vec4 in_var_POSITION[1]; diff --git a/Source/Tests/Data/Expected/Particle_GS.300.glsl b/Source/Tests/Data/Expected/Particle_GS.300.glsl index 9fd8cb1e..91575d4f 100644 --- a/Source/Tests/Data/Expected/Particle_GS.300.glsl +++ b/Source/Tests/Data/Expected/Particle_GS.300.glsl @@ -13,8 +13,8 @@ const vec2 _48[4] = vec2[](vec2(0.0, 1.0), vec2(1.0), vec2(0.0), vec2(1.0, 0.0)) layout(std140) uniform type_cbMain { - layout(row_major) mat4 invView; - layout(row_major) mat4 viewProj; + mat4 invView; + mat4 viewProj; } cbMain; layout(location = 0) in vec4 in_var_POSITION[1]; diff --git a/Source/Tests/Data/Expected/Particle_GS.310.essl b/Source/Tests/Data/Expected/Particle_GS.310.essl index 5034835a..b42bdf17 100644 --- a/Source/Tests/Data/Expected/Particle_GS.310.essl +++ b/Source/Tests/Data/Expected/Particle_GS.310.essl @@ -8,8 +8,8 @@ const vec2 _48[4] = vec2[](vec2(0.0, 1.0), vec2(1.0), vec2(0.0), vec2(1.0, 0.0)) layout(binding = 0, std140) uniform type_cbMain { - layout(row_major) mat4 invView; - layout(row_major) mat4 viewProj; + mat4 invView; + mat4 viewProj; } cbMain; layout(location = 0) in vec4 in_var_POSITION[1]; diff --git a/Source/Tests/Data/Expected/Particle_GS.410.glsl b/Source/Tests/Data/Expected/Particle_GS.410.glsl index 6983ca50..c7050f46 100644 --- a/Source/Tests/Data/Expected/Particle_GS.410.glsl +++ b/Source/Tests/Data/Expected/Particle_GS.410.glsl @@ -12,8 +12,8 @@ const vec2 _48[4] = vec2[](vec2(0.0, 1.0), vec2(1.0), vec2(0.0), vec2(1.0, 0.0)) layout(std140) uniform type_cbMain { - layout(row_major) mat4 invView; - layout(row_major) mat4 viewProj; + mat4 invView; + mat4 viewProj; } cbMain; layout(location = 0) in vec4 in_var_POSITION[1]; diff --git a/Source/Tests/Data/Expected/Transform_VS.30.hlsl b/Source/Tests/Data/Expected/Transform_VS.30.hlsl index 51b13139..5014c35a 100644 --- a/Source/Tests/Data/Expected/Transform_VS.30.hlsl +++ b/Source/Tests/Data/Expected/Transform_VS.30.hlsl @@ -1,6 +1,6 @@ cbuffer type_cbVS : register(b0) { - column_major float4x4 cbVS_wvp : packoffset(c0); + row_major float4x4 cbVS_wvp : packoffset(c0); }; uniform float4 gl_HalfPixel; diff --git a/Source/Tests/Data/Expected/Transform_VS.300.essl b/Source/Tests/Data/Expected/Transform_VS.300.essl index 3d721ee8..7611f6ab 100644 --- a/Source/Tests/Data/Expected/Transform_VS.300.essl +++ b/Source/Tests/Data/Expected/Transform_VS.300.essl @@ -2,7 +2,7 @@ layout(std140) uniform type_cbVS { - layout(row_major) mat4 wvp; + mat4 wvp; } cbVS; layout(location = 0) in vec4 in_var_POSITION; diff --git a/Source/Tests/Data/Expected/Transform_VS.300.glsl b/Source/Tests/Data/Expected/Transform_VS.300.glsl index ebd8cc28..50679cf1 100644 --- a/Source/Tests/Data/Expected/Transform_VS.300.glsl +++ b/Source/Tests/Data/Expected/Transform_VS.300.glsl @@ -8,7 +8,7 @@ out gl_PerVertex layout(std140) uniform type_cbVS { - layout(row_major) mat4 wvp; + mat4 wvp; } cbVS; in vec4 in_var_POSITION; diff --git a/Source/Tests/Data/Expected/Transform_VS.310.essl b/Source/Tests/Data/Expected/Transform_VS.310.essl index 771a97fd..f880bb80 100644 --- a/Source/Tests/Data/Expected/Transform_VS.310.essl +++ b/Source/Tests/Data/Expected/Transform_VS.310.essl @@ -2,7 +2,7 @@ layout(binding = 0, std140) uniform type_cbVS { - layout(row_major) mat4 wvp; + mat4 wvp; } cbVS; layout(location = 0) in vec4 in_var_POSITION; diff --git a/Source/Tests/Data/Expected/Transform_VS.40.hlsl b/Source/Tests/Data/Expected/Transform_VS.40.hlsl index 3bd5f429..6893d5cd 100644 --- a/Source/Tests/Data/Expected/Transform_VS.40.hlsl +++ b/Source/Tests/Data/Expected/Transform_VS.40.hlsl @@ -1,6 +1,6 @@ cbuffer type_cbVS : register(b0) { - column_major float4x4 cbVS_wvp : packoffset(c0); + row_major float4x4 cbVS_wvp : packoffset(c0); }; diff --git a/Source/Tests/Data/Expected/Transform_VS.410.glsl b/Source/Tests/Data/Expected/Transform_VS.410.glsl index 2591ac69..983ca575 100644 --- a/Source/Tests/Data/Expected/Transform_VS.410.glsl +++ b/Source/Tests/Data/Expected/Transform_VS.410.glsl @@ -7,7 +7,7 @@ out gl_PerVertex layout(std140) uniform type_cbVS { - layout(row_major) mat4 wvp; + mat4 wvp; } cbVS; layout(location = 0) in vec4 in_var_POSITION; diff --git a/Source/Tests/Data/Expected/Transform_VS.50.hlsl b/Source/Tests/Data/Expected/Transform_VS.50.hlsl index 3bd5f429..6893d5cd 100644 --- a/Source/Tests/Data/Expected/Transform_VS.50.hlsl +++ b/Source/Tests/Data/Expected/Transform_VS.50.hlsl @@ -1,6 +1,6 @@ cbuffer type_cbVS : register(b0) { - column_major float4x4 cbVS_wvp : packoffset(c0); + row_major float4x4 cbVS_wvp : packoffset(c0); }; diff --git a/Source/Tests/Data/Expected/Transform_VS.msl b/Source/Tests/Data/Expected/Transform_VS.msl index a9f708f7..34e68ffe 100644 --- a/Source/Tests/Data/Expected/Transform_VS.msl +++ b/Source/Tests/Data/Expected/Transform_VS.msl @@ -21,7 +21,7 @@ struct main0_in vertex main0_out main0(main0_in in [[stage_in]], constant type_cbVS& cbVS [[buffer(0)]]) { main0_out out = {}; - out.gl_Position = in.in_var_POSITION * cbVS.wvp; + out.gl_Position = cbVS.wvp * in.in_var_POSITION; return out; } diff --git a/Source/Tests/Data/Expected/Transform_VS_ColumnMajor.300.glsl b/Source/Tests/Data/Expected/Transform_VS_ColumnMajor.300.glsl index 50679cf1..ebd8cc28 100644 --- a/Source/Tests/Data/Expected/Transform_VS_ColumnMajor.300.glsl +++ b/Source/Tests/Data/Expected/Transform_VS_ColumnMajor.300.glsl @@ -8,7 +8,7 @@ out gl_PerVertex layout(std140) uniform type_cbVS { - mat4 wvp; + layout(row_major) mat4 wvp; } cbVS; in vec4 in_var_POSITION; From 3b40005e632eec8190810cc5a8b454adb711897c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Thu, 19 Sep 2019 10:24:12 +0200 Subject: [PATCH 06/11] Configure Wrapper entrypoints on LInux and Mac --- Source/CMakeLists.txt | 4 +--- Source/Wrapper/CMakeLists.txt | 34 +++++++++++++++++++--------------- Source/Wrapper/Native.cpp | 1 + Source/Wrapper/Native.h | 32 +++++++++++++++++++++++--------- 4 files changed, 44 insertions(+), 27 deletions(-) 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/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..edf81a1a 100644 --- a/Source/Wrapper/Native.cpp +++ b/Source/Wrapper/Native.cpp @@ -26,6 +26,7 @@ #include "Native.h" #include #include +#include using namespace ShaderConductor; diff --git a/Source/Wrapper/Native.h b/Source/Wrapper/Native.h index 5851bf33..3f64e67f 100644 --- a/Source/Wrapper/Native.h +++ b/Source/Wrapper/Native.h @@ -82,12 +82,26 @@ 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 + +SC_SYMBOL_EXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, ResultDescription* result); +SC_SYMBOL_EXPORT void Disassemble(DisassembleDescription* source, ResultDescription* result); + +SC_SYMBOL_EXPORT ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size); +SC_SYMBOL_EXPORT void DestroyShaderConductorBlob(ShaderConductorBlob* blob); +SC_SYMBOL_EXPORT const void* GetShaderConductorBlobData(ShaderConductorBlob* blob); +SC_SYMBOL_EXPORT int GetShaderConductorBlobSize(ShaderConductorBlob* blob); From cfcb706beaf558c11206b3be66d35bddc24c7d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Thu, 19 Sep 2019 10:30:24 +0200 Subject: [PATCH 07/11] Clang format --- Source/Wrapper/Native.cpp | 2 +- Source/Wrapper/Native.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Wrapper/Native.cpp b/Source/Wrapper/Native.cpp index edf81a1a..d9dd50e9 100644 --- a/Source/Wrapper/Native.cpp +++ b/Source/Wrapper/Native.cpp @@ -25,8 +25,8 @@ #include "Native.h" #include -#include #include +#include using namespace ShaderConductor; diff --git a/Source/Wrapper/Native.h b/Source/Wrapper/Native.h index 3f64e67f..668468a1 100644 --- a/Source/Wrapper/Native.h +++ b/Source/Wrapper/Native.h @@ -98,7 +98,8 @@ struct DisassembleDescription #define SC_SYMBOL_IMPORT __declspec(dllimport) #endif -SC_SYMBOL_EXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, ResultDescription* result); +SC_SYMBOL_EXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, + ResultDescription* result); SC_SYMBOL_EXPORT void Disassemble(DisassembleDescription* source, ResultDescription* result); SC_SYMBOL_EXPORT ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size); From a67cf62610daa06d834a3d540598898902ef93d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Thu, 19 Sep 2019 10:47:22 +0200 Subject: [PATCH 08/11] Fixed wrapper library export symbols --- Source/Wrapper/Native.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Wrapper/Native.h b/Source/Wrapper/Native.h index 668468a1..857674fb 100644 --- a/Source/Wrapper/Native.h +++ b/Source/Wrapper/Native.h @@ -98,11 +98,11 @@ struct DisassembleDescription #define SC_SYMBOL_IMPORT __declspec(dllimport) #endif -SC_SYMBOL_EXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, - ResultDescription* result); -SC_SYMBOL_EXPORT void Disassemble(DisassembleDescription* source, ResultDescription* result); - -SC_SYMBOL_EXPORT ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size); -SC_SYMBOL_EXPORT void DestroyShaderConductorBlob(ShaderConductorBlob* blob); -SC_SYMBOL_EXPORT const void* GetShaderConductorBlobData(ShaderConductorBlob* blob); -SC_SYMBOL_EXPORT int GetShaderConductorBlobSize(ShaderConductorBlob* blob); +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); From 5ef3487de0b46fe80600052d7fcab2a5ab684778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Cant=C3=B3n?= Date: Fri, 4 Oct 2019 14:25:16 +0200 Subject: [PATCH 09/11] Fixed load shader conductor dependencies --- Source/Core/ShaderConductor.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Core/ShaderConductor.cpp b/Source/Core/ShaderConductor.cpp index cc47d34f..24ca2d14 100644 --- a/Source/Core/ShaderConductor.cpp +++ b/Source/Core/ShaderConductor.cpp @@ -128,7 +128,22 @@ 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 From a2b626cf084dedd95d09caa862458ef6d5a39041 Mon Sep 17 00:00:00 2001 From: jorgemagic Date: Tue, 15 Oct 2019 12:20:24 +0200 Subject: [PATCH 10/11] - Passed clang-format to ShaderConductor.cpp --- Source/Core/ShaderConductor.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Core/ShaderConductor.cpp b/Source/Core/ShaderConductor.cpp index 24ca2d14..d51691d5 100644 --- a/Source/Core/ShaderConductor.cpp +++ b/Source/Core/ShaderConductor.cpp @@ -129,9 +129,10 @@ namespace #ifdef _WIN32 HMODULE hm = NULL; - if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)"DllMain", &hm) != 0) + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) "DllMain", + &hm) != 0) { - char path[MAX_PATH]; + char path[MAX_PATH]; if (GetModuleFileName(hm, path, sizeof(path)) != 0) { PathRemoveFileSpec(path); @@ -736,7 +737,8 @@ namespace { 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)); + compiler->set_name(remap.combined_id, + "SPIRV_Cross_Combined" + compiler->get_name(remap.image_id) + compiler->get_name(remap.sampler_id)); } } From f0c6a82b0a1784d7a5b87cd53b0e1d05c8a4b4ce Mon Sep 17 00:00:00 2001 From: jorgemagic Date: Wed, 16 Oct 2019 13:00:19 +0200 Subject: [PATCH 11/11] - Fixed expected ToneMapping PS 310 GLES (included layout binding) --- Source/Tests/Data/Expected/ToneMapping_PS.310.essl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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;