20#include "impeller/fixtures/baby.frag.h"
21#include "impeller/fixtures/baby.vert.h"
22#include "impeller/fixtures/instanced_attributes.frag.h"
23#include "impeller/fixtures/instanced_attributes.vert.h"
24#include "impeller/fixtures/mipmaps.frag.h"
25#include "impeller/fixtures/mipmaps.vert.h"
26#include "impeller/fixtures/texture.frag.h"
27#include "impeller/fixtures/texture.vert.h"
45#ifdef IMPELLER_GOLDEN_TESTS
57 using VS = BabyVertexShader;
58 using FS = BabyFragmentShader;
60 std::shared_ptr<Context>
context = GetContext();
64 ASSERT_TRUE(desc.has_value());
65 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
76 *
context->GetResourceAllocator());
80 context->GetCapabilities()->GetMinimumUniformAlignment());
82 ASSERT_TRUE(OpenPlaygroundHere([&](
RenderPass& pass) ->
bool {
89 FS::FragInfo frag_info;
90 frag_info.time = 0.0f;
91 FS::BindFragInfo(pass, host_buffer->EmplaceUniform(frag_info));
103 using VS = InstancedAttributesVertexShader;
104 using FS = InstancedAttributesFragmentShader;
106 std::shared_ptr<Context>
context = GetContext();
110 ASSERT_TRUE(desc.has_value());
111 ASSERT_TRUE(InitializePipelineDescriptorForRendering(*desc));
114 struct InstanceData {
122 auto vertex_desc = std::make_shared<VertexDescriptor>();
129 offset_slot.
offset = offsetof(InstanceData, offset);
131 color_slot.
offset = offsetof(InstanceData, color);
132 const std::vector<ShaderStageIOSlot> io_slots = {position_slot, offset_slot,
134 const std::vector<ShaderStageBufferLayout> layouts = {
142 vertex_desc->RegisterDescriptorSetLayouts(VS::kDescriptorSetLayouts);
143 vertex_desc->RegisterDescriptorSetLayouts(FS::kDescriptorSetLayouts);
144 vertex_desc->SetStageInputs(io_slots, layouts);
145 desc->SetVertexDescriptor(std::move(vertex_desc));
147 context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
151 std::array<Vector2, 3> geometry = {
157 static constexpr size_t kInstanceCount = 4u;
158 std::array<InstanceData, kInstanceCount> instances = {
165 auto geometry_buffer =
context->GetResourceAllocator()->CreateBufferWithCopy(
166 reinterpret_cast<uint8_t*
>(geometry.data()),
167 geometry.size() *
sizeof(
Vector2));
168 auto instance_buffer =
context->GetResourceAllocator()->CreateBufferWithCopy(
169 reinterpret_cast<uint8_t*
>(instances.data()),
170 instances.size() *
sizeof(InstanceData));
171 ASSERT_TRUE(geometry_buffer && instance_buffer);
175 context->GetCapabilities()->GetMinimumUniformAlignment());
177 ASSERT_TRUE(OpenPlaygroundHere([&](
RenderPass& pass) ->
bool {
180 host_buffer->Reset();
184 std::array<BufferView, 2> vertex_buffers = {
188 Range(0, instances.size() *
sizeof(InstanceData))),
194 VS::FrameInfo frame_info;
197 VS::BindFrameInfo(pass, host_buffer->EmplaceUniform(frame_info));
209 const std::vector<uint8_t>& block_data,
211 using VS = TextureVertexShader;
212 using FS = TextureFragmentShader;
223 auto texture =
context->GetResourceAllocator()->CreateTexture(texture_desc);
225 ASSERT_TRUE(
texture->SetContents(block_data.data(), block_data.size()));
228 ASSERT_TRUE(desc.has_value());
230 auto pipeline =
context->GetPipelineLibrary()->GetPipeline(desc).Get();
236 {{-1, -1, 0.0}, {0.0, 0.0}},
237 {{1, -1, 0.0}, {1.0, 0.0}},
238 {{1, 1, 0.0}, {1.0, 1.0}},
239 {{-1, -1, 0.0}, {0.0, 0.0}},
240 {{1, 1, 0.0}, {1.0, 1.0}},
241 {{-1, 1, 0.0}, {0.0, 1.0}},
244 *
context->GetResourceAllocator());
246 const auto& sampler =
context->GetSamplerLibrary()->GetSampler({});
250 context->GetCapabilities()->GetMinimumUniformAlignment());
253 host_buffer->Reset();
254 pass.SetPipeline(pipeline);
255 pass.SetVertexBuffer(vertex_buffer);
257 VS::UniformBuffer uniforms;
258 uniforms.mvp = Matrix();
259 VS::BindUniformBuffer(pass, host_buffer->EmplaceUniform(uniforms));
260 FS::BindTextureContents(pass, texture, sampler);
262 return pass.Draw().ok();
271 std::shared_ptr<Context>
context = GetContext();
273 if (!
context->GetCapabilities()->SupportsTextureCompression(
275 GTEST_SKIP() <<
"Backend does not support BC texture compression.";
280 auto bc1_solid_block = [](uint16_t rgb565) -> std::array<uint8_t, 8> {
281 const auto lo =
static_cast<uint8_t
>(rgb565 & 0xFF);
282 const auto hi =
static_cast<uint8_t
>(rgb565 >> 8);
283 return {{lo, hi, lo, hi, 0, 0, 0, 0}};
286 const std::array<std::array<uint8_t, 8>, 4> blocks = {
287 {bc1_solid_block(0xF800), bc1_solid_block(0x07E0),
288 bc1_solid_block(0x001F), bc1_solid_block(0xFFFF)}};
289 std::vector<uint8_t>
data;
290 for (
const auto& block : blocks) {
291 data.insert(
data.end(), block.begin(), block.end());
303 std::shared_ptr<Context>
context = GetContext();
305 if (!
context->GetCapabilities()->SupportsTextureCompression(
307 GTEST_SKIP() <<
"Backend does not support ETC2 texture compression.";
316 auto etc2_solid_block = [](uint8_t r, uint8_t g,
317 uint8_t b) -> std::array<uint8_t, 8> {
318 return {{r, g, b, 0x00, 0x00, 0x00, 0x00, 0x00}};
322 const std::array<std::array<uint8_t, 8>, 4> blocks = {
323 {etc2_solid_block(0xFF, 0x00, 0x00), etc2_solid_block(0x00, 0xFF, 0x00),
324 etc2_solid_block(0x00, 0x00, 0xFF), etc2_solid_block(0xFF, 0xFF, 0xFF)}};
325 std::vector<uint8_t>
data;
326 for (
const auto& block : blocks) {
327 data.insert(
data.end(), block.begin(), block.end());
339 std::shared_ptr<Context>
context = GetContext();
341 if (!
context->GetCapabilities()->SupportsTextureCompression(
343 GTEST_SKIP() <<
"Backend does not support ASTC texture compression.";
350 auto astc_solid_block = [](uint16_t r, uint16_t g,
351 uint16_t b) -> std::array<uint8_t, 16> {
352 return {{0xFC, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
353 static_cast<uint8_t
>(r & 0xFF),
static_cast<uint8_t
>(r >> 8),
354 static_cast<uint8_t
>(g & 0xFF),
static_cast<uint8_t
>(g >> 8),
355 static_cast<uint8_t
>(b & 0xFF),
static_cast<uint8_t
>(b >> 8), 0xFF,
359 const std::array<std::array<uint8_t, 16>, 4> blocks = {
360 {astc_solid_block(0xFFFF, 0, 0), astc_solid_block(0, 0xFFFF, 0),
361 astc_solid_block(0, 0, 0xFFFF),
362 astc_solid_block(0xFFFF, 0xFFFF, 0xFFFF)}};
363 std::vector<uint8_t>
data;
364 for (
const auto& block : blocks) {
365 data.insert(
data.end(), block.begin(), block.end());
382 using VS = MipmapsVertexShader;
383 using FS = MipmapsFragmentShader;
394 auto texture =
context->GetResourceAllocator()->CreateTexture(texture_desc);
398 std::vector<uint8_t> base_data(8 * 8 * 4);
399 for (
int y = 0;
y < 8; ++
y) {
400 for (
int x = 0;
x < 8; ++
x) {
401 const size_t i = (
static_cast<size_t>(
y) * 8 +
x) * 4;
402 const bool right =
x >= 4;
403 const bool bottom =
y >= 4;
404 uint8_t r = 0, g = 0, b = 0;
405 if (!right && !bottom) {
407 }
else if (right && !bottom) {
409 }
else if (!right && bottom) {
415 base_data[
i + 1] = g;
416 base_data[
i + 2] = b;
417 base_data[
i + 3] = 0xFF;
420 ASSERT_TRUE(
texture->SetContents(base_data.data(), base_data.size()));
428 std::vector<uint8_t> mip_data(4 * 4 * 4);
429 for (
size_t i = 0;
i < mip_data.size();
i += 4) {
431 mip_data[
i + 1] = 0x80;
432 mip_data[
i + 2] = 0x00;
433 mip_data[
i + 3] = 0xFF;
435 auto mip_buffer =
context->GetResourceAllocator()->CreateBufferWithCopy(
436 mip_data.data(), mip_data.size());
437 ASSERT_TRUE(mip_buffer);
438 auto cmd_buffer =
context->CreateCommandBuffer();
439 ASSERT_TRUE(cmd_buffer);
440 auto blit_pass = cmd_buffer->CreateBlitPass();
441 ASSERT_TRUE(blit_pass);
447 "Upload mip 1", 1u));
448 ASSERT_TRUE(blit_pass->EncodeCommands());
449 ASSERT_TRUE(
context->GetCommandQueue()->Submit({cmd_buffer}).ok());
452 ASSERT_TRUE(desc.has_value());
454 auto pipeline =
context->GetPipelineLibrary()->GetPipeline(desc).Get();
460 {{-1, -1}, {0.0, 0.0}},
461 {{1, -1}, {1.0, 0.0}},
462 {{1, 1}, {1.0, 1.0}},
463 {{-1, -1}, {0.0, 0.0}},
464 {{1, 1}, {1.0, 1.0}},
465 {{-1, 1}, {0.0, 1.0}},
468 *
context->GetResourceAllocator());
470 const auto& sampler =
context->GetSamplerLibrary()->GetSampler({});
474 context->GetCapabilities()->GetMinimumUniformAlignment());
477 host_buffer->Reset();
478 pass.SetPipeline(pipeline);
479 pass.SetVertexBuffer(vertex_buffer);
481 VS::FrameInfo frame_info;
482 frame_info.mvp = Matrix();
483 VS::BindFrameInfo(pass, host_buffer->EmplaceUniform(frame_info));
485 FS::FragInfo frag_info;
487 FS::BindFragInfo(pass, host_buffer->EmplaceUniform(frag_info));
489 FS::BindTex(pass, texture, sampler);
491 return pass.Draw().ok();
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
static std::shared_ptr< HostBuffer > Create(const std::shared_ptr< Allocator > &allocator, const std::shared_ptr< const IdleWaiter > &idle_waiter, size_t minimum_uniform_alignment, std::shared_ptr< const GpuSubmissionTracker > submission_tracker=nullptr)
bool OpenPlaygroundHere(const RenderCallback &render_callback)
bool InitializePipelineDescriptorForRendering(PipelineDescriptor &desc) const
Initializes the provided |PipelineDescriptor| with appropriate default values to match the conditions...
std::shared_ptr< Context > GetContext() const
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
const Matrix & GetOrthographicTransform() const
virtual void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
virtual void SetInstanceCount(size_t count)
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetElementCount(size_t count)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
VertexBuffer CreateVertexBuffer(HostBuffer &data_host_buffer, HostBuffer &indexes_host_buffer) const
VertexBufferBuilder & AddVertices(std::initializer_list< VertexType_ > vertices)
uint32_t uint32_t * format
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
static void DrawCompressedTextureGolden(RendererGoldenTest &test, PixelFormat format, const std::vector< uint8_t > &block_data, ISize size)
TEST_P(AiksTest, DrawAtlasNoColor)
PlaygroundTestWithGoldens RendererGoldenTest
static void DrawManuallyMippedTextureGolden(RendererGoldenTest &test, float lod)
@ kInstance
The binding is read once per instance.
@ kVertex
The binding is read once per vertex. This is the default.
GlyphAtlasPipeline::VertexShader VS
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
@ kBC
S3TC, RGTC, and BPTC (BC1 through BC7). Desktop GPUs.
@ kETC2
ETC2 and EAC. Mobile, OpenGL ES 3.0, and WebGL2.
@ kASTC
ASTC LDR. Modern mobile and some desktop.
GlyphAtlasPipeline::FragmentShader FS
#define INSTANTIATE_PLAYGROUND_SUITE(playground)
std::shared_ptr< ContextGLES > context
std::shared_ptr< PipelineGLES > pipeline
static constexpr Color Red()
static constexpr Color Blue()
static constexpr Color Green()
static constexpr Matrix MakeScale(const Vector3 &s)
static std::optional< PipelineDescriptor > MakeDefaultPipelineDescriptor(const Context &context, const std::vector< Scalar > &constants={})
Create a default pipeline descriptor using the combination reflected shader information....
static constexpr TRect MakeSize(const TSize< U > &size)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...