78 VkDescriptorSetLayout desc_set_layouts[] = {
84 VkPushConstantRange push_constant_range_curve = {
85 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
87 .size = 16*
sizeof(float)
90 VkPushConstantRange push_constant_range_apply = {
91 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
93 .size = 3*
sizeof(float)
97 .setLayoutCount =
LENGTH(desc_set_layouts),
98 .pSetLayouts = desc_set_layouts,
99 .pushConstantRangeCount = 0,
100 .pPushConstantRanges = NULL
105 .setLayoutCount =
LENGTH(desc_set_layouts),
106 .pSetLayouts = desc_set_layouts,
107 .pushConstantRangeCount = 1,
108 .pPushConstantRanges = &push_constant_range_curve
113 .setLayoutCount =
LENGTH(desc_set_layouts),
114 .pSetLayouts = desc_set_layouts,
115 .pushConstantRangeCount = 1,
116 .pPushConstantRanges = &push_constant_range_apply
150 .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
151 .stage =
SHADER_STAGE(QVK_MOD_TONE_MAPPING_HISTOGRAM_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
155 .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
156 .stage =
SHADER_STAGE(QVK_MOD_TONE_MAPPING_CURVE_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
160 .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
161 .stage =
SHADER_STAGE(QVK_MOD_TONE_MAPPING_APPLY_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
178 VkClearColorValue clear_histogram = {
179 .uint32 = { 0, 0, 0, 0 }
185 .size = VK_WHOLE_SIZE,
191 0, VK_WHOLE_SIZE, 0);
196 .size = VK_WHOLE_SIZE,
198 .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT
218 #define BARRIER_COMPUTE(cmd_buf, img) \
220 VkImageSubresourceRange subresource_range = { \
221 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
224 .baseArrayLayer = 0, \
227 IMAGE_BARRIER(cmd_buf, \
229 .subresourceRange = subresource_range, \
230 .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, \
231 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, \
232 .oldLayout = VK_IMAGE_LAYOUT_GENERAL, \
233 .newLayout = VK_IMAGE_LAYOUT_GENERAL, \
249 VkDescriptorSet desc_sets[] = {
259 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
262 vkCmdDispatch(cmd_buf,
270 .size = VK_WHOLE_SIZE,
271 .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
272 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT
279 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
297 float slope_blur_sigma =
Cvar_Get(
"tm_slope_blur_sigma",
"6.0", 0)->value;
298 float push_constants_tm2_curve[16] = {
308 float gaussian_sum = 0.0;
309 for (
int i = 0; i < 14; ++i)
311 float kernel_value = exp(-i * i / (2.0 * slope_blur_sigma * slope_blur_sigma));
312 gaussian_sum += kernel_value * (i == 0 ? 1 : 2);
313 push_constants_tm2_curve[i + 2] = kernel_value;
317 for (
int i = 0; i < 14; ++i) {
318 push_constants_tm2_curve[i + 2] /= gaussian_sum;
322 VK_SHADER_STAGE_COMPUTE_BIT, 0,
sizeof(push_constants_tm2_curve), push_constants_tm2_curve);
324 vkCmdDispatch(cmd_buf, 1, 1, 1);
329 .size = VK_WHOLE_SIZE,
330 .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
331 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT
339 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
364 float knee_start =
Cvar_Get(
"tm_knee_start",
"0.9", 0)->value;
366 float knee_white_point =
Cvar_Get(
"tm_white_point",
"10.0", 0)->value;
374 float knee_w = (knee_start*(knee_start - 2.0) + knee_white_point) / (knee_white_point - 1.0);
375 float knee_a = -knee_start * knee_start;
376 float knee_b = knee_w - 2.0*knee_start;
378 float push_constants_tm2_apply[3] = {
385 VK_SHADER_STAGE_COMPUTE_BIT, 0,
sizeof(push_constants_tm2_apply), push_constants_tm2_apply);
387 vkCmdDispatch(cmd_buf,