Commit Graph

100 Commits

Author SHA1 Message Date
Clément Foucault
ef1918d312 Gawain: Fix instancing messing next draw.
Everything was fine if one batch is always used with instancing. But problem arise if the next drawcall for this batch is not using instancing as the attrib divisor stays set to 1 in th VAO.

As instancing is less used than normal drawing I prefer to reset the divisor after drawing as it is reset before drawing instances.
2017-10-11 02:15:42 +02:00
Clément Foucault
f7db1a4366 Gawain: Make common uniforms become builtins
This improves eevee's cache performance by 13% in my test.
2017-10-08 15:49:25 +02:00
Clément Foucault
a4a5637d7a Gawain: Reduce shader interface bucket size
Tried 101 but it gives colisions.
I think 257 is enough now that we dont have thousands of uniforms.
This gives some noticeable performance improvement.
Could be refined further.
2017-10-06 16:25:50 +02:00
Clément Foucault
f94f141f24 Gawain: Add UBOs to shader interface. 2017-10-06 16:25:50 +02:00
Clément Foucault
d7d32ad452 Gawain: Simplify / optimize the shader interface.
This changes quite a few things:
- Drops the allocation of inputs as a chunk.
- Merge the linked list system into the Gwn_ShaderInput.
- Put name buffer into another memory block, easily resizable.
- Use offset instead of char* to direct to input name.
- Add only requested uniforms dynamicaly to the Shader Interface.

This drops some minor optimisation and use a bit more memory for small shaders (which are fixed count).
But this saves a lot of memory when using UBOs because the names and the Gwn_ShaderInput were alloc'ed for every UBO variable.
This also reduce the Shader Interface initial generation.
The lookup time is left unchanged.
2017-10-06 01:50:51 +02:00
Clément Foucault
9ab3db11c7 Revert "Gawain: Optimize out extra level on top of ShaderInput"
This reverts commit 5514d2df1c6d9f2f108336e46b0db14316610d24.
2017-10-06 01:50:16 +02:00
Sergey Sharybin
5514d2df1c Gawain: Optimize out extra level on top of ShaderInput
This is an internal structure, and we don't put it to a list for anything else
that hash collision resolution. No need to have dedicated entry here, saves us
from extra allocation and pointer dereference.
2017-10-05 18:38:23 +05:00
Sergey Sharybin
0b5bdc4265 Gawain: Make builtin uniform lookup to be O(1) 2017-10-05 16:19:14 +05:00
Sergey Sharybin
bb9b8b13e5 Gawain: Lookup uniforms and attributes from buckets
This way we reduce number of loops from look-over-all-inputs to
loop-over-collision, which is expected to be much less CPU ticks.

There is still possible optimization: use memory pool of some sort
to manage memory needed for hash entries, but that will only speedup
shader interface construction / deconstruction time.

There are also some trickery happening to speed up process even more
in the case there is no hash collisions detected when constructing
shader interface.
2017-10-05 15:46:15 +05:00
Sergey Sharybin
bda3e14f05 Gawain: Force hashing function to be inlined
Makes sure we don't waste CPU ticks on function call in such a time critical
area.
2017-10-05 15:46:15 +05:00
Clément Foucault
2bd36338d3 Gawain : Add workaround to fix bad sync of the program_in_use flag. 2017-10-02 22:16:50 +02:00
Campbell Barton
d0dad02604 Cleanup: use lowercase prefix for local API's
Also some minor corrections.
2017-08-18 08:58:26 +10:00
Campbell Barton
cb67873ac5 PyAPI: Iniital gawain API for Python
Wraps vertex-format, vertex-buffer and batch's (enough for drawing).

Doesn't yet expose index-buffers or shaders.
2017-08-18 08:45:41 +10:00
Campbell Barton
4d93323b8a Gawain: name struct's
Needed to reference without first including headers.
2017-08-17 20:37:37 +10:00
Campbell Barton
846c11c8cf Gawain: remove GWN_batch_discard_all
Use ownership flags instead.
2017-08-16 19:51:46 +10:00
Campbell Barton
4f97be617c Gawain: add ownership flag to Gwn_Batch
Flag ownership for each index array & vbo's
so we don't have to manually keep track of this and use the right free call.

Instead this can be passed on creation.

See D2676
2017-08-16 17:42:05 +10:00
Campbell Barton
b6308d79e5 Cleanup: use 'gwn' prefix for gawain filenames
Looking up names project wide or setting breakpoints wasn't so.
Names like common.h or element.h are also too generic.
2017-08-16 00:25:47 +10:00
Campbell Barton
95a7a0a06e Gawain: add GWN_vertbuf_clear
Needed to clear the buffer without freeing.
2017-07-13 01:48:52 +10:00
Clément Foucault
fdadb4829c Gawain: Add support for compressed index with instancing. 2017-07-08 18:21:49 +02:00
Campbell Barton
7dc9e42721 Missing from last commit 2017-06-29 20:33:24 +10:00
Campbell Barton
34566aa969 Gawain: add method of stepping over data directly
This avoids using GWN_vertbuf_attr_set which needs to calculate the
offset and perform a memcpy every call.

Exposing the data directly allows us to avoid a memcpy in some cases
and means we can write to the vertex buffer's memory directly.
2017-06-29 20:09:05 +10:00
Campbell Barton
2343dcf0d2 Gawain: Use common prefix for packed normal 2017-06-29 18:54:23 +10:00
Campbell Barton
b4d053efc7 Gawain API naming refactor
Use consistent prefix for gawain API names as well as
some abbreviations to avoid over-long names, see: D2678
2017-06-19 20:18:04 +10:00
Campbell Barton
eaadfdbdc0 CMake: add missing includes 2017-06-13 14:51:15 +10:00
Mike Erwin
bfa5efeebe Fix MSVC compile (T51740)
Gawain doesn't include Blender's cross-platform "inline" definition. This change slipped in as part of D2697.
2017-06-07 16:28:24 -04:00
Mike Erwin
179bb97740 Gawain: stricter lookup of builtin uniforms
UNIFORM_NONE should never match a valid uniform (builtin or custom).

The logic for UNIFORM_CUSTOM was just wrong, since it returned the first custom uniform. This function should only accept builtin (non-custom) uniforms.
2017-06-07 16:20:37 -04:00
Mike Erwin
bb3e669d06 Gawain: faster lookup shader attribs by name
Quick hash rejection instead of string comparison. Uniform lookups already work this way. I don't expect a major overall speedup since attributes are looked up less frequently than uniforms.
2017-06-07 16:20:37 -04:00
Sergey Sharybin
8c09826d58 Gawain: Optimize shader uniform access
Before this change Gawain was doing list lookup twice,
doing string comparison of every and each input which
is not efficient and not friendly for CPUs with small
cache size.

Now we store hash of input name together with actual
name and compare hashes first. Additionally, we do
everything in a single pass which is much better from
cache coherency point of view.

This brings Eevee cache population time from 80ms to
60ms on my desktop and from 800ms to 400ms for Clement
when navigating in a file from T50027.

Reviewers: merwin, dfelinto

Subscribers: fclem

Differential Revision: https://developer.blender.org/D2697
2017-06-01 12:33:41 +02:00
Mike Erwin
1fa216487d Gawain: update comments to match latest API 2017-05-29 13:37:02 -04:00
Clément Foucault
ec90780767 Gawain: Add support for rendering using an instance batch (for particles) 2017-05-29 16:28:54 +02:00
Mike Erwin
620516965b Gawain: move convert_prim_type_to_gl to private API 2017-05-26 11:23:23 -04:00
Sergey Sharybin
d859bac9e8 Cleanup: Make Gawain code style more consistent
Not as if i'm totally fine with such style, but i'd better be consistent
with whatever the project is using.
2017-05-23 11:53:47 +02:00
Mike Erwin
6cc293a6d9 Gawain: replace switch with lookup table
This function is not performance critical, but I prefer the branch-free code and no hack needed to appease gcc.

Follow-up to recent 23035cf46fb4dd6a0bf7e688b0f15128030c77d1 and f637145450010d14660fcb029d41560a138eae14.
2017-05-22 16:43:33 -04:00
Antony Riakiotakis
f637145450 Fix compilation on gcc 2017-05-22 03:36:05 +03:00
Mike Erwin
23035cf46f Gawain: remove GLenum from IndexType API
Goal is to make most of the API independent of OpenGL, Vulkan, any other backend.

Able to remove default case from ElementList_size because IndexType only covers index types. Not that and *everything else* like GLenum.
2017-05-21 18:25:30 -04:00
Mike Erwin
054eb9422c Gawain: use integer math to convert int16 to int10
@fclem does this work for you?
2017-05-21 18:07:23 -04:00
Mike Erwin
ea31c55b08 Gawain: cleanup code formatting 2017-05-21 17:53:16 -04:00
Mike Erwin
3f6f02e433 Gawain: drop support for APPLE_flush_buffer_range
Modern GL's glMapBufferRange works the same on all platforms.

Part of T49012
2017-05-21 17:06:42 -04:00
Mike Erwin
90a1d49180 Gawain: drop support for APPLE_vertex_array_object
Recent versions of OpenGL support VAOs natively.

Part of T49012
2017-05-21 16:48:54 -04:00
Mike Erwin
68d8618538 Gawain: promote 10_10_10 to first-class vertex format
This format is part of OpenGL 3.3, and one of the reasons for choosing 3.3 over 3.2.

Instead of checking #if USE_10_10_10 just use it wherever needed.
2017-05-21 15:59:34 -04:00
Dalai Felinto
60fc04fb9b Remove reference to WITH_GL_PROFILE_CORE
There is no more point of keep those around. ES20 may need special case
when/if we dabble with it again. Meanwhile no point on polluting the
code with this.

(ghost still has reference for the PROFILE, but that's reasonable)
2017-05-19 14:14:46 +02:00
Clément Foucault
c8bf3984ee Gawain: Fix crash in release build.
Non-initiliazed var, I thought I was clever than this. :(
2017-05-17 01:43:49 +02:00
Mike Erwin
87bbeb2837 Gawain: further cleanup to VertexBuffer_prime
Get buffer size once, use it to both allocate and track VRAM.
2017-05-15 13:08:38 -04:00
Mike Erwin
30d325c9e6 Gawain: cleanup VRAM usage metric
same functionality
2017-05-15 13:08:38 -04:00
Mike Erwin
4f7c738a38 Gawain: revert recent VRAM usage metric
Revert 7a18ee62eb4d6c6028d05f1da259fe8695f49a3f and 1ff97bbfff78a0c375fb5256a9d9d37cd3973bbe after discussing with @fclem.

VertexBuffer_size should always report the same buffer size, but without asking/calling OpenGL.
2017-05-15 13:08:38 -04:00
Clément Foucault
7a18ee62eb Gawain: Fix memory manager. 2017-05-15 16:24:24 +02:00
Clément Foucault
ae9da3786a Gawain: Add assert for maximum attribute name. 2017-05-15 16:14:18 +02:00
Clément Foucault
1ff97bbfff Gawain: Better metric for VRAM usage. 2017-05-15 16:14:18 +02:00
Clément Foucault
cfbfa94e6b Gawain: Add support for multiple attrib names.
This adds the possibility to give multiple name to the same attrib.
This allow multiple binding points depending on the shader.
2017-05-15 16:14:17 +02:00
Clément Foucault
b3e62a8aa2 Gawain: add short vector conversion to 10_10_10 2017-05-15 16:14:17 +02:00