Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/spirv-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ jobs:
echo running extras
${{ matrix.env.extras }}
- name: Install Zig
uses: goto-bus-stop/setup-zig@v2
- name: Setup .NET 6.0 and .NET 7.0
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
6.0.201
7.0.*
8.0.*
- name: Build SPIRV-Cross
run: ${{ matrix.env.nuke_invoke }} SPIRVCross
env:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/spirv-reflect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ jobs:
echo running extras
${{ matrix.env.extras }}
- name: Install Zig
uses: goto-bus-stop/setup-zig@v2
- name: Setup .NET 6.0 and .NET 7.0
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
6.0.201
7.0.*
8.0.*
- name: Build SPIRV-Reflect
run: ${{ matrix.env.nuke_invoke }} SPIRVReflect
env:
Expand Down
15 changes: 15 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Vulkan.Extensions.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Vulkan.Extensions.OHOS", "src\Vulkan\Extensions\Silk.NET.Vulkan.Extensions.OHOS\Silk.NET.Vulkan.Extensions.OHOS.csproj", "{4F35A32B-3EF0-4B0F-8784-01B9CCA5BC4D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpirvTest", "src\Lab\Experiments\SpirvTest\SpirvTest.csproj", "{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -3825,6 +3827,18 @@ Global
{4F35A32B-3EF0-4B0F-8784-01B9CCA5BC4D}.Release|x64.Build.0 = Release|Any CPU
{4F35A32B-3EF0-4B0F-8784-01B9CCA5BC4D}.Release|x86.ActiveCfg = Release|Any CPU
{4F35A32B-3EF0-4B0F-8784-01B9CCA5BC4D}.Release|x86.Build.0 = Release|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Debug|x64.ActiveCfg = Debug|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Debug|x64.Build.0 = Debug|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Debug|x86.ActiveCfg = Debug|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Debug|x86.Build.0 = Debug|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Release|Any CPU.Build.0 = Release|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Release|x64.ActiveCfg = Release|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Release|x64.Build.0 = Release|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Release|x86.ActiveCfg = Release|Any CPU
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -4129,6 +4143,7 @@ Global
{9338EAE3-2ADA-4E34-9965-43521D24FFA0} = {90471225-AC23-424E-B62E-F6EC4C6ECAC0}
{B8D369E0-424C-4C99-9A81-7E8552B0C225} = {49BC383A-D7E6-4013-93C7-371479B984CC}
{4F35A32B-3EF0-4B0F-8784-01B9CCA5BC4D} = {49BC383A-D7E6-4013-93C7-371479B984CC}
{DB1EAED4-699B-4254-A832-A8FFC15F6CC7} = {39B598E9-44BA-4A61-A1BB-7C543734DBA6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}
Expand Down
Binary file modified build/cache/spirv-cross.json.gz
Binary file not shown.
Binary file modified build/cache/spirv-reflect.json.gz
Binary file not shown.
Binary file modified build/cache/spirv.json.gz
Binary file not shown.
75 changes: 39 additions & 36 deletions build/nuke/Native/SPIRVCross.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
using static Nuke.Common.Tools.Git.GitTasks;
using static Nuke.Common.Tools.GitHub.GitHubTasks;

partial class Build {
partial class Build
{
AbsolutePath SPIRVCrossPath => RootDirectory / "build" / "submodules" / "SPIRV-Cross";

//This is the build script for the SPIRV-Reflect shared library
Expand All @@ -34,62 +35,64 @@ partial class Build {

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
const optimize = b.standardOptimizeOption(.{});

const shared_lib_options: std.Build.SharedLibraryOptions = .{
.name = ""spirv-cross"",
const lib_mod = b.createModule(.{
.target = target,
.optimize = mode,
};
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
});

const lib: *std.Build.Step.Compile = b.addSharedLibrary(shared_lib_options);
lib.linkLibC();
lib.linkLibCpp();
const lib = b.addLibrary(.{
.name = ""spirv-cross"",
.root_module = lib_mod,
.use_llvm = true,
.linkage = .dynamic,
});

const flags = &.{ ""-std=c++11"", ""-fPIC"" };

//Enable the GLSL, HLSL, MSL, CPP, and Reflect C APIs
lib.defineCMacro(""SPIRV_CROSS_C_API_GLSL"", ""1"");
lib.defineCMacro(""SPIRV_CROSS_C_API_HLSL"", ""1"");
lib.defineCMacro(""SPIRV_CROSS_C_API_MSL"", ""1"");
lib.defineCMacro(""SPIRV_CROSS_C_API_CPP"", ""1"");
lib.defineCMacro(""SPIRV_CROSS_C_API_REFLECT"", ""1"");
lib_mod.addCMacro(""SPIRV_CROSS_C_API_GLSL"", ""1"");
lib_mod.addCMacro(""SPIRV_CROSS_C_API_HLSL"", ""1"");
lib_mod.addCMacro(""SPIRV_CROSS_C_API_MSL"", ""1"");
lib_mod.addCMacro(""SPIRV_CROSS_C_API_CPP"", ""1"");
lib_mod.addCMacro(""SPIRV_CROSS_C_API_REFLECT"", ""1"");

//Export the C API symbols
lib.defineCMacro(""SPVC_EXPORT_SYMBOLS"", ""1"");
lib_mod.addCMacro(""SPVC_EXPORT_SYMBOLS"", ""1"");

//On windows, we need to specify `__declspec(dllexport)` ourselves
//else SPIRV-Cross thinks this is a GNU toolchain and uses the wrong attribute in this case
if (target.result.os.tag == .windows) {
lib.defineCMacro(""SPVC_PUBLIC_API"", ""__declspec(dllexport)"");
lib_mod.addCMacro(""SPVC_PUBLIC_API"", ""__declspec(dllexport)"");
}

//If we arent in debug, defined NDEBUG and strip symbols
if (mode != .Debug) {
lib.defineCMacro(""NDEBUG"", ""1"");
if (optimize != .Debug) {
lib_mod.addCMacro(""NDEBUG"", ""1"");

lib.root_module.strip = true;
lib_mod.strip = true;
}

lib.addCSourceFiles(.{
.files = &.{
""spirv_cross.cpp"",
""spirv_cfg.cpp"",
""spirv_cpp.cpp"",
""spirv_cross_c.cpp"",
""spirv_cross_parsed_ir.cpp"",
""spirv_cross_util.cpp"",
""spirv_glsl.cpp"",
""spirv_hlsl.cpp"",
""spirv_msl.cpp"",
""spirv_parser.cpp"",
""spirv_reflect.cpp"",
},
.flags = flags
});
lib_mod.addCSourceFiles(.{ .files = &.{
""spirv_cross.cpp"",
""spirv_cfg.cpp"",
""spirv_cpp.cpp"",
""spirv_cross_c.cpp"",
""spirv_cross_parsed_ir.cpp"",
""spirv_cross_util.cpp"",
""spirv_glsl.cpp"",
""spirv_hlsl.cpp"",
""spirv_msl.cpp"",
""spirv_parser.cpp"",
""spirv_reflect.cpp"",
}, .flags = flags });

b.installArtifact(lib);
}";
}
";

Target SPIRVCross => CommonTarget
(
Expand Down
33 changes: 21 additions & 12 deletions build/nuke/Native/SPIRVReflect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
using static Nuke.Common.Tools.Git.GitTasks;
using static Nuke.Common.Tools.GitHub.GitHubTasks;

partial class Build {
partial class Build
{
AbsolutePath SPIRVReflectPath => RootDirectory / "build" / "submodules" / "SPIRV-Reflect";

//This is the build script for the SPIRV-Reflect shared library
Expand All @@ -36,21 +37,29 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const shared_lib_options: std.Build.SharedLibraryOptions = .{
.name = ""spirv-reflect"",
const lib_mod = b.createModule(.{
.target = target,
.optimize = optimize,
};

const lib: *std.Build.Step.Compile = b.addSharedLibrary(shared_lib_options);
lib.linkLibC();

if(optimize != .Debug)
lib.root_module.strip = true;
.link_libc = true,
});

lib.addCSourceFiles(.{ .files = &.{""spirv_reflect.c""}, .flags = &.{ ""-std=c99"", ""-fPIC"" } });
const lib = b.addLibrary(.{
.name = ""spirv-reflect"",
.root_module = lib_mod,
.use_llvm = true,
.linkage = .dynamic,
});

if (optimize != .Debug)
lib_mod.strip = true;

lib_mod.addCSourceFiles(.{
.files = &.{""spirv_reflect.c""},
.flags = &.{ ""-std=c99"", ""-fPIC"" },
});
b.installArtifact(lib);
}";
}
";

Target SPIRVReflect => CommonTarget
(
Expand Down
2 changes: 1 addition & 1 deletion build/submodules/SPIRV-Cross
Submodule SPIRV-Cross updated 258 files
2 changes: 1 addition & 1 deletion build/submodules/SPIRV-Reflect
59 changes: 59 additions & 0 deletions src/Lab/Experiments/SpirvTest/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

using Silk.NET.Core.Native;
using Silk.NET.SPIRV.Reflect;
using Silk.NET.SPIRV.Cross;
using Result = Silk.NET.SPIRV.Reflect.Result;

unsafe
{
var reflect = Reflect.GetApi();
var cross = Cross.GetApi();

uint major = 0, minor = 0, patch = 0;
cross.GetVersion(ref major, ref minor, ref patch);

Console.WriteLine($"Version {major}.{minor}.{patch}");

byte[] shader = File.ReadAllBytes("../../../../ImGuiVulkan/shader.vert.spv");
fixed (byte* ptr = shader)
{
ReflectShaderModule module;
var result = reflect.CreateShaderModule2(0, (nuint) shader.Length, ptr, &module);
if (result != Result.Success)
throw new Exception($"failed to create shader module {result.ToString()}");

Console.WriteLine($"Parsed module, source language: {module.SourceLanguage.ToString()}");

reflect.DestroyShaderModule(&module);
}

fixed (byte* ptr = shader)
{
Context* context = null;
var result = cross.ContextCreate(&context);
if (result != Silk.NET.SPIRV.Cross.Result.Success)
throw new Exception($"failed to create context {result.ToString()}");

ParsedIr* parsedIr = null;
result = cross.ContextParseSpirv(context, (uint*) ptr, (nuint)(shader.LongLength / 4), &parsedIr);
if(result != Silk.NET.SPIRV.Cross.Result.Success)
throw new Exception($"failed to parse spirv {result.ToString()}");

Console.WriteLine($"Parsed IR");

Compiler* compiler = null;
result = cross.ContextCreateCompiler(context, Backend.Glsl, parsedIr, CaptureMode.Copy, &compiler);
if(result != Silk.NET.SPIRV.Cross.Result.Success)
throw new Exception($"failed to create compiler {result.ToString()}");

byte* source = null;
result = cross.CompilerCompile(compiler, &source);
if(result != Silk.NET.SPIRV.Cross.Result.Success)
throw new Exception($"failed to compile {result.ToString()}");

string? str = SilkMarshal.PtrToString((nint)source, NativeStringEncoding.UTF8);
Console.WriteLine($"Compiled int {str}");

cross.ContextDestroy(context);
}
}
16 changes: 16 additions & 0 deletions src/Lab/Experiments/SpirvTest/SpirvTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\SPIRV\Silk.NET.SPIRV.Cross\Silk.NET.SPIRV.Cross.csproj" />
<ProjectReference Include="..\..\..\SPIRV\Silk.NET.SPIRV.Reflect\Silk.NET.SPIRV.Reflect.csproj" />
</ItemGroup>

</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading