Texture fetch for layered texture

I am trying to use the layered textures. As mentioned in the documentation I used RT_BUFFER_LAYERED along with RT_BUFFER_INPUT flag while create the buffer (3D buffer, layers of 2D textures). When I am trying to access texture values in a program always a 0 is returned. Here is the code for creating the texture.

optix::Buffer specularTexBuffer = context->createBuffer(RT_BUFFER_INPUT | RT_BUFFER_LAYERED, RT_FORMAT_FLOAT, texture_dimensions.x, texture_dimensions.y, 14);
	data = (float*)specularTexBuffer->map();
	specularTextureFile.read((char*)data, sizeof(float)*texture_dimensions.x*texture_dimensions.y*14);
	specularTexBuffer->unmap();
	data = NULL;
	specularTextureFile.close();

	//setting specular texture sampler
	optix::TextureSampler specularTex = context->createTextureSampler();
	specularTex->setWrapMode(0,RT_WRAP_CLAMP_TO_EDGE);
	specularTex->setWrapMode(1,RT_WRAP_CLAMP_TO_EDGE);
	specularTex->setWrapMode(2,RT_WRAP_CLAMP_TO_EDGE);
	specularTex->setFilteringModes(RT_FILTER_LINEAR, RT_FILTER_LINEAR, RT_FILTER_NONE);
	specularTex->setIndexingMode(RT_TEXTURE_INDEX_ARRAY_INDEX);
	specularTex->setReadMode(RT_TEXTURE_READ_ELEMENT_TYPE);
	specularTex->setMaxAnisotropy(1.f);
	specularTex->setMipLevelCount(1u);
	specularTex->setArraySize(1u);
	specularTex->setBuffer(specularTexBuffer);

Here’s how I declare the texture in the program and how I access it

rtTextureSampler<float, 3, cudaReadModeElementType> specular_texture;
......
.....
//Code for fetching
tex3D(specular_texture, 0,0,0); //Always returns 0 for all coordinates

I have another doubt regarding rtTexD class of functions, how are they different from texD functions and when is it appropriate to use them?

Please read this thread: https://devtalk.nvidia.com/default/topic/1033091/?comment=5256494
That talks about cubemaps, but the mechanism is similar for layered textures.
Always use bindless texture IDs and the appropriate rtTex*() function.
In your case rtTex2DLayered(rtTextureId id, float x, float y, int layer) or the like.
See all definitions in optix_device.h

Is it recommended to always use bindless textures, even in the case of simple 2D texture?

Yes, because that gives almost arbitrary many textures in a scene without being limited to the maximum number of texture units of the underlying hardware and because it allows to check dynamically if a texture is present and because you can have buffers of texture IDs, etc.
Same here: https://devtalk.nvidia.com/default/topic/1020023/tex2dgrad-exception-when-translating-ptx-to-llvm/

Thanks alot for the information