#include "vulkan/vulkan.h" #include import Crafter.Graphics; using namespace Crafter; import std; import Crafter.Event; import Crafter.Math; int main() { Device::Initialize(); Window window(1280, 720, "HelloVulkan"); VkCommandBuffer cmd = window.StartInit(); DescriptorHeapVulkan descriptorHeap; descriptorHeap.Initialize(1,2,0); VkSpecializationMapEntry entry = { .constantID = 0, .offset = 0, .size = sizeof(uint16_t) }; VkSpecializationInfo specilizationInfo = { .mapEntryCount = 1, .pMapEntries = &entry, .dataSize = sizeof(uint16_t), .pData = &descriptorHeap.bufferStartElement }; std::array shaders{{ {"raygen.spv", "main", VK_SHADER_STAGE_RAYGEN_BIT_KHR, &specilizationInfo} }}; ShaderBindingTableVulkan shaderTable; shaderTable.Init(shaders); std::array raygenGroups {{ { .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR, .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR, .generalShader = 0, .closestHitShader = VK_SHADER_UNUSED_KHR, .anyHitShader = VK_SHADER_UNUSED_KHR, .intersectionShader = VK_SHADER_UNUSED_KHR, }, }}; std::array missGroups; std::array hitGroups; PipelineRTVulkan pipeline; pipeline.Init(cmd, raygenGroups, missGroups, hitGroups, shaderTable); window.FinishInit(); RendertargetBase<3> rendertargetBase(1280, 720); RenderingElement2DVulkan element( { 0.5, //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor 0.5, //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor 0.5, //relativeSizeX: the relative x size this element should be scaled to compared to its parent 0.5, //relativeSizeY: the relative y size this element should be scaled to compared to its parent 0.5, //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle) 0.5, //anchorOffsetY: the amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle) 0 //z: this elements Z position }, 2, 1 ); for(std::uint8_t i = 0; i < Window::numFrames; i++) { reinterpret_cast, true>*>(element.buffers[i])->value[0] = {1, 0, 0, 1}; reinterpret_cast, true>*>(element.buffers[i])->value[1] = {0, 1, 0, 1}; reinterpret_cast, true>*>(element.buffers[i])->FlushDevice(); } InitializeRenderingElement2DVulkanBuffer(); element.UpdatePosition(rendertargetBase, rendertargetBase.transform); renderingElement2DVulkanTransformBuffer[0].FlushDevice(); renderingElement2DVulkanTransformBuffer[1].FlushDevice(); renderingElement2DVulkanTransformBuffer[2].FlushDevice(); VkImageDescriptorInfoEXT imageInfo0 = { .sType = VK_STRUCTURE_TYPE_IMAGE_DESCRIPTOR_INFO_EXT, .pView = &window.imageViews[0], .layout = VK_IMAGE_LAYOUT_GENERAL }; VkImageDescriptorInfoEXT imageInfo1 = { .sType = VK_STRUCTURE_TYPE_IMAGE_DESCRIPTOR_INFO_EXT, .pView = &window.imageViews[1], .layout = VK_IMAGE_LAYOUT_GENERAL }; VkImageDescriptorInfoEXT imageInfo2 = { .sType = VK_STRUCTURE_TYPE_IMAGE_DESCRIPTOR_INFO_EXT, .pView = &window.imageViews[2], .layout = VK_IMAGE_LAYOUT_GENERAL }; std::array infos; infos[0] = { .sType = VK_STRUCTURE_TYPE_RESOURCE_DESCRIPTOR_INFO_EXT, .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, .data = { .pImage = &imageInfo0 } }; infos[1] = { .sType = VK_STRUCTURE_TYPE_RESOURCE_DESCRIPTOR_INFO_EXT, .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, .data = { .pImage = &imageInfo1 } }; infos[2] = { .sType = VK_STRUCTURE_TYPE_RESOURCE_DESCRIPTOR_INFO_EXT, .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, .data = { .pImage = &imageInfo2 } }; std::array ranges; ranges[0] = { .address = descriptorHeap.resourceHeap[0].value, .size = Device::descriptorHeapProperties.imageDescriptorSize }; ranges[1] = { .address = descriptorHeap.resourceHeap[1].value, .size = Device::descriptorHeapProperties.imageDescriptorSize }, ranges[2] = { .address = descriptorHeap.resourceHeap[2].value, .size = Device::descriptorHeapProperties.imageDescriptorSize }, WriteRenderingElement2DVulkanDescriptors(infos, ranges, 3, descriptorHeap.bufferStartOffset, descriptorHeap); window.pipeline = &pipeline; window.descriptorHeap = &descriptorHeap; window.Render(); window.StartSync(); }