templated pipeline
This commit is contained in:
parent
8275e01b6c
commit
74832c6824
8 changed files with 229 additions and 170 deletions
|
|
@ -9,31 +9,32 @@ import Crafter.Math;
|
|||
typedef VulkanShader<"raygen.spv", "main", VK_SHADER_STAGE_RAYGEN_BIT_KHR, 2, {{{VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1}}}> Raygenspv;
|
||||
typedef VulkanShader<"closesthit.spv", "main", VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, 0, {{}}> Closesthitspv;
|
||||
typedef VulkanShader<"miss.spv", "main", VK_SHADER_STAGE_MISS_BIT_KHR, 0, {{}}> Misspv;
|
||||
typedef std::tuple<Raygenspv, Misspv, Closesthitspv> AllShaders;
|
||||
typedef std::tuple<
|
||||
ShaderGroup<0, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR>,
|
||||
ShaderGroup<1, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR>,
|
||||
ShaderGroup<VK_SHADER_UNUSED_KHR, 2, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR>
|
||||
> ShaderGroups;
|
||||
typedef PipelineRTVulkan<AllShaders, ShaderGroups> Pipeline;
|
||||
|
||||
int main() {
|
||||
/*
|
||||
This sets up all necessary things and creates the vulkan device.
|
||||
This must be called before any vulkan related things.
|
||||
Things like VkDevice are static members of the VulkanDevice class.
|
||||
*/
|
||||
VulkanDevice::CreateDevice();
|
||||
VulkanDevice::CreateDevice();
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
|
||||
Raygenspv::CreateShader();
|
||||
Closesthitspv::CreateShader();
|
||||
Misspv::CreateShader();
|
||||
|
||||
ShaderBindingTableVulkan<AllShaders>::Init();
|
||||
std::array<VkDescriptorSetLayout, 3> layouts {{Raygenspv::layout, Raygenspv::layout, Raygenspv::layout}};
|
||||
PipelineRTVulkan<Raygenspv, Closesthitspv, Misspv, Raygenspv, Closesthitspv, Misspv>::Init(layouts);
|
||||
Pipeline::Init(cmd, layouts);
|
||||
window.SetPipelineRT<Pipeline>();
|
||||
|
||||
DescriptorPool pool;
|
||||
pool.sets.resize(3);
|
||||
pool.BuildPool(DescriptorPool::GetPoolSizes<Raygenspv, Raygenspv, Raygenspv>(), layouts);
|
||||
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
|
||||
/*
|
||||
StartInit gives you a VkCommandBuffer to use before the event loop starts
|
||||
Use this for inititializing things like textures.
|
||||
*/
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
|
||||
Mesh triangleMesh;
|
||||
std::array<Vertex, 3> verts {{{-150, -150, 100}, {0, 150, 100}, {150, -150, 100}}};
|
||||
std::array<std::uint32_t, 3> index {{2,1,0}};
|
||||
|
|
@ -41,13 +42,12 @@ int main() {
|
|||
RenderingElement3DVulkan& el = RenderingElement3DVulkan::elements.emplace_back(triangleMesh);
|
||||
MatrixRowMajor<float, 4, 3, 1> transform = MatrixRowMajor<float, 4, 3, 1>::Identity();
|
||||
std::memcpy(el.instance.transform.matrix, transform.m, sizeof(transform.m));
|
||||
|
||||
RenderingElement3DVulkan::tlases.resize(3);
|
||||
|
||||
window.SetPipelineRT<Raygenspv, Closesthitspv, Misspv, Raygenspv, Closesthitspv, Misspv>();
|
||||
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 0);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 1);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 2);
|
||||
|
||||
VkDescriptorImageInfo imageInfo = {
|
||||
.imageView = window.imageViews[0],
|
||||
.imageLayout = VK_IMAGE_LAYOUT_GENERAL
|
||||
|
|
|
|||
|
|
@ -9,30 +9,28 @@ import Crafter.Math;
|
|||
typedef VulkanShader<"raygen.spv", "main", VK_SHADER_STAGE_RAYGEN_BIT_KHR, 2, {{{VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 0}, {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1}}}> Raygenspv;
|
||||
typedef VulkanShader<"closesthit.spv", "main", VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, 0, {{}}> Closesthitspv;
|
||||
typedef VulkanShader<"miss.spv", "main", VK_SHADER_STAGE_MISS_BIT_KHR, 0, {{}}> Misspv;
|
||||
typedef std::tuple<Raygenspv, Misspv, Closesthitspv> AllShaders;
|
||||
typedef std::tuple<
|
||||
ShaderGroup<0, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR>,
|
||||
ShaderGroup<1, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR>,
|
||||
ShaderGroup<VK_SHADER_UNUSED_KHR, 2, VK_SHADER_UNUSED_KHR, VK_SHADER_UNUSED_KHR>
|
||||
> ShaderGroups;
|
||||
typedef PipelineRTVulkan<AllShaders, ShaderGroups> Pipeline;
|
||||
|
||||
int main() {
|
||||
/*
|
||||
This sets up all necessary things and creates the vulkan device.
|
||||
This must be called before any vulkan related things.
|
||||
Things like VkDevice are static members of the VulkanDevice class.
|
||||
*/
|
||||
VulkanDevice::CreateDevice();
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
|
||||
Raygenspv::CreateShader();
|
||||
Closesthitspv::CreateShader();
|
||||
Misspv::CreateShader();
|
||||
ShaderBindingTableVulkan<AllShaders>::Init();
|
||||
std::array<VkDescriptorSetLayout, 1> layouts {{Raygenspv::layout}};
|
||||
PipelineRTVulkan<Raygenspv, Closesthitspv, Misspv, Raygenspv, Closesthitspv, Misspv>::Init(layouts);
|
||||
Pipeline::Init(cmd, layouts);
|
||||
DescriptorPool pool;
|
||||
pool.sets.resize(1);
|
||||
pool.BuildPool(DescriptorPool::GetPoolSizes<Raygenspv, Closesthitspv, Misspv>(), layouts);
|
||||
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
|
||||
/*
|
||||
StartInit gives you a VkCommandBuffer to use before the event loop starts
|
||||
Use this for inititializing things like textures.
|
||||
*/
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
pool.BuildPool(DescriptorPool::GetPoolSizes<Raygenspv>(), layouts);
|
||||
|
||||
Mesh triangleMesh;
|
||||
std::array<Vertex, 3> verts {{{-150, -150, 100}, {0, 150, 100}, {150, -150, 100}}};
|
||||
|
|
@ -77,17 +75,10 @@ int main() {
|
|||
};
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 2, write, 0, nullptr);
|
||||
|
||||
|
||||
/*
|
||||
FinishInit executes all commands recorded to StartInit.
|
||||
This must be called before the the event loops starts if you called StartInit before.
|
||||
*/
|
||||
window.FinishInit();
|
||||
|
||||
window.SetPipelineRT<Raygenspv, Closesthitspv, Misspv, Raygenspv, Closesthitspv, Misspv>();
|
||||
window.SetPipelineRT<Pipeline>();
|
||||
window.descriptorsRt = pool.sets;
|
||||
|
||||
|
||||
window.FinishInit();
|
||||
window.Render();
|
||||
window.StartSync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-vulkan"
|
||||
"configuration":"lib-vulkan-debug"
|
||||
}
|
||||
],
|
||||
"shaders": [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue