Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/buffers.h
| Show All 34 Lines | |||||
| struct float4; | struct float4; | ||||
| /* Buffer Parameters | /* Buffer Parameters | ||||
| * Size of render buffer and how it fits in the full image (border render). */ | * Size of render buffer and how it fits in the full image (border render). */ | ||||
| class BufferParams { | class BufferParams { | ||||
| public: | public: | ||||
| /* width/height of the physical buffer */ | /* width/height of the physical buffer */ | ||||
| int width; | int width = 0; | ||||
| int height; | int height = 0; | ||||
| /* offset into and width/height of the full buffer */ | /* offset into and width/height of the full buffer */ | ||||
| int full_x; | int full_x = 0; | ||||
| int full_y; | int full_y = 0; | ||||
| int full_width; | int full_width = 0; | ||||
| int full_height; | int full_height = 0; | ||||
| /* passes */ | /* Runtime fields, only valid after `update_passes()` or `update_offset_stride()`. */ | ||||
| vector<Pass> passes; | int offset = -1, stride = -1; | ||||
| bool denoising_data_pass; | |||||
| /* If only some light path types should be target, an additional pass is needed. */ | /* Runtime fields, only valid after `update_passes()`. */ | ||||
| bool denoising_clean_pass; | int pass_stride = -1; | ||||
| /* When we're prefiltering the passes during rendering, we need to keep both the | |||||
| * original and the prefiltered data around because neighboring tiles might still | |||||
| * need the original data. */ | |||||
| bool denoising_prefiltered_pass; | |||||
| /* functions */ | /* functions */ | ||||
| BufferParams(); | BufferParams(); | ||||
| void get_offset_stride(int &offset, int &stride); | /* Pre-calculate all fields which depends on the passes. */ | ||||
| bool modified(const BufferParams ¶ms); | void update_passes(vector<Pass *> &passes); | ||||
| int get_passes_size(); | |||||
| int get_denoising_offset(); | /* Returns PASS_UNUSED if there is no such pass in the buffer. */ | ||||
| int get_denoising_prefiltered_offset(); | int get_pass_offset(PassType type, PassMode mode = PassMode::NOISY) const; | ||||
| void update_offset_stride(); | |||||
| bool modified(const BufferParams &other) const; | |||||
| protected: | |||||
| void reset_pass_offset(); | |||||
| /* Multipled by 2 to be able to store noisy and denoised pass types. */ | |||||
| static constexpr int kNumPassOffsets = PASS_NUM * 2; | |||||
| /* Indexed by pass type, indicates offset of the corresponding pass in the buffer. */ | |||||
| int pass_offset_[kNumPassOffsets]; | |||||
| }; | }; | ||||
| /* Render Buffers */ | /* Render Buffers */ | ||||
| class RenderBuffers { | class RenderBuffers { | ||||
| public: | public: | ||||
| /* buffer parameters */ | /* buffer parameters */ | ||||
| BufferParams params; | BufferParams params; | ||||
| /* float buffer */ | /* float buffer */ | ||||
| device_vector<float> buffer; | device_vector<float> buffer; | ||||
| bool map_neighbor_copied; | |||||
| double render_time; | |||||
| explicit RenderBuffers(Device *device); | explicit RenderBuffers(Device *device); | ||||
| ~RenderBuffers(); | ~RenderBuffers(); | ||||
| void reset(BufferParams ¶ms); | void reset(const BufferParams ¶ms); | ||||
| void zero(); | void zero(); | ||||
| bool copy_from_device(); | bool copy_from_device(); | ||||
| bool get_pass_rect( | void copy_to_device(); | ||||
| const string &name, float exposure, int sample, int components, float *pixels); | |||||
| bool get_denoising_pass_rect( | |||||
| int offset, float exposure, int sample, int components, float *pixels); | |||||
| bool set_pass_rect(PassType type, int components, float *pixels, int samples); | |||||
| }; | }; | ||||
| /* Display Buffer | /* Copy denoised passes form source to destination. | ||||
| * | * | ||||
| * The buffer used for drawing during render, filled by converting the render | * Buffer parameters are provided explicitly, allowing to copy pixelks between render buffers which | ||||
| * buffers to byte of half float storage */ | * content corresponds to a render result at a non-unit resolution divider. | ||||
| * | |||||
| class DisplayBuffer { | * `src_offset` allows to offset source pixel index which is used when a fraction of the source | ||||
| public: | * buffer is to be copied. | ||||
| /* buffer parameters */ | * | ||||
| BufferParams params; | * Copy happens of the number of pixels in the destination. */ | ||||
| /* dimensions for how much of the buffer is actually ready for display. | void render_buffers_host_copy_denoised(RenderBuffers *dst, | ||||
| * with progressive render we can be using only a subset of the buffer. | const BufferParams &dst_params, | ||||
| * if these are zero, it means nothing can be drawn yet */ | const RenderBuffers *src, | ||||
| int draw_width, draw_height; | const BufferParams &src_params, | ||||
| /* draw alpha channel? */ | const size_t src_offset = 0); | ||||
| bool transparent; | |||||
| /* use half float? */ | |||||
| bool half_float; | |||||
| /* byte buffer for converted result */ | |||||
| device_pixels<uchar4> rgba_byte; | |||||
| device_pixels<half4> rgba_half; | |||||
| DisplayBuffer(Device *device, bool linear = false); | |||||
| ~DisplayBuffer(); | |||||
| void reset(BufferParams ¶ms); | |||||
| void draw_set(int width, int height); | |||||
| void draw(Device *device, const DeviceDrawParams &draw_params); | |||||
| bool draw_ready(); | |||||
| }; | |||||
| /* Render Tile | |||||
| * Rendering task on a buffer */ | |||||
| class RenderTile { | |||||
| public: | |||||
| typedef enum { PATH_TRACE = (1 << 0), BAKE = (1 << 1), DENOISE = (1 << 2) } Task; | |||||
| Task task; | |||||
| int x, y, w, h; | |||||
| int start_sample; | |||||
| int num_samples; | |||||
| int sample; | |||||
| int resolution; | |||||
| int offset; | |||||
| int stride; | |||||
| int tile_index; | |||||
| device_ptr buffer; | |||||
| int device_size; | |||||
| typedef enum { NO_STEALING = 0, CAN_BE_STOLEN = 1, WAS_STOLEN = 2 } StealingState; | |||||
| StealingState stealing_state; | |||||
| RenderBuffers *buffers; | |||||
| RenderTile(); | |||||
| int4 bounds() const | |||||
| { | |||||
| return make_int4(x, /* xmin */ | |||||
| y, /* ymin */ | |||||
| x + w, /* xmax */ | |||||
| y + h); /* ymax */ | |||||
| } | |||||
| }; | |||||
| /* Render Tile Neighbors | |||||
| * Set of neighboring tiles used for denoising. Tile order: | |||||
| * 0 1 2 | |||||
| * 3 4 5 | |||||
| * 6 7 8 */ | |||||
| class RenderTileNeighbors { | |||||
| public: | |||||
| static const int SIZE = 9; | |||||
| static const int CENTER = 4; | |||||
| RenderTile tiles[SIZE]; | |||||
| RenderTile target; | |||||
| RenderTileNeighbors(const RenderTile ¢er) | |||||
| { | |||||
| tiles[CENTER] = center; | |||||
| } | |||||
| int4 bounds() const | |||||
| { | |||||
| return make_int4(tiles[3].x, /* xmin */ | |||||
| tiles[1].y, /* ymin */ | |||||
| tiles[5].x + tiles[5].w, /* xmax */ | |||||
| tiles[7].y + tiles[7].h); /* ymax */ | |||||
| } | |||||
| void set_bounds_from_center() | |||||
| { | |||||
| tiles[3].x = tiles[CENTER].x; | |||||
| tiles[1].y = tiles[CENTER].y; | |||||
| tiles[5].x = tiles[CENTER].x + tiles[CENTER].w; | |||||
| tiles[7].y = tiles[CENTER].y + tiles[CENTER].h; | |||||
| } | |||||
| }; | |||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| #endif /* __BUFFERS_H__ */ | #endif /* __BUFFERS_H__ */ | ||||