Skip to content

Conversation

@beaufortfrancois
Copy link
Contributor

This PR adds the "texture-component-swizzle feature" in parallel of gpuweb/gpuweb#5361

Copy link
Collaborator

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

LGTM but let's wait for any bikeshedding to happen in the WG first.

@beaufortfrancois
Copy link
Contributor Author

I believe we're good now.

@kainino0x
Copy link
Collaborator

Thanks. I guess we should still talk about what we want the C API for this to look like since it's not a direct mapping from JS. I'd really like it to be more ergonomic; I'm not sure if there's a good string-based solution but I still don't like the soup of channel identifiers. (I so wish that C 4-character literals like 'rrrr' were something we could use, but they're not really.)

Or we could just not worry about the ergonomics and leave it as is. Actually, there could be a macro based helper if we wanted to keep this structure and also make it ergonomic. But kinda unnecessary.

typedef enum CS { CS_R, CS_G, CS_B, CS_A, CS_0, CS_1 } CS;
typedef struct TCS { CS r, g, b, a; } TCS;
typedef struct TCSD { TCS swizzle; } TCSD;

#define MAKE_TCS(cr, cg, cb, ca) (TCS){ \
    .r = CS_##cr, .g = CS_##cg, .b = CS_##cb, .a = CS_##ca }

int main() {
    TCSD desc = { .swizzle = MAKE_TCS(B, 0, 1, R) };
}

@kainino0x
Copy link
Collaborator

@cwfitzgerald do you have opinions about this?

@cwfitzgerald
Copy link
Collaborator

Not any particular strong feelings, the macro would work for me. We also need docs

@beaufortfrancois
Copy link
Contributor Author

beaufortfrancois commented Oct 15, 2025

I would not worry about the ergonomics. The following code looks good to me.

  wgpu::TextureViewDescriptor viewDesc{};
  wgpu::TextureComponentSwizzleDescriptor swizzleDesc{};
  swizzleDesc.swizzle.r = wgpu::ComponentSwizzle::R;
  swizzleDesc.swizzle.g = wgpu::ComponentSwizzle::Zero;
  swizzleDesc.swizzle.b = wgpu::ComponentSwizzle::Zero;
  swizzleDesc.swizzle.a = wgpu::ComponentSwizzle::One;
  viewDesc.nextInChain = &swizzleDesc;

@Kangz
Copy link
Collaborator

Kangz commented Oct 15, 2025

I agree with @beaufortfrancois , it's fine and too niche to need a fancy ergonomic version. If people want they can make their own macro to do MAKE_SWIZZLE(R, One, Zero, B).

@kainino0x
Copy link
Collaborator

SGTM let's keep as is then.

For docs IMO we just need a very brief explanation of how this maps with the JS API since there's a non-trivial mapping. For the rest people can refer to JS.

@beaufortfrancois beaufortfrancois force-pushed the swizzle branch 3 times, most recently from 94c9364 to 175ea31 Compare October 16, 2025 06:58
@beaufortfrancois
Copy link
Contributor Author

I've added some doc

@beaufortfrancois
Copy link
Contributor Author

beaufortfrancois commented Oct 24, 2025 via email

Copy link
Collaborator

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

Sorry I completely missed your revision somehow!

I do want to avoid duplicating docs into this header but this is fine for now, we can resolve that at a later point when we figure out how to link the docs better.

@kainino0x kainino0x merged commit 706853a into webgpu-native:main Oct 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants