src/compiler/translator/ShaderStorageBlockOutputHLSL.cpp


Log

Author Commit Date CI Message
Stephen White 6803a2d0 2022-04-01T16:52:49 D3D11: implement SSBOs in pixel and vertex shaders. Since the 'u' register space for UAVs in pixel shaders is shared with render targets, and the number of render targets may vary depending on GL state, this required deferring register allocation until draw-time output in DynamicHLSL. Since non-compute shaders aren't able to immediately output the SSBO declaration, initial register allocation was broken out from ResourcesHLSL::shaderStorageBlocksHeader() into ResourcesHLSL::allocateShaderStorageBlockRegisters() with the former only called for compute shaders. These initial allocations are offset by the number of RTs at draw time. Since Raw UAVs may now be created at draw time for non-compute shaders, call markRawBufferUsage() from the Renderer11::draw*() entry points as it is from dispatchCompute*(). Bug: angleproject:7156 Change-Id: I6ab65af1ff36df0313e3c1f8f79661b1547ab9a2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3565562 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Stephen White <senorblanco@chromium.org>
Peter Kasting 1bffabe8 2021-06-29T18:13:39 Fix -Wunreachable-code-aggressive. Bug: chromium:1066980 Change-Id: I1fa08a40dbf223d60a10681af33ca8a29b12bf8b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2991094 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Stephen White ac8e1196 2021-03-20T11:29:50 SSBO handling rewrite. The basic idea is to replace the current SSBO output traversal by build a new AST for the Load and Store subtrees, then traverse that AST with the regular OutputHLSL traversal. This way, all the paren balancing and state management can go away. BUG: angleproject:5734 Change-Id: I14d2fecd724d7419fbc9315fad4e9202a741b03f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2773401 Commit-Queue: Stephen White <senorblanco@chromium.org> Reviewed-by: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Qin Jiajia ba0bd785 2021-03-15T16:00:33 Fix the assert error and inbalence parens for SSBO This PR strengthens below two cases: 1. Support calculate unsized array size for any type. Previously, it reported error when the type was a structure. 2. Correctly add the right paren for store function when any load/length functions are nested in it. Bug: angleproject:5734 Change-Id: I3428fa35f1481275e1d193094ceddb011f747cf1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2762655 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Shahbaz Youssefi 86d9c93a 2019-12-16T16:07:04 Use TSpan for TType's array sizes Until C++20, std::vector doesn't have a constexpr constructor, which means TType cannot use a `TVector` for `mArraySizes` if an arrayed type needs to be created constexpr. This is needed for the upcoming textureGatherOffsets implementation. A new TSpan class is introduced, based on std::span (from C++20) that holds the pointer/size allocated from a TVector without owning it. Since TVector's allocation are made from a pool, the allocated memory will live beyond the vector's destruction. `TType::mArraySizes` is changed to this type. This change will allow a new constexpr constructor to be added to TType that takes a TSpan as array directly, a value which is constexpr initialized from a static array (instead of TVector). Bug: angleproject:3569 Change-Id: I78793b0f4c64519e0ebe30cf6e0de995ba70035d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1968260 Reviewed-by: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
James Darpinian 7e48c9eb 2019-08-06T17:17:19 Add explicit integer casts WebKit uses the -Wshorten-64-to-32 flag which warns on these cases. Bug: 3439 Change-Id: I8c1de60da0f173ca2036e2120e79b857f5f2775f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1740866 Commit-Queue: James Darpinian <jdarpinian@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org>
Qin Jiajia 0e2c39f2 2019-03-20T15:17:28 Fix that uniform can't be used as the index of buffer variable ssbo.a[uniformBlock.index] should be a valid usage. So in this change, we forward EOpIndexDirectInterfaceBlock to OutputHLSL to process when the left node is not a SSBO. Bug: angleproject:3280 Change-Id: I2696d5b1cf420db133a8ba0728116261dd9e9f1e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1531980 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Jamie Madill 225f08bf 2019-01-03T15:59:29 Cleanups to StripArrayIndices. Not picked up in prior review. Bug: angleproject:3024 Change-Id: I9dd1ea146996c8ac3569070af0cb12df65f0d815 Reviewed-on: https://chromium-review.googlesource.com/c/1394570 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Jamie Madill 4e712be2 2019-01-03T13:53:59 Refactor BlockLayoutEncoder APIs for std430. This splits HLSL SSBO access into two steps. First we compute a mapping from the collected SSBO variable names to TField pointers. Then during tree traversal we use a block encoding visitor class that uses the shader names to store BlockMemberInfo structures for the structures and variables. Each nested structure is traversed separately so that the BlockMemberInfo offsets are relative to the structure start rather than the enclosing block. The array stride for a structure is the size of the struct after all the alignment is included. This gives the correct results for the SSBO access chain in the HLSL code. It also will allow us to use the same encoding and visiting logic for SSBOs on the API side. Bug: angleproject:3024 Change-Id: I42b1db0e7547782ae77fe5f64a797f803f203f45 Reviewed-on: https://chromium-review.googlesource.com/c/1352731 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Jamie Madill 904bb918 2019-01-02T16:00:02 Rename constants in blocklayout.h. This adds the "k" prefix. Bug: angleproject:3024 Change-Id: I3771a8a9d90cd5edc7173f2b3817a5f1f053bdd4 Reviewed-on: https://chromium-review.googlesource.com/c/1392399 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Qin Jiajia 4622905b 2018-12-10T13:31:00 ES31: Add atomic memory functions for SSBO Due to SSBO is translated to RWByteAddressBuffer in HLSL, the corresponding atomic memory functions atomic* will be translated to RWByteAddressBuffer.Interlocked*. The translation is like below: atomicAdd(instanceName.data[0], 5u); // becomes uint _ssbo_atomicAdd_uint(RWByteAddressBuffer buffer, uint loc, uint value) { uint original_value; buffer.InterlockedAdd(loc, value, original_value); return original_value; } _ssbo_atomicAdd_uint(_instanceName, 0 + 16 * 0, 5); Bug: angleproject:1951 Change-Id: If2af8bedb67a4135b443d2512d43c6058a78888d Reviewed-on: https://chromium-review.googlesource.com/c/1370676 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Qin Jiajia 88faa696 2018-12-03T16:22:24 ES31: Add unsized array length support in SSBO Bug: angleproject:1951 Change-Id: I10c798c62a741b156f5b614e0df0795c0e845108 Reviewed-on: https://chromium-review.googlesource.com/c/1365154 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Qin Jiajia 6494c415 2018-11-05T15:46:04 ES31: Add swizzle support in SSBO (Part 1) This patch adds the swizzle process if the swizzle node is the last node in ssbo access chain. Bug: angleproject:1951 Change-Id: Iecc95baa45e8cc40be9111a15398c7e858bfb99e Reviewed-on: https://chromium-review.googlesource.com/c/1341234 Commit-Queue: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Qin Jiajia b81ff9e6 2018-10-26T17:20:50 ES31: Add std430 encoder. Bug: angleproject:1951 Change-Id: I5e469ee5f13604102b0ee268d5bf9f5ac4809ecd Reviewed-on: https://chromium-review.googlesource.com/c/1278098 Commit-Queue: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Qin Jiajia 48f63f90 2018-10-26T17:20:50 ES31: add row major matrix support (part 2) This patch implements read/write vector data in matrix or matrix data directly in a shader storage block with row_major qualifier. Bug: angleproject:1951 Change-Id: Id7847e2245b09414709361412a95c4dd84b9ee97 Reviewed-on: https://chromium-review.googlesource.com/c/1304019 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Qin Jiajia 5d2dfa46 2018-11-03T09:28:17 ES31: Add array of arrays support in SSBO Bug: angleproject:1951 Change-Id: I5e92b75a59a3ab24a34b827ae6f968961b8bea49 Reviewed-on: https://chromium-review.googlesource.com/c/1317376 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Yuly Novikov 5ca3e5a0 2018-10-31T11:13:29 Fix ShaderStorageBlockOutputHLSL::writeEOpIndexDirectOrIndirectOutput https://chromium-review.googlesource.com/c/1304017 removed str() wrapping values passed to TInfoSinkBase::operator<<(). This broke ANGLE roll https://chromium-review.googlesource.com/c/chromium/src/+/1309331 failing compile on linux-libfuzzer-asan-rel bot. Looks like libfuzzer compiler has a bug, not being able to find sh::BlockLayoutEncoder::BytesPerComponent. Wrapping it in str() works around this. Bug: angleproject:1951 Change-Id: I2deb573667dc1e88d352bad1933c269ec36cf398 Reviewed-on: https://chromium-review.googlesource.com/c/1309975 Commit-Queue: Yuly Novikov <ynovikov@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Qin Jiajia d60e42f8 2018-10-25T16:33:16 ES31: add row major matrix support (part 1) This is the first patch to enable row major matrix suppot in series. This patch ensures that we can get correct location when we load/store data from matrix. Currently, only scalar data load/store works well. mat2x3 data The location of data[x][y] will be: data.offset + x * scalarStride + y * matrixStride //row_major data.offset + x * matrixStride + y * scalarStride //column_major Bug: angleproject:1951 Change-Id: I5bd7bad7d293219ba610f18eeafc56e70e36de43 Reviewed-on: https://chromium-review.googlesource.com/c/1304017 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Qin Jiajia df73a8e5 2018-10-25T16:11:20 ES31: Use std::map<const TField *, BlockMemberInfo> to save ssbo info Bug: angleproject:1951 Change-Id: I9d6a19c0d63065db69985845a1cd68cfd4b99d1f Reviewed-on: https://chromium-review.googlesource.com/c/1298913 Commit-Queue: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Qin Jiajia 8edb7188 2018-10-10T15:54:23 ES31: Add structure field member support in SSBO This patch adds the structure field member support in SSBO. To support it, below things are done: 1. Calculate the offset and arrayStride in SSBO structure. 2. Support array of arrays translation. Bug: angleproject:1951 Change-Id: If8f233e6388d5bb905e78c39a85112d394298138 Reviewed-on: https://chromium-review.googlesource.com/c/1278097 Commit-Queue: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Qin Jiajia 19603b9e 2018-10-18T17:25:33 ES31: Allow function call, unary, ternary operators in SSBO When we meet function call, unary or ternary operator in SSBO access chain, we should transfer the process of them to OutputHLSL. Bug: angleproject:1951 Change-Id: I740940ac4eee4c5ed52239f14b1d32b1f9cf9385 Reviewed-on: https://chromium-review.googlesource.com/c/1290470 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Qin Jiajia 6d765b07 2018-09-28T14:16:06 ES31: Fix some bugs in ShaderStorageBlockOutputHLSL When EOpIndexDirect/EOpIndexIndirect/EOpIndexDirectStruct/TIntermSwizzle appear in [] in ssbo access chain, we should transfer the process of them to OutputHLSL. For example: instance.v[gl_GlobalInvocationID.x] = data; // becomes float_Store(dx_instance, 0 + 16 * gl_GlobalInvocationID.x, _data); instance.v[s.index[0].x] = data; // becomes float_Store(dx_instance, 0 + 16 * _s.index[0].x, _data); Bug: angleproject:1951 Change-Id: I333e238400a10a799a6294f8759cf9c4ef2451c8 Reviewed-on: https://chromium-review.googlesource.com/c/1250661 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
Qin Jiajia a735ee2f 2018-05-18T13:29:09 ES31: Support shader storage block in D3D11 compiler - Part1 This patch is the first step to implement a basic skeleton to translate shader storage block to HLSL RWByteAddressBuffer. In GLSL each shader storage block is just one structured block and in API side it corresponds to a buffer range where stores the whole structure. RWStructuredBuffer is an array-like object and can have many structured elements. The structured element doesn't support unsized array and also have a small limitation on the element size. So we choose RWByteAddressBuffer as the counterpart of shader storage block in HLSL. Due to RWByteAddressBuffer does not support using an index to reference a specific location, we must use Load and Store to process the read/write operation of a buffer variable. Moreover, in the compiler tree, since we can't use variable name to get the resource value in RWByteAddressBuffer, we have to calculate the offset of buffer variable in a shader storage block, then call the corresponding wrapper function to get the right value. In this patch, we only process below situations: assign_to_ssbo := ssbo_access_chain = expr_no_ssbo; assign_from_ssbo := lvalue_no_ssbo = ssbo_access_chain; The translation is like below: // GLSL #version 310 es layout(local_size_x=8) in; layout(std140, binding = 0) buffer blockA { float f[8]; } instanceA; layout(std140, binding = 1) buffer blockB { float f[8]; }; void main() { float data = instanceA.f[gl_LocalInvocationIndex]; f[gl_LocalInvocationIndex] = data; } // HLSL RWByteAddressBuffer _instanceA: register(u0); RWByteAddressBuffer _blockB: register(u1); float float_Load(RWByteAddressBuffer buffer, uint loc) { float result = asfloat(buffer.Load(loc)); return result; } void float_Store(RWByteAddressBuffer buffer, uint loc, float value) { buffer.Store(loc, asuint(value)); } void gl_main() { float _data = float_Load(_instanceA, 0 + 16 * gl_LocalInvocationIndex); float_Store(_blockB, 0 + 16 * gl_LocalInvocationIndex, _data); } We will do below things in the following patches: 1. Modify the intermediate tree to flatten all ssbo usages to: assign_to_ssbo := ssbo_access_chain = expr_no_ssbo; assign_from_ssbo := lvalue_no_ssbo = ssbo_access_chain; e.g. intanceA.a +=1; ->tmp = intanceA.a; intanceA.a = tmp + 1; while(++instanceA.a < 16) { } -> int PreIncrement(out int a) { a += 1; return a; } tmp = instanceA.a; while(PreIncrement(tmp) < 16) { instanceA.a = tmp } 2. Add offset calculation for structure and array of arrays. TODOs have been marked in the corresponding places in this patch. 3. Improve helper functions so that they can process all possible types. TODOs have been marked in the corresponding places in this patch. 4. Process the swizzle situation. TODOs have been marked in the corresponding places in this patch. A possible method is to extend current helper functions like below: *_Load(RWByteAddressBuffer buffer, uint loc, bool isSwizzle, uint4 swizzleOffset) Bug: angleproject:1951 Test: angle_end2end_tests Change-Id: I68ae68d5bb77d0d5627c8272627a7f689b8dc38b Reviewed-on: https://chromium-review.googlesource.com/848215 Reviewed-by: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>