Hello,
I have following structure in cpp:
struct PixelData
{
float r;
float g;
float b;
float a;
unsigned int texId;
unsigned int type;
unsigned int index;
bool clip;
unsigned int clippedParentIndex;
};
in pixel shader I have this data:
struct Data
{
float4 col;
uint texId;
uint type;
uint index;
bool clip;
uint clippedParentIndex;
};
I'm using this data with shader resource:
D3D11_BUFFER_DESC psDataBufferDesc{};
psDataBufferDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
psDataBufferDesc.ByteWidth = sizeof(PixelData) * maxQuads;
psDataBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
psDataBufferDesc.StructureByteStride = sizeof(PixelData);
psDataBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
psDataBufferDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
hr = device->CreateBuffer(&psDataBufferDesc, NULL, psDataBuffer.ReleaseAndGetAddressOf());
throwIfFailed(hr);
hr = device->CreateShaderResourceView(psDataBuffer.Get(), NULL, psDataView.ReleaseAndGetAddressOf());
throwIfFailed(hr);
and
vector<PixelData> pixelData;
pixelData.push_back({ 0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, false, 0 });
D3D11_MAPPED_SUBRESOURCE mappedResource2;
hr = context->Map(psDataBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource2);
throwIfFailed(hr);
memcpy(mappedResource2.pData, static_cast<void*>(pixelData.data()), sizeof(PixelData) * pixelData.size());
context->Unmap(psDataBuffer.Get(), 0);
context->PSSetShaderResources(0, 1, psDataView.GetAddressOf());
Here pixelData have correct data, I double (actually triple) checked. But when I debug shader, bool field in Data is always true. Why? Maybe there're some rules that bool can't be set like this?