Istill can't figure that out
This commit is contained in:
@@ -182,6 +182,7 @@ bool device_evaluate(GraphicsDevice* g, VkPhysicalDevice device)
|
||||
|
||||
// does the device support the extensions we need?
|
||||
if (!device_evaluate_extensions(device, DEVICE_EXTENSIONS)) {
|
||||
yolo::error("Device {} does not support required extensions", deviceProperties.deviceName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -319,7 +320,13 @@ void device_create_vulkan_physical_device(GraphicsDevice* device)
|
||||
// established the device with the best score, or the only one in the system.
|
||||
device->VulkanPhysicalDevice = candidates.rbegin()->second;
|
||||
} else {
|
||||
yolo::error("failed to find a suitable GPU!");
|
||||
// log all devices and their scores
|
||||
for (const auto& device_candidate : candidates) {
|
||||
VkPhysicalDeviceProperties deviceProperties;
|
||||
vkGetPhysicalDeviceProperties(device_candidate.second, &deviceProperties);
|
||||
yolo::error("Device {} scored {}", deviceProperties.deviceName, device_candidate.first);
|
||||
}
|
||||
yolo::error("Failed to find a suitable GPU!");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,18 @@
|
||||
|
||||
namespace inferno::graphics {
|
||||
|
||||
// #define VALIDATION_LAYERS_ENABLED 1
|
||||
#define VALIDATION_LAYERS_ENABLED 1
|
||||
#ifdef VALIDATION_LAYERS_ENABLED
|
||||
const std::vector<const char*> VALIDATION_LAYERS = {
|
||||
"VK_LAYER_KHRONOS_validation",
|
||||
// "VK_LAYER_KHRONOS_validation",
|
||||
// "VK_LAYER_RENDERDOC_Capture",
|
||||
};
|
||||
#endif
|
||||
|
||||
const std::vector<const char*> DEVICE_EXTENSIONS = {
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
|
||||
VK_EXT_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS_EXTENSION_NAME,
|
||||
// VK_EXT_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS_EXTENSION_NAME,
|
||||
};
|
||||
|
||||
struct VulkanRenderer;
|
||||
|
||||
@@ -231,6 +231,35 @@ void dynamic_rendertarget_update(DynamicCPUTarget* target, void* data, VkExtent2
|
||||
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
|
||||
|
||||
// Sync with Fence
|
||||
// we need a fence here because we need to wait for the image to be ready
|
||||
// before we can copy to it
|
||||
VkFenceCreateInfo fenceInfo {};
|
||||
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
fenceInfo.flags = 0;
|
||||
|
||||
VkFence fence;
|
||||
if (vkCreateFence(target->Device->VulkanDevice, &fenceInfo, nullptr, &fence)
|
||||
!= VK_SUCCESS) {
|
||||
yolo::error("failed to create fence!");
|
||||
}
|
||||
|
||||
VkSubmitInfo submitInfo {};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.pNext = nullptr;
|
||||
submitInfo.waitSemaphoreCount = 0;
|
||||
submitInfo.pWaitSemaphores = nullptr;
|
||||
submitInfo.pWaitDstStageMask = nullptr;
|
||||
submitInfo.commandBufferCount = 0;
|
||||
submitInfo.pCommandBuffers = nullptr;
|
||||
submitInfo.signalSemaphoreCount = 0;
|
||||
submitInfo.pSignalSemaphores = nullptr;
|
||||
|
||||
if (vkQueueSubmit(target->Device->VulkanGraphicsQueue, 1, &submitInfo, fence)
|
||||
!= VK_SUCCESS) {
|
||||
yolo::error("failed to submit queue!");
|
||||
}
|
||||
|
||||
vkWaitForFences(target->Device->VulkanDevice, 1, &fence, VK_TRUE, UINT64_MAX);
|
||||
|
||||
// Map Memory
|
||||
void* mappedData;
|
||||
@@ -239,13 +268,16 @@ void dynamic_rendertarget_update(DynamicCPUTarget* target, void* data, VkExtent2
|
||||
memcpy(mappedData, data, target->StagingBuffer->Size);
|
||||
vkUnmapMemory(target->Device->VulkanDevice, target->StagingBuffer->DeviceData);
|
||||
|
||||
transition_image_layout(target->Device, target->Image, target->Format,
|
||||
VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
|
||||
// No we have the data in the buffer, let's move it to the image
|
||||
graphics::renderer_submit_now(
|
||||
target->Device->RenderContext, [&](VulkanRenderer* re, VkCommandBuffer* cmd) {
|
||||
VkBufferImageCopy region {};
|
||||
region.bufferOffset = 0;
|
||||
region.bufferRowLength = 0;
|
||||
region.bufferImageHeight = 0;
|
||||
region.bufferRowLength = size.width;
|
||||
region.bufferImageHeight = size.height;
|
||||
|
||||
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
region.imageSubresource.mipLevel = 0;
|
||||
@@ -260,6 +292,8 @@ void dynamic_rendertarget_update(DynamicCPUTarget* target, void* data, VkExtent2
|
||||
});
|
||||
|
||||
// Sync with Fence
|
||||
vkResetFences(target->Device->VulkanDevice, 1, &fence);
|
||||
vkDestroyFence(target->Device->VulkanDevice, fence, nullptr);
|
||||
|
||||
// Transition to whatever we need
|
||||
transition_image_layout(target->Device, target->Image, target->Format,
|
||||
|
||||
@@ -249,24 +249,24 @@ void inferno_end(InfernoApp* app)
|
||||
|
||||
int inferno_run(InfernoApp* app)
|
||||
{
|
||||
graphics::renderer_submit_repeat(
|
||||
app->Renderer,
|
||||
[&](graphics::VulkanRenderer* renderer, VkCommandBuffer* commandBuffer) {
|
||||
const auto lucy = app->Scene->Objects[0];
|
||||
for (auto& mesh : scene::scene_object_get_meshs(lucy)) {
|
||||
for (int i = 0; i < mesh->Indicies.size() - 1; i += 3) {
|
||||
graphics::debug_draw_line(mesh->Verticies[mesh->Indicies[i]].Position,
|
||||
mesh->Verticies[mesh->Indicies[i + 1]].Position, { 0, 0, 1 });
|
||||
graphics::debug_draw_line(
|
||||
mesh->Verticies[mesh->Indicies[i + 1]].Position,
|
||||
mesh->Verticies[mesh->Indicies[i + 2]].Position, { 0, 0, 1 });
|
||||
graphics::debug_draw_line(
|
||||
mesh->Verticies[mesh->Indicies[i + 2]].Position,
|
||||
mesh->Verticies[mesh->Indicies[i]].Position, { 0, 0, 1 });
|
||||
}
|
||||
}
|
||||
},
|
||||
false);
|
||||
// graphics::renderer_submit_repeat(
|
||||
// app->Renderer,
|
||||
// [&](graphics::VulkanRenderer* renderer, VkCommandBuffer* commandBuffer) {
|
||||
// const auto lucy = app->Scene->Objects[0];
|
||||
// for (auto& mesh : scene::scene_object_get_meshs(lucy)) {
|
||||
// for (int i = 0; i < mesh->Indicies.size() - 1; i += 3) {
|
||||
// graphics::debug_draw_line(mesh->Verticies[mesh->Indicies[i]].Position,
|
||||
// mesh->Verticies[mesh->Indicies[i + 1]].Position, { 0, 0, 1 });
|
||||
// graphics::debug_draw_line(
|
||||
// mesh->Verticies[mesh->Indicies[i + 1]].Position,
|
||||
// mesh->Verticies[mesh->Indicies[i + 2]].Position, { 0, 0, 1 });
|
||||
// graphics::debug_draw_line(
|
||||
// mesh->Verticies[mesh->Indicies[i + 2]].Position,
|
||||
// mesh->Verticies[mesh->Indicies[i]].Position, { 0, 0, 1 });
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// false);
|
||||
|
||||
while (graphics::window_new_frame()) {
|
||||
if (!inferno_pre(app))
|
||||
@@ -353,15 +353,15 @@ int inferno_run(InfernoApp* app)
|
||||
}
|
||||
|
||||
if (ImGui::Begin("Render")) {
|
||||
// static ImVec2 lastViewport = { 0, 0 };
|
||||
// ImVec2 currentViewport = ImGui::GetWindowSize();
|
||||
// if (lastViewport.x != currentViewport.x
|
||||
// || lastViewport.y != currentViewport.y) {
|
||||
// graphics::camera_ray_set_viewport(scene::scene_get_camera(app->Scene),
|
||||
// { ImGui::GetWindowSize().x, ImGui::GetWindowSize().y });
|
||||
// graphics::rayr_set_viewport(app->RayRenderer, app->Scene->Camera);
|
||||
// }
|
||||
// lastViewport = currentViewport;
|
||||
static ImVec2 lastViewport = { 0, 0 };
|
||||
ImVec2 currentViewport = ImGui::GetWindowSize();
|
||||
if (lastViewport.x != currentViewport.x
|
||||
|| lastViewport.y != currentViewport.y) {
|
||||
graphics::camera_ray_set_viewport(scene::scene_get_camera(app->Scene),
|
||||
{ ImGui::GetWindowSize().x, ImGui::GetWindowSize().y });
|
||||
graphics::rayr_set_viewport(app->RayRenderer, app->Scene->Camera);
|
||||
}
|
||||
lastViewport = currentViewport;
|
||||
|
||||
graphics::rayr_draw(app->RayRenderer);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ void rayr_set_viewport(RayRenderer* renderer, Camera* camera)
|
||||
delete[] renderer->RenderData;
|
||||
renderer->RenderData
|
||||
= new glm::fvec4[renderer->Viewport.extent.width * renderer->Viewport.extent.height];
|
||||
memset(renderer->RenderData, 0,
|
||||
memset(renderer->RenderData, 1,
|
||||
renderer->Viewport.extent.width * renderer->Viewport.extent.height * sizeof(glm::fvec4));
|
||||
|
||||
// Now resize the rendertarget
|
||||
@@ -103,15 +103,15 @@ void rayr_draw(RayRenderer* renderer)
|
||||
scene::scene_frame_tick(renderer->Scene);
|
||||
// TODO: Rays should definately be bump allocated if possible, this is KBs of
|
||||
// ray data and nothing else being reallocated every frame for no reason
|
||||
rays::ReferencedRayField startRays
|
||||
= rays::generate_initial_rays(scene::scene_get_camera(renderer->Scene), true);
|
||||
// rays::ReferencedRayField startRays
|
||||
// = rays::generate_initial_rays(scene::scene_get_camera(renderer->Scene), true);
|
||||
|
||||
#pragma omp parallel for
|
||||
for (int x = 0; x < renderer->Viewport.extent.width; x++) {
|
||||
for (int y = 0; y < renderer->Viewport.extent.height; y++) {
|
||||
rays::Ray* ray = startRays.Field[x * renderer->Viewport.extent.height + y];
|
||||
// rays::Ray* ray = startRays.Field[x * renderer->Viewport.extent.height + y];
|
||||
renderer->RenderData[y * renderer->Viewport.extent.width + x]
|
||||
= { ray->Direction.x, ray->Direction.y, ray->Direction.z, 1.0 };
|
||||
// = { ray->Direction.x, ray->Direction.y, ray->Direction.z, 1.0 };
|
||||
= { 1.0, 1.0, 1.0, 1.0 };
|
||||
// rays::HitInfo* closest_hit = nullptr;
|
||||
//
|
||||
// for (auto& obj : scene::scene_get_renderables(renderer->Scene)) {
|
||||
|
||||
Reference in New Issue
Block a user