Route shader runtime calls through renderer GL

This commit is contained in:
2026-06-03 06:53:51 +02:00
parent f20595aff6
commit acdaf3bb8e
6 changed files with 717 additions and 17 deletions

View File

@@ -96,6 +96,21 @@ struct RecordedOpenGlSamplerBorderCall {
const float* values = nullptr;
};
struct RecordedOpenGlUniformFloatVectorCall {
std::int32_t location = 0;
std::int32_t count = 0;
const float* values = nullptr;
std::uint8_t transpose = 0;
std::uint32_t component_count = 0;
};
struct RecordedOpenGlUniformScalarCall {
std::int32_t location = 0;
std::int32_t int_value = 0;
float float_value = 0.0F;
bool is_float = false;
};
std::vector<RecordedOpenGlStateCall> recorded_state_calls;
std::vector<std::uint32_t> recorded_string_queries;
std::vector<pp::renderer::gl::OpenGlDefaultClear> recorded_clear_calls;
@@ -118,6 +133,11 @@ std::vector<RecordedOpenGlBlitFramebufferCall> recorded_blit_framebuffer_calls;
std::vector<std::uint32_t> recorded_generated_sampler_counts;
std::vector<RecordedOpenGlSamplerParameterCall> recorded_sampler_parameter_calls;
std::vector<RecordedOpenGlSamplerBorderCall> recorded_sampler_border_calls;
std::vector<std::uint32_t> recorded_deleted_programs;
std::vector<RecordedOpenGlUniformFloatVectorCall> recorded_uniform_vector_calls;
std::vector<RecordedOpenGlUniformScalarCall> recorded_uniform_scalar_calls;
std::vector<std::uint32_t> recorded_attrib_location_programs;
std::vector<std::string_view> recorded_attrib_location_names;
std::uint32_t next_texture_id = 91U;
std::uint32_t next_framebuffer_id = 44U;
std::uint32_t next_sampler_id = 71U;
@@ -495,6 +515,83 @@ void record_sampler_parameter_fv(
});
}
void record_delete_program(std::uint32_t program) noexcept
{
recorded_deleted_programs.push_back(program);
}
void record_uniform_4fv(std::int32_t location, std::int32_t count, const float* values) noexcept
{
recorded_uniform_vector_calls.push_back(RecordedOpenGlUniformFloatVectorCall {
.location = location,
.count = count,
.values = values,
.component_count = 4U,
});
}
void record_uniform_3fv(std::int32_t location, std::int32_t count, const float* values) noexcept
{
recorded_uniform_vector_calls.push_back(RecordedOpenGlUniformFloatVectorCall {
.location = location,
.count = count,
.values = values,
.component_count = 3U,
});
}
void record_uniform_2fv(std::int32_t location, std::int32_t count, const float* values) noexcept
{
recorded_uniform_vector_calls.push_back(RecordedOpenGlUniformFloatVectorCall {
.location = location,
.count = count,
.values = values,
.component_count = 2U,
});
}
void record_uniform_matrix_4fv(
std::int32_t location,
std::int32_t count,
std::uint8_t transpose,
const float* values) noexcept
{
recorded_uniform_vector_calls.push_back(RecordedOpenGlUniformFloatVectorCall {
.location = location,
.count = count,
.values = values,
.transpose = transpose,
.component_count = 16U,
});
}
void record_uniform_1i(std::int32_t location, std::int32_t value) noexcept
{
recorded_uniform_scalar_calls.push_back(RecordedOpenGlUniformScalarCall {
.location = location,
.int_value = value,
});
}
void record_uniform_1f(std::int32_t location, float value) noexcept
{
recorded_uniform_scalar_calls.push_back(RecordedOpenGlUniformScalarCall {
.location = location,
.float_value = value,
.is_float = true,
});
}
std::int32_t record_get_attrib_location(std::uint32_t program, const char* name) noexcept
{
recorded_attrib_location_programs.push_back(program);
recorded_attrib_location_names.push_back(name == nullptr ? std::string_view {} : std::string_view { name });
if (name != nullptr && std::string_view { name } == std::string_view { "uvs" }) {
return 1;
}
return -1;
}
void detects_common_extension_capabilities(pp::tests::Harness& h)
{
constexpr std::array<std::string_view, 2> extensions {
@@ -1944,6 +2041,221 @@ void rejects_invalid_sampler_dispatch(pp::tests::Harness& h)
PP_EXPECT(h, missing_bind_dispatch.code == pp::foundation::StatusCode::invalid_argument);
}
void uses_and_deletes_programs_through_dispatch(pp::tests::Harness& h)
{
recorded_binding_calls.clear();
recorded_deleted_programs.clear();
const auto use_status = pp::renderer::gl::use_opengl_program(
91U,
pp::renderer::gl::OpenGlProgramUseDispatch {
.use_program = record_use_program,
});
const auto delete_status = pp::renderer::gl::delete_opengl_program(
91U,
pp::renderer::gl::OpenGlProgramDeleteDispatch {
.use_program = record_use_program,
.delete_program = record_delete_program,
});
const auto delete_zero_status = pp::renderer::gl::delete_opengl_program(
0U,
pp::renderer::gl::OpenGlProgramDeleteDispatch {
.use_program = record_use_program,
.delete_program = record_delete_program,
});
PP_EXPECT(h, use_status.ok());
PP_EXPECT(h, delete_status.ok());
PP_EXPECT(h, delete_zero_status.ok());
PP_EXPECT(h, recorded_binding_calls.size() == 2U);
PP_EXPECT(h, recorded_binding_calls[0].kind == RecordedOpenGlBindingCall::Kind::use_program);
PP_EXPECT(h, recorded_binding_calls[0].first == 91U);
PP_EXPECT(h, recorded_binding_calls[1].kind == RecordedOpenGlBindingCall::Kind::use_program);
PP_EXPECT(h, recorded_binding_calls[1].first == 0U);
PP_EXPECT(h, recorded_deleted_programs.size() == 1U);
PP_EXPECT(h, recorded_deleted_programs[0] == 91U);
}
void sets_vector_uniforms_through_dispatch(pp::tests::Harness& h)
{
recorded_uniform_vector_calls.clear();
constexpr std::array<float, 16> values {
1.0F, 2.0F, 3.0F, 4.0F,
5.0F, 6.0F, 7.0F, 8.0F,
9.0F, 10.0F, 11.0F, 12.0F,
13.0F, 14.0F, 15.0F, 16.0F,
};
const auto vec4_status = pp::renderer::gl::set_opengl_uniform_vec4(
4,
values.data(),
pp::renderer::gl::OpenGlUniformVec4Dispatch {
.uniform_4fv = record_uniform_4fv,
});
const auto vec3_status = pp::renderer::gl::set_opengl_uniform_vec3(
3,
values.data(),
pp::renderer::gl::OpenGlUniformVec3Dispatch {
.uniform_3fv = record_uniform_3fv,
});
const auto vec2_status = pp::renderer::gl::set_opengl_uniform_vec2(
2,
values.data(),
pp::renderer::gl::OpenGlUniformVec2Dispatch {
.uniform_2fv = record_uniform_2fv,
});
const auto mat4_status = pp::renderer::gl::set_opengl_uniform_mat4(
-1,
values.data(),
pp::renderer::gl::OpenGlUniformMat4Dispatch {
.uniform_matrix_4fv = record_uniform_matrix_4fv,
});
PP_EXPECT(h, vec4_status.ok());
PP_EXPECT(h, vec3_status.ok());
PP_EXPECT(h, vec2_status.ok());
PP_EXPECT(h, mat4_status.ok());
PP_EXPECT(h, recorded_uniform_vector_calls.size() == 4U);
PP_EXPECT(h, recorded_uniform_vector_calls[0].location == 4);
PP_EXPECT(h, recorded_uniform_vector_calls[0].count == 1);
PP_EXPECT(h, recorded_uniform_vector_calls[0].values == values.data());
PP_EXPECT(h, recorded_uniform_vector_calls[0].component_count == 4U);
PP_EXPECT(h, recorded_uniform_vector_calls[1].component_count == 3U);
PP_EXPECT(h, recorded_uniform_vector_calls[2].component_count == 2U);
PP_EXPECT(h, recorded_uniform_vector_calls[3].location == -1);
PP_EXPECT(h, recorded_uniform_vector_calls[3].transpose == 0U);
PP_EXPECT(h, recorded_uniform_vector_calls[3].component_count == 16U);
}
void sets_scalar_uniforms_through_dispatch(pp::tests::Harness& h)
{
recorded_uniform_scalar_calls.clear();
const auto int_status = pp::renderer::gl::set_opengl_uniform_int(
7,
42,
pp::renderer::gl::OpenGlUniformIntDispatch {
.uniform_1i = record_uniform_1i,
});
const auto float_status = pp::renderer::gl::set_opengl_uniform_float(
-1,
0.25F,
pp::renderer::gl::OpenGlUniformFloatDispatch {
.uniform_1f = record_uniform_1f,
});
PP_EXPECT(h, int_status.ok());
PP_EXPECT(h, float_status.ok());
PP_EXPECT(h, recorded_uniform_scalar_calls.size() == 2U);
PP_EXPECT(h, recorded_uniform_scalar_calls[0].location == 7);
PP_EXPECT(h, recorded_uniform_scalar_calls[0].int_value == 42);
PP_EXPECT(h, !recorded_uniform_scalar_calls[0].is_float);
PP_EXPECT(h, recorded_uniform_scalar_calls[1].location == -1);
PP_EXPECT(h, recorded_uniform_scalar_calls[1].float_value == 0.25F);
PP_EXPECT(h, recorded_uniform_scalar_calls[1].is_float);
}
void queries_attribute_location_through_dispatch(pp::tests::Harness& h)
{
recorded_attrib_location_programs.clear();
recorded_attrib_location_names.clear();
const auto location = pp::renderer::gl::get_opengl_attribute_location(
11U,
"uvs",
pp::renderer::gl::OpenGlAttributeLocationDispatch {
.get_attrib_location = record_get_attrib_location,
});
const auto missing = pp::renderer::gl::get_opengl_attribute_location(
11U,
"missing",
pp::renderer::gl::OpenGlAttributeLocationDispatch {
.get_attrib_location = record_get_attrib_location,
});
PP_EXPECT(h, location.ok());
PP_EXPECT(h, location.value() == 1);
PP_EXPECT(h, missing.ok());
PP_EXPECT(h, missing.value() == -1);
PP_EXPECT(h, recorded_attrib_location_programs.size() == 2U);
PP_EXPECT(h, recorded_attrib_location_programs[0] == 11U);
PP_EXPECT(h, recorded_attrib_location_names[0] == std::string_view("uvs"));
PP_EXPECT(h, recorded_attrib_location_names[1] == std::string_view("missing"));
}
void rejects_invalid_program_uniform_dispatch(pp::tests::Harness& h)
{
constexpr std::array<float, 4> values { 1.0F, 2.0F, 3.0F, 4.0F };
const auto missing_use = pp::renderer::gl::use_opengl_program(
1U,
pp::renderer::gl::OpenGlProgramUseDispatch {});
const auto missing_delete = pp::renderer::gl::delete_opengl_program(
1U,
pp::renderer::gl::OpenGlProgramDeleteDispatch {
.use_program = record_use_program,
});
const auto missing_vec4 = pp::renderer::gl::set_opengl_uniform_vec4(
1,
values.data(),
pp::renderer::gl::OpenGlUniformVec4Dispatch {});
const auto null_vec3 = pp::renderer::gl::set_opengl_uniform_vec3(
1,
nullptr,
pp::renderer::gl::OpenGlUniformVec3Dispatch {
.uniform_3fv = record_uniform_3fv,
});
const auto missing_vec2 = pp::renderer::gl::set_opengl_uniform_vec2(
1,
values.data(),
pp::renderer::gl::OpenGlUniformVec2Dispatch {});
const auto null_mat4 = pp::renderer::gl::set_opengl_uniform_mat4(
1,
nullptr,
pp::renderer::gl::OpenGlUniformMat4Dispatch {
.uniform_matrix_4fv = record_uniform_matrix_4fv,
});
const auto missing_int = pp::renderer::gl::set_opengl_uniform_int(
1,
2,
pp::renderer::gl::OpenGlUniformIntDispatch {});
const auto missing_float = pp::renderer::gl::set_opengl_uniform_float(
1,
2.0F,
pp::renderer::gl::OpenGlUniformFloatDispatch {});
const auto missing_attrib_dispatch = pp::renderer::gl::get_opengl_attribute_location(
1U,
"pos",
pp::renderer::gl::OpenGlAttributeLocationDispatch {});
const auto invalid_attrib_name = pp::renderer::gl::get_opengl_attribute_location(
1U,
"",
pp::renderer::gl::OpenGlAttributeLocationDispatch {
.get_attrib_location = record_get_attrib_location,
});
PP_EXPECT(h, !missing_use.ok());
PP_EXPECT(h, missing_use.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !missing_delete.ok());
PP_EXPECT(h, missing_delete.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !missing_vec4.ok());
PP_EXPECT(h, missing_vec4.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !null_vec3.ok());
PP_EXPECT(h, null_vec3.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !missing_vec2.ok());
PP_EXPECT(h, missing_vec2.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !null_mat4.ok());
PP_EXPECT(h, null_mat4.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !missing_int.ok());
PP_EXPECT(h, missing_int.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !missing_float.ok());
PP_EXPECT(h, missing_float.code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !missing_attrib_dispatch.ok());
PP_EXPECT(h, missing_attrib_dispatch.status().code == pp::foundation::StatusCode::invalid_argument);
PP_EXPECT(h, !invalid_attrib_name.ok());
PP_EXPECT(h, invalid_attrib_name.status().code == pp::foundation::StatusCode::invalid_argument);
}
void updates_texture_2d_through_dispatch(pp::tests::Harness& h)
{
recorded_binding_calls.clear();
@@ -2726,6 +3038,11 @@ int main()
harness.run("sets_sampler_border_color_through_dispatch", sets_sampler_border_color_through_dispatch);
harness.run("binds_sampler_through_dispatch", binds_sampler_through_dispatch);
harness.run("rejects_invalid_sampler_dispatch", rejects_invalid_sampler_dispatch);
harness.run("uses_and_deletes_programs_through_dispatch", uses_and_deletes_programs_through_dispatch);
harness.run("sets_vector_uniforms_through_dispatch", sets_vector_uniforms_through_dispatch);
harness.run("sets_scalar_uniforms_through_dispatch", sets_scalar_uniforms_through_dispatch);
harness.run("queries_attribute_location_through_dispatch", queries_attribute_location_through_dispatch);
harness.run("rejects_invalid_program_uniform_dispatch", rejects_invalid_program_uniform_dispatch);
harness.run("updates_texture_2d_through_dispatch", updates_texture_2d_through_dispatch);
harness.run("generates_texture_2d_mipmaps_through_dispatch", generates_texture_2d_mipmaps_through_dispatch);
harness.run("reads_back_texture_2d_through_framebuffer_dispatch", reads_back_texture_2d_through_framebuffer_dispatch);