• Create Account

### #Actualxoofx

Posted 19 October 2012 - 08:30 AM

Usually when I was creating a ShaderResourceView on a Buffer (in hlsl: Buffer<float4> for example) or a StructuredBuffer (for example: StructuredBuffer<float4>), I was using something like:

[source lang="cpp"]D3D11_SHADER_RESOURCE_VIEW_DESC desc;desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;desc.Format = ...;desc.Buffer.FirstElement = index; // Index in element countdesc.Buffer.NumElements = count; // Number of elements[/source]

It is working fine with both type of buffers (plain or structured), but today, I was checking the documentation of D3D11_BUFFER_SRV, and It says something completely invalid to the usage I have of it.
First of all, there is an union:

[source lang="cpp"]typedef struct D3D11_BUFFER_SRV { union { UINT FirstElement; UINT ElementOffset; }; union { UINT NumElements; UINT ElementWidth; };} D3D11_BUFFER_SRV;[/source]

I have two questions:

1) And as stated in the doc FirstElement is "Number of bytes between the beginning of the buffer and the first element to access.", which is not what I'm experiencing, as I use the index of element, not the index * sizeof(element).
Is it the documentation that is wrong or Am I missing something here?

2) Also, ElementOffset would appear to be used with a byte offset, and ElementWidth as the size of the element, but in which case these fields are interpreted like this? I can't find any relevant doc about this.

Any hint highly appreciated!

Edit: Sorry for the source code, I can't get the source tag to work correctly, everything is collapsed.

### #6xoofx

Posted 19 October 2012 - 08:29 AM

Usually when I was creating a ShaderResourceView on a Buffer (in hlsl: Buffer<float4> for example) or a StructuredBuffer (for example: StructuredBuffer<float4>), I was using something like:

[source lang="cpp"]D3D11_SHADER_RESOURCE_VIEW_DESC desc;desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;desc.Format = ...;desc.Buffer.FirstElement = index; // Index in element countdesc.Buffer.NumElements = count; // Number of elements[/source]

It is working fine with both type of buffers (plain or structured), but today, I was checking the documentation of D3D11_BUFFER_SRV, and It says something completely invalid to the usage I have of it.
First of all, there is an union:

[source lang="cpp"]typedef struct D3D11_BUFFER_SRV { union { UINT FirstElement; UINT ElementOffset; }; union { UINT NumElements; UINT ElementWidth; };} D3D11_BUFFER_SRV;[/source]

I have two questions:

1) And as stated in the doc FirstElement is "Number of bytes between the beginning of the buffer and the first element to access.", which is not what I'm experiencing, as I use the index of element, not the index * sizeof(element).
Is it the documentation that is wrong or Am I missing something here?

2) Also, ElementOffset would appear to be used with a byte offset, and ElementWidth as the size of the element, but in which case these fields are interpreted like this? I can't find any relevant doc about this.

Any hint highly appreciated!

### #5xoofx

Posted 19 October 2012 - 08:24 AM

Usually when I was creating a ShaderResourceView on a Buffer (in hlsl: Buffer<float4> for example) or a StructuredBuffer (for example: StructuredBuffer<float4>), I was using something like:

[source lang="cpp"]D3D11_SHADER_RESOURCE_VIEW_DESC desc;desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;desc.Format = ...;desc.Buffer.FirstElement = index; // Index in element countdesc.Buffer.NumElements = count; // Number of elements[/source]

It is working fine with both type of buffers (plain or structured), but today, I was checking the documentation of D3D11_BUFFER_SRV, and It says something completely invalid to the usage I have of it.
First of all, there is an union:

[source lang="cpp"]typedef struct D3D11_BUFFER_SRV { union { UINT FirstElement; UINT ElementOffset; }; union { UINT NumElements; UINT ElementWidth; };} D3D11_BUFFER_SRV;[/source]

I have two questions:

1) And as stated in the doc FirstElement is "Number of bytes between the beginning of the buffer and the first element to access.", which is not what I'm experiencing, as I use the index of element, not the index * sizeof(element).
Is it the documentation that is wrong or Am I missing something here?

2) Also, ElementOffset would appear to be used with a byte offset, and ElementWidth as the size of the element, but in which case these fields are interpreted like this? I can't find any relevant doc about this.

