add texture copy feature to PCDX11Scene

This commit is contained in:
Adam Jensen 2023-04-12 03:33:52 +01:00
parent dc5ad022fb
commit 0af9d22691
10 changed files with 94 additions and 33 deletions

View File

@ -50,10 +50,12 @@ void CommonRenderDevice::method_44() {
void CommonRenderDevice::createSiblingScene(
RenderViewport *viewport,
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer)
CommonDepthBuffer *depthBuffer,
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth)
{
// TODO
createSubScene(viewport, renderTarget, depthBuffer);
createSubScene(viewport, renderTarget, depthBuffer, sourceColor, sourceDepth);
// TODO
}

View File

@ -64,12 +64,16 @@ public:
virtual CommonScene *createSubScene(
RenderViewport *renderViewport,
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer) = 0;
virtual void createSiblingScene(
CommonDepthBuffer *depthBuffer,
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth) = 0;
virtual void createSiblingScene( // CreatePartition
RenderViewport *renderViewport,
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer);
virtual void finishScene() = 0; // 50
CommonDepthBuffer *depthBuffer,
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth);
virtual void finishScene() = 0; // 50, EndScene
virtual void method_54();
virtual uint32_t getSceneCreationCount(); // frame count, basically
virtual CommonScene *getScene();

View File

@ -11,15 +11,19 @@ CommonScene::CommonScene(
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer,
/* ... */
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth,
RenderGlobalState *globalState,
/* ... */
RenderPasses *renderPasses)
:
renderTarget(renderTarget),
depthBuffer(depthBuffer),
sourceColor(sourceColor),
sourceDepth(sourceDepth),
parentScene(parentScene),
nextScene(nullptr),
prevScene(nullptr),
depthBuffer(depthBuffer),
numSubScenes(0)
{
this->viewport = *viewport;

View File

@ -70,8 +70,8 @@ public:
CommonRenderTarget *renderTarget; //3F0
CommonDepthBuffer *depthBuffer; // 3F4
// uint32_t dword3F8;
// uint32_t dword3FC;
// uint32_t dword400;
CommonRenderTarget *sourceColor; //3FC
CommonDepthBuffer *sourceDepth; // 400
CommonScene *parentScene; // 404
CommonScene *nextScene; // 408
CommonScene *prevScene; // 40C
@ -122,6 +122,8 @@ public:
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer,
/* ... */
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth,
RenderGlobalState *globalState,
/* ... */
RenderPasses *renderPasses);

View File

