mirror of
https://github.com/jmarshall23/DoomRTX.git
synced 2026-08-12 08:11:10 +02:00
Raytracing backend now supports multiple worlds.
This commit is contained in:
@@ -2845,7 +2845,7 @@ void idSessionLocal::Init() {
|
||||
// the same idRenderWorld will be used for all games
|
||||
// and demos, insuring that level specific models
|
||||
// will be freed
|
||||
rw = renderSystem->AllocRenderWorld();
|
||||
rw = renderSystem->AllocRenderWorld(dxrWorldId_t::DXR_WORLD_GAME);
|
||||
sw = soundSystem->AllocSoundWorld( rw );
|
||||
|
||||
menuSoundWorld = soundSystem->AllocSoundWorld( rw );
|
||||
|
||||
+764
-401
File diff suppressed because it is too large
Load Diff
+93
-50
@@ -10441,10 +10441,18 @@ static void QD3D12_ResolveSceneToOutputAndEnterNativePhase(QD3D12Window& w)
|
||||
QD3D12_BindTargetsForCurrentPhase(w);
|
||||
}
|
||||
|
||||
void glLightScene(void)
|
||||
void glLightScene(glRaytracingSceneHandle_t sceneHandle)
|
||||
{
|
||||
const int width = (int)g_currentWindow->renderWidth;
|
||||
const int height = (int)g_currentWindow->renderHeight;
|
||||
if (sceneHandle == 0)
|
||||
return;
|
||||
|
||||
auto* window = g_currentWindow;
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
const int width = (int)window->renderWidth;
|
||||
const int height = (int)window->renderHeight;
|
||||
const auto frameIndex = window->frameIndex;
|
||||
|
||||
if (width <= 0 || height <= 0)
|
||||
return;
|
||||
@@ -10458,48 +10466,54 @@ void glLightScene(void)
|
||||
if (!lightingTex || !lightingTex->texture)
|
||||
return;
|
||||
|
||||
glRaytracingBuildScene();
|
||||
// Scene/TLAS ownership is now per render world. Querying the scene TLAS here
|
||||
// also builds dirty shared BLAS resources and this scene's TLAS before we
|
||||
// touch the window G-buffer state.
|
||||
ID3D12Resource* tlas = glRaytracingGetTopLevelASForScene(sceneHandle);
|
||||
if (!tlas)
|
||||
return;
|
||||
|
||||
glRaytracingBuildSceneForHandle(sceneHandle);
|
||||
|
||||
QD3D12_FlushQueuedBatches();
|
||||
QD3D12_ResolveGBufferForCurrentFrame(*g_currentWindow);
|
||||
QD3D12_ResolveGBufferForCurrentFrame(*window);
|
||||
|
||||
ID3D12GraphicsCommandList* cl = g_gl.cmdList.Get();
|
||||
ID3D12Resource* sceneColor = g_currentWindow->sceneColorBuffers[g_currentWindow->frameIndex].Get();
|
||||
ID3D12Resource* sceneNormal = g_currentWindow->normalBuffers[g_currentWindow->frameIndex].Get();
|
||||
ID3D12Resource* scenePosition = g_currentWindow->positionBuffers[g_currentWindow->frameIndex].Get();
|
||||
ID3D12Resource* sceneDepth = g_currentWindow->depthBuffer.Get();
|
||||
ID3D12Resource* tlas = glRaytracingGetTopLevelAS();
|
||||
ID3D12Resource* sceneColor = window->sceneColorBuffers[frameIndex].Get();
|
||||
ID3D12Resource* sceneNormal = window->normalBuffers[frameIndex].Get();
|
||||
ID3D12Resource* scenePosition = window->positionBuffers[frameIndex].Get();
|
||||
ID3D12Resource* sceneDepth = window->depthBuffer.Get();
|
||||
|
||||
if (!sceneColor || !sceneNormal || !scenePosition || !sceneDepth || !tlas)
|
||||
if (!sceneColor || !sceneNormal || !scenePosition || !sceneDepth)
|
||||
return;
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
sceneColor,
|
||||
g_currentWindow->sceneColorState[g_currentWindow->frameIndex],
|
||||
window->sceneColorState[frameIndex],
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
sceneNormal,
|
||||
g_currentWindow->normalBufferState[g_currentWindow->frameIndex],
|
||||
window->normalBufferState[frameIndex],
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
scenePosition,
|
||||
g_currentWindow->positionBufferState[g_currentWindow->frameIndex],
|
||||
window->positionBufferState[frameIndex],
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
sceneDepth,
|
||||
g_currentWindow->depthState,
|
||||
window->depthState,
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
// The external DXR module records and executes its own command list. Because
|
||||
// of that, the scene input transitions must be submitted on the main command
|
||||
// list before we call into glRaytracingLightingExecute.
|
||||
// list before we call into glRaytracingLightingExecuteForScene.
|
||||
if (g_lightingTextureState != D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE)
|
||||
{
|
||||
QD3D12_TransitionResource(
|
||||
@@ -10507,9 +10521,11 @@ void glLightScene(void)
|
||||
lightingTex->texture.Get(),
|
||||
g_lightingTextureState,
|
||||
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
g_lightingTextureState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
}
|
||||
|
||||
QD3D12_ExecuteMainCommandListAndWait(*g_currentWindow);
|
||||
QD3D12_ExecuteMainCommandListAndWait(*window);
|
||||
cl = g_gl.cmdList.Get();
|
||||
|
||||
glRaytracingLightingPassDesc_t pass = {};
|
||||
@@ -10528,44 +10544,43 @@ void glLightScene(void)
|
||||
pass.outputTexture = lightingTex->texture.Get();
|
||||
pass.outputFormat = lightingTex->dxgiFormat;
|
||||
|
||||
pass.topLevelAS = tlas;
|
||||
pass.width = (uint32_t)width;
|
||||
pass.height = (uint32_t)height;
|
||||
|
||||
if (!glRaytracingLightingExecute(&pass))
|
||||
if (!glRaytracingLightingExecuteForScene(&pass, sceneHandle))
|
||||
{
|
||||
if (QD3D12_GBufferMsaaEnabled())
|
||||
{
|
||||
QD3D12_TransitionResource(cl, g_currentWindow->sceneColorMsaaBuffers[g_currentWindow->frameIndex].Get(), g_currentWindow->sceneColorMsaaState[g_currentWindow->frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, g_currentWindow->normalMsaaBuffers[g_currentWindow->frameIndex].Get(), g_currentWindow->normalMsaaState[g_currentWindow->frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, g_currentWindow->positionMsaaBuffers[g_currentWindow->frameIndex].Get(), g_currentWindow->positionMsaaState[g_currentWindow->frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, g_currentWindow->velocityMsaaBuffers[g_currentWindow->frameIndex].Get(), g_currentWindow->velocityMsaaState[g_currentWindow->frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, g_currentWindow->depthMsaaBuffer.Get(), g_currentWindow->depthMsaaState, D3D12_RESOURCE_STATE_DEPTH_WRITE);
|
||||
QD3D12_TransitionResource(cl, window->sceneColorMsaaBuffers[frameIndex].Get(), window->sceneColorMsaaState[frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, window->normalMsaaBuffers[frameIndex].Get(), window->normalMsaaState[frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, window->positionMsaaBuffers[frameIndex].Get(), window->positionMsaaState[frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, window->velocityMsaaBuffers[frameIndex].Get(), window->velocityMsaaState[frameIndex], D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
QD3D12_TransitionResource(cl, window->depthMsaaBuffer.Get(), window->depthMsaaState, D3D12_RESOURCE_STATE_DEPTH_WRITE);
|
||||
}
|
||||
else
|
||||
{
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
sceneColor,
|
||||
g_currentWindow->sceneColorState[g_currentWindow->frameIndex],
|
||||
window->sceneColorState[frameIndex],
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
sceneNormal,
|
||||
g_currentWindow->normalBufferState[g_currentWindow->frameIndex],
|
||||
window->normalBufferState[frameIndex],
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
scenePosition,
|
||||
g_currentWindow->positionBufferState[g_currentWindow->frameIndex],
|
||||
window->positionBufferState[frameIndex],
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
sceneDepth,
|
||||
g_currentWindow->depthState,
|
||||
window->depthState,
|
||||
D3D12_RESOURCE_STATE_DEPTH_WRITE);
|
||||
}
|
||||
|
||||
@@ -10573,46 +10588,55 @@ void glLightScene(void)
|
||||
return;
|
||||
}
|
||||
|
||||
g_lightingTextureState = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
|
||||
// The scene-handle DXR path leaves outputTexture in PIXEL_SHADER_RESOURCE.
|
||||
g_lightingTextureState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
|
||||
QD3D12_RunRayAIDenoiseIfEnabled(cl, *g_currentWindow, lightingTex->texture.Get());
|
||||
QD3D12_RunRayAIDenoiseIfEnabled(cl, *window, lightingTex->texture.Get());
|
||||
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
lightingTex->texture.Get(),
|
||||
g_lightingTextureState,
|
||||
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
|
||||
// If the denoiser changes the texture state and updates g_lightingTextureState,
|
||||
// restore the texture to a shader-readable state for the post/upscale pass.
|
||||
if (g_lightingTextureState != D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE)
|
||||
{
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
lightingTex->texture.Get(),
|
||||
g_lightingTextureState,
|
||||
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
g_lightingTextureState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
||||
}
|
||||
|
||||
g_gl.raytracedLightingReadyThisFrame = true;
|
||||
|
||||
if (!QD3D12_UseLightingTextureAsUpscaleInput(*g_currentWindow))
|
||||
if (!QD3D12_UseLightingTextureAsUpscaleInput(*window))
|
||||
{
|
||||
QD3D12_TransitionResource(
|
||||
cl,
|
||||
sceneColor,
|
||||
g_currentWindow->sceneColorState[g_currentWindow->frameIndex],
|
||||
window->sceneColorState[frameIndex],
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
D3D12_VIEWPORT viewport{};
|
||||
viewport.TopLeftX = 0.0f;
|
||||
viewport.TopLeftY = 0.0f;
|
||||
viewport.Width = (float)g_currentWindow->renderWidth;
|
||||
viewport.Height = (float)g_currentWindow->renderHeight;
|
||||
viewport.Width = (float)window->renderWidth;
|
||||
viewport.Height = (float)window->renderHeight;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
|
||||
D3D12_RECT scissor{};
|
||||
scissor.left = 0;
|
||||
scissor.top = 0;
|
||||
scissor.right = (LONG)g_currentWindow->renderWidth;
|
||||
scissor.bottom = (LONG)g_currentWindow->renderHeight;
|
||||
scissor.right = (LONG)window->renderWidth;
|
||||
scissor.bottom = (LONG)window->renderHeight;
|
||||
|
||||
// Non-RR path: replace the low-resolution scene color with the lit result,
|
||||
// then upscale that scene color into the backbuffer.
|
||||
// then upscale that scene color into the backbuffer. Use the texture returned
|
||||
// for this window instead of a separate global texture pointer.
|
||||
QD3D12_PostFullscreenPass(
|
||||
cl,
|
||||
g_gl.postCopyPSO.Get(),
|
||||
g_lightingTexture->srvGpu,
|
||||
lightingTex->srvGpu,
|
||||
CurrentResolvedSceneColorRTV(),
|
||||
viewport,
|
||||
scissor);
|
||||
@@ -10624,9 +10648,10 @@ void glLightScene(void)
|
||||
// guide instead of overwriting it here.
|
||||
}
|
||||
|
||||
QD3D12_ResolveSceneToOutputAndEnterNativePhase(*g_currentWindow);
|
||||
QD3D12_ResolveSceneToOutputAndEnterNativePhase(*window);
|
||||
}
|
||||
|
||||
|
||||
ID3D12Resource* QD3D12_GetCurrentBackBuffer()
|
||||
{
|
||||
if (!g_currentWindow->swapChain)
|
||||
@@ -12090,9 +12115,17 @@ void glUpdateBottomAccelStructure(bool opaque, uint32_t& meshHandle)
|
||||
meshHandle = glRaytracingCreateMesh(&meshDesc);
|
||||
}
|
||||
|
||||
void glUpdateTopLevelAceelStructure(uint32_t mesh, float* transform, uint32_t& topLevelHandle) {
|
||||
void glUpdateTopLevelAceelStructure(
|
||||
glRaytracingSceneHandle_t scene,
|
||||
uint32_t mesh,
|
||||
float* transform,
|
||||
uint32_t& topLevelHandle)
|
||||
{
|
||||
if (scene == 0 || mesh == 0)
|
||||
return;
|
||||
|
||||
glRaytracingInstanceDesc_t instDesc = {};
|
||||
instDesc.meshHandle = mesh;
|
||||
instDesc.meshHandle = (glRaytracingMeshHandle_t)mesh;
|
||||
instDesc.instanceID = 0;
|
||||
instDesc.mask = 0xFF;
|
||||
|
||||
@@ -12104,15 +12137,25 @@ void glUpdateTopLevelAceelStructure(uint32_t mesh, float* transform, uint32_t& t
|
||||
}
|
||||
else
|
||||
{
|
||||
// Same contract as the old helper: transform is a 12-float
|
||||
// D3D12_RAYTRACING_INSTANCE_DESC-compatible 3x4 transform.
|
||||
memcpy(instDesc.transform, transform, sizeof(float) * 12);
|
||||
}
|
||||
|
||||
if (topLevelHandle == 0)
|
||||
{
|
||||
topLevelHandle = glRaytracingCreateInstance(&instDesc);
|
||||
}
|
||||
else {
|
||||
glRaytracingUpdateInstance(topLevelHandle, &instDesc);
|
||||
topLevelHandle = glRaytracingCreateInstanceInScene(scene, &instDesc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!glRaytracingUpdateInstanceInScene(
|
||||
scene,
|
||||
(glRaytracingInstanceHandle_t)topLevelHandle,
|
||||
&instDesc))
|
||||
{
|
||||
// The saved handle can become stale if the scene was cleared/deleted, or if
|
||||
// the caller accidentally reuses a handle from another render world. Create
|
||||
// a new per-scene instance and return that handle to the caller.
|
||||
topLevelHandle = glRaytracingCreateInstanceInScene(scene, &instDesc);
|
||||
}
|
||||
}
|
||||
+46
-13
@@ -275,6 +275,15 @@ typedef char GLchar;
|
||||
#define GL_TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef GL_RAYTRACING_MAX_RENDER_WORLDS
|
||||
#define GL_RAYTRACING_MAX_RENDER_WORLDS 24
|
||||
#endif
|
||||
|
||||
#ifndef GL_RAYTRACING_SCENE_HANDLE_T_DEFINED
|
||||
typedef uint32_t glRaytracingSceneHandle_t;
|
||||
#define GL_RAYTRACING_SCENE_HANDLE_T_DEFINED
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARRAY_BUFFER
|
||||
#define GL_ARRAY_BUFFER 0x8892
|
||||
#endif
|
||||
@@ -1540,8 +1549,6 @@ enum GeometryFlag_t
|
||||
|
||||
void APIENTRY glGeometryFlagf(GLfloat flag);
|
||||
|
||||
void glUpdateBottomAccelStructure(bool opaque, uint32_t& meshHandle);
|
||||
void glUpdateTopLevelAceelStructure(uint32_t mesh, float* transform, uint32_t& topLevelHandle);
|
||||
#endif
|
||||
|
||||
struct GLVertex
|
||||
@@ -1669,8 +1676,6 @@ typedef struct glRaytracingLightingPassDesc_s
|
||||
ID3D12Resource* outputTexture;
|
||||
DXGI_FORMAT outputFormat;
|
||||
|
||||
ID3D12Resource* topLevelAS;
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
} glRaytracingLightingPassDesc_t;
|
||||
@@ -1679,21 +1684,41 @@ int glRaytracingInit(void);
|
||||
void glRaytracingShutdown(void);
|
||||
void glRaytracingClear(void);
|
||||
|
||||
// Render-world / TLAS APIs.
|
||||
// A render world owns its own instance list and TLAS. Meshes and BLAS resources
|
||||
// remain shared globally. Valid scene handles are returned by glRaytracingCreateScene()
|
||||
// and are in the range 1..GL_RAYTRACING_MAX_RENDER_WORLDS.
|
||||
glRaytracingSceneHandle_t glRaytracingCreateScene(void);
|
||||
void glRaytracingClearScene(glRaytracingSceneHandle_t sceneHandle);
|
||||
void glRaytracingDeleteScene(glRaytracingSceneHandle_t sceneHandle);
|
||||
uint32_t glRaytracingGetSceneCount(void);
|
||||
|
||||
glRaytracingMeshHandle_t glRaytracingCreateMesh(const glRaytracingMeshDesc_t* desc);
|
||||
int glRaytracingUpdateMesh(glRaytracingMeshHandle_t meshHandle, const glRaytracingMeshDesc_t* desc);
|
||||
void glRaytracingDeleteMesh(glRaytracingMeshHandle_t meshHandle);
|
||||
|
||||
glRaytracingInstanceHandle_t glRaytracingCreateInstance(const glRaytracingInstanceDesc_t* desc);
|
||||
int glRaytracingUpdateInstance(glRaytracingInstanceHandle_t instanceHandle, const glRaytracingInstanceDesc_t* desc);
|
||||
void glRaytracingDeleteInstance(glRaytracingInstanceHandle_t instanceHandle);
|
||||
// Scene-specific instance APIs for multiple render worlds.
|
||||
glRaytracingInstanceHandle_t glRaytracingCreateInstanceInScene(
|
||||
glRaytracingSceneHandle_t sceneHandle,
|
||||
const glRaytracingInstanceDesc_t* desc);
|
||||
|
||||
int glRaytracingUpdateInstanceInScene(
|
||||
glRaytracingSceneHandle_t sceneHandle,
|
||||
glRaytracingInstanceHandle_t instanceHandle,
|
||||
const glRaytracingInstanceDesc_t* desc);
|
||||
|
||||
void glRaytracingDeleteInstanceInScene(
|
||||
glRaytracingSceneHandle_t sceneHandle,
|
||||
glRaytracingInstanceHandle_t instanceHandle);
|
||||
|
||||
int glRaytracingBuildMesh(glRaytracingMeshHandle_t meshHandle);
|
||||
int glRaytracingBuildAllMeshes(void);
|
||||
int glRaytracingBuildScene(void);
|
||||
int glRaytracingBuildSceneIfDirty(void);
|
||||
int glRaytracingBuildSceneForHandle(glRaytracingSceneHandle_t sceneHandle);
|
||||
|
||||
ID3D12Resource* glRaytracingGetTopLevelASForScene(glRaytracingSceneHandle_t sceneHandle);
|
||||
|
||||
uint32_t glRaytracingGetMeshCount(void);
|
||||
uint32_t glRaytracingGetInstanceCount(void);
|
||||
uint32_t glRaytracingGetInstanceCountForScene(glRaytracingSceneHandle_t sceneHandle);
|
||||
|
||||
bool glRaytracingLightingInit(void);
|
||||
void glRaytracingLightingShutdown(void);
|
||||
@@ -1711,7 +1736,9 @@ void glRaytracingLightingEnableSpecular(int enable);
|
||||
void glRaytracingLightingEnableHalfLambert(int enable);
|
||||
void glRaytracingLightingSetShadowBias(float bias);
|
||||
|
||||
bool glRaytracingLightingExecute(const glRaytracingLightingPassDesc_t* pass);
|
||||
bool glRaytracingLightingExecuteForScene(
|
||||
const glRaytracingLightingPassDesc_t* pass,
|
||||
glRaytracingSceneHandle_t sceneHandle);
|
||||
|
||||
glRaytracingLight_t glRaytracingLightingMakePointLight(
|
||||
float px, float py, float pz,
|
||||
@@ -1732,7 +1759,7 @@ glRaytracingLight_t glRaytracingLightingMakeRectLight(
|
||||
|
||||
uint32_t glRaytracingLightingGetLightCount(void);
|
||||
|
||||
void glLightScene(void);
|
||||
void glLightScene(glRaytracingSceneHandle_t sceneHandle);
|
||||
|
||||
ID3D12Device* QD3D12_GetDevice(void);
|
||||
ID3D12CommandQueue* QD3D12_GetQueue(void);
|
||||
@@ -2133,4 +2160,10 @@ void APIENTRY glTextureNormalMap(GLuint texture, GLboolean isNormalMap); // alia
|
||||
void APIENTRY glBindNormalMapTexture(GLuint texture); // 0 disables explicit normal map
|
||||
void APIENTRY glNormalMapTexture(GLuint texture); // alias
|
||||
void APIENTRY glNormalMapStrengthf(GLfloat strength); // default 1.0
|
||||
void APIENTRY glNormalMapYSignf(GLfloat sign); // default +1, pass -1 to flip green/Y
|
||||
void APIENTRY glNormalMapYSignf(GLfloat sign); // default +1, pass -1 to flip green/Y
|
||||
|
||||
void glUpdateTopLevelAceelStructure(
|
||||
glRaytracingSceneHandle_t scene,
|
||||
uint32_t mesh,
|
||||
float* transform,
|
||||
uint32_t& topLevelHandle);
|
||||
@@ -51,10 +51,18 @@ idRenderEntityLocal::idRenderEntityLocal() {
|
||||
entityRefs = NULL;
|
||||
firstInteraction = NULL;
|
||||
lastInteraction = NULL;
|
||||
dxrBottomAccelStruct = 0;
|
||||
needsPortalSky = false;
|
||||
}
|
||||
|
||||
void idRenderEntityLocal::FreeRenderEntity() {
|
||||
void idRenderEntityLocal::FreeRenderEntity(glRaytracingSceneHandle_t sceneHandle) {
|
||||
if (dxrBottomAccelStruct != 0)
|
||||
{
|
||||
glRaytracingDeleteMesh(dxrBottomAccelStruct);
|
||||
glRaytracingDeleteInstanceInScene(sceneHandle, dxrTopAccelStruct);
|
||||
}
|
||||
|
||||
dxrBottomAccelStruct = 0;
|
||||
}
|
||||
|
||||
void idRenderEntityLocal::UpdateRenderEntity( const renderEntity_t *re, bool forceUpdate ) {
|
||||
|
||||
@@ -989,9 +989,9 @@ void idRenderSystemLocal::CaptureRenderToFile( const char *fileName, bool fixAlp
|
||||
AllocRenderWorld
|
||||
==============
|
||||
*/
|
||||
idRenderWorld *idRenderSystemLocal::AllocRenderWorld() {
|
||||
idRenderWorldLocal *rw;
|
||||
rw = new idRenderWorldLocal;
|
||||
idRenderWorld *idRenderSystemLocal::AllocRenderWorld(dxrWorldId_t worldId) {
|
||||
idRenderWorldLocal *rw = new idRenderWorldLocal(worldId);
|
||||
glRaytracingClearScene(rw->dxrWorldId);
|
||||
worlds.Append( rw );
|
||||
return rw;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,17 @@ typedef struct glconfig_s {
|
||||
bool isInitialized;
|
||||
} glconfig_t;
|
||||
|
||||
//
|
||||
// dxrWorldId_t
|
||||
//
|
||||
enum dxrWorldId_t {
|
||||
DXR_WORLD_MAINMENU = 0,
|
||||
DXR_WORLD_GAME,
|
||||
DXR_WORLD_EDITOR,
|
||||
DXR_MATERIAL_PREVIEW,
|
||||
DXR_WIDGET_0,
|
||||
DXR_WORLD_NUM
|
||||
};
|
||||
|
||||
// font support
|
||||
const int GLYPH_START = 0;
|
||||
@@ -179,7 +190,7 @@ public:
|
||||
virtual int GetScreenHeight( void ) const = 0;
|
||||
|
||||
// allocate a renderWorld to be used for drawing
|
||||
virtual idRenderWorld * AllocRenderWorld( void ) = 0;
|
||||
virtual idRenderWorld * AllocRenderWorld( dxrWorldId_t worldId ) = 0;
|
||||
virtual void FreeRenderWorld( idRenderWorld * rw ) = 0;
|
||||
|
||||
// All data that will be used in a level should be
|
||||
|
||||
@@ -515,6 +515,12 @@ void R_InitOpenGL( void ) {
|
||||
// Reset our gamma
|
||||
R_SetColorMappings();
|
||||
|
||||
// Create the DXR worlds.
|
||||
for (int i = 0; i < DXR_WORLD_NUM; i++)
|
||||
{
|
||||
tr.dxrWorldHandles[i] = glRaytracingCreateScene();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static bool glCheck = false;
|
||||
if ( !glCheck && win32.osversion.dwMajorVersion == 6 ) {
|
||||
|
||||
@@ -125,10 +125,12 @@ void R_ListRenderEntityDefs_f( const idCmdArgs &args ) {
|
||||
idRenderWorldLocal::idRenderWorldLocal
|
||||
===================
|
||||
*/
|
||||
idRenderWorldLocal::idRenderWorldLocal() {
|
||||
idRenderWorldLocal::idRenderWorldLocal(dxrWorldId_t dxrWorldId) {
|
||||
mapName.Clear();
|
||||
mapTimeStamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||
|
||||
this->dxrWorldId = tr.dxrWorldHandles[dxrWorldId];
|
||||
|
||||
generateAllInteractionsCalled = false;
|
||||
|
||||
areaNodes = NULL;
|
||||
@@ -285,7 +287,7 @@ void idRenderWorldLocal::UpdateEntityDef( qhandle_t entityHandle, const renderEn
|
||||
float dxrTransformMatrix[16];
|
||||
|
||||
RB_CopyModelMatrixToDXRTransform(def->modelMatrix, dxrTransformMatrix);
|
||||
glUpdateTopLevelAceelStructure(def->dxrBottomAccelStruct, dxrTransformMatrix, def->dxrTopAccelStruct);
|
||||
glUpdateTopLevelAceelStructure(dxrWorldId, def->dxrBottomAccelStruct, dxrTransformMatrix, def->dxrTopAccelStruct);
|
||||
}
|
||||
|
||||
def->lastModifiedFrameNum = tr.frameCount;
|
||||
@@ -340,6 +342,8 @@ void idRenderWorldLocal::FreeEntityDef( qhandle_t entityHandle ) {
|
||||
def->parms.gui[ 1 ] = NULL;
|
||||
def->parms.gui[ 2 ] = NULL;
|
||||
|
||||
def->FreeRenderEntity(dxrWorldId);
|
||||
|
||||
delete def;
|
||||
entityDefs[ entityHandle ] = NULL;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,13 @@ void idRenderWorldLocal::FreeWorld() {
|
||||
// this will free all the lightDefs and entityDefs
|
||||
FreeDefs();
|
||||
|
||||
// clear the dxr models.
|
||||
glRaytracingClearScene(dxrWorldId);
|
||||
for (i = 0; i < worldDXRmodels.Num(); i++) {
|
||||
glRaytracingDeleteMesh(worldDXRmodels[i].dxrBottomAcel);
|
||||
}
|
||||
worldDXRmodels.Clear();
|
||||
|
||||
// free all the portals and check light/model references
|
||||
for ( i = 0 ; i < numPortalAreas ; i++ ) {
|
||||
portalArea_t *area;
|
||||
@@ -180,7 +187,7 @@ idRenderModel *idRenderWorldLocal::ParseModel( idLexer *src ) {
|
||||
idRenderModelStatic* modelStatic = (idRenderModelStatic*)model;
|
||||
dxrWorldModel_t dxrModel;
|
||||
modelStatic->UpdateDXR(dxrModel.dxrBottomAcel, model->NumSurfaces() - 1);
|
||||
glUpdateTopLevelAceelStructure(dxrModel.dxrBottomAcel, NULL, dxrModel.topAccelStruct);
|
||||
glUpdateTopLevelAceelStructure(dxrWorldId, dxrModel.dxrBottomAcel, NULL, dxrModel.topAccelStruct);
|
||||
worldDXRmodels.Append(dxrModel);
|
||||
}
|
||||
}
|
||||
@@ -499,7 +506,6 @@ bool idRenderWorldLocal::InitFromMap( const char *name ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// load it
|
||||
filename = name;
|
||||
filename.SetFileExtension( PROC_FILE_EXT );
|
||||
|
||||
@@ -81,7 +81,7 @@ struct dxrWorldModel_t {
|
||||
|
||||
class idRenderWorldLocal : public idRenderWorld {
|
||||
public:
|
||||
idRenderWorldLocal();
|
||||
idRenderWorldLocal(dxrWorldId_t dxrWorldId);
|
||||
virtual ~idRenderWorldLocal();
|
||||
|
||||
virtual qhandle_t AddEntityDef( const renderEntity_t *re );
|
||||
@@ -262,6 +262,7 @@ public:
|
||||
// tr_light.c
|
||||
void CreateLightDefInteractions( idRenderLightLocal *ldef );
|
||||
|
||||
glRaytracingSceneHandle_t dxrWorldId;
|
||||
idList<dxrWorldModel_t> worldDXRmodels;
|
||||
};
|
||||
|
||||
|
||||
@@ -50,6 +50,6 @@ void RB_DXDrawInteractions(void) {
|
||||
|
||||
|
||||
glFinish();
|
||||
glLightScene();
|
||||
glLightScene(backEnd.viewDef->renderWorld->dxrWorldId);
|
||||
glRaytracingLightingClearLights(false);
|
||||
}
|
||||
|
||||
@@ -1143,7 +1143,7 @@ idRenderModel *R_EntityDefDynamicModel( idRenderEntityLocal *def ) {
|
||||
float dxrTransformMatrix[16];
|
||||
staticMesh->UpdateDXR(def->dxrBottomAccelStruct);
|
||||
RB_CopyModelMatrixToDXRTransform(def->modelMatrix, dxrTransformMatrix);
|
||||
glUpdateTopLevelAceelStructure(def->dxrBottomAccelStruct, dxrTransformMatrix, def->dxrTopAccelStruct);
|
||||
glUpdateTopLevelAceelStructure(tr.primaryWorld->dxrWorldId, def->dxrBottomAccelStruct, dxrTransformMatrix, def->dxrTopAccelStruct);
|
||||
}
|
||||
|
||||
if ( def->cachedDynamicModel ) {
|
||||
|
||||
@@ -166,7 +166,7 @@ class idRenderEntity {
|
||||
public:
|
||||
virtual ~idRenderEntity() {}
|
||||
|
||||
virtual void FreeRenderEntity() = 0;
|
||||
virtual void FreeRenderEntity(glRaytracingSceneHandle_t sceneHandle) = 0;
|
||||
virtual void UpdateRenderEntity( const renderEntity_t *re, bool forceUpdate = false ) = 0;
|
||||
virtual void GetRenderEntity( renderEntity_t *re ) = 0;
|
||||
virtual void ForceUpdate() = 0;
|
||||
@@ -238,7 +238,7 @@ class idRenderEntityLocal : public idRenderEntity {
|
||||
public:
|
||||
idRenderEntityLocal();
|
||||
|
||||
virtual void FreeRenderEntity();
|
||||
virtual void FreeRenderEntity(glRaytracingSceneHandle_t sceneHandle);
|
||||
virtual void UpdateRenderEntity( const renderEntity_t *re, bool forceUpdate = false );
|
||||
virtual void GetRenderEntity( renderEntity_t *re );
|
||||
virtual void ForceUpdate();
|
||||
@@ -703,7 +703,7 @@ public:
|
||||
virtual bool IsFullScreen( void ) const;
|
||||
virtual int GetScreenWidth( void ) const;
|
||||
virtual int GetScreenHeight( void ) const;
|
||||
virtual idRenderWorld * AllocRenderWorld( void );
|
||||
virtual idRenderWorld * AllocRenderWorld(dxrWorldId_t worldId);
|
||||
virtual void FreeRenderWorld( idRenderWorld *rw );
|
||||
virtual void BeginLevelLoad( void );
|
||||
virtual void EndLevelLoad( void );
|
||||
@@ -734,7 +734,6 @@ public:
|
||||
virtual void UnCrop();
|
||||
virtual void GetCardCaps( bool &oldCard, bool &nv10or20 );
|
||||
virtual bool UploadImage( const char *imageName, const byte *data, int width, int height );
|
||||
|
||||
public:
|
||||
// internal functions
|
||||
idRenderSystemLocal( void );
|
||||
@@ -806,6 +805,8 @@ public:
|
||||
class idGuiModel * demoGuiModel;
|
||||
|
||||
unsigned short gammaTable[256]; // brightness / gamma modify this
|
||||
|
||||
glRaytracingSceneHandle_t dxrWorldHandles[dxrWorldId_t::DXR_WORLD_NUM];
|
||||
};
|
||||
|
||||
extern backEndState_t backEnd;
|
||||
|
||||
@@ -241,7 +241,7 @@ void idGLDrawableView::ResetView( void ) {
|
||||
void idGLDrawableView::InitWorld() {
|
||||
|
||||
if ( world == NULL ) {
|
||||
world = renderSystem->AllocRenderWorld();
|
||||
world = renderSystem->AllocRenderWorld(dxrWorldId_t::DXR_MATERIAL_PREVIEW);
|
||||
}
|
||||
if ( worldModel == NULL ) {
|
||||
worldModel = renderModelManager->AllocModel();
|
||||
|
||||
@@ -921,7 +921,7 @@ void idGLDrawableWorld::draw(int x, int y, int w, int h) {
|
||||
|
||||
void idGLDrawableWorld::InitWorld() {
|
||||
if ( world == NULL ) {
|
||||
world = renderSystem->AllocRenderWorld();
|
||||
world = renderSystem->AllocRenderWorld(dxrWorldId_t::DXR_WIDGET_0);
|
||||
}
|
||||
if ( worldModel == NULL ) {
|
||||
worldModel = renderModelManager->AllocModel();
|
||||
|
||||
@@ -106,7 +106,7 @@ void RadiantInit( void ) {
|
||||
|
||||
// allocate a renderWorld and a soundWorld
|
||||
if ( g_qeglobals.rw == NULL ) {
|
||||
g_qeglobals.rw = renderSystem->AllocRenderWorld();
|
||||
g_qeglobals.rw = renderSystem->AllocRenderWorld(dxrWorldId_t::DXR_WORLD_EDITOR);
|
||||
g_qeglobals.rw->InitFromMap( NULL );
|
||||
}
|
||||
if ( g_qeglobals.sw == NULL ) {
|
||||
|
||||
@@ -47,7 +47,7 @@ idRenderWindow::~idRenderWindow() {
|
||||
}
|
||||
|
||||
void idRenderWindow::CommonInit() {
|
||||
world = renderSystem->AllocRenderWorld();
|
||||
world = renderSystem->AllocRenderWorld(dxrWorldId_t::DXR_WORLD_MAINMENU);
|
||||
needsRender = true;
|
||||
lightOrigin = idVec4(-128.0f, 0.0f, 0.0f, 1.0f);
|
||||
lightColor = idVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
Reference in New Issue
Block a user