Cleanup
This commit is contained in:
+1
-55
@@ -1113,12 +1113,10 @@ gpu_texture_t *iron_load_texture(string_t *file) {
|
||||
}
|
||||
|
||||
#ifdef WITH_AUDIO
|
||||
|
||||
any iron_load_sound(string_t *file) {
|
||||
iron_a1_sound_t *sound = iron_a1_sound_create(file);
|
||||
return sound;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
buffer_t *iron_load_blob(string_t *file) {
|
||||
@@ -1741,56 +1739,4 @@ void iron_mp4_encode(buffer_t *pixels) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static gpu_buffer_t rt_constant_buffer;
|
||||
static gpu_raytrace_pipeline_t rt_pipeline;
|
||||
static gpu_raytrace_acceleration_structure_t rt_accel;
|
||||
static bool rt_created = false;
|
||||
static bool rt_accel_created = false;
|
||||
const int rt_constant_buffer_size = 24;
|
||||
|
||||
void iron_raytrace_init(buffer_t *shader) {
|
||||
if (rt_created) {
|
||||
gpu_buffer_destroy(&rt_constant_buffer);
|
||||
gpu_raytrace_pipeline_destroy(&rt_pipeline);
|
||||
}
|
||||
rt_created = true;
|
||||
gpu_constant_buffer_init(&rt_constant_buffer, rt_constant_buffer_size * 4);
|
||||
gpu_raytrace_pipeline_init(&rt_pipeline, shader->buffer, (int)shader->length, &rt_constant_buffer);
|
||||
}
|
||||
|
||||
void iron_raytrace_as_init() {
|
||||
if (rt_accel_created) {
|
||||
gpu_raytrace_acceleration_structure_destroy(&rt_accel);
|
||||
}
|
||||
rt_accel_created = true;
|
||||
gpu_raytrace_acceleration_structure_init(&rt_accel);
|
||||
}
|
||||
|
||||
void iron_raytrace_as_add(struct gpu_buffer *vb, gpu_buffer_t *ib, iron_matrix4x4_t transform) {
|
||||
gpu_raytrace_acceleration_structure_add(&rt_accel, vb, ib, transform);
|
||||
}
|
||||
|
||||
void iron_raytrace_as_build(struct gpu_buffer *vb_full, gpu_buffer_t *ib_full) {
|
||||
gpu_raytrace_acceleration_structure_build(&rt_accel, vb_full, ib_full);
|
||||
}
|
||||
|
||||
void iron_raytrace_set_textures(gpu_texture_t *tex0, gpu_texture_t *tex1, gpu_texture_t *tex2, gpu_texture_t *texenv, gpu_texture_t *texsobol, gpu_texture_t *texscramble, gpu_texture_t *texrank) {
|
||||
gpu_raytrace_set_textures(tex0, tex1, tex2, texenv, texsobol, texscramble, texrank);
|
||||
}
|
||||
|
||||
void iron_raytrace_dispatch_rays(gpu_texture_t *render_target, buffer_t *buffer) {
|
||||
float *cb = (float *)buffer->buffer;
|
||||
gpu_constant_buffer_lock(&rt_constant_buffer, 0, rt_constant_buffer.count);
|
||||
for (int i = 0; i < rt_constant_buffer_size; ++i) {
|
||||
float *floats = (float *)(&rt_constant_buffer.data[i * 4]);
|
||||
floats[0] = cb[i];
|
||||
}
|
||||
gpu_constant_buffer_unlock(&rt_constant_buffer);
|
||||
|
||||
gpu_raytrace_set_acceleration_structure(&rt_accel);
|
||||
gpu_raytrace_set_pipeline(&rt_pipeline);
|
||||
gpu_raytrace_set_target(render_target);
|
||||
gpu_raytrace_dispatch_rays();
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // NO_IRON_API
|
||||
|
||||
@@ -364,3 +364,51 @@ int gpu_texture_format_size(gpu_texture_format_t format) {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
static gpu_buffer_t rt_constant_buffer;
|
||||
static gpu_raytrace_pipeline_t rt_pipeline;
|
||||
static gpu_raytrace_acceleration_structure_t rt_accel;
|
||||
static bool rt_created = false;
|
||||
static bool rt_accel_created = false;
|
||||
static const int rt_constant_buffer_size = 24;
|
||||
|
||||
void _gpu_raytrace_init(buffer_t *shader) {
|
||||
if (rt_created) {
|
||||
gpu_buffer_destroy(&rt_constant_buffer);
|
||||
gpu_raytrace_pipeline_destroy(&rt_pipeline);
|
||||
}
|
||||
rt_created = true;
|
||||
gpu_constant_buffer_init(&rt_constant_buffer, rt_constant_buffer_size * 4);
|
||||
gpu_raytrace_pipeline_init(&rt_pipeline, shader->buffer, (int)shader->length, &rt_constant_buffer);
|
||||
}
|
||||
|
||||
void _gpu_raytrace_as_init() {
|
||||
if (rt_accel_created) {
|
||||
gpu_raytrace_acceleration_structure_destroy(&rt_accel);
|
||||
}
|
||||
rt_accel_created = true;
|
||||
gpu_raytrace_acceleration_structure_init(&rt_accel);
|
||||
}
|
||||
|
||||
void _gpu_raytrace_as_add(struct gpu_buffer *vb, gpu_buffer_t *ib, iron_matrix4x4_t transform) {
|
||||
gpu_raytrace_acceleration_structure_add(&rt_accel, vb, ib, transform);
|
||||
}
|
||||
|
||||
void _gpu_raytrace_as_build(struct gpu_buffer *vb_full, gpu_buffer_t *ib_full) {
|
||||
gpu_raytrace_acceleration_structure_build(&rt_accel, vb_full, ib_full);
|
||||
}
|
||||
|
||||
void _gpu_raytrace_dispatch_rays(gpu_texture_t *render_target, buffer_t *buffer) {
|
||||
float *cb = (float *)buffer->buffer;
|
||||
gpu_constant_buffer_lock(&rt_constant_buffer, 0, rt_constant_buffer.count);
|
||||
for (int i = 0; i < rt_constant_buffer_size; ++i) {
|
||||
float *floats = (float *)(&rt_constant_buffer.data[i * 4]);
|
||||
floats[0] = cb[i];
|
||||
}
|
||||
gpu_constant_buffer_unlock(&rt_constant_buffer);
|
||||
|
||||
gpu_raytrace_set_acceleration_structure(&rt_accel);
|
||||
gpu_raytrace_set_pipeline(&rt_pipeline);
|
||||
gpu_raytrace_set_target(render_target);
|
||||
gpu_raytrace_dispatch_rays();
|
||||
}
|
||||
|
||||
@@ -228,6 +228,13 @@ void gpu_raytrace_set_pipeline(gpu_raytrace_pipeline_t *pipeline);
|
||||
void gpu_raytrace_set_target(gpu_texture_t *output);
|
||||
void gpu_raytrace_dispatch_rays();
|
||||
|
||||
void _gpu_raytrace_init(buffer_t *shader);
|
||||
void _gpu_raytrace_as_init();
|
||||
void _gpu_raytrace_as_add(gpu_buffer_t *vb, gpu_buffer_t *ib, iron_matrix4x4_t transform);
|
||||
void _gpu_raytrace_as_build(gpu_buffer_t *vb_full, gpu_buffer_t *ib_full);
|
||||
void gpu_raytrace_set_textures(gpu_texture_t *tex0, gpu_texture_t *tex1, gpu_texture_t *tex2, gpu_texture_t *texenv, gpu_texture_t *texsobol, gpu_texture_t *texscramble, gpu_texture_t *texrank);
|
||||
void _gpu_raytrace_dispatch_rays(gpu_texture_t *render_target, buffer_t *buffer);
|
||||
|
||||
int gpu_vertex_data_size(gpu_vertex_data_t data);
|
||||
int gpu_vertex_struct_size(gpu_vertex_structure_t *s);
|
||||
int gpu_texture_format_size(gpu_texture_format_t format);
|
||||
|
||||
@@ -350,13 +350,12 @@ declare function iron_ml_inference(model: buffer_t, tensors: buffer_t[], input_s
|
||||
declare function iron_ml_unload(): void;
|
||||
|
||||
declare function gpu_raytrace_supported(): bool;
|
||||
declare function iron_raytrace_init(shader: buffer_t): void;
|
||||
declare function iron_raytrace_as_init(): void;
|
||||
declare function iron_raytrace_as_add(vb: any, ib: any, transform: mat4_t): void;
|
||||
declare function iron_raytrace_as_build(vb_full: any, ib_full: any): void;
|
||||
|
||||
declare function iron_raytrace_set_textures(tex0: gpu_texture_t, tex1: gpu_texture_t, tex2: gpu_texture_t, texenv: any, tex_sobol: any, tex_scramble: any, tex_rank: any): void;
|
||||
declare function iron_raytrace_dispatch_rays(target: any, cb: buffer_t): void;
|
||||
declare function _gpu_raytrace_init(shader: buffer_t): void;
|
||||
declare function _gpu_raytrace_as_init(): void;
|
||||
declare function _gpu_raytrace_as_add(vb: any, ib: any, transform: mat4_t): void;
|
||||
declare function _gpu_raytrace_as_build(vb_full: any, ib_full: any): void;
|
||||
declare function gpu_raytrace_set_textures(tex0: gpu_texture_t, tex1: gpu_texture_t, tex2: gpu_texture_t, texenv: any, tex_sobol: any, tex_scramble: any, tex_rank: any): void;
|
||||
declare function _gpu_raytrace_dispatch_rays(target: any, cb: buffer_t): void;
|
||||
|
||||
declare function iron_window_x(): i32;
|
||||
declare function iron_window_y(): i32;
|
||||
|
||||
@@ -59,7 +59,7 @@ function render_path_raytrace_commands(use_live_layer: bool) {
|
||||
let bnoise_rank: gpu_texture_t = map_get(scene_embedded, "bnoise_rank.k");
|
||||
|
||||
let l: slot_layer_t = layers_flatten(true);
|
||||
iron_raytrace_set_textures(l.texpaint, l.texpaint_nor, l.texpaint_pack, saved_envmap, bnoise_sobol, bnoise_scramble, bnoise_rank);
|
||||
gpu_raytrace_set_textures(l.texpaint, l.texpaint_nor, l.texpaint_pack, saved_envmap, bnoise_sobol, bnoise_scramble, bnoise_rank);
|
||||
}
|
||||
////
|
||||
|
||||
@@ -107,7 +107,7 @@ function render_path_raytrace_commands(use_live_layer: bool) {
|
||||
render_path_raytrace_f32a[22] = render_path_raytrace_uv_scale;
|
||||
|
||||
let framebuffer: render_target_t = map_get(render_path_render_targets, "buf");
|
||||
iron_raytrace_dispatch_rays(framebuffer._image, render_path_raytrace_f32a);
|
||||
_gpu_raytrace_dispatch_rays(framebuffer._image, render_path_raytrace_f32a);
|
||||
|
||||
if (context_raw.ddirty == 1 || context_raw.pdirty == 1) {
|
||||
///if arm_metal
|
||||
@@ -135,7 +135,7 @@ function render_path_raytrace_raytrace_init(shader_name: string, build: bool = t
|
||||
scene_embed_data("bnoise_rank.k");
|
||||
|
||||
let shader: buffer_t = data_get_blob(shader_name);
|
||||
iron_raytrace_init(shader);
|
||||
_gpu_raytrace_init(shader);
|
||||
}
|
||||
|
||||
if (build) {
|
||||
@@ -143,7 +143,7 @@ function render_path_raytrace_raytrace_init(shader_name: string, build: bool = t
|
||||
}
|
||||
|
||||
{
|
||||
iron_raytrace_as_init();
|
||||
_gpu_raytrace_as_init();
|
||||
|
||||
if (context_raw.tool == tool_type_t.GIZMO) {
|
||||
for (let i: i32 = 0; i < project_paint_objects.length; ++i) {
|
||||
@@ -151,17 +151,17 @@ function render_path_raytrace_raytrace_init(shader_name: string, build: bool = t
|
||||
if (!po.base.visible) {
|
||||
continue;
|
||||
}
|
||||
iron_raytrace_as_add(po.data._.vertex_buffer, po.data._.index_buffer, po.base.transform.world_unpack);
|
||||
_gpu_raytrace_as_add(po.data._.vertex_buffer, po.data._.index_buffer, po.base.transform.world_unpack);
|
||||
}
|
||||
}
|
||||
else {
|
||||
iron_raytrace_as_add(render_path_raytrace_vb, render_path_raytrace_ib, render_path_raytrace_transform);
|
||||
_gpu_raytrace_as_add(render_path_raytrace_vb, render_path_raytrace_ib, render_path_raytrace_transform);
|
||||
}
|
||||
|
||||
let vb_full: gpu_buffer_t = context_raw.merged_object.data._.vertex_buffer;
|
||||
let ib_full: gpu_buffer_t = context_raw.merged_object.data._.index_buffer;
|
||||
|
||||
iron_raytrace_as_build(vb_full, ib_full);
|
||||
_gpu_raytrace_as_build(vb_full, ib_full);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ function render_path_raytrace_bake_commands(parse_paint_material: (b?: bool)=>vo
|
||||
tex2 = texpaint_undo._image;
|
||||
}
|
||||
|
||||
iron_raytrace_set_textures(baketex0._image, baketex1._image, tex2, saved_envmap, bnoise_sobol, bnoise_scramble, bnoise_rank);
|
||||
gpu_raytrace_set_textures(baketex0._image, baketex1._image, tex2, saved_envmap, bnoise_sobol, bnoise_scramble, bnoise_rank);
|
||||
}
|
||||
|
||||
if (context_raw.brush_time > 0) {
|
||||
@@ -124,7 +124,7 @@ function render_path_raytrace_bake_commands(parse_paint_material: (b?: bool)=>vo
|
||||
f32a[6] = context_raw.envmap_angle;
|
||||
|
||||
let framebuffer: render_target_t = map_get(render_path_render_targets, "baketex2");
|
||||
iron_raytrace_dispatch_rays(framebuffer._image, f32a);
|
||||
_gpu_raytrace_dispatch_rays(framebuffer._image, f32a);
|
||||
|
||||
let id: i32 = context_raw.layer.id;
|
||||
let texpaint_id: string = "texpaint" + id;
|
||||
|
||||
Reference in New Issue
Block a user