Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
12 changed files with 118 additions and 85 deletions
Showing only changes of commit f6eaaf714a - Show all commits

View File

@ -929,7 +929,7 @@ def dump_template_messages(msgs, reports, settings):
def dump_addon_bl_info(msgs, reports, module, settings):
for prop in ('name', 'location', 'description'):
for prop in ('name', 'location', 'description', 'warning'):
process_msg(
msgs,
settings.DEFAULT_CONTEXT,

View File

@ -384,6 +384,13 @@ class CurvesGeometry : public ::CurvesGeometry {
{
return this->adapt_domain(GVArray(varray), from, to).typed<T>();
}
/* --------------------------------------------------------------------
* File Read/Write.
*/
void blend_read(BlendDataReader *reader);
void blend_write(BlendWriter *writer, ID *id);
};
static_assert(sizeof(blender::bke::CurvesGeometry) == sizeof(::CurvesGeometry));

View File

@ -16,6 +16,7 @@ struct Main;
struct Object;
struct Scene;
struct bGPDcurve;
struct bGPDlayer;
struct bGPDframe;
struct bGPDspoint;
struct bGPDstroke;

View File

@ -130,30 +130,12 @@ static void curves_blend_write(BlendWriter *writer, ID *id, const void *id_addre
{
Curves *curves = (Curves *)id;
Vector<CustomDataLayer, 16> point_layers;
Vector<CustomDataLayer, 16> curve_layers;
CustomData_blend_write_prepare(curves->geometry.point_data, point_layers);
CustomData_blend_write_prepare(curves->geometry.curve_data, curve_layers);
/* Write LibData */
BLO_write_id_struct(writer, Curves, id_address, &curves->id);
BKE_id_blend_write(writer, &curves->id);
/* Direct data */
CustomData_blend_write(writer,
&curves->geometry.point_data,
point_layers,
curves->geometry.point_num,
CD_MASK_ALL,
&curves->id);
CustomData_blend_write(writer,
&curves->geometry.curve_data,
curve_layers,
curves->geometry.curve_num,
CD_MASK_ALL,
&curves->id);
BLO_write_int32_array(writer, curves->geometry.curve_num + 1, curves->geometry.curve_offsets);
curves->geometry.wrap().blend_write(writer, &curves->id);
BLO_write_string(writer, curves->surface_uv_map);
@ -170,10 +152,7 @@ static void curves_blend_read_data(BlendDataReader *reader, ID *id)
BKE_animdata_blend_read_data(reader, curves->adt);
/* Geometry */
CustomData_blend_read(reader, &curves->geometry.point_data, curves->geometry.point_num);
CustomData_blend_read(reader, &curves->geometry.curve_data, curves->geometry.curve_num);
BLO_read_int32_array(reader, curves->geometry.curve_num + 1, &curves->geometry.curve_offsets);
curves->geometry.wrap().blend_read(reader);
BLO_read_data_address(reader, &curves->surface_uv_map);

View File

@ -17,11 +17,14 @@
#include "BLI_math_rotation_legacy.hh"
#include "BLI_task.hh"
#include "BLO_read_write.h"
#include "DNA_curves_types.h"
#include "BKE_attribute_math.hh"
#include "BKE_curves.hh"
#include "BKE_curves_utils.hh"
#include "BKE_customdata.h"
namespace blender::bke {
@ -1572,4 +1575,33 @@ GVArray CurvesGeometry::adapt_domain(const GVArray &varray,
/** \} */
/* -------------------------------------------------------------------- */
/** \name File reading/writing.
* \{ */
void CurvesGeometry::blend_read(BlendDataReader *reader)
{
filedescriptor marked this conversation as resolved Outdated

Remove blank line.

Remove blank line.
CustomData_blend_read(reader, &this->point_data, this->point_num);
CustomData_blend_read(reader, &this->curve_data, this->curve_num);
BLO_read_int32_array(reader, this->curve_num + 1, &this->curve_offsets);
}
void CurvesGeometry::blend_write(BlendWriter *writer, ID *id)
{
Vector<CustomDataLayer, 16> point_layers;
Vector<CustomDataLayer, 16> curve_layers;
CustomData_blend_write_prepare(this->point_data, point_layers);
CustomData_blend_write_prepare(this->curve_data, curve_layers);
CustomData_blend_write(
writer, &this->point_data, point_layers, this->point_num, CD_MASK_ALL, id);
CustomData_blend_write(
writer, &this->curve_data, curve_layers, this->curve_num, CD_MASK_ALL, id);
BLO_write_int32_array(writer, this->curve_num + 1, this->curve_offsets);
}
/** \} */
} // namespace blender::bke

View File

@ -230,6 +230,7 @@ void normals_calc_polys(const Span<float3> positions,
const Span<MLoop> loops,
MutableSpan<float3> poly_normals)
{
BLI_assert(polys.size() == poly_normals.size());
threading::parallel_for(polys.index_range(), 1024, [&](const IndexRange range) {
for (const int i : range) {
const MPoly &poly = polys[i];
@ -415,7 +416,7 @@ const float (*BKE_mesh_poly_normals_ensure(const Mesh *mesh))[3]
poly_normals = BKE_mesh_poly_normals_for_write(&mesh_mutable);
blender::bke::mesh::normals_calc_polys(
positions, polys, loops, {reinterpret_cast<float3 *>(poly_normals), mesh->totvert});
positions, polys, loops, {reinterpret_cast<float3 *>(poly_normals), mesh->totpoly});
BKE_mesh_poly_normals_clear_dirty(&mesh_mutable);
});

View File

@ -809,10 +809,11 @@ if(WITH_GTESTS)
set(TEST_SRC
tests/gpu_testing.cc
tests/gpu_index_buffer_test.cc
tests/gpu_push_constants_test.cc
tests/gpu_shader_test.cc
tests/gpu_storage_buffer_test.cc
tests/index_buffer_test.cc
tests/push_constants_test.cc
tests/shader_test.cc
tests/storage_buffer_test.cc
tests/texture_test.cc
tests/gpu_testing.hh
)

View File

@ -10,7 +10,7 @@
namespace blender::gpu::tests {
static void test_gpu_index_buffer_subbuilders()
static void test_index_buffer_subbuilders()
{
const uint num_subbuilders = 10;
const uint verts_per_subbuilders = 100;
@ -44,6 +44,6 @@ static void test_gpu_index_buffer_subbuilders()
GPU_INDEXBUF_DISCARD_SAFE(index_buffer);
}
GPU_TEST(gpu_index_buffer_subbuilders)
GPU_TEST(index_buffer_subbuilders)
} // namespace blender::gpu::tests

View File

@ -33,7 +33,7 @@ static void test_shader_compile_statically_defined()
}
GPU_TEST(shader_compile_statically_defined)
static void test_gpu_shader_compute_2d()
static void test_shader_compute_2d()
{
if (!GPU_compute_shader_support()) {
@ -77,9 +77,9 @@ static void test_gpu_shader_compute_2d()
GPU_texture_free(texture);
GPU_shader_free(shader);
}
GPU_TEST(gpu_shader_compute_2d)
GPU_TEST(shader_compute_2d)
static void test_gpu_shader_compute_1d()
static void test_shader_compute_1d()
{
if (!GPU_compute_shader_support()) {
@ -126,9 +126,9 @@ static void test_gpu_shader_compute_1d()
GPU_texture_free(texture);
GPU_shader_free(shader);
}
GPU_TEST(gpu_shader_compute_1d)
GPU_TEST(shader_compute_1d)
static void test_gpu_shader_compute_vbo()
static void test_shader_compute_vbo()
{
if (!GPU_compute_shader_support()) {
@ -173,9 +173,9 @@ static void test_gpu_shader_compute_vbo()
GPU_vertbuf_discard(vbo);
GPU_shader_free(shader);
}
GPU_TEST(gpu_shader_compute_vbo)
GPU_TEST(shader_compute_vbo)
static void test_gpu_shader_compute_ibo()
static void test_shader_compute_ibo()
{
if (!GPU_compute_shader_support()) {
@ -214,9 +214,9 @@ static void test_gpu_shader_compute_ibo()
GPU_indexbuf_discard(ibo);
GPU_shader_free(shader);
}
GPU_TEST(gpu_shader_compute_ibo)
GPU_TEST(shader_compute_ibo)
static void test_gpu_shader_compute_ssbo()
static void test_shader_compute_ssbo()
{
if (!GPU_compute_shader_support() && !GPU_shader_storage_buffer_objects_support()) {
@ -256,9 +256,9 @@ static void test_gpu_shader_compute_ssbo()
GPU_storagebuf_free(ssbo);
GPU_shader_free(shader);
}
GPU_TEST(gpu_shader_compute_ssbo)
GPU_TEST(shader_compute_ssbo)
static void test_gpu_shader_ssbo_binding()
static void test_shader_ssbo_binding()
{
if (!GPU_compute_shader_support()) {
/* We can't test as a the platform does not support compute shaders. */
@ -269,7 +269,7 @@ static void test_gpu_shader_ssbo_binding()
/* Build compute shader. */
GPUShader *shader = GPU_shader_create_from_info_name("gpu_compute_ssbo_binding_test");
EXPECT_NE(shader, nullptr);
/* Perform tests. */
EXPECT_EQ(0, GPU_shader_get_ssbo_binding(shader, "data0"));
EXPECT_EQ(1, GPU_shader_get_ssbo_binding(shader, "data1"));
@ -277,44 +277,7 @@ static void test_gpu_shader_ssbo_binding()
/* Cleanup. */
GPU_shader_free(shader);
}
GPU_TEST(gpu_shader_ssbo_binding)
static void test_gpu_texture_read()
{
GPU_render_begin();
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ;
GPUTexture *rgba32u = GPU_texture_create_2d("rgba32u", 1, 1, 1, GPU_RGBA32UI, usage, nullptr);
GPUTexture *rgba16u = GPU_texture_create_2d("rgba16u", 1, 1, 1, GPU_RGBA16UI, usage, nullptr);
GPUTexture *rgba32f = GPU_texture_create_2d("rgba32f", 1, 1, 1, GPU_RGBA32F, usage, nullptr);
const float4 fcol = {0.0f, 1.3f, -231.0f, 1000.0f};
const uint4 ucol = {0, 1, 2, 12223};
GPU_texture_clear(rgba32u, GPU_DATA_UINT, ucol);
GPU_texture_clear(rgba16u, GPU_DATA_UINT, ucol);
GPU_texture_clear(rgba32f, GPU_DATA_FLOAT, fcol);
GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE);
uint4 *rgba32u_data = (uint4 *)GPU_texture_read(rgba32u, GPU_DATA_UINT, 0);
uint4 *rgba16u_data = (uint4 *)GPU_texture_read(rgba16u, GPU_DATA_UINT, 0);
float4 *rgba32f_data = (float4 *)GPU_texture_read(rgba32f, GPU_DATA_FLOAT, 0);
EXPECT_EQ(ucol, *rgba32u_data);
EXPECT_EQ(ucol, *rgba16u_data);
EXPECT_EQ(fcol, *rgba32f_data);
MEM_freeN(rgba32u_data);
MEM_freeN(rgba16u_data);
MEM_freeN(rgba32f_data);
GPU_texture_free(rgba32u);
GPU_texture_free(rgba16u);
GPU_texture_free(rgba32f);
GPU_render_end();
}
GPU_TEST(gpu_texture_read)
GPU_TEST(shader_ssbo_binding)
static std::string print_test_data(const TestOutputRawData &raw, TestType type)
{
@ -487,11 +450,11 @@ static void gpu_shader_lib_test(const char *test_src_name, const char *additiona
GPU_render_end();
}
static void test_gpu_math_lib()
static void test_math_lib()
{
gpu_shader_lib_test("gpu_math_test.glsl");
}
GPU_TEST(gpu_math_lib)
GPU_TEST(math_lib)
static void test_eevee_lib()
{

View File

@ -22,7 +22,7 @@ static Vector<int32_t> test_data()
return data;
}
static void test_gpu_storage_buffer_create_update_read()
static void test_storage_buffer_create_update_read()
{
GPUStorageBuf *ssbo = GPU_storagebuf_create_ex(
SIZE_IN_BYTES, nullptr, GPU_USAGE_STATIC, __func__);
@ -45,6 +45,6 @@ static void test_gpu_storage_buffer_create_update_read()
GPU_storagebuf_free(ssbo);
}
GPU_TEST(gpu_storage_buffer_create_update_read);
GPU_TEST(storage_buffer_create_update_read);
} // namespace blender::gpu::tests

View File

@ -0,0 +1,49 @@
#include "gpu_testing.hh"
#include "MEM_guardedalloc.h"
#include "BLI_math_vector.hh"
#include "GPU_context.h"
#include "GPU_texture.h"
namespace blender::gpu::tests {
static void test_texture_read()
{
GPU_render_begin();
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_HOST_READ;
GPUTexture *rgba32u = GPU_texture_create_2d("rgba32u", 1, 1, 1, GPU_RGBA32UI, usage, nullptr);
GPUTexture *rgba16u = GPU_texture_create_2d("rgba16u", 1, 1, 1, GPU_RGBA16UI, usage, nullptr);
GPUTexture *rgba32f = GPU_texture_create_2d("rgba32f", 1, 1, 1, GPU_RGBA32F, usage, nullptr);
const float4 fcol = {0.0f, 1.3f, -231.0f, 1000.0f};
const uint4 ucol = {0, 1, 2, 12223};
GPU_texture_clear(rgba32u, GPU_DATA_UINT, ucol);
GPU_texture_clear(rgba16u, GPU_DATA_UINT, ucol);
GPU_texture_clear(rgba32f, GPU_DATA_FLOAT, fcol);
GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE);
uint4 *rgba32u_data = (uint4 *)GPU_texture_read(rgba32u, GPU_DATA_UINT, 0);
uint4 *rgba16u_data = (uint4 *)GPU_texture_read(rgba16u, GPU_DATA_UINT, 0);
float4 *rgba32f_data = (float4 *)GPU_texture_read(rgba32f, GPU_DATA_FLOAT, 0);
EXPECT_EQ(ucol, *rgba32u_data);
EXPECT_EQ(ucol, *rgba16u_data);
EXPECT_EQ(fcol, *rgba32f_data);
MEM_freeN(rgba32u_data);
MEM_freeN(rgba16u_data);
MEM_freeN(rgba32f_data);
GPU_texture_free(rgba32u);
GPU_texture_free(rgba16u);
GPU_texture_free(rgba32f);
GPU_render_end();
}
GPU_TEST(texture_read)
} // namespace blender::gpu::tests