Skip to content

Commit

Permalink
Merge branch 'pkristof/codeCleanup' into 'main'
Browse files Browse the repository at this point in the history
Cleaned up code and shader code formatting

See merge request lightspeedrtx/dxvk-remix-nv!975
  • Loading branch information
pkristof committed Sep 9, 2024
2 parents 34e103e + af6870a commit b86955b
Show file tree
Hide file tree
Showing 60 changed files with 485 additions and 317 deletions.
14 changes: 12 additions & 2 deletions src/dxvk/dxvk_adapter.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 @@ -302,6 +302,10 @@ namespace dxvk {
|| !required.vulkan11Features.shaderDrawParameters)
&& (m_deviceFeatures.vulkan12Features.hostQueryReset
|| !required.vulkan12Features.hostQueryReset)
&& (m_deviceFeatures.vulkan12Features.scalarBlockLayout
|| !required.vulkan12Features.scalarBlockLayout)
&& (m_deviceFeatures.vulkan12Features.uniformBufferStandardLayout
|| !required.vulkan12Features.uniformBufferStandardLayout)
&& (m_deviceFeatures.ext4444Formats.formatA4R4G4B4
|| !required.ext4444Formats.formatA4R4G4B4)
&& (m_deviceFeatures.ext4444Formats.formatA4B4G4R4
Expand Down Expand Up @@ -490,7 +494,9 @@ namespace dxvk {
enabledFeatures.khrAccelerationStructureFeatures.accelerationStructure = m_deviceFeatures.khrAccelerationStructureFeatures.accelerationStructure;
enabledFeatures.khrRayQueryFeatures.rayQuery = m_deviceFeatures.khrRayQueryFeatures.rayQuery;
enabledFeatures.khrDeviceRayTracingPipelineFeatures.rayTracingPipeline = m_deviceFeatures.khrDeviceRayTracingPipelineFeatures.rayTracingPipeline;

enabledFeatures.vulkan12Features.scalarBlockLayout = m_deviceFeatures.vulkan12Features.scalarBlockLayout;
enabledFeatures.vulkan12Features.uniformBufferStandardLayout = m_deviceFeatures.vulkan12Features.uniformBufferStandardLayout;

enabledFeatures.vulkan12Features.shaderInt8 = VK_TRUE;
enabledFeatures.vulkan12Features.storageBuffer8BitAccess = VK_TRUE;
enabledFeatures.vulkan12Features.uniformAndStorageBuffer8BitAccess = VK_TRUE;
Expand Down Expand Up @@ -1200,6 +1206,10 @@ namespace dxvk {
"\n shaderInt64 : ", features.core.features.shaderInt64 ? "1" : "0",
"\n variableMultisampleRate : ", features.core.features.variableMultisampleRate ? "1" : "0",
"\n hostQueryReset : ", features.vulkan12Features.hostQueryReset ? "1" : "0",
// NV-DXVK
"\n scalarBlockLayout : ", features.vulkan12Features.scalarBlockLayout ? "1" : "0",
"\n uniformBufferStandardLayout : ", features.vulkan12Features.uniformBufferStandardLayout ? "1" : "0",
// NV-DXVK end
"\n", VK_EXT_4444_FORMATS_EXTENSION_NAME,
"\n formatA4R4G4B4 : ", features.ext4444Formats.formatA4R4G4B4 ? "1" : "0",
"\n formatA4B4G4R4 : ", features.ext4444Formats.formatA4B4G4R4 ? "1" : "0",
Expand Down
9 changes: 8 additions & 1 deletion src/dxvk/dxvk_buffer.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 @@ -340,6 +340,13 @@ namespace dxvk {
Rc<DxvkBuffer> clone();
// NV-DXVK end


// NV-DXVK start: get access to VkDeviceMemory
const DxvkBufferHandle& getBufferHandle() {
return m_buffer;
}
// NV-DXVK end

protected:
DxvkDevice* m_device;
DxvkBufferCreateInfo m_info;
Expand Down
8 changes: 4 additions & 4 deletions src/dxvk/imgui/dxvk_imgui.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 @@ -297,8 +297,8 @@ namespace dxvk {
{UpscalerType::TAAU, "TAA-U"},
} });

ImGui::ComboWithKey<RussianRouletteMode> secondPlusRussianRouletteModeCombo {
"2nd+ Russian Roulette Mode",
ImGui::ComboWithKey<RussianRouletteMode> secondPlusBounceRussianRouletteModeCombo {
"2nd+ Bounce Russian Roulette Mode",
ImGui::ComboWithKey<RussianRouletteMode>::ComboEntries { {
{RussianRouletteMode::ThroughputBased, "Throughput Based"},
{RussianRouletteMode::SpecularBased, "Specular Based"}
Expand Down Expand Up @@ -2637,7 +2637,7 @@ namespace dxvk {
ImGui::DragFloat("1st bounce: Min Continue Probability", &RtxOptions::Get()->russianRoulette1stBounceMinContinueProbabilityObject(), 0.01f, 0.0f, 1.0f, "%.3f", sliderFlags);
ImGui::DragFloat("1st bounce: Max Continue Probability", &RtxOptions::Get()->russianRoulette1stBounceMaxContinueProbabilityObject(), 0.01f, 0.0f, 1.0f, "%.3f", sliderFlags);

secondPlusRussianRouletteModeCombo.getKey(&RtxOptions::Get()->russianRouletteModeObject());
secondPlusBounceRussianRouletteModeCombo.getKey(&RtxOptions::Get()->russianRouletteModeObject());
if (RtxOptions::Get()->russianRouletteMode() == RussianRouletteMode::ThroughputBased)
{
ImGui::DragFloat("2nd+ bounce: Max Continue Probability", &RtxOptions::Get()->russianRouletteMaxContinueProbabilityObject(), 0.01f, 0.0f, 1.0f, "%.3f", sliderFlags);
Expand Down
10 changes: 6 additions & 4 deletions src/dxvk/rtx_render/rtx_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ namespace dxvk {

const bool isRaytracingEnabled = RtxOptions::Get()->enableRaytracing();

if(isRaytracingEnabled && isCameraValid) {
if (isRaytracingEnabled && isCameraValid) {
if (targetImage == nullptr) {
targetImage = m_state.om.renderTargets.color[0].view->image();
}
Expand All @@ -455,7 +455,7 @@ namespace dxvk {
const bool captureScreenImage = s_triggerScreenshot || (captureTestScreenshot && !s_capturePrePresentTestScreenshot);
const bool captureDebugImage = RtxOptions::Get()->shouldCaptureDebugImage();

if(s_triggerUsdCapture) {
if (s_triggerUsdCapture) {
s_triggerUsdCapture = false;
m_common->capturer()->triggerNewCapture();
}
Expand Down Expand Up @@ -522,6 +522,7 @@ namespace dxvk {
// Path Tracing
dispatchPathTracing(rtOutput);

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

// ReSTIR GI
Expand Down Expand Up @@ -1338,8 +1339,9 @@ namespace dxvk {
denoiseInput.frameTimeMs = frameTimeMilliseconds;
denoiseInput.reset = m_resetHistory;

if(RtxOptions::Get()->useRTXDI() && m_common->metaRtxdiRayQuery().getEnableDenoiserConfidence())
if (RtxOptions::Get()->useRTXDI() && m_common->metaRtxdiRayQuery().getEnableDenoiserConfidence()) {
denoiseInput.confidence = &rtOutput.getCurrentRtxdiConfidence().resource(Resources::AccessType::Read);
}

DxvkDenoise::Output denoiseOutput;
denoiseOutput.diffuse_hitT = &rtOutput.m_primaryDirectDiffuseRadiance.resource(Resources::AccessType::Write);
Expand Down Expand Up @@ -1479,7 +1481,7 @@ namespace dxvk {
// The tone curve shouldn't be too different between raytracing modes,
// but the reset of denoised buffers causes wide tone curve differences
// until it converges and thus making comparison of raytracing mode outputs more difficult
if(RtxOptions::Get()->tonemappingMode() == TonemappingMode::Global) {
if (RtxOptions::Get()->tonemappingMode() == TonemappingMode::Global) {
DxvkToneMapping& toneMapper = m_common->metaToneMapping();
toneMapper.dispatch(this,
getResourceManager().getSampler(VK_FILTER_LINEAR, VK_SAMPLER_MIPMAP_MODE_NEAREST, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER),
Expand Down
21 changes: 11 additions & 10 deletions src/dxvk/rtx_render/rtx_debug_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ namespace dxvk {
{DEBUG_VIEW_NOISY_DEMODULATED_SECONDARY_COMBINED_SPECULAR_RADIANCE,"Secondary Combined Specular: Demodulated Noisy Color"},
{DEBUG_VIEW_DENOISED_SECONDARY_COMBINED_SPECULAR_RADIANCE, "Secondary Combined Specular: Denoised Color"},

{ DEBUG_VIEW_NOISY_PRIMARY_DIRECT_RADIANCE, "Primary Direct: Noisy Color" },
{ DEBUG_VIEW_NOISY_PRIMARY_INDIRECT_RADIANCE, "Primary Indirect: Noisy Color" },
{ DEBUG_VIEW_NOISY_PRIMARY_RADIANCE, "Primary: Noisy Color" },
{ DEBUG_VIEW_NOISY_SECONDARY_DIRECT_RADIANCE, "Secondary Direct: Noisy Color" },
{ DEBUG_VIEW_NOISY_SECONDARY_INDIRECT_RADIANCE, "Secondary Indirect: Noisy Color" },
{ DEBUG_VIEW_NOISY_SECONDARY_RADIANCE, "Secondary: Noisy Color" },
{ DEBUG_VIEW_NOISY_RADIANCE, "Primary + Secondary: Noisy Color" },
{DEBUG_VIEW_NOISY_PRIMARY_DIRECT_RADIANCE, "Primary Direct: Noisy Color" },
{DEBUG_VIEW_NOISY_PRIMARY_INDIRECT_RADIANCE, "Primary Indirect: Noisy Color" },
{DEBUG_VIEW_NOISY_PRIMARY_RADIANCE, "Primary: Noisy Color" },
{DEBUG_VIEW_NOISY_SECONDARY_DIRECT_RADIANCE, "Secondary Direct: Noisy Color" },
{DEBUG_VIEW_NOISY_SECONDARY_INDIRECT_RADIANCE, "Secondary Indirect: Noisy Color" },
{DEBUG_VIEW_NOISY_SECONDARY_RADIANCE, "Secondary: Noisy Color" },
{DEBUG_VIEW_NOISY_RADIANCE, "Primary + Secondary: Noisy Color" },

{DEBUG_VIEW_INSTRUMENTATION_THREAD_DIVERGENCE, "Thread Divergence(Debug Knob.x)"},
{DEBUG_VIEW_NAN, "Inf/NaN Check"},
Expand Down Expand Up @@ -488,7 +488,7 @@ namespace dxvk {
}
}

void DebugView::processOutputStatistics(Rc<DxvkContext>& ctx) {
void DebugView::processOutputStatistics(Rc<RtxContext>& ctx) {

if (m_showOutputStatistics) {
const uint32_t frameIdx = ctx->getDevice()->getCurrentFrameId();
Expand Down Expand Up @@ -853,8 +853,6 @@ namespace dxvk {
ctx->clearColorImage(m_instrumentation.image, clearColor, subRange);
}
}

processOutputStatistics(ctx);
}

DebugViewArgs DebugView::getCommonDebugViewArgs(
Expand Down Expand Up @@ -998,6 +996,9 @@ namespace dxvk {
const Resources::RaytracingOutput& rtOutput) {
ScopedGpuProfileZone(ctx, "Debug View");

// Process output statistics now before we schedule a debug view dispatch that updates them
processOutputStatistics(ctx);

// Inputs

ctx->bindResourceView(DEBUG_VIEW_BINDING_DENOISED_PRIMARY_DIRECT_DIFFUSE_RADIANCE_HIT_T_INPUT, rtOutput.m_primaryDirectDiffuseRadiance.view(Resources::AccessType::Read), nullptr);
Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/rtx_render/rtx_debug_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace dxvk {
virtual void onFrameBegin(Rc<DxvkContext>& ctx, const VkExtent3D& downscaledExtent, const VkExtent3D& targetExtent) override;

private:
void processOutputStatistics(Rc<DxvkContext>& ctx);
void processOutputStatistics(Rc<RtxContext>& ctx);
void showOutputStatistics();
bool shouldDebugViewDispatch() const;
void createConstantsBuffer();
Expand Down
6 changes: 3 additions & 3 deletions src/dxvk/rtx_render/rtx_options.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 @@ -1434,9 +1434,9 @@ namespace dxvk {
// General
bool getCaptureShowMenuOnHotkey() const { return m_captureShowMenuOnHotkey.getValue(); }
bool getCaptureInstances() const {
if(m_captureNoInstance.getValue() != m_captureNoInstance.getDefaultValue()) {
if (m_captureNoInstance.getValue() != m_captureNoInstance.getDefaultValue()) {
Logger::warn("rtx.captureNoInstance has been deprecated, but will still be respected for the time being, unless rtx.captureInstances is set.");
if(m_captureInstances.getValue() != m_captureInstances.getDefaultValue()) {
if (m_captureInstances.getValue() != m_captureInstances.getDefaultValue()) {
return m_captureInstances;
}
return !m_captureNoInstance;
Expand Down
15 changes: 9 additions & 6 deletions src/dxvk/rtx_render/rtx_pathtracer_gbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ namespace dxvk {
}
}

void DxvkPathtracerGbuffer::dispatch(RtxContext* ctx, const Resources::RaytracingOutput& rtOutput) {
void DxvkPathtracerGbuffer::dispatch(
RtxContext* ctx,
const Resources::RaytracingOutput& rtOutput) {
ScopedGpuProfileZone(ctx, "Gbuffer Raytracing");

// Bind resources
Expand Down Expand Up @@ -348,11 +350,12 @@ namespace dxvk {
}
}

DxvkRaytracingPipelineShaders DxvkPathtracerGbuffer::getPipelineShaders(const bool isPSRPass,
const bool useRayQuery,
const bool serEnabled,
const bool ommEnabled,
const bool includePortals) {
DxvkRaytracingPipelineShaders DxvkPathtracerGbuffer::getPipelineShaders(
const bool isPSRPass,
const bool useRayQuery,
const bool serEnabled,
const bool ommEnabled,
const bool includePortals) {
ScopedCpuProfileZone();
DxvkRaytracingPipelineShaders shaders;
if (useRayQuery) {
Expand Down
3 changes: 2 additions & 1 deletion src/dxvk/rtx_render/rtx_pathtracer_integrate_direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ namespace dxvk {

const bool isOpacityMicromapSupported = OpacityMicromapManager::checkIsOpacityMicromapSupported(*m_device);

for (int32_t ommEnabled = isOpacityMicromapSupported; ommEnabled > 0; ommEnabled--)
for (int32_t ommEnabled = isOpacityMicromapSupported; ommEnabled > 0; ommEnabled--) {
pipelineManager.registerRaytracingShaders(getPipelineShaders(true, ommEnabled));
}

DxvkComputePipelineShaders shaders;
shaders.cs = getComputeShader();
Expand Down
13 changes: 7 additions & 6 deletions src/dxvk/rtx_render/rtx_pathtracer_integrate_indirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,13 @@ namespace dxvk {
}
}

DxvkRaytracingPipelineShaders DxvkPathtracerIntegrateIndirect::getPipelineShaders(const bool useRayQuery,
const bool serEnabled,
const bool ommEnabled,
const bool useNeeCache,
const bool includePortals,
const bool pomEnabled) {
DxvkRaytracingPipelineShaders DxvkPathtracerIntegrateIndirect::getPipelineShaders(
const bool useRayQuery,
const bool serEnabled,
const bool ommEnabled,
const bool useNeeCache,
const bool includePortals,
const bool pomEnabled) {

DxvkRaytracingPipelineShaders shaders;
if (useRayQuery) {
Expand Down
55 changes: 31 additions & 24 deletions src/dxvk/shaders/rtx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ void main(uvec2 threadID : SV_DispatchThreadID)
- Delimiter commas (function calls or parameter lists) or semicolons (in for loops) should be followed by a space (or a new line if needed to split across lines).
- Lines should be kept at a reasonable length (100-120 ish characters max typically). Excessively long lines should be split up with newlines.
- Splitting across lines should be done ideally at delimiters or other logical points, for example after each item in a function call, after a bitwise or boolean and/or in a chain of expressions, or even at "important" binary math operators.

- An empty space should be between if/for/while/switch and (.
- Header files should be guarded with #pragma once.
A combined example of these stylistic choices in use is as follows:

```glsl
#pragma once
struct Foo
{
uint fooBarBaz;
Expand All @@ -169,33 +172,37 @@ vec3 exampleHelper(Foo foo, bool test, inout bool specialFlag)
// Do some calculations conditionally
if (foo.anotherFoo > someConstant)
int loopCounter = 2;
while (loopCounter-- > 0)
{
switch (foo.anotherFoo)
if (foo.anotherFoo > someConstant)
{
// Note: Fallthrough to Apple type.
default:
case anotherFooTypeApple:
someExcessivelyLongFunctionNameForDemonstrationPurposes(
foo.anotherBaz + 1.0h,
foo.anotherBaz / 2.0h,
foo.anotherBaz * 5.0h);
break;
case anotherFooTypeOrange:
if (
(foo.fooBarBaz == 26 && foo.anotherBaz == 2.0h) ||
foo.fooBarBaz == 5
)
switch (foo.anotherFoo)
{
const uint someScalar = uint(foo.anotherFoo) * foo.fooBarBaz;
specialFlag = true;
return vec3(float(someScalar));
// Note: Fallthrough to Apple type.
default:
case anotherFooTypeApple:
someExcessivelyLongFunctionNameForDemonstrationPurposes(
foo.anotherBaz + 1.0h,
foo.anotherBaz / 2.0h,
foo.anotherBaz * 5.0h);
break;
case anotherFooTypeOrange:
if (
(foo.fooBarBaz == 26 && foo.anotherBaz == 2.0h) ||
foo.fooBarBaz == 5
)
{
const uint someScalar = uint(foo.anotherFoo) * foo.fooBarBaz;
specialFlag = true;
return vec3(float(someScalar));
}
break;
}
break;
}
}
Expand Down
Loading

0 comments on commit b86955b

Please sign in to comment.