Win32 vulkan window
This commit is contained in:
parent
415e523a45
commit
b5e69c90fa
12 changed files with 950 additions and 85 deletions
|
|
@ -6,17 +6,17 @@ import std;
|
|||
import Crafter.Event;
|
||||
import Crafter.Math;
|
||||
|
||||
typedef VulkanShader<"raygen.spv", "main", VK_SHADER_STAGE_RAYGEN_BIT_KHR> Raygenspv;
|
||||
typedef VulkanShader<"closesthit.spv", "main", VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR> Closesthitspv;
|
||||
typedef VulkanShader<"miss.spv", "main", VK_SHADER_STAGE_MISS_BIT_KHR> Misspv;
|
||||
typedef VulkanShaderConst<"raygen.spv", "main", VK_SHADER_STAGE_RAYGEN_BIT_KHR> Raygenspv;
|
||||
typedef VulkanShaderConst<"closesthit.spv", "main", VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR> Closesthitspv;
|
||||
typedef VulkanShaderConst<"miss.spv", "main", VK_SHADER_STAGE_MISS_BIT_KHR> 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;
|
||||
typedef DescriptorSetLayoutVulkan<2, {{
|
||||
typedef PipelineRTVulkanConst<AllShaders, ShaderGroups> Pipeline;
|
||||
typedef DescriptorSetLayoutVulkanConst<3, {{
|
||||
{
|
||||
.binding = 0,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
|
||||
|
|
@ -28,6 +28,12 @@ typedef DescriptorSetLayoutVulkan<2, {{
|
|||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_KHR,
|
||||
},
|
||||
{
|
||||
.binding = 2,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_KHR,
|
||||
}
|
||||
}}> descriptorSetLayout;
|
||||
|
||||
|
|
@ -39,7 +45,7 @@ int main() {
|
|||
Raygenspv::CreateShader();
|
||||
Closesthitspv::CreateShader();
|
||||
Misspv::CreateShader();
|
||||
ShaderBindingTableVulkan<AllShaders>::Init();
|
||||
ShaderBindingTableVulkanConst<AllShaders>::Init();
|
||||
|
||||
descriptorSetLayout::Init();
|
||||
std::array<VkDescriptorSetLayout, 1> layouts {{descriptorSetLayout::layout}};
|
||||
|
|
@ -51,12 +57,24 @@ int main() {
|
|||
Pipeline::Init(cmd, layouts);
|
||||
|
||||
Mesh triangleMesh;
|
||||
std::array<Vertex, 3> verts {{{-150, -150, 100}, {0, 150, 100}, {150, -150, 100}}};
|
||||
std::array<Vector<float, 3, 3>, 3> verts {{{-150, -150, 100}, {0, 150, 100}, {150, -150, 100}}};
|
||||
std::array<std::uint32_t, 3> index {{2,1,0}};
|
||||
triangleMesh.Build(verts, index, cmd);
|
||||
RenderingElement3DVulkan& el = RenderingElement3DVulkan::elements.emplace_back(triangleMesh);
|
||||
|
||||
RenderingElement3DVulkan renderer = {
|
||||
.instance = {
|
||||
.instanceCustomIndex = 0,
|
||||
.mask = 0xFF,
|
||||
.instanceShaderBindingTableRecordOffset = 0,
|
||||
.flags = VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR,
|
||||
.accelerationStructureReference = triangleMesh.blasAddr
|
||||
}
|
||||
};
|
||||
|
||||
RenderingElement3DVulkan::elements.emplace_back(&renderer);
|
||||
|
||||
MatrixRowMajor<float, 4, 3, 1> transform = MatrixRowMajor<float, 4, 3, 1>::Identity();
|
||||
std::memcpy(el.instance.transform.matrix, transform.m, sizeof(transform.m));
|
||||
std::memcpy(renderer.instance.transform.matrix, transform.m, sizeof(transform.m));
|
||||
RenderingElement3DVulkan::tlases.resize(1);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 0);
|
||||
|
||||
|
|
@ -71,7 +89,10 @@ int main() {
|
|||
.pAccelerationStructures = &RenderingElement3DVulkan::tlases[0].accelerationStructure
|
||||
};
|
||||
|
||||
VkWriteDescriptorSet write[2] = {
|
||||
VulkanBuffer<std::uint32_t, true, false, false> lightBuffer;
|
||||
lightBuffer.Create(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, 1);
|
||||
|
||||
VkWriteDescriptorSet write[3] = {
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = &writeDescriptorSetAccelerationStructure,
|
||||
|
|
@ -89,9 +110,19 @@ int main() {
|
|||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
|
||||
.pImageInfo = &imageInfo
|
||||
},
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.dstSet = pool.sets[0],
|
||||
.dstBinding = 2,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.pBufferInfo = &lightBuffer.descriptor
|
||||
}
|
||||
};
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 2, write, 0, nullptr);
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 3, write, 0, nullptr);
|
||||
|
||||
|
||||
window.SetPipelineRT<Pipeline>();
|
||||
window.descriptorsRt = pool.sets;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-vulkan-debug"
|
||||
"configuration":"lib-vulkan"
|
||||
}
|
||||
],
|
||||
"shaders": [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue