查看GPU内存/查看Texture2D内存空间以进行调试

发布于 2024-11-28 19:50:51 字数 1468 浏览 1 评论 0原文

我有一个关于我正在尝试实现的 PixelShader 以及我当前所做的事情的问题(这只是为了调试,并试图弄清楚):

    int3 loc;
    loc.x = (int)(In.TextureUV.x * resolution_XY.x);
    loc.y = (int)(In.TextureUV.x * resolution_XY.x);
    loc.z = 0;

    float4 r = g_txDiffuse.Load(loc);
    return float4(r.x, r.y, r.z, 1);

重点是,这始终是

0,0,0,1创建纹理缓冲区:

D3D11_TEXTURE2D_DESC tDesc;
tDesc.Height = 480;
tDesc.Width = 640;
tDesc.Usage = D3D11_USAGE_DYNAMIC;
tDesc.MipLevels = 1;
tDesc.ArraySize = 1;
tDesc.SampleDesc.Count = 1;
tDesc.SampleDesc.Quality = 0;
tDesc.Format = DXGI_FORMAT_R8_UINT;
tDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
tDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tDesc.MiscFlags = 0;

V_RETURN(pd3dDevice->CreateTexture2D(&tDesc, NULL, &g_pCurrentImage));

我通过以下方式上传纹理(最后应该是实时显示):

    D3D11_MAPPED_SUBRESOURCE resource;
    pd3dImmediateContext->Map(g_pCurrentImage, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);
    memcpy( resource.pData, g_Images.GetData(), g_Images.GetDataSize() );
    pd3dImmediateContext->Unmap( g_pCurrentImage, 0 );

我检查了resource.pData,其中的数据是有效的8位单色图像。我确保来自相机的数据是 8 位单色 640x480。

有几件事我不完全理解:

  • 如果我在每一帧中运行 Map / memcpy / Unmap 例程,驱动程序最终将崩溃,系统将无响应。是否有不同的方法来更新每帧的完整纹理?
  • 我上传的纹理是8bit,为什么Texture2D.load()返回的是float4?我是否必须使用不同的方法来访问纹理数据?我尝试对其进行采样,但这也不起作用。我是否必须使用 int 缓冲区或其他东西来代替?
  • 有没有办法调试 GPU 内存,首先检查 memcpy 是否工作?

I've got a question about a PixelShader I am trying to implement, and what I currently do (this is just for debugging, and trying to figure stuff out):

    int3 loc;
    loc.x = (int)(In.TextureUV.x * resolution_XY.x);
    loc.y = (int)(In.TextureUV.x * resolution_XY.x);
    loc.z = 0;

    float4 r = g_txDiffuse.Load(loc);
    return float4(r.x, r.y, r.z, 1);

The point is, this is always 0,0,0,1

The texture buffer is created:

D3D11_TEXTURE2D_DESC tDesc;
tDesc.Height = 480;
tDesc.Width = 640;
tDesc.Usage = D3D11_USAGE_DYNAMIC;
tDesc.MipLevels = 1;
tDesc.ArraySize = 1;
tDesc.SampleDesc.Count = 1;
tDesc.SampleDesc.Quality = 0;
tDesc.Format = DXGI_FORMAT_R8_UINT;
tDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
tDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tDesc.MiscFlags = 0;

V_RETURN(pd3dDevice->CreateTexture2D(&tDesc, NULL, &g_pCurrentImage));

I upload the texture (which should be a live display at the end) via:

    D3D11_MAPPED_SUBRESOURCE resource;
    pd3dImmediateContext->Map(g_pCurrentImage, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);
    memcpy( resource.pData, g_Images.GetData(), g_Images.GetDataSize() );
    pd3dImmediateContext->Unmap( g_pCurrentImage, 0 );

I've checked the resource.pData, the data in there is a valid 8bit monochrome image. I made sure the data coming from the camera is 8bit monochrome 640x480.

There's a few things I don't fully understand:

  • if I run the Map / memcpy / Unmap routine in every frame, the driver will ultimately crash, the system will be unresponsive. Is there a different way to update a complete texture every frame which should be done?
  • the texture I uploaded is 8bit, why is the Texture2D.load() a float4 return? Do I have to use a different method to access the texture data? I tried to .sample it, but that didn't work either. Would I have to use a int buffer or something instead?
  • is there a way to debug the GPU memory, to check if the memcpy worked in the first place?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕色琉璃 2024-12-05 19:50:51
  • Map、memcpy、Unmap 确实不应该崩溃,除非您尝试将太多数据复制到纹理中。了解“GetDataSize()”返回什么会很有趣。等于 307,200 吗?如果不止这些,那就是你的问题了。

  • Texture2D 返回 float4,因为这就是您所要求的。如果你写 float r = g_txDiffuse.Load( ... )。作为加载过程的一部分,8 位将扩展为标准化浮点数。顺便说一句,您确定您对“loc”的计算是正确的,因为现在 loc.x 和 loc.y 将始终相同。

  • 您可以使用 PIX 调试 DirectX 的运行情况。它是一个很棒的工具,我强烈建议您熟悉它。

  • The Map, memcpy, Unmap really ought not to crash unless2 you are trying to copy too much data into the texture. It would be interesting to know what "GetDataSize()" returns. Does it equal 307,200? If its more than that then there lies your problem.

  • Texture2D returns a float4 because thats what you've asked for. If you write float r = g_txDiffuse.Load( ... ). The 8-bits get extended to a normalised float as part of the load process. Are you sure, btw, that your calculation of "loc" is correct because as you have it now loc.x and loc.y will always be the same.

  • You can debug whats going on with DirectX using PIX. Its a great tool and I highly recommend you familiarise yourself with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文