mirror of
https://github.com/ZDoom/ZDRay.git
synced 2025-01-24 16:51:08 +00:00
Create the pipeline
This commit is contained in:
parent
df1172346d
commit
d573f9e907
2 changed files with 49 additions and 2 deletions
|
@ -84,6 +84,9 @@ void GPURaytracer::Raytrace(LevelMesh* level)
|
|||
printf("Creating shaders\n");
|
||||
CreateShaders();
|
||||
|
||||
printf("Creating pipeline\n");
|
||||
CreatePipeline();
|
||||
|
||||
cmdbuffer->end();
|
||||
|
||||
#if 0
|
||||
|
@ -325,12 +328,12 @@ void GPURaytracer::CreateVertexAndIndexBuffers()
|
|||
size_t indexoffset = vertexoffset + vertexbuffersize;
|
||||
|
||||
BufferBuilder vbuilder;
|
||||
vbuilder.setUsage(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
|
||||
vbuilder.setUsage(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
|
||||
vbuilder.setSize(vertexbuffersize);
|
||||
vertexBuffer = vbuilder.create(device.get());
|
||||
|
||||
BufferBuilder ibuilder;
|
||||
ibuilder.setUsage(VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
|
||||
ibuilder.setUsage(VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
|
||||
ibuilder.setSize(indexbuffersize);
|
||||
indexBuffer = ibuilder.create(device.get());
|
||||
|
||||
|
@ -611,3 +614,39 @@ void GPURaytracer::CreateShaders()
|
|||
shaderClosestHit = builder.create(device.get());
|
||||
}
|
||||
}
|
||||
|
||||
void GPURaytracer::CreatePipeline()
|
||||
{
|
||||
DescriptorSetLayoutBuilder setbuilder;
|
||||
setbuilder.addBinding(0, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
|
||||
setbuilder.addBinding(1, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
|
||||
setbuilder.addBinding(2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
|
||||
descriptorSetLayout = setbuilder.create(device.get());
|
||||
|
||||
PipelineLayoutBuilder layoutbuilder;
|
||||
layoutbuilder.addSetLayout(descriptorSetLayout.get());
|
||||
pipelineLayout = layoutbuilder.create(device.get());
|
||||
|
||||
RayTracingPipelineBuilder builder;
|
||||
builder.setLayout(pipelineLayout.get());
|
||||
builder.setMaxPipelineRayRecursionDepth(1);
|
||||
builder.addShader(VK_SHADER_STAGE_RAYGEN_BIT_KHR, shaderRayGen.get());
|
||||
builder.addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, shaderClosestHit.get());
|
||||
builder.addShader(VK_SHADER_STAGE_MISS_BIT_KHR, shaderMiss.get());
|
||||
pipeline = builder.create(device.get());
|
||||
|
||||
BufferBuilder bufbuilder;
|
||||
bufbuilder.setUsage(VK_BUFFER_USAGE_SHADER_BINDING_TABLE_BIT_KHR | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
|
||||
bufbuilder.setSize(pipeline->shaderGroupHandles.size());
|
||||
shaderBindingTable = bufbuilder.create(device.get());
|
||||
|
||||
BufferBuilder tbuilder;
|
||||
tbuilder.setUsage(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_CPU_ONLY);
|
||||
tbuilder.setSize(pipeline->shaderGroupHandles.size());
|
||||
sbtTransferBuffer = tbuilder.create(device.get());
|
||||
auto data = sbtTransferBuffer->Map(0, pipeline->shaderGroupHandles.size());
|
||||
memcpy(data, pipeline->shaderGroupHandles.data(), pipeline->shaderGroupHandles.size());
|
||||
sbtTransferBuffer->Unmap();
|
||||
|
||||
cmdbuffer->copyBuffer(sbtTransferBuffer.get(), shaderBindingTable.get());
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ private:
|
|||
void CreateBottomLevelAccelerationStructure();
|
||||
void CreateTopLevelAccelerationStructure();
|
||||
void CreateShaders();
|
||||
void CreatePipeline();
|
||||
|
||||
void RaytraceProbeSample(LightProbeSample* probe);
|
||||
void RaytraceSurfaceSample(Surface* surface, int x, int y);
|
||||
|
@ -55,6 +56,13 @@ private:
|
|||
std::unique_ptr<VulkanShader> shaderMiss;
|
||||
std::unique_ptr<VulkanShader> shaderClosestHit;
|
||||
|
||||
std::unique_ptr<VulkanDescriptorSetLayout> descriptorSetLayout;
|
||||
|
||||
std::unique_ptr<VulkanPipelineLayout> pipelineLayout;
|
||||
std::unique_ptr<VulkanPipeline> pipeline;
|
||||
std::unique_ptr<VulkanBuffer> shaderBindingTable;
|
||||
std::unique_ptr<VulkanBuffer> sbtTransferBuffer;
|
||||
|
||||
std::unique_ptr<VulkanCommandPool> cmdpool;
|
||||
std::unique_ptr<VulkanCommandBuffer> cmdbuffer;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue