Skip to content

Commit

Permalink
RenderDeviceBase, DeviceContextBase: fixed compile issues with std::m…
Browse files Browse the repository at this point in the history
…in/std::max on Windows
  • Loading branch information
TheMostDiligent committed Dec 9, 2024
1 parent 5a6dddd commit 192ad3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
42 changes: 21 additions & 21 deletions Graphics/GraphicsEngine/include/DeviceContextBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ inline void DeviceContextBase<ImplementationTraits>::SetVertexBuffers(
m_VertexStreams[s] = VertexStreamInfo<BufferImplType>{};
m_NumVertexStreams = 0;
}
m_NumVertexStreams = std::max(m_NumVertexStreams, StartSlot + NumBuffersSet);
m_NumVertexStreams = (std::max)(m_NumVertexStreams, StartSlot + NumBuffersSet);

for (Uint32 Buff = 0; Buff < NumBuffersSet; ++Buff)
{
Expand Down Expand Up @@ -903,7 +903,7 @@ inline void DeviceContextBase<ImplementationTraits>::SetViewports(
}

DEV_CHECK_ERR(NumViewports < MAX_VIEWPORTS, "Number of viewports (", NumViewports, ") exceeds the limit (", MAX_VIEWPORTS, ")");
m_NumViewports = std::min(MAX_VIEWPORTS, NumViewports);
m_NumViewports = (std::min)(MAX_VIEWPORTS, NumViewports);

Viewport DefaultVP{RTWidth, RTHeight};
// If no viewports are specified, use default viewport
Expand Down Expand Up @@ -956,7 +956,7 @@ inline void DeviceContextBase<ImplementationTraits>::SetScissorRects(
}

DEV_CHECK_ERR(NumRects < MAX_VIEWPORTS, "Number of scissor rects (", NumRects, ") exceeds the limit (", MAX_VIEWPORTS, ")");
m_NumScissorRects = std::min(MAX_VIEWPORTS, NumRects);
m_NumScissorRects = (std::min)(MAX_VIEWPORTS, NumRects);

for (Uint32 sr = 0; sr < m_NumScissorRects; ++sr)
{
Expand Down Expand Up @@ -1011,18 +1011,18 @@ inline bool DeviceContextBase<ImplementationTraits>::SetRenderTargets(const SetR
// Use this RTV to set the render target size
if (m_FramebufferWidth == 0)
{
m_FramebufferWidth = std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U);
m_FramebufferHeight = std::max(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U);
m_FramebufferWidth = (std::max)(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U);
m_FramebufferHeight = (std::max)(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U);
m_FramebufferSlices = RTVDesc.NumArraySlices;
m_FramebufferSamples = TexDesc.SampleCount;
}
else
{
#ifdef DILIGENT_DEVELOPMENT
DEV_CHECK_ERR(m_FramebufferWidth == std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U),
"Render target width (", std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U), ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the width of previously bound render targets (", m_FramebufferWidth, ")");
DEV_CHECK_ERR(m_FramebufferHeight == std::max(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U),
"Render target height (", std::max(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U), ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the height of previously bound render targets (", m_FramebufferHeight, ")");
DEV_CHECK_ERR(m_FramebufferWidth == (std::max)(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U),
"Render target width (", (std::max)(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U), ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the width of previously bound render targets (", m_FramebufferWidth, ")");
DEV_CHECK_ERR(m_FramebufferHeight == (std::max)(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U),
"Render target height (", (std::max)(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U), ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the height of previously bound render targets (", m_FramebufferHeight, ")");
DEV_CHECK_ERR(m_FramebufferSlices == RTVDesc.NumArraySlices,
"The number of slices (", RTVDesc.NumArraySlices, ") specified by RTV '", RTVDesc.Name, "' is inconsistent with the number of slices in previously bound render targets (", m_FramebufferSlices, ")");
DEV_CHECK_ERR(m_FramebufferSamples == TexDesc.SampleCount,
Expand Down Expand Up @@ -1054,18 +1054,18 @@ inline bool DeviceContextBase<ImplementationTraits>::SetRenderTargets(const SetR
// Use depth stencil size to set render target size
if (m_FramebufferWidth == 0)
{
m_FramebufferWidth = std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U);
m_FramebufferHeight = std::max(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U);
m_FramebufferWidth = (std::max)(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U);
m_FramebufferHeight = (std::max)(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U);
m_FramebufferSlices = DSVDesc.NumArraySlices;
m_FramebufferSamples = TexDesc.SampleCount;
}
else
{
#ifdef DILIGENT_DEVELOPMENT
DEV_CHECK_ERR(m_FramebufferWidth == std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U),
"Depth-stencil target width (", std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U), ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the width of previously bound render targets (", m_FramebufferWidth, ")");
DEV_CHECK_ERR(m_FramebufferHeight == std::max(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U),
"Depth-stencil target height (", std::max(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U), ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the height of previously bound render targets (", m_FramebufferHeight, ")");
DEV_CHECK_ERR(m_FramebufferWidth == (std::max)(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U),
"Depth-stencil target width (", (std::max)(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U), ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the width of previously bound render targets (", m_FramebufferWidth, ")");
DEV_CHECK_ERR(m_FramebufferHeight == (std::max)(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U),
"Depth-stencil target height (", (std::max)(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U), ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the height of previously bound render targets (", m_FramebufferHeight, ")");
DEV_CHECK_ERR(m_FramebufferSlices == DSVDesc.NumArraySlices,
"The number of slices (", DSVDesc.NumArraySlices, ") specified by DSV '", DSVDesc.Name, "' is inconsistent with the number of slices in previously bound render targets (", m_FramebufferSlices, ")");
DEV_CHECK_ERR(m_FramebufferSamples == TexDesc.SampleCount,
Expand Down Expand Up @@ -1113,8 +1113,8 @@ inline bool DeviceContextBase<ImplementationTraits>::SetRenderTargets(const SetR
DEV_ERROR("IDeviceContext::SetRenderTargets: unexpected shading rate format");
}

const auto Width = std::max(TexDesc.Width >> ViewDesc.MostDetailedMip, 1u);
const auto Height = std::max(TexDesc.Height >> ViewDesc.MostDetailedMip, 1u);
const auto Width = (std::max)(TexDesc.Width >> ViewDesc.MostDetailedMip, 1u);
const auto Height = (std::max)(TexDesc.Height >> ViewDesc.MostDetailedMip, 1u);
const auto MinWidth = (m_FramebufferWidth + SRProps.MaxTileSize[0] - 1) / SRProps.MaxTileSize[0];
const auto MinHeight = (m_FramebufferHeight + SRProps.MaxTileSize[1] - 1) / SRProps.MaxTileSize[1];
DEV_CHECK_ERR(Width >= MinWidth,
Expand Down Expand Up @@ -2202,14 +2202,14 @@ inline Uint32 GetPrimitiveCount(PRIMITIVE_TOPOLOGY Topology, Uint32 Elements)

// clang-format off
case PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: return Elements / 3;
case PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: return std::max(Elements, 2u) - 2;
case PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: return (std::max)(Elements, 2u) - 2;
case PRIMITIVE_TOPOLOGY_POINT_LIST: return Elements;
case PRIMITIVE_TOPOLOGY_LINE_LIST: return Elements / 2;
case PRIMITIVE_TOPOLOGY_LINE_STRIP: return std::max(Elements, 1u) - 1;
case PRIMITIVE_TOPOLOGY_LINE_STRIP: return (std::max)(Elements, 1u) - 1;
case PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_ADJ: return Elements / 6;
case PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_ADJ: return std::max(Elements, 4u) - 4;
case PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_ADJ: return (std::max)(Elements, 4u) - 4;
case PRIMITIVE_TOPOLOGY_LINE_LIST_ADJ: return Elements / 4;
case PRIMITIVE_TOPOLOGY_LINE_STRIP_ADJ: return std::max(Elements, 3u) - 3;
case PRIMITIVE_TOPOLOGY_LINE_STRIP_ADJ: return (std::max)(Elements, 3u) - 3;
// clang-format on
default: UNEXPECTED("Unexpected primitive topology"); return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions Graphics/GraphicsEngine/include/RenderDeviceBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class RenderDeviceBase : public ObjectBase<typename EngineImplTraits::RenderDevi
m_AdapterInfo {AdapterInfo},
m_TextureFormatsInfo (TEX_FORMAT_NUM_FORMATS, TextureFormatInfoExt(), STD_ALLOCATOR_RAW_MEM(TextureFormatInfoExt, RawMemAllocator, "Allocator for vector<TextureFormatInfoExt>")),
m_TexFmtInfoInitFlags (TEX_FORMAT_NUM_FORMATS, false, STD_ALLOCATOR_RAW_MEM(bool, RawMemAllocator, "Allocator for vector<bool>")),
m_wpImmediateContexts (std::max(1u, EngineCI.NumImmediateContexts), RefCntWeakPtr<DeviceContextImplType>(), STD_ALLOCATOR_RAW_MEM(RefCntWeakPtr<DeviceContextImplType>, RawMemAllocator, "Allocator for vector<RefCntWeakPtr<DeviceContextImplType>>")),
m_wpImmediateContexts ((std::max)(1u, EngineCI.NumImmediateContexts), RefCntWeakPtr<DeviceContextImplType>(), STD_ALLOCATOR_RAW_MEM(RefCntWeakPtr<DeviceContextImplType>, RawMemAllocator, "Allocator for vector<RefCntWeakPtr<DeviceContextImplType>>")),
m_wpDeferredContexts (EngineCI.NumDeferredContexts, RefCntWeakPtr<DeviceContextImplType>(), STD_ALLOCATOR_RAW_MEM(RefCntWeakPtr<DeviceContextImplType>, RawMemAllocator, "Allocator for vector<RefCntWeakPtr<DeviceContextImplType>>")),
m_RawMemAllocator {RawMemAllocator},
m_TexObjAllocator {RawMemAllocator, sizeof(TextureImplType), 16},
Expand Down Expand Up @@ -357,17 +357,17 @@ class RenderDeviceBase : public ObjectBase<typename EngineImplTraits::RenderDevi
}
else if (NumThreads != 0)
{
const Uint32 NumCores = std::max(std::thread::hardware_concurrency(), 1u);
const Uint32 NumCores = (std::max)(std::thread::hardware_concurrency(), 1u);

ThreadPoolCreateInfo ThreadPoolCI;
if (NumThreads == ~0u)
{
// Leave one core for the main thread
ThreadPoolCI.NumThreads = std::max(NumCores, 2u) - 1u;
ThreadPoolCI.NumThreads = (std::max)(NumCores, 2u) - 1u;
}
else
{
ThreadPoolCI.NumThreads = std::min(NumThreads, std::max(NumCores * 4, 128u));
ThreadPoolCI.NumThreads = (std::min)(NumThreads, (std::max)(NumCores * 4, 128u));
}
m_pShaderCompilationThreadPool = CreateThreadPool(ThreadPoolCI);
}
Expand Down

0 comments on commit 192ad3e

Please sign in to comment.