如何将计算着色器的结果传递给顶点着色器?(How to pass result from compute shader to vertex shader?)
我的代码工作了。 首先,我创建一个缓冲区,通过CopyResource从计算着色器获取缓冲区。
然后我创建一个指针调用p1并从MappedResource1获取结果指针。 之后,我创建顶点缓冲区并渲染。
但我不认为这是从计算着色器获取顶点缓冲区的最佳方法:
D3D11_BUFFER_DESC desc; ZeroMemory(&desc, sizeof(desc)); mFirstBuffer->GetDesc(&desc); desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; desc.BindFlags = 0; desc.MiscFlags = 0; if (SUCCEEDED(device->CreateBuffer(&desc, nullptr, &debugbuf))) { context->CopyResource(debugbuf, mFirstBuffer.Get()); } unsigned int stride = sizeof(InstanceData); unsigned int offset = 0; D3D11_MAPPED_SUBRESOURCE MappedResource1; InstanceData *p1; context->Map(debugbuf, 0, D3D11_MAP_READ, 0, &MappedResource1); p1 = (InstanceData*)MappedResource1.pData; context->Unmap(debugbuf, 0); D3D11_SUBRESOURCE_DATA VertexBufferData; VertexBufferData.pSysMem = p1; VertexBufferData.SysMemPitch = 0; VertexBufferData.SysMemSlicePitch = 0; D3D11_BUFFER_DESC desc2; desc2.ByteWidth = sizeof(InstanceData) * MillionParticleCount; desc2.Usage = D3D11_USAGE_DEFAULT; desc2.BindFlags = D3D11_BIND_VERTEX_BUFFER; desc2.CPUAccessFlags = 0; desc2.MiscFlags = 0; desc2.StructureByteStride = 0; device->CreateBuffer(&desc2, &VertexBufferData, &vertexBuffer); context->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
我已经阅读了很多样本,他们都只在一个文件中编写了计算着色器和顶点着色器,因此他们可以直接从计算着色器中获得结果。
在我的代码中,计算着色器和顶点着色器被写入不同的文件中。 我该怎么做才能优化我的代码?
My code worked. Firstly, I create a buffer to get buffer from compute shader by CopyResource.
Then I create a pointer call p1 and get result pointer from MappedResource1. After that, I create vertex buffer and render.
But I don't think it's the best way to get vertex buffer from compute shader:
D3D11_BUFFER_DESC desc; ZeroMemory(&desc, sizeof(desc)); mFirstBuffer->GetDesc(&desc); desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; desc.BindFlags = 0; desc.MiscFlags = 0; if (SUCCEEDED(device->CreateBuffer(&desc, nullptr, &debugbuf))) { context->CopyResource(debugbuf, mFirstBuffer.Get()); } unsigned int stride = sizeof(InstanceData); unsigned int offset = 0; D3D11_MAPPED_SUBRESOURCE MappedResource1; InstanceData *p1; context->Map(debugbuf, 0, D3D11_MAP_READ, 0, &MappedResource1); p1 = (InstanceData*)MappedResource1.pData; context->Unmap(debugbuf, 0); D3D11_SUBRESOURCE_DATA VertexBufferData; VertexBufferData.pSysMem = p1; VertexBufferData.SysMemPitch = 0; VertexBufferData.SysMemSlicePitch = 0; D3D11_BUFFER_DESC desc2; desc2.ByteWidth = sizeof(InstanceData) * MillionParticleCount; desc2.Usage = D3D11_USAGE_DEFAULT; desc2.BindFlags = D3D11_BIND_VERTEX_BUFFER; desc2.CPUAccessFlags = 0; desc2.MiscFlags = 0; desc2.StructureByteStride = 0; device->CreateBuffer(&desc2, &VertexBufferData, &vertexBuffer); context->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
I have read many sample, all of them write compute shader and vertex shader together in only one file and therefor they can get result from compute shader directly.
In my code, compute shader and vertex shader are write in different files. How should I do to optimize my code?
原文:https://stackoverflow.com/questions/37053051
最满意答案
请改用
NotificationCompat.Builder
。 无论项目的API级别如何,都可以调用setStyle()
(当然,如果设备不支持样式,那么该部分将被忽略)。注意:您还缺少Builder构造函数中的
Context
参数 - 这对于本机Notification.Builder
和NotificationCompat.Builder
都是必需的。Use
NotificationCompat.Builder
instead. You can callsetStyle()
no matter the project's API level (of course, if the device doesn't support styles, that part will be ignored).Note: You're also missing the
Context
parameter in the Builder's constructor -- this is necessary both with the nativeNotification.Builder
andNotificationCompat.Builder
.
相关问答
更多-
看看文档: http : //developer.android.com/design/style/iconography.html 有字:“通知图标必须是完全白色的,而且系统可能会缩小图标和/或使图标变暗。 I have resolved changing the icon size to 16x16 px and using only white color
-
为什么Notification.Builder的多次使用会使应用程序崩溃?(Why do multiple uses to Notification.Builder crash the app?)[2022-07-25]
从您的日志中考虑这些行: java.lang.NumberFormatException: For input string: "26.57" at java.lang.Integer.parseInt(Integer.java:521) at java.lang.Integer.parseInt(Integer.java:556) ... -
这是在API 11中,所以如果你正在开发任何早于3.0的东西,你应该继续使用旧的API。 更新 :NotificationCompat.Builder类已添加到支持包中,因此我们可以使用它来支持API级别v4及以上: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html This is in API 11, so if you are developing for anyth ...
-
NoSuchMethodError Notification.Builder.build()(NoSuchMethodError Notification.Builder.build())[2022-07-10]
Notification.Builder.build()是API级别16。 在4.0.4中,你应该使用getNotification() 。 或者你最好使用NotificationCompat 。 Notification.Builder.build() is API level 16. In 4.0.4,you should use getNotification(). Or you had better use NotificationCompat. -
无法从Notification.builder转换为Notification(Can not convert from Notification.builder to Notification)[2023-05-14]
请改用NotificationCompat.Builder 。 无论项目的API级别如何,都可以调用setStyle() (当然,如果设备不支持样式,那么该部分将被忽略)。 注意:您还缺少Builder构造函数中的Context参数 - 这对于本机Notification.Builder和NotificationCompat.Builder都是必需的。 Use NotificationCompat.Builder instead. You can call setStyle() no matter the ... -
var notification = new Notification.Builder(Application.Context) .SetSmallIcon(Resource.Mipmap.Icon) .SetLargeIcon(BitmapFactory.DecodeResource(Application.Context.Resources, Resource.Mipmap.Icon)) .SetAutoCancel(true) .SetStyle(new Notific ...
-
getPendingAction()代码将始终返回相同的PendingIntent 。 每次调用此方法时,您都不会创建单独的PendingIntent 。 要确保每个调用都创建一个单独的PendingIntent ,您需要使Intent唯一。 您可以通过在Intent设置ACTION来完成此操作,如下所示: intent.setAction(action.name()); 为了确保具有相同ACTION的任何旧PendingIntent被最新的附加内容覆盖,我还会像这样调用getBroadcast() : ...
-
你可以使用像NotificationCompat.Builder#setLargeIcon(Bitmap)这样的东西,让你充分利用Android 3.0+和大图标之类的东西,同时保持3.0之前不支持这类东西的Android版本的兼容性。 You can use things like NotificationCompat.Builder#setLargeIcon(Bitmap) to allow you to take full advantage of Android 3.0+ with things l ...
-
使用Notification.Builder隐藏通知中的自动收报机文本(Hide ticker text in notification using Notification.Builder)[2022-06-24]
尝试在构建器之后将tickerView设置为null。 这对我来说很好用Code代码: Notification notif = builder.build(); notif.tickerView = null; mNotificationManager.notify(id, notif); try to set the tickerView to null after builder. that works fine for me Code like: Notification notif = buil ... -
在内容点击上删除通知notification.builder(Delete notification notification.builder on content click)[2022-05-26]
按下操作按钮时,通知永远不会被解除。 它只是向您发送相关意图。 如果你想要它解雇,你需要调用NoficationManager.cancel(int id)来自己取消它。 您通常会使用相同的方法来处理操作按钮意图。 您尝试使用的Notification.FLAG_AUTO_CANCEL标志仅适用于通知正文而不适用于操作按钮。 A notification is never dismissed when an action button is pressed. It just sends you associ ...