Advertisement

Writing to buffer outside Map/Unmap?

Started by November 15, 2017 02:53 PM
17 comments, last by Hodgman 7 years, 2 months ago
5 minutes ago, matt77hias said:

And what if you use an object which maps on construction and unmaps on destruction?

I thought about that and I don't like that solution, because now the destructor needs to reference the graphics device, and I must still call the destructor before the draw manually in most cases (by a dummy scope for example). Calling a function explicitly is more self documenting.

7 minutes ago, turanszkij said:

Calling a function explicitly is more self documenting.

But in this case it kind of looks like a Mutex or some other lock?

 

9 minutes ago, turanszkij said:

(by a dummy scope for example)

That is the same case for locks.

🧙

Advertisement
15 minutes ago, matt77hias said:

That is the same case for locks.

I remained from that solution in the case of locks as well. :D

1 hour ago, matt77hias said:

And what if you use an object which maps on construction and unmaps on destruction?

You can't use a resource in a draw command while it's mapped. 

Just now, Hodgman said:

You can't use a resource in a draw command while it's mapped. 

I never said that you should use the resource for drawing only for updating its content.

🧙

25 minutes ago, Hodgman said:

You can't use a resource in a draw command while it's mapped. 

I take it we were talking about something like this:


struct MappedMemory
{
	void* address;
	Id3d11devicecontext* context;
	Id3d11Buffer* buffer
	
	MappedMemory(ID3D11Buffer* buffer, Id3d11DeviceContext* context) : context(context), buffer(buffer)
	{
		context->Map(buffer, ...);
	}
	~MappedMemory()
	{
		context->Unmap(buffer);
	}
};

And that we could use it like this:


{
	MappedMemory mem(constantbuffer, context);
	((MyType*)mem.address)->color = float4(1,2,3,4);
}

context->SetConstantBuffer(constantbuffer);
context->Draw();

 

Advertisement

That is idd. what I was talking about :) 

🧙

Ah sorry :)

I actually do something like that in my API, but I just assert in the destructor that unmap was called, e.g.


{
ResourceLock l;
gpu.Map(l, buffer,...);
//use l.data, l.size
gpu.Unmap(l, buffer);
} //assertion here if you forget to unmap

Yeah that could also be used to simplify the API and completely remove Unmap. 

This topic is closed to new replies.

Advertisement