Skip to content

Commit

Permalink
"Release 1.60 - October 11th, 2024 - GPU Work Graphs | Filesystem Ref…
Browse files Browse the repository at this point in the history
…actor | Window System Refactor Phase 1"
  • Loading branch information
TFJenkins committed Oct 11, 2024
1 parent 25c57e6 commit b415318
Show file tree
Hide file tree
Showing 685 changed files with 28,508 additions and 26,007 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ Examples_3/Unit_Tests/macOS Xcode/The-Forge/CompiledShaders/
/**/macOS\ Xcode/**/Bin/
/**/macOS\ Xcode/**/build/
**/Xcode_Cache/
**/Xcode_Cache_Sanitizers/
**/BinSanitizers/

# Nuget packages
Tools/ShaderBuildCommand/packages/
Expand Down
4 changes: 2 additions & 2 deletions Common_3/Application/Screenshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ void initScreenshotInterface(Renderer* pRenderer, Queue* pGraphicsQueue)

CmdDesc cmdDesc = {};
cmdDesc.pPool = pCmdPool;
#ifdef ENABLE_GRAPHICS_DEBUG
#ifdef ENABLE_GRAPHICS_DEBUG_ANNOTATION
cmdDesc.pName = "Screenshot Cmd";
#endif // ENABLE_GRAPHICS_DEBUG
#endif // ENABLE_GRAPHICS_DEBUG_ANNOTATION
initCmd(pRenderer, &cmdDesc, &gCmd);

updateUIVisibility();
Expand Down
9 changes: 6 additions & 3 deletions Common_3/Application/ThirdParty/OpenSource/cr/cr.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,12 @@ cr_version_path(const char* basepath, unsigned version, const char* temppath)
(char*)tf_malloc(folderSize + 1 + fnameSize + verSize + 1 + extSize + 1);

char* curr = result;
memcpy(curr, folder2, folderSize);
curr += folderSize;
*(curr++) = '/';
if(folderSize)
{
memcpy(curr, folder2, folderSize);
curr += folderSize;
*(curr++) = '/';
}
memcpy(curr, fname, fnameSize);
curr += fnameSize;
memcpy(curr, version_str, verSize);
Expand Down
1 change: 1 addition & 0 deletions Common_3/Game/Scripting/LuaManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "../../Application/Interfaces/ICameraController.h"
#include "../../Utilities/Interfaces/IFileSystem.h"
#include "../../Utilities/Interfaces/IThread.h"

#include "../../Utilities/Interfaces/IMemory.h"

