Skip to content

Commit

Permalink
Sampler creation allows specifying comparison function
Browse files Browse the repository at this point in the history
Raytracing Unit Tests - Fix Release configuration
  • Loading branch information
manaskulkarni786 committed Apr 9, 2018
1 parent eb081ad commit a9e07b1
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 9 deletions.
10 changes: 8 additions & 2 deletions Common_3/Renderer/Direct3D12/Direct3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2799,9 +2799,15 @@ namespace RENDERER_CPP_NAMESPACE {
inline bool hasMipmaps(const FilterType filter) { return (filter >= FILTER_BILINEAR); }
inline bool hasAniso(const FilterType filter) { return (filter >= FILTER_BILINEAR_ANISO); }

void addSampler(Renderer* pRenderer, Sampler** ppSampler, FilterType minFilter, FilterType magFilter, MipMapMode mipMapMode, AddressMode addressU, AddressMode addressV, AddressMode addressW, float mipLosBias, float maxAnisotropy)
void addSampler(Renderer* pRenderer, Sampler** ppSampler,
FilterType minFilter, FilterType magFilter,
MipMapMode mipMapMode,
AddressMode addressU, AddressMode addressV, AddressMode addressW,
float mipLosBias, float maxAnisotropy,
CompareMode compareFunc)
{
ASSERT(pRenderer);
ASSERT(compareFunc < MAX_COMPARE_MODES);

//allocate new sampler
Sampler* pSampler = (Sampler*)conf_calloc(1, sizeof(*pSampler));
Expand All @@ -2818,7 +2824,7 @@ namespace RENDERER_CPP_NAMESPACE {
pSampler->mDxSamplerDesc.AddressW = util_to_dx_texture_address_mode(addressW);
pSampler->mDxSamplerDesc.MipLODBias = mipLosBias;
pSampler->mDxSamplerDesc.MaxAnisotropy = (hasAniso(minFilter) || hasAniso(magFilter)) ? (UINT)maxAnisotropy : 1U;
pSampler->mDxSamplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
pSampler->mDxSamplerDesc.ComparisonFunc = gDx12ComparisonFuncTranslator[compareFunc];
pSampler->mDxSamplerDesc.BorderColor[0] = 0.0f;
pSampler->mDxSamplerDesc.BorderColor[1] = 0.0f;
pSampler->mDxSamplerDesc.BorderColor[2] = 0.0f;
Expand Down
7 changes: 6 additions & 1 deletion Common_3/Renderer/IRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,12 @@ ApiExport uint32_t calculateVertexLayoutStride(const VertexLayout* p_vertex_layo

ApiExport void addRenderTarget(Renderer* pRenderer, const RenderTargetDesc* p_desc, RenderTarget** pp_render_target, void* pNativeHandle = NULL);
ApiExport void removeRenderTarget(Renderer* pRenderer, RenderTarget* p_render_target);
ApiExport void addSampler(Renderer* pRenderer, Sampler** pp_sampler, FilterType minFilter = FILTER_LINEAR, FilterType magFilter = FILTER_LINEAR, MipMapMode mipMapMode = MIPMAP_MODE_LINEAR, AddressMode addressU = ADDRESS_MODE_CLAMP_TO_BORDER, AddressMode addressV = ADDRESS_MODE_CLAMP_TO_BORDER, AddressMode addressW = ADDRESS_MODE_CLAMP_TO_BORDER, float mipLosBias = 0.0f, float maxAnisotropy = 0.0f);
ApiExport void addSampler(Renderer* pRenderer, Sampler** pp_sampler,
FilterType minFilter = FILTER_LINEAR, FilterType magFilter = FILTER_LINEAR,
MipMapMode mipMapMode = MIPMAP_MODE_LINEAR,
AddressMode addressU = ADDRESS_MODE_CLAMP_TO_BORDER, AddressMode addressV = ADDRESS_MODE_CLAMP_TO_BORDER, AddressMode addressW = ADDRESS_MODE_CLAMP_TO_BORDER,
float mipLosBias = 0.0f, float maxAnisotropy = 0.0f,
CompareMode compareFunc = CMP_NEVER);
ApiExport void removeSampler(Renderer* pRenderer, Sampler* p_sampler);

// shader functions
Expand Down
11 changes: 9 additions & 2 deletions Common_3/Renderer/Metal/MetalRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,16 @@ void removeRenderTarget(Renderer* pRenderer, RenderTarget* pRenderTarget)
SAFE_FREE(pRenderTarget);
}

void addSampler(Renderer* pRenderer, Sampler** ppSampler, FilterType minFilter, FilterType magFilter, MipMapMode mipMapMode, AddressMode addressU, AddressMode addressV, AddressMode addressW, float mipLosBias, float maxAnisotropy)
void addSampler(Renderer* pRenderer, Sampler** ppSampler,
FilterType minFilter, FilterType magFilter,
MipMapMode mipMapMode,
AddressMode addressU, AddressMode addressV, AddressMode addressW,
float mipLosBias, float maxAnisotropy,
CompareMode compareFunc)
{
ASSERT(pRenderer);
ASSERT(pRenderer->pDevice != nil);
ASSERT(compareFunc < MAX_COMPARE_MODES);

Sampler* pSampler = (Sampler*)conf_calloc(1, sizeof(*pSampler));
ASSERT(pSampler);
Expand All @@ -1202,10 +1208,11 @@ void addSampler(Renderer* pRenderer, Sampler** ppSampler, FilterType minFilter,
samplerDesc.minFilter = (minFilter == FILTER_NEAREST ? MTLSamplerMinMagFilterNearest : MTLSamplerMinMagFilterLinear);
samplerDesc.magFilter = (magFilter == FILTER_NEAREST ? MTLSamplerMinMagFilterNearest : MTLSamplerMinMagFilterLinear);
samplerDesc.mipFilter = (mipMapMode == MIPMAP_MODE_NEAREST ? MTLSamplerMipFilterNearest : MTLSamplerMipFilterLinear);
samplerDesc.maxAnisotropy = (maxAnisotropy==0 ? 1 : maxAnisotropy); // 0 is not allowed in Metal
samplerDesc.maxAnisotropy = (maxAnisotropy == 0 ? 1 : maxAnisotropy); // 0 is not allowed in Metal
samplerDesc.sAddressMode = gMtlAddressModeTranslator[addressU];
samplerDesc.tAddressMode = gMtlAddressModeTranslator[addressV];
samplerDesc.rAddressMode = gMtlAddressModeTranslator[addressW];
samplerDesc.compareFunction = gMtlComparisonFunctionTranslator[compareFunc];

pSampler->mtlSamplerState = [pRenderer->pDevice newSamplerStateWithDescriptor:samplerDesc];
pSampler->mSamplerId = (++gSamplerIds << 8U) + util_pthread_to_uint64(Thread::GetCurrentThreadID());
Expand Down
2 changes: 1 addition & 1 deletion Common_3/Renderer/ResourceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ void addResource(BufferLoadDesc* pBuffer, bool threaded = false);
void addResource(TextureLoadDesc* pTexture, bool threaded = false);
void addResources(uint32_t resourceCount, ResourceLoadDesc* pResources, bool threaded = false);

void updateResource(TextureUpdateDesc* pBuffer, bool batch = false);
void updateResource(BufferUpdateDesc* pBuffer, bool batch = false);
void updateResource(TextureUpdateDesc* pTexture, bool batch = false);
void updateResources(uint32_t resourceCount, ResourceUpdateDesc* pResources);

void flushResourceUpdates();
Expand Down
33 changes: 30 additions & 3 deletions Common_3/Renderer/Vulkan/Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2450,10 +2450,16 @@ namespace RENDERER_CPP_NAMESPACE {
SAFE_FREE(pRenderTarget);
}

void addSampler(Renderer* pRenderer, Sampler** pp_sampler, FilterType minFilter, FilterType magFilter, MipMapMode mipMapMode, AddressMode addressU, AddressMode addressV, AddressMode addressW, float mipLosBias, float maxAnisotropy)
void addSampler(Renderer* pRenderer, Sampler** pp_sampler,
FilterType minFilter, FilterType magFilter,
MipMapMode mipMapMode,
AddressMode addressU, AddressMode addressV, AddressMode addressW,
float mipLosBias, float maxAnisotropy,
CompareMode compareFunc)
{
ASSERT(pRenderer);
ASSERT(VK_NULL_HANDLE != pRenderer->pDevice);
ASSERT(compareFunc < MAX_COMPARE_MODES);

Sampler* pSampler = (Sampler*)conf_calloc(1, sizeof(*pSampler));
ASSERT(pSampler);
Expand All @@ -2473,8 +2479,8 @@ namespace RENDERER_CPP_NAMESPACE {
add_info.mipLodBias = mipLosBias;
add_info.anisotropyEnable = VK_FALSE;
add_info.maxAnisotropy = maxAnisotropy;
add_info.compareEnable = VK_FALSE;
add_info.compareOp = VK_COMPARE_OP_NEVER;
add_info.compareEnable = (gVkComparisonFuncTranslator[compareFunc] != VK_COMPARE_OP_NEVER) ? VK_TRUE : VK_FALSE;
add_info.compareOp = gVkComparisonFuncTranslator[compareFunc];
add_info.minLod = 0.0f;
add_info.maxLod = magFilter >= FILTER_LINEAR ? FLT_MAX : 0.0f;
add_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
Expand Down Expand Up @@ -3956,8 +3962,21 @@ namespace RENDERER_CPP_NAMESPACE {
pImageIndex);
ASSERT(VK_SUCCESS == vk_res);

pFence->mSubmitted = true;

// If swapchain is out of date, let caller know by setting image index to -1
if (vk_res == VK_ERROR_OUT_OF_DATE_KHR)
{
*pImageIndex = -1;
vkResetFences(pRenderer->pDevice, 1, &pFence->pVkFence);
pFence->mSubmitted = false;
return;
}

vk_res = vkWaitForFences(pRenderer->pDevice, 1, &pFence->pVkFence, VK_TRUE, UINT64_MAX);
ASSERT(VK_SUCCESS == vk_res);
vkResetFences(pRenderer->pDevice, 1, &pFence->pVkFence);
pFence->mSubmitted = false;
}
else
{
Expand All @@ -3969,6 +3988,14 @@ namespace RENDERER_CPP_NAMESPACE {
pImageIndex);
ASSERT(VK_SUCCESS == vk_res);

// If swapchain is out of date, let caller know by setting image index to -1
if (vk_res == VK_ERROR_OUT_OF_DATE_KHR)
{
*pImageIndex = -1;
pSignalSemaphore->mSignaled = true;
return;
}

pSignalSemaphore->mSignaled = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDx|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="Unit_Tests_Raytracing.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDx|x64'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDx|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="Unit_Tests_Raytracing.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDx|x64'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDx|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="Unit_Tests_Raytracing.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDx|x64'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDx|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="Unit_Tests_Raytracing.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDx|x64'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDx|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="Unit_Tests_Raytracing.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDx|x64'">
Expand Down

0 comments on commit a9e07b1

Please sign in to comment.