Validate renderer shader descriptors
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace pp::renderer {
|
||||
constexpr std::uint32_t max_texture_dimension = 32768;
|
||||
constexpr std::uint32_t max_mesh_vertices = 16777216;
|
||||
constexpr std::uint64_t max_texture_bytes = 1024ULL * 1024ULL * 1024ULL;
|
||||
constexpr std::size_t max_shader_source_bytes = 4ULL * 1024ULL * 1024ULL;
|
||||
|
||||
enum class TextureFormat : std::uint8_t {
|
||||
rgba8,
|
||||
@@ -136,6 +137,7 @@ public:
|
||||
[[nodiscard]] pp::foundation::Status validate_extent(Extent2D extent) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_viewport(Viewport viewport, Extent2D target_extent) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_shader_program_desc(ShaderProgramDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Result<std::uint64_t> texture_byte_size(TextureDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_readback_region(TextureDesc desc, ReadbackRegion region) noexcept;
|
||||
[[nodiscard]] const char* texture_format_name(TextureFormat format) noexcept;
|
||||
|
||||
Reference in New Issue
Block a user