Jump to content
  • Advertisement
Sign in to follow this  

Compute shader doesn't produce result..

This topic is 2147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a compute shader which simply writes a value to a texture.  The result is copied from the unordered access texture to a texture which is bound as an SRV and rendered as a quad.  However, the screen is blank.  According to the Visual Studio 2012 Resource Visualizer in the Graphics debugger, both the UAV texture and the output texture are empty.


Here is the code which creates the compute shader as well as the UAV and a texture to copy the output to:

bool NBodySim::createComputeShader(LPCWSTR path)
		HRESULT result = 0;
		LPCSTR target = "cs_5_0";
		ID3DBlob* blob = NULL;
		ID3DBlob* errorMessageBlob = NULL;

	#ifdef _DEBUG
		shaderFlags |= D3DCOMPILE_DEBUG;

		result = D3DCompileFromFile(path, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE,  "main", target, shaderFlags, 0, &blob, &errorMessageBlob);

			return false;
		result = this->device->CreateComputeShader(
			return false;

		//create a texture for the uav
		D3D11_TEXTURE2D_DESC uavTextureDesc;
		ZeroMemory(&uavTextureDesc, sizeof(D3D11_TEXTURE2D_DESC));
		uavTextureDesc.ArraySize = 1;
		uavTextureDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
		uavTextureDesc.CPUAccessFlags = 0;
		uavTextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
		uavTextureDesc.Height = 256;
		uavTextureDesc.Width = 256;
		uavTextureDesc.MipLevels = 1;
		uavTextureDesc.MiscFlags = 0;
		uavTextureDesc.Usage = D3D11_USAGE_DEFAULT;
		uavTextureDesc.SampleDesc.Count = 1;
		uavTextureDesc.SampleDesc.Quality = 0;

		if(FAILED(this->device->CreateTexture2D(&uavTextureDesc, NULL, &this->uavTexture)))
			return false;

		//create unordered access view
		ZeroMemory( &descView, sizeof(descView) );
		descView.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
		descView.Buffer.FirstElement = 0;

		descView.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;  
		descView.Texture2D.MipSlice = 0;
		if(FAILED(this->device->CreateUnorderedAccessView( this->uavTexture, &descView, &this->uav )))
			return false;

		//create output texture/srv for Compute Shader
		D3D11_TEXTURE2D_DESC csOutputTextureDesc;
		ZeroMemory(&csOutputTextureDesc, sizeof(D3D11_TEXTURE2D_DESC));
		csOutputTextureDesc.ArraySize = 1;
		csOutputTextureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		csOutputTextureDesc.CPUAccessFlags = 0;
		csOutputTextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
		csOutputTextureDesc.Height = 256;
		csOutputTextureDesc.Width = 256;
		csOutputTextureDesc.MipLevels = 1;
		csOutputTextureDesc.MiscFlags = 0;
		csOutputTextureDesc.Usage = D3D11_USAGE_DEFAULT;
		csOutputTextureDesc.SampleDesc.Count = 1;
		csOutputTextureDesc.SampleDesc.Quality = 0;

		if(FAILED(this->device->CreateTexture2D(&csOutputTextureDesc, NULL, &this->csOutputTexture)))
			return false;

		ZeroMemory(&csOutputTextureSRVDesc, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
		csOutputTextureSRVDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
		csOutputTextureSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
		csOutputTextureSRVDesc.Texture2D.MipLevels = 1;
		csOutputTextureSRVDesc.Texture2D.MostDetailedMip = 0;

		if(FAILED(this->device->CreateShaderResourceView(this->csOutputTexture, &csOutputTextureSRVDesc, &this->csOutputTextureSRV)))
			return false;

		return true;

Here is the code where the compute shader is run:

this->context->CSSetShader(this->cShader, NULL, 0);

		ID3D11UnorderedAccessView* uavs = {this->uav};
		this->context->CSSetUnorderedAccessViews(0, 1, &uavs, NULL);

		this->context->CSSetShader(NULL, NULL, 0);

		this->context->CopyResource(this->uavTexture, this->csOutputTexture);

Here is the actual code for the compute shader:

RWTexture2D<float4> output;

[numthreads(16, 16, 1)]
void main( uint3 threadID : SV_DispatchThreadID )
	output[threadID.xy] = float4(1.0f,0.0f,0.0f, 0.5f);

Any ideas?

Edited by jdub

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!