mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-17 19:23:51 +02:00
IES profile support and fixed numerous editor crashes.
This commit is contained in:
@@ -373,6 +373,7 @@ void QD3D12_SetCameraInfo(
|
||||
static void QD3D12_CreateUploadRingForWindow(struct QD3D12Window& w);
|
||||
static void QD3D12_DestroyUploadRingForWindow(struct QD3D12Window& w);
|
||||
static void QD3D12_SubmitOpenFrameNoPresentAndWait();
|
||||
static void QD3D12_WaitForGPU();
|
||||
static void QD3D12_EnsureFrameOpen();
|
||||
static void QD3D12_RunUpscalerOrBlit(QD3D12Window& w);
|
||||
static void QD3D12_ExecuteMainCommandListAndWait(QD3D12Window& w);
|
||||
@@ -664,7 +665,7 @@ static void QD3D12_InvalidateTextureMipChain(TextureResource& tex, bool invalida
|
||||
static bool QD3D12_TextureHasNeuralPOMData(const TextureResource& tex);
|
||||
static bool QD3D12_UploadNeuralPOM(TextureResource& tex);
|
||||
static void EnsureTextureResource(TextureResource& tex);
|
||||
static void UploadTexture(TextureResource& tex);
|
||||
static void UploadTexture(TextureResource& tex, ID3D12GraphicsCommandList* commandList = nullptr);
|
||||
static UINT QD3D12_NeuralPOMFallbackSrvIndex();
|
||||
static void QD3D12_CreateNeuralPOMZeroBuffer();
|
||||
|
||||
@@ -1336,17 +1337,6 @@ struct QD3D12Window* AllocD3D12Window() {
|
||||
return new QD3D12Window();
|
||||
}
|
||||
|
||||
void FreeD3D12Window(struct QD3D12Window* wnd) {
|
||||
if (wnd)
|
||||
{
|
||||
QD3D12_DestroyUploadRingForWindow(*wnd);
|
||||
QD3D12_UnregisterWindowDC(wnd->hdc);
|
||||
if (wnd->ownsHdc && wnd->hwnd && wnd->hdc)
|
||||
ReleaseDC(wnd->hwnd, wnd->hdc);
|
||||
}
|
||||
delete wnd;
|
||||
}
|
||||
|
||||
struct ImmediateVertexBuffer
|
||||
{
|
||||
std::vector<GLVertex> storage;
|
||||
@@ -1514,7 +1504,7 @@ struct GLState
|
||||
bool enableRayAIDenoise = false;
|
||||
bool enableDLSSRayReconstruction = false;
|
||||
bool enableFSRRayRegeneration = false;
|
||||
uint32_t frameGenerationMultiplier = 2;
|
||||
uint32_t frameGenerationMultiplier = 0;
|
||||
uint32_t pathTracingSamplesPerPixel = 1;
|
||||
uint32_t pathTracingFallbackSamplesPerPixel = 2;
|
||||
uint32_t pathTracingMaxBounces = 2;
|
||||
@@ -1850,6 +1840,24 @@ static void QD3D12_MatrixMultiplyCM(const float* a, const float* b, float* out)
|
||||
memcpy(out, r, sizeof(r));
|
||||
}
|
||||
|
||||
void FreeD3D12Window(struct QD3D12Window* wnd) {
|
||||
if (wnd)
|
||||
{
|
||||
if ((g_gl.frameOpen && g_gl.frameOwner == wnd) || g_currentWindow == wnd)
|
||||
QD3D12_SubmitOpenFrameNoPresentAndWait();
|
||||
if (g_currentWindow == wnd)
|
||||
g_currentWindow = nullptr;
|
||||
if (g_gl.device && g_gl.queue && g_gl.fence)
|
||||
QD3D12_WaitForGPU();
|
||||
QD3D12_DestroyUploadRingForWindow(*wnd);
|
||||
QD3D12_UnregisterWindowDC(wnd->hdc);
|
||||
if (wnd->ownsHdc && wnd->hwnd && wnd->hdc)
|
||||
ReleaseDC(wnd->hwnd, wnd->hdc);
|
||||
}
|
||||
delete wnd;
|
||||
}
|
||||
|
||||
|
||||
static bool QD3D12_MatrixInvertCM(const float* m, float* out)
|
||||
{
|
||||
if (!QD3D12_MatrixFinite(m) || !out)
|
||||
@@ -2583,6 +2591,32 @@ static TextureResource* QD3D12_FindTextureResource(GLuint id)
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
ID3D12Resource* QD3D12_GetTextureResource(GLuint texture, DXGI_FORMAT* format, UINT* width, UINT* height, ID3D12GraphicsCommandList* commandList)
|
||||
{
|
||||
TextureResource* tex = QD3D12_FindTextureResource(texture);
|
||||
if (!tex)
|
||||
return nullptr;
|
||||
|
||||
EnsureTextureResource(*tex);
|
||||
if (!tex->texture)
|
||||
return nullptr;
|
||||
|
||||
if (!tex->gpuValid && commandList)
|
||||
UploadTexture(*tex, commandList);
|
||||
|
||||
if (!tex->gpuValid)
|
||||
return nullptr;
|
||||
|
||||
if (format)
|
||||
*format = tex->dxgiFormat;
|
||||
if (width)
|
||||
*width = (UINT)tex->width;
|
||||
if (height)
|
||||
*height = (UINT)tex->height;
|
||||
|
||||
return tex->texture.Get();
|
||||
}
|
||||
|
||||
static TextureResource& QD3D12_EnsureTextureName(GLuint id)
|
||||
{
|
||||
auto it = g_gl.textures.find(id);
|
||||
@@ -6842,6 +6876,11 @@ static float QD3D12_QualityRatio(QD3D12UpscalerQuality quality)
|
||||
}
|
||||
}
|
||||
|
||||
static bool QD3D12_IsEmbeddedEditorWindow(const QD3D12Window& w)
|
||||
{
|
||||
return w.hwnd && GetParent(w.hwnd) != nullptr;
|
||||
}
|
||||
|
||||
#if defined(QD3D12_ENABLE_STREAMLINE)
|
||||
struct QD3D12StreamlineState
|
||||
{
|
||||
@@ -7169,6 +7208,7 @@ static bool QD3D12_WantsDLSSRayReconstruction()
|
||||
static bool QD3D12_CanUseDLSSRayReconstructionForLighting(const QD3D12Window& w)
|
||||
{
|
||||
return !w.isPbuffer &&
|
||||
!QD3D12_IsEmbeddedEditorWindow(w) &&
|
||||
g_gl.cameraState.valid &&
|
||||
QD3D12_WantsDLSSRayReconstruction();
|
||||
}
|
||||
@@ -7255,6 +7295,7 @@ static bool QD3D12_WantsDLSSFrameGeneration(const QD3D12Window& w)
|
||||
{
|
||||
return
|
||||
!w.isPbuffer &&
|
||||
!QD3D12_IsEmbeddedEditorWindow(w) &&
|
||||
g_gl.cameraState.valid &&
|
||||
g_qd3d12Sl.deviceBound &&
|
||||
g_qd3d12Sl.dlssGSupported &&
|
||||
@@ -7271,6 +7312,8 @@ static uint32_t QD3D12_GetDLSSFrameGenerationEligibilityMask(const QD3D12Window&
|
||||
uint32_t mask = 0;
|
||||
if (w.isPbuffer)
|
||||
mask |= 1u << 0;
|
||||
if (QD3D12_IsEmbeddedEditorWindow(w))
|
||||
mask |= 1u << 8;
|
||||
if (!g_gl.cameraState.valid)
|
||||
mask |= 1u << 1;
|
||||
if (!g_qd3d12Sl.deviceBound)
|
||||
@@ -7301,9 +7344,10 @@ static void QD3D12_LogDLSSFrameGenerationEligibility(const QD3D12Window& w, uint
|
||||
}
|
||||
|
||||
QD3D12_Log(
|
||||
"DLSS_G inactive: r_frameGen=%u, pbuffer=%d, camera=%d, deviceBound=%d, dlssG=%d, reflex=%d, resources=%d.",
|
||||
"DLSS_G inactive: r_frameGen=%u, pbuffer=%d, embedded=%d, camera=%d, deviceBound=%d, dlssG=%d, reflex=%d, resources=%d.",
|
||||
g_gl.frameGenerationMultiplier,
|
||||
w.isPbuffer ? 1 : 0,
|
||||
QD3D12_IsEmbeddedEditorWindow(w) ? 1 : 0,
|
||||
g_gl.cameraState.valid ? 1 : 0,
|
||||
g_qd3d12Sl.deviceBound ? 1 : 0,
|
||||
(g_qd3d12Sl.dlssGSupported && g_qd3d12Sl.dlssGFeatureLoaded) ? 1 : 0,
|
||||
@@ -11466,11 +11510,15 @@ static void QD3D12_ProcessCompletedTextureMipJobs(UINT maxUploads)
|
||||
}
|
||||
}
|
||||
|
||||
static void UploadTexture(TextureResource& tex)
|
||||
static void UploadTexture(TextureResource& tex, ID3D12GraphicsCommandList* commandList)
|
||||
{
|
||||
if (!tex.texture)
|
||||
return;
|
||||
|
||||
ID3D12GraphicsCommandList* cl = commandList ? commandList : g_gl.cmdList.Get();
|
||||
if (!cl)
|
||||
return;
|
||||
|
||||
if (tex.compressed)
|
||||
{
|
||||
const UINT blockBytes = tex.compressedBlockBytes ? tex.compressedBlockBytes : QD3D12_CompressedTextureBlockBytes(tex.compressedInternalFormat);
|
||||
@@ -11513,7 +11561,7 @@ static void UploadTexture(TextureResource& tex)
|
||||
toCopy.Transition.StateBefore = tex.state;
|
||||
toCopy.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toCopy.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toCopy);
|
||||
cl->ResourceBarrier(1, &toCopy);
|
||||
tex.state = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
}
|
||||
|
||||
@@ -11532,17 +11580,17 @@ static void UploadTexture(TextureResource& tex)
|
||||
dstLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
dstLoc.SubresourceIndex = 0;
|
||||
|
||||
g_gl.cmdList->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
cl->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
|
||||
D3D12_RESOURCE_BARRIER toSrv{};
|
||||
toSrv.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
toSrv.Transition.pResource = tex.texture.Get();
|
||||
toSrv.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toSrv);
|
||||
cl->ResourceBarrier(1, &toSrv);
|
||||
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
tex.gpuValid = true;
|
||||
return;
|
||||
}
|
||||
@@ -11561,7 +11609,7 @@ static void UploadTexture(TextureResource& tex)
|
||||
toCopy.Transition.StateBefore = tex.state;
|
||||
toCopy.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toCopy.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toCopy);
|
||||
cl->ResourceBarrier(1, &toCopy);
|
||||
tex.state = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
}
|
||||
|
||||
@@ -11593,17 +11641,17 @@ static void UploadTexture(TextureResource& tex)
|
||||
dstLoc.pResource = tex.texture.Get();
|
||||
dstLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
||||
dstLoc.SubresourceIndex = 0;
|
||||
g_gl.cmdList->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
cl->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);
|
||||
|
||||
D3D12_RESOURCE_BARRIER toSrv{};
|
||||
toSrv.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
toSrv.Transition.pResource = tex.texture.Get();
|
||||
toSrv.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
toSrv.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
g_gl.cmdList->ResourceBarrier(1, &toSrv);
|
||||
cl->ResourceBarrier(1, &toSrv);
|
||||
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
tex.state = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
|
||||
tex.gpuValid = true;
|
||||
|
||||
EnsureTextureResource(tex);
|
||||
@@ -12894,12 +12942,20 @@ void APIENTRY glFinish(void)
|
||||
if (!g_gl.device || !g_gl.queue || !g_gl.cmdList)
|
||||
return;
|
||||
|
||||
QD3D12Window* owner = g_gl.frameOwner ? g_gl.frameOwner : g_currentWindow;
|
||||
if (!owner)
|
||||
return;
|
||||
|
||||
if (!g_gl.frameOpen && g_gl.queuedBatches.empty())
|
||||
{
|
||||
QD3D12_WaitForGPU();
|
||||
if (!QD3D12_IsEmbeddedEditorWindow(*owner))
|
||||
QD3D12_WaitForGPU();
|
||||
return;
|
||||
}
|
||||
|
||||
QD3D12Window* savedWindow = g_currentWindow;
|
||||
g_currentWindow = owner;
|
||||
|
||||
QD3D12_EnsureFrameOpen();
|
||||
QD3D12_FlushQueuedBatches();
|
||||
|
||||
@@ -12917,16 +12973,17 @@ void APIENTRY glFinish(void)
|
||||
WaitForSingleObject(g_gl.fenceEvent, INFINITE);
|
||||
}
|
||||
|
||||
FrameResources& fr = g_currentWindow->frames[g_currentWindow->frameIndex];
|
||||
FrameResources& fr = owner->frames[owner->frameIndex];
|
||||
fr.fenceValue = signalValue;
|
||||
|
||||
QD3D12_CHECK(fr.cmdAlloc->Reset());
|
||||
QD3D12_CHECK(g_gl.cmdList->Reset(fr.cmdAlloc.Get(), nullptr));
|
||||
|
||||
QD3D12_BindTargetsForCurrentPhase(*g_currentWindow);
|
||||
QD3D12_BindTargetsForCurrentPhase(*owner);
|
||||
|
||||
g_gl.frameOpen = true;
|
||||
g_gl.frameOwner = g_currentWindow;
|
||||
g_gl.frameOwner = owner;
|
||||
g_currentWindow = savedWindow;
|
||||
}
|
||||
|
||||
void APIENTRY glMatrixMode(GLenum mode)
|
||||
@@ -14689,7 +14746,7 @@ void QD3D12_ReleaseWindowSizeResources(QD3D12Window& w)
|
||||
}
|
||||
void QD3D12_Resize()
|
||||
{
|
||||
if (!g_currentWindow)
|
||||
if (!g_currentWindow || !g_currentWindow->swapChain)
|
||||
return;
|
||||
|
||||
RECT rc{};
|
||||
@@ -14718,13 +14775,22 @@ void QD3D12_Resize()
|
||||
|
||||
QD3D12_ReleaseWindowSizeResources(*g_currentWindow);
|
||||
|
||||
QD3D12_CHECK(g_currentWindow->swapChain->ResizeBuffers(
|
||||
HRESULT resizeHr = g_currentWindow->swapChain->ResizeBuffers(
|
||||
QD3D12_FrameCount,
|
||||
width,
|
||||
height,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING
|
||||
));
|
||||
);
|
||||
if (FAILED(resizeHr))
|
||||
{
|
||||
QD3D12_Log("ResizeBuffers failed 0x%08X; recreating swapchain.", (unsigned)resizeHr);
|
||||
g_currentWindow->swapChain.Reset();
|
||||
g_currentWindow->width = width;
|
||||
g_currentWindow->height = height;
|
||||
QD3D12_SelectRenderResolution(*g_currentWindow, width, height);
|
||||
QD3D12_CreateSwapChainForWindow(*g_currentWindow);
|
||||
}
|
||||
|
||||
g_currentWindow->width = width;
|
||||
g_currentWindow->height = height;
|
||||
|
||||
Reference in New Issue
Block a user