MacOS: Enable support for EDR rendering #105662
|
@ -89,16 +89,18 @@ GHOST_ContextCGL::GHOST_ContextCGL(bool stereoVisual,
|
||||||
[m_metalLayer setDevice:metalDevice];
|
[m_metalLayer setDevice:metalDevice];
|
||||||
m_metalLayer.allowsNextDrawableTimeout = NO;
|
m_metalLayer.allowsNextDrawableTimeout = NO;
|
||||||
|
|
||||||
// Enable EDR support. This is done by:
|
if (m_useMetalForRendering) {
|
||||||
// 1. Using a floating point render target, so that values ouside 0..1 can be used
|
// Enable EDR support. This is done by:
|
||||||
// 2. Informing the OS that we are EDR aware, and intend to use values outside 0..1
|
// 1. Using a floating point render target, so that values ouside 0..1 can be used
|
||||||
// 3. Setting the extended sRGB color space so tha the OS knows how to interpret the values
|
// 2. Informing the OS that we are EDR aware, and intend to use values outside 0..1
|
||||||
m_metalLayer.wantsExtendedDynamicRangeContent = YES;
|
// 3. Setting the extended sRGB color space so that the OS knows how to interpret the values
|
||||||
m_metalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
|
m_metalLayer.wantsExtendedDynamicRangeContent = YES;
|
||||||
const CFStringRef name = kCGColorSpaceExtendedSRGB;
|
m_metalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
|
||||||
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(name);
|
const CFStringRef name = kCGColorSpaceExtendedSRGB;
|
||||||
m_metalLayer.colorspace = colorspace;
|
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(name);
|
||||||
CGColorSpaceRelease(colorspace);
|
m_metalLayer.colorspace = colorspace;
|
||||||
|
CGColorSpaceRelease(colorspace);
|
||||||
|
}
|
||||||
|
|
||||||
metalInit();
|
metalInit();
|
||||||
}
|
}
|
||||||
|
@ -530,8 +532,9 @@ GHOST_TSuccess GHOST_ContextCGL::releaseNativeHandles()
|
||||||
*
|
*
|
||||||
* Use Metal layer to avoid Viewport lagging on macOS, see #60043. */
|
* Use Metal layer to avoid Viewport lagging on macOS, see #60043. */
|
||||||
|
|
||||||
static const MTLPixelFormat METAL_FRAMEBUFFERPIXEL_FORMAT = MTLPixelFormatRGBA16Float;
|
static const MTLPixelFormat METAL_FRAMEBUFFERPIXEL_FORMAT_EDR = MTLPixelFormatRGBA16Float;
|
||||||
static const OSType METAL_CORE_VIDEO_PIXEL_FORMAT = kCVPixelFormatType_32BGRA;
|
static const MTLPixelFormat METAL_FRAMEBUFFERPIXEL_FORMAT_SDR = MTLPixelFormatBGRA8Unorm;
|
||||||
|
static const OSType METAL_CORE_VIDEO_PIXEL_FORMAT_SDR = kCVPixelFormatType_32BGRA;
|
||||||
|
|
||||||
void GHOST_ContextCGL::metalInit()
|
void GHOST_ContextCGL::metalInit()
|
||||||
{
|
{
|
||||||
|
@ -598,7 +601,9 @@ void GHOST_ContextCGL::metalInit()
|
||||||
/* Ensure library is released. */
|
/* Ensure library is released. */
|
||||||
[library autorelease];
|
[library autorelease];
|
||||||
|
|
||||||
[desc.colorAttachments objectAtIndexedSubscript:0].pixelFormat = METAL_FRAMEBUFFERPIXEL_FORMAT;
|
MTLPixelFormat attachmentFormat = m_useMetalForRendering ?
|
||||||
|
METAL_FRAMEBUFFERPIXEL_FORMAT_EDR : METAL_FRAMEBUFFERPIXEL_FORMAT_SDR;
|
||||||
|
[desc.colorAttachments objectAtIndexedSubscript:0].pixelFormat = attachmentFormat;
|
||||||
|
|
||||||
m_metalRenderPipeline = (MTLRenderPipelineState *)[device
|
m_metalRenderPipeline = (MTLRenderPipelineState *)[device
|
||||||
newRenderPipelineStateWithDescriptor:desc
|
newRenderPipelineStateWithDescriptor:desc
|
||||||
|
@ -698,7 +703,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer()
|
||||||
CVReturn cvret = CVPixelBufferCreate(kCFAllocatorDefault,
|
CVReturn cvret = CVPixelBufferCreate(kCFAllocatorDefault,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
METAL_CORE_VIDEO_PIXEL_FORMAT,
|
METAL_CORE_VIDEO_PIXEL_FORMAT_SDR,
|
||||||
(__bridge CFDictionaryRef)cvPixelBufferProps,
|
(__bridge CFDictionaryRef)cvPixelBufferProps,
|
||||||
&cvPixelBuffer);
|
&cvPixelBuffer);
|
||||||
if (cvret != kCVReturnSuccess) {
|
if (cvret != kCVReturnSuccess) {
|
||||||
|
@ -740,7 +745,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer()
|
||||||
cvMetalTexCache,
|
cvMetalTexCache,
|
||||||
cvPixelBuffer,
|
cvPixelBuffer,
|
||||||
nil,
|
nil,
|
||||||
METAL_FRAMEBUFFERPIXEL_FORMAT,
|
METAL_FRAMEBUFFERPIXEL_FORMAT_SDR,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -344,16 +344,18 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa,
|
||||||
[m_metalLayer removeAllAnimations];
|
[m_metalLayer removeAllAnimations];
|
||||||
[m_metalLayer setDevice:metalDevice];
|
[m_metalLayer setDevice:metalDevice];
|
||||||
|
|
||||||
// Enable EDR support. This is done by:
|
if (type == GHOST_kDrawingContextTypeMetal) {
|
||||||
// 1. Using a floating point render target, so that values ouside 0..1 can be used
|
// Enable EDR support. This is done by:
|
||||||
// 2. Informing the OS that we are EDR aware, and intend to use values outside 0..1
|
// 1. Using a floating point render target, so that values ouside 0..1 can be used
|
||||||
// 3. Setting the extended sRGB color space so tha the OS knows how to interpret the values
|
// 2. Informing the OS that we are EDR aware, and intend to use values outside 0..1
|
||||||
m_metalLayer.wantsExtendedDynamicRangeContent = YES;
|
// 3. Setting the extended sRGB color space so that the OS knows how to interpret the values
|
||||||
m_metalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
|
m_metalLayer.wantsExtendedDynamicRangeContent = YES;
|
||||||
const CFStringRef name = kCGColorSpaceExtendedSRGB;
|
m_metalLayer.pixelFormat = MTLPixelFormatRGBA16Float;
|
||||||
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(name);
|
const CFStringRef name = kCGColorSpaceExtendedSRGB;
|
||||||
m_metalLayer.colorspace = colorspace;
|
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(name);
|
||||||
CGColorSpaceRelease(colorspace);
|
m_metalLayer.colorspace = colorspace;
|
||||||
|
CGColorSpaceRelease(colorspace);
|
||||||
|
}
|
||||||
|
|
||||||
m_metalView = [[CocoaMetalView alloc] initWithFrame:rect];
|
m_metalView = [[CocoaMetalView alloc] initWithFrame:rect];
|
||||||
[m_metalView setWantsLayer:YES];
|
[m_metalView setWantsLayer:YES];
|
||||||
|
|
Loading…
Reference in New Issue