Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 02 Oct 2010
Offline Last Active Sep 22 2015 03:56 PM

Topics I've Started

Reducing CPU usage in Enet thread

20 August 2015 - 05:06 PM

I posted this question over a year ago but didn't find a good soultion.
I use a thread which Enet is created and managed on. The whole thing boils down to 1ms latency vs 100% CPU usage.
In the networking thread I can set the timeout to 1ms, such that it will consume less than 1% of the CPU. But this causes 1ms+ latency, or if Sleep() is used inside the Enet library upto 10ms.
I want to check for new packets every 0.1ms or less, but not consume more then 10% of the CPU core. How can this be done?

UpdateSubresource on StructuredBuffer

12 August 2015 - 05:49 PM



I am having some trouble trying to update a StructuredBuffer with new data.


Currently during initialization of the application I create a CComPtr<ID3D11ShaderResourceView> pStructuredBuffer that encapsulates a CComPtr<ID3D11Buffer> pBuffer that I create first with all the proper flags. I forget about pBuffer after creating the resource view and let pBuffer go out of scope.


Later when I want to update the resource I do this:

ID3D11Resource *pBuffer;
pDeviceContext->UpdateSubresource(pBuffer, 0, 0, VectorOfStructures.data(), 0, 0);
pDeviceContext->VSSetShaderResources(0, 1, &pStructuredBuffer.p);

However I get an Unhandled exception and Visual Studio is breaks at UpdateSubresource(), I suspect it might have something to do with SrcRowPitch or SrcDepthPitch.


Unhandled exception at 0x74D83E28 (KernelBase.dll) in app.exe: 0x0000087D (parameters: 0x00000000, 0x00C1E0A4, 0x00C1D4DC).


Any clues on what I might do wrong? What should SrcRowPitch and SrcDepthPitch be if I have a vector of structures?

Memory leaks when Windows shuts down the display

06 March 2015 - 11:25 AM

I posted this in another thread but I thought it needed a thread on its own.


When Windows power saving settings turn off the display my application stops releasing resources as they normally do. This means that if the user goes AFK and when the default 20 minutes has passed, all my GPU memory allocations starts to pile up. After a while ID3D11Device::CreateBuffer returns E_OUTOFMEMORY.


I'm not sure if it is the COM smart pointers (CComPtr<ID3D11Buffer>) that stop releasing, or if it happens further down in WDDM or gpu drivers.


As you can see in the screen-shot below: the program runs stable, then when windows turns off the display the GPU memory usage spikes to max, and on the CPU side, Commit Charge builds up, if it hits 100%, ID3D11Device::CreateBuffer returns E_OUTOFMEMORY.


Any help on how to alleviate or circumvent is much appreciated.




std::atomic<DWORD> or enum class ?

14 February 2015 - 08:47 PM



I am currently using a std::atomic<DWORD> Status to keep track of what state an object is in. I need the atomic to be able to check and set the status in a thread safe manner.


I have a set of codes which the status can be set to.

enum class EnumCodes

But in order to set the Status I need to cast the enum to a DWORD or else the compiler throws a tantrum.

pObject->Status = static_cast<DWORD>(EnumCodes::LoadingError);

Could / Should I instead use an atomic of enum?

std::atomic<EnumCodes> Status;

Funky normal World transformation

07 February 2015 - 07:10 PM

Hi, I hope this has not been asked a thousand times before unsure.png


I have a weird problem when applying the World transformation to normals. I am instancing 100 cubes and applying directional light on them. Every Cube has a simple World matrix which is calculated using XMMatrixTranslation wtih varying x and z positions.


Every World matrix gets multiplied with ViewProjection and stored in another array. Both World array and WorldViewProjection arrray gets passed to the shader.


The World matrices is used for tranforming normals, and the WorldViewProjection matrices are used for transforming vertices in the vertex shader.


The first Cube gets properly lighted since XMMatrixTranslation(0.0f, 0.0f, 0.0f) returns an IdentityMatrix, I think, but the rest is not.



How directional light is supposed to look (I just used IdentityMatrix for all normals instead of World):



How it looks when using World matrices:



Can anyone spot what I'm doing wrong?