yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaCorrect include dir for libslang (#5539)7b570feed

master
2.2 KiB62 linesraw
1// unit-test-fcpw-compile.cpp
2
3#include "../../source/core/slang-io.h"
4#include "../../source/core/slang-process.h"
5#include "slang-com-ptr.h"
6#include "slang.h"
7#include "unit-test/slang-unit-test.h"
8
9#include <stdio.h>
10#include <stdlib.h>
11
12using namespace Slang;
13
14// A test that uses the COM API to load and compile the FCPW library written by
15// Rohan Sawhney, shader code in MIT license.
16// https://github.com/rohan-sawhney/fcpw
17//
18SLANG_UNIT_TEST(fcpwCompile)
19{
20    ComPtr<slang::IGlobalSession> globalSession;
21    SLANG_CHECK(slang_createGlobalSession(SLANG_API_VERSION, globalSession.writeRef()) == SLANG_OK);
22    slang::TargetDesc targetDesc = {};
23    targetDesc.format = SLANG_SPIRV;
24    targetDesc.profile = globalSession->findProfile("spirv_1_5");
25    slang::SessionDesc sessionDesc = {};
26    sessionDesc.targetCount = 1;
27    sessionDesc.targets = &targetDesc;
28    sessionDesc.preprocessorMacroCount = 1;
29    slang::PreprocessorMacroDesc macroDesc = {};
30    macroDesc.name = "_BVH_TYPE";
31    macroDesc.value = "2";
32    sessionDesc.preprocessorMacros = &macroDesc;
33    ComPtr<slang::ISession> session;
34    SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK);
35
36    ComPtr<slang::IBlob> diagnosticBlob;
37    auto module =
38        session->loadModule("tests/fcpw/bvh-traversal.cs.slang", diagnosticBlob.writeRef());
39    SLANG_CHECK(module != nullptr);
40
41    ComPtr<slang::IEntryPoint> entryPoint;
42    module->findEntryPointByName("rayIntersection", entryPoint.writeRef());
43    SLANG_CHECK(entryPoint != nullptr);
44
45    ComPtr<slang::IComponentType> compositeProgram;
46    slang::IComponentType* components[] = {module, entryPoint.get()};
47    session->createCompositeComponentType(
48        components,
49        2,
50        compositeProgram.writeRef(),
51        diagnosticBlob.writeRef());
52    SLANG_CHECK(compositeProgram != nullptr);
53
54    ComPtr<slang::IComponentType> linkedProgram;
55    compositeProgram->link(linkedProgram.writeRef(), diagnosticBlob.writeRef());
56    SLANG_CHECK(linkedProgram != nullptr);
57
58    ComPtr<slang::IBlob> code;
59    linkedProgram->getEntryPointCode(0, 0, code.writeRef(), diagnosticBlob.writeRef());
60    SLANG_CHECK(code != nullptr);
61    SLANG_CHECK(code->getBufferSize() != 0);
62}