rendervulkan: Implement CTM

This commit is contained in:
Joshua Ashton 2023-10-25 04:02:55 +01:00
parent 039caccfea
commit 06532b071c
10 changed files with 36 additions and 13 deletions

View file

@ -3280,11 +3280,13 @@ float g_flInternalDisplayBrightnessNits = 500.0f;
float g_flHDRItmSdrNits = 100.f;
float g_flHDRItmTargetNits = 1000.f;
#pragma pack(push, 1)
struct BlitPushData_t
{
vec2_t scale[k_nMaxLayers];
vec2_t offset[k_nMaxLayers];
float opacity[k_nMaxLayers];
glm::mat3x4 ctm[k_nMaxLayers];
uint32_t borderMask;
uint32_t frameId;
uint32_t blurRadius;
@ -3309,7 +3311,21 @@ struct BlitPushData_t
else
u_shaderFilter[i] = (uint32_t)layer->filter;
if (layer->ctm)
{
ctm[i] = layer->ctm->matrix;
}
else
{
ctm[i] = glm::mat3x4
{
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0
};
}
}
borderMask = frameInfo->borderMask();
frameId = s_frameId++;
blurRadius = frameInfo->blurRadius ? ( frameInfo->blurRadius * 2 ) - 1 : 0;
@ -3340,16 +3356,16 @@ struct CaptureConvertBlitData_t
vec2_t scale[1];
vec2_t offset[1];
float opacity[1];
mat3x4 ctm[1];
uint32_t borderMask;
uint32_t halfExtent[2];
mat3x4 colorMatrix;
explicit CaptureConvertBlitData_t(float blit_scale, const mat3x4 &color_matrix) {
scale[0] = { blit_scale, blit_scale };
offset[0] = { 0.0f, 0.0f };
opacity[0] = 1.0f;
borderMask = 0;
colorMatrix = color_matrix;
ctm[0] = color_matrix;
}
};
@ -3385,6 +3401,7 @@ struct RcasPushData_t
vec2_t u_scale[k_nMaxLayers - 1];
vec2_t u_offset[k_nMaxLayers - 1];
float u_opacity[k_nMaxLayers];
glm::mat3x4 ctm[k_nMaxLayers];
uint32_t u_borderMask;
uint32_t u_frameId;
uint32_t u_c1;
@ -3439,6 +3456,7 @@ struct NisPushData_t
tempX, tempY);
}
};
#pragma pack(pop)
void bind_all_layers(CVulkanCmdBuffer* cmdBuffer, const struct FrameInfo_t *frameInfo)
{

View file

@ -1,8 +1,9 @@
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform layers_t {
vec2 u_scale[VKR_MAX_LAYERS];
vec2 u_offset[VKR_MAX_LAYERS];
float u_opacity[VKR_MAX_LAYERS];
mat3x4 u_ctm[VKR_MAX_LAYERS];
uint u_borderMask;
uint u_frameId;
uint u_blur_radius;

View file

@ -171,6 +171,7 @@ vec4 sampleLayerEx(sampler2D layerSampler, uint offsetLayerIdx, uint colorspaceL
else {
color = sampleRegular(layerSampler, coord, colorspace);
}
color.rgb = color.rgba * u_ctm[offsetLayerIdx];
color.rgb = apply_layer_color_mgmt(color.rgb, colorspace);
return color;

View file

@ -11,12 +11,13 @@ layout(
local_size_y = 1,
local_size_z = 1) in;
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform layers_t {
uvec2 u_layer0Offset;
vec2 u_scale[VKR_MAX_LAYERS - 1];
vec2 u_offset[VKR_MAX_LAYERS - 1];
float u_opacity[VKR_MAX_LAYERS];
mat3x4 u_ctm[VKR_MAX_LAYERS];
uint u_borderMask;
uint u_frameId;
uint u_c1;
@ -72,6 +73,7 @@ void rcasComposite(uvec2 pos)
}
outputValue.rgb = colorspace_plane_degamma_tf(outputValue.rgb, colorspace);
outputValue.rgb = (vec4(outputValue.rgb, 1.0f) * u_ctm[0]).rgb;
outputValue.rgb = apply_layer_color_mgmt(outputValue.rgb, colorspace);
outputValue *= u_opacity[0];
}

View file

@ -11,7 +11,7 @@ layout(
local_size_y = 1,
local_size_z = 1) in;
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform layers_t {
uvec4 c1, c2, c3, c4;
};

View file

@ -12,7 +12,7 @@ layout(
local_size_y = 1,
local_size_z = 1) in;
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform layers_t {
uvec4 c1, c2, c3, c4;
};

View file

@ -11,11 +11,12 @@ layout(
local_size_y = 8,
local_size_z = 1) in;
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform layers_t {
vec2 u_scale[VKR_MAX_LAYERS];
vec2 u_offset[VKR_MAX_LAYERS];
float u_opacity[VKR_MAX_LAYERS];
mat3x4 u_ctm[VKR_MAX_LAYERS];
uint u_borderMask;
uint u_frameId;
uint u_blur_radius;

View file

@ -9,7 +9,7 @@
#include "descriptor_set.h"
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform const_buffer
{
float kDetectRatio;

View file

@ -11,7 +11,7 @@
#include "descriptor_set.h"
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform const_buffer
{
float kDetectRatio;

View file

@ -23,14 +23,14 @@ const float u_nitsToLinear = 1.0f / 100.0f;
const float u_itmSdrNits = 100.f;
const float u_itmTargetNits = 1000.f;
layout(binding = 0, std430)
layout(binding = 0, scalar)
uniform layers_t {
vec2 u_scale[1];
vec2 u_offset[1];
float u_opacity[1];
mat3x4 u_ctm[1];
uint u_borderMask;
uvec2 u_halfExtent;
mat3x4 u_colorMatrix;
};
#include "composite.h"
@ -63,11 +63,11 @@ void main() {
};
vec3 avg_color = (color[0] + color[1] + color[2] + color[3]) / 4.0f;
vec2 uv = applyColorMatrix(avg_color, u_colorMatrix).yz;
vec2 uv = applyColorMatrix(avg_color, u_ctm[0]).yz;
imageStore(dst_chroma, chroma_uv, vec4(uv, 0.0f, 1.0f));
for (int i = 0; i < 4; i++) {
float y = applyColorMatrix(color[i], u_colorMatrix).x;
float y = applyColorMatrix(color[i], u_ctm[0]).x;
imageStore(dst_luma, luma_uv + offset_table[i], vec4(y, 0.0f, 0.0f, 1.0f));
}
}