Any hint highly appreciated!

### #4xoofx

Posted 19 October 2012 - 08:23 AM

Usually when I was creating a ShaderResourceView on a Buffer (in hlsl: Buffer<float4> for example) or a StructuredBuffer (for example: StructuredBuffer<float4>), I was using something like:

[source lang="cpp"]D3D11_SHADER_RESOURCE_VIEW_DESC desc;desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;desc.Format = ...;desc.Buffer.FirstElement = index; // Index in element countdesc.Buffer.NumElements = count; // Number of elements[/source]

It is working fine with both type of buffers (plain or structured), but today, I was checking the documentation of D3D11_BUFFER_SRV, and It says something completely invalid to the usage I have of it.
First of all, there is an union:

[source lang="cpp"]typedef struct D3D11_BUFFER_SRV { union { UINT FirstElement; UINT ElementOffset; }; union { UINT NumElements; UINT ElementWidth; };} D3D11_BUFFER_SRV;[/source]

I have two questions:

1) And as stated in the doc FirstElement is "Number of bytes between the beginning of the buffer and the first element to access.", which is not what I'm experiencing, as I use the index of element, not the index * sizeof(element).
Is it the documentation that is wrong or Am I missing something here?

2) Also, ElementOffset would appear to be used with a byte offset, and ElementWidth as the size of the element, but in which case these fields are interpreted like this? I can't find any relevant doc about this.

Any hint highly appreciated!

### #3xoofx

Posted 19 October 2012 - 08:22 AM

Usually when I was creating a ShaderResourceView on a Buffer (in hlsl: Buffer<float4> for example) or a StructuredBuffer (for example: StructuredBuffer<float4>), I was using something like:

[source lang="cpp"]D3D11_SHADER_RESOURCE_VIEW_DESC desc;desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;desc.Format = ...;desc.Buffer.FirstElement = index; // Index in element countdesc.Buffer.NumElements = count; // Number of elements[/source]

It is working fine with both type of buffers (plain or structured), but today, I was checking the documentation of D3D11_BUFFER_SRV, and It says something completely invalid to the usage I have of it.
First of all, there is an union:

[source lang="cpp"]typedef struct D3D11_BUFFER_SRV { union { UINT FirstElement; UINT ElementOffset; }; union { UINT NumElements; UINT ElementWidth; };} D3D11_BUFFER_SRV;[/source]
I have two questions:

1) And as stated in the doc FirstElement is "Number of bytes between the beginning of the buffer and the first element to access.", which is not what I'm experiencing, as I use the index of element, not the index * sizeof(element).
Is it the documentation that is wrong or Am I missing something here?

2) Also, ElementOffset would appear to be used with a byte offset, and ElementWidth as the size of the element, but in which case these fields are interpreted like this? I can't find any relevant doc about this.

Any hint highly appreciated!

### #2xoofx

Posted 19 October 2012 - 06:56 AM

Usually when I was creating a ShaderResourceView on a Buffer (in hlsl: Buffer<float4> for example) or a StructuredBuffer (for example: StructuredBuffer<float4>), I was using something like:

D3D11_SHADER_RESOURCE_VIEW_DESC desc;
desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
desc.Format = ...;
desc.Buffer.FirstElement = index;   // Index in element count
desc.Buffer.NumElements = count;  // Number of elements


It is working fine with both type of buffers (plain or structured), but today, I was checking the documentation of D3D11_BUFFER_SRV, and It says something completely invalid to the usage I have of it.
First of all, there is an union:

typedef struct D3D11_BUFFER_SRV {
union {
UINT FirstElement;
UINT ElementOffset;
};
union {
UINT NumElements;
UINT ElementWidth;
};
} D3D11_BUFFER_SRV;


I have two questions:

1) And as stated in the doc FirstElement is "Number of bytes between the beginning of the buffer and the first element to access.", which is not what I'm experiencing, as I use the index of element, not the index * sizeof(element).
Is it the documentation that is wrong or Am I missing something here?

2) Also, ElementOffset would appear to be used with a byte offset, and ElementWidth as the size of the element, but in which case these fields are interpreted like this? I can't find any relevant doc about this.

Any hint highly appreciated!

PARTNERS