Skip to content

Commit

Permalink
[gpu.hardware] emit an engine bug if the user tries to use 2 differen…
Browse files Browse the repository at this point in the history
…t pieces of hardware, which is not currently supported.
  • Loading branch information
harrand committed Nov 3, 2024
1 parent 5c88a3b commit 5d347e8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions include/tz/gpu/hardware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ namespace tz::gpu
hardware_handle i0;
std::uint32_t i1;
} internals;

bool operator==(const hardware& rhs) const
{
return this->internals.i0 == rhs.internals.i0;
}

bool operator!=(const hardware& rhs) const
{
return this->internals.i0 != rhs.internals.i0;
}
};

/**
Expand Down
1 change: 1 addition & 0 deletions include/tz/gpu/pass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ namespace tz::gpu
* @return @ref tz::error_code::invalid_value For a graphics pass if you fail to provide at least one colour target.
* @return @ref tz::error_code::invalid_value For a graphics pass if you provide a colour target that is invalid. A valid colour target is either a.) the window resource (and you have opened a window), b.) an image resource created with @ref tz::gpu::image_flag::colour_target
* @return @ref tz::error_code::precondition_failure For a graphics pass if any colour target provided does not exactly match the dimensions of all other provided colour targets. All colour targets must be images with the same dimensions. This does mean that if you provide the window resource as a colour target, all other colour targets must have the same dimensions as the window.
* @return @ref tz::error_code::machine_unsuitable If the currently-used hardware does not support the pass you're attempting to create, for example if you attempt to create a graphics pass but your hardware has @ref hardware_capabilities::compute_only.
* @return @ref tz::error_code::oom If CPU memory is exhausted while trying to create the pass.
* @return @ref tz::error_code::voom If GPU memory is exhausted while trying to create the pass.
*
Expand Down
23 changes: 20 additions & 3 deletions src/tz/gpu/rhi_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace tz::gpu
unsigned int swapchain_width = -1; unsigned int swapchain_height = -1;
std::vector<VkImage> swapchain_images = {};
std::vector<VkImageView> swapchain_views = {};
hardware current_hardware;
hardware current_hardware = {};
#define VULKAN_API_VERSION_USED VK_API_VERSION_1_3
constexpr VkFormat swapchain_format = VK_FORMAT_B8G8R8A8_UNORM;
VmaAllocator alloc = VK_NULL_HANDLE;
Expand Down Expand Up @@ -462,10 +462,18 @@ namespace tz::gpu

error_code use_hardware(hardware hw)
{
if(hw.caps != hardware_capabilities::graphics_compute)
if(current_hardware == hw)
{
return tz::error_code::success;
}
if(current_hardware != hardware{})
{
RETERR(tz::error_code::engine_bug, "I have not yet implemented the ability to select hardware twice for two different pieces of hardware. You previously selected \"{}\" but now want \"{}\"", current_hardware.name, hw.name);
}
if(hw.caps == hardware_capabilities::neither)
{
// incompatible hardware.
RETERR(error_code::machine_unsuitable, "Graphics hardware {} is not suitable because it does not have a graphics-compute queue.", hw.name);
RETERR(error_code::machine_unsuitable, "Graphics hardware {} is not suitable because it supports neither graphics nor compute operations.", hw.name);
}
auto pdev = reinterpret_cast<VkPhysicalDevice>(static_cast<std::uintptr_t>(hw.internals.i0.peek()));

Expand Down Expand Up @@ -1192,6 +1200,10 @@ namespace tz::gpu

if(shader1.ty == shader_type::compute)
{
if(current_hardware.caps == hardware_capabilities::graphics_only || current_hardware.caps == hardware_capabilities::neither)
{
UNERR(tz::error_code::machine_unsuitable, "Attempt to create compute pass using hardware {} which does not support compute operations.", current_hardware.name);
}
VkComputePipelineCreateInfo create
{
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
Expand Down Expand Up @@ -1222,6 +1234,11 @@ namespace tz::gpu
}
auto& shader2 = shaders[--bottom_part];

if(current_hardware.caps == hardware_capabilities::compute_only || current_hardware.caps == hardware_capabilities::neither)
{
UNERR(tz::error_code::machine_unsuitable, "Attempt to create graphics pass using hardware {} which does not support graphics operations.", current_hardware.name);
}

std::array<VkPipelineShaderStageCreateInfo, 2> shader_creates
{
VkPipelineShaderStageCreateInfo
Expand Down

0 comments on commit 5d347e8

Please sign in to comment.