writer/msl: Emit const on array and ptr parameters
This fixes issues with passing constant arrays to functions. Change-Id: I6e2f1c3f64df836c0b6a55ab925cf3c2bc317733 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51861 Auto-Submit: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
ed86bf99b0
commit
e5fdd58352
|
@ -1311,7 +1311,9 @@ bool GeneratorImpl::EmitFunctionInternal(ast::Function* func,
|
||||||
|
|
||||||
auto* type = program_->Sem().Get(v)->Type();
|
auto* type = program_->Sem().Get(v)->Type();
|
||||||
|
|
||||||
if (!EmitType(type, program_->Symbols().NameFor(v->symbol()))) {
|
std::string param_name =
|
||||||
|
"const " + program_->Symbols().NameFor(v->symbol());
|
||||||
|
if (!EmitType(type, param_name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Parameter name is output as part of the type for arrays and pointers.
|
// Parameter name is output as part of the type for arrays and pointers.
|
||||||
|
|
|
@ -770,7 +770,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
|
||||||
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
EXPECT_EQ(gen.result(), R"(#include <metal_stdlib>
|
||||||
|
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
void my_func(float a[5]) {
|
void my_func(float const a[5]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <metal_stdlib>
|
#include <metal_stdlib>
|
||||||
|
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
int func(int value, thread int* pointer) {
|
int func(int value, thread int* const pointer) {
|
||||||
int const x_9 = *(pointer);
|
int const x_9 = *(pointer);
|
||||||
return (value + x_9);
|
return (value + x_9);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <metal_stdlib>
|
#include <metal_stdlib>
|
||||||
|
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
int func(int value, thread int* pointer) {
|
int func(int value, thread int* const pointer) {
|
||||||
return (value + *(pointer));
|
return (value + *(pointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <metal_stdlib>
|
#include <metal_stdlib>
|
||||||
|
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
void func(int value, thread int* pointer) {
|
void func(int value, thread int* const pointer) {
|
||||||
*(pointer) = value;
|
*(pointer) = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <metal_stdlib>
|
#include <metal_stdlib>
|
||||||
|
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
void func(int value, thread int* pointer) {
|
void func(int value, thread int* const pointer) {
|
||||||
*(pointer) = value;
|
*(pointer) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ using namespace metal;
|
||||||
struct S {
|
struct S {
|
||||||
};
|
};
|
||||||
|
|
||||||
void foo(bool param_bool, int param_i32, uint param_u32, float param_f32, int2 param_v2i32, uint3 param_v3u32, float4 param_v4f32, float2x3 param_m2x3, float param_arr[4], S param_struct, thread float* param_ptr_f32, thread float4* param_ptr_vec, thread float (*param_ptr_arr)[4]) {
|
void foo(bool param_bool, int param_i32, uint param_u32, float param_f32, int2 param_v2i32, uint3 param_v3u32, float4 param_v4f32, float2x3 param_m2x3, float const param_arr[4], S param_struct, thread float* const param_ptr_f32, thread float4* const param_ptr_vec, thread float (*const param_ptr_arr)[4]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel void tint_symbol() {
|
kernel void tint_symbol() {
|
||||||
|
|
Loading…
Reference in New Issue