Sign in to follow this  
Tape_Worm

DX11 [SlimDX][DX11] Device object not being released?

Recommended Posts

Ok, so I'm encountering some weirdness with SlimDX + D3D11/DXGI.

I load up my app, switch to full screen mode (I'm doing this manually in code because I think there was an issue with WinForms and DXGI not handling the ALT+ENTER properly, no idea if it's been corrected), click on on textpad (or any other application) outside of the full screen app (the extra application is on another monitor), and I do this a couple of times.

I get this when I close the app:
[code]Total of 0 objects still alive.
D3D11: WARNING: Live Device: Name="ATI Radeon HD 4550 D3D11Device", Addr=0x000000000047EF00, ExtRef=1 [ STATE_CREATION WARNING #2097297: LIVE_DEVICE ]
D3D11: WARNING: Live Query: Name="unnamed", Addr=0x000000001E102CD0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097280: LIVE_QUERY ]
D3D11: WARNING: Live Sampler: Name="unnamed", Addr=0x000000001E102A20, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097268: LIVE_SAMPLER ]
D3D11: WARNING: Live RasterizerState: Name="unnamed", Addr=0x000000001E102790, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097277: LIVE_RASTERIZERSTATE ]
D3D11: WARNING: Live DepthStencilState: Name="unnamed", Addr=0x000000001E102580, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097274: LIVE_DEPTHSTENCILSTATE ]
D3D11: WARNING: Live BlendState: Name="unnamed", Addr=0x000000001E1023D0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097271: LIVE_BLENDSTATE ]
D3D11: WARNING: Live Context: Name="unnamed", Addr=0x000000001E0B0B80, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097226: LIVE_CONTEXT ]
D3D11: WARNING: Live Device Child Summary: Device Addr=0x000000000047EF00
Using ID3D11Debug::ReportLiveDeviceObjects with D3D11_RLDO_DETAIL will help drill into object lifetimes. Objects with ExtRef=0 and IntRef=0 will be eventually destroyed through typical Immediate Context usage. However, if the application requires these objects to be destroyed sooner, ClearState followed by Flush on the Immediate Context will realize their destruction.
Live Context: 1
Live Buffer: 0
Live Texture1D: 0
Live Texture2D: 0
Live Texture3D: 0
Live ShaderResourceView: 0
Live RenderTargetView: 0
Live DepthStencilView: 0
Live VertexShader: 0
Live GeometryShader: 0
Live PixelShader: 0
Live InputLayout: 0
Live Sampler: 1
Live BlendState: 1
Live DepthStencilState: 1
Live RasterizerState: 1
Live Query: 1
Live Predicate: 0
Live Counter: 0
Live CommandList: 0
Live HullShader: 0
Live DomainShader: 0
Live ClassInstance: 0
Live ClassLinkage: 0
Live ComputeShader: 0
Live UnorderedAccessView: 0
[ STATE_CREATION WARNING #2097298: LIVE_OBJECT_SUMMARY ]
[/code]


I've noted that there's an external reference to my D3D device object (ExtRef=1), but I'm absolutely certain I've disposed of the device object before the app closes. The weird thing is, if I ALT+ENTER back and forth many times between my application and another, it exits cleanly. Also, SlimDX is reporting that I have no outstanding references. If I run the application and just quit, it exits cleanly, if I run it, switch to full screen, it exits cleanly. It appears to only happen when I've clicked on another application outside of the window.

I'm at a loss as to why this could be happening. Any suggestions?

Share this post


Link to post
Share on other sites
Hope the following helps
I'm assuming Device.ComPointer is an address.


When you call Device.Dispose(),
1. check that Disposed is true
2. check its ComPointer and see if it matches
a. the ComPointer of the device you originally created
b. the ComPointer of the device it's warning about

Share this post


Link to post
Share on other sites
[quote name='jameszhao00' timestamp='1318872341' post='4873539']
Hope the following helps
I'm assuming Device.ComPointer is an address.


When you call Device.Dispose(),
1. check that Disposed is true
2. check its ComPointer and see if it matches
a. the ComPointer of the device you originally created
b. the ComPointer of the device it's warning about
[/quote]

I have confirmed that the pointers are the same, and that the device was not previously disposed. It is still messing up.

Share this post


Link to post
Share on other sites
Some extra info:

I've tested by doing absolutely nothing, no rendering, not even clearing the screen. Just creating a device, and a swap chain. That's it, and I -still- get this popping up. I'm wondering if it's not a SlimDX issue or a driver problem (I think that'd be pretty unlikely)? I walked through my code one line at a time, and it is indeed calling the Dispose method on the device object.


Maybe Promit or Mike can chime in?

Share this post


Link to post
Share on other sites
Hmm.

Try calling the following function repeatedly around your mode switching code

[code]int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}
[/code]
and see if the reported ref counts matches your expectations / agrees with the non-broken situation.

Share this post


Link to post
Share on other sites
[quote name='Tape_Worm' timestamp='1318879587' post='4873593']
Some extra info:

I've tested by doing absolutely nothing, no rendering, not even clearing the screen. Just creating a device, and a swap chain. That's it, and I -still- get this popping up. I'm wondering if it's not a SlimDX issue or a driver problem (I think that'd be pretty unlikely)? I walked through my code one line at a time, and it is indeed calling the Dispose method on the device object.


Maybe Promit or Mike can chime in?
[/quote]

Actually, I lied a little here. I completely forgot that I'm also creating a render target view as well. However, I am certain that I'm disposing it as my own logging shows the object being created and disposed every time. I'm going to disable it and see what happens.

Share this post


Link to post
Share on other sites
[quote name='Tape_Worm' timestamp='1318883059' post='4873617']
[quote name='Tape_Worm' timestamp='1318879587' post='4873593']
Some extra info:

I've tested by doing absolutely nothing, no rendering, not even clearing the screen. Just creating a device, and a swap chain. That's it, and I -still- get this popping up. I'm wondering if it's not a SlimDX issue or a driver problem (I think that'd be pretty unlikely)? I walked through my code one line at a time, and it is indeed calling the Dispose method on the device object.


Maybe Promit or Mike can chime in?
[/quote]

Actually, I lied a little here. I completely forgot that I'm also creating a render target view as well. However, I am certain that I'm disposing it as my own logging shows the object being created and disposed every time. I'm going to disable it and see what happens.
[/quote]

So, I commented out the code for the render target view, and it stopped messing up the reference count. However, I uncommented the code (1 line at a time, just to see which line might have been causing the issue) and even with the completely uncommented code, it still works. I am baffled. [img]http://public.gamedev.net/public/style_emoticons/default/dry.gif[/img]

I'd like to know why it messed up and said that the device wasn't released (when it definitely was) or else I'm sure it'll bite me in the ass when I'm least suspecting or prepared for it.

Update:
So, I just tried my code from earlier today (which was showing the issue) and now, mysteriously, it too is exiting cleanly. [img]http://public.gamedev.net/public/style_emoticons/default/huh.gif[/img] This just gets weirder and weirder. Edited by Tape_Worm

Share this post


Link to post
Share on other sites
[quote name='jameszhao00' timestamp='1318880299' post='4873597']
Hmm.

Try calling the following function repeatedly around your mode switching code

[code]int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}
[/code]
and see if the reported ref counts matches your expectations / agrees with the non-broken situation.
[/quote]

So I tried out your code to check the refcount. When I create the D3DDevice, it's got a count of 1 (naturally), and just before I destroy the device, it's got a count of 2, which is kind of odd. I only have a call to CreateSwapChain and the code to create the D3DDevice, so something's amiss. It claims the extra reference is an external reference, but I really have absolutely nothing else in here that's adding to the ref count. It just makes no sense.

Thanks for your help.

Share this post


Link to post
Share on other sites
[quote name='Tape_Worm' timestamp='1318900097' post='4873706']
[quote name='jameszhao00' timestamp='1318880299' post='4873597']
Hmm.

Try calling the following function repeatedly around your mode switching code

[code]int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}
[/code]
and see if the reported ref counts matches your expectations / agrees with the non-broken situation.
[/quote]

So I tried out your code to check the refcount. When I create the D3DDevice, it's got a count of 1 (naturally), and just before I destroy the device, it's got a count of 2, which is kind of odd. I only have a call to CreateSwapChain and the code to create the D3DDevice, so something's amiss. It claims the extra reference is an external reference, but I really have absolutely nothing else in here that's adding to the ref count. It just makes no sense.

Thanks for your help.
[/quote]

Locating where it broke:

Go into PIX. Select "A replayable Direct3D call stream". Run your app. Break your app. Then in PIX, find (binary search :P) the exact call site where "D3D11 Device" (in the Objects window) has unexpected "App Refs".

Note: To actually view the app refs, for some reason you have to a) select a random frame b) select render. Make sure you're in the Mesh or Render tab when selecting different calls (to force refresh)

