Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@bdero
Copy link
Member

@bdero bdero commented Apr 28, 2022

Only affects playgrounds.

Changes the color attribute to vec4 in the shader. On the host, convert ImDrawVerts to ImguiRasterVertexShader::PerVertexData before copying to the device buffer since they no longer map 1-1.

This works around the lack of support for int attributes and bitwise operations in GLSL ES 1.

I added a comment inline describing a possible impellerc-based solution to enable support for color ints that maybe we can try later.

@bdero bdero requested review from chinmaygarde and dnfield April 28, 2022 10:02
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We should update cocoon to recognize this as a test pattern for impeller. Until then we'll need to loop @Hixie for an exemption

// ...as opposed to:
// glVertexAttribPointer(2, 4, GL_FLOAT, false, 16, nullptr);
//
// impellerc could e.g. detect some kind of special naming convention hint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this bit be in an issue instead of a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

vtx_data.reserve(cmd_list->VtxBuffer.size());
for (const auto& v : cmd_list->VtxBuffer) {
const impeller::Scalar kScale = 1.0f / 255.0f;
impeller::Vector4 color(((v.col >> 0) & 0xFF) * kScale, //
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ColorConvertU32ToFloat4 instead. I bet it does exactly the same thing but I see defines in there to check to see if the format is BGRA instead. Good to not have this be tied to RGBA here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


auto draw_list_vtx_bytes =
static_cast<size_t>(cmd_list->VtxBuffer.size_in_bytes());
static_cast<size_t>(vtx_data.size() * sizeof(VS::PerVertexData));
Copy link
Member

@chinmaygarde chinmaygarde Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably (definitely) missing the forest for the trees here but IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT will let you specify a custom layout (you can make it PerVertexData). That way, you can re-order the elements in place without an additional allocation.

Your call on if you want to do this. Probably easier TBH and saves a copy. But this way works too.

Copy link
Member Author

@bdero bdero Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I think for this we would add some padding in the struct and then overwrite col + the extra space in place:

#define IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT \
  struct ImDrawVert {                         \
    ImVec2 pos;                               \
    ImVec2 uv;                                \
    ImU32 col;                                \
    float[3] col_gba;                         \
  };

But I'm not certain it's safe to modify the existing col data in-place to prevent the extra copy?
I'm also slightly biased towards not requiring overrides in imconfig for this backend. If people use Impeller in the future for anything else, it'd be nice if they can just drop it in and it'll magically work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment for the macro seems to indicate that it is. But your approach is safer and the perf differences minimal.

@Hixie
Copy link
Contributor

Hixie commented Apr 28, 2022

test-exempt: code refactor with no semantic change

@Hixie
Copy link
Contributor

Hixie commented Apr 28, 2022

(and also, "is a test")

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants