2

I want to use direct storage for my renderer, but in Direct Storage Sample it just upload data like (width: bytesize, height: 1), and D3D12_RESOURCE_DIMENSION_BUFFER.

What I want to do is upload it on D3D12_RESOURCE_DIMENSION_TEXTURE2D, and use it for texturing by SRV.

is there any tutorial about it? miniengine tutorial is too complicate...

this is my code for load texture by direct storage. as you see, it's width and height is not texture's width and height, so even if I loaded it successfully but I can't use it as SRV.

alloc is D3D12MA Allocator.(not part of d3d12, it's from AMD open source library.)

ComPtr<IDStorageFile> textureFile;
    mTextureFactory->OpenFile(filePath.c_str(), IID_PPV_ARGS(&textureFile));

    BY_HANDLE_FILE_INFORMATION fileInfo{};
    ThrowIfFailed(textureFile->GetFileInformation(&fileInfo));
    uint32_t fileSize = fileInfo.nFileSizeLow;

    ComPtr<D3D12MA::Allocation> textureAlloc;
    D3D12MA::ALLOCATION_DESC allocationDesc = {};
    allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;

    auto resourceDesc = CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_BUFFER,
        D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT, fileSize, 1, 1,
        1, DXGI_FORMAT_UNKNOWN, 1, 0, D3D12_TEXTURE_LAYOUT_ROW_MAJOR, D3D12_RESOURCE_FLAG_NONE);

    ThrowIfFailed(alloc->CreateResource(
        &allocationDesc,
        &resourceDesc,
        D3D12_RESOURCE_STATE_COMMON,
        NULL,
        &textureAlloc,
        IID_NULL, NULL));

    tracker.AddTrackingResource(textureAlloc->GetResource(), D3D12_RESOURCE_STATE_COMMON);

    DSTORAGE_REQUEST textureRequest = {};
    textureRequest.Options.SourceType = DSTORAGE_REQUEST_SOURCE_FILE;
    textureRequest.Options.DestinationType = DSTORAGE_REQUEST_DESTINATION_BUFFER;
    textureRequest.Source.File.Source = textureFile.Get();
    textureRequest.Source.File.Offset = 0;
    textureRequest.Source.File.Size = fileSize;
    textureRequest.UncompressedSize = fileSize;
    textureRequest.Destination.Buffer.Resource = textureAlloc->GetResource();
    textureRequest.Destination.Buffer.Offset = 0;
    textureRequest.Destination.Buffer.Size = textureRequest.Source.File.Size;

    mTextureQueue->EnqueueRequest(&textureRequest);

    UINT64 currFenceValue = ++mFenceValue;
    mTextureQueue->EnqueueSignal(mTextureLoadingFence.Get(), currFenceValue);

    mTextureQueue->Submit();

    if (mTextureLoadingFence->GetCompletedValue() < currFenceValue)
    {
        ThrowIfFailed(mTextureLoadingFence->SetEventOnCompletion(currFenceValue, mFenceEvent));
        WaitForSingleObject(mFenceEvent, INFINITE);
    }

    newTexture->SetTextureBufferAlloc(textureAlloc);

    tracker.TransitionBarrier(cmdList, textureAlloc->GetResource(), D3D12_RESOURCE_STATE_GENERIC_READ);

UPDATE

I've found that WIC and DDS Texture loaders are getting texture width and height to it's own way.

trying to get WIC texture size is not that hard, but if I want DDS texture's size, I must need to read dds data, so it makes me loads it twice...

is there any method for getting width - height of texture in general perpose?

UPDATE2

I've edited codes like this :

shared_ptr<Texture> newTexture = make_shared<Texture>();

    TexMetadata metaData = {};
    if (flag == FLAG_WIC)
    {
        ThrowIfFailed(GetMetadataFromWICFile(filePath.c_str(), WIC_FLAGS_NONE, metaData));
    }

    else if (flag == FLAG_DDS)
    {
        ThrowIfFailed(GetMetadataFromDDSFile(filePath.c_str(), DDS_FLAGS_NONE, metaData));
    }

    ComPtr<IDStorageFile> textureFile;
    mTextureFactory->OpenFile(filePath.c_str(), IID_PPV_ARGS(&textureFile));

    BY_HANDLE_FILE_INFORMATION fileInfo{};
    ThrowIfFailed(textureFile->GetFileInformation(&fileInfo));
    uint32_t fileSize = fileInfo.nFileSizeLow;

    ComPtr<D3D12MA::Allocation> textureAlloc;
    D3D12MA::ALLOCATION_DESC allocationDesc = {};
    allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;

    auto resourceDesc = CD3DX12_RESOURCE_DESC((D3D12_RESOURCE_DIMENSION)metaData.dimension,
        D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT, metaData.width, metaData.height, metaData.depth,
        1, metaData.format, 1, 0, D3D12_TEXTURE_LAYOUT_UNKNOWN, D3D12_RESOURCE_FLAG_NONE);

    ThrowIfFailed(alloc->CreateResource(
        &allocationDesc,
        &resourceDesc,
        D3D12_RESOURCE_STATE_COMMON,
        NULL,
        &textureAlloc,
        IID_NULL, NULL));

    tracker.AddTrackingResource(textureAlloc->GetResource(), 

D3D12_RESOURCE_STATE_COMMON);

    DSTORAGE_REQUEST textureRequest = {};
    textureRequest.Options.SourceType = DSTORAGE_REQUEST_SOURCE_FILE;
    textureRequest.Options.DestinationType = DSTORAGE_REQUEST_DESTINATION_MULTIPLE_SUBRESOURCES;
    textureRequest.Source.File.Source = textureFile.Get();
    textureRequest.Source.File.Offset = 0;
    textureRequest.Source.File.Size = fileSize;
    textureRequest.UncompressedSize = fileSize;
    textureRequest.Destination.Buffer.Resource = textureAlloc->GetResource();
    textureRequest.Destination.Buffer.Offset = 0;
    textureRequest.Destination.Buffer.Size = textureRequest.Source.File.Size;

    mTextureQueue->EnqueueRequest(&textureRequest);

    UINT64 currFenceValue = ++mFenceValue;
    mTextureQueue->EnqueueSignal(mTextureLoadingFence.Get(), currFenceValue);

    mTextureQueue->Submit();

    if (mTextureLoadingFence->GetCompletedValue() < currFenceValue)
    {
        ThrowIfFailed(mTextureLoadingFence->SetEventOnCompletion(currFenceValue, mFenceEvent));
        WaitForSingleObject(mFenceEvent, INFINITE);
    }

What I've updated is get texture metadata by DirectXTex, and use it for resource creation and DStorage requests.

and now Destination Type is DSTORAGE_REQUEST_DESTINATION_MULTIPLE_SUBRESOURCES, so I think it will work but errors are apeared.

D3D12 ERROR: ID3D12CommandList::CopyTextureRegion: The region specified by D3D12_TEXTURE_COPY_LOCATION:PlacedFootprint extends past the end of the buffer it is placed on. The size required by PlacedFootprint is 4194304, as the fields of PlacedFootprint::Placement are as follows: RowPitch is 4096, Height is 1024, and Format is R8G8B8A8_UNORM_SRGB. PlacedFootprint::Offset is 31461376, which requires the buffer to have 35655680 bytes; but the buffer only has 33554432 bytes. [ RESOURCE_MANIPULATION ERROR #869: COPYTEXTUREREGION_INVALIDSRCPLACEMENT]

like this.

few textures are loaded well but others gives me this kind of errors. why?

0 Answers0