Add renderer texture usage contract

This commit is contained in:
2026-06-02 16:42:53 +02:00
parent 75dd5cfdc9
commit 901aff1051
7 changed files with 345 additions and 68 deletions

View File

@@ -22,6 +22,34 @@ enum class TextureFormat : std::uint8_t {
depth24_stencil8,
};
enum class TextureUsage : std::uint32_t {
none = 0,
sampled = 1U << 0U,
render_target = 1U << 1U,
upload_destination = 1U << 2U,
readback_source = 1U << 3U,
copy_source = 1U << 4U,
copy_destination = 1U << 5U,
};
[[nodiscard]] constexpr TextureUsage operator|(TextureUsage lhs, TextureUsage rhs) noexcept
{
return static_cast<TextureUsage>(
static_cast<std::uint32_t>(lhs) | static_cast<std::uint32_t>(rhs));
}
[[nodiscard]] constexpr TextureUsage operator&(TextureUsage lhs, TextureUsage rhs) noexcept
{
return static_cast<TextureUsage>(
static_cast<std::uint32_t>(lhs) & static_cast<std::uint32_t>(rhs));
}
constexpr TextureUsage& operator|=(TextureUsage& lhs, TextureUsage rhs) noexcept
{
lhs = lhs | rhs;
return lhs;
}
struct Extent2D {
std::uint32_t width = 0;
std::uint32_t height = 0;
@@ -30,7 +58,11 @@ struct Extent2D {
struct TextureDesc {
Extent2D extent;
TextureFormat format = TextureFormat::rgba8;
bool render_target = false;
TextureUsage usage = TextureUsage::sampled
| TextureUsage::upload_destination
| TextureUsage::readback_source
| TextureUsage::copy_source
| TextureUsage::copy_destination;
};
struct ReadbackRegion {
@@ -279,7 +311,10 @@ public:
};
[[nodiscard]] std::uint32_t bytes_per_pixel(TextureFormat format) noexcept;
[[nodiscard]] bool has_texture_usage(TextureUsage usage, TextureUsage required) noexcept;
[[nodiscard]] pp::foundation::Status validate_extent(Extent2D extent) noexcept;
[[nodiscard]] pp::foundation::Status validate_texture_usage(TextureUsage usage) noexcept;
[[nodiscard]] pp::foundation::Status validate_texture_desc(TextureDesc desc) noexcept;
[[nodiscard]] pp::foundation::Status validate_viewport(Viewport viewport, Extent2D target_extent) noexcept;
[[nodiscard]] pp::foundation::Status validate_scissor(ScissorRect scissor, Extent2D target_extent) noexcept;
[[nodiscard]] pp::foundation::Status validate_render_pass_desc(RenderPassDesc desc) noexcept;