Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/libANGLE/CLSampler.cpp
1693 views
1
//
2
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// CLSampler.cpp: Implements the cl::Sampler class.
7
8
#include "libANGLE/CLSampler.h"
9
10
#include "libANGLE/CLContext.h"
11
12
#include <cstring>
13
14
namespace cl
15
{
16
17
cl_int Sampler::getInfo(SamplerInfo name, size_t valueSize, void *value, size_t *valueSizeRet) const
18
{
19
static_assert(std::is_same<cl_uint, cl_addressing_mode>::value &&
20
std::is_same<cl_uint, cl_filter_mode>::value,
21
"OpenCL type mismatch");
22
23
cl_uint valUInt = 0u;
24
void *valPointer = nullptr;
25
const void *copyValue = nullptr;
26
size_t copySize = 0u;
27
28
switch (name)
29
{
30
case SamplerInfo::ReferenceCount:
31
valUInt = getRefCount();
32
copyValue = &valUInt;
33
copySize = sizeof(valUInt);
34
break;
35
case SamplerInfo::Context:
36
valPointer = mContext->getNative();
37
copyValue = &valPointer;
38
copySize = sizeof(valPointer);
39
break;
40
case SamplerInfo::NormalizedCoords:
41
copyValue = &mNormalizedCoords;
42
copySize = sizeof(mNormalizedCoords);
43
break;
44
case SamplerInfo::AddressingMode:
45
valUInt = ToCLenum(mAddressingMode);
46
copyValue = &valUInt;
47
copySize = sizeof(valUInt);
48
break;
49
case SamplerInfo::FilterMode:
50
valUInt = ToCLenum(mFilterMode);
51
copyValue = &valUInt;
52
copySize = sizeof(valUInt);
53
break;
54
case SamplerInfo::Properties:
55
copyValue = mProperties.data();
56
copySize = mProperties.size() * sizeof(decltype(mProperties)::value_type);
57
break;
58
default:
59
return CL_INVALID_VALUE;
60
}
61
62
if (value != nullptr)
63
{
64
// CL_INVALID_VALUE if size in bytes specified by param_value_size is < size of return type
65
// as described in the Sampler Object Queries table and param_value is not NULL.
66
if (valueSize < copySize)
67
{
68
return CL_INVALID_VALUE;
69
}
70
if (copyValue != nullptr)
71
{
72
std::memcpy(value, copyValue, copySize);
73
}
74
}
75
if (valueSizeRet != nullptr)
76
{
77
*valueSizeRet = copySize;
78
}
79
return CL_SUCCESS;
80
}
81
82
Sampler::~Sampler() = default;
83
84
Sampler::Sampler(Context &context,
85
PropArray &&properties,
86
cl_bool normalizedCoords,
87
AddressingMode addressingMode,
88
FilterMode filterMode,
89
cl_int &errorCode)
90
: mContext(&context),
91
mProperties(std::move(properties)),
92
mNormalizedCoords(normalizedCoords),
93
mAddressingMode(addressingMode),
94
mFilterMode(filterMode),
95
mImpl(context.getImpl().createSampler(*this, errorCode))
96
{}
97
98
} // namespace cl
99
100