Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:20:46+00:00 2026-05-30T07:20:46+00:00

I am attempting to do some processing in the pixel shader on a texture.

  • 0

I am attempting to do some processing in the pixel shader on a texture. The data for the texture is coming from a memory chunk of 8 bit data. The problem I am facing is how to read the data in the shader.

Code to create the texture and ressource view:

In OnD3D11CreateDevice:

D3D11_TEXTURE2D_DESC tDesc;
tDesc.Height = 480;
tDesc.Width = 640;
tDesc.Usage = D3D11_USAGE_DYNAMIC;
tDesc.MipLevels = 1;
tDesc.ArraySize = 1;
tDesc.SampleDesc.Count = 1;
tDesc.SampleDesc.Quality = 0;
tDesc.Format = DXGI_FORMAT_R8_UINT;
tDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
tDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tDesc.MiscFlags = 0;
V_RETURN(pd3dDevice->CreateTexture2D(&tDesc, NULL, &g_pCurrentImage));
D3D11_SHADER_RESOURCE_VIEW_DESC rvDesc;
g_pCurrentImage->GetDesc(&tDesc);
rvDesc.Format = DXGI_FORMAT_R8_UINT;
rvDesc.Texture2D.MipLevels = tDesc.MipLevels;
rvDesc.Texture2D.MostDetailedMip = tDesc.MipLevels - 1;
rvDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
V_RETURN(pd3dDevice->CreateShaderResourceView(g_pCurrentImage, &rvDesc, &g_pImageRV));    </code>

in OnD3D11FrameRender:

HRESULT okay;

if( !g_updateDone ) {
    D3D11_MAPPED_SUBRESOURCE resource;
    resource.pData = mImage.GetData();
    resource.RowPitch = 640;
    resource.DepthPitch = 1;
    okay = pd3dImmediateContext->Map(g_pCurrentImage, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource);

    g_updateDone = true;
}

pd3dImmediateContext->PSSetShaderResources(0, 1, &g_pImageRV);

This returns no errors so far, everything seems to work.

The HLSL Shader:

//-----  
// Textures and Samplers  
//-----  

Texture2D <int> g_txDiffuse : register( t0 );  
SamplerState g_samLinear : register( s0 );  

//-----  
// shader input/output structure  
//-----  

struct VS_INPUT  
{  
    float4 Position     : POSITION; // vertex position   
    float2 TextureUV    : TEXCOORD0;// vertex texture coords   
};  

struct VS_OUTPUT  
{  
    float4 Position     : SV_POSITION; // vertex position   
    float2 TextureUV    : TEXCOORD0;   // vertex texture coords   
};  

//-----  
// Vertex shader  
//-----  
VS_OUTPUT RenderSceneVS( VS_INPUT input )  
{  
    VS_OUTPUT Output;  

    Output.Position = input.Position;  

    Output.TextureUV = input.TextureUV;   

    return Output;      
}  

//-----  
// Pixel Shader  
//-----  

float4 RenderScenePS( VS_OUTPUT In ) : SV_TARGET  
{   
    int3 loc;  
    loc.x = 0;  
    loc.y = 0;  
    loc.z = 1;  
    int r = g_txDiffuse.Load(loc);  
    //float fTest = (float) r;  

    return float4( In.TextureUV.x, In.TextureUV.y, In.TextureUV.x + In.TextureUV.y, 1);  
}

The thing is, I can’t even debug it in PIX to see what r results in, because even with Shader optimization disabled, the line int r = … is never reached

I tested

float fTest = (float) r;
return float4( In.TextureUV.x, In.TextureUV.y, In.TextureUV.x + In.TextureUV.y, fTest);

but this would result in “cannot map expression to pixel shader instruction set”, even though it’s a float.

So how do I read and use 8bit integers from a texture, and if possible, with no sampling at all.

Thanks for any feedback.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:20:48+00:00Added an answer on May 30, 2026 at 7:20 am

    Oh my this is a really old question, I thought it said 2012!

    But anyway as it’s still open:

    Due to the nature of GPU’s being optimised for floating point arithmetic, you probably wont get a great deal of performance advantage by using a Texture2D<int> over a Texture2D<float>.

    You could attempt to use a Texture2D<float> and then try:

    return float4( In.TextureUV.x, In.TextureUV.y, In.TextureUV.x + In.TextureUV.y, g_txDiffuse.Load(loc));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to pull some data from a SQLite database so that I can
I am attempting to get some information from a website, the info that I
I am attempting some pattern matching in Lua and have hit a small problem.
So, I'm doing some image processing in MATLAB, and attempting to save a file
I am attempting to parse some JSON from a URL via Flash/AS3. Here's my
I'm attempting to convert some of my code from Tkinter to wxPython. Currently I'm
I am attempting add some tests to an existing QT GUI application using QTest.
Does attempting to develop some sort of game, even just as a hobby during
I'm attempting to display some text in my program using (say) Windows GDI and
I'm attempting to display some text in my program using (say) Windows GDI and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.