Convert pixel formats in Compute Shader

Started by
13 comments, last by JB3DG 10 years, 6 months ago

Ok i changed things around a bit. The Shader resource view Texture2D obejct is now a class member that isnt released until shutdown. It is created with Dynamic usage and CPU Write access.


void CamToTex:CreateInput(void* data, UINT pitch, UINT stride)
{
	if(src_view)
		src_view->Release();
	src_view = NULL;

	D3D10_MAPPED_TEXTURE2D img;
	HRESULT hr = src->Map(0, D3D10_MAP_WRITE_DISCARD, 0, &img);
	
	if(hr == S_OK)
	{
		char* s = (char*)data;
		char* d = (char*)img.pData;
		for(int i = 0; i < 440; i ++)
		{
			SSEmemcpy(d, s, 3520);
			s += 3584;
			d += 3584;
		}
		src->Unmap(0);
		hr = D3DX10SaveTextureToFile(src, D3DX10_IFF_BMP, L"DX10Tests\\test.bmp");
		hr = dev->CreateShaderResourceView(src, NULL, &src_view);
		dev->PSSetShaderResources(0, 1, &src_view);
	}
};

As you can see i am only copying the 440*8bytes resulting in a pitch of 3520 but advancing the pointers by 3584 at the end since thats the pitch i get from img.RowPitch for both the source and destination surfaces.

I save out the texture to a 64bit format BMP file and when i view it I get a nice clean clear image. However I still get garbage coming out of the shader.

Here is my Vertex shader(generates the fullscreen quad in the GPU)


struct VS_Output
{
	float4 position : SV_POSITION;
	float2 tex : TEXCOORD0;
};

VS_Output VS(uint id : SV_VertexID)
{
	VS_Output Output;
	Output.tex = float2((id << 1) & 2, id & 2);
	Output.position = float4(Output.tex * float2(2,-2) + float2(-1,1), 0, 1);
	return Output;
}

And my Pixel Shader:


Texture2D shaderTextures;
SamplerState SampleType;

struct VS_Output
{
	float4 position : SV_POSITION;
	float2 tex : TEXCOORD0;
};

float4 PS(VS_Output input):SV_TARGET
{
	float4 color1;

	color1 = shaderTextures.SampleLevel(SampleType, input.tex, 0);
		
	return color1;
}

Any ideas on where it is going wrong here?

Advertisement

As you can see i am only copying the 440*8bytes resulting in a pitch of 3520 but advancing the pointers by 3584 at the end since thats the pitch i get from img.RowPitch for both the source and destination surfaces.

Do not assume that this is the case everytime. Every Map call can potentially return a different pitch for even the same resource. The only guarantee is that it is greater than or equal to the width * number of bytes per pixel.

Niko Suni

As you can see i am only copying the 440*8bytes resulting in a pitch of 3520 but advancing the pointers by 3584 at the end since thats the pitch i get from img.RowPitch for both the source and destination surfaces.

Do not assume that this is the case everytime. Every Map call can potentially return a different pitch for even the same resource. The only guarantee is that it is greater than or equal to the width * number of bytes per pixel.

Gotcha will try incrementing by the actual returned pitch values.

Nope still no luck

:Facepalm: Disregard....My absolute idiocy. I failed to notice that the 32bit format render target was also having this slight difference in pitch and when i adjusted for it, I got a nice clean image as a result.

Thanks for the help though...really appreciate it.

This topic is closed to new replies.

Advertisement