adding anyhit, doesnt work though
This commit is contained in:
@@ -172,7 +172,7 @@ void BasePass::render() {
|
||||
// LightEnv => provided by scene
|
||||
// Material => per material
|
||||
// LightCulling => calculated by pass
|
||||
permutation.setMaterial(materialData.material->getName());
|
||||
permutation.setMaterial(materialData.material->getName(), materialData.material->getProfile());
|
||||
Gfx::PermutationId id(permutation);
|
||||
|
||||
Gfx::ORenderCommand command = graphics->createRenderCommand("BaseRender");
|
||||
@@ -273,7 +273,7 @@ void BasePass::render() {
|
||||
transparentCommand->setViewport(viewport);
|
||||
for (const auto& [_, t] : sortedDraws) {
|
||||
permutation.setVertexData(t.vertexData->getTypeName());
|
||||
permutation.setMaterial(t.matInst->getBaseMaterial()->getName());
|
||||
permutation.setMaterial(t.matInst->getBaseMaterial()->getName(), t.matInst->getBaseMaterial()->getProfile());
|
||||
Gfx::PermutationId id(permutation);
|
||||
|
||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
||||
|
||||
@@ -87,7 +87,7 @@ void RayTracingPass::render() {
|
||||
PMaterial mat = matData.material;
|
||||
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("RayTracing");
|
||||
permutation.setMaterial(mat->getName());
|
||||
permutation.setMaterial(mat->getName(), mat->getProfile());
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
|
||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(Gfx::PermutationId(permutation));
|
||||
@@ -97,6 +97,7 @@ void RayTracingPass::render() {
|
||||
for (uint32 i = 0; i < inst.instanceData.size(); ++i) {
|
||||
Gfx::RayTracingHitGroup callableGroup = {
|
||||
.closestHitShader = collection->callableShader,
|
||||
.anyHitShader = anyhit,
|
||||
};
|
||||
callableGroup.parameters.resize(sizeof(VertexData::DrawCallOffsets));
|
||||
std::memcpy(callableGroup.parameters.data(), &inst.offsets, sizeof(VertexData::DrawCallOffsets));
|
||||
@@ -111,12 +112,13 @@ void RayTracingPass::render() {
|
||||
PMaterial mat = transparentData.matInst->getBaseMaterial();
|
||||
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("RayTracing");
|
||||
permutation.setMaterial(mat->getName());
|
||||
permutation.setMaterial(mat->getName(), mat->getProfile());
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(Gfx::PermutationId(permutation));
|
||||
assert(collection != nullptr);
|
||||
Gfx::RayTracingHitGroup callableGroup = {
|
||||
.closestHitShader = collection->callableShader,
|
||||
.anyHitShader = anyhit,
|
||||
};
|
||||
callableGroup.parameters.resize(sizeof(VertexData::DrawCallOffsets));
|
||||
std::memcpy(callableGroup.parameters.data(), &transparentData.offsets, sizeof(VertexData::DrawCallOffsets));
|
||||
@@ -200,14 +202,15 @@ void RayTracingPass::publishOutputs() {
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
|
||||
ShaderCompilationInfo compileInfo = {
|
||||
.name = "RayGenMiss",
|
||||
.modules = {"RayGen", "Miss"},
|
||||
.entryPoints = {{"raygen", "RayGen"}, {"miss", "Miss"}},
|
||||
.modules = {"RayGen", "AnyHit", "Miss"},
|
||||
.entryPoints = {{"raygen", "RayGen"}, {"anyhit", "AnyHit"}, {"miss", "Miss"}},
|
||||
.defines = {{"RAY_TRACING", "1"}},
|
||||
.rootSignature = pipelineLayout,
|
||||
};
|
||||
graphics->beginShaderCompilation(compileInfo);
|
||||
rayGen = graphics->createRayGenShader({0});
|
||||
miss = graphics->createMissShader({1});
|
||||
anyhit = graphics->createAnyHitShader({1});
|
||||
miss = graphics->createMissShader({2});
|
||||
pipelineLayout->create();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class RayTracingPass : public RenderPass {
|
||||
Gfx::PTextureCube skyBox;
|
||||
Gfx::OSampler skyBoxSampler;
|
||||
Gfx::ORayGenShader rayGen;
|
||||
Gfx::OAnyHitShader anyhit;
|
||||
Gfx::OMissShader miss;
|
||||
Gfx::PRayTracingPipeline pipeline;
|
||||
Gfx::OTopLevelAS tlas;
|
||||
|
||||
@@ -66,7 +66,7 @@ void ShaderCompiler::compile() {
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
permutation.setMaterial(mat->getName());
|
||||
permutation.setMaterial(mat->getName(), mat->getProfile());
|
||||
createShaders(permutation, std::move(layout), name);
|
||||
});
|
||||
}
|
||||
@@ -108,6 +108,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
|
||||
if (std::strlen(permutation.materialName) > 0) {
|
||||
createInfo.modules.add(permutation.materialName);
|
||||
createInfo.defines["MATERIAL_FILE_NAME"] = permutation.materialName;
|
||||
//createInfo.typeParameter.add({"IBRDF", "Phong"});
|
||||
}
|
||||
if (permutation.positionOnly) {
|
||||
createInfo.defines["POS_ONLY"] = "1";
|
||||
|
||||
@@ -91,6 +91,7 @@ struct ShaderPermutation {
|
||||
char vertexMeshFile[32];
|
||||
char fragmentFile[32];
|
||||
char vertexDataName[32];
|
||||
char brdfProfile[32];
|
||||
char materialName[64];
|
||||
uint8 hasFragment;
|
||||
uint8 useMeshShading;
|
||||
@@ -106,36 +107,38 @@ struct ShaderPermutation {
|
||||
void setTaskFile(std::string_view name) {
|
||||
std::memset(taskFile, 0, sizeof(taskFile));
|
||||
hasTaskShader = 1;
|
||||
strncpy(taskFile, name.data(), sizeof(taskFile));
|
||||
strncpy(taskFile, name.data(), name.size());
|
||||
}
|
||||
void setVertexFile(std::string_view name) {
|
||||
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
|
||||
useMeshShading = 0;
|
||||
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
|
||||
strncpy(vertexMeshFile, name.data(), name.size());
|
||||
}
|
||||
void setMeshFile(std::string_view name) {
|
||||
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
|
||||
useMeshShading = 1;
|
||||
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
|
||||
strncpy(vertexMeshFile, name.data(), name.size());
|
||||
}
|
||||
void setRayTracingFile(std::string_view name) {
|
||||
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
|
||||
rayTracing = true;
|
||||
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
|
||||
strncpy(vertexMeshFile, name.data(), name.size());
|
||||
}
|
||||
void setFragmentFile(std::string_view name) {
|
||||
std::memset(fragmentFile, 0, sizeof(fragmentFile));
|
||||
hasFragment = 1;
|
||||
strncpy(fragmentFile, name.data(), sizeof(fragmentFile));
|
||||
strncpy(fragmentFile, name.data(), name.size());
|
||||
}
|
||||
void setVertexData(std::string_view name) {
|
||||
std::memset(vertexDataName, 0, sizeof(vertexDataName));
|
||||
strncpy(vertexDataName, name.data(), sizeof(vertexDataName));
|
||||
strncpy(vertexDataName, name.data(), name.size());
|
||||
}
|
||||
void setMaterial(std::string_view name) {
|
||||
void setMaterial(std::string_view name, std::string_view brdf) {
|
||||
std::memset(materialName, 0, sizeof(materialName));
|
||||
std::memset(brdfProfile, 0, sizeof(brdfProfile));
|
||||
useMaterial = 1;
|
||||
strncpy(materialName, name.data(), sizeof(materialName));
|
||||
strncpy(materialName, name.data(), name.size());
|
||||
strncpy(brdfProfile, brdf.data(), brdf.size());
|
||||
}
|
||||
void setPositionOnly(bool enable) { positionOnly = enable; }
|
||||
void setDepthCulling(bool enable) { depthCulling = enable; }
|
||||
|
||||
@@ -508,6 +508,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
uint32 intersectionIndex = VK_SHADER_UNUSED_KHR;
|
||||
if (hitgroup.anyHitShader != nullptr) {
|
||||
auto anyHit = hitgroup.anyHitShader.cast<AnyHitShader>();
|
||||
anyHitIndex = shaderStages.size();
|
||||
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -520,6 +521,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
||||
}
|
||||
if (hitgroup.intersectionShader != nullptr) {
|
||||
auto intersect = hitgroup.intersectionShader.cast<IntersectionShader>();
|
||||
intersectionIndex = shaderGroups.size();
|
||||
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
|
||||
@@ -18,6 +18,7 @@ using namespace Seele;
|
||||
{ \
|
||||
if (diagnostics) { \
|
||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; \
|
||||
abort(); \
|
||||
} \
|
||||
}
|
||||
|
||||
@@ -88,7 +89,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
||||
sessionDesc.preprocessorMacroCount = macros.size();
|
||||
sessionDesc.preprocessorMacros = macros.data();
|
||||
slang::TargetDesc targetDesc;
|
||||
targetDesc.profile = globalSession->findProfile("glsl_450");
|
||||
targetDesc.profile = globalSession->findProfile("spv_1_4");
|
||||
targetDesc.format = target;
|
||||
sessionDesc.targetCount = 1;
|
||||
sessionDesc.targets = &targetDesc;
|
||||
@@ -149,10 +150,10 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
||||
if (info.name == "RayGenMiss")
|
||||
{
|
||||
layout->addMapping("pVertexData", 1);
|
||||
layout->addMapping("pResources", 4);
|
||||
layout->addMapping("pLightEnv", 3);
|
||||
layout->addMapping("pRayTracingParams", 5);
|
||||
layout->addMapping("pScene", 2);
|
||||
layout->addMapping("pLightEnv", 3);
|
||||
layout->addMapping("pResources", 4);
|
||||
layout->addMapping("pRayTracingParams", 5);
|
||||
}
|
||||
// layout->addMapping("pWaterMaterial", 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user