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
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,43 @@ add_dependencies(donut_interop check_interop_types)
# The functions have no dllexport, so export all of core/donut_interop.cpp's symbols; its import library
# is renamed so it doesn't overwrite the static donut_interop.lib.
# There is no JIT on Android, so no shared build there either.
# Under the JIT this one library is all an example gets, so it also holds the C++ modules that only
# some examples link into their executables (their add_tslang_example sources), with what those
# need: the OBJ, SDKMESH and meshlet loaders, the PBRT scene, DirectXCollision, Basis Universal's
# transcoder, the fast block compressor, the paged images, and (Windows) the video player.
set(JIT_MODULE_SOURCES
core/obj_model.cpp
core/sdkmesh.cpp
core/meshlet_model.cpp
core/denoised_rtao.cpp
core/pbrt/PBRTParser.cpp
core/pbrt/PlyParser.cpp
core/directx_collision.cpp
core/basis_transcoder.cpp
core/fast_block_compress.cpp
core/fbc_cpu.cpp
core/paged_images.cpp)
if (WIN32)
list(APPEND JIT_MODULE_SOURCES core/video_player.cpp)
endif()
if (NOT ANDROID)
add_library(donut_interop_shared SHARED core/donut_interop.cpp)
add_library(donut_interop_shared SHARED core/donut_interop.cpp ${JIT_MODULE_SOURCES})
configure_donut_interop(donut_interop_shared)
set_target_properties(donut_interop_shared PROPERTIES
OUTPUT_NAME donut_interop
ARCHIVE_OUTPUT_NAME donut_interop_shared
WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_link_libraries(donut_interop_shared PRIVATE basisu_transcoder)
# The Agility SDK runtime for the examples whose executables opt into it (see
# UseAgilitySdkUnderJit): tslang.exe doesn't.
if (DONUT_D3D_AGILITY_SDK_VERSION)
target_compile_definitions(donut_interop_shared PRIVATE DONUT_JIT_AGILITY_SDK_VERSION=${DONUT_D3D_AGILITY_SDK_VERSION})
endif()
if (WIN32)
# As video_texture's: mfplat.dll delay-loaded (Windows N editions lack it).
target_link_libraries(donut_interop_shared PRIVATE delayimp)
target_link_options(donut_interop_shared PRIVATE /DELAYLOAD:mfplat.dll)
endif()
endif()

# With DONUT_WITH_DLSS, NGX loads nvngx_dlss.dll from the directory of the executable (of
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,22 @@ does for `.cpp`.
- tslang can't write a depfile, so the files a `.ts` imports or references aren't tracked for it:
list them as its `OBJECT_DEPENDS`, as `CMakeLists.txt` does for `core/`.

The examples can also run under tslang's JIT, against the shared build of the interop layer:
The examples can also run under tslang's JIT, against the shared build of the interop layer
(`run_jit.bat examples/<name>.ts [-- args]` does this from the repo root):

```
tslang --emit=jit --shared-libs=build/bin/donut_interop.dll examples/basic_triangle.ts
tslang --emit=jit --jit-cache=false --shared-libs=build/bin/donut_interop.dll examples/basic_triangle.ts -- -dx12
```

- Program arguments go after `--`.
- `--jit-cache=false`: tslang pre-alpha93's JIT cache crashes in a run that compiles two or more
modules, so an example (with its imports) crashed on its first two runs
([TypeScriptCompiler#548](https://github.com/ASDAlexander77/TypeScriptCompiler/pull/548)).
- The shared library also holds the C++ modules some examples link (`core/sdkmesh.cpp`,
`core/meshlet_model.cpp`, `core/paged_images.cpp`, ...), and applies the D3D12 Agility SDK
runtime from `bin/D3D12` (the executables that need it opt in through their exports, which
`tslang.exe` doesn't have).

### Passing flags

```cmake
Expand Down
37 changes: 37 additions & 0 deletions core/donut_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,39 @@ extern "C"
{
// --- Application -----------------------------------------------------------------------

#if defined(DONUT_JIT_AGILITY_SDK_VERSION) && DONUT_WITH_DX12
// The executables that need the Agility SDK runtime (D3D12Core.dll in bin/D3D12) export its
// version and path (core/d3d12_agility_sdk.cpp), which D3D12 looks up in the process's
// executable. Under tslang's JIT that's tslang.exe, which doesn't, so this library (the JIT's
// build only) makes a device factory for that runtime and applies it to D3D12's global state
// before the first device: devices made afterwards (Donut's) use it. Once per process, and only
// when the executable doesn't opt in itself.
static void UseAgilitySdkUnderJit()
{
static bool s_Done = false;
if (s_Done)
return;
s_Done = true;
if (GetProcAddress(GetModuleHandleW(nullptr), "D3D12SDKVersion"))
return;
const std::filesystem::path sdkPath = GetExecutablePath().parent_path() / "D3D12";
if (!std::filesystem::exists(sdkPath / "D3D12Core.dll"))
return;
Microsoft::WRL::ComPtr<ID3D12SDKConfiguration1> configuration;
Microsoft::WRL::ComPtr<ID3D12DeviceFactory> factory;
// The path is the runtime's folder, with a trailing separator.
const std::string path = sdkPath.string() + "\\";
if (FAILED(D3D12GetInterface(CLSID_D3D12SDKConfiguration, IID_PPV_ARGS(&configuration)))
|| FAILED(configuration->CreateDeviceFactory(DONUT_JIT_AGILITY_SDK_VERSION, path.c_str(), IID_PPV_ARGS(&factory)))
|| FAILED(factory->ApplyToGlobalState()))
{
donut::log::warning("Cannot use the D3D12 Agility SDK runtime in %s; the system's runtime is used", path.c_str());
return;
}
donut::log::info("Using the D3D12 Agility SDK runtime %d in %s", DONUT_JIT_AGILITY_SDK_VERSION, path.c_str());
}
#endif

// Values of the `options` bit mask of Donut_CreateAppWithOptions.
enum AppOptions
{
Expand All @@ -2352,6 +2385,10 @@ extern "C"
donut::log::ConsoleApplicationMode();

const auto api = static_cast<nvrhi::GraphicsAPI>(graphicsApi);
#if defined(DONUT_JIT_AGILITY_SDK_VERSION) && DONUT_WITH_DX12
if (api == nvrhi::GraphicsAPI::D3D12)
UseAgilitySdkUnderJit();
#endif
std::unique_ptr<DeviceManager> deviceManager(DeviceManager::Create(api));
if (!deviceManager)
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion examples/bokeh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ namespace Bokeh {
// -preset N: start with preset scene N (0..3; Down cycles them).
// -slow: start with the full (not the fast) bokeh geometry shader (Up toggles it).
let options = AppOptions.UnormBackBuffer;
let preset = 0;
let preset: int = 0;
let slow = false;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
Expand Down
2 changes: 1 addition & 1 deletion examples/calibrated_timestamps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ namespace CalibratedTimestampsSample {
// and the times (see checkFrame).
let options = AppOptions.None;
let withUI = true;
let objectIndex = 0;
let objectIndex: int = 0;
let bloom = true;
let displaySkybox = true;
for (let i = 1; i < argc; i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/collision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ namespace Collision {
// -group <1..4>: the group looked at first. -time <seconds>: the objects frozen at that time.
// -help: start with the help screen.
let options = AppOptions.UnormBackBuffer;
let group = 0;
let group: int = 0;
let fixedTime = -1.0;
let showHelp = false;
for (let i = 1; i < argc; i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_multisample_rasterization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ namespace DynamicMultisampleRasterization {
let indices: int[] = [];
let firstIndex: int[] = [];
let baseVertex: int[] = [];
let meshCount = 0;
let meshCount: int = 0;
for (let p = 0; p < primitiveCount; p++) {
const vertexCount = scene.getVertexCount(p);
const indexCount = scene.getIndexCount(p);
Expand Down
4 changes: 2 additions & 2 deletions examples/dynamic_primitive_clipping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ namespace DynamicPrimitiveClipping {
// object 1 or 2.
let options = AppOptions.None;
let withUI = true;
let objectIndex = 0;
let visualization = 0;
let objectIndex: int = 0;
let visualization: int = 0;
let clipping = true;
let depthClip = false;
let only = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_rendering_local_read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ namespace DynamicRenderingLocalRead {
let indices: int[] = [];
let firstIndex: int[] = [];
let baseVertex: int[] = [];
let meshCount = 0;
let meshCount: int = 0;
for (let p = 0; p < primitiveCount; p++) {
const vertexCount = model.getVertexCount(p);
const indexCount = model.getIndexCount(p);
Expand Down
6 changes: 3 additions & 3 deletions examples/fast_block_compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,9 @@ namespace FastBlockCompress {
// The back buffers are UNORM, as the sample's (B8G8R8A8_UNORM): values shown as stored.
let options = AppOptions.UnormBackBuffer;
let withUI = true;
let image = 0;
let method = 0;
let mip = 0;
let image: int = 0;
let method: int = 0;
let mip: int = 0;
let fullscreen = false;
let original = false;
let highlight = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/fragment_shader_barycentric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ namespace FragmentShaderBarycentric {
// -effect <0..4>: the effect selected at start.
let options = AppOptions.None;
let withUI = true;
let effect = 0;
let effect: int = 0;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
if (arg == "-debug") {
Expand Down
8 changes: 4 additions & 4 deletions examples/fragment_shading_rate_dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ namespace FragmentShadingRateDynamic {

// The compute shader's parameters: the frequency (reduced size) and shading rate images'
// sizes, the largest rate, the rate count, the rates.
let maxRateX = 0;
let maxRateY = 0;
let maxRateX: int = 0;
let maxRateY: int = 0;
for (let r = 0; r < this.rateCount; r++) {
maxRateX = Math.max(maxRateX, this.rates[r * 2]);
maxRateY = Math.max(maxRateY, this.rates[r * 2 + 1]);
Expand Down Expand Up @@ -686,8 +686,8 @@ namespace FragmentShadingRateDynamic {
// everywhere. -nosky: without the sky sphere.
let options = AppOptions.None;
let withUI = true;
let visualize = 0;
let ratio = 4;
let visualize: int = 0;
let ratio: int = 4;
let noAttachment = false;
let noSky = false;
for (let i = 1; i < argc; i++) {
Expand Down
4 changes: 2 additions & 2 deletions examples/graphics_pipeline_library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ namespace GraphicsPipelineLibrary {
// -benchmark: 1/60 second per frame (as vulkan_samples' --benchmark).
let options = AppOptions.None;
let withUI = true;
let pipelines = 1;
let seed = -1;
let pipelines: int = 1;
let seed: int = -1;
let benchmark = false;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
Expand Down
2 changes: 1 addition & 1 deletion examples/hdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ namespace Hdr {
// -object <0..2>, -exposure <value>, -nobloom, -noskybox: the settings' initial values.
let options = AppOptions.None;
let withUI = true;
let objectIndex = 0;
let objectIndex: int = 0;
let exposure = 1.0;
let bloom = true;
let displaySkybox = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh_shader_culling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace MeshShaderCulling {
let options = AppOptions.None;
let withUI = true;
let cullRadius = 1.0;
let densityLevel = 2;
let densityLevel: int = 2;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
if (arg == "-debug") {
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_draw_indirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ namespace MultiDrawIndirect {
// -freeze: culling frozen.
let options = AppOptions.None;
let withUI = true;
let renderMode = RENDER_GPU;
let renderMode: int = RENDER_GPU;
let enableMdi = true;
let freezeCull = false;
for (let i = 1; i < argc; i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/multithreading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ namespace Multithreading {
if (app.readBackBufferRGBA8(Ref(pixels[0]), pixels.length) == 0) {
return "cannot read the back buffer";
}
let sum = 0;
let sum: number = 0;
let lit = 0;
for (let i = 0; i < width * height; i++) {
const p = pixels[i];
Expand Down
2 changes: 1 addition & 1 deletion examples/oit_depth_peeling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ namespace OitDepthPeeling {
// -rotate: start with the camera's auto-rotation on.
let options = AppOptions.None;
let withUI = true;
let frontLayer = 0;
let frontLayer: int = 0;
let backLayer = LAYER_MAX_COUNT - 1;
let alpha = 0.5;
let grayscale = 0.3;
Expand Down
2 changes: 1 addition & 1 deletion examples/oit_linked_lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ namespace OitLinkedLists {
let options = AppOptions.None;
let withUI = true;
let sortFragments = true;
let sortedFragmentCount = SORTED_FRAGMENT_MAX_COUNT;
let sortedFragmentCount: int = SORTED_FRAGMENT_MAX_COUNT;
let cameraAutoRotation = false;
let backgroundGrayscale = 0.3;
let benchmark = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/ray_tracing_extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ namespace RayTracingExtended {
// (as in the sample, 5 and 6 show the hit's texture: its ray generation shader stops before
// their shadow and AO output).
let options = AppOptions.RayTracing;
let renderMode = RENDER_DEFAULT;
let renderMode: int = RENDER_DEFAULT;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
if (arg == "-debug") {
Expand Down
2 changes: 1 addition & 1 deletion examples/ray_tracing_invocation_reorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ namespace RayTracingInvocationReorder {
// -noser, -nohint: SER, its coherence hint off at start.
// -noui: without the settings window.
let options = AppOptions.RayTracing;
let renderMode = RENDER_DEFAULT;
let renderMode: int = RENDER_DEFAULT;
let ser = true;
let hint = true;
let withUI = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/ray_tracing_position_fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ namespace RayTracingPositionFetch {
// -mode <n>: display mode 0 (geometric normal) or 1 (vertex position).
let options = AppOptions.RayTracing;
let withUI = true;
let displayMode = 0;
let displayMode: int = 0;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
if (arg == "-debug") {
Expand Down
2 changes: 1 addition & 1 deletion examples/shader_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ namespace ShaderObjectSample {
}
let vs = this.skyboxVS;
let ps = this.skyboxPS;
let gs = -1;
let gs: int = -1;
let cullMode = CullMode.None;
let depthWrite = 1;
if (combo == COMBO_SKYBOX) {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_bezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ namespace SimpleBezier {
// steps, the help screen).
let options = AppOptions.None;
let wireframe = false;
let partitionMode = PARTITION_INTEGER;
let partitionMode: int = PARTITION_INTEGER;
let subdivs = DEFAULT_SUBDIVS;
let rotateSteps = 0;
let showHelp = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_pbr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ namespace SimplePbr {
const i1 = pairs[e * 2 + 1];
const a = Math.max(i0, i1);
const b = Math.min(i0, i1);
let found = -1;
let found: int = -1;
for (let k = 0; k < edgeA.length; k++) {
if (edgeA[k] == a && edgeB[k] == b) {
found = edgeMid[k];
Expand Down
4 changes: 2 additions & 2 deletions examples/sparse_image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace SparseImage {

// The first position whose value isn't below value.
function lowerBound(values: int[], value: int): int {
let low = 0;
let low: int = 0;
let high = values.length;
while (low < high) {
const middle = Math.floor((low + high) / 2);
Expand Down Expand Up @@ -902,7 +902,7 @@ namespace SparseImage {
reallocate.push(false);
}
let anyToReallocate = false;
let sectorsToReallocate = 0;
let sectorsToReallocate: int = 0;

let kept: int[] = [];
for (let i = 0; i < this.sectorList.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions examples/texture_compression_basisu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ namespace TextureCompressionBasisu {
// (an index into the device's list), both transcoded at start.
let options = AppOptions.None;
let withUI = true;
let image = 0;
let target = 0;
let image: int = 0;
let target: int = 0;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
if (arg == "-debug") {
Expand Down
2 changes: 1 addition & 1 deletion examples/texture_compression_comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ namespace TextureCompressionComparison {
// -format <n>: 0 RGBA 32 (the default), 1 BC7, 2 BC3, 3 ASTC 4x4, 4 ETC2.
let options = AppOptions.None;
let withUI = true;
let format = 0;
let format: int = 0;
for (let i = 1; i < argc; i++) {
const arg = Donut_GetArg(argv, i);
if (arg == "-debug") {
Expand Down
2 changes: 1 addition & 1 deletion examples/texture_mipmap_generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ namespace TextureMipmapGeneration {
// -lodbias <x>: the level of detail bias. -rotate: the scene rotating.
let options = AppOptions.None;
let withUI = true;
let samplerIndex = 2;
let samplerIndex: int = 2;
let lodBias = 0.0;
let rotateScene = false;
for (let i = 1; i < argc; i++) {
Expand Down
2 changes: 1 addition & 1 deletion examples/timestamp_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ namespace TimestampQueries {
// -object <0..2>, -exposure <value>, -nobloom, -noskybox: the settings' initial values.
let options = AppOptions.None;
let withUI = true;
let objectIndex = 0;
let objectIndex: int = 0;
let exposure = 1.0;
let bloom = true;
let displaySkybox = true;
Expand Down
Loading