Skip to main content
gamedev.net
🔒 Locked

Using a tbuffer

Started by Diltsman Dec 9, 2008 at 11:29 PM 0 replies 3.2k views
Original Post
Diltsman
Diltsman
I am trying to use a tbuffer where I was using a cbuffer. For some reason PIX is saying that the shader is not using the constants from the buffer. I'm not certain why this is, since I'm binding the view to slot 0. The only thing I can guess is that I am not creating the view correctly or that the buffer gets messed up when I update it. Another thought I had is that it might be cause by binding the same buffer to both the Geometry shader and the Pixel shader. Could anyone suggest what I am missing?

    HRESULT hr = NULL;
    if(FAILED(hr = device->CreateBuffer(&bufferDescription, &data, &m_buffer)))
    {
        std::stringstream temp;
        temp << "CreateBuffer failed with HRESULT=" << std::hex << hr;
        throw std::runtime_error(temp.str());
    }
    D3D10_SHADER_RESOURCE_VIEW_DESC viewDescription;
    viewDescription.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    viewDescription.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
    viewDescription.Buffer.ElementOffset = 0;
    viewDescription.Buffer.ElementWidth = sizeof(ScreenConstants::ScreenConstantsBuffer)/sizeof(D3DXVECTOR4);
    if(FAILED(hr = device->CreateShaderResourceView(m_buffer, &viewDescription, &m_view)))
    {
        m_buffer->Release();
        m_buffer = NULL;
        std::stringstream temp;
        temp << "CreateShaderResourceView failed with HRESULT=" << std::hex << hr;
        throw std::runtime_error(temp.str());
    }




void ScreenConstants::setScreenWidth(float size)
{
    boost::lock_guard<boost::mutex> lock(m_mapMutex);
    ScreenConstants::ScreenConstantsBuffer * buffer = NULL;
    HRESULT hr = NULL;
    if(FAILED(hr = m_buffer->Map(D3D10_MAP_WRITE_DISCARD, 0x0, reinterpret_cast<void **>(&buffer))))
    {
        std::stringstream temp;
        temp << "Map failed with HRESULT=" << std::hex << hr;
        throw std::runtime_error(temp.str());
    }
    m_screenConstants.screenWidth = size;
    *buffer = m_screenConstants;
    m_buffer->Unmap();
    buffer = NULL;
}




    struct ScreenConstantsBuffer
    {
        D3DXMATRIX perspectiveTransform;
        float screenWidth;
        float screenHeight;
        float pointCrossSize;
        float invalid;
        D3DXVECTOR4 selectedColor;
        D3DXVECTOR4 defaultColor;
        D3DXVECTOR4 cameraLocation;
    };




tbuffer ScreenConstantsBuffer
{
    float4x4 perspectiveTransform;
    float screenWidth;
    float screenHeight;
    float pointCrossSize;
    float invalid;
    float4 selectedColor;
    float4 defaultColor;
    float4 cameraLocation;
};

struct VS_INPUT
{
    float4 pos : POSITION0;
};

struct PS_INPUT
{
    float4 pos : SV_Position;
};

[maxvertexcount(4)]
void GS(point VS_INPUT input[1], inout LineStream<PS_INPUT> output)
{
    PS_INPUT vertex;
    vertex.pos = input[0].pos;
    vertex.pos.x = input[0].pos.x - (2.0 / screenWidth) * pointCrossSize;
    output.Append(vertex);
    vertex.pos.x = input[0].pos.x + (2.0 / screenWidth) * pointCrossSize;
    output.Append(vertex);
    output.RestartStrip();

    vertex.pos = input[0].pos;
    vertex.pos.y = input[0].pos.y - (2.0 / screenHeight) * pointCrossSize;
    output.Append(vertex);
    vertex.pos.y = input[0].pos.y + (2.0 / screenHeight) * pointCrossSize;
    output.Append(vertex);

    output.RestartStrip();
}




//
// Generated by Microsoft (R) HLSL Shader Compiler
//
//
// Buffer Definitions: 
//
// tbuffer ScreenConstantsBuffer
// {
//
//   float4x4 perspectiveTransform;     // Offset:    0 Size:    64 [unused]
//   float screenWidth;                 // Offset:   64 Size:     4 [unused]
//   float screenHeight;                // Offset:   68 Size:     4 [unused]
//   float pointCrossSize;              // Offset:   72 Size:     4 [unused]
//   float invalid;                     // Offset:   76 Size:     4 [unused]
//   float4 selectedColor;              // Offset:   80 Size:    16 [unused]
//   float4 defaultColor;               // Offset:   96 Size:    16 [unused]
//   float4 cameraLocation;             // Offset:  112 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                   Type  Format         Dim Slot Elements
// ---------------- ---------- ------- ----------- ---- --------
// ScreenConstantsBuffer    tbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name             Index   Mask Register SysValue Format   Used
// ---------------- ----- ------ -------- -------- ------ ------
// POSITION             0   xyzw        0     NONE  float   xyzw
//
//
// Output signature:
//
// Name             Index   Mask Register SysValue Format   Used
// ---------------- ----- ------ -------- -------- ------ ------
// SV_Position          0   xyzw        0      POS  float   xyzw
//
gs_4_0
dcl_input v[1][0].xyzw
dcl_output_siv  o0.xyzw , position
dcl_resource_buffer ( mixed , mixed , mixed , mixed ) t0
dcl_temps 3
dcl_inputprimitive point 
dcl_outputtopology linestrip 
dcl_maxout 4
mov r0.yzw, v[0][0].yyzw
mov r1.yzw, v[0][0].yyzw
ld r2.xyzw, l(4, 4, 4, 4), t0.xyzw
div r2.x, l(2.000000), r2.x
mad r1.x, -r2.x, r2.z, v[0][0].x
mad r0.x, r2.x, r2.z, v[0][0].x
mov o0.xyzw, r1.xyzw
emit 
mov o0.xyzw, r0.xyzw
emit 
cut 
mov r0.xzw, v[0][0].xxzw
div r1.x, l(2.000000), r2.y
mad r0.y, -r1.x, r2.z, v[0][0].y
mad r1.y, r1.x, r2.z, v[0][0].y
mov o0.xyzw, r0.xyzw
emit 
mov r1.xzw, v[0][0].xxzw
mov o0.xyzw, r1.xyzw
emit 
cut 
ret 
// Approximately 22 instruction slots used




[Edited by - Diltsman on December 10, 2008 10:01:32 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.