Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 23 Mar 2013
Offline Last Active Today, 12:36 PM

Posts I've Made

In Topic: Resource barrier pre and post states

26 April 2016 - 03:55 PM

Subresources can be in different states, but the rules still apply when setting resource barriers in that the before and after states must be correct.  So for example, you could set mip level 0 to a shader resource and mip level 1 as a render target.  See the documentation for D3D12_RESOURCE_TRANSITION_BARRIER, specifically the Subresource member.

In Topic: [D3D12] About CommandList, CommandQueue and CommandAllocator

20 April 2016 - 06:24 PM

You can definitely re-use command lists, as well as command allocators, albeit at different paces.


You can think of a command list as providing the interface to write instructions to the command allocator.  The command allocator is basically just a chunk of memory that lives somewhere.  It doesn't really matter exactly where - that's for the driver implementer to decide.  When you submit a command list to the command queue, you're basically saying "this is the next chunk of work for the GPU to complete and here's the chunk of memory that contains all the instructions".  Even if the GPU immediately takes that work on (it probably won't), you still need that chunk of memory containing the instructions to be available the entire time they're being processed and executed.


So for command lists, you can reset them as soon as you have submitted them to the command queue and immediately begin to reuse them, because all you're really resetting is the command allocator they're using.  However, you must not reset the command allocator that's just been submitted until you are completely sure that all GPU work has completed.  Once you're sure the GPU has finished working on the tasks submitted to it, then you're free to cycle back and reset/reuse that allocator.


I'd recommend searching this site for ID3D12Fence.  I'm sure I've seen a few posts over the past few months that have touched on this topic and show how to synchronize command list and allocator usage across multiple frames.  To get you started, though, you'll need to think in terms of having enough allocators to cover however many frames of latency you'll be working with.

In Topic: [DX12] Constant Buffer Packing

07 February 2016 - 09:31 AM

You seem to have discovered for yourself, and Krzysztof mentioned, how arrays are stored in HLSL constant buffers.  A possible solution to this would be to just halve your sample count and use the full float4 for storage.  Your example would turn into:

static const int SampleCount = 64;

struct OffsetData
    float4 Samples[SampleCount];

Then just index into it for the value you want:

for(uint i = 0; i < SampleCount; ++i)
	for(uint j = 0; j < 4; ++j)

		float currentDataPoint = Samples[i][j];

You can update that loop to extract the float2 value if that's what you're after, the approach is essentially the same.


Edit:  Here's some documentation.  It's for SM4, but I'm almost positive it hasn't changed since https://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx

In Topic: [D3D12] Command Allocator / Command List usage

23 January 2016 - 07:18 PM

It's OK to reset the command list immediately after submitting it as long as you use a different allocator or wait for a GPU signal that the submitted work has completed.

ID3D12CommandAllocator* pAlloc1, pAlloc2;
ID3D12GraphicsCommandList* pCmdList;

// later on
pCmdList->Reset(pAlloc1, nullptr);
// record some commands
pCommandQueue->ExecuteCommandLists(1, &pCmdList);
pCommandQueue->Signal(pFence, fenceValue);

// now you can reset the command list, but use pAlloc2 since pAlloc1 will still be executing
pCmdList->Reset(pAlloc2, nullptr);

After submitting the command list the second time (after recording into pAlloc2), you need to check the fence value set after the first submission to make sure it has completed before resetting with pAlloc1.  You can use more allocators to avoid the likeliness of actually blocking on a fence very often if at all, but allocators only ever increase in size, so the largest batch of commands submitted to one is how much memory that allocator will consume until it's destroyed (COM destroyed through Release, not Reset).


Command Allocator Reset: It seems as though this is literally destroying the contents of the heap, which may have command list data active on the GPU.


Kind of.  That's exactly why you'd want to ensure the job is done executing before resetting the command allocator, but it's likely more of a pointer reset to the beginning of the allocator's memory than any type of expensive deconstruction.


How does the memory ownership work between the command allocator and command list? Is the allocator doing implicit double (or more?) buffering on a command list reset?


The allocator owns the memory.  The command list is your interface to write into that memory, but it doesn't actually own it.  You've probably deduced from the previous parts of the post that the allocator does no additional buffering (double or otherwise), so again, that's why you want to ensure your work is done (fence) before resetting an allocator.

In Topic: HLSL Bilinear Filtering ?

15 January 2016 - 03:45 PM

Doesn't D3D11_FILTER_MIN_MAG_MIP_LINEAR enable trilinear filtering


Yes, that's correct.  As long as the samples are from non-fractional mip levels, the result is the same as bilinear filtering.  In the use case above, you could also use D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT for the same result.