Skip to content

Commit

Permalink
Merge branch 'pkristof/code_tune' into 'main'
Browse files Browse the repository at this point in the history
Code cleanup and improvements

See merge request lightspeedrtx/dxvk-remix-nv!723
  • Loading branch information
pkristof committed Feb 27, 2024
2 parents 9549ee6 + ccc64e1 commit d1e34a1
Show file tree
Hide file tree
Showing 24 changed files with 231 additions and 190 deletions.
22 changes: 18 additions & 4 deletions src/dxvk/dxvk_instance.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace dxvk {
".*? MessageID = 0x534c50ad .*?",

"^.*?Validation Error: .*? You are adding vk.*? to VkCommandBuffer 0x[0-9a-fA-F]+.*? that is invalid because bound Vk[a-zA-Z0-9]+ 0x[0-9a-fA-F]+.*? was destroyed(.*?)?$",

// NV-DXVK start:
// NV SER Extension is not supported by VL
".*?SPIR-V module not valid: Invalid capability operand: 5383$",
".*?vkCreateShaderModule..: A SPIR-V Capability .Unhandled OpCapability. was declared that is not supported by Vulkan. The Vulkan spec states: pCode must not declare any capability that is not supported by the API, as described by the Capabilities section of the SPIR-V Environment appendix.*?",
Expand All @@ -80,12 +80,25 @@ namespace dxvk {

// cmdResetQuery has reset commented out since it hits an AV on initial reset - need to update dxvk that handles resets differently
".*? After query pool creation, each query must be reset before it is used. Queries must also be reset between uses.$",

// VL bug: it thinks we're using VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT when we're not
".*? MessageID = 0x769aa5a9 .*?",

// VL does not know about VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPTICAL_FLOW_FEATURES_NV
".*? MessageID = 0x901f59ec .*?\\(1000464000\\).*?",

// REMIX-2772
".*? vkCmdTraceRaysKHR\\(\\): .*? doesn't set up VK_DYNAMIC_STATE_VIEWPORT\\|VK_DYNAMIC_STATE_SCISSOR\\|VK_DYNAMIC_STATE_STENCIL_REFERENCE, "
"but it calls the related dynamic state setting commands\\. The Vulkan spec states: If a pipeline is bound to the pipeline bind point used by this command, "
"there must not have been any calls to dynamic state setting commands for any state not specified as dynamic in the VkPipeline object bound to the pipeline "
"bind point used by this command, since that pipeline was bound.*?$",

// REMIX-2771
".*? vkCmdCopyImage\\(\\): srcImage.*? was created with VK_IMAGE_USAGE_TRANSFER_DST_BIT\\|VK_IMAGE_USAGE_SAMPLED_BIT\\|VK_IMAGE_USAGE_STORAGE_BIT "
"but requires VK_IMAGE_USAGE_TRANSFER_SRC_BIT\\. The Vulkan spec states: If the aspect member of any element of pRegions includes any flag other than "
"VK_IMAGE_ASPECT_STENCIL_BIT or srcImage was not created with separate stencil usage, VK_IMAGE_USAGE_TRANSFER_SRC_BIT must have been included in the "
"VkImageCreateInfo::usage used to create srcImage.*?$",
// NV-DXVK end
};

for(auto& exp : ignoredErrors) {
Expand Down Expand Up @@ -132,7 +145,8 @@ namespace dxvk {

Logger::err(msgStr);
} else {
Logger::warn(str::format("(waived error) ", msgStr));
// Uncomment to see the waived errors
// Logger::warn(str::format("(waived error) ", msgStr));
}
} else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
if (messageTypes & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) {
Expand Down
8 changes: 4 additions & 4 deletions src/dxvk/dxvk_scoped_annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

#define ScopedGpuProfileZone(ctx, name) \
ScopedCpuProfileZoneN(name); \
TracyVkZone(ctx->getDevice()->queues().graphics.tracyCtx, ctx->getCmdBuffer(DxvkCmdBuffer::ExecBuffer), name); \
TracyVkZone((ctx)->getDevice()->queues().graphics.tracyCtx, (ctx)->getCmdBuffer(DxvkCmdBuffer::ExecBuffer), name); \
__ScopedAnnotation __scopedAnnotation(ctx, name)

#define ScopedGpuProfileZoneQ(device, cmdbuf, queue, name) \
ScopedCpuProfileZoneN(name); \
TracyVkZone(device->queues().queue.tracyCtx, cmdbuf, name); \
TracyVkZone((device)->queues().queue.tracyCtx, cmdbuf, name); \
__ScopedQueueAnnotation __scopedQueueAnnotation(device, cmdbuf, name)

#define ScopedGpuProfileZone_Present(device, cmdbuf, name) \
Expand All @@ -43,11 +43,11 @@
// Note: *Z variants take a C-style null-terminated string, normal variants take something std::string-esque with a data and length member.
#define ScopedCpuProfileZoneDynamic(name) \
ScopedCpuProfileZone(); \
ZoneText(name.data(), name.length());
ZoneText((name).data(), (name).length());
#define ScopedGpuProfileZoneDynamicZ(ctx, name) \
ScopedCpuProfileZone(); \
ZoneText(name, std::strlen(name)); \
TracyVkZoneTransient(ctx->getDevice()->queues().graphics.tracyCtx, TracyConcat(__tracy_gpu_source_location,__LINE__), ctx->getCmdBuffer(DxvkCmdBuffer::ExecBuffer), name, true); \
TracyVkZoneTransient((ctx)->getDevice()->queues().graphics.tracyCtx, TracyConcat(__tracy_gpu_source_location,__LINE__), (ctx)->getCmdBuffer(DxvkCmdBuffer::ExecBuffer), name, true); \
__ScopedAnnotation __scopedAnnotation(ctx, name)
#else
#define ScopedCpuProfileZoneDynamic(ctx, name)
Expand Down
34 changes: 20 additions & 14 deletions src/dxvk/rtx_render/rtx_context.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -439,17 +439,8 @@ namespace dxvk {
// Volumetric Lighting
dispatchVolumetrics(rtOutput);

// Gbuffer Raytracing
m_common->metaPathtracerGbuffer().dispatch(this, rtOutput);

// RTXDI
m_common->metaRtxdiRayQuery().dispatch(this, rtOutput);

// NEE Cache
dispatchNeeCache(rtOutput);

// Integration Raytracing
dispatchIntegrate(rtOutput);
// Path Tracing
dispatchPathTracing(rtOutput);

m_common->metaRtxdiRayQuery().dispatchConfidence(this, rtOutput);

Expand Down Expand Up @@ -869,7 +860,7 @@ namespace dxvk {

constants.terrainArgs = getSceneManager().getTerrainBaker().getTerrainArgs();

constants.thinOpaqueEnable = RtxOptions::SubsurfaceScattering::enableThinOpaque();
constants.enableThinOpaque = RtxOptions::SubsurfaceScattering::enableThinOpaque();

auto& restirGI = m_common->metaReSTIRGIRayQuery();
constants.enableReSTIRGI = restirGI.shouldDispatch();
Expand Down Expand Up @@ -1009,7 +1000,7 @@ namespace dxvk {

writeToBuffer(cb, 0, sizeof(constants), &constants);

m_cmd->trackResource<DxvkAccess::Read>(cb);
m_cmd->trackResource<DxvkAccess::Write>(cb);
}
}

Expand Down Expand Up @@ -1120,6 +1111,21 @@ namespace dxvk {
m_common->metaPathtracerIntegrateIndirect().dispatch(this, rtOutput);
m_common->metaPathtracerIntegrateIndirect().dispatchNEE(this, rtOutput);
}

void RtxContext::dispatchPathTracing(const Resources::RaytracingOutput& rtOutput) {

// Gbuffer Raytracing
m_common->metaPathtracerGbuffer().dispatch(this, rtOutput);

// RTXDI
m_common->metaRtxdiRayQuery().dispatch(this, rtOutput);

// NEE Cache
dispatchNeeCache(rtOutput);

// Integration Raytracing
dispatchIntegrate(rtOutput);
}

void RtxContext::dispatchDemodulate(const Resources::RaytracingOutput& rtOutput) {
ScopedCpuProfileZone();
Expand Down
3 changes: 2 additions & 1 deletion src/dxvk/rtx_render/rtx_context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -155,6 +155,7 @@ namespace dxvk {

void dispatchVolumetrics(const Resources::RaytracingOutput& rtOutput);
void dispatchIntegrate(const Resources::RaytracingOutput& rtOutput);
void dispatchPathTracing(const Resources::RaytracingOutput& rtOutput);
void dispatchDemodulate(const Resources::RaytracingOutput& rtOutput);
void dispatchNeeCache(const Resources::RaytracingOutput& rtOutput);
void dispatchDLSS(const Resources::RaytracingOutput& rtOutput);
Expand Down
7 changes: 5 additions & 2 deletions src/dxvk/rtx_render/rtx_nee_cache.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace dxvk {
return;
}

const auto& numRaysExtent = rtOutput.m_compositeOutputExtent;
const VkExtent3D& numRaysExtent = rtOutput.m_compositeOutputExtent;
VkExtent3D workgroups = util::computeBlockCount(numRaysExtent, VkExtent3D{ 16, 8, 1 });
Rc<DxvkBuffer> primitiveIDPrefixSumBuffer = ctx->getSceneManager().getCurrentFramePrimitiveIDPrefixSumBuffer();
Rc<DxvkBuffer> lastPrimitiveIDPrefixSumBuffer = ctx->getSceneManager().getLastFramePrimitiveIDPrefixSumBuffer();
Expand All @@ -135,6 +135,9 @@ namespace dxvk {
ctx->bindResourceBuffer(UPDATE_NEE_CACHE_BINDING_LAST_PRIMITIVE_ID_PREFIX_SUM, DxvkBufferSlice(lastPrimitiveIDPrefixSumBuffer, 0, lastPrimitiveIDPrefixSumBuffer->info().size));
ctx->bindResourceView(UPDATE_NEE_CACHE_BINDING_NEE_CACHE_THREAD_TASK, rtOutput.m_neeCacheThreadTask.view, nullptr);

// NEE Cache update updates the nee cache based on last frame's record.
// The cache is a world space hash grid storing short light and emissive triangle lists.
// Each frame the integrator generates some records to update the cache in the next frame
ctx->bindShader(VK_SHADER_STAGE_COMPUTE_BIT, UpdateNEECacheShader::getShader());
ctx->dispatch(NEE_CACHE_PROBE_RESOLUTION, NEE_CACHE_PROBE_RESOLUTION/8, NEE_CACHE_PROBE_RESOLUTION);
}
Expand Down
19 changes: 12 additions & 7 deletions src/dxvk/rtx_render/rtx_pathtracer_gbuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -190,6 +190,8 @@ namespace dxvk {
ctx->bindResourceView(GBUFFER_BINDING_SKYPROBE, ctx->getResourceManager().getSkyProbe(ctx).view, nullptr);
ctx->bindResourceSampler(GBUFFER_BINDING_SKYPROBE, linearClampSampler);

// Output resources

ctx->bindResourceView(GBUFFER_BINDING_SHARED_FLAGS_OUTPUT, rtOutput.m_sharedFlags.view, nullptr);
ctx->bindResourceView(GBUFFER_BINDING_SHARED_RADIANCE_RG_OUTPUT, rtOutput.m_sharedRadianceRG.view, nullptr);
ctx->bindResourceView(GBUFFER_BINDING_SHARED_RADIANCE_B_OUTPUT, rtOutput.m_sharedRadianceB.view, nullptr);
Expand Down Expand Up @@ -250,7 +252,7 @@ namespace dxvk {
ctx->bindResourceView(GBUFFER_BINDING_TRANSMISSION_PSR_DATA_STORAGE_2, rtOutput.m_gbufferPSRData[5].view(Resources::AccessType::Write), nullptr);
ctx->bindResourceView(GBUFFER_BINDING_TRANSMISSION_PSR_DATA_STORAGE_3, rtOutput.m_gbufferPSRData[6].view(Resources::AccessType::Write), nullptr);

auto rayDims = rtOutput.m_compositeOutputExtent;
const VkExtent3D& rayDims = rtOutput.m_compositeOutputExtent;

const bool serEnabled = RtxOptions::Get()->isShaderExecutionReorderingInPathtracerGbufferEnabled();
const bool ommEnabled = RtxOptions::Get()->getEnableOpacityMicromap();
Expand Down Expand Up @@ -350,8 +352,9 @@ namespace dxvk {
shaders.addGeneralShader(GET_SHADER_VARIANT(VK_SHADER_STAGE_RAYGEN_BIT_KHR, GbufferRayGenShader, gbuffer_rayquery_raygen));
shaders.debugName = "GBuffer RayQuery (RGS)";
}
}
else {
} else { // TraceRay

// PSR RayGen
if (isPSRPass) {
if (serEnabled) {
shaders.addGeneralShader(GET_SHADER_VARIANT(VK_SHADER_STAGE_RAYGEN_BIT_KHR, GbufferRayGenShader, gbuffer_psr_raygen_ser));
Expand All @@ -361,15 +364,15 @@ namespace dxvk {

shaders.addGeneralShader(GET_SHADER_VARIANT(VK_SHADER_STAGE_MISS_BIT_KHR, GbufferMissShader, gbuffer_psr_miss));

// HitGroup
if (includePortals) {
shaders.addHitGroup(GET_SHADER_VARIANT(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, GbufferClosestHitShader, gbuffer_psr_material_rayportal_closestHit), nullptr, nullptr);
} else {
shaders.addHitGroup(GET_SHADER_VARIANT(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, GbufferClosestHitShader, gbuffer_psr_material_opaque_translucent_closestHit), nullptr, nullptr);
}

shaders.debugName = "GBuffer PSR TraceRay (RGS)";
}
else {
} else { // RayGen
if (serEnabled) {
shaders.addGeneralShader(GET_SHADER_VARIANT(VK_SHADER_STAGE_RAYGEN_BIT_KHR, GbufferRayGenShader, gbuffer_raygen_ser));
} else {
Expand All @@ -378,6 +381,7 @@ namespace dxvk {

shaders.addGeneralShader(GET_SHADER_VARIANT(VK_SHADER_STAGE_MISS_BIT_KHR, GbufferMissShader, gbuffer_miss));

// Hit group
if (includePortals) {
shaders.addHitGroup(GET_SHADER_VARIANT(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, GbufferClosestHitShader, gbuffer_material_rayportal_closestHit), nullptr, nullptr);
} else {
Expand All @@ -388,8 +392,9 @@ namespace dxvk {
}
}

if (ommEnabled)
if (ommEnabled) {
shaders.pipelineFlags |= VK_PIPELINE_CREATE_RAY_TRACING_OPACITY_MICROMAP_BIT_EXT;
}

return shaders;
}
Expand Down
24 changes: 16 additions & 8 deletions src/dxvk/rtx_render/rtx_pathtracer_integrate_direct.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand All @@ -21,7 +21,7 @@
*/
#include "rtx_pathtracer_integrate_direct.h"
#include "dxvk_device.h"
#include "rtx_render/rtx_shader_manager.h"
#include "rtx_shader_manager.h"

#include "rtx/pass/common_binding_indices.h"
#include "rtx/pass/integrate/integrate_direct_binding_indices.h"
Expand Down Expand Up @@ -110,7 +110,9 @@ namespace dxvk {
pipelineManager.createComputePipeline(shaders);
}

void DxvkPathtracerIntegrateDirect::dispatch(RtxContext* ctx, const Resources::RaytracingOutput& rtOutput) {
void DxvkPathtracerIntegrateDirect::dispatch(
RtxContext* ctx,
const Resources::RaytracingOutput& rtOutput) {
ScopedGpuProfileZone(ctx, "Integrate Direct Raytracing");

// Bind resources
Expand All @@ -122,6 +124,8 @@ namespace dxvk {
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_SKYPROBE, ctx->getResourceManager().getSkyProbe(ctx).view, nullptr);
ctx->bindResourceSampler(INTEGRATE_DIRECT_BINDING_SKYPROBE, linearSampler);

// Inputs

ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_SHARED_INTEGRATION_SURFACE_PDF_INPUT, rtOutput.m_sharedIntegrationSurfacePdf.view(Resources::AccessType::Read), nullptr);
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_SHARED_MATERIAL_DATA0_INPUT, rtOutput.m_sharedMaterialData0.view, nullptr);
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_SHARED_MATERIAL_DATA1_INPUT, rtOutput.m_sharedMaterialData1.view, nullptr);
Expand Down Expand Up @@ -150,6 +154,8 @@ namespace dxvk {
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_PRIMARY_BASE_REFLECTIVITY_INPUT_OUTPUT, rtOutput.m_primaryBaseReflectivity.view(Resources::AccessType::ReadWrite), nullptr);
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_SECONDARY_BASE_REFLECTIVITY_INPUT_OUTPUT, rtOutput.m_secondaryBaseReflectivity.view(Resources::AccessType::ReadWrite), nullptr);

// Outputs

ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_PRIMARY_DIRECT_DIFFUSE_LOBE_RADIANCE_OUTPUT, rtOutput.m_primaryDirectDiffuseRadiance.view(Resources::AccessType::Write), nullptr);
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_PRIMARY_DIRECT_SPECULAR_LOBE_RADIANCE_OUTPUT, rtOutput.m_primaryDirectSpecularRadiance.view(Resources::AccessType::Write), nullptr);
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_SECONDARY_COMBINED_DIFFUSE_LOBE_RADIANCE_OUTPUT, rtOutput.m_secondaryCombinedDiffuseRadiance.view(Resources::AccessType::Write), nullptr);
Expand All @@ -168,7 +174,7 @@ namespace dxvk {
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_SECONDARY_POSITION_ERROR_INPUT, rtOutput.m_secondaryPositionError.view(Resources::AccessType::Read), nullptr);
ctx->bindResourceView(INTEGRATE_DIRECT_BINDING_INDIRECT_FIRST_SAMPLED_LOBE_DATA_OUTPUT, rtOutput.m_indirectFirstSampledLobeData.view(Resources::AccessType::Write), nullptr);

const auto rayDims = rtOutput.m_compositeOutputExtent;
const VkExtent3D& rayDims = rtOutput.m_compositeOutputExtent;

const bool ommEnabled = RtxOptions::Get()->getEnableOpacityMicromap();

Expand All @@ -188,19 +194,21 @@ namespace dxvk {
}
}

DxvkRaytracingPipelineShaders DxvkPathtracerIntegrateDirect::getPipelineShaders(const bool useRayQuery,
const bool ommEnabled) {
DxvkRaytracingPipelineShaders DxvkPathtracerIntegrateDirect::getPipelineShaders(
const bool useRayQuery,
const bool ommEnabled) {

DxvkRaytracingPipelineShaders shaders;
if (useRayQuery) {
shaders.addGeneralShader(GET_SHADER_VARIANT(VK_SHADER_STAGE_RAYGEN_BIT_KHR, IntegrateDirectRayGenShader, integrate_direct_rayquery_raygen));
shaders.debugName = "Integrate Direct RayQuery (RGS)";
shaders.addGeneralShader(GET_SHADER_VARIANT(VK_SHADER_STAGE_RAYGEN_BIT_KHR, IntegrateDirectRayGenShader, integrate_direct_rayquery_raygen));
} else {
assert(!"TraceRay versions of the Integrate Direct pass are not implemented.");
}

if (ommEnabled)
if (ommEnabled) {
shaders.pipelineFlags |= VK_PIPELINE_CREATE_RAY_TRACING_OPACITY_MICROMAP_BIT_EXT;
}

return shaders;
}
Expand Down
Loading

0 comments on commit d1e34a1

Please sign in to comment.