Skip to content

Commit e5a6d7c

Browse files
committed
debug accel update
1 parent d33f999 commit e5a6d7c

14 files changed

+112
-75
lines changed

errlog.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Processing d:\code\luisarender2
2+
Installing build dependencies: started
3+
Installing build dependencies: finished with status 'done'
4+
Getting requirements to build wheel: started
5+
Getting requirements to build wheel: finished with status 'done'
6+
Preparing metadata (pyproject.toml): started
7+
Preparing metadata (pyproject.toml): finished with status 'done'
8+
Building wheels for collected packages: luisarender-python
9+
Building wheel for luisarender-python (pyproject.toml): started
10+
Building wheel for luisarender-python (pyproject.toml): finished with status 'done'
11+
Created wheel for luisarender-python: filename=luisarender_python-0.0.4-cp310-cp310-win_amd64.whl size=142570754 sha256=0a7fa8cb4f0185fe0a1958fbcd36bb69b5d25304a9a2ae40a83272ade13d91ca
12+
Stored in directory: C:\Users\jiankai\AppData\Local\Temp\pip-ephem-wheel-cache-b57azy5n\wheels\f6\99\5f\252c215c0d5676460f053881571f097ce199905284240b4ed3
13+
Successfully built luisarender-python

src/base/differentiation.cpp

+18-12
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,13 @@ void Differentiation::materialize(CommandBuffer &command_buffer) noexcept {
168168
command_buffer << image.copy_to(_param_buffer->subview(param_offset, length))
169169
<< textured_params_range_shader(*_param_range_buffer, p.range(), param_offset).dispatch(length);
170170
}
171+
171172
//Todo: add buffer parameters(mesh vertex or sth) to _param_buffer
172173
for (auto &&p : _geometry_params) {
173174
auto buffer = p.buffer();
174175
auto param_offset = p.param_offset();
175176
auto length = buffer.size();
176-
command_buffer << _param_buffer->subview(param_offset, length).copy_from(buffer.as<float>());
177+
command_buffer << _param_buffer->subview(param_offset, length*8).copy_from(buffer.as<float>());
177178
}
178179

179180
command_buffer << synchronize();
@@ -451,20 +452,23 @@ void Differentiation::register_optimizer(Optimizer::Instance *optimizer) noexcep
451452
}
452453

453454
void Differentiation::register_geometry_parameter(const CommandBuffer &command_buffer, Geometry::MeshData& mesh, Accel& accel, uint instance_id) noexcept {
455+
454456
auto param_offset = _param_buffer_size;
455457
auto counter_offset = _counter_size;
456458
auto grad_offset = _gradient_buffer_size;
457459
auto param_index = static_cast<uint>(_geometry_params.size());
458460
//auto channels = 3u;
459-
uint buffer_id = mesh.geometry_buffer_id_base;
460-
auto [buffer_view, bindlessbuffer_id] = _pipeline.bindless_arena_buffer<Vertex>(buffer_id);
461-
auto length = buffer_view.size_bytes();
462-
//buffer.size();
463-
_counter_size = (_counter_size + length + 3u) & ~0b11u;
464-
_param_buffer_size = (_param_buffer_size + length + 3u) & ~0b11u;
465-
_gradient_buffer_size = (_gradient_buffer_size + length + 3u) & ~0b11u;
466-
_geometry_params.emplace_back(param_index, instance_id, grad_offset, param_offset, counter_offset, buffer_view, length, buffer_id);
467-
instance2offset.value()->write(instance_id, grad_offset+1u);
461+
//uint buffer_id = mesh.geometry_buffer_id_base;
462+
auto buffer_view = mesh.vertices;
463+
auto length = buffer_view.size() * 8;
464+
_counter_size = (_counter_size + length + 8u) & ~0b11u;
465+
_param_buffer_size = (_param_buffer_size + length + 8u) & ~0b11u;
466+
_gradient_buffer_size = (_gradient_buffer_size + length + 8u) & ~0b11u;
467+
_geometry_params.emplace_back(param_index, instance_id, grad_offset, param_offset, counter_offset, buffer_view, length, 0u);
468+
469+
LUISA_INFO("buffer_view size is {}",buffer_view.size());
470+
LUISA_INFO("working here, {}, {}, {}, Mesh with {} triangles.", length, _counter_size, _param_buffer_size, mesh.resource->triangle_count());
471+
//instance2offset.value()->write(instance_id, grad_offset+1u);
468472
//command_buffer << buffer.copy_to(_param_buffer->subview(param_offset, length));
469473
}
470474

