Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GPUSurfaceConfiguration.colorSpace #362

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/articles/Surfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if (!wgpuSurfaceGetCapabilities(mySurface, myAdapter, &caps)) {

// Do things with capabilities
bool canSampleSurface = caps.usages & WGPUTextureUsage_TextureBinding;
WGPUTextureFormat preferredFormat = caps.format[0];
WGPUTextureFormat preferredFormat = caps.formats[0];

bool supportsMailbox = false;
for (size_t i = 0; i < caps.presentModeCount; i++) {
Expand Down
30 changes: 30 additions & 0 deletions webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,28 @@ typedef enum WGPUCallbackMode {
WGPUCallbackMode_Force32 = 0x7FFFFFFF
} WGPUCallbackMode WGPU_ENUM_ATTRIBUTE;

/**
* Predefined sets of color space parameters.
*/
typedef enum WGPUColorSpace {
/**
* `0x00000000`.
* Use the default color space.
*/
WGPUColorSpace_Undefined = 0x00000000,
/**
* `0x00000001`.
* The color space defined by [`srgb`](https://www.w3.org/TR/css-color-4/#predefined-sRGB) in CSS.
*/
WGPUColorSpace_SRGB = 0x00000001,
/**
* `0x00000002`.
* The color space defined by [`display-p3`](https://www.w3.org/TR/css-color-4/#predefined-display-p3) in CSS.
*/
WGPUColorSpace_DisplayP3 = 0x00000002,
WGPUColorSpace_Force32 = 0x7FFFFFFF
} WGPUColorSpace WGPU_ENUM_ATTRIBUTE;

typedef enum WGPUCompareFunction {
WGPUCompareFunction_Undefined = 0x00000000,
WGPUCompareFunction_Never = 0x00000001,
Expand Down Expand Up @@ -1539,6 +1561,14 @@ typedef struct WGPUSurfaceConfiguration {
* When and in which order the surface's frames will be shown on the screen. Defaults to @ref WGPUPresentMode_Fifo.
*/
WGPUPresentMode presentMode;
/**
* Color space to display the surface with.
*
* The only value that implementations are required to support is @ref WGPUColorSpace_Undefined,
* which may be either "unmanaged" or "sRGB".
* Wasm implementations should support @ref WGPUColorSpace_SRGB and @ref WGPUColorSpace_DisplayP3.
*/
WGPUColorSpace colorSpace;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have the surface capabilities reflect the available color spaces?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We talked about this in #200 (comment) but it seemed complex in practice and not necessary yet. On the web we currently just support all three formats with all two color spaces, but in native I don't know if all of those combinations are possible, and certainly new color spaces might not be compatible with all formats or vice versa.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ack

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Approve then? :)
(docs updated)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

filed #366 for both colorspace and tonemapping capabilities

} WGPUSurfaceConfiguration WGPU_STRUCTURE_ATTRIBUTE;

/**
Expand Down
17 changes: 17 additions & 0 deletions webgpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ enums:
Implementations _should_ fire spontaneous callbacks as soon as possible.

@note Because spontaneous callbacks may fire at an arbitrary time on an arbitrary thread, applications should take extra care when acquiring locks or mutating state inside the callback. It undefined behavior to re-entrantly call into the webgpu.h API if the callback fires while inside the callstack of another webgpu.h function that is not `wgpuInstanceWaitAny` or `wgpuInstanceProcessEvents`.
- name: color_space
doc: Predefined sets of color space parameters.
entries:
- name: undefined
doc: Use the default color space.
kainino0x marked this conversation as resolved.
Show resolved Hide resolved
- name: sRGB
doc: The color space defined by [`srgb`](https://www.w3.org/TR/css-color-4/#predefined-sRGB) in CSS.
- name: display_p3
doc: The color space defined by [`display-p3`](https://www.w3.org/TR/css-color-4/#predefined-display-p3) in CSS.
- name: compare_function
doc: |
TODO
Expand Down Expand Up @@ -2699,6 +2708,14 @@ structs:
- name: present_mode
doc: When and in which order the surface's frames will be shown on the screen. Defaults to @ref WGPUPresentMode_Fifo.
type: enum.present_mode
- name: color_space
doc: |
Color space to display the surface with.

The only value that implementations are required to support is @ref WGPUColorSpace_Undefined,
which may be either "unmanaged" or "sRGB".
Wasm implementations should support @ref WGPUColorSpace_SRGB and @ref WGPUColorSpace_DisplayP3.
type: enum.color_space
- name: surface_descriptor
doc: |
The root descriptor for the creation of an @ref WGPUSurface with `::wgpuInstanceCreateSurface`.
Expand Down
Loading