buffers.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright 2011-2013 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __BUFFERS_H__
  17. #define __BUFFERS_H__
  18. #include "device/device_memory.h"
  19. #include "render/film.h"
  20. #include "kernel/kernel_types.h"
  21. #include "util/util_half.h"
  22. #include "util/util_string.h"
  23. #include "util/util_thread.h"
  24. #include "util/util_types.h"
  25. CCL_NAMESPACE_BEGIN
  26. class Device;
  27. struct DeviceDrawParams;
  28. struct float4;
  29. /* Buffer Parameters
  30. * Size of render buffer and how it fits in the full image (border render). */
  31. class BufferParams {
  32. public:
  33. /* width/height of the physical buffer */
  34. int width;
  35. int height;
  36. /* offset into and width/height of the full buffer */
  37. int full_x;
  38. int full_y;
  39. int full_width;
  40. int full_height;
  41. /* passes */
  42. vector<Pass> passes;
  43. bool denoising_data_pass;
  44. /* If only some light path types should be denoised, an additional pass is needed. */
  45. bool denoising_clean_pass;
  46. /* When we're prefiltering the passes during rendering, we need to keep both the
  47. * original and the prefiltered data around because neighboring tiles might still
  48. * need the original data. */
  49. bool denoising_prefiltered_pass;
  50. /* functions */
  51. BufferParams();
  52. void get_offset_stride(int &offset, int &stride);
  53. bool modified(const BufferParams &params);
  54. void add_pass(PassType type);
  55. int get_passes_size();
  56. int get_denoising_offset();
  57. int get_denoising_prefiltered_offset();
  58. };
  59. /* Render Buffers */
  60. class RenderBuffers {
  61. public:
  62. /* buffer parameters */
  63. BufferParams params;
  64. /* float buffer */
  65. device_vector<float> buffer;
  66. bool map_neighbor_copied;
  67. double render_time;
  68. explicit RenderBuffers(Device *device);
  69. ~RenderBuffers();
  70. void reset(BufferParams &params);
  71. void zero();
  72. bool copy_from_device();
  73. bool get_pass_rect(PassType type,
  74. float exposure,
  75. int sample,
  76. int components,
  77. float *pixels,
  78. const string &name);
  79. bool get_denoising_pass_rect(
  80. int offset, float exposure, int sample, int components, float *pixels);
  81. };
  82. /* Display Buffer
  83. *
  84. * The buffer used for drawing during render, filled by converting the render
  85. * buffers to byte of half float storage */
  86. class DisplayBuffer {
  87. public:
  88. /* buffer parameters */
  89. BufferParams params;
  90. /* dimensions for how much of the buffer is actually ready for display.
  91. * with progressive render we can be using only a subset of the buffer.
  92. * if these are zero, it means nothing can be drawn yet */
  93. int draw_width, draw_height;
  94. /* draw alpha channel? */
  95. bool transparent;
  96. /* use half float? */
  97. bool half_float;
  98. /* byte buffer for converted result */
  99. device_pixels<uchar4> rgba_byte;
  100. device_pixels<half4> rgba_half;
  101. DisplayBuffer(Device *device, bool linear = false);
  102. ~DisplayBuffer();
  103. void reset(BufferParams &params);
  104. void draw_set(int width, int height);
  105. void draw(Device *device, const DeviceDrawParams &draw_params);
  106. bool draw_ready();
  107. };
  108. /* Render Tile
  109. * Rendering task on a buffer */
  110. class RenderTile {
  111. public:
  112. typedef enum { PATH_TRACE, DENOISE } Task;
  113. Task task;
  114. int x, y, w, h;
  115. int start_sample;
  116. int num_samples;
  117. int sample;
  118. int resolution;
  119. int offset;
  120. int stride;
  121. int tile_index;
  122. device_ptr buffer;
  123. int device_size;
  124. RenderBuffers *buffers;
  125. RenderTile();
  126. };
  127. CCL_NAMESPACE_END
  128. #endif /* __BUFFERS_H__ */