Skip to content

Commit

Permalink
Get rid of AsyncGraphics queue.
Browse files Browse the repository at this point in the history
Kinda vestigial at this point and serves no real purpose.
Also gets rid of Vulkan beta ifdefs.
  • Loading branch information
Themaister committed Dec 27, 2023
1 parent e69b1cc commit 7224b24
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 185 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ option(GRANITE_INSTALL_TARGETS "Add install targets." ON)
option(GRANITE_INSTALL_EXE_TARGETS "Add executable install targets." OFF)
option(GRANITE_FFMPEG "Enable FFmpeg." OFF)
option(GRANITE_FFMPEG_VULKAN "Enable experimental Vulkan HW decode support in FFmpeg." OFF)
option(GRANITE_FFMPEG_VULKAN_ENCODE "Enable experimental Vulkan HW encode support in FFmpeg." OFF)
option(GRANITE_FAST_MATH "Enable fast math." ON)
option(GRANITE_SHIPPING "Disable code paths not related to development." OFF)

Expand Down
20 changes: 3 additions & 17 deletions renderer/render_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,11 +1847,6 @@ static void get_queue_type(Vulkan::CommandBuffer::Type &queue_type, bool &graphi
graphics = false;
queue_type = Vulkan::CommandBuffer::Type::AsyncCompute;
break;

case RENDER_GRAPH_QUEUE_ASYNC_GRAPHICS_BIT:
graphics = true;
queue_type = Vulkan::CommandBuffer::Type::AsyncGraphics;
break;
}
}

Expand Down Expand Up @@ -2369,19 +2364,15 @@ void RenderGraph::enqueue_swapchain_scale_pass(Vulkan::Device &device_)
unsigned resource_index = resource_to_index[backbuffer_source];
auto &source_resource = *this->resources[resource_index];

auto queue_type = (physical_dimensions[resource_index].queues & RENDER_GRAPH_QUEUE_GRAPHICS_BIT) != 0 ?
Vulkan::CommandBuffer::Type::Generic : Vulkan::CommandBuffer::Type::AsyncGraphics;

auto physical_queue_type = device_.get_physical_queue_type(queue_type);
const auto queue_type = Vulkan::CommandBuffer::Type::Generic;

auto cmd = device_.request_command_buffer(queue_type);
cmd->begin_region("render-graph-copy-to-swapchain");

unsigned index = source_resource.get_physical_index();
auto &image = physical_attachments[index]->get_image();

auto &wait_semaphore = physical_queue_type == Vulkan::QUEUE_INDEX_GRAPHICS ?
physical_events[index].wait_graphics_semaphore : physical_events[index].wait_compute_semaphore;
auto &wait_semaphore = physical_events[index].wait_graphics_semaphore;

auto target_layout = physical_dimensions[index].is_storage_image() ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

Expand Down Expand Up @@ -2606,8 +2597,6 @@ void RenderGraph::setup_physical_image(Vulkan::Device &device_, unsigned attachm
info.misc |= Vulkan::IMAGE_MISC_CONCURRENT_QUEUE_GRAPHICS_BIT;
if (att.queues & RENDER_GRAPH_QUEUE_ASYNC_COMPUTE_BIT)
info.misc |= Vulkan::IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_COMPUTE_BIT;
if (att.queues & RENDER_GRAPH_QUEUE_ASYNC_GRAPHICS_BIT)
info.misc |= Vulkan::IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_GRAPHICS_BIT;

physical_image_attachments[attachment] = device_.create_image(info, nullptr);
physical_image_attachments[attachment]->set_surface_transform(att.transform);
Expand Down Expand Up @@ -3023,10 +3012,7 @@ void RenderGraph::bake()
swapchain_dimensions.format, swapchain_dimensions.transform);

swapchain_physical_index = RenderResource::Unused;
if ((backbuffer_dim.queues & RENDER_GRAPH_QUEUE_GRAPHICS_BIT) == 0)
backbuffer_dim.queues |= RENDER_GRAPH_QUEUE_ASYNC_GRAPHICS_BIT;
else
backbuffer_dim.queues |= RENDER_GRAPH_QUEUE_GRAPHICS_BIT;
backbuffer_dim.queues |= RENDER_GRAPH_QUEUE_GRAPHICS_BIT;

