276 const std::vector<std::shared_ptr<MetalBindGroupFormat>>& bindGroupFormats,
277 MTL::SamplerState* defaultSampler, MTL::DepthStencilState* defaultDepthStencilState)
284 if (!_shader || !_composePass->vertexBuffer() || !_composePass->vertexFormat() || !_blendState || !_depthState) {
285 spdlog::warn(
"[executeSsaoPass] missing SSAO resources");
295 auto pipelineState = pipeline->
get(primitive, _composePass->vertexFormat(),
nullptr, -1, _shader, renderTarget,
297 if (!pipelineState) {
298 spdlog::warn(
"[executeSsaoPass] failed to get pipeline state");
303 if (!vb || !vb->raw()) {
304 spdlog::warn(
"[executeSsaoPass] missing vertex buffer");
308 encoder->setRenderPipelineState(pipelineState);
309 encoder->setCullMode(MTL::CullModeNone);
310 encoder->setDepthStencilState(_depthStencilState ? _depthStencilState : defaultDepthStencilState);
311 encoder->setVertexBuffer(vb->raw(), 0, 0);
314 encoder->setFragmentTexture(depthHw ? depthHw->raw() :
nullptr, 0);
315 if (defaultSampler) {
316 encoder->setFragmentSamplerState(defaultSampler, 0);
322 struct alignas(16) SsaoUniforms
326 float invResolution[2];
327 float sampleCount[2];
330 float angleIncCosSin[2];
332 float invRadiusSquared;
333 float minHorizonAngleSineSquared;
338 float projectionScaleRadius;
344 uniforms.aspect = params.
aspect;
345 uniforms._pad0 = 0.0f;
348 uniforms.sampleCount[0] =
static_cast<float>(params.
sampleCount);
349 uniforms.sampleCount[1] = 1.0f /
static_cast<float>(params.
sampleCount);
351 uniforms._pad1 = 0.0f;
354 uniforms.maxLevel = 0.0f;
357 uniforms.bias = params.
bias;
358 uniforms.peak2 = params.
peak2;
360 uniforms.power = params.
power;
365 encoder->setFragmentBytes(&uniforms,
sizeof(SsaoUniforms), 5);
367 encoder->drawPrimitives(MTL::PrimitiveTypeTriangle,
static_cast<NS::UInteger
>(0),
368 static_cast<NS::UInteger
>(3));
369 _device->recordDrawCall();
gpu::HardwareTexture * impl() const