|
| 1 | +// unit-test-ptr-layout.cpp |
| 2 | + |
| 3 | +#include "slang-com-ptr.h" |
| 4 | +#include "slang.h" |
| 5 | +#include "unit-test/slang-unit-test.h" |
| 6 | + |
| 7 | +#include <stdio.h> |
| 8 | +#include <stdlib.h> |
| 9 | + |
| 10 | +using namespace Slang; |
| 11 | + |
| 12 | +SLANG_UNIT_TEST(pointerTypeLayout) |
| 13 | +{ |
| 14 | + const char* testSource = "struct TestStruct {" |
| 15 | + " int3 member0;" |
| 16 | + " float member1;" |
| 17 | + "};"; |
| 18 | + |
| 19 | + ComPtr<slang::IGlobalSession> globalSession; |
| 20 | + SLANG_CHECK(slang_createGlobalSession(SLANG_API_VERSION, globalSession.writeRef()) == SLANG_OK); |
| 21 | + slang::TargetDesc targetDesc = {}; |
| 22 | + targetDesc.format = SLANG_SPIRV; |
| 23 | + targetDesc.profile = globalSession->findProfile("spirv_1_5"); |
| 24 | + slang::SessionDesc sessionDesc = {}; |
| 25 | + sessionDesc.targetCount = 1; |
| 26 | + sessionDesc.targets = &targetDesc; |
| 27 | + sessionDesc.compilerOptionEntryCount = 1; |
| 28 | + slang::CompilerOptionEntry compilerOptionEntry = {}; |
| 29 | + compilerOptionEntry.name = slang::CompilerOptionName::EmitSpirvViaGLSL; |
| 30 | + compilerOptionEntry.value.kind = slang::CompilerOptionValueKind::Int; |
| 31 | + compilerOptionEntry.value.intValue0 = 1; |
| 32 | + sessionDesc.compilerOptionEntries = &compilerOptionEntry; |
| 33 | + |
| 34 | + ComPtr<slang::ISession> session; |
| 35 | + SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK); |
| 36 | + |
| 37 | + ComPtr<slang::IBlob> diagnosticBlob; |
| 38 | + auto module = |
| 39 | + session->loadModuleFromSourceString("m", "m.slang", testSource, diagnosticBlob.writeRef()); |
| 40 | + SLANG_CHECK(module != nullptr); |
| 41 | + |
| 42 | + |
| 43 | + auto testBody = [&]() |
| 44 | + { |
| 45 | + auto reflection = module->getLayout(); |
| 46 | + auto testStruct = reflection->findTypeByName("Ptr<TestStruct>"); |
| 47 | + auto ptrLayout = reflection->getTypeLayout(testStruct); |
| 48 | + auto valueLayout = ptrLayout->getElementTypeLayout(); |
| 49 | + SLANG_CHECK_ABORT(valueLayout->getFieldCount() == 2); |
| 50 | + SLANG_CHECK_ABORT(valueLayout->getFieldByIndex(1)->getOffset() == 12); |
| 51 | + }; |
| 52 | + |
| 53 | + testBody(); |
| 54 | +} |
0 commit comments