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 KiB68 linesraw
1// unit-test-image-format-reflection.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// Test that the getBindingRangeImageFormat API works.
15
16SLANG_UNIT_TEST(imageFormatReflection)
17{
18    // Source for a module that contains an undecorated entrypoint.
19    const char* userSourceBody = R"(
20        Texture2D<uint4> g_tex : register(t0);
21        float4 fragMain(float4 pos:SV_Position) : SV_Position
22        {
23            return pos;
24        }
25        )";
26
27    auto moduleName = "moduleG" + String(Process::getId());
28    String userSource = "import " + moduleName + ";\n" + userSourceBody;
29    ComPtr<slang::IGlobalSession> globalSession;
30    SLANG_CHECK(slang_createGlobalSession(SLANG_API_VERSION, globalSession.writeRef()) == SLANG_OK);
31    slang::TargetDesc targetDesc = {};
32    targetDesc.format = SLANG_HLSL;
33    targetDesc.profile = globalSession->findProfile("sm_5_0");
34    slang::SessionDesc sessionDesc = {};
35    sessionDesc.targetCount = 1;
36    sessionDesc.targets = &targetDesc;
37    ComPtr<slang::ISession> session;
38    SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK);
39
40    ComPtr<slang::IBlob> diagnosticBlob;
41    auto module = session->loadModuleFromSourceString(
42        "m",
43        "m.slang",
44        userSourceBody,
45        diagnosticBlob.writeRef());
46    SLANG_CHECK(module != nullptr);
47
48    ComPtr<slang::IEntryPoint> entryPoint;
49    module->findAndCheckEntryPoint(
50        "fragMain",
51        SLANG_STAGE_FRAGMENT,
52        entryPoint.writeRef(),
53        diagnosticBlob.writeRef());
54    SLANG_CHECK(entryPoint != nullptr);
55
56    ComPtr<slang::IComponentType> compositeProgram;
57    slang::IComponentType* components[] = {module, entryPoint.get()};
58    session->createCompositeComponentType(
59        components,
60        2,
61        compositeProgram.writeRef(),
62        diagnosticBlob.writeRef());
63    SLANG_CHECK(compositeProgram != nullptr);
64
65    auto layout = compositeProgram->getLayout(0);
66    auto format = layout->getGlobalParamsTypeLayout()->getBindingRangeImageFormat(0);
67    SLANG_CHECK(format == SLANG_IMAGE_FORMAT_rgba32ui);
68}