aboutsummaryrefslogtreecommitdiffstats
path: root/api-test
diff options
context:
space:
mode:
Diffstat (limited to 'api-test')
-rw-r--r--api-test/command-buffer.cpp76
-rw-r--r--api-test/main.cpp30
-rw-r--r--api-test/vk-device.cpp41
3 files changed, 136 insertions, 11 deletions
diff --git a/api-test/command-buffer.cpp b/api-test/command-buffer.cpp
index 799968c..b130d3d 100644
--- a/api-test/command-buffer.cpp
+++ b/api-test/command-buffer.cpp
@@ -18,7 +18,7 @@ void command_buffer::start() const {
VKCHECK(vkBeginCommandBuffer(vk_command_buffer, &begin_info));
- const auto& bindless = vkdevice::get_render_device()->get_bindingmodel();
+ const auto& bindless = vkdevice::get_render_device()->get_bindingmodel();
const auto* global_set = &bindless.sets[BindlessSetType::GLOBAL];
if (queue_type == QueueType::GRAPHICS) {
vkCmdBindDescriptorSets(vk_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, bindless.layout, 0, 1U, global_set, 0U, nullptr);
@@ -80,7 +80,7 @@ void command_buffer::barrier(handle<device_texture> texture_handle, VkPipelineSt
}
void command_buffer::copy(handle<device_buffer> buffer_handle, ::handle<device_texture> texture_handle, VkDeviceSize offset) const {
- auto* device = vkdevice::get_render_device();
+ auto* device = vkdevice::get_render_device();
const auto& buffer = device->get_buffer(buffer_handle);
const auto& texture = device->get_texture(texture_handle);
VkImageAspectFlags aspect_mask = ((texture.desc.usages & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0U)
@@ -109,7 +109,7 @@ void command_buffer::copy(handle<device_buffer> buffer_handle, ::handle<device_t
vkCmdCopyBufferToImage(vk_command_buffer, buffer.vk_buffer, texture.vk_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &buffer_to_image_copy);
}
-void graphics_command_buffer::dispatch(const dispatch_params& params) {
+void graphics_command_buffer::dispatch(const dispatch_params& params) const {
const auto& pipeline = vkdevice::get_render_device()->get_pipeline(params.pipeline);
const auto& bindless = vkdevice::get_render_device()->get_bindingmodel();
vkCmdBindDescriptorSets(vk_command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, bindless.layout, static_cast<uint32_t>(BindlessSetType::UNIFORMS), 1U, &bindless.sets[BindlessSetType::UNIFORMS], 1U, &params.uniforms_offset);
@@ -118,3 +118,73 @@ void graphics_command_buffer::dispatch(const dispatch_params& params) {
vkCmdDispatch(vk_command_buffer, params.group_size.x / params.local_group_size.x, params.group_size.y / params.local_group_size.y, params.group_size.z / params.local_group_size.z);
}
+
+void graphics_command_buffer::begin_renderpass(const renderpass_params& params) const {
+ std::vector<VkRenderingAttachmentInfo> attachments_info(params.color_attachments.size());
+
+ for (auto index{ 0U }; index < params.color_attachments.size(); index++) {
+ auto& attachment_info = attachments_info[index];
+ auto& attachment = vkdevice::get_render_device()->get_texture(params.color_attachments[index]);
+
+ attachment_info.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
+ attachment_info.pNext = nullptr;
+ attachment_info.imageView = attachment.whole_view;
+ attachment_info.imageLayout = attachment.layout;
+ attachment_info.resolveMode = VK_RESOLVE_MODE_NONE;
+ attachment_info.resolveImageView = nullptr;
+ attachment_info.resolveImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ attachment_info.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
+ attachment_info.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ attachment_info.clearValue = VkClearValue{
+ .color = {
+ .float32 = { 0.f, 0.f, 0.f, 0.f },
+ },
+ };
+ }
+
+ VkRect2D scissor{
+ .offset{
+ .x = params.render_area.x,
+ .y = params.render_area.x,
+ },
+ .extent{
+ .width = params.render_area.width,
+ .height = params.render_area.height,
+ },
+ };
+ VkViewport viewport{
+ .x = static_cast<float>(params.render_area.x),
+ .y = static_cast<float>(params.render_area.y),
+ .width = static_cast<float>(params.render_area.width),
+ .height = static_cast<float>(params.render_area.height),
+ .minDepth = 0.f,
+ .maxDepth = 1.f,
+ };
+ VkRenderingInfo rendering_info{
+ .sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
+ .pNext = nullptr,
+ .flags = 0U,
+ .renderArea = scissor,
+ .layerCount = 1U,
+ .viewMask = 0U,
+ .colorAttachmentCount = static_cast<uint32_t>(attachments_info.size()),
+ .pColorAttachments = attachments_info.data(),
+ .pDepthAttachment = nullptr,
+ .pStencilAttachment = nullptr,
+ };
+ vkCmdBeginRendering(vk_command_buffer, &rendering_info);
+
+ vkCmdSetScissor(vk_command_buffer, 0U, 1U, &scissor);
+ vkCmdSetViewport(vk_command_buffer, 0U, 1U, &viewport);
+}
+
+void graphics_command_buffer::render(const draw_params& params) const {
+ const auto& pipeline = vkdevice::get_render_device()->get_pipeline(params.pipeline);
+
+ vkCmdBindPipeline(vk_command_buffer, pipeline.bind_point, pipeline.vk_pipeline);
+ vkCmdDraw(vk_command_buffer, params.vertex_count, params.instance_count, 0U, 0U);
+}
+
+void graphics_command_buffer::end_renderpass() const {
+ vkCmdEndRendering(vk_command_buffer);
+}
diff --git a/api-test/main.cpp b/api-test/main.cpp
index 35b8639..d6a4b3b 100644
--- a/api-test/main.cpp
+++ b/api-test/main.cpp
@@ -1,6 +1,7 @@
#include <cassert>
#include <cstdio>
#include <span>
+#include <array>
#include <vk_mem_alloc.h>
#define STB_IMAGE_IMPLEMENTATION
@@ -10,6 +11,8 @@
#include "vk-device.hpp"
#include "utils.hpp"
+struct device_texture;
+
#define ENABLE_RENDERDOC
#ifdef ENABLE_RENDERDOC
@@ -30,7 +33,9 @@ int main() {
}
#endif
- window wnd { 640U, 360U };
+ constexpr size_t window_width = 640U;
+ constexpr size_t window_height = 360U;
+ window wnd { window_width, window_height };
#ifdef ENABLE_RENDERDOC
if(rdoc_api != nullptr) rdoc_api->StartFrameCapture(nullptr, nullptr);
@@ -58,7 +63,7 @@ int main() {
auto gpu_texture_handle = device->create_texture({
.width = static_cast<uint32_t>(width),
.height = static_cast<uint32_t>(height),
- .usages = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
+ .usages = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
.format = VK_FORMAT_R8G8B8A8_UNORM,
.type = VK_IMAGE_TYPE_2D,
});
@@ -97,11 +102,13 @@ int main() {
.cs_code = std::span(code),
});
+ std::array<VkFormat, 1U> formats { VK_FORMAT_R8G8B8A8_UNORM };
auto vertex_code = read_file("shaders/api-test-ui.vert.spv");
auto fragment_code = read_file("shaders/api-test-ui.frag.spv");
auto graphics = device->create_pipeline({
.vs_code = std::span(vertex_code),
.fs_code = std::span(fragment_code),
+ .color_attachments_format = formats
});
@@ -138,6 +145,25 @@ int main() {
.uniforms_offset = 0U,
});
+ std::array<handle<device_texture>, 1U> color_attachment {gpu_texture_handle};
+
+ command_buffer.barrier(gpu_texture_handle, VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
+ command_buffer.begin_renderpass({
+ .render_area = {
+ .x = 0,
+ .y = 0,
+ .width = window_width,
+ .height = window_height,
+ },
+ .color_attachments = color_attachment,
+ });
+ command_buffer.render({
+ .pipeline = graphics,
+ .vertex_count = 3U,
+ .instance_count = 1U,
+ });
+ command_buffer.end_renderpass();
+
command_buffer.stop();
device->submit(&command_buffer, 1);
diff --git a/api-test/vk-device.cpp b/api-test/vk-device.cpp
index 0815592..6967e41 100644
--- a/api-test/vk-device.cpp
+++ b/api-test/vk-device.cpp
@@ -330,9 +330,9 @@ handle<device_pipeline> vkdevice::create_pipeline(const pipeline_desc& desc) {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
.pNext = nullptr,
.flags = 0U,
- .viewportCount = 0U,
+ .viewportCount = 1U,
.pViewports = nullptr,
- .scissorCount = 0U,
+ .scissorCount = 1U,
.pScissors = nullptr,
};
@@ -349,6 +349,35 @@ handle<device_pipeline> vkdevice::create_pipeline(const pipeline_desc& desc) {
.lineWidth = 1.f,
};
+ VkPipelineMultisampleStateCreateInfo multisample_state_create_info {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
+ .pNext = nullptr,
+ .flags = 0,
+ .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
+ .sampleShadingEnable = VK_FALSE,
+ .minSampleShading = 1.f,
+ };
+
+ VkPipelineColorBlendAttachmentState color_attachment_state {
+ .blendEnable = VK_TRUE,
+ .srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA,
+ .dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+ .colorBlendOp = VK_BLEND_OP_ADD,
+ .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
+ .dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+ .alphaBlendOp = VK_BLEND_OP_ADD,
+ .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
+ };
+
+ VkPipelineColorBlendStateCreateInfo color_blend_state_create_info {
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
+ .pNext = nullptr,
+ .flags = 0,
+ .logicOpEnable = VK_FALSE,
+ .attachmentCount = 1,
+ .pAttachments = &color_attachment_state,
+ };
+
VkDynamicState dynamic_states[] {
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR,
@@ -366,8 +395,8 @@ handle<device_pipeline> vkdevice::create_pipeline(const pipeline_desc& desc) {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.pNext = nullptr,
.viewMask = 0U,
- .colorAttachmentCount = 0U,
- .pColorAttachmentFormats = nullptr,
+ .colorAttachmentCount = static_cast<uint32_t>(desc.color_attachments_format.size()),
+ .pColorAttachmentFormats = desc.color_attachments_format.data(),
.depthAttachmentFormat = VK_FORMAT_UNDEFINED,
.stencilAttachmentFormat = VK_FORMAT_UNDEFINED,
};
@@ -383,9 +412,9 @@ handle<device_pipeline> vkdevice::create_pipeline(const pipeline_desc& desc) {
.pTessellationState = nullptr,
.pViewportState = &viewport_state_create_info,
.pRasterizationState = &rasterization_state_create_info,
- .pMultisampleState = nullptr,
+ .pMultisampleState = &multisample_state_create_info,
.pDepthStencilState = nullptr,
- .pColorBlendState = nullptr,
+ .pColorBlendState = &color_blend_state_create_info,
.pDynamicState = &dynamic_state_create_info,
.layout = bindless.layout,
.renderPass = nullptr,