@@ -126,6 +126,15 @@ void ArgLoadExpression::flatten(FlattenContext *ctx) {
126
126
stmt = ctx->back_stmt ();
127
127
}
128
128
129
+ void TexturePtrExpression::type_check (CompileConfig *config) {
130
+ }
131
+
132
+ void TexturePtrExpression::flatten (FlattenContext *ctx) {
133
+ ctx->push_back <ArgLoadStmt>(arg_id, PrimitiveType::f32, true );
134
+ ctx->push_back <TexturePtrStmt>(ctx->back_stmt ());
135
+ stmt = ctx->back_stmt ();
136
+ }
137
+
129
138
void RandExpression::type_check (CompileConfig *) {
130
139
TI_ASSERT_INFO (dt->is <PrimitiveType>() && dt != PrimitiveType::unknown,
131
140
" Invalid dt [{}] for RandExpression" , dt->to_string ());
@@ -589,6 +598,52 @@ void SNodeOpExpression::flatten(FlattenContext *ctx) {
589
598
stmt = ctx->back_stmt ();
590
599
}
591
600
601
+ void TextureOpExpression::type_check (CompileConfig *config) {
602
+ if (op == TextureOpType::sample_lod) {
603
+ // UV, Lod
604
+ TI_ASSERT_INFO (args.size () == 3 ,
605
+ " Invalid number of args for sample_lod Texture op" );
606
+ TI_ASSERT_TYPE_CHECKED (args[0 ]);
607
+ TI_ASSERT_TYPE_CHECKED (args[1 ]);
608
+ TI_ASSERT_TYPE_CHECKED (args[2 ]);
609
+ if (args[0 ].get_ret_type () != PrimitiveType::f32 ||
610
+ args[1 ].get_ret_type () != PrimitiveType::f32 ||
611
+ args[2 ].get_ret_type () != PrimitiveType::f32) {
612
+ throw TaichiTypeError (
613
+ fmt::format (" All arguments to sample_lod Texture op must be FP32" ));
614
+ }
615
+ } else if (op == TextureOpType::fetch_texel) {
616
+ // index, int LOD
617
+ TI_ASSERT_INFO (args.size () == 3 ,
618
+ " Invalid number of args for fetch_texel Texture op" );
619
+ TI_ASSERT_TYPE_CHECKED (args[0 ]);
620
+ TI_ASSERT_TYPE_CHECKED (args[1 ]);
621
+ TI_ASSERT_TYPE_CHECKED (args[2 ]);
622
+ if (args[0 ].get_ret_type () != PrimitiveType::i32 ||
623
+ args[1 ].get_ret_type () != PrimitiveType::i32 ||
624
+ args[2 ].get_ret_type () != PrimitiveType::i32) {
625
+ throw TaichiTypeError (
626
+ fmt::format (" All arguments to fetch_texel Texture op must be i32" ));
627
+ }
628
+ } else {
629
+ TI_ERROR (" Invalid TextureOpType" );
630
+ }
631
+ ret_type =
632
+ TypeFactory::get_instance ().get_pointer_type (PrimitiveType::f32,
633
+ /* is_bit_pointer=*/ false );
634
+ }
635
+
636
+ void TextureOpExpression::flatten (FlattenContext *ctx) {
637
+ flatten_rvalue (texture_ptr, ctx);
638
+ std::vector<Stmt *> arg_stmts;
639
+ for (Expr &arg : args.exprs ) {
640
+ flatten_rvalue (arg, ctx);
641
+ arg_stmts.push_back (arg->stmt );
642
+ }
643
+ ctx->push_back <TextureOpStmt>(op, texture_ptr->stmt , arg_stmts);
644
+ stmt = ctx->back_stmt ();
645
+ }
646
+
592
647
void ConstExpression::type_check (CompileConfig *) {
593
648
TI_ASSERT_INFO (
594
649
val.dt ->is <PrimitiveType>() && val.dt != PrimitiveType::unknown,
0 commit comments