Formatted EVERYTHING
This commit is contained in:
@@ -1,17 +1,29 @@
|
||||
#include "slang-compile.h"
|
||||
#include <slang.h>
|
||||
#include "Containers/Array.h"
|
||||
#include <fmt/core.h>
|
||||
#include <iostream>
|
||||
#include <slang.h>
|
||||
|
||||
#define CHECK_RESULT(x) {SlangResult r = x; if(r != 0) {throw std::runtime_error(fmt::format("Error: {0}", r));}}
|
||||
#define CHECK_DIAGNOSTICS() {if(diagnostics) {std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; assert(false);}}
|
||||
|
||||
Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& createInfo, SlangCompileTarget target, Map<std::string, uint32>& paramMapping)
|
||||
{
|
||||
#define CHECK_RESULT(x) \
|
||||
{ \
|
||||
SlangResult r = x; \
|
||||
if (r != 0) { \
|
||||
throw std::runtime_error(fmt::format("Error: {0}", r)); \
|
||||
} \
|
||||
}
|
||||
#define CHECK_DIAGNOSTICS() \
|
||||
{ \
|
||||
if (diagnostics) { \
|
||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; \
|
||||
assert(false); \
|
||||
} \
|
||||
}
|
||||
|
||||
Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& createInfo, SlangCompileTarget target,
|
||||
Map<std::string, uint32>& paramMapping) {
|
||||
thread_local Slang::ComPtr<slang::IGlobalSession> globalSession;
|
||||
if(!globalSession)
|
||||
{
|
||||
if (!globalSession) {
|
||||
slang::createGlobalSession(globalSession.writeRef());
|
||||
}
|
||||
slang::SessionDesc sessionDesc;
|
||||
@@ -34,8 +46,7 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
||||
sessionDesc.compilerOptionEntryCount = option.size();
|
||||
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
|
||||
Array<slang::PreprocessorMacroDesc> macros;
|
||||
for(const auto& [key, val] : createInfo.defines)
|
||||
{
|
||||
for (const auto& [key, val] : createInfo.defines) {
|
||||
macros.add(slang::PreprocessorMacroDesc{
|
||||
.name = key,
|
||||
.value = val,
|
||||
@@ -57,8 +68,7 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
||||
Slang::ComPtr<slang::IBlob> diagnostics;
|
||||
Array<slang::IComponentType*> modules;
|
||||
Slang::ComPtr<slang::IEntryPoint> entrypoint;
|
||||
for (const auto& moduleName : createInfo.additionalModules)
|
||||
{
|
||||
for (const auto& moduleName : createInfo.additionalModules) {
|
||||
modules.add(session->loadModule(moduleName.c_str(), diagnostics.writeRef()));
|
||||
CHECK_DIAGNOSTICS();
|
||||
}
|
||||
@@ -73,7 +83,7 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
||||
session->createCompositeComponentType(modules.data(), modules.size(), moduleComposition.writeRef(), diagnostics.writeRef());
|
||||
|
||||
CHECK_DIAGNOSTICS();
|
||||
|
||||
|
||||
Slang::ComPtr<slang::IComponentType> linkedProgram;
|
||||
moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef());
|
||||
|
||||
@@ -84,38 +94,26 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
||||
CHECK_DIAGNOSTICS();
|
||||
|
||||
Array<slang::SpecializationArg> specialization;
|
||||
for(const auto& [key, value] : createInfo.typeParameter)
|
||||
{
|
||||
for (const auto& [key, value] : createInfo.typeParameter) {
|
||||
specialization.add(slang::SpecializationArg::fromType(reflection->findTypeByName(value)));
|
||||
}
|
||||
Slang::ComPtr<slang::IComponentType> specializedComponent;
|
||||
linkedProgram->specialize(specialization.data(), specialization.size(), specializedComponent.writeRef(), diagnostics.writeRef());
|
||||
CHECK_DIAGNOSTICS();
|
||||
|
||||
|
||||
Slang::ComPtr<slang::IBlob> kernelBlob;
|
||||
specializedComponent->getEntryPointCode(
|
||||
0,
|
||||
0,
|
||||
kernelBlob.writeRef(),
|
||||
diagnostics.writeRef()
|
||||
);
|
||||
specializedComponent->getEntryPointCode(0, 0, kernelBlob.writeRef(), diagnostics.writeRef());
|
||||
CHECK_DIAGNOSTICS();
|
||||
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
|
||||
CHECK_DIAGNOSTICS();
|
||||
for(size_t i = 0; i < signature->getParameterCount(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < signature->getParameterCount(); ++i) {
|
||||
auto param = signature->getParameterByIndex(i);
|
||||
// workaround
|
||||
if (std::strcmp(param->getName(), "pVertexData") == 0)
|
||||
{
|
||||
if (std::strcmp(param->getName(), "pVertexData") == 0) {
|
||||
paramMapping[param->getName()] = 1;
|
||||
}
|
||||
else if (std::strcmp(param->getName(), "pMaterial") == 0)
|
||||
{
|
||||
} else if (std::strcmp(param->getName(), "pMaterial") == 0) {
|
||||
paramMapping[param->getName()] = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
paramMapping[param->getName()] = param->getBindingIndex();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user