从 XNA 上的后台缓冲区 (HLSL) 获取顶点
你好,很抱歉这个晦涩的标题:} 我会尽力解释。
首先,我是 HLSL 的新手,但我了解来自童话世界的管道和东西。我想做的是使用 GPU 进行一般计算(GPGPU)。
我不知道的是:我如何将顶点(已使用顶点着色器转换)读回我的 xna 应用程序?我读过一些关于使用 GPU 纹理内存的内容,但我找不到任何可靠的东西...
提前感谢您提供任何信息/提示! :-)
*不确定是否可能,因为光栅器和像素着色器(如果有),我的意思是,最终一切都与像素有关,对吗?
Hello and sorry for the obscure title :}
I`ll try to explain the best i can.
First of all, i am new to HLSL but i understand about the pipeline and stuff that are from the fairy world. What i`m trying to do is use the gpu for general computations (GPGPU).
What i don`t know is: how can i read* the vertices (that have been transformed using vertex shaders) back to my xna application? I read something about using the texture memory of the gpu but i can't find anything solid...
Thanks in advance for any info/tip! :-)
*not sure if possible bacause of the rasterizer and the pixel shader (if any), i mean, in the end it's all about pixels, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,这通常是不可能的。
你到底想做什么?可能还有另一种解决方案
编辑::考虑到评论。如果您只想在 GPU 上进行一般向量计算,请尝试在像素着色器而不是顶点着色器中进行计算。
举例来说,假设你想要交叉两个向量,首先我们需要将数据写入纹理
所以现在我们有了一个包含数据的 2*1 纹理,只需使用 spritebatch 和效果即可渲染纹理
:我们现在需要的是我上面展示的 gpgpu 效果。这只是一个标准的后处理着色器,看起来像这样:
这会将 A 和 B 的点积写入第一个像素,将 B 和 B 的点积写入第二个像素。然后你可以读回这些答案(忽略无用的)
tada!
尝试在更大范围内执行此操作会遇到很多小问题,请在此处发表评论,我会尽力帮助您解决遇到的任何问题:)
As far as I know this isn't generally possible.
What exactly are you trying to do? There is probably another solution
EDIT:: Taking into account the comment. If all you want to do is general vector calculations on the GPU try doing them in the pixel shader rather than the vertex shader.
So for example, say you want to do cross two vectors, first we need to write the data into a texture
So now we've got a 2*1 texture with the data in, render the texture simply using spritebatch and an effect:
All we need now is the gpgpu effect I've shown above. That's just a standard post processing shader, looking something like this:
This will write out the dot product of A and B into the first pixel, and the dot product of B and B into the second pixel. Then you can read these answers back (ignoring the useless ones)
tada!
There are a whole load of little issues with trying to do this on a larger scale, comment here and I'll try to help you with any you run into :)
如果您打开“Stream Output Stage”,顶点着色器的输出将存储在内存缓冲区中。稍后可以根据需要从 GPU 或 CPU 读取这些值。
If you turn on the "Stream Output Stage," the outputs of your vertex shader will be stored in a memory buffer. Later these values can be read from the GPU or CPU as desired.