Blender V5.0
write.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "kernel/globals.h"
8
10
12
13#include "util/types_rgbe.h"
14
15#ifdef __KERNEL_GPU__
16# include "util/atomic.h"
17# define __ATOMIC_PASS_WRITE__
18#endif
19
21
22/* Get pointer to pixel in render buffer. */
23
26{
27 const uint32_t render_pixel_index = INTEGRATOR_STATE(state, path, render_pixel_index);
28 const uint64_t render_buffer_offset = (uint64_t)render_pixel_index *
29 kernel_data.film.pass_stride;
30 return render_buffer + render_buffer_offset;
31}
32
37{
38 const uint32_t render_pixel_index = INTEGRATOR_STATE(state, shadow_path, render_pixel_index);
39 const uint64_t render_buffer_offset = (uint64_t)render_pixel_index *
40 kernel_data.film.pass_stride;
41 return render_buffer + render_buffer_offset;
42}
43
46 const int x,
47 const int y,
48 const int offset,
49 const int stride,
51{
52 const int render_pixel_index = offset + x + y * stride;
53 return render_buffer + (uint64_t)render_pixel_index * kernel_data.film.pass_stride;
54}
55
56/* Accumulate in passes. */
57
59 const float value)
60{
61#ifdef __ATOMIC_PASS_WRITE__
62 atomic_add_and_fetch_float(buffer, value);
63#else
64 *buffer += value;
65#endif
66}
67
69 const float3 value)
70{
71#ifdef __ATOMIC_PASS_WRITE__
72 ccl_global float *buf_x = buffer + 0;
73 ccl_global float *buf_y = buffer + 1;
74 ccl_global float *buf_z = buffer + 2;
75
76 atomic_add_and_fetch_float(buf_x, value.x);
77 atomic_add_and_fetch_float(buf_y, value.y);
78 atomic_add_and_fetch_float(buf_z, value.z);
79#else
80 buffer[0] += value.x;
81 buffer[1] += value.y;
82 buffer[2] += value.z;
83#endif
84}
85
91
93 const float4 value)
94{
95#ifdef __ATOMIC_PASS_WRITE__
96 ccl_global float *buf_x = buffer + 0;
97 ccl_global float *buf_y = buffer + 1;
98 ccl_global float *buf_z = buffer + 2;
99 ccl_global float *buf_w = buffer + 3;
100
101 atomic_add_and_fetch_float(buf_x, value.x);
102 atomic_add_and_fetch_float(buf_y, value.y);
103 atomic_add_and_fetch_float(buf_z, value.z);
104 atomic_add_and_fetch_float(buf_w, value.w);
105#else
106 buffer[0] += value.x;
107 buffer[1] += value.y;
108 buffer[2] += value.z;
109 buffer[3] += value.w;
110#endif
111}
112
114 const float3 value)
115{
116 *buffer = rgb_to_rgbe(value).f;
117}
118
119/* Overwrite for passes that only write on sample 0. This assumes only a single thread will write
120 * to this pixel and no atomics are needed. */
121
123 const float value)
124{
125 *buffer = value;
126}
127
129 const float3 value)
130{
131 buffer[0] = value.x;
132 buffer[1] = value.y;
133 buffer[2] = value.z;
134}
135
136/* Read back from passes. */
137
139{
140 return *buffer;
141}
142
144{
145 return make_float3(buffer[0], buffer[1], buffer[2]);
146}
147
149{
150 return make_float4(buffer[0], buffer[1], buffer[2], buffer[3]);
151}
152
154{
155 return rgbe_to_rgb(RGBE(*buffer));
156}
157
#define atomic_add_and_fetch_float(p, x)
Definition atomic.h:12
unsigned long long int uint64_t
#define kernel_data
#define ccl_restrict
#define ccl_device_forceinline
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_inline
#define ccl_global
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
ccl_device_inline float3 spectrum_to_rgb(Spectrum s)
static ulong state[N]
#define make_float4
#define INTEGRATOR_STATE(state, nested_struct, member)
Definition state.h:235
const IntegratorShadowStateCPU * ConstIntegratorShadowState
Definition state.h:231
const IntegratorStateCPU * ConstIntegratorState
Definition state.h:229
float f
Definition types_rgbe.h:18
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float y
Definition sky_math.h:225
float z
Definition sky_math.h:225
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225
ccl_device_inline float3 rgbe_to_rgb(const RGBE rgbe)
Definition types_rgbe.h:92
ccl_device RGBE rgb_to_rgbe(float3 rgb)
Definition types_rgbe.h:60
float3 Spectrum
ccl_device_inline float kernel_read_pass_float(const ccl_global float *ccl_restrict buffer)
Definition write.h:138
ccl_device_inline void film_write_pass_float4(ccl_global float *ccl_restrict buffer, const float4 value)
Definition write.h:92
ccl_device_inline void film_overwrite_pass_float3(ccl_global float *ccl_restrict buffer, const float3 value)
Definition write.h:128
ccl_device_inline void film_write_pass_float3(ccl_global float *ccl_restrict buffer, const float3 value)
Definition write.h:68
ccl_device_inline float3 kernel_read_pass_float3(const ccl_global float *ccl_restrict buffer)
Definition write.h:143
ccl_device_inline void film_overwrite_pass_rgbe(ccl_global float *ccl_restrict buffer, const float3 value)
Definition write.h:113
ccl_device_inline void film_write_pass_spectrum(ccl_global float *ccl_restrict buffer, Spectrum value)
Definition write.h:86
ccl_device_forceinline ccl_global float * film_pass_pixel_render_buffer_shadow(KernelGlobals kg, ConstIntegratorShadowState state, ccl_global float *ccl_restrict render_buffer)
Definition write.h:33
ccl_device_inline void film_write_pass_float(ccl_global float *ccl_restrict buffer, const float value)
Definition write.h:58
CCL_NAMESPACE_BEGIN ccl_device_forceinline ccl_global float * film_pass_pixel_render_buffer(KernelGlobals kg, ConstIntegratorState state, ccl_global float *ccl_restrict render_buffer)
Definition write.h:24
ccl_device_inline float4 kernel_read_pass_float4(ccl_global float *ccl_restrict buffer)
Definition write.h:148
ccl_device_inline void film_overwrite_pass_float(ccl_global float *ccl_restrict buffer, const float value)
Definition write.h:122
ccl_device_inline float3 kernel_read_pass_rgbe(const ccl_global float *ccl_restrict buffer)
Definition write.h:153