OSDN Git Service

Vulkan Sampler implementation
authorAlexis Hetu <sugoi@google.com>
Mon, 19 Nov 2018 16:30:43 +0000 (11:30 -0500)
committerAlexis Hétu <sugoi@google.com>
Wed, 21 Nov 2018 22:07:28 +0000 (22:07 +0000)
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>
src/Vulkan/VkDestroy.h
src/Vulkan/VkSampler.hpp [new file with mode: 0644]
src/Vulkan/libVulkan.cpp
src/Vulkan/vulkan.vcxproj
src/Vulkan/vulkan.vcxproj.filters

index 0957d89..cdc907f 100644 (file)
@@ -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 (file)
index 0000000..fc62389
--- /dev/null
@@ -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
index 8bea5e9..0972c62 100644 (file)
@@ -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 VkResult VKAPI_CALL vkCreateShaderModule(VkDevice device, const VkSha
 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 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(VkDevice device, const VkSamplerC
        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 @@ VKAPI_ATTR void VKAPI_CALL vkDestroySampler(VkDevice device, VkSampler sampler,
        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)
index 78ebcfa..a9a6383 100644 (file)
@@ -209,6 +209,7 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
     <ClInclude Include="VkPipelineLayout.hpp" />\r
     <ClInclude Include="VkQueue.hpp" />\r
     <ClInclude Include="VkRenderPass.hpp" />\r
+    <ClInclude Include="VkSampler.hpp" />\r
     <ClInclude Include="VkSemaphore.hpp" />\r
     <ClInclude Include="VkShaderModule.hpp" />\r
     <ClInclude Include="..\Device\Blitter.hpp" />\r
index 492be8e..1d684b4 100644 (file)
     <ClInclude Include="VkRenderPass.hpp">\r
       <Filter>Header Files\Vulkan</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="VkSampler.hpp">\r
+      <Filter>Header Files\Vulkan</Filter>\r
+    </ClInclude>\r
     <ClInclude Include="VkSemaphore.hpp">\r
       <Filter>Header Files\Vulkan</Filter>\r
     </ClInclude>\r