| 43 | using namespace donut::render; |
| 44 | |
| 45 | PixelReadbackPass::PixelReadbackPass( |
| 46 | nvrhi::IDevice* device, |
| 47 | std::shared_ptr<ShaderFactory> shaderFactory, |
| 48 | nvrhi::ITexture* inputTexture, |
| 49 | nvrhi::Format format, |
| 50 | uint32_t arraySlice, |
| 51 | uint32_t mipLevel) |
| 52 | : m_Device(device) |
| 53 | { |
| 54 | const char* formatName = ""; |
| 55 | switch (format) |
| 56 | { |
| 57 | case nvrhi::Format::RGBA32_FLOAT: formatName = "float4"; break; |
| 58 | case nvrhi::Format::RGBA32_UINT: formatName = "uint4"; break; |
| 59 | case nvrhi::Format::RGBA32_SINT: formatName = "int4"; break; |
| 60 | default: assert(!"unsupported readback format"); |
| 61 | } |
| 62 | |
| 63 | std::vector<ShaderMacro> macros; |
| 64 | macros.push_back(ShaderMacro("TYPE", formatName)); |
| 65 | macros.push_back(ShaderMacro("INPUT_MSAA", inputTexture->getDesc().sampleCount > 1 ? "1" : "0")); |
| 66 | m_Shader = shaderFactory->CreateAutoShader("donut/passes/pixel_readback_cs.hlsl", "main", DONUT_MAKE_PLATFORM_SHADER(g_pixel_readback_cs), ¯os, nvrhi::ShaderType::Compute); |
| 67 | |
| 68 | nvrhi::BufferDesc bufferDesc; |
| 69 | bufferDesc.byteSize = 16; |
| 70 | bufferDesc.format = format; |
| 71 | bufferDesc.canHaveUAVs = true; |
| 72 | bufferDesc.initialState = nvrhi::ResourceStates::CopySource; |
| 73 | bufferDesc.keepInitialState = true; |
| 74 | bufferDesc.debugName = "PixelReadbackPass/IntermediateBuffer"; |
| 75 | bufferDesc.canHaveTypedViews = true; |
| 76 | m_IntermediateBuffer = m_Device->createBuffer(bufferDesc); |
| 77 | |
| 78 | bufferDesc.canHaveUAVs = false; |
| 79 | bufferDesc.cpuAccess = nvrhi::CpuAccessMode::Read; |
| 80 | bufferDesc.debugName = "PixelReadbackPass/ReadbackBuffer"; |
| 81 | m_ReadbackBuffer = m_Device->createBuffer(bufferDesc); |
| 82 | |
| 83 | nvrhi::BufferDesc constantBufferDesc; |
| 84 | constantBufferDesc.byteSize = sizeof(PixelReadbackConstants); |
| 85 | constantBufferDesc.isConstantBuffer = true; |
| 86 | constantBufferDesc.isVolatile = true; |
| 87 | constantBufferDesc.debugName = "PixelReadbackPass/Constants"; |
| 88 | constantBufferDesc.maxVersions = engine::c_MaxRenderPassConstantBufferVersions; |
| 89 | m_ConstantBuffer = m_Device->createBuffer(constantBufferDesc); |
| 90 | |
| 91 | nvrhi::BindingLayoutDesc layoutDesc; |
| 92 | layoutDesc.visibility = nvrhi::ShaderType::Compute; |
| 93 | layoutDesc.bindings = { |
| 94 | nvrhi::BindingLayoutItem::VolatileConstantBuffer(0), |
| 95 | nvrhi::BindingLayoutItem::Texture_SRV(0), |
| 96 | nvrhi::BindingLayoutItem::TypedBuffer_UAV(0) |
| 97 | }; |
| 98 | |
| 99 | m_BindingLayout = m_Device->createBindingLayout(layoutDesc); |
| 100 | |
| 101 | nvrhi::BindingSetDesc setDesc; |
| 102 | setDesc.bindings = { |
nothing calls this directly
no test coverage detected