Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e6c4b69
Adding HDR texture formats.
dvijayak Jan 15, 2022
b888b8e
Completed HDR prototype! We can now switch between framebuffer format…
dvijayak Mar 4, 2022
dde0734
First pass at getting the shader right for YUV to HDR RGB.
dvijayak Mar 12, 2022
d9774a2
Added support for the 10-bit and higher YUV formats.
dvijayak Mar 14, 2022
727da7f
Fixed bug in 10-bit/16-bit texture format handling.
dvijayak Mar 14, 2022
5848c1a
Cleaned up the HDR yuv-to-rgb math for d3d11/d3d12.
dvijayak Mar 15, 2022
28dd654
The SDR UI is now properly composited on top of HDR video streams. Pe…
dvijayak Mar 21, 2022
aff6605
Added HDR metadata support for rendering quads.
dvijayak Mar 22, 2022
44693ca
Cleanup and refactor.
dvijayak Mar 23, 2022
7e791ab
Swapped in the rec2020 -> rec709 transform that OBS uses and just lik…
dvijayak Mar 25, 2022
ea48c63
Added matoya support for querying if a given window supports HDR. Sti…
dvijayak Mar 25, 2022
8cfe32b
Implemented D3D11 detection of HDR support.
dvijayak Mar 25, 2022
3717a37
Got rid of unnecessary clamping to (-0.5, 7.4999)
dvijayak Mar 30, 2022
16f1877
Fixed bug in HDR support detection that was always checking the prima…
dvijayak Apr 12, 2022
72b5898
HDR support detection now works when the parsec app is moved to diffe…
dvijayak Apr 12, 2022
b84a9a5
We now keep the HDR window's swapchain in HDR10 format (rec2020 10-bi…
dvijayak Mar 31, 2022
ce23da0
Addressed some code review comments.
dvijayak Apr 18, 2022
86de9d6
Added support for textures of format Y410. This is a 10-bit packed 4:…
dvijayak Apr 23, 2022
2eec3ec
Added support for textures of format I444 10-bit. This is a planar 4:…
dvijayak Apr 26, 2022
64203d9
Fixed linker errors for platforms using OpenGL.
dvijayak May 2, 2022
4f4af72
Fixed linker errors for macOS/Metal.
dvijayak May 2, 2022
d692231
Apply suggestions from code review
dvijayak May 9, 2022
ad3b0ef
Addressed some code review comments.
dvijayak May 9, 2022
b6a2dce
Apply suggestions from code review - 2
dvijayak May 9, 2022
0506f61
Addressed more code review comments, including a mem leak fix.
dvijayak May 9, 2022
61684cf
Addressed further review comment. Namely, cleaned up the format/color…
dvijayak May 10, 2022
3577ca6
Updated YUV -> RGB conversion for HDR to include support for full ran…
dvijayak May 13, 2022
b9f3139
Full range vs legal range color conversion can now be specified via a…
dvijayak May 16, 2022
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
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ DEFS = \
-DUNICODE \
-DWIN32_LEAN_AND_MEAN

!IFDEF D3D11_CTX_DEBUG
DEFS = $(DEFS) -DD3D11_CTX_DEBUG
!ENDIF

FXCFLAGS = \
/O3 \
/Ges \
Expand Down
8 changes: 8 additions & 0 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ bool MTY_WindowSetGFX(MTY_App *app, MTY_Window window, MTY_GFX api, bool vsync)
return gfx_ctx ? true : false;
}

bool MTY_WindowIsHDRSupported(MTY_App *app, MTY_Window window)
{
struct gfx_ctx *gfx_ctx = NULL;
MTY_GFX api = mty_window_get_gfx(app, window, &gfx_ctx);

return api != MTY_GFX_NONE && GFX_CTX_API[api].hdr_supported(gfx_ctx);
}


// Event utility

