-1

The calling code corresponding to the error in the title is:

this->directCommandList.Get()->CopyResource(
    this->srvBuffer.Get(), 
    this->stagingWriteBuffer.Get());

srvBuffer is a smart pointer to an ID3D12Resource. My first real interaction with it is here:

            DC12::CreateShaderResourceView(
                this->device.Get(),
                this->srvDescriptor.Get(),
                0,
                shaderResourceViewCount,
                this->srvBuffer.GetAddressOf());

After which I do nothing with srvBuffer until the attempt to copy into it. This suggests to me that I must have made at least one mistake in my CreateShaderResourceView function, which I have included here:

       static inline void CreateShaderResourceView(
                _In_ ID3D12Device* pDevice,
                _In_opt_ ID3D12DescriptorHeap* pDescriptorHeap,
                uint32_t index, // descriptor index
                uint32_t count,
                _COM_Outptr_ ID3D12Resource** ppBuffer)
        {
            D3D12_HEAP_PROPERTIES heapProperties =
            {
                D3D12_HEAP_TYPE_DEFAULT, // Type
                D3D12_CPU_PAGE_PROPERTY_UNKNOWN, // CPUPageProperty
                D3D12_MEMORY_POOL_UNKNOWN, // MemoryPoolPreference
                0, // CreationNodeMask
                0, // VisibleNodeMask
            };

            D3D12_RESOURCE_DESC resourceDesc =
            {
                D3D12_RESOURCE_DIMENSION_BUFFER, // Dimension
                D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT, // Alignment
                count * STRUCTURE_BYTE_STRIDE, // Width
                1, // Height
                1, // DepthOrArraySize
                1, // MipLevels
                DXGI_FORMAT_UNKNOWN, // Format
                {
                    1, // Count
                    0, // Quality
                }, // SampleDesc
                D3D12_TEXTURE_LAYOUT_ROW_MAJOR, // Layout
                D3D12_RESOURCE_FLAG_NONE, // Flags
            };

            CHR(pDevice->CreateCommittedResource(
                &heapProperties,
                D3D12_HEAP_FLAG_NONE,
                &resourceDesc,
                D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
                nullptr,
                IID_PPV_ARGS(ppBuffer)));

            if (pDescriptorHeap != nullptr)
            {
                D3D12_SHADER_RESOURCE_VIEW_DESC desc =
                {
                    DXGI_FORMAT_UNKNOWN, // Format
                    D3D12_SRV_DIMENSION_BUFFER, // ViewDimension
                    D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING,
                    {
                        0, // FirstElement
                        count, // NumElements
                        STRUCTURE_BYTE_STRIDE, // StructurebyteStride,
                        D3D12_BUFFER_SRV_FLAG_NONE // Flags
                    }, // Buffer
                };

                D3D12_CPU_DESCRIPTOR_HANDLE cpuDescriptor =
                    pDescriptorHeap->GetCPUDescriptorHandleForHeapStart();

                size_t offset = pDevice->GetDescriptorHandleIncrementSize(
                    D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);

                offset *= index;

                cpuDescriptor.ptr += offset;

                pDevice->CreateShaderResourceView(
                    *ppBuffer,
                    &desc,
                    cpuDescriptor);
            }
        }

I did also check that the final pDevice->CreateShaderResourceView is being hit by putting a breakpoint there, and it is. I'm hoping there's a simple answer to this.

Edit: A problem I've found is that prior to my attempt at copying to srvBuffer, I get another error with my Resource Transition Barrier: "D3D12 ERROR: ID3D12CommandList::ResourceBarrier: NULL pointer specified." It turns out that this->srvBuffer.Get() returns a null pointer, which suggests to me that I've a failure in CreateCommittedResource, which I'm trying to figure out. This problem would likely explain the original error, though.

MNagy
  • 423
  • 7
  • 20
  • 1
    The key is going to be what happens to the ``srvBuffer`` resource *after* you have closed and are executing the command list. You also don't show any of the resource barriers which are used to ensure proper resource synchronization. BTW, you might want to look at ``ResourceUploadBatch`` in the [DirectX Tool Kit for DX12](https://github.com/Microsoft/DirectXTK12). – Chuck Walbourn Feb 22 '19 at 03:46
  • ResourceUploadBatch looks very helpful and relevant, thanks. I'll compare and see if that holds the answer. – MNagy Feb 22 '19 at 04:31
  • I did check out the barriers, and I think I've isolated the problem a little more, put it into the edit. Is this something wrong with my CreateCommittedResource? – MNagy Feb 22 '19 at 05:35
  • What does your ``CHR`` macro do? If the function failed, it should have returned a failed ``HRESULT``. – Chuck Walbourn Feb 22 '19 at 08:07

1 Answers1

0

It turns out that the answer to my question isn't in the code I'd posted at all; what is here is sufficiently correct to work assuming everything else is correct. It turns out that my mistake was that I had a second this->srvBuffer in the inherited class which calls copy resource (I had forgotten to delete it when finalizing the overall structure), and thus the srvBuffer that had been initialized with CreateCommittedResource wasn't the one being passed to CopyResource.

MNagy
  • 423
  • 7
  • 20