Hash :
f102ef02
Author :
Date :
2025-02-18T18:05:28
CL/Vulkan: Fix handling for NormalizedSamplerMaskPushConstant * Fixes creation of normalized sampler for push constant * CLSamplerVk should check if the sampler has not been created Tests-Passing: OCLCTS.test_image_streams CL_FILTER_NEAREST 3D, OCLCTS.test_image_streams max_images CL_FILTER_NEAREST 3D, OCLCTS.test_image_streams use_pitches CL_FILTER_NEAREST 3D Bug: angleproject:42266936 Change-Id: Ic70c55ad05f4babdd10b516e78a061bdb7aa2488 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6277809 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// CLSamplerVk.cpp: Implements the class methods for CLSamplerVk.
#include "libANGLE/renderer/vulkan/CLSamplerVk.h"
#include "common/PackedCLEnums_autogen.h"
#include "libANGLE/renderer/vulkan/CLContextVk.h"
#include "libANGLE/CLContext.h"
#include "libANGLE/CLSampler.h"
#include "libANGLE/cl_utils.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
using namespace clspv;
namespace rx
{
VkSamplerAddressMode CLSamplerVk::getVkAddressMode()
{
VkSamplerAddressMode addressMode;
switch (mSampler.getAddressingMode())
{
case cl::AddressingMode::None:
addressMode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
break;
case cl::AddressingMode::ClampToEdge:
addressMode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
break;
case cl::AddressingMode::Clamp:
addressMode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
break;
case cl::AddressingMode::Repeat:
addressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT;
break;
case cl::AddressingMode::MirroredRepeat:
addressMode = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
break;
default:
addressMode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
break;
}
if (!mSampler.getNormalizedCoords() && (addressMode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE &&
addressMode != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER))
{
addressMode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
}
return addressMode;
}
VkFilter CLSamplerVk::getVkFilter()
{
switch (mSampler.getFilterMode())
{
case cl::FilterMode::Nearest:
return VK_FILTER_NEAREST;
case cl::FilterMode::Linear:
return VK_FILTER_LINEAR;
default:
return VK_FILTER_LINEAR;
}
}
VkSamplerMipmapMode CLSamplerVk::getVkMipmapMode()
{
if (mSampler.getNormalizedCoords())
{
switch (mSampler.getFilterMode())
{
case cl::FilterMode::Nearest:
return VK_SAMPLER_MIPMAP_MODE_NEAREST;
case cl::FilterMode::Linear:
return VK_SAMPLER_MIPMAP_MODE_LINEAR;
default:
return VK_SAMPLER_MIPMAP_MODE_LINEAR;
}
}
return VK_SAMPLER_MIPMAP_MODE_NEAREST;
}
uint32_t CLSamplerVk::getSamplerMask()
{
uint32_t mask = 0;
if (mSampler.getNormalizedCoords())
{
mask |= SamplerNormalizedCoords::CLK_NORMALIZED_COORDS_TRUE;
}
switch (mSampler.getAddressingMode())
{
case cl::AddressingMode::None:
break;
case cl::AddressingMode::ClampToEdge:
mask |= SamplerAddressingMode::CLK_ADDRESS_CLAMP_TO_EDGE;
break;
case cl::AddressingMode::Clamp:
mask |= SamplerAddressingMode::CLK_ADDRESS_CLAMP;
break;
case cl::AddressingMode::Repeat:
mask |= SamplerAddressingMode::CLK_ADDRESS_REPEAT;
break;
case cl::AddressingMode::MirroredRepeat:
mask |= SamplerAddressingMode::CLK_ADDRESS_MIRRORED_REPEAT;
break;
default:
break;
}
switch (mSampler.getFilterMode())
{
case cl::FilterMode::Nearest:
mask |= SamplerFilterMode::CLK_FILTER_NEAREST;
break;
case cl::FilterMode::Linear:
default:
mask |= SamplerFilterMode::CLK_FILTER_LINEAR;
break;
}
return mask;
}
CLSamplerVk::CLSamplerVk(const cl::Sampler &sampler)
: CLSamplerImpl(sampler),
mContext(&sampler.getContext().getImpl<CLContextVk>()),
mRenderer(mContext->getRenderer()),
mSamplerHelper(),
mSamplerHelperNormalized()
{
VkSamplerAddressMode addressMode = getVkAddressMode();
VkFilter filter = getVkFilter();
VkSamplerMipmapMode mipmapMode = getVkMipmapMode();
VkBool32 unnormalizedCoordinates = !(mSampler.getNormalizedCoords());
mDefaultSamplerCreateInfo = {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = nullptr,
.flags = 0x0,
.magFilter = filter,
.minFilter = filter,
.mipmapMode = mipmapMode,
.addressModeU = addressMode,
.addressModeV = addressMode,
.addressModeW = addressMode,
.mipLodBias = 0.0f,
.anisotropyEnable = VK_FALSE,
.maxAnisotropy = 0.0f,
.compareEnable = VK_FALSE,
.compareOp = VK_COMPARE_OP_NEVER,
.minLod = 0.0f,
.maxLod = 0.0f,
.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK,
.unnormalizedCoordinates = unnormalizedCoordinates,
};
}
CLSamplerVk::~CLSamplerVk()
{
mSamplerHelper.destroy(mContext->getDevice());
if (mSamplerHelperNormalized.valid())
{
mSamplerHelperNormalized.destroy(mContext->getDevice());
}
}
angle::Result CLSamplerVk::create()
{
ANGLE_TRY(mSamplerHelper.init(mContext, mDefaultSamplerCreateInfo));
return angle::Result::Continue;
}
angle::Result CLSamplerVk::createNormalized()
{
if (!mSamplerHelperNormalized.valid())
{
mDefaultSamplerCreateInfo.unnormalizedCoordinates = false;
ANGLE_TRY(mSamplerHelperNormalized.init(mContext, mDefaultSamplerCreateInfo));
}
return angle::Result::Continue;
}
} // namespace rx