Add renderer texture binding contract
This commit is contained in:
@@ -136,6 +136,33 @@ pp::foundation::Status RecordingCommandContext::bind_shader(IShaderProgram& shad
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::bind_texture(
|
||||
std::uint32_t slot,
|
||||
ITexture2D& texture) noexcept
|
||||
{
|
||||
if (!in_render_pass_) {
|
||||
return pp::foundation::Status::invalid_argument("render pass has not begun");
|
||||
}
|
||||
|
||||
const auto slot_status = validate_texture_slot(slot);
|
||||
if (!slot_status.ok()) {
|
||||
return slot_status;
|
||||
}
|
||||
|
||||
const auto desc = texture.desc();
|
||||
const auto size_status = texture_byte_size(desc);
|
||||
if (!size_status.ok()) {
|
||||
return size_status.status();
|
||||
}
|
||||
|
||||
push_command(commands_, RecordedRenderCommand {
|
||||
.kind = RecordedRenderCommandKind::bind_texture,
|
||||
.texture_desc = desc,
|
||||
.texture_slot = slot,
|
||||
});
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::bind_mesh(IMesh& mesh) noexcept
|
||||
{
|
||||
if (!in_render_pass_) {
|
||||
@@ -375,6 +402,8 @@ const char* recorded_render_command_kind_name(RecordedRenderCommandKind kind) no
|
||||
return "set_viewport";
|
||||
case RecordedRenderCommandKind::bind_shader:
|
||||
return "bind_shader";
|
||||
case RecordedRenderCommandKind::bind_texture:
|
||||
return "bind_texture";
|
||||
case RecordedRenderCommandKind::bind_mesh:
|
||||
return "bind_mesh";
|
||||
case RecordedRenderCommandKind::draw:
|
||||
|
||||
@@ -11,6 +11,7 @@ enum class RecordedRenderCommandKind : std::uint8_t {
|
||||
begin_render_pass,
|
||||
set_viewport,
|
||||
bind_shader,
|
||||
bind_texture,
|
||||
bind_mesh,
|
||||
draw,
|
||||
upload_texture,
|
||||
@@ -28,6 +29,7 @@ struct RecordedRenderCommand {
|
||||
Viewport viewport {};
|
||||
MeshDesc mesh_desc {};
|
||||
TextureDesc texture_desc {};
|
||||
std::uint32_t texture_slot = 0;
|
||||
TextureDesc source_desc {};
|
||||
TextureDesc destination_desc {};
|
||||
ReadbackRegion readback_region {};
|
||||
@@ -97,6 +99,9 @@ public:
|
||||
ClearColor clear_color) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_viewport(Viewport viewport) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_texture(
|
||||
std::uint32_t slot,
|
||||
ITexture2D& texture) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_mesh(IMesh& mesh) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status draw() noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status read_texture(
|
||||
|
||||
@@ -151,6 +151,15 @@ pp::foundation::Status validate_mesh_desc(MeshDesc desc) noexcept
|
||||
return pp::foundation::Status::invalid_argument("mesh topology is not supported");
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_texture_slot(std::uint32_t slot) noexcept
|
||||
{
|
||||
if (slot >= max_texture_slots) {
|
||||
return pp::foundation::Status::out_of_range("texture slot exceeds the configured limit");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_shader_program_desc(ShaderProgramDesc desc) noexcept
|
||||
{
|
||||
if (desc.debug_name == nullptr) {
|
||||
|
||||
@@ -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::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;
|
||||
|
||||
@@ -126,6 +127,9 @@ public:
|
||||
ClearColor clear_color) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_viewport(Viewport viewport) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_texture(
|
||||
std::uint32_t slot,
|
||||
ITexture2D& texture) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_mesh(IMesh& mesh) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status draw() noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status read_texture(
|
||||
@@ -160,6 +164,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_texture_slot(std::uint32_t slot) 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::Result<std::uint64_t> readback_byte_size(
|
||||
|
||||
Reference in New Issue
Block a user