@@ -479,13 +483,15 @@ void Differentiation::update_parameter_from_external(Stream &stream, luisa::vect
479483
stream << image.copy_from(textures[textures_id[i]]);
480484
}
481485

486+
LUISA_INFO("working on update paramaters");
482487
// apply geometry parameters
483488
for (auto i=0;i<geoms_id.size();i++) {
484489
auto &&p = _geometry_params[geoms_id[i]];
485490
auto param_offset = p.param_offset();
486-
auto buffer_id = p.buffer_id();
487-
auto [buffer_view, bindlessbuffer_id] = _pipeline.bindless_arena_buffer<Vertex>(buffer_id);
491+
auto buffer_view = p.buffer();
492+
//auto [buffer_view, bindlessbuffer_id] = _pipeline.bindless_arena_buffer<Vertex>(buffer_id);
488493
auto length = buffer_view.size();
494+
LUISA_INFO("here length is {}, size is {}, as<vertex> size is {}",length,geoms[geoms_id[i]].view().size(),geoms[geoms_id[i]].view().as<Vertex>().size());
489495
stream << buffer_view.copy_from(geoms[geoms_id[i]].view().as<Vertex>());
490496
_is_dirty = true;
491497
}

src/base/differentiation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Differentiation {
7272
GeometryParameter(uint index, uint instance_id, uint grad_offset, uint param_offset,
7373
uint counter_offset, BufferView<Vertex> buffer_view, uint length, uint buffer_id) noexcept
7474
: _index(index), _instance_id{instance_id}, _grad_offset{grad_offset}, _param_offset{param_offset},
75-
_counter_offset{counter_offset}, _buffer_view{_buffer_view}, _length(length), _buffer_id(buffer_id) {}
75+
_counter_offset{counter_offset}, _buffer_view{buffer_view}, _length(length), _buffer_id(buffer_id) {}
7676
[[nodiscard]] auto index() const noexcept { return _index; }
7777
[[nodiscard]] auto buffer() const noexcept { return _buffer_view; }
7878
[[nodiscard]] auto buffer_id() const noexcept { return _buffer_id; }

src/base/geometry.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ void Geometry::build(CommandBuffer &command_buffer,
2121
_triangle_count = 0u;
2222
for (auto shape : shapes) { _process_shape(command_buffer, shape, init_time, nullptr); }
2323
LUISA_INFO_WITH_LOCATION("Geometry built with {} triangles.", _triangle_count);
24+
2425
_instance_buffer = _pipeline.device().create_buffer<uint4>(_instances.size());
2526
command_buffer << _instance_buffer.copy_from(_instances.data())
2627
<< _accel.build();
28+
command_buffer << synchronize();
29+
LUISA_INFO_WITH_LOCATION("Finish accel_build");
2730
}
2831

2932
void Geometry::_process_shape(
@@ -85,7 +88,7 @@ void Geometry::_process_shape(
8588
command_buffer << alias_table_buffer_view.copy_from(alias_table.data())
8689
<< pdf_buffer_view.copy_from(pdf.data());
8790
command_buffer << compute::commit();
88-
auto geom = MeshGeometry{mesh, vertex_buffer_id};
91+
auto geom = MeshGeometry{mesh, vertex_buffer_id, vertex_buffer->view()};
8992
_mesh_cache.emplace(hash, geom);
9093
return geom;
9194
}();
@@ -96,22 +99,24 @@ void Geometry::_process_shape(
9699
// assign mesh data
97100
MeshData mesh_data{
98101
.resource = mesh_geom.resource,
102+
.vertices = mesh_geom.vertices,
99103
.shadow_term = encode_fixed_point(shape->has_vertex_normal() ? shape->shadow_terminator_factor() : 0.f),
100104
.intersection_offset = encode_fixed_point(shape->intersection_offset_factor()),
101105
.geometry_buffer_id_base = mesh_geom.buffer_id_base,
102106
.vertex_properties = shape->vertex_properties()};
103107
_meshes.emplace(shape, mesh_data);
104108
return mesh_data;
105109
}();
110+
//_pipeline.buffer<Vertex>(v_buffer)
106111
auto instance_id = static_cast<uint>(_accel.size());
107112
auto [t_node, is_static] = _transform_tree.leaf(shape->transform());
108113
InstancedTransform inst_xform{t_node, instance_id};
109114
if (!is_static) { _dynamic_transforms.emplace_back(inst_xform); }
110115
auto object_to_world = inst_xform.matrix(init_time);
111116
_accel.emplace_back(*mesh.resource, object_to_world, visible);
112-
113-
114-
if (shape->requires_grad()) {
117+
//LUISA_INFO("sdlfjdslkfjsdklf {}", instance_id);
118+
if (shape->requires_gradients()) {
119+
LUISA_INFO("requires_gradients {}", instance_id);
115120
_pipeline.differentiation()->register_geometry_parameter(command_buffer, mesh, _accel, instance_id);
116121
}
117122

@@ -190,7 +195,9 @@ bool Geometry::update(CommandBuffer &command_buffer, float time) noexcept {
190195
}
191196
_pipeline.differentiation()->clear_dirty();
192197
}
193-
command_buffer << _accel.build();
198+
LUISA_INFO("start build accel");
199+
command_buffer << _accel.build() << synchronize();
200+
LUISA_INFO("end build accel");
194201
}
195202
return updated;
196203
}

