Add renderer shader uniform command
This commit is contained in:
@@ -208,6 +208,30 @@ pp::foundation::Status RecordingCommandContext::bind_shader(IShaderProgram& shad
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::set_shader_uniform(
|
||||
const char* name,
|
||||
std::span<const std::byte> bytes) noexcept
|
||||
{
|
||||
if (!in_render_pass_) {
|
||||
return pp::foundation::Status::invalid_argument("render pass has not begun");
|
||||
}
|
||||
if (!shader_bound_) {
|
||||
return pp::foundation::Status::invalid_argument("shader must be bound before setting uniforms");
|
||||
}
|
||||
|
||||
const auto status = validate_shader_uniform_write(name, bytes);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
push_command(commands_, RecordedRenderCommand {
|
||||
.kind = RecordedRenderCommandKind::set_shader_uniform,
|
||||
.uniform_bytes = static_cast<std::uint64_t>(bytes.size()),
|
||||
.name = name,
|
||||
});
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::bind_texture(
|
||||
std::uint32_t slot,
|
||||
ITexture2D& texture) noexcept
|
||||
@@ -574,6 +598,8 @@ const char* recorded_render_command_kind_name(RecordedRenderCommandKind kind) no
|
||||
return "set_depth_state";
|
||||
case RecordedRenderCommandKind::bind_shader:
|
||||
return "bind_shader";
|
||||
case RecordedRenderCommandKind::set_shader_uniform:
|
||||
return "set_shader_uniform";
|
||||
case RecordedRenderCommandKind::bind_texture:
|
||||
return "bind_texture";
|
||||
case RecordedRenderCommandKind::bind_sampler:
|
||||
|
||||
@@ -14,6 +14,7 @@ enum class RecordedRenderCommandKind : std::uint8_t {
|
||||
set_blend_state,
|
||||
set_depth_state,
|
||||
bind_shader,
|
||||
set_shader_uniform,
|
||||
bind_texture,
|
||||
bind_sampler,
|
||||
bind_mesh,
|
||||
@@ -50,6 +51,7 @@ struct RecordedRenderCommand {
|
||||
std::uint64_t capture_bytes = 0;
|
||||
std::uint64_t blit_source_bytes = 0;
|
||||
std::uint64_t blit_destination_bytes = 0;
|
||||
std::uint64_t uniform_bytes = 0;
|
||||
const char* component = "";
|
||||
const char* name = "";
|
||||
};
|
||||
@@ -111,6 +113,9 @@ public:
|
||||
[[nodiscard]] pp::foundation::Status set_blend_state(BlendState state) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_depth_state(DepthState state) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_shader_uniform(
|
||||
const char* name,
|
||||
std::span<const std::byte> bytes) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_texture(
|
||||
std::uint32_t slot,
|
||||
ITexture2D& texture) noexcept override;
|
||||
|
||||
@@ -348,6 +348,25 @@ pp::foundation::Status validate_shader_program_desc(ShaderProgramDesc desc) noex
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_shader_uniform_write(
|
||||
const char* name,
|
||||
std::span<const std::byte> bytes) noexcept
|
||||
{
|
||||
if (is_empty_c_string(name)) {
|
||||
return pp::foundation::Status::invalid_argument("shader uniform name must not be empty");
|
||||
}
|
||||
|
||||
if (bytes.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("shader uniform bytes must not be empty");
|
||||
}
|
||||
|
||||
if (bytes.size() > max_shader_uniform_bytes) {
|
||||
return pp::foundation::Status::out_of_range("shader uniform bytes exceed the configured limit");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_readback_region(TextureDesc desc, ReadbackRegion region) noexcept
|
||||
{
|
||||
const auto extent_status = validate_extent(desc.extent);
|
||||
|
||||
@@ -14,6 +14,7 @@ constexpr std::uint32_t max_mesh_vertices = 16777216;
|
||||
constexpr std::uint32_t max_texture_slots = 32;
|
||||
constexpr std::uint64_t max_texture_bytes = 1024ULL * 1024ULL * 1024ULL;
|
||||
constexpr std::size_t max_shader_source_bytes = 4ULL * 1024ULL * 1024ULL;
|
||||
constexpr std::size_t max_shader_uniform_bytes = 64ULL * 1024ULL;
|
||||
|
||||
enum class TextureFormat : std::uint8_t {
|
||||
rgba8,
|
||||
@@ -206,6 +207,9 @@ public:
|
||||
[[nodiscard]] virtual pp::foundation::Status set_blend_state(BlendState state) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_depth_state(DepthState state) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_shader_uniform(
|
||||
const char* name,
|
||||
std::span<const std::byte> bytes) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_texture(
|
||||
std::uint32_t slot,
|
||||
ITexture2D& texture) noexcept = 0;
|
||||
@@ -267,6 +271,9 @@ public:
|
||||
[[nodiscard]] pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_texture_slot(std::uint32_t slot) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_shader_program_desc(ShaderProgramDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_shader_uniform_write(
|
||||
const char* name,
|
||||
std::span<const std::byte> bytes) noexcept;
|
||||
[[nodiscard]] pp::foundation::Result<std::uint64_t> texture_byte_size(TextureDesc desc) noexcept;
|
||||
[[nodiscard]] pp::foundation::Result<std::uint64_t> readback_byte_size(
|
||||
TextureDesc desc,
|
||||
|
||||
Reference in New Issue
Block a user