// We will need to sample from the image to blit to backbuffer.
backbuffer_dim.image_usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
Expand Down
13 changes: 2 additions & 11 deletions renderer/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ enum RenderGraphQueueFlagBits
{
RENDER_GRAPH_QUEUE_GRAPHICS_BIT = 1 << 0,
RENDER_GRAPH_QUEUE_COMPUTE_BIT = 1 << 1,
RENDER_GRAPH_QUEUE_ASYNC_COMPUTE_BIT = 1 << 2,
RENDER_GRAPH_QUEUE_ASYNC_GRAPHICS_BIT = 1 << 3
RENDER_GRAPH_QUEUE_ASYNC_COMPUTE_BIT = 1 << 2
};
using RenderGraphQueueFlags = uint32_t;

Expand Down Expand Up @@ -858,15 +857,7 @@ class RenderGraph : public Vulkan::NoCopyNoMove, public EventHandler

static inline RenderGraphQueueFlagBits get_default_post_graphics_queue()
{
if (Vulkan::ImplementationQuirks::get().use_async_compute_post &&
!Vulkan::ImplementationQuirks::get().render_graph_force_single_queue)
{
return RENDER_GRAPH_QUEUE_ASYNC_GRAPHICS_BIT;
}
else
{
return RENDER_GRAPH_QUEUE_GRAPHICS_BIT;
}
return RENDER_GRAPH_QUEUE_GRAPHICS_BIT;
}

static inline RenderGraphQueueFlagBits get_default_compute_queue()
Expand Down
2 changes: 1 addition & 1 deletion tests/render_graph_sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct RenderGraphSandboxApplication : Granite::Application, Granite::EventHandl
});

// Composite + UI
auto &swap = graph.add_pass("final", RENDER_GRAPH_QUEUE_ASYNC_GRAPHICS_BIT);
auto &swap = graph.add_pass("final", RENDER_GRAPH_QUEUE_GRAPHICS_BIT);
swap.add_color_output("back", back);
swap.add_texture_input("image");
swap.add_texture_input("first");
Expand Down
6 changes: 3 additions & 3 deletions tests/video_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ struct VideoPlayerApplication : Application, EventHandler
float aspect = float(video->decoder.get_width()) / float(video->decoder.get_height());
float x_scale = 1.0f * aspect;
float z_scale = 1.0f;
node->transform.scale = vec3(x_scale, 1.0f, z_scale);
node->transform.rotation = angleAxis(muglm::half_pi<float>(), vec3(0.0f, 1.0f, 0.0f)) * angleAxis(muglm::half_pi<float>(), vec3(1.0f, 0.0f, 0.0f));
node->transform.translation = vec3(0.0f, 1.0f, -0.5f);
node->get_transform().scale = vec3(x_scale, 1.0f, z_scale);
node->get_transform().rotation = angleAxis(muglm::half_pi<float>(), vec3(0.0f, 1.0f, 0.0f)) * angleAxis(muglm::half_pi<float>(), vec3(1.0f, 0.0f, 0.0f));
node->get_transform().translation = vec3(0.0f, 1.0f, -0.5f);
node->invalidate_cached_transform();
auto root = scene.get_root_node();
if (root)
Expand Down
5 changes: 0 additions & 5 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ target_include_directories(granite-volk-headers INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan-headers/include/vk_video
${CMAKE_CURRENT_SOURCE_DIR}/khronos/vulkan-headers/include/vulkan)

if (GRANITE_FFMPEG_VULKAN_ENCODE)
# Encode is still not ratified.
target_compile_definitions(granite-volk-headers INTERFACE VK_ENABLE_BETA_EXTENSIONS)
endif()

