Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 3 additions & 67 deletions MarathonRecomp/gpu/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ struct PipelineState
GuestShader* vertexShader = nullptr;
GuestShader* pixelShader = nullptr;
GuestVertexDeclaration* vertexDeclaration = nullptr;
bool instancing = false;
bool zEnable = true;
bool zWriteEnable = true;
bool stencilEnable = false;
Expand Down Expand Up @@ -4463,11 +4462,7 @@ static std::unique_ptr<RenderPipeline> CreateGraphicsPipeline(const PipelineStat
auto& inputSlot = inputSlots[inputSlotIndex - 1];
inputSlot.index = inputElement.slotIndex;
inputSlot.stride = pipelineState.vertexStrides[inputElement.slotIndex];

if (pipelineState.instancing && inputElement.slotIndex != 0 && inputElement.slotIndex != 15)
inputSlot.classification = RenderInputSlotClassification::PER_INSTANCE_DATA;
else
inputSlot.classification = RenderInputSlotClassification::PER_VERTEX_DATA;
inputSlot.classification = RenderInputSlotClassification::PER_VERTEX_DATA;
}

desc.inputSlots = inputSlots;
Expand Down Expand Up @@ -4511,7 +4506,6 @@ static RenderPipeline* CreateGraphicsPipelineInRenderThread(PipelineState pipeli
" vertexShader: {}\n"
" pixelShader: {}\n"
" vertexDeclaration: {:X}\n"
" instancing: {}\n"
" zEnable: {}\n"
" zWriteEnable: {}\n"
" stencilEnable: {}\n"
Expand Down Expand Up @@ -4554,7 +4548,6 @@ static RenderPipeline* CreateGraphicsPipelineInRenderThread(PipelineState pipeli
pipelineState.vertexShader->name,
pipelineState.pixelShader != nullptr ? pipelineState.pixelShader->name : "<none>",
reinterpret_cast<size_t>(pipelineState.vertexDeclaration),
pipelineState.instancing,
pipelineState.zEnable,
pipelineState.zWriteEnable,
pipelineState.stencilEnable,
Expand Down Expand Up @@ -4956,36 +4949,6 @@ static void SetPrimitiveType(uint32_t primitiveType)
SetDirtyValue(g_dirtyStates.pipelineState, g_pipelineState.primitiveTopology, ConvertPrimitiveType(primitiveType));
}

static uint32_t CheckInstancing()
{
uint32_t indexCount = 0;

SetDirtyValue(g_dirtyStates.pipelineState, g_pipelineState.instancing, g_pipelineState.vertexDeclaration->indexVertexStream != 0);
if (g_pipelineState.instancing)
{
// Index buffer is passed as a vertex stream
indexCount = g_vertexBufferViews[g_pipelineState.vertexDeclaration->indexVertexStream].size / 4;
}

return indexCount;
}

static void UnsetInstancingStream()
{
bool dirty = false;
uint32_t index = g_pipelineState.vertexDeclaration->indexVertexStream;

SetDirtyValue(dirty, g_vertexBufferViews[index].buffer, RenderBufferReference{});
SetDirtyValue(dirty, g_vertexBufferViews[index].size, 0u);
SetDirtyValue(dirty, g_inputSlots[index].stride, 0u);

if (dirty)
{
g_dirtyStates.vertexStreamFirst = std::min<uint8_t>(g_dirtyStates.vertexStreamFirst, index);
g_dirtyStates.vertexStreamLast = std::max<uint8_t>(g_dirtyStates.vertexStreamLast, index);
}
}

static void DrawPrimitive(GuestDevice* device, uint32_t primitiveType, uint32_t startVertex, uint32_t primitiveCount)
{
LocalRenderCommandQueue queue;
Expand All @@ -5006,26 +4969,10 @@ static void ProcDrawPrimitive(const RenderCommand& cmd)

SetPrimitiveType(args.primitiveType);

uint32_t indexCount = CheckInstancing();
if (indexCount > 0)
{
auto& vertexBufferView = g_vertexBufferViews[g_pipelineState.vertexDeclaration->indexVertexStream];

SetDirtyValue(g_dirtyStates.indices, g_indexBufferView.buffer, vertexBufferView.buffer);
SetDirtyValue(g_dirtyStates.indices, g_indexBufferView.size, vertexBufferView.size);
SetDirtyValue(g_dirtyStates.indices, g_indexBufferView.format, RenderFormat::R32_UINT);

UnsetInstancingStream();
}

FlushRenderStateForRenderThread();

auto& commandList = g_commandLists[g_frame];

if (indexCount > 0)
commandList->drawIndexedInstanced(indexCount, args.primitiveCount / indexCount, 0, 0, 0);
else
commandList->drawInstanced(args.primitiveCount, 1, args.startVertex, 0);
commandList->drawInstanced(args.primitiveCount, 1, args.startVertex, 0);
}

static void DrawIndexedPrimitive(GuestDevice* device, uint32_t primitiveType, int32_t baseVertexIndex, uint32_t startIndex, uint32_t primCount)
Expand All @@ -5047,10 +4994,6 @@ static void ProcDrawIndexedPrimitive(const RenderCommand& cmd)
{
const auto& args = cmd.drawIndexedPrimitive;

uint32_t indexCount = CheckInstancing();
if (indexCount > 0)
UnsetInstancingStream();

SetPrimitiveType(args.primitiveType);
FlushRenderStateForRenderThread();

Expand Down Expand Up @@ -5078,10 +5021,6 @@ static void ProcDrawPrimitiveUP(const RenderCommand& cmd)
{
const auto& args = cmd.drawPrimitiveUP;

uint32_t indexCount = CheckInstancing();
if (indexCount > 0)
UnsetInstancingStream();

SetPrimitiveType(args.primitiveType);
SetDirtyValue(g_dirtyStates.pipelineState, g_pipelineState.vertexStrides[0], uint8_t(args.vertexStreamZeroStride));

Expand All @@ -5093,7 +5032,7 @@ static void ProcDrawPrimitiveUP(const RenderCommand& cmd)
g_inputSlots[0].stride = args.vertexStreamZeroStride;
g_dirtyStates.vertexStreamFirst = 0;

indexCount = 0;
uint32_t indexCount = 0;

if (args.primitiveType == D3DPT_QUADLIST)
indexCount = g_quadIndexData.prepare(args.primitiveCount);
Expand Down Expand Up @@ -6809,7 +6748,6 @@ struct CompilationArgs
bool hasMoreThanOneBone{};
bool velocityMapQuickStep{};
bool objectIcon{};
bool instancing{};
};

enum class MeshLayer
Expand Down Expand Up @@ -7873,7 +7811,6 @@ class SDLEventListenerForPSOCaching : public SDLEventListener
"{},"
"{},"
"{},"
"{},"
"RenderBlend::{},"
"RenderBlend::{},"
"RenderCullMode::{},"
Expand Down Expand Up @@ -7908,7 +7845,6 @@ class SDLEventListenerForPSOCaching : public SDLEventListener
pipelineState.vertexShader->shaderCacheEntry->hash,
pipelineState.pixelShader != nullptr ? pipelineState.pixelShader->shaderCacheEntry->hash : 0,
pipelineState.vertexDeclaration->hash,
pipelineState.instancing,
pipelineState.zEnable,
pipelineState.zWriteEnable,
pipelineState.stencilEnable,
Expand Down
Loading