Commit eac32c45 by Ben Clayton

SpirvShaderSampling: Fix flaky tests.

The cache keys were colliding, causing mayhem. Add 32-bit unique keys to ImageViews and Samplers, combine them into a unique 64 bit key. Bug: b/131246679 Change-Id: I74c86a80ee5fec1c97eda720bd0797bff4a1a7e0 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29934 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent bd54e075
...@@ -322,6 +322,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command> ...@@ -322,6 +322,7 @@ if %errorlevel% neq 0 goto :VCEnd</Command>
<ClInclude Include="$(SolutionDir)src\Vulkan\VkQueue.hpp" /> <ClInclude Include="$(SolutionDir)src\Vulkan\VkQueue.hpp" />
<ClCompile Include="$(SolutionDir)src\Vulkan\VkRenderPass.cpp" /> <ClCompile Include="$(SolutionDir)src\Vulkan\VkRenderPass.cpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkRenderPass.hpp" /> <ClInclude Include="$(SolutionDir)src\Vulkan\VkRenderPass.hpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkSampler.cpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkSampler.hpp" /> <ClInclude Include="$(SolutionDir)src\Vulkan\VkSampler.hpp" />
<ClInclude Include="$(SolutionDir)src\Vulkan\VkSemaphore.hpp" /> <ClInclude Include="$(SolutionDir)src\Vulkan\VkSemaphore.hpp" />
<ClCompile Include="$(SolutionDir)src\Vulkan\VkShaderModule.cpp" /> <ClCompile Include="$(SolutionDir)src\Vulkan\VkShaderModule.cpp" />
......
...@@ -190,6 +190,9 @@ ...@@ -190,6 +190,9 @@
<ClCompile Include="$(SolutionDir)src\Vulkan\VkRenderPass.cpp"> <ClCompile Include="$(SolutionDir)src\Vulkan\VkRenderPass.cpp">
<Filter>src\Vulkan</Filter> <Filter>src\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="$(SolutionDir)src\Vulkan\VkSampler.cpp">
<Filter>src\Vulkan</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)src\Vulkan\VkShaderModule.cpp"> <ClCompile Include="$(SolutionDir)src\Vulkan\VkShaderModule.cpp">
<Filter>src\Vulkan</Filter> <Filter>src\Vulkan</Filter>
</ClCompile> </ClCompile>
......
...@@ -51,12 +51,11 @@ SpirvShader::ImageSampler *SpirvShader::getImageSamplerExplicitLod(const vk::Ima ...@@ -51,12 +51,11 @@ SpirvShader::ImageSampler *SpirvShader::getImageSamplerExplicitLod(const vk::Ima
SpirvShader::ImageSampler *SpirvShader::getImageSampler(SamplerMethod samplerMethod, const vk::ImageView *imageView, const vk::Sampler *sampler) SpirvShader::ImageSampler *SpirvShader::getImageSampler(SamplerMethod samplerMethod, const vk::ImageView *imageView, const vk::Sampler *sampler)
{ {
// TODO(b/129523279): Move somewhere sensible. // TODO(b/129523279): Move somewhere sensible.
static std::unordered_map<uintptr_t, ImageSampler*> cache; static std::unordered_map<uint64_t, ImageSampler*> cache;
static std::mutex mutex; static std::mutex mutex;
// FIXME(b/129523279): Don't use pointers: they can be deleted and reused. Instead combine some two unique ids.
// FIXME(b/129523279): Take instruction opcode and optional parameters into acount (SamplerMethod / SamplerOption). // FIXME(b/129523279): Take instruction opcode and optional parameters into acount (SamplerMethod / SamplerOption).
auto key = reinterpret_cast<uintptr_t>(imageView) ^ reinterpret_cast<uintptr_t>(sampler); auto key = (static_cast<uint64_t>(imageView->id) << 32) | static_cast<uint64_t>(sampler->id);
std::unique_lock<std::mutex> lock(mutex); std::unique_lock<std::mutex> lock(mutex);
auto it = cache.find(key); auto it = cache.find(key);
...@@ -79,7 +78,7 @@ void SpirvShader::emitSamplerFunction( ...@@ -79,7 +78,7 @@ void SpirvShader::emitSamplerFunction(
const vk::ImageView *imageView, const vk::Sampler *sampler, const vk::ImageView *imageView, const vk::Sampler *sampler,
Pointer<Byte> image, Pointer<SIMD::Float> in, Pointer<Byte> out, Pointer<Byte> constants) Pointer<Byte> image, Pointer<SIMD::Float> in, Pointer<Byte> out, Pointer<Byte> constants)
{ {
Sampler::State samplerState; Sampler::State samplerState = {};
samplerState.textureType = convertTextureType(imageView->getType()); samplerState.textureType = convertTextureType(imageView->getType());
samplerState.textureFormat = imageView->getFormat(); samplerState.textureFormat = imageView->getFormat();
samplerState.textureFilter = convertFilterMode(sampler); samplerState.textureFilter = convertFilterMode(sampler);
......
...@@ -42,6 +42,8 @@ namespace ...@@ -42,6 +42,8 @@ namespace
namespace vk namespace vk
{ {
std::atomic<uint32_t> ImageView::nextID(1);
ImageView::ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem) : ImageView::ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem) :
image(Cast(pCreateInfo->image)), viewType(pCreateInfo->viewType), format(pCreateInfo->format), image(Cast(pCreateInfo->image)), viewType(pCreateInfo->viewType), format(pCreateInfo->format),
components(ResolveIdentityMapping(pCreateInfo->components)), components(ResolveIdentityMapping(pCreateInfo->components)),
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "VkObject.hpp" #include "VkObject.hpp"
#include "VkImage.hpp" #include "VkImage.hpp"
#include <atomic>
namespace vk namespace vk
{ {
...@@ -52,7 +54,10 @@ public: ...@@ -52,7 +54,10 @@ public:
const VkImageSubresourceRange &getSubresourceRange() const { return subresourceRange; } const VkImageSubresourceRange &getSubresourceRange() const { return subresourceRange; }
size_t getImageSizeInBytes() const { return image->getMemoryRequirements().size; } size_t getImageSizeInBytes() const { return image->getMemoryRequirements().size; }
const uint32_t id = nextID++;
private: private:
static std::atomic<uint32_t> nextID;
bool imageTypesMatch(VkImageType imageType) const; bool imageTypesMatch(VkImageType imageType) const;
Image *const image = nullptr; Image *const image = nullptr;
......
// Copyright 2019 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.
#include "VkSampler.hpp"
namespace vk
{
std::atomic<uint32_t> Sampler::nextID(1);
} // namespace vk
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "VkDevice.hpp" #include "VkDevice.hpp"
#include <atomic>
namespace vk namespace vk
{ {
...@@ -49,6 +51,7 @@ public: ...@@ -49,6 +51,7 @@ public:
return 0; return 0;
} }
const uint32_t id = nextID++;
const VkFilter magFilter = VK_FILTER_NEAREST; const VkFilter magFilter = VK_FILTER_NEAREST;
const VkFilter minFilter = VK_FILTER_NEAREST; const VkFilter minFilter = VK_FILTER_NEAREST;
const VkSamplerMipmapMode mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; const VkSamplerMipmapMode mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
...@@ -64,6 +67,9 @@ public: ...@@ -64,6 +67,9 @@ public:
const float maxLod = 0.0f; const float maxLod = 0.0f;
const VkBorderColor borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; const VkBorderColor borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
const VkBool32 unnormalizedCoordinates = VK_FALSE; const VkBool32 unnormalizedCoordinates = VK_FALSE;
private:
static std::atomic<uint32_t> nextID;
}; };
static inline Sampler* Cast(VkSampler object) static inline Sampler* Cast(VkSampler object)
......
...@@ -134,6 +134,7 @@ IF EXIST "$(SolutionDir)..\deqp\build\external\vulkancts\modules\vulkan\" (copy ...@@ -134,6 +134,7 @@ IF EXIST "$(SolutionDir)..\deqp\build\external\vulkancts\modules\vulkan\" (copy
<ClCompile Include="VkQueryPool.cpp" /> <ClCompile Include="VkQueryPool.cpp" />
<ClCompile Include="VkQueue.cpp" /> <ClCompile Include="VkQueue.cpp" />
<ClCompile Include="VkRenderPass.cpp" /> <ClCompile Include="VkRenderPass.cpp" />
<ClCompile Include="VkSampler.cpp" />
<ClCompile Include="VkShaderModule.cpp" /> <ClCompile Include="VkShaderModule.cpp" />
<ClCompile Include="..\Device\Blitter.cpp" /> <ClCompile Include="..\Device\Blitter.cpp" />
<ClCompile Include="..\Device\Clipper.cpp" /> <ClCompile Include="..\Device\Clipper.cpp" />
......
...@@ -246,6 +246,9 @@ ...@@ -246,6 +246,9 @@
<ClCompile Include="VkRenderPass.cpp"> <ClCompile Include="VkRenderPass.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VkSampler.cpp">
<Filter>Source Files\Vulkan</Filter>
</ClCompile>
<ClCompile Include="VkShaderModule.cpp"> <ClCompile Include="VkShaderModule.cpp">
<Filter>Source Files\Vulkan</Filter> <Filter>Source Files\Vulkan</Filter>
</ClCompile> </ClCompile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment