Add renderer scissor state contract
This commit is contained in:
@@ -285,14 +285,15 @@ Known local toolchain state:
|
||||
source code reintroduces raw `GL_*`/`WGL_*` constants outside the allowed
|
||||
legacy OpenGL implementation files.
|
||||
- `pp_renderer_api` exposes a headless `RecordingRenderDevice` that validates
|
||||
command order, blend state, texture-slot binding, texture-upload byte counts,
|
||||
readback bounds, frame-capture sources, destination buffer sizes, and
|
||||
render-target blit regions, records render/blend/texture-bind/upload/
|
||||
readback/frame-capture/blit commands, and records trace markers without a
|
||||
window or GL context.
|
||||
command order, scissor state, blend state, texture-slot binding,
|
||||
texture-upload byte counts, readback bounds, frame-capture sources,
|
||||
destination buffer sizes, and render-target blit regions, records
|
||||
render/scissor/blend/texture-bind/upload/readback/frame-capture/blit
|
||||
commands, and records trace markers without a window or GL context.
|
||||
- `pano_cli record-render` exposes the recording renderer through JSON
|
||||
automation, including blend/texture-bind/upload/readback/frame-capture/blit
|
||||
command and byte totals, and is covered by `pano_cli_record_render_smoke` plus
|
||||
automation, including scissor/blend/texture-bind/upload/readback/frame-
|
||||
capture/blit command and byte totals, and is covered by
|
||||
`pano_cli_record_render_smoke` plus
|
||||
`pano_cli_record_render_rejects_oversized_target`.
|
||||
- `pano_cli simulate-document-history` exposes `pp_document::DocumentHistory`
|
||||
apply/undo/redo state through JSON automation and is covered by
|
||||
|
||||
@@ -419,8 +419,9 @@ context, render device, shader program descriptor, mesh, render target,
|
||||
readback byte-size helpers, texture-upload/readback command validation,
|
||||
frame-capture byte-size helpers, frame-capture command validation,
|
||||
render-target blit validation, texture-slot binding validation, blend-state
|
||||
validation, trace interface validation, and the canonical PanoPainter shader
|
||||
catalog now consumed by the legacy OpenGL app initialization path.
|
||||
validation, scissor-state validation, trace interface validation, and the
|
||||
canonical PanoPainter shader catalog now consumed by the legacy OpenGL app
|
||||
initialization path.
|
||||
`pp_renderer_gl` now exists as the first OpenGL backend library and owns pure
|
||||
OpenGL capability detection for framebuffer fetch, map-buffer alignment, and
|
||||
float texture support. It also owns the OpenGL texture upload-type mapping used
|
||||
@@ -722,8 +723,9 @@ Results:
|
||||
PanoPainter shader catalog validation, readback byte-size and command-order
|
||||
validation, texture-upload byte-count validation, frame-capture byte-size and
|
||||
command-order validation, render-target blit validation, texture-slot binding
|
||||
validation, blend-state validation, recording blend/texture-bind/upload/
|
||||
readback/frame-capture/blit command capture, and invalid catalog rejection.
|
||||
validation, blend-state validation, scissor-state validation, recording
|
||||
scissor/blend/texture-bind/upload/readback/frame-capture/blit command
|
||||
capture, and invalid catalog rejection.
|
||||
- `pp_paint_renderer_compositor_tests` passed.
|
||||
- `pp_ui_core_color_tests` passed.
|
||||
- `pp_ui_core_layout_value_tests` passed.
|
||||
@@ -817,16 +819,16 @@ Results:
|
||||
reintroduces raw `GL_*`/`WGL_*` constants outside the allowed legacy OpenGL
|
||||
implementation files.
|
||||
- `pp_renderer_api` now includes a headless `RecordingRenderDevice` with strict
|
||||
command-order/blend-state/texture-bind/texture-upload/readback/frame-capture/
|
||||
blit validation; it records commands, trace markers, blend state, texture
|
||||
binds, uploads/readbacks, frame captures, and render-target blits, giving
|
||||
automation a backend-neutral render path that does not require a window or GL
|
||||
context.
|
||||
command-order/scissor-state/blend-state/texture-bind/texture-upload/readback/
|
||||
frame-capture/blit validation; it records commands, trace markers, scissor
|
||||
state, blend state, texture binds, uploads/readbacks, frame captures, and
|
||||
render-target blits, giving automation a backend-neutral render path that
|
||||
does not require a window or GL context.
|
||||
- `pano_cli record-render` exercises that headless recording renderer and emits
|
||||
JSON command counts, target dimensions, backend name, trace/draw summary, and
|
||||
blend-state plus texture-bind/upload/readback/frame-capture/blit command/byte
|
||||
totals for agent automation, with an expected-failure smoke for oversized
|
||||
render/readback targets.
|
||||
scissor/blend-state plus texture-bind/upload/readback/frame-capture/blit
|
||||
command/byte totals for agent automation, with an expected-failure smoke for
|
||||
oversized render/readback targets.
|
||||
- `pano_cli simulate-document-history` exercises pure document history
|
||||
apply/undo/redo behavior and emits JSON layer/frame/history state for agent
|
||||
automation.
|
||||
|
||||
@@ -122,6 +122,24 @@ pp::foundation::Status RecordingCommandContext::set_viewport(Viewport viewport)
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::set_scissor(ScissorRect scissor) noexcept
|
||||
{
|
||||
if (!in_render_pass_) {
|
||||
return pp::foundation::Status::invalid_argument("render pass has not begun");
|
||||
}
|
||||
|
||||
const auto status = validate_scissor(scissor, active_target_.extent);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
push_command(commands_, RecordedRenderCommand {
|
||||
.kind = RecordedRenderCommandKind::set_scissor,
|
||||
.scissor = scissor,
|
||||
});
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status RecordingCommandContext::set_blend_state(BlendState state) noexcept
|
||||
{
|
||||
if (!in_render_pass_) {
|
||||
@@ -418,6 +436,8 @@ const char* recorded_render_command_kind_name(RecordedRenderCommandKind kind) no
|
||||
return "begin_render_pass";
|
||||
case RecordedRenderCommandKind::set_viewport:
|
||||
return "set_viewport";
|
||||
case RecordedRenderCommandKind::set_scissor:
|
||||
return "set_scissor";
|
||||
case RecordedRenderCommandKind::set_blend_state:
|
||||
return "set_blend_state";
|
||||
case RecordedRenderCommandKind::bind_shader:
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace pp::renderer {
|
||||
enum class RecordedRenderCommandKind : std::uint8_t {
|
||||
begin_render_pass,
|
||||
set_viewport,
|
||||
set_scissor,
|
||||
set_blend_state,
|
||||
bind_shader,
|
||||
bind_texture,
|
||||
@@ -28,6 +29,7 @@ struct RecordedRenderCommand {
|
||||
TextureDesc target_desc {};
|
||||
ClearColor clear_color {};
|
||||
Viewport viewport {};
|
||||
ScissorRect scissor {};
|
||||
BlendState blend_state {};
|
||||
MeshDesc mesh_desc {};
|
||||
TextureDesc texture_desc {};
|
||||
@@ -100,6 +102,7 @@ public:
|
||||
IRenderTarget& target,
|
||||
ClearColor clear_color) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_viewport(Viewport viewport) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_scissor(ScissorRect scissor) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status set_blend_state(BlendState state) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept override;
|
||||
[[nodiscard]] pp::foundation::Status bind_texture(
|
||||
|
||||
@@ -131,6 +131,38 @@ pp::foundation::Status validate_viewport(Viewport viewport, Extent2D target_exte
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_scissor(ScissorRect scissor, Extent2D target_extent) noexcept
|
||||
{
|
||||
const auto extent_status = validate_extent(target_extent);
|
||||
if (!extent_status.ok()) {
|
||||
return extent_status;
|
||||
}
|
||||
|
||||
if (!scissor.enabled) {
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
if (scissor.x < 0 || scissor.y < 0) {
|
||||
return pp::foundation::Status::invalid_argument("scissor origin must be non-negative");
|
||||
}
|
||||
|
||||
if (scissor.width == 0 || scissor.height == 0) {
|
||||
return pp::foundation::Status::invalid_argument("scissor size must be greater than zero");
|
||||
}
|
||||
|
||||
const auto x = static_cast<std::uint32_t>(scissor.x);
|
||||
const auto y = static_cast<std::uint32_t>(scissor.y);
|
||||
if (x > target_extent.width || y > target_extent.height) {
|
||||
return pp::foundation::Status::out_of_range("scissor origin is outside the render target");
|
||||
}
|
||||
|
||||
if (scissor.width > target_extent.width - x || scissor.height > target_extent.height - y) {
|
||||
return pp::foundation::Status::out_of_range("scissor exceeds render target bounds");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status validate_blend_factor(BlendFactor factor) noexcept
|
||||
{
|
||||
switch (factor) {
|
||||
|
||||
@@ -47,6 +47,14 @@ struct Viewport {
|
||||
float max_depth = 1.0F;
|
||||
};
|
||||
|
||||
struct ScissorRect {
|
||||
bool enabled = false;
|
||||
std::int32_t x = 0;
|
||||
std::int32_t y = 0;
|
||||
std::uint32_t width = 0;
|
||||
std::uint32_t height = 0;
|
||||
};
|
||||
|
||||
struct ClearColor {
|
||||
float r = 0.0F;
|
||||
float g = 0.0F;
|
||||
@@ -155,6 +163,7 @@ public:
|
||||
IRenderTarget& target,
|
||||
ClearColor clear_color) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_viewport(Viewport viewport) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_scissor(ScissorRect scissor) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status set_blend_state(BlendState state) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept = 0;
|
||||
[[nodiscard]] virtual pp::foundation::Status bind_texture(
|
||||
@@ -193,6 +202,7 @@ public:
|
||||
[[nodiscard]] std::uint32_t bytes_per_pixel(TextureFormat format) noexcept;
|
||||
[[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_scissor(ScissorRect scissor, Extent2D target_extent) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_blend_factor(BlendFactor factor) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_blend_op(BlendOp op) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status validate_blend_state(BlendState state) noexcept;
|
||||
|
||||
@@ -365,7 +365,7 @@ if(TARGET pano_cli)
|
||||
COMMAND pano_cli record-render --width 32 --height 16)
|
||||
set_tests_properties(pano_cli_record_render_smoke PROPERTIES
|
||||
LABELS "renderer;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"backend\":\"recording\".*\"width\":32.*\"height\":16.*\"commands\":13.*\"drawCommands\":1.*\"blendCommands\":1.*\"bindTextureCommands\":1.*\"boundTextureBytes\":2048.*\"uploadCommands\":1.*\"uploadBytes\":4.*\"readbackCommands\":1.*\"readbackBytes\":2048.*\"captureCommands\":1.*\"captureBytes\":2048.*\"blitCommands\":1.*\"blitSourceBytes\":2048.*\"blitDestinationBytes\":2048")
|
||||
PASS_REGULAR_EXPRESSION "\"backend\":\"recording\".*\"width\":32.*\"height\":16.*\"commands\":14.*\"drawCommands\":1.*\"scissorCommands\":1.*\"blendCommands\":1.*\"bindTextureCommands\":1.*\"boundTextureBytes\":2048.*\"uploadCommands\":1.*\"uploadBytes\":4.*\"readbackCommands\":1.*\"readbackBytes\":2048.*\"captureCommands\":1.*\"captureBytes\":2048.*\"blitCommands\":1.*\"blitSourceBytes\":2048.*\"blitDestinationBytes\":2048")
|
||||
|
||||
add_test(NAME pano_cli_record_render_rejects_oversized_target
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
|
||||
@@ -34,6 +34,7 @@ using pp::renderer::RecordingRenderDevice;
|
||||
using pp::renderer::RecordingRenderTarget;
|
||||
using pp::renderer::RecordingShaderProgram;
|
||||
using pp::renderer::RecordingTexture2D;
|
||||
using pp::renderer::ScissorRect;
|
||||
using pp::renderer::ShaderProgramDesc;
|
||||
using pp::renderer::ShaderStageSource;
|
||||
using pp::renderer::TextureDesc;
|
||||
@@ -57,6 +58,7 @@ using pp::renderer::validate_blend_op;
|
||||
using pp::renderer::validate_blend_state;
|
||||
using pp::renderer::validate_mesh_desc;
|
||||
using pp::renderer::validate_readback_region;
|
||||
using pp::renderer::validate_scissor;
|
||||
using pp::renderer::validate_shader_catalog;
|
||||
using pp::renderer::validate_shader_program_desc;
|
||||
using pp::renderer::validate_texture_slot;
|
||||
@@ -150,6 +152,19 @@ public:
|
||||
return validate_viewport(viewport, Extent2D { .width = 64, .height = 32 });
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::foundation::Status set_scissor(ScissorRect scissor) noexcept override
|
||||
{
|
||||
if (!in_render_pass) {
|
||||
return pp::foundation::Status::invalid_argument("render pass has not begun");
|
||||
}
|
||||
const auto status = validate_scissor(scissor, Extent2D { .width = 64, .height = 32 });
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
last_scissor = scissor;
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] pp::foundation::Status bind_shader(IShaderProgram& shader) noexcept override
|
||||
{
|
||||
shader_name = shader.debug_name();
|
||||
@@ -286,6 +301,7 @@ public:
|
||||
|
||||
bool in_render_pass = false;
|
||||
const char* shader_name = nullptr;
|
||||
ScissorRect last_scissor {};
|
||||
BlendState last_blend_state {};
|
||||
std::uint32_t last_texture_slot = 0;
|
||||
std::uint64_t last_texture_bytes = 0;
|
||||
@@ -502,6 +518,11 @@ void validates_viewports_and_mesh_descriptors(pp::tests::Harness& h)
|
||||
Viewport { .x = 0, .y = 0, .width = 64, .height = 32, .min_depth = 0.0F, .max_depth = 1.0F },
|
||||
target)
|
||||
.ok());
|
||||
PP_EXPECT(h, validate_scissor(ScissorRect {}, target).ok());
|
||||
PP_EXPECT(h, validate_scissor(ScissorRect { .enabled = true, .x = 0, .y = 0, .width = 64, .height = 32 }, target)
|
||||
.ok());
|
||||
PP_EXPECT(h, validate_scissor(ScissorRect { .enabled = true, .x = 63, .y = 31, .width = 1, .height = 1 }, target)
|
||||
.ok());
|
||||
PP_EXPECT(h, validate_mesh_desc(MeshDesc { .vertex_count = 3, .topology = PrimitiveTopology::triangles }).ok());
|
||||
PP_EXPECT(h, primitive_topology_name(PrimitiveTopology::lines) == std::string_view("lines"));
|
||||
|
||||
@@ -511,6 +532,9 @@ void validates_viewports_and_mesh_descriptors(pp::tests::Harness& h)
|
||||
Viewport { .x = 0, .y = 0, .width = 1, .height = 1, .min_depth = 0.75F, .max_depth = 0.25F },
|
||||
target);
|
||||
const auto empty_mesh = validate_mesh_desc(MeshDesc {});
|
||||
const auto negative_scissor = validate_scissor(ScissorRect { .enabled = true, .x = -1, .y = 0, .width = 1, .height = 1 }, target);
|
||||
const auto empty_scissor = validate_scissor(ScissorRect { .enabled = true, .x = 0, .y = 0, .width = 0, .height = 1 }, target);
|
||||
const auto scissor_overrun = validate_scissor(ScissorRect { .enabled = true, .x = 63, .y = 0, .width = 2, .height = 1 }, target);
|
||||
|
||||
PP_EXPECT(h, !negative_origin.ok());
|
||||
PP_EXPECT(h, negative_origin.code == StatusCode::invalid_argument);
|
||||
@@ -520,6 +544,12 @@ void validates_viewports_and_mesh_descriptors(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, bad_depth.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !empty_mesh.ok());
|
||||
PP_EXPECT(h, empty_mesh.code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !negative_scissor.ok());
|
||||
PP_EXPECT(h, negative_scissor.code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !empty_scissor.ok());
|
||||
PP_EXPECT(h, empty_scissor.code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !scissor_overrun.ok());
|
||||
PP_EXPECT(h, scissor_overrun.code == StatusCode::out_of_range);
|
||||
|
||||
PP_EXPECT(h, validate_texture_slot(0).ok());
|
||||
PP_EXPECT(h, validate_texture_slot(max_texture_slots - 1U).ok());
|
||||
@@ -655,6 +685,7 @@ void renderer_interfaces_support_backend_neutral_dispatch(pp::tests::Harness& h)
|
||||
auto& context = device.immediate_context();
|
||||
PP_EXPECT(h, context.begin_render_pass(target, ClearColor { .r = 0.1F, .g = 0.2F, .b = 0.3F, .a = 1.0F }).ok());
|
||||
PP_EXPECT(h, context.set_viewport(Viewport { .x = 0, .y = 0, .width = 64, .height = 32 }).ok());
|
||||
PP_EXPECT(h, context.set_scissor(ScissorRect { .enabled = true, .x = 4, .y = 5, .width = 16, .height = 8 }).ok());
|
||||
PP_EXPECT(h, context.set_blend_state(BlendState {
|
||||
.enabled = true,
|
||||
.source_color = BlendFactor::source_alpha,
|
||||
@@ -689,6 +720,9 @@ void renderer_interfaces_support_backend_neutral_dispatch(pp::tests::Harness& h)
|
||||
BlitFilter::linear)
|
||||
.ok());
|
||||
PP_EXPECT(h, device.context.shader_name == std::string_view("fake-shader"));
|
||||
PP_EXPECT(h, device.context.last_scissor.enabled);
|
||||
PP_EXPECT(h, device.context.last_scissor.x == 4);
|
||||
PP_EXPECT(h, device.context.last_scissor.height == 8U);
|
||||
PP_EXPECT(h, device.context.last_blend_state.enabled);
|
||||
PP_EXPECT(h, device.context.last_blend_state.source_color == BlendFactor::source_alpha);
|
||||
PP_EXPECT(h, device.context.last_blend_state.destination_color == BlendFactor::one_minus_source_alpha);
|
||||
@@ -731,6 +765,7 @@ void recording_renderer_records_valid_command_sequences(pp::tests::Harness& h)
|
||||
auto& context = device.immediate_context();
|
||||
PP_EXPECT(h, context.begin_render_pass(target, ClearColor { .r = 0.2F, .g = 0.3F, .b = 0.4F, .a = 1.0F }).ok());
|
||||
PP_EXPECT(h, context.set_viewport(Viewport { .x = 0, .y = 0, .width = 64, .height = 32 }).ok());
|
||||
PP_EXPECT(h, context.set_scissor(ScissorRect { .enabled = true, .x = 4, .y = 6, .width = 16, .height = 8 }).ok());
|
||||
PP_EXPECT(h, context.set_blend_state(BlendState {
|
||||
.enabled = true,
|
||||
.source_color = BlendFactor::source_alpha,
|
||||
@@ -746,7 +781,7 @@ void recording_renderer_records_valid_command_sequences(pp::tests::Harness& h)
|
||||
context.end_render_pass();
|
||||
|
||||
const auto commands = device.commands();
|
||||
PP_EXPECT(h, commands.size() == 9U);
|
||||
PP_EXPECT(h, commands.size() == 10U);
|
||||
PP_EXPECT(h, commands[0].kind == RecordedRenderCommandKind::trace_marker);
|
||||
PP_EXPECT(h, commands[0].component == std::string_view("renderer"));
|
||||
PP_EXPECT(h, commands[0].name == std::string_view("frame"));
|
||||
@@ -755,21 +790,26 @@ void recording_renderer_records_valid_command_sequences(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, commands[1].clear_color.a == 1.0F);
|
||||
PP_EXPECT(h, commands[2].kind == RecordedRenderCommandKind::set_viewport);
|
||||
PP_EXPECT(h, commands[2].viewport.height == 32U);
|
||||
PP_EXPECT(h, commands[3].kind == RecordedRenderCommandKind::set_blend_state);
|
||||
PP_EXPECT(h, commands[3].blend_state.enabled);
|
||||
PP_EXPECT(h, commands[3].blend_state.destination_color == BlendFactor::one_minus_source_alpha);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands[3].kind) == std::string_view("set_blend_state"));
|
||||
PP_EXPECT(h, commands[4].kind == RecordedRenderCommandKind::bind_shader);
|
||||
PP_EXPECT(h, commands[4].name == std::string_view("recorded-shader"));
|
||||
PP_EXPECT(h, commands[5].kind == RecordedRenderCommandKind::bind_texture);
|
||||
PP_EXPECT(h, commands[5].texture_slot == 1U);
|
||||
PP_EXPECT(h, commands[5].texture_desc.extent.height == 32U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands[5].kind) == std::string_view("bind_texture"));
|
||||
PP_EXPECT(h, commands[6].kind == RecordedRenderCommandKind::bind_mesh);
|
||||
PP_EXPECT(h, commands[6].mesh_desc.vertex_count == 3U);
|
||||
PP_EXPECT(h, commands[7].kind == RecordedRenderCommandKind::draw);
|
||||
PP_EXPECT(h, commands[8].kind == RecordedRenderCommandKind::end_render_pass);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands[7].kind) == std::string_view("draw"));
|
||||
PP_EXPECT(h, commands[3].kind == RecordedRenderCommandKind::set_scissor);
|
||||
PP_EXPECT(h, commands[3].scissor.enabled);
|
||||
PP_EXPECT(h, commands[3].scissor.x == 4);
|
||||
PP_EXPECT(h, commands[3].scissor.height == 8U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands[3].kind) == std::string_view("set_scissor"));
|
||||
PP_EXPECT(h, commands[4].kind == RecordedRenderCommandKind::set_blend_state);
|
||||
PP_EXPECT(h, commands[4].blend_state.enabled);
|
||||
PP_EXPECT(h, commands[4].blend_state.destination_color == BlendFactor::one_minus_source_alpha);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands[4].kind) == std::string_view("set_blend_state"));
|
||||
PP_EXPECT(h, commands[5].kind == RecordedRenderCommandKind::bind_shader);
|
||||
PP_EXPECT(h, commands[5].name == std::string_view("recorded-shader"));
|
||||
PP_EXPECT(h, commands[6].kind == RecordedRenderCommandKind::bind_texture);
|
||||
PP_EXPECT(h, commands[6].texture_slot == 1U);
|
||||
PP_EXPECT(h, commands[6].texture_desc.extent.height == 32U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands[6].kind) == std::string_view("bind_texture"));
|
||||
PP_EXPECT(h, commands[7].kind == RecordedRenderCommandKind::bind_mesh);
|
||||
PP_EXPECT(h, commands[7].mesh_desc.vertex_count == 3U);
|
||||
PP_EXPECT(h, commands[8].kind == RecordedRenderCommandKind::draw);
|
||||
PP_EXPECT(h, commands[9].kind == RecordedRenderCommandKind::end_render_pass);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands[8].kind) == std::string_view("draw"));
|
||||
|
||||
PP_EXPECT(h, context.upload_texture(
|
||||
texture,
|
||||
@@ -777,12 +817,12 @@ void recording_renderer_records_valid_command_sequences(pp::tests::Harness& h)
|
||||
upload_bytes)
|
||||
.ok());
|
||||
const auto commands_after_upload = device.commands();
|
||||
PP_EXPECT(h, commands_after_upload.size() == 10U);
|
||||
PP_EXPECT(h, commands_after_upload[9].kind == RecordedRenderCommandKind::upload_texture);
|
||||
PP_EXPECT(h, commands_after_upload[9].texture_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_upload[9].readback_region.x == 4U);
|
||||
PP_EXPECT(h, commands_after_upload[9].upload_bytes == 96U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_upload[9].kind) == std::string_view("upload_texture"));
|
||||
PP_EXPECT(h, commands_after_upload.size() == 11U);
|
||||
PP_EXPECT(h, commands_after_upload[10].kind == RecordedRenderCommandKind::upload_texture);
|
||||
PP_EXPECT(h, commands_after_upload[10].texture_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_upload[10].readback_region.x == 4U);
|
||||
PP_EXPECT(h, commands_after_upload[10].upload_bytes == 96U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_upload[10].kind) == std::string_view("upload_texture"));
|
||||
|
||||
PP_EXPECT(h, context.read_texture(
|
||||
texture,
|
||||
@@ -790,22 +830,22 @@ void recording_renderer_records_valid_command_sequences(pp::tests::Harness& h)
|
||||
readback_buffer)
|
||||
.ok());
|
||||
const auto commands_after_readback = device.commands();
|
||||
PP_EXPECT(h, commands_after_readback.size() == 11U);
|
||||
PP_EXPECT(h, commands_after_readback[10].kind == RecordedRenderCommandKind::read_texture);
|
||||
PP_EXPECT(h, commands_after_readback[10].texture_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_readback[10].readback_region.x == 4U);
|
||||
PP_EXPECT(h, commands_after_readback[10].readback_region.height == 3U);
|
||||
PP_EXPECT(h, commands_after_readback[10].readback_bytes == 96U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_readback[10].kind) == std::string_view("read_texture"));
|
||||
PP_EXPECT(h, commands_after_readback.size() == 12U);
|
||||
PP_EXPECT(h, commands_after_readback[11].kind == RecordedRenderCommandKind::read_texture);
|
||||
PP_EXPECT(h, commands_after_readback[11].texture_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_readback[11].readback_region.x == 4U);
|
||||
PP_EXPECT(h, commands_after_readback[11].readback_region.height == 3U);
|
||||
PP_EXPECT(h, commands_after_readback[11].readback_bytes == 96U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_readback[11].kind) == std::string_view("read_texture"));
|
||||
|
||||
PP_EXPECT(h, context.capture_frame(target, readback_buffer).ok());
|
||||
const auto commands_after_capture = device.commands();
|
||||
PP_EXPECT(h, commands_after_capture.size() == 12U);
|
||||
PP_EXPECT(h, commands_after_capture[11].kind == RecordedRenderCommandKind::capture_frame);
|
||||
PP_EXPECT(h, commands_after_capture[11].target_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_capture[11].target_desc.extent.height == 32U);
|
||||
PP_EXPECT(h, commands_after_capture[11].capture_bytes == 8192U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_capture[11].kind) == std::string_view("capture_frame"));
|
||||
PP_EXPECT(h, commands_after_capture.size() == 13U);
|
||||
PP_EXPECT(h, commands_after_capture[12].kind == RecordedRenderCommandKind::capture_frame);
|
||||
PP_EXPECT(h, commands_after_capture[12].target_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_capture[12].target_desc.extent.height == 32U);
|
||||
PP_EXPECT(h, commands_after_capture[12].capture_bytes == 8192U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_capture[12].kind) == std::string_view("capture_frame"));
|
||||
|
||||
PP_EXPECT(h, context.blit_render_target(
|
||||
target,
|
||||
@@ -815,16 +855,16 @@ void recording_renderer_records_valid_command_sequences(pp::tests::Harness& h)
|
||||
BlitFilter::linear)
|
||||
.ok());
|
||||
const auto commands_after_blit = device.commands();
|
||||
PP_EXPECT(h, commands_after_blit.size() == 13U);
|
||||
PP_EXPECT(h, commands_after_blit[12].kind == RecordedRenderCommandKind::blit_render_target);
|
||||
PP_EXPECT(h, commands_after_blit[12].source_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_blit[12].destination_desc.extent.height == 32U);
|
||||
PP_EXPECT(h, commands_after_blit[12].source_region.width == 16U);
|
||||
PP_EXPECT(h, commands_after_blit[12].destination_region.x == 2U);
|
||||
PP_EXPECT(h, commands_after_blit[12].blit_filter == BlitFilter::linear);
|
||||
PP_EXPECT(h, commands_after_blit[12].blit_source_bytes == 512U);
|
||||
PP_EXPECT(h, commands_after_blit[12].blit_destination_bytes == 128U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_blit[12].kind) == std::string_view("blit_render_target"));
|
||||
PP_EXPECT(h, commands_after_blit.size() == 14U);
|
||||
PP_EXPECT(h, commands_after_blit[13].kind == RecordedRenderCommandKind::blit_render_target);
|
||||
PP_EXPECT(h, commands_after_blit[13].source_desc.extent.width == 64U);
|
||||
PP_EXPECT(h, commands_after_blit[13].destination_desc.extent.height == 32U);
|
||||
PP_EXPECT(h, commands_after_blit[13].source_region.width == 16U);
|
||||
PP_EXPECT(h, commands_after_blit[13].destination_region.x == 2U);
|
||||
PP_EXPECT(h, commands_after_blit[13].blit_filter == BlitFilter::linear);
|
||||
PP_EXPECT(h, commands_after_blit[13].blit_source_bytes == 512U);
|
||||
PP_EXPECT(h, commands_after_blit[13].blit_destination_bytes == 128U);
|
||||
PP_EXPECT(h, recorded_render_command_kind_name(commands_after_blit[13].kind) == std::string_view("blit_render_target"));
|
||||
|
||||
device.clear();
|
||||
PP_EXPECT(h, device.commands().empty());
|
||||
@@ -870,6 +910,10 @@ void recording_renderer_rejects_invalid_command_order_and_targets(pp::tests::Har
|
||||
PP_EXPECT(h, !blend_before_begin.ok());
|
||||
PP_EXPECT(h, blend_before_begin.code == StatusCode::invalid_argument);
|
||||
|
||||
const auto scissor_before_begin = context.set_scissor(ScissorRect {});
|
||||
PP_EXPECT(h, !scissor_before_begin.ok());
|
||||
PP_EXPECT(h, scissor_before_begin.code == StatusCode::invalid_argument);
|
||||
|
||||
const auto invalid_target = context.begin_render_pass(non_render_target, ClearColor {});
|
||||
PP_EXPECT(h, !invalid_target.ok());
|
||||
PP_EXPECT(h, invalid_target.code == StatusCode::invalid_argument);
|
||||
@@ -919,6 +963,24 @@ void recording_renderer_rejects_invalid_command_order_and_targets(pp::tests::Har
|
||||
.destination_color = BlendFactor::one_minus_source_alpha,
|
||||
})
|
||||
.ok());
|
||||
PP_EXPECT(h, context.set_scissor(ScissorRect {
|
||||
.enabled = true,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = 16,
|
||||
.height = 8,
|
||||
})
|
||||
.ok());
|
||||
|
||||
const auto invalid_scissor = context.set_scissor(ScissorRect {
|
||||
.enabled = true,
|
||||
.x = 31,
|
||||
.y = 15,
|
||||
.width = 2,
|
||||
.height = 1,
|
||||
});
|
||||
PP_EXPECT(h, !invalid_scissor.ok());
|
||||
PP_EXPECT(h, invalid_scissor.code == StatusCode::out_of_range);
|
||||
|
||||
const auto draw_without_bindings = context.draw();
|
||||
PP_EXPECT(h, !draw_without_bindings.ok());
|
||||
@@ -950,6 +1012,10 @@ void recording_renderer_rejects_invalid_command_order_and_targets(pp::tests::Har
|
||||
PP_EXPECT(h, !blend_after_end.ok());
|
||||
PP_EXPECT(h, blend_after_end.code == StatusCode::invalid_argument);
|
||||
|
||||
const auto scissor_after_end = context.set_scissor(ScissorRect {});
|
||||
PP_EXPECT(h, !scissor_after_end.ok());
|
||||
PP_EXPECT(h, scissor_after_end.code == StatusCode::invalid_argument);
|
||||
|
||||
const auto bind_texture_after_end = context.bind_texture(0, texture);
|
||||
PP_EXPECT(h, !bind_texture_after_end.ok());
|
||||
PP_EXPECT(h, bind_texture_after_end.code == StatusCode::invalid_argument);
|
||||
|
||||
@@ -2272,6 +2272,18 @@ int record_render(int argc, char** argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto scissor_status = context.set_scissor(pp::renderer::ScissorRect {
|
||||
.enabled = true,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = args.width,
|
||||
.height = args.height,
|
||||
});
|
||||
if (!scissor_status.ok()) {
|
||||
print_error("record-render", scissor_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto shader_status = context.bind_shader(shader);
|
||||
const auto blend_status = context.set_blend_state(pp::renderer::BlendState {
|
||||
.enabled = true,
|
||||
@@ -2348,6 +2360,7 @@ int record_render(int argc, char** argv)
|
||||
}
|
||||
|
||||
std::size_t draw_commands = 0;
|
||||
std::size_t scissor_commands = 0;
|
||||
std::size_t blend_commands = 0;
|
||||
std::size_t bind_texture_commands = 0;
|
||||
std::size_t upload_commands = 0;
|
||||
@@ -2365,6 +2378,8 @@ int record_render(int argc, char** argv)
|
||||
for (const auto& command : commands) {
|
||||
if (command.kind == pp::renderer::RecordedRenderCommandKind::draw) {
|
||||
++draw_commands;
|
||||
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::set_scissor) {
|
||||
++scissor_commands;
|
||||
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::set_blend_state) {
|
||||
++blend_commands;
|
||||
} else if (command.kind == pp::renderer::RecordedRenderCommandKind::bind_texture) {
|
||||
@@ -2398,6 +2413,7 @@ int record_render(int argc, char** argv)
|
||||
<< ",\"format\":\"rgba8\"}"
|
||||
<< ",\"commands\":" << commands.size()
|
||||
<< ",\"drawCommands\":" << draw_commands
|
||||
<< ",\"scissorCommands\":" << scissor_commands
|
||||
<< ",\"blendCommands\":" << blend_commands
|
||||
<< ",\"bindTextureCommands\":" << bind_texture_commands
|
||||
<< ",\"boundTextureBytes\":" << bound_texture_bytes
|
||||
|
||||
Reference in New Issue
Block a user