Jump to content
  • Advertisement

collie

Member
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

213 Neutral

About collie

  • Rank
    Member

Personal Information

  • Interests
    Art
    Audio
    Design
    DevOps
    Programming
    QA
  1. If anyone is interested the error appeared to arise from the order I was calling the different Map's. Previously it was calling the Maps in the order of...   D3D11_MAP_WRITE_NO_OVERWRITE <- Obj 1 D3D11_MAP_WRITE_DISCARD      <- Obj 2   Simply switching them around allowed both objects to render correctly. I'm still unsure why pressing the mouse or prtscr allowed the rendering to be correct; but at least it works now.   Thank you.
  2. Hello,   I am trying to speed up a D3D11 graphics engine I am working on by limiting the amount of DrawIndexedInstanced() calls. My newly modified code only does a DrawIndexedInstanced() when A) a buffer is filled up B) an object has changed or C) there are no more objects to render. The pseudo code would be like this... {     loop (objects)     {         if (new-object OR buffer-filled)         {            // A            IASetInputLayout()            IASetVertexBuffers()            DrawIndexedInstanced()            hresult = Map (D3D11_MAP_WRITE_DISCARD)         }         else         {            // B            hresult = Map (D3D11_MAP_WRITE_NO_OVERWRITE)         }         memcpy buffer                        UnMap     }     // no more objects     IASetInputLayout()     IASetVertexBuffers()     DrawIndexedInstanced() } I am currently rendering two different sized objects into a small window. Everything appears to be rendering correctly if I capture a frame via the Graphics debugger; I see both objects. The problem is that only one object is actually being displayed within the small window...that is *until* I use the mouse to press the windows title bar (or press prtscr). When I do the second object appears (rendered correctly).  When I release the mouse the second object disappears again. It appears that when you grab the caption the DX application is paused until the mouse is released.  If both objects share the same buffer could this be causing an issue; where the pause allows more time for it to be processed?  Has anyone got any ideas whats happening?   Thank you
  3. I created a C++ lossless bit compression stream a couple of years back as a quick prototype.  It's something I might use later for a game I'm making? It probably needs to be RLE before the actual packing; maybe something to add another day?   https://github.com/cole-anstey/bit-compression-stream/wiki
  4. collie

    Unused param

    With VC++ I use the macro UNREFERENCED_PARAMETER(x).   I've just had a quick peek and it's defined as the following. #define UNREFERENCED_PARAMETER(P)          (P)
  5. Hi Jason,  Thank you for the reply. Yes I believe blending was off..   D3D11_BLEND_DESC desc; ::ZeroMemory(&desc, sizeof(D3D11_BLEND_DESC)); desc.RenderTarget[0].BlendEnable = FALSE; ...   Regards
  6. Hi, I'm rendering to a Texture2D via a pixelshader and everything is working correctly. The input.depth value being returned from it is 0.045904520. Texture2D DepthMap : register(t0); SamplerState DepthMapSampler : register(s0); float4 txDepthMapPixelShader(in PixelShaderInput_DepthMap input) : SV_TARGET {     return float4(input.depth, 0, 0, 0); <-- 0.045904520 } When I sample the texture in another pixel shader the depth value has changed to 1.045904520; becoming 1.0 higher. float4 txPixelShader(in PixelShaderInput input) : SV_TARGET {     float2 depthTexCoords = 0.5 * input.vertexPosition2.xy / input.vertexPosition2.w + float2(0.5, 0.5);     depthTexCoords.y = 1.0f - depthTexCoords.y; // Inverse - good for debugging.     float depth = DepthMap.Sample(DepthMapSampler, depthTexCoords.xy).r; <-- 1.045904520     ... Now I can delete this value by 1.0 to get the effect I desire so it's not really a problem; but I'm curious as to where this additional 1.0 has originated from? Has anyone got any ideas?  Thank you in advance. The data structures I use are as follows. D3D11_TEXTURE2D_DESC depthTextureDesc; ::ZeroMemory(&depthTextureDesc, sizeof(D3D11_TEXTURE2D_DESC)); depthTextureDesc.Width = _windowWidth; depthTextureDesc.Height = _windowHeight; depthTextureDesc.MipLevels = 1; depthTextureDesc.ArraySize = 1; depthTextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; depthTextureDesc.SampleDesc.Count = 1; depthTextureDesc.Usage = D3D11_USAGE_DEFAULT; depthTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; depthTextureDesc.CPUAccessFlags = 0; depthTextureDesc.MiscFlags = 0; hr = _device->CreateTexture2D(&depthTextureDesc, NULL, &_depthDepthStencil); assert(SUCCEEDED(hr)); D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc; ::ZeroMemory(&shaderResourceViewDesc, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC)); shaderResourceViewDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; shaderResourceViewDesc.Texture2D.MipLevels = 1; hr = _device->CreateShaderResourceView(_depthDepthStencil, &shaderResourceViewDesc, &_depthResourceView); assert(SUCCEEDED(hr)); D3D11_RENDER_TARGET_VIEW_DESC depthTargetViewDesc; ::ZeroMemory(&depthTargetViewDesc, sizeof(D3D11_RENDER_TARGET_VIEW_DESC)); depthTargetViewDesc.Format = shaderResourceViewDesc.Format; depthTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; depthTargetViewDesc.Texture2D.MipSlice = 0; hr = _device->CreateRenderTargetView(_depthDepthStencil, &depthTargetViewDesc, &_depthRenderTargetView); assert(SUCCEEDED(hr)); D3D11_RASTERIZER_DESC depthRenderStateDesc; ::ZeroMemory(&depthRenderStateDesc, sizeof(D3D11_RASTERIZER_DESC)); depthRenderStateDesc.CullMode = D3D11_CULL_FRONT; depthRenderStateDesc.FillMode = D3D11_FILL_SOLID; depthRenderStateDesc.DepthClipEnable = true; hr = _device->CreateRasterizerState(&depthRenderStateDesc, &_depthRasterState); assert(SUCCEEDED(hr));  
  7. If your seeing a variable show as a NaN double check that it's really is being *used* within the shader. If your seeing a variable show as 0.000000000 check that it's going to be accessed within your shader, i.e. it may be in an 'if' that won't be entered?   The compiler could be optimizing those variables out.  Assuming this is the issue you've described?
  8. collie

    Constant buffer not working

    I read somewhere the other day that you have to use XMMatrixTranspose() in DX11 otherwise you'll get NaN in the pixel shader.   http://stackoverflow.com/questions/14150922/directx-11-shader-error-pixel-shader-receiving-only-nan/14164755#14164755
  9. Well done; you were right I *wasn't* using... float2 textureCoordinates : TEXCOORD0; ...within the vertex shader. I did a quick hack and added it to another existing value, recompiled and it magically appeared. As I was only using the .x part of the float2 it appeared as... textureCoordinates x = 5.000000000, y = NaN float2 So 'NaN's basically could mean a variable is unused.    Also interestingly... float bitWidth : TEXCOORD2; ...turned out to have a value of... bitWidth 00.000000000 float ...because though it *was* being used within the vertex shader it was within a 'if' that wouldn't be entered. Another quick bodge to allow the entering of the 'if' showed the value as... bitWidth 33.000000000 float So a 0.000000000 value could/may mean that though a variable is being used within the vertex shader it may not be called (so you won't see the true value). I wonder if this behaviour is written down anywhere as I can't remember reading this or seeing it before? Many thanks for your help Polarist; have a good weekend.   Regards Cole
  10. Thanks for the reply. I set it directly after the vertexLayoutDesc declaration.   const D3D11_INPUT_ELEMENT_DESC vertexLayoutDesc[] = { // Vertex buffer slot 0. { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // vertexPosition { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // textureCoordinates { "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // vertexNumber // Vertex buffer slot 1. { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitColour // Vertex buffer slot 2. { "TEXCOORD", 2, DXGI_FORMAT_R32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitWidth // Vertex buffer slot 3. { "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT, 3, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitOffset }; hr = device->CreateInputLayout( vertexLayoutDesc, ARRAYSIZE(vertexLayoutDesc), vertexShaderBytecode, vertexShaderBytecodeLength, &_inputLayout); deviceContext->IASetInputLayout(_inputLayout);
  11. I have a problem where certain floats in a VertexShaderInput are either NaN or 0.000000000. I have 4 streams being sent to the vertex shader. float2 'textureCoordinates' of slot 0 always appear to be NaN. float 'bitWidth' of slot 2 always appear to be 0.000000000. struct VertexShaderInput { // Vertex buffer slot 0. float4 vertexPosition : POSITION0; float2 textureCoordinates : TEXCOORD0; float vertexNumber : TEXCOORD1; // Vertex buffer slot 1. float4 bitColour : COLOR0; // Vertex buffer slot 2. float bitWidth : TEXCOORD2; // Vertex buffer slot 4. float2 bitOffset : TEXCOORD3; }; The other floats appear to have the expected values when debugged.  Slot 2-3 are instanced streams. I have tried changing float sizes and the matching DXGI_FORMAT_xxxx_FLOAT to no avail. In the data I have given each float an incrementing value to make it easier to check the input.   const D3D11_INPUT_ELEMENT_DESC vertexLayoutDesc[] = { // Vertex buffer slot 0. { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // vertexPosition { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // textureCoordinates { "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }, // vertexNumber // Vertex buffer slot 1. { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitColour // Vertex buffer slot 2. { "TEXCOORD", 2, DXGI_FORMAT_R32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitWidth // Vertex buffer slot 3. { "TEXCOORD", 3, DXGI_FORMAT_R32G32_FLOAT, 3, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, // bitOffset };   hr = device->CreateInputLayout(     vertexLayoutDesc,     ARRAYSIZE(vertexLayoutDesc),     vertexShaderBytecode,     vertexShaderBytecodeLength,     &_inputLayout); deviceContext->IASetInputLayout(_inputLayout); struct VertexPositions { DirectX::XMFLOAT4 _vertexPosition; DirectX::XMFLOAT2 _textureCoordinates; FLOAT _vertexNumber; } VertexPositions vpnts[] = { { DirectX::XMFLOAT4(1.0f, 2.0f, 3.0f, 4.0f), // vertexPosition DirectX::XMFLOAT2(5.0f, 6.0f), // textureCoordinates 7.0f // vertexNumber }, { DirectX::XMFLOAT4(8.0f, 9.0f, 10.0f, 10.0f), // vertexPosition DirectX::XMFLOAT2(12.0f, 13.0f), // textureCoordinates 14.0f // vertexNumber }, { DirectX::XMFLOAT4(15.0f, 16.0f, 17.0f, 18.0f), // vertexPosition DirectX::XMFLOAT2(19.0f, 20.0f), // textureCoordinates 21.0f // vertexNumber }, { DirectX::XMFLOAT4(22.0f, 24.0f, 24.0f, 25.0f), // vertexPosition DirectX::XMFLOAT2(26.0f, 27.0f), // textureCoordinates 28.0f // vertexNumber } }; #pragma region Vertex Buffer slot 0 D3D11_BUFFER_DESC vertexBufferDesc; ::ZeroMemory(&vertexBufferDesc, sizeof(D3D11_BUFFER_DESC)); vertexBufferDesc.ByteWidth = sizeof(VertexPositions) * 4; vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vertexBufferData; ::ZeroMemory(&vertexBufferData, sizeof(D3D11_SUBRESOURCE_DATA)); vertexBufferData.pSysMem = vpnts; vertexBufferData.SysMemPitch = 0; vertexBufferData.SysMemSlicePitch = 0; hr = device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &_vbBitBlock); #pragma endregion INT instanceCount = 1; DirectX::XMFLOAT4* bitColors = new DirectX::XMFLOAT4[1]; (*bitColors).x = 29.0f; (*bitColors).y = 30.0f; (*bitColors).z = 31.0f; (*bitColors).w = 32.0f; FLOAT* bitWidths = new FLOAT[1]; (*bitWidths) = 33.0f; DirectX::XMFLOAT2* bitOffsets = new DirectX::XMFLOAT2[1]; (*bitOffsets).x = 34.0f; (*bitOffsets).y = 35.0f; #pragma region Vertex Buffer slot 1 D3D11_BUFFER_DESC vertexBufferDesc_one; ::ZeroMemory(&vertexBufferDesc_one, sizeof(D3D11_BUFFER_DESC)); vertexBufferDesc_one.ByteWidth = sizeof(DirectX::XMFLOAT4) * instanceCount; vertexBufferDesc_one.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc_one.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc_one.CPUAccessFlags = 0; vertexBufferDesc_one.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vertexBufferData_one; ::ZeroMemory(&vertexBufferData_one, sizeof(D3D11_SUBRESOURCE_DATA)); vertexBufferData_one.pSysMem = bitColors; vertexBufferData_one.SysMemPitch = 0; vertexBufferData_one.SysMemSlicePitch = 0; hr = device->CreateBuffer(&vertexBufferDesc_one, &vertexBufferData_one, &_vbBitColors); assert(SUCCEEDED(hr)); #pragma endregion #pragma region Vertex Buffer slot 2 D3D11_BUFFER_DESC vertexBufferDesc_two; ::ZeroMemory(&vertexBufferDesc_two, sizeof(D3D11_BUFFER_DESC)); vertexBufferDesc_two.ByteWidth = sizeof(FLOAT) * instanceCount; vertexBufferDesc_two.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc_two.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc_two.CPUAccessFlags = 0; vertexBufferDesc_two.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vertexBufferData_two; ::ZeroMemory(&vertexBufferData_two, sizeof(D3D11_SUBRESOURCE_DATA)); vertexBufferData_two.pSysMem = bitWidths; vertexBufferData_two.SysMemPitch = 0; vertexBufferData_two.SysMemSlicePitch = 0; hr = device->CreateBuffer(&vertexBufferDesc_two, &vertexBufferData_two, &_vbBitWidths); assert(SUCCEEDED(hr)); #pragma endregion #pragma region Vertex Buffer slot 3 D3D11_BUFFER_DESC vertexBufferDesc_three; ::ZeroMemory(&vertexBufferDesc_three, sizeof(D3D11_BUFFER_DESC)); vertexBufferDesc_three.ByteWidth = sizeof(DirectX::XMFLOAT2) * instanceCount; vertexBufferDesc_three.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc_three.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc_three.CPUAccessFlags = 0; vertexBufferDesc_three.MiscFlags = 0; D3D11_SUBRESOURCE_DATA vertexBufferData_three; ::ZeroMemory(&vertexBufferData_three, sizeof(D3D11_SUBRESOURCE_DATA)); vertexBufferData_three.pSysMem = bitOffsets; vertexBufferData_three.SysMemPitch = 0; vertexBufferData_three.SysMemSlicePitch = 0; hr = device->CreateBuffer(&vertexBufferDesc_three, &vertexBufferData_three, &_vbBitOffsets); assert(SUCCEEDED(hr)); #pragma endregion const int NumVertexBuffers = 4; UINT strides[NumVertexBuffers]; strides[0] = sizeof(VertexPositions); // stride 28. strides[1] = sizeof(DirectX::XMFLOAT4); // stride 16. strides[2] = sizeof(FLOAT); // stride 4. strides[3] = sizeof(DirectX::XMFLOAT2); // stride 8. // Set the buffer offsets. UINT offsets[NumVertexBuffers]; offsets[0] = 0; offsets[1] = 0; offsets[2] = 0; offsets[3] = 0; // Set the array of pointers to the vertex and instance buffers. ID3D11Buffer* bufferPointers[NumVertexBuffers]; bufferPointers[0] = _vbBitBlock; bufferPointers[1] = _vbBitColors; bufferPointers[2] = _vbBitWidths; bufferPointers[3] = _vbBitOffsets; DeviceContext->IASetVertexBuffers(0, NumVertexBuffers, bufferPointers, strides, offsets); DeviceContext->DrawIndexedInstanced(6, instanceCount, 0, 0, 0); The vertex buffers captured from PIX below appear to be correct.   Currently used format: float --------------------------------------------------------------------------------------------------------------------------------- 0 [0x00000000-0x00000003] | +1 1 [0x00000004-0x00000007] | +2 2 [0x00000008-0x0000000b] | +3 3 [0x0000000c-0x0000000f] | +4 4 [0x00000010-0x00000013] | +5 5 [0x00000014-0x00000017] | +6 6 [0x00000018-0x0000001b] | +7 7 [0x0000001c-0x0000001f] | +8 8 [0x00000020-0x00000023] | +9 9 [0x00000024-0x00000027] | +10 10 [0x00000028-0x0000002b] | +10 11 [0x0000002c-0x0000002f] | +12 12 [0x00000030-0x00000033] | +13 13 [0x00000034-0x00000037] | +14 14 [0x00000038-0x0000003b] | +15 15 [0x0000003c-0x0000003f] | +16 16 [0x00000040-0x00000043] | +17 17 [0x00000044-0x00000047] | +18 18 [0x00000048-0x0000004b] | +19 19 [0x0000004c-0x0000004f] | +20 20 [0x00000050-0x00000053] | +21 21 [0x00000054-0x00000057] | +22 22 [0x00000058-0x0000005b] | +24 23 [0x0000005c-0x0000005f] | +24 24 [0x00000060-0x00000063] | +25 25 [0x00000064-0x00000067] | +26 26 [0x00000068-0x0000006b] | +27 27 [0x0000006c-0x0000006f] | +28 0 [0x00000000-0x00000003] | +29 1 [0x00000004-0x00000007] | +30 2 [0x00000008-0x0000000b] | +31 3 [0x0000000c-0x0000000f] | +32 0 [0x00000000-0x00000003] | +33 0 [0x00000000-0x00000003] | +34 1 [0x00000004-0x00000007] | +35 Debugging the vertex shader input values within hlsl shows that most values do appear to be correct.   vertexPosition x = 1.000000000, y = 2.000000000, z = 3.000000000, w = 4.000000000 float4 textureCoordinates x = NaN, y = NaN float2 vertexNumber 7.000000000 float bitColour x = 29.000000000, y = 30.000000000, z = 31.000000000, w = 32.000000000 float4 bitWidth 0.000000000 float bitOffset x = 34.000000000, y = 35.000000000 float2 So whats happened to 'textureCoordinates' and 'bitWidth'? I've left out the IASetIndexBuffer() code as I don't think it's causing the issue. I am using debug D3D11_CREATE_DEVICE_DEBUG and during execution there appears to be no DX errors or warnings.   Hopefully I've given enough information above to describe what I'm doing. I've been trying to figure this out for the last week by commenting bits out and changing type sizes but nothing works. As far as I can see it appears what I'm doing is correct so any pointers into what could be giving me the NaN and 0.000000000 would be *really* appreciated.   Many thanks. Cole
  • 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!