rt: pass both positions and "color" to g-buffer

vgpr is up to 57 :(
This commit is contained in:
Ivan Avdeev 2022-01-07 22:43:27 -08:00
parent f85b1b9dc1
commit 4b540d28eb
7 changed files with 45 additions and 4 deletions

View File

@ -11,6 +11,7 @@ layout(set = 0, binding = 2, rgba16f) uniform readonly image2D src_diffuse_gi;
layout(set = 0, binding = 3, rgba16f) uniform readonly image2D src_specular;
layout(set = 0, binding = 4, rgba16f) uniform readonly image2D src_additive;
layout(set = 0, binding = 5, rgba16f) uniform readonly image2D src_normals;
layout(set = 0, binding = 6, rgba32f) uniform readonly image2D src_position_t;
// Blatantly copypasted from https://www.shadertoy.com/view/XsGfWV
vec3 aces_tonemap(vec3 color){
@ -68,7 +69,8 @@ void main() {
const float material_index = imageLoad(src_diffuse_gi, pix).a;
//imageStore(dest, pix, vec4(aces_tonemap(base_color.rgb), 0.)); return;
imageStore(dest, pix, vec4((base_color.rgb), 0.)); return;
//imageStore(dest, pix, vec4((base_color.rgb), 0.)); return;
imageStore(dest, pix, vec4(fract(imageLoad(src_position_t, pix).rgb / 10.), 0.)); return;
//imageStore(dest, pix, vec4((imageLoad(src_diffuse_gi, pix).rgb), 0.)); return;
//imageStore(dest, pix, vec4(aces_tonemap(imageLoad(src_diffuse_gi, pix).rgb), 0.)); return;
//imageStore(dest, pix, vec4(aces_tonemap(imageLoad(src_specular, pix).rgb), 0.)); return;

View File

@ -4,6 +4,8 @@
#include "ray_primary_common.glsl"
layout(set = 0, binding = 0, rgba8) uniform image2D out_image_base_color_r;
layout(set = 0, binding = 6, rgba32f) uniform image2D out_image_position_t;
layout(set = 0, binding = 1) uniform accelerationStructureEXT tlas;
layout(set = 0, binding = 2) uniform UBO {
mat4 inv_proj, inv_view;
@ -28,8 +30,8 @@ void main() {
origin, 0., direction, L,
PAYLOAD_LOCATION_PRIMARY);
//vec4 out_base_color_r = vec4(fract(payload.hit_t.xyz), 0.);
vec4 out_base_color_r = vec4(fract(payload.uv), 0., 0.);
const vec4 out_base_color_r = vec4(fract(payload.uv), 0., 0.);
imageStore(out_image_position_t, ivec2(gl_LaunchIDEXT.xy), payload.hit_t);
imageStore(out_image_base_color_r, ivec2(gl_LaunchIDEXT.xy), out_base_color_r);
}

View File

@ -14,6 +14,8 @@ enum {
DenoiserBinding_Source_Additive = 4,
DenoiserBinding_Source_Normals = 5,
DenoiserBinding_Source_PositionT = 6,
DenoiserBinding_COUNT
};
@ -81,6 +83,13 @@ static void createLayouts( void ) {
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
};
g_denoiser.desc_bindings[DenoiserBinding_Source_PositionT] = (VkDescriptorSetLayoutBinding){
.binding = DenoiserBinding_Source_PositionT,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
};
VK_DescriptorsCreate(&g_denoiser.descriptors);
}
@ -159,6 +168,12 @@ void XVK_DenoiserDenoise( const xvk_denoiser_args_t* args ) {
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
};
g_denoiser.desc_values[DenoiserBinding_Source_PositionT].image = (VkDescriptorImageInfo){
.sampler = VK_NULL_HANDLE,
.imageView = args->src.position_t_view,
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
};
VK_DescriptorsWrite(&g_denoiser.descriptors);
vkCmdBindPipeline(args->cmdbuf, VK_PIPELINE_BIND_POINT_COMPUTE, g_denoiser.pipeline);

View File

@ -17,6 +17,7 @@ typedef struct {
VkImageView specular_view;
VkImageView additive_view;
VkImageView normals_view;
VkImageView position_t_view;
} src;
VkImageView dst_view;

View File

@ -25,6 +25,9 @@ enum {
RtPrim_Desc_Vertices = 5,
//RtPrim_Desc_Textures = 6,
// TODO set 1
RtPrim_Desc_Out_PositionT = 6,
RtPrim_Desc_COUNT
};
@ -66,6 +69,8 @@ static void initDescriptors( void ) {
}
INIT_BINDING(RtPrim_Desc_Out_BaseColorR, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
INIT_BINDING(RtPrim_Desc_Out_PositionT, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
INIT_BINDING(RtPrim_Desc_UBO, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
INIT_BINDING(RtPrim_Desc_TLAS, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
INIT_BINDING(RtPrim_Desc_Kusochki, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR);
@ -228,6 +233,12 @@ static void updateDescriptors( const xvk_ray_trace_primary_t* args ) {
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
};
g_ray_primary.desc.values[RtPrim_Desc_Out_PositionT].image = (VkDescriptorImageInfo){
.sampler = VK_NULL_HANDLE,
.imageView = args->out.position_t,
.imageLayout = VK_IMAGE_LAYOUT_GENERAL,
};
g_ray_primary.desc.values[RtPrim_Desc_TLAS].accel = (VkWriteDescriptorSetAccelerationStructureKHR){
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
.accelerationStructureCount = 1,

View File

@ -19,8 +19,8 @@ typedef struct {
} in;
struct {
VkImageView position_t;
VkImageView base_color_r;
//VkImageView normals;
} out;
} xvk_ray_trace_primary_t;

View File

@ -89,7 +89,11 @@ enum {
typedef struct {
xvk_image_t denoised;
xvk_image_t position_t;
xvk_image_t base_color;
//xvk_image_t rough_metal_trans;
xvk_image_t diffuse_gi;
xvk_image_t specular;
xvk_image_t additive;
@ -925,6 +929,7 @@ static void performTracing( VkCommandBuffer cmdbuf, const vk_ray_frame_render_ar
updateDescriptors(args, current_frame);
#define LIST_GBUFFER_IMAGES(X) \
X(position_t) \
X(base_color) \
X(diffuse_gi) \
X(specular) \
@ -989,6 +994,7 @@ LIST_GBUFFER_IMAGES(GBUFFER_WRITE_BARRIER)
},
},
.out = {
.position_t = current_frame->position_t.view,
.base_color_r = current_frame->base_color.view,
},
};
@ -1042,6 +1048,7 @@ LIST_GBUFFER_IMAGES(GBUFFER_READ_BARRIER)
.width = FRAME_WIDTH,
.height = FRAME_HEIGHT,
.src = {
.position_t_view = current_frame->position_t.view,
.base_color_view = current_frame->base_color.view,
.diffuse_gi_view = current_frame->diffuse_gi.view,
.specular_view = current_frame->specular.view,
@ -1358,6 +1365,8 @@ qboolean VK_RayInit( void )
} while(0)
CREATE_GBUFFER_IMAGE(denoised, VK_FORMAT_R16G16B16A16_SFLOAT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
CREATE_GBUFFER_IMAGE(position_t, VK_FORMAT_R32G32B32A32_SFLOAT, 0);
CREATE_GBUFFER_IMAGE(base_color, VK_FORMAT_R8G8B8A8_UNORM, 0);
CREATE_GBUFFER_IMAGE(diffuse_gi, VK_FORMAT_R16G16B16A16_SFLOAT, 0);
CREATE_GBUFFER_IMAGE(specular, VK_FORMAT_R16G16B16A16_SFLOAT, 0);
@ -1381,6 +1390,7 @@ void VK_RayShutdown( void ) {
for (int i = 0; i < ARRAYSIZE(g_rtx.frames); ++i) {
XVK_ImageDestroy(&g_rtx.frames[i].denoised);
XVK_ImageDestroy(&g_rtx.frames[i].position_t);
XVK_ImageDestroy(&g_rtx.frames[i].base_color);
XVK_ImageDestroy(&g_rtx.frames[i].diffuse_gi);
XVK_ImageDestroy(&g_rtx.frames[i].specular);