Share this post


Link to post
Share on other sites
[quote name='jameszhao00' timestamp='1318902367' post='4873714']
[quote name='Tape_Worm' timestamp='1318900097' post='4873706']
[quote name='jameszhao00' timestamp='1318880299' post='4873597']
Hmm.

Try calling the following function repeatedly around your mode switching code

[code]int GetRefCount(ComObject co)
{
Marshal.AddRef(co.ComPtr);
return Marshal.Release(co.ComPtr);
}
[/code]
and see if the reported ref counts matches your expectations / agrees with the non-broken situation.
[/quote]

So I tried out your code to check the refcount. When I create the D3DDevice, it's got a count of 1 (naturally), and just before I destroy the device, it's got a count of 2, which is kind of odd. I only have a call to CreateSwapChain and the code to create the D3DDevice, so something's amiss. It claims the extra reference is an external reference, but I really have absolutely nothing else in here that's adding to the ref count. It just makes no sense.

Thanks for your help.
[/quote]

Locating where it broke:

Go into PIX. Select "A replayable Direct3D call stream". Run your app. Break your app. Then in PIX, find (binary search :P) the exact call site where "D3D11 Device" (in the Objects window) has unexpected "App Refs".

Note: To actually view the app refs, for some reason you have to a) select a random frame b) select render. Make sure you're in the Mesh or Render tab when selecting different calls (to force refresh)
[/quote]