Expand Down
4 changes: 3 additions & 1 deletion src/gfx/mod-ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct gfx_ctx;
bool wrap(api, set_ui_texture)(struct gfx_ctx *gfx_ctx, uint32_t id, const void *rgba, \
uint32_t width, uint32_t height); \
bool wrap(api, has_ui_texture)(struct gfx_ctx *gfx_ctx, uint32_t id); \
bool wrap(api, make_current)(struct gfx_ctx *gfx_ctx, bool current);
bool wrap(api, make_current)(struct gfx_ctx *gfx_ctx, bool current); \
bool wrap(api, hdr_supported)(struct gfx_ctx *gfx_ctx);

#define GFX_CTX_PROTOTYPES(api) \
GFX_CTX_DECLARE_API(api, GFX_CTX_PROTO)
Expand All @@ -49,4 +50,5 @@ struct gfx_ctx;
mty##api##ctx_set_ui_texture, \
mty##api##ctx_has_ui_texture, \
mty##api##ctx_make_current, \
mty##api##ctx_hdr_supported, \
},
96 changes: 68 additions & 28 deletions src/matoya.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,37 @@ typedef enum {

/// @brief Raw image color formats.
typedef enum {
MTY_COLOR_FORMAT_UNKNOWN = 0, ///< Unknown color format.
MTY_COLOR_FORMAT_BGRA = 1, ///< 8-bits per channel BGRA.
MTY_COLOR_FORMAT_NV12 = 2, ///< 4:2:0 full W/H Y plane followed by an interleaved half
///< W/H UV plane.
MTY_COLOR_FORMAT_I420 = 3, ///< 4:2:0 full W/H Y plane followed by a half W/H U plane
///< followed by a half W/H V plane.
MTY_COLOR_FORMAT_I444 = 4, ///< 4:4:4 full W/H consecutive Y, U, V planes.
MTY_COLOR_FORMAT_NV16 = 5, ///< 4:2:2 full W/H Y plane followed by an interleaved half W
///< full H UV plane.
MTY_COLOR_FORMAT_BGR565 = 6, ///< 5-bits blue, 6-bits green, 5-bits red.
MTY_COLOR_FORMAT_BGRA5551 = 7, ///< 5-bits per BGR channels, 1-bit alpha.
MTY_COLOR_FORMAT_AYUV = 8, ///< 4:4:4 full W/H interleaved Y, U, V.
MTY_COLOR_FORMAT_MAKE_32 = INT32_MAX,
MTY_COLOR_FORMAT_UNKNOWN = 0, ///< Unknown color format.
MTY_COLOR_FORMAT_BGRA = 1, ///< 8-bits per channel BGRA.
MTY_COLOR_FORMAT_NV12 = 2, ///< 4:2:0 full W/H Y plane followed by an interleaved half
///< W/H UV plane.
MTY_COLOR_FORMAT_I420 = 3, ///< 4:2:0 full W/H Y plane followed by a half W/H U plane
///< followed by a half W/H V plane.
MTY_COLOR_FORMAT_I444 = 4, ///< 4:4:4 full W/H consecutive Y, U, V planes.
MTY_COLOR_FORMAT_NV16 = 5, ///< 4:2:2 full W/H Y plane followed by an interleaved half W
///< full H UV plane.
MTY_COLOR_FORMAT_BGR565 = 6, ///< 5-bits blue, 6-bits green, 5-bits red.
MTY_COLOR_FORMAT_BGRA5551 = 7, ///< 5-bits per BGR channels, 1-bit alpha.
MTY_COLOR_FORMAT_AYUV = 8, ///< 4:4:4 full W/H interleaved Y, U, V.
MTY_COLOR_FORMAT_Y410 = 9, ///< 4:4:4 full W/H interleaved Y, U, V. 10-bit YUV, 2-bit alpha.
MTY_COLOR_FORMAT_P016 = 10, ///< 4:2:0 full W/H Y plane followed by a half W/H U plane
///< followed by a half W/H V plane. Supports 10-bit to 16-bit data.
MTY_COLOR_FORMAT_I444_10 = 11, ///< 4:4:4 full W/H consecutive Y, U, V planes. Supports 10-bit data.
MTY_COLOR_FORMAT_I444_16 = 12, ///< 4:4:4 full W/H consecutive Y, U, V planes. Supports 16-bit data.
MTY_COLOR_FORMAT_RGB10A2 = 13, ///< 10-bits per RGB channels, 2-bit alpha.
MTY_COLOR_FORMAT_RGBA16F = 14, ///< 16-bits floating-point precision per channel RGBA.
MTY_COLOR_FORMAT_MAKE_32 = INT32_MAX,
} MTY_ColorFormat;

/// @brief Defines the color encoding of the raw image. Note that certain color spaces and color formats are tightly coupled with each other.
typedef enum {
MTY_COLOR_SPACE_UNKNOWN = 0, ///< Unknown color space.
MTY_COLOR_SPACE_SRGB = 1, ///< sRGB/rec709 primaries and a non-linear transfer function (approx gamma curve of 2.2). Supported by all color formats.
MTY_COLOR_SPACE_SCRGB_LINEAR = 2, ///< Microsoft's scRGB wide gamut color space which is based on sRGB/rec709 primaries and has a linear transfer function. Only supported by color format MTY_COLOR_FORMAT_RGBA16F.
MTY_COLOR_SPACE_HDR10 = 3, ///< Uses the rec2020 color primaries and the rec2100 non-linear transfer function (ST 2084 perceptual quantizer, aka PQ). Only supported by color format MTY_COLOR_FORMAT_RGB10A2.
MTY_COLOR_SPACE_MAKE_32 = INT32_MAX,
} MTY_ColorSpace;

/// @brief Quad texture filtering.
typedef enum {
MTY_FILTER_NEAREST = 0, ///< Nearest neighbor filter by the GPU, can cause shimmering.
Expand All @@ -99,23 +115,39 @@ typedef enum {
MTY_ROTATION_MAKE_32 = INT32_MAX,
} MTY_Rotation;

/// @brief HDR metadata associated with an image being rendered.
typedef struct {
float color_primary_red[2]; ///< xy coordinates for the red primary of the image's color space according to the CIE 1931 color space chromaticity diagram.
float color_primary_green[2]; ///< xy coordinates for the green primary of the image's color space according to the CIE 1931 color space chromaticity diagram.
float color_primary_blue[2]; ///< xy coordinates for the blue primary of the image's color space according to the CIE 1931 color space chromaticity diagram.
float white_point[2]; ///< xy coordinates for the white point of the image's color space according to the CIE 1931 color space chromaticity diagram.
float min_luminance; ///< Min luminance supported by the display that is the source of the image.
float max_luminance; ///< Max luminance supported by the display that is the source of the image.
float max_content_light_level; ///< MaxCLL. This is the nit value of the brightest possible pixel that could ever occur in an image. If unknown, you can set it to max_luminance.
float max_frame_average_light_level; ///< MaxFALL. This is the highest nit value that an image's average luminance is expected to have. If unknown, you can set it to MaxCLL.
} MTY_HDRDesc;

/// @brief Description of a render operation.
typedef struct {
MTY_ColorFormat format; ///< The color format of a raw image.
MTY_Rotation rotation; ///< Rotation applied to the image.
MTY_Filter filter; ///< Filter applied to the image.
MTY_Effect effect; ///< Effect applied to the image.
uint32_t imageWidth; ///< The width in pixels of the image.
uint32_t imageHeight; ///< The height in pixels of the image.
uint32_t cropWidth; ///< Desired crop width of the image from the top left corner.
uint32_t cropHeight; ///< Desired crop height of the image from the top left corner.
uint32_t viewWidth; ///< The width of the viewport.
uint32_t viewHeight; ///< The height of the viewport.
float aspectRatio; ///< Desired aspect ratio of the image. The renderer will letterbox
///< the image to maintain the specified aspect ratio.
float scale; ///< Multiplier applied to the dimensions of the image, producing an
///< minimized or magnified image. This can be set to 0
///< if unnecessary.
MTY_ColorFormat format; ///< The color format of a raw image.
MTY_ColorSpace colorspace; ///< Defines the color encoding of the image.
MTY_Rotation rotation; ///< Rotation applied to the image.
MTY_Filter filter; ///< Filter applied to the image.
MTY_Effect effect; ///< Effect applied to the image.
uint32_t imageWidth; ///< The width in pixels of the image.
uint32_t imageHeight; ///< The height in pixels of the image.
uint32_t cropWidth; ///< Desired crop width of the image from the top left corner.
uint32_t cropHeight; ///< Desired crop height of the image from the top left corner.
uint32_t viewWidth; ///< The width of the viewport.
uint32_t viewHeight; ///< The height of the viewport.
float aspectRatio; ///< Desired aspect ratio of the image. The renderer will letterbox
///< the image to maintain the specified aspect ratio.
float scale; ///< Multiplier applied to the dimensions of the image, producing an
///< minimized or magnified image. This can be set to 0
///< if unnecessary.
bool fullRange; ///< If true, then the image components comprise the range [0, 1]; else, they comprise the "partial" or "legal" range based on the format of the image.
bool hdrDescSpecified; ///< Is HDR metadata provided. Only relevant if format + colorspace indicate an HDR image.
MTY_HDRDesc hdrDesc; ///< HDR metadata for the image. Only relevant if format + colorspace indicate an HDR image.
} MTY_RenderDesc;

/// @brief A point with an `x` and `y` coordinate.
Expand Down Expand Up @@ -170,6 +202,7 @@ typedef struct {
uint32_t idxTotalLength; ///< Total number of indices in all command lists.
uint32_t vtxTotalLength; ///< Total number of vertices in all command lists.
bool clear; ///< Surface should be cleared before drawing.
bool hdr; ///< UI in SDR will be composited on top of an HDR quad.
} MTY_DrawData;

/// @brief Create an MTY_Renderer capable of executing drawing commands.
Expand Down Expand Up @@ -1257,6 +1290,13 @@ MTY_WindowSetGFX(MTY_App *app, MTY_Window window, MTY_GFX api, bool vsync);
MTY_EXPORT MTY_ContextState
MTY_WindowGetContextState(MTY_App *app, MTY_Window window);

/// @brief Tells you whether the window can show HDR content or not.
/// @param app The MTY_App.
/// @param window An MTY_Window.
/// @returns Returns true if the window can render HDR content, false otherwise.
MTY_EXPORT bool
MTY_WindowIsHDRSupported(MTY_App *app, MTY_Window window);

/// @brief Get the string representation of a key combination.
/// @details This function attempts to use the current locale.
/// @param mod Combo modifier.
Expand Down
5 changes: 5 additions & 0 deletions src/unix/apple/macosx/gfx/gl-ctx.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,8 @@ bool mty_gl_ctx_make_current(struct gfx_ctx *gfx_ctx, bool current)

return true;
}

bool mty_gl_ctx_hdr_supported(struct gfx_ctx *gfx_ctx)
{
return false;
}
5 changes: 5 additions & 0 deletions src/unix/apple/macosx/gfx/metal-ctx.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,8 @@ bool mty_metal_ctx_make_current(struct gfx_ctx *gfx_ctx, bool current)
{
return false;
}

bool mty_metal_ctx_hdr_supported(struct gfx_ctx *gfx_ctx)
{
return false;
}
5 changes: 5 additions & 0 deletions src/unix/linux/android/gfx/gl-ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,8 @@ bool mty_gl_ctx_make_current(struct gfx_ctx *gfx_ctx, bool current)

return r;
}

bool mty_gl_ctx_hdr_supported(struct gfx_ctx *gfx_ctx)
{
return false;
}
5 changes: 5 additions & 0 deletions src/unix/linux/generic/gfx/gl-ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,8 @@ bool mty_gl_ctx_make_current(struct gfx_ctx *gfx_ctx, bool current)

return r;
}

bool mty_gl_ctx_hdr_supported(struct gfx_ctx *gfx_ctx)
{
return false;
}
5 changes: 5 additions & 0 deletions src/unix/web/gfx/gl-ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ bool mty_gl_ctx_make_current(struct gfx_ctx *gfx_ctx, bool current)
{
return false;
}

bool mty_gl_ctx_hdr_supported(struct gfx_ctx *gfx_ctx)
{
return false;
}
Loading