Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask out unsupported pipeline stages #31

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions internal/RendererVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,57 +56,57 @@ namespace Ray {
extern const int LUT_DIMS;
extern const uint32_t *transform_luts[];
namespace Vk {
#include "shaders/output/convolution_112_112_coop.comp.spv.inl"
#include "shaders/output/convolution_112_112_fp16.comp.spv.inl"
#include "shaders/output/convolution_112_112_fp32.comp.spv.inl"
#include "shaders/output/convolution_112_112_coop.comp.spv.inl"
#include "shaders/output/convolution_32_32_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_32_32_Downsample_fp16.comp.spv.inl"
#include "shaders/output/convolution_32_32_Downsample_fp32.comp.spv.inl"
#include "shaders/output/convolution_32_32_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_32_3_img_coop.comp.spv.inl"
#include "shaders/output/convolution_32_3_img_fp16.comp.spv.inl"
#include "shaders/output/convolution_32_3_img_fp32.comp.spv.inl"
#include "shaders/output/convolution_32_3_img_coop.comp.spv.inl"
#include "shaders/output/convolution_32_48_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_32_48_Downsample_fp16.comp.spv.inl"
#include "shaders/output/convolution_32_48_Downsample_fp32.comp.spv.inl"
#include "shaders/output/convolution_32_48_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_48_64_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_48_64_Downsample_fp16.comp.spv.inl"
#include "shaders/output/convolution_48_64_Downsample_fp32.comp.spv.inl"
#include "shaders/output/convolution_48_64_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_64_32_coop.comp.spv.inl"
#include "shaders/output/convolution_64_32_fp16.comp.spv.inl"
#include "shaders/output/convolution_64_32_fp32.comp.spv.inl"
#include "shaders/output/convolution_64_32_coop.comp.spv.inl"
#include "shaders/output/convolution_64_64_coop.comp.spv.inl"
#include "shaders/output/convolution_64_64_fp16.comp.spv.inl"
#include "shaders/output/convolution_64_64_fp32.comp.spv.inl"
#include "shaders/output/convolution_64_64_coop.comp.spv.inl"
#include "shaders/output/convolution_64_80_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_64_80_Downsample_fp16.comp.spv.inl"
#include "shaders/output/convolution_64_80_Downsample_fp32.comp.spv.inl"
#include "shaders/output/convolution_64_80_Downsample_coop.comp.spv.inl"
#include "shaders/output/convolution_80_96_coop.comp.spv.inl"
#include "shaders/output/convolution_80_96_fp16.comp.spv.inl"
#include "shaders/output/convolution_80_96_fp32.comp.spv.inl"
#include "shaders/output/convolution_80_96_coop.comp.spv.inl"
#include "shaders/output/convolution_96_96_coop.comp.spv.inl"
#include "shaders/output/convolution_96_96_fp16.comp.spv.inl"
#include "shaders/output/convolution_96_96_fp32.comp.spv.inl"
#include "shaders/output/convolution_96_96_coop.comp.spv.inl"
#include "shaders/output/convolution_Img_9_32_coop.comp.spv.inl"
#include "shaders/output/convolution_Img_9_32_fp16.comp.spv.inl"
#include "shaders/output/convolution_Img_9_32_fp32.comp.spv.inl"
#include "shaders/output/convolution_Img_9_32_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_112_48_96_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_112_48_96_fp16.comp.spv.inl"
#include "shaders/output/convolution_concat_112_48_96_fp32.comp.spv.inl"
#include "shaders/output/convolution_concat_112_48_96_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_64_3_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_64_3_64_fp16.comp.spv.inl"
#include "shaders/output/convolution_concat_64_3_64_fp32.comp.spv.inl"
#include "shaders/output/convolution_concat_64_3_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_64_6_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_64_6_64_fp16.comp.spv.inl"
#include "shaders/output/convolution_concat_64_6_64_fp32.comp.spv.inl"
#include "shaders/output/convolution_concat_64_6_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_64_9_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_64_9_64_fp16.comp.spv.inl"
#include "shaders/output/convolution_concat_64_9_64_fp32.comp.spv.inl"
#include "shaders/output/convolution_concat_64_9_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_96_32_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_96_32_64_fp16.comp.spv.inl"
#include "shaders/output/convolution_concat_96_32_64_fp32.comp.spv.inl"
#include "shaders/output/convolution_concat_96_32_64_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_96_64_112_coop.comp.spv.inl"
#include "shaders/output/convolution_concat_96_64_112_fp16.comp.spv.inl"
#include "shaders/output/convolution_concat_96_64_112_fp32.comp.spv.inl"
#include "shaders/output/convolution_concat_96_64_112_coop.comp.spv.inl"
#include "shaders/output/debug_rt.comp.spv.inl"
#include "shaders/output/filter_variance.comp.spv.inl"
#include "shaders/output/intersect_area_lights.comp.spv.inl"
Expand Down Expand Up @@ -642,9 +642,12 @@ void Ray::Vk::Renderer::RenderScene(const SceneBase *_s, RegionContext &region)
mem_barrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
mem_barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
ctx_->api().vkCmdPipelineBarrier(
cmd_buf, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, 0, 1, &mem_barrier, 0,
nullptr, 0, nullptr);
cmd_buf,
(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR) &
ctx_->supported_stages_mask(),
(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR) &
ctx_->supported_stages_mask(),
0, 1, &mem_barrier, 0, nullptr, 0, nullptr);

const rect_t rect = region.rect();
const uint32_t rand_seed = Ref::hash((region.iteration - 1) / RAND_SAMPLES_COUNT);
Expand Down
8 changes: 5 additions & 3 deletions internal/SceneVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,9 @@ void Ray::Vk::Scene::_insert_mem_barrier(void *cmd_buf) {
mem_barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
ctx_->api().vkCmdPipelineBarrier(
reinterpret_cast<VkCommandBuffer>(cmd_buf),
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, 0, 1, &mem_barrier, 0,
nullptr, 0, nullptr);
(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR) &
ctx_->supported_stages_mask(),
(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR) &
ctx_->supported_stages_mask(),
0, 1, &mem_barrier, 0, nullptr, 0, nullptr);
}
12 changes: 12 additions & 0 deletions internal/Vk/BufferVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ void Ray::Vk::Buffer::UpdateSubRegion(const uint32_t offset, const uint32_t size
dst_stages |= VKPipelineStagesForState(eResState::CopyDst);
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

if (!barriers.empty()) {
ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages, dst_stages, 0, 0, nullptr, uint32_t(barriers.size()),
barriers.cdata(), 0, nullptr);
Expand Down Expand Up @@ -330,6 +333,9 @@ void Ray::Vk::Buffer::Fill(const uint32_t dst_offset, const uint32_t size, const
dst_stages |= VKPipelineStagesForState(eResState::CopySrc);
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

if (!barriers.empty()) {
ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
dst_stages, 0, 0, nullptr, uint32_t(barriers.size()), barriers.cdata(), 0,
Expand Down Expand Up @@ -362,6 +368,9 @@ void Ray::Vk::Buffer::UpdateImmediate(uint32_t dst_offset, uint32_t size, const
dst_stages |= VKPipelineStagesForState(eResState::CopySrc);
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

if (!barriers.empty()) {
ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
dst_stages, 0, 0, nullptr, uint32_t(barriers.size()), barriers.cdata(), 0,
Expand Down Expand Up @@ -410,6 +419,9 @@ void Ray::Vk::CopyBufferToBuffer(Buffer &src, const uint32_t src_offset, Buffer
dst_stages |= VKPipelineStagesForState(eResState::CopyDst);
}

src_stages &= src.ctx()->supported_stages_mask();
dst_stages &= src.ctx()->supported_stages_mask();

if (!barriers.empty()) {
src.ctx()->api().vkCmdPipelineBarrier(cmd_buf, src_stages, dst_stages, 0, 0, nullptr, uint32_t(barriers.size()),
barriers.cdata(), 0, nullptr);
Expand Down
22 changes: 14 additions & 8 deletions internal/Vk/ContextVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ bool Ray::Vk::Context::Init(ILog *log, const char *preferred_device, const int v
return false;
}

if (!raytracing_supported_) {
// mask out unsupported stage
supported_stages_mask_ &= ~VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
}

// Disable as it is not needed for now
dynamic_rendering_supported_ = false;

Expand Down Expand Up @@ -382,13 +387,14 @@ bool Ray::Vk::Context::InitVkInstance(const Api &api, VkInstance &instance, cons
return true;
}

bool Ray::Vk::Context::ChooseVkPhysicalDevice(const Api &api, VkPhysicalDevice &physical_device,
bool Ray::Vk::Context::ChooseVkPhysicalDevice(const Api &api, VkPhysicalDevice &out_physical_device,
VkPhysicalDeviceProperties &out_device_properties,
VkPhysicalDeviceMemoryProperties &out_mem_properties,
uint32_t &out_graphics_family_index, bool &out_raytracing_supported,
bool &out_ray_query_supported, bool &out_dynamic_rendering_supported,
bool &out_fp16_supported, bool &out_coop_matrix_supported,
const char *preferred_device, VkInstance instance, ILog *log) {
uint32_t &out_graphics_family_index,
bool &out_raytracing_supported, bool &out_ray_query_supported,
bool &out_dynamic_rendering_supported, bool &out_fp16_supported,
bool &out_coop_matrix_supported, const char *preferred_device,
VkInstance instance, ILog *log) {
uint32_t physical_device_count = 0;
api.vkEnumeratePhysicalDevices(instance, &physical_device_count, nullptr);

Expand Down Expand Up @@ -486,7 +492,7 @@ bool Ray::Vk::Context::ChooseVkPhysicalDevice(const Api &api, VkPhysicalDevice &
if (score > best_score) {
best_score = score;

physical_device = physical_devices[i];
out_physical_device = physical_devices[i];
out_device_properties = device_properties;
out_graphics_family_index = graphics_family_index;
out_raytracing_supported = (acc_struct_supported && raytracing_supported);
Expand All @@ -498,12 +504,12 @@ bool Ray::Vk::Context::ChooseVkPhysicalDevice(const Api &api, VkPhysicalDevice &
}
}

if (!physical_device) {
if (!out_physical_device) {
log->Error("No physical device detected that can render and present!");
return false;
}

api.vkGetPhysicalDeviceMemoryProperties(physical_device, &out_mem_properties);
api.vkGetPhysicalDeviceMemoryProperties(out_physical_device, &out_mem_properties);

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions internal/Vk/ContextVK.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Context {

bool coop_matrix_supported_ = false;

uint32_t supported_stages_mask_ = 0xffffffff;

VkQueue graphics_queue_ = {};

VkCommandPool command_pool_ = {}, temp_command_pool_ = {};
Expand Down Expand Up @@ -87,6 +89,7 @@ class Context {
bool subgroup_supported() const { return subgroup_supported_; }
bool coop_matrix_supported() const { return coop_matrix_supported_; }

uint32_t supported_stages_mask() const { return supported_stages_mask_; };
bool image_blit_supported() const { return true; }

const VkPhysicalDeviceLimits &phys_device_limits() const { return phys_device_limits_; }
Expand Down
19 changes: 11 additions & 8 deletions internal/Vk/ResourceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ void Ray::Vk::TransitionResourceStates(void *_cmd_buf, const eStageBits src_stag
SmallVector<VkBufferMemoryBarrier, 32> buf_barriers;
SmallVector<VkImageMemoryBarrier, 32> img_barriers;

const Api *api = nullptr;
const Context *ctx = nullptr;

for (const TransitionInfo &transition : transitions) {
if (transition.p_tex && transition.p_tex->ready()) {
api = &transition.p_tex->ctx()->api();
ctx = transition.p_tex->ctx();

eResState old_state = transition.old_state;
if (old_state == eResState::Undefined) {
Expand Down Expand Up @@ -209,7 +209,7 @@ void Ray::Vk::TransitionResourceStates(void *_cmd_buf, const eStageBits src_stag
transition.p_tex->resource_state = transition.new_state;
}
} else if (transition.p_3dtex) {
api = &transition.p_3dtex->ctx()->api();
ctx = transition.p_3dtex->ctx();

eResState old_state = transition.old_state;
if (old_state == eResState::Undefined) {
Expand Down Expand Up @@ -245,7 +245,7 @@ void Ray::Vk::TransitionResourceStates(void *_cmd_buf, const eStageBits src_stag
transition.p_3dtex->resource_state = transition.new_state;
}
} else if (transition.p_buf && *transition.p_buf) {
api = &transition.p_buf->ctx()->api();
ctx = transition.p_buf->ctx();

eResState old_state = transition.old_state;
if (old_state == eResState::Undefined) {
Expand Down Expand Up @@ -275,7 +275,7 @@ void Ray::Vk::TransitionResourceStates(void *_cmd_buf, const eStageBits src_stag
transition.p_buf->resource_state = transition.new_state;
}
} else if (transition.p_tex_arr && transition.p_tex_arr->page_count()) {
api = &transition.p_tex_arr->ctx()->api();
ctx = transition.p_tex_arr->ctx();

eResState old_state = transition.old_state;
if (old_state == eResState::Undefined) {
Expand Down Expand Up @@ -318,8 +318,11 @@ void Ray::Vk::TransitionResourceStates(void *_cmd_buf, const eStageBits src_stag
dst_stages &= to_pipeline_stage_flags_vk(dst_stages_mask);

if (!buf_barriers.empty() || !img_barriers.empty()) {
api->vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, dst_stages, 0,
0, nullptr, uint32_t(buf_barriers.size()), buf_barriers.cdata(),
uint32_t(img_barriers.size()), img_barriers.cdata());
src_stages &= ctx->supported_stages_mask();
dst_stages &= ctx->supported_stages_mask();

ctx->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
dst_stages, 0, 0, nullptr, uint32_t(buf_barriers.size()), buf_barriers.cdata(),
uint32_t(img_barriers.size()), img_barriers.cdata());
}
}
25 changes: 22 additions & 3 deletions internal/Vk/TextureAtlasVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ bool Ray::Vk::TextureAtlas::Resize(const int pages_count) {
dst_stages |= VKPipelineStagesForState(eResState::CopyDst);
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

VkCommandBuffer cmd_buf = BegSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->temp_command_pool());

ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Expand Down Expand Up @@ -450,9 +453,10 @@ bool Ray::Vk::TextureAtlas::Resize(const int pages_count) {

VkCommandBuffer cmd_buf = BegSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->temp_command_pool());

ctx_->api().vkCmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VKPipelineStagesForState(eResState::ShaderResource), 0, 0, nullptr, 0, nullptr,
uint32_t(img_barriers.size()), img_barriers.cdata());
ctx_->api().vkCmdPipelineBarrier(
cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VKPipelineStagesForState(eResState::ShaderResource) & ctx_->supported_stages_mask(), 0, 0, nullptr, 0,
nullptr, uint32_t(img_barriers.size()), img_barriers.cdata());

EndSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->graphics_queue(), cmd_buf, ctx_->temp_command_pool());
}
Expand Down Expand Up @@ -505,6 +509,9 @@ int Ray::Vk::TextureAtlas::DownsampleRegion(const int src_page, const int src_po
dst_stages |= VK_PIPELINE_STAGE_TRANSFER_BIT;
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
dst_stages, 0, 0, nullptr, 0, nullptr, uint32_t(img_barriers.size()),
img_barriers.cdata());
Expand Down Expand Up @@ -556,6 +563,9 @@ int Ray::Vk::TextureAtlas::DownsampleRegion(const int src_page, const int src_po
dst_stages |= VK_PIPELINE_STAGE_TRANSFER_BIT;
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
dst_stages, 0, 0, nullptr, 0, nullptr, uint32_t(img_barriers.size()),
img_barriers.cdata());
Expand Down Expand Up @@ -727,6 +737,9 @@ int Ray::Vk::TextureAtlas::DownsampleRegion(const int src_page, const int src_po
dst_stages |= VKPipelineStagesForState(resource_state);
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
dst_stages, 0, 0, nullptr, 0, nullptr, uint32_t(img_barriers.size()),
img_barriers.cdata());
Expand Down Expand Up @@ -813,6 +826,9 @@ void Ray::Vk::TextureAtlas::WritePageData(const int page, const int posx, const
dst_stages |= VKPipelineStagesForState(eResState::CopyDst);
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

VkCommandBuffer cmd_buf = BegSingleTimeCommands(ctx_->api(), ctx_->device(), ctx_->temp_command_pool());

ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, dst_stages,
Expand Down Expand Up @@ -886,6 +902,9 @@ void Ray::Vk::TextureAtlas::CopyRegionTo(const int page, const int x, const int
dst_stages |= VKPipelineStagesForState(eResState::CopyDst);
}

src_stages &= ctx_->supported_stages_mask();
dst_stages &= ctx_->supported_stages_mask();

if (!buf_barriers.empty() || !img_barriers.empty()) {
ctx_->api().vkCmdPipelineBarrier(cmd_buf, src_stages ? src_stages : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
dst_stages, 0, 0, nullptr, uint32_t(buf_barriers.size()), buf_barriers.cdata(),
Expand Down
Loading
Loading