/**
 ******************************************************************************
 * Xenia : Xbox 360 Emulator Research Project                                 *
 ******************************************************************************
 * Copyright 2022 Ben Vanik. All rights reserved.                             *
 * Released under the BSD license - see LICENSE in the root for more details. *
 ******************************************************************************
 */

#ifndef XENIA_GPU_SHADERS_HOST_DEPTH_STORE_XESLI_
#define XENIA_GPU_SHADERS_HOST_DEPTH_STORE_XESLI_

#include "../../ui/shaders/xesl.xesli"

push_const_begin_xe(b0, space0)
  uint xe_host_depth_store_rectangle;
  uint xe_host_depth_store_render_target;
push_const_end_xe

#define XE_HOST_DEPTH_STORE_PUSH_CONSTANTS_BINDING \
    push_const_binding_xe(buffer(0))

uint2_xe XeHostDepthStoreRectUnscaledOrigin(uint rect_constant) {
  return ((uint_x2_xe(rect_constant) >> uint2_xe(0u, 10u)) & 0x3FFu) << 3u;
}

uint XeHostDepthStoreRectUnscaledWidthDiv8(uint rect_constant) {
  // The width divided by 8 minus 1 is stored.
  return ((rect_constant >> 20u) & 0x3FFu) + 1u;
}

uint2_xe XeHostDepthStoreRTResolutionScale(uint rt_constant) {
  return (uint_x2_xe(rt_constant) >> uint2_xe(10u, 13u)) & 0x7u;
}

// As host depth is needed for at most one transfer destination per update, base
// is not passed to the shader - (0, 0) of the render target is at 0 of the
// destination buffer.

uint XeHostDepthStoreRTPitchTiles(uint rt_constant) {
  return rt_constant & 0x3FFu;
}

bool XeHostDepthStoreRTMsaa2xSupported(uint rt_constant) {
  return bool((rt_constant >> 16u) & 0x1u);
}

// 40-sample columns are not swapped for addressing simplicity (because this is
// used for depth -> depth transfers, where swapping isn't needed).

#endif  // XENIA_GPU_SHADERS_HOST_DEPTH_STORE_XESLI_
