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:
Rian Drake 2026-10-27 09:10:25 +13:00 • committed by GitHub
commit 7a3b72d843
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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");
}
}