slang doesnt support mesh shading yet, exploring later
This commit is contained in:
Binary file not shown.
@@ -1,19 +0,0 @@
|
|||||||
#version 450
|
|
||||||
#extension GL_EXT_mesh_shader : require
|
|
||||||
layout(row_major) uniform;
|
|
||||||
layout(row_major) buffer;
|
|
||||||
|
|
||||||
#line 27 0
|
|
||||||
layout(local_size_x = 3, local_size_y = 1, local_size_z = 1) in;
|
|
||||||
layout(max_vertices = 12) out;
|
|
||||||
layout(max_primitives = 4) out;
|
|
||||||
layout(triangles) out;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
|
|
||||||
SetMeshOutputsEXT(12U, 4U);
|
|
||||||
|
|
||||||
#line 46
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
{
|
|
||||||
"EntryPoint": "taskMain",
|
|
||||||
"FunctionConstants": [],
|
|
||||||
"NeedsFunctionConstants": false,
|
|
||||||
"Resources": [
|
|
||||||
{
|
|
||||||
"abIndex": 0,
|
|
||||||
"slot": 0,
|
|
||||||
"type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"abIndex": 1,
|
|
||||||
"slot": 1,
|
|
||||||
"type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"abIndex": 2,
|
|
||||||
"slot": 2,
|
|
||||||
"type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"abIndex": 3,
|
|
||||||
"slot": 3,
|
|
||||||
"type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"abIndex": 4,
|
|
||||||
"slot": 0,
|
|
||||||
"type": "CBV"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"ShaderID": "2266638404583382645",
|
|
||||||
"ShaderType": "Amplification",
|
|
||||||
"TopLevelArgumentBuffer": [
|
|
||||||
{
|
|
||||||
"EltOffset": 0,
|
|
||||||
"Size": 24,
|
|
||||||
"Slot": 0,
|
|
||||||
"Space": 2,
|
|
||||||
"Type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"EltOffset": 24,
|
|
||||||
"Size": 24,
|
|
||||||
"Slot": 1,
|
|
||||||
"Space": 2,
|
|
||||||
"Type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"EltOffset": 48,
|
|
||||||
"Size": 24,
|
|
||||||
"Slot": 2,
|
|
||||||
"Space": 2,
|
|
||||||
"Type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"EltOffset": 72,
|
|
||||||
"Size": 24,
|
|
||||||
"Slot": 3,
|
|
||||||
"Space": 2,
|
|
||||||
"Type": "SRV"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"EltOffset": 96,
|
|
||||||
"Size": 24,
|
|
||||||
"Slot": 0,
|
|
||||||
"Space": 1,
|
|
||||||
"Type": "CBV"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"max_payload_size_in_bytes": 4096,
|
|
||||||
"num_threads": [
|
|
||||||
128,
|
|
||||||
1,
|
|
||||||
1
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -71,7 +71,7 @@ public:
|
|||||||
PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout);
|
PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout);
|
||||||
virtual ~PipelineLayout();
|
virtual ~PipelineLayout();
|
||||||
virtual void create() override;
|
virtual void create() override;
|
||||||
Array<Array<uint32>>
|
|
||||||
private:
|
private:
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#include "Metal/MTLLibrary.hpp"
|
#include "Metal/MTLLibrary.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <metal_irconverter/metal_irconverter.h>
|
|
||||||
#include <slang.h>
|
#include <slang.h>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
@@ -27,127 +26,20 @@ Shader::~Shader() {
|
|||||||
void Shader::create(const ShaderCreateInfo& createInfo) {
|
void Shader::create(const ShaderCreateInfo& createInfo) {
|
||||||
std::cout << "Compiling " << createInfo.name << std::endl;
|
std::cout << "Compiling " << createInfo.name << std::endl;
|
||||||
Map<std::string, uint32> paramMapping;
|
Map<std::string, uint32> paramMapping;
|
||||||
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_DXIL, paramMapping);
|
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_METAL, paramMapping);
|
||||||
|
std::cout << (char*)kernelBlob->getBufferPointer() << std::endl;
|
||||||
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
|
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
|
||||||
IRCompiler* pCompiler = IRCompilerCreate();
|
dispatch_data_t dispatchData = dispatch_data_create(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), dispatch_get_main_queue(), NULL);
|
||||||
IRCompilerSetMinimumGPUFamily(pCompiler, IRGPUFamilyMetal3);
|
NS::Error* error;
|
||||||
IRCompilerIgnoreRootSignature(pCompiler, true);
|
library = graphics->getDevice()->newLibrary(dispatchData, &error);
|
||||||
IRCompilerSetEntryPointName(pCompiler, "main");
|
if(error)
|
||||||
IRCompilerSetValidationFlags(pCompiler, IRCompilerValidationFlagAll);
|
{
|
||||||
|
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
|
||||||
IRObject* pDXIL = IRObjectCreateFromDXIL((const uint8*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(),
|
|
||||||
IRBytecodeOwnershipNone);
|
|
||||||
IRVersionedRootSignatureDescriptor descriptor;
|
|
||||||
descriptor.version = IRRootSignatureVersion_1_1;
|
|
||||||
Map<std::string, Gfx::PDescriptorLayout> layouts = createInfo.rootSignature->getLayouts();
|
|
||||||
descriptor.desc_1_1.NumParameters = layouts.size();
|
|
||||||
descriptor.desc_1_1.NumStaticSamplers = 0;
|
|
||||||
descriptor.desc_1_1.pStaticSamplers = nullptr;
|
|
||||||
Array<IRRootParameter1> parameters;
|
|
||||||
// each layout has an array for its bindings
|
|
||||||
Array<Array<IRDescriptorRange1>> ranges;
|
|
||||||
for (const auto& [name, layout] : layouts) {
|
|
||||||
uint32 textureReg = 0; // SRV
|
|
||||||
uint32 samplerReg = 0; // Sampler
|
|
||||||
uint32 uavReg = 0; // UAV
|
|
||||||
uint32 constantReg = 0; // CBV
|
|
||||||
auto& bindingRanges = ranges.add();
|
|
||||||
for (auto binding : layout->getBindings()) {
|
|
||||||
IRDescriptorRangeType type;
|
|
||||||
uint32 reg = 0;
|
|
||||||
switch (binding.descriptorType) {
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
||||||
type = IRDescriptorRangeTypeSRV;
|
|
||||||
reg = textureReg++;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
||||||
type = IRDescriptorRangeTypeCBV;
|
|
||||||
reg = constantReg++;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
|
||||||
if (binding.access == Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT) {
|
|
||||||
type = IRDescriptorRangeTypeSRV;
|
|
||||||
reg = textureReg++;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
type = IRDescriptorRangeTypeUAV;
|
|
||||||
reg = uavReg++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw std::logic_error("Not implemented");
|
|
||||||
};
|
|
||||||
bindingRanges.add() = IRDescriptorRange1{
|
|
||||||
.BaseShaderRegister = reg,
|
|
||||||
.NumDescriptors = binding.descriptorCount,
|
|
||||||
.RangeType = type,
|
|
||||||
.RegisterSpace = createInfo.rootSignature->findParameter(name),
|
|
||||||
.Flags = IRDescriptorRangeFlagDescriptorsStaticKeepingBufferBoundsChecks,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
parameters.add() = IRRootParameter1{
|
|
||||||
.ParameterType = IRRootParameterTypeDescriptorTable,
|
|
||||||
.DescriptorTable =
|
|
||||||
IRRootDescriptorTable1{.NumDescriptorRanges = (uint32)(bindingRanges.size()), bindingRanges.data()},
|
|
||||||
.ShaderVisibility = IRShaderVisibilityAll,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
IRError* signatureError = nullptr;
|
|
||||||
descriptor.desc_1_1.NumParameters = parameters.size();
|
|
||||||
descriptor.desc_1_1.pParameters = parameters.data();
|
|
||||||
IRRootSignature* rootSignature = IRRootSignatureCreateFromDescriptor(&descriptor, &signatureError);
|
|
||||||
assert(rootSignature);
|
|
||||||
// IRCompilerSetGlobalRootSignature(pCompiler, rootSignature);
|
|
||||||
// Compile DXIL to Metal IR:
|
|
||||||
IRError* pError = nullptr;
|
|
||||||
IRObject* pOutIR = IRCompilerAllocCompileAndLink(pCompiler, NULL, pDXIL, &pError);
|
|
||||||
|
|
||||||
if (!pOutIR) {
|
|
||||||
// Inspect pError to determine cause.
|
|
||||||
IRErrorDestroy(pError);
|
|
||||||
}
|
|
||||||
IRShaderStage irStage;
|
|
||||||
switch (stage) {
|
|
||||||
case Gfx::SE_SHADER_STAGE_VERTEX_BIT:
|
|
||||||
irStage = IRShaderStageVertex;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_SHADER_STAGE_FRAGMENT_BIT:
|
|
||||||
irStage = IRShaderStageFragment;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_SHADER_STAGE_COMPUTE_BIT:
|
|
||||||
irStage = IRShaderStageCompute;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_SHADER_STAGE_TASK_BIT_EXT:
|
|
||||||
irStage = IRShaderStageAmplification;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_SHADER_STAGE_MESH_BIT_EXT:
|
|
||||||
irStage = IRShaderStageMesh;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Retrieve Metallib:
|
|
||||||
IRMetalLibBinary* pMetallib = IRMetalLibBinaryCreate();
|
|
||||||
IRObjectGetMetalLibBinary(pOutIR, irStage, pMetallib);
|
|
||||||
dispatch_data_t data = IRMetalLibGetBytecodeData(pMetallib);
|
|
||||||
|
|
||||||
IRShaderReflection* reflection = IRShaderReflectionCreate();
|
|
||||||
IRObjectGetReflection(pOutIR, irStage, reflection);
|
|
||||||
std::cout << IRShaderReflectionAllocStringAndSerialize(reflection) << std::endl;
|
|
||||||
IRShaderReflectionDestroy(reflection);
|
|
||||||
|
|
||||||
// Store the metallib to custom format or disk, or use to create a MTLLibrary.
|
|
||||||
NS::Error* error;
|
|
||||||
library = graphics->getDevice()->newLibrary(data, &error);
|
|
||||||
function = library->newFunction(NS::String::string("main", NS::ASCIIStringEncoding));
|
function = library->newFunction(NS::String::string("main", NS::ASCIIStringEncoding));
|
||||||
if (!function) {
|
if (!function) {
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
IRMetalLibBinaryDestroy(pMetallib);
|
|
||||||
IRObjectDestroy(pDXIL);
|
|
||||||
IRObjectDestroy(pOutIR);
|
|
||||||
IRCompilerDestroy(pCompiler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Shader::getShaderHash() const { return hash; }
|
uint32 Shader::getShaderHash() const { return hash; }
|
||||||
|
|||||||
@@ -28,9 +28,18 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
|||||||
}
|
}
|
||||||
sessionDesc.preprocessorMacroCount = macros.size();
|
sessionDesc.preprocessorMacroCount = macros.size();
|
||||||
sessionDesc.preprocessorMacros = macros.data();
|
sessionDesc.preprocessorMacros = macros.data();
|
||||||
|
slang::CompilerOptionEntry option;
|
||||||
|
option.name = slang::CompilerOptionName::IgnoreCapabilities;
|
||||||
|
option.value = slang::CompilerOptionValue();
|
||||||
|
option.value.kind = slang::CompilerOptionValueKind::Int;
|
||||||
|
option.value.intValue0 = 1;
|
||||||
slang::TargetDesc targetDesc;
|
slang::TargetDesc targetDesc;
|
||||||
|
targetDesc.compilerOptionEntries = &option;
|
||||||
|
targetDesc.compilerOptionEntryCount = 1;
|
||||||
targetDesc.profile = globalSession->findProfile("sm_6_6");
|
targetDesc.profile = globalSession->findProfile("sm_6_6");
|
||||||
targetDesc.format = target;
|
targetDesc.format = target;
|
||||||
|
targetDesc.compilerOptionEntryCount = 1;
|
||||||
|
targetDesc.compilerOptionEntries = &option;
|
||||||
sessionDesc.targetCount = 1;
|
sessionDesc.targetCount = 1;
|
||||||
sessionDesc.targets = &targetDesc;
|
sessionDesc.targets = &targetDesc;
|
||||||
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
|
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
|
||||||
@@ -99,6 +108,7 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
|||||||
}
|
}
|
||||||
for(size_t i = 0; i < signature->getParameterCount(); ++i)
|
for(size_t i = 0; i < signature->getParameterCount(); ++i)
|
||||||
{
|
{
|
||||||
|
auto param = signature->getParameterByIndex(i);
|
||||||
paramMapping[param->getName()] = offset++;
|
paramMapping[param->getName()] = offset++;
|
||||||
}
|
}
|
||||||
return kernelBlob;
|
return kernelBlob;
|
||||||
|
|||||||
Reference in New Issue
Block a user