Validate OpenGL texture binding slots

This commit is contained in:
2026-06-02 21:14:07 +02:00
parent d664e9fc39
commit 55b725e876
7 changed files with 99 additions and 17 deletions

View File

@@ -164,6 +164,7 @@ void maps_binding_draw_and_blit_commands(pp::tests::Harness& h)
.extent = pp::renderer::Extent2D { .width = 16U, .height = 16U },
.format = pp::renderer::TextureFormat::depth24_stencil8,
},
.texture_slot = 3U,
});
const auto sampler = pp::renderer::gl::plan_recorded_render_command(pp::renderer::RecordedRenderCommand {
.kind = pp::renderer::RecordedRenderCommandKind::bind_sampler,
@@ -175,6 +176,7 @@ void maps_binding_draw_and_blit_commands(pp::tests::Harness& h)
.address_v = pp::renderer::SamplerAddressMode::mirrored_repeat,
.address_w = pp::renderer::SamplerAddressMode::clamp_to_border,
},
.sampler_slot = 3U,
});
const auto mesh = pp::renderer::gl::plan_recorded_render_command(pp::renderer::RecordedRenderCommand {
.kind = pp::renderer::RecordedRenderCommandKind::bind_mesh,
@@ -191,9 +193,11 @@ void maps_binding_draw_and_blit_commands(pp::tests::Harness& h)
PP_EXPECT(h, texture.supported);
PP_EXPECT(h, texture.requires_render_pass);
PP_EXPECT(h, texture.texture_format.internal_format == 0x88F0U);
PP_EXPECT(h, texture.texture_slot == 3U);
PP_EXPECT(h, sampler.supported);
PP_EXPECT(h, sampler.sampler.min_filter == 0x2702U);
PP_EXPECT(h, sampler.sampler.wrap_t == 0x8370U);
PP_EXPECT(h, sampler.sampler_slot == 3U);
PP_EXPECT(h, mesh.supported);
PP_EXPECT(h, mesh.primitive_mode == 0x0005U);
PP_EXPECT(h, draw.supported);
@@ -321,6 +325,18 @@ void rejects_unsupported_command_tokens(pp::tests::Harness& h)
.address_u = static_cast<pp::renderer::SamplerAddressMode>(255U),
},
});
const auto bad_texture_slot = pp::renderer::gl::plan_recorded_render_command(pp::renderer::RecordedRenderCommand {
.kind = pp::renderer::RecordedRenderCommandKind::bind_texture,
.texture_desc = pp::renderer::TextureDesc {
.extent = pp::renderer::Extent2D { .width = 1U, .height = 1U },
.format = pp::renderer::TextureFormat::rgba8,
},
.texture_slot = pp::renderer::max_texture_slots,
});
const auto bad_sampler_slot = pp::renderer::gl::plan_recorded_render_command(pp::renderer::RecordedRenderCommand {
.kind = pp::renderer::RecordedRenderCommandKind::bind_sampler,
.sampler_slot = pp::renderer::max_texture_slots,
});
const auto bad_mesh = pp::renderer::gl::plan_recorded_render_command(pp::renderer::RecordedRenderCommand {
.kind = pp::renderer::RecordedRenderCommandKind::draw,
.mesh_desc = pp::renderer::MeshDesc {
@@ -349,6 +365,10 @@ void rejects_unsupported_command_tokens(pp::tests::Harness& h)
PP_EXPECT(h, bad_depth.depth.compare_function == 0U);
PP_EXPECT(h, !bad_sampler.supported);
PP_EXPECT(h, bad_sampler.sampler.wrap_s == 0U);
PP_EXPECT(h, !bad_texture_slot.supported);
PP_EXPECT(h, bad_texture_slot.texture_slot == pp::renderer::max_texture_slots);
PP_EXPECT(h, !bad_sampler_slot.supported);
PP_EXPECT(h, bad_sampler_slot.sampler_slot == pp::renderer::max_texture_slots);
PP_EXPECT(h, !bad_mesh.supported);
PP_EXPECT(h, bad_mesh.primitive_mode == 0U);
PP_EXPECT(h, !bad_blit.supported);
@@ -404,6 +424,8 @@ void plans_valid_recorded_command_streams(pp::tests::Harness& h)
PP_EXPECT(h, plan.draw_command_count == 1U);
PP_EXPECT(h, plan.shader_bind_command_count == 1U);
PP_EXPECT(h, plan.uniform_command_count == 1U);
PP_EXPECT(h, plan.texture_bind_command_count == 0U);
PP_EXPECT(h, plan.sampler_bind_command_count == 0U);
PP_EXPECT(h, plan.passthrough_command_count == 0U);
PP_EXPECT(h, plan.trace_command_count == 1U);
PP_EXPECT(h, plan.unsupported_command_count == 0U);
@@ -421,6 +443,39 @@ void plans_valid_recorded_command_streams(pp::tests::Harness& h)
PP_EXPECT(h, plan.commands[8].kind == pp::renderer::gl::OpenGlPlannedCommandKind::blit_render_target);
}
void counts_texture_and_sampler_bindings_in_streams(pp::tests::Harness& h)
{
pp::renderer::RecordedRenderCommand texture_command;
texture_command.kind = pp::renderer::RecordedRenderCommandKind::bind_texture;
texture_command.texture_desc.format = pp::renderer::TextureFormat::rgba8;
texture_command.texture_slot = 2U;
pp::renderer::RecordedRenderCommand sampler_command;
sampler_command.kind = pp::renderer::RecordedRenderCommandKind::bind_sampler;
sampler_command.sampler_slot = 2U;
const std::vector<pp::renderer::RecordedRenderCommand> commands {
begin_render_pass_command(),
bind_shader_command("shader"),
texture_command,
sampler_command,
bind_mesh_command(),
draw_command(),
command_with_kind(pp::renderer::RecordedRenderCommandKind::end_render_pass),
};
const auto plan = pp::renderer::gl::plan_recorded_render_commands(commands);
PP_EXPECT(h, plan.supported);
PP_EXPECT(h, plan.texture_bind_command_count == 1U);
PP_EXPECT(h, plan.sampler_bind_command_count == 1U);
PP_EXPECT(h, plan.unsupported_command_count == 0U);
PP_EXPECT(h, plan.render_pass_order_error_count == 0U);
PP_EXPECT(h, plan.dependency_error_count == 0U);
PP_EXPECT(h, plan.commands[2].texture_slot == 2U);
PP_EXPECT(h, plan.commands[3].sampler_slot == 2U);
}
void flags_broken_render_pass_command_order(pp::tests::Harness& h)
{
const std::vector<pp::renderer::RecordedRenderCommand> outside_pass {
@@ -594,6 +649,7 @@ int main()
harness.run("rejects_unsupported_command_tokens", rejects_unsupported_command_tokens);
harness.run("names_planned_command_kinds", names_planned_command_kinds);
harness.run("plans_valid_recorded_command_streams", plans_valid_recorded_command_streams);
harness.run("counts_texture_and_sampler_bindings_in_streams", counts_texture_and_sampler_bindings_in_streams);
harness.run("flags_broken_render_pass_command_order", flags_broken_render_pass_command_order);
harness.run("flags_missing_render_dependencies", flags_missing_render_dependencies);
harness.run("tracks_unsupported_commands_in_streams", tracks_unsupported_commands_in_streams);