Code Monkey home page Code Monkey logo

Comments (2)

benanil avatar benanil commented on May 28, 2024

but I can create index buffer without problem like this.

D3D12_HEAP_PROPERTIES props {};
props.Type = D3D12_HEAP_TYPE_UPLOAD;
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
D3D12_RESOURCE_DESC desc{};
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
desc.Width = size * sizeof(T);
desc.Height = 1;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
desc.Format = DXGI_FORMAT_UNKNOWN;
desc.SampleDesc.Count = 1;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
desc.Flags = D3D12_RESOURCE_FLAG_NONE;

if (device->CreateCommittedResource(&props,
    D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, 
    NULL, IID_PPV_ARGS(&indexBuffer)) < 0)
    throw std::exception("index buffer creation failed!");

void* idxResource = nullptr;
D3D12_RANGE range{};
if(indexBuffer->Map(0, &range, &idxResource) != S_OK) 
    throw std::exception("index buffer maping failed!");

memcpy(idxResource, _data, desc.Width);

indexBuffer->Unmap(0, &range);

from d3d12memoryallocator.

benanil avatar benanil commented on May 28, 2024

problem fixed like this:

class BufferBase
{
protected:
	ID3D12Resource* mpVidMemBuffer;
	ID3D12Resource* mpSysMemBuffer;
public:
	void Initialize(ID3D12Device2* device, const void* data, uint size,
		ID3D12GraphicsCommandList* pCmd, D3D12_RESOURCE_STATES resourceState,
		D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE) 
	{
		auto heapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
		auto resourceDesc = CD3DX12_RESOURCE_DESC::Buffer(size, flags);
		ThrowIfFailed(device->CreateCommittedResource(
			&heapProperties,
			D3D12_HEAP_FLAG_NONE,
			&resourceDesc,
			resourceState,
			nullptr, IID_PPV_ARGS(&mpVidMemBuffer)
		));

		auto sysHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);

		ThrowIfFailed(device->CreateCommittedResource(
			&sysHeapProperties,
			D3D12_HEAP_FLAG_NONE,
			&resourceDesc,
			D3D12_RESOURCE_STATE_GENERIC_READ,
			nullptr, IID_PPV_ARGS(&mpSysMemBuffer)
		));

		// copy to sys
		void* mappedMem;
		D3D12_RANGE range;
		mpSysMemBuffer->Map(0, &range, &mappedMem);
		memcpy(mappedMem, data, size);
		mpSysMemBuffer->Unmap(0, &range);
	}
};

from d3d12memoryallocator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.