Validate renderer shader descriptors

This commit is contained in:
2026-06-01 09:05:43 +02:00
parent 44aebf61b2
commit 4eee018367
5 changed files with 114 additions and 4 deletions

View File

@@ -5,6 +5,34 @@
namespace pp::renderer {
namespace {
[[nodiscard]] bool is_empty_c_string(const char* text) noexcept
{
return text == nullptr || text[0] == '\0';
}
[[nodiscard]] pp::foundation::Status validate_shader_stage_source(
ShaderStageSource source,
const char* stage_name) noexcept
{
if (is_empty_c_string(source.entry_point)) {
return pp::foundation::Status::invalid_argument(stage_name);
}
if (source.source == nullptr || source.source_size == 0U) {
return pp::foundation::Status::invalid_argument("shader source must not be empty");
}
if (source.source_size > max_shader_source_bytes) {
return pp::foundation::Status::out_of_range("shader source exceeds the configured limit");
}
return pp::foundation::Status::success();
}
}
std::uint32_t bytes_per_pixel(TextureFormat format) noexcept
{
switch (format) {
@@ -123,6 +151,29 @@ pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept
return pp::foundation::Status::invalid_argument("mesh topology is not supported");
}
pp::foundation::Status validate_shader_program_desc(ShaderProgramDesc desc) noexcept
{
if (desc.debug_name == nullptr) {
return pp::foundation::Status::invalid_argument("shader debug name must not be null");
}
const auto vertex_status = validate_shader_stage_source(
desc.vertex,
"vertex shader entry point must not be empty");
if (!vertex_status.ok()) {
return vertex_status;
}
const auto fragment_status = validate_shader_stage_source(
desc.fragment,
"fragment shader entry point must not be empty");
if (!fragment_status.ok()) {
return fragment_status;
}
return pp::foundation::Status::success();
}
pp::foundation::Status validate_readback_region(TextureDesc desc, ReadbackRegion region) noexcept
{
const auto extent_status = validate_extent(desc.extent);