BVB Source Codes

CRYENGINE Show ParticleDataStreamsImplSSE.h Source code

Return Download CRYENGINE: download ParticleDataStreamsImplSSE.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. namespace pfx2
  4. {
  5.  
  6. namespace detail
  7. {
  8.  
  9. ILINE floatv LoadIndexed4(const float* __restrict pStream, const uint32v index, float defaultVal)
  10. {
  11.         const mask32v4 mask = index == convert<uint32v>(gInvalidId);
  12.         const uint32v mIndex = _mm_andnot_si128(mask, index);
  13.         const uint32v mFirst = _mm_shuffle_epi32(mIndex, 0);
  14.  
  15.         if (All(index == mFirst + convert<uint32v>(0, 1, 2, 3)))
  16.                 return _mm_loadu_ps(pStream + get_element<0>(mFirst));
  17.  
  18.         floatv output = _mm_load1_ps(pStream + get_element<0>((mFirst)));
  19.         if (!All(mFirst == mIndex))
  20.         {
  21.                 const float f1 = *(pStream + get_element<1>(mIndex));
  22.                 const float f2 = *(pStream + get_element<2>(mIndex));
  23.                 const float f3 = *(pStream + get_element<3>(mIndex));
  24.                 const floatv m = vcast<floatv>(convert<uint32v>(~0, 0, 0, 0));
  25.                 const floatv v0 = convert<floatv>(0.0f, f1, f2, f3);
  26.                 output = _mm_or_ps(v0, _mm_and_ps(output, m));
  27.         }
  28.  
  29.         return if_else(mask, convert<floatv>(defaultVal), output);
  30. }
  31.  
  32. }
  33.  
  34. //////////////////////////////////////////////////////////////////////////
  35. // floatv
  36.  
  37. template<>
  38. ILINE floatv TIStream<float, floatv >::Load(TParticleGroupId pgId) const
  39. {
  40.         return _mm_load_ps(m_pStream + pgId);
  41. }
  42.  
  43. template<>
  44. ILINE floatv TIStream<float, floatv >::Load(TParticleIdv pIdv, float defaultVal) const
  45. {
  46.         return detail::LoadIndexed4(m_pStream, pIdv, defaultVal);
  47. }
  48.  
  49. template<>
  50. ILINE floatv TIStream<float, floatv >::SafeLoad(TParticleGroupId pgId) const
  51. {
  52.         return _mm_load_ps(m_pStream + (pgId & m_safeMask));
  53. }
  54.  
  55. template<>
  56. ILINE void TIOStream<float, floatv >::Store(TParticleGroupId pgId, floatv value)
  57. {
  58.         _mm_store_ps(const_cast<float*>(m_pStream) + pgId, value);
  59. }
  60.  
  61. //////////////////////////////////////////////////////////////////////////
  62. // uint32
  63.  
  64. template<>
  65. ILINE uint32v TIStream<uint32, uint32v >::Load(TParticleGroupId pgId) const
  66. {
  67.         return _mm_load_si128(reinterpret_cast<const __m128i*>(m_pStream + pgId));
  68. }
  69.  
  70. template<>
  71. ILINE uint32v TIStream<uint32, uint32v >::Load(TParticleIdv pIdv, uint32 defaultVal) const
  72. {
  73.         const float defaultValF = _mm_cvtss_f32(_mm_castsi128_ps(_mm_set1_epi32(defaultVal)));
  74.         const float* streamF = reinterpret_cast<const float*>(m_pStream);
  75.         __m128 dataF = detail::LoadIndexed4(streamF, pIdv, defaultValF);
  76.         return _mm_castps_si128(dataF);
  77. }
  78.  
  79. template<>
  80. ILINE uint32v TIStream<uint32, uint32v >::SafeLoad(TParticleGroupId pgId) const
  81. {
  82.         return _mm_load_si128(reinterpret_cast<const __m128i*>(m_pStream + (pgId & m_safeMask)));
  83. }
  84.  
  85. template<>
  86. ILINE void TIOStream<uint32, uint32v >::Store(TParticleGroupId pgId, uint32v value)
  87. {
  88.         _mm_store_si128(reinterpret_cast<__m128i*>(const_cast<uint32*>(m_pStream) + pgId), value);
  89. }
  90.  
  91. //////////////////////////////////////////////////////////////////////////
  92. // UColv
  93.  
  94. template<>
  95. ILINE UColv TIStream<UCol, UColv >::Load(TParticleGroupId pgId) const
  96. {
  97.         return _mm_load_si128(reinterpret_cast<const __m128i*>(m_pStream + pgId));
  98. }
  99.  
  100. template<>
  101. ILINE UColv TIStream<UCol, UColv >::Load(TParticleIdv pIdv, UCol defaultVal) const
  102. {
  103.         const float defaultValF = _mm_cvtss_f32(_mm_castsi128_ps(_mm_set1_epi32(defaultVal.dcolor)));
  104.         const float* streamF = reinterpret_cast<const float*>(m_pStream);
  105.         __m128 dataF = detail::LoadIndexed4(streamF, pIdv, defaultValF);
  106.         return _mm_castps_si128(dataF);
  107. }
  108.  
  109. template<>
  110. ILINE UColv TIStream<UCol, UColv >::SafeLoad(TParticleGroupId pgId) const
  111. {
  112.         return _mm_load_si128(reinterpret_cast<const __m128i*>(m_pStream + (pgId & m_safeMask)));
  113. }
  114.  
  115. template<>
  116. ILINE void TIOStream<UCol, UColv >::Store(TParticleGroupId pgId, UColv value)
  117. {
  118.         _mm_store_si128(reinterpret_cast<__m128i*>(const_cast<UCol*>(m_pStream) + pgId), value);
  119. }
  120.  
  121. //////////////////////////////////////////////////////////////////////////
  122.  
  123. ILINE Vec3v IVec3Stream::Load(TParticleGroupId pgId) const
  124. {
  125.         return Vec3v(
  126.                 _mm_load_ps(m_pXStream + pgId),
  127.                 _mm_load_ps(m_pYStream + pgId),
  128.                 _mm_load_ps(m_pZStream + pgId));
  129. }
  130.  
  131. ILINE Vec3v IVec3Stream::Load(TParticleIdv pIdv, Vec3 defaultVal) const
  132. {
  133.         return Vec3v(
  134.                 detail::LoadIndexed4(m_pXStream, pIdv, defaultVal.x),
  135.                 detail::LoadIndexed4(m_pYStream, pIdv, defaultVal.y),
  136.                 detail::LoadIndexed4(m_pZStream, pIdv, defaultVal.z));
  137. }
  138.  
  139. ILINE Vec3v IVec3Stream::SafeLoad(TParticleGroupId pgId) const
  140. {
  141.         return Vec3v(
  142.                 _mm_load_ps(m_pXStream + (pgId & m_safeMask)),
  143.                 _mm_load_ps(m_pYStream + (pgId & m_safeMask)),
  144.                 _mm_load_ps(m_pZStream + (pgId & m_safeMask)));
  145. }
  146.  
  147. ILINE void IOVec3Stream::Store(TParticleGroupId pgId, const Vec3v& value) const
  148. {
  149.         _mm_store_ps(const_cast<float*>(m_pXStream) + pgId, value.x);
  150.         _mm_store_ps(const_cast<float*>(m_pYStream) + pgId, value.y);
  151.         _mm_store_ps(const_cast<float*>(m_pZStream) + pgId, value.z);
  152. }
  153.  
  154. ILINE Quatv IQuatStream::Load(TParticleGroupId pgId) const
  155. {
  156.         return Quatv(
  157.                 _mm_load_ps(m_pWStream + pgId),
  158.                 _mm_load_ps(m_pXStream + pgId),
  159.                 _mm_load_ps(m_pYStream + pgId),
  160.                 _mm_load_ps(m_pZStream + pgId));
  161. }
  162.  
  163. ILINE Quatv IQuatStream::Load(TParticleIdv pIdv, Quat defaultVal) const
  164. {
  165.         return Quatv(
  166.                 detail::LoadIndexed4(m_pWStream, pIdv, defaultVal.w),
  167.                 detail::LoadIndexed4(m_pXStream, pIdv, defaultVal.v.x),
  168.                 detail::LoadIndexed4(m_pYStream, pIdv, defaultVal.v.y),
  169.                 detail::LoadIndexed4(m_pZStream, pIdv, defaultVal.v.z));
  170. }
  171.  
  172. ILINE Quatv IQuatStream::SafeLoad(TParticleGroupId pgId) const
  173. {
  174.         return Quatv(
  175.                 _mm_load_ps(m_pWStream + (pgId & m_safeMask)),
  176.                 _mm_load_ps(m_pXStream + (pgId & m_safeMask)),
  177.                 _mm_load_ps(m_pYStream + (pgId & m_safeMask)),
  178.                 _mm_load_ps(m_pZStream + (pgId & m_safeMask)));
  179. }
  180.  
  181. ILINE void IOQuatStream::Store(TParticleGroupId pgId, const Quatv& value) const
  182. {
  183.         _mm_store_ps(const_cast<float*>(m_pWStream) + pgId, value.w);
  184.         _mm_store_ps(const_cast<float*>(m_pXStream) + pgId, value.v.x);
  185.         _mm_store_ps(const_cast<float*>(m_pYStream) + pgId, value.v.y);
  186.         _mm_store_ps(const_cast<float*>(m_pZStream) + pgId, value.v.z);
  187. }
  188.  
  189. }
  190.  
downloadParticleDataStreamsImplSSE.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top