# OpenGL D3D12 atrocious performance

This topic is 1068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm getting about 10 FPS with only about 20 draw calls of very small meshes.

Clearly I'm doing something very very wrong.

Is there an issue with populating a single command list to draw 20 items?  I figured even if that isn't optimal, it shouldn't be THIS terrible.  At this point my iPad running OpenGL ES is outperforming my d3d12 engine by a massive margin.

The following code runs before most of my draw calls to set up necessary state:

Sorry for the messed up tab spacings

	void CoreStateMachine::prepareToDraw()
{
auto cl = continueRenderingCommands();
cl->SetGraphicsRootSignature(rootSignature.Get());

//prepare any buffers required by current shader program
auto prog = currentProgram;

if(prog)
{
if(!prog->globalCBuffer)
{
prog->globalCBuffer = make_shared<BufferArray>();
prog->globalCBufferDirty = true;
}
else
{
//this should be cleaned up at some point
preserveResourceUntilRenderComplete(prog->globalCBuffer->buffers[0]);
prog->globalCBuffer = make_shared<BufferArray>();
prog->globalCBufferDirty = true;
}

if(prog->globalCBufferDirty)
{
prog->globalCBuffer->provideData(0, prog->globalCBufferSize, prog->globalCBufferData, BufferArray::UT_DYNAMIC);
prog->globalCBufferDirty = false;
}

}

auto currentVA = VertexArray::current();
assert(currentVA != nullptr);
currentVA->prepareForDraw();

if(descriptorHeapsChanged)
{
ID3D12DescriptorHeap *descHeaps[] = { cbSrvHeaps[descriptorHeapIndex]->get(), samplerHeaps[descriptorHeapIndex]->get() };
cl->SetDescriptorHeaps(ARRAYSIZE(descHeaps), descHeaps);
descriptorHeapsChanged = false;
}

//might be smarter to set this up earlier if I can.. not sure what the tradeoff is here
if(pipelineState)
{
preserveResourceUntilRenderComplete(pipelineState);
pipelineState = nullptr;
}
ThrowIfFailed(device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)));

cl->SetPipelineState(pipelineState.Get());

if(descriptorTablesChanged)
{
cl->SetGraphicsRootDescriptorTable(0, cbSrvHeaps[descriptorHeapIndex]->hGPU(textureTableIndex));
cl->SetGraphicsRootDescriptorTable(1, samplerHeaps[descriptorHeapIndex]->hGPU(textureTableIndex));
descriptorTablesChanged = false;
}
}


##### Share on other sites

Thanks.   You're so right.  I just came to this.  My arch isn't setup well for caching PSOs but after refactoring some stuff, fingers crossed, I'll get some good draw call performance.

##### Share on other sites

omfg.  here's another tip.  DON'T test performance with debug builds.  I forgot about how bad the performance of MSVC generated debug builds are.  Doing a release build shot the performance of the whole system up to max FPS

Spent the last hour chasing around a phantom

##### Share on other sites

omfg.  here's another tip.  DON'T test performance with debug builds.  I forgot about how bad the performance of MSVC generated debug builds are.  Doing a release build shot the performance of the whole system up to max FPS

Spent the last hour chasing around a phantom

I wrote a massive nest of inter-related entities involving thousands of STL containers and a half-assed messaging/scheduling system for school once. The time to simulate a single day in debug was about 2 minutes. The time in release was about 10 seconds.

##### Share on other sites

It may be time to give up on d3d12.  My opengl system massively outperforms it with a drastically simpler architecture, even on a freaking ipad.  I thought I'd be able to get performance gains without dicking around too much - that was the appeal of d3d12 and the coming vulkan to me.  But man... 7 days in a row of staying up til 2am... and I still don't have it.  This just plainly is not worth it for me.

My system changes "uniform" global constants very often and at unpredictable times.  At a high level, the kind of "precomputation" that d3d12 would need to be fast just isnt there.  It feels like instanced rendering all over again.  I can't seem to find a way to efficiently copy the needed cbuffer data before draw calls in a way that doesn't hurt performance.

I know my code is suboptimal, but I expected to outperform opengl at the very least with this kind of baseline.

very dissapointing...

##### Share on other sites

Without trying to be too dismissive of your technical abilities, I feel pretty confident in saying that the fault probably lies at your door rather than any shortcomings in the API.

The ability to rapidly "map" and set new constants very quickly is one of the key areas that has become a lot faster in D3D12. The simplest scheme to be able efficiently update constants is simply to allocate two chunks of memory, each large enough to hold all the constants that need to be written for a single frame. You can persistently map a buffer for the lifetime of the application and need only memcpy your constants to a monotonically increasing address during the frame before switching to the other of the two buffers for the following frame.

Perhaps you could explain how you've implemented constant updates?

##### Share on other sites

It may be time to give up on d3d12.  My opengl system massively outperforms it with a drastically simpler architecture, even on a freaking ipad.  I thought I'd be able to get performance gains without dicking around too much - that was the appeal of d3d12 and the coming vulkan to me.

This is very important right here. D3D12, Vulkan (and Mantle) do not exist to make a programmer's life easier, they exist to get the most out of your hardware when you need it, at the cost of the developer having to take on a lot more work to get the rendering side of your application in a stable state.

If you can comfortably do whatever your application needs to do with OpenGL/D3D11, then by all means keep using those APIs; the new generation of APIs is not meant as a replacement for these, but as an alternative.

If you feel that your application can't get to the point where you want it to be because the runtime itself is holding you back then you'll want to spend your time getting intimate with D3D12 or Vulkan.

Remember that these new APIs are not a magic wand you can wave at your application to suddenly make things run faster (even though Microsoft's marketing department would like you to believe that), nor do they magically push your GPU into overdrive so it can suddenly process a lot more data. These APIs were designed by and for those people who needed to push things to the limit and those people who felt confident enough in their knowledge of the inner workings of both graphics hardware and modern rendering engines to be able to make better low level decisions than any D3D11/OpenGL driver ever could.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
19
4. 4
5. 5
gaxio
13

• 17
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631730
• Total Posts
3001917
×