From 442fa7cd7c41daa6ecd92fd3a8e42a96c9118a40 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Thu, 1 Jan 2026 16:34:09 +0800 Subject: [PATCH] support for circular textures in sdcpp --- expose.h | 2 + koboldcpp.py | 6 ++- otherarch/sdcpp/sdtype_adapter.cpp | 60 ++++++++++------------------ otherarch/sdcpp/stable-diffusion.cpp | 27 +++++++++++++ otherarch/sdcpp/stable-diffusion.h | 2 + 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/expose.h b/expose.h index 9a6163072..f1961de8f 100644 --- a/expose.h +++ b/expose.h @@ -217,6 +217,8 @@ struct sd_generation_inputs const int vid_req_frames = 1; const int video_output_type = 0; //0=gif, 1=avi, 2=both const bool remove_limits = false; + const bool circular_x = false; + const bool circular_y = false; }; struct sd_generation_outputs { diff --git a/koboldcpp.py b/koboldcpp.py index 553abd784..857fdbf84 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -337,7 +337,9 @@ class sd_generation_inputs(ctypes.Structure): ("clip_skip", ctypes.c_int), ("vid_req_frames", ctypes.c_int), ("video_output_type", ctypes.c_int), - ("remove_limits", ctypes.c_bool)] + ("remove_limits", ctypes.c_bool), + ("circular_x", ctypes.c_bool), + ("circular_y", ctypes.c_bool)] class sd_generation_outputs(ctypes.Structure): _fields_ = [("status", ctypes.c_int), @@ -2032,6 +2034,8 @@ def sd_generate(genparams): inputs.vid_req_frames = vid_req_frames inputs.video_output_type = video_output_type inputs.remove_limits = allow_remove_limits + inputs.circular_x = tryparseint(adapter_obj.get("circular_x", genparams.get("circular_x",0)),0) + inputs.circular_y = tryparseint(adapter_obj.get("circular_y", genparams.get("circular_y",0)),0) ret = handle.sd_generate(inputs) data_main = "" data_extra = "" diff --git a/otherarch/sdcpp/sdtype_adapter.cpp b/otherarch/sdcpp/sdtype_adapter.cpp index 1013a6862..8983b89fe 100644 --- a/otherarch/sdcpp/sdtype_adapter.cpp +++ b/otherarch/sdcpp/sdtype_adapter.cpp @@ -362,7 +362,6 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) { params.n_threads = sd_params->n_threads; params.wtype = sd_params->wtype; - params.keep_clip_on_cpu = sd_params->clip_on_cpu; params.diffusion_flash_attn = sd_params->diffusion_flash_attn; params.diffusion_conv_direct = sd_params->diffusion_conv_direct; params.vae_conv_direct = sd_params->vae_conv_direct; @@ -380,19 +379,12 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) { if(inputs.debugmode==1) { - std::stringstream ss; - ss << "\nMODEL:" << params.model_path - << "\nDIFFUSION:" << params.diffusion_model_path - << "\nVAE:" << params.vae_path - << "\nTAESD:" << params.taesd_path - << "\nPHOTOMAKER:" << params.photo_maker_path - << "\nTHREADS:" << params.n_threads - << "\nWTYPE:" << params.wtype - << "\nDIFFUSIONFLASHATTN:" << (params.diffusion_flash_attn ? 1 : 0) - << "\nDIFFUSIONCONVDIRECT:" << (params.diffusion_conv_direct ? 1 : 0) - << "\nVAECONVDIRECT:" << (params.vae_conv_direct ? 1 : 0) - << "\n"; - printf("%s", ss.str().c_str()); + char* buf = sd_ctx_params_to_str(¶ms); + if(buf) + { + printf("\n%s\n", buf); + free(buf); + } } sd_ctx = new_sd_ctx(¶ms); @@ -774,6 +766,8 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) sd_params->sample_method = sd_get_default_sample_method(sd_ctx); } + SetCircularAxesAll(sd_ctx, inputs.circular_x, inputs.circular_y); + auto loadedsdver = get_loaded_sd_version(sd_ctx); bool is_img2img = img2img_data != ""; bool is_wan = (loadedsdver == SDVersion::VERSION_WAN2 || loadedsdver == SDVersion::VERSION_WAN2_2_I2V || loadedsdver == SDVersion::VERSION_WAN2_2_TI2V); @@ -1061,19 +1055,12 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) { if(!sd_is_quiet && sddebugmode==1) { - std::stringstream ss; - ss << "\nTXT2IMG PROMPT:" << params.prompt - << "\nNPROMPT:" << params.negative_prompt - << "\nCLPSKP:" << params.clip_skip - << "\nCFGSCLE:" << params.sample_params.guidance.txt_cfg - << "\nSIZE:" << params.width << "x" << params.height - << "\nSM:" << sd_sample_method_name(params.sample_params.sample_method) - << "\nSCHED:" << get_scheduler_name(params.sample_params.scheduler) - << "\nSTEP:" << params.sample_params.sample_steps - << "\nSEED:" << params.seed - << "\nBATCH:" << params.batch_count - << "\n\n"; - printf("%s", ss.str().c_str()); + char* buf = sd_img_gen_params_to_str(¶ms); + if(buf) + { + printf("\n%s\n", buf); + free(buf); + } } fflush(stdout); @@ -1146,19 +1133,12 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) if(!sd_is_quiet && sddebugmode==1) { - std::stringstream ss; - ss << "\nIMG2IMG PROMPT:" << params.prompt - << "\nNPROMPT:" << params.negative_prompt - << "\nCLPSKP:" << params.clip_skip - << "\nCFGSCLE:" << params.sample_params.guidance.txt_cfg - << "\nSIZE:" << params.width << "x" << params.height - << "\nSM:" << sd_sample_method_name(params.sample_params.sample_method) - << "\nSTEP:" << params.sample_params.sample_steps - << "\nSEED:" << params.seed - << "\nSTRENGTH:" << params.strength - << "\nBATCH:" << params.batch_count - << "\n\n"; - printf("%s", ss.str().c_str()); + char* buf = sd_img_gen_params_to_str(¶ms); + if(buf) + { + printf("\n%s\n", buf); + free(buf); + } } fflush(stdout); diff --git a/otherarch/sdcpp/stable-diffusion.cpp b/otherarch/sdcpp/stable-diffusion.cpp index 35cb40596..66969f965 100644 --- a/otherarch/sdcpp/stable-diffusion.cpp +++ b/otherarch/sdcpp/stable-diffusion.cpp @@ -2732,6 +2732,26 @@ public: ggml_ext_tensor_clamp_inplace(result, 0.0f, 1.0f); return result; } + + //added for kcpp + void SetCircularAxesAll(bool circular_x, bool circular_y) + { + diffusion_model->set_circular_axes(circular_x, circular_y); + if (high_noise_diffusion_model) { + high_noise_diffusion_model->set_circular_axes(circular_x, circular_y); + } + if (control_net) { + control_net->set_circular_axes(circular_x, circular_y); + } + if (first_stage_model) { + first_stage_model->set_circular_axes(circular_x, circular_y); + } + if (tae_first_stage) { + tae_first_stage->set_circular_axes(circular_x, circular_y); + } + } + //end added for kcpp + }; /*================================================= SD API ==================================================*/ @@ -4331,3 +4351,10 @@ SD_API sd_image_t* generate_video(sd_ctx_t* sd_ctx, const sd_vid_gen_params_t* s return result_images; } + +//added for kcpp +void SetCircularAxesAll(sd_ctx_t* sd_ctx, bool circular_x, bool circular_y) +{ + sd_ctx->sd->SetCircularAxesAll(circular_x, circular_y); +} +//end added for kcpp diff --git a/otherarch/sdcpp/stable-diffusion.h b/otherarch/sdcpp/stable-diffusion.h index 3e9faf854..1707dfcdc 100644 --- a/otherarch/sdcpp/stable-diffusion.h +++ b/otherarch/sdcpp/stable-diffusion.h @@ -369,6 +369,8 @@ SD_API sd_image_t* generate_image(sd_ctx_t* sd_ctx, const sd_img_gen_params_t* s SD_API void sd_vid_gen_params_init(sd_vid_gen_params_t* sd_vid_gen_params); SD_API sd_image_t* generate_video(sd_ctx_t* sd_ctx, const sd_vid_gen_params_t* sd_vid_gen_params, int* num_frames_out); +void SetCircularAxesAll(sd_ctx_t* sd_ctx, bool circular_x, bool circular_y); + typedef struct upscaler_ctx_t upscaler_ctx_t; SD_API upscaler_ctx_t* new_upscaler_ctx(const char* esrgan_path,