How to get the index of the specified light for shader?

I want to implement the volume light function of SpotLight. No problem with just one light. But when there are multiple lights, I need to write the index of the specified light to the material in order to sample the corresponding shadow map and calculate the distance falloff.

How to get this index value through code?

I found renderingData.lightData.visibleLights in RenderingData, is the index here corresponding to the index in the CBuffer of AdditionalLights?

After testing, the index obtained from visibleLights is in the same order as the index in CBuffer, but the number of parallel lights needs to be subtracted.

Is there a more explicit way to get the index?