Expand Down
54 changes: 45 additions & 9 deletions Common_3/Graphics/CommonShaderReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ void addPipelineReflection(ShaderReflection* pReflection, uint32_t stageCount, P
// Combine all shaders
// this will have a large amount of looping
// 1. count number of resources
uint32_t vertexStageIndex = ~0u;
uint32_t hullStageIndex = ~0u;
uint32_t domainStageIndex = ~0u;
uint32_t geometryStageIndex = ~0u;
uint32_t pixelStageIndex = ~0u;
uint32_t vertexStageIndex = UINT32_MAX;
uint32_t hullStageIndex = UINT32_MAX;
uint32_t domainStageIndex = UINT32_MAX;
uint32_t geometryStageIndex = UINT32_MAX;
uint32_t pixelStageIndex = UINT32_MAX;
ShaderResource* pResources = NULL;
ShaderVariable* pVariables = NULL;

Expand All @@ -135,16 +135,21 @@ void addPipelineReflection(ShaderReflection* pReflection, uint32_t stageCount, P
for (uint32_t i = 0; i < stageCount; ++i)
{
ShaderReflection* pSrcRef = pReflection + i;
pOutReflection->mStageReflections[i] = *pSrcRef;
#if defined(DIRECT3D12)
pOutReflection->mResourceHeapIndexing |= pSrcRef->mResourceHeapIndexing;
pOutReflection->mSamplerHeapIndexing |= pSrcRef->mSamplerHeapIndexing;
#endif

if (pSrcRef->mShaderStage == SHADER_STAGE_VERT)
{
vertexStageIndex = i;
pOutReflection->mVertexInputsCount = pSrcRef->mVertexInputsCount;
}
#if !defined(METAL)
else if (pSrcRef->mShaderStage == SHADER_STAGE_HULL)
{
hullStageIndex = i;
pOutReflection->mNumControlPoint = pSrcRef->mNumControlPoint;
}
else if (pSrcRef->mShaderStage == SHADER_STAGE_DOMN)
{
Expand All @@ -158,6 +163,11 @@ void addPipelineReflection(ShaderReflection* pReflection, uint32_t stageCount, P
else if (pSrcRef->mShaderStage == SHADER_STAGE_FRAG)
{
pixelStageIndex = i;
pOutReflection->mOutputRenderTargetTypesMask = pSrcRef->mOutputRenderTargetTypesMask;
}
else if (pSrcRef->mShaderStage == SHADER_STAGE_COMP)
{
memcpy(pOutReflection->mNumThreadsPerGroup, pSrcRef->mNumThreadsPerGroup, sizeof(pSrcRef->mNumThreadsPerGroup));
}

// Loop through all shader resources
Expand Down Expand Up @@ -218,6 +228,27 @@ void addPipelineReflection(ShaderReflection* pReflection, uint32_t stageCount, P
}
}

if (arrlen(pUniqueResources))
{
for (uint32_t i = 0; i < (uint32_t)arrlen(pUniqueResources); ++i)
{
pOutReflection->mNamePoolSize += pUniqueResources[i]->name_size + 1;
}
}
if (arrlen(pUniqueVariable))
{
for (uint32_t i = 0; i < (uint32_t)arrlen(pUniqueVariable); ++i)
{
pOutReflection->mNamePoolSize += pUniqueVariable[i]->name_size + 1;
}
}
if (pOutReflection->mNamePoolSize)
{
pOutReflection->pNamePool = (char*)tf_calloc(pOutReflection->mNamePoolSize, 1);
}

char* namePool = pOutReflection->pNamePool;

// Copy over the shader resources in a dynamic array of the correct size
if (arrlen(pUniqueResources))
{
Expand All @@ -227,6 +258,9 @@ void addPipelineReflection(ShaderReflection* pReflection, uint32_t stageCount, P
{
pResources[i] = *pUniqueResources[i];
pResources[i].used_stages = pShaderUsage[i];
pResources[i].name = namePool;
strncpy(namePool, pUniqueResources[i]->name, pUniqueResources[i]->name_size);
namePool += pUniqueResources[i]->name_size + 1;
}
}

Expand All @@ -238,6 +272,10 @@ void addPipelineReflection(ShaderReflection* pReflection, uint32_t stageCount, P
for (uint32_t i = 0; i < (uint32_t)arrlen(pUniqueVariable); ++i)
{
pVariables[i] = *pUniqueVariable[i];
pVariables[i].name = namePool;
strncpy(namePool, pUniqueVariable[i]->name, pUniqueVariable[i]->name_size);
namePool += pUniqueVariable[i]->name_size + 1;

ShaderResource* parentResource = pUniqueVariableParent[i];
// look for parent
for (uint32_t j = 0; j < (uint32_t)arrlen(pUniqueResources); ++j)
Expand Down Expand Up @@ -279,9 +317,7 @@ void removePipelineReflection(PipelineReflection* pReflection)
if (pReflection == NULL)
return;

for (uint32_t i = 0; i < pReflection->mStageReflectionCount; ++i)
removeShaderReflection(&pReflection->mStageReflections[i]);

tf_free(pReflection->pShaderResources);
tf_free(pReflection->pVariables);
tf_free(pReflection->pNamePool);
}
73 changes: 30 additions & 43 deletions Common_3/Graphics/Direct3D11/Direct3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#define RENDERER_IMPLEMENTATION
#define IID_ARGS IID_PPV_ARGS

#include "../../../Data/Libraries/winpixeventruntime/Include/WinPixEventRuntime/pix3.h"
#include "../../../Common_3/Graphics/ThirdParty/OpenSource/winpixeventruntime/Include/WinPixEventRuntime/pix3.h"
#include "../../Resources/ResourceLoader/ThirdParty/OpenSource/tinyimageformat/tinyimageformat_apis.h"
#include "../../Resources/ResourceLoader/ThirdParty/OpenSource/tinyimageformat/tinyimageformat_base.h"
#include "../../Resources/ResourceLoader/ThirdParty/OpenSource/tinyimageformat/tinyimageformat_query.h"
Expand Down Expand Up @@ -353,7 +353,7 @@ DXGI_FORMAT util_to_dx11_uav_format(DXGI_FORMAT defaultFormat)
case DXGI_FORMAT_R32_FLOAT:
return DXGI_FORMAT_R32_FLOAT;

#if defined(ENABLE_GRAPHICS_DEBUG)
#if defined(ENABLE_GRAPHICS_RUNTIME_CHECK)
case DXGI_FORMAT_R32G8X24_TYPELESS:
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
Expand Down Expand Up @@ -862,19 +862,10 @@ static bool AddDevice(Renderer* pRenderer, const RendererDesc* pDesc)
// Create the actual device
DWORD deviceFlags = 0;

// The D3D debug layer (as well as Microsoft PIX and other graphics debugger
// tools using an injection library) is not compatible with Nsight Aftermath.
// If Aftermath detects that any of these tools are present it will fail initialization.
#if defined(ENABLE_GRAPHICS_DEBUG) && !defined(ENABLE_NSIGHT_AFTERMATH)
#if defined(ENABLE_GRAPHICS_VALIDATION)
deviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

#if defined(ENABLE_NSIGHT_AFTERMATH)
// Enable Nsight Aftermath GPU crash dump creation.
// This needs to be done before the Vulkan device is created.
CreateAftermathTracker(pRenderer->pName, &pRenderer->mAftermathTracker);
#endif

D3D_FEATURE_LEVEL featureLevel;
HRESULT hr = d3d11dll_CreateDevice(pRenderer->pGpu->mDx11.pGpu, D3D_DRIVER_TYPE_UNKNOWN, (HMODULE)0, deviceFlags,
&featureLevels[levelIndex], featureLevelCount, D3D11_SDK_VERSION, &pRenderer->mDx11.pDevice,
Expand Down Expand Up @@ -908,11 +899,7 @@ static bool AddDevice(Renderer* pRenderer, const RendererDesc* pDesc)
LOGF(LogLevel::eINFO, "Device supports ID3D11DeviceContext1.");
}

#if defined(ENABLE_NSIGHT_AFTERMATH)
SetAftermathDevice(pRenderer->mDx11.pDevice);
#endif

#if defined(ENABLE_GRAPHICS_DEBUG)
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
hr = pRenderer->mDx11.pContext->QueryInterface(__uuidof(pRenderer->mDx11.pUserDefinedAnnotation),
(void**)(&pRenderer->mDx11.pUserDefinedAnnotation));
if (FAILED(hr))
Expand All @@ -926,10 +913,12 @@ static bool AddDevice(Renderer* pRenderer, const RendererDesc* pDesc)

static void RemoveDevice(Renderer* pRenderer)
{
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
SAFE_RELEASE(pRenderer->mDx11.pUserDefinedAnnotation);
#endif
SAFE_RELEASE(pRenderer->mDx11.pContext1);
SAFE_RELEASE(pRenderer->mDx11.pContext);
#if defined(ENABLE_GRAPHICS_DEBUG) && !defined(ENABLE_NSIGHT_AFTERMATH)
#if defined(ENABLE_GRAPHICS_VALIDATION)
ID3D11Debug* pDebugDevice = NULL;
pRenderer->mDx11.pDevice->QueryInterface(&pDebugDevice);
SAFE_RELEASE(pRenderer->mDx11.pDevice);
Expand All @@ -947,10 +936,6 @@ static void RemoveDevice(Renderer* pRenderer)
#else
SAFE_RELEASE(pRenderer->mDx11.pDevice);
#endif

#if defined(ENABLE_NSIGHT_AFTERMATH)
DestroyAftermathTracker(&pRenderer->mAftermathTracker);
#endif
}
/************************************************************************/
// Pipeline State Functions
Expand Down Expand Up @@ -983,7 +968,7 @@ static ID3D11BlendState* util_to_blend_state(Renderer* pRenderer, const BlendSta
UNREF_PARAM(pRenderer);

int blendDescIndex = 0;
#if defined(ENABLE_GRAPHICS_DEBUG)
#if defined(ENABLE_GRAPHICS_RUNTIME_CHECK)

for (int i = 0; i < MAX_RENDER_TARGET_ATTACHMENTS; ++i)
{
Expand Down Expand Up @@ -1838,7 +1823,7 @@ void addRenderTarget(Renderer* pRenderer, const RenderTargetDesc* pDesc, RenderT
// Set this by default to be able to sample the rendertarget in shader
textureDesc.mWidth = pDesc->mWidth;
textureDesc.pNativeHandle = pDesc->pNativeHandle;
#if defined(ENABLE_GRAPHICS_DEBUG)
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
textureDesc.pName = pDesc->pName;
#endif
textureDesc.mNodeIndex = pDesc->mNodeIndex;
Expand Down Expand Up @@ -2020,6 +2005,8 @@ void addShaderBinary(Renderer* pRenderer, const BinaryShaderDesc* pDesc, Shader*

uint32_t reflectionCount = 0;

ShaderReflection stageReflections[SHADER_STAGE_COUNT] = {};

for (uint32_t i = 0; i < SHADER_STAGE_COUNT; ++i)
{
ShaderStage stage_mask = (ShaderStage)(1 << i);
Expand Down Expand Up @@ -2086,13 +2073,18 @@ void addShaderBinary(Renderer* pRenderer, const BinaryShaderDesc* pDesc, Shader*
}

d3d11_addShaderReflection((uint8_t*)(pStage->pByteCode), (uint32_t)pStage->mByteCodeSize, stage_mask, //-V522
&pShaderProgram->pReflection->mStageReflections[reflectionCount]);
&stageReflections[reflectionCount]);

reflectionCount++;
}
}

addPipelineReflection(pShaderProgram->pReflection->mStageReflections, reflectionCount, pShaderProgram->pReflection);
addPipelineReflection(stageReflections, reflectionCount, pShaderProgram->pReflection);

for (uint32_t i = 0; i < pShaderProgram->pReflection->mStageReflectionCount; ++i)
{
removeShaderReflection(&stageReflections[i]);
}

*ppShaderProgram = pShaderProgram;
}
Expand Down Expand Up @@ -2787,7 +2779,7 @@ void addRootSignature(Renderer* pRenderer, const RootSignatureDesc* pRootSignatu

if (pReflection->mShaderStages & SHADER_STAGE_VERT)
{
if (pReflection->mStageReflections[pReflection->mVertexStageIndex].mVertexInputsCount)
if (pReflection->mVertexInputsCount)
{
useInputLayout = true;
}
Expand Down Expand Up @@ -3223,7 +3215,7 @@ void addGraphicsPipeline(Renderer* pRenderer, const GraphicsPipelineDesc* pDesc,
case PRIMITIVE_TOPO_PATCH_LIST:
{
const PipelineReflection* pReflection = pDesc->pShaderProgram->pReflection;
uint32_t controlPoint = pReflection->mStageReflections[pReflection->mHullStageIndex].mNumControlPoint;
uint32_t controlPoint = pReflection->mNumControlPoint;
topology = (D3D_PRIMITIVE_TOPOLOGY)(D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + (controlPoint - 1));
}
break;
Expand Down Expand Up @@ -3380,7 +3372,7 @@ void removeDescriptorSet(Renderer* pRenderer, DescriptorSet* pDescriptorSet)
SAFE_FREE(pDescriptorSet);
}

#if defined(ENABLE_GRAPHICS_DEBUG) || defined(PVS_STUDIO)
#if defined(ENABLE_GRAPHICS_RUNTIME_CHECK) || defined(PVS_STUDIO)
#define VALIDATE_DESCRIPTOR(descriptor, msgFmt, ...) \
if (!VERIFYMSG((descriptor), "%s : " msgFmt, __FUNCTION__, ##__VA_ARGS__)) \
{ \
Expand Down Expand Up @@ -4156,13 +4148,6 @@ void queuePresent(Queue* pQueue, const QueuePresentDesc* pDesc)
}
#endif

#if defined(ENABLE_NSIGHT_AFTERMATH)
// DXGI_ERROR error notification is asynchronous to the NVIDIA display
// driver's GPU crash handling. Give the Nsight Aftermath GPU crash dump
// thread some time to do its work before terminating the process.
threadSleep(3000);
#endif

ASSERT(false);
}
}
Expand Down Expand Up @@ -4483,6 +4468,7 @@ void cmdBeginDebugMarker(Cmd* pCmd, float r, float g, float b, const char* pName
UNREF_PARAM(r);
UNREF_PARAM(g);
UNREF_PARAM(b);
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
if (!pCmd->pRenderer->mDx11.pUserDefinedAnnotation)
{
return;
Expand All @@ -4491,33 +4477,34 @@ void cmdBeginDebugMarker(Cmd* pCmd, float r, float g, float b, const char* pName
int nameLen = int(strlen(pName));
MultiByteToWideChar(0, 0, pName, nameLen, markerName, nameLen);
pCmd->pRenderer->mDx11.pUserDefinedAnnotation->BeginEvent(markerName);
#endif
}

void cmdEndDebugMarker(Cmd* pCmd)
{
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
if (!pCmd->pRenderer->mDx11.pUserDefinedAnnotation)
{
return;
}
pCmd->pRenderer->mDx11.pUserDefinedAnnotation->EndEvent();
#endif
}

void cmdAddDebugMarker(Cmd* pCmd, float r, float g, float b, const char* pName)
{
UNREF_PARAM(r);
UNREF_PARAM(g);
UNREF_PARAM(b);
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
if (pCmd->pRenderer->mDx11.pUserDefinedAnnotation)
{
wchar_t markerName[256] = { 0 };
int nameLen = int(strlen(pName));
MultiByteToWideChar(0, 0, pName, nameLen, markerName, nameLen);
pCmd->pRenderer->mDx11.pUserDefinedAnnotation->SetMarker(markerName);
}

#if defined(ENABLE_NSIGHT_AFTERMATH)
SetAftermathMarker(&pCmd->pRenderer->mAftermathTracker, pCmd->pRenderer->mDx11.pContext, pName);
#endif
#endif // ENABLE_GRAPHICS_DEBUG_ANNOTATION
}
/************************************************************************/
// Resource Debug Naming Interface
Expand All @@ -4526,7 +4513,7 @@ void SetResourceName(ID3D11DeviceChild* pResource, const char* pName)
{
UNREF_PARAM(pResource);
UNREF_PARAM(pName);
#if defined(ENABLE_GRAPHICS_DEBUG)
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
if (!pName)
{
return;
Expand All @@ -4540,7 +4527,7 @@ void setBufferName(Renderer* pRenderer, Buffer* pBuffer, const char* pName)
UNREF_PARAM(pRenderer);
UNREF_PARAM(pBuffer);
UNREF_PARAM(pName);
#if defined(ENABLE_GRAPHICS_DEBUG)
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
ASSERT(pRenderer);
ASSERT(pBuffer);
ASSERT(pName);
Expand All @@ -4555,7 +4542,7 @@ void setTextureName(Renderer* pRenderer, Texture* pTexture, const char* pName)
UNREF_PARAM(pRenderer);
UNREF_PARAM(pTexture);
UNREF_PARAM(pName);
#if defined(ENABLE_GRAPHICS_DEBUG)
#if defined(ENABLE_GRAPHICS_DEBUG_ANNOTATION)
ASSERT(pRenderer);
ASSERT(pTexture);
ASSERT(pName);
Expand Down
Loading

0 comments on commit b415318

Please sign in to comment.