@@ -2228,63 +2228,48 @@ namespace dxvk {
22282228 const DxbcRegisterValue srcValue = emitRegisterLoad (
22292229 ins.src [0 ], DxbcRegMask (true , true , true , true ));
22302230
2231- // Compute sin and cos together; either output may be null.
2232- const bool useBuiltIn = !m_moduleInfo.options .sincosEmulation ;
2233-
2234- if (ins.dst [0 ].type != DxbcOperandType::Null ||
2235- ins.dst [1 ].type != DxbcOperandType::Null) {
2236-
2237- // Determine component count from whichever destination is non‑null
2238- DxbcRegMask sharedMask = ins.dst [0 ].type != DxbcOperandType::Null
2239- ? ins.dst [0 ].mask : ins.dst [1 ].mask ;
2240- const DxbcRegisterValue srcInput =
2241- emitRegisterExtract (srcValue, sharedMask);
2242-
2243- uint32_t componentCount = srcInput.type .ccount ;
2244- std::array<uint32_t , 4 > sinIds = {};
2245- std::array<uint32_t , 4 > cosIds = {};
2246-
2247- uint32_t floatType = m_module.defFloatType (32 );
2248-
2249- for (uint32_t i = 0 ; i < componentCount; i++) {
2250- uint32_t scalarX = componentCount > 1
2251- ? m_module.opVectorExtractDynamic (
2252- floatType, srcInput.id ,
2253- m_module.constu32 (i))
2254- : srcInput.id ;
2255-
2256- uint32_t sincos = m_module.opSinCos (scalarX, useBuiltIn);
2257-
2258- // opSinCos returns vec2: index 0 = sin, index 1 = cos
2259- uint32_t sinIndex = 0u , cosIndex = 1u ;
2260- sinIds[i] = m_module.opCompositeExtract (
2261- floatType, sincos, 1u , &sinIndex);
2262- cosIds[i] = m_module.opCompositeExtract (
2263- floatType, sincos, 1u , &cosIndex);
2264- }
2231+ uint32_t typeId = getScalarTypeId (srcValue.type .ctype );
22652232
2266- if (ins.dst [0 ].type != DxbcOperandType::Null) {
2267- DxbcRegisterValue sin;
2268- sin.type = srcInput.type ;
2269- sin.id = componentCount > 1
2270- ? m_module.opCompositeConstruct (
2271- getVectorTypeId (sin.type ),
2272- componentCount, sinIds.data ())
2273- : sinIds[0 ];
2274- emitRegisterStore (ins.dst [0 ], sin);
2275- }
2233+ DxbcRegisterValue sinVector = { };
2234+ sinVector.type .ctype = DxbcScalarType::Float32;
2235+
2236+ DxbcRegisterValue cosVector = { };
2237+ cosVector.type .ctype = DxbcScalarType::Float32;
2238+
2239+ // Only compute sincos for enabled components
2240+ std::array<uint32_t , 4 > sinIds = { };
2241+ std::array<uint32_t , 4 > cosIds = { };
2242+
2243+ for (uint32_t i = 0 ; i < 4 ; i++) {
2244+ const uint32_t sinIndex = 0u ;
2245+ const uint32_t cosIndex = 1u ;
22762246
2277- if (ins.dst [1 ].type != DxbcOperandType::Null) {
2278- DxbcRegisterValue cos;
2279- cos.type = srcInput.type ;
2280- cos.id = componentCount > 1
2281- ? m_module.opCompositeConstruct (
2282- getVectorTypeId (cos.type ),
2283- componentCount, cosIds.data ())
2284- : cosIds[0 ];
2285- emitRegisterStore (ins.dst [1 ], cos);
2247+ if (ins.dst [0 ].mask [i] || ins.dst [1 ].mask [i]) {
2248+ uint32_t sincosId = m_module.opSinCos (
2249+ m_module.opCompositeExtract (typeId, srcValue.id , 1u , &i),
2250+ !m_moduleInfo.options .sincosEmulation );
2251+
2252+ if (ins.dst [0 ].type != DxbcOperandType::Null && ins.dst [0 ].mask [i])
2253+ sinIds[sinVector.type .ccount ++] = m_module.opCompositeExtract (typeId, sincosId, 1u , &sinIndex);
2254+
2255+ if (ins.dst [1 ].type != DxbcOperandType::Null && ins.dst [1 ].mask [i])
2256+ cosIds[cosVector.type .ccount ++] = m_module.opCompositeExtract (typeId, sincosId, 1u , &cosIndex);
22862257 }
22872258 }
2259+
2260+ if (sinVector.type .ccount ) {
2261+ sinVector.id = sinVector.type .ccount > 1u
2262+ ? m_module.opCompositeConstruct (getVectorTypeId (sinVector.type ), sinVector.type .ccount , sinIds.data ())
2263+ : sinIds[0 ];
2264+ emitRegisterStore (ins.dst [0 ], sinVector);
2265+ }
2266+
2267+ if (cosVector.type .ccount ) {
2268+ cosVector.id = cosVector.type .ccount > 1u
2269+ ? m_module.opCompositeConstruct (getVectorTypeId (cosVector.type ), cosVector.type .ccount , cosIds.data ())
2270+ : cosIds[0 ];
2271+ emitRegisterStore (ins.dst [1 ], cosVector);
2272+ }
22882273 }
22892274
22902275
0 commit comments