mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
samples: add Hello/Demo samples for most BRUTAL packages (#19)
Add samples/, a collection of single-file .NET 10 apps run with `dotnet run <file>.cs`. Hello/ has one minimal sample per package that has a public API, many of them headless; Demo/ has fuller programs that combine packages into a more interesting application. samples/README.md indexes every sample and covers the layout, error handling and per-OS requirements.
This commit is contained in:
parent
4ac91e105e
commit
7a3b72d843
1 changed files with 4599 additions and 1 deletions
48
samples/Hello/HelloSlang.cs
Normal file
48
samples/Hello/HelloSlang.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* HelloSlang
|
||||
*
|
||||
* Compiles a small inline Slang vertex shader to SPIR-V and prints its size.
|
||||
*/
|
||||
|
||||
#:property AllowUnsafeBlocks=true
|
||||
#:package Ahwoo.Brutal.Slang@2026.10.1
|
||||
#:package Ahwoo.Brutal.Core@2026.10.1
|
||||
#:package Ahwoo.Brutal.Strings@2026.10.1
|
||||
|
||||
using Brutal.SlangApi;
|
||||
|
||||
Run();
|
||||
|
||||
static void Run()
|
||||
{
|
||||
// The global session is a COM proxy that the GC releases, so only the request needs disposing.
|
||||
var globalSession = Slang.CreateGlobalSession();
|
||||
|
||||
using var request = globalSession.CreateCompileRequest();
|
||||
request.SetCodeGenTarget(CompileTarget.Spirv);
|
||||
|
||||
var translationUnit = request.AddTranslationUnit(SourceLanguage.Slang, "hello"u8);
|
||||
request.AddTranslationUnitSourceString(
|
||||
translationUnit,
|
||||
"hello.slang"u8,
|
||||
"""
|
||||
[shader("vertex")]
|
||||
float4 vertexMain(float3 position : POSITION) : SV_Position
|
||||
{
|
||||
return float4(position, 1.0);
|
||||
}
|
||||
"""u8
|
||||
);
|
||||
|
||||
var entryPoint = request.AddEntryPoint(translationUnit, "vertexMain"u8, Stage.Vertex);
|
||||
|
||||
var compileResult = request.Compile();
|
||||
if (compileResult.IsFailure)
|
||||
throw new SlangException(compileResult, $"Slang compile failed: {request.GetDiagnosticOutput()}");
|
||||
|
||||
unsafe
|
||||
{
|
||||
request.GetEntryPointCode(entryPoint, out var size);
|
||||
Console.WriteLine($"Compiled Slang to {size} of SPIR-V");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue