Vulkan Sampler implementation The Vulkan sampler is simply a state, similar to the existing sw::Sampler::State(), which will eventually be used by the texture sampling code. Bug b/119823006 Change-Id: Ib2f09683f82dbf5b5aacde1555ee850c76cda9e2 Reviewed-on: https://swiftshader-review.googlesource.com/c/22728 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkDestroy.h b/src/Vulkan/VkDestroy.h index 0957d89..cdc907f 100644 --- a/src/Vulkan/VkDestroy.h +++ b/src/Vulkan/VkDestroy.h
@@ -26,6 +26,7 @@ #include "VkPipelineLayout.hpp" #include "VkPhysicalDevice.hpp" #include "VkQueue.hpp" +#include "VkSampler.hpp" #include "VkSemaphore.hpp" #include "VkShaderModule.hpp" #include "VkRenderPass.hpp"
diff --git a/src/Vulkan/VkSampler.hpp b/src/Vulkan/VkSampler.hpp new file mode 100644 index 0000000..fc62389 --- /dev/null +++ b/src/Vulkan/VkSampler.hpp
@@ -0,0 +1,77 @@ +// Copyright 2018 The SwiftShader Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef VK_SAMPLER_HPP_ +#define VK_SAMPLER_HPP_ + +#include "VkDevice.hpp" + +namespace vk +{ + +class Sampler : public Object<Sampler, VkSampler> +{ +public: + Sampler(const VkSamplerCreateInfo* pCreateInfo, void* mem) : + magFilter(pCreateInfo->magFilter), + minFilter(pCreateInfo->minFilter), + mipmapMode(pCreateInfo->mipmapMode), + addressModeU(pCreateInfo->addressModeU), + addressModeV(pCreateInfo->addressModeV), + addressModeW(pCreateInfo->addressModeW), + mipLodBias(pCreateInfo->mipLodBias), + anisotropyEnable(pCreateInfo->anisotropyEnable), + maxAnisotropy(pCreateInfo->maxAnisotropy), + compareEnable(pCreateInfo->compareEnable), + compareOp(pCreateInfo->compareOp), + minLod(pCreateInfo->minLod), + maxLod(pCreateInfo->maxLod), + borderColor(pCreateInfo->borderColor), + unnormalizedCoordinates(pCreateInfo->unnormalizedCoordinates) + { + } + + ~Sampler() = delete; + + static size_t ComputeRequiredAllocationSize(const VkSamplerCreateInfo* pCreateInfo) + { + return 0; + } + +private: + VkFilter magFilter = VK_FILTER_NEAREST; + VkFilter minFilter = VK_FILTER_NEAREST; + VkSamplerMipmapMode mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; + VkSamplerAddressMode addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; + VkSamplerAddressMode addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; + VkSamplerAddressMode addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; + float mipLodBias = 0.0f; + VkBool32 anisotropyEnable = VK_FALSE; + float maxAnisotropy = 0.0f; + VkBool32 compareEnable = VK_FALSE; + VkCompareOp compareOp = VK_COMPARE_OP_NEVER; + float minLod = 0.0f; + float maxLod = 0.0f; + VkBorderColor borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; + VkBool32 unnormalizedCoordinates = VK_FALSE; +}; + +static inline Sampler* Cast(VkSampler object) +{ + return reinterpret_cast<Sampler*>(object); +} + +} // namespace vk + +#endif // VK_SAMPLER_HPP_ \ No newline at end of file
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp index 8bea5e9..0972c62 100644 --- a/src/Vulkan/libVulkan.cpp +++ b/src/Vulkan/libVulkan.cpp
@@ -30,6 +30,7 @@ #include "VkPipeline.hpp" #include "VkPipelineLayout.hpp" #include "VkQueue.hpp" +#include "VkSampler.hpp" #include "VkSemaphore.hpp" #include "VkShaderModule.hpp" #include "VkRenderPass.hpp" @@ -768,7 +769,7 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator) { TRACE("(VkDevice device = 0x%X, VkShaderModule shaderModule = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)", - device, shaderModule, pAllocator); + device, shaderModule, pAllocator); vk::destroy(shaderModule, pAllocator); } @@ -898,9 +899,12 @@ TRACE("(VkDevice device = 0x%X, const VkSamplerCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkSampler* pSampler = 0x%X)", device, pCreateInfo, pAllocator, pSampler); - UNIMPLEMENTED(); + if(pCreateInfo->pNext || pCreateInfo->flags) + { + UNIMPLEMENTED(); + } - return VK_SUCCESS; + return vk::Sampler::Create(pAllocator, pCreateInfo, pSampler); } VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator) @@ -908,7 +912,7 @@ TRACE("(VkDevice device = 0x%X, VkSampler sampler = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)", device, sampler, pAllocator); - UNIMPLEMENTED(); + vk::destroy(sampler, pAllocator); } VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout)
diff --git a/src/Vulkan/vulkan.vcxproj b/src/Vulkan/vulkan.vcxproj index 78ebcfa..a9a6383 100644 --- a/src/Vulkan/vulkan.vcxproj +++ b/src/Vulkan/vulkan.vcxproj
@@ -209,6 +209,7 @@ <ClInclude Include="VkPipelineLayout.hpp" /> <ClInclude Include="VkQueue.hpp" /> <ClInclude Include="VkRenderPass.hpp" /> + <ClInclude Include="VkSampler.hpp" /> <ClInclude Include="VkSemaphore.hpp" /> <ClInclude Include="VkShaderModule.hpp" /> <ClInclude Include="..\Device\Blitter.hpp" />
diff --git a/src/Vulkan/vulkan.vcxproj.filters b/src/Vulkan/vulkan.vcxproj.filters index 492be8e..1d684b4 100644 --- a/src/Vulkan/vulkan.vcxproj.filters +++ b/src/Vulkan/vulkan.vcxproj.filters
@@ -311,6 +311,9 @@ <ClInclude Include="VkRenderPass.hpp"> <Filter>Header Files\Vulkan</Filter> </ClInclude> + <ClInclude Include="VkSampler.hpp"> + <Filter>Header Files\Vulkan</Filter> + </ClInclude> <ClInclude Include="VkSemaphore.hpp"> <Filter>Header Files\Vulkan</Filter> </ClInclude>