2018-01-09 14:09:14 +01:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2016, Blender Foundation.
|
2018-01-09 14:09:14 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup draw
|
2018-01-09 14:09:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-02-14 18:16:52 +01:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
|
|
|
|
|
|
#include "GPU_batch.h"
|
|
|
|
|
|
2018-06-04 19:17:26 +02:00
|
|
|
#define MAX_INSTANCE_DATA_SIZE 64 /* Can be adjusted for more */
|
2018-02-08 00:40:50 +01:00
|
|
|
|
2019-05-13 17:56:20 +02:00
|
|
|
#define DRW_BUFFER_VERTS_CHUNK 128
|
|
|
|
|
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
struct GHash;
|
|
|
|
|
struct GPUUniformAttrList;
|
|
|
|
|
|
2018-01-09 14:09:14 +01:00
|
|
|
typedef struct DRWInstanceData DRWInstanceData;
|
|
|
|
|
typedef struct DRWInstanceDataList DRWInstanceDataList;
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
typedef struct DRWSparseUniformBuf DRWSparseUniformBuf;
|
2018-01-09 14:09:14 +01:00
|
|
|
|
|
|
|
|
void *DRW_instance_data_next(DRWInstanceData *idata);
|
2019-01-29 07:46:25 +11:00
|
|
|
DRWInstanceData *DRW_instance_data_request(DRWInstanceDataList *idatalist, uint attr_size);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-13 17:56:20 +02:00
|
|
|
GPUVertBuf *DRW_temp_buffer_request(DRWInstanceDataList *idatalist,
|
|
|
|
|
GPUVertFormat *format,
|
2019-05-31 01:45:41 +02:00
|
|
|
int *vert_len);
|
2019-05-13 17:56:20 +02:00
|
|
|
GPUBatch *DRW_temp_batch_instance_request(DRWInstanceDataList *idatalist,
|
|
|
|
|
GPUVertBuf *buf,
|
2019-12-02 01:40:58 +01:00
|
|
|
GPUBatch *instancer,
|
2019-05-13 17:56:20 +02:00
|
|
|
GPUBatch *geom);
|
|
|
|
|
GPUBatch *DRW_temp_batch_request(DRWInstanceDataList *idatalist,
|
|
|
|
|
GPUVertBuf *buf,
|
|
|
|
|
GPUPrimType type);
|
2018-02-14 18:16:52 +01:00
|
|
|
|
|
|
|
|
/* Upload all instance data to the GPU as soon as possible. */
|
|
|
|
|
void DRW_instance_buffer_finish(DRWInstanceDataList *idatalist);
|
|
|
|
|
|
2018-01-09 14:09:14 +01:00
|
|
|
void DRW_instance_data_list_reset(DRWInstanceDataList *idatalist);
|
|
|
|
|
void DRW_instance_data_list_free_unused(DRWInstanceDataList *idatalist);
|
|
|
|
|
void DRW_instance_data_list_resize(DRWInstanceDataList *idatalist);
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
|
|
|
|
|
/* Sparse chunked UBO manager. */
|
|
|
|
|
DRWSparseUniformBuf *DRW_sparse_uniform_buffer_new(unsigned int item_size,
|
|
|
|
|
unsigned int chunk_size);
|
|
|
|
|
void DRW_sparse_uniform_buffer_flush(DRWSparseUniformBuf *buffer);
|
|
|
|
|
void DRW_sparse_uniform_buffer_clear(DRWSparseUniformBuf *buffer, bool free_all);
|
|
|
|
|
void DRW_sparse_uniform_buffer_free(DRWSparseUniformBuf *buffer);
|
|
|
|
|
bool DRW_sparse_uniform_buffer_is_empty(DRWSparseUniformBuf *buffer);
|
|
|
|
|
void DRW_sparse_uniform_buffer_bind(DRWSparseUniformBuf *buffer, int chunk, int location);
|
|
|
|
|
void DRW_sparse_uniform_buffer_unbind(DRWSparseUniformBuf *buffer, int chunk);
|
2020-11-03 15:26:23 -06:00
|
|
|
void *DRW_sparse_uniform_buffer_ensure_item(DRWSparseUniformBuf *buffer, int chunk, int item);
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
|
|
|
|
|
/* Uniform attribute UBO management. */
|
|
|
|
|
struct GHash *DRW_uniform_attrs_pool_new(void);
|
|
|
|
|
void DRW_uniform_attrs_pool_flush_all(struct GHash *table);
|
|
|
|
|
void DRW_uniform_attrs_pool_clear_all(struct GHash *table);
|
|
|
|
|
struct DRWSparseUniformBuf *DRW_uniform_attrs_pool_find_ubo(struct GHash *table,
|
|
|
|
|
struct GPUUniformAttrList *key);
|