M
Manda Rajo
Guest
Hi, I want to set a pixel in a texture by the CPU then render it by the GPU but there is an error.
ID3D11Device *device = ...;
ID3D11DeviceContext *deviceContext = ...;
ID3D11Texture2D *texture2D = nullptr;
D3D11_TEXTURE2D_DESC desc = { 0 };
desc.Width = resolutionX;
desc.Height = resolutionY;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DYNAMIC; // DYNAMIC: GPU (read only) & CPU (write only)
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
HRESULT hr;
hr = device->CreateTexture2D(&desc, nullptr, &texture2D);
// The texture is successfully created.
...
D3D11_MAPPED_SUBRESOURCE mappedResource;
hr = deviceContext->Map(texture2D, 0, D3D11_MAP_WRITE, 0, &mappedResource);
// This fails: E_INVALIDARG: One or more arguments are invalid.
...
Continue reading...
ID3D11Device *device = ...;
ID3D11DeviceContext *deviceContext = ...;
ID3D11Texture2D *texture2D = nullptr;
D3D11_TEXTURE2D_DESC desc = { 0 };
desc.Width = resolutionX;
desc.Height = resolutionY;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DYNAMIC; // DYNAMIC: GPU (read only) & CPU (write only)
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.MiscFlags = 0;
HRESULT hr;
hr = device->CreateTexture2D(&desc, nullptr, &texture2D);
// The texture is successfully created.
...
D3D11_MAPPED_SUBRESOURCE mappedResource;
hr = deviceContext->Map(texture2D, 0, D3D11_MAP_WRITE, 0, &mappedResource);
// This fails: E_INVALIDARG: One or more arguments are invalid.
...
Continue reading...