Hi,

I ran into a problem caused by this part of the OCL specs (6.1.5
Alignment of Types):
"For 3-component vector data types, the size of the data type is 4 *
sizeof(component)."

and the corresponding part of Khronos cl_platform.h (with all types, not
just float):
/* cl_float3 is identical in size, alignment and behavior to cl_float4.
See section 6.1.5. */
typedef  cl_float4  cl_float3;

So when I try to run kernel that takes 3 element vectors as arguments I
get 'invalid arg size' error.

Not sure whether this is best solved in clang, libclc or clover. I tried
changing float3 to have 4 elements in libclc, it caused clang to
complain in thousand places. I don't think this can be handled cleanly
in clang, unless we add something like __attribute__((padding)).

I have attached a workaround that I use now.

any advice welcome,
Jan

-- 
Jan Vesely <jan.ves...@rutgers.edu>
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index a81bdf8..71ee01f 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -62,6 +62,8 @@
 #include <llvm/IR/DataLayout.h>
 #endif
 
+#include <llvm/Support/Debug.h>
+
 #include "pipe/p_state.h"
 #include "util/u_memory.h"
 
@@ -309,6 +311,13 @@ namespace {
 
             llvm::Type *arg_type = arg.getType();
             unsigned arg_size = TD.getTypeStoreSize(arg_type);
+            if (arg_type->isVectorTy() &&
+               ::llvm::cast<::llvm::VectorType>(arg_type)->getNumElements() == 3) {
+               ::llvm::dbgs() << "Fixing argument type: " << *arg_type
+                              << " size: " << arg_size << "->"
+                              << (arg_size / 3) * 4 << "\n";
+               arg_size = (arg_size / 3) * 4;
+            }
 
             llvm::Type *target_type = arg_type->isIntegerTy() ?
                TD.getSmallestLegalIntType(mod->getContext(), arg_size * 8) :

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to