Depth rendering of terrain works
This commit is contained in:
@@ -115,7 +115,7 @@ struct ShaderCreateInfo
|
||||
Array<std::string> additionalModules;
|
||||
std::string name; // Debug info
|
||||
std::string entryPoint;
|
||||
Array<const char*> typeParameter;
|
||||
Array<Pair<const char*, const char*>> typeParameter;
|
||||
Map<const char*, const char*> defines;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ private:
|
||||
PCameraActor source;
|
||||
Gfx::OPipelineLayout basePassLayout;
|
||||
// Set 0: viewParameter, provided by renderpass
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
// Set 1: light environment, provided by lightenv
|
||||
static constexpr uint32 INDEX_LIGHT_ENV = 1;
|
||||
// Set 2: light culling data
|
||||
|
||||
@@ -49,9 +49,10 @@ void DepthPrepass::render()
|
||||
permutation.setVertexFile("LegacyBasePass");
|
||||
}
|
||||
graphics->beginRenderPass(renderPass);
|
||||
Array<Gfx::PRenderCommand> commands;
|
||||
for (VertexData* vertexData : VertexData::getList())
|
||||
{
|
||||
std::strncpy(permutation.vertexDataName, vertexData->getTypeName().c_str(), sizeof(permutation.vertexDataName));
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
const auto& materials = vertexData->getMaterialData();
|
||||
for (const auto& [_, materialData] : materials)
|
||||
{
|
||||
@@ -64,6 +65,7 @@ void DepthPrepass::render()
|
||||
Gfx::PermutationId id(permutation);
|
||||
|
||||
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
|
||||
command->setViewport(viewport);
|
||||
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
|
||||
//layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
||||
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
|
||||
@@ -122,11 +124,14 @@ void DepthPrepass::render()
|
||||
{
|
||||
command->draw(vertexData->getMeshVertexCount(mesh.id), 1, vertexOffset, instanceOffset);
|
||||
}
|
||||
instanceOffset+=mesh.meshes;
|
||||
}
|
||||
}
|
||||
}
|
||||
commands.add(command);
|
||||
}
|
||||
}
|
||||
graphics->executeCommands(commands);
|
||||
graphics->endRenderPass();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ private:
|
||||
|
||||
Gfx::OPipelineLayout depthPrepassLayout;
|
||||
// Set 0: viewParameter
|
||||
// Set 1: vertices, from VertexData
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
// Set 0: vertices, from VertexData
|
||||
constexpr static uint32 INDEX_VERTEX_DATA = 1;
|
||||
// Set 2: mesh data, either index buffer or meshlet data
|
||||
constexpr static uint32 INDEX_SCENE_DATA = 2;
|
||||
|
||||
@@ -36,7 +36,6 @@ protected:
|
||||
Vector2 pad0;
|
||||
} viewParams;
|
||||
PRenderGraphResources resources;
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
Gfx::ODescriptorLayout viewParamsLayout;
|
||||
Gfx::OUniformBuffer viewParamsBuffer;
|
||||
Gfx::PDescriptorSet viewParamsSet;
|
||||
|
||||
@@ -87,12 +87,12 @@ ShaderCollection& ShaderCompiler::createShaders(ShaderPermutation permutation)
|
||||
ShaderCollection collection;
|
||||
|
||||
ShaderCreateInfo createInfo;
|
||||
createInfo.typeParameter = { permutation.vertexDataName };
|
||||
createInfo.typeParameter = { Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) };
|
||||
createInfo.name = std::format("Material {0}", permutation.materialName);
|
||||
if (std::strlen(permutation.materialName) > 0)
|
||||
{
|
||||
createInfo.additionalModules.add(permutation.materialName);
|
||||
createInfo.typeParameter.add(permutation.materialName);
|
||||
createInfo.typeParameter.add(Pair<const char*, const char*>("IMaterial", permutation.materialName));
|
||||
}
|
||||
createInfo.additionalModules.add(permutation.vertexDataName);
|
||||
createInfo.additionalModules.add(permutation.vertexMeshFile);
|
||||
|
||||
@@ -36,6 +36,54 @@ void VertexData::updateMesh(const Component::Transform& transform, PMesh mesh)
|
||||
matInstanceData.numMeshes += meshData[mesh->id].size();
|
||||
}
|
||||
|
||||
void VertexData::createDescriptors()
|
||||
{
|
||||
instanceDataLayout->reset();
|
||||
for (const auto& [_, mat] : materialData)
|
||||
{
|
||||
for (auto& [_, matInst] : mat.instances)
|
||||
{
|
||||
Array<InstanceData> instanceData;
|
||||
Array<MeshData> meshes;
|
||||
for (auto& inst : matInst.meshes)
|
||||
{
|
||||
inst.meshes = 0;
|
||||
for (const auto& mesh : meshData[inst.id])
|
||||
{
|
||||
instanceData.add(inst.instance);
|
||||
meshes.add(mesh);
|
||||
inst.meshes++;
|
||||
}
|
||||
}
|
||||
matInst.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(InstanceData) * instanceData.size(),
|
||||
.data = (uint8*)instanceData.data(),
|
||||
},
|
||||
.stride = sizeof(InstanceData)
|
||||
});
|
||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
||||
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(MeshData) * meshes.size(),
|
||||
.data = (uint8*)meshes.data(),
|
||||
},
|
||||
.stride = sizeof(MeshData)
|
||||
});
|
||||
matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer);
|
||||
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
||||
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
|
||||
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
|
||||
}
|
||||
matInst.descriptorSet->writeChanges();
|
||||
matInst.numMeshes = meshes.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
|
||||
{
|
||||
meshData[id].clear();
|
||||
@@ -65,79 +113,33 @@ void VertexData::loadMesh(MeshId id, Array<Meshlet> loadedMeshlets)
|
||||
.numMeshlets = numMeshlets,
|
||||
.meshletOffset = meshletOffset,
|
||||
.indicesOffset = static_cast<uint32>(meshOffsets[id]),
|
||||
});
|
||||
});
|
||||
currentMesh += numMeshlets;
|
||||
}
|
||||
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo {
|
||||
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(MeshletDescription) * meshlets.size(),
|
||||
.data = (uint8*)meshlets.data()
|
||||
},
|
||||
.stride = sizeof(MeshletDescription),
|
||||
.dynamic = true,
|
||||
});
|
||||
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo {
|
||||
});
|
||||
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(uint32) * vertexIndices.size(),
|
||||
.data = (uint8*)vertexIndices.data(),
|
||||
},
|
||||
.stride = sizeof(uint32),
|
||||
.dynamic = true,
|
||||
});
|
||||
primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo {
|
||||
});
|
||||
primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(uint8) * primitiveIndices.size(),
|
||||
.data = (uint8*)primitiveIndices.data(),
|
||||
},
|
||||
.stride = sizeof(uint8),
|
||||
.dynamic = true,
|
||||
});
|
||||
}
|
||||
|
||||
void VertexData::createDescriptors()
|
||||
{
|
||||
for (const auto& [_, mat] : materialData)
|
||||
{
|
||||
for (auto& [_, matInst] : mat.instances)
|
||||
{
|
||||
Array<InstanceData> instanceData;
|
||||
Array<MeshData> meshes;
|
||||
for (const auto& inst : matInst.meshes)
|
||||
{
|
||||
for (const auto& mesh : meshData[inst.id])
|
||||
{
|
||||
instanceData.add(inst.instance);
|
||||
meshes.add(mesh);
|
||||
}
|
||||
}
|
||||
matInst.instanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(InstanceData) * instanceData.size(),
|
||||
.data = (uint8*)instanceData.data(),
|
||||
},
|
||||
.stride = sizeof(InstanceData)
|
||||
});
|
||||
instanceDataLayout->reset();
|
||||
matInst.descriptorSet = instanceDataLayout->allocateDescriptorSet();
|
||||
matInst.descriptorSet->updateBuffer(0, matInst.instanceBuffer);
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
matInst.meshDataBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData = {
|
||||
.size = sizeof(MeshData) * meshes.size(),
|
||||
.data = (uint8*)meshes.data(),
|
||||
},
|
||||
.stride = sizeof(MeshData)
|
||||
});
|
||||
matInst.descriptorSet->updateBuffer(1, matInst.meshDataBuffer);
|
||||
matInst.descriptorSet->updateBuffer(2, meshletBuffer);
|
||||
matInst.descriptorSet->updateBuffer(3, primitiveIndicesBuffer);
|
||||
matInst.descriptorSet->updateBuffer(4, vertexIndicesBuffer);
|
||||
}
|
||||
matInst.descriptorSet->writeChanges();
|
||||
matInst.numMeshes = meshes.size();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
MeshId VertexData::allocateVertexData(uint64 numVertices)
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
MeshId id;
|
||||
InstanceData instance;
|
||||
Gfx::PIndexBuffer indexBuffer;
|
||||
uint32 meshes;
|
||||
};
|
||||
struct MaterialInstanceData
|
||||
{
|
||||
@@ -62,8 +63,8 @@ public:
|
||||
};
|
||||
void resetMeshData();
|
||||
void updateMesh(const Component::Transform& transform, PMesh mesh);
|
||||
void loadMesh(MeshId id, Array<Meshlet> meshlets);
|
||||
void createDescriptors();
|
||||
void loadMesh(MeshId id, Array<Meshlet> meshlets);
|
||||
MeshId allocateVertexData(uint64 numVertices);
|
||||
uint64 getMeshOffset(MeshId id);
|
||||
uint64 getMeshVertexCount(MeshId id);
|
||||
|
||||
@@ -265,9 +265,10 @@ uint32 Allocator::findMemoryType(uint32 typeFilter, VkMemoryPropertyFlags proper
|
||||
throw std::runtime_error("error finding memory");
|
||||
}
|
||||
|
||||
StagingBuffer::StagingBuffer(OSubAllocation allocation, VkBuffer buffer, VkBufferUsageFlags usage, uint8 readable)
|
||||
StagingBuffer::StagingBuffer(OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, VkBufferUsageFlags usage, uint8 readable)
|
||||
: allocation(std::move(allocation))
|
||||
, buffer(buffer)
|
||||
, size(size)
|
||||
, usage(usage)
|
||||
, readable(readable)
|
||||
{
|
||||
@@ -306,7 +307,7 @@ VkDeviceSize StagingBuffer::getOffset() const
|
||||
|
||||
uint64 StagingBuffer::getSize() const
|
||||
{
|
||||
return allocation->getSize();
|
||||
return size;
|
||||
}
|
||||
|
||||
StagingManager::StagingManager(PGraphics graphics, PAllocator allocator)
|
||||
@@ -368,6 +369,7 @@ OStagingBuffer StagingManager::allocateStagingBuffer(uint64 size, VkBufferUsageF
|
||||
OStagingBuffer stagingBuffer = new StagingBuffer(
|
||||
allocator->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | (readable ? VK_MEMORY_PROPERTY_HOST_COHERENT_BIT : VK_MEMORY_PROPERTY_HOST_CACHED_BIT), buffer),
|
||||
buffer,
|
||||
size,
|
||||
usage,
|
||||
readable
|
||||
);
|
||||
|
||||
@@ -154,7 +154,7 @@ DECLARE_REF(StagingManager)
|
||||
class StagingBuffer
|
||||
{
|
||||
public:
|
||||
StagingBuffer(OSubAllocation allocation, VkBuffer buffer, VkBufferUsageFlags usage, uint8 readable);
|
||||
StagingBuffer(OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, VkBufferUsageFlags usage, uint8 readable);
|
||||
~StagingBuffer();
|
||||
void* getMappedPointer();
|
||||
void flushMappedMemory();
|
||||
@@ -179,6 +179,7 @@ public:
|
||||
private:
|
||||
OSubAllocation allocation;
|
||||
VkBuffer buffer;
|
||||
VkDeviceSize size;
|
||||
VkBufferUsageFlags usage;
|
||||
uint8 readable;
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
sessionDesc.preprocessorMacroCount = macros.size();
|
||||
sessionDesc.preprocessorMacros = macros.data();
|
||||
slang::TargetDesc vulkan;
|
||||
vulkan.profile = globalSession->findProfile("glsl_vk");
|
||||
vulkan.profile = globalSession->findProfile("sm_6_6");
|
||||
vulkan.format = SLANG_SPIRV;
|
||||
sessionDesc.targetCount = 1;
|
||||
sessionDesc.targets = &vulkan;
|
||||
@@ -85,29 +85,14 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
mainModule->findEntryPointByName(createInfo.entryPoint.c_str(), entrypoint.writeRef());
|
||||
modules.add(entrypoint);
|
||||
|
||||
slang::IComponentType* moduleComposition;
|
||||
session->createCompositeComponentType(modules.data(), modules.size(), &moduleComposition, diagnostics.writeRef());
|
||||
Slang::ComPtr<slang::IComponentType> moduleComposition;
|
||||
session->createCompositeComponentType(modules.data(), modules.size(), moduleComposition.writeRef(), diagnostics.writeRef());
|
||||
|
||||
if(diagnostics)
|
||||
{
|
||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
||||
}
|
||||
|
||||
/*slang::ProgramLayout* layout = moduleComposition->getLayout();
|
||||
for(auto typeParam : createInfo.typeParameter)
|
||||
{
|
||||
Slang::ComPtr<slang::ITypeConformance> typeConformance;
|
||||
session->createTypeConformanceComponentType(layout->findTypeByName(typeParam), layout->findTypeByName("IMaterial"), typeConformance.writeRef(), -1, diagnostics.writeRef());
|
||||
modules.add(typeConformance);
|
||||
if(diagnostics)
|
||||
{
|
||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Slang::ComPtr<slang::IComponentType> conformingModule;
|
||||
session->createCompositeComponentType(modules.data(), modules.size(), conformingModule.writeRef(), diagnostics.writeRef());
|
||||
*/
|
||||
Slang::ComPtr<slang::IComponentType> linkedProgram;
|
||||
moduleComposition->link(linkedProgram.writeRef(), diagnostics.writeRef());
|
||||
if(diagnostics)
|
||||
@@ -122,9 +107,9 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
}
|
||||
|
||||
Array<slang::SpecializationArg> specialization;
|
||||
for(auto typeArg : createInfo.typeParameter)
|
||||
for(const auto& [key, value] : createInfo.typeParameter)
|
||||
{
|
||||
specialization.add(slang::SpecializationArg::fromType(reflection->findTypeByName(typeArg)));
|
||||
specialization.add(slang::SpecializationArg::fromType(reflection->findTypeByName(value)));
|
||||
}
|
||||
Slang::ComPtr<slang::IComponentType> specializedComponent;
|
||||
linkedProgram->specialize(specialization.data(), specialization.size(), specializedComponent.writeRef(), diagnostics.writeRef());
|
||||
@@ -143,13 +128,20 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
||||
{
|
||||
std::cout << (const char*)diagnostics->getBufferPointer() << std::endl;
|
||||
}
|
||||
|
||||
VkShaderModuleCreateInfo moduleInfo;
|
||||
moduleInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||
moduleInfo.pNext = nullptr;
|
||||
moduleInfo.flags = 0;
|
||||
moduleInfo.codeSize = kernelBlob->getBufferSize();
|
||||
moduleInfo.pCode = (uint32_t*)kernelBlob->getBufferPointer();
|
||||
for (uint32 i = 0; i < reflection->getParameterCount(); ++i)
|
||||
{
|
||||
slang::VariableLayoutReflection* varLayout = reflection->getParameterByIndex(i);
|
||||
std::cout << varLayout->getName() << " in space " << varLayout->getBindingSpace() << " index " << varLayout->getBindingIndex() << std::endl;
|
||||
}
|
||||
std::cout << reflection->getGlobalConstantBufferSize() << std::endl;
|
||||
VkShaderModuleCreateInfo moduleInfo =
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.codeSize = kernelBlob->getBufferSize(),
|
||||
.pCode = (uint32_t*)kernelBlob->getBufferPointer(),
|
||||
};
|
||||
VK_CHECK(vkCreateShaderModule(graphics->getDevice(), &moduleInfo, nullptr, &module));
|
||||
|
||||
hash = CRC::Calculate(entryPointName.data(), entryPointName.size(), CRC::CRC_32());
|
||||
|
||||
Reference in New Issue
Block a user