-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
always use normalized sampler to read image3d with literal sampler (#…
…1215) We cannot use unormalized sampled with 3D images. This commit intend to fix that for literal sampler (static sampler defined in the kernel). When detecting a case of reading a image3d with a literal sampler using unnormalized coordinate: - create a equivalent sampler using normalized coordinate - normalized the coordinate Ref #1202
- Loading branch information
Showing
11 changed files
with
286 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2023 The Clspv 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 "SamplerUtils.h" | ||
|
||
using namespace llvm; | ||
|
||
namespace clspv { | ||
|
||
Value *NormalizedCoordinate(Module &M, IRBuilder<> &B, Value *Coord, Value *Img, | ||
Type *ImgTy) { | ||
auto getImageSizesFct = M.getOrInsertFunction( | ||
"clspv.get_image_sizes", | ||
FunctionType::get(Coord->getType(), {ImgTy}, false)); | ||
Value *ImgSizes = B.CreateCall(getImageSizesFct, {Img}); | ||
|
||
return B.CreateFDiv(Coord, ImgSizes); | ||
} | ||
|
||
} // namespace clspv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2023 The Clspv 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 _CLSPV_SAMPLER_UTILS_H | ||
#define _CLSPV_SAMPLER_UTILS_H | ||
|
||
#include "llvm/IR/IRBuilder.h" | ||
#include "llvm/IR/Value.h" | ||
|
||
namespace clspv { | ||
|
||
llvm::Value *NormalizedCoordinate(llvm::Module &M, llvm::IRBuilder<> &B, | ||
llvm::Value *Coord, llvm::Value *Img, | ||
llvm::Type *ImgTy); | ||
|
||
} // namespace clspv | ||
|
||
#endif |
30 changes: 30 additions & 0 deletions
30
test/ImageBuiltins/read_image3d_with_literal_unorm_sampler.cl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: clspv %s -o %t.spv --cl-native-math | ||
// RUN: spirv-dis %t.spv -o %t.spvasm | ||
// RUN: spirv-val %t.spv --target-env spv1.0 | ||
// RUN: FileCheck %s < %t.spvasm | ||
|
||
// CHECK-DAG: [[uint:%[^ ]+]] = OpTypeInt 32 0 | ||
// CHECK-DAG: [[float:%[^ ]+]] = OpTypeFloat 32 | ||
// CHECK-DAG: [[uint3:%[^ ]+]] = OpTypeVector [[uint]] 3 | ||
// CHECK-DAG: [[uint4:%[^ ]+]] = OpTypeVector [[uint]] 4 | ||
// CHECK-DAG: [[float4:%[^ ]+]] = OpTypeVector [[float]] 4 | ||
// CHECK-DAG: [[float_0:%[^ ]+]] = OpConstant [[float]] 0 | ||
// CHECK-DAG: [[uint_0:%[^ ]+]] = OpConstant [[uint]] 0 | ||
// CHECK-DAG: [[uint_1:%[^ ]+]] = OpConstant [[uint]] 1 | ||
// CHECK-DAG: [[uint_21:%[^ ]+]] = OpConstant [[uint]] 21 | ||
// CHECK-DAG: [[vec:%[^ ]+]] = OpConstantComposite [[uint4]] [[uint_1]] [[uint_1]] [[uint_1]] [[uint_1]] | ||
|
||
// CHECK: [[sizes:%[^ ]+]] = OpImageQuerySizeLod [[uint3]] {{.*}} [[uint_0]] | ||
// CHECK: [[shuffle:%[^ ]+]] = OpVectorShuffle [[uint4]] [[sizes]] [[vec]] 0 1 2 4 | ||
// CHECK: [[convert:%[^ ]+]] = OpConvertUToF [[float4]] [[shuffle]] | ||
// CHECK: [[div:%[^ ]+]] = OpFDiv [[float4]] %44 [[convert]] | ||
// CHECK: OpImageSampleExplicitLod [[float4]] {{.*}} [[div]] Lod [[float_0]] | ||
|
||
// CHECK: OpExtInst %void {{.*}} LiteralSampler [[uint_0]] [[uint_0]] [[uint_21]] | ||
|
||
static const sampler_t my_sampler = CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST | CLK_NORMALIZED_COORDS_FALSE; | ||
|
||
void kernel foo(read_only image3d_t img, global float4 *out, int i) | ||
{ | ||
*out = read_imagef(img, my_sampler, (int4)(2, 3, 4, 5)); | ||
} |
Oops, something went wrong.