@ -139,16 +139,19 @@ void PCDX11RenderDevice::createDefaultVertexAttribLayouts() {
attrs.push_back({VertexAttributeA::kTexcoord1, 0xffff, 1, 0});
attrs.push_back({VertexAttributeA::kTexcoord2, 0xffff, 1, 0});
drawVertexDecls[0] = VertexDecl::Create(attrs.data(), attrs.size(), /*stride=*/ 0);
drawVertexDecls[0]->hash0 |= 1; // HACK
attrs.clear();
attrs.push_back({VertexAttributeA::kPosition, 0xffff, 2, 0});
attrs.push_back({VertexAttributeA::kColor1, 0xffff, 4, 0});
attrs.push_back({VertexAttributeA::kTexcoord0, 0xffff, 1, 0}); // HACK
drawVertexDecls[5] = VertexDecl::Create(attrs.data(), attrs.size(), /*stride=*/ 0);
drawVertexDecls[5]->hash0 |= 5; // HACK
attrs.clear();
attrs.push_back({VertexAttributeA::kPosition, 0xffff, 2, 0});
drawVertexDecls[6] = VertexDecl::Create(attrs.data(), attrs.size(), /*stride=*/ 0);
drawVertexDecls[6]->hash0 |= 6; // HACK
PCDX11VertexShader *vs;
@ -339,10 +342,12 @@ void PCDX11RenderDevice::method_30() {
// TODO
}
CommonScene *PCDX11RenderDevice::createSubScene(
CommonScene *PCDX11RenderDevice::createSubScene( // 48
RenderViewport *viewport,
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer
CommonDepthBuffer *depthBuffer,
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth
) {
sceneCreationCount++;
// TODO
@ -352,6 +357,8 @@ CommonScene *PCDX11RenderDevice::createSubScene(
viewport,
renderTarget,
depthBuffer,
sourceColor,
sourceDepth,
getGlobalState(),
&renderPasses);
scene7C = scene;

View File

@ -126,7 +126,9 @@ public:
CommonScene *createSubScene(
RenderViewport *renderViewport,
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer) override;
CommonDepthBuffer *depthBuffer,
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth) override;
void finishScene() override;
void getSceneRenderTarget() override;
void method_64() override;

View File

@ -21,6 +21,12 @@ void PCDX11Scene::draw(uint32_t funcSetIndex, IRenderDrawable *other) {
auto& sceneBuffer = stateManager->accessCommonCB(1);
sceneBuffer.assignRow(27, globalState.m_aParams, 16);
// TODO
if (sourceColor)
stateManager->m_renderTarget->copyFromTexture(static_cast<PCDX11RenderTarget*>(sourceColor));
if (sourceDepth)
stateManager->m_depthBuffer->copyFromTexture(static_cast<PCDX11DepthBuffer*>(sourceDepth)); // not implemented in original binary
if (drawableListsAndMasks) {
drawableListsAndMasks->renderPasses->sortAndDraw(
drawableListsAndMasks->passType,

View File

@ -15,11 +15,13 @@ public:
CommonRenderTarget *renderTarget,
CommonDepthBuffer *depthBuffer,
/* ... */
CommonRenderTarget *sourceColor,
CommonDepthBuffer *sourceDepth,
RenderGlobalState *globalState,
/* ... */
RenderPasses *renderPasses)
:
CommonScene(renderDevice, parentScene, viewport, renderTarget, depthBuffer, globalState, renderPasses),
CommonScene(renderDevice, parentScene, viewport, renderTarget, depthBuffer, sourceColor, sourceDepth, globalState, renderPasses),
renderDevice(static_cast<PCDX11RenderDevice*>(renderDevice))
{
// TODO

View File

@ -44,6 +44,8 @@ ID3D11RenderTargetView *PCDX11DefaultRenderTarget::getRenderTargetView() {
}
void PCDX11DefaultRenderTarget::copyFromTexture(PCDX11RenderTarget *sourceRT) {
// used from PCDX11Scene::draw when it has been constructed with sourceColor != nullptr
if (sourceRT->method_3C())
sourceRT->method_40();

View File

@ -440,7 +440,8 @@ int spinnyCube(HWND window,
bool mouseLook = false;
bool useFrustumCulling = true;
bool drawCellBoxes = false;
bool applyFXAA = false;
bool applyFXAA = true;
bool pointlessCopy = true;
cdc::Vector cameraPos{0, 0, 0};
///////////////////////////////////////////////////////////////////////////////////////////////
@ -704,7 +705,7 @@ int spinnyCube(HWND window,
cdc::PCDX11RenderTarget *tempRenderTarget = nullptr;
if (applyFXAA)
if (applyFXAA && !pointlessCopy)
tempRenderTarget = static_cast<cdc::PCDX11RenderTarget*>(renderDevice->dx11_createRenderTarget(
100, 100, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, 0x18, 0));
@ -712,8 +713,10 @@ int spinnyCube(HWND window,
renderDevice->beginRenderList(nullptr);
auto *scene = renderDevice->createSubScene(
&renderViewport,
applyFXAA ? tempRenderTarget : renderContext->renderTarget2C,
renderContext->depthBuffer);
tempRenderTarget ? tempRenderTarget : renderContext->renderTarget2C,
renderContext->depthBuffer,
nullptr,
nullptr);
scene->viewMatrix = viewMatrix;
cdc::OrthonormalInverse3x4(&renderViewport.viewMatrix, viewMatrix);
@ -933,23 +936,50 @@ int spinnyCube(HWND window,
}
if (applyFXAA) {
renderDevice->finishScene();
tempRenderTarget->getRenderTexture11()->createRenderTargetView();
if (pointlessCopy) {
tempRenderTarget = static_cast<cdc::PCDX11RenderTarget*>(renderDevice->dx11_createRenderTarget(
100, 100, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, 0x18, 0));
tempRenderTarget->getRenderTexture11()->createRenderTargetView();
auto *fxaaDrawable = new (renderDevice, 0) cdc::PCDX11FXAADrawable(
renderDevice,
/*quality*/ 0,
/*texture*/ tempRenderTarget->getRenderTexture(),
/*renderTarget*/ renderContext->renderTarget2C,
/*flags*/ 0,
/*sortZ*/ 0.0f);
// now draw to the real buffer
renderDevice->createSubScene(
&renderViewport,
renderContext->renderTarget2C,
renderContext->depthBuffer);
renderDevice->recordDrawable(fxaaDrawable, /*mask=*/ 0x100, 0);
auto *fxaaDrawable = new (renderDevice, 0) cdc::PCDX11FXAADrawable(
renderDevice,
/*quality*/ 0,
/*texture*/ renderContext->renderTarget2C->getRenderTexture(),
/*renderTarget*/ tempRenderTarget,
/*flags*/ 0,
/*sortZ*/ 0.0f);
renderDevice->recordDrawable(fxaaDrawable, /*mask=*/ 0x100, 0);
renderDevice->finishScene();
// restart the scene to cause a (pointless) copy
renderDevice->createSubScene(
&renderViewport,
renderContext->renderTarget2C,
renderContext->depthBuffer,
tempRenderTarget,
nullptr);
} else {
renderDevice->finishScene();
tempRenderTarget->getRenderTexture11()->createRenderTargetView();
auto *fxaaDrawable = new (renderDevice, 0) cdc::PCDX11FXAADrawable(
renderDevice,
/*quality*/ 0,
/*texture*/ tempRenderTarget->getRenderTexture(),
/*renderTarget*/ renderContext->renderTarget2C,
/*flags*/ 0,
/*sortZ*/ 0.0f);
// now draw to the real buffer
renderDevice->createSubScene(
&renderViewport,
renderContext->renderTarget2C,
renderContext->depthBuffer,
nullptr,
nullptr);
renderDevice->recordDrawable(fxaaDrawable, /*mask=*/ 0x100, 0);
}
}
renderDevice->recordDrawable(&imGuiDrawable, /*mask=*/ 0x100, /*addToParent=*/ 0);