Thanks for that. I've always had a hell of a time getting PIX to behave itself with .NET apps, and it was a little better tonight.

So, here's what my logging (and your ref counter code) told me before it destroyed the ID3D11Device:
[10/17/2011 08:24:04 PM] D3D Device Ref Count #: 3

So, according to that, there were 3 references to the device.

Then I poured through the calls in PIX, and I found a very different story. The AppRefs never went above 2, and always fell back to 1 (until the final Dispose call on the device object, which then said there were no more references). But, when I turn on the return result I can see in each AddRef/Release from the reference counting code that the values are higher. In some cases, it returns as high as 5. I understand these could be internal references, and as such, and my releasing of my only reference to the ID3D11Device is only going to decrement the count by 1, leaving those other references.

Share this post


Link to post
Share on other sites
So, I stripped everything down to a very minimal application and switching between applications still gives me an unreleased device object.

The funny thing is, if I ALT+TAB back and forth this does not happen when I close. If I click on an external application and go back to my application (multiple times) it gives me the warning about the unreleased device object when I close.

Again, here's the warning for anyone who might have an inkling as to what's going on here:
[code]

Total of 0 objects still alive.
D3D11: WARNING: Live Device: Name="unnamed", Addr=0x00000000005DDEE0, ExtRef=1 [ STATE_CREATION WARNING #2097297: LIVE_DEVICE ]
D3D11: WARNING: Live Texture2D: Name="unnamed", Addr=0x000000001DAF4EC0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097235: LIVE_TEXTURE2D ]
D3D11: WARNING: Live RenderTargetView: Name="unnamed", Addr=0x000000001DAF9B00, ExtRef=0, IntRef=0 [ STATE_CREATION WARNING #2097244: LIVE_RENDERTARGETVIEW ]
D3D11: WARNING: Live Texture2D: Name="unnamed", Addr=0x000000001DAF43B0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097235: LIVE_TEXTURE2D ]
D3D11: WARNING: Live Query: Name="unnamed", Addr=0x000000001DAF2190, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097280: LIVE_QUERY ]
D3D11: WARNING: Live Sampler: Name="unnamed", Addr=0x000000001DAF1E00, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097268: LIVE_SAMPLER ]
D3D11: WARNING: Live RasterizerState: Name="unnamed", Addr=0x000000001DAF1A80, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097277: LIVE_RASTERIZERSTATE ]
D3D11: WARNING: Live DepthStencilState: Name="unnamed", Addr=0x000000001DAF1730, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097274: LIVE_DEPTHSTENCILSTATE ]
D3D11: WARNING: Live BlendState: Name="unnamed", Addr=0x000000001DAF11A0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097271: LIVE_BLENDSTATE ]
D3D11: WARNING: Live Context: Name="unnamed", Addr=0x000000001DAA00B0, ExtRef=0, IntRef=1 [ STATE_CREATION WARNING #2097226: LIVE_CONTEXT ]
D3D11: WARNING: Live Device Child Summary: Device Addr=0x00000000005DDEE0
Using ID3D11Debug::ReportLiveDeviceObjects with D3D11_RLDO_DETAIL will help drill into object lifetimes. Objects with ExtRef=0 and IntRef=0 will be eventually destroyed through typical Immediate Context usage. However, if the application requires these objects to be destroyed sooner, ClearState followed by Flush on the Immediate Context will realize their destruction.
Live Context: 1
Live Buffer: 0
Live Texture1D: 0
Live Texture2D: 2
Live Texture3D: 0
Live ShaderResourceView: 0
Live RenderTargetView: 1
Live DepthStencilView: 0
Live VertexShader: 0
Live GeometryShader: 0
Live PixelShader: 0
Live InputLayout: 0
Live Sampler: 1
Live BlendState: 1
Live DepthStencilState: 1
Live RasterizerState: 1
Live Query: 1
Live Predicate: 0
Live Counter: 0
Live CommandList: 0
Live HullShader: 0
Live DomainShader: 0
Live ClassInstance: 0
Live ClassLinkage: 0
Live ComputeShader: 0
Live UnorderedAccessView: 0
[ STATE_CREATION WARNING #2097298: LIVE_OBJECT_SUMMARY ]
[/code]

I'm about to give up and accept it as part of life, I really hope leaving this this doesn't cause any major issues in the future.

Share this post


Link to post
Share on other sites
I'm not using slimdx but I have the same issue (exact same error message) and I did a pix capture of it.
It happens when you close a full screen application. It doesn't show any warning when in window mode.
.
Did anyone find a solution for this?

[code]
// Initialization
4 D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 2, NULL, 0, 7, 0x0041FD88, 0x0041FDC4 --> 0x05566820, 0x0041FDC8 --> 0x05566070, NULL, 0x0041FDCC --> 0x055D9C78) 1262568822
5 CreateObject(D3D11 Device, 0x05566070) 1651416894
6 CreateObject(DXGI Factory, 0x05566718) 1651427760
7 CreateObject(DXGI Adapter, 0x05566768) 1651429571
8 CreateObject(DXGI Device, 0x055667C0) 1651431081
9 CreateObject(DXGI Swap Chain, 0x05566820) 1651432590
10 CreateObject(DXGI Surface, 0x055668B8) 1651434703
11 CreateObject(D3D11 Texture2D, 0x05566918) 1651437721
12 CreateObject(D3D11 Device Context, 0x055D9C78) 1651451305
13 <0x05566820> IDXGISwapChain::GetBuffer(0, IID_ID3D11Texture2D, 0x0041F67C --> 0x05566918) 1651467907
14 <0x05566070> ID3D11Device::CreateRenderTargetView(0x05566918, NULL, 0x0041F654 --> 0x05566DB8) 1651472133
15 CreateObject(D3D11 Render Target View, 0x05566DB8) 1651537031
16 <0x05566918> ID3D11Texture2D::AddRef() 1651547596
17 <0x05566DB8> ID3D11RenderTargetView::AddRef() 1651549407
18 <0x05566918> ID3D11Texture2D::Release() 1651550614
19 <0x05566DB8> ID3D11RenderTargetView::Release() 1651551520
20 <0x05566DB8> ID3D11RenderTargetView::AddRef() 1651557557

// Update frames ...
21 <0x05566820> IDXGISwapChain::GetFullscreenState(0x0041F778, NULL) 1683438579
22 <0x055D9C78> ID3D11DeviceContext::OMSetRenderTargets(1, 0x05737AA8 --> { 0x05566DB8 }, NULL) 1683450351
23 <0x055D9C78> ID3D11DeviceContext::RSSetViewports(1, 0x0041F52C) 1683475405
24 <0x05566820> IDXGISwapChain::Present(0, 0) 1728516577

...
// Uninitialization
81 <0x05566918> ID3D11Texture2D::Release() 1844018799
82 <0x05566DB8> ID3D11RenderTargetView::Release() 1844024534
83 <0x05566DB8> ID3D11RenderTargetView::Release() 1844029062
84 <0x055D9C78> ID3D11DeviceContext::OMSetRenderTargets(0, NULL, NULL) 1844036306
85 DestroyObject(D3D11 Render Target View, 0x05566DB8) 1844043853
86 <0x055D9C78> ID3D11DeviceContext::Release() 1844049286
87 <0x05566820> IDXGISwapChain::Release() 1844051701
88 DestroyObject(DXGI Swap Chain, 0x05566820) 1844260884
89 DestroyObject(DXGI Surface, 0x055668B8) 1844267223
90 DestroyObject(D3D11 Texture2D, 0x05566918) 1844269940
91 <0x05566070> ID3D11Device::Release() 1844274468
92 DestroyObject(D3D11 Device, 0x05566070) 1844276581
93 DestroyObject(D3D11 Device Context, 0x055D9C78) 1844278694
94 DestroyObject(DXGI Device, 0x055667C0) 1844280807
95 DestroyObject(DXGI Adapter, 0x05566768) 1844282919
[/code]

Seems like the DXGI Factory is not destroyed... I use CreateDeviceAndSwapChain, I do not manage the Factory.
I tried calling "ClearState" and "Flush" just before I release the context but "Flush" crash my application (again only in fullscreen).

Share this post


Link to post
Share on other sites
[quote name='Shnoutz' timestamp='1321760447' post='4885785']
I fixed my problem by calling "SetFullscreenState(false, NULL);" just before releasing the swap chain. Not sure if its what I should have done in the first place but it kinda makes sense.
[/quote]

Yep, Microsoft [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174537(v=vs.85).aspx"]recommends you do that before destroying a swap chain[/url]:
[font="Arial"][color=#2A2A2A][/color][quote][color=#2A2A2A]If the swap chain is in full-screen mode, before you release it you must use [/color][url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174579(v=vs.85).aspx"][b]SetFullscreenState[/b][/url][color=#2A2A2A] to switch it to windowed mode. For more information about releasing a swap chain, see the "Destroying a Swap Chain" section of [/color][url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb205075(v=vs.85).aspx"]DXGI Overview[/url][color=#2A2A2A].[/color][/quote][color=#2A2A2A][/color][/font]
[font="Arial"]
[/font]
[font="Arial"]However, that didn't help with my issue. I just said to hell with it and moved on.[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628284
    • Total Posts
      2981829
  • Similar Content

    • By GreenGodDiary
      I'm attempting to implement some basic post-processing in my "engine" and the HLSL part of the Compute Shader and such I think I've understood, however I'm at a loss at how to actually get/use it's output for rendering to the screen.
      Assume I'm doing something to a UAV in my CS:
      RWTexture2D<float4> InputOutputMap : register(u0); I want that texture to essentially "be" the backbuffer.
       
      I'm pretty certain I'm doing something wrong when I create the views (what I think I'm doing is having the backbuffer be bound as render target aswell as UAV and then using it in my CS):
       
      DXGI_SWAP_CHAIN_DESC scd; ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); scd.BufferCount = 1; scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_UNORDERED_ACCESS; scd.OutputWindow = wndHandle; scd.SampleDesc.Count = 1; scd.Windowed = TRUE; HRESULT hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &scd, &gSwapChain, &gDevice, NULL, &gDeviceContext); // get the address of the back buffer ID3D11Texture2D* pBackBuffer = nullptr; gSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); // use the back buffer address to create the render target gDevice->CreateRenderTargetView(pBackBuffer, NULL, &gBackbufferRTV); // set the render target as the back buffer CreateDepthStencilBuffer(); gDeviceContext->OMSetRenderTargets(1, &gBackbufferRTV, depthStencilView); //UAV for compute shader D3D11_UNORDERED_ACCESS_VIEW_DESC uavd; ZeroMemory(&uavd, sizeof(uavd)); uavd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; uavd.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; uavd.Texture2D.MipSlice = 1; gDevice->CreateUnorderedAccessView(pBackBuffer, &uavd, &gUAV); pBackBuffer->Release();  
      After I render the scene, I dispatch like this:
      gDeviceContext->OMSetRenderTargets(0, NULL, NULL); m_vShaders["cs1"]->Bind(); gDeviceContext->CSSetUnorderedAccessViews(0, 1, &gUAV, 0); gDeviceContext->Dispatch(32, 24, 0); //hard coded ID3D11UnorderedAccessView* nullview = { nullptr }; gDeviceContext->CSSetUnorderedAccessViews(0, 1, &nullview, 0); gDeviceContext->OMSetRenderTargets(1, &gBackbufferRTV, depthStencilView); gSwapChain->Present(0, 0); Worth noting is the scene is rendered as usual, but I dont get any results from the CS (simple gaussian blur)
      I'm sure it's something fairly basic I'm doing wrong, perhaps my understanding of render targets / views / what have you is just completely wrong and my approach just makes no sense.

      If someone with more experience could point me in the right direction I would really appreciate it!

      On a side note, I'd really like to learn more about this kind of stuff. I can really see the potential of the CS aswell as rendering to textures and using them for whatever in the engine so I would love it if you know some good resources I can read about this!

      Thank you <3
       
      P.S I excluded the .hlsl since I cant imagine that being the issue, but if you think you need it to help me just ask

      P:P:S. As you can see this is my first post however I do have another account, but I can't log in with it because gamedev.net just keeps asking me to accept terms and then logs me out when I do over and over
    • By noodleBowl
      I was wondering if anyone could explain the depth buffer and the depth stencil state comparison function to me as I'm a little confused
      So I have set up a depth stencil state where the DepthFunc is set to D3D11_COMPARISON_LESS, but what am I actually comparing here? What is actually written to the buffer, the pixel that should show up in the front?
      I have these 2 quad faces, a Red Face and a Blue Face. The Blue Face is further away from the Viewer with a Z index value of -100.0f. Where the Red Face is close to the Viewer with a Z index value of 0.0f.
      When DepthFunc is set to D3D11_COMPARISON_LESS the Red Face shows up in front of the Blue Face like it should based on the Z index values. BUT if I change the DepthFunc to D3D11_COMPARISON_LESS_EQUAL the Blue Face shows in front of the Red Face. Which does not make sense to me, I would think that when the function is set to D3D11_COMPARISON_LESS_EQUAL the Red Face would still show up in front of the Blue Face as the Z index for the Red Face is still closer to the viewer
      Am I thinking of this comparison function all wrong?
      Vertex data just in case
      //Vertex date that make up the 2 faces Vertex verts[] = { //Red face Vertex(Vector4(0.0f, 0.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(100.0f, 100.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(100.0f, 0.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(0.0f, 0.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(0.0f, 100.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), Vertex(Vector4(100.0f, 100.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)), //Blue face Vertex(Vector4(0.0f, 0.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(100.0f, 100.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(100.0f, 0.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(0.0f, 0.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(0.0f, 100.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), Vertex(Vector4(100.0f, 100.0f, -100.0f), Color(0.0f, 0.0f, 1.0f)), };  
    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By turanszkij
      If I do a buffer update with MAP_NO_OVERWRITE or MAP_DISCARD, can I just write to the buffer after I called Unmap() on the buffer? It seems to work fine for me (Nvidia driver), but is it actually legal to do so? I have a graphics device wrapper and I don't want to expose Map/Unmap, but just have a function like void* AllocateFromRingBuffer(GPUBuffer* buffer, uint size, uint& offset); This function would just call Map on the buffer, then Unmap immediately and then return the address of the buffer. It usually does a MAP_NO_OVERWRITE, but sometimes it is a WRITE_DISCARD (when the buffer wraps around). Previously I have been using it so that the function expected the data upfront and would copy to the buffer between Map/Unmap, but now I want to extend functionality of it so that it would just return an address to write to.
    • By mister345
      Trying to write a multitexturing shader in DirectX11 - 3 textures work fine, but adding 4th gets sampled as black!
      Could you please look at the textureClass.cpp line 79? - I'm guess its D3D11_TEXTURE2D_DESC settings are wrong, 
      but no idea how to set it up right. I tried changing ArraySize from 1 to 4, but does nothing. If thats not the issue, please look
      at the LightShader_ps - maybe doing something wrong there? Otherwise, no idea.
          // Setup the description of the texture.
          textureDesc.Height = height;
          textureDesc.Width = width;
          textureDesc.MipLevels = 0;
          textureDesc.ArraySize = 1;
          textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
          textureDesc.SampleDesc.Count = 1;
          textureDesc.SampleDesc.Quality = 0;
          textureDesc.Usage = D3D11_USAGE_DEFAULT;
          textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
          textureDesc.CPUAccessFlags = 0;
          textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
      Please help, thanks.
      https://github.com/mister51213/DirectX11Engine/blob/master/DirectX11Engine/Texture.cpp
       
  • Popular Now