# volk must be STATIC.
add_library(granite-volk STATIC volk/volk.c volk/volk.h)
if (WIN32)
Expand Down
2 changes: 1 addition & 1 deletion third_party/fsr2
3 changes: 0 additions & 3 deletions video/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ endif()
if (GRANITE_FFMPEG_VULKAN)
target_compile_definitions(granite-video PRIVATE HAVE_FFMPEG_VULKAN)
endif()
if (GRANITE_FFMPEG_VULKAN_ENCODE)
target_compile_definitions(granite-video PRIVATE HAVE_FFMPEG_VULKAN_ENCODE)
endif()
target_include_directories(granite-video PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(granite-video PUBLIC HAVE_GRANITE_FFMPEG)
5 changes: 2 additions & 3 deletions video/ffmpeg_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ unsigned VideoDecoder::Impl::acquire_decode_video_frame()
info.flags = VK_IMAGE_CREATE_EXTENDED_USAGE_BIT;
info.misc = Vulkan::IMAGE_MISC_CONCURRENT_QUEUE_GRAPHICS_BIT |
Vulkan::IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_COMPUTE_BIT |
Vulkan::IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_GRAPHICS_BIT |
Vulkan::IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_TRANSFER_BIT |
Vulkan::IMAGE_MISC_MUTABLE_SRGB_BIT;
if (opts.mipgen)
Expand Down Expand Up @@ -1394,7 +1393,7 @@ void VideoDecoder::Impl::process_video_frame_in_task_vulkan(DecodedImage &img, A
}

auto conversion_queue = opts.mipgen ?
Vulkan::CommandBuffer::Type::AsyncGraphics :
Vulkan::CommandBuffer::Type::Generic :
Vulkan::CommandBuffer::Type::AsyncCompute;

if (img.sem_from_client)
Expand Down Expand Up @@ -1576,7 +1575,7 @@ void VideoDecoder::Impl::process_video_frame_in_task_upload(DecodedImage &img, A
device->submit(cmd, nullptr, 1, &transfer_to_compute);

auto conversion_queue = opts.mipgen ?
Vulkan::CommandBuffer::Type::AsyncGraphics :
Vulkan::CommandBuffer::Type::Generic :
Vulkan::CommandBuffer::Type::AsyncCompute;

device->add_wait_semaphore(conversion_queue,
Expand Down
16 changes: 8 additions & 8 deletions video/ffmpeg_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct VideoEncoder::Impl final
void write_frames_interleaved_f32(const float *data, size_t frames) override;
#endif

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
void submit_process_rgb_vulkan(Vulkan::CommandBufferHandle &cmd, YCbCrPipelineData &pipeline);
#endif
void submit_process_rgb_readback(Vulkan::CommandBufferHandle &cmd, YCbCrPipelineData &pipeline);
Expand Down Expand Up @@ -1080,7 +1080,7 @@ bool VideoEncoder::Impl::init_video_codec()
return false;
}
}
#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
else if (hw.get_hw_device_type() == AV_HWDEVICE_TYPE_VULKAN)
{
// Do not allocate av_frame, we'll convert YUV into the frame context.
Expand Down Expand Up @@ -1298,7 +1298,7 @@ AVFrame *VideoEncoder::Impl::alloc_video_frame(AVPixelFormat pix_fmt, unsigned w
return frame;
}

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
struct FrameLock
{
AVHWFramesContext *frames;
Expand Down Expand Up @@ -1375,7 +1375,7 @@ void VideoEncoder::process_rgb(Vulkan::CommandBuffer &cmd, YCbCrPipeline &pipeli
Vulkan::ImageViewHandle wrapped_planes[2];
Vulkan::ImageHandle wrapped_image;

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
auto &device = cmd.get_device();
AVHWFramesContext *frames = nullptr;
AVVulkanFramesContext *vk = nullptr;
Expand Down Expand Up @@ -1580,7 +1580,7 @@ void VideoEncoder::submit_process_rgb(Vulkan::CommandBufferHandle &cmd, YCbCrPip
{
auto &pipeline = *pipeline_ptr;

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
if (pipeline.hw_frame)
{
impl->submit_process_rgb_vulkan(cmd, pipeline);
Expand Down Expand Up @@ -1622,7 +1622,7 @@ VideoEncoder::YCbCrPipeline VideoEncoder::create_ycbcr_pipeline(const FFmpegEnco
image_info.initial_layout = VK_IMAGE_LAYOUT_UNDEFINED;
image_info.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
if (impl->hw.get_pix_fmt() != AV_PIX_FMT_VULKAN)
#endif
{
Expand Down Expand Up @@ -1677,7 +1677,7 @@ VideoEncoder::YCbCrPipeline VideoEncoder::create_ycbcr_pipeline(const FFmpegEnco
image_info.width = impl->options.width / 2;
image_info.height = impl->options.height / 2;

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
if (impl->hw.get_pix_fmt() != AV_PIX_FMT_VULKAN)
#endif
{
Expand All @@ -1698,7 +1698,7 @@ VideoEncoder::YCbCrPipeline VideoEncoder::create_ycbcr_pipeline(const FFmpegEnco
pipeline.constants.chroma_dispatch[0] = (image_info.width + 7) / 8;
pipeline.constants.chroma_dispatch[1] = (image_info.height + 7) / 8;

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
if (impl->hw.get_pix_fmt() != AV_PIX_FMT_VULKAN)
#endif
{
Expand Down
14 changes: 4 additions & 10 deletions video/ffmpeg_hw_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ struct FFmpegHWDevice::Impl
Vulkan::Device *device = nullptr;
const AVCodec *cached_av_codec = nullptr;

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
VkVideoProfileInfoKHR profile_info = { VK_STRUCTURE_TYPE_VIDEO_PROFILE_INFO_KHR };
VkVideoProfileListInfoKHR profile_list_info = { VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR };
VkVideoEncodeH264ProfileInfoEXT h264_encode = { VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_PROFILE_INFO_EXT };
VkVideoEncodeH264ProfileInfoKHR h264_encode = { VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_PROFILE_INFO_KHR };
#endif

~Impl()
Expand Down Expand Up @@ -93,14 +93,8 @@ struct FFmpegHWDevice::Impl
vk->nb_comp_queues = int(q.counts[Vulkan::QUEUE_INDEX_COMPUTE]);
vk->nb_tx_queues = int(q.counts[Vulkan::QUEUE_INDEX_TRANSFER]);
vk->nb_decode_queues = int(q.counts[Vulkan::QUEUE_INDEX_VIDEO_DECODE]);

#ifdef VK_ENABLE_BETA_EXTENSIONS
vk->queue_family_encode_index = int(q.family_indices[Vulkan::QUEUE_INDEX_VIDEO_ENCODE]);
vk->nb_encode_queues = int(q.counts[Vulkan::QUEUE_INDEX_VIDEO_ENCODE]);
#else
vk->queue_family_encode_index = -1;
vk->nb_encode_queues = 0;
#endif

vk->lock_queue = [](AVHWDeviceContext *ctx, uint32_t, uint32_t) {
auto *self = static_cast<Impl *>(ctx->user_opaque);
Expand Down Expand Up @@ -203,7 +197,7 @@ struct FFmpegHWDevice::Impl
ctx->height = height;
ctx->sw_format = sw_format;

#ifdef HAVE_FFMPEG_VULKAN_ENCODE
#ifdef HAVE_FFMPEG_VULKAN
if (ctx->format == AV_PIX_FMT_VULKAN)
{
auto *vk = static_cast<AVVulkanFramesContext *>(ctx->hwctx);
Expand All @@ -215,7 +209,7 @@ struct FFmpegHWDevice::Impl

h264_encode.stdProfileIdc = STD_VIDEO_H264_PROFILE_IDC_HIGH;

profile_info.videoCodecOperation = VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_EXT;
profile_info.videoCodecOperation = VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR;
profile_info.chromaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR;
profile_info.lumaBitDepth = VK_VIDEO_COMPONENT_BIT_DEPTH_8_BIT_KHR;
profile_info.chromaSubsampling = VK_VIDEO_CHROMA_SUBSAMPLING_420_BIT_KHR;
Expand Down
4 changes: 0 additions & 4 deletions vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ if (GRANITE_FFMPEG_VULKAN)
target_compile_definitions(granite-vulkan PRIVATE HAVE_FFMPEG_VULKAN)
endif()

if (GRANITE_FFMPEG_VULKAN_ENCODE)
target_compile_definitions(granite-vulkan PRIVATE HAVE_FFMPEG_VULKAN_ENCODE)
endif()

if (GRANITE_VULKAN_PROFILES)
# Must be defined by caller as an INTERFACE library before including Granite.
if (NOT TARGET granite-vulkan-profiles)
Expand Down
3 changes: 1 addition & 2 deletions vulkan/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ static uint32_t deduce_acquire_release_family_index(Device &device, const Image
if (queue_info.family_indices[QUEUE_INDEX_GRAPHICS] != family)
return VK_QUEUE_FAMILY_IGNORED;

if (image.get_create_info().misc &
(IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_GRAPHICS_BIT | IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_COMPUTE_BIT))
if (image.get_create_info().misc & IMAGE_MISC_CONCURRENT_QUEUE_ASYNC_COMPUTE_BIT)
{
if (queue_info.family_indices[QUEUE_INDEX_COMPUTE] != family)
return VK_QUEUE_FAMILY_IGNORED;
Expand Down
3 changes: 0 additions & 3 deletions vulkan/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,7 @@ class CommandBuffer : public Util::IntrusivePtrEnabled<CommandBuffer, CommandBuf
AsyncCompute = QUEUE_INDEX_COMPUTE,
AsyncTransfer = QUEUE_INDEX_TRANSFER,
VideoDecode = QUEUE_INDEX_VIDEO_DECODE,
#ifdef VK_ENABLE_BETA_EXTENSIONS
VideoEncode = QUEUE_INDEX_VIDEO_ENCODE,
#endif
AsyncGraphics = QUEUE_INDEX_COUNT, // Aliases with either Generic or AsyncCompute queue
Count
};

Expand Down
Loading

0 comments on commit 7224b24

Please sign in to comment.