diff options
Diffstat (limited to 'intern')
146 files changed, 1901 insertions, 1405 deletions
diff --git a/intern/cycles/blender/camera.cpp b/intern/cycles/blender/camera.cpp index 402fd7c4ec6..2ab5f02a337 100644 --- a/intern/cycles/blender/camera.cpp +++ b/intern/cycles/blender/camera.cpp @@ -643,7 +643,7 @@ void BlenderSync::sync_camera_motion( /* TODO(sergey): De-duplicate calculation with camera sync. */ float fov = 2.0f * atanf((0.5f * sensor_size) / bcam.lens / aspectratio); if (fov != cam->get_fov()) { - VLOG(3) << "Camera " << b_ob.name() << " FOV change detected."; + VLOG_WORK << "Camera " << b_ob.name() << " FOV change detected."; if (motion_time == 0.0f) { cam->set_fov(fov); } diff --git a/intern/cycles/blender/curves.cpp b/intern/cycles/blender/curves.cpp index 4e9f4f62087..b01cb85711a 100644 --- a/intern/cycles/blender/curves.cpp +++ b/intern/cycles/blender/curves.cpp @@ -341,7 +341,7 @@ static void ExportCurveSegments(Scene *scene, Hair *hair, ParticleCurveData *CDa /* check allocation */ if ((hair->get_curve_keys().size() != num_keys) || (hair->num_curves() != num_curves)) { - VLOG(1) << "Hair memory allocation failed, clearing data."; + VLOG_WARNING << "Hair memory allocation failed, clearing data."; hair->clear(true); } } @@ -397,7 +397,7 @@ static void export_hair_motion_validate_attribute(Hair *hair, if (num_motion_keys != num_keys || !have_motion) { /* No motion or hair "topology" changed, remove attributes again. */ if (num_motion_keys != num_keys) { - VLOG(1) << "Hair topology changed, removing motion attribute."; + VLOG_WORK << "Hair topology changed, removing motion attribute."; } hair->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION); } diff --git a/intern/cycles/blender/display_driver.cpp b/intern/cycles/blender/display_driver.cpp index ee67073a9a4..a1bc064be68 100644 --- a/intern/cycles/blender/display_driver.cpp +++ b/intern/cycles/blender/display_driver.cpp @@ -982,10 +982,8 @@ void BlenderDisplayDriver::draw(const Params ¶ms) gl_render_sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); glFlush(); - if (VLOG_IS_ON(5)) { - VLOG(5) << "Number of textures: " << GLTexture::num_used; - VLOG(5) << "Number of PBOs: " << GLPixelBufferObject::num_used; - } + VLOG_DEVICE_STATS << "Display driver number of textures: " << GLTexture::num_used; + VLOG_DEVICE_STATS << "Display driver number of PBOs: " << GLPixelBufferObject::num_used; if (use_gl_context_) { gl_context_mutex_.unlock(); diff --git a/intern/cycles/blender/mesh.cpp b/intern/cycles/blender/mesh.cpp index e2db52cc5c1..63913b7cd7f 100644 --- a/intern/cycles/blender/mesh.cpp +++ b/intern/cycles/blender/mesh.cpp @@ -1212,17 +1212,17 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph, memcmp(mP, &mesh->get_verts()[0], sizeof(float3) * numverts) == 0) { /* no motion, remove attributes again */ if (b_mesh.vertices.length() != numverts) { - VLOG(1) << "Topology differs, disabling motion blur for object " << ob_name; + VLOG_WARNING << "Topology differs, disabling motion blur for object " << ob_name; } else { - VLOG(1) << "No actual deformation motion for object " << ob_name; + VLOG_DEBUG << "No actual deformation motion for object " << ob_name; } mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION); if (attr_mN) mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_NORMAL); } else if (motion_step > 0) { - VLOG(1) << "Filling deformation motion for object " << ob_name; + VLOG_DEBUG << "Filling deformation motion for object " << ob_name; /* motion, fill up previous steps that we might have skipped because * they had no motion, but we need them anyway now */ float3 *P = &mesh->get_verts()[0]; @@ -1236,8 +1236,8 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph, } else { if (b_mesh.vertices.length() != numverts) { - VLOG(1) << "Topology differs, discarding motion blur for object " << ob_name << " at time " - << motion_step; + VLOG_WARNING << "Topology differs, discarding motion blur for object " << ob_name + << " at time " << motion_step; memcpy(mP, &mesh->get_verts()[0], sizeof(float3) * numverts); if (mN != NULL) { memcpy(mN, attr_N->data_float3(), sizeof(float3) * numverts); diff --git a/intern/cycles/blender/object.cpp b/intern/cycles/blender/object.cpp index 9b08b564b25..ca1aa6329d9 100644 --- a/intern/cycles/blender/object.cpp +++ b/intern/cycles/blender/object.cpp @@ -762,7 +762,7 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render, continue; } - VLOG(1) << "Synchronizing motion for the relative time " << relative_time << "."; + VLOG_WORK << "Synchronizing motion for the relative time " << relative_time << "."; /* fixed shutter time to get previous and next frame for motion pass */ float shuttertime = scene->motion_shutter_time(); diff --git a/intern/cycles/blender/session.cpp b/intern/cycles/blender/session.cpp index 87f051ba50b..6d27b8e7d87 100644 --- a/intern/cycles/blender/session.cpp +++ b/intern/cycles/blender/session.cpp @@ -458,8 +458,8 @@ void BlenderSession::render(BL::Depsgraph &b_depsgraph_) double total_time, render_time; session->progress.get_time(total_time, render_time); - VLOG(1) << "Total render time: " << total_time; - VLOG(1) << "Render time (without synchronization): " << render_time; + VLOG_INFO << "Total render time: " << total_time; + VLOG_INFO << "Render time (without synchronization): " << render_time; } void BlenderSession::render_frame_finish() diff --git a/intern/cycles/blender/sync.cpp b/intern/cycles/blender/sync.cpp index 1028c940772..63e9e1e0e68 100644 --- a/intern/cycles/blender/sync.cpp +++ b/intern/cycles/blender/sync.cpp @@ -285,7 +285,7 @@ void BlenderSync::sync_data(BL::RenderSettings &b_render, free_data_after_sync(b_depsgraph); - VLOG(1) << "Total time spent synchronizing data: " << timer.get_time(); + VLOG_INFO << "Total time spent synchronizing data: " << timer.get_time(); has_updates_ = false; } @@ -390,7 +390,7 @@ void BlenderSync::sync_integrator(BL::ViewLayer &b_view_layer, bool background) } if (scrambling_distance != 1.0f) { - VLOG(3) << "Using scrambling distance: " << scrambling_distance; + VLOG_INFO << "Using scrambling distance: " << scrambling_distance; } integrator->set_scrambling_distance(scrambling_distance); diff --git a/intern/cycles/bvh/build.cpp b/intern/cycles/bvh/build.cpp index 1df3517673e..cf03f05de60 100644 --- a/intern/cycles/bvh/build.cpp +++ b/intern/cycles/bvh/build.cpp @@ -529,7 +529,7 @@ BVHNode *BVHBuild::run() if (progress.get_cancel()) { rootnode->deleteSubtree(); rootnode = NULL; - VLOG(1) << "BVH build cancelled."; + VLOG_WORK << "BVH build cancelled."; } else { /*rotate(rootnode, 4, 5);*/ @@ -537,26 +537,26 @@ BVHNode *BVHBuild::run() rootnode->update_time(); } if (rootnode != NULL) { - VLOG(1) << "BVH build statistics:\n" - << " Build time: " << time_dt() - build_start_time << "\n" - << " Total number of nodes: " - << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_NODE_COUNT)) - << "\n" - << " Number of inner nodes: " - << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_INNER_COUNT)) - << "\n" - << " Number of leaf nodes: " - << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_LEAF_COUNT)) - << "\n" - << " Number of unaligned nodes: " - << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_UNALIGNED_COUNT)) - << "\n" - << " Allocation slop factor: " - << ((prim_type.capacity() != 0) ? (float)prim_type.size() / prim_type.capacity() : - 1.0f) - << "\n" - << " Maximum depth: " - << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_DEPTH)) << "\n"; + VLOG_WORK << "BVH build statistics:\n" + << " Build time: " << time_dt() - build_start_time << "\n" + << " Total number of nodes: " + << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_NODE_COUNT)) + << "\n" + << " Number of inner nodes: " + << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_INNER_COUNT)) + << "\n" + << " Number of leaf nodes: " + << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_LEAF_COUNT)) + << "\n" + << " Number of unaligned nodes: " + << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_UNALIGNED_COUNT)) + << "\n" + << " Allocation slop factor: " + << ((prim_type.capacity() != 0) ? (float)prim_type.size() / prim_type.capacity() : + 1.0f) + << "\n" + << " Maximum depth: " + << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_DEPTH)) << "\n"; } } diff --git a/intern/cycles/bvh/embree.cpp b/intern/cycles/bvh/embree.cpp index 0fc71f49ce3..eed7ae19965 100644 --- a/intern/cycles/bvh/embree.cpp +++ b/intern/cycles/bvh/embree.cpp @@ -250,7 +250,7 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args) *isect = current_isect; /* Only primitives from volume object. */ uint tri_object = isect->object; - int object_flag = kernel_tex_fetch(__object_flag, tri_object); + int object_flag = kernel_data_fetch(object_flag, tri_object); if ((object_flag & SD_OBJECT_HAS_VOLUME) == 0) { --ctx->num_hits; } @@ -332,7 +332,7 @@ static bool rtc_memory_monitor_func(void *userPtr, const ssize_t bytes, const bo static void rtc_error_func(void *, enum RTCError, const char *str) { - VLOG(1) << str; + VLOG_WARNING << str; } static double progress_start_time = 0.0; @@ -521,8 +521,8 @@ void BVHEmbree::add_triangles(const Object *ob, const Mesh *mesh, int i) geom_id, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT3, sizeof(int) * 3, num_triangles); assert(rtc_indices); if (!rtc_indices) { - VLOG(1) << "Embree could not create new geometry buffer for mesh " << mesh->name.c_str() - << ".\n"; + VLOG_WARNING << "Embree could not create new geometry buffer for mesh " << mesh->name.c_str() + << ".\n"; return; } for (size_t j = 0; j < num_triangles; ++j) { diff --git a/intern/cycles/device/cpu/device_impl.cpp b/intern/cycles/device/cpu/device_impl.cpp index 612c391f7d5..d4f0532aa5e 100644 --- a/intern/cycles/device/cpu/device_impl.cpp +++ b/intern/cycles/device/cpu/device_impl.cpp @@ -51,12 +51,12 @@ CCL_NAMESPACE_BEGIN CPUDevice::CPUDevice(const DeviceInfo &info_, Stats &stats_, Profiler &profiler_) - : Device(info_, stats_, profiler_), texture_info(this, "__texture_info", MEM_GLOBAL) + : Device(info_, stats_, profiler_), texture_info(this, "texture_info", MEM_GLOBAL) { /* Pick any kernel, all of them are supposed to have same level of microarchitecture * optimization. */ - VLOG(1) << "Using " << get_cpu_kernels().integrator_init_from_camera.get_uarch_name() - << " CPU kernels."; + VLOG_INFO << "Using " << get_cpu_kernels().integrator_init_from_camera.get_uarch_name() + << " CPU kernels."; if (info.cpu_threads == 0) { info.cpu_threads = TaskScheduler::max_concurrency(); @@ -111,9 +111,9 @@ void CPUDevice::mem_alloc(device_memory &mem) } else { if (mem.name) { - VLOG(1) << "Buffer allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Buffer allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; } if (mem.type == MEM_DEVICE_ONLY || !mem.host_pointer) { @@ -192,7 +192,7 @@ device_ptr CPUDevice::mem_alloc_sub_ptr(device_memory &mem, size_t offset, size_ void CPUDevice::const_copy_to(const char *name, void *host, size_t size) { #ifdef WITH_EMBREE - if (strcmp(name, "__data") == 0) { + if (strcmp(name, "data") == 0) { assert(size <= sizeof(KernelData)); // Update scene handle (since it is different for each device on multi devices) @@ -205,9 +205,9 @@ void CPUDevice::const_copy_to(const char *name, void *host, size_t size) void CPUDevice::global_alloc(device_memory &mem) { - VLOG(1) << "Global memory allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Global memory allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; kernel_global_memory_copy(&kernel_globals, mem.name, mem.host_pointer, mem.data_size); @@ -227,9 +227,9 @@ void CPUDevice::global_free(device_memory &mem) void CPUDevice::tex_alloc(device_texture &mem) { - VLOG(1) << "Texture allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Texture allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; mem.device_pointer = (device_ptr)mem.host_pointer; mem.device_size = mem.memory_size(); diff --git a/intern/cycles/device/cuda/device.cpp b/intern/cycles/device/cuda/device.cpp index 400490336d6..5a213c45b71 100644 --- a/intern/cycles/device/cuda/device.cpp +++ b/intern/cycles/device/cuda/device.cpp @@ -29,24 +29,25 @@ bool device_cuda_init() initialized = true; int cuew_result = cuewInit(CUEW_INIT_CUDA); if (cuew_result == CUEW_SUCCESS) { - VLOG(1) << "CUEW initialization succeeded"; + VLOG_INFO << "CUEW initialization succeeded"; if (CUDADevice::have_precompiled_kernels()) { - VLOG(1) << "Found precompiled kernels"; + VLOG_INFO << "Found precompiled kernels"; result = true; } else if (cuewCompilerPath() != NULL) { - VLOG(1) << "Found CUDA compiler " << cuewCompilerPath(); + VLOG_INFO << "Found CUDA compiler " << cuewCompilerPath(); result = true; } else { - VLOG(1) << "Neither precompiled kernels nor CUDA compiler was found," - << " unable to use CUDA"; + VLOG_INFO << "Neither precompiled kernels nor CUDA compiler was found," + << " unable to use CUDA"; } } else { - VLOG(1) << "CUEW initialization failed: " - << ((cuew_result == CUEW_ERROR_ATEXIT_FAILED) ? "Error setting up atexit() handler" : - "Error opening the library"); + VLOG_WARNING << "CUEW initialization failed: " + << ((cuew_result == CUEW_ERROR_ATEXIT_FAILED) ? + "Error setting up atexit() handler" : + "Error opening the library"); } return result; @@ -121,7 +122,8 @@ void device_cuda_info(vector<DeviceInfo> &devices) int major; cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, num); if (major < 3) { - VLOG(1) << "Ignoring device \"" << name << "\", this graphics card is no longer supported."; + VLOG_INFO << "Ignoring device \"" << name + << "\", this graphics card is no longer supported."; continue; } @@ -166,21 +168,21 @@ void device_cuda_info(vector<DeviceInfo> &devices) * Windows 10 even when it is, due to an issue in application profiles. * Detect case where we expect it to be available and override. */ if (preempt_attr == 0 && (major >= 6) && system_windows_version_at_least(10, 17134)) { - VLOG(1) << "Assuming device has compute preemption on Windows 10."; + VLOG_INFO << "Assuming device has compute preemption on Windows 10."; preempt_attr = 1; } if (timeout_attr && !preempt_attr) { - VLOG(1) << "Device is recognized as display."; + VLOG_INFO << "Device is recognized as display."; info.description += " (Display)"; info.display_device = true; display_devices.push_back(info); } else { - VLOG(1) << "Device has compute preemption or is not used for display."; + VLOG_INFO << "Device has compute preemption or is not used for display."; devices.push_back(info); } - VLOG(1) << "Added device \"" << name << "\" with id \"" << info.id << "\"."; + VLOG_INFO << "Added device \"" << name << "\" with id \"" << info.id << "\"."; } if (!display_devices.empty()) diff --git a/intern/cycles/device/cuda/device_impl.cpp b/intern/cycles/device/cuda/device_impl.cpp index cb7e909a2d5..00851a8e91c 100644 --- a/intern/cycles/device/cuda/device_impl.cpp +++ b/intern/cycles/device/cuda/device_impl.cpp @@ -23,6 +23,8 @@ # include "util/types.h" # include "util/windows.h" +# include "kernel/device/cuda/globals.h" + CCL_NAMESPACE_BEGIN class CUDADevice; @@ -51,7 +53,7 @@ void CUDADevice::set_error(const string &error) } CUDADevice::CUDADevice(const DeviceInfo &info, Stats &stats, Profiler &profiler) - : Device(info, stats, profiler), texture_info(this, "__texture_info", MEM_GLOBAL) + : Device(info, stats, profiler), texture_info(this, "texture_info", MEM_GLOBAL) { first_error = true; @@ -244,9 +246,9 @@ string CUDADevice::compile_kernel(const uint kernel_features, if (!use_adaptive_compilation()) { if (!force_ptx) { const string cubin = path_get(string_printf("lib/%s_sm_%d%d.cubin", name, major, minor)); - VLOG(1) << "Testing for pre-compiled kernel " << cubin << "."; + VLOG_INFO << "Testing for pre-compiled kernel " << cubin << "."; if (path_exists(cubin)) { - VLOG(1) << "Using precompiled kernel."; + VLOG_INFO << "Using precompiled kernel."; return cubin; } } @@ -256,9 +258,9 @@ string CUDADevice::compile_kernel(const uint kernel_features, while (ptx_major >= 3) { const string ptx = path_get( string_printf("lib/%s_compute_%d%d.ptx", name, ptx_major, ptx_minor)); - VLOG(1) << "Testing for pre-compiled kernel " << ptx << "."; + VLOG_INFO << "Testing for pre-compiled kernel " << ptx << "."; if (path_exists(ptx)) { - VLOG(1) << "Using precompiled kernel."; + VLOG_INFO << "Using precompiled kernel."; return ptx; } @@ -287,9 +289,9 @@ string CUDADevice::compile_kernel(const uint kernel_features, const string cubin_file = string_printf( "cycles_%s_%s_%d%d_%s.%s", name, kernel_arch, major, minor, kernel_md5.c_str(), kernel_ext); const string cubin = path_cache_get(path_join("kernels", cubin_file)); - VLOG(1) << "Testing for locally compiled kernel " << cubin << "."; + VLOG_INFO << "Testing for locally compiled kernel " << cubin << "."; if (path_exists(cubin)) { - VLOG(1) << "Using locally compiled kernel."; + VLOG_INFO << "Using locally compiled kernel."; return cubin; } @@ -323,7 +325,7 @@ string CUDADevice::compile_kernel(const uint kernel_features, } const int nvcc_cuda_version = cuewCompilerVersion(); - VLOG(1) << "Found nvcc " << nvcc << ", CUDA version " << nvcc_cuda_version << "."; + VLOG_INFO << "Found nvcc " << nvcc << ", CUDA version " << nvcc_cuda_version << "."; if (nvcc_cuda_version < 101) { printf( "Unsupported CUDA version %d.%d detected, " @@ -399,7 +401,8 @@ bool CUDADevice::load_kernels(const uint kernel_features) */ if (cuModule) { if (use_adaptive_compilation()) { - VLOG(1) << "Skipping CUDA kernel reload for adaptive compilation, not currently supported."; + VLOG_INFO + << "Skipping CUDA kernel reload for adaptive compilation, not currently supported."; } return true; } @@ -481,8 +484,8 @@ void CUDADevice::reserve_local_memory(const uint kernel_features) cuMemGetInfo(&free_after, &total); } - VLOG(1) << "Local memory reserved " << string_human_readable_number(free_before - free_after) - << " bytes. (" << string_human_readable_size(free_before - free_after) << ")"; + VLOG_INFO << "Local memory reserved " << string_human_readable_number(free_before - free_after) + << " bytes. (" << string_human_readable_size(free_before - free_after) << ")"; # if 0 /* For testing mapped host memory, fill up device memory. */ @@ -513,7 +516,7 @@ void CUDADevice::init_host_memory() } } else { - VLOG(1) << "Mapped host memory disabled, failed to get system RAM"; + VLOG_WARNING << "Mapped host memory disabled, failed to get system RAM"; map_host_limit = 0; } @@ -524,8 +527,8 @@ void CUDADevice::init_host_memory() device_working_headroom = 32 * 1024 * 1024LL; // 32MB device_texture_headroom = 128 * 1024 * 1024LL; // 128MB - VLOG(1) << "Mapped host memory limit set to " << string_human_readable_number(map_host_limit) - << " bytes. (" << string_human_readable_size(map_host_limit) << ")"; + VLOG_INFO << "Mapped host memory limit set to " << string_human_readable_number(map_host_limit) + << " bytes. (" << string_human_readable_size(map_host_limit) << ")"; } void CUDADevice::load_texture_info() @@ -593,7 +596,7 @@ void CUDADevice::move_textures_to_host(size_t size, bool for_texture) * multiple CUDA devices could be moving the memory. The * first one will do it, and the rest will adopt the pointer. */ if (max_mem) { - VLOG(1) << "Move memory from device to host: " << max_mem->name; + VLOG_WORK << "Move memory from device to host: " << max_mem->name; static thread_mutex move_mutex; thread_scoped_lock lock(move_mutex); @@ -701,9 +704,9 @@ CUDADevice::CUDAMem *CUDADevice::generic_alloc(device_memory &mem, size_t pitch_ } if (mem.name) { - VLOG(1) << "Buffer allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")" << status; + VLOG_WORK << "Buffer allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")" << status; } mem.device_pointer = (device_ptr)device_pointer; @@ -899,9 +902,19 @@ void CUDADevice::const_copy_to(const char *name, void *host, size_t size) CUdeviceptr mem; size_t bytes; - cuda_assert(cuModuleGetGlobal(&mem, &bytes, cuModule, name)); - // assert(bytes == size); - cuda_assert(cuMemcpyHtoD(mem, host, size)); + cuda_assert(cuModuleGetGlobal(&mem, &bytes, cuModule, "kernel_params")); + assert(bytes == sizeof(KernelParamsCUDA)); + + /* Update data storage pointers in launch parameters. */ +# define KERNEL_DATA_ARRAY(data_type, data_name) \ + if (strcmp(name, #data_name) == 0) { \ + cuda_assert(cuMemcpyHtoD(mem + offsetof(KernelParamsCUDA, data_name), host, size)); \ + return; \ + } + KERNEL_DATA_ARRAY(KernelData, data) + KERNEL_DATA_ARRAY(IntegratorStateGPU, integrator_state) +# include "kernel/data_arrays.h" +# undef KERNEL_DATA_ARRAY } void CUDADevice::global_alloc(device_memory &mem) @@ -925,7 +938,6 @@ void CUDADevice::tex_alloc(device_texture &mem) { CUDAContextScope scope(this); - string bind_name = mem.name; size_t dsize = datatype_size(mem.data_type); size_t size = mem.memory_size(); @@ -1008,9 +1020,9 @@ void CUDADevice::tex_alloc(device_texture &mem) desc.NumChannels = mem.data_elements; desc.Flags = 0; - VLOG(1) << "Array 3D allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Array 3D allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; cuda_assert(cuArray3DCreate(&array_3d, &desc)); diff --git a/intern/cycles/device/cuda/queue.cpp b/intern/cycles/device/cuda/queue.cpp index 38c71866ad0..5912e68a92b 100644 --- a/intern/cycles/device/cuda/queue.cpp +++ b/intern/cycles/device/cuda/queue.cpp @@ -39,12 +39,12 @@ int CUDADeviceQueue::num_concurrent_states(const size_t state_size) const num_states = max((int)(num_states * factor), 1024); } else { - VLOG(3) << "CYCLES_CONCURRENT_STATES_FACTOR evaluated to 0"; + VLOG_DEVICE_STATS << "CYCLES_CONCURRENT_STATES_FACTOR evaluated to 0"; } } - VLOG(3) << "GPU queue concurrent states: " << num_states << ", using up to " - << string_human_readable_size(num_states * state_size); + VLOG_DEVICE_STATS << "GPU queue concurrent states: " << num_states << ", using up to " + << string_human_readable_size(num_states * state_size); return num_states; } diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index ea5b3c6dc8c..82c7881da5f 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -325,8 +325,8 @@ DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices, int orig_cpu_threads = (threads) ? threads : TaskScheduler::max_concurrency(); int cpu_threads = max(orig_cpu_threads - (subdevices.size() - 1), size_t(0)); - VLOG(1) << "CPU render threads reduced from " << orig_cpu_threads << " to " << cpu_threads - << ", to dedicate to GPU."; + VLOG_INFO << "CPU render threads reduced from " << orig_cpu_threads << " to " + << cpu_threads << ", to dedicate to GPU."; if (cpu_threads >= 1) { DeviceInfo cpu_device = device; @@ -338,7 +338,7 @@ DeviceInfo Device::get_multi_device(const vector<DeviceInfo> &subdevices, } } else { - VLOG(1) << "CPU render threads disabled for interactive render."; + VLOG_INFO << "CPU render threads disabled for interactive render."; continue; } } diff --git a/intern/cycles/device/hip/device.cpp b/intern/cycles/device/hip/device.cpp index d6a5ed9c419..3c9c73e7db0 100644 --- a/intern/cycles/device/hip/device.cpp +++ b/intern/cycles/device/hip/device.cpp @@ -29,30 +29,31 @@ bool device_hip_init() initialized = true; int hipew_result = hipewInit(HIPEW_INIT_HIP); if (hipew_result == HIPEW_SUCCESS) { - VLOG(1) << "HIPEW initialization succeeded"; + VLOG_INFO << "HIPEW initialization succeeded"; if (HIPDevice::have_precompiled_kernels()) { - VLOG(1) << "Found precompiled kernels"; + VLOG_INFO << "Found precompiled kernels"; result = true; } else if (hipewCompilerPath() != NULL) { - VLOG(1) << "Found HIPCC " << hipewCompilerPath(); + VLOG_INFO << "Found HIPCC " << hipewCompilerPath(); result = true; } else { - VLOG(1) << "Neither precompiled kernels nor HIPCC was found," - << " unable to use HIP"; + VLOG_INFO << "Neither precompiled kernels nor HIPCC was found," + << " unable to use HIP"; } } else { if (hipew_result == HIPEW_ERROR_ATEXIT_FAILED) { - VLOG(1) << "HIPEW initialization failed: Error setting up atexit() handler"; + VLOG_WARNING << "HIPEW initialization failed: Error setting up atexit() handler"; } else if (hipew_result == HIPEW_ERROR_OLD_DRIVER) { - VLOG(1) << "HIPEW initialization failed: Driver version too old, requires AMD Radeon Pro " - "21.Q4 driver or newer"; + VLOG_WARNING + << "HIPEW initialization failed: Driver version too old, requires AMD Radeon Pro " + "21.Q4 driver or newer"; } else { - VLOG(1) << "HIPEW initialization failed: Error opening HIP dynamic library"; + VLOG_WARNING << "HIPEW initialization failed: Error opening HIP dynamic library"; } } @@ -165,16 +166,16 @@ void device_hip_info(vector<DeviceInfo> &devices) hipDeviceGetAttribute(&timeout_attr, hipDeviceAttributeKernelExecTimeout, num); if (timeout_attr && !preempt_attr) { - VLOG(1) << "Device is recognized as display."; + VLOG_INFO << "Device is recognized as display."; info.description += " (Display)"; info.display_device = true; display_devices.push_back(info); } else { - VLOG(1) << "Device has compute preemption or is not used for display."; + VLOG_INFO << "Device has compute preemption or is not used for display."; devices.push_back(info); } - VLOG(1) << "Added device \"" << name << "\" with id \"" << info.id << "\"."; + VLOG_INFO << "Added device \"" << name << "\" with id \"" << info.id << "\"."; } if (!display_devices.empty()) diff --git a/intern/cycles/device/hip/device_impl.cpp b/intern/cycles/device/hip/device_impl.cpp index ea68c821166..82db55ea715 100644 --- a/intern/cycles/device/hip/device_impl.cpp +++ b/intern/cycles/device/hip/device_impl.cpp @@ -24,6 +24,8 @@ # include "util/types.h" # include "util/windows.h" +# include "kernel/device/hip/globals.h" + CCL_NAMESPACE_BEGIN class HIPDevice; @@ -52,7 +54,7 @@ void HIPDevice::set_error(const string &error) } HIPDevice::HIPDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler) - : Device(info, stats, profiler), texture_info(this, "__texture_info", MEM_GLOBAL) + : Device(info, stats, profiler), texture_info(this, "texture_info", MEM_GLOBAL) { first_error = true; @@ -233,9 +235,9 @@ string HIPDevice::compile_kernel(const uint kernel_features, const char *name, c /* Attempt to use kernel provided with Blender. */ if (!use_adaptive_compilation()) { const string fatbin = path_get(string_printf("lib/%s_%s.fatbin", name, arch)); - VLOG(1) << "Testing for pre-compiled kernel " << fatbin << "."; + VLOG_INFO << "Testing for pre-compiled kernel " << fatbin << "."; if (path_exists(fatbin)) { - VLOG(1) << "Using precompiled kernel."; + VLOG_INFO << "Using precompiled kernel."; return fatbin; } } @@ -265,9 +267,9 @@ string HIPDevice::compile_kernel(const uint kernel_features, const char *name, c const string include_path = source_path; const string fatbin_file = string_printf("cycles_%s_%s_%s", name, arch, kernel_md5.c_str()); const string fatbin = path_cache_get(path_join("kernels", fatbin_file)); - VLOG(1) << "Testing for locally compiled kernel " << fatbin << "."; + VLOG_INFO << "Testing for locally compiled kernel " << fatbin << "."; if (path_exists(fatbin)) { - VLOG(1) << "Using locally compiled kernel."; + VLOG_INFO << "Using locally compiled kernel."; return fatbin; } @@ -301,7 +303,7 @@ string HIPDevice::compile_kernel(const uint kernel_features, const char *name, c } const int hipcc_hip_version = hipewCompilerVersion(); - VLOG(1) << "Found hipcc " << hipcc << ", HIP version " << hipcc_hip_version << "."; + VLOG_INFO << "Found hipcc " << hipcc << ", HIP version " << hipcc_hip_version << "."; if (hipcc_hip_version < 40) { printf( "Unsupported HIP version %d.%d detected, " @@ -361,7 +363,7 @@ bool HIPDevice::load_kernels(const uint kernel_features) */ if (hipModule) { if (use_adaptive_compilation()) { - VLOG(1) << "Skipping HIP kernel reload for adaptive compilation, not currently supported."; + VLOG_INFO << "Skipping HIP kernel reload for adaptive compilation, not currently supported."; } return true; } @@ -444,8 +446,8 @@ void HIPDevice::reserve_local_memory(const uint kernel_features) hipMemGetInfo(&free_after, &total); } - VLOG(1) << "Local memory reserved " << string_human_readable_number(free_before - free_after) - << " bytes. (" << string_human_readable_size(free_before - free_after) << ")"; + VLOG_INFO << "Local memory reserved " << string_human_readable_number(free_before - free_after) + << " bytes. (" << string_human_readable_size(free_before - free_after) << ")"; # if 0 /* For testing mapped host memory, fill up device memory. */ @@ -476,7 +478,7 @@ void HIPDevice::init_host_memory() } } else { - VLOG(1) << "Mapped host memory disabled, failed to get system RAM"; + VLOG_WARNING << "Mapped host memory disabled, failed to get system RAM"; map_host_limit = 0; } @@ -487,8 +489,8 @@ void HIPDevice::init_host_memory() device_working_headroom = 32 * 1024 * 1024LL; // 32MB device_texture_headroom = 128 * 1024 * 1024LL; // 128MB - VLOG(1) << "Mapped host memory limit set to " << string_human_readable_number(map_host_limit) - << " bytes. (" << string_human_readable_size(map_host_limit) << ")"; + VLOG_INFO << "Mapped host memory limit set to " << string_human_readable_number(map_host_limit) + << " bytes. (" << string_human_readable_size(map_host_limit) << ")"; } void HIPDevice::load_texture_info() @@ -556,7 +558,7 @@ void HIPDevice::move_textures_to_host(size_t size, bool for_texture) * multiple HIP devices could be moving the memory. The * first one will do it, and the rest will adopt the pointer. */ if (max_mem) { - VLOG(1) << "Move memory from device to host: " << max_mem->name; + VLOG_WORK << "Move memory from device to host: " << max_mem->name; static thread_mutex move_mutex; thread_scoped_lock lock(move_mutex); @@ -658,9 +660,9 @@ HIPDevice::HIPMem *HIPDevice::generic_alloc(device_memory &mem, size_t pitch_pad } if (mem.name) { - VLOG(1) << "Buffer allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")" << status; + VLOG_WORK << "Buffer allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")" << status; } mem.device_pointer = (device_ptr)device_pointer; @@ -856,8 +858,19 @@ void HIPDevice::const_copy_to(const char *name, void *host, size_t size) hipDeviceptr_t mem; size_t bytes; - hip_assert(hipModuleGetGlobal(&mem, &bytes, hipModule, name)); - hip_assert(hipMemcpyHtoD(mem, host, size)); + hip_assert(hipModuleGetGlobal(&mem, &bytes, hipModule, "kernel_params")); + assert(bytes == sizeof(KernelParamsHIP)); + + /* Update data storage pointers in launch parameters. */ +# define KERNEL_DATA_ARRAY(data_type, data_name) \ + if (strcmp(name, #data_name) == 0) { \ + hip_assert(hipMemcpyHtoD(mem + offsetof(KernelParamsHIP, data_name), host, size)); \ + return; \ + } + KERNEL_DATA_ARRAY(KernelData, data) + KERNEL_DATA_ARRAY(IntegratorStateGPU, integrator_state) +# include "kernel/data_arrays.h" +# undef KERNEL_DATA_ARRAY } void HIPDevice::global_alloc(device_memory &mem) @@ -881,7 +894,6 @@ void HIPDevice::tex_alloc(device_texture &mem) { HIPContextScope scope(this); - string bind_name = mem.name; size_t dsize = datatype_size(mem.data_type); size_t size = mem.memory_size(); @@ -966,9 +978,9 @@ void HIPDevice::tex_alloc(device_texture &mem) desc.NumChannels = mem.data_elements; desc.Flags = 0; - VLOG(1) << "Array 3D allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Array 3D allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; hip_assert(hipArray3DCreate((hArray *)&array_3d, &desc)); diff --git a/intern/cycles/device/hip/queue.cpp b/intern/cycles/device/hip/queue.cpp index 6c2c2c29624..8b3d963a32f 100644 --- a/intern/cycles/device/hip/queue.cpp +++ b/intern/cycles/device/hip/queue.cpp @@ -39,12 +39,12 @@ int HIPDeviceQueue::num_concurrent_states(const size_t state_size) const num_states = max((int)(num_states * factor), 1024); } else { - VLOG(3) << "CYCLES_CONCURRENT_STATES_FACTOR evaluated to 0"; + VLOG_DEVICE_STATS << "CYCLES_CONCURRENT_STATES_FACTOR evaluated to 0"; } } - VLOG(3) << "GPU queue concurrent states: " << num_states << ", using up to " - << string_human_readable_size(num_states * state_size); + VLOG_DEVICE_STATS << "GPU queue concurrent states: " << num_states << ", using up to " + << string_human_readable_size(num_states * state_size); return num_states; } diff --git a/intern/cycles/device/memory.h b/intern/cycles/device/memory.h index 55d6d39cef8..5f44475077e 100644 --- a/intern/cycles/device/memory.h +++ b/intern/cycles/device/memory.h @@ -350,7 +350,7 @@ template<typename T> class device_only_memory : public device_memory { * * When using memory type MEM_GLOBAL, a pointer to this memory will be * automatically attached to kernel globals, using the provided name - * matching an entry in kernel_textures.h. */ + * matching an entry in kernel/data_arrays.h. */ template<typename T> class device_vector : public device_memory { public: diff --git a/intern/cycles/device/metal/device_impl.mm b/intern/cycles/device/metal/device_impl.mm index 086bf0af979..0a89055af34 100644 --- a/intern/cycles/device/metal/device_impl.mm +++ b/intern/cycles/device/metal/device_impl.mm @@ -35,7 +35,7 @@ void MetalDevice::set_error(const string &error) } MetalDevice::MetalDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler) - : Device(info, stats, profiler), texture_info(this, "__texture_info", MEM_GLOBAL) + : Device(info, stats, profiler), texture_info(this, "texture_info", MEM_GLOBAL) { mtlDevId = info.num; @@ -411,9 +411,9 @@ MetalDevice::MetalMem *MetalDevice::generic_alloc(device_memory &mem) } if (mem.name) { - VLOG(2) << "Buffer allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Buffer allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; } mem.device_size = metal_buffer.allocatedSize; @@ -625,7 +625,7 @@ device_ptr MetalDevice::mem_alloc_sub_ptr(device_memory &mem, size_t offset, siz void MetalDevice::const_copy_to(const char *name, void *host, size_t size) { - if (strcmp(name, "__data") == 0) { + if (strcmp(name, "data") == 0) { assert(size == sizeof(KernelData)); memcpy((uint8_t *)&launch_params + offsetof(KernelParamsMetal, data), host, size); return; @@ -646,19 +646,19 @@ void MetalDevice::const_copy_to(const char *name, void *host, size_t size) }; /* Update data storage pointers in launch parameters. */ - if (strcmp(name, "__integrator_state") == 0) { + if (strcmp(name, "integrator_state") == 0) { /* IntegratorStateGPU is contiguous pointers */ const size_t pointer_block_size = sizeof(IntegratorStateGPU); update_launch_pointers( - offsetof(KernelParamsMetal, __integrator_state), host, size, pointer_block_size); + offsetof(KernelParamsMetal, integrator_state), host, size, pointer_block_size); } -# define KERNEL_TEX(data_type, tex_name) \ +# define KERNEL_DATA_ARRAY(data_type, tex_name) \ else if (strcmp(name, #tex_name) == 0) \ { \ update_launch_pointers(offsetof(KernelParamsMetal, tex_name), host, size, size); \ } -# include "kernel/textures.h" -# undef KERNEL_TEX +# include "kernel/data_arrays.h" +# undef KERNEL_DATA_ARRAY } void MetalDevice::global_alloc(device_memory &mem) @@ -800,9 +800,9 @@ void MetalDevice::tex_alloc(device_texture &mem) desc.textureType = MTLTextureType3D; desc.depth = mem.data_depth; - VLOG(2) << "Texture 3D allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Texture 3D allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; mtlTexture = [mtlDevice newTextureWithDescriptor:desc]; assert(mtlTexture); @@ -834,9 +834,9 @@ void MetalDevice::tex_alloc(device_texture &mem) desc.storageMode = storage_mode; desc.usage = MTLTextureUsageShaderRead; - VLOG(2) << "Texture 2D allocate: " << mem.name << ", " - << string_human_readable_number(mem.memory_size()) << " bytes. (" - << string_human_readable_size(mem.memory_size()) << ")"; + VLOG_WORK << "Texture 2D allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; mtlTexture = [mtlDevice newTextureWithDescriptor:desc]; assert(mtlTexture); diff --git a/intern/cycles/device/metal/queue.mm b/intern/cycles/device/metal/queue.mm index 0e260886abb..da5408373bb 100644 --- a/intern/cycles/device/metal/queue.mm +++ b/intern/cycles/device/metal/queue.mm @@ -311,8 +311,8 @@ bool MetalDeviceQueue::enqueue(DeviceKernel kernel, return false; } - VLOG(3) << "Metal queue launch " << device_kernel_as_string(kernel) << ", work_size " - << work_size; + VLOG_DEVICE_STATS << "Metal queue launch " << device_kernel_as_string(kernel) << ", work_size " + << work_size; id<MTLComputeCommandEncoder> mtlComputeCommandEncoder = get_compute_encoder(kernel); @@ -358,7 +358,7 @@ bool MetalDeviceQueue::enqueue(DeviceKernel kernel, /* Prepare any non-pointer (i.e. plain-old-data) KernelParamsMetal data */ /* The plain-old-data is contiguous, continuing to the end of KernelParamsMetal */ - size_t plain_old_launch_data_offset = offsetof(KernelParamsMetal, __integrator_state) + + size_t plain_old_launch_data_offset = offsetof(KernelParamsMetal, integrator_state) + sizeof(IntegratorStateGPU); size_t plain_old_launch_data_size = sizeof(KernelParamsMetal) - plain_old_launch_data_offset; memcpy(init_arg_buffer + globals_offsets + plain_old_launch_data_offset, @@ -415,7 +415,7 @@ bool MetalDeviceQueue::enqueue(DeviceKernel kernel, } /* this relies on IntegratorStateGPU layout being contiguous device_ptrs */ - const size_t pointer_block_end = offsetof(KernelParamsMetal, __integrator_state) + + const size_t pointer_block_end = offsetof(KernelParamsMetal, integrator_state) + sizeof(IntegratorStateGPU); for (size_t offset = 0; offset < pointer_block_end; offset += sizeof(device_ptr)) { int pointer_index = int(offset / sizeof(device_ptr)); diff --git a/intern/cycles/device/optix/device.cpp b/intern/cycles/device/optix/device.cpp index 70810bae10d..68ca21374fd 100644 --- a/intern/cycles/device/optix/device.cpp +++ b/intern/cycles/device/optix/device.cpp @@ -31,12 +31,12 @@ bool device_optix_init() const OptixResult result = optixInit(); if (result == OPTIX_ERROR_UNSUPPORTED_ABI_VERSION) { - VLOG(1) << "OptiX initialization failed because the installed NVIDIA driver is too old. " - "Please update to the latest driver first!"; + VLOG_WARNING << "OptiX initialization failed because the installed NVIDIA driver is too old. " + "Please update to the latest driver first!"; return false; } else if (result != OPTIX_SUCCESS) { - VLOG(1) << "OptiX initialization failed with error code " << (unsigned int)result; + VLOG_WARNING << "OptiX initialization failed with error code " << (unsigned int)result; return false; } diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp index 9ab9bbb59c5..e7dcc29a2da 100644 --- a/intern/cycles/device/optix/device_impl.cpp +++ b/intern/cycles/device/optix/device_impl.cpp @@ -246,7 +246,7 @@ OptiXDevice::Denoiser::Denoiser(OptiXDevice *device) OptiXDevice::OptiXDevice(const DeviceInfo &info, Stats &stats, Profiler &profiler) : CUDADevice(info, stats, profiler), sbt_data(this, "__sbt", MEM_READ_ONLY), - launch_params(this, "__params", false), + launch_params(this, "kernel_params", false), denoiser_(this) { /* Make the CUDA context current. */ @@ -278,7 +278,7 @@ OptiXDevice::OptiXDevice(const DeviceInfo &info, Stats &stats, Profiler &profile }; # endif if (DebugFlags().optix.use_debug) { - VLOG(1) << "Using OptiX debug mode."; + VLOG_INFO << "Using OptiX debug mode."; options.validationMode = OPTIX_DEVICE_CONTEXT_VALIDATION_MODE_ALL; } optix_assert(optixDeviceContextCreate(cuContext, &options, &context)); @@ -421,7 +421,7 @@ bool OptiXDevice::load_kernels(const uint kernel_features) pipeline_options.numPayloadValues = 8; pipeline_options.numAttributeValues = 2; /* u, v */ pipeline_options.exceptionFlags = OPTIX_EXCEPTION_FLAG_NONE; - pipeline_options.pipelineLaunchParamsVariableName = "__params"; /* See globals.h */ + pipeline_options.pipelineLaunchParamsVariableName = "kernel_params"; /* See globals.h */ pipeline_options.usesPrimitiveTypeFlags = OPTIX_PRIMITIVE_TYPE_FLAGS_TRIANGLE; if (kernel_features & KERNEL_FEATURE_HAIR) { @@ -1392,11 +1392,11 @@ bool OptiXDevice::build_optix_bvh(BVHOptiX *bvh, /* The build flags have to match the ones used to query the built-in curve intersection program (see optixBuiltinISModuleGet above) */ build_input.type == OPTIX_BUILD_INPUT_TYPE_CURVES) { - VLOG(2) << "Using fast to trace OptiX BVH"; + VLOG_INFO << "Using fast to trace OptiX BVH"; options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_TRACE | OPTIX_BUILD_FLAG_ALLOW_COMPACTION; } else { - VLOG(2) << "Using fast to update OptiX BVH"; + VLOG_INFO << "Using fast to update OptiX BVH"; options.buildFlags = OPTIX_BUILD_FLAG_PREFER_FAST_BUILD | OPTIX_BUILD_FLAG_ALLOW_UPDATE; } @@ -2042,7 +2042,7 @@ void OptiXDevice::const_copy_to(const char *name, void *host, size_t size) /* Set constant memory for CUDA module. */ CUDADevice::const_copy_to(name, host, size); - if (strcmp(name, "__data") == 0) { + if (strcmp(name, "data") == 0) { assert(size <= sizeof(KernelData)); /* Update traversable handle (since it is different for each device on multi devices). */ @@ -2054,14 +2054,14 @@ void OptiXDevice::const_copy_to(const char *name, void *host, size_t size) } /* Update data storage pointers in launch parameters. */ -# define KERNEL_TEX(data_type, tex_name) \ - if (strcmp(name, #tex_name) == 0) { \ - update_launch_params(offsetof(KernelParamsOptiX, tex_name), host, size); \ +# define KERNEL_DATA_ARRAY(data_type, data_name) \ + if (strcmp(name, #data_name) == 0) { \ + update_launch_params(offsetof(KernelParamsOptiX, data_name), host, size); \ return; \ } - KERNEL_TEX(IntegratorStateGPU, __integrator_state) -# include "kernel/textures.h" -# undef KERNEL_TEX + KERNEL_DATA_ARRAY(IntegratorStateGPU, integrator_state) +# include "kernel/data_arrays.h" +# undef KERNEL_DATA_ARRAY } void OptiXDevice::update_launch_params(size_t offset, void *data, size_t data_size) diff --git a/intern/cycles/device/queue.cpp b/intern/cycles/device/queue.cpp index de65047ed6a..cc0cf0ccf84 100644 --- a/intern/cycles/device/queue.cpp +++ b/intern/cycles/device/queue.cpp @@ -19,7 +19,7 @@ DeviceQueue::DeviceQueue(Device *device) DeviceQueue::~DeviceQueue() { - if (VLOG_IS_ON(3)) { + if (VLOG_DEVICE_STATS_IS_ON) { /* Print kernel execution times sorted by time. */ vector<pair<DeviceKernelMask, double>> stats_sorted; for (const auto &stat : stats_kernel_time_) { @@ -32,17 +32,18 @@ DeviceQueue::~DeviceQueue() return a.second > b.second; }); - VLOG(3) << "GPU queue stats:"; + VLOG_DEVICE_STATS << "GPU queue stats:"; for (const auto &[mask, time] : stats_sorted) { - VLOG(3) << " " << std::setfill(' ') << std::setw(10) << std::fixed << std::setprecision(5) - << std::right << time << "s: " << device_kernel_mask_as_string(mask); + VLOG_DEVICE_STATS << " " << std::setfill(' ') << std::setw(10) << std::fixed + << std::setprecision(5) << std::right << time + << "s: " << device_kernel_mask_as_string(mask); } } } void DeviceQueue::debug_init_execution() { - if (VLOG_IS_ON(3)) { + if (VLOG_DEVICE_STATS_IS_ON) { last_sync_time_ = time_dt(); } @@ -51,9 +52,9 @@ void DeviceQueue::debug_init_execution() void DeviceQueue::debug_enqueue(DeviceKernel kernel, const int work_size) { - if (VLOG_IS_ON(3)) { - VLOG(4) << "GPU queue launch " << device_kernel_as_string(kernel) << ", work_size " - << work_size; + if (VLOG_DEVICE_STATS_IS_ON) { + VLOG_DEVICE_STATS << "GPU queue launch " << device_kernel_as_string(kernel) << ", work_size " + << work_size; } last_kernels_enqueued_ |= (uint64_t(1) << (uint64_t)kernel); @@ -61,10 +62,10 @@ void DeviceQueue::debug_enqueue(DeviceKernel kernel, const int work_size) void DeviceQueue::debug_synchronize() { - if (VLOG_IS_ON(3)) { + if (VLOG_DEVICE_STATS_IS_ON) { const double new_time = time_dt(); const double elapsed_time = new_time - last_sync_time_; - VLOG(4) << "GPU queue synchronize, elapsed " << std::setw(10) << elapsed_time << "s"; + VLOG_DEVICE_STATS << "GPU queue synchronize, elapsed " << std::setw(10) << elapsed_time << "s"; stats_kernel_time_[last_kernels_enqueued_] += elapsed_time; diff --git a/intern/cycles/integrator/denoiser.cpp b/intern/cycles/integrator/denoiser.cpp index 23ab825a4d2..94991d63e4c 100644 --- a/intern/cycles/integrator/denoiser.cpp +++ b/intern/cycles/integrator/denoiser.cpp @@ -58,8 +58,8 @@ bool Denoiser::load_kernels(Progress *progress) return false; } - VLOG(3) << "Will denoise on " << denoiser_device->info.description << " (" - << denoiser_device->info.id << ")"; + VLOG_WORK << "Will denoise on " << denoiser_device->info.description << " (" + << denoiser_device->info.id << ")"; return true; } diff --git a/intern/cycles/integrator/denoiser_device.cpp b/intern/cycles/integrator/denoiser_device.cpp index 595397312b3..5414f9dfb1a 100644 --- a/intern/cycles/integrator/denoiser_device.cpp +++ b/intern/cycles/integrator/denoiser_device.cpp @@ -48,7 +48,7 @@ bool DeviceDenoiser::denoise_buffer(const BufferParams &buffer_params, task.render_buffers = render_buffers; } else { - VLOG(3) << "Creating temporary buffer on denoiser device."; + VLOG_WORK << "Creating temporary buffer on denoiser device."; DeviceQueue *queue = denoiser_device->get_denoise_queue(); diff --git a/intern/cycles/integrator/denoiser_oidn.cpp b/intern/cycles/integrator/denoiser_oidn.cpp index b074408e229..04e659a15e2 100644 --- a/intern/cycles/integrator/denoiser_oidn.cpp +++ b/intern/cycles/integrator/denoiser_oidn.cpp @@ -284,8 +284,8 @@ class OIDNDenoiseContext { /* Read pass pixels using PassAccessor into a temporary buffer which is owned by the pass.. */ void read_pass_pixels_into_buffer(OIDNPass &oidn_pass) { - VLOG(3) << "Allocating temporary buffer for pass " << oidn_pass.name << " (" - << pass_type_as_string(oidn_pass.type) << ")"; + VLOG_WORK << "Allocating temporary buffer for pass " << oidn_pass.name << " (" + << pass_type_as_string(oidn_pass.type) << ")"; const int64_t width = buffer_params_.width; const int64_t height = buffer_params_.height; diff --git a/intern/cycles/integrator/path_trace.cpp b/intern/cycles/integrator/path_trace.cpp index 36a0326e405..9ad1c465725 100644 --- a/intern/cycles/integrator/path_trace.cpp +++ b/intern/cycles/integrator/path_trace.cpp @@ -348,8 +348,8 @@ void PathTrace::path_trace(RenderWork &render_work) return; } - VLOG(3) << "Will path trace " << render_work.path_trace.num_samples - << " samples at the resolution divider " << render_work.resolution_divider; + VLOG_WORK << "Will path trace " << render_work.path_trace.num_samples + << " samples at the resolution divider " << render_work.resolution_divider; const double start_time = time_dt(); @@ -373,9 +373,9 @@ void PathTrace::path_trace(RenderWork &render_work) work_balance_infos_[i].time_spent += work_time; work_balance_infos_[i].occupancy = statistics.occupancy; - VLOG(3) << "Rendered " << num_samples << " samples in " << work_time << " seconds (" - << work_time / num_samples - << " seconds per sample), occupancy: " << statistics.occupancy; + VLOG_WORK << "Rendered " << num_samples << " samples in " << work_time << " seconds (" + << work_time / num_samples + << " seconds per sample), occupancy: " << statistics.occupancy; }); float occupancy_accum = 0.0f; @@ -398,10 +398,10 @@ void PathTrace::adaptive_sample(RenderWork &render_work) bool did_reschedule_on_idle = false; while (true) { - VLOG(3) << "Will filter adaptive stopping buffer, threshold " - << render_work.adaptive_sampling.threshold; + VLOG_WORK << "Will filter adaptive stopping buffer, threshold " + << render_work.adaptive_sampling.threshold; if (render_work.adaptive_sampling.reset) { - VLOG(3) << "Will re-calculate convergency flag for currently converged pixels."; + VLOG_WORK << "Will re-calculate convergency flag for currently converged pixels."; } const double start_time = time_dt(); @@ -420,11 +420,11 @@ void PathTrace::adaptive_sample(RenderWork &render_work) render_work, time_dt() - start_time, is_cancel_requested()); if (num_active_pixels == 0) { - VLOG(3) << "All pixels converged."; + VLOG_WORK << "All pixels converged."; if (!render_scheduler_.render_work_reschedule_on_converge(render_work)) { break; } - VLOG(3) << "Continuing with lower threshold."; + VLOG_WORK << "Continuing with lower threshold."; } else if (did_reschedule_on_idle) { break; @@ -436,10 +436,10 @@ void PathTrace::adaptive_sample(RenderWork &render_work) * A better heuristic is possible here: for example, use maximum of 128^2 and percentage of * the final resolution. */ if (!render_scheduler_.render_work_reschedule_on_idle(render_work)) { - VLOG(3) << "Rescheduling is not possible: final threshold is reached."; + VLOG_WORK << "Rescheduling is not possible: final threshold is reached."; break; } - VLOG(3) << "Rescheduling lower threshold."; + VLOG_WORK << "Rescheduling lower threshold."; did_reschedule_on_idle = true; } else { @@ -483,7 +483,7 @@ void PathTrace::cryptomatte_postprocess(const RenderWork &render_work) if (!render_work.cryptomatte.postprocess) { return; } - VLOG(3) << "Perform cryptomatte work."; + VLOG_WORK << "Perform cryptomatte work."; parallel_for_each(path_trace_works_, [&](unique_ptr<PathTraceWork> &path_trace_work) { path_trace_work->cryptomatte_postproces(); @@ -501,7 +501,7 @@ void PathTrace::denoise(const RenderWork &render_work) return; } - VLOG(3) << "Perform denoising work."; + VLOG_WORK << "Perform denoising work."; const double start_time = time_dt(); @@ -599,26 +599,26 @@ void PathTrace::update_display(const RenderWork &render_work) } if (!display_ && !output_driver_) { - VLOG(3) << "Ignore display update."; + VLOG_WORK << "Ignore display update."; return; } if (full_params_.width == 0 || full_params_.height == 0) { - VLOG(3) << "Skipping PathTraceDisplay update due to 0 size of the render buffer."; + VLOG_WORK << "Skipping PathTraceDisplay update due to 0 size of the render buffer."; return; } const double start_time = time_dt(); if (output_driver_) { - VLOG(3) << "Invoke buffer update callback."; + VLOG_WORK << "Invoke buffer update callback."; PathTraceTile tile(*this); output_driver_->update_render_tile(tile); } if (display_) { - VLOG(3) << "Perform copy to GPUDisplay work."; + VLOG_WORK << "Perform copy to GPUDisplay work."; const int texture_width = render_state_.effective_big_tile_params.window_width; const int texture_height = render_state_.effective_big_tile_params.window_height; @@ -654,33 +654,33 @@ void PathTrace::rebalance(const RenderWork &render_work) const int num_works = path_trace_works_.size(); if (num_works == 1) { - VLOG(3) << "Ignoring rebalance work due to single device render."; + VLOG_WORK << "Ignoring rebalance work due to single device render."; return; } const double start_time = time_dt(); if (VLOG_IS_ON(3)) { - VLOG(3) << "Perform rebalance work."; - VLOG(3) << "Per-device path tracing time (seconds):"; + VLOG_WORK << "Perform rebalance work."; + VLOG_WORK << "Per-device path tracing time (seconds):"; for (int i = 0; i < num_works; ++i) { - VLOG(3) << path_trace_works_[i]->get_device()->info.description << ": " - << work_balance_infos_[i].time_spent; + VLOG_WORK << path_trace_works_[i]->get_device()->info.description << ": " + << work_balance_infos_[i].time_spent; } } const bool did_rebalance = work_balance_do_rebalance(work_balance_infos_); if (VLOG_IS_ON(3)) { - VLOG(3) << "Calculated per-device weights for works:"; + VLOG_WORK << "Calculated per-device weights for works:"; for (int i = 0; i < num_works; ++i) { - VLOG(3) << path_trace_works_[i]->get_device()->info.description << ": " - << work_balance_infos_[i].weight; + VLOG_WORK << path_trace_works_[i]->get_device()->info.description << ": " + << work_balance_infos_[i].weight; } } if (!did_rebalance) { - VLOG(3) << "Balance in path trace works did not change."; + VLOG_WORK << "Balance in path trace works did not change."; render_scheduler_.report_rebalance_time(render_work, time_dt() - start_time, false); return; } @@ -704,7 +704,7 @@ void PathTrace::write_tile_buffer(const RenderWork &render_work) return; } - VLOG(3) << "Write tile result."; + VLOG_WORK << "Write tile result."; render_state_.tile_written = true; @@ -718,14 +718,14 @@ void PathTrace::write_tile_buffer(const RenderWork &render_work) * * Important thing is: tile should be written to the software via callback only once. */ if (!has_multiple_tiles) { - VLOG(3) << "Write tile result via buffer write callback."; + VLOG_WORK << "Write tile result via buffer write callback."; tile_buffer_write(); } /* Write tile to disk, so that the render work's render buffer can be re-used for the next tile. */ if (has_multiple_tiles) { - VLOG(3) << "Write tile result into ."; + VLOG_WORK << "Write tile result into ."; tile_buffer_write_to_disk(); } } @@ -736,10 +736,10 @@ void PathTrace::finalize_full_buffer_on_disk(const RenderWork &render_work) return; } - VLOG(3) << "Handle full-frame render buffer work."; + VLOG_WORK << "Handle full-frame render buffer work."; if (!tile_manager_.has_written_tiles()) { - VLOG(3) << "No tiles on disk."; + VLOG_WORK << "No tiles on disk."; return; } @@ -935,7 +935,7 @@ static string get_layer_view_name(const RenderBuffers &buffers) void PathTrace::process_full_buffer_from_disk(string_view filename) { - VLOG(3) << "Processing full frame buffer file " << filename; + VLOG_WORK << "Processing full frame buffer file " << filename; progress_set_status("Reading full buffer from disk"); diff --git a/intern/cycles/integrator/path_trace_work_gpu.cpp b/intern/cycles/integrator/path_trace_work_gpu.cpp index ede81705ae8..e262c252ce3 100644 --- a/intern/cycles/integrator/path_trace_work_gpu.cpp +++ b/intern/cycles/integrator/path_trace_work_gpu.cpp @@ -152,7 +152,7 @@ void PathTraceWorkGPU::alloc_integrator_soa() total_soa_size += soa_memory->memory_size(); } - VLOG(3) << "GPU SoA state size: " << string_human_readable_size(total_soa_size); + VLOG_DEVICE_STATS << "GPU SoA state size: " << string_human_readable_size(total_soa_size); } } @@ -239,7 +239,7 @@ void PathTraceWorkGPU::init_execution() /* Copy to device side struct in constant memory. */ device_->const_copy_to( - "__integrator_state", &integrator_state_gpu_, sizeof(integrator_state_gpu_)); + "integrator_state", &integrator_state_gpu_, sizeof(integrator_state_gpu_)); } void PathTraceWorkGPU::render_samples(RenderStatistics &statistics, @@ -820,10 +820,10 @@ bool PathTraceWorkGPU::should_use_graphics_interop() interop_use_ = device->should_use_graphics_interop(); if (interop_use_) { - VLOG(2) << "Using graphics interop GPU display update."; + VLOG_INFO << "Using graphics interop GPU display update."; } else { - VLOG(2) << "Using naive GPU display update."; + VLOG_INFO << "Using naive GPU display update."; } interop_use_checked_ = true; diff --git a/intern/cycles/integrator/render_scheduler.cpp b/intern/cycles/integrator/render_scheduler.cpp index ebc3170393f..e4676bd059c 100644 --- a/intern/cycles/integrator/render_scheduler.cpp +++ b/intern/cycles/integrator/render_scheduler.cpp @@ -225,7 +225,7 @@ bool RenderScheduler::render_work_reschedule_on_idle(RenderWork &render_work) void RenderScheduler::render_work_reschedule_on_cancel(RenderWork &render_work) { - VLOG(3) << "Schedule work for cancel."; + VLOG_WORK << "Schedule work for cancel."; /* Un-schedule samples: they will not be rendered and should not be counted. */ state_.num_rendered_samples -= render_work.path_trace.num_samples; @@ -475,14 +475,14 @@ void RenderScheduler::report_path_trace_time(const RenderWork &render_work, path_trace_time_.add_average(final_time_approx, render_work.path_trace.num_samples); - VLOG(4) << "Average path tracing time: " << path_trace_time_.get_average() << " seconds."; + VLOG_WORK << "Average path tracing time: " << path_trace_time_.get_average() << " seconds."; } void RenderScheduler::report_path_trace_occupancy(const RenderWork &render_work, float occupancy) { state_.occupancy_num_samples = render_work.path_trace.num_samples; state_.occupancy = occupancy; - VLOG(4) << "Measured path tracing occupancy: " << occupancy; + VLOG_WORK << "Measured path tracing occupancy: " << occupancy; } void RenderScheduler::report_adaptive_filter_time(const RenderWork &render_work, @@ -503,8 +503,8 @@ void RenderScheduler::report_adaptive_filter_time(const RenderWork &render_work, adaptive_filter_time_.add_average(final_time_approx, render_work.path_trace.num_samples); - VLOG(4) << "Average adaptive sampling filter time: " << adaptive_filter_time_.get_average() - << " seconds."; + VLOG_WORK << "Average adaptive sampling filter time: " << adaptive_filter_time_.get_average() + << " seconds."; } void RenderScheduler::report_denoise_time(const RenderWork &render_work, double time) @@ -523,7 +523,7 @@ void RenderScheduler::report_denoise_time(const RenderWork &render_work, double denoise_time_.add_average(final_time_approx); - VLOG(4) << "Average denoising time: " << denoise_time_.get_average() << " seconds."; + VLOG_WORK << "Average denoising time: " << denoise_time_.get_average() << " seconds."; } void RenderScheduler::report_display_update_time(const RenderWork &render_work, double time) @@ -542,7 +542,8 @@ void RenderScheduler::report_display_update_time(const RenderWork &render_work, display_update_time_.add_average(final_time_approx); - VLOG(4) << "Average display update time: " << display_update_time_.get_average() << " seconds."; + VLOG_WORK << "Average display update time: " << display_update_time_.get_average() + << " seconds."; /* Move the display update moment further in time, so that logic which checks when last update * did happen have more reliable point in time (without path tracing and denoising parts of the @@ -568,7 +569,7 @@ void RenderScheduler::report_rebalance_time(const RenderWork &render_work, state_.last_rebalance_changed = balance_changed; - VLOG(4) << "Average rebalance time: " << rebalance_time_.get_average() << " seconds."; + VLOG_WORK << "Average rebalance time: " << rebalance_time_.get_average() << " seconds."; } string RenderScheduler::full_report() const @@ -1063,7 +1064,7 @@ void RenderScheduler::update_start_resolution_divider() /* Resolution divider has never been calculated before: use default resolution, so that we have * somewhat good initial behavior, giving a chance to collect real numbers. */ start_resolution_divider_ = default_start_resolution_divider_; - VLOG(3) << "Initial resolution divider is " << start_resolution_divider_; + VLOG_WORK << "Initial resolution divider is " << start_resolution_divider_; return; } @@ -1092,7 +1093,7 @@ void RenderScheduler::update_start_resolution_divider() * simple and compute device is fast). */ start_resolution_divider_ = max(resolution_divider_for_update, pixel_size_); - VLOG(3) << "Calculated resolution divider is " << start_resolution_divider_; + VLOG_WORK << "Calculated resolution divider is " << start_resolution_divider_; } double RenderScheduler::guess_viewport_navigation_update_interval_in_seconds() const diff --git a/intern/cycles/integrator/shader_eval.cpp b/intern/cycles/integrator/shader_eval.cpp index 92b9d1c662d..b1450732f5c 100644 --- a/intern/cycles/integrator/shader_eval.cpp +++ b/intern/cycles/integrator/shader_eval.cpp @@ -31,8 +31,8 @@ bool ShaderEval::eval(const ShaderEvalType type, device_->foreach_device([&](Device *device) { if (!first_device) { - LOG(ERROR) << "Multi-devices are not yet fully implemented, will evaluate shader on a " - "single device."; + VLOG_WORK << "Multi-devices are not yet fully implemented, will evaluate shader on a " + "single device."; return; } first_device = false; diff --git a/intern/cycles/integrator/work_tile_scheduler.cpp b/intern/cycles/integrator/work_tile_scheduler.cpp index 6dc511064c9..4bc8c0c4396 100644 --- a/intern/cycles/integrator/work_tile_scheduler.cpp +++ b/intern/cycles/integrator/work_tile_scheduler.cpp @@ -55,7 +55,7 @@ void WorkTileScheduler::reset_scheduler_state() tile_size_ = tile_calculate_best_size( accelerated_rt_, image_size_px_, samples_num_, max_num_path_states_, scrambling_distance_); - VLOG(3) << "Will schedule tiles of size " << tile_size_; + VLOG_WORK << "Will schedule tiles of size " << tile_size_; if (VLOG_IS_ON(3)) { /* The logging is based on multiple tiles scheduled, ignoring overhead of multi-tile scheduling @@ -63,8 +63,8 @@ void WorkTileScheduler::reset_scheduler_state() const int num_path_states_in_tile = tile_size_.width * tile_size_.height * tile_size_.num_samples; const int num_tiles = max_num_path_states_ / num_path_states_in_tile; - VLOG(3) << "Number of unused path states: " - << max_num_path_states_ - num_tiles * num_path_states_in_tile; + VLOG_WORK << "Number of unused path states: " + << max_num_path_states_ - num_tiles * num_path_states_in_tile; } num_tiles_x_ = divide_up(image_size_px_.x, tile_size_.width); diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index 473bdb67920..a07d7852211 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -267,8 +267,8 @@ set(SRC_KERNEL_UTIL_HEADERS ) set(SRC_KERNEL_TYPES_HEADERS + data_arrays.h tables.h - textures.h types.h ) diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h index 04ccb7ceff5..a1d0e307170 100644 --- a/intern/cycles/kernel/bvh/bvh.h +++ b/intern/cycles/kernel/bvh/bvh.h @@ -452,7 +452,7 @@ ccl_device_intersect bool scene_intersect_local(KernelGlobals kg, # ifdef __EMBREE__ if (kernel_data.bvh.scene) { - const bool has_bvh = !(kernel_tex_fetch(__object_flag, local_object) & + const bool has_bvh = !(kernel_data_fetch(object_flag, local_object) & SD_OBJECT_TRANSFORM_APPLIED); CCLIntersectContext ctx( kg, has_bvh ? CCLIntersectContext::RAY_SSS : CCLIntersectContext::RAY_LOCAL); diff --git a/intern/cycles/kernel/bvh/embree.h b/intern/cycles/kernel/bvh/embree.h index 4f7e6435daf..1c6b9bc1e62 100644 --- a/intern/cycles/kernel/bvh/embree.h +++ b/intern/cycles/kernel/bvh/embree.h @@ -146,14 +146,14 @@ ccl_device_inline void kernel_embree_convert_hit(KernelGlobals kg, const bool is_hair = hit->geomID & 1; if (is_hair) { - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, isect->prim); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, isect->prim); isect->type = segment.type; isect->prim = segment.prim; isect->u = hit->u; isect->v = hit->v; } else { - isect->type = kernel_tex_fetch(__objects, isect->object).primitive_type; + isect->type = kernel_data_fetch(objects, isect->object).primitive_type; isect->u = 1.0f - hit->v - hit->u; isect->v = hit->u; } @@ -170,7 +170,7 @@ ccl_device_inline void kernel_embree_convert_sss_hit( isect->prim = hit->primID + (intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID)); isect->object = object; - isect->type = kernel_tex_fetch(__objects, object).primitive_type; + isect->type = kernel_data_fetch(objects, object).primitive_type; } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/bvh/local.h b/intern/cycles/kernel/bvh/local.h index 0d05e09d75f..3b6b30ea93d 100644 --- a/intern/cycles/kernel/bvh/local.h +++ b/intern/cycles/kernel/bvh/local.h @@ -41,7 +41,7 @@ ccl_device_inline /* traversal variables in registers */ int stack_ptr = 0; - int node_addr = kernel_tex_fetch(__object_node, local_object); + int node_addr = kernel_data_fetch(object_node, local_object); /* ray parameters in registers */ float3 P = ray->P; @@ -55,7 +55,7 @@ ccl_device_inline } kernel_assert((local_isect == NULL) == (max_hits == 0)); - const int object_flag = kernel_tex_fetch(__object_flag, local_object); + const int object_flag = kernel_data_fetch(object_flag, local_object); if (!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) { #if BVH_FEATURE(BVH_MOTION) Transform ob_itfm; @@ -73,7 +73,7 @@ ccl_device_inline while (node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { int node_addr_child1, traverse_mask; float dist[2]; - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); traverse_mask = NODE_INTERSECT(kg, P, @@ -117,7 +117,7 @@ ccl_device_inline /* if node is leaf, fetch triangle list */ if (node_addr < 0) { - float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1)); + float4 leaf = kernel_data_fetch(bvh_leaf_nodes, (-node_addr - 1)); int prim_addr = __float_as_int(leaf.x); const int prim_addr2 = __float_as_int(leaf.y); @@ -132,18 +132,18 @@ ccl_device_inline case PRIMITIVE_TRIANGLE: { /* intersect ray against primitive */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert(kernel_tex_fetch(__prim_type, prim_addr) == type); + kernel_assert(kernel_data_fetch(prim_type, prim_addr) == type); /* Only intersect with matching object, for instanced objects we * already know we are only intersecting the right object. */ if (object == OBJECT_NONE) { - if (kernel_tex_fetch(__prim_object, prim_addr) != local_object) { + if (kernel_data_fetch(prim_object, prim_addr) != local_object) { continue; } } /* Skip self intersection. */ - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self_local(ray->self, prim)) { continue; } @@ -167,18 +167,18 @@ ccl_device_inline case PRIMITIVE_MOTION_TRIANGLE: { /* intersect ray against primitive */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert(kernel_tex_fetch(__prim_type, prim_addr) == type); + kernel_assert(kernel_data_fetch(prim_type, prim_addr) == type); /* Only intersect with matching object, for instanced objects we * already know we are only intersecting the right object. */ if (object == OBJECT_NONE) { - if (kernel_tex_fetch(__prim_object, prim_addr) != local_object) { + if (kernel_data_fetch(prim_object, prim_addr) != local_object) { continue; } } /* Skip self intersection. */ - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self_local(ray->self, prim)) { continue; } diff --git a/intern/cycles/kernel/bvh/nodes.h b/intern/cycles/kernel/bvh/nodes.h index fd475dcd5e9..c19dea9223b 100644 --- a/intern/cycles/kernel/bvh/nodes.h +++ b/intern/cycles/kernel/bvh/nodes.h @@ -9,9 +9,9 @@ ccl_device_forceinline Transform bvh_unaligned_node_fetch_space(KernelGlobals kg { Transform space; const int child_addr = node_addr + child * 3; - space.x = kernel_tex_fetch(__bvh_nodes, child_addr + 1); - space.y = kernel_tex_fetch(__bvh_nodes, child_addr + 2); - space.z = kernel_tex_fetch(__bvh_nodes, child_addr + 3); + space.x = kernel_data_fetch(bvh_nodes, child_addr + 1); + space.y = kernel_data_fetch(bvh_nodes, child_addr + 2); + space.z = kernel_data_fetch(bvh_nodes, child_addr + 3); return space; } @@ -26,11 +26,11 @@ ccl_device_forceinline int bvh_aligned_node_intersect(KernelGlobals kg, /* fetch node data */ #ifdef __VISIBILITY_FLAG__ - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); #endif - float4 node0 = kernel_tex_fetch(__bvh_nodes, node_addr + 1); - float4 node1 = kernel_tex_fetch(__bvh_nodes, node_addr + 2); - float4 node2 = kernel_tex_fetch(__bvh_nodes, node_addr + 3); + float4 node0 = kernel_data_fetch(bvh_nodes, node_addr + 1); + float4 node1 = kernel_data_fetch(bvh_nodes, node_addr + 2); + float4 node2 = kernel_data_fetch(bvh_nodes, node_addr + 3); /* intersect ray against child nodes */ float c0lox = (node0.x - P.x) * idir.x; @@ -100,7 +100,7 @@ ccl_device_forceinline int bvh_unaligned_node_intersect(KernelGlobals kg, { int mask = 0; #ifdef __VISIBILITY_FLAG__ - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); #endif if (bvh_unaligned_node_intersect_child(kg, P, dir, t, node_addr, 0, &dist[0])) { #ifdef __VISIBILITY_FLAG__ @@ -130,7 +130,7 @@ ccl_device_forceinline int bvh_node_intersect(KernelGlobals kg, const uint visibility, float dist[2]) { - float4 node = kernel_tex_fetch(__bvh_nodes, node_addr); + float4 node = kernel_data_fetch(bvh_nodes, node_addr); if (__float_as_uint(node.x) & PATH_RAY_NODE_UNALIGNED) { return bvh_unaligned_node_intersect(kg, P, dir, idir, t, node_addr, visibility, dist); } diff --git a/intern/cycles/kernel/bvh/shadow_all.h b/intern/cycles/kernel/bvh/shadow_all.h index 2f58929c1e5..e86fe867eac 100644 --- a/intern/cycles/kernel/bvh/shadow_all.h +++ b/intern/cycles/kernel/bvh/shadow_all.h @@ -80,7 +80,7 @@ ccl_device_inline while (node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { int node_addr_child1, traverse_mask; float dist[2]; - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); traverse_mask = NODE_INTERSECT(kg, P, @@ -124,7 +124,7 @@ ccl_device_inline /* if node is leaf, fetch triangle list */ if (node_addr < 0) { - float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1)); + float4 leaf = kernel_data_fetch(bvh_leaf_nodes, (-node_addr - 1)); int prim_addr = __float_as_int(leaf.x); if (prim_addr >= 0) { @@ -137,7 +137,7 @@ ccl_device_inline /* primitive intersection */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert((kernel_tex_fetch(__prim_type, prim_addr) & PRIMITIVE_ALL) == + kernel_assert((kernel_data_fetch(prim_type, prim_addr) & PRIMITIVE_ALL) == (type & PRIMITIVE_ALL)); bool hit; @@ -147,9 +147,9 @@ ccl_device_inline Intersection isect ccl_optional_struct_init; const int prim_object = (object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, prim_addr) : + kernel_data_fetch(prim_object, prim_addr) : object; - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self_shadow(ray->self, prim_object, prim)) { continue; } @@ -181,14 +181,14 @@ ccl_device_inline case PRIMITIVE_CURVE_RIBBON: case PRIMITIVE_MOTION_CURVE_RIBBON: { if ((type & PRIMITIVE_MOTION) && kernel_data.bvh.use_bvh_steps) { - const float2 prim_time = kernel_tex_fetch(__prim_time, prim_addr); + const float2 prim_time = kernel_data_fetch(prim_time, prim_addr); if (ray->time < prim_time.x || ray->time > prim_time.y) { hit = false; break; } } - const int curve_type = kernel_tex_fetch(__prim_type, prim_addr); + const int curve_type = kernel_data_fetch(prim_type, prim_addr); hit = curve_intersect( kg, &isect, P, dir, t_max_current, prim_object, prim, ray->time, curve_type); @@ -199,14 +199,14 @@ ccl_device_inline case PRIMITIVE_POINT: case PRIMITIVE_MOTION_POINT: { if ((type & PRIMITIVE_MOTION) && kernel_data.bvh.use_bvh_steps) { - const float2 prim_time = kernel_tex_fetch(__prim_time, prim_addr); + const float2 prim_time = kernel_data_fetch(prim_time, prim_addr); if (ray->time < prim_time.x || ray->time > prim_time.y) { hit = false; break; } } - const int point_type = kernel_tex_fetch(__prim_type, prim_addr); + const int point_type = kernel_data_fetch(prim_type, prim_addr); hit = point_intersect( kg, &isect, P, dir, t_max_current, prim_object, prim, ray->time, point_type); break; @@ -291,7 +291,7 @@ ccl_device_inline } else { /* instance push */ - object = kernel_tex_fetch(__prim_object, -prim_addr - 1); + object = kernel_data_fetch(prim_object, -prim_addr - 1); #if BVH_FEATURE(BVH_MOTION) t_world_to_instance = bvh_instance_motion_push( @@ -307,7 +307,7 @@ ccl_device_inline kernel_assert(stack_ptr < BVH_STACK_SIZE); traversal_stack[stack_ptr] = ENTRYPOINT_SENTINEL; - node_addr = kernel_tex_fetch(__object_node, object); + node_addr = kernel_data_fetch(object_node, object); } } } while (node_addr != ENTRYPOINT_SENTINEL); diff --git a/intern/cycles/kernel/bvh/traversal.h b/intern/cycles/kernel/bvh/traversal.h index 1181d4bfdee..784fbf4fd11 100644 --- a/intern/cycles/kernel/bvh/traversal.h +++ b/intern/cycles/kernel/bvh/traversal.h @@ -62,7 +62,7 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg, while (node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { int node_addr_child1, traverse_mask; float dist[2]; - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); { traverse_mask = NODE_INTERSECT(kg, @@ -108,7 +108,7 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg, /* if node is leaf, fetch triangle list */ if (node_addr < 0) { - float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1)); + float4 leaf = kernel_data_fetch(bvh_leaf_nodes, (-node_addr - 1)); int prim_addr = __float_as_int(leaf.x); if (prim_addr >= 0) { @@ -121,12 +121,12 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg, /* primitive intersection */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert(kernel_tex_fetch(__prim_type, prim_addr) == type); + kernel_assert(kernel_data_fetch(prim_type, prim_addr) == type); const int prim_object = (object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, prim_addr) : + kernel_data_fetch(prim_object, prim_addr) : object; - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self_shadow(ray->self, prim_object, prim)) { continue; } @@ -166,13 +166,13 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg, case PRIMITIVE_CURVE_RIBBON: case PRIMITIVE_MOTION_CURVE_RIBBON: { if ((type & PRIMITIVE_MOTION) && kernel_data.bvh.use_bvh_steps) { - const float2 prim_time = kernel_tex_fetch(__prim_time, prim_addr); + const float2 prim_time = kernel_data_fetch(prim_time, prim_addr); if (ray->time < prim_time.x || ray->time > prim_time.y) { break; } } - const int curve_type = kernel_tex_fetch(__prim_type, prim_addr); + const int curve_type = kernel_data_fetch(prim_type, prim_addr); const bool hit = curve_intersect( kg, isect, P, dir, isect->t, prim_object, prim, ray->time, curve_type); if (hit) { @@ -187,13 +187,13 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg, case PRIMITIVE_POINT: case PRIMITIVE_MOTION_POINT: { if ((type & PRIMITIVE_MOTION) && kernel_data.bvh.use_bvh_steps) { - const float2 prim_time = kernel_tex_fetch(__prim_time, prim_addr); + const float2 prim_time = kernel_data_fetch(prim_time, prim_addr); if (ray->time < prim_time.x || ray->time > prim_time.y) { break; } } - const int point_type = kernel_tex_fetch(__prim_type, prim_addr); + const int point_type = kernel_data_fetch(prim_type, prim_addr); const bool hit = point_intersect( kg, isect, P, dir, isect->t, prim_object, prim, ray->time, point_type); if (hit) { @@ -209,7 +209,7 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg, } else { /* instance push */ - object = kernel_tex_fetch(__prim_object, -prim_addr - 1); + object = kernel_data_fetch(prim_object, -prim_addr - 1); #if BVH_FEATURE(BVH_MOTION) isect->t *= bvh_instance_motion_push(kg, object, ray, &P, &dir, &idir, &ob_itfm); @@ -221,7 +221,7 @@ ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals kg, kernel_assert(stack_ptr < BVH_STACK_SIZE); traversal_stack[stack_ptr] = ENTRYPOINT_SENTINEL; - node_addr = kernel_tex_fetch(__object_node, object); + node_addr = kernel_data_fetch(object_node, object); } } } while (node_addr != ENTRYPOINT_SENTINEL); diff --git a/intern/cycles/kernel/bvh/util.h b/intern/cycles/kernel/bvh/util.h index 71045157372..572e023db25 100644 --- a/intern/cycles/kernel/bvh/util.h +++ b/intern/cycles/kernel/bvh/util.h @@ -53,20 +53,20 @@ ccl_device_forceinline int intersection_get_shader_flags(KernelGlobals kg, int shader = 0; if (type & PRIMITIVE_TRIANGLE) { - shader = kernel_tex_fetch(__tri_shader, prim); + shader = kernel_data_fetch(tri_shader, prim); } #ifdef __POINTCLOUD__ else if (type & PRIMITIVE_POINT) { - shader = kernel_tex_fetch(__points_shader, prim); + shader = kernel_data_fetch(points_shader, prim); } #endif #ifdef __HAIR__ else if (type & PRIMITIVE_CURVE) { - shader = kernel_tex_fetch(__curves, prim).shader_id; + shader = kernel_data_fetch(curves, prim).shader_id; } #endif - return kernel_tex_fetch(__shaders, (shader & SHADER_MASK)).flags; + return kernel_data_fetch(shaders, (shader & SHADER_MASK)).flags; } ccl_device_forceinline int intersection_get_shader_from_isect_prim(KernelGlobals kg, @@ -76,16 +76,16 @@ ccl_device_forceinline int intersection_get_shader_from_isect_prim(KernelGlobals int shader = 0; if (isect_type & PRIMITIVE_TRIANGLE) { - shader = kernel_tex_fetch(__tri_shader, prim); + shader = kernel_data_fetch(tri_shader, prim); } #ifdef __POINTCLOUD__ else if (isect_type & PRIMITIVE_POINT) { - shader = kernel_tex_fetch(__points_shader, prim); + shader = kernel_data_fetch(points_shader, prim); } #endif #ifdef __HAIR__ else if (isect_type & PRIMITIVE_CURVE) { - shader = kernel_tex_fetch(__curves, prim).shader_id; + shader = kernel_data_fetch(curves, prim).shader_id; } #endif @@ -101,7 +101,7 @@ ccl_device_forceinline int intersection_get_shader( ccl_device_forceinline int intersection_get_object_flags( KernelGlobals kg, ccl_private const Intersection *ccl_restrict isect) { - return kernel_tex_fetch(__object_flag, isect->object); + return kernel_data_fetch(object_flag, isect->object); } /* TODO: find a better (faster) solution for this. Maybe store offset per object for @@ -110,27 +110,27 @@ ccl_device_inline int intersection_find_attribute(KernelGlobals kg, const int object, const uint id) { - uint attr_offset = kernel_tex_fetch(__objects, object).attribute_map_offset; - uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + uint attr_offset = kernel_data_fetch(objects, object).attribute_map_offset; + AttributeMap attr_map = kernel_data_fetch(attributes_map, attr_offset); - while (attr_map.x != id) { - if (UNLIKELY(attr_map.x == ATTR_STD_NONE)) { - if (UNLIKELY(attr_map.y == 0)) { + while (attr_map.id != id) { + if (UNLIKELY(attr_map.id == ATTR_STD_NONE)) { + if (UNLIKELY(attr_map.element == 0)) { return (int)ATTR_STD_NOT_FOUND; } else { /* Chain jump to a different part of the table. */ - attr_offset = attr_map.z; + attr_offset = attr_map.offset; } } else { attr_offset += ATTR_PRIM_TYPES; } - attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + attr_map = kernel_data_fetch(attributes_map, attr_offset); } /* return result */ - return (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z; + return (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.offset; } /* Transparent Shadows */ @@ -151,12 +151,12 @@ ccl_device_inline float intersection_curve_shadow_transparency(KernelGlobals kg, } /* Interpolate transparency between curve keys. */ - const KernelCurve kcurve = kernel_tex_fetch(__curves, prim); + const KernelCurve kcurve = kernel_data_fetch(curves, prim); const int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(kcurve.type); const int k1 = k0 + 1; - const float f0 = kernel_tex_fetch(__attributes_float, offset + k0); - const float f1 = kernel_tex_fetch(__attributes_float, offset + k1); + const float f0 = kernel_data_fetch(attributes_float, offset + k0); + const float f1 = kernel_data_fetch(attributes_float, offset + k1); return (1.0f - u) * f0 + u * f1; } diff --git a/intern/cycles/kernel/bvh/volume.h b/intern/cycles/kernel/bvh/volume.h index d711b3abbf4..9715712a8f2 100644 --- a/intern/cycles/kernel/bvh/volume.h +++ b/intern/cycles/kernel/bvh/volume.h @@ -65,7 +65,7 @@ ccl_device_inline while (node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { int node_addr_child1, traverse_mask; float dist[2]; - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); traverse_mask = NODE_INTERSECT(kg, P, @@ -109,7 +109,7 @@ ccl_device_inline /* if node is leaf, fetch triangle list */ if (node_addr < 0) { - float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1)); + float4 leaf = kernel_data_fetch(bvh_leaf_nodes, (-node_addr - 1)); int prim_addr = __float_as_int(leaf.x); if (prim_addr >= 0) { @@ -125,17 +125,17 @@ ccl_device_inline case PRIMITIVE_TRIANGLE: { /* intersect ray against primitive */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert(kernel_tex_fetch(__prim_type, prim_addr) == type); + kernel_assert(kernel_data_fetch(prim_type, prim_addr) == type); /* only primitives from volume object */ const int prim_object = (object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, prim_addr) : + kernel_data_fetch(prim_object, prim_addr) : object; - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self(ray->self, prim_object, prim)) { continue; } - int object_flag = kernel_tex_fetch(__object_flag, prim_object); + int object_flag = kernel_data_fetch(object_flag, prim_object); if ((object_flag & SD_OBJECT_HAS_VOLUME) == 0) { continue; } @@ -148,16 +148,16 @@ ccl_device_inline case PRIMITIVE_MOTION_TRIANGLE: { /* intersect ray against primitive */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert(kernel_tex_fetch(__prim_type, prim_addr) == type); + kernel_assert(kernel_data_fetch(prim_type, prim_addr) == type); /* only primitives from volume object */ const int prim_object = (object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, prim_addr) : + kernel_data_fetch(prim_object, prim_addr) : object; - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self(ray->self, prim_object, prim)) { continue; } - int object_flag = kernel_tex_fetch(__object_flag, prim_object); + int object_flag = kernel_data_fetch(object_flag, prim_object); if ((object_flag & SD_OBJECT_HAS_VOLUME) == 0) { continue; } @@ -182,8 +182,8 @@ ccl_device_inline } else { /* instance push */ - object = kernel_tex_fetch(__prim_object, -prim_addr - 1); - int object_flag = kernel_tex_fetch(__object_flag, object); + object = kernel_data_fetch(prim_object, -prim_addr - 1); + int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_HAS_VOLUME) { #if BVH_FEATURE(BVH_MOTION) isect->t *= bvh_instance_motion_push(kg, object, ray, &P, &dir, &idir, &ob_itfm); @@ -195,7 +195,7 @@ ccl_device_inline kernel_assert(stack_ptr < BVH_STACK_SIZE); traversal_stack[stack_ptr] = ENTRYPOINT_SENTINEL; - node_addr = kernel_tex_fetch(__object_node, object); + node_addr = kernel_data_fetch(object_node, object); } else { /* pop */ diff --git a/intern/cycles/kernel/bvh/volume_all.h b/intern/cycles/kernel/bvh/volume_all.h index a969bae14a1..d06ea8fe557 100644 --- a/intern/cycles/kernel/bvh/volume_all.h +++ b/intern/cycles/kernel/bvh/volume_all.h @@ -67,7 +67,7 @@ ccl_device_inline while (node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { int node_addr_child1, traverse_mask; float dist[2]; - float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr + 0); + float4 cnodes = kernel_data_fetch(bvh_nodes, node_addr + 0); traverse_mask = NODE_INTERSECT(kg, P, @@ -111,7 +111,7 @@ ccl_device_inline /* if node is leaf, fetch triangle list */ if (node_addr < 0) { - float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-node_addr - 1)); + float4 leaf = kernel_data_fetch(bvh_leaf_nodes, (-node_addr - 1)); int prim_addr = __float_as_int(leaf.x); if (prim_addr >= 0) { @@ -128,16 +128,16 @@ ccl_device_inline case PRIMITIVE_TRIANGLE: { /* intersect ray against primitive */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert(kernel_tex_fetch(__prim_type, prim_addr) == type); + kernel_assert(kernel_data_fetch(prim_type, prim_addr) == type); /* only primitives from volume object */ const int prim_object = (object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, prim_addr) : + kernel_data_fetch(prim_object, prim_addr) : object; - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self(ray->self, prim_object, prim)) { continue; } - int object_flag = kernel_tex_fetch(__object_flag, prim_object); + int object_flag = kernel_data_fetch(object_flag, prim_object); if ((object_flag & SD_OBJECT_HAS_VOLUME) == 0) { continue; } @@ -172,16 +172,16 @@ ccl_device_inline case PRIMITIVE_MOTION_TRIANGLE: { /* intersect ray against primitive */ for (; prim_addr < prim_addr2; prim_addr++) { - kernel_assert(kernel_tex_fetch(__prim_type, prim_addr) == type); + kernel_assert(kernel_data_fetch(prim_type, prim_addr) == type); /* only primitives from volume object */ const int prim_object = (object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, prim_addr) : + kernel_data_fetch(prim_object, prim_addr) : object; - const int prim = kernel_tex_fetch(__prim_index, prim_addr); + const int prim = kernel_data_fetch(prim_index, prim_addr); if (intersection_skip_self(ray->self, prim_object, prim)) { continue; } - int object_flag = kernel_tex_fetch(__object_flag, prim_object); + int object_flag = kernel_data_fetch(object_flag, prim_object); if ((object_flag & SD_OBJECT_HAS_VOLUME) == 0) { continue; } @@ -228,8 +228,8 @@ ccl_device_inline } else { /* instance push */ - object = kernel_tex_fetch(__prim_object, -prim_addr - 1); - int object_flag = kernel_tex_fetch(__object_flag, object); + object = kernel_data_fetch(prim_object, -prim_addr - 1); + int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_HAS_VOLUME) { #if BVH_FEATURE(BVH_MOTION) isect_t *= bvh_instance_motion_push(kg, object, ray, &P, &dir, &idir, &ob_itfm); @@ -244,7 +244,7 @@ ccl_device_inline kernel_assert(stack_ptr < BVH_STACK_SIZE); traversal_stack[stack_ptr] = ENTRYPOINT_SENTINEL; - node_addr = kernel_tex_fetch(__object_node, object); + node_addr = kernel_data_fetch(object_node, object); } else { /* pop */ diff --git a/intern/cycles/kernel/camera/camera.h b/intern/cycles/kernel/camera/camera.h index aad68e527ac..25960a94ddb 100644 --- a/intern/cycles/kernel/camera/camera.h +++ b/intern/cycles/kernel/camera/camera.h @@ -90,7 +90,7 @@ ccl_device void camera_sample_perspective(KernelGlobals kg, #ifdef __CAMERA_MOTION__ if (kernel_data.cam.num_motion_steps) { transform_motion_array_interpolate(&cameratoworld, - kernel_tex_array(__camera_motion), + kernel_data_array(camera_motion), kernel_data.cam.num_motion_steps, ray->time); } @@ -210,7 +210,7 @@ ccl_device void camera_sample_orthographic(KernelGlobals kg, #ifdef __CAMERA_MOTION__ if (kernel_data.cam.num_motion_steps) { transform_motion_array_interpolate(&cameratoworld, - kernel_tex_array(__camera_motion), + kernel_data_array(camera_motion), kernel_data.cam.num_motion_steps, ray->time); } @@ -421,7 +421,7 @@ ccl_device_inline void camera_sample(KernelGlobals kg, } else { #ifdef __CAMERA_MOTION__ - ccl_global const DecomposedTransform *cam_motion = kernel_tex_array(__camera_motion); + ccl_global const DecomposedTransform *cam_motion = kernel_data_array(camera_motion); camera_sample_panorama(&kernel_data.cam, cam_motion, raster_x, raster_y, lens_u, lens_v, ray); #else camera_sample_panorama(&kernel_data.cam, raster_x, raster_y, lens_u, lens_v, ray); diff --git a/intern/cycles/kernel/closure/bsdf.h b/intern/cycles/kernel/closure/bsdf.h index 011155cdf5f..6f3c2092c64 100644 --- a/intern/cycles/kernel/closure/bsdf.h +++ b/intern/cycles/kernel/closure/bsdf.h @@ -434,7 +434,7 @@ ccl_device_inline int bsdf_sample(KernelGlobals kg, else { /* Shadow terminator offset. */ const float frequency_multiplier = - kernel_tex_fetch(__objects, sd->object).shadow_terminator_shading_offset; + kernel_data_fetch(objects, sd->object).shadow_terminator_shading_offset; if (frequency_multiplier > 1.0f) { *eval *= shift_cos_in(dot(*omega_in, sc->N), frequency_multiplier); } @@ -556,7 +556,7 @@ ccl_device_inline } /* Shadow terminator offset. */ const float frequency_multiplier = - kernel_tex_fetch(__objects, sd->object).shadow_terminator_shading_offset; + kernel_data_fetch(objects, sd->object).shadow_terminator_shading_offset; if (frequency_multiplier > 1.0f) { eval *= shift_cos_in(dot(omega_in, sc->N), frequency_multiplier); } diff --git a/intern/cycles/kernel/data_arrays.h b/intern/cycles/kernel/data_arrays.h new file mode 100644 index 00000000000..7205f728088 --- /dev/null +++ b/intern/cycles/kernel/data_arrays.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2011-2022 Blender Foundation */ + +#ifndef KERNEL_DATA_ARRAY +# define KERNEL_DATA_ARRAY(type, name) +#endif + +/* BVH2, not used for OptiX or Embree. */ +KERNEL_DATA_ARRAY(float4, bvh_nodes) +KERNEL_DATA_ARRAY(float4, bvh_leaf_nodes) +KERNEL_DATA_ARRAY(uint, prim_type) +KERNEL_DATA_ARRAY(uint, prim_visibility) +KERNEL_DATA_ARRAY(uint, prim_index) +KERNEL_DATA_ARRAY(uint, prim_object) +KERNEL_DATA_ARRAY(uint, object_node) +KERNEL_DATA_ARRAY(float2, prim_time) + +/* objects */ +KERNEL_DATA_ARRAY(KernelObject, objects) +KERNEL_DATA_ARRAY(Transform, object_motion_pass) +KERNEL_DATA_ARRAY(DecomposedTransform, object_motion) +KERNEL_DATA_ARRAY(uint, object_flag) +KERNEL_DATA_ARRAY(float, object_volume_step) +KERNEL_DATA_ARRAY(uint, object_prim_offset) + +/* cameras */ +KERNEL_DATA_ARRAY(DecomposedTransform, camera_motion) + +/* triangles */ +KERNEL_DATA_ARRAY(uint, tri_shader) +KERNEL_DATA_ARRAY(packed_float3, tri_vnormal) +KERNEL_DATA_ARRAY(uint4, tri_vindex) +KERNEL_DATA_ARRAY(uint, tri_patch) +KERNEL_DATA_ARRAY(float2, tri_patch_uv) +KERNEL_DATA_ARRAY(packed_float3, tri_verts) + +/* curves */ +KERNEL_DATA_ARRAY(KernelCurve, curves) +KERNEL_DATA_ARRAY(float4, curve_keys) +KERNEL_DATA_ARRAY(KernelCurveSegment, curve_segments) + +/* patches */ +KERNEL_DATA_ARRAY(uint, patches) + +/* pointclouds */ +KERNEL_DATA_ARRAY(float4, points) +KERNEL_DATA_ARRAY(uint, points_shader) + +/* attributes */ +KERNEL_DATA_ARRAY(AttributeMap, attributes_map) +KERNEL_DATA_ARRAY(float, attributes_float) +KERNEL_DATA_ARRAY(float2, attributes_float2) +KERNEL_DATA_ARRAY(packed_float3, attributes_float3) +KERNEL_DATA_ARRAY(float4, attributes_float4) +KERNEL_DATA_ARRAY(uchar4, attributes_uchar4) + +/* lights */ +KERNEL_DATA_ARRAY(KernelLightDistribution, light_distribution) +KERNEL_DATA_ARRAY(KernelLight, lights) +KERNEL_DATA_ARRAY(float2, light_background_marginal_cdf) +KERNEL_DATA_ARRAY(float2, light_background_conditional_cdf) + +/* particles */ +KERNEL_DATA_ARRAY(KernelParticle, particles) + +/* shaders */ +KERNEL_DATA_ARRAY(uint4, svm_nodes) +KERNEL_DATA_ARRAY(KernelShader, shaders) + +/* lookup tables */ +KERNEL_DATA_ARRAY(float, lookup_table) + +/* sobol */ +KERNEL_DATA_ARRAY(float, sample_pattern_lut) + +/* image textures */ +KERNEL_DATA_ARRAY(TextureInfo, texture_info) + +/* ies lights */ +KERNEL_DATA_ARRAY(float, ies) + +#undef KERNEL_DATA_ARRAY diff --git a/intern/cycles/kernel/device/cpu/compat.h b/intern/cycles/kernel/device/cpu/compat.h index e1c20169582..3bfc37e98ee 100644 --- a/intern/cycles/kernel/device/cpu/compat.h +++ b/intern/cycles/kernel/device/cpu/compat.h @@ -35,20 +35,6 @@ CCL_NAMESPACE_BEGIN #define kernel_assert(cond) assert(cond) -/* Texture types to be compatible with CUDA textures. These are really just - * simple arrays and after inlining fetch hopefully revert to being a simple - * pointer lookup. */ -template<typename T> struct texture { - ccl_always_inline const T &fetch(int index) const - { - kernel_assert(index >= 0 && index < width); - return data[index]; - } - - T *data; - int width; -}; - /* Macros to handle different memory storage on different devices */ #ifdef __KERNEL_SSE2__ diff --git a/intern/cycles/kernel/device/cpu/globals.h b/intern/cycles/kernel/device/cpu/globals.h index 7e080d428ea..309afae412e 100644 --- a/intern/cycles/kernel/device/cpu/globals.h +++ b/intern/cycles/kernel/device/cpu/globals.h @@ -12,7 +12,7 @@ CCL_NAMESPACE_BEGIN /* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in - * the kernel, to access constant data. These are all stored as "textures", but + * the kernel, to access constant data. These are all stored as flat arrays. * these are really just standard arrays. We can't use actually globals because * multiple renders may be running inside the same process. */ @@ -22,11 +22,23 @@ struct OSLThreadData; struct OSLShadingSystem; #endif +/* Array for kernel data, with size to be able to assert on invalid data access. */ +template<typename T> struct kernel_array { + ccl_always_inline const T &fetch(int index) const + { + kernel_assert(index >= 0 && index < width); + return data[index]; + } + + T *data; + int width; +}; + typedef struct KernelGlobalsCPU { -#define KERNEL_TEX(type, name) texture<type> name; -#include "kernel/textures.h" +#define KERNEL_DATA_ARRAY(type, name) kernel_array<type> name; +#include "kernel/data_arrays.h" - KernelData __data; + KernelData data; #ifdef __OSL__ /* On the CPU, we also have the OSL globals here. Most data structures are shared @@ -44,8 +56,8 @@ typedef struct KernelGlobalsCPU { typedef const KernelGlobalsCPU *ccl_restrict KernelGlobals; /* Abstraction macros */ -#define kernel_tex_fetch(tex, index) (kg->tex.fetch(index)) -#define kernel_tex_array(tex) (kg->tex.data) -#define kernel_data (kg->__data) +#define kernel_data_fetch(name, index) (kg->name.fetch(index)) +#define kernel_data_array(name) (kg->name.data) +#define kernel_data (kg->data) CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/device/cpu/image.h b/intern/cycles/kernel/device/cpu/image.h index 7809ec5f4a7..320e6309128 100644 --- a/intern/cycles/kernel/device/cpu/image.h +++ b/intern/cycles/kernel/device/cpu/image.h @@ -733,7 +733,7 @@ template<typename TexT, typename OutT = float4> struct NanoVDBInterpolator { ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, int id, float x, float y) { - const TextureInfo &info = kernel_tex_fetch(__texture_info, id); + const TextureInfo &info = kernel_data_fetch(texture_info, id); if (UNLIKELY(!info.data)) { return zero_float4(); @@ -776,7 +776,7 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals kg, float3 P, InterpolationType interp) { - const TextureInfo &info = kernel_tex_fetch(__texture_info, id); + const TextureInfo &info = kernel_data_fetch(texture_info, id); if (UNLIKELY(!info.data)) { return zero_float4(); diff --git a/intern/cycles/kernel/device/cpu/kernel.cpp b/intern/cycles/kernel/device/cpu/kernel.cpp index b12e3089378..01087c96dd6 100644 --- a/intern/cycles/kernel/device/cpu/kernel.cpp +++ b/intern/cycles/kernel/device/cpu/kernel.cpp @@ -53,8 +53,8 @@ CCL_NAMESPACE_BEGIN void kernel_const_copy(KernelGlobalsCPU *kg, const char *name, void *host, size_t) { - if (strcmp(name, "__data") == 0) { - kg->__data = *(KernelData *)host; + if (strcmp(name, "data") == 0) { + kg->data = *(KernelData *)host; } else { assert(0); @@ -66,13 +66,13 @@ void kernel_global_memory_copy(KernelGlobalsCPU *kg, const char *name, void *mem if (0) { } -#define KERNEL_TEX(type, tname) \ +#define KERNEL_DATA_ARRAY(type, tname) \ else if (strcmp(name, #tname) == 0) \ { \ kg->tname.data = (type *)mem; \ kg->tname.width = size; \ } -#include "kernel/textures.h" +#include "kernel/data_arrays.h" else { assert(0); } diff --git a/intern/cycles/kernel/device/cuda/globals.h b/intern/cycles/kernel/device/cuda/globals.h index e77fcd2b424..f5f7bcf58ee 100644 --- a/intern/cycles/kernel/device/cuda/globals.h +++ b/intern/cycles/kernel/device/cuda/globals.h @@ -20,18 +20,24 @@ struct KernelGlobalsGPU { }; typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; -/* Global scene data and textures */ -__constant__ KernelData __data; -#define KERNEL_TEX(type, name) const __constant__ __device__ type *name; -#include "kernel/textures.h" +struct KernelParamsCUDA { + /* Global scene data and textures */ + KernelData data; +#define KERNEL_DATA_ARRAY(type, name) const type *name; +#include "kernel/data_arrays.h" + + /* Integrator state */ + IntegratorStateGPU integrator_state; +}; -/* Integrator state */ -__constant__ IntegratorStateGPU __integrator_state; +#ifdef __KERNEL_GPU__ +__constant__ KernelParamsCUDA kernel_params; +#endif /* Abstraction macros */ -#define kernel_data __data -#define kernel_tex_fetch(t, index) t[(index)] -#define kernel_tex_array(t) (t) -#define kernel_integrator_state __integrator_state +#define kernel_data kernel_params.data +#define kernel_data_fetch(name, index) kernel_params.name[(index)] +#define kernel_data_array(name) (kernel_params.name) +#define kernel_integrator_state kernel_params.integrator_state CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/device/gpu/image.h b/intern/cycles/kernel/device/gpu/image.h index 29d851ae478..a8c72645569 100644 --- a/intern/cycles/kernel/device/gpu/image.h +++ b/intern/cycles/kernel/device/gpu/image.h @@ -181,7 +181,7 @@ ccl_device_noinline typename nanovdb::NanoGrid<T>::ValueType kernel_tex_image_in ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, int id, float x, float y) { - ccl_global const TextureInfo &info = kernel_tex_fetch(__texture_info, id); + ccl_global const TextureInfo &info = kernel_data_fetch(texture_info, id); /* float4, byte4, ushort4 and half4 */ const int texture_type = info.data_type; @@ -216,7 +216,7 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals kg, float3 P, InterpolationType interp) { - ccl_global const TextureInfo &info = kernel_tex_fetch(__texture_info, id); + ccl_global const TextureInfo &info = kernel_data_fetch(texture_info, id); if (info.use_transform_3d) { P = transform_point(&info.transform_3d, P); diff --git a/intern/cycles/kernel/device/hip/globals.h b/intern/cycles/kernel/device/hip/globals.h index 50f117038a2..3a334b21a9e 100644 --- a/intern/cycles/kernel/device/hip/globals.h +++ b/intern/cycles/kernel/device/hip/globals.h @@ -20,18 +20,24 @@ struct KernelGlobalsGPU { }; typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; -/* Global scene data and textures */ -__constant__ KernelData __data; -#define KERNEL_TEX(type, name) __attribute__((used)) const __constant__ __device__ type *name; -#include "kernel/textures.h" +struct KernelParamsHIP { + /* Global scene data and textures */ + KernelData data; +#define KERNEL_DATA_ARRAY(type, name) const type *name; +#include "kernel/data_arrays.h" + + /* Integrator state */ + IntegratorStateGPU integrator_state; +}; -/* Integrator state */ -__constant__ IntegratorStateGPU __integrator_state; +#ifdef __KERNEL_GPU__ +__constant__ KernelParamsHIP kernel_params; +#endif /* Abstraction macros */ -#define kernel_data __data -#define kernel_tex_fetch(t, index) t[(index)] -#define kernel_tex_array(t) (t) -#define kernel_integrator_state __integrator_state +#define kernel_data kernel_params.data +#define kernel_data_fetch(name, index) kernel_params.name[(index)] +#define kernel_data_array(name) (kernel_params.name) +#define kernel_integrator_state kernel_params.integrator_state CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/device/metal/context_end.h b/intern/cycles/kernel/device/metal/context_end.h index b4c8661c401..44ac0478266 100644 --- a/intern/cycles/kernel/device/metal/context_end.h +++ b/intern/cycles/kernel/device/metal/context_end.h @@ -7,4 +7,4 @@ /* NOTE: These macros will need maintaining as entry-points change. */ #undef kernel_integrator_state -#define kernel_integrator_state context.launch_params_metal.__integrator_state +#define kernel_integrator_state context.launch_params_metal.integrator_state diff --git a/intern/cycles/kernel/device/metal/globals.h b/intern/cycles/kernel/device/metal/globals.h index 1c3e775dbae..a336c096440 100644 --- a/intern/cycles/kernel/device/metal/globals.h +++ b/intern/cycles/kernel/device/metal/globals.h @@ -12,11 +12,11 @@ CCL_NAMESPACE_BEGIN typedef struct KernelParamsMetal { -#define KERNEL_TEX(type, name) ccl_global const type *name; -#include "kernel/textures.h" -#undef KERNEL_TEX +#define KERNEL_DATA_ARRAY(type, name) ccl_global const type *name; +#include "kernel/data_arrays.h" +#undef KERNEL_DATA_ARRAY - const IntegratorStateGPU __integrator_state; + const IntegratorStateGPU integrator_state; const KernelData data; } KernelParamsMetal; @@ -27,12 +27,10 @@ typedef struct KernelGlobalsGPU { typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; +/* Abstraction macros */ #define kernel_data launch_params_metal.data -#define kernel_integrator_state launch_params_metal.__integrator_state - -/* data lookup defines */ - -#define kernel_tex_fetch(tex, index) launch_params_metal.tex[index] -#define kernel_tex_array(tex) launch_params_metal.tex +#define kernel_data_fetch(name, index) launch_params_metal.name[index] +#define kernel_data_array(name) launch_params_metal.name +#define kernel_integrator_state launch_params_metal.integrator_state CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/device/metal/kernel.metal b/intern/cycles/kernel/device/metal/kernel.metal index a7252570e64..3c31dc3354c 100644 --- a/intern/cycles/kernel/device/metal/kernel.metal +++ b/intern/cycles/kernel/device/metal/kernel.metal @@ -59,7 +59,7 @@ TReturn metalrt_local_hit(constant KernelParamsMetal &launch_params_metal, TReturn result; #ifdef __BVH_LOCAL__ - uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); + uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); if ((object != payload.local_object) || intersection_skip_self_local(payload.self, prim)) { /* Only intersect with matching object and skip self-intersecton. */ @@ -113,16 +113,16 @@ TReturn metalrt_local_hit(constant KernelParamsMetal &launch_params_metal, isect->t = ray_tmax; isect->prim = prim; isect->object = object; - isect->type = kernel_tex_fetch(__objects, object).primitive_type; + isect->type = kernel_data_fetch(objects, object).primitive_type; isect->u = 1.0f - barycentrics.y - barycentrics.x; isect->v = barycentrics.x; /* Record geometric normal */ - const uint tri_vindex = kernel_tex_fetch(__tri_vindex, isect->prim).w; - const float3 tri_a = float3(kernel_tex_fetch(__tri_verts, tri_vindex + 0)); - const float3 tri_b = float3(kernel_tex_fetch(__tri_verts, tri_vindex + 1)); - const float3 tri_c = float3(kernel_tex_fetch(__tri_verts, tri_vindex + 2)); + const uint tri_vindex = kernel_data_fetch(tri_vindex, isect->prim).w; + const float3 tri_a = float3(kernel_data_fetch(tri_verts, tri_vindex + 0)); + const float3 tri_b = float3(kernel_data_fetch(tri_verts, tri_vindex + 1)); + const float3 tri_c = float3(kernel_data_fetch(tri_verts, tri_vindex + 2)); payload.local_isect.Ng[hit] = normalize(cross(tri_b - tri_a, tri_c - tri_a)); /* Continue tracing (without this the trace call would return after the first hit) */ @@ -168,7 +168,7 @@ bool metalrt_shadow_all_hit(constant KernelParamsMetal &launch_params_metal, #ifdef __SHADOW_RECORD_ALL__ # ifdef __VISIBILITY_FLAG__ const uint visibility = payload.visibility; - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { /* continue search */ return true; } @@ -184,14 +184,14 @@ bool metalrt_shadow_all_hit(constant KernelParamsMetal &launch_params_metal, if (intersection_type == METALRT_HIT_TRIANGLE) { u = 1.0f - barycentrics.y - barycentrics.x; v = barycentrics.x; - type = kernel_tex_fetch(__objects, object).primitive_type; + type = kernel_data_fetch(objects, object).primitive_type; } # ifdef __HAIR__ else { u = barycentrics.x; v = barycentrics.y; - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, prim); type = segment.type; prim = segment.prim; @@ -294,7 +294,7 @@ __anyhit__cycles_metalrt_shadow_all_hit_tri(constant KernelParamsMetal &launch_p float2 barycentrics [[barycentric_coord]], float ray_tmax [[distance]]) { - uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); + uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); TriangleIntersectionResult result; result.continue_search = metalrt_shadow_all_hit<METALRT_HIT_TRIANGLE>( @@ -337,7 +337,7 @@ inline TReturnType metalrt_visibility_test(constant KernelParamsMetal &launch_pa uint visibility = payload.visibility; # ifdef __VISIBILITY_FLAG__ - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { result.accept = false; result.continue_search = true; return result; @@ -377,12 +377,12 @@ __anyhit__cycles_metalrt_visibility_test_tri(constant KernelParamsMetal &launch_ unsigned int object [[user_instance_id]], unsigned int primitive_id [[primitive_id]]) { - uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); + uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); TriangleIntersectionResult result = metalrt_visibility_test<TriangleIntersectionResult, METALRT_HIT_TRIANGLE>( launch_params_metal, payload, object, prim, 0.0f); if (result.accept) { payload.prim = prim; - payload.type = kernel_tex_fetch(__objects, object).primitive_type; + payload.type = kernel_data_fetch(objects, object).primitive_type; } return result; } @@ -414,7 +414,7 @@ void metalrt_intersection_curve(constant KernelParamsMetal &launch_params_metal, { # ifdef __VISIBILITY_FLAG__ const uint visibility = payload.visibility; - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { return; } # endif @@ -495,8 +495,8 @@ __intersection__curve_ribbon(constant KernelParamsMetal &launch_params_metal [[b const float3 ray_direction [[direction]], const float ray_tmax [[max_distance]]) { - uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim); + uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, prim); BoundingBoxIntersectionResult result; result.accept = false; @@ -526,8 +526,8 @@ __intersection__curve_ribbon_shadow(constant KernelParamsMetal &launch_params_me const float3 ray_direction [[direction]], const float ray_tmax [[max_distance]]) { - uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim); + uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, prim); BoundingBoxIntersectionResult result; result.accept = false; @@ -557,8 +557,8 @@ __intersection__curve_all(constant KernelParamsMetal &launch_params_metal [[buff const float3 ray_direction [[direction]], const float ray_tmax [[max_distance]]) { - uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim); + uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, prim); BoundingBoxIntersectionResult result; result.accept = false; @@ -585,8 +585,8 @@ __intersection__curve_all_shadow(constant KernelParamsMetal &launch_params_metal const float3 ray_direction [[direction]], const float ray_tmax [[max_distance]]) { - uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim); + uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, prim); BoundingBoxIntersectionResult result; result.accept = false; @@ -620,7 +620,7 @@ void metalrt_intersection_point(constant KernelParamsMetal &launch_params_metal, { # ifdef __VISIBILITY_FLAG__ const uint visibility = payload.visibility; - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { return; } # endif @@ -701,8 +701,8 @@ __intersection__point(constant KernelParamsMetal &launch_params_metal [[buffer(1 const float3 ray_direction [[direction]], const float ray_tmax [[max_distance]]) { - const uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); - const int type = kernel_tex_fetch(__objects, object).primitive_type; + const uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); + const int type = kernel_data_fetch(objects, object).primitive_type; BoundingBoxIntersectionResult result; result.accept = false; @@ -730,8 +730,8 @@ __intersection__point_shadow(constant KernelParamsMetal &launch_params_metal [[b const float3 ray_direction [[direction]], const float ray_tmax [[max_distance]]) { - const uint prim = primitive_id + kernel_tex_fetch(__object_prim_offset, object); - const int type = kernel_tex_fetch(__objects, object).primitive_type; + const uint prim = primitive_id + kernel_data_fetch(object_prim_offset, object); + const int type = kernel_data_fetch(objects, object).primitive_type; BoundingBoxIntersectionResult result; result.accept = false; diff --git a/intern/cycles/kernel/device/optix/globals.h b/intern/cycles/kernel/device/optix/globals.h index bb752c531f0..7af2e421378 100644 --- a/intern/cycles/kernel/device/optix/globals.h +++ b/intern/cycles/kernel/device/optix/globals.h @@ -28,21 +28,21 @@ struct KernelParamsOptiX { /* Global scene data and textures */ KernelData data; -#define KERNEL_TEX(type, name) const type *name; -#include "kernel/textures.h" +#define KERNEL_DATA_ARRAY(type, name) const type *name; +#include "kernel/data_arrays.h" /* Integrator state */ - IntegratorStateGPU __integrator_state; + IntegratorStateGPU integrator_state; }; #ifdef __NVCC__ -extern "C" static __constant__ KernelParamsOptiX __params; +extern "C" static __constant__ KernelParamsOptiX kernel_params; #endif /* Abstraction macros */ -#define kernel_data __params.data -#define kernel_tex_array(t) __params.t -#define kernel_tex_fetch(t, index) __params.t[(index)] -#define kernel_integrator_state __params.__integrator_state +#define kernel_data kernel_params.data +#define kernel_data_array(name) kernel_params.name +#define kernel_data_fetch(name, index) kernel_params.name[(index)] +#define kernel_integrator_state kernel_params.integrator_state CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/device/optix/kernel.cu b/intern/cycles/kernel/device/optix/kernel.cu index 9843b2e99be..949bf41d171 100644 --- a/intern/cycles/kernel/device/optix/kernel.cu +++ b/intern/cycles/kernel/device/optix/kernel.cu @@ -51,15 +51,15 @@ ccl_device_forceinline int get_object_id() extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_closest() { const int global_index = optixGetLaunchIndex().x; - const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] : + const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : global_index; - integrator_intersect_closest(nullptr, path_index, __params.render_buffer); + integrator_intersect_closest(nullptr, path_index, kernel_params.render_buffer); } extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_shadow() { const int global_index = optixGetLaunchIndex().x; - const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] : + const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : global_index; integrator_intersect_shadow(nullptr, path_index); } @@ -67,7 +67,7 @@ extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_shadow() extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_subsurface() { const int global_index = optixGetLaunchIndex().x; - const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] : + const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : global_index; integrator_intersect_subsurface(nullptr, path_index); } @@ -75,7 +75,7 @@ extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_subsurfac extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_volume_stack() { const int global_index = optixGetLaunchIndex().x; - const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] : + const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : global_index; integrator_intersect_volume_stack(nullptr, path_index); } @@ -151,17 +151,17 @@ extern "C" __global__ void __anyhit__kernel_optix_local_hit() isect->t = optixGetRayTmax(); isect->prim = prim; isect->object = get_object_id(); - isect->type = kernel_tex_fetch(__objects, isect->object).primitive_type; + isect->type = kernel_data_fetch(objects, isect->object).primitive_type; const float2 barycentrics = optixGetTriangleBarycentrics(); isect->u = 1.0f - barycentrics.y - barycentrics.x; isect->v = barycentrics.x; /* Record geometric normal. */ - const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w; - const float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0); - const float3 tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1); - const float3 tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); + const uint tri_vindex = kernel_data_fetch(tri_vindex, prim).w; + const float3 tri_a = kernel_data_fetch(tri_verts, tri_vindex + 0); + const float3 tri_b = kernel_data_fetch(tri_verts, tri_vindex + 1); + const float3 tri_c = kernel_data_fetch(tri_verts, tri_vindex + 2); local_isect->Ng[hit] = normalize(cross(tri_b - tri_a, tri_c - tri_a)); /* Continue tracing (without this the trace call would return after the first hit). */ @@ -176,7 +176,7 @@ extern "C" __global__ void __anyhit__kernel_optix_shadow_all_hit() const uint object = get_object_id(); # ifdef __VISIBILITY_FLAG__ const uint visibility = optixGetPayload_4(); - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { return optixIgnoreIntersection(); } # endif @@ -192,14 +192,14 @@ extern "C" __global__ void __anyhit__kernel_optix_shadow_all_hit() const float2 barycentrics = optixGetTriangleBarycentrics(); u = 1.0f - barycentrics.y - barycentrics.x; v = barycentrics.x; - type = kernel_tex_fetch(__objects, object).primitive_type; + type = kernel_data_fetch(objects, object).primitive_type; } # ifdef __HAIR__ else if ((optixGetHitKind() & (~PRIMITIVE_MOTION)) != PRIMITIVE_POINT) { u = __uint_as_float(optixGetAttribute_0()); v = __uint_as_float(optixGetAttribute_1()); - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, prim); type = segment.type; prim = segment.prim; @@ -212,7 +212,7 @@ extern "C" __global__ void __anyhit__kernel_optix_shadow_all_hit() } # endif else { - type = kernel_tex_fetch(__objects, object).primitive_type; + type = kernel_data_fetch(objects, object).primitive_type; u = 0.0f; v = 0.0f; } @@ -307,12 +307,12 @@ extern "C" __global__ void __anyhit__kernel_optix_volume_test() const uint object = get_object_id(); #ifdef __VISIBILITY_FLAG__ const uint visibility = optixGetPayload_4(); - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { return optixIgnoreIntersection(); } #endif - if ((kernel_tex_fetch(__object_flag, object) & SD_OBJECT_HAS_VOLUME) == 0) { + if ((kernel_data_fetch(object_flag, object) & SD_OBJECT_HAS_VOLUME) == 0) { return optixIgnoreIntersection(); } @@ -340,7 +340,7 @@ extern "C" __global__ void __anyhit__kernel_optix_visibility_test() const uint object = get_object_id(); const uint visibility = optixGetPayload_4(); #ifdef __VISIBILITY_FLAG__ - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { return optixIgnoreIntersection(); } #endif @@ -377,10 +377,10 @@ extern "C" __global__ void __closesthit__kernel_optix_hit() optixSetPayload_1(__float_as_uint(1.0f - barycentrics.y - barycentrics.x)); optixSetPayload_2(__float_as_uint(barycentrics.x)); optixSetPayload_3(prim); - optixSetPayload_5(kernel_tex_fetch(__objects, object).primitive_type); + optixSetPayload_5(kernel_data_fetch(objects, object).primitive_type); } else if ((optixGetHitKind() & (~PRIMITIVE_MOTION)) != PRIMITIVE_POINT) { - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, prim); optixSetPayload_1(optixGetAttribute_0()); /* Same as 'optixGetCurveParameter()' */ optixSetPayload_2(optixGetAttribute_1()); optixSetPayload_3(segment.prim); @@ -390,7 +390,7 @@ extern "C" __global__ void __closesthit__kernel_optix_hit() optixSetPayload_1(0); optixSetPayload_2(0); optixSetPayload_3(prim); - optixSetPayload_5(kernel_tex_fetch(__objects, object).primitive_type); + optixSetPayload_5(kernel_data_fetch(objects, object).primitive_type); } } @@ -401,7 +401,7 @@ ccl_device_inline void optix_intersection_curve(const int prim, const int type) # ifdef __VISIBILITY_FLAG__ const uint visibility = optixGetPayload_4(); - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { return; } # endif @@ -436,7 +436,7 @@ ccl_device_inline void optix_intersection_curve(const int prim, const int type) extern "C" __global__ void __intersection__curve_ribbon() { - const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, optixGetPrimitiveIndex()); + const KernelCurveSegment segment = kernel_data_fetch(curve_segments, optixGetPrimitiveIndex()); const int prim = segment.prim; const int type = segment.type; if (type & PRIMITIVE_CURVE_RIBBON) { @@ -451,11 +451,11 @@ extern "C" __global__ void __intersection__point() { const int prim = optixGetPrimitiveIndex(); const int object = get_object_id(); - const int type = kernel_tex_fetch(__objects, object).primitive_type; + const int type = kernel_data_fetch(objects, object).primitive_type; # ifdef __VISIBILITY_FLAG__ const uint visibility = optixGetPayload_4(); - if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) { + if ((kernel_data_fetch(objects, object).visibility & visibility) == 0) { return; } # endif diff --git a/intern/cycles/kernel/device/optix/kernel_shader_raytrace.cu b/intern/cycles/kernel/device/optix/kernel_shader_raytrace.cu index 3bd57bc0f1a..41e6224f6da 100644 --- a/intern/cycles/kernel/device/optix/kernel_shader_raytrace.cu +++ b/intern/cycles/kernel/device/optix/kernel_shader_raytrace.cu @@ -11,15 +11,15 @@ extern "C" __global__ void __raygen__kernel_optix_integrator_shade_surface_raytrace() { const int global_index = optixGetLaunchIndex().x; - const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] : + const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : global_index; - integrator_shade_surface_raytrace(nullptr, path_index, __params.render_buffer); + integrator_shade_surface_raytrace(nullptr, path_index, kernel_params.render_buffer); } extern "C" __global__ void __raygen__kernel_optix_integrator_shade_surface_mnee() { const int global_index = optixGetLaunchIndex().x; - const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] : + const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : global_index; - integrator_shade_surface_mnee(nullptr, path_index, __params.render_buffer); + integrator_shade_surface_mnee(nullptr, path_index, kernel_params.render_buffer); } diff --git a/intern/cycles/kernel/geom/attribute.h b/intern/cycles/kernel/geom/attribute.h index da620f69e2d..31a9e39d528 100644 --- a/intern/cycles/kernel/geom/attribute.h +++ b/intern/cycles/kernel/geom/attribute.h @@ -18,7 +18,7 @@ CCL_NAMESPACE_BEGIN ccl_device_inline uint subd_triangle_patch(KernelGlobals kg, ccl_private const ShaderData *sd) { - return (sd->prim != PRIM_NONE) ? kernel_tex_fetch(__tri_patch, sd->prim) : ~0; + return (sd->prim != PRIM_NONE) ? kernel_data_fetch(tri_patch, sd->prim) : ~0; } ccl_device_inline uint attribute_primitive_type(KernelGlobals kg, ccl_private const ShaderData *sd) @@ -42,7 +42,7 @@ ccl_device_inline AttributeDescriptor attribute_not_found() ccl_device_inline uint object_attribute_map_offset(KernelGlobals kg, int object) { - return kernel_tex_fetch(__objects, object).attribute_map_offset; + return kernel_data_fetch(objects, object).attribute_map_offset; } ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, @@ -56,26 +56,26 @@ ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, /* for SVM, find attribute by unique id */ uint attr_offset = object_attribute_map_offset(kg, sd->object); attr_offset += attribute_primitive_type(kg, sd); - uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + AttributeMap attr_map = kernel_data_fetch(attributes_map, attr_offset); - while (attr_map.x != id) { - if (UNLIKELY(attr_map.x == ATTR_STD_NONE)) { - if (UNLIKELY(attr_map.y == 0)) { + while (attr_map.id != id) { + if (UNLIKELY(attr_map.id == ATTR_STD_NONE)) { + if (UNLIKELY(attr_map.element == 0)) { return attribute_not_found(); } else { /* Chain jump to a different part of the table. */ - attr_offset = attr_map.z; + attr_offset = attr_map.offset; } } else { attr_offset += ATTR_PRIM_TYPES; } - attr_map = kernel_tex_fetch(__attributes_map, attr_offset); + attr_map = kernel_data_fetch(attributes_map, attr_offset); } AttributeDescriptor desc; - desc.element = (AttributeElement)attr_map.y; + desc.element = (AttributeElement)attr_map.element; if (sd->prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH && desc.element != ATTR_ELEMENT_VOXEL && desc.element != ATTR_ELEMENT_OBJECT) { @@ -83,9 +83,10 @@ ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg, } /* return result */ - desc.offset = (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z; - desc.type = (NodeAttributeType)(attr_map.w & 0xff); - desc.flags = (AttributeFlag)(attr_map.w >> 8); + desc.offset = (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : + (int)attr_map.offset; + desc.type = (NodeAttributeType)attr_map.type; + desc.flags = (AttributeFlag)attr_map.flags; return desc; } @@ -98,9 +99,9 @@ ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, { Transform tfm; - tfm.x = kernel_tex_fetch(__attributes_float4, desc.offset + 0); - tfm.y = kernel_tex_fetch(__attributes_float4, desc.offset + 1); - tfm.z = kernel_tex_fetch(__attributes_float4, desc.offset + 2); + tfm.x = kernel_data_fetch(attributes_float4, desc.offset + 0); + tfm.y = kernel_data_fetch(attributes_float4, desc.offset + 1); + tfm.z = kernel_data_fetch(attributes_float4, desc.offset + 2); return tfm; } diff --git a/intern/cycles/kernel/geom/curve.h b/intern/cycles/kernel/geom/curve.h index 4dbc6d4f6db..e243adfde21 100644 --- a/intern/cycles/kernel/geom/curve.h +++ b/intern/cycles/kernel/geom/curve.h @@ -23,12 +23,12 @@ ccl_device float curve_attribute_float(KernelGlobals kg, ccl_private float *dy) { if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) { - KernelCurve curve = kernel_tex_fetch(__curves, sd->prim); + KernelCurve curve = kernel_data_fetch(curves, sd->prim); int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; - float f0 = kernel_tex_fetch(__attributes_float, desc.offset + k0); - float f1 = kernel_tex_fetch(__attributes_float, desc.offset + k1); + float f0 = kernel_data_fetch(attributes_float, desc.offset + k0); + float f1 = kernel_data_fetch(attributes_float, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ if (dx) @@ -50,7 +50,7 @@ ccl_device float curve_attribute_float(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float, offset); + return kernel_data_fetch(attributes_float, offset); } else { return 0.0f; @@ -65,12 +65,12 @@ ccl_device float2 curve_attribute_float2(KernelGlobals kg, ccl_private float2 *dy) { if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) { - KernelCurve curve = kernel_tex_fetch(__curves, sd->prim); + KernelCurve curve = kernel_data_fetch(curves, sd->prim); int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; - float2 f0 = kernel_tex_fetch(__attributes_float2, desc.offset + k0); - float2 f1 = kernel_tex_fetch(__attributes_float2, desc.offset + k1); + float2 f0 = kernel_data_fetch(attributes_float2, desc.offset + k0); + float2 f1 = kernel_data_fetch(attributes_float2, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ if (dx) @@ -96,7 +96,7 @@ ccl_device float2 curve_attribute_float2(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float2, offset); + return kernel_data_fetch(attributes_float2, offset); } else { return make_float2(0.0f, 0.0f); @@ -111,12 +111,12 @@ ccl_device float3 curve_attribute_float3(KernelGlobals kg, ccl_private float3 *dy) { if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) { - KernelCurve curve = kernel_tex_fetch(__curves, sd->prim); + KernelCurve curve = kernel_data_fetch(curves, sd->prim); int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; - float3 f0 = kernel_tex_fetch(__attributes_float3, desc.offset + k0); - float3 f1 = kernel_tex_fetch(__attributes_float3, desc.offset + k1); + float3 f0 = kernel_data_fetch(attributes_float3, desc.offset + k0); + float3 f1 = kernel_data_fetch(attributes_float3, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ if (dx) @@ -138,7 +138,7 @@ ccl_device float3 curve_attribute_float3(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float3, offset); + return kernel_data_fetch(attributes_float3, offset); } else { return make_float3(0.0f, 0.0f, 0.0f); @@ -153,12 +153,12 @@ ccl_device float4 curve_attribute_float4(KernelGlobals kg, ccl_private float4 *dy) { if (desc.element & (ATTR_ELEMENT_CURVE_KEY | ATTR_ELEMENT_CURVE_KEY_MOTION)) { - KernelCurve curve = kernel_tex_fetch(__curves, sd->prim); + KernelCurve curve = kernel_data_fetch(curves, sd->prim); int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; - float4 f0 = kernel_tex_fetch(__attributes_float4, desc.offset + k0); - float4 f1 = kernel_tex_fetch(__attributes_float4, desc.offset + k1); + float4 f0 = kernel_data_fetch(attributes_float4, desc.offset + k0); + float4 f1 = kernel_data_fetch(attributes_float4, desc.offset + k1); # ifdef __RAY_DIFFERENTIALS__ if (dx) @@ -180,7 +180,7 @@ ccl_device float4 curve_attribute_float4(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_CURVE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_CURVE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float4, offset); + return kernel_data_fetch(attributes_float4, offset); } else { return zero_float4(); @@ -195,15 +195,15 @@ ccl_device float curve_thickness(KernelGlobals kg, ccl_private const ShaderData float r = 0.0f; if (sd->type & PRIMITIVE_CURVE) { - KernelCurve curve = kernel_tex_fetch(__curves, sd->prim); + KernelCurve curve = kernel_data_fetch(curves, sd->prim); int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; float4 P_curve[2]; if (!(sd->type & PRIMITIVE_MOTION)) { - P_curve[0] = kernel_tex_fetch(__curve_keys, k0); - P_curve[1] = kernel_tex_fetch(__curve_keys, k1); + P_curve[0] = kernel_data_fetch(curve_keys, k0); + P_curve[1] = kernel_data_fetch(curve_keys, k1); } else { motion_curve_keys_linear(kg, sd->object, sd->prim, sd->time, k0, k1, P_curve); @@ -232,14 +232,14 @@ ccl_device float curve_random(KernelGlobals kg, ccl_private const ShaderData *sd ccl_device float3 curve_motion_center_location(KernelGlobals kg, ccl_private const ShaderData *sd) { - KernelCurve curve = kernel_tex_fetch(__curves, sd->prim); + KernelCurve curve = kernel_data_fetch(curves, sd->prim); int k0 = curve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; float4 P_curve[2]; - P_curve[0] = kernel_tex_fetch(__curve_keys, k0); - P_curve[1] = kernel_tex_fetch(__curve_keys, k1); + P_curve[0] = kernel_data_fetch(curve_keys, k0); + P_curve[1] = kernel_data_fetch(curve_keys, k1); return float4_to_float3(P_curve[1]) * sd->u + float4_to_float3(P_curve[0]) * (1.0f - sd->u); } diff --git a/intern/cycles/kernel/geom/curve_intersect.h b/intern/cycles/kernel/geom/curve_intersect.h index e1a1f9c02c5..11ec42a0598 100644 --- a/intern/cycles/kernel/geom/curve_intersect.h +++ b/intern/cycles/kernel/geom/curve_intersect.h @@ -624,7 +624,7 @@ ccl_device_forceinline bool curve_intersect(KernelGlobals kg, { const bool is_motion = (type & PRIMITIVE_MOTION); - KernelCurve kcurve = kernel_tex_fetch(__curves, prim); + KernelCurve kcurve = kernel_data_fetch(curves, prim); int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(type); int k1 = k0 + 1; @@ -633,10 +633,10 @@ ccl_device_forceinline bool curve_intersect(KernelGlobals kg, float4 curve[4]; if (!is_motion) { - curve[0] = kernel_tex_fetch(__curve_keys, ka); - curve[1] = kernel_tex_fetch(__curve_keys, k0); - curve[2] = kernel_tex_fetch(__curve_keys, k1); - curve[3] = kernel_tex_fetch(__curve_keys, kb); + curve[0] = kernel_data_fetch(curve_keys, ka); + curve[1] = kernel_data_fetch(curve_keys, k0); + curve[2] = kernel_data_fetch(curve_keys, k1); + curve[3] = kernel_data_fetch(curve_keys, kb); } else { motion_curve_keys(kg, object, prim, time, ka, k0, k1, kb, curve); @@ -682,7 +682,7 @@ ccl_device_inline void curve_shader_setup(KernelGlobals kg, D = safe_normalize_len(D, &t); } - KernelCurve kcurve = kernel_tex_fetch(__curves, isect_prim); + KernelCurve kcurve = kernel_data_fetch(curves, isect_prim); int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; @@ -692,10 +692,10 @@ ccl_device_inline void curve_shader_setup(KernelGlobals kg, float4 P_curve[4]; if (!(sd->type & PRIMITIVE_MOTION)) { - P_curve[0] = kernel_tex_fetch(__curve_keys, ka); - P_curve[1] = kernel_tex_fetch(__curve_keys, k0); - P_curve[2] = kernel_tex_fetch(__curve_keys, k1); - P_curve[3] = kernel_tex_fetch(__curve_keys, kb); + P_curve[0] = kernel_data_fetch(curve_keys, ka); + P_curve[1] = kernel_data_fetch(curve_keys, k0); + P_curve[2] = kernel_data_fetch(curve_keys, k1); + P_curve[3] = kernel_data_fetch(curve_keys, kb); } else { motion_curve_keys(kg, sd->object, sd->prim, sd->time, ka, k0, k1, kb, P_curve); @@ -750,7 +750,7 @@ ccl_device_inline void curve_shader_setup(KernelGlobals kg, sd->P = P; sd->Ng = (sd->type & PRIMITIVE_CURVE_RIBBON) ? sd->I : sd->N; sd->dPdv = cross(sd->dPdu, sd->Ng); - sd->shader = kernel_tex_fetch(__curves, sd->prim).shader_id; + sd->shader = kernel_data_fetch(curves, sd->prim).shader_id; } #endif diff --git a/intern/cycles/kernel/geom/motion_curve.h b/intern/cycles/kernel/geom/motion_curve.h index b5289b6dda1..448e4b95e0b 100644 --- a/intern/cycles/kernel/geom/motion_curve.h +++ b/intern/cycles/kernel/geom/motion_curve.h @@ -27,8 +27,8 @@ ccl_device_inline void motion_curve_keys_for_step_linear(KernelGlobals kg, { if (step == numsteps) { /* center step: regular key location */ - keys[0] = kernel_tex_fetch(__curve_keys, k0); - keys[1] = kernel_tex_fetch(__curve_keys, k1); + keys[0] = kernel_data_fetch(curve_keys, k0); + keys[1] = kernel_data_fetch(curve_keys, k1); } else { /* center step is not stored in this array */ @@ -37,8 +37,8 @@ ccl_device_inline void motion_curve_keys_for_step_linear(KernelGlobals kg, offset += step * numkeys; - keys[0] = kernel_tex_fetch(__attributes_float4, offset + k0); - keys[1] = kernel_tex_fetch(__attributes_float4, offset + k1); + keys[0] = kernel_data_fetch(attributes_float4, offset + k0); + keys[1] = kernel_data_fetch(attributes_float4, offset + k1); } } @@ -83,10 +83,10 @@ ccl_device_inline void motion_curve_keys_for_step(KernelGlobals kg, { if (step == numsteps) { /* center step: regular key location */ - keys[0] = kernel_tex_fetch(__curve_keys, k0); - keys[1] = kernel_tex_fetch(__curve_keys, k1); - keys[2] = kernel_tex_fetch(__curve_keys, k2); - keys[3] = kernel_tex_fetch(__curve_keys, k3); + keys[0] = kernel_data_fetch(curve_keys, k0); + keys[1] = kernel_data_fetch(curve_keys, k1); + keys[2] = kernel_data_fetch(curve_keys, k2); + keys[3] = kernel_data_fetch(curve_keys, k3); } else { /* center step is not stored in this array */ @@ -95,10 +95,10 @@ ccl_device_inline void motion_curve_keys_for_step(KernelGlobals kg, offset += step * numkeys; - keys[0] = kernel_tex_fetch(__attributes_float4, offset + k0); - keys[1] = kernel_tex_fetch(__attributes_float4, offset + k1); - keys[2] = kernel_tex_fetch(__attributes_float4, offset + k2); - keys[3] = kernel_tex_fetch(__attributes_float4, offset + k3); + keys[0] = kernel_data_fetch(attributes_float4, offset + k0); + keys[1] = kernel_data_fetch(attributes_float4, offset + k1); + keys[2] = kernel_data_fetch(attributes_float4, offset + k2); + keys[3] = kernel_data_fetch(attributes_float4, offset + k3); } } diff --git a/intern/cycles/kernel/geom/motion_point.h b/intern/cycles/kernel/geom/motion_point.h index c1952ab090a..4916ae702ff 100644 --- a/intern/cycles/kernel/geom/motion_point.h +++ b/intern/cycles/kernel/geom/motion_point.h @@ -19,7 +19,7 @@ motion_point_for_step(KernelGlobals kg, int offset, int numkeys, int numsteps, i { if (step == numsteps) { /* center step: regular key location */ - return kernel_tex_fetch(__points, prim); + return kernel_data_fetch(points, prim); } else { /* center step is not stored in this array */ @@ -28,7 +28,7 @@ motion_point_for_step(KernelGlobals kg, int offset, int numkeys, int numsteps, i offset += step * numkeys; - return kernel_tex_fetch(__attributes_float4, offset + prim); + return kernel_data_fetch(attributes_float4, offset + prim); } } diff --git a/intern/cycles/kernel/geom/motion_triangle.h b/intern/cycles/kernel/geom/motion_triangle.h index a87eb11f4f4..06308071700 100644 --- a/intern/cycles/kernel/geom/motion_triangle.h +++ b/intern/cycles/kernel/geom/motion_triangle.h @@ -30,9 +30,9 @@ ccl_device_inline void motion_triangle_verts_for_step(KernelGlobals kg, { if (step == numsteps) { /* center step: regular vertex location */ - verts[0] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 0); - verts[1] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 1); - verts[2] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 2); + verts[0] = kernel_data_fetch(tri_verts, tri_vindex.w + 0); + verts[1] = kernel_data_fetch(tri_verts, tri_vindex.w + 1); + verts[2] = kernel_data_fetch(tri_verts, tri_vindex.w + 2); } else { /* center step not store in this array */ @@ -41,9 +41,9 @@ ccl_device_inline void motion_triangle_verts_for_step(KernelGlobals kg, offset += step * numverts; - verts[0] = kernel_tex_fetch(__attributes_float3, offset + tri_vindex.x); - verts[1] = kernel_tex_fetch(__attributes_float3, offset + tri_vindex.y); - verts[2] = kernel_tex_fetch(__attributes_float3, offset + tri_vindex.z); + verts[0] = kernel_data_fetch(attributes_float3, offset + tri_vindex.x); + verts[1] = kernel_data_fetch(attributes_float3, offset + tri_vindex.y); + verts[2] = kernel_data_fetch(attributes_float3, offset + tri_vindex.z); } } @@ -57,9 +57,9 @@ ccl_device_inline void motion_triangle_normals_for_step(KernelGlobals kg, { if (step == numsteps) { /* center step: regular vertex location */ - normals[0] = kernel_tex_fetch(__tri_vnormal, tri_vindex.x); - normals[1] = kernel_tex_fetch(__tri_vnormal, tri_vindex.y); - normals[2] = kernel_tex_fetch(__tri_vnormal, tri_vindex.z); + normals[0] = kernel_data_fetch(tri_vnormal, tri_vindex.x); + normals[1] = kernel_data_fetch(tri_vnormal, tri_vindex.y); + normals[2] = kernel_data_fetch(tri_vnormal, tri_vindex.z); } else { /* center step is not stored in this array */ @@ -68,9 +68,9 @@ ccl_device_inline void motion_triangle_normals_for_step(KernelGlobals kg, offset += step * numverts; - normals[0] = kernel_tex_fetch(__attributes_float3, offset + tri_vindex.x); - normals[1] = kernel_tex_fetch(__attributes_float3, offset + tri_vindex.y); - normals[2] = kernel_tex_fetch(__attributes_float3, offset + tri_vindex.z); + normals[0] = kernel_data_fetch(attributes_float3, offset + tri_vindex.x); + normals[1] = kernel_data_fetch(attributes_float3, offset + tri_vindex.y); + normals[2] = kernel_data_fetch(attributes_float3, offset + tri_vindex.z); } } @@ -92,7 +92,7 @@ ccl_device_inline void motion_triangle_vertices( /* fetch vertex coordinates */ float3 next_verts[3]; - uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); + uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts); motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step + 1, next_verts); @@ -121,7 +121,7 @@ ccl_device_inline void motion_triangle_vertices_and_normals( /* Fetch vertex coordinates. */ float3 next_verts[3]; - uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); + uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts); motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step + 1, next_verts); @@ -167,7 +167,7 @@ ccl_device_inline float3 motion_triangle_smooth_normal( /* fetch normals */ float3 normals[3], next_normals[3]; - uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); + uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); motion_triangle_normals_for_step(kg, tri_vindex, offset, numverts, numsteps, step, normals); motion_triangle_normals_for_step( diff --git a/intern/cycles/kernel/geom/motion_triangle_intersect.h b/intern/cycles/kernel/geom/motion_triangle_intersect.h index fb951fa151d..6eea5096567 100644 --- a/intern/cycles/kernel/geom/motion_triangle_intersect.h +++ b/intern/cycles/kernel/geom/motion_triangle_intersect.h @@ -63,7 +63,7 @@ ccl_device_inline bool motion_triangle_intersect(KernelGlobals kg, /* Visibility flag test. we do it here under the assumption * that most triangles are culled by node flags. */ - if (kernel_tex_fetch(__prim_visibility, prim_addr) & visibility) + if (kernel_data_fetch(prim_visibility, prim_addr) & visibility) #endif { isect->t = t; diff --git a/intern/cycles/kernel/geom/motion_triangle_shader.h b/intern/cycles/kernel/geom/motion_triangle_shader.h index 2b2bb858816..236e737b785 100644 --- a/intern/cycles/kernel/geom/motion_triangle_shader.h +++ b/intern/cycles/kernel/geom/motion_triangle_shader.h @@ -31,7 +31,7 @@ ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals kg, bool is_local) { /* Get shader. */ - sd->shader = kernel_tex_fetch(__tri_shader, sd->prim); + sd->shader = kernel_data_fetch(tri_shader, sd->prim); /* Get motion info. */ /* TODO(sergey): This logic is really similar to motion_triangle_vertices(), * can we de-duplicate something here? @@ -47,7 +47,7 @@ ccl_device_noinline void motion_triangle_shader_setup(KernelGlobals kg, kernel_assert(offset != ATTR_STD_NOT_FOUND); /* Fetch vertex coordinates. */ float3 verts[3], next_verts[3]; - uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); + uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim); motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step, verts); motion_triangle_verts_for_step(kg, tri_vindex, offset, numverts, numsteps, step + 1, next_verts); /* Interpolate between steps. */ diff --git a/intern/cycles/kernel/geom/object.h b/intern/cycles/kernel/geom/object.h index 3faab7fa905..b15f6b5dda5 100644 --- a/intern/cycles/kernel/geom/object.h +++ b/intern/cycles/kernel/geom/object.h @@ -31,10 +31,10 @@ ccl_device_inline Transform object_fetch_transform(KernelGlobals kg, enum ObjectTransform type) { if (type == OBJECT_INVERSE_TRANSFORM) { - return kernel_tex_fetch(__objects, object).itfm; + return kernel_data_fetch(objects, object).itfm; } else { - return kernel_tex_fetch(__objects, object).tfm; + return kernel_data_fetch(objects, object).tfm; } } @@ -43,10 +43,10 @@ ccl_device_inline Transform object_fetch_transform(KernelGlobals kg, ccl_device_inline Transform lamp_fetch_transform(KernelGlobals kg, int lamp, bool inverse) { if (inverse) { - return kernel_tex_fetch(__lights, lamp).itfm; + return kernel_data_fetch(lights, lamp).itfm; } else { - return kernel_tex_fetch(__lights, lamp).tfm; + return kernel_data_fetch(lights, lamp).tfm; } } @@ -57,7 +57,7 @@ ccl_device_inline Transform object_fetch_motion_pass_transform(KernelGlobals kg, enum ObjectVectorTransform type) { int offset = object * OBJECT_MOTION_PASS_SIZE + (int)type; - return kernel_tex_fetch(__object_motion_pass, offset); + return kernel_data_fetch(object_motion_pass, offset); } /* Motion blurred object transformations */ @@ -65,9 +65,9 @@ ccl_device_inline Transform object_fetch_motion_pass_transform(KernelGlobals kg, #ifdef __OBJECT_MOTION__ ccl_device_inline Transform object_fetch_transform_motion(KernelGlobals kg, int object, float time) { - const uint motion_offset = kernel_tex_fetch(__objects, object).motion_offset; - ccl_global const DecomposedTransform *motion = &kernel_tex_fetch(__object_motion, motion_offset); - const uint num_steps = kernel_tex_fetch(__objects, object).numsteps * 2 + 1; + const uint motion_offset = kernel_data_fetch(objects, object).motion_offset; + ccl_global const DecomposedTransform *motion = &kernel_data_fetch(object_motion, motion_offset); + const uint num_steps = kernel_data_fetch(objects, object).numsteps * 2 + 1; Transform tfm; transform_motion_array_interpolate(&tfm, motion, num_steps, time); @@ -80,7 +80,7 @@ ccl_device_inline Transform object_fetch_transform_motion_test(KernelGlobals kg, float time, ccl_private Transform *itfm) { - int object_flag = kernel_tex_fetch(__object_flag, object); + int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_MOTION) { /* if we do motion blur */ Transform tfm = object_fetch_transform_motion(kg, object, time); @@ -259,7 +259,7 @@ ccl_device_inline float3 object_color(KernelGlobals kg, int object) if (object == OBJECT_NONE) return make_float3(0.0f, 0.0f, 0.0f); - ccl_global const KernelObject *kobject = &kernel_tex_fetch(__objects, object); + ccl_global const KernelObject *kobject = &kernel_data_fetch(objects, object); return make_float3(kobject->color[0], kobject->color[1], kobject->color[2]); } @@ -270,7 +270,7 @@ ccl_device_inline float object_alpha(KernelGlobals kg, int object) if (object == OBJECT_NONE) return 0.0f; - return kernel_tex_fetch(__objects, object).alpha; + return kernel_data_fetch(objects, object).alpha; } /* Pass ID number of object */ @@ -280,7 +280,7 @@ ccl_device_inline float object_pass_id(KernelGlobals kg, int object) if (object == OBJECT_NONE) return 0.0f; - return kernel_tex_fetch(__objects, object).pass_id; + return kernel_data_fetch(objects, object).pass_id; } /* Lightgroup of lamp */ @@ -290,7 +290,7 @@ ccl_device_inline int lamp_lightgroup(KernelGlobals kg, int lamp) if (lamp == LAMP_NONE) return LIGHTGROUP_NONE; - return kernel_tex_fetch(__lights, lamp).lightgroup; + return kernel_data_fetch(lights, lamp).lightgroup; } /* Lightgroup of object */ @@ -300,7 +300,7 @@ ccl_device_inline int object_lightgroup(KernelGlobals kg, int object) if (object == OBJECT_NONE) return LIGHTGROUP_NONE; - return kernel_tex_fetch(__objects, object).lightgroup; + return kernel_data_fetch(objects, object).lightgroup; } /* Per lamp random number for shader variation */ @@ -310,7 +310,7 @@ ccl_device_inline float lamp_random_number(KernelGlobals kg, int lamp) if (lamp == LAMP_NONE) return 0.0f; - return kernel_tex_fetch(__lights, lamp).random; + return kernel_data_fetch(lights, lamp).random; } /* Per object random number for shader variation */ @@ -320,7 +320,7 @@ ccl_device_inline float object_random_number(KernelGlobals kg, int object) if (object == OBJECT_NONE) return 0.0f; - return kernel_tex_fetch(__objects, object).random_number; + return kernel_data_fetch(objects, object).random_number; } /* Particle ID from which this object was generated */ @@ -330,7 +330,7 @@ ccl_device_inline int object_particle_id(KernelGlobals kg, int object) if (object == OBJECT_NONE) return 0; - return kernel_tex_fetch(__objects, object).particle_index; + return kernel_data_fetch(objects, object).particle_index; } /* Generated texture coordinate on surface from where object was instanced */ @@ -340,7 +340,7 @@ ccl_device_inline float3 object_dupli_generated(KernelGlobals kg, int object) if (object == OBJECT_NONE) return make_float3(0.0f, 0.0f, 0.0f); - ccl_global const KernelObject *kobject = &kernel_tex_fetch(__objects, object); + ccl_global const KernelObject *kobject = &kernel_data_fetch(objects, object); return make_float3( kobject->dupli_generated[0], kobject->dupli_generated[1], kobject->dupli_generated[2]); } @@ -352,7 +352,7 @@ ccl_device_inline float3 object_dupli_uv(KernelGlobals kg, int object) if (object == OBJECT_NONE) return make_float3(0.0f, 0.0f, 0.0f); - ccl_global const KernelObject *kobject = &kernel_tex_fetch(__objects, object); + ccl_global const KernelObject *kobject = &kernel_data_fetch(objects, object); return make_float3(kobject->dupli_uv[0], kobject->dupli_uv[1], 0.0f); } @@ -365,13 +365,13 @@ ccl_device_inline void object_motion_info(KernelGlobals kg, ccl_private int *numkeys) { if (numkeys) { - *numkeys = kernel_tex_fetch(__objects, object).numkeys; + *numkeys = kernel_data_fetch(objects, object).numkeys; } if (numsteps) - *numsteps = kernel_tex_fetch(__objects, object).numsteps; + *numsteps = kernel_data_fetch(objects, object).numsteps; if (numverts) - *numverts = kernel_tex_fetch(__objects, object).numverts; + *numverts = kernel_data_fetch(objects, object).numverts; } /* Offset to an objects patch map */ @@ -381,7 +381,7 @@ ccl_device_inline uint object_patch_map_offset(KernelGlobals kg, int object) if (object == OBJECT_NONE) return 0; - return kernel_tex_fetch(__objects, object).patch_map_offset; + return kernel_data_fetch(objects, object).patch_map_offset; } /* Volume step size */ @@ -392,7 +392,7 @@ ccl_device_inline float object_volume_density(KernelGlobals kg, int object) return 1.0f; } - return kernel_tex_fetch(__objects, object).volume_density; + return kernel_data_fetch(objects, object).volume_density; } ccl_device_inline float object_volume_step_size(KernelGlobals kg, int object) @@ -401,14 +401,14 @@ ccl_device_inline float object_volume_step_size(KernelGlobals kg, int object) return kernel_data.background.volume_step_size; } - return kernel_tex_fetch(__object_volume_step, object); + return kernel_data_fetch(object_volume_step, object); } /* Pass ID for shader */ ccl_device int shader_pass_id(KernelGlobals kg, ccl_private const ShaderData *sd) { - return kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).pass_id; + return kernel_data_fetch(shaders, (sd->shader & SHADER_MASK)).pass_id; } /* Cryptomatte ID */ @@ -418,7 +418,7 @@ ccl_device_inline float object_cryptomatte_id(KernelGlobals kg, int object) if (object == OBJECT_NONE) return 0.0f; - return kernel_tex_fetch(__objects, object).cryptomatte_object; + return kernel_data_fetch(objects, object).cryptomatte_object; } ccl_device_inline float object_cryptomatte_asset_id(KernelGlobals kg, int object) @@ -426,49 +426,49 @@ ccl_device_inline float object_cryptomatte_asset_id(KernelGlobals kg, int object if (object == OBJECT_NONE) return 0; - return kernel_tex_fetch(__objects, object).cryptomatte_asset; + return kernel_data_fetch(objects, object).cryptomatte_asset; } /* Particle data from which object was instanced */ ccl_device_inline uint particle_index(KernelGlobals kg, int particle) { - return kernel_tex_fetch(__particles, particle).index; + return kernel_data_fetch(particles, particle).index; } ccl_device float particle_age(KernelGlobals kg, int particle) { - return kernel_tex_fetch(__particles, particle).age; + return kernel_data_fetch(particles, particle).age; } ccl_device float particle_lifetime(KernelGlobals kg, int particle) { - return kernel_tex_fetch(__particles, particle).lifetime; + return kernel_data_fetch(particles, particle).lifetime; } ccl_device float particle_size(KernelGlobals kg, int particle) { - return kernel_tex_fetch(__particles, particle).size; + return kernel_data_fetch(particles, particle).size; } ccl_device float4 particle_rotation(KernelGlobals kg, int particle) { - return kernel_tex_fetch(__particles, particle).rotation; + return kernel_data_fetch(particles, particle).rotation; } ccl_device float3 particle_location(KernelGlobals kg, int particle) { - return float4_to_float3(kernel_tex_fetch(__particles, particle).location); + return float4_to_float3(kernel_data_fetch(particles, particle).location); } ccl_device float3 particle_velocity(KernelGlobals kg, int particle) { - return float4_to_float3(kernel_tex_fetch(__particles, particle).velocity); + return float4_to_float3(kernel_data_fetch(particles, particle).velocity); } ccl_device float3 particle_angular_velocity(KernelGlobals kg, int particle) { - return float4_to_float3(kernel_tex_fetch(__particles, particle).angular_velocity); + return float4_to_float3(kernel_data_fetch(particles, particle).angular_velocity); } /* Object intersection in BVH */ diff --git a/intern/cycles/kernel/geom/patch.h b/intern/cycles/kernel/geom/patch.h index 1c63a00e30d..ec98ddf51f0 100644 --- a/intern/cycles/kernel/geom/patch.h +++ b/intern/cycles/kernel/geom/patch.h @@ -62,7 +62,7 @@ patch_map_find_patch(KernelGlobals kg, int object, int patch, float u, float v) int quadrant = patch_map_resolve_quadrant(median, &u, &v); kernel_assert(quadrant >= 0); - uint child = kernel_tex_fetch(__patches, node + quadrant); + uint child = kernel_data_fetch(patches, node + quadrant); /* is the quadrant a hole? */ if (!(child & PATCH_MAP_NODE_IS_SET)) { @@ -73,9 +73,9 @@ patch_map_find_patch(KernelGlobals kg, int object, int patch, float u, float v) uint index = child & PATCH_MAP_NODE_INDEX_MASK; if (child & PATCH_MAP_NODE_IS_LEAF) { - handle.array_index = kernel_tex_fetch(__patches, index + 0); - handle.patch_index = kernel_tex_fetch(__patches, index + 1); - handle.vert_index = kernel_tex_fetch(__patches, index + 2); + handle.array_index = kernel_data_fetch(patches, index + 0); + handle.patch_index = kernel_data_fetch(patches, index + 1); + handle.vert_index = kernel_data_fetch(patches, index + 2); return handle; } @@ -189,11 +189,11 @@ ccl_device_inline int patch_eval_indices(KernelGlobals kg, int channel, int indices[PATCH_MAX_CONTROL_VERTS]) { - int index_base = kernel_tex_fetch(__patches, handle->array_index + 2) + handle->vert_index; + int index_base = kernel_data_fetch(patches, handle->array_index + 2) + handle->vert_index; /* XXX: regular patches only */ for (int i = 0; i < 16; i++) { - indices[i] = kernel_tex_fetch(__patches, index_base + i); + indices[i] = kernel_data_fetch(patches, index_base + i); } return 16; @@ -209,7 +209,7 @@ ccl_device_inline void patch_eval_basis(KernelGlobals kg, float weights_du[PATCH_MAX_CONTROL_VERTS], float weights_dv[PATCH_MAX_CONTROL_VERTS]) { - uint patch_bits = kernel_tex_fetch(__patches, handle->patch_index + 1); /* read patch param */ + uint patch_bits = kernel_data_fetch(patches, handle->patch_index + 1); /* read patch param */ float d_scale = 1 << patch_eval_depth(patch_bits); bool non_quad_root = (patch_bits >> 4) & 0x1; @@ -287,7 +287,7 @@ ccl_device float patch_eval_float(KernelGlobals kg, *dv = 0.0f; for (int i = 0; i < num_control; i++) { - float v = kernel_tex_fetch(__attributes_float, offset + indices[i]); + float v = kernel_data_fetch(attributes_float, offset + indices[i]); val += v * weights[i]; if (du) @@ -324,7 +324,7 @@ ccl_device float2 patch_eval_float2(KernelGlobals kg, *dv = make_float2(0.0f, 0.0f); for (int i = 0; i < num_control; i++) { - float2 v = kernel_tex_fetch(__attributes_float2, offset + indices[i]); + float2 v = kernel_data_fetch(attributes_float2, offset + indices[i]); val += v * weights[i]; if (du) @@ -361,7 +361,7 @@ ccl_device float3 patch_eval_float3(KernelGlobals kg, *dv = make_float3(0.0f, 0.0f, 0.0f); for (int i = 0; i < num_control; i++) { - float3 v = kernel_tex_fetch(__attributes_float3, offset + indices[i]); + float3 v = kernel_data_fetch(attributes_float3, offset + indices[i]); val += v * weights[i]; if (du) @@ -398,7 +398,7 @@ ccl_device float4 patch_eval_float4(KernelGlobals kg, *dv = zero_float4(); for (int i = 0; i < num_control; i++) { - float4 v = kernel_tex_fetch(__attributes_float4, offset + indices[i]); + float4 v = kernel_data_fetch(attributes_float4, offset + indices[i]); val += v * weights[i]; if (du) @@ -436,7 +436,7 @@ ccl_device float4 patch_eval_uchar4(KernelGlobals kg, for (int i = 0; i < num_control; i++) { float4 v = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, offset + indices[i]))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, offset + indices[i]))); val += v * weights[i]; if (du) diff --git a/intern/cycles/kernel/geom/point.h b/intern/cycles/kernel/geom/point.h index ee7eca9e0c6..726d829c329 100644 --- a/intern/cycles/kernel/geom/point.h +++ b/intern/cycles/kernel/geom/point.h @@ -26,7 +26,7 @@ ccl_device float point_attribute_float(KernelGlobals kg, # endif if (desc.element == ATTR_ELEMENT_VERTEX) { - return kernel_tex_fetch(__attributes_float, desc.offset + sd->prim); + return kernel_data_fetch(attributes_float, desc.offset + sd->prim); } else { return 0.0f; @@ -47,7 +47,7 @@ ccl_device float2 point_attribute_float2(KernelGlobals kg, # endif if (desc.element == ATTR_ELEMENT_VERTEX) { - return kernel_tex_fetch(__attributes_float2, desc.offset + sd->prim); + return kernel_data_fetch(attributes_float2, desc.offset + sd->prim); } else { return make_float2(0.0f, 0.0f); @@ -68,7 +68,7 @@ ccl_device float3 point_attribute_float3(KernelGlobals kg, # endif if (desc.element == ATTR_ELEMENT_VERTEX) { - return kernel_tex_fetch(__attributes_float3, desc.offset + sd->prim); + return kernel_data_fetch(attributes_float3, desc.offset + sd->prim); } else { return make_float3(0.0f, 0.0f, 0.0f); @@ -89,7 +89,7 @@ ccl_device float4 point_attribute_float4(KernelGlobals kg, # endif if (desc.element == ATTR_ELEMENT_VERTEX) { - return kernel_tex_fetch(__attributes_float4, desc.offset + sd->prim); + return kernel_data_fetch(attributes_float4, desc.offset + sd->prim); } else { return zero_float4(); @@ -104,7 +104,7 @@ ccl_device float3 point_position(KernelGlobals kg, ccl_private const ShaderData /* World space center. */ float3 P = (sd->type & PRIMITIVE_MOTION) ? float4_to_float3(motion_point(kg, sd->object, sd->prim, sd->time)) : - float4_to_float3(kernel_tex_fetch(__points, sd->prim)); + float4_to_float3(kernel_data_fetch(points, sd->prim)); if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) { object_position_transform(kg, sd, &P); @@ -122,7 +122,7 @@ ccl_device float point_radius(KernelGlobals kg, ccl_private const ShaderData *sd { if (sd->type & PRIMITIVE_POINT) { /* World space radius. */ - const float r = kernel_tex_fetch(__points, sd->prim).w; + const float r = kernel_data_fetch(points, sd->prim).w; if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) { return r; @@ -155,7 +155,7 @@ ccl_device float point_random(KernelGlobals kg, ccl_private const ShaderData *sd ccl_device float3 point_motion_center_location(KernelGlobals kg, ccl_private const ShaderData *sd) { - return float4_to_float3(kernel_tex_fetch(__points, sd->prim)); + return float4_to_float3(kernel_data_fetch(points, sd->prim)); } #endif /* __POINTCLOUD__ */ diff --git a/intern/cycles/kernel/geom/point_intersect.h b/intern/cycles/kernel/geom/point_intersect.h index c7ae72bb488..dfd9d9a015b 100644 --- a/intern/cycles/kernel/geom/point_intersect.h +++ b/intern/cycles/kernel/geom/point_intersect.h @@ -63,7 +63,7 @@ ccl_device_forceinline bool point_intersect(KernelGlobals kg, const int type) { const float4 point = (type & PRIMITIVE_MOTION) ? motion_point(kg, object, prim, time) : - kernel_tex_fetch(__points, prim); + kernel_data_fetch(points, prim); if (!point_intersect_test(point, P, dir, tmax, &isect->t)) { return false; @@ -82,7 +82,7 @@ ccl_device_inline void point_shader_setup(KernelGlobals kg, ccl_private const Intersection *isect, ccl_private const Ray *ray) { - sd->shader = kernel_tex_fetch(__points_shader, isect->prim); + sd->shader = kernel_data_fetch(points_shader, isect->prim); sd->P = ray->P + ray->D * isect->t; /* Texture coordinates, zero for now. */ @@ -94,7 +94,7 @@ ccl_device_inline void point_shader_setup(KernelGlobals kg, /* Compute point center for normal. */ float3 center = float4_to_float3((isect->type & PRIMITIVE_MOTION) ? motion_point(kg, sd->object, sd->prim, sd->time) : - kernel_tex_fetch(__points, sd->prim)); + kernel_data_fetch(points, sd->prim)); if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) { object_position_transform_auto(kg, sd, ¢er); } diff --git a/intern/cycles/kernel/geom/shader_data.h b/intern/cycles/kernel/geom/shader_data.h index 7a439da427a..e5dbeac5e66 100644 --- a/intern/cycles/kernel/geom/shader_data.h +++ b/intern/cycles/kernel/geom/shader_data.h @@ -40,7 +40,7 @@ ccl_device_inline void shader_setup_from_ray(KernelGlobals kg, sd->ray_length = isect->t; sd->type = isect->type; sd->object = isect->object; - sd->object_flag = kernel_tex_fetch(__object_flag, sd->object); + sd->object_flag = kernel_data_fetch(object_flag, sd->object); sd->prim = isect->prim; sd->lamp = LAMP_NONE; sd->flag = 0; @@ -73,7 +73,7 @@ ccl_device_inline void shader_setup_from_ray(KernelGlobals kg, if (sd->type == PRIMITIVE_TRIANGLE) { /* static triangle */ float3 Ng = triangle_normal(kg, sd); - sd->shader = kernel_tex_fetch(__tri_shader, sd->prim); + sd->shader = kernel_data_fetch(tri_shader, sd->prim); /* vectors */ sd->P = triangle_point_from_uv(kg, sd, isect->object, isect->prim, isect->u, isect->v); @@ -106,7 +106,7 @@ ccl_device_inline void shader_setup_from_ray(KernelGlobals kg, } } - sd->flag = kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).flags; + sd->flag = kernel_data_fetch(shaders, (sd->shader & SHADER_MASK)).flags; /* backfacing test */ bool backfacing = (dot(sd->Ng, sd->I) < 0.0f); @@ -169,10 +169,10 @@ ccl_device_inline void shader_setup_from_sample(KernelGlobals kg, sd->time = time; sd->ray_length = t; - sd->flag = kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).flags; + sd->flag = kernel_data_fetch(shaders, (sd->shader & SHADER_MASK)).flags; sd->object_flag = 0; if (sd->object != OBJECT_NONE) { - sd->object_flag |= kernel_tex_fetch(__object_flag, sd->object); + sd->object_flag |= kernel_data_fetch(object_flag, sd->object); #ifdef __OBJECT_MOTION__ shader_setup_object_transforms(kg, sd, time); @@ -264,21 +264,20 @@ ccl_device void shader_setup_from_displace(KernelGlobals kg, /* force smooth shading for displacement */ shader |= SHADER_SMOOTH_NORMAL; - shader_setup_from_sample( - kg, - sd, - P, - Ng, - I, - shader, - object, - prim, - u, - v, - 0.0f, - 0.5f, - !(kernel_tex_fetch(__object_flag, object) & SD_OBJECT_TRANSFORM_APPLIED), - LAMP_NONE); + shader_setup_from_sample(kg, + sd, + P, + Ng, + I, + shader, + object, + prim, + u, + v, + 0.0f, + 0.5f, + !(kernel_data_fetch(object_flag, object) & SD_OBJECT_TRANSFORM_APPLIED), + LAMP_NONE); } /* ShaderData setup for point on curve. */ @@ -300,18 +299,18 @@ ccl_device void shader_setup_from_curve(KernelGlobals kg, sd->ray_length = 0.0f; /* Shader */ - sd->shader = kernel_tex_fetch(__curves, prim).shader_id; - sd->flag = kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).flags; + sd->shader = kernel_data_fetch(curves, prim).shader_id; + sd->flag = kernel_data_fetch(shaders, (sd->shader & SHADER_MASK)).flags; /* Object */ sd->object = object; - sd->object_flag = kernel_tex_fetch(__object_flag, sd->object); + sd->object_flag = kernel_data_fetch(object_flag, sd->object); #ifdef __OBJECT_MOTION__ shader_setup_object_transforms(kg, sd, sd->time); #endif /* Get control points. */ - KernelCurve kcurve = kernel_tex_fetch(__curves, prim); + KernelCurve kcurve = kernel_data_fetch(curves, prim); int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(sd->type); int k1 = k0 + 1; @@ -320,10 +319,10 @@ ccl_device void shader_setup_from_curve(KernelGlobals kg, float4 P_curve[4]; - P_curve[0] = kernel_tex_fetch(__curve_keys, ka); - P_curve[1] = kernel_tex_fetch(__curve_keys, k0); - P_curve[2] = kernel_tex_fetch(__curve_keys, k1); - P_curve[3] = kernel_tex_fetch(__curve_keys, kb); + P_curve[0] = kernel_data_fetch(curve_keys, ka); + P_curve[1] = kernel_data_fetch(curve_keys, k0); + P_curve[2] = kernel_data_fetch(curve_keys, k1); + P_curve[3] = kernel_data_fetch(curve_keys, kb); /* Interpolate position and tangent. */ sd->P = float4_to_float3(catmull_rom_basis_derivative(P_curve, sd->u)); @@ -373,7 +372,7 @@ ccl_device_inline void shader_setup_from_background(KernelGlobals kg, sd->Ng = -ray_D; sd->I = -ray_D; sd->shader = kernel_data.background.surface_shader; - sd->flag = kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).flags; + sd->flag = kernel_data_fetch(shaders, (sd->shader & SHADER_MASK)).flags; sd->object_flag = 0; sd->time = ray_time; sd->ray_length = 0.0f; diff --git a/intern/cycles/kernel/geom/subd_triangle.h b/intern/cycles/kernel/geom/subd_triangle.h index 24e1e454b8c..8b73b342e16 100644 --- a/intern/cycles/kernel/geom/subd_triangle.h +++ b/intern/cycles/kernel/geom/subd_triangle.h @@ -13,11 +13,11 @@ ccl_device_inline void subd_triangle_patch_uv(KernelGlobals kg, ccl_private const ShaderData *sd, float2 uv[3]) { - uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); + uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim); - uv[0] = kernel_tex_fetch(__tri_patch_uv, tri_vindex.x); - uv[1] = kernel_tex_fetch(__tri_patch_uv, tri_vindex.y); - uv[2] = kernel_tex_fetch(__tri_patch_uv, tri_vindex.z); + uv[0] = kernel_data_fetch(tri_patch_uv, tri_vindex.x); + uv[1] = kernel_data_fetch(tri_patch_uv, tri_vindex.y); + uv[2] = kernel_data_fetch(tri_patch_uv, tri_vindex.z); } /* Vertex indices of patch */ @@ -26,10 +26,10 @@ ccl_device_inline uint4 subd_triangle_patch_indices(KernelGlobals kg, int patch) { uint4 indices; - indices.x = kernel_tex_fetch(__patches, patch + 0); - indices.y = kernel_tex_fetch(__patches, patch + 1); - indices.z = kernel_tex_fetch(__patches, patch + 2); - indices.w = kernel_tex_fetch(__patches, patch + 3); + indices.x = kernel_data_fetch(patches, patch + 0); + indices.y = kernel_data_fetch(patches, patch + 1); + indices.z = kernel_data_fetch(patches, patch + 2); + indices.w = kernel_data_fetch(patches, patch + 3); return indices; } @@ -38,14 +38,14 @@ ccl_device_inline uint4 subd_triangle_patch_indices(KernelGlobals kg, int patch) ccl_device_inline uint subd_triangle_patch_face(KernelGlobals kg, int patch) { - return kernel_tex_fetch(__patches, patch + 4); + return kernel_data_fetch(patches, patch + 4); } /* Number of corners on originating face */ ccl_device_inline uint subd_triangle_patch_num_corners(KernelGlobals kg, int patch) { - return kernel_tex_fetch(__patches, patch + 5) & 0xffff; + return kernel_data_fetch(patches, patch + 5) & 0xffff; } /* Indices of the four corners that are used by the patch */ @@ -54,10 +54,10 @@ ccl_device_inline void subd_triangle_patch_corners(KernelGlobals kg, int patch, { uint4 data; - data.x = kernel_tex_fetch(__patches, patch + 4); - data.y = kernel_tex_fetch(__patches, patch + 5); - data.z = kernel_tex_fetch(__patches, patch + 6); - data.w = kernel_tex_fetch(__patches, patch + 7); + data.x = kernel_data_fetch(patches, patch + 4); + data.y = kernel_data_fetch(patches, patch + 5); + data.z = kernel_data_fetch(patches, patch + 6); + data.w = kernel_data_fetch(patches, patch + 7); int num_corners = data.y & 0xffff; @@ -141,7 +141,7 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals kg, if (dy) *dy = 0.0f; - return kernel_tex_fetch(__attributes_float, desc.offset + subd_triangle_patch_face(kg, patch)); + return kernel_data_fetch(attributes_float, desc.offset + subd_triangle_patch_face(kg, patch)); } else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { float2 uv[3]; @@ -149,10 +149,10 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals kg, uint4 v = subd_triangle_patch_indices(kg, patch); - float f0 = kernel_tex_fetch(__attributes_float, desc.offset + v.x); - float f1 = kernel_tex_fetch(__attributes_float, desc.offset + v.y); - float f2 = kernel_tex_fetch(__attributes_float, desc.offset + v.z); - float f3 = kernel_tex_fetch(__attributes_float, desc.offset + v.w); + float f0 = kernel_data_fetch(attributes_float, desc.offset + v.x); + float f1 = kernel_data_fetch(attributes_float, desc.offset + v.y); + float f2 = kernel_data_fetch(attributes_float, desc.offset + v.z); + float f3 = kernel_data_fetch(attributes_float, desc.offset + v.w); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -179,10 +179,10 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals kg, int corners[4]; subd_triangle_patch_corners(kg, patch, corners); - float f0 = kernel_tex_fetch(__attributes_float, corners[0] + desc.offset); - float f1 = kernel_tex_fetch(__attributes_float, corners[1] + desc.offset); - float f2 = kernel_tex_fetch(__attributes_float, corners[2] + desc.offset); - float f3 = kernel_tex_fetch(__attributes_float, corners[3] + desc.offset); + float f0 = kernel_data_fetch(attributes_float, corners[0] + desc.offset); + float f1 = kernel_data_fetch(attributes_float, corners[1] + desc.offset); + float f2 = kernel_data_fetch(attributes_float, corners[2] + desc.offset); + float f3 = kernel_data_fetch(attributes_float, corners[3] + desc.offset); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -208,7 +208,7 @@ ccl_device_noinline float subd_triangle_attribute_float(KernelGlobals kg, if (dy) *dy = 0.0f; - return kernel_tex_fetch(__attributes_float, desc.offset); + return kernel_data_fetch(attributes_float, desc.offset); } else { if (dx) @@ -281,8 +281,7 @@ ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals kg, if (dy) *dy = make_float2(0.0f, 0.0f); - return kernel_tex_fetch(__attributes_float2, - desc.offset + subd_triangle_patch_face(kg, patch)); + return kernel_data_fetch(attributes_float2, desc.offset + subd_triangle_patch_face(kg, patch)); } else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { float2 uv[3]; @@ -290,10 +289,10 @@ ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals kg, uint4 v = subd_triangle_patch_indices(kg, patch); - float2 f0 = kernel_tex_fetch(__attributes_float2, desc.offset + v.x); - float2 f1 = kernel_tex_fetch(__attributes_float2, desc.offset + v.y); - float2 f2 = kernel_tex_fetch(__attributes_float2, desc.offset + v.z); - float2 f3 = kernel_tex_fetch(__attributes_float2, desc.offset + v.w); + float2 f0 = kernel_data_fetch(attributes_float2, desc.offset + v.x); + float2 f1 = kernel_data_fetch(attributes_float2, desc.offset + v.y); + float2 f2 = kernel_data_fetch(attributes_float2, desc.offset + v.z); + float2 f3 = kernel_data_fetch(attributes_float2, desc.offset + v.w); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -322,10 +321,10 @@ ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals kg, float2 f0, f1, f2, f3; - f0 = kernel_tex_fetch(__attributes_float2, corners[0] + desc.offset); - f1 = kernel_tex_fetch(__attributes_float2, corners[1] + desc.offset); - f2 = kernel_tex_fetch(__attributes_float2, corners[2] + desc.offset); - f3 = kernel_tex_fetch(__attributes_float2, corners[3] + desc.offset); + f0 = kernel_data_fetch(attributes_float2, corners[0] + desc.offset); + f1 = kernel_data_fetch(attributes_float2, corners[1] + desc.offset); + f2 = kernel_data_fetch(attributes_float2, corners[2] + desc.offset); + f3 = kernel_data_fetch(attributes_float2, corners[3] + desc.offset); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -351,7 +350,7 @@ ccl_device_noinline float2 subd_triangle_attribute_float2(KernelGlobals kg, if (dy) *dy = make_float2(0.0f, 0.0f); - return kernel_tex_fetch(__attributes_float2, desc.offset); + return kernel_data_fetch(attributes_float2, desc.offset); } else { if (dx) @@ -423,8 +422,7 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals kg, if (dy) *dy = make_float3(0.0f, 0.0f, 0.0f); - return kernel_tex_fetch(__attributes_float3, - desc.offset + subd_triangle_patch_face(kg, patch)); + return kernel_data_fetch(attributes_float3, desc.offset + subd_triangle_patch_face(kg, patch)); } else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { float2 uv[3]; @@ -432,10 +430,10 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals kg, uint4 v = subd_triangle_patch_indices(kg, patch); - float3 f0 = kernel_tex_fetch(__attributes_float3, desc.offset + v.x); - float3 f1 = kernel_tex_fetch(__attributes_float3, desc.offset + v.y); - float3 f2 = kernel_tex_fetch(__attributes_float3, desc.offset + v.z); - float3 f3 = kernel_tex_fetch(__attributes_float3, desc.offset + v.w); + float3 f0 = kernel_data_fetch(attributes_float3, desc.offset + v.x); + float3 f1 = kernel_data_fetch(attributes_float3, desc.offset + v.y); + float3 f2 = kernel_data_fetch(attributes_float3, desc.offset + v.z); + float3 f3 = kernel_data_fetch(attributes_float3, desc.offset + v.w); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -464,10 +462,10 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals kg, float3 f0, f1, f2, f3; - f0 = kernel_tex_fetch(__attributes_float3, corners[0] + desc.offset); - f1 = kernel_tex_fetch(__attributes_float3, corners[1] + desc.offset); - f2 = kernel_tex_fetch(__attributes_float3, corners[2] + desc.offset); - f3 = kernel_tex_fetch(__attributes_float3, corners[3] + desc.offset); + f0 = kernel_data_fetch(attributes_float3, corners[0] + desc.offset); + f1 = kernel_data_fetch(attributes_float3, corners[1] + desc.offset); + f2 = kernel_data_fetch(attributes_float3, corners[2] + desc.offset); + f3 = kernel_data_fetch(attributes_float3, corners[3] + desc.offset); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -493,7 +491,7 @@ ccl_device_noinline float3 subd_triangle_attribute_float3(KernelGlobals kg, if (dy) *dy = make_float3(0.0f, 0.0f, 0.0f); - return kernel_tex_fetch(__attributes_float3, desc.offset); + return kernel_data_fetch(attributes_float3, desc.offset); } else { if (dx) @@ -570,8 +568,7 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals kg, if (dy) *dy = zero_float4(); - return kernel_tex_fetch(__attributes_float4, - desc.offset + subd_triangle_patch_face(kg, patch)); + return kernel_data_fetch(attributes_float4, desc.offset + subd_triangle_patch_face(kg, patch)); } else if (desc.element == ATTR_ELEMENT_VERTEX || desc.element == ATTR_ELEMENT_VERTEX_MOTION) { float2 uv[3]; @@ -579,10 +576,10 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals kg, uint4 v = subd_triangle_patch_indices(kg, patch); - float4 f0 = kernel_tex_fetch(__attributes_float4, desc.offset + v.x); - float4 f1 = kernel_tex_fetch(__attributes_float4, desc.offset + v.y); - float4 f2 = kernel_tex_fetch(__attributes_float4, desc.offset + v.z); - float4 f3 = kernel_tex_fetch(__attributes_float4, desc.offset + v.w); + float4 f0 = kernel_data_fetch(attributes_float4, desc.offset + v.x); + float4 f1 = kernel_data_fetch(attributes_float4, desc.offset + v.y); + float4 f2 = kernel_data_fetch(attributes_float4, desc.offset + v.z); + float4 f3 = kernel_data_fetch(attributes_float4, desc.offset + v.w); if (subd_triangle_patch_num_corners(kg, patch) != 4) { f1 = (f1 + f0) * 0.5f; @@ -613,19 +610,19 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals kg, if (desc.element == ATTR_ELEMENT_CORNER_BYTE) { f0 = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[0] + desc.offset))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[0] + desc.offset))); f1 = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[1] + desc.offset))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[1] + desc.offset))); f2 = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[2] + desc.offset))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[2] + desc.offset))); f3 = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, corners[3] + desc.offset))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, corners[3] + desc.offset))); } else { - f0 = kernel_tex_fetch(__attributes_float4, corners[0] + desc.offset); - f1 = kernel_tex_fetch(__attributes_float4, corners[1] + desc.offset); - f2 = kernel_tex_fetch(__attributes_float4, corners[2] + desc.offset); - f3 = kernel_tex_fetch(__attributes_float4, corners[3] + desc.offset); + f0 = kernel_data_fetch(attributes_float4, corners[0] + desc.offset); + f1 = kernel_data_fetch(attributes_float4, corners[1] + desc.offset); + f2 = kernel_data_fetch(attributes_float4, corners[2] + desc.offset); + f3 = kernel_data_fetch(attributes_float4, corners[3] + desc.offset); } if (subd_triangle_patch_num_corners(kg, patch) != 4) { @@ -652,7 +649,7 @@ ccl_device_noinline float4 subd_triangle_attribute_float4(KernelGlobals kg, if (dy) *dy = zero_float4(); - return kernel_tex_fetch(__attributes_float4, desc.offset); + return kernel_data_fetch(attributes_float4, desc.offset); } else { if (dx) diff --git a/intern/cycles/kernel/geom/triangle.h b/intern/cycles/kernel/geom/triangle.h index 8ac7e67ff05..788bfaca7cf 100644 --- a/intern/cycles/kernel/geom/triangle.h +++ b/intern/cycles/kernel/geom/triangle.h @@ -15,10 +15,10 @@ CCL_NAMESPACE_BEGIN ccl_device_inline float3 triangle_normal(KernelGlobals kg, ccl_private ShaderData *sd) { /* load triangle vertices */ - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); - const float3 v0 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 0); - const float3 v1 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 1); - const float3 v2 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 2); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim); + const float3 v0 = kernel_data_fetch(tri_verts, tri_vindex.w + 0); + const float3 v1 = kernel_data_fetch(tri_verts, tri_vindex.w + 1); + const float3 v2 = kernel_data_fetch(tri_verts, tri_vindex.w + 2); /* return normal */ if (sd->object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) { @@ -40,15 +40,15 @@ ccl_device_inline void triangle_point_normal(KernelGlobals kg, ccl_private int *shader) { /* load triangle vertices */ - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); - float3 v0 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 0); - float3 v1 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 1); - float3 v2 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 2); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); + float3 v0 = kernel_data_fetch(tri_verts, tri_vindex.w + 0); + float3 v1 = kernel_data_fetch(tri_verts, tri_vindex.w + 1); + float3 v2 = kernel_data_fetch(tri_verts, tri_vindex.w + 2); /* compute point */ float t = 1.0f - u - v; *P = (u * v0 + v * v1 + t * v2); /* get object flags */ - int object_flag = kernel_tex_fetch(__object_flag, object); + int object_flag = kernel_data_fetch(object_flag, object); /* compute normal */ if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) { *Ng = normalize(cross(v2 - v0, v1 - v0)); @@ -57,17 +57,17 @@ ccl_device_inline void triangle_point_normal(KernelGlobals kg, *Ng = normalize(cross(v1 - v0, v2 - v0)); } /* shader`*/ - *shader = kernel_tex_fetch(__tri_shader, prim); + *shader = kernel_data_fetch(tri_shader, prim); } /* Triangle vertex locations */ ccl_device_inline void triangle_vertices(KernelGlobals kg, int prim, float3 P[3]) { - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); - P[0] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 0); - P[1] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 1); - P[2] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 2); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); + P[0] = kernel_data_fetch(tri_verts, tri_vindex.w + 0); + P[1] = kernel_data_fetch(tri_verts, tri_vindex.w + 1); + P[2] = kernel_data_fetch(tri_verts, tri_vindex.w + 2); } /* Triangle vertex locations and vertex normals */ @@ -77,13 +77,13 @@ ccl_device_inline void triangle_vertices_and_normals(KernelGlobals kg, float3 P[3], float3 N[3]) { - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); - P[0] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 0); - P[1] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 1); - P[2] = kernel_tex_fetch(__tri_verts, tri_vindex.w + 2); - N[0] = kernel_tex_fetch(__tri_vnormal, tri_vindex.x); - N[1] = kernel_tex_fetch(__tri_vnormal, tri_vindex.y); - N[2] = kernel_tex_fetch(__tri_vnormal, tri_vindex.z); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); + P[0] = kernel_data_fetch(tri_verts, tri_vindex.w + 0); + P[1] = kernel_data_fetch(tri_verts, tri_vindex.w + 1); + P[2] = kernel_data_fetch(tri_verts, tri_vindex.w + 2); + N[0] = kernel_data_fetch(tri_vnormal, tri_vindex.x); + N[1] = kernel_data_fetch(tri_vnormal, tri_vindex.y); + N[2] = kernel_data_fetch(tri_vnormal, tri_vindex.z); } /* Interpolate smooth vertex normal from vertices */ @@ -92,10 +92,10 @@ ccl_device_inline float3 triangle_smooth_normal(KernelGlobals kg, float3 Ng, int prim, float u, float v) { /* load triangle vertices */ - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); - float3 n0 = kernel_tex_fetch(__tri_vnormal, tri_vindex.x); - float3 n1 = kernel_tex_fetch(__tri_vnormal, tri_vindex.y); - float3 n2 = kernel_tex_fetch(__tri_vnormal, tri_vindex.z); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); + float3 n0 = kernel_data_fetch(tri_vnormal, tri_vindex.x); + float3 n1 = kernel_data_fetch(tri_vnormal, tri_vindex.y); + float3 n2 = kernel_data_fetch(tri_vnormal, tri_vindex.z); float3 N = safe_normalize((1.0f - u - v) * n2 + u * n0 + v * n1); @@ -106,10 +106,10 @@ ccl_device_inline float3 triangle_smooth_normal_unnormalized( KernelGlobals kg, ccl_private const ShaderData *sd, float3 Ng, int prim, float u, float v) { /* load triangle vertices */ - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); - float3 n0 = kernel_tex_fetch(__tri_vnormal, tri_vindex.x); - float3 n1 = kernel_tex_fetch(__tri_vnormal, tri_vindex.y); - float3 n2 = kernel_tex_fetch(__tri_vnormal, tri_vindex.z); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); + float3 n0 = kernel_data_fetch(tri_vnormal, tri_vindex.x); + float3 n1 = kernel_data_fetch(tri_vnormal, tri_vindex.y); + float3 n2 = kernel_data_fetch(tri_vnormal, tri_vindex.z); /* ensure that the normals are in object space */ if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) { @@ -131,10 +131,10 @@ ccl_device_inline void triangle_dPdudv(KernelGlobals kg, ccl_private float3 *dPdv) { /* fetch triangle vertex coordinates */ - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, prim); - const float3 p0 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 0); - const float3 p1 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 1); - const float3 p2 = kernel_tex_fetch(__tri_verts, tri_vindex.w + 2); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, prim); + const float3 p0 = kernel_data_fetch(tri_verts, tri_vindex.w + 0); + const float3 p1 = kernel_data_fetch(tri_verts, tri_vindex.w + 1); + const float3 p2 = kernel_data_fetch(tri_verts, tri_vindex.w + 2); /* compute derivatives of P w.r.t. uv */ *dPdu = (p0 - p2); @@ -153,16 +153,16 @@ ccl_device float triangle_attribute_float(KernelGlobals kg, float f0, f1, f2; if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) { - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); - f0 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.x); - f1 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.y); - f2 = kernel_tex_fetch(__attributes_float, desc.offset + tri_vindex.z); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim); + f0 = kernel_data_fetch(attributes_float, desc.offset + tri_vindex.x); + f1 = kernel_data_fetch(attributes_float, desc.offset + tri_vindex.y); + f2 = kernel_data_fetch(attributes_float, desc.offset + tri_vindex.z); } else { const int tri = desc.offset + sd->prim * 3; - f0 = kernel_tex_fetch(__attributes_float, tri + 0); - f1 = kernel_tex_fetch(__attributes_float, tri + 1); - f2 = kernel_tex_fetch(__attributes_float, tri + 2); + f0 = kernel_data_fetch(attributes_float, tri + 0); + f1 = kernel_data_fetch(attributes_float, tri + 1); + f2 = kernel_data_fetch(attributes_float, tri + 2); } #ifdef __RAY_DIFFERENTIALS__ @@ -185,7 +185,7 @@ ccl_device float triangle_attribute_float(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float, offset); + return kernel_data_fetch(attributes_float, offset); } else { return 0.0f; @@ -203,16 +203,16 @@ ccl_device float2 triangle_attribute_float2(KernelGlobals kg, float2 f0, f1, f2; if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) { - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); - f0 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.x); - f1 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.y); - f2 = kernel_tex_fetch(__attributes_float2, desc.offset + tri_vindex.z); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim); + f0 = kernel_data_fetch(attributes_float2, desc.offset + tri_vindex.x); + f1 = kernel_data_fetch(attributes_float2, desc.offset + tri_vindex.y); + f2 = kernel_data_fetch(attributes_float2, desc.offset + tri_vindex.z); } else { const int tri = desc.offset + sd->prim * 3; - f0 = kernel_tex_fetch(__attributes_float2, tri + 0); - f1 = kernel_tex_fetch(__attributes_float2, tri + 1); - f2 = kernel_tex_fetch(__attributes_float2, tri + 2); + f0 = kernel_data_fetch(attributes_float2, tri + 0); + f1 = kernel_data_fetch(attributes_float2, tri + 1); + f2 = kernel_data_fetch(attributes_float2, tri + 2); } #ifdef __RAY_DIFFERENTIALS__ @@ -235,7 +235,7 @@ ccl_device float2 triangle_attribute_float2(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float2, offset); + return kernel_data_fetch(attributes_float2, offset); } else { return make_float2(0.0f, 0.0f); @@ -253,16 +253,16 @@ ccl_device float3 triangle_attribute_float3(KernelGlobals kg, float3 f0, f1, f2; if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) { - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); - f0 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x); - f1 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y); - f2 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim); + f0 = kernel_data_fetch(attributes_float3, desc.offset + tri_vindex.x); + f1 = kernel_data_fetch(attributes_float3, desc.offset + tri_vindex.y); + f2 = kernel_data_fetch(attributes_float3, desc.offset + tri_vindex.z); } else { const int tri = desc.offset + sd->prim * 3; - f0 = kernel_tex_fetch(__attributes_float3, tri + 0); - f1 = kernel_tex_fetch(__attributes_float3, tri + 1); - f2 = kernel_tex_fetch(__attributes_float3, tri + 2); + f0 = kernel_data_fetch(attributes_float3, tri + 0); + f1 = kernel_data_fetch(attributes_float3, tri + 1); + f2 = kernel_data_fetch(attributes_float3, tri + 2); } #ifdef __RAY_DIFFERENTIALS__ @@ -285,7 +285,7 @@ ccl_device float3 triangle_attribute_float3(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float3, offset); + return kernel_data_fetch(attributes_float3, offset); } else { return make_float3(0.0f, 0.0f, 0.0f); @@ -304,25 +304,25 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals kg, float4 f0, f1, f2; if (desc.element & (ATTR_ELEMENT_VERTEX | ATTR_ELEMENT_VERTEX_MOTION)) { - const uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim); - f0 = kernel_tex_fetch(__attributes_float4, desc.offset + tri_vindex.x); - f1 = kernel_tex_fetch(__attributes_float4, desc.offset + tri_vindex.y); - f2 = kernel_tex_fetch(__attributes_float4, desc.offset + tri_vindex.z); + const uint4 tri_vindex = kernel_data_fetch(tri_vindex, sd->prim); + f0 = kernel_data_fetch(attributes_float4, desc.offset + tri_vindex.x); + f1 = kernel_data_fetch(attributes_float4, desc.offset + tri_vindex.y); + f2 = kernel_data_fetch(attributes_float4, desc.offset + tri_vindex.z); } else { const int tri = desc.offset + sd->prim * 3; if (desc.element == ATTR_ELEMENT_CORNER) { - f0 = kernel_tex_fetch(__attributes_float4, tri + 0); - f1 = kernel_tex_fetch(__attributes_float4, tri + 1); - f2 = kernel_tex_fetch(__attributes_float4, tri + 2); + f0 = kernel_data_fetch(attributes_float4, tri + 0); + f1 = kernel_data_fetch(attributes_float4, tri + 1); + f2 = kernel_data_fetch(attributes_float4, tri + 2); } else { f0 = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, tri + 0))); f1 = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, tri + 1))); f2 = color_srgb_to_linear_v4( - color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2))); + color_uchar4_to_float4(kernel_data_fetch(attributes_uchar4, tri + 2))); } } @@ -346,7 +346,7 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals kg, if (desc.element & (ATTR_ELEMENT_FACE | ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { const int offset = (desc.element == ATTR_ELEMENT_FACE) ? desc.offset + sd->prim : desc.offset; - return kernel_tex_fetch(__attributes_float4, offset); + return kernel_data_fetch(attributes_float4, offset); } else { return zero_float4(); diff --git a/intern/cycles/kernel/geom/triangle_intersect.h b/intern/cycles/kernel/geom/triangle_intersect.h index fe531e6868a..0c76de9ccc7 100644 --- a/intern/cycles/kernel/geom/triangle_intersect.h +++ b/intern/cycles/kernel/geom/triangle_intersect.h @@ -23,17 +23,17 @@ ccl_device_inline bool triangle_intersect(KernelGlobals kg, int prim, int prim_addr) { - const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w; - const float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), - tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), - tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); + const uint tri_vindex = kernel_data_fetch(tri_vindex, prim).w; + const float3 tri_a = kernel_data_fetch(tri_verts, tri_vindex + 0), + tri_b = kernel_data_fetch(tri_verts, tri_vindex + 1), + tri_c = kernel_data_fetch(tri_verts, tri_vindex + 2); float t, u, v; if (ray_triangle_intersect(P, dir, tmax, tri_a, tri_b, tri_c, &u, &v, &t)) { #ifdef __VISIBILITY_FLAG__ /* Visibility flag test. we do it here under the assumption * that most triangles are culled by node flags. */ - if (kernel_tex_fetch(__prim_visibility, prim_addr) & visibility) + if (kernel_data_fetch(prim_visibility, prim_addr) & visibility) #endif { isect->object = object; @@ -66,10 +66,10 @@ ccl_device_inline bool triangle_intersect_local(KernelGlobals kg, ccl_private uint *lcg_state, int max_hits) { - const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w; - const float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), - tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), - tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); + const uint tri_vindex = kernel_data_fetch(tri_vindex, prim).w; + const float3 tri_a = kernel_data_fetch(tri_verts, tri_vindex + 0), + tri_b = kernel_data_fetch(tri_verts, tri_vindex + 1), + tri_c = kernel_data_fetch(tri_verts, tri_vindex + 2); float t, u, v; if (!ray_triangle_intersect(P, dir, tmax, tri_a, tri_b, tri_c, &u, &v, &t)) { return false; @@ -139,10 +139,10 @@ ccl_device_inline float3 triangle_point_from_uv(KernelGlobals kg, const float u, const float v) { - const uint tri_vindex = kernel_tex_fetch(__tri_vindex, isect_prim).w; - const packed_float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0), - tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1), - tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2); + const uint tri_vindex = kernel_data_fetch(tri_vindex, isect_prim).w; + const packed_float3 tri_a = kernel_data_fetch(tri_verts, tri_vindex + 0), + tri_b = kernel_data_fetch(tri_verts, tri_vindex + 1), + tri_c = kernel_data_fetch(tri_verts, tri_vindex + 2); float w = 1.0f - u - v; float3 P = u * tri_a + v * tri_b + w * tri_c; diff --git a/intern/cycles/kernel/geom/volume.h b/intern/cycles/kernel/geom/volume.h index 22715dee5bf..3510a905def 100644 --- a/intern/cycles/kernel/geom/volume.h +++ b/intern/cycles/kernel/geom/volume.h @@ -62,7 +62,7 @@ ccl_device float4 volume_attribute_float4(KernelGlobals kg, const AttributeDescriptor desc) { if (desc.element & (ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) { - return kernel_tex_fetch(__attributes_float4, desc.offset); + return kernel_data_fetch(attributes_float4, desc.offset); } else if (desc.element == ATTR_ELEMENT_VOXEL) { /* todo: optimize this so we don't have to transform both here and in diff --git a/intern/cycles/kernel/integrator/init_from_bake.h b/intern/cycles/kernel/integrator/init_from_bake.h index 0db4241b6e3..7d53bf479bf 100644 --- a/intern/cycles/kernel/integrator/init_from_bake.h +++ b/intern/cycles/kernel/integrator/init_from_bake.h @@ -160,7 +160,7 @@ ccl_device bool integrator_init_from_bake(KernelGlobals kg, int shader; triangle_point_normal(kg, object, prim, u, v, &P, &Ng, &shader); - const int object_flag = kernel_tex_fetch(__object_flag, object); + const int object_flag = kernel_data_fetch(object_flag, object); if (!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) { Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM); P = transform_point_auto(&tfm, P); @@ -193,7 +193,7 @@ ccl_device bool integrator_init_from_bake(KernelGlobals kg, } const int shader_index = shader & SHADER_MASK; - const int shader_flags = kernel_tex_fetch(__shaders, shader_index).flags; + const int shader_flags = kernel_data_fetch(shaders, shader_index).flags; /* Fast path for position and normal passes not affected by shaders. */ if (kernel_data.film.pass_position != PASS_UNUSED) { diff --git a/intern/cycles/kernel/integrator/intersect_closest.h b/intern/cycles/kernel/integrator/intersect_closest.h index 2dfac44b414..621aa05f46b 100644 --- a/intern/cycles/kernel/integrator/intersect_closest.h +++ b/intern/cycles/kernel/integrator/intersect_closest.h @@ -122,7 +122,7 @@ ccl_device_forceinline void integrator_split_shadow_catcher( /* Continue with shading shadow catcher surface. */ const int shader = intersection_get_shader(kg, isect); - const int flags = kernel_tex_fetch(__shaders, shader).flags; + const int flags = kernel_data_fetch(shaders, shader).flags; const bool use_caustics = kernel_data.integrator.use_caustics && (object_flags & SD_OBJECT_CAUSTICS); const bool use_raytrace_kernel = (flags & SD_HAS_RAYTRACE); @@ -149,7 +149,7 @@ ccl_device_forceinline void integrator_intersect_next_kernel_after_shadow_catche integrator_state_read_isect(kg, state, &isect); const int shader = intersection_get_shader(kg, &isect); - const int flags = kernel_tex_fetch(__shaders, shader).flags; + const int flags = kernel_data_fetch(shaders, shader).flags; const int object_flags = intersection_get_object_flags(kg, &isect); const bool use_caustics = kernel_data.integrator.use_caustics && (object_flags & SD_OBJECT_CAUSTICS); @@ -203,7 +203,7 @@ ccl_device_forceinline void integrator_intersect_next_kernel( if (!integrator_state_volume_stack_is_empty(kg, state)) { const bool hit_surface = hit && !(isect->type & PRIMITIVE_LAMP); const int shader = (hit_surface) ? intersection_get_shader(kg, isect) : SHADER_NONE; - const int flags = (hit_surface) ? kernel_tex_fetch(__shaders, shader).flags : 0; + const int flags = (hit_surface) ? kernel_data_fetch(shaders, shader).flags : 0; if (!integrator_intersect_terminate(kg, state, flags)) { INTEGRATOR_PATH_NEXT(current_kernel, DEVICE_KERNEL_INTEGRATOR_SHADE_VOLUME); @@ -223,7 +223,7 @@ ccl_device_forceinline void integrator_intersect_next_kernel( else { /* Hit a surface, continue with surface kernel unless terminated. */ const int shader = intersection_get_shader(kg, isect); - const int flags = kernel_tex_fetch(__shaders, shader).flags; + const int flags = kernel_data_fetch(shaders, shader).flags; if (!integrator_intersect_terminate(kg, state, flags)) { const int object_flags = intersection_get_object_flags(kg, isect); @@ -279,7 +279,7 @@ ccl_device_forceinline void integrator_intersect_next_kernel_after_volume( else { /* Hit a surface, continue with surface kernel unless terminated. */ const int shader = intersection_get_shader(kg, isect); - const int flags = kernel_tex_fetch(__shaders, shader).flags; + const int flags = kernel_data_fetch(shaders, shader).flags; const int object_flags = intersection_get_object_flags(kg, isect); const bool use_caustics = kernel_data.integrator.use_caustics && (object_flags & SD_OBJECT_CAUSTICS); @@ -332,7 +332,7 @@ ccl_device void integrator_intersect_closest(KernelGlobals kg, ray.t = kernel_data.integrator.ao_bounces_distance; if (last_isect_object != OBJECT_NONE) { - const float object_ao_distance = kernel_tex_fetch(__objects, last_isect_object).ao_distance; + const float object_ao_distance = kernel_data_fetch(objects, last_isect_object).ao_distance; if (object_ao_distance != 0.0f) { ray.t = object_ao_distance; } @@ -366,7 +366,7 @@ ccl_device void integrator_intersect_closest(KernelGlobals kg, bool from_caustic_caster = false; bool from_caustic_receiver = false; if (!(path_flag & PATH_RAY_CAMERA) && last_isect_object != OBJECT_NONE) { - const int object_flags = kernel_tex_fetch(__object_flag, last_isect_object); + const int object_flags = kernel_data_fetch(object_flag, last_isect_object); from_caustic_receiver = (object_flags & SD_OBJECT_CAUSTICS_RECEIVER); from_caustic_caster = (object_flags & SD_OBJECT_CAUSTICS_CASTER); } diff --git a/intern/cycles/kernel/integrator/mnee.h b/intern/cycles/kernel/integrator/mnee.h index ad83f82d091..75d30a0aeff 100644 --- a/intern/cycles/kernel/integrator/mnee.h +++ b/intern/cycles/kernel/integrator/mnee.h @@ -115,7 +115,7 @@ ccl_device_forceinline void mnee_update_light_sample(KernelGlobals kg, { /* correct light sample position/direction and pdf * NOTE: preserve pdf in area measure */ - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, ls->lamp); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, ls->lamp); if (ls->type == LIGHT_POINT || ls->type == LIGHT_SPOT) { ls->D = normalize_len(ls->P - P, &ls->t); @@ -154,12 +154,12 @@ ccl_device_forceinline void mnee_setup_manifold_vertex(KernelGlobals kg, ccl_private const Intersection *isect, ccl_private ShaderData *sd_vtx) { - sd_vtx->object = (isect->object == OBJECT_NONE) ? kernel_tex_fetch(__prim_object, isect->prim) : + sd_vtx->object = (isect->object == OBJECT_NONE) ? kernel_data_fetch(prim_object, isect->prim) : isect->object; sd_vtx->type = isect->type; sd_vtx->flag = 0; - sd_vtx->object_flag = kernel_tex_fetch(__object_flag, sd_vtx->object); + sd_vtx->object_flag = kernel_data_fetch(object_flag, sd_vtx->object); /* Matrices and time. */ shader_setup_object_transforms(kg, sd_vtx, ray->time); @@ -171,7 +171,7 @@ ccl_device_forceinline void mnee_setup_manifold_vertex(KernelGlobals kg, sd_vtx->u = isect->u; sd_vtx->v = isect->v; - sd_vtx->shader = kernel_tex_fetch(__tri_shader, sd_vtx->prim); + sd_vtx->shader = kernel_data_fetch(tri_shader, sd_vtx->prim); float3 verts[3]; float3 normals[3]; @@ -509,7 +509,7 @@ ccl_device_forceinline bool mnee_newton_solver(KernelGlobals kg, break; int hit_object = (projection_isect.object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, projection_isect.prim) : + kernel_data_fetch(prim_object, projection_isect.prim) : projection_isect.object; if (hit_object == mv.object) { @@ -870,7 +870,7 @@ ccl_device_forceinline bool mnee_path_contribution(KernelGlobals kg, probe_ray.D = normalize_len(v.p - probe_ray.P, &probe_ray.t); if (scene_intersect(kg, &probe_ray, PATH_RAY_TRANSMIT, &probe_isect)) { int hit_object = (probe_isect.object == OBJECT_NONE) ? - kernel_tex_fetch(__prim_object, probe_isect.prim) : + kernel_data_fetch(prim_object, probe_isect.prim) : probe_isect.object; /* Test whether the ray hit the appropriate object at its intended location. */ if (hit_object != v.object || fabsf(probe_ray.t - probe_isect.t) > MNEE_MIN_DISTANCE) diff --git a/intern/cycles/kernel/integrator/shade_background.h b/intern/cycles/kernel/integrator/shade_background.h index 72ecf67e8a0..4791a963ae6 100644 --- a/intern/cycles/kernel/integrator/shade_background.h +++ b/intern/cycles/kernel/integrator/shade_background.h @@ -107,7 +107,7 @@ ccl_device_inline void integrate_background(KernelGlobals kg, for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) { /* This path should have been resolved with mnee, it will * generate a firefly for small lights since it is improbable. */ - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp); if (klight->type == LIGHT_BACKGROUND && klight->use_caustics) { eval_background = false; break; @@ -160,7 +160,7 @@ ccl_device_inline void integrate_distant_lights(KernelGlobals kg, if (INTEGRATOR_STATE(state, path, mnee) & PATH_MNEE_CULL_LIGHT_CONNECTION) { /* This path should have been resolved with mnee, it will * generate a firefly for small lights since it is improbable. */ - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp); if (klight->use_caustics) return; } diff --git a/intern/cycles/kernel/integrator/shade_surface.h b/intern/cycles/kernel/integrator/shade_surface.h index ce1398859b7..e0a7f998a3f 100644 --- a/intern/cycles/kernel/integrator/shade_surface.h +++ b/intern/cycles/kernel/integrator/shade_surface.h @@ -141,7 +141,7 @@ ccl_device_forceinline void integrate_surface_direct_light(KernelGlobals kg, { if (ls.lamp != LAMP_NONE) { /* Is this a caustic light? */ - const bool use_caustics = kernel_tex_fetch(__lights, ls.lamp).use_caustics; + const bool use_caustics = kernel_data_fetch(lights, ls.lamp).use_caustics; if (use_caustics) { /* Are we on a caustic caster? */ if (is_transmission && (sd->object_flag & SD_OBJECT_CAUSTICS_CASTER)) diff --git a/intern/cycles/kernel/integrator/shader_eval.h b/intern/cycles/kernel/integrator/shader_eval.h index 4da92929366..ed4d973e864 100644 --- a/intern/cycles/kernel/integrator/shader_eval.h +++ b/intern/cycles/kernel/integrator/shader_eval.h @@ -528,12 +528,12 @@ ccl_device bool shader_constant_emission_eval(KernelGlobals kg, ccl_private float3 *eval) { int shader_index = shader & SHADER_MASK; - int shader_flag = kernel_tex_fetch(__shaders, shader_index).flags; + int shader_flag = kernel_data_fetch(shaders, shader_index).flags; if (shader_flag & SD_HAS_CONSTANT_EMISSION) { - *eval = make_float3(kernel_tex_fetch(__shaders, shader_index).constant_emission[0], - kernel_tex_fetch(__shaders, shader_index).constant_emission[1], - kernel_tex_fetch(__shaders, shader_index).constant_emission[2]); + *eval = make_float3(kernel_data_fetch(shaders, shader_index).constant_emission[0], + kernel_data_fetch(shaders, shader_index).constant_emission[1], + kernel_data_fetch(shaders, shader_index).constant_emission[2]); return true; } @@ -821,11 +821,11 @@ ccl_device_inline void shader_eval_volume(KernelGlobals kg, sd->shader = entry.shader; sd->flag &= ~SD_SHADER_FLAGS; - sd->flag |= kernel_tex_fetch(__shaders, (sd->shader & SHADER_MASK)).flags; + sd->flag |= kernel_data_fetch(shaders, (sd->shader & SHADER_MASK)).flags; sd->object_flag &= ~SD_OBJECT_FLAGS; if (sd->object != OBJECT_NONE) { - sd->object_flag |= kernel_tex_fetch(__object_flag, sd->object); + sd->object_flag |= kernel_data_fetch(object_flag, sd->object); # ifdef __OBJECT_MOTION__ /* todo: this is inefficient for motion blur, we should be @@ -837,7 +837,7 @@ ccl_device_inline void shader_eval_volume(KernelGlobals kg, kernel_assert(v_desc.offset != ATTR_STD_NOT_FOUND); const float3 P = sd->P; - const float velocity_scale = kernel_tex_fetch(__objects, sd->object).velocity_scale; + const float velocity_scale = kernel_data_fetch(objects, sd->object).velocity_scale; const float time_offset = kernel_data.cam.motion_position == MOTION_POSITION_CENTER ? 0.5f : 0.0f; @@ -946,7 +946,7 @@ ccl_device void shader_eval_displacement(KernelGlobals kg, ccl_device float shader_cryptomatte_id(KernelGlobals kg, int shader) { - return kernel_tex_fetch(__shaders, (shader & SHADER_MASK)).cryptomatte_id; + return kernel_data_fetch(shaders, (shader & SHADER_MASK)).cryptomatte_id; } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/integrator/subsurface.h b/intern/cycles/kernel/integrator/subsurface.h index b449f807290..1e6fcf4aff0 100644 --- a/intern/cycles/kernel/integrator/subsurface.h +++ b/intern/cycles/kernel/integrator/subsurface.h @@ -147,7 +147,7 @@ ccl_device_inline bool subsurface_scatter(KernelGlobals kg, IntegratorState stat /* Update volume stack if needed. */ if (kernel_data.integrator.use_volumes) { const int object = ss_isect.hits[0].object; - const int object_flag = kernel_tex_fetch(__object_flag, object); + const int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_INTERSECTS_VOLUME) { float3 P = INTEGRATOR_STATE(state, ray, P); @@ -170,7 +170,7 @@ ccl_device_inline bool subsurface_scatter(KernelGlobals kg, IntegratorState stat INTEGRATOR_STATE_WRITE(state, path, rng_offset) += PRNG_BOUNCE_NUM; const int shader = intersection_get_shader(kg, &ss_isect.hits[0]); - const int shader_flags = kernel_tex_fetch(__shaders, shader).flags; + const int shader_flags = kernel_data_fetch(shaders, shader).flags; const int object_flags = intersection_get_object_flags(kg, &ss_isect.hits[0]); const bool use_caustics = kernel_data.integrator.use_caustics && (object_flags & SD_OBJECT_CAUSTICS); diff --git a/intern/cycles/kernel/integrator/subsurface_disk.h b/intern/cycles/kernel/integrator/subsurface_disk.h index 34330671748..ae857c50493 100644 --- a/intern/cycles/kernel/integrator/subsurface_disk.h +++ b/intern/cycles/kernel/integrator/subsurface_disk.h @@ -113,7 +113,7 @@ ccl_device_inline bool subsurface_disk(KernelGlobals kg, for (int hit = 0; hit < num_eval_hits; hit++) { /* Get geometric normal. */ const int object = ss_isect.hits[hit].object; - const int object_flag = kernel_tex_fetch(__object_flag, object); + const int object_flag = kernel_data_fetch(object_flag, object); float3 hit_Ng = ss_isect.Ng[hit]; if (path_flag & PATH_RAY_SUBSURFACE_BACKFACING) { hit_Ng = -hit_Ng; diff --git a/intern/cycles/kernel/integrator/volume_stack.h b/intern/cycles/kernel/integrator/volume_stack.h index 5256349a0cc..97a0f0f386c 100644 --- a/intern/cycles/kernel/integrator/volume_stack.h +++ b/intern/cycles/kernel/integrator/volume_stack.h @@ -133,7 +133,7 @@ ccl_device float volume_stack_step_size(KernelGlobals kg, StackReadOp stack_read break; } - int shader_flag = kernel_tex_fetch(__shaders, (entry.shader & SHADER_MASK)).flags; + int shader_flag = kernel_data_fetch(shaders, (entry.shader & SHADER_MASK)).flags; bool heterogeneous = false; @@ -146,7 +146,7 @@ ccl_device float volume_stack_step_size(KernelGlobals kg, StackReadOp stack_read * heterogeneous volume objects may be using the same shader. */ int object = entry.object; if (object != OBJECT_NONE) { - int object_flag = kernel_tex_fetch(__object_flag, object); + int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_HAS_VOLUME_ATTRIBUTES) { heterogeneous = true; } @@ -180,7 +180,7 @@ ccl_device VolumeSampleMethod volume_stack_sample_method(KernelGlobals kg, Integ break; } - int shader_flag = kernel_tex_fetch(__shaders, (entry.shader & SHADER_MASK)).flags; + int shader_flag = kernel_data_fetch(shaders, (entry.shader & SHADER_MASK)).flags; if (shader_flag & SD_VOLUME_MIS) { /* Multiple importance sampling. */ diff --git a/intern/cycles/kernel/light/background.h b/intern/cycles/kernel/light/background.h index 0cbf7fb76fe..2a97d43c9ce 100644 --- a/intern/cycles/kernel/light/background.h +++ b/intern/cycles/kernel/light/background.h @@ -31,7 +31,7 @@ ccl_device float3 background_map_sample(KernelGlobals kg, int step = count >> 1; int middle = first + step; - if (kernel_tex_fetch(__light_background_marginal_cdf, middle).y < randv) { + if (kernel_data_fetch(light_background_marginal_cdf, middle).y < randv) { first = middle + 1; count -= step + 1; } @@ -42,9 +42,9 @@ ccl_device float3 background_map_sample(KernelGlobals kg, int index_v = max(0, first - 1); kernel_assert(index_v >= 0 && index_v < res_y); - float2 cdf_v = kernel_tex_fetch(__light_background_marginal_cdf, index_v); - float2 cdf_next_v = kernel_tex_fetch(__light_background_marginal_cdf, index_v + 1); - float2 cdf_last_v = kernel_tex_fetch(__light_background_marginal_cdf, res_y); + float2 cdf_v = kernel_data_fetch(light_background_marginal_cdf, index_v); + float2 cdf_next_v = kernel_data_fetch(light_background_marginal_cdf, index_v + 1); + float2 cdf_last_v = kernel_data_fetch(light_background_marginal_cdf, res_y); /* importance-sampled V direction */ float dv = inverse_lerp(cdf_v.y, cdf_next_v.y, randv); @@ -57,7 +57,7 @@ ccl_device float3 background_map_sample(KernelGlobals kg, int step = count >> 1; int middle = first + step; - if (kernel_tex_fetch(__light_background_conditional_cdf, index_v * cdf_width + middle).y < + if (kernel_data_fetch(light_background_conditional_cdf, index_v * cdf_width + middle).y < randu) { first = middle + 1; count -= step + 1; @@ -69,12 +69,12 @@ ccl_device float3 background_map_sample(KernelGlobals kg, int index_u = max(0, first - 1); kernel_assert(index_u >= 0 && index_u < res_x); - float2 cdf_u = kernel_tex_fetch(__light_background_conditional_cdf, - index_v * cdf_width + index_u); - float2 cdf_next_u = kernel_tex_fetch(__light_background_conditional_cdf, - index_v * cdf_width + index_u + 1); - float2 cdf_last_u = kernel_tex_fetch(__light_background_conditional_cdf, - index_v * cdf_width + res_x); + float2 cdf_u = kernel_data_fetch(light_background_conditional_cdf, + index_v * cdf_width + index_u); + float2 cdf_next_u = kernel_data_fetch(light_background_conditional_cdf, + index_v * cdf_width + index_u + 1); + float2 cdf_last_u = kernel_data_fetch(light_background_conditional_cdf, + index_v * cdf_width + res_x); /* importance-sampled U direction */ float du = inverse_lerp(cdf_u.y, cdf_next_u.y, randu); @@ -112,9 +112,9 @@ ccl_device float background_map_pdf(KernelGlobals kg, float3 direction) int index_v = clamp(float_to_int(uv.y * res_y), 0, res_y - 1); /* pdfs in V direction */ - float2 cdf_last_u = kernel_tex_fetch(__light_background_conditional_cdf, - index_v * cdf_width + res_x); - float2 cdf_last_v = kernel_tex_fetch(__light_background_marginal_cdf, res_y); + float2 cdf_last_u = kernel_data_fetch(light_background_conditional_cdf, + index_v * cdf_width + res_x); + float2 cdf_last_v = kernel_data_fetch(light_background_marginal_cdf, res_y); float denom = (M_2PI_F * M_PI_F * sin_theta) * cdf_last_u.x * cdf_last_v.x; @@ -122,9 +122,9 @@ ccl_device float background_map_pdf(KernelGlobals kg, float3 direction) return 0.0f; /* pdfs in U direction */ - float2 cdf_u = kernel_tex_fetch(__light_background_conditional_cdf, - index_v * cdf_width + index_u); - float2 cdf_v = kernel_tex_fetch(__light_background_marginal_cdf, index_v); + float2 cdf_u = kernel_data_fetch(light_background_conditional_cdf, + index_v * cdf_width + index_u); + float2 cdf_v = kernel_data_fetch(light_background_marginal_cdf, index_v); return (cdf_u.x * cdf_v.x) / denom; } @@ -133,7 +133,7 @@ ccl_device_inline bool background_portal_data_fetch_and_check_side( KernelGlobals kg, float3 P, int index, ccl_private float3 *lightpos, ccl_private float3 *dir) { int portal = kernel_data.background.portal_offset + index; - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, portal); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, portal); *lightpos = make_float3(klight->co[0], klight->co[1], klight->co[2]); *dir = make_float3(klight->area.dir[0], klight->area.dir[1], klight->area.dir[2]); @@ -166,7 +166,7 @@ ccl_device_inline float background_portal_pdf( num_possible++; int portal = kernel_data.background.portal_offset + p; - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, portal); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, portal); float3 axisu = make_float3( klight->area.axisu[0], klight->area.axisu[1], klight->area.axisu[2]); float3 axisv = make_float3( @@ -242,7 +242,7 @@ ccl_device float3 background_portal_sample(KernelGlobals kg, if (portal == 0) { /* p is the portal to be sampled. */ int portal = kernel_data.background.portal_offset + p; - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, portal); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, portal); float3 axisu = make_float3( klight->area.axisu[0], klight->area.axisu[1], klight->area.axisu[2]); float3 axisv = make_float3( diff --git a/intern/cycles/kernel/light/light.h b/intern/cycles/kernel/light/light.h index 1df1615ed99..1e7a333d013 100644 --- a/intern/cycles/kernel/light/light.h +++ b/intern/cycles/kernel/light/light.h @@ -38,7 +38,7 @@ ccl_device_inline bool light_sample(KernelGlobals kg, const uint32_t path_flag, ccl_private LightSample *ls) { - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp); if (path_flag & PATH_RAY_SHADOW_CATCHER_PASS) { if (klight->shader_id & SHADER_EXCLUDE_SHADOW_CATCHER) { return false; @@ -237,7 +237,7 @@ ccl_device bool lights_intersect(KernelGlobals kg, const uint32_t path_flag) { for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) { - const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp); if (path_flag & PATH_RAY_CAMERA) { if (klight->shader_id & SHADER_EXCLUDE_CAMERA) { @@ -358,7 +358,7 @@ ccl_device bool light_sample_from_distant_ray(KernelGlobals kg, const int lamp, ccl_private LightSample *ccl_restrict ls) { - ccl_global const KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + ccl_global const KernelLight *klight = &kernel_data_fetch(lights, lamp); const int shader = klight->shader_id; const float radius = klight->distant.radius; const LightType type = (LightType)klight->type; @@ -433,7 +433,7 @@ ccl_device bool light_sample_from_intersection(KernelGlobals kg, ccl_private LightSample *ccl_restrict ls) { const int lamp = isect->prim; - ccl_global const KernelLight *klight = &kernel_tex_fetch(__lights, lamp); + ccl_global const KernelLight *klight = &kernel_data_fetch(lights, lamp); LightType type = (LightType)klight->type; ls->type = type; ls->shader = klight->shader_id; @@ -562,7 +562,7 @@ ccl_device_inline bool triangle_world_space_vertices( KernelGlobals kg, int object, int prim, float time, float3 V[3]) { bool has_motion = false; - const int object_flag = kernel_tex_fetch(__object_flag, object); + const int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_HAS_VERTEX_MOTION && time >= 0.0f) { motion_triangle_vertices(kg, object, prim, time, V); @@ -699,12 +699,12 @@ ccl_device_forceinline void triangle_light_sample(KernelGlobals kg, float area = 0.5f * Nl; /* flip normal if necessary */ - const int object_flag = kernel_tex_fetch(__object_flag, object); + const int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) { ls->Ng = -ls->Ng; } ls->eval_fac = 1.0f; - ls->shader = kernel_tex_fetch(__tri_shader, prim); + ls->shader = kernel_data_fetch(tri_shader, prim); ls->object = object; ls->prim = prim; ls->lamp = LAMP_NONE; @@ -845,7 +845,7 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *ra int half_len = len >> 1; int middle = first + half_len; - if (r < kernel_tex_fetch(__light_distribution, middle).totarea) { + if (r < kernel_data_fetch(light_distribution, middle).totarea) { len = half_len; } else { @@ -860,8 +860,8 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *ra /* Rescale to reuse random number. this helps the 2D samples within * each area light be stratified as well. */ - float distr_min = kernel_tex_fetch(__light_distribution, index).totarea; - float distr_max = kernel_tex_fetch(__light_distribution, index + 1).totarea; + float distr_min = kernel_data_fetch(light_distribution, index).totarea; + float distr_max = kernel_data_fetch(light_distribution, index + 1).totarea; *randu = (r - distr_min) / (distr_max - distr_min); return index; @@ -871,7 +871,7 @@ ccl_device int light_distribution_sample(KernelGlobals kg, ccl_private float *ra ccl_device_inline bool light_select_reached_max_bounces(KernelGlobals kg, int index, int bounce) { - return (bounce > kernel_tex_fetch(__lights, index).max_bounces); + return (bounce > kernel_data_fetch(lights, index).max_bounces); } template<bool in_volume_segment> @@ -886,8 +886,8 @@ ccl_device_noinline bool light_distribution_sample(KernelGlobals kg, { /* Sample light index from distribution. */ const int index = light_distribution_sample(kg, &randu); - ccl_global const KernelLightDistribution *kdistribution = &kernel_tex_fetch(__light_distribution, - index); + ccl_global const KernelLightDistribution *kdistribution = &kernel_data_fetch(light_distribution, + index); const int prim = kdistribution->prim; if (prim >= 0) { @@ -896,7 +896,7 @@ ccl_device_noinline bool light_distribution_sample(KernelGlobals kg, /* Exclude synthetic meshes from shadow catcher pass. */ if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) && - !(kernel_tex_fetch(__object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) { + !(kernel_data_fetch(object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) { return false; } diff --git a/intern/cycles/kernel/light/sample.h b/intern/cycles/kernel/light/sample.h index 9bbbd5b0d10..ea7b9950268 100644 --- a/intern/cycles/kernel/light/sample.h +++ b/intern/cycles/kernel/light/sample.h @@ -81,7 +81,7 @@ light_sample_shader_eval(KernelGlobals kg, eval *= ls->eval_fac; if (ls->lamp != LAMP_NONE) { - ccl_global const KernelLight *klight = &kernel_tex_fetch(__lights, ls->lamp); + ccl_global const KernelLight *klight = &kernel_data_fetch(lights, ls->lamp); eval *= make_float3(klight->strength[0], klight->strength[1], klight->strength[2]); } @@ -187,7 +187,7 @@ ccl_device_inline float3 shadow_ray_offset(KernelGlobals kg, if ((sd->type & PRIMITIVE_TRIANGLE) && (sd->shader & SHADER_SMOOTH_NORMAL)) { const float offset_cutoff = - kernel_tex_fetch(__objects, sd->object).shadow_terminator_geometry_offset; + kernel_data_fetch(objects, sd->object).shadow_terminator_geometry_offset; /* Do ray offset (heavy stuff) only for close to be terminated triangles: * offset_cutoff = 0.1f means that 10-20% of rays will be affected. Also * make a smooth transition near the threshold. */ diff --git a/intern/cycles/kernel/osl/services.cpp b/intern/cycles/kernel/osl/services.cpp index e2e10b5b83f..6e75ae54f33 100644 --- a/intern/cycles/kernel/osl/services.cpp +++ b/intern/cycles/kernel/osl/services.cpp @@ -132,7 +132,7 @@ OSLRenderServices::OSLRenderServices(OSL::TextureSystem *texture_system) OSLRenderServices::~OSLRenderServices() { if (texture_system) { - VLOG(2) << "OSL texture system stats:\n" << texture_system->getstats(); + VLOG_INFO << "OSL texture system stats:\n" << texture_system->getstats(); } } diff --git a/intern/cycles/kernel/sample/jitter.h b/intern/cycles/kernel/sample/jitter.h index b8da94248a4..b5cfa624406 100644 --- a/intern/cycles/kernel/sample/jitter.h +++ b/intern/cycles/kernel/sample/jitter.h @@ -97,7 +97,7 @@ ccl_device float pmj_sample_1D(KernelGlobals kg, uint sample, uint rng_hash, uin * the x part is used for even dims and the y for odd. */ int index = 2 * ((dim >> 1) * NUM_PMJ_SAMPLES + (s % NUM_PMJ_SAMPLES)) + (dim & 1); - float fx = kernel_tex_fetch(__sample_pattern_lut, index); + float fx = kernel_data_fetch(sample_pattern_lut, index); #ifndef _NO_CRANLEY_PATTERSON_ROTATION_ /* Use Cranley-Patterson rotation to displace the sample pattern. */ @@ -154,8 +154,8 @@ ccl_device void pmj_sample_2D(KernelGlobals kg, uint dim = d % NUM_PMJ_PATTERNS; int index = 2 * (dim * NUM_PMJ_SAMPLES + (s % NUM_PMJ_SAMPLES)); - float fx = kernel_tex_fetch(__sample_pattern_lut, index); - float fy = kernel_tex_fetch(__sample_pattern_lut, index + 1); + float fx = kernel_data_fetch(sample_pattern_lut, index); + float fy = kernel_data_fetch(sample_pattern_lut, index + 1); #ifndef _NO_CRANLEY_PATTERSON_ROTATION_ /* Use Cranley-Patterson rotation to displace the sample pattern. */ diff --git a/intern/cycles/kernel/sample/pattern.h b/intern/cycles/kernel/sample/pattern.h index 1e66f39ede2..89500d51872 100644 --- a/intern/cycles/kernel/sample/pattern.h +++ b/intern/cycles/kernel/sample/pattern.h @@ -32,7 +32,7 @@ ccl_device uint sobol_dimension(KernelGlobals kg, int index, int dimension) uint i = index + SOBOL_SKIP; for (int j = 0, x; (x = find_first_set(i)); i >>= x) { j += x; - result ^= __float_as_uint(kernel_tex_fetch(__sample_pattern_lut, 32 * dimension + j - 1)); + result ^= __float_as_uint(kernel_data_fetch(sample_pattern_lut, 32 * dimension + j - 1)); } return result; } diff --git a/intern/cycles/kernel/svm/bevel.h b/intern/cycles/kernel/svm/bevel.h index 5abffe1c771..f79bcae5cd2 100644 --- a/intern/cycles/kernel/svm/bevel.h +++ b/intern/cycles/kernel/svm/bevel.h @@ -222,7 +222,7 @@ ccl_device float3 svm_bevel( /* Get geometric normal. */ float3 hit_Ng = isect.Ng[hit]; int object = isect.hits[hit].object; - int object_flag = kernel_tex_fetch(__object_flag, object); + int object_flag = kernel_data_fetch(object_flag, object); if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) { hit_Ng = -hit_Ng; } @@ -230,7 +230,7 @@ ccl_device float3 svm_bevel( /* Compute smooth normal. */ float3 N = hit_Ng; int prim = isect.hits[hit].prim; - int shader = kernel_tex_fetch(__tri_shader, prim); + int shader = kernel_data_fetch(tri_shader, prim); if (shader & SHADER_SMOOTH_NORMAL) { float u = isect.hits[hit].u; diff --git a/intern/cycles/kernel/svm/ies.h b/intern/cycles/kernel/svm/ies.h index 201d88101cd..3648cb580d5 100644 --- a/intern/cycles/kernel/svm/ies.h +++ b/intern/cycles/kernel/svm/ies.h @@ -17,7 +17,7 @@ ccl_device_inline float interpolate_ies_vertical( * Therefore, the assumption is made that the light is going to be symmetrical, which means that * we can just take the corresponding value at the current horizontal coordinate. */ -#define IES_LOOKUP(v) kernel_tex_fetch(__ies, ofs + h * v_num + (v)) +#define IES_LOOKUP(v) kernel_data_fetch(ies, ofs + h * v_num + (v)) /* If v is zero, assume symmetry and read at v=1 instead of v=-1. */ float a = IES_LOOKUP((v == 0) ? 1 : v - 1); float b = IES_LOOKUP(v); @@ -31,16 +31,16 @@ ccl_device_inline float interpolate_ies_vertical( ccl_device_inline float kernel_ies_interp(KernelGlobals kg, int slot, float h_angle, float v_angle) { /* Find offset of the IES data in the table. */ - int ofs = __float_as_int(kernel_tex_fetch(__ies, slot)); + int ofs = __float_as_int(kernel_data_fetch(ies, slot)); if (ofs == -1) { return 100.0f; } - int h_num = __float_as_int(kernel_tex_fetch(__ies, ofs++)); - int v_num = __float_as_int(kernel_tex_fetch(__ies, ofs++)); + int h_num = __float_as_int(kernel_data_fetch(ies, ofs++)); + int v_num = __float_as_int(kernel_data_fetch(ies, ofs++)); -#define IES_LOOKUP_ANGLE_H(h) kernel_tex_fetch(__ies, ofs + (h)) -#define IES_LOOKUP_ANGLE_V(v) kernel_tex_fetch(__ies, ofs + h_num + (v)) +#define IES_LOOKUP_ANGLE_H(h) kernel_data_fetch(ies, ofs + (h)) +#define IES_LOOKUP_ANGLE_V(v) kernel_data_fetch(ies, ofs + h_num + (v)) /* Check whether the angle is within the bounds of the IES texture. */ if (v_angle >= IES_LOOKUP_ANGLE_V(v_num - 1)) { diff --git a/intern/cycles/kernel/svm/ramp.h b/intern/cycles/kernel/svm/ramp.h index 342b15da9ed..0df9268bd9c 100644 --- a/intern/cycles/kernel/svm/ramp.h +++ b/intern/cycles/kernel/svm/ramp.h @@ -9,7 +9,7 @@ CCL_NAMESPACE_BEGIN ccl_device_inline float fetch_float(KernelGlobals kg, int offset) { - uint4 node = kernel_tex_fetch(__svm_nodes, offset); + uint4 node = kernel_data_fetch(svm_nodes, offset); return __uint_as_float(node.x); } diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 5def943c87f..624ef810e85 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -95,14 +95,14 @@ ccl_device_inline bool stack_valid(uint a) ccl_device_inline uint4 read_node(KernelGlobals kg, ccl_private int *offset) { - uint4 node = kernel_tex_fetch(__svm_nodes, *offset); + uint4 node = kernel_data_fetch(svm_nodes, *offset); (*offset)++; return node; } ccl_device_inline float4 read_node_float(KernelGlobals kg, ccl_private int *offset) { - uint4 node = kernel_tex_fetch(__svm_nodes, *offset); + uint4 node = kernel_data_fetch(svm_nodes, *offset); float4 f = make_float4(__uint_as_float(node.x), __uint_as_float(node.y), __uint_as_float(node.z), @@ -113,7 +113,7 @@ ccl_device_inline float4 read_node_float(KernelGlobals kg, ccl_private int *offs ccl_device_inline float4 fetch_node_float(KernelGlobals kg, int offset) { - uint4 node = kernel_tex_fetch(__svm_nodes, offset); + uint4 node = kernel_data_fetch(svm_nodes, offset); return make_float4(__uint_as_float(node.x), __uint_as_float(node.y), __uint_as_float(node.z), diff --git a/intern/cycles/kernel/textures.h b/intern/cycles/kernel/textures.h deleted file mode 100644 index 7deb589a0a9..00000000000 --- a/intern/cycles/kernel/textures.h +++ /dev/null @@ -1,82 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 - * Copyright 2011-2022 Blender Foundation */ - -#ifndef KERNEL_TEX -# define KERNEL_TEX(type, name) -#endif - -/* BVH2, not used for OptiX or Embree. */ -KERNEL_TEX(float4, __bvh_nodes) -KERNEL_TEX(float4, __bvh_leaf_nodes) -KERNEL_TEX(uint, __prim_type) -KERNEL_TEX(uint, __prim_visibility) -KERNEL_TEX(uint, __prim_index) -KERNEL_TEX(uint, __prim_object) -KERNEL_TEX(uint, __object_node) -KERNEL_TEX(float2, __prim_time) - -/* objects */ -KERNEL_TEX(KernelObject, __objects) -KERNEL_TEX(Transform, __object_motion_pass) -KERNEL_TEX(DecomposedTransform, __object_motion) -KERNEL_TEX(uint, __object_flag) -KERNEL_TEX(float, __object_volume_step) -KERNEL_TEX(uint, __object_prim_offset) - -/* cameras */ -KERNEL_TEX(DecomposedTransform, __camera_motion) - -/* triangles */ -KERNEL_TEX(uint, __tri_shader) -KERNEL_TEX(packed_float3, __tri_vnormal) -KERNEL_TEX(uint4, __tri_vindex) -KERNEL_TEX(uint, __tri_patch) -KERNEL_TEX(float2, __tri_patch_uv) -KERNEL_TEX(packed_float3, __tri_verts) - -/* curves */ -KERNEL_TEX(KernelCurve, __curves) -KERNEL_TEX(float4, __curve_keys) -KERNEL_TEX(KernelCurveSegment, __curve_segments) - -/* patches */ -KERNEL_TEX(uint, __patches) - -/* pointclouds */ -KERNEL_TEX(float4, __points) -KERNEL_TEX(uint, __points_shader) - -/* attributes */ -KERNEL_TEX(uint4, __attributes_map) -KERNEL_TEX(float, __attributes_float) -KERNEL_TEX(float2, __attributes_float2) -KERNEL_TEX(packed_float3, __attributes_float3) -KERNEL_TEX(float4, __attributes_float4) -KERNEL_TEX(uchar4, __attributes_uchar4) - -/* lights */ -KERNEL_TEX(KernelLightDistribution, __light_distribution) -KERNEL_TEX(KernelLight, __lights) -KERNEL_TEX(float2, __light_background_marginal_cdf) -KERNEL_TEX(float2, __light_background_conditional_cdf) - -/* particles */ -KERNEL_TEX(KernelParticle, __particles) - -/* shaders */ -KERNEL_TEX(uint4, __svm_nodes) -KERNEL_TEX(KernelShader, __shaders) - -/* lookup tables */ -KERNEL_TEX(float, __lookup_table) - -/* sobol */ -KERNEL_TEX(float, __sample_pattern_lut) - -/* image textures */ -KERNEL_TEX(TextureInfo, __texture_info) - -/* ies lights */ -KERNEL_TEX(float, __ies) - -#undef KERNEL_TEX diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h index b1ca379bab8..ad022716207 100644 --- a/intern/cycles/kernel/types.h +++ b/intern/cycles/kernel/types.h @@ -670,6 +670,16 @@ typedef struct AttributeDescriptor { int offset; } AttributeDescriptor; +/* For looking up attributes on objects and geometry. */ +typedef struct AttributeMap { + uint id; /* Global unique identifier. */ + uint element; /* AttributeElement. */ + int offset; /* Offset into __attributes global arrays. */ + uint8_t type; /* NodeAttributeType. */ + uint8_t flags; /* AttributeFlag. */ + uint8_t pad[2]; +} AttributeMap; + /* Closure data */ #ifndef __MAX_CLOSURE__ diff --git a/intern/cycles/kernel/util/lookup_table.h b/intern/cycles/kernel/util/lookup_table.h index e19e2ce5bd1..4db4dadab0e 100644 --- a/intern/cycles/kernel/util/lookup_table.h +++ b/intern/cycles/kernel/util/lookup_table.h @@ -15,11 +15,11 @@ ccl_device float lookup_table_read(KernelGlobals kg, float x, int offset, int si int nindex = min(index + 1, size - 1); float t = x - index; - float data0 = kernel_tex_fetch(__lookup_table, index + offset); + float data0 = kernel_data_fetch(lookup_table, index + offset); if (t == 0.0f) return data0; - float data1 = kernel_tex_fetch(__lookup_table, nindex + offset); + float data1 = kernel_data_fetch(lookup_table, nindex + offset); return (1.0f - t) * data0 + t * data1; } diff --git a/intern/cycles/scene/alembic.cpp b/intern/cycles/scene/alembic.cpp index c1e2d306fcc..e6f39bf8625 100644 --- a/intern/cycles/scene/alembic.cpp +++ b/intern/cycles/scene/alembic.cpp @@ -1514,7 +1514,7 @@ void AlembicProcedural::build_caches(Progress &progress) } } - VLOG(1) << "AlembicProcedural memory usage : " << string_human_readable_size(memory_used); + VLOG_WORK << "AlembicProcedural memory usage : " << string_human_readable_size(memory_used); } CCL_NAMESPACE_END diff --git a/intern/cycles/scene/camera.cpp b/intern/cycles/scene/camera.cpp index 710f1c5ee90..eec269ab542 100644 --- a/intern/cycles/scene/camera.cpp +++ b/intern/cycles/scene/camera.cpp @@ -530,7 +530,7 @@ void Camera::device_update_volume(Device * /*device*/, DeviceScene *dscene, Scen if (object->get_geometry()->has_volume && viewplane_boundbox.intersects(object->bounds)) { /* TODO(sergey): Consider adding more grained check. */ - VLOG(1) << "Detected camera inside volume."; + VLOG_INFO << "Detected camera inside volume."; kcam->is_inside_volume = 1; parallel_for_cancel(); break; @@ -539,7 +539,7 @@ void Camera::device_update_volume(Device * /*device*/, DeviceScene *dscene, Scen }); if (!kcam->is_inside_volume) { - VLOG(1) << "Camera is outside of the volume."; + VLOG_INFO << "Camera is outside of the volume."; } } diff --git a/intern/cycles/scene/colorspace.cpp b/intern/cycles/scene/colorspace.cpp index f87b4c62ab2..189e3bc752d 100644 --- a/intern/cycles/scene/colorspace.cpp +++ b/intern/cycles/scene/colorspace.cpp @@ -55,8 +55,8 @@ ColorSpaceProcessor *ColorSpaceManager::get_processor(ustring colorspace) } catch (OCIO::Exception &exception) { cached_processors[colorspace] = OCIO::ConstProcessorRcPtr(); - VLOG(1) << "Colorspace " << colorspace.c_str() - << " can't be converted to scene_linear: " << exception.what(); + VLOG_WARNING << "Colorspace " << colorspace.c_str() + << " can't be converted to scene_linear: " << exception.what(); } } @@ -132,12 +132,12 @@ ustring ColorSpaceManager::detect_known_colorspace(ustring colorspace, thread_scoped_lock cache_lock(cache_colorspaces_mutex); if (is_scene_linear) { - VLOG(1) << "Colorspace " << colorspace.string() << " is no-op"; + VLOG_INFO << "Colorspace " << colorspace.string() << " is no-op"; cached_colorspaces[colorspace] = u_colorspace_raw; return u_colorspace_raw; } else if (is_srgb) { - VLOG(1) << "Colorspace " << colorspace.string() << " is sRGB"; + VLOG_INFO << "Colorspace " << colorspace.string() << " is sRGB"; cached_colorspaces[colorspace] = u_colorspace_srgb; return u_colorspace_srgb; } @@ -146,22 +146,23 @@ ustring ColorSpaceManager::detect_known_colorspace(ustring colorspace, if (!get_processor(colorspace)) { OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); if (!config || !config->getColorSpace(colorspace.c_str())) { - VLOG(1) << "Colorspace " << colorspace.c_str() << " not found, using raw instead"; + VLOG_WARNING << "Colorspace " << colorspace.c_str() << " not found, using raw instead"; } else { - VLOG(1) << "Colorspace " << colorspace.c_str() - << " can't be converted to scene_linear, using raw instead"; + VLOG_WARNING << "Colorspace " << colorspace.c_str() + << " can't be converted to scene_linear, using raw instead"; } cached_colorspaces[colorspace] = u_colorspace_raw; return u_colorspace_raw; } /* Convert to/from colorspace with OpenColorIO. */ - VLOG(1) << "Colorspace " << colorspace.string() << " handled through OpenColorIO"; + VLOG_INFO << "Colorspace " << colorspace.string() << " handled through OpenColorIO"; cached_colorspaces[colorspace] = colorspace; return colorspace; #else - VLOG(1) << "Colorspace " << colorspace.c_str() << " not available, built without OpenColorIO"; + VLOG_WARNING << "Colorspace " << colorspace.c_str() + << " not available, built without OpenColorIO"; return u_colorspace_raw; #endif } diff --git a/intern/cycles/scene/constant_fold.cpp b/intern/cycles/scene/constant_fold.cpp index 46ffbe9043a..4bce5661f9b 100644 --- a/intern/cycles/scene/constant_fold.cpp +++ b/intern/cycles/scene/constant_fold.cpp @@ -30,8 +30,8 @@ bool ConstantFolder::all_inputs_constant() const void ConstantFolder::make_constant(float value) const { - VLOG(3) << "Folding " << node->name << "::" << output->name() << " to constant (" << value - << ")."; + VLOG_DEBUG << "Folding " << node->name << "::" << output->name() << " to constant (" << value + << ")."; foreach (ShaderInput *sock, output->links) { sock->set(value); @@ -43,7 +43,8 @@ void ConstantFolder::make_constant(float value) const void ConstantFolder::make_constant(float3 value) const { - VLOG(3) << "Folding " << node->name << "::" << output->name() << " to constant " << value << "."; + VLOG_DEBUG << "Folding " << node->name << "::" << output->name() << " to constant " << value + << "."; foreach (ShaderInput *sock, output->links) { sock->set(value); @@ -99,8 +100,8 @@ void ConstantFolder::bypass(ShaderOutput *new_output) const { assert(new_output); - VLOG(3) << "Folding " << node->name << "::" << output->name() << " to socket " - << new_output->parent->name << "::" << new_output->name() << "."; + VLOG_DEBUG << "Folding " << node->name << "::" << output->name() << " to socket " + << new_output->parent->name << "::" << new_output->name() << "."; /* Remove all outgoing links from socket and connect them to new_output instead. * The graph->relink method affects node inputs, so it's not safe to use in constant @@ -118,7 +119,7 @@ void ConstantFolder::discard() const { assert(output->type() == SocketType::CLOSURE); - VLOG(3) << "Discarding closure " << node->name << "."; + VLOG_DEBUG << "Discarding closure " << node->name << "."; graph->disconnect(output); } diff --git a/intern/cycles/scene/film.cpp b/intern/cycles/scene/film.cpp index 7f69df7b321..8239ee84b82 100644 --- a/intern/cycles/scene/film.cpp +++ b/intern/cycles/scene/film.cpp @@ -152,7 +152,7 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene) KernelFilm *kfilm = &dscene->data.film; - /* update __data */ + /* update data */ kfilm->exposure = exposure; kfilm->pass_alpha_threshold = pass_alpha_threshold; kfilm->pass_flag = 0; @@ -580,10 +580,10 @@ void Film::update_passes(Scene *scene, bool add_sample_count_pass) tag_modified(); /* Debug logging. */ - if (VLOG_IS_ON(2)) { - VLOG(2) << "Effective scene passes:"; + if (VLOG_INFO_IS_ON) { + VLOG_INFO << "Effective scene passes:"; for (const Pass *pass : scene->passes) { - VLOG(2) << "- " << *pass; + VLOG_INFO << "- " << *pass; } } } diff --git a/intern/cycles/scene/geometry.cpp b/intern/cycles/scene/geometry.cpp index 9152abacbdb..bdc8839e277 100644 --- a/intern/cycles/scene/geometry.cpp +++ b/intern/cycles/scene/geometry.cpp @@ -407,43 +407,47 @@ void GeometryManager::update_osl_attributes(Device *device, /* Generate a normal attribute map entry from an attribute descriptor. */ static void emit_attribute_map_entry( - uint4 *attr_map, int index, uint id, TypeDesc type, const AttributeDescriptor &desc) + AttributeMap *attr_map, int index, uint id, TypeDesc type, const AttributeDescriptor &desc) { - attr_map[index].x = id; - attr_map[index].y = desc.element; - attr_map[index].z = as_uint(desc.offset); + attr_map[index].id = id; + attr_map[index].element = desc.element; + attr_map[index].offset = as_uint(desc.offset); if (type == TypeDesc::TypeFloat) - attr_map[index].w = NODE_ATTR_FLOAT; + attr_map[index].type = NODE_ATTR_FLOAT; else if (type == TypeDesc::TypeMatrix) - attr_map[index].w = NODE_ATTR_MATRIX; + attr_map[index].type = NODE_ATTR_MATRIX; else if (type == TypeFloat2) - attr_map[index].w = NODE_ATTR_FLOAT2; + attr_map[index].type = NODE_ATTR_FLOAT2; else if (type == TypeFloat4) - attr_map[index].w = NODE_ATTR_FLOAT4; + attr_map[index].type = NODE_ATTR_FLOAT4; else if (type == TypeRGBA) - attr_map[index].w = NODE_ATTR_RGBA; + attr_map[index].type = NODE_ATTR_RGBA; else - attr_map[index].w = NODE_ATTR_FLOAT3; + attr_map[index].type = NODE_ATTR_FLOAT3; - attr_map[index].w |= desc.flags << 8; + attr_map[index].flags = desc.flags; } /* Generate an attribute map end marker, optionally including a link to another map. * Links are used to connect object attribute maps to mesh attribute maps. */ -static void emit_attribute_map_terminator(uint4 *attr_map, int index, bool chain, uint chain_link) +static void emit_attribute_map_terminator(AttributeMap *attr_map, + int index, + bool chain, + uint chain_link) { for (int j = 0; j < ATTR_PRIM_TYPES; j++) { - attr_map[index + j].x = ATTR_STD_NONE; - attr_map[index + j].y = chain; /* link is valid flag */ - attr_map[index + j].z = chain ? chain_link + j : 0; /* link to the correct sub-entry */ - attr_map[index + j].w = 0; + attr_map[index + j].id = ATTR_STD_NONE; + attr_map[index + j].element = chain; /* link is valid flag */ + attr_map[index + j].offset = chain ? chain_link + j : 0; /* link to the correct sub-entry */ + attr_map[index + j].type = 0; + attr_map[index + j].flags = 0; } } /* Generate all necessary attribute map entries from the attribute request. */ static void emit_attribute_mapping( - uint4 *attr_map, int index, Scene *scene, AttributeRequest &req, Geometry *geom) + AttributeMap *attr_map, int index, Scene *scene, AttributeRequest &req, Geometry *geom) { uint id; @@ -501,8 +505,8 @@ void GeometryManager::update_svm_attributes(Device *, } /* create attribute map */ - uint4 *attr_map = dscene->attributes_map.alloc(attr_map_size); - memset(attr_map, 0, dscene->attributes_map.size() * sizeof(uint)); + AttributeMap *attr_map = dscene->attributes_map.alloc(attr_map_size); + memset(attr_map, 0, dscene->attributes_map.size() * sizeof(*attr_map)); for (size_t i = 0; i < scene->geometry.size(); i++) { Geometry *geom = scene->geometry[i]; @@ -1288,7 +1292,7 @@ void GeometryManager::device_update_bvh(Device *device, bparams.bvh_type = scene->params.bvh_type; bparams.curve_subdivisions = scene->params.curve_subdivisions(); - VLOG(1) << "Using " << bvh_layout_name(bparams.bvh_layout) << " layout."; + VLOG_INFO << "Using " << bvh_layout_name(bparams.bvh_layout) << " layout."; const bool can_refit = scene->bvh != nullptr && (bparams.bvh_layout == BVHLayout::BVH_LAYOUT_OPTIX || @@ -1799,7 +1803,7 @@ void GeometryManager::device_update(Device *device, if (!need_update()) return; - VLOG(1) << "Total " << scene->geometry.size() << " meshes."; + VLOG_INFO << "Total " << scene->geometry.size() << " meshes."; bool true_displacement_used = false; bool curve_shadow_transparency_used = false; @@ -1953,7 +1957,7 @@ void GeometryManager::device_update(Device *device, { /* Copy constant data needed by shader evaluation. */ - device->const_copy_to("__data", &dscene->data, sizeof(dscene->data)); + device->const_copy_to("data", &dscene->data, sizeof(dscene->data)); scoped_callback_timer timer([scene](double time) { if (scene->update_stats) { @@ -2038,7 +2042,7 @@ void GeometryManager::device_update(Device *device, TaskPool::Summary summary; pool.wait_work(&summary); - VLOG(2) << "Objects BVH build pool statistics:\n" << summary.full_report(); + VLOG_WORK << "Objects BVH build pool statistics:\n" << summary.full_report(); } foreach (Shader *shader, scene->shaders) { diff --git a/intern/cycles/scene/image.cpp b/intern/cycles/scene/image.cpp index 1b44162351a..0352ed3e66c 100644 --- a/intern/cycles/scene/image.cpp +++ b/intern/cycles/scene/image.cpp @@ -653,8 +653,8 @@ bool ImageManager::file_load_image(Image *img, int texture_limit) while (max_size * scale_factor > texture_limit) { scale_factor *= 0.5f; } - VLOG(1) << "Scaling image " << img->loader->name() << " by a factor of " << scale_factor - << "."; + VLOG_WORK << "Scaling image " << img->loader->name() << " by a factor of " << scale_factor + << "."; vector<StorageType> scaled_pixels; size_t scaled_width, scaled_height, scaled_depth; util_image_resize_pixels(pixels_storage, @@ -697,7 +697,7 @@ void ImageManager::device_load_image(Device *device, Scene *scene, int slot, Pro ImageDataType type = img->metadata.type; /* Name for debugging. */ - img->mem_name = string_printf("__tex_image_%s_%03d", name_from_type(type), slot); + img->mem_name = string_printf("tex_image_%s_%03d", name_from_type(type), slot); /* Free previous texture in slot. */ if (img->mem) { diff --git a/intern/cycles/scene/image_oiio.cpp b/intern/cycles/scene/image_oiio.cpp index 09676455308..500e53ed763 100644 --- a/intern/cycles/scene/image_oiio.cpp +++ b/intern/cycles/scene/image_oiio.cpp @@ -22,11 +22,11 @@ bool OIIOImageLoader::load_metadata(const ImageDeviceFeatures & /*features*/, { /* Perform preliminary checks, with meaningful logging. */ if (!path_exists(filepath.string())) { - VLOG(1) << "File '" << filepath.string() << "' does not exist."; + VLOG_WARNING << "File '" << filepath.string() << "' does not exist."; return false; } if (path_is_directory(filepath.string())) { - VLOG(1) << "File '" << filepath.string() << "' is a directory, can't use as image."; + VLOG_WARNING << "File '" << filepath.string() << "' is a directory, can't use as image."; return false; } diff --git a/intern/cycles/scene/image_vdb.cpp b/intern/cycles/scene/image_vdb.cpp index 2209be60a97..059eb09fef4 100644 --- a/intern/cycles/scene/image_vdb.cpp +++ b/intern/cycles/scene/image_vdb.cpp @@ -70,7 +70,7 @@ struct ToNanoOp { nanogrid = nanovdb::openToNanoVDB(floatgrid); } catch (const std::exception &e) { - VLOG(1) << "Error converting OpenVDB to NanoVDB grid: " << e.what(); + VLOG_WARNING << "Error converting OpenVDB to NanoVDB grid: " << e.what(); } return true; } diff --git a/intern/cycles/scene/integrator.cpp b/intern/cycles/scene/integrator.cpp index fda6ecc8d14..aa11004fb48 100644 --- a/intern/cycles/scene/integrator.cpp +++ b/intern/cycles/scene/integrator.cpp @@ -338,7 +338,7 @@ AdaptiveSampling Integrator::get_adaptive_sampling() const if (aa_samples > 0 && adaptive_threshold == 0.0f) { adaptive_sampling.threshold = max(0.001f, 1.0f / (float)aa_samples); - VLOG(1) << "Cycles adaptive sampling: automatic threshold = " << adaptive_sampling.threshold; + VLOG_INFO << "Cycles adaptive sampling: automatic threshold = " << adaptive_sampling.threshold; } else { adaptive_sampling.threshold = adaptive_threshold; @@ -350,8 +350,8 @@ AdaptiveSampling Integrator::get_adaptive_sampling() const * in various test scenes. */ const int min_samples = (int)ceilf(16.0f / powf(adaptive_sampling.threshold, 0.3f)); adaptive_sampling.min_samples = max(4, min_samples); - VLOG(1) << "Cycles adaptive sampling: automatic min samples = " - << adaptive_sampling.min_samples; + VLOG_INFO << "Cycles adaptive sampling: automatic min samples = " + << adaptive_sampling.min_samples; } else { adaptive_sampling.min_samples = max(4, adaptive_min_samples); diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp index 5e311d3051f..ea1f45793fa 100644 --- a/intern/cycles/scene/light.cpp +++ b/intern/cycles/scene/light.cpp @@ -34,7 +34,7 @@ static void shade_background_pixels(Device *device, Progress &progress) { /* Needs to be up to data for attribute access. */ - device->const_copy_to("__data", &dscene->data, sizeof(dscene->data)); + device->const_copy_to("data", &dscene->data, sizeof(dscene->data)); const int size = width * height; const int num_channels = 3; @@ -215,7 +215,9 @@ void LightManager::test_enabled_lights(Scene *scene) */ Shader *shader = scene->background->get_shader(scene); const bool disable_mis = !(has_portal || shader->has_surface_spatial_varying); - VLOG_IF(1, disable_mis) << "Background MIS has been disabled.\n"; + if (disable_mis) { + VLOG_INFO << "Background MIS has been disabled.\n"; + } foreach (Light *light, scene->lights) { if (light->light_type == LIGHT_BACKGROUND) { light->is_enabled = !disable_mis; @@ -309,7 +311,7 @@ void LightManager::device_update_distribution(Device *, } size_t num_distribution = num_triangles + num_lights; - VLOG(1) << "Total " << num_distribution << " of light distribution primitives."; + VLOG_INFO << "Total " << num_distribution << " of light distribution primitives."; /* emission area */ KernelLightDistribution *distribution = dscene->light_distribution.alloc(num_distribution + 1); @@ -655,13 +657,14 @@ void LightManager::device_update_background(Device *device, if (res.x == 0) { res = environment_res; if (res.x > 0 && res.y > 0) { - VLOG(2) << "Automatically set World MIS resolution to " << res.x << " by " << res.y << "\n"; + VLOG_INFO << "Automatically set World MIS resolution to " << res.x << " by " << res.y + << "\n"; } } /* If it's still unknown, just use the default. */ if (res.x == 0 || res.y == 0) { res = make_int2(1024, 512); - VLOG(2) << "Setting World MIS resolution to default\n"; + VLOG_INFO << "Setting World MIS resolution to default\n"; } kbackground->map_res_x = res.x; kbackground->map_res_y = res.y; @@ -704,7 +707,7 @@ void LightManager::device_update_background(Device *device, marg_cdf[res.y].y = 1.0f; - VLOG(2) << "Background MIS build time " << time_dt() - time_start << "\n"; + VLOG_WORK << "Background MIS build time " << time_dt() - time_start << "\n"; /* update device */ dscene->light_background_marginal_cdf.copy_to_device(); @@ -725,7 +728,7 @@ void LightManager::device_update_points(Device *, DeviceScene *dscene, Scene *sc KernelLight *klights = dscene->lights.alloc(num_lights); if (num_lights == 0) { - VLOG(1) << "No effective light, ignoring points update."; + VLOG_WORK << "No effective light, ignoring points update."; return; } @@ -955,9 +958,9 @@ void LightManager::device_update_points(Device *, DeviceScene *dscene, Scene *sc light_index++; } - VLOG(1) << "Number of lights sent to the device: " << light_index; + VLOG_INFO << "Number of lights sent to the device: " << light_index; - VLOG(1) << "Number of lights without contribution: " << num_scene_lights - light_index; + VLOG_INFO << "Number of lights without contribution: " << num_scene_lights - light_index; dscene->lights.copy_to_device(); } @@ -976,7 +979,7 @@ void LightManager::device_update(Device *device, } }); - VLOG(1) << "Total " << scene->lights.size() << " lights."; + VLOG_INFO << "Total " << scene->lights.size() << " lights."; /* Detect which lights are enabled, also determines if we need to update the background. */ test_enabled_lights(scene); diff --git a/intern/cycles/scene/object.cpp b/intern/cycles/scene/object.cpp index ddd89a16640..3a1c177fe3b 100644 --- a/intern/cycles/scene/object.cpp +++ b/intern/cycles/scene/object.cpp @@ -688,7 +688,7 @@ void ObjectManager::device_update(Device *device, dscene->objects.tag_modified(); } - VLOG(1) << "Total " << scene->objects.size() << " objects."; + VLOG_INFO << "Total " << scene->objects.size() << " objects."; device_free(device, dscene, false); diff --git a/intern/cycles/scene/osl.cpp b/intern/cycles/scene/osl.cpp index 6698e6e2cce..f5ee0c0f1d3 100644 --- a/intern/cycles/scene/osl.cpp +++ b/intern/cycles/scene/osl.cpp @@ -92,7 +92,7 @@ void OSLShaderManager::device_update_specific(Device *device, } }); - VLOG(1) << "Total " << scene->shaders.size() << " shaders."; + VLOG_INFO << "Total " << scene->shaders.size() << " shaders."; device_free(device, dscene, scene); @@ -240,7 +240,7 @@ void OSLShaderManager::shading_system_init() ss_shared->attribute("searchpath:shader", shader_path); ss_shared->attribute("greedyjit", 1); - VLOG(1) << "Using shader search path: " << shader_path; + VLOG_INFO << "Using shader search path: " << shader_path; /* our own ray types */ static const char *raytypes[] = { diff --git a/intern/cycles/scene/particles.cpp b/intern/cycles/scene/particles.cpp index a05acf17ccf..b527dd0ebe8 100644 --- a/intern/cycles/scene/particles.cpp +++ b/intern/cycles/scene/particles.cpp @@ -105,7 +105,7 @@ void ParticleSystemManager::device_update(Device *device, } }); - VLOG(1) << "Total " << scene->particle_systems.size() << " particle systems."; + VLOG_INFO << "Total " << scene->particle_systems.size() << " particle systems."; device_free(device, dscene); diff --git a/intern/cycles/scene/scene.cpp b/intern/cycles/scene/scene.cpp index 8b5604eba72..1fcc3331337 100644 --- a/intern/cycles/scene/scene.cpp +++ b/intern/cycles/scene/scene.cpp @@ -34,49 +34,49 @@ CCL_NAMESPACE_BEGIN DeviceScene::DeviceScene(Device *device) - : bvh_nodes(device, "__bvh_nodes", MEM_GLOBAL), - bvh_leaf_nodes(device, "__bvh_leaf_nodes", MEM_GLOBAL), - object_node(device, "__object_node", MEM_GLOBAL), - prim_type(device, "__prim_type", MEM_GLOBAL), - prim_visibility(device, "__prim_visibility", MEM_GLOBAL), - prim_index(device, "__prim_index", MEM_GLOBAL), - prim_object(device, "__prim_object", MEM_GLOBAL), - prim_time(device, "__prim_time", MEM_GLOBAL), - tri_verts(device, "__tri_verts", MEM_GLOBAL), - tri_shader(device, "__tri_shader", MEM_GLOBAL), - tri_vnormal(device, "__tri_vnormal", MEM_GLOBAL), - tri_vindex(device, "__tri_vindex", MEM_GLOBAL), - tri_patch(device, "__tri_patch", MEM_GLOBAL), - tri_patch_uv(device, "__tri_patch_uv", MEM_GLOBAL), - curves(device, "__curves", MEM_GLOBAL), - curve_keys(device, "__curve_keys", MEM_GLOBAL), - curve_segments(device, "__curve_segments", MEM_GLOBAL), - patches(device, "__patches", MEM_GLOBAL), - points(device, "__points", MEM_GLOBAL), - points_shader(device, "__points_shader", MEM_GLOBAL), - objects(device, "__objects", MEM_GLOBAL), - object_motion_pass(device, "__object_motion_pass", MEM_GLOBAL), - object_motion(device, "__object_motion", MEM_GLOBAL), - object_flag(device, "__object_flag", MEM_GLOBAL), - object_volume_step(device, "__object_volume_step", MEM_GLOBAL), - object_prim_offset(device, "__object_prim_offset", MEM_GLOBAL), - camera_motion(device, "__camera_motion", MEM_GLOBAL), - attributes_map(device, "__attributes_map", MEM_GLOBAL), - attributes_float(device, "__attributes_float", MEM_GLOBAL), - attributes_float2(device, "__attributes_float2", MEM_GLOBAL), - attributes_float3(device, "__attributes_float3", MEM_GLOBAL), - attributes_float4(device, "__attributes_float4", MEM_GLOBAL), - attributes_uchar4(device, "__attributes_uchar4", MEM_GLOBAL), - light_distribution(device, "__light_distribution", MEM_GLOBAL), - lights(device, "__lights", MEM_GLOBAL), - light_background_marginal_cdf(device, "__light_background_marginal_cdf", MEM_GLOBAL), - light_background_conditional_cdf(device, "__light_background_conditional_cdf", MEM_GLOBAL), - particles(device, "__particles", MEM_GLOBAL), - svm_nodes(device, "__svm_nodes", MEM_GLOBAL), - shaders(device, "__shaders", MEM_GLOBAL), - lookup_table(device, "__lookup_table", MEM_GLOBAL), - sample_pattern_lut(device, "__sample_pattern_lut", MEM_GLOBAL), - ies_lights(device, "__ies", MEM_GLOBAL) + : bvh_nodes(device, "bvh_nodes", MEM_GLOBAL), + bvh_leaf_nodes(device, "bvh_leaf_nodes", MEM_GLOBAL), + object_node(device, "object_node", MEM_GLOBAL), + prim_type(device, "prim_type", MEM_GLOBAL), + prim_visibility(device, "prim_visibility", MEM_GLOBAL), + prim_index(device, "prim_index", MEM_GLOBAL), + prim_object(device, "prim_object", MEM_GLOBAL), + prim_time(device, "prim_time", MEM_GLOBAL), + tri_verts(device, "tri_verts", MEM_GLOBAL), + tri_shader(device, "tri_shader", MEM_GLOBAL), + tri_vnormal(device, "tri_vnormal", MEM_GLOBAL), + tri_vindex(device, "tri_vindex", MEM_GLOBAL), + tri_patch(device, "tri_patch", MEM_GLOBAL), + tri_patch_uv(device, "tri_patch_uv", MEM_GLOBAL), + curves(device, "curves", MEM_GLOBAL), + curve_keys(device, "curve_keys", MEM_GLOBAL), + curve_segments(device, "curve_segments", MEM_GLOBAL), + patches(device, "patches", MEM_GLOBAL), + points(device, "points", MEM_GLOBAL), + points_shader(device, "points_shader", MEM_GLOBAL), + objects(device, "objects", MEM_GLOBAL), + object_motion_pass(device, "object_motion_pass", MEM_GLOBAL), + object_motion(device, "object_motion", MEM_GLOBAL), + object_flag(device, "object_flag", MEM_GLOBAL), + object_volume_step(device, "object_volume_step", MEM_GLOBAL), + object_prim_offset(device, "object_prim_offset", MEM_GLOBAL), + camera_motion(device, "camera_motion", MEM_GLOBAL), + attributes_map(device, "attributes_map", MEM_GLOBAL), + attributes_float(device, "attributes_float", MEM_GLOBAL), + attributes_float2(device, "attributes_float2", MEM_GLOBAL), + attributes_float3(device, "attributes_float3", MEM_GLOBAL), + attributes_float4(device, "attributes_float4", MEM_GLOBAL), + attributes_uchar4(device, "attributes_uchar4", MEM_GLOBAL), + light_distribution(device, "light_distribution", MEM_GLOBAL), + lights(device, "lights", MEM_GLOBAL), + light_background_marginal_cdf(device, "light_background_marginal_cdf", MEM_GLOBAL), + light_background_conditional_cdf(device, "light_background_conditional_cdf", MEM_GLOBAL), + particles(device, "particles", MEM_GLOBAL), + svm_nodes(device, "svm_nodes", MEM_GLOBAL), + shaders(device, "shaders", MEM_GLOBAL), + lookup_table(device, "lookup_table", MEM_GLOBAL), + sample_pattern_lut(device, "sample_pattern_lut", MEM_GLOBAL), + ies_lights(device, "ies", MEM_GLOBAL) { memset((void *)&data, 0, sizeof(data)); } @@ -366,18 +366,18 @@ void Scene::device_update(Device *device_, Progress &progress) dscene.data.volume_stack_size = get_volume_stack_size(); progress.set_status("Updating Device", "Writing constant memory"); - device->const_copy_to("__data", &dscene.data, sizeof(dscene.data)); + device->const_copy_to("data", &dscene.data, sizeof(dscene.data)); } if (print_stats) { size_t mem_used = util_guarded_get_mem_used(); size_t mem_peak = util_guarded_get_mem_peak(); - VLOG(1) << "System memory statistics after full device sync:\n" - << " Usage: " << string_human_readable_number(mem_used) << " (" - << string_human_readable_size(mem_used) << ")\n" - << " Peak: " << string_human_readable_number(mem_peak) << " (" - << string_human_readable_size(mem_peak) << ")"; + VLOG_INFO << "System memory statistics after full device sync:\n" + << " Usage: " << string_human_readable_number(mem_used) << " (" + << string_human_readable_size(mem_used) << ")\n" + << " Peak: " << string_human_readable_number(mem_peak) << " (" + << string_human_readable_size(mem_peak) << ")"; } } @@ -586,35 +586,38 @@ bool Scene::update(Progress &progress) static void log_kernel_features(const uint features) { - VLOG(2) << "Requested features:\n"; - VLOG(2) << "Use BSDF " << string_from_bool(features & KERNEL_FEATURE_NODE_BSDF) << "\n"; - VLOG(2) << "Use Principled BSDF " << string_from_bool(features & KERNEL_FEATURE_PRINCIPLED) - << "\n"; - VLOG(2) << "Use Emission " << string_from_bool(features & KERNEL_FEATURE_NODE_EMISSION) << "\n"; - VLOG(2) << "Use Volume " << string_from_bool(features & KERNEL_FEATURE_NODE_VOLUME) << "\n"; - VLOG(2) << "Use Bump " << string_from_bool(features & KERNEL_FEATURE_NODE_BUMP) << "\n"; - VLOG(2) << "Use Voronoi " << string_from_bool(features & KERNEL_FEATURE_NODE_VORONOI_EXTRA) - << "\n"; - VLOG(2) << "Use Shader Raytrace " << string_from_bool(features & KERNEL_FEATURE_NODE_RAYTRACE) - << "\n"; - VLOG(2) << "Use MNEE" << string_from_bool(features & KERNEL_FEATURE_MNEE) << "\n"; - VLOG(2) << "Use Transparent " << string_from_bool(features & KERNEL_FEATURE_TRANSPARENT) << "\n"; - VLOG(2) << "Use Denoising " << string_from_bool(features & KERNEL_FEATURE_DENOISING) << "\n"; - VLOG(2) << "Use Path Tracing " << string_from_bool(features & KERNEL_FEATURE_PATH_TRACING) - << "\n"; - VLOG(2) << "Use Hair " << string_from_bool(features & KERNEL_FEATURE_HAIR) << "\n"; - VLOG(2) << "Use Pointclouds " << string_from_bool(features & KERNEL_FEATURE_POINTCLOUD) << "\n"; - VLOG(2) << "Use Object Motion " << string_from_bool(features & KERNEL_FEATURE_OBJECT_MOTION) - << "\n"; - VLOG(2) << "Use Camera Motion " << string_from_bool(features & KERNEL_FEATURE_CAMERA_MOTION) - << "\n"; - VLOG(2) << "Use Baking " << string_from_bool(features & KERNEL_FEATURE_BAKING) << "\n"; - VLOG(2) << "Use Subsurface " << string_from_bool(features & KERNEL_FEATURE_SUBSURFACE) << "\n"; - VLOG(2) << "Use Volume " << string_from_bool(features & KERNEL_FEATURE_VOLUME) << "\n"; - VLOG(2) << "Use Patch Evaluation " - << string_from_bool(features & KERNEL_FEATURE_PATCH_EVALUATION) << "\n"; - VLOG(2) << "Use Shadow Catcher " << string_from_bool(features & KERNEL_FEATURE_SHADOW_CATCHER) - << "\n"; + VLOG_INFO << "Requested features:\n"; + VLOG_INFO << "Use BSDF " << string_from_bool(features & KERNEL_FEATURE_NODE_BSDF) << "\n"; + VLOG_INFO << "Use Principled BSDF " << string_from_bool(features & KERNEL_FEATURE_PRINCIPLED) + << "\n"; + VLOG_INFO << "Use Emission " << string_from_bool(features & KERNEL_FEATURE_NODE_EMISSION) + << "\n"; + VLOG_INFO << "Use Volume " << string_from_bool(features & KERNEL_FEATURE_NODE_VOLUME) << "\n"; + VLOG_INFO << "Use Bump " << string_from_bool(features & KERNEL_FEATURE_NODE_BUMP) << "\n"; + VLOG_INFO << "Use Voronoi " << string_from_bool(features & KERNEL_FEATURE_NODE_VORONOI_EXTRA) + << "\n"; + VLOG_INFO << "Use Shader Raytrace " << string_from_bool(features & KERNEL_FEATURE_NODE_RAYTRACE) + << "\n"; + VLOG_INFO << "Use MNEE" << string_from_bool(features & KERNEL_FEATURE_MNEE) << "\n"; + VLOG_INFO << "Use Transparent " << string_from_bool(features & KERNEL_FEATURE_TRANSPARENT) + << "\n"; + VLOG_INFO << "Use Denoising " << string_from_bool(features & KERNEL_FEATURE_DENOISING) << "\n"; + VLOG_INFO << "Use Path Tracing " << string_from_bool(features & KERNEL_FEATURE_PATH_TRACING) + << "\n"; + VLOG_INFO << "Use Hair " << string_from_bool(features & KERNEL_FEATURE_HAIR) << "\n"; + VLOG_INFO << "Use Pointclouds " << string_from_bool(features & KERNEL_FEATURE_POINTCLOUD) + << "\n"; + VLOG_INFO << "Use Object Motion " << string_from_bool(features & KERNEL_FEATURE_OBJECT_MOTION) + << "\n"; + VLOG_INFO << "Use Camera Motion " << string_from_bool(features & KERNEL_FEATURE_CAMERA_MOTION) + << "\n"; + VLOG_INFO << "Use Baking " << string_from_bool(features & KERNEL_FEATURE_BAKING) << "\n"; + VLOG_INFO << "Use Subsurface " << string_from_bool(features & KERNEL_FEATURE_SUBSURFACE) << "\n"; + VLOG_INFO << "Use Volume " << string_from_bool(features & KERNEL_FEATURE_VOLUME) << "\n"; + VLOG_INFO << "Use Patch Evaluation " + << string_from_bool(features & KERNEL_FEATURE_PATCH_EVALUATION) << "\n"; + VLOG_INFO << "Use Shadow Catcher " << string_from_bool(features & KERNEL_FEATURE_SHADOW_CATCHER) + << "\n"; } bool Scene::load_kernels(Progress &progress, bool lock_scene) @@ -675,8 +678,8 @@ int Scene::get_max_closure_count() * closures discarded due to mixing or low weights. We need to limit * to MAX_CLOSURE as this is hardcoded in CPU/mega kernels, and it * avoids excessive memory usage for split kernels. */ - VLOG(2) << "Maximum number of closures exceeded: " << max_closure_global << " > " - << MAX_CLOSURE; + VLOG_WARNING << "Maximum number of closures exceeded: " << max_closure_global << " > " + << MAX_CLOSURE; max_closure_global = MAX_CLOSURE; } @@ -723,7 +726,7 @@ int Scene::get_volume_stack_size() const volume_stack_size = min(volume_stack_size, MAX_VOLUME_STACK_SIZE); - VLOG(3) << "Detected required volume stack size " << volume_stack_size; + VLOG_WORK << "Detected required volume stack size " << volume_stack_size; return volume_stack_size; } diff --git a/intern/cycles/scene/scene.h b/intern/cycles/scene/scene.h index a0d2f4a6c06..d04c6a27f11 100644 --- a/intern/cycles/scene/scene.h +++ b/intern/cycles/scene/scene.h @@ -98,7 +98,7 @@ class DeviceScene { device_vector<DecomposedTransform> camera_motion; /* attributes */ - device_vector<uint4> attributes_map; + device_vector<AttributeMap> attributes_map; device_vector<float> attributes_float; device_vector<float2> attributes_float2; device_vector<packed_float3> attributes_float3; diff --git a/intern/cycles/scene/shader_graph.cpp b/intern/cycles/scene/shader_graph.cpp index f25d0b7c7b9..ef3f142ed4e 100644 --- a/intern/cycles/scene/shader_graph.cpp +++ b/intern/cycles/scene/shader_graph.cpp @@ -659,7 +659,7 @@ void ShaderGraph::deduplicate_nodes() } if (num_deduplicated > 0) { - VLOG(1) << "Deduplicated " << num_deduplicated << " nodes."; + VLOG_DEBUG << "Deduplicated " << num_deduplicated << " nodes."; } } @@ -700,7 +700,7 @@ void ShaderGraph::verify_volume_output() } } if (!has_valid_volume) { - VLOG(1) << "Disconnect meaningless volume output."; + VLOG_DEBUG << "Disconnect meaningless volume output."; disconnect(volume_in->link); } } diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp index 3b58556f601..f93a1a5231a 100644 --- a/intern/cycles/scene/shader_nodes.cpp +++ b/intern/cycles/scene/shader_nodes.cpp @@ -2391,7 +2391,7 @@ void GlossyBsdfNode::simplify_settings(Scene *scene) * NOTE: Keep the epsilon in sync with kernel! */ if (!roughness_input->link && roughness <= 1e-4f) { - VLOG(3) << "Using sharp glossy BSDF."; + VLOG_DEBUG << "Using sharp glossy BSDF."; distribution = CLOSURE_BSDF_REFLECTION_ID; } } @@ -2400,7 +2400,7 @@ void GlossyBsdfNode::simplify_settings(Scene *scene) * benefit from closure blur to remove unwanted noise. */ if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_REFLECTION_ID) { - VLOG(3) << "Using GGX glossy with filter glossy."; + VLOG_DEBUG << "Using GGX glossy with filter glossy."; distribution = CLOSURE_BSDF_MICROFACET_GGX_ID; roughness = 0.0f; } @@ -2484,7 +2484,7 @@ void GlassBsdfNode::simplify_settings(Scene *scene) * NOTE: Keep the epsilon in sync with kernel! */ if (!roughness_input->link && roughness <= 1e-4f) { - VLOG(3) << "Using sharp glass BSDF."; + VLOG_DEBUG << "Using sharp glass BSDF."; distribution = CLOSURE_BSDF_SHARP_GLASS_ID; } } @@ -2493,7 +2493,7 @@ void GlassBsdfNode::simplify_settings(Scene *scene) * benefit from closure blur to remove unwanted noise. */ if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_SHARP_GLASS_ID) { - VLOG(3) << "Using GGX glass with filter glossy."; + VLOG_DEBUG << "Using GGX glass with filter glossy."; distribution = CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID; roughness = 0.0f; } @@ -2577,7 +2577,7 @@ void RefractionBsdfNode::simplify_settings(Scene *scene) * NOTE: Keep the epsilon in sync with kernel! */ if (!roughness_input->link && roughness <= 1e-4f) { - VLOG(3) << "Using sharp refraction BSDF."; + VLOG_DEBUG << "Using sharp refraction BSDF."; distribution = CLOSURE_BSDF_REFRACTION_ID; } } @@ -2586,7 +2586,7 @@ void RefractionBsdfNode::simplify_settings(Scene *scene) * benefit from closure blur to remove unwanted noise. */ if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_REFRACTION_ID) { - VLOG(3) << "Using GGX refraction with filter glossy."; + VLOG_DEBUG << "Using GGX refraction with filter glossy."; distribution = CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID; roughness = 0.0f; } diff --git a/intern/cycles/scene/svm.cpp b/intern/cycles/scene/svm.cpp index 484a7d6de72..4bc5a1b9cc2 100644 --- a/intern/cycles/scene/svm.cpp +++ b/intern/cycles/scene/svm.cpp @@ -51,9 +51,9 @@ void SVMShaderManager::device_update_shader(Scene *scene, compiler.background = (shader == scene->background->get_shader(scene)); compiler.compile(shader, *svm_nodes, 0, &summary); - VLOG(3) << "Compilation summary:\n" - << "Shader name: " << shader->name << "\n" - << summary.full_report(); + VLOG_WORK << "Compilation summary:\n" + << "Shader name: " << shader->name << "\n" + << summary.full_report(); } void SVMShaderManager::device_update_specific(Device *device, @@ -72,7 +72,7 @@ void SVMShaderManager::device_update_specific(Device *device, const int num_shaders = scene->shaders.size(); - VLOG(1) << "Total " << num_shaders << " shaders."; + VLOG_INFO << "Total " << num_shaders << " shaders."; double start_time = time_dt(); @@ -148,8 +148,8 @@ void SVMShaderManager::device_update_specific(Device *device, update_flags = UPDATE_NONE; - VLOG(1) << "Shader manager updated " << num_shaders << " shaders in " << time_dt() - start_time - << " seconds."; + VLOG_INFO << "Shader manager updated " << num_shaders << " shaders in " << time_dt() - start_time + << " seconds."; } void SVMShaderManager::device_free(Device *device, DeviceScene *dscene, Scene *scene) diff --git a/intern/cycles/scene/tables.cpp b/intern/cycles/scene/tables.cpp index bb35880d37e..3e57b535f35 100644 --- a/intern/cycles/scene/tables.cpp +++ b/intern/cycles/scene/tables.cpp @@ -34,7 +34,7 @@ void LookupTables::device_update(Device *, DeviceScene *dscene, Scene *scene) } }); - VLOG(1) << "Total " << lookup_tables.size() << " lookup tables."; + VLOG_INFO << "Total " << lookup_tables.size() << " lookup tables."; if (lookup_tables.size() > 0) dscene->lookup_table.copy_to_device(); diff --git a/intern/cycles/scene/volume.cpp b/intern/cycles/scene/volume.cpp index 39e9b0bbbf4..77955350305 100644 --- a/intern/cycles/scene/volume.cpp +++ b/intern/cycles/scene/volume.cpp @@ -754,11 +754,11 @@ void GeometryManager::create_volume_mesh(const Scene *scene, Volume *volume, Pro } /* Print stats. */ - VLOG(1) << "Memory usage volume mesh: " - << ((vertices.size() + face_normals.size()) * sizeof(float3) + - indices.size() * sizeof(int)) / - (1024.0 * 1024.0) - << "Mb."; + VLOG_WORK << "Memory usage volume mesh: " + << ((vertices.size() + face_normals.size()) * sizeof(float3) + + indices.size() * sizeof(int)) / + (1024.0 * 1024.0) + << "Mb."; } CCL_NAMESPACE_END diff --git a/intern/cycles/session/session.cpp b/intern/cycles/session/session.cpp index ef177636046..ba30be817cf 100644 --- a/intern/cycles/session/session.cpp +++ b/intern/cycles/session/session.cpp @@ -146,11 +146,11 @@ void Session::run_main_render_loop() RenderWork render_work = run_update_for_next_iteration(); if (!render_work) { - if (VLOG_IS_ON(2)) { + if (VLOG_WORK_IS_ON) { double total_time, render_time; progress.get_time(total_time, render_time); - VLOG(2) << "Rendering in main loop is done in " << render_time << " seconds."; - VLOG(2) << path_trace_->full_report(); + VLOG_WORK << "Rendering in main loop is done in " << render_time << " seconds."; + VLOG_WORK << path_trace_->full_report(); } if (params.background) { diff --git a/intern/cycles/session/tile.cpp b/intern/cycles/session/tile.cpp index 82272a7dbf5..f4930cbb945 100644 --- a/intern/cycles/session/tile.cpp +++ b/intern/cycles/session/tile.cpp @@ -335,7 +335,7 @@ int TileManager::compute_render_tile_size(const int suggested_tile_size) const void TileManager::reset_scheduling(const BufferParams ¶ms, int2 tile_size) { - VLOG(3) << "Using tile size of " << tile_size; + VLOG_WORK << "Using tile size of " << tile_size; close_tile_output(); @@ -466,7 +466,7 @@ bool TileManager::open_tile_output() write_state_.num_tiles_written = 0; - VLOG(3) << "Opened tile file " << write_state_.filename; + VLOG_WORK << "Opened tile file " << write_state_.filename; return true; } @@ -485,7 +485,7 @@ bool TileManager::close_tile_output() return false; } - VLOG(3) << "Tile output is closed."; + VLOG_WORK << "Tile output is closed."; return true; } @@ -536,7 +536,7 @@ bool TileManager::write_tile(const RenderBuffers &tile_buffers) pixels = pixel_storage.data(); } - VLOG(3) << "Write tile at " << tile_x << ", " << tile_y; + VLOG_WORK << "Write tile at " << tile_x << ", " << tile_y; /* The image tile sizes in the OpenEXR file are different from the size of our big tiles. The * write_tiles() method expects a contiguous image region that will be split into tiles @@ -567,7 +567,7 @@ bool TileManager::write_tile(const RenderBuffers &tile_buffers) ++write_state_.num_tiles_written; - VLOG(3) << "Tile written in " << time_dt() - time_start << " seconds."; + VLOG_WORK << "Tile written in " << time_dt() - time_start << " seconds."; return true; } @@ -591,7 +591,7 @@ void TileManager::finish_write_tiles() const int tile_x = tile.x + tile.window_x; const int tile_y = tile.y + tile.window_y; - VLOG(3) << "Write dummy tile at " << tile_x << ", " << tile_y; + VLOG_WORK << "Write dummy tile at " << tile_x << ", " << tile_y; write_state_.tile_out->write_tiles(tile_x, tile_x + tile.window_width, @@ -610,8 +610,8 @@ void TileManager::finish_write_tiles() full_buffer_written_cb(write_state_.filename); } - VLOG(3) << "Tile file size is " - << string_human_readable_number(path_file_size(write_state_.filename)) << " bytes."; + VLOG_WORK << "Tile file size is " + << string_human_readable_number(path_file_size(write_state_.filename)) << " bytes."; /* Advance the counter upon explicit finish of the file. * Makes it possible to re-use tile manager for another scene, and avoids unnecessary increments diff --git a/intern/cycles/test/render_graph_finalize_test.cpp b/intern/cycles/test/render_graph_finalize_test.cpp index dac36ab0135..2dc13f0eccb 100644 --- a/intern/cycles/test/render_graph_finalize_test.cpp +++ b/intern/cycles/test/render_graph_finalize_test.cpp @@ -166,7 +166,7 @@ class RenderGraph : public testing::Test { virtual void SetUp() { util_logging_start(); - util_logging_verbosity_set(3); + util_logging_verbosity_set(5); device_cpu = Device::create(device_info, stats, profiler); scene = new Scene(scene_params, device_cpu); diff --git a/intern/cycles/util/debug.cpp b/intern/cycles/util/debug.cpp index 65d108bb9d1..faa54a92c24 100644 --- a/intern/cycles/util/debug.cpp +++ b/intern/cycles/util/debug.cpp @@ -25,7 +25,7 @@ void DebugFlags::CPU::reset() do { \ flag = (getenv(env) == NULL); \ if (!flag) { \ - VLOG(1) << "Disabling " << STRINGIFY(flag) << " instruction set."; \ + VLOG_INFO << "Disabling " << STRINGIFY(flag) << " instruction set."; \ } \ } while (0) diff --git a/intern/cycles/util/log.h b/intern/cycles/util/log.h index b33c826d6f5..3780d03c0d1 100644 --- a/intern/cycles/util/log.h +++ b/intern/cycles/util/log.h @@ -69,9 +69,22 @@ class LogMessageVoidify { # define LOG_ASSERT(expression) LOG_SUPPRESS() #endif -#define VLOG_ONCE(level, flag) \ - if (!flag) \ - flag = true, VLOG(level) +/* Verbose logging categories. */ + +/* Warnings. */ +#define VLOG_WARNING VLOG(1) +/* Info about devices, scene contents and features used. */ +#define VLOG_INFO VLOG(2) +#define VLOG_INFO_IS_ON VLOG_IS_ON(2) +/* Work being performed and timing/memory stats about that work. */ +#define VLOG_WORK VLOG(3) +#define VLOG_WORK_IS_ON VLOG_IS_ON(3) +/* Detailed device timing stats. */ +#define VLOG_DEVICE_STATS VLOG(4) +#define VLOG_DEVICE_STATS_IS_ON VLOG_IS_ON(4) +/* Verbose debug messages. */ +#define VLOG_DEBUG VLOG(5) +#define VLOG_DEBUG_IS_ON VLOG_IS_ON(5) struct int2; struct float3; diff --git a/intern/cycles/util/task.cpp b/intern/cycles/util/task.cpp index 2edc82eb7c3..12f661f752d 100644 --- a/intern/cycles/util/task.cpp +++ b/intern/cycles/util/task.cpp @@ -70,7 +70,7 @@ void TaskScheduler::init(int num_threads) } if (num_threads > 0) { /* Automatic number of threads. */ - VLOG(1) << "Overriding number of TBB threads to " << num_threads << "."; + VLOG_INFO << "Overriding number of TBB threads to " << num_threads << "."; global_control = new tbb::global_control(tbb::global_control::max_allowed_parallelism, num_threads); active_num_threads = num_threads; diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt index 5b06b5d98e6..945b3261562 100644 --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -303,59 +303,63 @@ elseif(WITH_GHOST_X11 OR WITH_GHOST_WAYLAND) message(FATAL_ERROR "path to wayland-protocols not found") endif() + set(INC_DST ${CMAKE_CURRENT_BINARY_DIR}/libwayland) + # Generate protocols bindings. - macro(generate_protocol_bindings NAME PROT_DEF) + macro(generate_protocol_bindings PROT_DEF) + # File name without directory or extension (use for header name). + get_filename_component(_name ${PROT_DEF} NAME_WLE) add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.h - COMMAND ${WAYLAND_SCANNER} client-header ${PROT_DEF} ${NAME}-client-protocol.h + OUTPUT ${INC_DST}/${_name}-client-protocol.h + COMMAND ${CMAKE_COMMAND} -E make_directory ${INC_DST} + COMMAND ${WAYLAND_SCANNER} client-header ${PROT_DEF} ${INC_DST}/${_name}-client-protocol.h ) add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.c - COMMAND ${WAYLAND_SCANNER} private-code ${PROT_DEF} ${NAME}-client-protocol.c - DEPENDS ${NAME}-client-protocol.h + OUTPUT ${INC_DST}/${_name}-client-protocol.c + COMMAND ${CMAKE_COMMAND} -E make_directory ${INC_DST} + COMMAND ${WAYLAND_SCANNER} private-code ${PROT_DEF} ${INC_DST}/${_name}-client-protocol.c + DEPENDS ${INC_DST}/${_name}-client-protocol.h ) list(APPEND SRC - ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.c - ${CMAKE_CURRENT_BINARY_DIR}/${NAME}-client-protocol.h + ${INC_DST}/${_name}-client-protocol.c + ${INC_DST}/${_name}-client-protocol.h ) + unset(_name) endmacro() + list(APPEND INC_SYS - ${CMAKE_CURRENT_BINARY_DIR} + ${INC_DST} ) # `xdg-shell`. generate_protocol_bindings( - xdg-shell "${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml" ) # `xdg-decoration`. generate_protocol_bindings( - xdg-decoration "${WAYLAND_PROTOCOLS_DIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml" ) # `xdg-output`. generate_protocol_bindings( - xdg-output "${WAYLAND_PROTOCOLS_DIR}/unstable/xdg-output/xdg-output-unstable-v1.xml" ) # Pointer-constraints. generate_protocol_bindings( - pointer-constraints "${WAYLAND_PROTOCOLS_DIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml" ) # Relative-pointer. generate_protocol_bindings( - relative-pointer "${WAYLAND_PROTOCOLS_DIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml" ) # Tablet. generate_protocol_bindings( - tablet "${WAYLAND_PROTOCOLS_DIR}/unstable/tablet/tablet-unstable-v2.xml" ) add_definitions(-DWITH_GHOST_WAYLAND) + + unset(INC_DST) endif() if(WITH_INPUT_NDOF) diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index c92e6ba78c1..5ace0fcc9d2 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -20,7 +20,7 @@ extern "C" { * \param event: The event received. * \param userdata: The callback's user data, supplied to #GHOST_CreateSystem. */ -typedef int (*GHOST_EventCallbackProcPtr)(GHOST_EventHandle event, GHOST_TUserDataPtr userdata); +typedef bool (*GHOST_EventCallbackProcPtr)(GHOST_EventHandle event, GHOST_TUserDataPtr userdata); /** * Creates the one and only system. @@ -206,7 +206,7 @@ extern GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandl */ extern void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr userdata); -extern int GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle); +extern bool GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle); /** * Dispose a window. @@ -223,7 +223,7 @@ extern GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, * \param windowhandle: Handle to the window to be checked. * \return Indication of validity. */ -extern int GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle); +extern bool GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle); /** * Begins full screen mode. @@ -235,7 +235,7 @@ extern int GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle */ extern GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle, GHOST_DisplaySetting *setting, - const int stereoVisual); + const bool stereoVisual); /** * Ends full screen mode. @@ -249,7 +249,7 @@ extern GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle); * \param systemhandle: The handle to the system. * \return The current status. */ -extern int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle); +extern bool GHOST_GetFullScreen(GHOST_SystemHandle systemhandle); /** * Get the Window under the cursor. @@ -364,12 +364,15 @@ extern GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle int hotY, bool canInvertColor); +extern GHOST_TSuccess GHOST_GetCursorBitmap(GHOST_WindowHandle windowhandle, + GHOST_CursorBitmapRef *bitmap); + /** * Returns the visibility state of the cursor. * \param windowhandle: The handle to the window. * \return The visibility state of the cursor. */ -extern int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle); +extern bool GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle); /** * Shows or hides the cursor. @@ -377,7 +380,7 @@ extern int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle); * \param visible: The new visibility state of the cursor. * \return Indication of success. */ -extern GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, int visible); +extern GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, bool visible); /** * Returns the current location of the cursor (location in screen coordinates) @@ -404,8 +407,9 @@ extern GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle, void GHOST_GetCursorGrabState(GHOST_WindowHandle windowhandle, GHOST_TGrabCursorMode *r_mode, - GHOST_TAxisFlag *r_wrap_axis, - int r_bounds[4]); + GHOST_TAxisFlag *r_axis_flag, + int r_bounds[4], + bool *r_use_software_cursor); /** * Grabs the cursor for a modal operation, to keep receiving @@ -436,7 +440,7 @@ extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle, */ extern GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle, GHOST_TModifierKeyMask mask, - int *isDown); + bool *r_is_down); /** * Returns the state of a mouse button (outside the message queue). @@ -447,7 +451,7 @@ extern GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle, */ extern GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle, GHOST_TButtonMask mask, - int *isDown); + bool *r_is_down); #ifdef WITH_INPUT_NDOF /*************************************************************************************** @@ -468,7 +472,7 @@ extern void GHOST_setNDOFDeadZone(float deadzone); /** * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop */ -extern void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool canAccept); +extern void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool can_accept); /** * Returns the event type. @@ -534,7 +538,7 @@ extern void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle, * \param windowhandle: The handle to the window. * \return The validity of the window. */ -extern int GHOST_GetValid(GHOST_WindowHandle windowhandle); +extern bool GHOST_GetValid(GHOST_WindowHandle windowhandle); /** * Returns the type of drawing context used in this window. @@ -894,22 +898,22 @@ extern void GHOST_putClipboard(const char *buffer, bool selection); * \param action: console state * \return current status (1 -visible, 0 - hidden) */ -extern int setConsoleWindowState(GHOST_TConsoleWindowState action); +extern bool GHOST_setConsoleWindowState(GHOST_TConsoleWindowState action); /** * Use native pixel size (MacBook pro 'retina'), if supported. */ -extern int GHOST_UseNativePixels(void); +extern bool GHOST_UseNativePixels(void); /** * Warp the cursor, if supported. */ -extern int GHOST_SupportsCursorWarp(void); +extern bool GHOST_SupportsCursorWarp(void); /** * Support positioning windows (when false `wmWindow.x,y` are meaningless). */ -extern int GHOST_SupportsWindowPosition(void); +extern bool GHOST_SupportsWindowPosition(void); /** * Assign the callback which generates a back-trace (may be NULL). @@ -919,7 +923,7 @@ extern void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn); /** * Focus window after opening, or put them in the background. */ -extern void GHOST_UseWindowFocus(int use_focus); +extern void GHOST_UseWindowFocus(bool use_focus); /** * If window was opened using native pixel size, it returns scaling factor. diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h index 7927190de04..f712d9bd9f0 100644 --- a/intern/ghost/GHOST_IWindow.h +++ b/intern/ghost/GHOST_IWindow.h @@ -258,7 +258,10 @@ class GHOST_IWindow { virtual void getCursorGrabState(GHOST_TGrabCursorMode &mode, GHOST_TAxisFlag &axis_flag, - GHOST_Rect &bounds) = 0; + GHOST_Rect &bounds, + bool &use_software_cursor) = 0; + + virtual bool getCursorGrabUseSoftwareDisplay() = 0; /** * Test if the standard cursor shape is supported by current platform. @@ -282,6 +285,8 @@ class GHOST_IWindow { int hotY, bool canInvertColor) = 0; + virtual GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap) = 0; + /** * Returns the visibility state of the cursor. * \return The visibility state of the cursor. diff --git a/intern/ghost/GHOST_Rect.h b/intern/ghost/GHOST_Rect.h index 0a5561b7d68..1cbc75fe60b 100644 --- a/intern/ghost/GHOST_Rect.h +++ b/intern/ghost/GHOST_Rect.h @@ -101,6 +101,12 @@ class GHOST_Rect { * \param y: The y-coordinate of the point. */ virtual inline void wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis); + /** + * Confine x & y within the rectangle (inclusive). + * \param x: The x-coordinate of the point. + * \param y: The y-coordinate of the point. + */ + virtual inline void clampPoint(int32_t &x, int32_t &y); /** * Returns whether the point is inside this rectangle. @@ -190,26 +196,34 @@ inline bool GHOST_Rect::isValid() const inline void GHOST_Rect::unionRect(const GHOST_Rect &r) { - if (r.m_l < m_l) + if (r.m_l < m_l) { m_l = r.m_l; - if (r.m_r > m_r) + } + if (r.m_r > m_r) { m_r = r.m_r; - if (r.m_t < m_t) + } + if (r.m_t < m_t) { m_t = r.m_t; - if (r.m_b > m_b) + } + if (r.m_b > m_b) { m_b = r.m_b; + } } inline void GHOST_Rect::unionPoint(int32_t x, int32_t y) { - if (x < m_l) + if (x < m_l) { m_l = x; - if (x > m_r) + } + if (x > m_r) { m_r = x; - if (y < m_t) + } + if (y < m_t) { m_t = y; - if (y > m_b) + } + if (y > m_b) { m_b = y; + } } inline void GHOST_Rect::wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis) @@ -223,16 +237,37 @@ inline void GHOST_Rect::wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAx } if (axis & GHOST_kAxisX) { - while (x - ofs < m_l) + while (x - ofs < m_l) { x += w - (ofs * 2); - while (x + ofs > m_r) + } + while (x + ofs > m_r) { x -= w - (ofs * 2); + } } if (axis & GHOST_kGrabAxisY) { - while (y - ofs < m_t) + while (y - ofs < m_t) { y += h - (ofs * 2); - while (y + ofs > m_b) + } + while (y + ofs > m_b) { y -= h - (ofs * 2); + } + } +} + +inline void GHOST_Rect::clampPoint(int32_t &x, int32_t &y) +{ + if (x < m_l) { + x = m_l; + } + else if (x > m_r) { + x = m_r; + } + + if (y < m_t) { + y = m_t; + } + else if (y > m_b) { + y = m_b; } } diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index 78f2b24ea78..35bde3d4413 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -44,6 +44,16 @@ GHOST_DECLARE_HANDLE(GHOST_XrContextHandle); typedef void (*GHOST_TBacktraceFn)(void *file_handle); +/** + * A reference to cursor bitmap data. + */ +typedef struct { + /** `RGBA` bytes. */ + const uint8_t *data; + int data_size[2]; + int hot_spot[2]; +} GHOST_CursorBitmapRef; + typedef struct { int flags; } GHOST_GLSettings; diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index b1a15fdf4d7..2b5414cd47b 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -177,11 +177,11 @@ void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr window->setUserData(userdata); } -int GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle) +bool GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)window->isDialog(); + return window->isDialog(); } GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, @@ -193,17 +193,17 @@ GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, return system->disposeWindow(window); } -int GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle) +bool GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)system->validWindow(window); + return system->validWindow(window); } GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle, GHOST_DisplaySetting *setting, - const int stereoVisual) + const bool stereoVisual) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_IWindow *window = nullptr; @@ -228,11 +228,11 @@ GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle) return system->endFullScreen(); } -int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle) +bool GHOST_GetFullScreen(GHOST_SystemHandle systemhandle) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; - return (int)system->getFullScreen(); + return system->getFullScreen(); } GHOST_WindowHandle GHOST_GetWindowUnderCursor(GHOST_SystemHandle systemhandle, @@ -326,18 +326,26 @@ GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle, return window->setCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor); } -int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle) +GHOST_TSuccess GHOST_GetCursorBitmap(GHOST_WindowHandle windowhandle, + GHOST_CursorBitmapRef *bitmap) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)window->getCursorVisibility(); + return window->getCursorBitmap(bitmap); } -GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, int visible) +bool GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return window->setCursorVisibility(visible ? true : false); + return window->getCursorVisibility(); +} + +GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, bool visible) +{ + GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; + + return window->setCursorVisibility(visible); } GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle, int32_t *x, int32_t *y) @@ -379,41 +387,44 @@ GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle, void GHOST_GetCursorGrabState(GHOST_WindowHandle windowhandle, GHOST_TGrabCursorMode *r_mode, GHOST_TAxisFlag *r_axis_flag, - int r_bounds[4]) + int r_bounds[4], + bool *r_use_software_cursor) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; GHOST_Rect bounds_rect; - window->getCursorGrabState(*r_mode, *r_axis_flag, bounds_rect); + bool use_software_cursor; + window->getCursorGrabState(*r_mode, *r_axis_flag, bounds_rect, use_software_cursor); r_bounds[0] = bounds_rect.m_l; r_bounds[1] = bounds_rect.m_t; r_bounds[2] = bounds_rect.m_r; r_bounds[3] = bounds_rect.m_b; + *r_use_software_cursor = use_software_cursor; } GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle, GHOST_TModifierKeyMask mask, - int *isDown) + bool *r_is_down) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_TSuccess result; - bool isdown = false; + bool is_down = false; - result = system->getModifierKeyState(mask, isdown); - *isDown = (int)isdown; + result = system->getModifierKeyState(mask, is_down); + *r_is_down = is_down; return result; } GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle, GHOST_TButtonMask mask, - int *isDown) + bool *r_is_down) { GHOST_ISystem *system = (GHOST_ISystem *)systemhandle; GHOST_TSuccess result; - bool isdown = false; + bool is_down = false; - result = system->getButtonState(mask, isdown); - *isDown = (int)isdown; + result = system->getButtonState(mask, is_down); + *r_is_down = is_down; return result; } @@ -426,11 +437,11 @@ void GHOST_setNDOFDeadZone(float deadzone) } #endif -void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool canAccept) +void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, bool can_accept) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - window->setAcceptDragOperation(canAccept); + window->setAcceptDragOperation(can_accept); } GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle) @@ -489,11 +500,11 @@ void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle, GHOST_TUs timertask->setUserData(userdata); } -int GHOST_GetValid(GHOST_WindowHandle windowhandle) +bool GHOST_GetValid(GHOST_WindowHandle windowhandle) { GHOST_IWindow *window = (GHOST_IWindow *)windowhandle; - return (int)window->getValid(); + return window->getValid(); } GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle) @@ -817,25 +828,26 @@ void GHOST_putClipboard(const char *buffer, bool selection) system->putClipboard(buffer, selection); } -int setConsoleWindowState(GHOST_TConsoleWindowState action) +bool GHOST_setConsoleWindowState(GHOST_TConsoleWindowState action) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); - return system->setConsoleWindowState(action); + /* FIXME: use `bool` instead of int for this value. */ + return (bool)system->setConsoleWindowState(action); } -int GHOST_UseNativePixels(void) +bool GHOST_UseNativePixels(void) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->useNativePixel(); } -int GHOST_SupportsCursorWarp(void) +bool GHOST_SupportsCursorWarp(void) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->supportsCursorWarp(); } -int GHOST_SupportsWindowPosition(void) +bool GHOST_SupportsWindowPosition(void) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->supportsWindowPosition(); @@ -846,7 +858,7 @@ void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn) GHOST_ISystem::setBacktraceFn(backtrace_fn); } -void GHOST_UseWindowFocus(int use_focus) +void GHOST_UseWindowFocus(bool use_focus) { GHOST_ISystem *system = GHOST_ISystem::getSystem(); return system->useWindowFocus(use_focus); diff --git a/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp b/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp index 72aeebdc876..9f14d56cd9a 100644 --- a/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp +++ b/intern/ghost/intern/GHOST_CallbackEventConsumer.cpp @@ -22,5 +22,5 @@ GHOST_CallbackEventConsumer::GHOST_CallbackEventConsumer(GHOST_EventCallbackProc bool GHOST_CallbackEventConsumer::processEvent(GHOST_IEvent *event) { - return m_eventCallback((GHOST_EventHandle)event, m_userData) != 0; + return m_eventCallback((GHOST_EventHandle)event, m_userData); } diff --git a/intern/ghost/intern/GHOST_ContextGLX.cpp b/intern/ghost/intern/GHOST_ContextGLX.cpp index baabdc6c521..b4a076e4598 100644 --- a/intern/ghost/intern/GHOST_ContextGLX.cpp +++ b/intern/ghost/intern/GHOST_ContextGLX.cpp @@ -105,7 +105,7 @@ GHOST_TSuccess GHOST_ContextGLX::initializeDrawingContext() GHOST_X11_ERROR_HANDLERS_OVERRIDE(handler_store); /* -------------------------------------------------------------------- */ - /* Begin Inline Glew */ + /* Begin Inline GLEW. */ #ifdef USE_GLXEW_INIT_WORKAROUND const GLubyte *extStart = (GLubyte *)""; @@ -142,11 +142,11 @@ GHOST_TSuccess GHOST_ContextGLX::initializeDrawingContext() "GLX_EXT_create_context_es2_profile", extStart, extEnd); # endif /* WITH_GLEW_ES */ - /* End Inline Glew */ + /* End Inline GLEW. */ /* -------------------------------------------------------------------- */ #else - /* important to initialize only glxew (_not_ glew), - * since this breaks w/ Mesa's `swrast`, see: T46431 */ + /* Important to initialize only glxew (_not_ GLEW), + * since this breaks w/ Mesa's `swrast`, see: T46431. */ glxewInit(); #endif /* USE_GLXEW_INIT_WORKAROUND */ @@ -395,7 +395,7 @@ int GHOST_X11_GL_GetAttributes( return i; } -/* excuse inlining part of glew */ +/* Excuse inlining part of GLEW. */ #ifdef USE_GLXEW_INIT_WORKAROUND static GLuint _glewStrLen(const GLubyte *s) { diff --git a/intern/ghost/intern/GHOST_DropTargetX11.cpp b/intern/ghost/intern/GHOST_DropTargetX11.cpp index 70c2eb8c29e..900e46c3732 100644 --- a/intern/ghost/intern/GHOST_DropTargetX11.cpp +++ b/intern/ghost/intern/GHOST_DropTargetX11.cpp @@ -31,7 +31,7 @@ int GHOST_DropTargetX11::m_refCounter = 0; #define dndTypePlainText m_dndTypes[dndTypePlainTextID] #define dndTypeOctetStream m_dndTypes[dndTypeOctetStreamID] -void GHOST_DropTargetX11::Initialize(void) +void GHOST_DropTargetX11::Initialize() { Display *display = m_system->getXDisplay(); int dndTypesCount = sizeof(m_dndMimeTypes) / sizeof(char *); @@ -60,7 +60,7 @@ void GHOST_DropTargetX11::Initialize(void) m_dndActions[counter++] = 0; } -void GHOST_DropTargetX11::Uninitialize(void) +void GHOST_DropTargetX11::Uninitialize() { xdnd_shut(&m_dndClass); @@ -98,12 +98,12 @@ GHOST_DropTargetX11::~GHOST_DropTargetX11() /* Based on: https://stackoverflow.com/a/2766963/432509 */ -typedef enum DecodeState_e { +using DecodeState_e = enum DecodeState_e { /** Searching for an ampersand to convert. */ STATE_SEARCH = 0, /** Convert the two proceeding characters from hex. */ STATE_CONVERTING -} DecodeState_e; +}; void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char *encodedIn) { @@ -122,7 +122,7 @@ void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char case STATE_SEARCH: if (encodedIn[i] != '%') { strncat(decodedOut, &encodedIn[i], 1); - assert(strlen(decodedOut) < bufferSize); + assert((int)strlen(decodedOut) < bufferSize); break; } @@ -145,18 +145,19 @@ void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char /* Ensure both characters are hexadecimal */ for (j = 0; j < 2; ++j) { - if (!isxdigit(tempNumBuf[j])) + if (!isxdigit(tempNumBuf[j])) { bothDigits = false; + } } - if (!bothDigits) + if (!bothDigits) { break; - + } /* Convert two hexadecimal characters into one character */ sscanf(tempNumBuf, "%x", &asciiCharacter); /* Ensure we aren't going to overflow */ - assert(strlen(decodedOut) < bufferSize); + assert((int)strlen(decodedOut) < bufferSize); /* Concatenate this character onto the output */ strncat(decodedOut, (char *)&asciiCharacter, 1); diff --git a/intern/ghost/intern/GHOST_EventPrinter.cpp b/intern/ghost/intern/GHOST_EventPrinter.cpp index 758938e879e..2620bcc075d 100644 --- a/intern/ghost/intern/GHOST_EventPrinter.cpp +++ b/intern/ghost/intern/GHOST_EventPrinter.cpp @@ -12,7 +12,7 @@ #include "GHOST_EventKey.h" #include <iostream> -#include <stdio.h> +#include <cstdio> bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event) { @@ -20,9 +20,9 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event) GHOST_ASSERT(event, "event==0"); - if (event->getType() == GHOST_kEventWindowUpdate) + if (event->getType() == GHOST_kEventWindowUpdate) { return false; - + } std::cout << "GHOST_EventPrinter::processEvent, time: " << (int32_t)event->getTime() << ", type: "; switch (event->getType()) { @@ -106,8 +106,9 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event) std::cout << " type : GHOST_kDragnDropTypeFilenames,"; std::cout << "\n Received " << strArray->count << " filename" << (strArray->count > 1 ? "s:" : ":"); - for (i = 0; i < strArray->count; i++) + for (i = 0; i < strArray->count; i++) { std::cout << "\n File[" << i << "] : " << strArray->strings[i]; + } } break; default: break; @@ -117,10 +118,12 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event) case GHOST_kEventOpenMainFile: { GHOST_TEventDataPtr eventData = ((GHOST_IEvent *)event)->getData(); - if (eventData) + if (eventData) { std::cout << "GHOST_kEventOpenMainFile for path : " << (char *)eventData; - else + } + else { std::cout << "GHOST_kEventOpenMainFile with no path specified!!"; + } } break; case GHOST_kEventQuitRequest: @@ -167,7 +170,7 @@ void GHOST_EventPrinter::getKeyString(GHOST_TKey key, char str[32]) const sprintf(str, "F%d", key - GHOST_kKeyF1 + 1); } else { - const char *tstr = NULL; + const char *tstr = nullptr; switch (key) { case GHOST_kKeyBackSpace: tstr = "BackSpace"; diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp index 7f6b5f53316..2298ba86521 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.cpp +++ b/intern/ghost/intern/GHOST_NDOFManager.cpp @@ -6,10 +6,10 @@ #include "GHOST_EventNDOF.h" #include "GHOST_WindowManager.h" -#include <limits.h> -#include <math.h> -#include <stdio.h> /* For error/info reporting. */ -#include <string.h> /* For memory functions. */ +#include <climits> +#include <cmath> +#include <cstdio> /* For error/info reporting. */ +#include <cstring> /* For memory functions. */ #ifdef DEBUG_NDOF_MOTION /* Printable version of each GHOST_TProgress value. */ @@ -255,8 +255,9 @@ bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ printf("ndof: unknown device %04hx:%04hx\n", vendor_id, product_id); } - if (m_buttonMask == 0) + if (m_buttonMask == 0) { m_buttonMask = (int)~(UINT_MAX << m_buttonCount); + } #ifdef DEBUG_NDOF_BUTTONS printf("ndof: %d buttons -> hex:%X\n", m_buttonCount, m_buttonMask); diff --git a/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp b/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp index 7e53ce45f70..7770f5f39ce 100644 --- a/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp +++ b/intern/ghost/intern/GHOST_NDOFManagerUnix.cpp @@ -32,10 +32,11 @@ GHOST_NDOFManagerUnix::GHOST_NDOFManagerUnix(GHOST_System &sys) char line[MAX_LINE_LENGTH] = {0}; while (fgets(line, MAX_LINE_LENGTH, command_output)) { unsigned short vendor_id = 0, product_id = 0; - if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2) + if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2) { if (setDevice(vendor_id, product_id)) { break; /* stop looking once the first 3D mouse is found */ } + } } pclose(command_output); } @@ -44,8 +45,9 @@ GHOST_NDOFManagerUnix::GHOST_NDOFManagerUnix(GHOST_System &sys) GHOST_NDOFManagerUnix::~GHOST_NDOFManagerUnix() { - if (m_available) + if (m_available) { spnav_close(); + } } bool GHOST_NDOFManagerUnix::available() diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp index c8308b3586b..cc8d0915c5a 100644 --- a/intern/ghost/intern/GHOST_System.cpp +++ b/intern/ghost/intern/GHOST_System.cpp @@ -158,7 +158,7 @@ GHOST_TSuccess GHOST_System::updateFullScreen(const GHOST_DisplaySetting &settin return success; } -GHOST_TSuccess GHOST_System::endFullScreen(void) +GHOST_TSuccess GHOST_System::endFullScreen() { GHOST_TSuccess success = GHOST_kFailure; GHOST_ASSERT(m_windowManager, "GHOST_System::endFullScreen(): invalid window manager"); @@ -177,7 +177,7 @@ GHOST_TSuccess GHOST_System::endFullScreen(void) return success; } -bool GHOST_System::getFullScreen(void) +bool GHOST_System::getFullScreen() { bool fullScreen; if (m_windowManager) { @@ -289,7 +289,7 @@ void GHOST_System::setTabletAPI(GHOST_TTabletAPI api) m_tabletAPI = api; } -GHOST_TTabletAPI GHOST_System::getTabletAPI(void) +GHOST_TTabletAPI GHOST_System::getTabletAPI() { return m_tabletAPI; } @@ -319,9 +319,7 @@ GHOST_TSuccess GHOST_System::init() if (m_timerManager && m_windowManager && m_eventManager) { return GHOST_kSuccess; } - else { - return GHOST_kFailure; - } + return GHOST_kFailure; } GHOST_TSuccess GHOST_System::exit() @@ -357,10 +355,12 @@ GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window **window, { GHOST_GLSettings glSettings = {0}; - if (stereoVisual) + if (stereoVisual) { glSettings.flags |= GHOST_glStereoVisual; - if (alphaBackground) + } + if (alphaBackground) { glSettings.flags |= GHOST_glAlphaBackground; + } /* NOTE: don't use #getCurrentDisplaySetting() because on X11 we may * be zoomed in and the desktop may be bigger than the viewport. */ diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index d8fbe875f67..33afb5f3155 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -26,15 +26,18 @@ #include <unordered_map> #include <unordered_set> -#include "GHOST_WaylandCursorSettings.h" -#include <pointer-constraints-client-protocol.h> -#include <relative-pointer-client-protocol.h> -#include <tablet-client-protocol.h> #include <wayland-cursor.h> -#include <xdg-output-client-protocol.h> + +#include "GHOST_WaylandCursorSettings.h" #include <xkbcommon/xkbcommon.h> +/* Generated by `wayland-scanner`. */ +#include <pointer-constraints-unstable-v1-client-protocol.h> +#include <relative-pointer-unstable-v1-client-protocol.h> +#include <tablet-unstable-v2-client-protocol.h> +#include <xdg-output-unstable-v1-client-protocol.h> + #include <fcntl.h> #include <sys/mman.h> #include <unistd.h> @@ -44,6 +47,24 @@ static GHOST_WindowWayland *window_from_surface(struct wl_surface *surface); +/** + * GNOME (mutter 42.2 had a bug with confine not respecting scale - Hi-DPI), See: T98793. + * Even though this has been fixed, at time of writing it's not yet in a release. + * Workaround the problem by implementing confine with a software cursor. + * While this isn't ideal, it's not adding a lot of overhead as software + * cursors are already used for warping (which WAYLAND doesn't support). + */ +#define USE_GNOME_CONFINE_HACK +/** + * Always use software confine (not just in GNOME). + * Useful for developing with compositors that don't need this workaround. + */ +// #define USE_GNOME_CONFINE_HACK_ALWAYS_ON + +#ifdef USE_GNOME_CONFINE_HACK +static bool use_gnome_confine_hack = false; +#endif + /* -------------------------------------------------------------------- */ /** \name Private Types & Defines * \{ */ @@ -78,6 +99,14 @@ struct buffer_t { struct cursor_t { bool visible = false; + /** + * When false, hide the hardware cursor, while the cursor is still considered to be `visible`, + * since the grab-mode determines the state of the software cursor, + * this may change - removing the need for a software cursor and in this case it's important + * the hardware cursor is used. + */ + bool is_hardware = true; + bool is_custom = false; struct wl_surface *wl_surface = nullptr; struct wl_buffer *wl_buffer = nullptr; struct wl_cursor_image wl_image = {0}; @@ -87,7 +116,9 @@ struct cursor_t { std::string theme_name; /** Outputs on which the cursor is visible. */ std::unordered_set<const output_t *> outputs; - int scale = 1; + + int theme_scale = 1; + int custom_scale = 1; }; /** @@ -125,6 +156,12 @@ struct key_repeat_payload_t { GHOST_TEventKeyData key_data = {GHOST_kKeyUnknown}; }; +/** Internal variables used to track grab-state. */ +struct input_grab_state_t { + bool use_lock = false; + bool use_confine = false; +}; + struct input_t { GHOST_SystemWayland *system = nullptr; @@ -153,9 +190,14 @@ struct input_t { * wl_fixed_to_int(scale * input->xy[0]), * wl_fixed_to_int(scale * input->xy[1]), * }; - * \endocde + * \endcode */ wl_fixed_t xy[2] = {0, 0}; + +#ifdef USE_GNOME_CONFINE_HACK + bool xy_software_confine = false; +#endif + GHOST_Buttons buttons = GHOST_Buttons(); struct cursor_t cursor; @@ -496,7 +538,7 @@ static GHOST_TTabletMode tablet_tool_map_type(enum zwp_tablet_tool_v2_type wl_ta static const int default_cursor_size = 24; -static const std::unordered_map<GHOST_TStandardCursor, std::string> cursors = { +static const std::unordered_map<GHOST_TStandardCursor, const char *> cursors = { {GHOST_kStandardCursorDefault, "left_ptr"}, {GHOST_kStandardCursorRightArrow, "right_ptr"}, {GHOST_kStandardCursorLeftArrow, "left_ptr"}, @@ -590,6 +632,21 @@ static void relative_pointer_handle_relative_motion( input->xy[0] += dx / scale; input->xy[1] += dy / scale; +#ifdef USE_GNOME_CONFINE_HACK + if (input->xy_software_confine) { + GHOST_Rect bounds; + win->getClientBounds(bounds); + /* Needed or the cursor is considered outside the window and doesn't restore the location. */ + bounds.m_r -= 1; + bounds.m_b -= 1; + + bounds.m_l = wl_fixed_from_int(bounds.m_l) / scale; + bounds.m_t = wl_fixed_from_int(bounds.m_t) / scale; + bounds.m_r = wl_fixed_from_int(bounds.m_r) / scale; + bounds.m_b = wl_fixed_from_int(bounds.m_b) / scale; + bounds.clampPoint(input->xy[0], input->xy[1]); + } +#endif input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(), GHOST_kEventCursorMove, win, @@ -1039,9 +1096,11 @@ static bool update_cursor_scale(cursor_t &cursor, wl_shm *shm) } } - if (scale > 0 && cursor.scale != scale) { - cursor.scale = scale; - wl_surface_set_buffer_scale(cursor.wl_surface, scale); + if (scale > 0 && cursor.theme_scale != scale) { + cursor.theme_scale = scale; + if (!cursor.is_custom) { + wl_surface_set_buffer_scale(cursor.wl_surface, scale); + } wl_cursor_theme_destroy(cursor.wl_theme); cursor.wl_theme = wl_cursor_theme_load(cursor.theme_name.c_str(), scale * cursor.size, shm); return true; @@ -1123,12 +1182,13 @@ static void pointer_handle_leave(void *data, uint32_t /*serial*/, struct wl_surface *surface) { + /* First clear the `focus_pointer`, since the window won't exist when closing the window. */ + static_cast<input_t *>(data)->focus_pointer = nullptr; + GHOST_IWindow *win = window_from_surface(surface); if (!win) { return; } - - static_cast<input_t *>(data)->focus_pointer = nullptr; static_cast<GHOST_WindowWayland *>(win)->deactivate(); } @@ -1860,16 +1920,21 @@ static void xdg_output_handle_logical_size(void *data, if (output->size_logical[0] != 0 && output->size_logical[1] != 0) { /* Original comment from SDL. */ - /* FIXME: GNOME has a bug where the logical size does not account for + /* FIXME(@flibit): GNOME has a bug where the logical size does not account for * scale, resulting in bogus viewport sizes. * * Until this is fixed, validate that _some_ kind of scaling is being * done (we can't match exactly because fractional scaling can't be - * detected otherwise), then override if necessary. - * -flibit - */ + * detected otherwise), then override if necessary. */ if ((output->size_logical[0] == width) && (output->scale_fractional == wl_fixed_from_int(1))) { GHOST_PRINT("xdg_output scale did not match, overriding with wl_output scale"); + +#ifdef USE_GNOME_CONFINE_HACK + /* Use a bug in GNOME to check GNOME is in use. If the bug is fixed this won't cause an issue + * as T98793 has been fixed up-stream too, but not in a release at time of writing. */ + use_gnome_confine_hack = true; +#endif + return; } } @@ -1968,7 +2033,7 @@ static void output_handle_done(void *data, struct wl_output * /*wl_output*/) int32_t size_native[2]; if (output->transform & WL_OUTPUT_TRANSFORM_90) { size_native[0] = output->size_native[1]; - size_native[1] = output->size_native[1]; + size_native[1] = output->size_native[0]; } else { size_native[0] = output->size_native[0]; @@ -2317,16 +2382,33 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorPosition(int32_t /*x*/, int32_t /*y void GHOST_SystemWayland::getMainDisplayDimensions(uint32_t &width, uint32_t &height) const { - if (getNumDisplays() > 0) { - /* We assume first output as main. */ - width = uint32_t(d->outputs[0]->size_native[0]) / d->outputs[0]->scale; - height = uint32_t(d->outputs[0]->size_native[1]) / d->outputs[0]->scale; + if (getNumDisplays() == 0) { + return; } + /* We assume first output as main. */ + width = uint32_t(d->outputs[0]->size_native[0]); + height = uint32_t(d->outputs[0]->size_native[1]); } void GHOST_SystemWayland::getAllDisplayDimensions(uint32_t &width, uint32_t &height) const { - getMainDisplayDimensions(width, height); + int32_t xy_min[2] = {INT32_MAX, INT32_MAX}; + int32_t xy_max[2] = {INT32_MIN, INT32_MIN}; + + for (const output_t *output : d->outputs) { + int32_t xy[2] = {0, 0}; + if (output->has_position_logical) { + xy[0] = output->position_logical[0]; + xy[1] = output->position_logical[1]; + } + xy_min[0] = std::min(xy_min[0], xy[0]); + xy_min[1] = std::min(xy_min[1], xy[1]); + xy_max[0] = std::max(xy_max[0], xy[0] + output->size_native[0]); + xy_max[1] = std::max(xy_max[1], xy[1] + output->size_native[1]); + } + + width = xy_max[0] - xy_min[0]; + height = xy_max[1] - xy_min[1]; } GHOST_IContext *GHOST_SystemWayland::createOffscreenContext(GHOST_GLSettings /*glSettings*/) @@ -2466,47 +2548,152 @@ void GHOST_SystemWayland::setSelection(const std::string &selection) this->selection = selection; } -static void set_cursor_buffer(input_t *input, wl_buffer *buffer) +/** + * Show the buffer defined by #cursor_buffer_set without changing anything else, + * so #cursor_buffer_hide can be used to display it again. + * + * The caller is responsible for setting `input->cursor.visible`. + */ +static void cursor_buffer_show(const input_t *input) +{ + const cursor_t *c = &input->cursor; + const int scale = c->is_custom ? c->custom_scale : c->theme_scale; + const int32_t hotspot_x = int32_t(c->wl_image.hotspot_x) / scale; + const int32_t hotspot_y = int32_t(c->wl_image.hotspot_y) / scale; + wl_pointer_set_cursor( + input->wl_pointer, input->pointer_serial, c->wl_surface, hotspot_x, hotspot_y); + for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : input->tablet_tools) { + tablet_tool_input_t *tool_input = static_cast<tablet_tool_input_t *>( + zwp_tablet_tool_v2_get_user_data(zwp_tablet_tool_v2)); + zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, + input->tablet_serial, + tool_input->cursor_surface, + hotspot_x, + hotspot_y); + } +} + +/** + * Hide the buffer defined by #cursor_buffer_set without changing anything else, + * so #cursor_buffer_show can be used to display it again. + * + * The caller is responsible for setting `input->cursor.visible`. + */ +static void cursor_buffer_hide(const input_t *input) +{ + wl_pointer_set_cursor(input->wl_pointer, input->pointer_serial, nullptr, 0, 0); + for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : input->tablet_tools) { + zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, input->tablet_serial, nullptr, 0, 0); + } +} + +static void cursor_buffer_set(const input_t *input, wl_buffer *buffer) { - cursor_t *c = &input->cursor; + const cursor_t *c = &input->cursor; + const int scale = c->is_custom ? c->custom_scale : c->theme_scale; - c->visible = (buffer != nullptr); + const bool visible = (c->visible && c->is_hardware); const int32_t image_size_x = int32_t(c->wl_image.width); const int32_t image_size_y = int32_t(c->wl_image.height); - const int32_t hotspot_x = int32_t(c->wl_image.hotspot_x) / c->scale; - const int32_t hotspot_y = int32_t(c->wl_image.hotspot_y) / c->scale; + /* This is a requirement of WAYLAND, when this isn't the case, + * it causes Blender's window to close intermittently. */ + GHOST_ASSERT((image_size_x % scale) == 0 && (image_size_y % scale) == 0, + "The size must be a multiple of the scale!"); + const int32_t hotspot_x = int32_t(c->wl_image.hotspot_x) / scale; + const int32_t hotspot_y = int32_t(c->wl_image.hotspot_y) / scale; + + wl_surface_set_buffer_scale(c->wl_surface, scale); wl_surface_attach(c->wl_surface, buffer, 0, 0); wl_surface_damage(c->wl_surface, 0, 0, image_size_x, image_size_y); + wl_surface_commit(c->wl_surface); wl_pointer_set_cursor(input->wl_pointer, input->pointer_serial, - c->visible ? c->wl_surface : nullptr, + visible ? c->wl_surface : nullptr, hotspot_x, hotspot_y); - wl_surface_commit(c->wl_surface); - /* Set the cursor for all tablet tools as well. */ for (struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2 : input->tablet_tools) { tablet_tool_input_t *tool_input = static_cast<tablet_tool_input_t *>( zwp_tablet_tool_v2_get_user_data(zwp_tablet_tool_v2)); + /* FIXME: for some reason cursor scale is applied twice (when the scale isn't 1x), * this happens both in gnome-shell & KDE. Setting the surface scale here doesn't help. */ - // wl_surface_set_buffer_scale(tool_input->cursor_surface, 1); + wl_surface_set_buffer_scale(tool_input->cursor_surface, scale); wl_surface_attach(tool_input->cursor_surface, buffer, 0, 0); wl_surface_damage(tool_input->cursor_surface, 0, 0, image_size_x, image_size_y); + wl_surface_commit(tool_input->cursor_surface); zwp_tablet_tool_v2_set_cursor(zwp_tablet_tool_v2, input->tablet_serial, - c->visible ? tool_input->cursor_surface : nullptr, + visible ? tool_input->cursor_surface : nullptr, hotspot_x, hotspot_y); + } +} - wl_surface_commit(tool_input->cursor_surface); +enum eCursorSetMode { + CURSOR_VISIBLE_ALWAYS_SET = 1, + CURSOR_VISIBLE_ONLY_HIDE, + CURSOR_VISIBLE_ONLY_SHOW, +}; + +static void cursor_visible_set(input_t *input, + const bool visible, + const bool is_hardware, + const enum eCursorSetMode set_mode) +{ + cursor_t *cursor = &input->cursor; + const bool was_visible = cursor->is_hardware && cursor->visible; + const bool use_visible = is_hardware && visible; + + if (set_mode == CURSOR_VISIBLE_ALWAYS_SET) { + /* Pass. */ + } + else if ((set_mode == CURSOR_VISIBLE_ONLY_SHOW)) { + if (!use_visible) { + return; + } + } + else if ((set_mode == CURSOR_VISIBLE_ONLY_HIDE)) { + if (use_visible) { + return; + } + } + + if (use_visible) { + if (!was_visible) { + cursor_buffer_show(input); + } + } + else { + if (was_visible) { + cursor_buffer_hide(input); + } + } + cursor->visible = visible; + cursor->is_hardware = is_hardware; +} + +static bool cursor_is_software(const GHOST_TGrabCursorMode mode, const bool use_software_confine) +{ + if (mode == GHOST_kGrabWrap) { + return true; + } +#ifdef USE_GNOME_CONFINE_HACK + if (mode == GHOST_kGrabNormal) { + if (use_software_confine) { + return true; + } } +#else + (void)use_software_confine; +#endif + return false; } GHOST_TSuccess GHOST_SystemWayland::setCursorShape(GHOST_TStandardCursor shape) @@ -2514,8 +2701,10 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorShape(GHOST_TStandardCursor shape) if (d->inputs.empty()) { return GHOST_kFailure; } - const std::string cursor_name = cursors.count(shape) ? cursors.at(shape) : - cursors.at(GHOST_kStandardCursorDefault); + auto cursor_find = cursors.find(shape); + const char *cursor_name = (cursor_find == cursors.end()) ? + cursors.at(GHOST_kStandardCursorDefault) : + (*cursor_find).second; input_t *input = d->inputs[0]; cursor_t *c = &input->cursor; @@ -2526,7 +2715,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorShape(GHOST_TStandardCursor shape) c->theme_name.c_str(), c->size, d->inputs[0]->system->shm()); } - wl_cursor *cursor = wl_cursor_theme_get_cursor(c->wl_theme, cursor_name.c_str()); + wl_cursor *cursor = wl_cursor_theme_get_cursor(c->wl_theme, cursor_name); if (!cursor) { GHOST_PRINT("cursor '" << cursor_name << "' does not exist" << std::endl); @@ -2539,17 +2728,27 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorShape(GHOST_TStandardCursor shape) return GHOST_kFailure; } + c->visible = true; + c->is_custom = false; c->wl_buffer = buffer; c->wl_image = *image; - set_cursor_buffer(input, buffer); + cursor_buffer_set(input, buffer); return GHOST_kSuccess; } GHOST_TSuccess GHOST_SystemWayland::hasCursorShape(GHOST_TStandardCursor cursorShape) { - return GHOST_TSuccess(cursors.count(cursorShape) && !cursors.at(cursorShape).empty()); + auto cursor_find = cursors.find(cursorShape); + if (cursor_find == cursors.end()) { + return GHOST_kFailure; + } + const char *value = (*cursor_find).second; + if (*value == '\0') { + return GHOST_kFailure; + } + return GHOST_kSuccess; } GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap, @@ -2602,6 +2801,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap, nullptr, cursor->file_buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (cursor->file_buffer->data == MAP_FAILED) { + cursor->file_buffer->data = nullptr; close(fd); return GHOST_kFailure; } @@ -2646,37 +2846,49 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap, } } + cursor->visible = true; + cursor->is_custom = true; + cursor->custom_scale = 1; /* TODO: support Hi-DPI custom cursors. */ cursor->wl_buffer = buffer; cursor->wl_image.width = uint32_t(sizex); cursor->wl_image.height = uint32_t(sizey); cursor->wl_image.hotspot_x = uint32_t(hotX); cursor->wl_image.hotspot_y = uint32_t(hotY); - set_cursor_buffer(d->inputs[0], buffer); + cursor_buffer_set(d->inputs[0], buffer); return GHOST_kSuccess; } -GHOST_TSuccess GHOST_SystemWayland::setCursorVisibility(bool visible) +GHOST_TSuccess GHOST_SystemWayland::getCursorBitmap(GHOST_CursorBitmapRef *bitmap) { - if (d->inputs.empty()) { + cursor_t *cursor = &d->inputs[0]->cursor; + if (cursor->file_buffer->data == nullptr) { + return GHOST_kFailure; + } + if (!cursor->is_custom) { return GHOST_kFailure; } - input_t *input = d->inputs[0]; + bitmap->data_size[0] = cursor->wl_image.width; + bitmap->data_size[1] = cursor->wl_image.height; - cursor_t *cursor = &input->cursor; - if (visible) { - if (!cursor->visible) { - set_cursor_buffer(input, cursor->wl_buffer); - } - } - else { - if (cursor->visible) { - set_cursor_buffer(input, nullptr); - } + bitmap->hot_spot[0] = cursor->wl_image.hotspot_x; + bitmap->hot_spot[1] = cursor->wl_image.hotspot_y; + + bitmap->data = (uint8_t *)static_cast<void *>(cursor->file_buffer->data); + + return GHOST_kSuccess; +} + +GHOST_TSuccess GHOST_SystemWayland::setCursorVisibility(bool visible) +{ + if (d->inputs.empty()) { + return GHOST_kFailure; } + input_t *input = d->inputs[0]; + cursor_visible_set(input, visible, input->cursor.is_hardware, CURSOR_VISIBLE_ALWAYS_SET); return GHOST_kSuccess; } @@ -2693,6 +2905,60 @@ bool GHOST_SystemWayland::supportsWindowPosition() return false; } +bool GHOST_SystemWayland::getCursorGrabUseSoftwareDisplay(const GHOST_TGrabCursorMode mode) +{ + if (d->inputs.empty()) { + return false; + } + +#ifdef USE_GNOME_CONFINE_HACK + input_t *input = d->inputs[0]; + const bool use_software_confine = input->xy_software_confine; +#else + const bool use_software_confine = false; +#endif + + return cursor_is_software(mode, use_software_confine); +} + +#ifdef USE_GNOME_CONFINE_HACK +static bool setCursorGrab_use_software_confine(const GHOST_TGrabCursorMode mode, + wl_surface *surface) +{ +# ifndef USE_GNOME_CONFINE_HACK_ALWAYS_ON + if (use_gnome_confine_hack == false) { + return false; + } +# endif + if (mode != GHOST_kGrabNormal) { + return false; + } + GHOST_WindowWayland *win = window_from_surface(surface); + if (!win) { + return false; + } + +# ifndef USE_GNOME_CONFINE_HACK_ALWAYS_ON + if (win->scale() <= 1) { + return false; + } +# endif + return true; +} +#endif + +static input_grab_state_t input_grab_state_from_mode(const GHOST_TGrabCursorMode mode, + const bool use_software_confine) +{ + /* Initialize all members. */ + const struct input_grab_state_t grab_state = { + /* Warping happens to require software cursor which also hides. */ + .use_lock = (mode == GHOST_kGrabWrap || mode == GHOST_kGrabHide) || use_software_confine, + .use_confine = (mode == GHOST_kGrabNormal) && (use_software_confine == false), + }; + return grab_state; +} + GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mode, const GHOST_TGrabCursorMode mode_current, wl_surface *surface) @@ -2705,7 +2971,6 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo if (d->inputs.empty()) { return GHOST_kFailure; } - /* No change, success. */ if (mode == mode_current) { return GHOST_kSuccess; @@ -2713,32 +2978,33 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo input_t *input = d->inputs[0]; -#define MODE_NEEDS_LOCK(m) ((m) == GHOST_kGrabWrap || (m) == GHOST_kGrabHide) -#define MODE_NEEDS_HIDE(m) ((m) == GHOST_kGrabHide) -#define MODE_NEEDS_CONFINE(m) ((m) == GHOST_kGrabNormal) +#ifdef USE_GNOME_CONFINE_HACK + const bool was_software_confine = input->xy_software_confine; + const bool use_software_confine = setCursorGrab_use_software_confine(mode, surface); +#else + const bool was_software_confine = false; + const bool use_software_confine = false; +#endif - const bool was_lock = MODE_NEEDS_LOCK(mode_current); - const bool use_lock = MODE_NEEDS_LOCK(mode); + const struct input_grab_state_t grab_state_prev = input_grab_state_from_mode( + mode_current, was_software_confine); + const struct input_grab_state_t grab_state_next = input_grab_state_from_mode( + mode, use_software_confine); /* Check for wrap as #supportsCursorWarp isn't supported. */ - const bool was_hide = MODE_NEEDS_HIDE(mode_current) || (mode_current == GHOST_kGrabWrap); - const bool use_hide = MODE_NEEDS_HIDE(mode) || (mode == GHOST_kGrabWrap); + const bool use_visible = !(((mode == GHOST_kGrabHide) || (mode == GHOST_kGrabWrap)) || + use_software_confine); - const bool was_confine = MODE_NEEDS_CONFINE(mode_current); - const bool use_confine = MODE_NEEDS_CONFINE(mode); + const bool is_hardware_cursor = !cursor_is_software(mode, use_software_confine); -#undef MODE_NEEDS_LOCK -#undef MODE_NEEDS_HIDE -#undef MODE_NEEDS_CONFINE - - if (!use_hide) { - setCursorVisibility(true); - } + /* Only hide so the cursor is not made visible before it's location is restored. + * This function is called again at the end of this function which only shows. */ + cursor_visible_set(input, use_visible, is_hardware_cursor, CURSOR_VISIBLE_ONLY_HIDE); /* Switching from one grab mode to another, * in this case disable the current locks as it makes logic confusing, * postpone changing the cursor to avoid flickering. */ - if (!use_lock) { + if (!grab_state_next.use_lock) { if (input->relative_pointer) { zwp_relative_pointer_v1_destroy(input->relative_pointer); input->relative_pointer = nullptr; @@ -2786,13 +3052,22 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo wl_surface_commit(surface); } } +#ifdef USE_GNOME_CONFINE_HACK + else if (mode_current == GHOST_kGrabNormal) { + if (was_software_confine) { + zwp_locked_pointer_v1_set_cursor_position_hint( + input->locked_pointer, input->xy[0], input->xy[1]); + wl_surface_commit(surface); + } + } +#endif zwp_locked_pointer_v1_destroy(input->locked_pointer); input->locked_pointer = nullptr; } } - if (!use_confine) { + if (!grab_state_next.use_confine) { if (input->confined_pointer) { zwp_confined_pointer_v1_destroy(input->confined_pointer); input->confined_pointer = nullptr; @@ -2800,8 +3075,8 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo } if (mode != GHOST_kGrabDisable) { - if (use_lock) { - if (!was_lock) { + if (grab_state_next.use_lock) { + if (!grab_state_prev.use_lock) { /* TODO(@campbellbarton): As WAYLAND does not support warping the pointer it may not be * possible to support #GHOST_kGrabWrap by pragmatically settings it's coordinates. * An alternative could be to draw the cursor in software (and hide the real cursor), @@ -2818,8 +3093,8 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); } } - else if (use_confine) { - if (!was_confine) { + else if (grab_state_next.use_confine) { + if (!grab_state_prev.use_confine) { input->confined_pointer = zwp_pointer_constraints_v1_confine_pointer( d->pointer_constraints, surface, @@ -2828,12 +3103,15 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); } } - - if (use_hide && !was_hide) { - setCursorVisibility(false); - } } + /* Only show so the cursor is made visible as the last step. */ + cursor_visible_set(input, use_visible, is_hardware_cursor, CURSOR_VISIBLE_ONLY_SHOW); + +#ifdef USE_GNOME_CONFINE_HACK + input->xy_software_confine = use_software_confine; +#endif + return GHOST_kSuccess; } diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h index 762ceb80e38..4b953dccac6 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.h +++ b/intern/ghost/intern/GHOST_SystemWayland.h @@ -12,7 +12,9 @@ #include "GHOST_WindowWayland.h" #include <wayland-client.h> -#include <xdg-decoration-client-protocol.h> + +/* Generated by `wayland-scanner`. */ +#include <xdg-decoration-unstable-v1-client-protocol.h> #include <xdg-shell-client-protocol.h> #include <string> @@ -32,6 +34,7 @@ struct output_t { int32_t size_logical[2] = {0, 0}; bool has_size_logical = false; + /** Monitor position in pixels. */ int32_t position_logical[2] = {0, 0}; bool has_position_logical = false; @@ -122,11 +125,15 @@ class GHOST_SystemWayland : public GHOST_System { int hotY, bool canInvertColor); + GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap); + GHOST_TSuccess setCursorVisibility(bool visible); bool supportsCursorWarp(); bool supportsWindowPosition(); + bool getCursorGrabUseSoftwareDisplay(const GHOST_TGrabCursorMode mode); + GHOST_TSuccess setCursorGrab(const GHOST_TGrabCursorMode mode, const GHOST_TGrabCursorMode mode_current, wl_surface *surface); diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index e93a56cc8d4..bed9cd6c784 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -506,8 +506,9 @@ static void destroyIMCallback(XIM /*xim*/, XPointer ptr, XPointer /*data*/) { GHOST_PRINT("XIM server died\n"); - if (ptr) + if (ptr) { *(XIM *)ptr = nullptr; + } } bool GHOST_SystemX11::openX11_IM() @@ -519,8 +520,9 @@ bool GHOST_SystemX11::openX11_IM() XSetLocaleModifiers(""); m_xim = XOpenIM(m_display, nullptr, (char *)GHOST_X11_RES_NAME, (char *)GHOST_X11_RES_CLASS); - if (!m_xim) + if (!m_xim) { return false; + } XIMCallback destroy; destroy.callback = (XIMProc)destroyIMCallback; @@ -641,10 +643,11 @@ bool GHOST_SystemX11::processEvents(bool waitForEvent) SleepTillEvent(m_display, -1); } else { - int64_t maxSleep = next - getMilliSeconds(); + const int64_t maxSleep = next - getMilliSeconds(); - if (maxSleep >= 0) + if (maxSleep >= 0) { SleepTillEvent(m_display, next - getMilliSeconds()); + } } } @@ -692,8 +695,9 @@ bool GHOST_SystemX11::processEvents(bool waitForEvent) } else if (xevent.type == KeyPress) { if ((xevent.xkey.keycode == m_last_release_keycode) && - ((xevent.xkey.time <= m_last_release_time))) + ((xevent.xkey.time <= m_last_release_time))) { continue; + } } processEvent(&xevent); @@ -733,7 +737,7 @@ bool GHOST_SystemX11::processEvents(bool waitForEvent) XK_Super_R, }; - for (int i = 0; i < (sizeof(modifiers) / sizeof(*modifiers)); i++) { + for (int i = 0; i < (int)(sizeof(modifiers) / sizeof(*modifiers)); i++) { KeyCode kc = XKeysymToKeycode(m_display, modifiers[i]); if (kc != 0 && ((xevent.xkeymap.key_vector[kc >> 3] >> (kc & 7)) & 1) != 0) { pushEvent(new GHOST_EventKey(getMilliSeconds(), @@ -1233,36 +1237,46 @@ void GHOST_SystemX11::processEvent(XEvent *xe) /* process wheel mouse events and break, only pass on press events */ if (xbe.button == Button4) { - if (xbe.type == ButtonPress) + if (xbe.type == ButtonPress) { g_event = new GHOST_EventWheel(getMilliSeconds(), window, 1); + } break; } - else if (xbe.button == Button5) { - if (xbe.type == ButtonPress) + if (xbe.button == Button5) { + if (xbe.type == ButtonPress) { g_event = new GHOST_EventWheel(getMilliSeconds(), window, -1); + } break; } /* process rest of normal mouse buttons */ - if (xbe.button == Button1) + if (xbe.button == Button1) { gbmask = GHOST_kButtonMaskLeft; - else if (xbe.button == Button2) + } + else if (xbe.button == Button2) { gbmask = GHOST_kButtonMaskMiddle; - else if (xbe.button == Button3) + } + else if (xbe.button == Button3) { gbmask = GHOST_kButtonMaskRight; - /* It seems events 6 and 7 are for horizontal scrolling. - * you can re-order button mapping like this... (swaps 6,7 with 8,9) - * `xmodmap -e "pointer = 1 2 3 4 5 8 9 6 7"` */ - else if (xbe.button == 6) + /* It seems events 6 and 7 are for horizontal scrolling. + * you can re-order button mapping like this... (swaps 6,7 with 8,9) + * `xmodmap -e "pointer = 1 2 3 4 5 8 9 6 7"` */ + } + else if (xbe.button == 6) { gbmask = GHOST_kButtonMaskButton6; - else if (xbe.button == 7) + } + else if (xbe.button == 7) { gbmask = GHOST_kButtonMaskButton7; - else if (xbe.button == 8) + } + else if (xbe.button == 8) { gbmask = GHOST_kButtonMaskButton4; - else if (xbe.button == 9) + } + else if (xbe.button == 9) { gbmask = GHOST_kButtonMaskButton5; - else + } + else { break; + } g_event = new GHOST_EventButton( getMilliSeconds(), type, window, gbmask, window->GetTabletData()); @@ -1326,8 +1340,9 @@ void GHOST_SystemX11::processEvent(XEvent *xe) if (XGetWindowAttributes(m_display, xcme.window, &attr) == True) { if (XGetInputFocus(m_display, &fwin, &revert_to) == True) { if (attr.map_state == IsViewable) { - if (fwin != xcme.window) + if (fwin != xcme.window) { XSetInputFocus(m_display, xcme.window, RevertToParent, xcme.data.l[1]); + } } } } @@ -1376,10 +1391,12 @@ void GHOST_SystemX11::processEvent(XEvent *xe) // printf("X: %s window %d\n", // xce.type == EnterNotify ? "entering" : "leaving", (int) xce.window); - if (xce.type == EnterNotify) + if (xce.type == EnterNotify) { m_windowManager->setActiveWindow(window); - else + } + else { m_windowManager->setWindowInactive(window); + } break; } @@ -1645,10 +1662,10 @@ static GHOST_TSuccess getCursorPosition_impl(Display *display, &mask_return) == False) { return GHOST_kFailure; } - else { - x = rx; - y = ry; - } + + x = rx; + y = ry; + return GHOST_kSuccess; } @@ -1955,18 +1972,19 @@ void GHOST_SystemX11::getClipboard_xcout(const XEvent *evt, return; case XCLIB_XCOUT_SENTCONVSEL: - if (evt->type != SelectionNotify) + if (evt->type != SelectionNotify) { return; + } if (target == m_atom.UTF8_STRING && evt->xselection.property == None) { *context = XCLIB_XCOUT_FALLBACK_UTF8; return; } - else if (target == m_atom.COMPOUND_TEXT && evt->xselection.property == None) { + if (target == m_atom.COMPOUND_TEXT && evt->xselection.property == None) { *context = XCLIB_XCOUT_FALLBACK_COMP; return; } - else if (target == m_atom.TEXT && evt->xselection.property == None) { + if (target == m_atom.TEXT && evt->xselection.property == None) { *context = XCLIB_XCOUT_FALLBACK_TEXT; return; } @@ -2042,12 +2060,14 @@ void GHOST_SystemX11::getClipboard_xcout(const XEvent *evt, * then read it, delete it, etc. */ /* make sure that the event is relevant */ - if (evt->type != PropertyNotify) + if (evt->type != PropertyNotify) { return; + } /* skip unless the property has a new value */ - if (evt->xproperty.state != PropertyNewValue) + if (evt->xproperty.state != PropertyNewValue) { return; + } /* check size and format of the property */ XGetWindowProperty(m_display, @@ -2121,7 +2141,6 @@ void GHOST_SystemX11::getClipboard_xcout(const XEvent *evt, XFlush(m_display); return; } - return; } char *GHOST_SystemX11::getClipboard(bool selection) const @@ -2136,10 +2155,12 @@ char *GHOST_SystemX11::getClipboard(bool selection) const XEvent evt; unsigned int context = XCLIB_XCOUT_NONE; - if (selection == True) + if (selection == True) { sseln = m_atom.PRIMARY; - else + } + else { sseln = m_atom.CLIPBOARD; + } const vector<GHOST_IWindow *> &win_vec = m_windowManager->getWindows(); vector<GHOST_IWindow *>::const_iterator win_it = win_vec.begin(); @@ -2154,20 +2175,18 @@ char *GHOST_SystemX11::getClipboard(bool selection) const strcpy(sel_buf, txt_cut_buffer); return sel_buf; } - else { - sel_buf = (char *)malloc(strlen(txt_select_buffer) + 1); - strcpy(sel_buf, txt_select_buffer); - return sel_buf; - } + sel_buf = (char *)malloc(strlen(txt_select_buffer) + 1); + strcpy(sel_buf, txt_select_buffer); + return sel_buf; } - else if (owner == None) { + if (owner == None) { return nullptr; } /* Restore events so copy doesn't swallow other event types (keyboard/mouse). */ vector<XEvent> restore_events; - while (1) { + while (true) { /* only get an event if xcout() is doing something */ bool restore_this_event = false; if (context != XCLIB_XCOUT_NONE) { @@ -2188,26 +2207,27 @@ char *GHOST_SystemX11::getClipboard(bool selection) const target = m_atom.STRING; continue; } - else if (context == XCLIB_XCOUT_FALLBACK_UTF8) { + if (context == XCLIB_XCOUT_FALLBACK_UTF8) { /* utf8 fail, move to compound text. */ context = XCLIB_XCOUT_NONE; target = m_atom.COMPOUND_TEXT; continue; } - else if (context == XCLIB_XCOUT_FALLBACK_COMP) { + if (context == XCLIB_XCOUT_FALLBACK_COMP) { /* Compound text fail, move to text. */ context = XCLIB_XCOUT_NONE; target = m_atom.TEXT; continue; } - else if (context == XCLIB_XCOUT_FALLBACK_TEXT) { + if (context == XCLIB_XCOUT_FALLBACK_TEXT) { /* Text fail, nothing else to try, break. */ context = XCLIB_XCOUT_NONE; } /* Only continue if #xcout() is doing something. */ - if (context == XCLIB_XCOUT_NONE) + if (context == XCLIB_XCOUT_NONE) { break; + } } while (!restore_events.empty()) { @@ -2221,10 +2241,12 @@ char *GHOST_SystemX11::getClipboard(bool selection) const memcpy(tmp_data, (char *)sel_buf, sel_len); tmp_data[sel_len] = '\0'; - if (sseln == m_atom.STRING) + if (sseln == m_atom.STRING) { XFree(sel_buf); - else + } + else { free(sel_buf); + } return tmp_data; } @@ -2244,8 +2266,9 @@ void GHOST_SystemX11::putClipboard(const char *buffer, bool selection) const if (selection == False) { XSetSelectionOwner(m_display, m_atom.CLIPBOARD, m_window, CurrentTime); owner = XGetSelectionOwner(m_display, m_atom.CLIPBOARD); - if (txt_cut_buffer) + if (txt_cut_buffer) { free((void *)txt_cut_buffer); + } txt_cut_buffer = (char *)malloc(strlen(buffer) + 1); strcpy(txt_cut_buffer, buffer); @@ -2253,15 +2276,17 @@ void GHOST_SystemX11::putClipboard(const char *buffer, bool selection) const else { XSetSelectionOwner(m_display, m_atom.PRIMARY, m_window, CurrentTime); owner = XGetSelectionOwner(m_display, m_atom.PRIMARY); - if (txt_select_buffer) + if (txt_select_buffer) { free((void *)txt_select_buffer); + } txt_select_buffer = (char *)malloc(strlen(buffer) + 1); strcpy(txt_select_buffer, buffer); } - if (owner != m_window) + if (owner != m_window) { fprintf(stderr, "failed to own primary\n"); + } } } @@ -2374,7 +2399,7 @@ GHOST_TSuccess GHOST_SystemX11::showMessageBox(const char *title, const char *help_label, const char *continue_label, const char *link, - GHOST_DialogOptions) const + GHOST_DialogOptions /*dialog_options*/) const { char **text_splitted = nullptr; int textLines = 0; @@ -2557,18 +2582,23 @@ static bool match_token(const char *haystack, const char *needle) { const char *h, *n; for (h = haystack; *h;) { - while (*h && is_filler_char(*h)) + while (*h && is_filler_char(*h)) { h++; - if (!*h) + } + if (!*h) { break; + } - for (n = needle; *n && *h && tolower(*h) == tolower(*n); n++) + for (n = needle; *n && *h && tolower(*h) == tolower(*n); n++) { h++; - if (!*n && (is_filler_char(*h) || !*h)) + } + if (!*n && (is_filler_char(*h) || !*h)) { return true; + } - while (*h && !is_filler_char(*h)) + while (*h && !is_filler_char(*h)) { h++; + } } return false; } diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp index de7c5422d3f..3f093840d0c 100644 --- a/intern/ghost/intern/GHOST_Window.cpp +++ b/intern/ghost/intern/GHOST_Window.cpp @@ -164,7 +164,8 @@ GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect &bounds) void GHOST_Window::getCursorGrabState(GHOST_TGrabCursorMode &mode, GHOST_TAxisFlag &wrap_axis, - GHOST_Rect &bounds) + GHOST_Rect &bounds, + bool &use_software_cursor) { mode = m_cursorGrab; if (m_cursorGrab == GHOST_kGrabWrap) { @@ -178,6 +179,14 @@ void GHOST_Window::getCursorGrabState(GHOST_TGrabCursorMode &mode, bounds.m_b = -1; wrap_axis = GHOST_kGrabAxisNone; } + use_software_cursor = (m_cursorGrab != GHOST_kGrabDisable) ? getCursorGrabUseSoftwareDisplay() : + false; +} + +bool GHOST_Window::getCursorGrabUseSoftwareDisplay() +{ + /* Sub-classes may override, by default don't use software cursor. */ + return false; } GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape) @@ -199,6 +208,12 @@ GHOST_TSuccess GHOST_Window::setCustomCursorShape( return GHOST_kFailure; } +GHOST_TSuccess GHOST_Window::getCursorBitmap(GHOST_CursorBitmapRef * /*bitmap*/) +{ + /* Sub-classes may override. */ + return GHOST_kFailure; +} + void GHOST_Window::setAcceptDragOperation(bool canAccept) { m_canAcceptDragOperation = canAccept; diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h index adbc29eb84e..5ff91c05b16 100644 --- a/intern/ghost/intern/GHOST_Window.h +++ b/intern/ghost/intern/GHOST_Window.h @@ -117,6 +117,8 @@ class GHOST_Window : public GHOST_IWindow { int hotY, bool canInvertColor); + GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap); + /** * Returns the visibility state of the cursor. * \return The visibility state of the cursor. @@ -154,7 +156,12 @@ class GHOST_Window : public GHOST_IWindow { void getCursorGrabState(GHOST_TGrabCursorMode &mode, GHOST_TAxisFlag &axis_flag, - GHOST_Rect &bounds); + GHOST_Rect &bounds, + bool &use_software_cursor); + /** + * Return true when a software cursor should be used. + */ + bool getCursorGrabUseSoftwareDisplay(); /** * Sets the progress bar value displayed in the window/application icon diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp index 21e3793d3b1..941e08ff035 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.cpp +++ b/intern/ghost/intern/GHOST_WindowWayland.cpp @@ -492,12 +492,22 @@ GHOST_TSuccess GHOST_WindowWayland::setWindowCursorShape(GHOST_TStandardCursor s return ok; } +bool GHOST_WindowWayland::getCursorGrabUseSoftwareDisplay() +{ + return m_system->getCursorGrabUseSoftwareDisplay(m_cursorGrab); +} + GHOST_TSuccess GHOST_WindowWayland::setWindowCustomCursorShape( uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor) { return m_system->setCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor); } +GHOST_TSuccess GHOST_WindowWayland::getCursorBitmap(GHOST_CursorBitmapRef *bitmap) +{ + return m_system->getCursorBitmap(bitmap); +} + void GHOST_WindowWayland::setTitle(const char *title) { xdg_toplevel_set_title(w->xdg_toplevel, title); diff --git a/intern/ghost/intern/GHOST_WindowWayland.h b/intern/ghost/intern/GHOST_WindowWayland.h index b6d9fa04079..89354c54c0f 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.h +++ b/intern/ghost/intern/GHOST_WindowWayland.h @@ -10,7 +10,6 @@ #include "GHOST_Window.h" -#include <unordered_set> #include <vector> class GHOST_SystemWayland; @@ -52,6 +51,9 @@ class GHOST_WindowWayland : public GHOST_Window { int hotX, int hotY, bool canInvertColor) override; + bool getCursorGrabUseSoftwareDisplay() override; + + GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap) override; void setTitle(const char *title) override; diff --git a/intern/ghost/intern/GHOST_XrAction.cpp b/intern/ghost/intern/GHOST_XrAction.cpp index 587b1124848..0e725bf4075 100644 --- a/intern/ghost/intern/GHOST_XrAction.cpp +++ b/intern/ghost/intern/GHOST_XrAction.cpp @@ -332,23 +332,26 @@ void GHOST_XrAction::updateState(XrSession session, break; } case GHOST_kXrActionTypePoseInput: { - XrActionStatePose state{XR_TYPE_ACTION_STATE_POSE}; - CHECK_XR( - xrGetActionStatePose(session, &state_info, &state), - (std::string("Failed to get state for pose action \"") + action_name + "\".").data()); - if (state.isActive) { - XrSpace pose_space = ((subaction != nullptr) && (subaction->space != nullptr)) ? - subaction->space->getSpace() : - XR_NULL_HANDLE; - if (pose_space != XR_NULL_HANDLE) { - XrSpaceLocation space_location{XR_TYPE_SPACE_LOCATION}; - CHECK_XR( - xrLocateSpace( - pose_space, reference_space, predicted_display_time, &space_location), - (std::string("Failed to query pose space for action \"") + action_name + "\".") - .data()); - copy_openxr_pose_to_ghost_pose(space_location.pose, - ((GHOST_XrPose *)m_states)[subaction_idx]); + /* Check for valid display time to avoid an error in #xrLocateSpace(). */ + if (predicted_display_time > 0) { + XrActionStatePose state{XR_TYPE_ACTION_STATE_POSE}; + CHECK_XR(xrGetActionStatePose(session, &state_info, &state), + (std::string("Failed to get state for pose action \"") + action_name + "\".") + .data()); + if (state.isActive) { + XrSpace pose_space = ((subaction != nullptr) && (subaction->space != nullptr)) ? + subaction->space->getSpace() : + XR_NULL_HANDLE; + if (pose_space != XR_NULL_HANDLE) { + XrSpaceLocation space_location{XR_TYPE_SPACE_LOCATION}; + CHECK_XR( + xrLocateSpace( + pose_space, reference_space, predicted_display_time, &space_location), + (std::string("Failed to query pose space for action \"") + action_name + "\".") + .data()); + copy_openxr_pose_to_ghost_pose(space_location.pose, + ((GHOST_XrPose *)m_states)[subaction_idx]); + } } } break; diff --git a/intern/ghost/test/gears/GHOST_C-Test.c b/intern/ghost/test/gears/GHOST_C-Test.c index 71f3a6f43b4..46c8fda0665 100644 --- a/intern/ghost/test/gears/GHOST_C-Test.c +++ b/intern/ghost/test/gears/GHOST_C-Test.c @@ -31,7 +31,7 @@ #endif /* defined(WIN32) || defined(__APPLE__) */ static void gearsTimerProc(GHOST_TimerTaskHandle task, uint64_t time); -int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData); +bool processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData); static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; static GLfloat fAngle = 0.0; @@ -269,9 +269,9 @@ static void setViewPortGL(GHOST_WindowHandle hWindow) GHOST_DisposeRectangle(hRect); } -int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) +bool processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) { - int handled = 1; + bool handled = true; int cursor; int visibility; GHOST_TEventKeyData *keyData = NULL; @@ -389,10 +389,10 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) } break; case GHOST_kEventWindowActivate: - handled = 0; + handled = false; break; case GHOST_kEventWindowDeactivate: - handled = 0; + handled = false; break; case GHOST_kEventWindowUpdate: { GHOST_WindowHandle window2 = GHOST_GetEventWindow(hEvent); @@ -404,7 +404,7 @@ int processEvent(GHOST_EventHandle hEvent, GHOST_TUserDataPtr userData) } break; default: - handled = 0; + handled = false; break; } return handled; diff --git a/intern/ghost/test/multitest/MultiTest.c b/intern/ghost/test/multitest/MultiTest.c index 35b1de65171..157e4f1b0f2 100644 --- a/intern/ghost/test/multitest/MultiTest.c +++ b/intern/ghost/test/multitest/MultiTest.c @@ -812,7 +812,7 @@ struct _MultiTestApp { int exit; }; -static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr data) +static bool multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr data) { MultiTestApp *app = data; GHOST_WindowHandle win; @@ -820,7 +820,7 @@ static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr dat win = GHOST_GetEventWindow(evt); if (win && !GHOST_ValidWindow(app->sys, win)) { loggerwindow_log(app->logger, "WARNING: bad event, non-valid window\n"); - return 1; + return true; } if (win) { @@ -845,7 +845,7 @@ static int multitest_event_handler(GHOST_EventHandle evt, GHOST_TUserDataPtr dat } } - return 1; + return true; } /**/ |