src/base/geometry.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using compute::Expr;
3636
using compute::Float4x4;
3737
using compute::Mesh;
3838
using compute::Var;
39+
using compute::BufferView;
3940

4041
class Pipeline;
4142

@@ -45,17 +46,19 @@ class Geometry {
4546
struct MeshGeometry {
4647
Mesh *resource;
4748
uint buffer_id_base;
49+
BufferView<Vertex> vertices;
4850
};
4951

5052
struct MeshData {
5153
Mesh *resource;
54+
BufferView<Vertex> vertices;
5255
uint16_t shadow_term;
5356
uint16_t intersection_offset;
5457
uint geometry_buffer_id_base : 22;
5558
uint vertex_properties : 10;
5659
};
5760

58-
static_assert(sizeof(MeshData) == 16u);
61+
//static_assert(sizeof(MeshData) == 16u);
5962

6063
private:
6164
Pipeline &_pipeline;

src/base/pipeline.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,18 @@ luisa::unique_ptr<Pipeline> Pipeline::create(Device &device, Stream &stream, con
8686
"No lights or environment found in the scene.");
8787
}
8888
update_bindless_if_dirty();
89+
90+
8991
pipeline->_integrator = scene.integrator()->build(*pipeline, command_buffer);
92+
93+
94+
LUISA_INFO_WITH_LOCATION("start _differentiation build.");
9095
if (auto &&diff = pipeline->_differentiation) {
9196
diff->register_optimizer(dynamic_cast<DifferentiableIntegrator::Instance *>(pipeline->_integrator.get())->optimizer());
97+
LUISA_INFO_WITH_LOCATION("middle _differentiation build.");
9298
diff->materialize(command_buffer);
9399
}
100+
LUISA_INFO_WITH_LOCATION("finish _differentiation build.");
94101
if (!pipeline->_transforms.empty()) {
95102
command_buffer << pipeline->_transform_matrix_buffer.view(0u, pipeline->_transforms.size())
96103
.copy_from(pipeline->_transform_matrices.data());

src/base/scene.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,6 @@ luisa::unique_ptr<Scene> Scene::create(const Context &ctx, const SceneDesc *desc
248248
}
249249
}
250250
}
251-
for (auto &&[_, node] : scene->_config->nodes) {
252-
if (node->tag() == SceneNodeTag::TEXTURE) {
253-
auto texture = static_cast<Texture *>(node.get());
254-
if (texture->requires_gradients()) {
255-
disabled++;
256-
texture->disable_gradients();
257-
}
258-
}
259-
}
260251
if (disabled != 0u) {
261252
LUISA_WARNING_WITH_LOCATION(
262253
"Disabled gradient computation in {} "

src/base/shape.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Shape : public SceneNode {
5454
[[nodiscard]] virtual float shadow_terminator_factor() const noexcept;
5555
[[nodiscard]] virtual float intersection_offset_factor() const noexcept;
5656
[[nodiscard]] virtual bool is_mesh() const noexcept;
57-
[[nodiscard]] virtual bool requires_grad() const noexcept { return _requires_grad; }
57+
[[nodiscard]] virtual bool requires_gradients() const noexcept { return _requires_grad; }
5858
[[nodiscard]] virtual uint vertex_properties() const noexcept;
5959
[[nodiscard]] bool has_vertex_normal() const noexcept;
6060
[[nodiscard]] bool has_vertex_uv() const noexcept;

src/integrators/megappm_diff.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,11 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
656656
};
657657
};
658658

659-
Kernel2D emit_photons_kernel = [&](UInt frame_index, Float time) noexcept {
659+
Kernel2D emit_photons_kernel = [&](UInt frame_index, Float time, BufferFloat grad_in) noexcept {
660660
auto pixel_id = dispatch_id().xy();
661661
auto sampler_id = UInt2(pixel_id.x + resolution.x, pixel_id.y);
662662
$if(pixel_id.x * resolution.y + pixel_id.y < photon_per_iter) {
663-
photon_tracing_bp(camera, frame_index, sampler_id, time, pixel_id.x * resolution.y + pixel_id.y);
663+
photon_tracing_bp(camera, frame_index, sampler_id, time, pixel_id.x * resolution.y + pixel_id.y, grad_in);
664664
};
665665
};
666666

@@ -718,7 +718,7 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
718718
command_buffer << viewpoint_reset().dispatch(viewpoints->size());
719719
command_buffer << viewpath_construct(sample_id++, s.point.time, s.point.weight).dispatch(resolution);
720720
command_buffer << build_grid().dispatch(viewpoints->size());
721-
command_buffer << emit_photon(sample_id++, s.point.time).dispatch(make_uint2(add_x, resolution.y));
721+
command_buffer << emit_photon(sample_id++, s.point.time, grad_in).dispatch(make_uint2(add_x, resolution.y));
722722
command_buffer << indirect_update().dispatch(viewpoints_per_iter);
723723
if (node<MegakernelPhotonMappingDiff>()->shared_radius()) {
724724
command_buffer << shared_update().dispatch(1u);
@@ -887,10 +887,11 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
887887
}
888888
}
889889

890+
command_buffer << synchronize();
890891
command_buffer << indirect_draw(node<MegakernelPhotonMappingDiff>()->photon_per_iter(), runtime_spp).dispatch(resolution);
891-
LUISA_INFO("Finishi indirect_draw");
892892
command_buffer << synchronize();
893893
command_buffer << pipeline().printer().retrieve();
894+
LUISA_INFO("Finishi indirect_draw");
894895
progress.done();
895896
auto render_time = clock.toc();
896897
LUISA_INFO("Rendering finished in {} ms.", render_time);
@@ -1103,7 +1104,7 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
11031104
auto wi_local = it->shading().world_to_local(wi);
11041105
Float3 Phi;
11051106
auto rel_dis = dis / indirect->radius(pixel_id);
1106-
auto weight = 3.0f*(1.0f-rel_dis);//- 6 * pow(rel_dis, 5.) + 15 * pow(rel_dis, 4.) - 10 * pow(rel_dis, 3.);
1107+
auto weight = 3.5f*(1.0f- 6 * pow(rel_dis, 5.) + 15 * pow(rel_dis, 4.) - 10 * pow(rel_dis, 3.));
11071108
if (!spectrum->node()->is_fixed()) {
11081109
auto viewpoint_swl = viewpoints->swl(pixel_id);
11091110
Phi = spectrum->wavelength_mul(swl, beta * (eval_viewpoint / abs_cos_theta(wi_local)), viewpoint_swl, viewpoint_beta);
@@ -1409,11 +1410,11 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
14091410
requires_grad(bary, beta_diff);
14101411
Float3 photon_pos = point_0 * bary[0] + point_1 * bary[1] + point_2 * (1 - bary[0] - bary[1]);
14111412
auto rel_dis_diff = distance(position, photon_pos) / rad;
1412-
auto weight = (1-rel_dis_diff)*3;// 1- 6*pow(rel_dis_diff, 5.) + 15*pow(rel_dis_diff, 4.) - 10*pow(rel_dis_diff, 3.);
1413+
auto weight = 3.5f*(1- 6*pow(rel_dis_diff, 5.) + 15*pow(rel_dis_diff, 4.) - 10*pow(rel_dis_diff, 3.));
14131414
auto wi_local = it->shading().world_to_local(wi);
14141415
auto Phi = spectrum->srgb(swl, viewpoint_beta * eval_viewpoint / abs_cos_theta(wi_local));
14151416
auto Phi_beta = Phi * beta_diff * weight;
1416-
auto _grad_dimension = 5u;
1417+
auto _grad_dimension = 3u;
14171418
auto grad_pixel_0 = grad_in->read(pixel_id*_grad_dimension+0);
14181419
auto grad_pixel_1 = grad_in->read(pixel_id * _grad_dimension + 1);
14191420
auto grad_pixel_2 = grad_in->read(pixel_id * _grad_dimension + 2);

src/python/lrapi.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ PYBIND11_MODULE(_lrapi, m) {
250250
geoms.push_back(std::move(buffer));
251251
}
252252
}
253+
LUISA_INFO("geom_id_size is {}", geoms_id.size());
253254
scene_python._pipeline->differentiation()->update_parameter_from_external(*scene_python._stream, constants_id, constants, textures_id, textures, geoms_id, geoms);
254255
});
255256

src/shapes/mesh.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class MeshLoader {
5050
aiProcess_ValidateDataStructure | aiProcess_ImproveCacheLocality |
5151
aiProcess_PreTransformVertices | aiProcess_FindInvalidData |
5252
aiProcess_JoinIdenticalVertices;
53+
5354
auto remove_flags = aiComponent_ANIMATIONS | aiComponent_BONEWEIGHTS |
5455
aiComponent_CAMERAS | aiComponent_LIGHTS |
5556
aiComponent_MATERIALS | aiComponent_TEXTURES |
@@ -101,6 +102,7 @@ class MeshLoader {
101102
mesh->mNumUVComponents[0]);
102103
}
103104
auto vertex_count = mesh->mNumVertices;
105+
LUISA_INFO("vertex_count in loading mesh is {}", vertex_count);
104106
auto ai_positions = mesh->mVertices;
105107
auto ai_normals = mesh->mNormals;
106108
auto ai_uvs = mesh->mTextureCoords[0];

src/tests/gt.exr

995 KB
Binary file not shown.

src/tests/init.exr

318 KB
Binary file not shown.

0 commit comments

Comments
 (0)